[gtk+/wip/cssvalue: 42/142] styleproperty: Make _gtk_style_property_query() take a GValue
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 42/142] styleproperty: Make _gtk_style_property_query() take a GValue
- Date: Sat, 7 Apr 2012 19:49:54 +0000 (UTC)
commit bd9e690952c239c5265967204837aeec6e8065be
Author: Benjamin Otte <otte redhat com>
Date: Mon Mar 26 07:08:24 2012 +0200
styleproperty: Make _gtk_style_property_query() take a GValue
... and don't make it return a GtkCssValue. We want to use this for
compat with the old GValue APIs after all...
gtk/gtkcssshorthandproperty.c | 5 ++-
gtk/gtkcssshorthandpropertyimpl.c | 42 +++++++++++++++++-----------------
gtk/gtkcssshorthandpropertyprivate.h | 3 +-
gtk/gtkcssstyleproperty.c | 28 +++++++++++++---------
gtk/gtkstylecontext.c | 5 +---
gtk/gtkstyleproperties.c | 10 +++-----
gtk/gtkstyleproperty.c | 10 +++++---
gtk/gtkstylepropertyprivate.h | 6 +++-
8 files changed, 58 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c
index f961791..6905b45 100644
--- a/gtk/gtkcssshorthandproperty.c
+++ b/gtk/gtkcssshorthandproperty.c
@@ -72,14 +72,15 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
shorthand->assign (shorthand, props, state, value);
}
-static GtkCssValue *
+static void
_gtk_css_shorthand_property_query (GtkStyleProperty *property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
- return shorthand->query (shorthand, query_func, query_data);
+ return shorthand->query (shorthand, value, query_func, query_data);
}
static void
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 05a027c..19c7895 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -609,8 +609,9 @@ unpack_border (GtkCssShorthandProperty *shorthand,
g_value_unset (&v);
}
-static GtkCssValue *
+static void
pack_border (GtkCssShorthandProperty *shorthand,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
@@ -635,7 +636,8 @@ pack_border (GtkCssShorthandProperty *shorthand,
if (v)
border.left = _gtk_css_value_get_int (v);
- return _gtk_css_value_new_from_border (&border);
+ g_value_init (value, GTK_TYPE_BORDER);
+ g_value_set_boxed (value, &border);
}
static void
@@ -659,15 +661,16 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
g_value_unset (&v);
}
-static GtkCssValue *
+static void
pack_border_radius (GtkCssShorthandProperty *shorthand,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
const GtkCssBorderCornerRadius *top_left;
GtkCssStyleProperty *prop;
GtkCssValue *v;
- int value = 0;
+ int i = 0;
prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
@@ -675,10 +678,11 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
{
top_left = _gtk_css_value_get_border_corner_radius (v);
if (top_left)
- value = top_left->horizontal.value;
+ i = top_left->horizontal.value;
}
- return _gtk_css_value_new_from_int (value);
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, i);
}
static void
@@ -761,8 +765,9 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
}
}
-static GtkCssValue *
+static void
pack_font_description (GtkCssShorthandProperty *shorthand,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
@@ -796,7 +801,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
if (v)
pango_font_description_set_weight (description, _gtk_css_value_get_pango_weight (v));
- return _gtk_css_value_new_take_font_description (description);
+ g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
+ g_value_take_boxed (value, description);
}
static void
@@ -817,30 +823,24 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand,
}
}
-static GtkCssValue *
+static void
pack_first_element (GtkCssShorthandProperty *shorthand,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssStyleProperty *prop;
- GtkCssValue *v;
- guint i;
/* NB: This is a fallback for properties that originally were
* not used as shorthand. We just pick the first subproperty
* as a representative.
* Lesson learned: Don't query the shorthand, query the
* real properties instead. */
- for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
- {
- prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
- v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
- if (v)
- {
- return _gtk_css_value_ref (v);
- }
- }
- return NULL;
+ prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
+ _gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
+ value,
+ query_func,
+ query_data);
}
static void
diff --git a/gtk/gtkcssshorthandpropertyprivate.h b/gtk/gtkcssshorthandpropertyprivate.h
index 9a79a3d..4592949 100644
--- a/gtk/gtkcssshorthandpropertyprivate.h
+++ b/gtk/gtkcssshorthandpropertyprivate.h
@@ -46,7 +46,8 @@ typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssS
GtkStyleProperties *props,
GtkStateFlags state,
const GValue *value);
-typedef GtkCssValue * (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand,
+typedef void (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data);
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 40d73f0..ef5a8fe 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -132,8 +132,9 @@ _gtk_css_style_property_assign (GtkStyleProperty *property,
_gtk_css_value_unref (css_value);
}
-static GtkCssValue *
+static void
_gtk_css_style_property_query (GtkStyleProperty *property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
@@ -150,11 +151,11 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
cairo_surface_t *surface;
cairo_matrix_t matrix;
- if (image == NULL)
- return _gtk_css_value_new_from_pattern (NULL);
- else if (GTK_IS_CSS_IMAGE_GRADIENT (image))
- return _gtk_css_value_new_from_pattern (GTK_CSS_IMAGE_GRADIENT (image)->pattern);
- else
+ g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
+
+ if (GTK_IS_CSS_IMAGE_GRADIENT (image))
+ g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
+ else if (image != NULL)
{
double width, height;
@@ -165,19 +166,24 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
cairo_matrix_init_scale (&matrix, width, height);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_surface_destroy (surface);
- return _gtk_css_value_new_take_pattern (pattern);
+ g_value_take_boxed (value, pattern);
}
}
else if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_NUMBER))
{
- int v = round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100));
- return _gtk_css_value_new_from_int (v);
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
}
else
- return _gtk_css_value_ref (css_value);
+ {
+ _gtk_css_value_init_gvalue (css_value, value);
+ }
}
else
- return _gtk_css_value_ref (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)));
+ {
+ _gtk_css_value_init_gvalue (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)),
+ value);
+ }
}
static gboolean
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index c1b9387..f2bb8eb 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -1345,7 +1345,6 @@ gtk_style_context_get_property (GtkStyleContext *context,
GtkStyleContextPrivate *priv;
GtkStyleProperty *prop;
StyleData *data;
- GtkCssValue *v;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (property != NULL);
@@ -1367,9 +1366,7 @@ gtk_style_context_get_property (GtkStyleContext *context,
}
data = style_data_lookup (context, state);
- v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store);
- _gtk_css_value_init_gvalue (v, value);
- _gtk_css_value_unref (v);
+ _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
}
/**
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index d63b659..5446d99 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -638,7 +638,6 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
{
StyleQueryData query = { props, state };
GtkStyleProperty *node;
- GtkCssValue *v;
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
g_return_val_if_fail (property != NULL, FALSE);
@@ -656,11 +655,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
return FALSE;
}
- v = _gtk_style_property_query (node,
- style_query_func,
- &query);
- _gtk_css_value_init_gvalue (v, value);
- _gtk_css_value_unref (v);
+ _gtk_style_property_query (node,
+ value,
+ style_query_func,
+ &query);
return TRUE;
}
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index c70c76f..7418b93 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -205,19 +205,21 @@ _gtk_style_property_assign (GtkStyleProperty *property,
* turn gtk_style_context_get() and similar functions to get the
* value to return to code using old APIs.
**/
-GtkCssValue *
+void
_gtk_style_property_query (GtkStyleProperty *property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkStylePropertyClass *klass;
- g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
- g_return_val_if_fail (query_func != NULL, NULL);
+ g_return_if_fail (value != NULL);
+ g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
+ g_return_if_fail (query_func != NULL);
klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
- return klass->query (property, query_func, query_data);
+ return klass->query (property, value, query_func, query_data);
}
void
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index 898b97f..d169139 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -57,7 +57,8 @@ struct _GtkStylePropertyClass
GtkStyleProperties *props,
GtkStateFlags state,
const GValue *value);
- GtkCssValue * (* query) (GtkStyleProperty *property,
+ void (* query) (GtkStyleProperty *property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data);
gboolean (* parse_value) (GtkStyleProperty * property,
@@ -82,7 +83,8 @@ gboolean _gtk_style_property_parse_value (GtkStyleProperty *
GFile *base);
GType _gtk_style_property_get_value_type(GtkStyleProperty * property);
-GtkCssValue * _gtk_style_property_query (GtkStyleProperty * property,
+void _gtk_style_property_query (GtkStyleProperty * property,
+ GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data);
void _gtk_style_property_assign (GtkStyleProperty *property,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]