summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-05-14 02:49:33 +0200
committerBenjamin Otte <otte@redhat.com>2018-06-18 23:49:19 +0200
commitb2dc303e5e7dde1648b26513afbf07989a1538bc (patch)
tree4781e4d85d069a576c43ff36306f958dbcddc8db
parent2e27967814276fb94d2c4d1982bc504a26282188 (diff)
downloadgtk+-b2dc303e5e7dde1648b26513afbf07989a1538bc.tar.gz
dnd: Add gdk_drop_get_actions()
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).
-rw-r--r--docs/reference/gdk/gdk4-sections.txt1
-rw-r--r--gdk/gdkdnd.c5
-rw-r--r--gdk/gdkdnd.h9
-rw-r--r--gdk/gdkdrop.c69
-rw-r--r--gdk/gdkdrop.h2
-rw-r--r--gdk/gdkdropprivate.h2
6 files changed, 88 insertions, 0 deletions
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 1da322155d..d03ddf3cd3 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -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
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index 4f2b5830dd..2ddc075c54 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -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);
}
/**
diff --git a/gdk/gdkdnd.h b/gdk/gdkdnd.h
index f153af44a1..d7a20d2866 100644
--- a/gdk/gdkdnd.h
+++ b/gdk/gdkdnd.h
@@ -60,6 +60,15 @@ typedef enum
} 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.
* @GDK_DRAG_CANCEL_USER_CANCELLED: Drag cancelled by the user
diff --git a/gdk/gdkdrop.c b/gdk/gdkdrop.c
index c11383eb24..0908a065c5 100644
--- a/gdk/gdkdrop.c
+++ b/gdk/gdkdrop.c
@@ -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;
@@ -169,6 +179,22 @@ gdk_drop_class_init (GdkDropClass *klass)
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:
*
* The #GdkDevice performing the drop
@@ -275,6 +301,49 @@ gdk_drop_get_formats (GdkDrop *self)
}
/**
+ * 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
* @mime_types: (array zero-terminated=1) (element-type utf8):
diff --git a/gdk/gdkdrop.h b/gdk/gdkdrop.h
index b1b4488d6b..5df8872b78 100644
--- a/gdk/gdkdrop.h
+++ b/gdk/gdkdrop.h
@@ -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,
diff --git a/gdk/gdkdropprivate.h b/gdk/gdkdropprivate.h
index ebe95e76cb..b5759fb2b6 100644
--- a/gdk/gdkdropprivate.h
+++ b/gdk/gdkdropprivate.h
@@ -51,6 +51,8 @@ struct _GdkDropClass {
GError **error);
};
+void gdk_drop_set_actions (GdkDrop *self,
+ GdkDragAction actions);
G_END_DECLS