dnd: Add gdk_drop_get_actions()
authorBenjamin Otte <otte@redhat.com>
Mon, 14 May 2018 00:49:33 +0000 (02:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 18 Jun 2018 21:49:19 +0000 (23:49 +0200)
This uses the new method without GDK_ACTION_ASK:

Either it is a single action (queryable via gdk_drag_action_is_unique())
or it is not and then the drop target has to make a decision
(potentially by asking someone).

docs/reference/gdk/gdk4-sections.txt
gdk/gdkdnd.c
gdk/gdkdnd.h
gdk/gdkdrop.c
gdk/gdkdrop.h
gdk/gdkdropprivate.h

index 1da322155df245f49e7d75f46c9693cfb72d8533..d03ddf3cd33e7e67eaede3063f38215a3561fff1 100644 (file)
@@ -785,6 +785,7 @@ gdk_drag_drop_done
 gdk_drag_begin
 gdk_drop_finish
 GdkDragAction
+GDK_ACTION_ALL
 gdk_drag_status
 
 gdk_drag_context_get_display
index 4f2b5830ddf5de67c7275feaa4518bd082e7b5c4..2ddc075c540fe85940e38680287a4ecce473ee45 100644 (file)
@@ -722,6 +722,11 @@ gdk_drag_context_set_actions (GdkDragContext *context,
 
   priv->actions = actions;
   priv->suggested_action = suggested_action;
+
+  if (suggested_action & GDK_ACTION_ASK)
+    gdk_drop_set_actions (GDK_DROP (context), actions & GDK_ACTION_ALL);
+  else
+    gdk_drop_set_actions (GDK_DROP (context), suggested_action);
 }
 
 /**
index f153af44a10a9e4b69fc31cf06cab24b0a5c20bd..d7a20d286627465eff8e6813e2f8f64c29ca363f 100644 (file)
@@ -59,6 +59,15 @@ typedef enum
   GDK_ACTION_ASK     = 1 << 3
 } GdkDragAction;
 
+/**
+ * GDK_ACTION_ALL:
+ *
+ * Defines all possible DND actions. This can be used in gdk_drop_status()
+ * messages when any drop can be accepted or a more specific drop method
+ * is not yet known.
+ */
+#define GDK_ACTION_ALL (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK)
+
 /**
  * GdkDragCancelReason:
  * @GDK_DRAG_CANCEL_NO_TARGET: There is no suitable drop target.
index c11383eb246790dfad02e5fce237ee7895dcf889..0908a065c5489b872e41f48865bd5915843e7134 100644 (file)
@@ -35,10 +35,12 @@ typedef struct _GdkDropPrivate GdkDropPrivate;
 struct _GdkDropPrivate {
   GdkDevice *device;
   GdkContentFormats *formats;
+  GdkDragAction actions;
 };
 
 enum {
   PROP_0,
+  PROP_ACTIONS,
   PROP_DEVICE,
   PROP_DISPLAY,
   PROP_FORMATS,
@@ -101,6 +103,10 @@ gdk_drop_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
+    case PROP_ACTIONS:
+      gdk_drop_set_actions (self, g_value_get_flags (value));
+      break;
+
     case PROP_DEVICE:
       priv->device = g_value_dup_object (value);
       g_assert (priv->device != NULL);
@@ -130,6 +136,10 @@ gdk_drop_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
+    case PROP_ACTIONS:
+      g_value_set_flags (value, priv->actions);
+      break;
+
     case PROP_DEVICE:
       g_value_set_object (value, priv->device);
       break;
@@ -168,6 +178,22 @@ gdk_drop_class_init (GdkDropClass *klass)
   object_class->set_property = gdk_drop_set_property;
   object_class->finalize = gdk_drop_finalize;
 
+  /**
+   * GdkDrop:actions:
+   *
+   * The possible actions for this drop
+   */
+  properties[PROP_ACTIONS] =
+    g_param_spec_flags ("actions",
+                        "Actions",
+                        "The possible actions for this drop",
+                         GDK_TYPE_DRAG_ACTION,
+                         GDK_ACTION_ALL,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY);
+
   /**
    * GdkDrop:device:
    *
@@ -274,6 +300,49 @@ gdk_drop_get_formats (GdkDrop *self)
   return priv->formats;
 }
 
+/**
+ * gdk_drop_get_actions:
+ * @self: a #GdkDrop
+ *
+ * Returns the possible actions for this #GdkDrop. If this value
+ * contains multiple actions - ie gdk_drag_action_is_unique()
+ * returns %FALSE for the result - gdk_drop_finish() must choose
+ * the action to use when accepting the drop.
+ *
+ * This value may change over the lifetime of the #GdkDrop both
+ * as a response to source side actions as well as to calls to
+ * gdk_drop_status() or gdk_drop_finish(). The source side will
+ * not change this value anymore once a drop has started.
+ *
+ * Returns: The possible #GdkDragActions
+ **/
+GdkDragAction
+gdk_drop_get_actions (GdkDrop *self)
+{
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+  g_return_val_if_fail (GDK_IS_DROP (self), 0);
+
+  return priv->actions;
+}
+
+void
+gdk_drop_set_actions (GdkDrop       *self,
+                      GdkDragAction  actions)
+{
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+  g_return_if_fail (GDK_IS_DROP (self));
+  g_return_if_fail ((actions & GDK_ACTION_ASK) == 0);
+
+  if (priv->actions == actions)
+    return;
+
+  priv->actions = actions;
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
+}
+
 /**
  * gdk_drop_read_async:
  * @self: a #GdkDrop
index b1b4488d6b75dd3084038a261737f29350c74568..5df8872b78e42369b2e12ab410e0f042974517a5 100644 (file)
@@ -45,6 +45,8 @@ GDK_AVAILABLE_IN_ALL
 GdkDevice *             gdk_drop_get_device             (GdkDrop                *self);
 GDK_AVAILABLE_IN_ALL
 GdkContentFormats *     gdk_drop_get_formats            (GdkDrop                *self);
+GDK_AVAILABLE_IN_ALL
+GdkDragAction           gdk_drop_get_actions            (GdkDrop                *self);
 
 GDK_AVAILABLE_IN_ALL
 void                    gdk_drop_read_async             (GdkDrop                *self,
index ebe95e76cbbef56dc2a83660720a54be3e3a1378..b5759fb2b6209fab61ccbd19e8c4df84f01e1144 100644 (file)
@@ -51,6 +51,8 @@ struct _GdkDropClass {
                                                                  GError                **error);
 };
 
+void                    gdk_drop_set_actions                    (GdkDrop                *self,
+                                                                 GdkDragAction           actions);
 
 G_END_DECLS