[gtk/wip/baedert/for-master: 41/57] stack: Add GtkStackPage:visible accessors



commit 52e4f7d81266309d93b428262f4f8cab1527837b
Author: Timm Bäder <mail baedert org>
Date:   Tue Feb 18 09:27:42 2020 +0100

    stack: Add GtkStackPage:visible accessors

 docs/reference/gtk/gtk4-sections.txt |  6 ++--
 gtk/gtkstack.c                       | 65 ++++++++++++++++++++++++++++--------
 gtk/gtkstack.h                       | 10 ++++--
 3 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 030fe98bce..6b4dfca4b1 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5783,15 +5783,17 @@ gtk_header_bar_get_type
 <SECTION>
 <FILE>gtkstack</FILE>
 <TITLE>GtkStack</TITLE>
-GtkStack
 GtkStackPage
+gtk_stack_page_get_visible
+gtk_stack_page_set_visible
+gtk_stack_page_get_child
+GtkStack
 gtk_stack_new
 gtk_stack_add_named
 gtk_stack_add_titled
 gtk_stack_get_child_by_name
 gtk_stack_get_page
 gtk_stack_get_pages
-gtk_stack_page_get_child
 gtk_stack_set_visible_child
 gtk_stack_get_visible_child
 gtk_stack_set_visible_child_name
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 71e3ad4297..fc6a46347e 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -189,19 +189,22 @@ enum
   LAST_CHILD_PROP
 };
 
-struct _GtkStackPage {
-  GObject instance;
+struct _GtkStackPage
+{
+  GObject parent_instance;
+
   GtkWidget *widget;
-  gchar *name;
-  gchar *title;
-  gchar *icon_name;
+  char *name;
+  char *title;
+  char *icon_name;
   gboolean needs_attention;
   gboolean visible;
   GtkWidget *last_focus;
 };
 
 typedef struct _GtkStackPageClass GtkStackPageClass;
-struct _GtkStackPageClass {
+struct _GtkStackPageClass
+{
   GObjectClass parent_class;
 };
 
@@ -264,7 +267,7 @@ gtk_stack_page_get_property (GObject      *object,
       break;
 
     case CHILD_PROP_VISIBLE:
-      g_value_set_boolean (value, info->visible);
+      g_value_set_boolean (value, gtk_stack_page_get_visible (info));
       break;
 
     default:
@@ -344,13 +347,7 @@ gtk_stack_page_set_property (GObject      *object,
       break;
 
     case CHILD_PROP_VISIBLE:
-      if (info->visible != g_value_get_boolean (value))
-        {
-          info->visible = g_value_get_boolean (value);
-          if (info->widget)
-            gtk_widget_set_visible (info->widget, info->visible);
-          g_object_notify_by_pspec (object, pspec);
-        }
+      gtk_stack_page_set_visible (info, g_value_get_boolean (value));
       break;
 
     default:
@@ -2592,3 +2589,43 @@ gtk_stack_get_pages (GtkStack *stack)
 
   return priv->pages;
 }
+
+/**
+ * gtk_stack_page_get_visible:
+ * @page: a #GtkStackPage
+ *
+ * Returns whether @page is visible in its #GtkStack.
+ * This is independent from the #GtkWidget:visible value of its
+ * #GtkWidget.
+ */
+gboolean
+gtk_stack_page_get_visible (GtkStackPage *page)
+{
+  g_return_val_if_fail (GTK_IS_STACK_PAGE (page), FALSE);
+
+  return page->visible;
+}
+
+/**
+ * gtk_stack_page_set_visible:
+ * @page: a #GtkStackPage
+ * @visible: The new property value
+ *
+ * Sets the new value of the #GtkStackPage:visible property
+ * to @visible.
+ */
+void
+gtk_stack_page_set_visible (GtkStackPage *page,
+                            gboolean      visible)
+{
+  g_return_if_fail (GTK_IS_STACK_PAGE (page));
+
+  visible = !!visible;
+
+  if (visible != page->visible)
+    {
+      page->visible = visible;
+
+      g_object_notify_by_pspec (G_OBJECT (page), stack_child_props[CHILD_PROP_VISIBLE]);
+    }
+}
diff --git a/gtk/gtkstack.h b/gtk/gtkstack.h
index 75a8d6871e..ad8b4cb697 100644
--- a/gtk/gtkstack.h
+++ b/gtk/gtkstack.h
@@ -72,6 +72,13 @@ typedef enum {
 
 GDK_AVAILABLE_IN_ALL
 GType                  gtk_stack_page_get_type           (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_ALL
+GtkWidget *            gtk_stack_page_get_child          (GtkStackPage           *page);
+GDK_AVAILABLE_IN_ALL
+gboolean               gtk_stack_page_get_visible        (GtkStackPage           *page);
+GDK_AVAILABLE_IN_ALL
+void                   gtk_stack_page_set_visible        (GtkStackPage           *page,
+                                                          gboolean                visible);
 
 GDK_AVAILABLE_IN_ALL
 GType                  gtk_stack_get_type                (void) G_GNUC_CONST;
@@ -91,9 +98,6 @@ GtkStackPage *         gtk_stack_add_titled              (GtkStack
 GDK_AVAILABLE_IN_ALL
 GtkStackPage *         gtk_stack_get_page                (GtkStack               *stack,
                                                           GtkWidget              *child);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *            gtk_stack_page_get_child          (GtkStackPage           *page);
-
 GDK_AVAILABLE_IN_ALL
 GtkWidget *            gtk_stack_get_child_by_name       (GtkStack               *stack,
                                                           const gchar            *name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]