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...
This commit is contained in:
Benjamin Otte 2012-03-26 07:08:24 +02:00
parent 58e4fdf911
commit 5ac9ba714a
8 changed files with 58 additions and 51 deletions

View File

@ -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

View File

@ -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;
_gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
value,
query_func,
query_data);
}
static void

View File

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

View File

@ -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

View File

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

View File

@ -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,
_gtk_style_property_query (node,
value,
style_query_func,
&query);
_gtk_css_value_init_gvalue (v, value);
_gtk_css_value_unref (v);
return TRUE;
}

View File

@ -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

View File

@ -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,