[gnome-shell/wip/clutter-deprecation-fixes: 13/25] st-widget: Keep track of first/last children by property notifiers



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

    st-widget: Keep track of first/last children by property notifiers

 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 79145ef..0d62731 100644
--- a/src/st/st-widget.c
+++ b/src/st/st-widget.c
@@ -76,6 +76,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;
 };
 
 /**
@@ -316,6 +322,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);
 }
 
@@ -1410,6 +1419,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;
@@ -1420,6 +1479,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]