Functions

GTK+ 2.0 Tutorial
<<< Previous | Drag-and-drop (DND) | Next >>>

# Functions

## 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:

- `widget` specifies the drag source widget

- `start_button_mask` specifies a bitmask of buttons that can start the drag (e.g. GDK_BUTTON1_MASK)

- `targets` specifies a table of target data types the drag will support

- `n_targets` specifies the number of targets above

- `actions` specifies a bitmask of possible actions for a drag from this window

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 );

## Signals on the source widget:

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

Table 1. Source widget signals

drag_begin | `void (*drag_begin)(GtkWidget *widget, GdkDragContext *dc, gpointer data)`
drag_motion | `gboolean (*drag_motion)(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data)`
drag_data_get | `void (*drag_data_get)(GtkWidget *widget, GdkDragContext *dc, GtkSelectionData *selection_data, guint info, guint t, gpointer data)`
drag_data_delete | `void (*drag_data_delete)(GtkWidget *widget, GdkDragContext *dc, gpointer data)`
drag_drop | `gboolean (*drag_drop)(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data)`
drag_end | `void (*drag_end)(GtkWidget *widget, GdkDragContext *dc, gpointer data)`

## 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 );

## Signals on the destination widget:

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

Table 2. Destination widget signals

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

<<< Previous | Home | Next >>>
Properties | Up | GLib