else {
newTargets = (Atom *) XtMalloc
(sizeof (Atom) * (numExportTargets + 2));
for (m = 0; m < numExportTargets; m++)
newTargets[m] = exportTargets[m];
newTargets[m] = FILE_CONTENTS;
newTargets[m+1] = FILE_NAME;
XtSetArg (args[n], XmNexportTargets, newTargets); n++;
XtSetArg (args[n], XmNnumExportTargets, numExportTargets + 2); n++;
}
/* modify other DragContext resources */
XtSetArg (args[n], XmNblendModel, XmBLEND_JUST_SOURCE); n++;
XtSetArg (args[n], XmNcursorBackground, bg); n++;
XtSetArg (args[n], XmNcursorForeground, fg); n++;
XtSetArg (args[n], XmNsourceCursorIcon, drag_icon); n++;
XtSetArg (args[n], XmNdragOperations, XmDROP_COPY); n++;
XtSetArg (args[n], XmNconvertProc, NewConvertProc); n++;
XtSetArg (args[n], XmNclientData, widget); n++;
XtSetValues (dc, args, n);
XtAddCallback (dc, XmNdragDropFinishCallback, DragDropFinish, NULL);
}
This routine performs many of the same tasks as the StartDrag() action routine, such as accessing the appropriate
structure in the files array and creating a DragIcon for the source icon. The main difference is that we use
XmGetDragContext() to retrieve the current DragContext object, rather than creating one using
XmStartDrag().
The routine retrieves the values of the XmN-exportTargets, XmN-numExportTargets, and
XmN-convertProc resources using XtGetValues() so that it can preserve the existing functionality. The
appropriate new targets are added to the list of targets based on the type of the file, and XmN-exportTargets is set
to the new list. The NewConvertProc() routine is used for the XmN-convertProc. The rest of the DragContext
resources are specified as in StartDrag(), and the DragContext is modified using XtSetValues().
There is only one difference between the NewConvertProc() routine and ConvertProc() in file_manager.c.
Instead of simply returning False if the requested target is not FILE_CONTENTS or FILE_NAME,
NewConvertProc() calls the conversion procedure retrieved from the Label widget, as shown in the following
fragment:
(*convert_proc) (widget, selection, target, type_return,
value_return, length_return, format_return);
Essentially, our conversion routine handles our data targets and passes other targets to the Label widget's default
conversion procedure.
19.4.5 Providing Custom Drag−over Visuals
The DragContext has a number of callback routines that the initiating application can use to provide custom drag−over
visuals. These callbacks are invoked when different events occur during the drag, like when the drag icon enters or
leaves a drop site. The DragContext provides the following callback routines for monitoring the drag:
XmNdragMotionCallback
XmNdropSiteEnterCallback
XmNdropSiteLeaveCallback
19 Drag and Drop19.4.5 Providing Custom Drag−over Visuals
542
XmNoperationChangedCallback
XmNtopLevelEnterCallback
XmNtopLevelLeaveCallback
The names of the routines are fairly self−explanatory. Each callback has its own special callback structure that
contains the relevant information about the current state of the drag operation. For example, the
XmN-dropSiteEnterCallback uses a callback structure of type XmDropSiteEnterCallbackStruct,
which is defined as follows:
typedef struct {
int reason;
XEvent *event;
Time timeStamp;
unsigned char operation;
unsigned char operations;
unsigned char dropSiteStatus;
Position x;
Position y;
} XmDropSiteEnterCallbackStruct, *XmDropSiteEnterCallback;
The reason field in this structure is always XmCR_DROP_SITE_ENTER. The operation and operations
fields specify the current operation and the set of supported operations, respectively. The dropSiteStatus
element indicates whether or not the current drop site is valid, based on the targets supported by the drag source and
the drop site. This field can have one of the following values:
XmDROP_SITE_VALID
XmDROP_SITE_INVALID
XmNO_DROP_SITE
The operation, operations, and dropSiteStatus fields are initialized by the toolkit based on the values of
different resources for both the drag source and the drop site. If the drop site has registered an XmN-dragProc and
the dynamic protocol is being used, this routine can update these fields as necessary before the data is passed to the
callback routine. A drop site might want to update these fields if it is performing any special processing or simulating
multiple drop sites.
All of the callback structures for the DragContext callback routines have a reason field that indicates why the
callback was invoked. The callback structures also provide information that is relevant to the particular routine; they
are all similar to the XmDropSiteEnterCallbackStruct. See the DragContext reference page in Volume Six
B, Motif Reference Manual, for complete information about the different callback structures.
When an application creates the DragContext for a drag, it can register routines for the different callback resources.
These routines can perform any special processing that is necessary, as well as handle custom drag−over effects for
the transfer. The typical way to handle drag−over effects is to modify the various drag icon resources of the
DragContext during the drag. The XmN-sourcePixmapIcon, XmN-sourceCursorIcon,
XmN-operationCursorIcon, and XmN-stateCursorIcon resources specify the different components of the
drag icon. The XmN-validCursorForeground, XmN-invalidCursorForeground, and
XmN-noneCursorForeground resources of the DragContext can be used to further distinguish between the
different states during a drag.
The XmN-sourcePixmapIcon is used under the preregister protocol and can be any size, while the
XmN-sourceCursorIcon is used for the dynamic protocol and is limited to the size of the largest cursor for a
particular platform. If you want to specify a color icon, you must use the XmN-sourcePixmapIcon resource. If
XmN-sourcePixmapIcon is not specified, the value of XmN-sourceCursorIcon is used. If this resource has
19 Drag and Drop19.4.5 Providing Custom Drag−over Visuals
543

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.