Commit a2da26de authored by Matthias Clasen's avatar Matthias Clasen

GtkSidebar: not a listbox anymore

Applications are not expected to call GtkListBox API on a
sidebar, so don't make it one. Instead, make it have a
listbox.
parent 7b2e526c
...@@ -46,12 +46,13 @@ ...@@ -46,12 +46,13 @@
struct _GtkSidebarPrivate struct _GtkSidebarPrivate
{ {
GtkListBox *list;
GtkStack *stack; GtkStack *stack;
GHashTable *rows; GHashTable *rows;
gboolean in_child_changed; gboolean in_child_changed;
}; };
G_DEFINE_TYPE_WITH_PRIVATE (GtkSidebar, gtk_sidebar, GTK_TYPE_LIST_BOX) G_DEFINE_TYPE_WITH_PRIVATE (GtkSidebar, gtk_sidebar, GTK_TYPE_BIN)
enum enum
{ {
...@@ -154,9 +155,10 @@ sort_list (GtkListBoxRow *row1, ...@@ -154,9 +155,10 @@ sort_list (GtkListBoxRow *row1,
static void static void
gtk_sidebar_row_selected (GtkListBox *box, gtk_sidebar_row_selected (GtkListBox *box,
GtkListBoxRow *row) GtkListBoxRow *row,
gpointer userdata)
{ {
GtkSidebar *sidebar = GTK_SIDEBAR (box); GtkSidebar *sidebar = GTK_SIDEBAR (userdata);
GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar); GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
GtkWidget *item; GtkWidget *item;
GtkWidget *widget; GtkWidget *widget;
...@@ -180,13 +182,22 @@ gtk_sidebar_init (GtkSidebar *sidebar) ...@@ -180,13 +182,22 @@ gtk_sidebar_init (GtkSidebar *sidebar)
priv = gtk_sidebar_get_instance_private (sidebar); priv = gtk_sidebar_get_instance_private (sidebar);
gtk_list_box_set_header_func (GTK_LIST_BOX (sidebar), update_header, sidebar, NULL); priv->list = GTK_LIST_BOX (gtk_list_box_new ());
gtk_list_box_set_sort_func (GTK_LIST_BOX (sidebar), sort_list, sidebar, NULL);
_gtk_bin_set_child (GTK_BIN (sidebar), GTK_WIDGET (priv->list));
gtk_widget_set_parent (GTK_WIDGET (priv->list), GTK_WIDGET (sidebar));
gtk_widget_show (GTK_WIDGET (priv->list));
gtk_widget_set_no_show_all (GTK_WIDGET (priv->list), TRUE);
gtk_list_box_set_header_func (priv->list, update_header, sidebar, NULL);
gtk_list_box_set_sort_func (priv->list, sort_list, sidebar, NULL);
g_signal_connect (priv->list, "row-selected",
G_CALLBACK (gtk_sidebar_row_selected), sidebar);
style = gtk_widget_get_style_context (GTK_WIDGET (sidebar)); style = gtk_widget_get_style_context (GTK_WIDGET (sidebar));
gtk_style_context_add_class (style, "sidebar"); gtk_style_context_add_class (style, "sidebar");
/* Store this for later use */
priv->rows = g_hash_table_new (NULL, NULL); priv->rows = g_hash_table_new (NULL, NULL);
} }
...@@ -225,7 +236,9 @@ on_position_updated (GtkWidget *widget, ...@@ -225,7 +236,9 @@ on_position_updated (GtkWidget *widget,
GParamSpec *pspec, GParamSpec *pspec,
GtkSidebar *sidebar) GtkSidebar *sidebar)
{ {
gtk_list_box_invalidate_sort (GTK_LIST_BOX (sidebar)); GtkSidebarPrivate *priv = gtk_sidebar_get_instance_private (sidebar);
gtk_list_box_invalidate_sort (priv->list);
} }
static void static void
...@@ -279,7 +292,7 @@ add_child (GtkWidget *widget, ...@@ -279,7 +292,7 @@ add_child (GtkWidget *widget,
g_object_set_data (G_OBJECT (item), "stack-child", widget); g_object_set_data (G_OBJECT (item), "stack-child", widget);
g_hash_table_insert (priv->rows, widget, row); g_hash_table_insert (priv->rows, widget, row);
gtk_container_add (GTK_CONTAINER (sidebar), row); gtk_container_add (GTK_CONTAINER (priv->list), row);
} }
static void static void
...@@ -296,7 +309,7 @@ remove_child (GtkWidget *widget, ...@@ -296,7 +309,7 @@ remove_child (GtkWidget *widget,
g_signal_handlers_disconnect_by_func (widget, on_child_updated, sidebar); g_signal_handlers_disconnect_by_func (widget, on_child_updated, sidebar);
g_signal_handlers_disconnect_by_func (widget, on_position_updated, sidebar); g_signal_handlers_disconnect_by_func (widget, on_position_updated, sidebar);
gtk_container_remove (GTK_CONTAINER (sidebar), row); gtk_container_remove (GTK_CONTAINER (priv->list), row);
g_hash_table_remove (priv->rows, widget); g_hash_table_remove (priv->rows, widget);
} }
...@@ -330,7 +343,7 @@ on_child_changed (GtkWidget *widget, ...@@ -330,7 +343,7 @@ on_child_changed (GtkWidget *widget,
if (row != NULL) if (row != NULL)
{ {
priv->in_child_changed = TRUE; priv->in_child_changed = TRUE;
gtk_list_box_select_row (GTK_LIST_BOX (sidebar), GTK_LIST_BOX_ROW (row)); gtk_list_box_select_row (priv->list, GTK_LIST_BOX_ROW (row));
priv->in_child_changed = FALSE; priv->in_child_changed = FALSE;
} }
} }
...@@ -402,15 +415,12 @@ static void ...@@ -402,15 +415,12 @@ static void
gtk_sidebar_class_init (GtkSidebarClass *klass) gtk_sidebar_class_init (GtkSidebarClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (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->dispose = gtk_sidebar_dispose;
object_class->finalize = gtk_sidebar_finalize; object_class->finalize = gtk_sidebar_finalize;
object_class->set_property = gtk_sidebar_set_property; object_class->set_property = gtk_sidebar_set_property;
object_class->get_property = gtk_sidebar_get_property; object_class->get_property = gtk_sidebar_get_property;
list_box_class->row_selected = gtk_sidebar_row_selected;
obj_properties[PROP_STACK] = obj_properties[PROP_STACK] =
g_param_spec_pointer ("stack", P_("Stack"), g_param_spec_pointer ("stack", P_("Stack"),
P_("Associated stack for this GtkSidebar"), P_("Associated stack for this GtkSidebar"),
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
#error "Only <gtk/gtk.h> can be included directly." #error "Only <gtk/gtk.h> can be included directly."
#endif #endif
#include <gtk/gtkwidget.h> #include <gtk/gtkbin.h>
#include <gtk/gtklistbox.h>
#include <gtk/gtkstack.h> #include <gtk/gtkstack.h>
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -45,12 +44,12 @@ typedef struct _GtkSidebarClass GtkSidebarClass; ...@@ -45,12 +44,12 @@ typedef struct _GtkSidebarClass GtkSidebarClass;
struct _GtkSidebar struct _GtkSidebar
{ {
GtkListBox parent; GtkBin parent;
}; };
struct _GtkSidebarClass struct _GtkSidebarClass
{ {
GtkListBoxClass parent_class; GtkBinClass parent_class;
/* Padding for future expansion */ /* Padding for future expansion */
void (*_gtk_reserved1) (void); void (*_gtk_reserved1) (void);
......
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