[gtk: 1/2] tree/iconview: Use a unique drag action in drag_enter/motion callbacks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] tree/iconview: Use a unique drag action in drag_enter/motion callbacks
- Date: Mon, 18 Jul 2022 14:35:13 +0000 (UTC)
commit d89297b152998b3908f0ffa3cf199cfeced26c8e
Author: Mat <mail mathias is>
Date: Sat Jul 16 20:50:41 2022 +0300
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 c647b16c9c..1e194744a2 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -5692,8 +5692,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,
@@ -5780,7 +5807,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);
@@ -6020,7 +6047,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);
@@ -6085,7 +6112,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);
@@ -6115,32 +6142,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 60e54f6da7..61deb96d19 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -6811,9 +6811,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,
@@ -6919,7 +6946,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);
@@ -7184,7 +7211,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;
@@ -7264,7 +7291,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);
@@ -7297,32 +7324,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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]