[gtk/dnd-gestures-2: 58/173] testlist3: Use async read api for selection
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dnd-gestures-2: 58/173] testlist3: Use async read api for selection
- Date: Wed, 8 Jan 2020 23:53:48 +0000 (UTC)
commit 7048790931fb603f045c1fc04fdd3a8da31e5170
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jan 3 00:46:31 2020 -0500
testlist3: Use async read api for selection
tests/testlist3.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/tests/testlist3.c b/tests/testlist3.c
index d1d3563873..8bce1c77b9 100644
--- a/tests/testlist3.c
+++ b/tests/testlist3.c
@@ -24,19 +24,25 @@ drag_begin (GtkDragSource *source,
}
static void
-drag_data_received (GtkDropTarget *dest,
- GtkSelectionData *selection_data,
- gpointer data)
+got_row (GObject *src,
+ GAsyncResult *result,
+ gpointer data)
{
+ GtkDropTarget *dest = GTK_DROP_TARGET (src);
GtkWidget *target = data;
GtkWidget *row;
GtkWidget *source;
int pos;
+ GtkSelectionData *selection_data;
+
+ selection_data = gtk_drop_target_read_selection_finish (dest, result, NULL);
pos = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (target));
row = (gpointer)* (gpointer*)gtk_selection_data_get_data (selection_data);
source = gtk_widget_get_ancestor (row, GTK_TYPE_LIST_BOX_ROW);
+ gtk_selection_data_free (selection_data);
+
if (source == target)
return;
@@ -46,6 +52,15 @@ drag_data_received (GtkDropTarget *dest,
g_object_unref (source);
}
+static void
+drag_drop (GtkDropTarget *dest,
+ int x,
+ int y,
+ gpointer data)
+{
+ gtk_drop_target_read_selection (dest, "GTK_LIST_BOX_ROW", NULL, got_row, data);
+}
+
static GtkWidget *
create_row (const gchar *text)
{
@@ -73,8 +88,8 @@ create_row (const gchar *text)
gtk_drag_source_attach (source, image, GDK_BUTTON1_MASK);
targets = gdk_content_formats_new (entries, 1);
- dest = gtk_drop_target_new (GTK_DEST_DEFAULT_ALL, targets, GDK_ACTION_MOVE);
- g_signal_connect (dest, "drag-data-received", G_CALLBACK (drag_data_received), row);
+ dest = gtk_drop_target_new (GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT, targets,
GDK_ACTION_MOVE);
+ g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), row);
gtk_drop_target_attach (dest, row);
gdk_content_formats_unref (targets);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]