diff options
author | Benjamin Otte <otte@redhat.com> | 2011-05-31 16:51:38 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-06-02 02:03:52 +0200 |
commit | 18458495967ccf73bc1f8b0fb2a2150402d5cd91 (patch) | |
tree | 5fb63df8a6e2d046e5378a1ec9a5e2e962cb1d95 | |
parent | cc3afc7c0fb5fc90173ca084bb6b55e9be217252 (diff) | |
download | gtk+-18458495967ccf73bc1f8b0fb2a2150402d5cd91.tar.gz |
styleproperty: Move resolving code
Also, resolving now always succeeds - if it doesn't we fall back to the
default value right here, instead of later.
-rw-r--r-- | gtk/gtkstyleproperties.c | 121 | ||||
-rw-r--r-- | gtk/gtkstyleproperty.c | 113 | ||||
-rw-r--r-- | gtk/gtkstylepropertyprivate.h | 4 |
3 files changed, 120 insertions, 118 deletions
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c index 45fdfbd8d5..6cf497390c 100644 --- a/gtk/gtkstyleproperties.c +++ b/gtk/gtkstyleproperties.c @@ -633,121 +633,6 @@ gtk_style_properties_set (GtkStyleProperties *props, va_end (args); } -static gboolean -resolve_color (GtkStyleProperties *props, - GValue *value) -{ - GdkRGBA color; - - /* Resolve symbolic color to GdkRGBA */ - if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color)) - return FALSE; - - /* Store it back, this is where GdkRGBA caching happens */ - g_value_unset (value); - g_value_init (value, GDK_TYPE_RGBA); - g_value_set_boxed (value, &color); - - return TRUE; -} - -static gboolean -resolve_color_rgb (GtkStyleProperties *props, - GValue *value) -{ - GdkColor color = { 0 }; - GdkRGBA rgba; - - if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba)) - return FALSE; - - color.red = rgba.red * 65535. + 0.5; - color.green = rgba.green * 65535. + 0.5; - color.blue = rgba.blue * 65535. + 0.5; - - g_value_unset (value); - g_value_init (value, GDK_TYPE_COLOR); - g_value_set_boxed (value, &color); - - return TRUE; -} - -static gboolean -resolve_gradient (GtkStyleProperties *props, - GValue *value) -{ - cairo_pattern_t *gradient; - - if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient)) - return FALSE; - - /* Store it back, this is where cairo_pattern_t caching happens */ - g_value_unset (value); - g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN); - g_value_take_boxed (value, gradient); - - return TRUE; -} - -static gboolean -resolve_shadow (GtkStyleProperties *props, - GValue *value) -{ - GtkShadow *resolved, *base; - - base = g_value_get_boxed (value); - - if (base == NULL) - return TRUE; - - if (_gtk_shadow_get_resolved (base)) - return TRUE; - - resolved = _gtk_shadow_resolve (base, props); - if (resolved == NULL) - return FALSE; - - g_value_take_boxed (value, resolved); - - return TRUE; -} - -static gboolean -style_properties_resolve_type (GtkStyleProperties *props, - const GtkStyleProperty *node, - GValue *val) -{ - if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR) - { - if (node->pspec->value_type == GDK_TYPE_RGBA) - { - if (!resolve_color (props, val)) - return FALSE; - } - else if (node->pspec->value_type == GDK_TYPE_COLOR) - { - if (!resolve_color_rgb (props, val)) - return FALSE; - } - else - return FALSE; - } - else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT) - { - g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE); - - if (!resolve_gradient (props, val)) - return FALSE; - } - else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW) - { - if (!resolve_shadow (props, val)) - return FALSE; - } - - return TRUE; -} - /* NB: Will return NULL for shorthands */ const GValue * _gtk_style_properties_peek_property (GtkStyleProperties *props, @@ -780,10 +665,10 @@ _gtk_style_properties_peek_property (GtkStyleProperties *props, return NULL; val = property_data_match_state (prop, state); - - if (val && - !style_properties_resolve_type (props, node, val)) + if (val == NULL) return NULL; + + _gtk_style_property_resolve (node, props, val); return val; } diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c index 6458c83f8f..8115603494 100644 --- a/gtk/gtkstyleproperty.c +++ b/gtk/gtkstyleproperty.c @@ -1949,6 +1949,119 @@ _gtk_style_property_is_inherit (const GtkStyleProperty *property) return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE; } +static gboolean +resolve_color (GtkStyleProperties *props, + GValue *value) +{ + GdkRGBA color; + + /* Resolve symbolic color to GdkRGBA */ + if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color)) + return FALSE; + + /* Store it back, this is where GdkRGBA caching happens */ + g_value_unset (value); + g_value_init (value, GDK_TYPE_RGBA); + g_value_set_boxed (value, &color); + + return TRUE; +} + +static gboolean +resolve_color_rgb (GtkStyleProperties *props, + GValue *value) +{ + GdkColor color = { 0 }; + GdkRGBA rgba; + + if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba)) + return FALSE; + + color.red = rgba.red * 65535. + 0.5; + color.green = rgba.green * 65535. + 0.5; + color.blue = rgba.blue * 65535. + 0.5; + + g_value_unset (value); + g_value_init (value, GDK_TYPE_COLOR); + g_value_set_boxed (value, &color); + + return TRUE; +} + +static gboolean +resolve_gradient (GtkStyleProperties *props, + GValue *value) +{ + cairo_pattern_t *gradient; + + if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient)) + return FALSE; + + /* Store it back, this is where cairo_pattern_t caching happens */ + g_value_unset (value); + g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN); + g_value_take_boxed (value, gradient); + + return TRUE; +} + +static gboolean +resolve_shadow (GtkStyleProperties *props, + GValue *value) +{ + GtkShadow *resolved, *base; + + base = g_value_get_boxed (value); + + if (base == NULL) + return TRUE; + + if (_gtk_shadow_get_resolved (base)) + return TRUE; + + resolved = _gtk_shadow_resolve (base, props); + if (resolved == NULL) + return FALSE; + + g_value_take_boxed (value, resolved); + + return TRUE; +} + +void +_gtk_style_property_resolve (const GtkStyleProperty *property, + GtkStyleProperties *props, + GValue *val) +{ + if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR) + { + if (property->pspec->value_type == GDK_TYPE_RGBA) + { + if (!resolve_color (props, val)) + _gtk_style_property_resolve (property, props, val); + } + else if (property->pspec->value_type == GDK_TYPE_COLOR) + { + if (!resolve_color_rgb (props, val)) + _gtk_style_property_resolve (property, props, val); + } + else + _gtk_style_property_resolve (property, props, val); + } + else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT) + { + g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN); + + if (!resolve_gradient (props, val)) + _gtk_style_property_resolve (property, props, val); + } + else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW) + { + if (!resolve_shadow (props, val)) + _gtk_style_property_resolve (property, props, val); + } +} + gboolean _gtk_style_property_is_shorthand (const GtkStyleProperty *property) { diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h index dab6f07af0..afa76be616 100644 --- a/gtk/gtkstylepropertyprivate.h +++ b/gtk/gtkstylepropertyprivate.h @@ -73,6 +73,10 @@ void _gtk_style_property_default_value (const GtkStyleProper GtkStyleProperties *properties, GValue *value); +void _gtk_style_property_resolve (const GtkStyleProperty *property, + GtkStyleProperties *properties, + GValue *value); + gboolean _gtk_style_property_is_shorthand (const GtkStyleProperty *property); GParameter * _gtk_style_property_unpack (const GtkStyleProperty *property, const GValue *value, |