testtoolbar: Convert to GtkDropTarget

This commit is contained in:
Matthias Clasen 2020-01-02 08:37:06 -05:00
parent ccaf70e1b7
commit a309e74be7

View File

@ -293,11 +293,11 @@ bold_toggled (GtkToggleToolButton *button)
} }
static gboolean static gboolean
toolbar_drag_drop (GtkWidget *widget, toolbar_drag_drop (GtkDropTarget *dest,
GdkDrop *drop,
gint x, gint y, gint x, gint y,
GtkWidget *label) GtkWidget *label)
{ {
GtkWidget *widget = gtk_drop_target_get_target (dest);
gchar buf[32]; gchar buf[32];
g_snprintf(buf, sizeof(buf), "%d", g_snprintf(buf, sizeof(buf), "%d",
@ -323,13 +323,12 @@ rtl_toggled (GtkCheckButton *check)
static GtkToolItem *drag_item = NULL; static GtkToolItem *drag_item = NULL;
static gboolean static gboolean
toolbar_drag_motion (GtkToolbar *toolbar, toolbar_drag_motion (GtkDropTarget *dest,
GdkDrop *drop,
gint x, gint x,
gint y, gint y,
guint time, GtkToolbar *toolbar)
gpointer null)
{ {
GdkDrop *drop = gtk_drop_target_get_drop (dest);
gint index; gint index;
if (!drag_item) if (!drag_item)
@ -348,9 +347,8 @@ toolbar_drag_motion (GtkToolbar *toolbar,
} }
static void static void
toolbar_drag_leave (GtkToolbar *toolbar, toolbar_drag_leave (GtkDropTarget *dest,
GdkDrop *drop, GtkToolbar *toolbar)
gpointer null)
{ {
if (drag_item) if (drag_item)
{ {
@ -391,6 +389,7 @@ main (gint argc, gchar **argv)
GdkContentFormats *targets; GdkContentFormats *targets;
GdkContentProvider *content; GdkContentProvider *content;
GtkDragSource *source; GtkDragSource *source;
GtkDropTarget *dest;
static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)", static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)",
"both (horizontal)" }; "both (horizontal)" };
GtkToolItem *item; GtkToolItem *item;
@ -622,16 +621,12 @@ main (gint argc, gchar **argv)
source = gtk_drag_source_new (content, GDK_ACTION_MOVE); source = gtk_drag_source_new (content, GDK_ACTION_MOVE);
g_object_unref (content); g_object_unref (content);
gtk_drag_source_attach (source, button, GDK_BUTTON1_MASK); gtk_drag_source_attach (source, button, GDK_BUTTON1_MASK);
gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP, dest = gtk_drop_target_new (GTK_DEST_DEFAULT_DROP, targets, GDK_ACTION_MOVE);
targets, g_signal_connect (dest, "drag_motion", G_CALLBACK (toolbar_drag_motion), toolbar);
GDK_ACTION_MOVE); g_signal_connect (dest, "drag_leave", G_CALLBACK (toolbar_drag_leave), toolbar);
g_signal_connect (dest, "drag_drop", G_CALLBACK (toolbar_drag_drop), label);
gtk_drop_target_attach (dest, toolbar);
gdk_content_formats_unref (targets); gdk_content_formats_unref (targets);
g_signal_connect (toolbar, "drag_motion",
G_CALLBACK (toolbar_drag_motion), NULL);
g_signal_connect (toolbar, "drag_leave",
G_CALLBACK (toolbar_drag_leave), NULL);
g_signal_connect (toolbar, "drag_drop",
G_CALLBACK (toolbar_drag_drop), label);
gtk_widget_show (window); gtk_widget_show (window);