Gtk.Widget::drag-motion
function callback(widget, context:Gdk.DragContext, x:Number, y:Number, time:Number, ):Boolean;
The ::drag-motion signal is emitted on the drop site when the user moves the cursor over the widget during a drag. The signal handler must determine whether the cursor position is in a drop zone or not. If it is not in a drop zone, it returns false and no further processing is necessary. Otherwise, the handler returns true. In this case, the handler is responsible for providing the necessary information for displaying feedback to the user, by calling Gdk.drag_status.
If the decision whether the drop will be accepted or rejected can't be made based solely on the cursor position and the type of the data, the handler may inspect the dragged data by calling Gtk.Widget.prototype.drag_get_data and defer the Gdk.drag_status call to the Gtk.Widget::drag-data-received handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP, #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to Gtk.Widget.prototype.drag_dest_set when using the drag-motion signal that way.
Also note that there is no drag-enter signal. The drag receiver has to keep track of whether he has received any drag-motion signals since the last Gtk.Widget::drag-leave and if not, treat the drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight the drop site with Gtk.Widget.prototype.drag_highlight. |[ static void drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GdkAtom target;
PrivateData *private_data = GET_PRIVATE_DATA (widget);
if (!private_data->drag_highlight) { private_data->drag_highlight = 1; gtk_drag_highlight (widget); }
target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) gdk_drag_status (context, 0, time); else { private_data->pending_status = gdk_drag_context_get_suggested_action (context); gtk_drag_get_data (widget, context, target, time); }
return TRUE; }
static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { PrivateData *private_data = GET_PRIVATE_DATA (widget);
if (private_data->suggested_action) { private_data->suggested_action = 0;
/* We are getting this data due to a request in drag_motion, * rather than due to a request in drag_drop, so we are just * supposed to call Gdk.drag_status, not actually paste in * the data. */ str = gtk_selection_data_get_text (selection_data); if (!data_is_acceptable (str)) gdk_drag_status (context, 0, time); else gdk_drag_status (context, private_data->suggested_action, time); } else { /* accept the drop */ } } ]|
- widget
instance of Gtk.Widget that is emitting the signal
- context
the drag context
- x
the x coordinate of the current cursor position
- y
the y coordinate of the current cursor position
- time
the timestamp of the motion event
- Returns
whether the cursor position is in a drop zone