18.1. Overview

An application capable of GTK+ drag-and-drop first defines and sets up the GTK+ widget(s) for drag-and-drop. Each widget can be a source and/or destination for drag-and-drop. Note that these GTK+ widgets must have an associated X Window.

Source widgets can send out drag data, thus allowing the user to drag things off them, while destination widgets can receive drag data. Drag-and-drop destinations can limit who they accept data from, e.g. the same application or any application (including itself).

Sending and receiving drop data makes use of GTK+ signals. Dropping an item to a destination widget requires both a data request (for the source widget) and data received signal handler (for the target widget). Additional signal handlers can be connected if you want to know when a drag begins (at the very instant it starts), to when a drop is made, and when the entire drag-and-drop procedure has ended (successfully or not).

Your application will need to provide data for source widgets when requested, that involves having a drag data request signal handler. For destination widgets they will need a drop data received signal handler.

So a typical drag-and-drop cycle would look as follows:

  1. Drag begins.
  2. Drag data request (when a drop occurs).
  3. Drop data received (may be on same or different application.)
  4. Drag data delete (if drag was a move).
  5. Drag-and-Drop procedure done.

There are a few minor steps that go in between here and there, but we will get into detail about that later.


Prev Next