stackswitcher: Port to GtkDropTarget

This commit is contained in:
Matthias Clasen 2020-01-02 00:21:01 -05:00
parent b0d9a6ff20
commit 07c889c5ea

View File

@ -93,6 +93,14 @@ enum {
PROP_STACK
};
static void gtk_stack_switcher_drag_leave (GtkDropTarget *dest,
GtkStackSwitcher *self);
static gboolean gtk_stack_switcher_drag_motion (GtkDropTarget *dest,
int x,
int y,
GtkStackSwitcher *self);
G_DEFINE_TYPE_WITH_PRIVATE (GtkStackSwitcher, gtk_stack_switcher, GTK_TYPE_WIDGET)
static void
@ -100,14 +108,21 @@ gtk_stack_switcher_init (GtkStackSwitcher *switcher)
{
GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (switcher);
GtkStyleContext *context;
GdkContentFormats *formats;
GtkDropTarget *dest;
priv->buttons = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
context = gtk_widget_get_style_context (GTK_WIDGET (switcher));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
gtk_drag_dest_set (GTK_WIDGET (switcher), 0, NULL, 0);
gtk_drag_dest_set_track_motion (GTK_WIDGET (switcher), TRUE);
formats = gdk_content_formats_new (NULL, 0);
dest = gtk_drop_target_new (0, formats, 0);
gdk_content_formats_unref (formats);
gtk_drop_target_set_track_motion (dest, TRUE);
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_stack_switcher_drag_leave), switcher);
g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_stack_switcher_drag_motion), switcher);
gtk_drop_target_attach (dest, GTK_WIDGET (switcher));
}
static void
@ -249,12 +264,11 @@ gtk_stack_switcher_switch_timeout (gpointer data)
}
static gboolean
gtk_stack_switcher_drag_motion (GtkWidget *widget,
GdkDrop *drop,
gint x,
gint y)
gtk_stack_switcher_drag_motion (GtkDropTarget *dest,
int x,
int y,
GtkStackSwitcher *self)
{
GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget);
GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (self);
GtkWidget *button;
GHashTableIter iter;
@ -292,11 +306,9 @@ gtk_stack_switcher_drag_motion (GtkWidget *widget,
}
static void
gtk_stack_switcher_drag_leave (GtkWidget *widget,
GdkDrop *drop)
gtk_stack_switcher_drag_leave (GtkDropTarget *dest,
GtkStackSwitcher *self)
{
GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget);
remove_switch_timer (self);
}
@ -562,9 +574,6 @@ gtk_stack_switcher_class_init (GtkStackSwitcherClass *class)
object_class->dispose = gtk_stack_switcher_dispose;
object_class->finalize = gtk_stack_switcher_finalize;
widget_class->drag_motion = gtk_stack_switcher_drag_motion;
widget_class->drag_leave = gtk_stack_switcher_drag_leave;
g_object_class_install_property (object_class,
PROP_STACK,
g_param_spec_object ("stack",