From: Benjamin Otte Date: Mon, 14 May 2018 00:49:33 +0000 (+0200) Subject: dnd: Add gdk_drop_get_actions() X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~125 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b2dc303e5e7dde1648b26513afbf07989a1538bc;p=gtk4.git 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). --- 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 @@ -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. 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; @@ -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 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