Widget.connectDragMotion

Connect to DragMotion signal.

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.global.dragStatus.

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.Widget.dragGetData and defer the gdk.global.dragStatus call to the #GtkWidget::drag-data-received handler. Note that you must pass #GTK_DEST_DEFAULT_DROP, #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk.widget.Widget.dragDestSet 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 #GtkWidget::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.Widget.dragHighlight.

1 static void
2 drag_motion (GtkWidget      *widget,
3              GdkDragContext *context,
4              gint            x,
5              gint            y,
6              guint           time)
7 {
8   GdkAtom target;
9 
10   PrivateData *private_data = GET_PRIVATE_DATA (widget);
11 
12   if (!private_data->drag_highlight)
13    {
14      private_data->drag_highlight = 1;
15      gtk_drag_highlight (widget);
16    }
17 
18   target = gtk_drag_dest_find_target (widget, context, NULL);
19   if (target == GDK_NONE)
20     gdk_drag_status (context, 0, time);
21   else
22    {
23      private_data->pending_status
24         = gdk_drag_context_get_suggested_action (context);
25      gtk_drag_get_data (widget, context, target, time);
26    }
27 
28   return TRUE;
29 }
30 
31 static void
32 drag_data_received (GtkWidget        *widget,
33                     GdkDragContext   *context,
34                     gint              x,
35                     gint              y,
36                     GtkSelectionData *selection_data,
37                     guint             info,
38                     guint             time)
39 {
40   PrivateData *private_data = GET_PRIVATE_DATA (widget);
41 
42   if (private_data->suggested_action)
43    {
44      private_data->suggested_action = 0;
45 
46      // We are getting this data due to a request in drag_motion,
47      // rather than due to a request in drag_drop, so we are just
48      // supposed to call gdk_drag_status(), not actually paste in
49      // the data.
50 
51      str = gtk_selection_data_get_text (selection_data);
52      if (!data_is_acceptable (str))
53        gdk_drag_status (context, 0, time);
54      else
55        gdk_drag_status (context,
56                         private_data->suggested_action,
57                         time);
58    }
59   else
60    {
61      // accept the drop
62    }
63 }
class Widget
gulong
connectDragMotion
(
T
)
(,
Flag!"After" after = No.After
)
if (
isCallable!T &&
is(ReturnType!T == bool)
&&
(
Parameters!T.length < 1 ||
(
ParameterStorageClassTuple!T[0] == ParameterStorageClass.none &&
is(Parameters!T[0] : gdk.drag_context.DragContext)
)
)
&&
(
Parameters!T.length < 2 ||
(
ParameterStorageClassTuple!T[1] == ParameterStorageClass.none &&
is(Parameters!T[1] == int)
)
)
&&
(
Parameters!T.length < 3 ||
(
ParameterStorageClassTuple!T[2] == ParameterStorageClass.none &&
is(Parameters!T[2] == int)
)
)
&&
(
Parameters!T.length < 4 ||
(
ParameterStorageClassTuple!T[3] == ParameterStorageClass.none &&
is(Parameters!T[3] == uint)
)
)
&&
(
Parameters!T.length < 5 ||
(
ParameterStorageClassTuple!T[4] == ParameterStorageClass.none &&
is(Parameters!T[4] : gtk.widget.Widget)
)
)
&&
Parameters!T.length < 6
)

Parameters

callback T

signal callback delegate or function to connect

bool callback(gdk.drag_context.DragContext context, int x, int y, uint time, gtk.widget.Widget widget)

context the drag context (optional)

x the x coordinate of the current cursor position (optional)

y the y coordinate of the current cursor position (optional)

time the timestamp of the motion event (optional)

widget the instance the signal is connected to (optional)

Returns whether the cursor position is in a drop zone

after Flag!"After"

Yes.After to execute callback after default handler, No.After to execute before (default)

Return Value

Type: gulong

Signal ID