2013-04-21 11:51:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
#include "gtkstackswitcher.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
2019-10-12 16:09:12 +00:00
|
|
|
#include "gtkboxlayout.h"
|
2020-02-22 03:16:42 +00:00
|
|
|
#include "gtkdropcontrollermotion.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkimage.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtklabel.h"
|
2013-04-21 11:51:14 +00:00
|
|
|
#include "gtkprivate.h"
|
2019-02-09 01:38:01 +00:00
|
|
|
#include "gtkselectionmodel.h"
|
2020-08-30 21:56:11 +00:00
|
|
|
#include "gtktogglebutton.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2013-04-21 15:05:38 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkstackswitcher
|
2013-04-22 14:23:56 +00:00
|
|
|
* @Short_description: A controller for GtkStack
|
2013-04-21 15:05:38 +00:00
|
|
|
* @Title: GtkStackSwitcher
|
|
|
|
* @See_also: #GtkStack
|
|
|
|
*
|
|
|
|
* The GtkStackSwitcher widget acts as a controller for a
|
|
|
|
* #GtkStack; it shows a row of buttons to switch between
|
|
|
|
* the various pages of the associated stack widget.
|
|
|
|
*
|
|
|
|
* All the content for the buttons comes from the child properties
|
2017-10-10 09:19:53 +00:00
|
|
|
* of the #GtkStack; the button visibility in a #GtkStackSwitcher
|
|
|
|
* widget is controlled by the visibility of the child in the
|
|
|
|
* #GtkStack.
|
2013-04-21 15:05:38 +00:00
|
|
|
*
|
|
|
|
* It is possible to associate multiple #GtkStackSwitcher widgets
|
2017-10-10 09:19:53 +00:00
|
|
|
* with the same #GtkStack widget.
|
2013-04-21 15:05:38 +00:00
|
|
|
*
|
2015-11-04 04:24:49 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
2015-11-15 22:11:48 +00:00
|
|
|
* GtkStackSwitcher has a single CSS node named stackswitcher and
|
|
|
|
* style class .stack-switcher.
|
2015-11-05 13:17:49 +00:00
|
|
|
*
|
|
|
|
* When circumstances require it, GtkStackSwitcher adds the
|
|
|
|
* .needs-attention style class to the widgets representing the
|
|
|
|
* stack pages.
|
2020-10-15 02:27:09 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
|
|
|
* GtkStackSwitcher uses the #GTK_ACCESSIBLE_ROLE_TAB_LIST role
|
|
|
|
* and uses the #GTK_ACCESSIBLE_ROLE_TAB for its buttons.
|
2013-04-21 15:05:38 +00:00
|
|
|
*/
|
|
|
|
|
2016-03-13 05:11:52 +00:00
|
|
|
#define TIMEOUT_EXPAND 500
|
|
|
|
|
2019-05-26 20:23:17 +00:00
|
|
|
typedef struct _GtkStackSwitcherClass GtkStackSwitcherClass;
|
|
|
|
|
|
|
|
struct _GtkStackSwitcher
|
|
|
|
{
|
2019-10-12 16:09:12 +00:00
|
|
|
GtkWidget parent_instance;
|
2020-04-26 19:48:46 +00:00
|
|
|
|
|
|
|
GtkStack *stack;
|
|
|
|
GtkSelectionModel *pages;
|
|
|
|
GHashTable *buttons;
|
2019-05-26 20:23:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkStackSwitcherClass
|
|
|
|
{
|
2019-10-12 16:09:12 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2019-05-26 20:23:17 +00:00
|
|
|
};
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_STACK
|
|
|
|
};
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
G_DEFINE_TYPE (GtkStackSwitcher, gtk_stack_switcher, GTK_TYPE_WIDGET)
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_stack_switcher_init (GtkStackSwitcher *switcher)
|
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
switcher->buttons = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (switcher), "linked");
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
on_button_toggled (GtkWidget *button,
|
|
|
|
GParamSpec *pspec,
|
2013-04-21 11:51:14 +00:00
|
|
|
GtkStackSwitcher *self)
|
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
gboolean active;
|
|
|
|
guint index;
|
2013-09-22 03:36:05 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
|
|
|
|
index = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "child-index"));
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
if (active)
|
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
gtk_selection_model_select_item (self->pages, index, TRUE);
|
2019-02-09 01:38:01 +00:00
|
|
|
}
|
|
|
|
else
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
gboolean selected = gtk_selection_model_is_selected (self->pages, index);
|
2019-02-09 01:38:01 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rebuild_child (GtkWidget *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *icon_name,
|
|
|
|
const char *title,
|
2020-04-30 23:17:34 +00:00
|
|
|
gboolean use_underline)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button_child;
|
|
|
|
|
|
|
|
button_child = NULL;
|
|
|
|
|
|
|
|
if (icon_name != NULL)
|
|
|
|
{
|
2017-11-15 00:43:13 +00:00
|
|
|
button_child = gtk_image_new_from_icon_name (icon_name);
|
2013-04-21 11:51:14 +00:00
|
|
|
if (title != NULL)
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (self), title);
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (self, "text-button");
|
|
|
|
gtk_widget_add_css_class (self, "image-button");
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
else if (title != NULL)
|
|
|
|
{
|
|
|
|
button_child = gtk_label_new (title);
|
2020-04-30 23:17:34 +00:00
|
|
|
gtk_label_set_use_underline (GTK_LABEL (button_child), use_underline);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2013-04-25 00:10:05 +00:00
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL);
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (self, "image-button");
|
|
|
|
gtk_widget_add_css_class (self, "text-button");
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (button_child)
|
|
|
|
{
|
2014-07-16 17:35:29 +00:00
|
|
|
gtk_widget_set_halign (GTK_WIDGET (button_child), GTK_ALIGN_CENTER);
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_button_set_child (GTK_BUTTON (self), button_child);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-30 20:32:42 +00:00
|
|
|
static void
|
2019-02-06 17:54:18 +00:00
|
|
|
update_button (GtkStackSwitcher *self,
|
2019-02-09 01:38:01 +00:00
|
|
|
GtkStackPage *page,
|
2019-02-06 17:54:18 +00:00
|
|
|
GtkWidget *button)
|
2013-08-30 20:32:42 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *title;
|
|
|
|
char *icon_name;
|
2013-08-30 20:32:42 +00:00
|
|
|
gboolean needs_attention;
|
2019-02-09 01:38:01 +00:00
|
|
|
gboolean visible;
|
2020-04-30 23:17:34 +00:00
|
|
|
gboolean use_underline;
|
2013-08-30 20:32:42 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
g_object_get (page,
|
2019-02-06 17:54:18 +00:00
|
|
|
"title", &title,
|
|
|
|
"icon-name", &icon_name,
|
|
|
|
"needs-attention", &needs_attention,
|
2019-02-09 01:38:01 +00:00
|
|
|
"visible", &visible,
|
2020-04-30 23:17:34 +00:00
|
|
|
"use-underline", &use_underline,
|
2019-02-06 17:54:18 +00:00
|
|
|
NULL);
|
|
|
|
|
2020-04-30 23:17:34 +00:00
|
|
|
rebuild_child (button, icon_name, title, use_underline);
|
2019-02-06 17:54:18 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
gtk_widget_set_visible (button, visible && (title != NULL || icon_name != NULL));
|
2013-08-30 20:32:42 +00:00
|
|
|
|
2014-07-17 01:08:27 +00:00
|
|
|
if (needs_attention)
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (button, "needs-attention");
|
2013-08-30 20:32:42 +00:00
|
|
|
else
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_remove_css_class (button, "needs-attention");
|
2019-02-06 17:54:18 +00:00
|
|
|
|
|
|
|
g_free (title);
|
|
|
|
g_free (icon_name);
|
2013-08-30 20:32:42 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
on_page_updated (GtkStackPage *page,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkStackSwitcher *self)
|
2013-08-30 20:32:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
button = g_hash_table_lookup (self->buttons, page);
|
2019-02-09 01:38:01 +00:00
|
|
|
update_button (self, page, button);
|
2013-08-30 20:32:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 05:11:52 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_stack_switcher_switch_timeout (gpointer data)
|
|
|
|
{
|
2020-02-22 03:16:42 +00:00
|
|
|
GtkWidget *button = data;
|
2016-03-13 05:11:52 +00:00
|
|
|
|
2020-02-22 03:16:42 +00:00
|
|
|
g_object_steal_data (G_OBJECT (button), "-gtk-switch-timer");
|
2016-03-13 05:11:52 +00:00
|
|
|
|
|
|
|
if (button)
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2020-01-11 02:56:26 +00:00
|
|
|
static void
|
2020-02-22 03:16:42 +00:00
|
|
|
gtk_stack_switcher_drag_enter (GtkDropControllerMotion *motion,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer unused)
|
2016-03-13 05:11:52 +00:00
|
|
|
{
|
2020-02-22 03:16:42 +00:00
|
|
|
GtkWidget *button = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
|
2016-03-13 05:11:52 +00:00
|
|
|
|
2020-02-22 03:16:42 +00:00
|
|
|
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
2016-03-13 05:11:52 +00:00
|
|
|
{
|
2020-02-22 03:16:42 +00:00
|
|
|
guint switch_timer = g_timeout_add (TIMEOUT_EXPAND,
|
2018-02-02 14:51:47 +00:00
|
|
|
gtk_stack_switcher_switch_timeout,
|
2020-02-22 03:16:42 +00:00
|
|
|
button);
|
|
|
|
g_source_set_name_by_id (switch_timer, "[gtk] gtk_stack_switcher_switch_timeout");
|
|
|
|
g_object_set_data (G_OBJECT (button), "-gtk-switch-timer", GUINT_TO_POINTER (switch_timer));
|
2016-03-13 05:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-22 03:16:42 +00:00
|
|
|
gtk_stack_switcher_drag_leave (GtkDropControllerMotion *motion,
|
|
|
|
gpointer unused)
|
2016-03-13 05:11:52 +00:00
|
|
|
{
|
2020-02-22 03:16:42 +00:00
|
|
|
GtkWidget *button = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
|
|
|
|
guint switch_timer;
|
|
|
|
|
|
|
|
switch_timer = GPOINTER_TO_UINT (g_object_steal_data (G_OBJECT (button), "-gtk-switch-timer"));
|
|
|
|
if (switch_timer)
|
|
|
|
g_source_remove (switch_timer);
|
2016-03-13 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
add_child (guint position,
|
2014-09-12 00:42:12 +00:00
|
|
|
GtkStackSwitcher *self)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2019-02-09 01:38:01 +00:00
|
|
|
gboolean selected;
|
2019-02-06 17:54:18 +00:00
|
|
|
GtkStackPage *page;
|
2020-02-22 03:16:42 +00:00
|
|
|
GtkEventController *controller;
|
2013-09-22 03:36:05 +00:00
|
|
|
|
2020-10-14 04:18:02 +00:00
|
|
|
button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
|
|
|
|
"accessible-role", GTK_ACCESSIBLE_ROLE_TAB,
|
|
|
|
NULL);
|
2015-10-23 20:13:30 +00:00
|
|
|
gtk_widget_set_focus_on_click (button, FALSE);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-02-22 03:16:42 +00:00
|
|
|
controller = gtk_drop_controller_motion_new ();
|
|
|
|
g_signal_connect (controller, "enter", G_CALLBACK (gtk_stack_switcher_drag_enter), NULL);
|
|
|
|
g_signal_connect (controller, "leave", G_CALLBACK (gtk_stack_switcher_drag_leave), NULL);
|
|
|
|
gtk_widget_add_controller (button, controller);
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
page = g_list_model_get_item (G_LIST_MODEL (self->pages), position);
|
2019-02-09 01:38:01 +00:00
|
|
|
update_button (self, page, button);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2019-10-12 16:09:12 +00:00
|
|
|
gtk_widget_set_parent (button, GTK_WIDGET (self));
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "child-index", GUINT_TO_POINTER (position));
|
2020-04-26 19:48:46 +00:00
|
|
|
selected = gtk_selection_model_is_selected (self->pages, position);
|
2019-02-09 01:38:01 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-10-14 04:25:57 +00:00
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (button),
|
|
|
|
GTK_ACCESSIBLE_STATE_SELECTED, selected,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (button),
|
|
|
|
GTK_ACCESSIBLE_RELATION_CONTROLS, g_list_append (NULL, page),
|
|
|
|
-1);
|
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
g_signal_connect (button, "notify::active", G_CALLBACK (on_button_toggled), self);
|
|
|
|
g_signal_connect (page, "notify", G_CALLBACK (on_page_updated), self);
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
g_hash_table_insert (self->buttons, g_object_ref (page), button);
|
2019-02-09 01:38:01 +00:00
|
|
|
|
|
|
|
g_object_unref (page);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
populate_switcher (GtkStackSwitcher *self)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
guint i;
|
2014-09-12 00:42:12 +00:00
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->pages)); i++)
|
2019-02-09 01:38:01 +00:00
|
|
|
add_child (i, self);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
clear_switcher (GtkStackSwitcher *self)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
GtkWidget *page;
|
|
|
|
GtkWidget *button;
|
2014-10-07 03:06:09 +00:00
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->buttons);
|
2019-02-09 01:38:01 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&page, (gpointer *)&button))
|
2014-10-07 03:06:09 +00:00
|
|
|
{
|
2019-10-12 16:09:12 +00:00
|
|
|
gtk_widget_unparent (button);
|
2019-02-09 01:38:01 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (page, on_page_updated, self);
|
|
|
|
g_hash_table_iter_remove (&iter);
|
2014-10-07 03:06:09 +00:00
|
|
|
}
|
2014-09-12 00:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
items_changed_cb (GListModel *model,
|
|
|
|
guint position,
|
|
|
|
guint removed,
|
|
|
|
guint added,
|
|
|
|
GtkStackSwitcher *switcher)
|
2014-09-12 00:42:12 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
clear_switcher (switcher);
|
|
|
|
populate_switcher (switcher);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
selection_changed_cb (GtkSelectionModel *model,
|
|
|
|
guint position,
|
|
|
|
guint n_items,
|
|
|
|
GtkStackSwitcher *switcher)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
guint i;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
for (i = position; i < position + n_items; i++)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
GtkStackPage *page;
|
|
|
|
GtkWidget *button;
|
|
|
|
gboolean selected;
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
page = g_list_model_get_item (G_LIST_MODEL (switcher->pages), i);
|
|
|
|
button = g_hash_table_lookup (switcher->buttons, page);
|
2019-02-09 01:38:01 +00:00
|
|
|
if (button)
|
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
selected = gtk_selection_model_is_selected (switcher->pages, i);
|
2019-02-09 01:38:01 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
|
2020-10-14 04:25:57 +00:00
|
|
|
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (button),
|
|
|
|
GTK_ACCESSIBLE_STATE_SELECTED, selected,
|
|
|
|
-1);
|
2019-02-09 01:38:01 +00:00
|
|
|
}
|
|
|
|
g_object_unref (page);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
disconnect_stack_signals (GtkStackSwitcher *switcher)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (switcher->pages, items_changed_cb, switcher);
|
|
|
|
g_signal_handlers_disconnect_by_func (switcher->pages, selection_changed_cb, switcher);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
connect_stack_signals (GtkStackSwitcher *switcher)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
g_signal_connect (switcher->pages, "items-changed", G_CALLBACK (items_changed_cb), switcher);
|
|
|
|
g_signal_connect (switcher->pages, "selection-changed", G_CALLBACK (selection_changed_cb), switcher);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
set_stack (GtkStackSwitcher *switcher,
|
|
|
|
GtkStack *stack)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2019-02-09 01:38:01 +00:00
|
|
|
if (stack)
|
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
switcher->stack = g_object_ref (stack);
|
|
|
|
switcher->pages = gtk_stack_get_pages (stack);
|
2019-02-09 01:38:01 +00:00
|
|
|
populate_switcher (switcher);
|
|
|
|
connect_stack_signals (switcher);
|
|
|
|
}
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 01:38:01 +00:00
|
|
|
unset_stack (GtkStackSwitcher *switcher)
|
2013-04-21 11:51:14 +00:00
|
|
|
{
|
2020-04-26 19:48:46 +00:00
|
|
|
if (switcher->stack)
|
2019-02-09 01:38:01 +00:00
|
|
|
{
|
|
|
|
disconnect_stack_signals (switcher);
|
|
|
|
clear_switcher (switcher);
|
2020-04-26 19:48:46 +00:00
|
|
|
g_clear_object (&switcher->stack);
|
|
|
|
g_clear_object (&switcher->pages);
|
2019-02-09 01:38:01 +00:00
|
|
|
}
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_stack_switcher_set_stack:
|
|
|
|
* @switcher: a #GtkStackSwitcher
|
|
|
|
* @stack: (allow-none): a #GtkStack
|
|
|
|
*
|
|
|
|
* Sets the stack to control.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_stack_switcher_set_stack (GtkStackSwitcher *switcher,
|
|
|
|
GtkStack *stack)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_STACK_SWITCHER (switcher));
|
2013-09-22 03:36:05 +00:00
|
|
|
g_return_if_fail (GTK_IS_STACK (stack) || stack == NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
if (switcher->stack == stack)
|
2013-04-21 11:51:14 +00:00
|
|
|
return;
|
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
unset_stack (switcher);
|
|
|
|
set_stack (switcher, stack);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (switcher));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (switcher), "stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_stack_switcher_get_stack:
|
|
|
|
* @switcher: a #GtkStackSwitcher
|
|
|
|
*
|
2013-04-21 15:05:38 +00:00
|
|
|
* Retrieves the stack.
|
|
|
|
* See gtk_stack_switcher_set_stack().
|
2013-04-21 11:51:14 +00:00
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
* Returns: (nullable) (transfer none): the stack, or %NULL if
|
2013-04-21 11:51:14 +00:00
|
|
|
* none has been set explicitly.
|
|
|
|
*/
|
|
|
|
GtkStack *
|
|
|
|
gtk_stack_switcher_get_stack (GtkStackSwitcher *switcher)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_STACK_SWITCHER (switcher), NULL);
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
return switcher->stack;
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_stack_switcher_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_STACK:
|
2020-04-26 19:48:46 +00:00
|
|
|
g_value_set_object (value, switcher->stack);
|
2013-04-21 11:51:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_stack_switcher_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_STACK:
|
|
|
|
gtk_stack_switcher_set_stack (switcher, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_stack_switcher_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
|
|
|
|
2019-02-09 01:38:01 +00:00
|
|
|
unset_stack (switcher);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_stack_switcher_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2014-03-29 22:14:51 +00:00
|
|
|
static void
|
|
|
|
gtk_stack_switcher_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
|
|
|
|
2020-04-26 19:48:46 +00:00
|
|
|
g_hash_table_destroy (switcher->buttons);
|
2014-03-29 22:14:51 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_stack_switcher_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-04-21 11:51:14 +00:00
|
|
|
static void
|
|
|
|
gtk_stack_switcher_class_init (GtkStackSwitcherClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
2015-11-04 04:24:49 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
object_class->get_property = gtk_stack_switcher_get_property;
|
|
|
|
object_class->set_property = gtk_stack_switcher_set_property;
|
|
|
|
object_class->dispose = gtk_stack_switcher_dispose;
|
2014-03-29 22:14:51 +00:00
|
|
|
object_class->finalize = gtk_stack_switcher_finalize;
|
2013-04-21 11:51:14 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_STACK,
|
|
|
|
g_param_spec_object ("stack",
|
|
|
|
P_("Stack"),
|
|
|
|
P_("Stack"),
|
|
|
|
GTK_TYPE_STACK,
|
|
|
|
GTK_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
2015-11-04 04:24:49 +00:00
|
|
|
|
2019-10-12 16:09:12 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("stackswitcher"));
|
2020-10-14 04:18:02 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TAB_LIST);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:05:38 +00:00
|
|
|
/**
|
|
|
|
* gtk_stack_switcher_new:
|
|
|
|
*
|
|
|
|
* Create a new #GtkStackSwitcher.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: a new #GtkStackSwitcher.
|
2013-04-21 15:05:38 +00:00
|
|
|
*/
|
2013-04-21 11:51:14 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_stack_switcher_new (void)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
return g_object_new (GTK_TYPE_STACK_SWITCHER, NULL);
|
2013-04-21 11:51:14 +00:00
|
|
|
}
|