[monet/bberg-playground] Give the parser earlier values of the same property.



commit a1124c6c326dce8bbd1fe08686d7df282684cf2f
Author: Benjamin Berg <benjamin sipsolutions net>
Date:   Thu Aug 20 20:17:50 2009 +0200

    Give the parser earlier values of the same property.
    
    This is needed if one parses properties that can be split into
    multiple small properties.

 monet/mn-stylesheet.c |   13 ++++++++++---
 tests/test.c          |   35 +++++++++++++++++++++++++----------
 2 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/monet/mn-stylesheet.c b/monet/mn-stylesheet.c
index 8c909a0..d0f3d8b 100644
--- a/monet/mn-stylesheet.c
+++ b/monet/mn-stylesheet.c
@@ -869,6 +869,7 @@ _mn_stylesheet_resolve_properties (MnStylesheet *stylesheet,
       MnPListItem *plist_item = (MnPListItem*) plist->data;
       MnPropertyInfo *prop_info;
       GValue *parent_value;
+      gboolean insert = FALSE;
       constant = TRUE;
 
       prop_info = mn_theme_type_get_property_info (theme_type,
@@ -884,8 +885,13 @@ _mn_stylesheet_resolve_properties (MnStylesheet *stylesheet,
       if (parent_properties)
         parent_value = g_hash_table_lookup (parent_properties, prop_info->priv);
 
-      value = g_slice_new0 (GValue);
-      g_value_init (value, prop_info->property_type);
+      value = g_hash_table_lookup (properties, prop_info->priv);
+      if (!value)
+        {
+          value = g_slice_new0 (GValue);
+          g_value_init (value, prop_info->property_type);
+          insert = TRUE;
+        }
       
       prop_info->parser (prop_info,
                          plist_item->property,
@@ -895,7 +901,8 @@ _mn_stylesheet_resolve_properties (MnStylesheet *stylesheet,
                          value,
                          &constant);
 
-      g_hash_table_insert (properties, prop_info->priv, value);
+      if (insert)
+        g_hash_table_insert (properties, prop_info->priv, value);
 
       plist = plist->next;
     }
diff --git a/tests/test.c b/tests/test.c
index 2442362..5741404 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -39,11 +39,11 @@ color_parser (MnPropertyInfo       *info,
 {
   GdkColor gdk_color;
   gboolean success;
-  TestColor color;
 
   success = gdk_color_parse (rc_string, &gdk_color);
   if (success)
     {
+      TestColor color;
       color.r = (gdouble) gdk_color.red / 65535.0;
       color.g = (gdouble) gdk_color.green / 65535.0;
       color.b = (gdouble) gdk_color.blue / 65535.0;
@@ -56,10 +56,21 @@ color_parser (MnPropertyInfo       *info,
       if (parent_value)
         {
           g_assert (G_VALUE_TYPE (parent_value) == G_VALUE_TYPE (property_value));
-          g_print ("inheriting!\n");
           g_value_copy (parent_value, property_value);
         }
     }
+  else if (g_str_has_prefix (rc_string, "darken"))
+    {
+      TestColor *color;
+      /* Just a demonstration. All values will be parsed currently. */
+      color = g_value_get_boxed (property_value);
+      if (color)
+        {
+          color->r *= 0.80;
+          color->g *= 0.80;
+          color->b *= 0.80;
+        }
+    }
 }
 
 int
@@ -95,10 +106,10 @@ main(int argc, char **argv)
   "  color: gray; \n"
   "} \n"
   "button.urgent { \n"
-  "  color: blue; \n"
+  "  color: red; \n"
   "} \n"
   ":prelight { \n"
-  "  color: red; \n"
+  "  color: darken; \n"
   "} \n"
   "window { \n"
   "  color: green; \n"
@@ -118,19 +129,22 @@ main(int argc, char **argv)
     g_print ("window: %f, %f, %f, %f\n", (float)color->r, (float)color->g, (float)color->b, (float)color->a);
 
   mn_context_push (context, "button");
-
   g_value_reset (&value);
   mn_context_get_property (context, "color", &value);
   color = g_value_get_boxed (&value);
   if (color)
     g_print ("window > button: %f, %f, %f, %f\n", (float)color->r, (float)color->g, (float)color->b, (float)color->a);
 
-  mn_context_add_class (context, "urgent");
-  /*mn_context_add_pseudo_class (context, "active");
   mn_context_add_pseudo_class (context, "prelight");
-  mn_context_remove_pseudo_class (context, "active");
-  mn_context_clear_pseudo_classes (context);
-  mn_context_add_pseudo_class (context, "insensitive");*/
+
+  g_value_reset (&value);
+  mn_context_get_property (context, "color", &value);
+  color = g_value_get_boxed (&value);
+  if (color)
+    g_print ("window > button:prelight: %f, %f, %f, %f\n", (float)color->r, (float)color->g, (float)color->b, (float)color->a);
+
+  mn_context_remove_pseudo_class (context, "prelight");
+  mn_context_add_class (context, "urgent");
 
   g_value_reset (&value);
   mn_context_get_property (context, "color", &value);
@@ -139,6 +153,7 @@ main(int argc, char **argv)
     g_print ("window > button.urgent: %f, %f, %f, %f\n", (float)color->r, (float)color->g, (float)color->b, (float)color->a);
 
   mn_context_add_pseudo_class (context, "prelight");
+
   g_value_reset (&value);
   mn_context_get_property (context, "color", &value);
   color = g_value_get_boxed (&value);



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