Commit aad116c1 authored by Dominique Lasserre's avatar Dominique Lasserre Committed by Sebastien Granjoux

New setting tab-pos for GdlSwitcher.

 * tab-pos has only an effect with GDL_SWITCHER_STYLE_TABS style.
 * Also update example.
parent ff578fc8
......@@ -111,6 +111,8 @@ static void gdl_dock_master_layout_changed (GdlDockMaster *master);
static void gdl_dock_master_set_switcher_style (GdlDockMaster *master,
GdlSwitcherStyle switcher_style);
static void gdl_dock_master_set_tab_pos (GdlDockMaster *master,
GtkPositionType pos);
/* ----- Private data types and variables ----- */
......@@ -118,7 +120,8 @@ enum {
PROP_0,
PROP_DEFAULT_TITLE,
PROP_LOCKED,
PROP_SWITCHER_STYLE
PROP_SWITCHER_STYLE,
PROP_TAB_POS
};
enum {
......@@ -152,6 +155,7 @@ struct _GdlDockMasterPrivate {
GHashTable *unlocked_items;
GdlSwitcherStyle switcher_style;
GtkPositionType tab_pos;
/* Window for preview rect */
GtkWidget* area_window;
......@@ -206,6 +210,14 @@ gdl_dock_master_class_init (GdlDockMasterClass *klass)
GDL_SWITCHER_STYLE_BOTH,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class, PROP_TAB_POS,
g_param_spec_enum ("tab-pos", _("Tab Position"),
_("Which side of the notebook holds the tabs"),
GTK_TYPE_POSITION_TYPE,
GTK_POS_BOTTOM,
G_PARAM_READWRITE));
/**
* GdlDockMaster::layout-changed:
*
......@@ -241,6 +253,7 @@ gdl_dock_master_init (GdlDockMaster *master)
master->priv->number = 1;
master->priv->switcher_style = GDL_SWITCHER_STYLE_BOTH;
master->priv->tab_pos = GTK_POS_BOTTOM;
master->priv->locked_items = g_hash_table_new (g_direct_hash, g_direct_equal);
master->priv->unlocked_items = g_hash_table_new (g_direct_hash, g_direct_equal);
}
......@@ -426,6 +439,9 @@ gdl_dock_master_set_property (GObject *object,
case PROP_SWITCHER_STYLE:
gdl_dock_master_set_switcher_style (master, g_value_get_enum (value));
break;
case PROP_TAB_POS:
gdl_dock_master_set_tab_pos (master, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -450,6 +466,9 @@ gdl_dock_master_get_property (GObject *object,
case PROP_SWITCHER_STYLE:
g_value_set_enum (value, master->priv->switcher_style);
break;
case PROP_TAB_POS:
g_value_set_enum (value, master->priv->tab_pos);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -883,12 +902,15 @@ gdl_dock_master_add (GdlDockMaster *master,
item_notify_cb (object, NULL, master);
}
/* If the item is notebook, set the switcher style */
/* If the item is notebook, set the switcher style and tab position */
if (GDL_IS_DOCK_NOTEBOOK (object) &&
GDL_IS_SWITCHER (gdl_dock_item_get_child (GDL_DOCK_ITEM (object))))
{
g_object_set (gdl_dock_item_get_child (GDL_DOCK_ITEM (object)), "switcher-style",
GtkWidget *child = gdl_dock_item_get_child (GDL_DOCK_ITEM (object));
g_object_set (child, "switcher-style",
master->priv->switcher_style, NULL);
g_object_set (child, "tab-pos",
master->priv->tab_pos, NULL);
}
/* post a layout_changed emission if the item is not automatic
......@@ -1131,3 +1153,46 @@ gdl_dock_master_set_switcher_style (GdlDockMaster *master,
GINT_TO_POINTER (switcher_style));
}
static void
set_tab_pos_foreach (GtkWidget *obj, gpointer user_data)
{
GtkPositionType tab_pos = GPOINTER_TO_INT (user_data);
if (!GDL_IS_DOCK_ITEM (obj))
return;
if (GDL_IS_DOCK_NOTEBOOK (obj)) {
GtkWidget *child = gdl_dock_item_get_child (GDL_DOCK_ITEM (obj));
if (GDL_IS_SWITCHER (child)) {
g_object_set (child, "tab-pos", tab_pos, NULL);
}
} else if (gdl_dock_object_is_compound (GDL_DOCK_OBJECT (obj))) {
gtk_container_foreach (GTK_CONTAINER (obj),
set_tab_pos_foreach,
user_data);
}
}
static void
gdl_dock_master_set_tab_pos (GdlDockMaster *master,
GtkPositionType tab_pos)
{
GList *l;
g_return_if_fail (GDL_IS_DOCK_MASTER (master));
master->priv->tab_pos = tab_pos;
for (l = master->priv->toplevel_docks; l; l = l->next) {
GdlDock *dock = GDL_DOCK (l->data);
GtkWidget *root = GTK_WIDGET (gdl_dock_get_root (dock));
if (root != NULL)
set_tab_pos_foreach (root,
GINT_TO_POINTER (tab_pos));
}
/* just to be sure hidden items are set too */
gdl_dock_master_foreach (master, (GFunc) set_tab_pos_foreach,
GINT_TO_POINTER (tab_pos));
}
......@@ -74,11 +74,13 @@ static void gdl_switcher_set_show_buttons (GdlSwitcher *switcher, gboolean show)
static void gdl_switcher_set_style (GdlSwitcher *switcher,
GdlSwitcherStyle switcher_style);
static GdlSwitcherStyle gdl_switcher_get_style (GdlSwitcher *switcher);
static void gdl_switcher_set_tab_pos (GdlSwitcher *switcher, GtkPositionType pos);
static void gdl_switcher_update_lone_button_visibility (GdlSwitcher *switcher);
enum {
PROP_0,
PROP_SWITCHER_STYLE
PROP_SWITCHER_STYLE,
PROP_TAB_POS
};
typedef struct {
......@@ -94,6 +96,7 @@ typedef struct {
struct _GdlSwitcherPrivate {
GdlSwitcherStyle switcher_style;
GdlSwitcherStyle toolbar_style;
GtkPositionType tab_pos;
gboolean show;
GSList *buttons;
......@@ -729,6 +732,9 @@ gdl_switcher_set_property (GObject *object,
case PROP_SWITCHER_STYLE:
gdl_switcher_set_style (switcher, g_value_get_enum (value));
break;
case PROP_TAB_POS:
gdl_switcher_set_tab_pos (switcher, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -747,6 +753,9 @@ gdl_switcher_get_property (GObject *object,
case PROP_SWITCHER_STYLE:
g_value_set_enum (value, gdl_switcher_get_style (switcher));
break;
case PROP_TAB_POS:
g_value_set_enum (value, switcher->priv->tab_pos);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -880,6 +889,14 @@ gdl_switcher_class_init (GdlSwitcherClass *klass)
GDL_SWITCHER_STYLE_BOTH,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class, PROP_TAB_POS,
g_param_spec_enum ("tab-pos", _("Tab Position"),
_("Which side of the notebook holds the tabs"),
GTK_TYPE_POSITION_TYPE,
GTK_POS_BOTTOM,
G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GdlSwitcherPrivate));
/* set the style */
......@@ -903,6 +920,7 @@ gdl_switcher_init (GdlSwitcher *switcher)
priv->show = TRUE;
priv->buttons_height_request = -1;
priv->tab_pos = GTK_POS_BOTTOM;
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (switcher), GTK_POS_BOTTOM);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), FALSE);
......@@ -1213,3 +1231,14 @@ gdl_switcher_get_style (GdlSwitcher *switcher)
return GDL_SWITCHER_STYLE_TABS;
return switcher->priv->switcher_style;
}
static void
gdl_switcher_set_tab_pos (GdlSwitcher *switcher, GtkPositionType pos)
{
if (switcher->priv->tab_pos == pos)
return;
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (switcher), pos);
switcher->priv->tab_pos = pos;
}
......@@ -209,6 +209,8 @@ main (int argc, char **argv)
/* create the dock */
dock = gdl_dock_new ();
GdlDockMaster *master = GDL_DOCK_MASTER (gdl_dock_object_get_master (GDL_DOCK_OBJECT (dock)));
g_object_set (master, "tab-pos", GTK_POS_TOP, NULL);
/* ... and the layout manager */
layout = gdl_dock_layout_new (G_OBJECT (dock));
......
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