]> Pileus Git - ~andy/gtk/commitdiff
Add GtkStylePropertyContext and use it in when getting style properties
authorAlexander Larsson <alexl@redhat.com>
Tue, 15 Nov 2011 15:56:59 +0000 (16:56 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 17 Nov 2011 11:27:22 +0000 (12:27 +0100)
At the toplevel we have _gtk_theming_engine_get, which lets us pass
in a property context with (atm) the size to get the property for.
Then there is a lot of plumbing to push this down into the lower
layers of the style property code until finally hitting
the property resolvers.

I need this because I will be adding a property resolver for win32
theme parts, and they render differently depending on the size
(i.e. they don't scale linearly). The idea is that the code
to get the background properties will pass in the final size
and we will resolve the theme part specification to that particular
size.

If the old non-context calls are used we just hardcode a size
of 100x100.

gtk/gtkborderimage.c
gtk/gtkborderimageprivate.h
gtk/gtkstylecontext.c
gtk/gtkstylecontextprivate.h
gtk/gtkstyleproperties.c
gtk/gtkstylepropertiesprivate.h
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h
gtk/gtkthemingengine.c
gtk/gtkthemingengineprivate.h

index dd8259131b24ad13467a0a36768c73d7021ddd7a..48d690d2e6fe2f745b0992d5f1c675968c8f0baa 100644 (file)
@@ -27,6 +27,7 @@
 #include <math.h>
 
 #include "gtkborderimageprivate.h"
+#include "gtkstylepropertiesprivate.h"
 
 /* this is in case round() is not provided by the compiler, 
  * such as in the case of C89 compilers, like MSVC
@@ -194,19 +195,20 @@ _gtk_border_image_unpack (const GValue *value,
 void
 _gtk_border_image_pack (GValue             *value,
                         GtkStyleProperties *props,
-                        GtkStateFlags       state)
+                        GtkStateFlags       state,
+                       GtkStylePropertyContext *context)
 {
   GtkBorderImage *image;
   cairo_pattern_t *source;
   GtkBorder *slice, *width;
   GtkCssBorderImageRepeat *repeat;
 
-  gtk_style_properties_get (props, state,
-                            "border-image-source", &source,
-                            "border-image-slice", &slice,
-                            "border-image-repeat", &repeat,
-                            "border-image-width", &width,
-                            NULL);
+  _gtk_style_properties_get (props, state, context,
+                            "border-image-source", &source,
+                            "border-image-slice", &slice,
+                            "border-image-repeat", &repeat,
+                            "border-image-width", &width,
+                            NULL);
 
   if (source == NULL)
     {
index 563ce299de08c1771e693ec29ac907737972480e..ee4975f26375fbdb3d900900069a326171fecfdf 100644 (file)
@@ -29,6 +29,7 @@
 #include "gtkstyleproperties.h"
 #include "gtkthemingengine.h"
 #include "gtkcsstypesprivate.h"
+#include "gtkstylecontextprivate.h"
 
 G_BEGIN_DECLS
 
@@ -63,7 +64,8 @@ GParameter *      _gtk_border_image_unpack           (const GValue         *valu
                                                       guint                *n_params);
 void              _gtk_border_image_pack             (GValue               *value,
                                                       GtkStyleProperties   *props,
-                                                      GtkStateFlags         state);
+                                                      GtkStateFlags         state,
+                                                     GtkStylePropertyContext *context);
 
 G_END_DECLS
 
index e67c4cca383eb19af9baa9943f7580414cb0cf0f..b2993ecfee847d0541d351c67631498445dc958a 100644 (file)
@@ -1367,6 +1367,24 @@ gtk_style_context_get_property (GtkStyleContext *context,
   gtk_style_properties_get_property (data->store, property, state, value);
 }
 
+void
+_gtk_style_context_get_valist (GtkStyleContext *context,
+                              GtkStateFlags    state,
+                              GtkStylePropertyContext *property_context,
+                              va_list          args)
+{
+  GtkStyleContextPrivate *priv;
+  StyleData *data;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+  priv = context->priv;
+  g_return_if_fail (priv->widget_path != NULL);
+
+  data = style_data_lookup (context);
+  _gtk_style_properties_get_valist (data->store, state, property_context, args);
+}
+
 /**
  * gtk_style_context_get_valist:
  * @context: a #GtkStyleContext
index 57db77e5cb6b44b9613d48b51d1065ee05b99621..9796bafc662ee69ae97d30fe1493773a4458d927 100644 (file)
 
 G_BEGIN_DECLS
 
-
+typedef struct _GtkStylePropertyContext GtkStylePropertyContext;
+struct _GtkStylePropertyContext
+{
+  int width;
+  int height;
+};
+
+void           _gtk_style_context_get_valist (GtkStyleContext *context,
+                                             GtkStateFlags    state,
+                                             GtkStylePropertyContext *property_context,
+                                             va_list          args);
 const GValue * _gtk_style_context_peek_style_property        (GtkStyleContext *context,
                                                               GType            widget_type,
                                                               GtkStateFlags    state,
index f3946f86598e9af4a96543e08ff56e92a2e9584f..3a6b4b475a3f69ad8881fb54fa0611e3b63b31cc 100644 (file)
@@ -640,6 +640,7 @@ const GValue *
 _gtk_style_properties_peek_property (GtkStyleProperties      *props,
                                      const gchar             *prop_name,
                                      GtkStateFlags            state,
+                                    GtkStylePropertyContext *context,
                                      const GtkStyleProperty **property)
 {
   GtkStylePropertiesPrivate *priv;
@@ -670,30 +671,17 @@ _gtk_style_properties_peek_property (GtkStyleProperties      *props,
   if (val == NULL)
     return NULL;
   
-  _gtk_style_property_resolve (node, props, state, val);
+  _gtk_style_property_resolve (node, props, state, context, val);
 
   return val;
 }
 
-/**
- * gtk_style_properties_get_property:
- * @props: a #GtkStyleProperties
- * @property: style property name
- * @state: state to retrieve the property value for
- * @value: (out) (transfer full):  return location for the style property value.
- *
- * Gets a style property from @props for the given state. When done with @value,
- * g_value_unset() needs to be called to free any allocated memory.
- *
- * Returns: %TRUE if the property exists in @props, %FALSE otherwise
- *
- * Since: 3.0
- **/
 gboolean
-gtk_style_properties_get_property (GtkStyleProperties *props,
-                                   const gchar        *property,
-                                   GtkStateFlags       state,
-                                   GValue             *value)
+_gtk_style_properties_get_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   GtkStylePropertyContext *context,
+                                   GValue             *value)
 {
   const GtkStyleProperty *node;
   const GValue *val;
@@ -702,7 +690,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
   g_return_val_if_fail (property != NULL, FALSE);
   g_return_val_if_fail (value != NULL, FALSE);
 
-  val = _gtk_style_properties_peek_property (props, property, state, &node);
+  val = _gtk_style_properties_peek_property (props, property, state, context, &node);
 
   if (!node)
     return FALSE;
@@ -712,7 +700,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
   if (val)
     g_value_copy (val, value);
   else if (_gtk_style_property_is_shorthand (node))
-    _gtk_style_property_pack (node, props, state, value);
+    _gtk_style_property_pack (node, props, state, context, value);
   else
     _gtk_style_property_default_value (node, props, state, value);
 
@@ -720,19 +708,41 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
 }
 
 /**
- * gtk_style_properties_get_valist:
+ * gtk_style_properties_get_property:
  * @props: a #GtkStyleProperties
- * @state: state to retrieve the property values for
- * @args: va_list of property name/return location pairs, followed by %NULL
+ * @property: style property name
+ * @state: state to retrieve the property value for
+ * @value: (out) (transfer full):  return location for the style property value.
  *
- * Retrieves several style property values from @props for a given state.
+ * Gets a style property from @props for the given state. When done with @value,
+ * g_value_unset() needs to be called to free any allocated memory.
+ *
+ * Returns: %TRUE if the property exists in @props, %FALSE otherwise
  *
  * Since: 3.0
  **/
+gboolean
+gtk_style_properties_get_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   GValue             *value)
+{
+  GtkStylePropertyContext context = { 100, 100};
+
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
+  g_return_val_if_fail (property != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
+
+  return _gtk_style_properties_get_property (props,
+                                            property,
+                                            state, &context, value);
+}
+
 void
-gtk_style_properties_get_valist (GtkStyleProperties *props,
-                                 GtkStateFlags       state,
-                                 va_list             args)
+_gtk_style_properties_get_valist (GtkStyleProperties *props,
+                                 GtkStateFlags       state,
+                                 GtkStylePropertyContext *context,
+                                 va_list             args)
 {
   const gchar *property_name;
 
@@ -746,7 +756,7 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
       gchar *error = NULL;
       const GValue *val;
 
-      val = _gtk_style_properties_peek_property (props, property_name, state, &node);
+      val = _gtk_style_properties_peek_property (props, property_name, state, context, &node);
       if (!node)
         break;
 
@@ -759,7 +769,7 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
           GValue packed = G_VALUE_INIT;
 
           g_value_init (&packed, node->pspec->value_type);
-          _gtk_style_property_pack (node, props, state, &packed);
+          _gtk_style_property_pack (node, props, state, context, &packed);
           G_VALUE_LCOPY (&packed, args, 0, &error);
           g_value_unset (&packed);
         }
@@ -784,6 +794,41 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
     }
 }
 
+/**
+ * gtk_style_properties_get_valist:
+ * @props: a #GtkStyleProperties
+ * @state: state to retrieve the property values for
+ * @args: va_list of property name/return location pairs, followed by %NULL
+ *
+ * Retrieves several style property values from @props for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_get_valist (GtkStyleProperties *props,
+                                 GtkStateFlags       state,
+                                 va_list             args)
+{
+  GtkStylePropertyContext context = { 100, 100};
+  
+  return _gtk_style_properties_get_valist (props, state, &context, args);
+}
+
+void
+_gtk_style_properties_get (GtkStyleProperties *props,
+                          GtkStateFlags       state,
+                          GtkStylePropertyContext *context,
+                          ...)
+{
+  va_list args;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  va_start (args, context);
+  _gtk_style_properties_get_valist (props, state, context, args);
+  va_end (args);
+}
+
 /**
  * gtk_style_properties_get:
  * @props: a #GtkStyleProperties
index bbb5d81fbf1b0abfbb55aebec4c2641c0c244a01..628fd5033931e3534556bd48bbb97f77ba00e2f9 100644 (file)
 
 #include "gtkstyleproperties.h"
 #include "gtkstylepropertyprivate.h"
+#include "gtkstylecontextprivate.h"
 
 G_BEGIN_DECLS
 
 const GValue * _gtk_style_properties_peek_property            (GtkStyleProperties      *props,
                                                                const gchar             *prop_name,
                                                                GtkStateFlags            state,
+                                                              GtkStylePropertyContext *context,
                                                                const GtkStyleProperty **property);
+void           _gtk_style_properties_get                      (GtkStyleProperties      *props,
+                                                              GtkStateFlags            state,
+                                                              GtkStylePropertyContext *context,
+                                                              ...);
+void           _gtk_style_properties_get_valist               (GtkStyleProperties      *props,
+                                                              GtkStateFlags            state,
+                                                              GtkStylePropertyContext *context,
+                                                              va_list                  args);
+
+const GValue * _gtk_style_properties_resolve_property         (GtkStyleProperties      *props,
+                                                              const gchar             *prop_name,
+                                                              GtkStateFlags            state,
+                                                              const GtkStyleProperty **property,
+                                                              GtkStylePropertyContext *context,
+                                                              GValue                  *value);
 
 void           _gtk_style_properties_set_property_by_property (GtkStyleProperties      *props,
                                                                const GtkStyleProperty  *property,
index 99b804f595bd8cc8960a69609a707d501fc20a99..2ece9b65de047122e2717db9a9ced6d91698cc9d 100644 (file)
@@ -1855,7 +1855,8 @@ unpack_border_width (const GValue *value,
 static void
 pack_border_width (GValue             *value,
                    GtkStyleProperties *props,
-                   GtkStateFlags       state)
+                   GtkStateFlags       state,
+                  GtkStylePropertyContext *context)
 {
   pack_border (value, props, state,
                "border-top-width", "border-left-width",
@@ -1874,7 +1875,8 @@ unpack_padding (const GValue *value,
 static void
 pack_padding (GValue             *value,
               GtkStyleProperties *props,
-              GtkStateFlags       state)
+              GtkStateFlags       state,
+             GtkStylePropertyContext *context)
 {
   pack_border (value, props, state,
                "padding-top", "padding-left",
@@ -1893,7 +1895,8 @@ unpack_margin (const GValue *value,
 static void
 pack_margin (GValue             *value,
              GtkStyleProperties *props,
-             GtkStateFlags       state)
+             GtkStateFlags       state,
+            GtkStylePropertyContext *context)
 {
   pack_border (value, props, state,
                "margin-top", "margin-left",
@@ -1935,7 +1938,8 @@ unpack_border_radius (const GValue *value,
 static void
 pack_border_radius (GValue             *value,
                     GtkStyleProperties *props,
-                    GtkStateFlags       state)
+                    GtkStateFlags       state,
+                   GtkStylePropertyContext *context)
 {
   GtkCssBorderCornerRadius *top_left;
 
@@ -2035,7 +2039,8 @@ unpack_font_description (const GValue *value,
 static void
 pack_font_description (GValue             *value,
                        GtkStyleProperties *props,
-                       GtkStateFlags       state)
+                       GtkStateFlags       state,
+                      GtkStylePropertyContext *context)
 {
   PangoFontDescription *description;
   char **families;
@@ -2113,7 +2118,8 @@ unpack_border_color (const GValue *value,
 static void
 pack_border_color (GValue             *value,
                    GtkStyleProperties *props,
-                   GtkStateFlags       state)
+                   GtkStateFlags       state,
+                  GtkStylePropertyContext *context)
 {
   /* NB: We are a color property, so we have to resolve to a color here.
    * So we just resolve to a color. We pick one and stick to it.
@@ -2512,6 +2518,7 @@ void
 _gtk_style_property_resolve (const GtkStyleProperty *property,
                              GtkStyleProperties     *props,
                              GtkStateFlags           state,
+                            GtkStylePropertyContext *context,
                              GValue                 *val)
 {
   if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
@@ -2579,6 +2586,7 @@ void
 _gtk_style_property_pack (const GtkStyleProperty *property,
                           GtkStyleProperties     *props,
                           GtkStateFlags           state,
+                         GtkStylePropertyContext *context,
                           GValue                 *value)
 {
   g_return_if_fail (property != NULL);
@@ -2586,7 +2594,7 @@ _gtk_style_property_pack (const GtkStyleProperty *property,
   g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
   g_return_if_fail (G_IS_VALUE (value));
 
-  property->pack_func (value, props, state);
+  property->pack_func (value, props, state, context);
 }
 
 static void
index aef18b8893b5cc3758ab6ab3c29475da99f081af..07994d5f2620700d3a66c70631e979068d0a6a97 100644 (file)
@@ -21,6 +21,7 @@
 #define __GTK_STYLEPROPERTY_PRIVATE_H__
 
 #include "gtkcssparserprivate.h"
+#include "gtkstylecontextprivate.h"
 
 G_BEGIN_DECLS
 
@@ -33,7 +34,8 @@ typedef GParameter *     (* GtkStyleUnpackFunc)            (const GValue
                                                             guint                  *n_params);
 typedef void             (* GtkStylePackFunc)              (GValue                 *value,
                                                             GtkStyleProperties     *props,
-                                                            GtkStateFlags           state);
+                                                            GtkStateFlags           state,
+                                                           GtkStylePropertyContext *context);
 typedef gboolean         (* GtkStyleParseFunc)             (GtkCssParser           *parser,
                                                             GFile                  *base,
                                                             GValue                 *value);
@@ -82,7 +84,8 @@ void                     _gtk_style_property_default_value (const GtkStyleProper
 void                     _gtk_style_property_resolve       (const GtkStyleProperty *property,
                                                             GtkStyleProperties     *properties,
                                                             GtkStateFlags           state,
-                                                            GValue                 *value);
+                                                           GtkStylePropertyContext *context,
+                                                            GValue                 *orig_value);
 
 gboolean                 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property);
 GParameter *             _gtk_style_property_unpack        (const GtkStyleProperty *property,
@@ -91,6 +94,7 @@ GParameter *             _gtk_style_property_unpack        (const GtkStyleProper
 void                     _gtk_style_property_pack          (const GtkStyleProperty *property,
                                                             GtkStyleProperties     *props,
                                                             GtkStateFlags           state,
+                                                           GtkStylePropertyContext *context,
                                                             GValue                 *value);
 
 gboolean                 _gtk_style_property_parse_value   (const GtkStyleProperty *property,
index f068c3d38dbb9412beb53e5b9d1239acf4877439..81430d56e22fa30644c5ca82ab184cae4354b425 100644 (file)
@@ -450,6 +450,25 @@ gtk_theming_engine_get_valist (GtkThemingEngine *engine,
   gtk_style_context_get_valist (priv->context, state, args);
 }
 
+void
+_gtk_theming_engine_get (GtkThemingEngine *engine,
+                        GtkStateFlags     state,
+                        GtkStylePropertyContext *property_context,
+                        ...)
+{
+  GtkThemingEnginePrivate *priv;
+  va_list args;
+
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+  priv = engine->priv;
+
+  va_start (args, property_context);
+  _gtk_style_context_get_valist (priv->context, state, property_context, args);
+  va_end (args);
+}
+
+
 /**
  * gtk_theming_engine_get:
  * @engine: a #GtkThemingEngine
index caf189ec6b3d4c3172a02635d2603b34068ebd0a..5191fa05b83245a58406bbdf8f10244cc7eced5f 100644 (file)
 #define __GTK_THEMING_ENGINE_PRIVATE_H__
 
 #include <gdk/gdk.h>
+#include "gtkstylecontextprivate.h"
+
+void _gtk_theming_engine_get          (GtkThemingEngine *engine,
+                                      GtkStateFlags     state,
+                                      GtkStylePropertyContext *property_context,
+                                      ...) G_GNUC_NULL_TERMINATED;
+
 
 void _gtk_theming_engine_paint_spinner (cairo_t *cr,
                                         gdouble  radius,