[gthumb] use a GtkStack instead of a GtkNotebook



commit b99b6b821dd579d9c12557d9bb06e83cba46a37a
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Oct 21 23:40:20 2013 +0200

    use a GtkStack instead of a GtkNotebook

 gthumb/gth-multipage.c |   31 ++++++++++++++++++++-----------
 gthumb/gth-sidebar.c   |   23 ++++++++---------------
 gthumb/gth-sidebar.h   |    4 ++--
 gthumb/gth-toolbox.c   |   20 ++++++++------------
 gthumb/gth-toolbox.h   |    4 ++--
 5 files changed, 40 insertions(+), 42 deletions(-)
---
diff --git a/gthumb/gth-multipage.c b/gthumb/gth-multipage.c
index 7d13c0c..b6451ff 100644
--- a/gthumb/gth-multipage.c
+++ b/gthumb/gth-multipage.c
@@ -27,6 +27,7 @@
 
 #define GTH_MULTIPAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_MULTIPAGE, 
GthMultipagePrivate))
 
+
 enum {
        CHANGED,
        LAST_SIGNAL
@@ -36,6 +37,7 @@ enum {
 enum {
        ICON_COLUMN,
        NAME_COLUMN,
+       CHILD_COLUMN,
        N_COLUMNS
 };
 
@@ -46,7 +48,7 @@ static guint gth_multipage_signals[LAST_SIGNAL] = { 0 };
 struct _GthMultipagePrivate {
        GtkListStore *model;
        GtkWidget    *combobox;
-       GtkWidget    *notebook;
+       GtkWidget    *stack;
        GList        *children;
 };
 
@@ -96,9 +98,16 @@ combobox_changed_cb (GtkComboBox *widget,
                     gpointer     user_data)
 {
        GthMultipage *multipage = user_data;
+       GtkTreeIter   iter;
+       GtkWidget    *child;
+
+       if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (multipage->priv->combobox), &iter))
+               return;
 
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (multipage->priv->notebook),
-                                      gtk_combo_box_get_active (GTK_COMBO_BOX (multipage->priv->combobox)));
+       gtk_tree_model_get (GTK_TREE_MODEL (multipage->priv->model), &iter,
+                           CHILD_COLUMN, &child,
+                           -1);
+       gtk_stack_set_visible_child (GTK_STACK (multipage->priv->stack), child);
        g_signal_emit (G_OBJECT (multipage), gth_multipage_signals[CHANGED], 0);
 }
 
@@ -150,7 +159,8 @@ gth_multipage_init (GthMultipage *multipage)
                          multipage);
        multipage->priv->model = gtk_list_store_new (N_COLUMNS,
                                                     G_TYPE_STRING,
-                                                    G_TYPE_STRING);
+                                                    G_TYPE_STRING,
+                                                    G_TYPE_POINTER);
        multipage->priv->combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (multipage->priv->model));
        gtk_widget_show (multipage->priv->combobox);
        gtk_box_pack_start (GTK_BOX (multipage), multipage->priv->combobox, FALSE, FALSE, 0);
@@ -183,13 +193,11 @@ gth_multipage_init (GthMultipage *multipage)
                                         "text", NAME_COLUMN,
                                         NULL);
 
-       /* notebook */
+       /* stack */
 
-       multipage->priv->notebook = gtk_notebook_new ();
-       gtk_notebook_set_show_tabs (GTK_NOTEBOOK (multipage->priv->notebook), FALSE);
-       gtk_notebook_set_show_border (GTK_NOTEBOOK (multipage->priv->notebook), FALSE);
-       gtk_widget_show (multipage->priv->notebook);
-       gtk_box_pack_start (GTK_BOX (multipage), multipage->priv->notebook, TRUE, TRUE, 0);
+       multipage->priv->stack = gtk_stack_new ();
+       gtk_widget_show (multipage->priv->stack);
+       gtk_box_pack_start (GTK_BOX (multipage), multipage->priv->stack, TRUE, TRUE, 0);
 }
 
 
@@ -213,12 +221,13 @@ gth_multipage_add_child (GthMultipage      *multipage,
        gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (child), TRUE, TRUE, 0);
        gtk_widget_show (GTK_WIDGET (child));
        gtk_widget_show (box);
-       gtk_notebook_append_page (GTK_NOTEBOOK (multipage->priv->notebook), box, NULL);
+       gtk_container_add (GTK_CONTAINER (multipage->priv->stack), box);
 
        gtk_list_store_append (GTK_LIST_STORE (multipage->priv->model), &iter);
        gtk_list_store_set (GTK_LIST_STORE (multipage->priv->model), &iter,
                            NAME_COLUMN, gth_multipage_child_get_name (child),
                            ICON_COLUMN, gth_multipage_child_get_icon (child),
+                           CHILD_COLUMN, box,
                            -1);
 }
 
diff --git a/gthumb/gth-sidebar.c b/gthumb/gth-sidebar.c
index 66ab62d..bd7aecb 100644
--- a/gthumb/gth-sidebar.c
+++ b/gthumb/gth-sidebar.c
@@ -30,12 +30,8 @@
 
 
 #define GTH_SIDEBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_SIDEBAR, GthSidebarPrivate))
-
-
-enum {
-       GTH_SIDEBAR_PAGE_PROPERTIES,
-       GTH_SIDEBAR_PAGE_TOOLS
-};
+#define GTH_SIDEBAR_PAGE_PROPERTIES "GthSidebar.Properties"
+#define GTH_SIDEBAR_PAGE_TOOLS "GthSidebar.Tools"
 
 
 struct _GthSidebarPrivate {
@@ -46,7 +42,7 @@ struct _GthSidebarPrivate {
 };
 
 
-G_DEFINE_TYPE (GthSidebar, gth_sidebar, GTK_TYPE_NOTEBOOK)
+G_DEFINE_TYPE (GthSidebar, gth_sidebar, GTK_TYPE_STACK)
 
 
 static void
@@ -65,7 +61,7 @@ static gboolean
 _gth_sidebar_properties_visible (GthSidebar *sidebar)
 {
        return (gtk_widget_get_mapped (GTK_WIDGET (sidebar->priv->properties))
-               && (gtk_notebook_get_current_page (GTK_NOTEBOOK (sidebar)) == GTH_SIDEBAR_PAGE_PROPERTIES));
+               && (g_strcmp0 (gtk_stack_get_visible_child_name (GTK_STACK (sidebar)), 
GTH_SIDEBAR_PAGE_PROPERTIES) == 0));
 }
 
 
@@ -112,9 +108,6 @@ gth_sidebar_init (GthSidebar *sidebar)
        sidebar->priv = GTH_SIDEBAR_GET_PRIVATE (sidebar);
        sidebar->priv->dirty = NULL;
        sidebar->priv->file_data = NULL;
-
-       gtk_notebook_set_show_tabs (GTK_NOTEBOOK (sidebar), FALSE);
-       gtk_notebook_set_show_border (GTK_NOTEBOOK (sidebar), FALSE);
 }
 
 
@@ -146,7 +139,7 @@ _gth_sidebar_construct (GthSidebar *sidebar,
 {
        sidebar->priv->properties = gth_multipage_new ();
        gtk_widget_show (sidebar->priv->properties);
-       gtk_notebook_append_page (GTK_NOTEBOOK (sidebar), sidebar->priv->properties, NULL);
+       gtk_stack_add_named (GTK_STACK (sidebar), sidebar->priv->properties, GTH_SIDEBAR_PAGE_PROPERTIES);
 
        g_signal_connect_swapped (sidebar->priv->properties,
                                  "map",
@@ -159,7 +152,7 @@ _gth_sidebar_construct (GthSidebar *sidebar,
 
        sidebar->priv->toolbox = gth_toolbox_new (name);
        gtk_widget_show (sidebar->priv->toolbox);
-       gtk_notebook_append_page (GTK_NOTEBOOK (sidebar), sidebar->priv->toolbox, NULL);
+       gtk_stack_add_named (GTK_STACK (sidebar), sidebar->priv->toolbox, GTH_SIDEBAR_PAGE_TOOLS);
 }
 
 
@@ -226,14 +219,14 @@ gth_sidebar_set_file (GthSidebar  *sidebar,
 void
 gth_sidebar_show_properties (GthSidebar *sidebar)
 {
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (sidebar), GTH_SIDEBAR_PAGE_PROPERTIES);
+       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), GTH_SIDEBAR_PAGE_PROPERTIES);
 }
 
 
 void
 gth_sidebar_show_tools (GthSidebar *sidebar)
 {
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (sidebar), GTH_SIDEBAR_PAGE_TOOLS);
+       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), GTH_SIDEBAR_PAGE_TOOLS);
 }
 
 
diff --git a/gthumb/gth-sidebar.h b/gthumb/gth-sidebar.h
index cacf0ba..4c2cad0 100644
--- a/gthumb/gth-sidebar.h
+++ b/gthumb/gth-sidebar.h
@@ -51,13 +51,13 @@ typedef struct _GthSidebarPrivate GthSidebarPrivate;
 
 struct _GthSidebar
 {
-       GtkNotebook __parent;
+       GtkStack __parent;
        GthSidebarPrivate *priv;
 };
 
 struct _GthSidebarClass
 {
-       GtkNotebookClass __parent_class;
+       GtkStackClass __parent_class;
 };
 
 typedef struct _GthPropertyView GthPropertyView;
diff --git a/gthumb/gth-toolbox.c b/gthumb/gth-toolbox.c
index 4cc3ae4..3a86d5a 100644
--- a/gthumb/gth-toolbox.c
+++ b/gthumb/gth-toolbox.c
@@ -27,10 +27,8 @@
 #include "gtk-utils.h"
 
 
-enum {
-       GTH_TOOLBOX_LIST_PAGE = 0,
-       GTH_TOOLBOX_OPTIONS_PAGE
-};
+#define GTH_TOOLBOX_PAGE_TOOLS "GthToolbox.Tools"
+#define GTH_TOOLBOX_PAGE_OPTIONS "GthToolbox.Options"
 
 
 enum  {
@@ -49,7 +47,7 @@ struct _GthToolboxPrivate {
 };
 
 
-G_DEFINE_TYPE (GthToolbox, gth_toolbox, GTK_TYPE_NOTEBOOK)
+G_DEFINE_TYPE (GthToolbox, gth_toolbox, GTK_TYPE_STACK)
 
 
 static void
@@ -128,18 +126,16 @@ gth_toolbox_init (GthToolbox *toolbox)
        GtkWidget *header_align;
 
        toolbox->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbox, GTH_TYPE_TOOLBOX, GthToolboxPrivate);
-       gtk_notebook_set_show_tabs (GTK_NOTEBOOK (toolbox), FALSE);
-       gtk_notebook_set_show_border (GTK_NOTEBOOK (toolbox), FALSE);
 
        /* tool list page */
 
        scrolled = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN);
+       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_NONE);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
                                        GTK_POLICY_AUTOMATIC,
                                        GTK_POLICY_AUTOMATIC);
        gtk_widget_show (scrolled);
-       gtk_notebook_append_page (GTK_NOTEBOOK (toolbox), scrolled, NULL);
+       gtk_stack_add_named (GTK_STACK (toolbox), scrolled, GTH_TOOLBOX_PAGE_TOOLS);
 
        toolbox->priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        gtk_box_set_spacing (GTK_BOX (toolbox->priv->box), 0);
@@ -150,7 +146,7 @@ gth_toolbox_init (GthToolbox *toolbox)
 
        options_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        gtk_widget_show (options_box);
-       gtk_notebook_append_page (GTK_NOTEBOOK (toolbox), options_box, NULL);
+       gtk_stack_add_named (GTK_STACK (toolbox), options_box, GTH_TOOLBOX_PAGE_OPTIONS);
 
        header_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (header_align), 5, 5, 0, 0);
@@ -207,7 +203,7 @@ child_show_options_cb (GtkWidget *tool,
        gtk_label_set_markup (GTK_LABEL (toolbox->priv->options_title), markup);
        gtk_image_set_from_icon_name (GTK_IMAGE (toolbox->priv->options_icon), gth_file_tool_get_icon_name 
(GTH_FILE_TOOL (tool)), GTK_ICON_SIZE_LARGE_TOOLBAR);
        gtk_container_add (GTK_CONTAINER (toolbox->priv->options), options);
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (toolbox), GTH_TOOLBOX_OPTIONS_PAGE);
+       gtk_stack_set_visible_child_name (GTK_STACK (toolbox), GTH_TOOLBOX_PAGE_OPTIONS);
 
        g_free (markup);
 }
@@ -224,7 +220,7 @@ child_hide_options_cb (GtkWidget *tool,
        tool_options = gtk_bin_get_child (GTK_BIN (toolbox->priv->options));
        if (tool_options != NULL)
                gtk_container_remove (GTK_CONTAINER (toolbox->priv->options), tool_options);
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (toolbox), GTH_TOOLBOX_LIST_PAGE);
+       gtk_stack_set_visible_child_name (GTK_STACK (toolbox), GTH_TOOLBOX_PAGE_TOOLS);
        gth_toolbox_update_sensitivity (GTH_TOOLBOX (toolbox));
 
        toolbox->priv->active_tool = NULL;
diff --git a/gthumb/gth-toolbox.h b/gthumb/gth-toolbox.h
index 25eeeb4..61e33e6 100644
--- a/gthumb/gth-toolbox.h
+++ b/gthumb/gth-toolbox.h
@@ -39,13 +39,13 @@ typedef struct _GthToolboxPrivate GthToolboxPrivate;
 
 struct _GthToolbox
 {
-       GtkNotebook __parent;
+       GtkStack __parent;
        GthToolboxPrivate *priv;
 };
 
 struct _GthToolboxClass
 {
-       GtkNotebookClass __parent_class;
+       GtkStackClass __parent_class;
 };
 
 GType          gth_toolbox_get_type              (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]