[gtk/wip/otte/dnd: 1/10] dnd: simplify code
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/dnd: 1/10] dnd: simplify code
- Date: Mon, 17 Feb 2020 04:00:33 +0000 (UTC)
commit e1f8c1430fefb70498296b4b40ebb135715509bc
Author: Benjamin Otte <otte redhat com>
Date: Sun Feb 16 18:32:42 2020 +0100
dnd: simplify code
The old code did mimetype checks everywhere when type compatibility has
since been moved to the GtkDropTarget::accept signal.
So the code can now just assume a compatible mime type exists.
gtk/gtktext.c | 22 +++++++---------------
gtk/gtktextview.c | 15 ++++-----------
tests/testdnd3.c | 23 ++---------------------
3 files changed, 13 insertions(+), 47 deletions(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 6dce1b327b..c7ca23be88 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -6229,21 +6229,14 @@ gtk_text_drag_accept (GtkDropTarget *dest,
GtkText *self)
{
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
- GdkDragAction suggested_action;
- if (priv->editable &&
- gtk_drop_target_find_mimetype (dest) != NULL)
- {
- suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
- }
- else
- {
- /* Entry not editable, or no text */
- suggested_action = 0;
- }
+ if (!priv->editable)
+ return FALSE;
- gdk_drop_status (drop, suggested_action);
- return suggested_action != 0;
+ if ((gdk_drop_get_actions (drop) & gtk_drop_target_get_actions (dest)) == 0)
+ return FALSE;
+
+ return gdk_content_formats_match (gtk_drop_target_get_formats (dest), gdk_drop_get_formats (drop));
}
static void
@@ -6259,8 +6252,7 @@ gtk_text_drag_motion (GtkDropTarget *dest,
old_position = priv->dnd_position;
new_position = gtk_text_find_position (self, x + priv->scroll_offset);
- if (priv->editable &&
- gtk_drop_target_find_mimetype (dest) != NULL)
+ if (priv->editable)
{
if (priv->selection_bound == priv->current_pos ||
new_position < priv->selection_bound ||
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 5f677847a1..9ca2659e18 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -7781,7 +7781,6 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
GtkTextIter end;
GdkRectangle target_rect;
gint bx, by;
- GdkAtom target;
gboolean can_accept = FALSE;
target_rect = priv->text_window->allocation;
@@ -7801,16 +7800,10 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
&newplace,
bx, by);
- target = gtk_drop_target_find_mimetype (dest);
-
- if (target == NULL)
- {
- /* can't accept any of the offered targets */
- }
- else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
- &start, &end) &&
- gtk_text_iter_compare (&newplace, &start) >= 0 &&
- gtk_text_iter_compare (&newplace, &end) <= 0)
+ if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
+ &start, &end) &&
+ gtk_text_iter_compare (&newplace, &start) >= 0 &&
+ gtk_text_iter_compare (&newplace, &end) <= 0)
{
/* We're inside the selection. */
}
diff --git a/tests/testdnd3.c b/tests/testdnd3.c
index 67a0b61065..b1c4a47dc8 100644
--- a/tests/testdnd3.c
+++ b/tests/testdnd3.c
@@ -213,26 +213,8 @@ item_drag_drop (GtkDropTarget *dest,
int x,
int y)
{
- if (gtk_drop_target_find_mimetype (dest))
- {
- gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-item_drag_motion (GtkDropTarget *dest,
- GdkDrop *drop)
-{
- if (gtk_drop_target_find_mimetype (dest) != NULL)
- {
- gdk_drop_status (drop, GDK_ACTION_COPY);
- return TRUE;
- }
-
- return FALSE;
+ gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
+ return TRUE;
}
static void
@@ -307,7 +289,6 @@ canvas_item_new (int i,
formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
g_signal_connect (dest, "drag-drop", G_CALLBACK (item_drag_drop), NULL);
- g_signal_connect (dest, "accept", G_CALLBACK (item_drag_motion), NULL);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (formats);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]