styleproperty: Move member variables

These variables are only relevant for style properties, but not for
shorthands, so put them there.
This commit is contained in:
Benjamin Otte 2011-12-31 19:59:16 +01:00
parent d9c5d37e56
commit 341a738dc6
4 changed files with 110 additions and 40 deletions

View File

@ -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
* <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance>
* the CSS documentation</ulink> for an explanation of this concept.
*
* Returns: %TRUE if the property is inherited by default.
**/
gboolean
_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
{
g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
return property->inherit;
}
/**
* _gtk_css_style_property_get_id:
* @property: the property
@ -142,19 +209,21 @@ _gtk_css_style_property_get_id (GtkCssStyleProperty *property)
return property->id;
}
gboolean
_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
{
g_return_val_if_fail (property != NULL, FALSE);
return GTK_STYLE_PROPERTY (property)->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
}
/**
* _gtk_css_style_property_get_initial_value:
* @property: the property
*
* Queries the initial value of the given @property. See
* <ulink url="http://www.w3.org/TR/css3-cascade/#intial>
* the CSS documentation</ulink> 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 &GTK_STYLE_PROPERTY (property)->initial_value;
return &property->initial_value;
}

View File

@ -39,7 +39,9 @@ struct _GtkCssStyleProperty
{
GtkStyleProperty parent;
GValue initial_value;
guint id;
guint inherit :1;
};
struct _GtkCssStylePropertyClass

View File

@ -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);
}

View File

@ -61,8 +61,6 @@ struct _GtkStyleProperty
GType value_type;
GParamSpec *pspec;
GtkStylePropertyFlags flags;
GValue initial_value;
GtkStylePropertyParser property_parse_func;
GtkStyleUnpackFunc unpack_func;