Drag and drop allows the user to "pick up" objects on the screen, "drag" them around the display, and "drop" them at a new location, possibly in another application.
With drag and drop the user can
This section describes what the user does and sees during a drag and drop transaction.
A drag and drop transaction consists of the following actions:
Locations on the screen that can accept drops are drop sites, and the application owning that drop site is the destination or receiver.
The drag icon can be dropped anywhere on the screen. However, only certain widgets have registered themselves as drop sites and are able to process the drop.
The receiver application usually performs some action on the information represented by the dragged icon. The initiator application may also perform some action based on the results of a drag transaction.
A drop can be between applications or within the same application. An application can be both source and destination of a drop, source only, destination only, or not participate in drag and drop at all.
The user can request help about a drop site, if available, by dragging to the drop site and pressing osfHelp (usually F1).
The user can cancel the drag at any time by pressing osfCancel, usually Escape.
The drag icon consists of three parts:
In the following illustration, the running figure is the source icon, the arrow in the upper left is the state icon, and the rectangles with the corner folded over indicate a Copy is desired.
Figure 16. A Drag Icon.
These parts can be combined (blended) and attached to each other in different ways. The default blending and attachment are shown in the previous illustration.
Parts of the drag icon may change shape or color as it is being dragged through potential drop sites, providing visual feedback about possible drop sites to the user. These changes are drag-over effects.
Applications can use the default drag icon effects, or provide more sophisticated or custom drag icons. The application or user can customize these drag-over effects in resource files.
This chapter contains several illustrations of default Motif drag and drop icons. In reality, there are two different sets of default Motif icons. The XmNenableDragIcon resource of XmDisplay determines which set is used. If XmNenableDragIcon is False (the default), the traditional Motif drag and drop icons are used. If XmNenableDragIcon is True, alternate Motif drag and drop icons are used. We have used only the traditional Motif drag and drop icons for the illustrations in this chapter.
During a drag, there are three states that describe the relationship of a drag icon to what is under it at the time:
The drag icon is over a drop site on which it can potentially be dropped (this is only a hint; when the drop is actually attempted, further processing may show that the drop cannot actually be done).
The drag icon is over a drop site, but it cannot be dropped there.
The drag icon is not over a registered drop site.
The default state icon for all three states is the same: an arrow in the upper left corner of the drag icon. Because the icon is the same for all three states, it appears not to change during the drag. The application or the user can provide custom state icons or colors in a resource file.
The user specifies what action is to take place when the drop occurs by pressing certain keys when the drag starts or while the drag is in process:
The operation chosen by the user must be valid for both the drag source and the drop site, or the drop site will be considered invalid.
If the user does not specify an operation, one is chosen by the toolkit. It choses an operation that is valid for both the drag source and drop site. Move is the first choice, Copy is the second, and Link is the third. If the system cannot find a valid operation, the drop site is considered invalid.
The operation icon reflects the operation chosen by the user or by the system. If the operation is changed by the user during the drag, the operation icon changes also.
The operation icon may change as the drag icon moves to different drop sites if the drop sites accept different operations.
A widget registered as a drop site may change visually as a drag icon passes over it. These visual cues are drag-under effects. The sensitive area of the widget is the part that responds to drag and drop. By default it is the whole widget, but applications can specify that only parts of the widget respond to drag and drop.
In addition, a widget may support pause drag. This means that if a drag icon pauses over a specifed part of a widget, some action will occur, such as scrolling. See Section 18.104.22.168 for more information about this feature.
Various highlighting styles are possible:
Applications can use the default drag-under visual effects, or create more sophisticated or custom effects, such as special animation or sound effects.
Visual effects also take place during the drop:
These drop effects cannot be changed by the application or the user. However, if the receiver wants to cancel these effects completely, the receiver should ask the source to convert the special _MOTIF_CANCEL_DROP_EFFECT target. For example, the receiver can make a call like the following to cancel the effects:
XmTransferValue(cs->transfer_id, XInternAtom(XtDisplay(wid), XmS_MOTIF_CANCEL_DROP_EFFECT, False), NULL, NULL, XtLastTimeStampProcessed(XtDisplay(wid)));
The Motif toolkit will intercept this request and fulfill it by cancelling all visual effects. The drag source should not provide any code to handle this target.
The application or widget should supply a DialogBox containing information about a drop site if the user has requested help and the receiver client provides help.