[gtk+/wip/cssvalue: 7/164] matcher: Turn GtkCssMatcher into a union



commit 427bb3985825f0b691d090fec07c2e2b59a57611
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 17 14:32:52 2012 +0100

    matcher: Turn GtkCssMatcher into a union
    
    That way, we can add more matchers as we need them.

 gtk/gtkcssmatcher.c        |   82 ++++++++++++++++++++++---------------------
 gtk/gtkcssmatcherprivate.h |   10 ++++-
 2 files changed, 50 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index e796cfc..053280f 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -21,18 +21,20 @@
 
 #include "gtkwidgetpath.h"
 
+/* GTK_CSS_MATCHER_WIDGET_PATH */
+
 static gboolean
 gtk_css_matcher_widget_path_get_parent (GtkCssMatcher       *matcher,
                                         const GtkCssMatcher *child)
 {
-  if (child->index == 0)
+  if (child->path.index == 0)
     return FALSE;
 
-  matcher->klass = child->klass;
-  matcher->path = child->path;
-  matcher->state_flags = 0;
-  matcher->index = child->index - 1;
-  matcher->sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index);
+  matcher->path.klass = child->path.klass;
+  matcher->path.path = child->path.path;
+  matcher->path.state_flags = 0;
+  matcher->path.index = child->path.index - 1;
+  matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
 
   return TRUE;
 }
@@ -41,14 +43,14 @@ static gboolean
 gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
                                           const GtkCssMatcher *next)
 {
-  if (next->sibling_index == 0)
+  if (next->path.sibling_index == 0)
     return FALSE;
 
-  matcher->klass = next->klass;
-  matcher->path = next->path;
-  matcher->state_flags = 0;
-  matcher->index = next->index;
-  matcher->sibling_index = next->sibling_index - 1;
+  matcher->path.klass = next->path.klass;
+  matcher->path.path = next->path.path;
+  matcher->path.state_flags = 0;
+  matcher->path.index = next->path.index;
+  matcher->path.sibling_index = next->path.sibling_index - 1;
 
   return TRUE;
 }
@@ -56,7 +58,7 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
 static GtkStateFlags
 gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
 {
-  return matcher->state_flags;
+  return matcher->path.state_flags;
 }
 
 static gboolean
@@ -67,11 +69,11 @@ gtk_css_matcher_widget_path_has_name (const GtkCssMatcher *matcher,
   GType type;
   
   type = g_type_from_name (name);
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
-  if (siblings && matcher->sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index))
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->sibling_index), type);
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
+    return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
   else
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path, matcher->index), type);
+    return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), type);
 }
 
 static gboolean
@@ -80,11 +82,11 @@ gtk_css_matcher_widget_path_has_class (const GtkCssMatcher *matcher,
 {
   const GtkWidgetPath *siblings;
   
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
-  if (siblings && matcher->sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index))
-    return gtk_widget_path_iter_has_class (siblings, matcher->sibling_index, class_name);
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
+    return gtk_widget_path_iter_has_class (siblings, matcher->path.sibling_index, class_name);
   else
-    return gtk_widget_path_iter_has_class (matcher->path, matcher->index, class_name);
+    return gtk_widget_path_iter_has_class (matcher->path.path, matcher->path.index, class_name);
 }
 
 static gboolean
@@ -93,11 +95,11 @@ gtk_css_matcher_widget_path_has_id (const GtkCssMatcher *matcher,
 {
   const GtkWidgetPath *siblings;
   
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
-  if (siblings && matcher->sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index))
-    return gtk_widget_path_iter_has_name (siblings, matcher->sibling_index, id);
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
+    return gtk_widget_path_iter_has_name (siblings, matcher->path.sibling_index, id);
   else
-    return gtk_widget_path_iter_has_name (matcher->path, matcher->index, id);
+    return gtk_widget_path_iter_has_name (matcher->path.path, matcher->path.index, id);
 }
 
 static gboolean
@@ -107,11 +109,11 @@ gtk_css_matcher_widget_path_has_regions (const GtkCssMatcher *matcher)
   GSList *regions;
   gboolean result;
   
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
-  if (siblings && matcher->sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index))
-    regions = gtk_widget_path_iter_list_regions (siblings, matcher->sibling_index);
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
+    regions = gtk_widget_path_iter_list_regions (siblings, matcher->path.sibling_index);
   else
-    regions = gtk_widget_path_iter_list_regions (matcher->path, matcher->index);
+    regions = gtk_widget_path_iter_list_regions (matcher->path.path, matcher->path.index);
   result = regions != NULL;
   g_slist_free (regions);
 
@@ -126,15 +128,15 @@ gtk_css_matcher_widget_path_has_region (const GtkCssMatcher *matcher,
   const GtkWidgetPath *siblings;
   GtkRegionFlags region_flags;
   
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
-  if (siblings && matcher->sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path, matcher->index))
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
     {
-      if (!gtk_widget_path_iter_has_region (siblings, matcher->sibling_index, region, &region_flags))
+      if (!gtk_widget_path_iter_has_region (siblings, matcher->path.sibling_index, region, &region_flags))
         return FALSE;
     }
   else
     {
-      if (!gtk_widget_path_iter_has_region (matcher->path, matcher->index, region, &region_flags))
+      if (!gtk_widget_path_iter_has_region (matcher->path.path, matcher->path.index, region, &region_flags))
         return FALSE;
     }
 
@@ -147,7 +149,7 @@ gtk_css_matcher_widget_path_has_region (const GtkCssMatcher *matcher,
 static guint
 gtk_css_matcher_widget_path_get_sibling_index (const GtkCssMatcher *matcher)
 {
-  return matcher->sibling_index;
+  return matcher->path.sibling_index;
 }
 
 static guint
@@ -155,7 +157,7 @@ gtk_css_matcher_widget_path_get_n_siblings (const GtkCssMatcher *matcher)
 {
   const GtkWidgetPath *siblings;
 
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path, matcher->index);
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
   if (!siblings)
     return 0;
 
@@ -180,10 +182,10 @@ _gtk_css_matcher_init (GtkCssMatcher       *matcher,
                        const GtkWidgetPath *path,
                        GtkStateFlags        state)
 {
-  matcher->klass = &GTK_CSS_MATCHER_WIDGET_PATH;
-  matcher->path = path;
-  matcher->state_flags = state;
-  matcher->index = gtk_widget_path_length (path) - 1;
-  matcher->sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->index);
+  matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
+  matcher->path.path = path;
+  matcher->path.state_flags = state;
+  matcher->path.index = gtk_widget_path_length (path) - 1;
+  matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
 }
 
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 83eff0e..50412f4 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -23,7 +23,8 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GtkCssMatcher GtkCssMatcher;
+typedef union _GtkCssMatcher GtkCssMatcher;
+typedef struct _GtkCssMatcherWidgetPath GtkCssMatcherWidgetPath;
 typedef struct _GtkCssMatcherClass GtkCssMatcherClass;
 
 struct _GtkCssMatcherClass {
@@ -47,7 +48,7 @@ struct _GtkCssMatcherClass {
   guint           (* get_n_siblings)              (const GtkCssMatcher   *matcher);
 };
 
-struct _GtkCssMatcher {
+struct _GtkCssMatcherWidgetPath {
   const GtkCssMatcherClass *klass;
   const GtkWidgetPath      *path;
   GtkStateFlags             state_flags;
@@ -55,6 +56,11 @@ struct _GtkCssMatcher {
   guint                     sibling_index;
 };
 
+union _GtkCssMatcher {
+  const GtkCssMatcherClass *klass;
+  GtkCssMatcherWidgetPath   path;
+};
+
 void              _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
                                                    const GtkWidgetPath    *path,
                                                    GtkStateFlags           state);



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