summaryrefslogtreecommitdiff
path: root/tests/testclipboard2.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-11-22 14:19:02 +0100
committerBenjamin Otte <otte@redhat.com>2017-12-03 05:46:28 +0100
commit88684baecf164875f5947a9eff40f567aa172c67 (patch)
treeb67c8d0d8b27a45f52961ae34099585935b14eba /tests/testclipboard2.c
parent02d1f90d13a58395cd81c020299dde83d85f14a3 (diff)
downloadgtk+-88684baecf164875f5947a9eff40f567aa172c67.tar.gz
clipboard: Add gdk_clipboard_read_text_async()
Also add deserializers for G_TYPE_STRING.
Diffstat (limited to 'tests/testclipboard2.c')
-rw-r--r--tests/testclipboard2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/testclipboard2.c b/tests/testclipboard2.c
index 31efc64e0d..23eddfe6d9 100644
--- a/tests/testclipboard2.c
+++ b/tests/testclipboard2.c
@@ -27,6 +27,9 @@ clipboard_changed_cb (GdkClipboard *clipboard,
child = gtk_stack_get_child_by_name (GTK_STACK (stack), "image");
gtk_image_clear (GTK_IMAGE (child));
+
+ child = gtk_stack_get_child_by_name (GTK_STACK (stack), "text");
+ gtk_label_set_text (GTK_LABEL (child), "");
}
static void
@@ -50,6 +53,26 @@ pixbuf_loaded_cb (GObject *clipboard,
}
static void
+text_loaded_cb (GObject *clipboard,
+ GAsyncResult *res,
+ gpointer data)
+{
+ GError *error = NULL;
+ char *text;
+
+ text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (clipboard), res, &error);
+ if (text == NULL)
+ {
+ g_print ("%s\n", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ gtk_label_set_text (data, text);
+ g_free (text);
+}
+
+static void
visible_child_changed_cb (GtkWidget *stack,
GParamSpec *pspec,
GdkClipboard *clipboard)
@@ -69,6 +92,15 @@ visible_child_changed_cb (GtkWidget *stack,
pixbuf_loaded_cb,
image);
}
+ else if (g_str_equal (visible_child, "text"))
+ {
+ GtkWidget *label = gtk_stack_get_child_by_name (GTK_STACK (stack), "text");
+
+ gdk_clipboard_read_text_async (clipboard,
+ NULL,
+ text_loaded_cb,
+ label);
+ }
}
static void
@@ -103,6 +135,10 @@ get_contents_widget (GdkClipboard *clipboard)
child = gtk_image_new ();
gtk_stack_add_titled (GTK_STACK (stack), child, "image", "Image");
+ child = gtk_label_new (NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (child), TRUE);
+ gtk_stack_add_titled (GTK_STACK (stack), child, "text", "Text");
+
return stack;
}