Commit 6558ab4b authored by Matthias Clasen's avatar Matthias Clasen

tab strip: Allow custom tabs

Add a ::create-tab signal that can be used to override the default
choice of simple or closable tabs with a custom tab implementation.
parent 76da4b48
......@@ -31,7 +31,6 @@
/*
* TODO:
* - custom tabs
* - reordering
* - dnd
* - other edges
......@@ -63,6 +62,13 @@ enum {
static GParamSpec *properties[N_PROPS];
enum {
CREATE_TAB,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
gtk_tab_strip_add (GtkContainer *container,
GtkWidget *widget)
......@@ -137,6 +143,9 @@ gtk_tab_strip_set_property (GObject *object,
}
}
static GtkTab *gtk_tab_strip_real_create_tab (GtkTabStrip *self,
GtkWidget *widget);
static void
gtk_tab_strip_class_init (GtkTabStripClass *klass)
{
......@@ -151,6 +160,18 @@ gtk_tab_strip_class_init (GtkTabStripClass *klass)
container_class->add = gtk_tab_strip_add;
klass->create_tab = gtk_tab_strip_real_create_tab;
signals[CREATE_TAB] =
g_signal_new (I_("create-tab"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkTabStripClass, create_tab),
gtk_object_handled_accumulator, NULL,
NULL,
GTK_TYPE_TAB, 1,
GTK_TYPE_WIDGET);
properties[PROP_STACK] =
g_param_spec_object ("stack", P_("Stack"), P_("The stack of items to manage"),
GTK_TYPE_STACK,
......@@ -413,6 +434,17 @@ tab_activated (GtkTab *tab,
gtk_stack_set_visible_child (priv->stack, widget);
}
static GtkTab *
gtk_tab_strip_real_create_tab (GtkTabStrip *self,
GtkWidget *widget)
{
GtkTabStripPrivate *priv = gtk_tab_strip_get_instance_private (self);
return g_object_new (priv->closable ? GTK_TYPE_CLOSABLE_TAB : GTK_TYPE_SIMPLE_TAB,
"widget", widget,
NULL);
}
static void
gtk_tab_strip_stack_add (GtkTabStrip *self,
GtkWidget *widget,
......@@ -426,9 +458,7 @@ gtk_tab_strip_stack_add (GtkTabStrip *self,
"position", &position,
NULL);
tab = g_object_new (priv->closable ? GTK_TYPE_CLOSABLE_TAB : GTK_TYPE_SIMPLE_TAB,
"widget", widget,
NULL);
g_signal_emit (self, signals[CREATE_TAB], 0, widget, &tab);
g_object_set_data (G_OBJECT (widget), "GTK_TAB", tab);
......
......@@ -25,6 +25,7 @@
#include <gtk/gtkbox.h>
#include <gtk/gtkstack.h>
#include <gtk/gtktab.h>
#include <gtk/gtktypebuiltins.h>
G_BEGIN_DECLS
......@@ -47,6 +48,17 @@ struct _GtkTabStrip
struct _GtkTabStripClass
{
GtkBoxClass parent_class;
GtkTab * (* create_tab) (GtkTabStrip *self,
GtkWidget *child);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
};
GDK_AVAILABLE_IN_3_22
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment