summaryrefslogtreecommitdiff
path: root/gtk/gtkdragsource.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-01-06 14:46:14 -0500
committerMatthias Clasen <mclasen@redhat.com>2020-01-08 18:48:21 -0500
commite8b830a3ddbfe5d1b162e4dfa678d5e323c78267 (patch)
tree5fa9d9e1c59d6827addd6539014544965d5a2e0a /gtk/gtkdragsource.c
parent38974d7d2bc56496b45e1b7406d68a37009530d7 (diff)
downloadgtk+-e8b830a3ddbfe5d1b162e4dfa678d5e323c78267.tar.gz
dragsource: Reshuffle api a bit
Remove arguments from the constructor. For actions, we now default to COPY, which is the most common one that we should enable by default (MOVE requires handling deletion on the the source side, and ASK only makes sense if we have multiple actions). For the content provider, we add a new ::prepare signal where it should be provided just-in-time.
Diffstat (limited to 'gtk/gtkdragsource.c')
-rw-r--r--gtk/gtkdragsource.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c
index 6fa40897f4..68a0a344df 100644
--- a/gtk/gtkdragsource.c
+++ b/gtk/gtkdragsource.c
@@ -107,6 +107,7 @@ enum {
static GParamSpec *properties[NUM_PROPERTIES];
enum {
+ PREPARE,
DRAG_BEGIN,
DRAG_END,
DRAG_FAILED,
@@ -115,11 +116,21 @@ enum {
static guint signals[NUM_SIGNALS];
+static void gtk_drag_source_dnd_finished_cb (GdkDrag *drag,
+ GtkDragSource *source);
+static void gtk_drag_source_drop_performed_cb (GdkDrag *drag,
+ GtkDragSource *source);
+static void gtk_drag_source_cancel_cb (GdkDrag *drag,
+ GdkDragCancelReason reason,
+ GtkDragSource *source);
+
+
G_DEFINE_TYPE (GtkDragSource, gtk_drag_source, G_TYPE_OBJECT);
static void
gtk_drag_source_init (GtkDragSource *source)
{
+ source->actions = GDK_ACTION_COPY;
}
static void
@@ -216,11 +227,21 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
g_param_spec_flags ("actions",
P_("Actions"),
P_("Supported actions"),
- GDK_TYPE_DRAG_ACTION, 0,
+ GDK_TYPE_DRAG_ACTION, GDK_ACTION_COPY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
+ signals[PREPARE] =
+ g_signal_new (I_("prepare"),
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+
/**
* GtkDragSource::drag-begin:
* @source: the #GtkDragSource
@@ -287,14 +308,6 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
GDK_TYPE_DRAG_CANCEL_REASON);
}
-static void gtk_drag_source_dnd_finished_cb (GdkDrag *drag,
- GtkDragSource *source);
-static void gtk_drag_source_drop_performed_cb (GdkDrag *drag,
- GtkDragSource *source);
-static void gtk_drag_source_cancel_cb (GdkDrag *drag,
- GdkDragCancelReason reason,
- GtkDragSource *source);
-
static void
drag_end (GtkDragSource *source,
gboolean success)
@@ -390,7 +403,13 @@ gtk_drag_source_drag_begin (GtkDragSource *source,
dx = round (px) - x;
dy = round (py) - y;
+ g_signal_emit (source, signals[PREPARE], 0, x, y);
+
+ if (source->content == NULL || source->actions == 0)
+ return;
+
source->drag = gdk_drag_begin (surface, device, source->content, source->actions, dx, dy);
+
if (source->drag == NULL)
{
g_print ("no drag :(\n");
@@ -439,21 +458,15 @@ gtk_drag_source_drag_begin (GtkDragSource *source,
/**
* gtk_drag_source_new:
- * @content: (nullable): the #GdkContentProvider to use, or %NULL
- * @actions: the actions to offer
*
* Creates a new #GtkDragSource object.
*
* Returns: the new #GtkDragSource
*/
GtkDragSource *
-gtk_drag_source_new (GdkContentProvider *content,
- GdkDragAction actions)
+gtk_drag_source_new (void)
{
- return g_object_new (GTK_TYPE_DRAG_SOURCE,
- "content", content,
- "actions", actions,
- NULL);
+ return g_object_new (GTK_TYPE_DRAG_SOURCE, NULL);
}
/**