[gtk+/wip/css: 122/143] stylecontext: NMake safe to call into during lookup



commit dd74c675079b60d85b0dba76f6de1a72a24f4d54
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 3 04:36:11 2012 +0100

    stylecontext: NMake safe to call into during lookup
    
    When resolving a lookup, we may want to query the current style context,
    as in the next patch. This works now.

 gtk/gtkcsslookup.c        |   19 +++++++----------
 gtk/gtkcsslookupprivate.h |    5 ++-
 gtk/gtkstylecontext.c     |   49 +++++++++++++++++++++-----------------------
 3 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkcsslookup.c b/gtk/gtkcsslookup.c
index ff833cb..ef075d3 100644
--- a/gtk/gtkcsslookup.c
+++ b/gtk/gtkcsslookup.c
@@ -107,29 +107,28 @@ _gtk_css_lookup_set (GtkCssLookup  *lookup,
  * _gtk_css_lookup_resolve:
  * @lookup: the lookup
  * @context: the context the values are resolved for
+ * @props: a new #GtkStyleProperties to be filled with the new properties
  *
  * Resolves the current lookup into a styleproperties object. This is done
  * by converting from the "winning declaration" to the "computed value".
  *
  * XXX: This bypasses the notion of "specified value". If this ever becomes
  * an issue, go fix it.
- *
- * Returns: a new #GtkStyleProperties
  **/
-GtkStyleProperties *
-_gtk_css_lookup_resolve (GtkCssLookup    *lookup,
-                         GtkStyleContext *context)
+void
+_gtk_css_lookup_resolve (GtkCssLookup       *lookup,
+                         GtkStyleContext    *context,
+                         GtkStyleProperties *props)
 {
-  GtkStyleProperties *props;
   GtkStyleContext *parent;
   guint i, n;
 
-  g_return_val_if_fail (lookup != NULL, NULL);
-  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+  g_return_if_fail (lookup != NULL);
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
 
   parent = gtk_style_context_get_parent (context);
   n = _gtk_css_style_property_get_n_properties ();
-  props = gtk_style_properties_new ();
 
   for (i = 0; i < n; i++)
     {
@@ -219,6 +218,4 @@ _gtk_css_lookup_resolve (GtkCssLookup    *lookup,
                                                       &value);
       g_value_unset (&value);
     }
-
-  return props;
 }
diff --git a/gtk/gtkcsslookupprivate.h b/gtk/gtkcsslookupprivate.h
index 79e5578..90cf0cf 100644
--- a/gtk/gtkcsslookupprivate.h
+++ b/gtk/gtkcsslookupprivate.h
@@ -41,8 +41,9 @@ void                    _gtk_css_lookup_set                     (GtkCssLookup
                                                                  guint               id,
                                                                  GtkCssSection      *section,
                                                                  const GValue       *value);
-GtkStyleProperties *    _gtk_css_lookup_resolve                 (GtkCssLookup       *lookup,
-                                                                 GtkStyleContext    *context);
+void                    _gtk_css_lookup_resolve                 (GtkCssLookup       *lookup,
+                                                                 GtkStyleContext    *context,
+                                                                 GtkStyleProperties *props);
 
 
 G_END_DECLS
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index be0fb8a..b53f82c 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -987,10 +987,11 @@ build_properties (GtkStyleContext *context,
         }
     }
 
-  style_data->store = _gtk_css_lookup_resolve (lookup, context);
+  style_data->store = gtk_style_properties_new ();
   _gtk_style_properties_set_color_lookup_func (style_data->store,
                                                gtk_style_context_color_lookup_func,
                                                context);
+  _gtk_css_lookup_resolve (lookup, context, style_data->store);
   _gtk_css_lookup_free (lookup);
 }
 
@@ -1091,44 +1092,40 @@ style_data_lookup (GtkStyleContext *context,
       gtk_style_context_set_state (context, state);
     }
 
-  data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
+  priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
+  priv->current_state = state;
 
-  if (!data)
+  if (!priv->current_data)
     {
       GtkWidgetPath *path;
 
-      data = style_data_new ();
-      path = create_query_path (context);
-
-      build_properties (context, data, path, state);
-      build_icon_factories (context, data, path);
-
+      priv->current_data = style_data_new ();
       g_hash_table_insert (priv->style_data,
                            style_info_copy (priv->info_stack->data),
-                           data);
+                           priv->current_data);
+
+      path = create_query_path (context);
+
+      build_properties (context, priv->current_data, path, state);
+      build_icon_factories (context, priv->current_data, path);
 
       gtk_widget_path_free (path);
     }
 
-  if (G_UNLIKELY (state_mismatch))
-    {
-      gtk_style_context_restore (context);
-    }
-  else
-    {
-      if (priv->theming_engine)
-        g_object_unref (priv->theming_engine);
+  data = priv->current_data;
 
-      gtk_style_properties_get (data->store, 0,
-                                "engine", &priv->theming_engine,
-                                NULL);
+  if (priv->theming_engine)
+    g_object_unref (priv->theming_engine);
 
-      if (!priv->theming_engine)
-        priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
-    }
+  gtk_style_properties_get (priv->current_data->store, 0,
+                            "engine", &priv->theming_engine,
+                            NULL);
 
-  priv->current_data = data;
-  priv->current_state = state;
+  if (!priv->theming_engine)
+    priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
+
+  if (G_UNLIKELY (state_mismatch))
+    gtk_style_context_restore (context);
 
   return data;
 }



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