mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-12 20:00:09 +00:00
testdnd: Fix up for current api
This commit is contained in:
parent
c7dc17d837
commit
f33fe6daed
@ -299,6 +299,7 @@ static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
|
|||||||
|
|
||||||
void
|
void
|
||||||
target_drag_leave (GtkDropTarget *dest,
|
target_drag_leave (GtkDropTarget *dest,
|
||||||
|
GdkDrop *drop,
|
||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
g_print("leave\n");
|
g_print("leave\n");
|
||||||
@ -308,11 +309,11 @@ target_drag_leave (GtkDropTarget *dest,
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
target_drag_motion (GtkDropTarget *dest,
|
target_drag_motion (GtkDropTarget *dest,
|
||||||
|
GdkDrop *drop,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (!have_drag)
|
if (!have_drag)
|
||||||
@ -342,15 +343,17 @@ got_text_in_target (GObject *object,
|
|||||||
g_print ("Received \"%s\" in target\n", str);
|
g_print ("Received \"%s\" in target\n", str);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdk_drop_finish (GDK_DROP (object), GDK_ACTION_MOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
target_drag_drop (GtkDropTarget *dest,
|
target_drag_drop (GtkDropTarget *dest,
|
||||||
|
GdkDrop *drop,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
|
||||||
GdkContentFormats *formats;
|
GdkContentFormats *formats;
|
||||||
const char *format;
|
const char *format;
|
||||||
|
|
||||||
@ -367,6 +370,8 @@ target_drag_drop (GtkDropTarget *dest,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdk_drop_status (drop, 0);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,12 +411,11 @@ got_text (GObject *object,
|
|||||||
|
|
||||||
void
|
void
|
||||||
label_drag_drop (GtkDropTarget *dest,
|
label_drag_drop (GtkDropTarget *dest,
|
||||||
|
GdkDrop *drop,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
|
||||||
|
|
||||||
gdk_drop_read_text_async (drop, NULL, got_text, widget);
|
gdk_drop_read_text_async (drop, NULL, got_text, widget);
|
||||||
GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop));
|
GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop));
|
||||||
gdk_drop_finish (drop, action);
|
gdk_drop_finish (drop, action);
|
||||||
@ -445,6 +449,14 @@ popup_motion (GtkDropTarget *dest,
|
|||||||
int x,
|
int x,
|
||||||
int y)
|
int y)
|
||||||
{
|
{
|
||||||
|
gdk_drop_status (drop, GDK_ACTION_COPY);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
popup_enter (GtkDropTarget *dest)
|
||||||
|
{
|
||||||
|
g_print ("popup enter\n");
|
||||||
if (!in_popup)
|
if (!in_popup)
|
||||||
{
|
{
|
||||||
in_popup = TRUE;
|
in_popup = TRUE;
|
||||||
@ -455,13 +467,12 @@ popup_motion (GtkDropTarget *dest,
|
|||||||
popdown_timer = 0;
|
popdown_timer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
popup_leave (GtkDropTarget *dest)
|
popup_leave (GtkDropTarget *dest)
|
||||||
{
|
{
|
||||||
|
g_print ("popup leave\n");
|
||||||
if (in_popup)
|
if (in_popup)
|
||||||
{
|
{
|
||||||
in_popup = FALSE;
|
in_popup = FALSE;
|
||||||
@ -473,6 +484,15 @@ popup_leave (GtkDropTarget *dest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
popup_drop (GtkDropTarget *dest,
|
||||||
|
GdkDrop *drop)
|
||||||
|
{
|
||||||
|
gdk_drop_finish (drop, GDK_ACTION_COPY);
|
||||||
|
popdown_cb (NULL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
popup_cb (gpointer data)
|
popup_cb (gpointer data)
|
||||||
{
|
{
|
||||||
@ -488,7 +508,7 @@ popup_cb (gpointer data)
|
|||||||
popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
||||||
|
|
||||||
grid = gtk_grid_new ();
|
grid = gtk_grid_new ();
|
||||||
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */
|
targets = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
|
||||||
|
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
for (j=0; j<3; j++)
|
for (j=0; j<3; j++)
|
||||||
@ -504,7 +524,9 @@ popup_cb (gpointer data)
|
|||||||
|
|
||||||
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
||||||
g_signal_connect (dest, "accept", G_CALLBACK (popup_motion), NULL);
|
g_signal_connect (dest, "accept", G_CALLBACK (popup_motion), NULL);
|
||||||
|
g_signal_connect (dest, "drag-enter", G_CALLBACK (popup_enter), NULL);
|
||||||
g_signal_connect (dest, "drag-leave", G_CALLBACK (popup_leave), NULL);
|
g_signal_connect (dest, "drag-leave", G_CALLBACK (popup_leave), NULL);
|
||||||
|
g_signal_connect (dest, "drag-drop", G_CALLBACK (popup_drop), NULL);
|
||||||
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
|
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
|
||||||
}
|
}
|
||||||
gtk_container_add (GTK_CONTAINER (popup_window), grid);
|
gtk_container_add (GTK_CONTAINER (popup_window), grid);
|
||||||
@ -515,9 +537,6 @@ popup_cb (gpointer data)
|
|||||||
popped_up = TRUE;
|
popped_up = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
popdown_timer = g_timeout_add (500, popdown_cb, NULL);
|
|
||||||
g_print ("added popdown\n");
|
|
||||||
|
|
||||||
popup_timer = FALSE;
|
popup_timer = FALSE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -529,15 +548,22 @@ popsite_motion (GtkDropTarget *dest,
|
|||||||
int y,
|
int y,
|
||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
popsite_enter (GtkDropTarget *dest)
|
||||||
|
{
|
||||||
|
g_print ("popsite enter\n");
|
||||||
if (!popup_timer)
|
if (!popup_timer)
|
||||||
popup_timer = g_timeout_add (500, popup_cb, NULL);
|
popup_timer = g_timeout_add (500, popup_cb, NULL);
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
popsite_leave (GtkDropTarget *dest)
|
popsite_leave (GtkDropTarget *dest)
|
||||||
{
|
{
|
||||||
|
g_print ("popsite leave\n");
|
||||||
if (popup_timer)
|
if (popup_timer)
|
||||||
{
|
{
|
||||||
g_source_remove (popup_timer);
|
g_source_remove (popup_timer);
|
||||||
@ -608,6 +634,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
||||||
g_signal_connect (dest, "accept", G_CALLBACK (popsite_motion), NULL);
|
g_signal_connect (dest, "accept", G_CALLBACK (popsite_motion), NULL);
|
||||||
|
g_signal_connect (dest, "drag-enter", G_CALLBACK (popsite_enter), NULL);
|
||||||
g_signal_connect (dest, "drag-leave", G_CALLBACK (popsite_leave), NULL);
|
g_signal_connect (dest, "drag-leave", G_CALLBACK (popsite_leave), NULL);
|
||||||
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
|
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
|
||||||
|
|
||||||
@ -633,7 +660,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
/* Drag site */
|
/* Drag site */
|
||||||
|
|
||||||
button = gtk_button_new_with_label ("Drag Here\n");
|
button = gtk_label_new ("Drag Here\n");
|
||||||
|
|
||||||
source = gtk_drag_source_new ();
|
source = gtk_drag_source_new ();
|
||||||
g_value_init (&value, G_TYPE_STRING);
|
g_value_init (&value, G_TYPE_STRING);
|
||||||
@ -652,9 +679,6 @@ main (int argc, char **argv)
|
|||||||
gtk_widget_set_vexpand (button, TRUE);
|
gtk_widget_set_vexpand (button, TRUE);
|
||||||
gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1);
|
gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1);
|
||||||
|
|
||||||
g_signal_connect (source, "drag-data-delete",
|
|
||||||
G_CALLBACK (source_drag_data_delete), NULL);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
gtk_widget_show (window);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
Loading…
Reference in New Issue
Block a user