[gtk/wip/otte/dnd: 4/9] testdnd3: Use GValue dnd
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/dnd: 4/9] testdnd3: Use GValue dnd
- Date: Sun, 16 Feb 2020 19:13:40 +0000 (UTC)
commit dbad4404680204923df9abaa37ff077d1e350294
Author: Benjamin Otte <otte redhat com>
Date: Sun Feb 16 14:29:22 2020 +0100
testdnd3: Use GValue dnd
tests/testdnd3.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/tests/testdnd3.c b/tests/testdnd3.c
index c63bb0d9db..67a0b61065 100644
--- a/tests/testdnd3.c
+++ b/tests/testdnd3.c
@@ -5,8 +5,6 @@ prepare (GtkDragSource *source, double x, double y)
{
GtkWidget *canvas;
GtkWidget *item;
- GdkContentProvider *provider;
- GBytes *bytes;
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
item = gtk_widget_pick (canvas, x, y, GTK_PICK_DEFAULT);
@@ -14,13 +12,9 @@ prepare (GtkDragSource *source, double x, double y)
if (!GTK_IS_LABEL (item))
return NULL;
- bytes = g_bytes_new (&item, sizeof (gpointer));
- provider = gdk_content_provider_new_for_bytes ("CANVAS_ITEM", bytes);
- g_bytes_unref (bytes);
-
g_object_set_data (G_OBJECT (canvas), "dragged-item", item);
- return provider;
+ return gdk_content_provider_new_typed (GTK_TYPE_WIDGET, item);
}
static void
@@ -48,6 +42,14 @@ drag_end (GtkDragSource *source, GdkDrag *drag)
gtk_widget_set_opacity (item, 1.0);
}
+static void
+drag_cancel (GtkDragSource *source,
+ GdkDrag *drag,
+ GdkDragCancelReason reason)
+{
+ drag_end (source, drag);
+}
+
typedef struct {
GtkWidget *canvas;
double x;
@@ -81,18 +83,20 @@ got_data (GObject *source,
{
GdkDrop *drop = GDK_DROP (source);
DropData *data = user_data;
- GInputStream *stream;
- GBytes *bytes;
GtkWidget *item;
- const char *mime_type;
- GError *error = NULL;
+ const GValue *value;
TransformData *transform_data;
GtkWidget *canvas;
GtkWidget *last_child;
- stream = gdk_drop_read_finish (drop, result, &mime_type, &error);
- bytes = g_input_stream_read_bytes (stream, sizeof (gpointer), NULL, NULL);
- item = (gpointer) *(gpointer *)g_bytes_get_data (bytes, NULL);
+ value = gdk_drop_read_value_finish (drop, result, NULL);
+ if (value == NULL)
+ {
+ gdk_drop_finish (drop, 0);
+ return;
+ }
+
+ item = g_value_get_object (value);
transform_data = g_object_get_data (G_OBJECT (item), "transform-data");
@@ -108,8 +112,6 @@ got_data (GObject *source,
gdk_drop_finish (drop, GDK_ACTION_MOVE);
- g_bytes_unref (bytes);
- g_object_unref (stream);
g_free (data);
}
@@ -126,7 +128,7 @@ drag_drop (GtkDropTarget *dest,
data->x = x;
data->y = y;
- gdk_drop_read_async (drop, (const char *[]){"CANVAS_ITEM", NULL}, G_PRIORITY_DEFAULT, NULL, got_data,
data);
+ gdk_drop_read_value_async (drop, GTK_TYPE_WIDGET, G_PRIORITY_DEFAULT, NULL, got_data, data);
return TRUE;
}
@@ -149,9 +151,10 @@ canvas_new (void)
g_signal_connect (source, "prepare", G_CALLBACK (prepare), NULL);
g_signal_connect (source, "drag-begin", G_CALLBACK (drag_begin), NULL);
g_signal_connect (source, "drag-end", G_CALLBACK (drag_end), NULL);
+ g_signal_connect (source, "drag-cancel", G_CALLBACK (drag_cancel), NULL);
gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (source));
- formats = gdk_content_formats_new ((const char *[]){"CANVAS_ITEM", NULL}, 1);
+ formats = gdk_content_formats_new_for_gtype (GTK_TYPE_WIDGET);
dest = gtk_drop_target_new (formats, GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), NULL);
gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (dest));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]