[gnome-shell/wip/clutter-deprecation-fixes: 5/17] st-widget: Keep track of first/last children



commit 9ac5b78939e4fdbdca82632e2c0b14f0269f7420
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Feb 13 20:06:45 2012 -0500

    st-widget: Keep track of first/last children
    
    Clutter now provides two new properties on ClutterActor - first-child
    and last-child, so we have notifiers on when they change. Unfortunately,
    it still doesn't help us too much - we need to keep track of the previous
    values of the properties so we can remove their pseudoclasses.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670034

 src/st/st-widget.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-widget.c b/src/st/st-widget.c
index 2a81427..5005af1 100644
--- a/src/st/st-widget.c
+++ b/src/st/st-widget.c
@@ -70,6 +70,12 @@ struct _StWidgetPrivate
   AtkObject *accessible;
 
   ClutterActor *label_actor;
+
+  /* Even though Clutter has first_child/last_child properties,
+   * we need to keep track of the old first/last children so
+   * that we can remove the pseudo classes on them. */
+  StWidget *prev_last_child;
+  StWidget *prev_first_child;
 };
 
 /**
@@ -275,6 +281,9 @@ st_widget_dispose (GObject *gobject)
       priv->label_actor = NULL;
     }
 
+  g_clear_object (&priv->prev_first_child);
+  g_clear_object (&priv->prev_last_child);
+
   G_OBJECT_CLASS (st_widget_parent_class)->dispose (gobject);
 }
 
@@ -1283,6 +1292,56 @@ st_widget_name_notify (StWidget   *widget,
 }
 
 static void
+st_widget_first_child_notify (StWidget   *widget,
+                              GParamSpec *pspec,
+                              gpointer    data)
+{
+  ClutterActor *first_child;
+
+  if (widget->priv->prev_first_child != NULL)
+    {
+      st_widget_remove_style_pseudo_class (widget->priv->prev_first_child, "first-child");
+      g_clear_object (&widget->priv->prev_first_child);
+    }
+
+  first_child = clutter_actor_get_first_child (CLUTTER_ACTOR (widget));
+
+  if (first_child == NULL)
+    return;
+
+  if (ST_IS_WIDGET (first_child))
+    {
+      st_widget_add_style_pseudo_class (ST_WIDGET (first_child), "first-child");
+      widget->priv->prev_first_child = g_object_ref (ST_WIDGET (first_child));
+    }
+}
+
+static void
+st_widget_last_child_notify (StWidget   *widget,
+                             GParamSpec *pspec,
+                             gpointer    data)
+{
+  ClutterActor *last_child;
+
+  if (widget->priv->prev_last_child != NULL)
+    {
+      st_widget_remove_style_pseudo_class (widget->priv->prev_last_child, "last-child");
+      g_clear_object (&widget->priv->prev_last_child);
+    }
+
+  last_child = clutter_actor_get_last_child (CLUTTER_ACTOR (widget));
+
+  if (last_child == NULL)
+    return;
+
+  if (ST_IS_WIDGET (last_child))
+    {
+      st_widget_add_style_pseudo_class (ST_WIDGET (last_child), "last-child");
+      widget->priv->prev_last_child = g_object_ref (ST_WIDGET (last_child));
+    }
+}
+
+static void
 st_widget_init (StWidget *actor)
 {
   StWidgetPrivate *priv;
@@ -1293,6 +1352,9 @@ st_widget_init (StWidget *actor)
 
   /* connect style changed */
   g_signal_connect (actor, "notify::name", G_CALLBACK (st_widget_name_notify), NULL);
+
+  g_signal_connect (actor, "notify::first-child", G_CALLBACK (st_widget_first_child_notify), NULL);
+  g_signal_connect (actor, "notify::last-child", G_CALLBACK (st_widget_last_child_notify), NULL);
 }
 
 static void



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