Commit 5939baa5 authored by Benjamin Otte's avatar Benjamin Otte

styleproperty: Make query function take a vfunc

This way we can use different methods to query properties and aren't
bound to a GtkStyleProperties object.
parent 738f9625
......@@ -75,13 +75,13 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
static void
_gtk_css_shorthand_property_query (GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
GValue *value)
GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
shorthand->query (shorthand, value, props, state);
shorthand->query (shorthand, value, query_func, query_data);
}
static gboolean
......
......@@ -537,27 +537,27 @@ unpack_border (GtkCssShorthandProperty *shorthand,
static void
pack_border (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
GtkStateFlags state)
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssStyleProperty *prop;
GtkBorder border;
const GValue *v;
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
v = _gtk_style_properties_peek_property (props, prop, state);
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
if (v)
border.top = g_value_get_int (v);
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
v = _gtk_style_properties_peek_property (props, prop, state);
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
if (v)
border.right = g_value_get_int (v);
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
v = _gtk_style_properties_peek_property (props, prop, state);
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
if (v)
border.bottom = g_value_get_int (v);
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
v = _gtk_style_properties_peek_property (props, prop, state);
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
if (v)
border.left = g_value_get_int (v);
......@@ -587,24 +587,21 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
static void
pack_border_radius (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
GtkStateFlags state)
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssBorderCornerRadius *top_left;
GtkCssStyleProperty *prop;
const GValue *v;
/* NB: We are an int property, so we have to resolve to an int here.
* So we just resolve to an int. We pick one and stick to it.
* Lesson learned: Don't query border-radius shorthand, query the
* real properties instead. */
gtk_style_properties_get (props,
state,
"border-top-left-radius", &top_left,
NULL);
if (top_left)
g_value_set_int (value, top_left->horizontal);
g_free (top_left);
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);
if (v)
{
top_left = g_value_get_boxed (v);
if (top_left)
g_value_set_int (value, top_left->horizontal);
}
}
static void
......@@ -690,35 +687,38 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
static void
pack_font_description (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
GtkStateFlags state)
GtkStyleQueryFunc query_func,
gpointer query_data)
{
PangoFontDescription *description;
char **families;
PangoStyle style;
PangoVariant variant;
PangoWeight weight;
double size;
gtk_style_properties_get (props,
state,
"font-family", &families,
"font-style", &style,
"font-variant", &variant,
"font-weight", &weight,
"font-size", &size,
NULL);
const GValue *v;
description = pango_font_description_new ();
/* xxx: Can we set all the families here somehow? */
if (families)
pango_font_description_set_family (description, families[0]);
pango_font_description_set_size (description, round (size * PANGO_SCALE));
pango_font_description_set_style (description, style);
pango_font_description_set_variant (description, variant);
pango_font_description_set_weight (description, weight);
g_strfreev (families);
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
if (v)
{
const char **families = g_value_get_boxed (v);
/* xxx: Can we set all the families here somehow? */
if (families)
pango_font_description_set_family (description, families[0]);
}
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
if (v)
pango_font_description_set_size (description, round (g_value_get_double (v) * PANGO_SCALE));
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
if (v)
pango_font_description_set_style (description, g_value_get_enum (v));
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
if (v)
pango_font_description_set_variant (description, g_value_get_enum (v));
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
if (v)
pango_font_description_set_weight (description, g_value_get_enum (v));
g_value_take_boxed (value, description);
}
......@@ -744,8 +744,8 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand,
static void
pack_first_element (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
GtkStateFlags state)
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkCssStyleProperty *prop;
const GValue *v;
......@@ -759,7 +759,7 @@ pack_first_element (GtkCssShorthandProperty *shorthand,
for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
{
prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
v = _gtk_style_properties_peek_property (props, prop, state);
v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
if (v)
{
g_value_copy (v, value);
......
......@@ -49,8 +49,8 @@ typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssS
const GValue *value);
typedef void (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand,
GValue *value,
GtkStyleProperties *props,
GtkStateFlags state);
GtkStyleQueryFunc query_func,
gpointer query_data);
struct _GtkCssShorthandProperty
{
......
......@@ -117,13 +117,13 @@ _gtk_css_style_property_assign (GtkStyleProperty *property,
static void
_gtk_css_style_property_query (GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
GValue *value)
GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
const GValue *val;
val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state);
val = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
if (val)
{
/* Somebody make this a vfunc */
......
......@@ -605,6 +605,22 @@ _gtk_style_properties_peek_property (GtkStyleProperties *props,
return property_data_match_state (prop, state);
}
typedef struct {
GtkStyleProperties *props;
GtkStateFlags state;
} StyleQueryData;
static const GValue *
style_query_func (guint id,
gpointer data)
{
StyleQueryData *query = data;
return _gtk_style_properties_peek_property (query->props,
_gtk_css_style_property_lookup_by_id (id),
query->state);
}
/**
* gtk_style_properties_get_property:
* @props: a #GtkStyleProperties
......@@ -625,6 +641,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
GtkStateFlags state,
GValue *value)
{
StyleQueryData query = { props, state };
GtkStyleProperty *node;
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
......@@ -643,7 +660,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
return FALSE;
}
_gtk_style_property_query (node, props, state, value);
_gtk_style_property_query (node,
value,
style_query_func,
&query);
return TRUE;
}
......
......@@ -198,32 +198,32 @@ _gtk_style_property_assign (GtkStyleProperty *property,
/**
* _gtk_style_property_query:
* @property: the property
* @props: The properties to query
* @state: The state to query
* @value: (out): an uninitialized #GValue to be filled with the
* contents of the lookup
* @query_func: The function to use to query properties
* @query_data: The data to pass to @query_func
*
* This function is called by gtk_style_properties_get() and in
* turn gtk_style_context_get() and similar functions to get the
* value to return to code using old APIs.
**/
void
_gtk_style_property_query (GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
GValue *value)
_gtk_style_property_query (GtkStyleProperty *property,
GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
GtkStylePropertyClass *klass;
g_return_if_fail (property != NULL);
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
g_return_if_fail (value != NULL);
g_return_if_fail (query_func != NULL);
klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
g_value_init (value, property->value_type);
klass->query (property, props, state, value);
klass->query (property, value, query_func, query_data);
}
void
......
......@@ -39,6 +39,9 @@ typedef enum {
GTK_STYLE_PROPERTY_INHERIT = (1 << 0)
} GtkStylePropertyFlags;
typedef const GValue * (* GtkStyleQueryFunc) (guint id,
gpointer data);
struct _GtkStyleProperty
{
GObject parent;
......@@ -56,9 +59,9 @@ struct _GtkStylePropertyClass
GtkStateFlags state,
const GValue *value);
void (* query) (GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
GValue *value);
GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data);
gboolean (* parse_value) (GtkStyleProperty * property,
GValue *value,
GtkCssParser *parser,
......@@ -82,9 +85,9 @@ gboolean _gtk_style_property_parse_value (GtkStyleProperty *
GType _gtk_style_property_get_value_type(GtkStyleProperty * property);
void _gtk_style_property_query (GtkStyleProperty * property,
GtkStyleProperties *props,
GtkStateFlags state,
GValue *value);
GValue *value,
GtkStyleQueryFunc query_func,
gpointer query_data);
void _gtk_style_property_assign (GtkStyleProperty *property,
GtkStyleProperties *props,
GtkStateFlags state,
......
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