From 7e4d6b556c07cfd721023a57aad87effd21093d8 Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 16 Jul 2022 20:50:41 +0300 Subject: [PATCH] tree/iconview: Use a unique drag action in drag_enter/motion callbacks Functions already exist for providing a unique drag action for gdk_drop_finish(). Reuse these functions in the drag_enter/motion callbacks, since they require a unique action as the return value. Fixes #3187 --- gtk/gtkiconview.c | 59 ++++++++++++++++++++++++----------------------- gtk/gtktreeview.c | 59 ++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index 41f824610d..9a35cc682e 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -5726,8 +5726,35 @@ drag_scroll_timeout (gpointer data) return TRUE; } +static GdkDragAction +gtk_icon_view_get_action (GtkWidget *widget, + GdkDrop *drop) +{ + GtkIconView *iconview = GTK_ICON_VIEW (widget); + GdkDrag *drag = gdk_drop_get_drag (drop); + GdkDragAction actions; + + actions = gdk_drop_get_actions (drop); + + if (drag == iconview->priv->drag && + 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 gboolean set_destination (GtkIconView *icon_view, + GdkDrop *drop, GtkDropTargetAsync *dest, int x, int y, @@ -5814,7 +5841,7 @@ set_destination (GtkIconView *icon_view, out: if (can_drop) { - *suggested_action = GDK_ACTION_ALL; + *suggested_action = gtk_icon_view_get_action (widget, drop); gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget), path, pos); @@ -6054,7 +6081,7 @@ gtk_icon_view_drag_motion (GtkDropTargetAsync *dest, gboolean empty; GdkDragAction result; - if (!set_destination (icon_view, dest, x, y, &suggested_action, &target)) + if (!set_destination (icon_view, drop, dest, x, y, &suggested_action, &target)) return 0; gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos); @@ -6119,7 +6146,7 @@ gtk_icon_view_drag_drop (GtkDropTargetAsync *dest, if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drop")) return FALSE; - if (!set_destination (icon_view, dest, x, y, &suggested_action, &target)) + if (!set_destination (icon_view, drop, dest, x, y, &suggested_action, &target)) return FALSE; path = get_logical_destination (icon_view, &drop_append_mode); @@ -6149,32 +6176,6 @@ gtk_icon_view_drag_drop (GtkDropTargetAsync *dest, return FALSE; } -static GdkDragAction -gtk_icon_view_get_action (GtkWidget *widget, - GdkDrop *drop) -{ - GtkIconView *iconview = GTK_ICON_VIEW (widget); - GdkDrag *drag = gdk_drop_get_drag (drop); - GdkDragAction actions; - - actions = gdk_drop_get_actions (drop); - - if (drag == iconview->priv->drag && - 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 gtk_icon_view_drag_data_received (GObject *source, GAsyncResult *result, diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 55c8b28f15..f684cc1b3e 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -6845,9 +6845,36 @@ scroll_row_timeout (gpointer data) return TRUE; } +static GdkDragAction +gtk_tree_view_get_action (GtkWidget *widget, + GdkDrop *drop) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + TreeViewDragInfo *di; + GdkDrag *drag = gdk_drop_get_drag (drop); + GdkDragAction actions; + + di = get_info (tree_view); + + actions = gdk_drop_get_actions (drop); + + if (di && di->drag == drag && + 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; + + return 0; +} + /* Returns TRUE if event should not be propagated to parent widgets */ static gboolean set_destination_row (GtkTreeView *tree_view, + GdkDrop *drop, GtkDropTargetAsync *dest, /* coordinates relative to the widget */ int x, @@ -6953,7 +6980,7 @@ set_destination_row (GtkTreeView *tree_view, out: if (can_drop) { - *suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE; + *suggested_action = gtk_tree_view_get_action (widget, drop); gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), path, pos); @@ -7218,7 +7245,7 @@ gtk_tree_view_drag_motion (GtkDropTargetAsync *dest, GdkDragAction suggested_action = 0; GType target; - if (!set_destination_row (tree_view, dest, x, y, &suggested_action, &target)) + if (!set_destination_row (tree_view, drop, dest, x, y, &suggested_action, &target)) return 0; priv->event_last_x = x; @@ -7298,7 +7325,7 @@ gtk_tree_view_drag_drop (GtkDropTargetAsync *dest, if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop")) return FALSE; - if (!set_destination_row (tree_view, dest, x, y, &suggested_action, &target)) + if (!set_destination_row (tree_view, drop, dest, x, y, &suggested_action, &target)) return FALSE; path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode); @@ -7331,32 +7358,6 @@ gtk_tree_view_drag_drop (GtkDropTargetAsync *dest, return FALSE; } -static GdkDragAction -gtk_tree_view_get_action (GtkWidget *widget, - GdkDrop *drop) -{ - GtkTreeView *tree_view = GTK_TREE_VIEW (widget); - TreeViewDragInfo *di; - GdkDrag *drag = gdk_drop_get_drag (drop); - GdkDragAction actions; - - di = get_info (tree_view); - - actions = gdk_drop_get_actions (drop); - - if (di && di->drag == drag && - 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; - - return 0; -} - static void gtk_tree_view_drag_data_received (GObject *source, GAsyncResult *result,