18.3. Functions

18.3.1. Setting up the source widget

The function gtk_drag_source_set() specifies a set of target types for a drag operation on a widget.

void gtk_drag_source_set( GtkWidget            *widget,
                          GdkModifierType       start_button_mask,
                          const GtkTargetEntry *targets,
                          gint                  n_targets,
                          GdkDragAction         actions );

The parameters signify the following:

The targets parameter is an array of the following structure:

struct GtkTargetEntry {
   gchar *target;
   guint  flags;
   guint  info;
 };

The fields specify a string representing the drag type, optional flags and application assigned integer identifier.

If a widget is no longer required to act as a source for drag-and-drop operations, the function gtk_drag_source_unset() can be used to remove a set of drag-and-drop target types.

void gtk_drag_source_unset( GtkWidget *widget );

18.3.2. Signals on the source widget:

The source widget is sent the following signals during a drag-and-drop operation.

Table 18-1. Source widget signals

drag_beginvoid (*drag_begin)(GtkWidget *widget, GdkDragContext *dc, gpointer data)
drag_motiongboolean (*drag_motion)(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data)
drag_data_getvoid (*drag_data_get)(GtkWidget *widget, GdkDragContext *dc, GtkSelectionData *selection_data, guint info, guint t, gpointer data)
drag_data_deletevoid (*drag_data_delete)(GtkWidget *widget, GdkDragContext *dc, gpointer data)
drag_dropgboolean (*drag_drop)(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data)
drag_endvoid (*drag_end)(GtkWidget *widget, GdkDragContext *dc, gpointer data)

18.3.3. Setting up a destination widget:

gtk_drag_dest_set() specifies that this widget can receive drops and specifies what types of drops it can receive.

gtk_drag_dest_unset() specifies that the widget can no longer receive drops.

void gtk_drag_dest_set( GtkWidget            *widget,
                        GtkDestDefaults       flags,
                        const GtkTargetEntry *targets,
                        gint                  n_targets,
                        GdkDragAction         actions );

void gtk_drag_dest_unset( GtkWidget *widget );

18.3.4. Signals on the destination widget:

The destination widget is sent the following signals during a drag-and-drop operation.

Table 18-2. Destination widget signals

drag_data_receivedvoid (*drag_data_received)(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, gpointer data)