This section provides an overview of the drag-and-drop application program interface (API).
The drag-and-drop functionality is implemented in the Desktop Services library, DtSvc. To access the drag-and-drop API, include the header file <Dt/Dnd.h> and link with -lDtSvc.
The API includes four function calls, which are declared in the header file Dnd.h and outlined in the following paragraphs. These functions are described in greater detail in later sections.
DtDndDragStart() starts a drag in response to a user action.
DtDndCreateSourceIcon() creates a source icon to use with DtDndDragStart().
DtDndDropRegister() registers a widget as a drop zone. Drop zone registration usually occurs immediately after the widget is created, but may be performed at any time.
DtDndDropUnregister() unregisters a previously registered widget. A drop zone is usually unregistered immediately before being destroyed, but may be unregistered any time after being registered.
You handle transfers of data using the DtDndContext data structure. This structure contains fields for the transfer protocol, the number of items being transferred, and an array of the data items being transferred. See the DtDndDragStart(3X) and DtDndDropRegister(3X) man pages for details about the syntax of this structure.
Protocols are used to tell the API the type of data being transferred. The predefined protocols are shown in Table 5-6.
Table 5-6 Predefined Protocols
Protocol |
Description |
---|---|
DtDND_TEXT_TRANSFER |
Text transfer. Compound text. (Motif uses a compound text target for text transfers.) |
DtDND_FILENAME_TRANSFER |
File name transfer. |
DtDND_BUFFER_TRANSFER |
Memory buffer. |
The drag source and the drop zone can transfer the data in one of three ways, as described in Table 5-7.
Table 5-7 Data Transfer Operations
Operation |
Description |
---|---|
XmDROP_MOVE |
Moves the data (Copy followed by Delete). |
XmDROP_COPY |
Copies the data. |
XmDROP_LINK |
Contains a link to the data. |