Copyright © 1999 by Red Hat, Inc.
| Abstract GTK+ provides a drag-and-drop implementation that allows for sophisticated negotiation of the drag operation (move, copy, link, or ask), and the format of the data that is transferred while providing interactive feedback to the user. It supports the Xdnd and Motif protocols, allowing interoperability with most common applications. By writing to the GTK+'s interfaces for drag-and-drop, the application developer transparently gains support for both protocols. Drag-and-drop is used throughout GNOME to provide tight integration between applications and the desktop. |
Figure 1. Moving text with drag-and-drop. Icon changes during drag to indicate whether a drop can occur is valid. (drag over animation) Cursor is displayed in target to indicate where text will be inserted. (drag under animation).

Drag-and-drop is a user interface idiom commonly used in most modern user interfaces. The user clicks on a user interface object, drags the mouse elsewhere and releases the mouse. Usually, this is used to trigger moving or copying information from one location to another. The operation that is performed is known as the action. Along with move and copy, another fairly frequent action is that of linking. In linking, a hot link is established, where the data at the target location is dynamically updated to reflect future changes to data at the source location. The action is typically selected by holding down a modifier key during the drag; for instance, the Control key indicates the copy action.
While the user is dragging, several forms of feedback can be provided. An icon is displayed that represents the object being dragged. Additional symbols may be attached to the icon to show the action being performed and whether a drop can be be performed at the current location. Feedback done in this fashion is known as drag-over animation. In addition, the appearance of the drop target may be modified to indicate when the cursor is over a valid drop target. Animation where the destination widget is modified is known as drag-under animation.
The source and target need to cooperate to determine what the result of the drag will be so that appropriate feedback is shown to the user. This can be done in a limited fashion if all possible destination windows attach information to their windows that the source application can read to determine what drop types will be accepted. However this is cumbersome and prevents having the feedback depend on the data of the drag. For that reason, most implementations of drag-and-drop negotiate the drag status by exchanging messages between the source and target applications.