[gtk+] Add GtkSidebar
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add GtkSidebar
- Date: Wed, 1 Oct 2014 04:52:23 +0000 (UTC)
commit cdd2651db054ecd6cd92c9d1ad728fff7cd7ff33
Author: Ikey Doherty <michael i doherty intel com>
Date: Sat Aug 23 17:38:42 2014 +0100
Add GtkSidebar
GtkSidebar behaves internally much like GtkStackSwitcher, providing a vertical
sidebar like widget. It is virtually identical in appearance to the widget
currently used in GNOME Tweak Tool.
This widget is connected to a GtkStack, and builds its own contents as a
GtkListBox subclass, using the "title" child property to provide a consistent
navigatable widget.
Being a subclass of GtkListBox it benefits immediately from strong keyboard
navigation, and minimal changes are required for theming.
https://bugzilla.gnome.org/show_bug.cgi?id=735293
Signed-off-by: Ikey Doherty <michael i doherty intel com>
demos/gtk-demo/Makefile.am | 1 +
demos/gtk-demo/demo.gresource.xml | 1 +
demos/gtk-demo/sidebar.c | 77 +++++
docs/reference/gtk/gtk-docs.sgml | 1 +
docs/reference/gtk/gtk3-sections.txt | 20 ++
docs/reference/gtk/gtk3.types.in | 1 +
docs/reference/gtk/images/sidebar.png | Bin 0 -> 8465 bytes
docs/reference/gtk/visual_index.xml | 3 +
gtk/Makefile.am | 2 +
gtk/gtk.h | 1 +
gtk/gtksidebar.c | 499 +++++++++++++++++++++++++++++++++
gtk/gtksidebar.h | 74 +++++
gtk/makefile.msc.in | 2 +
tests/teststack.c | 13 +-
14 files changed, 693 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 0ef288f..6b0b8da 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -48,6 +48,7 @@ demos = \
rotated_text.c \
search_entry.c \
search_entry2.c \
+ sidebar.c \
sizegroup.c \
spinner.c \
stack.c \
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 4f90eb4..e9c628d 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -118,6 +118,7 @@
<file>search_entry.c</file>
<file>search_entry2.c</file>
<file>sizegroup.c</file>
+ <file>sidebar.c</file>
<file>stack.c</file>
<file>spinner.c</file>
<file>textview.c</file>
diff --git a/demos/gtk-demo/sidebar.c b/demos/gtk-demo/sidebar.c
new file mode 100644
index 0000000..2d373f4
--- /dev/null
+++ b/demos/gtk-demo/sidebar.c
@@ -0,0 +1,77 @@
+/* Sidebar
+ *
+ * GtkSidebar provides an automatic sidebar widget to control navigation
+ * of a GtkStack object. This widget automatically updates it content
+ * based on what is presently available in the GtkStack object, and
+ * using the "title" child property to set the display labels.
+ */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+static GtkWidget *window = NULL;
+
+GtkWidget *
+do_sidebar (GtkWidget *do_widget)
+{
+ GtkWidget *sidebar;
+ GtkWidget *stack;
+ GtkWidget *box;
+ GtkWidget *widget;
+ GtkWidget *header;
+ const gchar* pages[] = { "Welcome to GTK+", "GtkSidebar Widget", "Automatic navigation", "Consistent
appearance", NULL };
+ const gchar *c = NULL;
+ guint i;
+
+ if (!window)
+ {
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
+ gtk_widget_set_size_request (window, 500, 350);
+
+ header = gtk_header_bar_new ();
+ gtk_header_bar_set_show_close_button (GTK_HEADER_BAR(header), TRUE);
+ gtk_window_set_titlebar (GTK_WINDOW(window), header);
+ gtk_window_set_title (GTK_WINDOW(window), "Sidebar demo");
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ sidebar = gtk_sidebar_new ();
+ gtk_box_pack_start (GTK_BOX (box), sidebar, FALSE, FALSE, 0);
+
+ stack = gtk_stack_new ();
+ gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
+ gtk_sidebar_set_stack (GTK_SIDEBAR (sidebar), GTK_STACK (stack));
+
+ /* Separator between sidebar and stack */
+ widget = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+ gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (box), stack, TRUE, TRUE, 0);
+
+ for (i=0; (c = *(pages+i)) != NULL; i++ )
+ {
+ if (i == 0)
+ {
+ widget = gtk_image_new_from_icon_name ("help-about", GTK_ICON_SIZE_INVALID);
+ gtk_image_set_pixel_size (GTK_IMAGE (widget), 256);
+ } else
+ {
+ widget = gtk_label_new (c);
+ }
+ gtk_stack_add_named (GTK_STACK (stack), widget, c);
+ gtk_container_child_set (GTK_CONTAINER (stack), widget, "title", c, NULL);
+ }
+
+ gtk_container_add (GTK_CONTAINER (window), box);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show_all (window);
+ else
+ gtk_widget_destroy (window);
+
+ return window;
+}
diff --git a/docs/reference/gtk/gtk-docs.sgml b/docs/reference/gtk/gtk-docs.sgml
index 2e00bae..e3956d6 100644
--- a/docs/reference/gtk/gtk-docs.sgml
+++ b/docs/reference/gtk/gtk-docs.sgml
@@ -76,6 +76,7 @@
<xi:include href="xml/gtkflowbox.xml" />
<xi:include href="xml/gtkstack.xml" />
<xi:include href="xml/gtkstackswitcher.xml" />
+ <xi:include href="xml/gtksidebar.xml" />
<xi:include href="xml/gtkactionbar.xml" />
<xi:include href="xml/gtkheaderbar.xml" />
<xi:include href="xml/gtkoverlay.xml" />
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 41fb440..9058cd7 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -8157,3 +8157,23 @@ GTK_GESTURE_ZOOM_GET_CLASS
<SUBSECTION Private>
gtk_gesture_zoom_get_type
</SECTION>
+
+
+<SECTION>
+<FILE>gtksidebar</FILE>
+GtkSidebar
+GtkSidebarClass
+gtk_sidebar_new
+
+<SUBSECTION Standard>
+GTK_TYPE_SIDEBAR
+GTK_SIDEBAR
+GTK_SIDEBAR_CLASS
+GTK_IS_SIDEBAR
+GTK_IS_SIDEBAR_CLASS
+GTK_SIDEBAR_GET_CLASS
+
+<SUBSECTION Private>
+GtkSidebarPrivate
+gtk_sidebar_get_type
+</SECTION>
diff --git a/docs/reference/gtk/gtk3.types.in b/docs/reference/gtk/gtk3.types.in
index 87c6d8f..be467ff 100644
--- a/docs/reference/gtk/gtk3.types.in
+++ b/docs/reference/gtk/gtk3.types.in
@@ -170,6 +170,7 @@ gtk_separator_get_type
gtk_separator_menu_item_get_type
gtk_separator_tool_item_get_type
gtk_settings_get_type
+gtk_sidebar_get_type
gtk_size_group_get_type
@ENABLE_ON_X11 gtk_socket_get_type
gtk_spin_button_get_type
diff --git a/docs/reference/gtk/images/sidebar.png b/docs/reference/gtk/images/sidebar.png
new file mode 100644
index 0000000..d7be78f
Binary files /dev/null and b/docs/reference/gtk/images/sidebar.png differ
diff --git a/docs/reference/gtk/visual_index.xml b/docs/reference/gtk/visual_index.xml
index 5806d39..b9e1430 100644
--- a/docs/reference/gtk/visual_index.xml
+++ b/docs/reference/gtk/visual_index.xml
@@ -141,6 +141,9 @@
<link linkend="GtkStackSwitcher">
<inlinegraphic fileref="stackswitcher.png" format="PNG"></inlinegraphic>
</link>
+ <link linkend="GtkSidebar">
+ <inlinegraphic fileref="sidebar.png" format="PNG"></inlinegraphic>
+ </link>
<link linkend="GtkTreeView">
<inlinegraphic fileref="list-and-tree.png" format="PNG"></inlinegraphic>
</link>
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index f1de3f7..fcae22b 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -431,6 +431,7 @@ gtk_public_h_sources = \
gtkseparatortoolitem.h \
gtksettings.h \
gtkshow.h \
+ gtksidebar.h \
gtksizegroup.h \
gtksizerequest.h \
gtksocket.h \
@@ -1027,6 +1028,7 @@ gtk_base_c_sources = \
gtksizerequest.c \
gtksizerequestcache.c \
gtkshow.c \
+ gtksidebar.c \
gtkspinbutton.c \
gtkspinner.c \
gtkstack.c \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index b027dc6..330f14a 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -180,6 +180,7 @@
#include <gtk/gtkseparatortoolitem.h>
#include <gtk/gtksettings.h>
#include <gtk/gtkshow.h>
+#include <gtk/gtksidebar.h>
#include <gtk/gtksizegroup.h>
#include <gtk/gtksizerequest.h>
#include <gtk/gtkspinbutton.h>
diff --git a/gtk/gtksidebar.c b/gtk/gtksidebar.c
new file mode 100644
index 0000000..aafdfe9
--- /dev/null
+++ b/gtk/gtksidebar.c
@@ -0,0 +1,499 @@
+/*
+ * Copyright (c) 2014 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Ikey Doherty <michael i doherty intel com>
+ */
+
+#include "config.h"
+
+#include "gtksidebar.h"
+#include "gtklistbox.h"
+#include "gtkseparator.h"
+#include "gtkstylecontext.h"
+#include "gtklabel.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+
+/**
+ * SECTION:gtk-sidebar
+ * @short_description: An automatic sidebar widget
+ * @title: GtkSidebar
+ *
+ * A GtkSidebarWindow enables you to quickly and easily provide a consistent
+ * "sidebar" object for your user interface.
+ *
+ * In order to use a GtkSidebar, you simply use a GtkStack to organise
+ * your UI flow, and add the sidebar to your sidebar area. You can use
+ * gtk_sidebar_set_stack() to connect the #GtkSidebar to the #GtkStack.
+ *
+ * Since: 3.16
+ */
+
+struct _GtkSidebarPrivate
+{
+ GtkStack *stack;
+ GHashTable *rows;
+ gboolean in_child_changed;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSidebar, gtk_sidebar, GTK_TYPE_LIST_BOX)
+
+enum
+{
+ PROP_0,
+ PROP_STACK,
+ N_PROPERTIES
+};
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
+static void
+gtk_sidebar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_STACK:
+ gtk_sidebar_set_stack (GTK_SIDEBAR (object), g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_sidebar_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (GTK_SIDEBAR (object));
+
+ switch (prop_id)
+ {
+ case PROP_STACK:
+ g_value_set_object (value, priv->stack);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+update_header (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ gpointer userdata)
+{
+ GtkWidget *ret = NULL;
+
+ if (before && !gtk_list_box_row_get_header (row))
+ {
+ ret = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_list_box_row_set_header (row, ret);
+ }
+}
+
+static gint
+sort_list (GtkListBoxRow *row1,
+ GtkListBoxRow *row2,
+ gpointer userdata)
+{
+ GtkSidebar *sidebar = GTK_SIDEBAR (userdata);
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *item;
+ GtkWidget *widget;
+ gint left = 0; gint right = 0;
+
+
+ if (row1)
+ {
+ item = gtk_bin_get_child (GTK_BIN (row1));
+ widget = g_object_get_data (G_OBJECT (item), "stack-child");
+ gtk_container_child_get (GTK_CONTAINER (priv->stack), widget,
+ "position", &left,
+ NULL);
+ }
+
+ if (row2)
+ {
+ item = gtk_bin_get_child (GTK_BIN (row2));
+ widget = g_object_get_data (G_OBJECT (item), "stack-child");
+ gtk_container_child_get (GTK_CONTAINER (priv->stack), widget,
+ "position", &right,
+ NULL);
+ }
+
+ if (left < right)
+ return -1;
+
+ if (left == right)
+ return 0;
+
+ return 1;
+}
+
+static void
+gtk_sidebar_row_selected (GtkListBox *box,
+ GtkListBoxRow *row)
+{
+ GtkSidebar *sidebar = GTK_SIDEBAR (box);
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *item;
+ GtkWidget *widget;
+
+ if (priv->in_child_changed)
+ return;
+
+ if (!row)
+ return;
+
+ item = gtk_bin_get_child (GTK_BIN (row));
+ widget = g_object_get_data (G_OBJECT (item), "stack-child");
+ gtk_stack_set_visible_child (priv->stack, widget);
+}
+
+static void
+gtk_sidebar_init (GtkSidebar *sidebar)
+{
+ GtkStyleContext *style;
+ GtkSidebarPrivate *priv;
+
+ priv = gtk_sidebar_get_instance_private (sidebar);
+
+ gtk_list_box_set_header_func (GTK_LIST_BOX (sidebar), update_header, sidebar, NULL);
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (sidebar), sort_list, sidebar, NULL);
+
+ style = gtk_widget_get_style_context (GTK_WIDGET (sidebar));
+ gtk_style_context_add_class (style, "sidebar");
+
+ /* Store this for later use */
+ priv->rows = g_hash_table_new (NULL, NULL);
+}
+
+static void
+update_row (GtkSidebar *sidebar,
+ GtkWidget *widget,
+ GtkWidget *row)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *item;
+ gchar *title;
+ gboolean needs_attention;
+ GtkStyleContext *context;
+
+ gtk_container_child_get (GTK_CONTAINER (priv->stack), widget,
+ "title", &title,
+ "needs-attention", &needs_attention,
+ NULL);
+
+ item = gtk_bin_get_child (GTK_BIN (row));
+ gtk_label_set_text (GTK_LABEL (item), title);
+
+ gtk_widget_set_visible (row, gtk_widget_get_visible (widget) && title != NULL);
+
+ context = gtk_widget_get_style_context (row);
+ if (needs_attention)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+
+ g_free (title);
+}
+
+static void
+on_position_updated (GtkWidget *widget,
+ GParamSpec *pspec,
+ GtkSidebar *sidebar)
+{
+ gtk_list_box_invalidate_sort (GTK_LIST_BOX (sidebar));
+}
+
+static void
+on_child_updated (GtkWidget *widget,
+ GParamSpec *pspec,
+ GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *row;
+
+ row = g_hash_table_lookup (priv->rows, widget);
+ update_row (sidebar, widget, row);
+}
+
+static void
+add_child (GtkWidget *widget,
+ GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkStyleContext *style;
+ GtkWidget *item;
+ GtkWidget *row;
+
+ /* Check we don't actually already know about this widget */
+ if (g_hash_table_lookup (priv->rows, widget))
+ return;
+
+ /* Make a pretty item when we add kids */
+ item = gtk_label_new ("");
+ gtk_widget_set_halign (item, GTK_ALIGN_START);
+ gtk_widget_set_valign (item, GTK_ALIGN_CENTER);
+ row = gtk_list_box_row_new ();
+ gtk_container_add (GTK_CONTAINER (row), item);
+ gtk_widget_show (item);
+
+ update_row (sidebar, widget, row);
+
+ /* Fix up styling */
+ style = gtk_widget_get_style_context (row);
+ gtk_style_context_add_class (style, "sidebar-item");
+
+ /* Hook up for events */
+ g_signal_connect (widget, "child-notify::title",
+ G_CALLBACK (on_child_updated), sidebar);
+ g_signal_connect (widget, "child-notify::needs-attention",
+ G_CALLBACK (on_child_updated), sidebar);
+ g_signal_connect (widget, "notify::visible",
+ G_CALLBACK (on_child_updated), sidebar);
+ g_signal_connect (widget, "child-notify::position",
+ G_CALLBACK (on_position_updated), sidebar);
+
+ g_object_set_data (G_OBJECT (item), "stack-child", widget);
+ g_hash_table_insert (priv->rows, widget, row);
+ gtk_container_add (GTK_CONTAINER (sidebar), row);
+}
+
+static void
+remove_child (GtkWidget *widget,
+ GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *row;
+
+ row = g_hash_table_lookup (priv->rows, widget);
+ if (!row)
+ return;
+
+ g_signal_handlers_disconnect_by_func (widget, on_child_updated, sidebar);
+ g_signal_handlers_disconnect_by_func (widget, on_position_updated, sidebar);
+
+ gtk_container_remove (GTK_CONTAINER (sidebar), row);
+ g_hash_table_remove (priv->rows, widget);
+}
+
+static void
+populate_sidebar (GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+
+ gtk_container_foreach (GTK_CONTAINER (priv->stack), (GtkCallback)add_child, sidebar);
+}
+
+static void
+clear_sidebar (GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+
+ gtk_container_foreach (GTK_CONTAINER (priv->stack), (GtkCallback)remove_child, sidebar);
+}
+
+static void
+on_child_changed (GtkWidget *widget,
+ GParamSpec *pspec,
+ GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+ GtkWidget *child;
+ GtkWidget *row;
+
+ child = gtk_stack_get_visible_child (GTK_STACK (widget));
+ row = g_hash_table_lookup (priv->rows, child);
+ if (row != NULL)
+ {
+ priv->in_child_changed = TRUE;
+ gtk_list_box_select_row (GTK_LIST_BOX (sidebar), GTK_LIST_BOX_ROW (row));
+ priv->in_child_changed = FALSE;
+ }
+}
+
+static void
+on_stack_child_added (GtkContainer *container,
+ GtkWidget *widget,
+ GtkSidebar *sidebar)
+{
+ add_child (widget, sidebar);
+}
+
+static void
+on_stack_child_removed (GtkContainer *container,
+ GtkWidget *widget,
+ GtkSidebar *sidebar)
+{
+ remove_child (widget, sidebar);
+}
+
+static void
+disconnect_stack_signals (GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+
+ g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_added, sidebar);
+ g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_removed, sidebar);
+ g_signal_handlers_disconnect_by_func (priv->stack, on_child_changed, sidebar);
+ g_signal_handlers_disconnect_by_func (priv->stack, disconnect_stack_signals, sidebar);
+}
+
+static void
+connect_stack_signals (GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+
+ g_signal_connect_after (priv->stack, "add",
+ G_CALLBACK (on_stack_child_added), sidebar);
+ g_signal_connect_after (priv->stack, "remove",
+ G_CALLBACK (on_stack_child_removed), sidebar);
+ g_signal_connect (priv->stack, "notify::visible-child",
+ G_CALLBACK (on_child_changed), sidebar);
+ g_signal_connect_swapped (priv->stack, "destroy",
+ G_CALLBACK (disconnect_stack_signals), sidebar);
+}
+
+static void
+gtk_sidebar_dispose (GObject *object)
+{
+ GtkSidebar *sidebar = GTK_SIDEBAR (object);
+
+ gtk_sidebar_set_stack (sidebar, NULL);
+
+ G_OBJECT_CLASS (gtk_sidebar_parent_class)->dispose (object);
+}
+
+static void
+gtk_sidebar_finalize (GObject *object)
+{
+ GtkSidebar *sidebar = GTK_SIDEBAR (object);
+ GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
+
+ g_hash_table_destroy (priv->rows);
+
+ G_OBJECT_CLASS (gtk_sidebar_parent_class)->finalize (object);
+}
+
+static void
+gtk_sidebar_class_init (GtkSidebarClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkListBoxClass *list_box_class = GTK_LIST_BOX_CLASS (klass);
+
+ object_class->dispose = gtk_sidebar_dispose;
+ object_class->finalize = gtk_sidebar_finalize;
+ object_class->set_property = gtk_sidebar_set_property;
+ object_class->get_property = gtk_sidebar_get_property;
+
+ list_box_class->row_selected = gtk_sidebar_row_selected;
+
+ obj_properties[PROP_STACK] =
+ g_param_spec_pointer ("stack", P_("Stack"),
+ P_("Associated stack for this GtkSidebar"),
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
+}
+
+/**
+ * gtk_sidebar_new:
+ *
+ * Creates a new sidebar.
+ *
+ * Returns: the new #GtkSidebar
+ *
+ * Since: 3.16
+ */
+GtkWidget *
+gtk_sidebar_new (void)
+{
+ return GTK_WIDGET (g_object_new (GTK_TYPE_SIDEBAR, NULL));
+}
+
+/**
+ * gtk_sidebar_set_stack:
+ * @sidebar: a #GtkSidebar
+ * @stack: a #GtkStack
+ *
+ * Set the #GtkStack associated with this #GtkSidebar.
+ *
+ * The sidebar widget will automatically update according to the order
+ * (packing) and items within the given #GtkStack.
+ *
+ * Since: 3.16
+ */
+void
+gtk_sidebar_set_stack (GtkSidebar *sidebar,
+ GtkStack *stack)
+{
+ GtkSidebarPrivate *priv;
+
+ g_return_if_fail (GTK_IS_SIDEBAR (sidebar));
+ g_return_if_fail (GTK_IS_STACK (stack) || stack == NULL);
+
+ priv = gtk_sidebar_get_instance_private (sidebar);
+
+ if (priv->stack == stack)
+ return;
+
+ if (priv->stack)
+ {
+ disconnect_stack_signals (sidebar);
+ clear_sidebar (sidebar);
+ g_clear_object (&priv->stack);
+ }
+ if (stack)
+ {
+ priv->stack = g_object_ref (stack);
+ populate_sidebar (sidebar);
+ connect_stack_signals (sidebar);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (sidebar));
+
+ g_object_notify (G_OBJECT (sidebar), "stack");
+}
+
+/**
+ * gtk_sidebar_get_stack:
+ * @sidebar: a #GtkSidebar
+ *
+ * Returns: (transfer full): the associated #GtkStack
+ *
+ * Since: 3.16
+ */
+GtkStack *
+gtk_sidebar_get_stack (GtkSidebar *sidebar)
+{
+ GtkSidebarPrivate *priv;
+
+ g_return_if_fail (GTK_IS_SIDEBAR (sidebar));
+
+ priv = gtk_sidebar_get_instance_private (sidebar);
+
+ return GTK_STACK (priv->stack);
+}
diff --git a/gtk/gtksidebar.h b/gtk/gtksidebar.h
new file mode 100644
index 0000000..2f076a6
--- /dev/null
+++ b/gtk/gtksidebar.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2014 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Ikey Doherty <michael i doherty intel com>
+ */
+
+#ifndef __GTK_SIDEBAR_H__
+#define __GTK_SIDEBAR_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkwidget.h>
+#include <gtk/gtklistbox.h>
+#include <gtk/gtkstack.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SIDEBAR (gtk_sidebar_get_type ())
+#define GTK_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SIDEBAR, GtkSidebar))
+#define GTK_IS_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SIDEBAR))
+#define GTK_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SIDEBAR,
GtkSidebarClass))
+#define GTK_IS_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SIDEBAR))
+#define GTK_SIDEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SIDEBAR,
GtkSidebarClass))
+
+typedef struct _GtkSidebar GtkSidebar;
+typedef struct _GtkSidebarPrivate GtkSidebarPrivate;
+typedef struct _GtkSidebarClass GtkSidebarClass;
+
+struct _GtkSidebar
+{
+ GtkListBox parent;
+};
+
+struct _GtkSidebarClass
+{
+ GtkListBoxClass parent_class;
+
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+};
+
+GDK_AVAILABLE_IN_3_16
+GType gtk_sidebar_get_type (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_16
+GtkWidget * gtk_sidebar_new (void);
+GDK_AVAILABLE_IN_3_16
+void gtk_sidebar_set_stack (GtkSidebar *sidebar,
+ GtkStack *stack);
+GDK_AVAILABLE_IN_3_16
+GtkStack * gtk_sidebar_get_stack (GtkSidebar *sidebar);
+
+G_END_DECLS
+
+#endif /* __GTK_SIDEBAR_H__ */
diff --git a/gtk/makefile.msc.in b/gtk/makefile.msc.in
index 619b87d..3ee1baa 100644
--- a/gtk/makefile.msc.in
+++ b/gtk/makefile.msc.in
@@ -283,6 +283,7 @@ gtk_OBJECTS = \
gtkseparatortoolitem.obj \
gtksettings.obj \
gtkshow.obj \
+ gtksidebar.obj \
gtksizegroup.obj \
gtksizerequest.obj \
gtkspinbutton.obj \
@@ -475,6 +476,7 @@ gtk_public_h_sources = \
gtkseparatortoolitem.h \
gtksettings.h \
gtkshow.h \
+ gtksidebar.h \
gtksizegroup.h \
gtksizerequest.h \
gtksocket.h \
diff --git a/tests/teststack.c b/tests/teststack.c
index 35c7abc..2c9e5fa 100644
--- a/tests/teststack.c
+++ b/tests/teststack.c
@@ -2,6 +2,7 @@
GtkWidget *stack;
GtkWidget *switcher;
+GtkWidget *sidebar;
GtkWidget *w1;
static void
@@ -99,7 +100,7 @@ gint
main (gint argc,
gchar ** argv)
{
- GtkWidget *window, *box, *button, *hbox, *combo;
+ GtkWidget *window, *box, *button, *hbox, *combo, *layout;
GtkWidget *w2, *w3;
GtkListStore* store;
GtkWidget *tree_view;
@@ -127,7 +128,15 @@ main (gint argc,
gtk_stack_set_transition_duration (GTK_STACK (stack), 1500);
gtk_widget_set_halign (stack, GTK_ALIGN_START);
- gtk_container_add (GTK_CONTAINER (box), stack);
+
+ /* Add sidebar before stack */
+ sidebar = gtk_sidebar_new ();
+ gtk_sidebar_set_stack (GTK_SIDEBAR (sidebar), GTK_STACK (stack));
+ layout = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_pack_start (GTK_BOX (layout), sidebar, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (layout), stack, TRUE, TRUE, 0);
+
+ gtk_container_add (GTK_CONTAINER (box), layout);
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]