Widget.addOnDragMotion

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_drag_get_data() and defer the gdk_drag_status() call to the drag-data-received handler. Note that you must pass GTK_DEST_DEFAULT_DROP, GTK_DEST_DEFAULT_MOTION or GTK_DEST_DEFAULT_ALL to gtk_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 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_drag_highlight().

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

Return Value

Type: gulong

whether the cursor position is in a drop zone