[gtk+/wip/cssnode3: 2/91] stylecontext: Turn CssNode accesses into getters/setters



commit 645871f2950709433fdfcabf7cf727bc18a42b04
Author: Benjamin Otte <otte redhat com>
Date:   Sat Jan 10 22:35:38 2015 +0100

    stylecontext: Turn CssNode accesses into getters/setters
    
    That way we can hide the struct in the source file.

 gtk/gtkcssnode.c        |  146 +++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssnodeprivate.h |   44 ++++++++++++--
 gtk/gtkstylecontext.c   |   72 ++++++++++++-----------
 3 files changed, 220 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 5a3c4fe..5993b3a 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -19,6 +19,13 @@
 
 #include "gtkcssnodeprivate.h"
 
+struct _GtkCssNode
+{
+  GtkCssNodeDeclaration *decl;
+  GtkCssNode            *parent;
+  GtkCssStyle           *style;
+};
+
 GtkCssNode *
 gtk_css_node_new (void)
 {
@@ -30,6 +37,18 @@ gtk_css_node_new (void)
   return cssnode;
 }
 
+GtkCssNode *
+gtk_css_node_copy (GtkCssNode *cssnode)
+{
+  GtkCssNode *copy;
+
+  copy = gtk_css_node_new ();
+  gtk_css_node_declaration_unref (copy->decl);
+  copy->decl = gtk_css_node_declaration_ref (cssnode->decl);
+
+  return copy;
+}
+
 void
 gtk_css_node_free (GtkCssNode *cssnode)
 {
@@ -39,6 +58,13 @@ gtk_css_node_free (GtkCssNode *cssnode)
   g_slice_free (GtkCssNode, cssnode);
 }
 
+void
+gtk_css_node_set_parent (GtkCssNode *cssnode,
+                         GtkCssNode *parent)
+{
+  cssnode->parent = parent;
+}
+
 GtkCssNode *
 gtk_css_node_get_parent (GtkCssNode *cssnode)
 {
@@ -67,3 +93,123 @@ gtk_css_node_get_style (GtkCssNode *cssnode)
   return cssnode->style;
 }
 
+void
+gtk_css_node_set_widget_type (GtkCssNode *cssnode,
+                              GType       widget_type)
+{
+  gtk_css_node_declaration_set_type (&cssnode->decl, widget_type);
+}
+
+GType
+gtk_css_node_get_widget_type (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_get_type (cssnode->decl);
+}
+
+gboolean
+gtk_css_node_set_id (GtkCssNode *cssnode,
+                     const char *id)
+{
+  return gtk_css_node_declaration_set_id (&cssnode->decl, id);
+}
+
+const char *
+gtk_css_node_get_id (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_get_id (cssnode->decl);
+}
+
+gboolean
+gtk_css_node_set_state (GtkCssNode    *cssnode,
+                        GtkStateFlags  state_flags)
+{
+  return gtk_css_node_declaration_set_state (&cssnode->decl, state_flags);
+}
+
+GtkStateFlags
+gtk_css_node_get_state (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_get_state (cssnode->decl);
+}
+
+void
+gtk_css_node_set_junction_sides (GtkCssNode       *cssnode,
+                                 GtkJunctionSides  junction_sides)
+{
+  gtk_css_node_declaration_set_junction_sides (&cssnode->decl, junction_sides);
+}
+
+GtkJunctionSides
+gtk_css_node_get_junction_sides (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_get_junction_sides (cssnode->decl);
+}
+
+gboolean
+gtk_css_node_add_class (GtkCssNode *cssnode,
+                        GQuark      style_class)
+{
+  return gtk_css_node_declaration_add_class (&cssnode->decl, style_class);
+}
+
+gboolean
+gtk_css_node_remove_class (GtkCssNode *cssnode,
+                           GQuark      style_class)
+{
+  return gtk_css_node_declaration_remove_class (&cssnode->decl, style_class);
+}
+
+gboolean
+gtk_css_node_has_class (GtkCssNode *cssnode,
+                        GQuark      style_class)
+{
+  return gtk_css_node_declaration_has_class (cssnode->decl, style_class);
+}
+
+GList *
+gtk_css_node_list_classes (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_list_classes (cssnode->decl);
+}
+
+gboolean
+gtk_css_node_add_region (GtkCssNode     *cssnode,
+                         GQuark          region,
+                         GtkRegionFlags  flags)
+{
+  return gtk_css_node_declaration_add_region (&cssnode->decl, region, flags);
+}
+
+gboolean
+gtk_css_node_remove_region (GtkCssNode *cssnode,
+                            GQuark      region)
+{
+  return gtk_css_node_declaration_remove_region (&cssnode->decl, region);
+}
+
+gboolean
+gtk_css_node_has_region (GtkCssNode     *cssnode,
+                         GQuark          region,
+                         GtkRegionFlags *out_flags)
+{
+  return gtk_css_node_declaration_has_region (cssnode->decl, region, out_flags);
+}
+
+GList *
+gtk_css_node_list_regions (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_list_regions (cssnode->decl);
+}
+
+
+const GtkCssNodeDeclaration *
+gtk_css_node_get_declaration (GtkCssNode *cssnode)
+{
+  return cssnode->decl;
+}
+
+GtkCssNodeDeclaration *
+gtk_css_node_dup_declaration (GtkCssNode *cssnode)
+{
+  return gtk_css_node_declaration_ref (cssnode->decl);
+}
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index c8f2ff8..0999ab5 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -25,19 +25,49 @@ G_BEGIN_DECLS
 
 typedef struct _GtkCssNode GtkCssNode;
 
-struct _GtkCssNode
-{
-  GtkCssNodeDeclaration *decl;
-  GtkCssNode            *parent;
-  GtkCssStyle           *style;
-};
-
 GtkCssNode *            gtk_css_node_new                (void);
+GtkCssNode *            gtk_css_node_copy               (GtkCssNode            *cssnode);
 
 void                    gtk_css_node_free               (GtkCssNode            *cssnode);
 
+void                    gtk_css_node_set_parent         (GtkCssNode            *cssnode,
+                                                         GtkCssNode            *parent);
 GtkCssNode *            gtk_css_node_get_parent         (GtkCssNode            *cssnode);
 
+void                    gtk_css_node_set_widget_type    (GtkCssNode            *cssnode,
+                                                         GType                  widget_type);
+GType                   gtk_css_node_get_widget_type    (GtkCssNode            *cssnode);
+gboolean                gtk_css_node_set_id             (GtkCssNode            *cssnode,
+                                                         const char            *id);
+const char *            gtk_css_node_get_id             (GtkCssNode            *cssnode);
+gboolean                gtk_css_node_set_state          (GtkCssNode            *cssnode,
+                                                         GtkStateFlags          state_flags);
+GtkStateFlags           gtk_css_node_get_state          (GtkCssNode            *cssnode);
+void                    gtk_css_node_set_junction_sides (GtkCssNode            *cssnode,
+                                                         GtkJunctionSides       junction_sides);
+GtkJunctionSides        gtk_css_node_get_junction_sides (GtkCssNode            *cssnode);
+gboolean                gtk_css_node_add_class          (GtkCssNode            *cssnode,
+                                                         GQuark                 style_class);
+gboolean                gtk_css_node_remove_class       (GtkCssNode            *cssnode,
+                                                         GQuark                 style_class);
+gboolean                gtk_css_node_has_class          (GtkCssNode            *cssnode,
+                                                         GQuark                 style_class);
+GList *                 gtk_css_node_list_classes       (GtkCssNode            *cssnode);
+gboolean                gtk_css_node_add_region         (GtkCssNode            *cssnode,
+                                                         GQuark                 region,
+                                                         GtkRegionFlags         flags);
+gboolean                gtk_css_node_remove_region      (GtkCssNode            *cssnode,
+                                                         GQuark                 region);
+gboolean                gtk_css_node_has_region         (GtkCssNode            *cssnode,
+                                                         GQuark                 region,
+                                                         GtkRegionFlags        *out_flags);
+GList *                 gtk_css_node_list_regions       (GtkCssNode            *cssnode);
+
+const GtkCssNodeDeclaration *
+                        gtk_css_node_get_declaration    (GtkCssNode            *cssnode);
+GtkCssNodeDeclaration * gtk_css_node_dup_declaration    (GtkCssNode            *cssnode);
+
+
 GtkCssStyle *           gtk_css_node_get_style          (GtkCssNode            *cssnode);
 void                    gtk_css_node_set_style          (GtkCssNode            *cssnode,
                                                          GtkCssStyle           *style);
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index a75d062..9a062d4 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -378,7 +378,7 @@ gtk_style_context_init (GtkStyleContext *style_context)
 
   /* Create default info store */
   priv->cssnode = gtk_css_node_new ();
-  gtk_css_node_declaration_set_state (&priv->cssnode->decl, GTK_STATE_FLAG_DIR_LTR);
+  gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR);
 
   priv->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
 
@@ -648,7 +648,7 @@ create_query_path (GtkStyleContext              *context,
       GtkCssNode *root = gtk_style_context_get_root (context);
 
       if (length > 0)
-        gtk_css_node_declaration_add_to_widget_path (root->decl, path, length - 1);
+        gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (root), path, length - 1);
 
       gtk_widget_path_append_type (path, length > 0 ? gtk_widget_path_iter_get_object_type (path, length - 
1) : G_TYPE_NONE);
       gtk_css_node_declaration_add_to_widget_path (decl, path, length);
@@ -833,6 +833,7 @@ GtkCssStyle *
 gtk_style_context_lookup_style (GtkStyleContext *context)
 {
   GtkStyleContextPrivate *priv;
+  GtkCssNodeDeclaration *decl;
   GtkCssStyle *values;
   GtkCssNode *cssnode;
 
@@ -846,20 +847,22 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
 
   if (!gtk_style_context_is_saved (context))
     {
-      values = build_properties (context, cssnode->decl, TRUE, gtk_css_node_get_parent_style (context, 
cssnode));
+      values = build_properties (context, gtk_css_node_get_declaration (cssnode), TRUE, 
gtk_css_node_get_parent_style (context, cssnode));
     }
   else
     {
-      values = g_hash_table_lookup (priv->style_values, cssnode->decl);
+      decl = gtk_css_node_dup_declaration (cssnode);
+      values = g_hash_table_lookup (priv->style_values, decl);
       if (values)
         {
           gtk_css_node_set_style (cssnode, values);
+          gtk_css_node_declaration_unref (decl);
           return values;
         }
 
-      values = build_properties (context, cssnode->decl, FALSE, gtk_css_node_get_parent_style (context, 
cssnode));
+      values = build_properties (context, decl, FALSE, gtk_css_node_get_parent_style (context, cssnode));
       g_hash_table_insert (priv->style_values,
-                           gtk_css_node_declaration_ref (cssnode->decl),
+                           decl,
                            g_object_ref (values));
     }
   
@@ -876,13 +879,13 @@ gtk_style_context_lookup_style_for_state (GtkStyleContext *context,
   GtkCssNodeDeclaration *decl;
   GtkCssStyle *values;
 
-  if (gtk_css_node_declaration_get_state (context->priv->cssnode->decl) == state)
+  if (gtk_css_node_get_state (context->priv->cssnode) == state)
     return g_object_ref (gtk_style_context_lookup_style (context));
 
   if (g_getenv ("GTK_STYLE_CONTEXT_WARNING"))
     g_warning ("State does not match current state");
 
-  decl = gtk_css_node_declaration_ref (context->priv->cssnode->decl);
+  decl = gtk_css_node_dup_declaration (context->priv->cssnode);
   gtk_css_node_declaration_set_state (&decl, state);
   values = build_properties (context,
                              decl,
@@ -965,9 +968,9 @@ _gtk_style_context_set_widget (GtkStyleContext *context,
   context->priv->widget = widget;
 
   if (widget)
-    gtk_css_node_declaration_set_type (&context->priv->cssnode->decl, G_OBJECT_TYPE (widget));
+    gtk_css_node_set_widget_type (context->priv->cssnode, G_OBJECT_TYPE (widget));
   else
-    gtk_css_node_declaration_set_type (&context->priv->cssnode->decl, G_TYPE_NONE);
+    gtk_css_node_set_widget_type (context->priv->cssnode, G_TYPE_NONE);
 
   _gtk_style_context_update_animating (context);
 
@@ -1323,7 +1326,7 @@ gtk_style_context_set_id (GtkStyleContext *context,
 {
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
-  if (!gtk_css_node_declaration_set_id (&context->priv->cssnode->decl, id))
+  if (!gtk_css_node_set_id (context->priv->cssnode, id))
     return;
 
   gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_ID);
@@ -1342,7 +1345,7 @@ gtk_style_context_get_id (GtkStyleContext *context)
 {
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
 
-  return gtk_css_node_declaration_get_id (context->priv->cssnode->decl);
+  return gtk_css_node_get_id (context->priv->cssnode);
 }
 
 /**
@@ -1362,9 +1365,9 @@ gtk_style_context_set_state (GtkStyleContext *context,
   GtkStateFlags old_flags;
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
-  old_flags = gtk_css_node_declaration_get_state (context->priv->cssnode->decl);
+  old_flags = gtk_css_node_get_state (context->priv->cssnode);
 
-  if (!gtk_css_node_declaration_set_state (&context->priv->cssnode->decl, flags))
+  if (!gtk_css_node_set_state (context->priv->cssnode, flags))
     return;
 
   if (((old_flags ^ flags) & (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)) &&
@@ -1389,7 +1392,7 @@ gtk_style_context_get_state (GtkStyleContext *context)
 {
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
 
-  return gtk_css_node_declaration_get_state (context->priv->cssnode->decl);
+  return gtk_css_node_get_state (context->priv->cssnode);
 }
 
 /**
@@ -1508,15 +1511,15 @@ gtk_style_context_set_path (GtkStyleContext *context,
     {
       gtk_widget_path_free (priv->widget_path);
       priv->widget_path = NULL;
-      gtk_css_node_declaration_set_type (&context->priv->cssnode->decl, G_TYPE_NONE);
+      gtk_css_node_set_widget_type (context->priv->cssnode, G_TYPE_NONE);
     }
 
   if (path)
     {
       priv->widget_path = gtk_widget_path_copy (path);
       if (gtk_widget_path_length (path))
-        gtk_css_node_declaration_set_type (&context->priv->cssnode->decl,
-                                           gtk_widget_path_iter_get_object_type (path, -1));
+        gtk_css_node_set_widget_type (context->priv->cssnode,
+                                      gtk_widget_path_iter_get_object_type (path, -1));
     }
 
 
@@ -1638,9 +1641,8 @@ gtk_style_context_save (GtkStyleContext *context)
   if (!gtk_style_context_is_saved (context))
     gtk_style_context_lookup_style (context);
 
-  cssnode = gtk_css_node_new ();
-  cssnode->decl = gtk_css_node_declaration_ref (priv->cssnode->decl);
-  cssnode->parent = gtk_style_context_get_root (context);
+  cssnode = gtk_css_node_copy (priv->cssnode);
+  gtk_css_node_set_parent (cssnode, gtk_style_context_get_root (context));
 
   priv->saved_nodes = g_slist_prepend (priv->saved_nodes, priv->cssnode);
   priv->cssnode = cssnode;
@@ -1707,7 +1709,7 @@ gtk_style_context_add_class (GtkStyleContext *context,
   priv = context->priv;
   class_quark = g_quark_from_string (class_name);
 
-  if (gtk_css_node_declaration_add_class (&priv->cssnode->decl, class_quark))
+  if (gtk_css_node_add_class (priv->cssnode, class_quark))
     gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
 }
 
@@ -1737,7 +1739,7 @@ gtk_style_context_remove_class (GtkStyleContext *context,
 
   priv = context->priv;
 
-  if (gtk_css_node_declaration_remove_class (&priv->cssnode->decl, class_quark))
+  if (gtk_css_node_remove_class (priv->cssnode, class_quark))
     gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
 }
 
@@ -1770,7 +1772,7 @@ gtk_style_context_has_class (GtkStyleContext *context,
 
   priv = context->priv;
 
-  return gtk_css_node_declaration_has_class (priv->cssnode->decl, class_quark);
+  return gtk_css_node_has_class (priv->cssnode, class_quark);
 }
 
 static void
@@ -1807,7 +1809,7 @@ gtk_style_context_list_classes (GtkStyleContext *context)
 
   priv = context->priv;
   
-  classes = gtk_css_node_declaration_list_classes (priv->cssnode->decl);
+  classes = gtk_css_node_list_classes (priv->cssnode);
   quarks_to_strings (classes);
 
   return classes;
@@ -1838,7 +1840,7 @@ gtk_style_context_list_regions (GtkStyleContext *context)
 
   priv = context->priv;
 
-  regions = gtk_css_node_declaration_list_regions (priv->cssnode->decl);
+  regions = gtk_css_node_list_regions (priv->cssnode);
   quarks_to_strings (regions);
 
   return regions;
@@ -1912,7 +1914,7 @@ gtk_style_context_add_region (GtkStyleContext *context,
   priv = context->priv;
   region_quark = g_quark_from_string (region_name);
 
-  if (gtk_css_node_declaration_add_region (&priv->cssnode->decl, region_quark, flags))
+  if (gtk_css_node_add_region (priv->cssnode, region_quark, flags))
     gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
 }
 
@@ -1944,7 +1946,7 @@ gtk_style_context_remove_region (GtkStyleContext *context,
 
   priv = context->priv;
 
-  if (gtk_css_node_declaration_remove_region (&priv->cssnode->decl, region_quark))
+  if (gtk_css_node_remove_region (priv->cssnode, region_quark))
     gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
 }
 
@@ -1985,7 +1987,7 @@ gtk_style_context_has_region (GtkStyleContext *context,
 
   priv = context->priv;
 
-  return gtk_css_node_declaration_has_region (priv->cssnode->decl, region_quark, flags_return);
+  return gtk_css_node_has_region (priv->cssnode, region_quark, flags_return);
 }
 
 static gint
@@ -2553,7 +2555,7 @@ gtk_style_context_set_junction_sides (GtkStyleContext  *context,
 {
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
-  gtk_css_node_declaration_set_junction_sides (&context->priv->cssnode->decl, sides);
+  gtk_css_node_set_junction_sides (context->priv->cssnode, sides);
 }
 
 /**
@@ -2571,7 +2573,7 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
 {
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
 
-  return gtk_css_node_declaration_get_junction_sides (context->priv->cssnode->decl);
+  return gtk_css_node_get_junction_sides (context->priv->cssnode);
 }
 
 gboolean
@@ -2971,7 +2973,7 @@ _gtk_style_context_validate (GtkStyleContext  *context,
     {
       GtkCssStyle *style, *static_style;
 
-      static_style = build_properties (context, cssnode->decl, TRUE, gtk_css_node_get_parent_style (context, 
cssnode));
+      static_style = build_properties (context, gtk_css_node_get_declaration (cssnode), TRUE, 
gtk_css_node_get_parent_style (context, cssnode));
       style = gtk_css_animated_style_new (static_style,
                                           priv->parent ? gtk_style_context_lookup_style (priv->parent) : 
NULL,
                                           timestamp,
@@ -2997,7 +2999,7 @@ _gtk_style_context_validate (GtkStyleContext  *context,
               
               new_base = update_properties (context,
                                             GTK_CSS_ANIMATED_STYLE (current)->style,
-                                            cssnode->decl,
+                                            gtk_css_node_get_declaration (cssnode),
                                             TRUE,
                                             gtk_css_node_get_parent_style (context, cssnode),
                                             parent_changes);
@@ -3010,7 +3012,7 @@ _gtk_style_context_validate (GtkStyleContext  *context,
             {
              new_values = update_properties (context,
                                               current,
-                                              cssnode->decl,
+                                              gtk_css_node_get_declaration (cssnode),
                                               TRUE,
                                               gtk_css_node_get_parent_style (context, cssnode),
                                               parent_changes);
@@ -3102,7 +3104,7 @@ gtk_style_context_invalidate (GtkStyleContext *context)
 
   root = gtk_style_context_get_root (context);
   style = build_properties (context,
-                            root->decl,
+                            gtk_css_node_get_declaration (root),
                             TRUE,
                             gtk_css_node_get_parent_style (context, root));
   gtk_css_node_set_style (root, style);


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