19.4.2 Starting the Drag
When the user starts a drag, the DragStart() action routine is called. This routine creates a custom drag icon and
calls XmDragStart() to start the drag. To create the appropriate drag icon, we need to know whether the drag
source represents a file or a directory, so we fetch the XmN-userData from the Label widget that is the drag source.
We use this value to access the appropriate structure in the files array and determine the type of file the user is
manipulating.
Once we know what type of file we are dealing with, we can create the source icon for the drag. We use the same
pixmap as for the image Label, so the drag icon is either a file image or a folder image. We use
XmGetPixmapByDepth() to create both the icon and an iconmask so that we can specify a depth of 1. We call
XmCreateDragIcon() to create the drag icon, as shown in the following code fragment from the source code
n = 0;
XtSetArg (args[n], XmNpixmap, icon); n++;
XtSetArg (args[n], XmNmask, iconmask); n++;
drag_icon = XmCreateDragIcon (widget, "drag_icon", args, n);
The DragIcon is created as a child of the drag source widget. We only need to specify the XmN-pixmap and
XmN-mask resources because the DragIcon sets its other attributes, such as width and height, based on the pixmap.
The DragIcon takes its foreground and background colors from its parent, so we don't need to specify these resources
either. The XmN-mask resource must be set to a pixmap of depth 1, while the XmN-pixmap can be any depth.