forked from AuroraMiddleware/gtk
testlist3: Use async read api for selection
This commit is contained in:
parent
b9034015d7
commit
7048790931
@ -24,19 +24,25 @@ drag_begin (GtkDragSource *source,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drag_data_received (GtkDropTarget *dest,
|
got_row (GObject *src,
|
||||||
GtkSelectionData *selection_data,
|
GAsyncResult *result,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
|
GtkDropTarget *dest = GTK_DROP_TARGET (src);
|
||||||
GtkWidget *target = data;
|
GtkWidget *target = data;
|
||||||
GtkWidget *row;
|
GtkWidget *row;
|
||||||
GtkWidget *source;
|
GtkWidget *source;
|
||||||
int pos;
|
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));
|
pos = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (target));
|
||||||
row = (gpointer)* (gpointer*)gtk_selection_data_get_data (selection_data);
|
row = (gpointer)* (gpointer*)gtk_selection_data_get_data (selection_data);
|
||||||
source = gtk_widget_get_ancestor (row, GTK_TYPE_LIST_BOX_ROW);
|
source = gtk_widget_get_ancestor (row, GTK_TYPE_LIST_BOX_ROW);
|
||||||
|
|
||||||
|
gtk_selection_data_free (selection_data);
|
||||||
|
|
||||||
if (source == target)
|
if (source == target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -46,6 +52,15 @@ drag_data_received (GtkDropTarget *dest,
|
|||||||
g_object_unref (source);
|
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 *
|
static GtkWidget *
|
||||||
create_row (const gchar *text)
|
create_row (const gchar *text)
|
||||||
{
|
{
|
||||||
@ -73,8 +88,8 @@ create_row (const gchar *text)
|
|||||||
gtk_drag_source_attach (source, image, GDK_BUTTON1_MASK);
|
gtk_drag_source_attach (source, image, GDK_BUTTON1_MASK);
|
||||||
|
|
||||||
targets = gdk_content_formats_new (entries, 1);
|
targets = gdk_content_formats_new (entries, 1);
|
||||||
dest = gtk_drop_target_new (GTK_DEST_DEFAULT_ALL, targets, GDK_ACTION_MOVE);
|
dest = gtk_drop_target_new (GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT, targets, GDK_ACTION_MOVE);
|
||||||
g_signal_connect (dest, "drag-data-received", G_CALLBACK (drag_data_received), row);
|
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), row);
|
||||||
gtk_drop_target_attach (dest, row);
|
gtk_drop_target_attach (dest, row);
|
||||||
|
|
||||||
gdk_content_formats_unref (targets);
|
gdk_content_formats_unref (targets);
|
||||||
|
Loading…
Reference in New Issue
Block a user