2014-08-23 16:38:42 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2015-02-12 17:09:13 +00:00
|
|
|
#include "gtkstacksidebar.h"
|
2014-10-02 10:50:33 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2014-10-02 10:50:33 +00:00
|
|
|
#include "gtklabel.h"
|
2014-08-23 16:38:42 +00:00
|
|
|
#include "gtklistbox.h"
|
2014-10-02 10:50:33 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
2014-08-23 16:38:42 +00:00
|
|
|
#include "gtkseparator.h"
|
|
|
|
#include "gtkstylecontext.h"
|
2019-02-08 23:27:10 +00:00
|
|
|
#include "gtkselectionmodel.h"
|
2019-10-06 11:46:05 +00:00
|
|
|
#include "gtkstack.h"
|
2014-08-23 16:38:42 +00:00
|
|
|
#include "gtkprivate.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-08-23 16:38:42 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
/**
|
2015-02-12 17:09:13 +00:00
|
|
|
* SECTION:gtkstacksidebar
|
|
|
|
* @Title: GtkStackSidebar
|
2014-10-22 04:45:22 +00:00
|
|
|
* @Short_description: An automatic sidebar widget
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
2015-02-12 17:09:13 +00:00
|
|
|
* A GtkStackSidebar enables you to quickly and easily provide a
|
|
|
|
* consistent "sidebar" object for your user interface.
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
2015-02-12 17:09:13 +00:00
|
|
|
* In order to use a GtkStackSidebar, you simply use a GtkStack to
|
|
|
|
* organize your UI flow, and add the sidebar to your sidebar area. You
|
|
|
|
* can use gtk_stack_sidebar_set_stack() to connect the #GtkStackSidebar
|
|
|
|
* to the #GtkStack.
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
2015-11-04 04:27:34 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
2015-11-05 13:18:06 +00:00
|
|
|
* GtkStackSidebar has a single CSS node with name stacksidebar and
|
|
|
|
* style class .sidebar.
|
|
|
|
*
|
2016-02-09 07:05:16 +00:00
|
|
|
* When circumstances require it, GtkStackSidebar adds the
|
2015-11-05 13:18:06 +00:00
|
|
|
* .needs-attention style class to the widgets representing the stack
|
|
|
|
* pages.
|
2014-08-23 16:38:42 +00:00
|
|
|
*/
|
2016-02-09 07:05:16 +00:00
|
|
|
|
2019-05-26 20:19:44 +00:00
|
|
|
typedef struct _GtkStackSidebarClass GtkStackSidebarClass;
|
|
|
|
|
|
|
|
struct _GtkStackSidebar
|
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkWidget parent_instance;
|
2019-05-26 20:19:44 +00:00
|
|
|
|
2014-10-02 02:45:30 +00:00
|
|
|
GtkListBox *list;
|
2014-08-23 16:38:42 +00:00
|
|
|
GtkStack *stack;
|
2019-02-08 23:27:10 +00:00
|
|
|
GtkSelectionModel *pages;
|
2014-08-23 16:38:42 +00:00
|
|
|
GHashTable *rows;
|
|
|
|
};
|
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
struct _GtkStackSidebarClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkStackSidebar, gtk_stack_sidebar, GTK_TYPE_WIDGET)
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_STACK,
|
|
|
|
N_PROPERTIES
|
|
|
|
};
|
|
|
|
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
|
|
|
|
|
|
|
|
static void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_STACK:
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (object), g_value_get_object (value));
|
2014-08-23 16:38:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self = GTK_STACK_SIDEBAR (object);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_STACK:
|
2019-10-06 11:46:05 +00:00
|
|
|
g_value_set_object (value, self->stack);
|
2014-08-23 16:38:42 +00:00
|
|
|
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 void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_row_selected (GtkListBox *box,
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
gpointer userdata)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self = GTK_STACK_SIDEBAR (userdata);
|
2019-02-08 23:27:10 +00:00
|
|
|
guint index;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
if (row == NULL)
|
2014-08-23 16:38:42 +00:00
|
|
|
return;
|
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
index = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (row), "child-index"));
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_selection_model_select_item (self->pages, index, TRUE);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_stack_sidebar_init (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2014-10-02 10:50:33 +00:00
|
|
|
GtkWidget *sw;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2014-10-02 10:50:33 +00:00
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2014-10-02 02:45:30 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_widget_set_parent (sw, GTK_WIDGET (self));
|
2014-10-02 10:50:33 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
self->list = GTK_LIST_BOX (gtk_list_box_new ());
|
2014-10-02 10:50:33 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (self->list));
|
2014-10-02 02:45:30 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_list_box_set_header_func (self->list, update_header, self, NULL);
|
2014-10-02 02:45:30 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_signal_connect (self->list, "row-selected",
|
|
|
|
G_CALLBACK (gtk_stack_sidebar_row_selected), self);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "sidebar");
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
self->rows = g_hash_table_new (NULL, NULL);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
update_row (GtkStackSidebar *self,
|
2019-02-08 23:27:10 +00:00
|
|
|
GtkStackPage *page,
|
2015-02-12 17:09:13 +00:00
|
|
|
GtkWidget *row)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
gchar *title;
|
|
|
|
gboolean needs_attention;
|
2019-02-08 23:27:10 +00:00
|
|
|
gboolean visible;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
g_object_get (page,
|
2019-02-06 17:54:18 +00:00
|
|
|
"title", &title,
|
|
|
|
"needs-attention", &needs_attention,
|
2019-02-08 23:27:10 +00:00
|
|
|
"visible", &visible,
|
2019-02-06 17:54:18 +00:00
|
|
|
NULL);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
item = gtk_bin_get_child (GTK_BIN (row));
|
|
|
|
gtk_label_set_text (GTK_LABEL (item), title);
|
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
gtk_widget_set_visible (row, visible && title != NULL);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
if (needs_attention)
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (row, GTK_STYLE_CLASS_NEEDS_ATTENTION);
|
2014-08-23 16:38:42 +00:00
|
|
|
else
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (row, GTK_STYLE_CLASS_NEEDS_ATTENTION);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-08 23:27:10 +00:00
|
|
|
on_page_updated (GtkStackPage *page,
|
|
|
|
GParamSpec *pspec,
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
row = g_hash_table_lookup (self->rows, page);
|
|
|
|
update_row (self, page, row);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-08 23:27:10 +00:00
|
|
|
add_child (guint position,
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
GtkWidget *row;
|
2019-02-08 12:55:41 +00:00
|
|
|
GtkStackPage *page;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
/* 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);
|
2019-02-08 23:27:10 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
page = g_list_model_get_item (G_LIST_MODEL (self->pages), position);
|
|
|
|
update_row (self, page, row);
|
2019-02-08 23:27:10 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (self->list), row);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
g_object_set_data (G_OBJECT (row), "child-index", GUINT_TO_POINTER (position));
|
2019-10-06 11:46:05 +00:00
|
|
|
if (gtk_selection_model_is_selected (self->pages, position))
|
|
|
|
gtk_list_box_select_row (self->list, GTK_LIST_BOX_ROW (row));
|
2019-02-08 23:27:10 +00:00
|
|
|
else
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_list_box_unselect_row (self->list, GTK_LIST_BOX_ROW (row));
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_signal_connect (page, "notify", G_CALLBACK (on_page_updated), self);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_hash_table_insert (self->rows, page, row);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
g_object_unref (page);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
populate_sidebar (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-02-08 23:27:10 +00:00
|
|
|
guint i;
|
2014-10-07 03:06:54 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->pages)); i++)
|
|
|
|
add_child (i, self);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
clear_sidebar (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-02-08 23:27:10 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
GtkStackPage *page;
|
|
|
|
GtkWidget *row;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->rows);
|
2019-02-08 23:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&page, (gpointer *)&row))
|
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (self->list), row);
|
2019-02-08 23:27:10 +00:00
|
|
|
g_hash_table_iter_remove (&iter);
|
2019-10-06 11:46:05 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (page, on_page_updated, self);
|
2019-02-08 23:27:10 +00:00
|
|
|
}
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-08 23:27:10 +00:00
|
|
|
items_changed_cb (GListModel *model,
|
|
|
|
guint position,
|
|
|
|
guint removed,
|
|
|
|
guint added,
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self)
|
2019-02-08 23:27:10 +00:00
|
|
|
{
|
|
|
|
/* FIXME: we can do better */
|
2019-10-06 11:46:05 +00:00
|
|
|
clear_sidebar (self);
|
|
|
|
populate_sidebar (self);
|
2019-02-08 23:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_changed_cb (GtkSelectionModel *model,
|
|
|
|
guint position,
|
|
|
|
guint n_items,
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-02-08 23:27:10 +00:00
|
|
|
guint i;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-02-08 23:27:10 +00:00
|
|
|
for (i = position; i < position + n_items; i++)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-02-08 23:27:10 +00:00
|
|
|
GtkStackPage *page;
|
|
|
|
GtkWidget *row;
|
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
page = g_list_model_get_item (G_LIST_MODEL (self->pages), i);
|
|
|
|
row = g_hash_table_lookup (self->rows, page);
|
|
|
|
if (gtk_selection_model_is_selected (self->pages, i))
|
|
|
|
gtk_list_box_select_row (self->list, GTK_LIST_BOX_ROW (row));
|
2019-02-08 23:27:10 +00:00
|
|
|
else
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_list_box_unselect_row (self->list, GTK_LIST_BOX_ROW (row));
|
2019-02-08 23:27:10 +00:00
|
|
|
g_object_unref (page);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
disconnect_stack_signals (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (self->pages, items_changed_cb, self);
|
|
|
|
g_signal_handlers_disconnect_by_func (self->pages, selection_changed_cb, self);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
connect_stack_signals (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
g_signal_connect (self->pages, "items-changed", G_CALLBACK (items_changed_cb), self);
|
|
|
|
g_signal_connect (self->pages, "selection-changed", G_CALLBACK (selection_changed_cb), self);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
set_stack (GtkStackSidebar *self,
|
2019-02-08 23:27:10 +00:00
|
|
|
GtkStack *stack)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-02-08 23:27:10 +00:00
|
|
|
if (stack)
|
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
self->stack = g_object_ref (stack);
|
|
|
|
self->pages = gtk_stack_get_pages (stack);
|
|
|
|
populate_sidebar (self);
|
|
|
|
connect_stack_signals (self);
|
2019-02-08 23:27:10 +00:00
|
|
|
}
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-06 11:46:05 +00:00
|
|
|
unset_stack (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
if (self->stack)
|
2019-02-08 23:27:10 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
disconnect_stack_signals (self);
|
|
|
|
clear_sidebar (self);
|
|
|
|
g_clear_object (&self->stack);
|
|
|
|
g_clear_object (&self->pages);
|
2019-02-08 23:27:10 +00:00
|
|
|
}
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_dispose (GObject *object)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self = GTK_STACK_SIDEBAR (object);
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
unset_stack (self);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
/* The scrolled window */
|
|
|
|
child = gtk_widget_get_first_child (GTK_WIDGET (self));
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
gtk_widget_unparent (child);
|
|
|
|
self->list = NULL;
|
|
|
|
}
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2015-02-12 17:09:13 +00:00
|
|
|
G_OBJECT_CLASS (gtk_stack_sidebar_parent_class)->dispose (object);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_finalize (GObject *object)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
GtkStackSidebar *self = GTK_STACK_SIDEBAR (object);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_hash_table_destroy (self->rows);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2015-02-12 17:09:13 +00:00
|
|
|
G_OBJECT_CLASS (gtk_stack_sidebar_parent_class)->finalize (object);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_class_init (GtkStackSidebarClass *klass)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2015-11-04 04:27:34 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2015-02-12 17:09:13 +00:00
|
|
|
object_class->dispose = gtk_stack_sidebar_dispose;
|
|
|
|
object_class->finalize = gtk_stack_sidebar_finalize;
|
|
|
|
object_class->set_property = gtk_stack_sidebar_set_property;
|
|
|
|
object_class->get_property = gtk_stack_sidebar_get_property;
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2020-04-08 11:43:28 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_none;
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
|
|
|
|
2014-08-23 16:38:42 +00:00
|
|
|
obj_properties[PROP_STACK] =
|
2014-10-03 01:59:55 +00:00
|
|
|
g_param_spec_object (I_("stack"), P_("Stack"),
|
2015-02-12 17:09:13 +00:00
|
|
|
P_("Associated stack for this GtkStackSidebar"),
|
2014-10-03 01:59:55 +00:00
|
|
|
GTK_TYPE_STACK,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
|
2015-11-04 04:27:34 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("stacksidebar"));
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-12 17:09:13 +00:00
|
|
|
* gtk_stack_sidebar_new:
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
|
|
|
* Creates a new sidebar.
|
|
|
|
*
|
2015-02-12 17:09:13 +00:00
|
|
|
* Returns: the new #GtkStackSidebar
|
2014-08-23 16:38:42 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_new (void)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2015-02-12 17:09:13 +00:00
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_STACK_SIDEBAR, NULL));
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-12 17:09:13 +00:00
|
|
|
* gtk_stack_sidebar_set_stack:
|
2019-10-06 11:46:05 +00:00
|
|
|
* @self: a #GtkStackSidebar
|
2014-08-23 16:38:42 +00:00
|
|
|
* @stack: a #GtkStack
|
|
|
|
*
|
2015-02-12 17:09:13 +00:00
|
|
|
* Set the #GtkStack associated with this #GtkStackSidebar.
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
|
|
|
* The sidebar widget will automatically update according to the order
|
|
|
|
* (packing) and items within the given #GtkStack.
|
|
|
|
*/
|
|
|
|
void
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_stack_sidebar_set_stack (GtkStackSidebar *self,
|
2015-02-12 17:09:13 +00:00
|
|
|
GtkStack *stack)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
g_return_if_fail (GTK_IS_STACK_SIDEBAR (self));
|
2014-08-23 16:38:42 +00:00
|
|
|
g_return_if_fail (GTK_IS_STACK (stack) || stack == NULL);
|
|
|
|
|
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
if (self->stack == stack)
|
2014-08-23 16:38:42 +00:00
|
|
|
return;
|
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
unset_stack (self);
|
|
|
|
set_stack (self, stack);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (self));
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "stack");
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-12 17:09:13 +00:00
|
|
|
* gtk_stack_sidebar_get_stack:
|
2019-10-06 11:46:05 +00:00
|
|
|
* @self: a #GtkStackSidebar
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
2014-10-22 04:36:16 +00:00
|
|
|
* Retrieves the stack.
|
2015-02-12 17:09:13 +00:00
|
|
|
* See gtk_stack_sidebar_set_stack().
|
2014-10-22 04:36:16 +00:00
|
|
|
*
|
2016-02-08 13:02:25 +00:00
|
|
|
* Returns: (nullable) (transfer none): the associated #GtkStack or
|
2014-10-22 04:36:16 +00:00
|
|
|
* %NULL if none has been set explicitly
|
2014-08-23 16:38:42 +00:00
|
|
|
*/
|
|
|
|
GtkStack *
|
2019-10-06 11:46:05 +00:00
|
|
|
gtk_stack_sidebar_get_stack (GtkStackSidebar *self)
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
2019-10-06 11:46:05 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_STACK_SIDEBAR (self), NULL);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2019-10-06 11:46:05 +00:00
|
|
|
return GTK_STACK (self->stack);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|