[gtk+/wip/css: 54/153] styleproperty: Move member variables
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 54/153] styleproperty: Move member variables
- Date: Sat, 7 Jan 2012 02:01:07 +0000 (UTC)
commit be8eb0ff34b48c973bfd80486114b1fff4db99b4
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 31 19:59:16 2011 +0100
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 | 49 +++++++++++----------
gtk/gtkstylepropertyprivate.h | 2 -
4 files changed, 106 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 8e20137..66ce7ff 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)
@@ -44,6 +46,32 @@ gtk_css_style_property_constructed (GObject *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,
GValue *value,
@@ -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 ();
}
@@ -126,6 +175,24 @@ _gtk_css_style_property_lookup_by_id (guint 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 >K_STYLE_PROPERTY (property)->initial_value;
+ return &property->initial_value;
}
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 0436f98..32ab48d 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 63badd9..3543952 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, };
- node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
- "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
+ if (initial_value == NULL)
{
- g_value_init (&node->initial_value, pspec->value_type);
+ g_value_init (&initial_fallback, pspec->value_type);
if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
- g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
+ g_value_set_object (&initial_fallback, 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"));
+ 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 (&node->initial_value, &color);
+ g_value_set_boxed (&initial_fallback, &color);
}
else if (pspec->value_type == GTK_TYPE_BORDER)
{
- g_value_take_boxed (&node->initial_value, gtk_border_new ());
+ g_value_take_boxed (&initial_fallback, gtk_border_new ());
}
else
- g_param_value_set_default (pspec, &node->initial_value);
+ 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->pspec = pspec;
+ node->property_parse_func = property_parse_func;
+ node->parse_func = parse_func;
+ node->print_func = print_func;
+
+ if (G_IS_VALUE (&initial_fallback))
+ g_value_unset (&initial_fallback);
}
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index d498c4c..c907451 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]