drop: Add a convenience api
authorMatthias Clasen <mclasen@redhat.com>
Thu, 2 Jan 2020 18:05:29 +0000 (13:05 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 8 Jan 2020 23:48:20 +0000 (18:48 -0500)
This is a question that drag-drop handlers frequently
need to answer, so make it easy.

gdk/gdkdrop.c
gdk/gdkdrop.h

index eb04ca26ad70d01d863a8c5b07d171c303e00909..d82e90df2c53ba4cfc8cc67c3cbeb33e4dc18163 100644 (file)
@@ -1001,3 +1001,30 @@ gdk_drop_emit_drop_event (GdkDrop  *self,
   gdk_drop_do_emit_event (event, dont_queue);
 }
 
+/**
+ * gdk_drop_has_value:
+ * @drop: a #GdkDrop
+ * @type: the type to check
+ *
+ * Returns whether calling gdk_drop_read_value_async() for @type
+ * can succeed.
+ *
+ * Returns: %TRUE if the data can be deserialized to the given type
+ */ 
+gboolean
+gdk_drop_has_value (GdkDrop *drop,
+                    GType    type)
+{
+  GdkContentFormats *formats;
+  gboolean ret;
+
+  formats = gdk_content_formats_ref (gdk_drop_get_formats (drop));
+  formats = gdk_content_formats_union_deserialize_gtypes (formats);
+
+  ret = gdk_content_formats_contain_gtype (formats, type);
+
+  gdk_content_formats_unref (formats);
+
+  return ret;
+}
+
index db5acd13e94a9ca23e60ee909d7b1c543e2491a9..6e29864293a236ff422edda2c977876e06e97fde 100644 (file)
@@ -92,6 +92,9 @@ char *                  gdk_drop_read_text_finish       (GdkDrop
                                                          GAsyncResult           *result,
                                                          GError                **error);
 
+GDK_AVAILABLE_IN_ALL
+gboolean                gdk_drop_has_value              (GdkDrop                *self,
+                                                         GType                   type);
 
 G_END_DECLS