Arg args[10];
int n;
Widget label;
Atom importList[1];
void HandleDrop();
...
n = 0;
importList[0] = COMPOUND_TEXT;
XtSetArg (args[n], XmNimportTargets, importList); n++;
XtSetArg (args[n], XmNnumImportTargets, XtNumber (importList)); n++;
XtSetArg (args[n], XmNdropSiteOperations, XmDROP_COPY); n++;
XtSetArg (args[n], XmNdropProc, HandleDrop); n++;
XmDropSiteRegister (label, args, n);
When a drop occurs in the drop site, the XmN-dropProc is called automatically by the Motif toolkit. This routine
must call XmDropTransferStart() whether or not the drop is -successful. XmDropTransferStart()
creates a DropTransfer object that maintains information about the data transfer. When The DropTransfer object is
created, the XmN-transferStatus resource must be set to indicate the success or failure of the drop. If the
resource is set to XmTRANSFER_FAILURE, XmDropTransferStart() does not transfer any data and merely
cleans up after the drag and drop transfer.
If XmN-transferStatus is set to XmTRANSFER_SUCCESS when the DropTransfer object is created, some other
resources must also be specified to cause the data to be transferred. The XmN-dropTransfers and
XmN-numDropTransfers resources specify the data targets to be processed, while XmN-transferProc
indicates the procedure that receives the converted data from the drag source. This procedure is of type
XtSelectionCallbackProc. Once the data transfer has started, XmDropTransferAdd() can be used to
request the processing of additional data targets. In Section #sdropsite, we discuss in detail the tasks involved in
creating a drop site.
When a drop takes place, visual effects are used to indicate the status of the transfer. Unlike the different drag effects,
these visuals are not customizable. When the drop occurs, the pointer shape is changed back to the standard cursor,
while the drag icon sits over the drop site. If the drop succeeds, the icon melts into the drop site. If the transfer fails or
is cancelled by the user, the icon snaps back to the drag source.
A drop site is normally the size and shape of the widget with which it is associated. However, a drop site can also be
shaped. The XmN-dropRectangles and XmN-numDropRectangles resources control this feature. Drop sites
can also be nested, so that a manager widget can be a drop site and can also contain children that are drop sites. The
XmN-dropSiteType resource controls whether the drop site is a simple drop site or a compound drop site. Drop
sites have a stacking order, which means that they can overlap. When drop sites overlap, the drop site on the top of the
stack obscures the drop sites beneath it, as you would expect. An application can control the stacking order of drop
sites using XmDropSiteQueryStackingOrder() and XmDropSiteConfigureStackingOrder().
19.2.3 The Drag Icon
During a drag, the pointer shape is changed into a drag icon that represents the data that is being dragged. One of the
purposes of the special icon is to make it clear that a drag and drop transfer is in progress. The drag icon can also
change during a drag to indicate the current status of the transfer. These visual effects are called drag−over visuals.
Typical effects include changing the shape and changing the color of the icon.
A drag icon can be composed of three distinct parts, each of which is really a separate icon. The source icon
represents the type of data that is being dragged; this icon is the only necessary component of a drag icon. The source
icon for a drag that manipulates files might be an image of a piece of paper, for example. The state icon indicates
19 Drag and Drop 19.2.3 The Drag Icon
519
whether the pointer is over a valid drop site, over an invalid drop site, or not over a drop site. The operation icon
specifies the current operation. The source icon in a drag icon is static, while the state and operation icons can be
dynamic. the figure shows the components of a drag icon.
A drag icon
The Motif toolkit provides default icons for all of the different drag icon components. The default source icons for
textual data and for generic data are shown in the figure.
Default source icons
The default state icon for all of the different states is an arrow, as shown in the figure, while the default operation
icons for the move, copy, and link operations are shown in the figure.
Default operation icons
Motif uses DragIcon objects to represent the parts of a drag icon. In order to use a custom image, you need to create
each part of the icon using XmCreateDragIcon(). The XmN-blendModel resource of the DragContext for a
drag and drop transfer specifies the different pieces that are blended together to create the actual drag icon.
A drag icon is essentially a pixmap, and the DragIcon object encapsulates all of the information about the image.
When you create a DragIcon, you specify resources that describe the image. The XmN-pixmap and XmN-mask
resources represent the actual pixmap and its mask if you use one. Other resources include XmN-height,
19 Drag and Drop 19.2.3 The Drag Icon
520
Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.