drag_motion


Description:

public virtual signal bool drag_motion (DragContext context, int x, int y, uint time_)

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 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 drag_get_data and defer the drag_status call to the drag_data_received handler. Note that you must pass DROP, MOTION or ALL to 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 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
}
}

Parameters:

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