From 341a738dc6ac8e79472c27db1a5ad0cbf0450b41 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 31 Dec 2011 19:59:16 +0100 Subject: [PATCH] styleproperty: Move member variables These variables are only relevant for style properties, but not for shorthands, so put them there. --- gtk/gtkcssstyleproperty.c | 89 ++++++++++++++++++++++++++++---- gtk/gtkcssstylepropertyprivate.h | 2 + gtk/gtkstyleproperty.c | 57 ++++++++++---------- gtk/gtkstylepropertyprivate.h | 2 - 4 files changed, 110 insertions(+), 40 deletions(-) diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c index 8e2013781a..66ce7ff020 100644 --- a/gtk/gtkcssstyleproperty.c +++ b/gtk/gtkcssstyleproperty.c @@ -27,6 +27,8 @@ enum { PROP_0, PROP_ID, + PROP_INHERIT, + PROP_INITIAL }; G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY) @@ -43,6 +45,32 @@ gtk_css_style_property_constructed (GObject *object) G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object); } +static void +gtk_css_style_property_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object); + const GValue *initial; + + switch (prop_id) + { + case PROP_INHERIT: + property->inherit = g_value_get_boolean (value); + break; + case PROP_INITIAL: + initial = g_value_get_boxed (value); + g_assert (initial); + g_value_init (&property->initial_value, G_VALUE_TYPE (initial)); + g_value_copy (initial, &property->initial_value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void gtk_css_style_property_get_property (GObject *object, guint prop_id, @@ -56,6 +84,12 @@ gtk_css_style_property_get_property (GObject *object, case PROP_ID: g_value_set_boolean (value, property->id); break; + case PROP_INHERIT: + g_value_set_boolean (value, property->inherit); + break; + case PROP_INITIAL: + g_value_set_boxed (value, &property->initial_value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -68,6 +102,7 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructed = gtk_css_style_property_constructed; + object_class->set_property = gtk_css_style_property_set_property; object_class->get_property = gtk_css_style_property_get_property; g_object_class_install_property (object_class, @@ -77,6 +112,20 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass) P_("The numeric id for quick access"), 0, G_MAXUINT, 0, G_PARAM_READABLE)); + g_object_class_install_property (object_class, + PROP_INHERIT, + g_param_spec_boolean ("inherit", + P_("Inherit"), + P_("Set if the value is inherited by default"), + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_INITIAL, + g_param_spec_boxed ("initial-value", + P_("Initial value"), + P_("The initial specified value used for this property"), + G_TYPE_VALUE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); klass->style_properties = g_ptr_array_new (); } @@ -125,6 +174,24 @@ _gtk_css_style_property_lookup_by_id (guint id) return g_ptr_array_index (klass->style_properties, id); } +/** + * _gtk_css_style_property_is_inherit: + * @property: the property + * + * Queries if the given @property is inherited. See + * + * the CSS documentation for an explanation of this concept. + * + * Returns: a reference to the initial value. The value will never change. + **/ const GValue * _gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property) { - g_return_val_if_fail (property != NULL, NULL); + g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL); - return >K_STYLE_PROPERTY (property)->initial_value; + return &property->initial_value; } diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h index 0436f98ae2..32ab48dfdd 100644 --- a/gtk/gtkcssstylepropertyprivate.h +++ b/gtk/gtkcssstylepropertyprivate.h @@ -39,7 +39,9 @@ struct _GtkCssStyleProperty { GtkStyleProperty parent; + GValue initial_value; guint id; + guint inherit :1; }; struct _GtkCssStylePropertyClass diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c index 63badd9951..3543952fa9 100644 --- a/gtk/gtkstyleproperty.c +++ b/gtk/gtkstyleproperty.c @@ -1801,7 +1801,7 @@ _gtk_style_property_default_value (GtkStyleProperty *property, GtkStateFlags state, GValue *value) { - g_value_copy (&property->initial_value, value); + g_value_copy (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)), value); } static gboolean @@ -2495,41 +2495,42 @@ _gtk_style_property_register (GParamSpec *pspec, const GValue * initial_value) { GtkStyleProperty *node; + GValue initial_fallback = { 0, }; + + if (initial_value == NULL) + { + g_value_init (&initial_fallback, pspec->value_type); + if (pspec->value_type == GTK_TYPE_THEMING_ENGINE) + g_value_set_object (&initial_fallback, gtk_theming_engine_load (NULL)); + else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION) + g_value_take_boxed (&initial_fallback, pango_font_description_from_string ("Sans 10")); + else if (pspec->value_type == GDK_TYPE_RGBA) + { + GdkRGBA color; + gdk_rgba_parse (&color, "pink"); + g_value_set_boxed (&initial_fallback, &color); + } + else if (pspec->value_type == GTK_TYPE_BORDER) + { + g_value_take_boxed (&initial_fallback, gtk_border_new ()); + } + else + g_param_value_set_default (pspec, &initial_fallback); + + initial_value = &initial_fallback; + } node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY, + "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE, + "initial-value", initial_value, "name", pspec->name, "value-type", pspec->value_type, NULL); - node->flags = flags; node->pspec = pspec; node->property_parse_func = property_parse_func; node->parse_func = parse_func; node->print_func = print_func; - /* initialize the initial value */ - if (initial_value) - { - g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value)); - g_value_copy (initial_value, &node->initial_value); - } - else - { - g_value_init (&node->initial_value, pspec->value_type); - if (pspec->value_type == GTK_TYPE_THEMING_ENGINE) - g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL)); - else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION) - g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10")); - else if (pspec->value_type == GDK_TYPE_RGBA) - { - GdkRGBA color; - gdk_rgba_parse (&color, "pink"); - g_value_set_boxed (&node->initial_value, &color); - } - else if (pspec->value_type == GTK_TYPE_BORDER) - { - g_value_take_boxed (&node->initial_value, gtk_border_new ()); - } - else - g_param_value_set_default (pspec, &node->initial_value); - } + if (G_IS_VALUE (&initial_fallback)) + g_value_unset (&initial_fallback); } diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h index d498c4c6d8..c907451d7e 100644 --- a/gtk/gtkstylepropertyprivate.h +++ b/gtk/gtkstylepropertyprivate.h @@ -61,8 +61,6 @@ struct _GtkStyleProperty GType value_type; GParamSpec *pspec; - GtkStylePropertyFlags flags; - GValue initial_value; GtkStylePropertyParser property_parse_func; GtkStyleUnpackFunc unpack_func;