summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte.benjamin@googlemail.com>2020-03-02 21:32:20 +0000
committerBenjamin Otte <otte.benjamin@googlemail.com>2020-03-02 21:32:20 +0000
commit3ef1dca51c9994caba03e046c16398cdf03dc259 (patch)
treeba3f3f25292e6a9ba2808437d850bee21a523109
parent47230f191f2b4e16a3038303567f8b8bb0d515f5 (diff)
parent2e55c9cf8c03be9a67eb515a4bd973bacf35d701 (diff)
downloadgtk+-3ef1dca51c9994caba03e046c16398cdf03dc259.tar.gz
Merge branch 'wip/otte/for-master' into 'master'
Wip/otte/for master See merge request GNOME/gtk!1496
-rw-r--r--docs/reference/gtk/gtk4-docs.xml1
-rw-r--r--gdk/gdkdrop.c9
-rw-r--r--gtk/gtkdroptarget.c49
3 files changed, 43 insertions, 16 deletions
diff --git a/docs/reference/gtk/gtk4-docs.xml b/docs/reference/gtk/gtk4-docs.xml
index 732173b671..aabc016df4 100644
--- a/docs/reference/gtk/gtk4-docs.xml
+++ b/docs/reference/gtk/gtk4-docs.xml
@@ -343,6 +343,7 @@
<xi:include href="xml/gtkdragsource.xml"/>
<xi:include href="xml/gtkdragicon.xml"/>
<xi:include href="xml/gtkdroptarget.xml"/>
+ <xi:include href="xml/gtkdroptargetasync.xml"/>
</chapter>
</part>
diff --git a/gdk/gdkdrop.c b/gdk/gdkdrop.c
index 20676937e1..1df4a4ffdb 100644
--- a/gdk/gdkdrop.c
+++ b/gdk/gdkdrop.c
@@ -785,14 +785,11 @@ gdk_drop_read_value_internal (GdkDrop *self,
if (priv->drag)
{
GError *error = NULL;
- GdkContentProvider *content;
gboolean res;
- g_object_get (priv->drag, "content", &content, NULL);
-
- res = gdk_content_provider_get_value (content, value, &error);
-
- g_object_unref (content);
+ res = gdk_content_provider_get_value (gdk_drag_get_content (priv->drag),
+ value,
+ &error);
if (res)
{
diff --git a/gtk/gtkdroptarget.c b/gtk/gtkdroptarget.c
index 3bd86fa93a..89e91a9a9a 100644
--- a/gtk/gtkdroptarget.c
+++ b/gtk/gtkdroptarget.c
@@ -45,25 +45,25 @@
* receive Drag-and-Drop operations.
*
* The most basic way to use a #GtkDropTarget to receive drops on a
- * widget, is to create it via gtk_drop_target_new(), passing in the
+ * widget is to create it via gtk_drop_target_new() passing in the
* #GType of the data you want to receive and connect to the
* GtkDropTarget::drop signal to receive the data.
*
* #GtkDropTarget supports more options, such as:
*
- * * rejecting potential drops via the GtkDropTarget::accept signal
+ * * rejecting potential drops via the #GtkDropTarget::accept signal
* and the gtk_drop_target_reject() function to let other drop
* targets handle the drop
* * tracking an ongoing drag operation before the drop via the
- * GtkDropTarget::enter, GtkDropTarget::motion and
- * GtkDropTarget::leave signals
+ * #GtkDropTarget::enter, #GtkDropTarget::motion and
+ * #GtkDropTarget::leave signals
* * configuring how to receive data by setting the
- * GtkDropTarget:preload property and listening for its availability
- * via the GtkDropTarget:value property
+ * #GtkDropTarget:preload property and listening for its availability
+ * via the #GtkDropTarget:value property
*
* However, #GtkDropTarget is ultimately modeled in a synchronous way
* and only supports data transferred via #GType.
- * If you want full control over an ongoing drop, the #GdkDropTargetAsync
+ * If you want full control over an ongoing drop, the #GtkDropTargetAsync
* object gives you this ability.
*
* While a pointer is dragged over the drop target's widget and the drop
@@ -223,8 +223,30 @@ gtk_drop_target_load_done (GObject *source,
}
static gboolean
+gtk_drop_target_load_local (GtkDropTarget *self,
+ GType type)
+{
+ GdkDrag *drag;
+
+ drag = gdk_drop_get_drag (self->drop);
+ if (drag == NULL)
+ return FALSE;
+
+ g_value_init (&self->value, type);
+ if (gdk_content_provider_get_value (gdk_drag_get_content (drag),
+ &self->value,
+ NULL))
+ return TRUE;
+
+ g_value_unset (&self->value);
+ return FALSE;
+}
+
+static gboolean
gtk_drop_target_load (GtkDropTarget *self)
{
+ GType type;
+
g_assert (self->drop);
if (G_IS_VALUE (&self->value))
@@ -233,10 +255,15 @@ gtk_drop_target_load (GtkDropTarget *self)
if (self->cancellable)
return FALSE;
+ type = gdk_content_formats_match_gtype (self->formats, gdk_drop_get_formats (self->drop));
+
+ if (gtk_drop_target_load_local (self, type))
+ return TRUE;
+
self->cancellable = g_cancellable_new ();
gdk_drop_read_value_async (self->drop,
- gdk_content_formats_match_gtype (self->formats, gdk_drop_get_formats (self->drop)),
+ type,
G_PRIORITY_DEFAULT,
self->cancellable,
gtk_drop_target_load_done,
@@ -590,11 +617,13 @@ gtk_drop_target_class_init (GtkDropTargetClass *class)
* huge amounts of data by accident.
* For example, if somebody drags a full document of gigabytes of text
* from a text editor across a widget with a preloading drop target,
- * this data will be downlaoded, even if the data is ultimately dropped
+ * this data will be downloaded, even if the data is ultimately dropped
* elsewhere.
*
* For a lot of data formats, the amount of data is very small (like
- * %GDK_TYPE_RGBA), so enabling this property does not hurt at all.
+ * %GDK_TYPE_RGBA), so enabling this property does not hurt at all.
+ * And for local-only drag'n'drop operations, no data transfer is done,
+ * so enabling it there is free.
*/
properties[PROP_PRELOAD] =
g_param_spec_boolean ("preload",