Commit 5ac9ba71 authored by Benjamin Otte's avatar Benjamin Otte

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...
parent 58e4fdf9
...@@ -72,14 +72,15 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property, ...@@ -72,14 +72,15 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
shorthand->assign (shorthand, props, state, value); shorthand->assign (shorthand, props, state, value);
} }
static GtkCssValue * static void
_gtk_css_shorthand_property_query (GtkStyleProperty *property, _gtk_css_shorthand_property_query (GtkStyleProperty *property,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property); 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 static void
......
...@@ -609,8 +609,9 @@ unpack_border (GtkCssShorthandProperty *shorthand, ...@@ -609,8 +609,9 @@ unpack_border (GtkCssShorthandProperty *shorthand,
g_value_unset (&v); g_value_unset (&v);
} }
static GtkCssValue * static void
pack_border (GtkCssShorthandProperty *shorthand, pack_border (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
...@@ -635,7 +636,8 @@ pack_border (GtkCssShorthandProperty *shorthand, ...@@ -635,7 +636,8 @@ pack_border (GtkCssShorthandProperty *shorthand,
if (v) if (v)
border.left = _gtk_css_value_get_int (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 static void
...@@ -659,15 +661,16 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand, ...@@ -659,15 +661,16 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
g_value_unset (&v); g_value_unset (&v);
} }
static GtkCssValue * static void
pack_border_radius (GtkCssShorthandProperty *shorthand, pack_border_radius (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
const GtkCssBorderCornerRadius *top_left; const GtkCssBorderCornerRadius *top_left;
GtkCssStyleProperty *prop; GtkCssStyleProperty *prop;
GtkCssValue *v; GtkCssValue *v;
int value = 0; int i = 0;
prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius")); 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); v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
...@@ -675,10 +678,11 @@ pack_border_radius (GtkCssShorthandProperty *shorthand, ...@@ -675,10 +678,11 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
{ {
top_left = _gtk_css_value_get_border_corner_radius (v); top_left = _gtk_css_value_get_border_corner_radius (v);
if (top_left) 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 static void
...@@ -761,8 +765,9 @@ unpack_font_description (GtkCssShorthandProperty *shorthand, ...@@ -761,8 +765,9 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
} }
} }
static GtkCssValue * static void
pack_font_description (GtkCssShorthandProperty *shorthand, pack_font_description (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
...@@ -796,7 +801,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand, ...@@ -796,7 +801,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
if (v) if (v)
pango_font_description_set_weight (description, _gtk_css_value_get_pango_weight (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 static void
...@@ -817,30 +823,24 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand, ...@@ -817,30 +823,24 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand,
} }
} }
static GtkCssValue * static void
pack_first_element (GtkCssShorthandProperty *shorthand, pack_first_element (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
GtkCssStyleProperty *prop; GtkCssStyleProperty *prop;
GtkCssValue *v;
guint i;
/* NB: This is a fallback for properties that originally were /* NB: This is a fallback for properties that originally were
* not used as shorthand. We just pick the first subproperty * not used as shorthand. We just pick the first subproperty
* as a representative. * as a representative.
* Lesson learned: Don't query the shorthand, query the * Lesson learned: Don't query the shorthand, query the
* real properties instead. */ * 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);
{ _gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0); value,
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); query_func,
if (v) query_data);
{
return _gtk_css_value_ref (v);
}
}
return NULL;
} }
static void static void
......
...@@ -46,7 +46,8 @@ typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssS ...@@ -46,7 +46,8 @@ typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssS
GtkStyleProperties *props, GtkStyleProperties *props,
GtkStateFlags state, GtkStateFlags state,
const GValue *value); const GValue *value);
typedef GtkCssValue * (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand, typedef void (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data); gpointer query_data);
......
...@@ -132,8 +132,9 @@ _gtk_css_style_property_assign (GtkStyleProperty *property, ...@@ -132,8 +132,9 @@ _gtk_css_style_property_assign (GtkStyleProperty *property,
_gtk_css_value_unref (css_value); _gtk_css_value_unref (css_value);
} }
static GtkCssValue * static void
_gtk_css_style_property_query (GtkStyleProperty *property, _gtk_css_style_property_query (GtkStyleProperty *property,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
...@@ -150,11 +151,11 @@ _gtk_css_style_property_query (GtkStyleProperty *property, ...@@ -150,11 +151,11 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_matrix_t matrix; cairo_matrix_t matrix;
if (image == NULL) g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
return _gtk_css_value_new_from_pattern (NULL);
else if (GTK_IS_CSS_IMAGE_GRADIENT (image)) if (GTK_IS_CSS_IMAGE_GRADIENT (image))
return _gtk_css_value_new_from_pattern (GTK_CSS_IMAGE_GRADIENT (image)->pattern); g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
else else if (image != NULL)
{ {
double width, height; double width, height;
...@@ -165,19 +166,24 @@ _gtk_css_style_property_query (GtkStyleProperty *property, ...@@ -165,19 +166,24 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
cairo_matrix_init_scale (&matrix, width, height); cairo_matrix_init_scale (&matrix, width, height);
cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_matrix (pattern, &matrix);
cairo_surface_destroy (surface); 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)) 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)); g_value_init (value, G_TYPE_INT);
return _gtk_css_value_new_from_int (v); g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
} }
else else
return _gtk_css_value_ref (css_value); {
_gtk_css_value_init_gvalue (css_value, value);
}
} }
else 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 static gboolean
......
...@@ -1345,7 +1345,6 @@ gtk_style_context_get_property (GtkStyleContext *context, ...@@ -1345,7 +1345,6 @@ gtk_style_context_get_property (GtkStyleContext *context,
GtkStyleContextPrivate *priv; GtkStyleContextPrivate *priv;
GtkStyleProperty *prop; GtkStyleProperty *prop;
StyleData *data; StyleData *data;
GtkCssValue *v;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (property != NULL); g_return_if_fail (property != NULL);
...@@ -1367,9 +1366,7 @@ gtk_style_context_get_property (GtkStyleContext *context, ...@@ -1367,9 +1366,7 @@ gtk_style_context_get_property (GtkStyleContext *context,
} }
data = style_data_lookup (context, state); data = style_data_lookup (context, state);
v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store); _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
_gtk_css_value_init_gvalue (v, value);
_gtk_css_value_unref (v);
} }
/** /**
......
...@@ -638,7 +638,6 @@ gtk_style_properties_get_property (GtkStyleProperties *props, ...@@ -638,7 +638,6 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
{ {
StyleQueryData query = { props, state }; StyleQueryData query = { props, state };
GtkStyleProperty *node; GtkStyleProperty *node;
GtkCssValue *v;
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE); g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
g_return_val_if_fail (property != NULL, FALSE); g_return_val_if_fail (property != NULL, FALSE);
...@@ -656,11 +655,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props, ...@@ -656,11 +655,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
return FALSE; return FALSE;
} }
v = _gtk_style_property_query (node, _gtk_style_property_query (node,
style_query_func, value,
&query); style_query_func,
_gtk_css_value_init_gvalue (v, value); &query);
_gtk_css_value_unref (v);
return TRUE; return TRUE;
} }
......
...@@ -205,19 +205,21 @@ _gtk_style_property_assign (GtkStyleProperty *property, ...@@ -205,19 +205,21 @@ _gtk_style_property_assign (GtkStyleProperty *property,
* turn gtk_style_context_get() and similar functions to get the * turn gtk_style_context_get() and similar functions to get the
* value to return to code using old APIs. * value to return to code using old APIs.
**/ **/
GtkCssValue * void
_gtk_style_property_query (GtkStyleProperty *property, _gtk_style_property_query (GtkStyleProperty *property,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data) gpointer query_data)
{ {
GtkStylePropertyClass *klass; GtkStylePropertyClass *klass;
g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL); g_return_if_fail (value != NULL);
g_return_val_if_fail (query_func != NULL, NULL); g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
g_return_if_fail (query_func != NULL);
klass = GTK_STYLE_PROPERTY_GET_CLASS (property); 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 void
......
...@@ -57,7 +57,8 @@ struct _GtkStylePropertyClass ...@@ -57,7 +57,8 @@ struct _GtkStylePropertyClass
GtkStyleProperties *props, GtkStyleProperties *props,
GtkStateFlags state, GtkStateFlags state,
const GValue *value); const GValue *value);
GtkCssValue * (* query) (GtkStyleProperty *property, void (* query) (GtkStyleProperty *property,
GValue *value,
GtkStyleQueryFunc query_func, GtkStyleQueryFunc query_func,
gpointer query_data); gpointer query_data);
gboolean (* parse_value) (GtkStyleProperty * property, gboolean (* parse_value) (GtkStyleProperty * property,
...@@ -82,7 +83,8 @@ gboolean _gtk_style_property_parse_value (GtkStyleProperty * ...@@ -82,7 +83,8 @@ gboolean _gtk_style_property_parse_value (GtkStyleProperty *
GFile *base); GFile *base);
GType _gtk_style_property_get_value_type(GtkStyleProperty * property); 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, GtkStyleQueryFunc query_func,
gpointer query_data); gpointer query_data);
void _gtk_style_property_assign (GtkStyleProperty *property, void _gtk_style_property_assign (GtkStyleProperty *property,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment