Drag-and-Drop in GTK+ and GNOME


< Prev Contents Next >

Drag-and-Drop in GTK+

Figure 2. Architecture of drag-and-drop in GTK+

The GTK+ toolkit [1] internally supports both Xdnd and Motif drag-and-drop. On top of the protocol implementations, GTK+ provides a comprehensive set of interfaces for the application developer who wants to use drag-and-drop. By writing to these interfaces, the developer tranparently gains support for both protocols, along with any protocols which are added to GTK+ in the future.

The basic principle of GTK+ drag-and-drop is that there is an extremely flexible interface underneath that allows applications fine-grained control over the details of drag-and-drop, and then, on top of this, there are a set of default behaviors that the application can request. By requesting the default behaviors, the amount of work that the application needs to do is greatly reduced. This gives the developer the best of both worlds - it is very easy to get simple instances of drag and drop going, but the application can also customize the behavior when more sophisticated actions are needed.

Figure 3. Default and custom drag-under highlighting

As an example of this, consider the drag-under animation mentioned above. If the application requests the GTK_DRAG_DEFAULT_HIGHLIGHT behavior for a widget, then when the user is dragging over that widget and it is a valid drop target, GTK+ will automatically draw a highlight border around the widget to indicate that the drop will be received by that widget. However, if this default behavior is not requested by the application, then it can directly handle the signals when the drag enters and leaves the widget and display a custom form of highlighting. For instance, a trashcan drop target might open when the drag enters the widget. (See Figure 3)

Notes
[1] GTK+


< Prev Contents Next >