[gtk+/wip/actor: 11/24] css: Add a matcher for actors.



commit f7ef7c11d337433844d8450b7277bc61159b27a5
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 12 20:12:59 2012 +0100

    css: Add a matcher for actors.

 gtk/gtkcssmatcher.c        |  161 ++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssmatcherprivate.h |   10 +++
 2 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index ccdf547..536e511 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -422,3 +422,164 @@ _gtk_css_matcher_superset_init (GtkCssMatcher       *matcher,
   matcher->superset.relevant = relevant;
 }
 
+/* GTK_CSS_MATCHER_WIDGET_ACTOR */
+
+static gboolean
+gtk_css_matcher_actor_get_parent (GtkCssMatcher       *matcher,
+                                  const GtkCssMatcher *child)
+{
+  GtkActor *parent;
+  
+  for (parent = _gtk_actor_get_parent (child->actor.actor);
+       parent != NULL;
+       parent = _gtk_actor_get_parent (parent))
+    {
+      if (GTK_IS_CSS_BOX (parent))
+        {
+          _gtk_css_matcher_actor_init (matcher, GTK_CSS_BOX (parent));
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+static gboolean
+gtk_css_matcher_actor_get_previous (GtkCssMatcher       *matcher,
+                                    const GtkCssMatcher *next)
+{
+  GtkActor *prev;
+  
+  for (prev = _gtk_actor_get_previous_sibling (next->actor.actor);
+       prev != NULL;
+       prev = _gtk_actor_get_previous_sibling (prev))
+    {
+      if (GTK_IS_CSS_BOX (prev))
+        {
+          _gtk_css_matcher_actor_init (matcher, GTK_CSS_BOX (prev));
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+static GtkStateFlags
+gtk_css_matcher_actor_get_state (const GtkCssMatcher *matcher)
+{
+  return _gtk_css_box_get_effective_state (GTK_CSS_BOX (matcher->actor.actor));
+}
+
+static gboolean
+gtk_css_matcher_actor_has_type (const GtkCssMatcher *matcher,
+                                GType                type)
+{
+  GtkWidget *widget;
+  
+  widget = _gtk_actor_get_widget (matcher->actor.actor);
+  if (widget == NULL)
+    return FALSE;
+
+  return g_type_is_a (G_OBJECT_TYPE (widget), type);
+}
+
+static gboolean
+gtk_css_matcher_actor_has_class (const GtkCssMatcher *matcher,
+                                 GQuark               class_name)
+{
+  return _gtk_css_box_has_class (GTK_CSS_BOX (matcher->actor.actor), g_quark_to_string (class_name));
+}
+
+static gboolean
+gtk_css_matcher_actor_has_id (const GtkCssMatcher *matcher,
+                              const char          *id)
+{
+  const char *box_id;
+
+  box_id = _gtk_css_box_get_id (GTK_CSS_BOX (matcher->actor.actor));
+  if (box_id == NULL)
+    return FALSE;
+
+  return g_ascii_strcasecmp (box_id, id) == 0;
+}
+
+static gboolean
+gtk_css_matcher_actor_has_regions (const GtkCssMatcher *matcher)
+{
+  return FALSE;
+}
+
+static gboolean
+gtk_css_matcher_actor_has_region (const GtkCssMatcher *matcher,
+                                  const char          *region,
+                                  GtkRegionFlags       flags)
+{
+  return FALSE;
+}
+
+static gboolean
+gtk_css_matcher_actor_has_position (const GtkCssMatcher *matcher,
+                                    gboolean             forward,
+                                    int                  a,
+                                    int                  b)
+{
+  GtkActor *actor;
+  int x;
+
+  x = 0;
+
+  if (forward)
+    {
+      for (actor = matcher->actor.actor;
+           actor;
+           actor = _gtk_actor_get_previous_sibling (actor))
+        {
+          if (GTK_IS_CSS_BOX (actor))
+            x++;
+        }
+    }
+  else
+    {
+      for (actor = matcher->actor.actor;
+           actor;
+           actor = _gtk_actor_get_next_sibling (actor))
+        {
+          if (GTK_IS_CSS_BOX (actor))
+            x++;
+        }
+    }
+
+  x -= b;
+
+  if (a == 0)
+    return x == 0;
+
+  if (x % a)
+    return FALSE;
+
+  return x / a > 0;
+}
+
+static const GtkCssMatcherClass GTK_CSS_MATCHER_ACTOR = {
+  gtk_css_matcher_actor_get_parent,
+  gtk_css_matcher_actor_get_previous,
+  gtk_css_matcher_actor_get_state,
+  gtk_css_matcher_actor_has_type,
+  gtk_css_matcher_actor_has_class,
+  gtk_css_matcher_actor_has_id,
+  gtk_css_matcher_actor_has_regions,
+  gtk_css_matcher_actor_has_region,
+  gtk_css_matcher_actor_has_position,
+  FALSE
+};
+
+void
+_gtk_css_matcher_actor_init (GtkCssMatcher *matcher,
+                             GtkCssBox     *box)
+{
+  g_return_if_fail (matcher != NULL);
+  g_return_if_fail (GTK_IS_CSS_BOX (box));
+
+  matcher->actor.klass = &GTK_CSS_MATCHER_ACTOR;
+  matcher->actor.actor = GTK_ACTOR (box);
+}
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 1b2108c..2d99eb8 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -21,10 +21,12 @@
 #include <gtk/gtkenums.h>
 #include <gtk/gtktypes.h>
 #include "gtk/gtkcsstypesprivate.h"
+#include "gtk/actors/gtkcssboxprivate.h"
 
 G_BEGIN_DECLS
 
 typedef union _GtkCssMatcher GtkCssMatcher;
+typedef struct _GtkCssMatcherActor GtkCssMatcherActor;
 typedef struct _GtkCssMatcherSuperset GtkCssMatcherSuperset;
 typedef struct _GtkCssMatcherWidgetPath GtkCssMatcherWidgetPath;
 typedef struct _GtkCssMatcherClass GtkCssMatcherClass;
@@ -67,10 +69,16 @@ struct _GtkCssMatcherSuperset {
   GtkCssChange              relevant;
 };
 
+struct _GtkCssMatcherActor {
+  const GtkCssMatcherClass *klass;
+  GtkActor                 *actor;
+};
+
 union _GtkCssMatcher {
   const GtkCssMatcherClass *klass;
   GtkCssMatcherWidgetPath   path;
   GtkCssMatcherSuperset     superset;
+  GtkCssMatcherActor        actor;
 };
 
 gboolean          _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
@@ -80,6 +88,8 @@ void              _gtk_css_matcher_any_init       (GtkCssMatcher          *match
 void              _gtk_css_matcher_superset_init  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *subset,
                                                    GtkCssChange            relevant);
+void              _gtk_css_matcher_actor_init     (GtkCssMatcher          *matcher,
+                                                   GtkCssBox              *box);
 
 
 static inline gboolean



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