Method
GtkWidgetdrag_dest_set
Declaration [src]
void
gtk_drag_dest_set (
GtkWidget* widget,
GtkDestDefaults flags,
const GtkTargetEntry* targets,
gint n_targets,
GdkDragAction actions
)
Description [src]
Sets a widget as a potential drop destination, and adds default behaviors.
The default behaviors listed in flags have an effect similar
to installing default handlers for the widget’s drag-and-drop signals
(GtkWidget::drag-motion, GtkWidget::drag-drop, …). They all exist
for convenience. When passing #GTK_DEST_DEFAULT_ALL for instance it is
sufficient to connect to the widget’s GtkWidget::drag-data-received
signal to get primitive, but consistent drag-and-drop support.
Things become more complicated when you try to preview the dragged data,
as described in the documentation for GtkWidget::drag-motion. The default
behaviors described by flags make some assumptions, that can conflict
with your own signal handlers. For instance #GTK_DEST_DEFAULT_DROP causes
invokations of gdk_drag_status() in the context of GtkWidget::drag-motion,
and invokations of gtk_drag_finish() in GtkWidget::drag-data-received.
Especially the later is dramatic, when your own GtkWidget::drag-motion
handler calls gtk_drag_get_data() to inspect the dragged data.
There’s no way to set a default action here, you can use the
GtkWidget::drag-motion callback for that. Here’s an example which selects
the action to use depending on whether the control key is pressed or not:
static void
drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GdkModifierType mask;
gdk_window_get_pointer (gtk_widget_get_window (widget),
NULL, NULL, &mask);
if (mask & GDK_CONTROL_MASK)
gdk_drag_status (context, GDK_ACTION_COPY, time);
else
gdk_drag_status (context, GDK_ACTION_MOVE, time);
}
Parameters
flags-
Type:
GtkDestDefaultsWhich types of default drag behavior to use.
targets-
Type: An array of
GtkTargetEntryA pointer to an array of
GtkTargetEntrysindicating the drop types that thiswidgetwill accept, orNULL. Later you can access the list withgtk_drag_dest_get_target_list()and gtk_drag_dest_find_target().The argument can be NULL.The length of the array is specified in the n_targetsargument.The data is owned by the caller of the method. n_targets-
Type:
gintThe number of entries in
targets. actions-
Type:
GdkDragActionA bitmask of possible actions for a drop onto this
widget.