[libhandy/wip/exalm/leaflet-transltions: 27/31] stackable-box: Add child-visible-changed signal



commit 9a9c2a57e35943b3c155de24b45e33688c61f089
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri May 29 01:00:39 2020 +0500

    stackable-box: Add child-visible-changed signal
    
    This will be used as a replacement for transition-running that takes into
    account visibility of each page individually.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-stackable-box.c | 65 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 56 insertions(+), 9 deletions(-)
---
diff --git a/src/hdy-stackable-box.c b/src/hdy-stackable-box.c
index d230b255..39bfd12c 100644
--- a/src/hdy-stackable-box.c
+++ b/src/hdy-stackable-box.c
@@ -78,6 +78,11 @@ enum {
   LAST_CHILD_PROP,
 };
 
+enum {
+  SIGNAL_CHILD_VISIBLE_CHANGED,
+  SIGNAL_LAST_SIGNAL,
+};
+
 #define HDY_FOLD_UNFOLDED FALSE
 #define HDY_FOLD_FOLDED TRUE
 #define HDY_FOLD_MAX 2
@@ -170,6 +175,7 @@ struct _HdyStackableBox
 
 static GParamSpec *props[LAST_PROP];
 static GParamSpec *child_props[LAST_CHILD_PROP];
+static guint signals[SIGNAL_LAST_SIGNAL];
 
 static gint HOMOGENEOUS_PROP[HDY_FOLD_MAX][GTK_ORIENTATION_MAX] = {
   { PROP_HHOMOGENEOUS_UNFOLDED, PROP_VHOMOGENEOUS_UNFOLDED},
@@ -325,6 +331,26 @@ get_child_window_y (HdyStackableBox          *self,
   return 0;
 }
 
+static void
+set_child_visible (HdyStackableBox          *self,
+                   HdyStackableBoxChildInfo *child_info,
+                   gboolean                  visible)
+{
+  GtkWidget *widget;
+
+  if (!child_info || !child_info->widget)
+    return;
+
+  widget = child_info->widget;
+
+  if (gtk_widget_get_child_visible (widget) == visible)
+    return;
+
+  gtk_widget_set_child_visible (widget, visible);
+
+  g_signal_emit (self, signals[SIGNAL_CHILD_VISIBLE_CHANGED], 0, widget, visible);
+}
+
 static void
 hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
 {
@@ -341,8 +367,8 @@ hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
     if (self->child_transition.is_cancelled) {
       if (self->last_visible_child != NULL) {
         if (self->folded) {
-          gtk_widget_set_child_visible (self->last_visible_child->widget, TRUE);
-          gtk_widget_set_child_visible (self->visible_child->widget, FALSE);
+          set_child_visible (self, self->last_visible_child, TRUE);
+          set_child_visible (self, self->visible_child, FALSE);
         }
         self->visible_child = self->last_visible_child;
         self->last_visible_child = NULL;
@@ -357,7 +383,7 @@ hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
     } else {
       if (self->last_visible_child != NULL) {
         if (self->folded)
-          gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+          set_child_visible (self, self->last_visible_child, FALSE);
         self->last_visible_child = NULL;
       }
     }
@@ -431,7 +457,7 @@ hdy_stackable_box_stop_child_transition (HdyStackableBox *self)
   hdy_stackable_box_unschedule_child_ticks (self);
   gtk_progress_tracker_finish (&self->child_transition.tracker);
   if (self->last_visible_child != NULL) {
-    gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+    set_child_visible (self, self->last_visible_child, FALSE);
     self->last_visible_child = NULL;
   }
 
@@ -530,7 +556,7 @@ set_visible_child_info (HdyStackableBox               *self,
   /* } */
 
   if (self->last_visible_child)
-    gtk_widget_set_child_visible (self->last_visible_child->widget, !self->folded);
+    set_child_visible (self, self->last_visible_child, !self->folded);
   self->last_visible_child = NULL;
 
   hdy_shadow_helper_clear_cache (self->shadow_helper);
@@ -539,7 +565,7 @@ set_visible_child_info (HdyStackableBox               *self,
     if (gtk_widget_is_visible (widget))
       self->last_visible_child = self->visible_child;
     else
-      gtk_widget_set_child_visible (self->visible_child->widget, !self->folded);
+      set_child_visible (self, self->visible_child, !self->folded);
   }
 
   /* FIXME This comes from GtkStack and should be adapted. */
@@ -550,7 +576,7 @@ set_visible_child_info (HdyStackableBox               *self,
   self->visible_child = new_visible_child;
 
   if (new_visible_child) {
-    gtk_widget_set_child_visible (new_visible_child->widget, TRUE);
+    set_child_visible (self, new_visible_child, TRUE);
 
     /* FIXME This comes from GtkStack and should be adapted. */
     /* if (contains_focus) { */
@@ -2006,7 +2032,7 @@ hdy_stackable_box_size_allocate (HdyStackableBox *self,
 
     child_info = children->data;
 
-    gtk_widget_set_child_visible (child_info->widget, child_info->visible);
+    set_child_visible (self, child_info, child_info->visible);
 
     if (child_info->window &&
         child_info->visible != gdk_window_is_visible (child_info->window)) {
@@ -2206,7 +2232,7 @@ hdy_stackable_box_child_visibility_notify_cb (GObject    *obj,
     set_visible_child_info (self, NULL, self->transition_type, self->child_transition.duration, TRUE);
 
   if (child_info == self->last_visible_child) {
-    gtk_widget_set_child_visible (self->last_visible_child->widget, !self->folded);
+    set_child_visible (self, self->last_visible_child, !self->folded);
     self->last_visible_child = NULL;
   }
 }
@@ -3015,6 +3041,27 @@ hdy_stackable_box_class_init (HdyStackableBoxClass *klass)
                          _("The name of the child page"),
                          NULL,
                          G_PARAM_READWRITE);
+
+  /**
+   * HdyStackableBox::child-visible-changed:
+   * @self: The #HdyStackableBox instance
+   * @child: The child
+   * @visible: The new value
+   *
+   * This signal is emitted after a child has been shown or hidden.
+   *
+   * Since: 1.0
+   */
+  signals[SIGNAL_CHILD_VISIBLE_CHANGED] =
+    g_signal_new ("child-visible-changed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE,
+                  2,
+                  GTK_TYPE_WIDGET,
+                  G_TYPE_BOOLEAN);
 }
 
 HdyStackableBox *


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