[gtk+] shorthand: Get rid of GParameter dance
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] shorthand: Get rid of GParameter dance
- Date: Wed, 11 Jan 2012 14:53:27 +0000 (UTC)
commit 738f96252ea677e5327cdf09d2d0d09b312c2f02
Author: Benjamin Otte <otte redhat com>
Date: Wed Jan 11 01:11:58 2012 +0100
shorthand: Get rid of GParameter dance
Instead assign properties directly.
gtk/gtkcssshorthandproperty.c | 14 +---
gtk/gtkcssshorthandpropertyimpl.c | 156 +++++++++++++++-------------------
gtk/gtkcssshorthandpropertyprivate.h | 7 +-
3 files changed, 75 insertions(+), 102 deletions(-)
---
diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c
index dbe8216..2002ccc 100644
--- a/gtk/gtkcssshorthandproperty.c
+++ b/gtk/gtkcssshorthandproperty.c
@@ -69,20 +69,8 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
const GValue *value)
{
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
- GParameter *parameters;
- guint i, n_parameters;
- parameters = shorthand->assign (shorthand, value, &n_parameters);
-
- for (i = 0; i < n_parameters; i++)
- {
- _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
- props,
- state,
- ¶meters[i].value);
- g_value_unset (¶meters[i].value);
- }
- g_free (parameters);
+ shorthand->assign (shorthand, props, state, value);
}
static void
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index c13f0c2..9c088ce 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -511,29 +511,27 @@ parse_background (GtkCssShorthandProperty *shorthand,
/*** PACKING ***/
-static GParameter *
+static void
unpack_border (GtkCssShorthandProperty *shorthand,
- const GValue *value,
- guint *n_params)
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ const GValue *value)
{
- GParameter *parameter = g_new0 (GParameter, 4);
+ GValue v = G_VALUE_INIT;
GtkBorder *border = g_value_get_boxed (value);
- parameter[0].name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)));
- g_value_init (¶meter[0].value, G_TYPE_INT);
- g_value_set_int (¶meter[0].value, border->top);
- parameter[1].name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)));
- g_value_init (¶meter[1].value, G_TYPE_INT);
- g_value_set_int (¶meter[1].value, border->right);
- parameter[2].name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)));
- g_value_init (¶meter[2].value, G_TYPE_INT);
- g_value_set_int (¶meter[2].value, border->bottom);
- parameter[3].name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)));
- g_value_init (¶meter[3].value, G_TYPE_INT);
- g_value_set_int (¶meter[3].value, border->left);
-
- *n_params = 4;
- return parameter;
+ g_value_init (&v, G_TYPE_INT);
+
+ g_value_set_int (&v, border->top);
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)), props, state, &v);
+ g_value_set_int (&v, border->right);
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)), props, state, &v);
+ g_value_set_int (&v, border->bottom);
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)), props, state, &v);
+ g_value_set_int (&v, border->left);
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)), props, state, &v);
+
+ g_value_unset (&v);
}
static void
@@ -566,31 +564,24 @@ pack_border (GtkCssShorthandProperty *shorthand,
g_value_set_boxed (value, &border);
}
-static GParameter *
+static void
unpack_border_radius (GtkCssShorthandProperty *shorthand,
- const GValue *value,
- guint *n_params)
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ const GValue *value)
{
- GParameter *parameter = g_new0 (GParameter, 4);
GtkCssBorderCornerRadius border;
+ GValue v = G_VALUE_INIT;
+ guint i;
border.horizontal = border.vertical = g_value_get_int (value);
+ g_value_init (&v, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
+ g_value_set_boxed (&v, &border);
- parameter[0].name = "border-top-left-radius";
- g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- g_value_set_boxed (¶meter[0].value, &border);
- parameter[1].name = "border-top-right-radius";
- g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- g_value_set_boxed (¶meter[1].value, &border);
- parameter[2].name = "border-bottom-right-radius";
- g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- g_value_set_boxed (¶meter[2].value, &border);
- parameter[3].name = "border-bottom-left-radius";
- g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- g_value_set_boxed (¶meter[3].value, &border);
-
- *n_params = 4;
- return parameter;
+ for (i = 0; i < 4; i++)
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, i)), props, state, &v);
+
+ g_value_unset (&v);
}
static void
@@ -616,15 +607,16 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
g_free (top_left);
}
-static GParameter *
+static void
unpack_font_description (GtkCssShorthandProperty *shorthand,
- const GValue *value,
- guint *n_params)
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ const GValue *value)
{
- GParameter *parameter = g_new0 (GParameter, 5);
+ GtkStyleProperty *prop;
PangoFontDescription *description;
PangoFontMask mask;
- guint n;
+ GValue v = G_VALUE_INIT;
/* For backwards compat, we only unpack values that are indeed set.
* For strict CSS conformance we need to unpack all of them.
@@ -634,7 +626,6 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
*/
description = g_value_get_boxed (value);
- n = 0;
if (description)
mask = pango_font_description_get_set_fields (description);
@@ -647,52 +638,53 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
g_ptr_array_add (strv, NULL);
- parameter[n].name = "font-family";
- g_value_init (¶meter[n].value, G_TYPE_STRV);
- g_value_take_boxed (¶meter[n].value,
- g_ptr_array_free (strv, FALSE));
- n++;
+ g_value_init (&v, G_TYPE_STRV);
+ g_value_take_boxed (&v, g_ptr_array_free (strv, FALSE));
+
+ prop = _gtk_style_property_lookup ("font-family");
+ _gtk_style_property_assign (prop, props, state, &v);
+ g_value_unset (&v);
}
if (mask & PANGO_FONT_MASK_STYLE)
{
- parameter[n].name = "font-style";
- g_value_init (¶meter[n].value, PANGO_TYPE_STYLE);
- g_value_set_enum (¶meter[n].value,
- pango_font_description_get_style (description));
- n++;
+ g_value_init (&v, PANGO_TYPE_STYLE);
+ g_value_set_enum (&v, pango_font_description_get_style (description));
+
+ prop = _gtk_style_property_lookup ("font-style");
+ _gtk_style_property_assign (prop, props, state, &v);
+ g_value_unset (&v);
}
if (mask & PANGO_FONT_MASK_VARIANT)
{
- parameter[n].name = "font-variant";
- g_value_init (¶meter[n].value, PANGO_TYPE_VARIANT);
- g_value_set_enum (¶meter[n].value,
- pango_font_description_get_variant (description));
- n++;
+ g_value_init (&v, PANGO_TYPE_VARIANT);
+ g_value_set_enum (&v, pango_font_description_get_variant (description));
+
+ prop = _gtk_style_property_lookup ("font-variant");
+ _gtk_style_property_assign (prop, props, state, &v);
+ g_value_unset (&v);
}
if (mask & PANGO_FONT_MASK_WEIGHT)
{
- parameter[n].name = "font-weight";
- g_value_init (¶meter[n].value, PANGO_TYPE_WEIGHT);
- g_value_set_enum (¶meter[n].value,
- pango_font_description_get_weight (description));
- n++;
+ g_value_init (&v, PANGO_TYPE_WEIGHT);
+ g_value_set_enum (&v, pango_font_description_get_weight (description));
+
+ prop = _gtk_style_property_lookup ("font-weight");
+ _gtk_style_property_assign (prop, props, state, &v);
+ g_value_unset (&v);
}
if (mask & PANGO_FONT_MASK_SIZE)
{
- parameter[n].name = "font-size";
- g_value_init (¶meter[n].value, G_TYPE_DOUBLE);
- g_value_set_double (¶meter[n].value,
- (double) pango_font_description_get_size (description) / PANGO_SCALE);
- n++;
- }
+ g_value_init (&v, G_TYPE_DOUBLE);
+ g_value_set_double (&v, (double) pango_font_description_get_size (description) / PANGO_SCALE);
- *n_params = n;
-
- return parameter;
+ prop = _gtk_style_property_lookup ("font-size");
+ _gtk_style_property_assign (prop, props, state, &v);
+ g_value_unset (&v);
+ }
}
static void
@@ -731,30 +723,22 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
g_value_take_boxed (value, description);
}
-static GParameter *
+static void
unpack_to_everything (GtkCssShorthandProperty *shorthand,
- const GValue *value,
- guint *n_params)
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ const GValue *value)
{
GtkCssStyleProperty *prop;
- GParameter *parameter;
guint i, n;
- GType type;
n = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
- parameter = g_new0 (GParameter, n);
- type = G_VALUE_TYPE (value);
for (i = 0; i < n; i++)
{
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
- parameter[i].name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
- g_value_init (¶meter[i].value, type);
- g_value_copy (value, ¶meter[i].value);
+ _gtk_style_property_assign (GTK_STYLE_PROPERTY (prop), props, state, value);
}
-
- *n_params = n;
- return parameter;
}
static void
diff --git a/gtk/gtkcssshorthandpropertyprivate.h b/gtk/gtkcssshorthandpropertyprivate.h
index a4d5b2b..110fdc6 100644
--- a/gtk/gtkcssshorthandpropertyprivate.h
+++ b/gtk/gtkcssshorthandpropertyprivate.h
@@ -43,9 +43,10 @@ typedef gboolean (* GtkCssShorthandPropertyParseFunc) (GtkCssS
GValue *values,
GtkCssParser *parser,
GFile *base);
-typedef GParameter * (* GtkCssShorthandPropertyAssignFunc) (GtkCssShorthandProperty *shorthand,
- const GValue *value,
- guint *n_params);
+typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssShorthandProperty *shorthand,
+ GtkStyleProperties *props,
+ GtkStateFlags state,
+ const GValue *value);
typedef void (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]