dnd: Make drag-motion and drag-drop signals use GdkDrop

This commit is contained in:
Benjamin Otte 2018-05-17 04:51:18 +02:00
parent 6d7cb2b781
commit b00609c21c
19 changed files with 316 additions and 330 deletions

View File

@ -315,17 +315,15 @@ static void gtk_calendar_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data); GtkSelectionData *selection_data);
static gboolean gtk_calendar_drag_motion (GtkWidget *widget, static gboolean gtk_calendar_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_calendar_drag_leave (GtkWidget *widget, static void gtk_calendar_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static gboolean gtk_calendar_drag_drop (GtkWidget *widget, static gboolean gtk_calendar_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void calendar_start_spinning (GtkCalendar *calendar, static void calendar_start_spinning (GtkCalendar *calendar,
@ -2952,10 +2950,9 @@ gtk_calendar_drag_leave (GtkWidget *widget,
static gboolean static gboolean
gtk_calendar_drag_motion (GtkWidget *widget, gtk_calendar_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkCalendarPrivate *priv = GTK_CALENDAR (widget)->priv; GtkCalendarPrivate *priv = GTK_CALENDAR (widget)->priv;
GdkAtom target; GdkAtom target;
@ -2966,13 +2963,13 @@ gtk_calendar_drag_motion (GtkWidget *widget,
gtk_drag_highlight (widget); gtk_drag_highlight (widget);
} }
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
if (target == NULL || gdk_drag_context_get_suggested_action (context) == 0) if (target == NULL || gdk_drop_get_actions (drop) == 0)
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
else if (get_status_pending (GDK_DROP (context)) == 0) else if (get_status_pending (drop) == 0)
{ {
set_status_pending (GDK_DROP (context), gdk_drag_context_get_suggested_action (context)); set_status_pending (drop, gdk_drop_get_actions (drop));
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
} }
return TRUE; return TRUE;
@ -2980,19 +2977,16 @@ gtk_calendar_drag_motion (GtkWidget *widget,
static gboolean static gboolean
gtk_calendar_drag_drop (GtkWidget *widget, gtk_calendar_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GdkAtom target; GdkAtom target;
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
if (target != NULL) if (target != NULL)
{ {
gtk_drag_get_data (widget, context, gtk_drag_get_data (widget, drop, target);
target,
time);
return TRUE; return TRUE;
} }

View File

@ -154,10 +154,9 @@ static void set_icon_helper (GdkDragContext *context,
********************/ ********************/
typedef struct { typedef struct {
GdkDragContext *context; GdkDrop *drop;
GtkWidget *widget; GtkWidget *widget;
const char *mime_type; const char *mime_type;
guint time;
} GtkDragGetData; } GtkDragGetData;
static void static void
@ -185,7 +184,7 @@ gtk_drag_get_data_finish (GtkDragGetData *data,
size >= 0) size >= 0)
g_signal_emit_by_name (data->widget, g_signal_emit_by_name (data->widget,
"drag-data-received", "drag-data-received",
data->context, data->drop,
&sdata); &sdata);
} }
} }
@ -193,20 +192,30 @@ gtk_drag_get_data_finish (GtkDragGetData *data,
{ {
g_signal_emit_by_name (data->widget, g_signal_emit_by_name (data->widget,
"drag-data-received", "drag-data-received",
data->context, data->drop,
&sdata); &sdata);
} }
if (site && site->flags & GTK_DEST_DEFAULT_DROP) if (site && site->flags & GTK_DEST_DEFAULT_DROP)
{ {
GdkDragAction action = site->actions & gdk_drop_get_actions (data->drop);
gdk_drag_finish (data->context, if (size == 0)
size > 0, action = 0;
data->time);
if (!gdk_drag_action_is_unique (action))
{
if (action & GDK_ACTION_COPY)
action = GDK_ACTION_COPY;
else if (action & GDK_ACTION_MOVE)
action = GDK_ACTION_MOVE;
}
gdk_drop_finish (data->drop, action);
} }
g_object_unref (data->widget); g_object_unref (data->widget);
g_object_unref (data->context); g_object_unref (data->drop);
g_slice_free (GtkDragGetData, data); g_slice_free (GtkDragGetData, data);
} }
@ -263,7 +272,7 @@ gtk_drag_get_data_got_stream (GObject *source,
* gtk_drag_get_data: (method) * gtk_drag_get_data: (method)
* @widget: the widget that will receive the * @widget: the widget that will receive the
* #GtkWidget::drag-data-received signal * #GtkWidget::drag-data-received signal
* @context: the drag context * @drop: the #GdkDrop
* @target: the target (form of the data) to retrieve * @target: the target (form of the data) to retrieve
* @time_: a timestamp for retrieving the data. This will * @time_: a timestamp for retrieving the data. This will
* generally be the time received in a #GtkWidget::drag-motion * generally be the time received in a #GtkWidget::drag-motion
@ -279,23 +288,21 @@ gtk_drag_get_data_got_stream (GObject *source,
* drops. * drops.
*/ */
void void
gtk_drag_get_data (GtkWidget *widget, gtk_drag_get_data (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GdkAtom target, GdkAtom target)
guint32 time_)
{ {
GtkDragGetData *data; GtkDragGetData *data;
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context)); g_return_if_fail (GDK_IS_DROP (drop));
data = g_slice_new0 (GtkDragGetData); data = g_slice_new0 (GtkDragGetData);
data->widget = g_object_ref (widget); data->widget = g_object_ref (widget);
data->context = g_object_ref (context); data->drop = g_object_ref (drop);
data->mime_type = target; data->mime_type = target;
data->time = time_;
gdk_drop_read_async (GDK_DROP (context), gdk_drop_read_async (drop,
(const gchar *[2]) { target, NULL }, (const gchar *[2]) { target, NULL },
G_PRIORITY_DEFAULT, G_PRIORITY_DEFAULT,
NULL, NULL,
@ -682,7 +689,7 @@ gtk_drag_dest_motion (GtkWidget *widget,
} }
} }
if (action && gtk_drag_dest_find_target (widget, context, NULL)) if (action && gtk_drag_dest_find_target (widget, GDK_DROP (context), NULL))
{ {
if (!site->have_drag) if (!site->have_drag)
{ {
@ -702,7 +709,7 @@ gtk_drag_dest_motion (GtkWidget *widget,
} }
g_signal_emit_by_name (widget, "drag-motion", g_signal_emit_by_name (widget, "drag-motion",
context, x, y, time, &retval); context, x, y, &retval);
return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval; return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
} }
@ -726,7 +733,7 @@ gtk_drag_dest_drop (GtkWidget *widget,
if (site->flags & GTK_DEST_DEFAULT_DROP) if (site->flags & GTK_DEST_DEFAULT_DROP)
{ {
GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); GdkAtom target = gtk_drag_dest_find_target (widget, GDK_DROP (context), NULL);
if (target == NULL) if (target == NULL)
{ {
@ -734,11 +741,11 @@ gtk_drag_dest_drop (GtkWidget *widget,
return TRUE; return TRUE;
} }
else else
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, GDK_DROP (context), target);
} }
g_signal_emit_by_name (widget, "drag-drop", g_signal_emit_by_name (widget, "drag-drop",
context, x, y, time, &retval); context, x, y, &retval);
return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval; return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
} }

View File

@ -41,9 +41,8 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_drag_get_data (GtkWidget *widget, void gtk_drag_get_data (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GdkAtom target, GdkAtom target);
guint32 time_);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkWidget *gtk_drag_get_source_widget (GdkDragContext *context); GtkWidget *gtk_drag_get_source_widget (GdkDragContext *context);

View File

@ -380,11 +380,11 @@ gtk_drag_dest_get_track_motion (GtkWidget *widget)
/** /**
* gtk_drag_dest_find_target: (method) * gtk_drag_dest_find_target: (method)
* @widget: drag destination widget * @widget: drag destination widget
* @context: drag context * @drop: #GdkDrop
* @target_list: (allow-none): list of droppable targets, or %NULL to use * @target_list: (allow-none): list of droppable targets, or %NULL to use
* gtk_drag_dest_get_target_list (@widget). * gtk_drag_dest_get_target_list (@widget).
* *
* Looks for a match between the supported targets of @context and the * Looks for a match between the supported targets of @drop and the
* @dest_target_list, returning the first matching target, otherwise * @dest_target_list, returning the first matching target, otherwise
* returning %NULL. @dest_target_list should usually be the return * returning %NULL. @dest_target_list should usually be the return
* value from gtk_drag_dest_get_target_list(), but some widgets may * value from gtk_drag_dest_get_target_list(), but some widgets may
@ -397,11 +397,11 @@ gtk_drag_dest_get_track_motion (GtkWidget *widget)
*/ */
const char * const char *
gtk_drag_dest_find_target (GtkWidget *widget, gtk_drag_dest_find_target (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GdkContentFormats *target_list) GdkContentFormats *target_list)
{ {
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL); g_return_val_if_fail (GDK_IS_DROP (drop), NULL);
if (target_list == NULL) if (target_list == NULL)
target_list = gtk_drag_dest_get_target_list (widget); target_list = gtk_drag_dest_get_target_list (widget);
@ -410,6 +410,6 @@ gtk_drag_dest_find_target (GtkWidget *widget,
return NULL; return NULL;
return gdk_content_formats_match_mime_type (target_list, return gdk_content_formats_match_mime_type (target_list,
gdk_drag_context_get_formats (context)); gdk_drop_get_formats (drop));
} }

View File

@ -77,7 +77,7 @@ void gtk_drag_dest_unset (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
const char * gtk_drag_dest_find_target (GtkWidget *widget, const char * gtk_drag_dest_find_target (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GdkContentFormats *target_list); GdkContentFormats *target_list);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkContentFormats* gtk_drag_dest_get_target_list (GtkWidget *widget); GdkContentFormats* gtk_drag_dest_get_target_list (GtkWidget *widget);

View File

@ -437,15 +437,13 @@ static void gtk_entry_display_changed (GtkWidget *widget,
GdkDisplay *old_display); GdkDisplay *old_display);
static gboolean gtk_entry_drag_drop (GtkWidget *widget, static gboolean gtk_entry_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static gboolean gtk_entry_drag_motion (GtkWidget *widget, static gboolean gtk_entry_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_entry_drag_leave (GtkWidget *widget, static void gtk_entry_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static void gtk_entry_drag_data_received (GtkWidget *widget, static void gtk_entry_drag_data_received (GtkWidget *widget,
@ -8601,36 +8599,34 @@ gtk_entry_drag_leave (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_entry_drag_drop (GtkWidget *widget, gtk_entry_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkEntry *entry = GTK_ENTRY (widget); GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry); GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
GdkAtom target = NULL; GdkAtom target = NULL;
if (priv->editable) if (priv->editable)
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
if (target != NULL) if (target != NULL)
{ {
priv->drop_position = gtk_entry_find_position (entry, x + priv->scroll_offset); priv->drop_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
} }
else else
gdk_drag_finish (context, FALSE, time); gdk_drop_finish (drop, 0);
return TRUE; return TRUE;
} }
static gboolean static gboolean
gtk_entry_drag_motion (GtkWidget *widget, gtk_entry_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkEntry *entry = GTK_ENTRY (widget); GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry); GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
@ -8642,7 +8638,7 @@ gtk_entry_drag_motion (GtkWidget *widget,
new_position = gtk_entry_find_position (entry, x + priv->scroll_offset); new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
if (priv->editable && if (priv->editable &&
gtk_drag_dest_find_target (widget, context, NULL) != NULL) gtk_drag_dest_find_target (widget, drop, NULL) != NULL)
{ {
suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE; suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
@ -8666,7 +8662,7 @@ gtk_entry_drag_motion (GtkWidget *widget,
if (show_placeholder_text (entry)) if (show_placeholder_text (entry))
priv->dnd_position = -1; priv->dnd_position = -1;
gdk_drag_status (context, suggested_action, time); gdk_drop_status (drop, suggested_action);
if (suggested_action == 0) if (suggested_action == 0)
gtk_drag_unhighlight (widget); gtk_drag_unhighlight (widget);
else else

View File

@ -179,10 +179,9 @@ static void gtk_expander_size_allocate (GtkWidget *widget,
static gboolean gtk_expander_focus (GtkWidget *widget, static gboolean gtk_expander_focus (GtkWidget *widget,
GtkDirectionType direction); GtkDirectionType direction);
static gboolean gtk_expander_drag_motion (GtkWidget *widget, static gboolean gtk_expander_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_expander_drag_leave (GtkWidget *widget, static void gtk_expander_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
@ -526,11 +525,10 @@ expand_timeout (gpointer data)
} }
static gboolean static gboolean
gtk_expander_drag_motion (GtkWidget *widget, gtk_expander_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkExpander *expander = GTK_EXPANDER (widget); GtkExpander *expander = GTK_EXPANDER (widget);
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander); GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);

View File

@ -1981,10 +1981,9 @@ file_list_drag_data_received_cb (GtkWidget *widget,
/* Don't do anything with the drag_drop signal */ /* Don't do anything with the drag_drop signal */
static gboolean static gboolean
file_list_drag_drop_cb (GtkWidget *widget, file_list_drag_drop_cb (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time_,
GtkFileChooserWidget *impl) GtkFileChooserWidget *impl)
{ {
g_signal_stop_emission_by_name (widget, "drag-drop"); g_signal_stop_emission_by_name (widget, "drag-drop");
@ -2005,10 +2004,9 @@ file_list_drag_begin_cb (GtkWidget *widget,
dropping the dragged item onto a tree item */ dropping the dragged item onto a tree item */
static gboolean static gboolean
file_list_drag_motion_cb (GtkWidget *widget, file_list_drag_motion_cb (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time_,
GtkFileChooserWidget *impl) GtkFileChooserWidget *impl)
{ {
g_signal_stop_emission_by_name (widget, "drag-motion"); g_signal_stop_emission_by_name (widget, "drag-motion");

View File

@ -291,15 +291,13 @@ static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
static void gtk_icon_view_drag_leave (GtkWidget *widget, static void gtk_icon_view_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static gboolean gtk_icon_view_drag_motion (GtkWidget *widget, static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static gboolean gtk_icon_view_drag_drop (GtkWidget *widget, static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_icon_view_drag_data_received (GtkWidget *widget, static void gtk_icon_view_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data); GtkSelectionData *selection_data);
@ -5878,7 +5876,7 @@ drag_scroll_timeout (gpointer data)
static gboolean static gboolean
set_destination (GtkIconView *icon_view, set_destination (GtkIconView *icon_view,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
GdkDragAction *suggested_action, GdkDragAction *suggested_action,
@ -5911,7 +5909,7 @@ set_destination (GtkIconView *icon_view,
return FALSE; /* no longer a drop site */ return FALSE; /* no longer a drop site */
} }
*target = gtk_drag_dest_find_target (widget, context, *target = gtk_drag_dest_find_target (widget, drop,
gtk_drag_dest_get_target_list (widget)); gtk_drag_dest_get_target_list (widget));
if (*target == NULL) if (*target == NULL)
return FALSE; return FALSE;
@ -5963,19 +5961,7 @@ set_destination (GtkIconView *icon_view,
out: out:
if (can_drop) if (can_drop)
{ {
GtkWidget *source_widget; *suggested_action = GDK_ACTION_ALL;
*suggested_action = gdk_drag_context_get_suggested_action (context);
source_widget = gtk_drag_get_source_widget (context);
if (source_widget == widget)
{
/* Default to MOVE, unless the user has
* pressed ctrl or shift to affect available actions
*/
if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
*suggested_action = GDK_ACTION_MOVE;
}
gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget), gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
path, pos); path, pos);
@ -6232,11 +6218,10 @@ gtk_icon_view_drag_leave (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_icon_view_drag_motion (GtkWidget *widget, gtk_icon_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkTreePath *path = NULL; GtkTreePath *path = NULL;
GtkIconViewDropPosition pos; GtkIconViewDropPosition pos;
@ -6247,7 +6232,7 @@ gtk_icon_view_drag_motion (GtkWidget *widget,
icon_view = GTK_ICON_VIEW (widget); icon_view = GTK_ICON_VIEW (widget);
if (!set_destination (icon_view, context, x, y, &suggested_action, &target)) if (!set_destination (icon_view, drop, x, y, &suggested_action, &target))
return FALSE; return FALSE;
icon_view->priv->event_last_x = x; icon_view->priv->event_last_x = x;
@ -6261,7 +6246,7 @@ gtk_icon_view_drag_motion (GtkWidget *widget,
if (path == NULL && !empty) if (path == NULL && !empty)
{ {
/* Can't drop here. */ /* Can't drop here. */
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
} }
else else
{ {
@ -6276,13 +6261,13 @@ gtk_icon_view_drag_motion (GtkWidget *widget,
/* Request data so we can use the source row when /* Request data so we can use the source row when
* determining whether to accept the drop * determining whether to accept the drop
*/ */
set_status_pending (GDK_DROP (context), suggested_action); set_status_pending (drop, suggested_action);
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
} }
else else
{ {
set_status_pending (GDK_DROP (context), 0); set_status_pending (drop, 0);
gdk_drag_status (context, suggested_action, time); gdk_drop_status (drop, suggested_action);
} }
} }
@ -6293,11 +6278,10 @@ gtk_icon_view_drag_motion (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_icon_view_drag_drop (GtkWidget *widget, gtk_icon_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkIconView *icon_view; GtkIconView *icon_view;
GtkTreePath *path; GtkTreePath *path;
@ -6317,7 +6301,7 @@ gtk_icon_view_drag_drop (GtkWidget *widget,
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop")) if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
return FALSE; return FALSE;
if (!set_destination (icon_view, context, x, y, &suggested_action, &target)) if (!set_destination (icon_view, drop, x, y, &suggested_action, &target))
return FALSE; return FALSE;
path = get_logical_destination (icon_view, &drop_append_mode); path = get_logical_destination (icon_view, &drop_append_mode);
@ -6327,8 +6311,8 @@ gtk_icon_view_drag_drop (GtkWidget *widget,
/* in case a motion had requested drag data, change things so we /* in case a motion had requested drag data, change things so we
* treat drag data receives as a drop. * treat drag data receives as a drop.
*/ */
set_status_pending (GDK_DROP (context), 0); set_status_pending (drop, 0);
set_dest_row (GDK_DROP (context), model, path, set_dest_row (drop, model, path,
icon_view->priv->empty_view_drop, drop_append_mode); icon_view->priv->empty_view_drop, drop_append_mode);
} }
@ -6340,20 +6324,45 @@ gtk_icon_view_drag_drop (GtkWidget *widget,
if (target != NULL) if (target != NULL)
{ {
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
return TRUE; return TRUE;
} }
else else
return FALSE; return FALSE;
} }
static GdkDragAction
gtk_icon_view_get_action (GtkWidget *treeview,
GdkDrop *drop)
{
GdkDragContext *drag = gdk_drop_get_drag (drop);
GtkWidget *source_widget = gtk_drag_get_source_widget (drag);
GdkDragAction actions;
actions = gdk_drop_get_actions (drop);
if (source_widget == treeview &&
actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
return 0;
}
static void static void
gtk_icon_view_drag_data_received (GtkWidget *widget, gtk_icon_view_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data) GtkSelectionData *selection_data)
{ {
GtkTreePath *path; GtkTreePath *path;
gboolean accepted = FALSE;
GtkTreeModel *model; GtkTreeModel *model;
GtkIconView *icon_view; GtkIconView *icon_view;
GtkTreePath *dest_row; GtkTreePath *dest_row;
@ -6412,13 +6421,16 @@ gtk_icon_view_drag_data_received (GtkWidget *widget,
if (gtk_selection_data_get_length (selection_data) >= 0) if (gtk_selection_data_get_length (selection_data) >= 0)
{ {
if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model), suggested_action = gtk_icon_view_get_action (widget, drop);
dest_row,
selection_data)) if (suggested_action &&
accepted = TRUE; !gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
dest_row,
selection_data))
suggested_action = 0;
} }
gdk_drop_finish (drop, accepted ? suggested_action : 0); gdk_drop_finish (drop, suggested_action);
gtk_tree_path_free (dest_row); gtk_tree_path_free (dest_row);

View File

@ -29,7 +29,7 @@ BOOLEAN:ENUM,DOUBLE
BOOLEAN:ENUM,INT BOOLEAN:ENUM,INT
BOOLEAN:OBJECT BOOLEAN:OBJECT
BOOLEAN:OBJECT,UINT,FLAGS BOOLEAN:OBJECT,UINT,FLAGS
BOOLEAN:OBJECT,INT,INT,UINT BOOLEAN:OBJECT,INT,INT
BOOLEAN:OBJECT,STRING,STRING,BOXED BOOLEAN:OBJECT,STRING,STRING,BOXED
BOOLEAN:OBJECT,BOXED BOOLEAN:OBJECT,BOXED
BOOLEAN:OBJECT,OBJECT,BOXED BOOLEAN:OBJECT,OBJECT,BOXED

View File

@ -392,17 +392,15 @@ static gboolean gtk_notebook_drag_failed (GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
GtkDragResult result); GtkDragResult result);
static gboolean gtk_notebook_drag_motion (GtkWidget *widget, static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_notebook_drag_leave (GtkWidget *widget, static void gtk_notebook_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static gboolean gtk_notebook_drag_drop (GtkWidget *widget, static gboolean gtk_notebook_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_notebook_drag_data_get (GtkWidget *widget, static void gtk_notebook_drag_data_get (GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
GtkSelectionData *data, GtkSelectionData *data,
@ -3018,11 +3016,10 @@ gtk_notebook_switch_tab_timeout (gpointer data)
} }
static gboolean static gboolean
gtk_notebook_drag_motion (GtkWidget *widget, gtk_notebook_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPrivate *priv = notebook->priv; GtkNotebookPrivate *priv = notebook->priv;
@ -3037,14 +3034,14 @@ gtk_notebook_drag_motion (GtkWidget *widget,
{ {
priv->click_child = arrow; priv->click_child = arrow;
gtk_notebook_set_scroll_timer (notebook); gtk_notebook_set_scroll_timer (notebook);
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
retval = TRUE; retval = TRUE;
goto out; goto out;
} }
stop_scrolling (notebook); stop_scrolling (notebook);
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
tab_target = g_intern_static_string ("GTK_NOTEBOOK_TAB"); tab_target = g_intern_static_string ("GTK_NOTEBOOK_TAB");
if (target == tab_target) if (target == tab_target)
@ -3055,7 +3052,7 @@ gtk_notebook_drag_motion (GtkWidget *widget,
retval = TRUE; retval = TRUE;
source = GTK_NOTEBOOK (gtk_drag_get_source_widget (context)); source = GTK_NOTEBOOK (gtk_drag_get_source_widget (gdk_drop_get_drag (drop)));
g_assert (source->priv->cur_page != NULL); g_assert (source->priv->cur_page != NULL);
source_child = source->priv->cur_page->child; source_child = source->priv->cur_page->child;
@ -3066,14 +3063,14 @@ gtk_notebook_drag_motion (GtkWidget *widget,
!(widget == source_child || !(widget == source_child ||
gtk_widget_is_ancestor (widget, source_child))) gtk_widget_is_ancestor (widget, source_child)))
{ {
gdk_drag_status (context, GDK_ACTION_MOVE, time); gdk_drop_status (drop, GDK_ACTION_MOVE);
goto out; goto out;
} }
else else
{ {
/* it's a tab, but doesn't share /* it's a tab, but doesn't share
* ID with this notebook */ * ID with this notebook */
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
} }
} }
@ -3117,23 +3114,22 @@ gtk_notebook_drag_leave (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_notebook_drag_drop (GtkWidget *widget, gtk_notebook_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GdkAtom target, tab_target; GdkAtom target, tab_target;
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
tab_target = g_intern_static_string ("GTK_NOTEBOOK_TAB"); tab_target = g_intern_static_string ("GTK_NOTEBOOK_TAB");
if (target == tab_target) if (target == tab_target)
{ {
notebook->priv->mouse_x = x; notebook->priv->mouse_x = x;
notebook->priv->mouse_y = y; notebook->priv->mouse_y = y;
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
return TRUE; return TRUE;
} }

View File

@ -1620,20 +1620,19 @@ update_possible_drop_targets (GtkPlacesSidebar *sidebar,
static gboolean static gboolean
get_drag_data (GtkWidget *list_box, get_drag_data (GtkWidget *list_box,
GdkDragContext *context, GdkDrop *drop,
GtkListBoxRow *row, GtkListBoxRow *row)
guint time)
{ {
GdkAtom target; GdkAtom target;
target = gtk_drag_dest_find_target (list_box, context, NULL); target = gtk_drag_dest_find_target (list_box, drop, NULL);
if (target == NULL) if (target == NULL)
return FALSE; return FALSE;
if (row) if (row)
g_object_set_data_full (G_OBJECT (context), "places-sidebar-row", g_object_ref (row), g_object_unref); g_object_set_data_full (G_OBJECT (drop), "places-sidebar-row", g_object_ref (row), g_object_unref);
gtk_drag_get_data (list_box, context, target, time); gtk_drag_get_data (list_box, drop, target);
return TRUE; return TRUE;
} }
@ -1766,14 +1765,12 @@ create_placeholder_row (GtkPlacesSidebar *sidebar)
} }
static gboolean static gboolean
drag_motion_callback (GtkWidget *widget, drag_motion_callback (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time, gpointer user_data)
gpointer user_data)
{ {
GdkDrop *drop = GDK_DROP (context);
gint action; gint action;
GtkListBoxRow *row; GtkListBoxRow *row;
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data); GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
@ -1790,7 +1787,7 @@ drag_motion_callback (GtkWidget *widget,
/* Nothing to do if no drag data */ /* Nothing to do if no drag data */
if (!sidebar->drag_data_received && if (!sidebar->drag_data_received &&
!get_drag_data (sidebar->list_box, context, row, time)) !get_drag_data (sidebar->list_box, drop, row))
goto out; goto out;
/* Nothing to do if the target is not valid drop destination */ /* Nothing to do if the target is not valid drop destination */
@ -1896,7 +1893,7 @@ drag_motion_callback (GtkWidget *widget,
g_signal_stop_emission_by_name (sidebar->list_box, "drag-motion"); g_signal_stop_emission_by_name (sidebar->list_box, "drag-motion");
gdk_drag_status (context, action, time); gdk_drop_status (drop, action);
return TRUE; return TRUE;
} }
@ -2144,12 +2141,11 @@ drag_leave_callback (GtkWidget *widget,
} }
static gboolean static gboolean
drag_drop_callback (GtkWidget *list_box, drag_drop_callback (GtkWidget *list_box,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time, gpointer user_data)
gpointer user_data)
{ {
gboolean retval = FALSE; gboolean retval = FALSE;
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data); GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
@ -2157,7 +2153,7 @@ drag_drop_callback (GtkWidget *list_box,
row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y); row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y);
sidebar->drop_occurred = TRUE; sidebar->drop_occurred = TRUE;
retval = get_drag_data (sidebar->list_box, context, row, time); retval = get_drag_data (sidebar->list_box, drop, row);
g_signal_stop_emission_by_name (sidebar->list_box, "drag-drop"); g_signal_stop_emission_by_name (sidebar->list_box, "drag-drop");
return retval; return retval;

View File

@ -291,11 +291,10 @@ gtk_stack_switcher_switch_timeout (gpointer data)
} }
static gboolean static gboolean
gtk_stack_switcher_drag_motion (GtkWidget *widget, gtk_stack_switcher_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget); GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget);
GtkStackSwitcherPrivate *priv; GtkStackSwitcherPrivate *priv;

View File

@ -431,15 +431,13 @@ static void gtk_text_view_drag_data_delete (GtkWidget *widget,
static void gtk_text_view_drag_leave (GtkWidget *widget, static void gtk_text_view_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static gboolean gtk_text_view_drag_motion (GtkWidget *widget, static gboolean gtk_text_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static gboolean gtk_text_view_drag_drop (GtkWidget *widget, static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_text_view_drag_data_received (GtkWidget *widget, static void gtk_text_view_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data); GtkSelectionData *selection_data);
@ -7718,11 +7716,10 @@ gtk_text_view_drag_leave (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_text_view_drag_motion (GtkWidget *widget, gtk_text_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkTextIter newplace; GtkTextIter newplace;
GtkTextView *text_view; GtkTextView *text_view;
@ -7754,7 +7751,7 @@ gtk_text_view_drag_motion (GtkWidget *widget,
&newplace, &newplace,
bx, by); bx, by);
target = gtk_drag_dest_find_target (widget, context, target = gtk_drag_dest_find_target (widget, drop,
gtk_drag_dest_get_target_list (widget)); gtk_drag_dest_get_target_list (widget));
if (target == NULL) if (target == NULL)
@ -7776,11 +7773,11 @@ gtk_text_view_drag_motion (GtkWidget *widget,
if (can_accept) if (can_accept)
{ {
gtk_text_mark_set_visible (priv->dnd_mark, cursor_visible (text_view)); gtk_text_mark_set_visible (priv->dnd_mark, cursor_visible (text_view));
gdk_drag_status (context, GDK_ACTION_COPY | GDK_ACTION_MOVE, time); gdk_drop_status (drop, GDK_ACTION_COPY | GDK_ACTION_MOVE);
} }
else else
{ {
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
gtk_text_mark_set_visible (priv->dnd_mark, FALSE); gtk_text_mark_set_visible (priv->dnd_mark, FALSE);
} }
@ -7805,11 +7802,10 @@ gtk_text_view_drag_motion (GtkWidget *widget,
} }
static gboolean static gboolean
gtk_text_view_drag_drop (GtkWidget *widget, gtk_text_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkTextView *text_view; GtkTextView *text_view;
GtkTextViewPrivate *priv; GtkTextViewPrivate *priv;
@ -7831,12 +7827,12 @@ gtk_text_view_drag_drop (GtkWidget *widget,
priv->dnd_mark); priv->dnd_mark);
if (gtk_text_iter_can_insert (&drop_point, priv->editable)) if (gtk_text_iter_can_insert (&drop_point, priv->editable))
target = gtk_drag_dest_find_target (widget, context, NULL); target = gtk_drag_dest_find_target (widget, drop, NULL);
if (target != NULL) if (target != NULL)
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
else else
gdk_drag_finish (context, FALSE, time); gdk_drop_finish (drop, 0);
return TRUE; return TRUE;
} }

View File

@ -632,15 +632,13 @@ static void gtk_tree_view_drag_data_delete (GtkWidget *widget,
static void gtk_tree_view_drag_leave (GtkWidget *widget, static void gtk_tree_view_drag_leave (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
static gboolean gtk_tree_view_drag_motion (GtkWidget *widget, static gboolean gtk_tree_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static gboolean gtk_tree_view_drag_drop (GtkWidget *widget, static gboolean gtk_tree_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time);
static void gtk_tree_view_drag_data_received (GtkWidget *widget, static void gtk_tree_view_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data); GtkSelectionData *selection_data);
@ -7130,7 +7128,7 @@ scroll_row_timeout (gpointer data)
/* Returns TRUE if event should not be propagated to parent widgets */ /* Returns TRUE if event should not be propagated to parent widgets */
static gboolean static gboolean
set_destination_row (GtkTreeView *tree_view, set_destination_row (GtkTreeView *tree_view,
GdkDragContext *context, GdkDrop *drop,
/* coordinates relative to the widget */ /* coordinates relative to the widget */
gint x, gint x,
gint y, gint y,
@ -7168,7 +7166,7 @@ set_destination_row (GtkTreeView *tree_view,
return FALSE; /* no longer a drop site */ return FALSE; /* no longer a drop site */
} }
*target = gtk_drag_dest_find_target (widget, context, *target = gtk_drag_dest_find_target (widget, drop,
gtk_drag_dest_get_target_list (widget)); gtk_drag_dest_get_target_list (widget));
if (*target == NULL) if (*target == NULL)
{ {
@ -7540,12 +7538,10 @@ gtk_tree_view_drag_leave (GtkWidget *widget,
static gboolean static gboolean
gtk_tree_view_drag_motion (GtkWidget *widget, gtk_tree_view_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
/* coordinates relative to the widget */ gint x,
gint x, gint y)
gint y,
guint time)
{ {
gboolean empty; gboolean empty;
GtkTreePath *path = NULL; GtkTreePath *path = NULL;
@ -7556,7 +7552,7 @@ gtk_tree_view_drag_motion (GtkWidget *widget,
tree_view = GTK_TREE_VIEW (widget); tree_view = GTK_TREE_VIEW (widget);
if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target)) if (!set_destination_row (tree_view, drop, x, y, &suggested_action, &target))
return FALSE; return FALSE;
tree_view->priv->event_last_x = x; tree_view->priv->event_last_x = x;
@ -7570,7 +7566,7 @@ gtk_tree_view_drag_motion (GtkWidget *widget,
if (path == NULL && !empty) if (path == NULL && !empty)
{ {
/* Can't drop here. */ /* Can't drop here. */
gdk_drag_status (context, 0, time); gdk_drop_status (drop, 0);
} }
else else
{ {
@ -7592,13 +7588,13 @@ gtk_tree_view_drag_motion (GtkWidget *widget,
/* Request data so we can use the source row when /* Request data so we can use the source row when
* determining whether to accept the drop * determining whether to accept the drop
*/ */
set_status_pending (GDK_DROP (context), suggested_action); set_status_pending (drop, suggested_action);
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
} }
else else
{ {
set_status_pending (GDK_DROP (context), 0); set_status_pending (drop, 0);
gdk_drag_status (context, suggested_action, time); gdk_drop_status (drop, suggested_action);
} }
} }
@ -7610,12 +7606,10 @@ gtk_tree_view_drag_motion (GtkWidget *widget,
static gboolean static gboolean
gtk_tree_view_drag_drop (GtkWidget *widget, gtk_tree_view_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
/* coordinates relative to the widget */ gint x,
gint x, gint y)
gint y,
guint time)
{ {
GtkTreeView *tree_view; GtkTreeView *tree_view;
GtkTreePath *path; GtkTreePath *path;
@ -7641,7 +7635,7 @@ gtk_tree_view_drag_drop (GtkWidget *widget,
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop")) if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
return FALSE; return FALSE;
if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target)) if (!set_destination_row (tree_view, drop, x, y, &suggested_action, &target))
return FALSE; return FALSE;
path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode); path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
@ -7651,8 +7645,8 @@ gtk_tree_view_drag_drop (GtkWidget *widget,
/* in case a motion had requested drag data, change things so we /* in case a motion had requested drag data, change things so we
* treat drag data receives as a drop. * treat drag data receives as a drop.
*/ */
set_status_pending (GDK_DROP (context), 0); set_status_pending (drop, 0);
set_dest_row (GDK_DROP (context), model, path, set_dest_row (drop, model, path,
path_down_mode, tree_view->priv->empty_view_drop, path_down_mode, tree_view->priv->empty_view_drop,
drop_append_mode); drop_append_mode);
} }
@ -7667,7 +7661,7 @@ gtk_tree_view_drag_drop (GtkWidget *widget,
if (target != NULL) if (target != NULL)
{ {
gtk_drag_get_data (widget, context, target, time); gtk_drag_get_data (widget, drop, target);
return TRUE; return TRUE;
} }
else else

View File

@ -1830,10 +1830,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
/** /**
* GtkWidget::drag-motion: * GtkWidget::drag-motion:
* @widget: the object which received the signal * @widget: the object which received the signal
* @context: the drag context * @drop: the #GdkDrop
* @x: the x coordinate of the current cursor position * @x: the x coordinate of the current cursor position
* @y: the y coordinate of the current cursor position * @y: the y coordinate of the current cursor position
* @time: the timestamp of the motion event
* *
* The ::drag-motion signal is emitted on the drop site when the user * 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 * moves the cursor over the widget during a drag. The signal handler
@ -1858,11 +1857,10 @@ gtk_widget_class_init (GtkWidgetClass *klass)
* the drop site with gtk_drag_highlight(). * the drop site with gtk_drag_highlight().
* |[<!-- language="C" --> * |[<!-- language="C" -->
* static void * static void
* drag_motion (GtkWidget *widget, * drag_motion (GtkWidget *widget,
* GdkDragContext *context, * GdkDrop *drop,
* gint x, * gint x,
* gint y, * gint y,
* guint time)
* { * {
* GdkAtom target; * GdkAtom target;
* *
@ -1874,14 +1872,14 @@ gtk_widget_class_init (GtkWidgetClass *klass)
* gtk_drag_highlight (widget); * gtk_drag_highlight (widget);
* } * }
* *
* target = gtk_drag_dest_find_target (widget, context, NULL); * target = gtk_drag_dest_find_target (widget, drop, NULL);
* if (target == NULL) * if (target == NULL)
* gdk_drag_status (context, 0, time); * gdk_drop_status (drop, 0);
* else * else
* { * {
* private_data->pending_status * private_data->pending_status
* = gdk_drag_context_get_suggested_action (context); * = gdk_drop_get_actions (drop);
* gtk_drag_get_data (widget, context, target, time); * gtk_drag_get_data (widget, drop, target);
* } * }
* *
* return TRUE; * return TRUE;
@ -1889,12 +1887,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
* *
* static void * static void
* drag_data_received (GtkWidget *widget, * drag_data_received (GtkWidget *widget,
* GdkDragContext *context, * GdkDrop *drop,
* gint x, * GtkSelectionData *selection_data)
* gint y,
* GtkSelectionData *selection_data,
* guint info,
* guint time)
* { * {
* PrivateData *private_data = GET_PRIVATE_DATA (widget); * PrivateData *private_data = GET_PRIVATE_DATA (widget);
* *
@ -1909,11 +1903,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
* *
* str = gtk_selection_data_get_text (selection_data); * str = gtk_selection_data_get_text (selection_data);
* if (!data_is_acceptable (str)) * if (!data_is_acceptable (str))
* gdk_drag_status (context, 0, time); * gdk_drop_status (drop, 0);
* else * else
* gdk_drag_status (context, * gdk_drag_status (drop, GDK_ACTION_ALL);
* private_data->suggested_action,
* time);
* } * }
* else * else
* { * {
@ -1930,20 +1922,18 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_motion), G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
_gtk_boolean_handled_accumulator, NULL, _gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT, _gtk_marshal_BOOLEAN__OBJECT_INT_INT,
G_TYPE_BOOLEAN, 4, G_TYPE_BOOLEAN, 3,
GDK_TYPE_DRAG_CONTEXT, GDK_TYPE_DROP,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
G_TYPE_UINT);
/** /**
* GtkWidget::drag-drop: * GtkWidget::drag-drop:
* @widget: the object which received the signal * @widget: the object which received the signal
* @context: the drag context * @drop: the #GdkDrop
* @x: the x coordinate of the current cursor position * @x: the x coordinate of the current cursor position
* @y: the y coordinate of the current cursor position * @y: the y coordinate of the current cursor position
* @time: the timestamp of the motion event
* *
* The ::drag-drop signal is emitted on the drop site when the user drops * The ::drag-drop signal is emitted on the drop site when the user drops
* the data onto the widget. The signal handler must determine whether * the data onto the widget. The signal handler must determine whether
@ -1964,12 +1954,11 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_drop), G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
_gtk_boolean_handled_accumulator, NULL, _gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT, _gtk_marshal_BOOLEAN__OBJECT_INT_INT,
G_TYPE_BOOLEAN, 4, G_TYPE_BOOLEAN, 3,
GDK_TYPE_DRAG_CONTEXT, GDK_TYPE_DROP,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
G_TYPE_UINT);
/** /**
* GtkWidget::drag-data-get: * GtkWidget::drag-data-get:

View File

@ -308,15 +308,13 @@ struct _GtkWidgetClass
void (* drag_leave) (GtkWidget *widget, void (* drag_leave) (GtkWidget *widget,
GdkDrop *drop); GdkDrop *drop);
gboolean (* drag_motion) (GtkWidget *widget, gboolean (* drag_motion) (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time_);
gboolean (* drag_drop) (GtkWidget *widget, gboolean (* drag_drop) (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y);
guint time_);
void (* drag_data_received) (GtkWidget *widget, void (* drag_data_received) (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data); GtkSelectionData *selection_data);

View File

@ -299,7 +299,7 @@ static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
void void
target_drag_leave (GtkWidget *widget, target_drag_leave (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
guint time) guint time)
{ {
g_print("leave\n"); g_print("leave\n");
@ -309,12 +309,12 @@ target_drag_leave (GtkWidget *widget,
gboolean gboolean
target_drag_motion (GtkWidget *widget, target_drag_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GtkWidget *source_widget; GtkWidget *source_widget;
GdkDragContext *drag;
char *s; char *s;
if (!have_drag) if (!have_drag)
@ -323,25 +323,25 @@ target_drag_motion (GtkWidget *widget,
gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open); gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open);
} }
source_widget = gtk_drag_get_source_widget (context); drag = gdk_drop_get_drag (drop);
source_widget = drag ? gtk_drag_get_source_widget (drag) : NULL;
g_print ("motion, source %s\n", source_widget ? g_print ("motion, source %s\n", source_widget ?
G_OBJECT_TYPE_NAME (source_widget) : G_OBJECT_TYPE_NAME (source_widget) :
"NULL"); "NULL");
s = gdk_content_formats_to_string (gdk_drag_context_get_formats (context)); s = gdk_content_formats_to_string (gdk_drop_get_formats (drop));
g_print ("%s\n", s); g_print ("%s\n", s);
gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time); gdk_drop_status (drop, GDK_ACTION_ALL);
return TRUE; return TRUE;
} }
gboolean gboolean
target_drag_drop (GtkWidget *widget, target_drag_drop (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
GdkContentFormats *formats; GdkContentFormats *formats;
const char *format; const char *format;
@ -351,53 +351,69 @@ target_drag_drop (GtkWidget *widget,
gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed); gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
formats = gdk_drag_context_get_formats (context); formats = gdk_drop_get_formats (drop);
format = gdk_content_formats_match_mime_type (formats, formats); format = gdk_content_formats_match_mime_type (formats, formats);
if (format) if (format)
{ {
gtk_drag_get_data (widget, context, gtk_drag_get_data (widget, drop, format);
format,
time);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
static GdkDragAction
action_make_unique (GdkDragAction action)
{
if (gdk_drag_action_is_unique (action))
return action;
if (action & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (action & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (action & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
g_assert_not_reached ();
return 0;
}
void void
target_drag_data_received (GtkWidget *widget, target_drag_data_received (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GtkSelectionData *selection_data, GtkSelectionData *selection_data)
guint info,
guint time)
{ {
if (gtk_selection_data_get_length (selection_data) >= 0 && if (gtk_selection_data_get_length (selection_data) >= 0 &&
gtk_selection_data_get_format (selection_data) == 8) gtk_selection_data_get_format (selection_data) == 8)
{ {
GdkDragAction action = gdk_drop_get_actions (drop);
g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data)); g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data));
gdk_drag_finish (context, TRUE, time); action = action_make_unique (action);
gdk_drop_finish (drop, action);
return; return;
} }
gdk_drag_finish (context, FALSE, time); gdk_drop_finish (drop, 0);
} }
void void
label_drag_data_received (GtkWidget *widget, label_drag_data_received (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
GtkSelectionData *selection_data, GtkSelectionData *selection_data)
guint info,
guint time)
{ {
if (gtk_selection_data_get_length (selection_data) >= 0 && if (gtk_selection_data_get_length (selection_data) >= 0 &&
gtk_selection_data_get_format (selection_data) == 8) gtk_selection_data_get_format (selection_data) == 8)
{ {
GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop));
g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data)); g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data));
gdk_drag_finish (context, TRUE, time); gdk_drop_finish (drop, action);
return; return;
} }
gdk_drag_finish (context, FALSE, time); gdk_drop_finish (drop, 0);
} }
void void
@ -439,10 +455,9 @@ popdown_cb (gpointer data)
gboolean gboolean
popup_motion (GtkWidget *widget, popup_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
if (!in_popup) if (!in_popup)
{ {
@ -460,8 +475,7 @@ popup_motion (GtkWidget *widget,
void void
popup_leave (GtkWidget *widget, popup_leave (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop)
guint time)
{ {
if (in_popup) if (in_popup)
{ {
@ -506,9 +520,9 @@ popup_cb (gpointer data)
GTK_DEST_DEFAULT_ALL, GTK_DEST_DEFAULT_ALL,
targets, targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE); GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (button, "drag_motion", g_signal_connect (button, "drag-motion",
G_CALLBACK (popup_motion), NULL); G_CALLBACK (popup_motion), NULL);
g_signal_connect (button, "drag_leave", g_signal_connect (button, "drag-leave",
G_CALLBACK (popup_leave), NULL); G_CALLBACK (popup_leave), NULL);
} }
gtk_container_add (GTK_CONTAINER (popup_window), grid); gtk_container_add (GTK_CONTAINER (popup_window), grid);
@ -529,10 +543,9 @@ popup_cb (gpointer data)
gboolean gboolean
popsite_motion (GtkWidget *widget, popsite_motion (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y)
guint time)
{ {
if (!popup_timer) if (!popup_timer)
popup_timer = g_timeout_add (500, popup_cb, NULL); popup_timer = g_timeout_add (500, popup_cb, NULL);
@ -542,8 +555,7 @@ popsite_motion (GtkWidget *widget,
void void
popsite_leave (GtkWidget *widget, popsite_leave (GtkWidget *widget,
GdkDragContext *context, GdkDrop *drop)
guint time)
{ {
if (popup_timer) if (popup_timer)
{ {
@ -623,9 +635,9 @@ main (int argc, char **argv)
gtk_widget_set_vexpand (label, TRUE); gtk_widget_set_vexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
g_signal_connect (label, "drag_motion", g_signal_connect (label, "drag-motion",
G_CALLBACK (popsite_motion), NULL); G_CALLBACK (popsite_motion), NULL);
g_signal_connect (label, "drag_leave", g_signal_connect (label, "drag-leave",
G_CALLBACK (popsite_leave), NULL); G_CALLBACK (popsite_leave), NULL);
gdk_content_formats_unref (targets); gdk_content_formats_unref (targets);
@ -635,16 +647,16 @@ main (int argc, char **argv)
gtk_widget_set_vexpand (pixmap, TRUE); gtk_widget_set_vexpand (pixmap, TRUE);
gtk_grid_attach (GTK_GRID (grid), pixmap, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), pixmap, 1, 0, 1, 1);
g_signal_connect (pixmap, "drag_leave", g_signal_connect (pixmap, "drag-leave",
G_CALLBACK (target_drag_leave), NULL); G_CALLBACK (target_drag_leave), NULL);
g_signal_connect (pixmap, "drag_motion", g_signal_connect (pixmap, "drag-motion",
G_CALLBACK (target_drag_motion), NULL); G_CALLBACK (target_drag_motion), NULL);
g_signal_connect (pixmap, "drag_drop", g_signal_connect (pixmap, "drag-drop",
G_CALLBACK (target_drag_drop), NULL); G_CALLBACK (target_drag_drop), NULL);
g_signal_connect (pixmap, "drag_data_received", g_signal_connect (pixmap, "drag-data-received",
G_CALLBACK (target_drag_data_received), NULL); G_CALLBACK (target_drag_data_received), NULL);
/* Drag site */ /* Drag site */
@ -664,9 +676,9 @@ main (int argc, char **argv)
gtk_widget_set_vexpand (button, TRUE); gtk_widget_set_vexpand (button, TRUE);
gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1);
g_signal_connect (button, "drag_data_get", g_signal_connect (button, "drag-data-get",
G_CALLBACK (source_drag_data_get), NULL); G_CALLBACK (source_drag_data_get), NULL);
g_signal_connect (button, "drag_data_delete", g_signal_connect (button, "drag-data-delete",
G_CALLBACK (source_drag_data_delete), NULL); G_CALLBACK (source_drag_data_delete), NULL);
gtk_widget_show (window); gtk_widget_show (window);

View File

@ -293,8 +293,10 @@ bold_toggled (GtkToggleToolButton *button)
} }
static gboolean static gboolean
toolbar_drag_drop (GtkWidget *widget, GdkDragContext *context, toolbar_drag_drop (GtkWidget *widget,
gint x, gint y, guint time, GtkWidget *label) GdkDrop *drop,
gint x, gint y,
GtkWidget *label)
{ {
gchar buf[32]; gchar buf[32];
@ -375,12 +377,12 @@ popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
static GtkToolItem *drag_item = NULL; static GtkToolItem *drag_item = NULL;
static gboolean static gboolean
toolbar_drag_motion (GtkToolbar *toolbar, toolbar_drag_motion (GtkToolbar *toolbar,
GdkDragContext *context, GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time, guint time,
gpointer null) gpointer null)
{ {
gint index; gint index;
@ -390,7 +392,7 @@ toolbar_drag_motion (GtkToolbar *toolbar,
g_object_ref_sink (g_object_ref (drag_item)); g_object_ref_sink (g_object_ref (drag_item));
} }
gdk_drag_status (context, GDK_ACTION_MOVE, time); gdk_drop_status (drop, GDK_ACTION_MOVE);
index = gtk_toolbar_get_drop_index (toolbar, x, y); index = gtk_toolbar_get_drop_index (toolbar, x, y);