diff options
author | Benjamin Otte <otte@redhat.com> | 2012-03-26 06:46:29 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-04-17 08:59:11 +0200 |
commit | 58e4fdf911377c303858d0eebbd2594505dd3a21 (patch) | |
tree | 168be147511201c3f0a92b48b959f54c2d9d6416 | |
parent | b728cfd3e8af1b07fb5f15a22ed9b144b190d37e (diff) | |
download | gtk+-58e4fdf911377c303858d0eebbd2594505dd3a21.tar.gz |
styleproperty: Make print_func take a GtkCssValue
Also, constify GtkCssValue getters, so we can pass a const GtkCssValue
to the print_func.
-rw-r--r-- | gtk/gtkcssstyleproperty.c | 9 | ||||
-rw-r--r-- | gtk/gtkcssstylepropertyimpl.c | 30 | ||||
-rw-r--r-- | gtk/gtkcssstylepropertyprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtkcssvalue.c | 95 | ||||
-rw-r--r-- | gtk/gtkcssvalueprivate.h | 64 |
5 files changed, 116 insertions, 84 deletions
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c index 95b8ba1669..e783aa02c2 100644 --- a/gtk/gtkcssstyleproperty.c +++ b/gtk/gtkcssstyleproperty.c @@ -284,10 +284,10 @@ gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property, static void gtk_css_style_property_real_print_value (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - _gtk_css_style_print_value (value, string); + _gtk_css_value_print (value, string); } static GtkCssValue * @@ -540,10 +540,7 @@ _gtk_css_style_property_print_value (GtkCssStyleProperty *property, } else { - GValue value = G_VALUE_INIT; - _gtk_css_value_init_gvalue (css_value, &value); - property->print_value (property, &value, string); - g_value_unset (&value); + property->print_value (property, css_value, string); } } diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c index acd103f65c..a6a06db7ef 100644 --- a/gtk/gtkcssstylepropertyimpl.c +++ b/gtk/gtkcssstylepropertyimpl.c @@ -235,10 +235,10 @@ font_family_parse (GtkCssStyleProperty *property, static void font_family_value_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - const char **names = g_value_get_boxed (value); + const char **names = _gtk_css_value_get_strv (value); if (names == NULL || *names == NULL) { @@ -298,13 +298,13 @@ bindings_value_parse (GtkCssStyleProperty *property, static void bindings_value_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { GPtrArray *array; guint i; - array = g_value_get_boxed (value); + array = _gtk_css_value_get_boxed (value); for (i = 0; i < array->len; i++) { @@ -348,12 +348,12 @@ border_corner_radius_value_parse (GtkCssStyleProperty *property, static void border_corner_radius_value_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - GtkCssBorderCornerRadius *corner; + const GtkCssBorderCornerRadius *corner; - corner = g_value_get_boxed (value); + corner = _gtk_css_value_get_border_corner_radius (value); _gtk_css_number_print (&corner->horizontal, string); @@ -387,10 +387,10 @@ css_image_value_parse (GtkCssStyleProperty *property, static void css_image_value_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - GtkCssImage *image = g_value_get_object (value); + GtkCssImage *image = _gtk_css_value_get_image (value); if (image) _gtk_css_image_print (image, string); @@ -575,14 +575,14 @@ background_repeat_value_parse (GtkCssStyleProperty *property, static void background_repeat_value_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { GEnumClass *enum_class; GEnumValue *enum_value; GtkCssBackgroundRepeat repeat; - repeat = g_value_get_enum (value); + repeat = _gtk_css_value_get_enum (value); enum_class = g_type_class_ref (GTK_TYPE_CSS_BACKGROUND_REPEAT); enum_value = g_enum_get_value (enum_class, repeat); @@ -649,10 +649,10 @@ background_size_parse (GtkCssStyleProperty *property, static void background_size_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - GtkCssBackgroundSize *size = g_value_get_boxed (value); + const GtkCssBackgroundSize *size = _gtk_css_value_get_background_size (value); if (size->cover) g_string_append (string, "cover"); @@ -792,10 +792,10 @@ background_position_parse (GtkCssStyleProperty *property, static void background_position_print (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string) { - GtkCssBackgroundPosition *pos = g_value_get_boxed (value); + const GtkCssBackgroundPosition *pos = _gtk_css_value_get_background_position (value); static const GtkCssNumber center = GTK_CSS_NUMBER_INIT (50, GTK_CSS_PERCENT); static const struct { const char *x_name; diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h index 21c57b9e65..391f418fd3 100644 --- a/gtk/gtkcssstylepropertyprivate.h +++ b/gtk/gtkcssstylepropertyprivate.h @@ -39,7 +39,7 @@ typedef gboolean (* GtkCssStylePropertyParseFunc) (GtkCssStyleProperty GtkCssParser *parser, GFile *base); typedef void (* GtkCssStylePropertyPrintFunc) (GtkCssStyleProperty *property, - const GValue *value, + const GtkCssValue *value, GString *string); typedef GtkCssValue * (* GtkCssStylePropertyComputeFunc)(GtkCssStyleProperty *property, GtkStyleContext *context, diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c index abd7dc9d11..8030cd475f 100644 --- a/gtk/gtkcssvalue.c +++ b/gtk/gtkcssvalue.c @@ -18,6 +18,7 @@ #include "config.h" #include "gtkcssvalueprivate.h" +#include "gtkcssstylefuncsprivate.h" #include "gtktypebuiltins.h" #include "gtkgradient.h" #include <cairo-gobject.h> @@ -25,7 +26,6 @@ #include "fallback-c89.c" -typedef struct _GtkCssValue GtkCssValue; struct _GtkCssValue { GTK_CSS_VALUE_BASE @@ -79,8 +79,20 @@ gtk_css_value_default_free (GtkCssValue *value) g_slice_free (GtkCssValue, value); } +static void +gtk_css_value_default_print (const GtkCssValue *value, + GString *string) +{ + GValue g_value = G_VALUE_INIT; + + _gtk_css_value_init_gvalue (value, &g_value); + _gtk_css_style_print_value (&g_value, string); + g_value_unset (&g_value); +} + static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = { - gtk_css_value_default_free + gtk_css_value_default_free, + gtk_css_value_default_print }; G_DEFINE_BOXED_TYPE (GtkCssValue, _gtk_css_value, _gtk_css_value_ref, _gtk_css_value_unref) @@ -447,21 +459,31 @@ _gtk_css_value_unref (GtkCssValue *value) value->class->free (value); } +void +_gtk_css_value_print (const GtkCssValue *value, + GString *string) +{ + g_return_if_fail (value != NULL); + g_return_if_fail (string != NULL); + + value->class->print (value, string); +} + GType -_gtk_css_value_get_content_type (GtkCssValue *value) +_gtk_css_value_get_content_type (const GtkCssValue *value) { return value->type; } gboolean -_gtk_css_value_holds (GtkCssValue *value, GType type) +_gtk_css_value_holds (const GtkCssValue *value, GType type) { return g_type_is_a (value->type, type); } static void -fill_gvalue (GtkCssValue *value, - GValue *g_value) +fill_gvalue (const GtkCssValue *value, + GValue *g_value) { GType type; @@ -492,8 +514,8 @@ fill_gvalue (GtkCssValue *value, } void -_gtk_css_value_init_gvalue (GtkCssValue *value, - GValue *g_value) +_gtk_css_value_init_gvalue (const GtkCssValue *value, + GValue *g_value) { if (value != NULL) { @@ -503,55 +525,62 @@ _gtk_css_value_init_gvalue (GtkCssValue *value, } gboolean -_gtk_css_value_is_special (GtkCssValue *value) +_gtk_css_value_is_special (const GtkCssValue *value) { return _gtk_css_value_holds (value, GTK_TYPE_CSS_SPECIAL_VALUE); } GtkCssSpecialValue -_gtk_css_value_get_special_kind (GtkCssValue *value) +_gtk_css_value_get_special_kind (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_SPECIAL_VALUE), 0); return value->u.gint; } const GtkCssNumber * -_gtk_css_value_get_number (GtkCssValue *value) +_gtk_css_value_get_number (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_NUMBER), NULL); return value->u.ptr; } GtkSymbolicColor * -_gtk_css_value_get_symbolic_color (GtkCssValue *value) +_gtk_css_value_get_symbolic_color (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_SYMBOLIC_COLOR), NULL); return value->u.ptr; } int -_gtk_css_value_get_int (GtkCssValue *value) +_gtk_css_value_get_int (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_INT), 0); return value->u.gint; } +int +_gtk_css_value_get_enum (const GtkCssValue *value) +{ + g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_ENUM), 0); + return value->u.gint; +} + double -_gtk_css_value_get_double (GtkCssValue *value) +_gtk_css_value_get_double (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_DOUBLE), 0); return value->u.dbl; } const char * -_gtk_css_value_get_string (GtkCssValue *value) +_gtk_css_value_get_string (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_STRING), 0); return value->u.ptr; } gpointer -_gtk_css_value_dup_object (GtkCssValue *value) +_gtk_css_value_dup_object (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_OBJECT), NULL); if (value->u.ptr) @@ -560,119 +589,119 @@ _gtk_css_value_dup_object (GtkCssValue *value) } gpointer -_gtk_css_value_get_object (GtkCssValue *value) +_gtk_css_value_get_object (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_OBJECT), NULL); return value->u.ptr; } gpointer -_gtk_css_value_get_boxed (GtkCssValue *value) +_gtk_css_value_get_boxed (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_BOXED), NULL); return value->u.ptr; } const char ** -_gtk_css_value_get_strv (GtkCssValue *value) +_gtk_css_value_get_strv (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_STRV), NULL); return value->u.ptr; } GtkCssImage * -_gtk_css_value_get_image (GtkCssValue *value) +_gtk_css_value_get_image (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_IMAGE), NULL); return value->u.ptr; } GtkBorderStyle -_gtk_css_value_get_border_style (GtkCssValue *value) +_gtk_css_value_get_border_style (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_BORDER_STYLE), 0); return value->u.gint; } const GtkCssBackgroundSize * -_gtk_css_value_get_background_size (GtkCssValue *value) +_gtk_css_value_get_background_size (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BACKGROUND_SIZE), NULL); return value->u.ptr; } const GtkCssBackgroundPosition * -_gtk_css_value_get_background_position (GtkCssValue *value) +_gtk_css_value_get_background_position (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BACKGROUND_POSITION), NULL); return value->u.ptr; } const GtkCssBorderImageRepeat * -_gtk_css_value_get_border_image_repeat (GtkCssValue *value) +_gtk_css_value_get_border_image_repeat (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT), NULL); return value->u.ptr; } const GtkCssBorderCornerRadius * -_gtk_css_value_get_border_corner_radius (GtkCssValue *value) +_gtk_css_value_get_border_corner_radius (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS), NULL); return value->u.ptr; } PangoFontDescription * -_gtk_css_value_get_font_description (GtkCssValue *value) +_gtk_css_value_get_font_description (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_FONT_DESCRIPTION), 0); return value->u.ptr; } PangoStyle -_gtk_css_value_get_pango_style (GtkCssValue *value) +_gtk_css_value_get_pango_style (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_STYLE), 0); return value->u.gint; } PangoVariant -_gtk_css_value_get_pango_variant (GtkCssValue *value) +_gtk_css_value_get_pango_variant (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_VARIANT), 0); return value->u.gint; } PangoWeight -_gtk_css_value_get_pango_weight (GtkCssValue *value) +_gtk_css_value_get_pango_weight (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_WEIGHT), 0); return value->u.gint; } const GdkRGBA * -_gtk_css_value_get_rgba (GtkCssValue *value) +_gtk_css_value_get_rgba (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GDK_TYPE_RGBA), NULL); return value->u.ptr; } cairo_pattern_t * -_gtk_css_value_get_pattern (GtkCssValue *value) +_gtk_css_value_get_pattern (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, CAIRO_GOBJECT_TYPE_PATTERN), NULL); return value->u.ptr; } GtkGradient * -_gtk_css_value_get_gradient (GtkCssValue *value) +_gtk_css_value_get_gradient (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_GRADIENT), NULL); return value->u.ptr; } GtkShadow * -_gtk_css_value_get_shadow (GtkCssValue *value) +_gtk_css_value_get_shadow (const GtkCssValue *value) { g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_SHADOW), NULL); return value->u.ptr; diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h index 7fcb06661b..b87dc576ad 100644 --- a/gtk/gtkcssvalueprivate.h +++ b/gtk/gtkcssvalueprivate.h @@ -38,7 +38,6 @@ G_BEGIN_DECLS /* A GtkCssValue is a refcounted immutable value type */ typedef struct _GtkCssValue GtkCssValue; -typedef struct _GtkCssValueBase GtkCssValueBase; typedef struct _GtkCssValueClass GtkCssValueClass; /* using define instead of struct here so compilers get the packing right */ @@ -48,6 +47,9 @@ typedef struct _GtkCssValueClass GtkCssValueClass; struct _GtkCssValueClass { void (* free) (GtkCssValue *value); + + void (* print) (const GtkCssValue *value, + GString *string); }; GType _gtk_css_value_get_type (void) G_GNUC_CONST; @@ -59,8 +61,11 @@ GtkCssValue *_gtk_css_value_alloc (const GtkCssValueClass GtkCssValue *_gtk_css_value_ref (GtkCssValue *value); void _gtk_css_value_unref (GtkCssValue *value); -GType _gtk_css_value_get_content_type (GtkCssValue *value); -gboolean _gtk_css_value_holds (GtkCssValue *value, +void _gtk_css_value_print (const GtkCssValue *value, + GString *string); + +GType _gtk_css_value_get_content_type (const GtkCssValue *value); +gboolean _gtk_css_value_holds (const GtkCssValue *value, GType type); GtkCssValue *_gtk_css_value_new_from_gvalue (const GValue *g_value); GtkCssValue *_gtk_css_value_new_take_gvalue (GValue *g_value); @@ -78,34 +83,35 @@ GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage GtkCssValue *_gtk_css_value_new_from_number (const GtkCssNumber *v); GtkCssValue *_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v); GtkCssValue *_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v); -void _gtk_css_value_init_gvalue (GtkCssValue *value, +void _gtk_css_value_init_gvalue (const GtkCssValue *value, GValue *g_value); -gboolean _gtk_css_value_is_special (GtkCssValue *value); -GtkCssSpecialValue _gtk_css_value_get_special_kind (GtkCssValue *value); -int _gtk_css_value_get_int (GtkCssValue *value); -double _gtk_css_value_get_double (GtkCssValue *value); -const char * _gtk_css_value_get_string (GtkCssValue *value); -gpointer _gtk_css_value_dup_object (GtkCssValue *value); -gpointer _gtk_css_value_get_object (GtkCssValue *value); -gpointer _gtk_css_value_get_boxed (GtkCssValue *value); -const char ** _gtk_css_value_get_strv (GtkCssValue *value); -const GtkCssNumber *_gtk_css_value_get_number (GtkCssValue *value); -GtkSymbolicColor *_gtk_css_value_get_symbolic_color (GtkCssValue *value); -GtkCssImage *_gtk_css_value_get_image (GtkCssValue *value); -GtkBorderStyle _gtk_css_value_get_border_style (GtkCssValue *value); -const GtkCssBackgroundSize *_gtk_css_value_get_background_size (GtkCssValue *value); -const GtkCssBackgroundPosition *_gtk_css_value_get_background_position (GtkCssValue *value); -const GtkCssBorderCornerRadius *_gtk_css_value_get_border_corner_radius (GtkCssValue *value); -const GtkCssBorderImageRepeat *_gtk_css_value_get_border_image_repeat (GtkCssValue *value); -PangoFontDescription * _gtk_css_value_get_font_description (GtkCssValue *value); -PangoStyle _gtk_css_value_get_pango_style (GtkCssValue *value); -PangoVariant _gtk_css_value_get_pango_variant (GtkCssValue *value); -PangoWeight _gtk_css_value_get_pango_weight (GtkCssValue *value); -const GdkRGBA *_gtk_css_value_get_rgba (GtkCssValue *value); -cairo_pattern_t *_gtk_css_value_get_pattern (GtkCssValue *value); -GtkGradient *_gtk_css_value_get_gradient (GtkCssValue *value); -GtkShadow *_gtk_css_value_get_shadow (GtkCssValue *value); +gboolean _gtk_css_value_is_special (const GtkCssValue *value); +GtkCssSpecialValue _gtk_css_value_get_special_kind (const GtkCssValue *value); +int _gtk_css_value_get_int (const GtkCssValue *value); +int _gtk_css_value_get_enum (const GtkCssValue *value); +double _gtk_css_value_get_double (const GtkCssValue *value); +const char * _gtk_css_value_get_string (const GtkCssValue *value); +gpointer _gtk_css_value_dup_object (const GtkCssValue *value); +gpointer _gtk_css_value_get_object (const GtkCssValue *value); +gpointer _gtk_css_value_get_boxed (const GtkCssValue *value); +const char ** _gtk_css_value_get_strv (const GtkCssValue *value); +const GtkCssNumber *_gtk_css_value_get_number (const GtkCssValue *value); +GtkSymbolicColor *_gtk_css_value_get_symbolic_color (const GtkCssValue *value); +GtkCssImage *_gtk_css_value_get_image (const GtkCssValue *value); +GtkBorderStyle _gtk_css_value_get_border_style (const GtkCssValue *value); +const GtkCssBackgroundSize *_gtk_css_value_get_background_size (const GtkCssValue *value); +const GtkCssBackgroundPosition *_gtk_css_value_get_background_position (const GtkCssValue *value); +const GtkCssBorderCornerRadius *_gtk_css_value_get_border_corner_radius (const GtkCssValue *value); +const GtkCssBorderImageRepeat *_gtk_css_value_get_border_image_repeat (const GtkCssValue *value); +PangoFontDescription * _gtk_css_value_get_font_description (const GtkCssValue *value); +PangoStyle _gtk_css_value_get_pango_style (const GtkCssValue *value); +PangoVariant _gtk_css_value_get_pango_variant (const GtkCssValue *value); +PangoWeight _gtk_css_value_get_pango_weight (const GtkCssValue *value); +const GdkRGBA *_gtk_css_value_get_rgba (const GtkCssValue *value); +cairo_pattern_t *_gtk_css_value_get_pattern (const GtkCssValue *value); +GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value); +GtkShadow *_gtk_css_value_get_shadow (const GtkCssValue *value); G_END_DECLS |