Commit 297fa7a3 authored by Carlos Garnacho's avatar Carlos Garnacho

GtkStyleProvider: Add GtkStateFlags parameter to get_style_property().

Widget style properties can now have different values depending on the
current state.
parent 2ca905db
......@@ -1340,6 +1340,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
static gboolean
gtk_css_provider_get_style_property (GtkStyleProvider *provider,
GtkWidgetPath *path,
GtkStateFlags state,
GParamSpec *pspec,
GValue *value)
{
......@@ -1362,7 +1363,9 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
info = &g_array_index (priority_info, StylePriorityInfo, i);
val = g_hash_table_lookup (info->style, prop_name);
if (val)
if (val &&
(info->state & state) != 0 &&
(info->state & ~(state)) == 0)
{
const gchar *val_str;
......
......@@ -427,6 +427,7 @@ struct PropertyValue
{
GType widget_type;
GParamSpec *pspec;
GtkStateFlags state;
GValue value;
};
......@@ -2221,15 +2222,22 @@ style_property_values_cmp (gconstpointer bsearch_node1,
const PropertyValue *val1 = bsearch_node1;
const PropertyValue *val2 = bsearch_node2;
if (val1->widget_type == val2->widget_type)
return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
else
if (val1->widget_type != val2->widget_type)
return val1->widget_type < val2->widget_type ? -1 : 1;
if (val1->pspec != val2->pspec)
return val1->pspec < val2->pspec ? -1 : 1;
if (val1->state != val2->state)
return val1->state < val2->state ? -1 : 1;
return 0;
}
const GValue *
_gtk_style_context_peek_style_property (GtkStyleContext *context,
GType widget_type,
GtkStateFlags state,
GParamSpec *pspec)
{
GtkStyleContextPrivate *priv;
......@@ -2242,6 +2250,7 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
data = style_data_lookup (context);
key.widget_type = widget_type;
key.state = state;
key.pspec = pspec;
/* need value cache array */
......@@ -2293,8 +2302,8 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
global = global->prev;
if (gtk_style_provider_get_style_property (provider_data->provider,
priv->widget_path, pspec,
&pcache->value))
priv->widget_path, state,
pspec, &pcache->value))
{
/* Resolve symbolic colors to GdkColor/GdkRGBA */
if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
......@@ -2358,6 +2367,7 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
{
GtkStyleContextPrivate *priv;
GtkWidgetClass *widget_class;
GtkStateFlags state;
GParamSpec *pspec;
const GValue *peek_value;
GType widget_type;
......@@ -2386,9 +2396,9 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
return;
}
peek_value = _gtk_style_context_peek_style_property (context,
widget_type,
pspec);
state = gtk_style_context_get_state (context);
peek_value = _gtk_style_context_peek_style_property (context, widget_type,
state, pspec);
if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
g_value_copy (peek_value, value);
......@@ -2417,6 +2427,7 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
{
GtkStyleContextPrivate *priv;
const gchar *prop_name;
GtkStateFlags state;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
......@@ -2426,6 +2437,8 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
if (!priv->widget_path)
return;
state = gtk_style_context_get_state (context);
while (prop_name)
{
GtkWidgetClass *widget_class;
......@@ -2449,9 +2462,8 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
continue;
}
peek_value = _gtk_style_context_peek_style_property (context,
widget_type,
pspec);
peek_value = _gtk_style_context_peek_style_property (context, widget_type,
state, pspec);
G_VALUE_LCOPY (peek_value, args, 0, &error);
......
......@@ -424,6 +424,7 @@ void gtk_style_context_pop_animatable_region (GtkStyleContext *context);
/* Semi-private API */
const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
GType widget_type,
GtkStateFlags state,
GParamSpec *pspec);
void _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context);
void _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
......
......@@ -86,6 +86,7 @@ gtk_style_provider_get_style (GtkStyleProvider *provider,
* gtk_style_provider_get_style_property:
* @provider: a #GtkStyleProvider
* @path: #GtkWidgetPath to query
* @state: state to query the style property for
* @pspec: The #GParamSpec to query
* @value: (out): return location for the property value
*
......@@ -97,6 +98,7 @@ gtk_style_provider_get_style (GtkStyleProvider *provider,
gboolean
gtk_style_provider_get_style_property (GtkStyleProvider *provider,
GtkWidgetPath *path,
GtkStateFlags state,
GParamSpec *pspec,
GValue *value)
{
......@@ -113,7 +115,7 @@ gtk_style_provider_get_style_property (GtkStyleProvider *provider,
if (!iface->get_style_property)
return FALSE;
return iface->get_style_property (provider, path, pspec, value);
return iface->get_style_property (provider, path, state, pspec, value);
}
/**
......
......@@ -97,6 +97,7 @@ struct _GtkStyleProviderIface
gboolean (* get_style_property) (GtkStyleProvider *provider,
GtkWidgetPath *path,
GtkStateFlags state,
GParamSpec *pspec,
GValue *value);
......@@ -111,6 +112,7 @@ GtkStyleProperties *gtk_style_provider_get_style (GtkStyleProvider *provider,
gboolean gtk_style_provider_get_style_property (GtkStyleProvider *provider,
GtkWidgetPath *path,
GtkStateFlags state,
GParamSpec *pspec,
GValue *value);
......
......@@ -11372,11 +11372,14 @@ gtk_widget_style_get_property (GtkWidget *widget,
{
GtkStyleContext *context;
const GValue *peek_value;
GtkStateFlags state;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
peek_value = _gtk_style_context_peek_style_property (context,
G_OBJECT_TYPE (widget),
pspec);
state, pspec);
/* auto-conversion of the caller's value type
*/
......@@ -11410,12 +11413,14 @@ gtk_widget_style_get_valist (GtkWidget *widget,
va_list var_args)
{
GtkStyleContext *context;
GtkStateFlags state;
const gchar *name;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_object_ref (widget);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
name = first_property_name;
while (name)
......@@ -11440,7 +11445,7 @@ gtk_widget_style_get_valist (GtkWidget *widget,
peek_value = _gtk_style_context_peek_style_property (context,
G_OBJECT_TYPE (widget),
pspec);
state, pspec);
G_VALUE_LCOPY (peek_value, var_args, 0, &error);
if (error)
......
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