summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-06-19 15:08:43 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-06-19 15:26:53 -0400
commit290611f9ce3cb649d0e550a578447414e1f62270 (patch)
tree1580b091f3f66b0df8c04ec46494c276a83699f2
parent62800662077b532f1f6f684f0863aabfe4b1b052 (diff)
downloadgtk+-290611f9ce3cb649d0e550a578447414e1f62270.tar.gz
editablelabel: Accept text drops
This seems natural. If we allow editing, we should allow drops too.
-rw-r--r--gtk/gtkeditablelabel.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gtk/gtkeditablelabel.c b/gtk/gtkeditablelabel.c
index d9df3fb303..ad36867a22 100644
--- a/gtk/gtkeditablelabel.c
+++ b/gtk/gtkeditablelabel.c
@@ -17,6 +17,7 @@
#include "config.h"
+#include "gtkdroptarget.h"
#include "gtkeditablelabel.h"
#include "gtkeditable.h"
#include "gtklabel.h"
@@ -133,10 +134,40 @@ text_changed (GtkEditableLabel *self)
}
}
+static gboolean
+gtk_editable_label_drag_accept (GtkDropTarget *dest,
+ GdkDrop *drop,
+ GtkEditableLabel *self)
+{
+ if (!gtk_editable_get_editable (GTK_EDITABLE (self)))
+ return FALSE;
+
+ 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 gboolean
+gtk_editable_label_drag_drop (GtkDropTarget *dest,
+ const GValue *value,
+ double x,
+ double y,
+ GtkEditableLabel *self)
+{
+ if (!gtk_editable_get_editable (GTK_EDITABLE (self)))
+ return FALSE;
+
+ gtk_editable_set_text (GTK_EDITABLE (self), g_value_get_string (value));
+
+ return TRUE;
+}
+
static void
gtk_editable_label_init (GtkEditableLabel *self)
{
GtkGesture *gesture;
+ GtkDropTarget *target;
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
@@ -157,6 +188,11 @@ gtk_editable_label_init (GtkEditableLabel *self)
g_signal_connect_swapped (self->entry, "activate", G_CALLBACK (activate_cb), self);
g_signal_connect_swapped (self->entry, "notify::text", G_CALLBACK (text_changed), self);
+ target = gtk_drop_target_new (G_TYPE_STRING, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+ g_signal_connect (target, "accept", G_CALLBACK (gtk_editable_label_drag_accept), self);
+ g_signal_connect (target, "drop", G_CALLBACK (gtk_editable_label_drag_drop), self);
+ gtk_widget_add_controller (self->label, GTK_EVENT_CONTROLLER (target));
+
gtk_editable_init_delegate (GTK_EDITABLE (self));
}