[gtk+/wip/matthiasc/tab-strip: 8/10] tab strip: Allow custom tabs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/tab-strip: 8/10] tab strip: Allow custom tabs
- Date: Sat, 21 May 2016 20:19:11 +0000 (UTC)
commit 6558ab4bb3efb6c6f146db0a29056445c5700e9d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat May 21 11:05:32 2016 -0400
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.
gtk/gtktabstrip.c | 38 ++++++++++++++++++++++++++++++++++----
gtk/gtktabstrip.h | 12 ++++++++++++
2 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtktabstrip.c b/gtk/gtktabstrip.c
index 12546d3..67c16b6 100644
--- a/gtk/gtktabstrip.c
+++ b/gtk/gtktabstrip.c
@@ -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);
diff --git a/gtk/gtktabstrip.h b/gtk/gtktabstrip.h
index ec63cc8..ccb4f7c 100644
--- a/gtk/gtktabstrip.h
+++ b/gtk/gtktabstrip.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]