[gtk/wip/baedert/for-master: 9/9] stackswitcher: Inherit from GtkWidget
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 9/9] stackswitcher: Inherit from GtkWidget
- Date: Sat, 12 Oct 2019 16:13:59 +0000 (UTC)
commit 989307e4c2fe7ea0a33716621a041e9887a16596
Author: Timm Bäder <mail baedert org>
Date: Sat Oct 12 18:09:12 2019 +0200
stackswitcher: Inherit from GtkWidget
gtk/gtkshortcutssection.c | 39 +++++++++++++++++++++------------------
gtk/gtkstackswitcher.c | 19 ++++++++-----------
gtk/gtkstackswitcher.h | 1 -
3 files changed, 29 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkshortcutssection.c b/gtk/gtkshortcutssection.c
index c3c758d7ee..677e92d496 100644
--- a/gtk/gtkshortcutssection.c
+++ b/gtk/gtkshortcutssection.c
@@ -20,6 +20,7 @@
#include "gtkshortcutssection.h"
+#include "gtkbox.h"
#include "gtkshortcutsgroup.h"
#include "gtkbutton.h"
#include "gtklabel.h"
@@ -429,7 +430,6 @@ gtk_shortcuts_section_init (GtkShortcutsSection *self)
self->switcher = g_object_new (GTK_TYPE_STACK_SWITCHER,
"halign", GTK_ALIGN_CENTER,
"stack", self->stack,
- "spacing", 12,
"visible", FALSE,
NULL);
@@ -563,18 +563,6 @@ gtk_shortcuts_section_filter_groups (GtkShortcutsSection *self)
gtk_widget_get_visible (GTK_WIDGET (self->switcher)));
}
-static void
-adjust_page_buttons (GtkWidget *widget,
- gpointer data)
-{
- GtkWidget *label;
-
- gtk_style_context_add_class (gtk_widget_get_style_context (widget), "circular");
-
- label = gtk_bin_get_child (GTK_BIN (widget));
- gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
-}
-
static void
gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
{
@@ -738,11 +726,26 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
}
/* fix up stack switcher */
- gtk_container_foreach (GTK_CONTAINER (self->switcher), adjust_page_buttons, NULL);
- gtk_widget_set_visible (GTK_WIDGET (self->switcher), (n_pages > 1));
- gtk_widget_set_visible (gtk_widget_get_parent (GTK_WIDGET (self->switcher)),
- gtk_widget_get_visible (GTK_WIDGET (self->show_all)) ||
- gtk_widget_get_visible (GTK_WIDGET (self->switcher)));
+ {
+ GtkWidget *w;
+
+ for (w = gtk_widget_get_first_child (GTK_WIDGET (self->switcher));
+ w != NULL;
+ w = gtk_widget_get_next_sibling (w))
+ {
+ GtkWidget *label;
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (w), "circular");
+
+ label = gtk_bin_get_child (GTK_BIN (w));
+ gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
+ }
+
+ gtk_widget_set_visible (GTK_WIDGET (self->switcher), (n_pages > 1));
+ gtk_widget_set_visible (gtk_widget_get_parent (GTK_WIDGET (self->switcher)),
+ gtk_widget_get_visible (GTK_WIDGET (self->show_all)) ||
+ gtk_widget_get_visible (GTK_WIDGET (self->switcher)));
+ }
/* clean up */
g_list_free (groups);
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 21969f156b..00bd50ece5 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -21,12 +21,12 @@
#include "gtkstackswitcher.h"
+#include "gtkboxlayout.h"
#include "gtkdnd.h"
#include "gtkdragdest.h"
#include "gtkimage.h"
#include "gtkintl.h"
#include "gtklabel.h"
-#include "gtkorientable.h"
#include "gtkprivate.h"
#include "gtkradiobutton.h"
#include "gtkselectionmodel.h"
@@ -71,12 +71,12 @@ typedef struct _GtkStackSwitcherPrivate GtkStackSwitcherPrivate;
struct _GtkStackSwitcher
{
- GtkBox widget;
+ GtkWidget parent_instance;
};
struct _GtkStackSwitcherClass
{
- GtkBoxClass parent_class;
+ GtkWidgetClass parent_class;
};
struct _GtkStackSwitcherPrivate
@@ -93,23 +93,19 @@ enum {
PROP_STACK
};
-G_DEFINE_TYPE_WITH_PRIVATE (GtkStackSwitcher, gtk_stack_switcher, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkStackSwitcher, gtk_stack_switcher, GTK_TYPE_WIDGET)
static void
gtk_stack_switcher_init (GtkStackSwitcher *switcher)
{
+ GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (switcher);
GtkStyleContext *context;
- GtkStackSwitcherPrivate *priv;
-
- priv = gtk_stack_switcher_get_instance_private (switcher);
priv->buttons = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
context = gtk_widget_get_style_context (GTK_WIDGET (switcher));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
-
gtk_drag_dest_set (GTK_WIDGET (switcher), 0, NULL, 0);
gtk_drag_dest_set_track_motion (GTK_WIDGET (switcher), TRUE);
}
@@ -317,7 +313,7 @@ add_child (guint position,
page = g_list_model_get_item (G_LIST_MODEL (priv->pages), position);
update_button (self, page, button);
- gtk_container_add (GTK_CONTAINER (self), button);
+ gtk_widget_set_parent (button, GTK_WIDGET (self));
g_object_set_data (G_OBJECT (button), "child-index", GUINT_TO_POINTER (position));
selected = gtk_selection_model_is_selected (priv->pages, position);
@@ -352,7 +348,7 @@ clear_switcher (GtkStackSwitcher *self)
g_hash_table_iter_init (&iter, priv->buttons);
while (g_hash_table_iter_next (&iter, (gpointer *)&page, (gpointer *)&button))
{
- gtk_container_remove (GTK_CONTAINER (self), button);
+ gtk_widget_unparent (button);
g_signal_handlers_disconnect_by_func (page, on_page_updated, self);
g_hash_table_iter_remove (&iter);
}
@@ -576,6 +572,7 @@ gtk_stack_switcher_class_init (GtkStackSwitcherClass *class)
GTK_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("stackswitcher"));
}
diff --git a/gtk/gtkstackswitcher.h b/gtk/gtkstackswitcher.h
index 28922c3e35..bb8e5277d8 100644
--- a/gtk/gtkstackswitcher.h
+++ b/gtk/gtkstackswitcher.h
@@ -24,7 +24,6 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
-#include <gtk/gtkbox.h>
#include <gtk/gtkstack.h>
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]