forked from AuroraMiddleware/gtk
Add GtkStylePropertyContext and use it in when getting style properties
At the toplevel we have _gtk_theming_engine_get, which lets us pass in a property context with (atm) the size to get the property for. Then there is a lot of plumbing to push this down into the lower layers of the style property code until finally hitting the property resolvers. I need this because I will be adding a property resolver for win32 theme parts, and they render differently depending on the size (i.e. they don't scale linearly). The idea is that the code to get the background properties will pass in the final size and we will resolve the theme part specification to that particular size. If the old non-context calls are used we just hardcode a size of 100x100.
This commit is contained in:
parent
e953465e33
commit
c09148ca09
@ -27,6 +27,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "gtkborderimageprivate.h"
|
||||
#include "gtkstylepropertiesprivate.h"
|
||||
|
||||
/* this is in case round() is not provided by the compiler,
|
||||
* such as in the case of C89 compilers, like MSVC
|
||||
@ -194,14 +195,15 @@ _gtk_border_image_unpack (const GValue *value,
|
||||
void
|
||||
_gtk_border_image_pack (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
GtkBorderImage *image;
|
||||
cairo_pattern_t *source;
|
||||
GtkBorder *slice, *width;
|
||||
GtkCssBorderImageRepeat *repeat;
|
||||
|
||||
gtk_style_properties_get (props, state,
|
||||
_gtk_style_properties_get (props, state, context,
|
||||
"border-image-source", &source,
|
||||
"border-image-slice", &slice,
|
||||
"border-image-repeat", &repeat,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "gtkstyleproperties.h"
|
||||
#include "gtkthemingengine.h"
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -63,7 +64,8 @@ GParameter * _gtk_border_image_unpack (const GValue *valu
|
||||
guint *n_params);
|
||||
void _gtk_border_image_pack (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state);
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -1367,6 +1367,24 @@ gtk_style_context_get_property (GtkStyleContext *context,
|
||||
gtk_style_properties_get_property (data->store, property, state, value);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_style_context_get_valist (GtkStyleContext *context,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *property_context,
|
||||
va_list args)
|
||||
{
|
||||
GtkStyleContextPrivate *priv;
|
||||
StyleData *data;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
|
||||
priv = context->priv;
|
||||
g_return_if_fail (priv->widget_path != NULL);
|
||||
|
||||
data = style_data_lookup (context);
|
||||
_gtk_style_properties_get_valist (data->store, state, property_context, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_get_valist:
|
||||
* @context: a #GtkStyleContext
|
||||
|
@ -24,7 +24,17 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GtkStylePropertyContext GtkStylePropertyContext;
|
||||
struct _GtkStylePropertyContext
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
void _gtk_style_context_get_valist (GtkStyleContext *context,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *property_context,
|
||||
va_list args);
|
||||
const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
|
||||
GType widget_type,
|
||||
GtkStateFlags state,
|
||||
|
@ -640,6 +640,7 @@ const GValue *
|
||||
_gtk_style_properties_peek_property (GtkStyleProperties *props,
|
||||
const gchar *prop_name,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
const GtkStyleProperty **property)
|
||||
{
|
||||
GtkStylePropertiesPrivate *priv;
|
||||
@ -670,11 +671,42 @@ _gtk_style_properties_peek_property (GtkStyleProperties *props,
|
||||
if (val == NULL)
|
||||
return NULL;
|
||||
|
||||
_gtk_style_property_resolve (node, props, state, val);
|
||||
_gtk_style_property_resolve (node, props, state, context, val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gtk_style_properties_get_property (GtkStyleProperties *props,
|
||||
const gchar *property,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *value)
|
||||
{
|
||||
const GtkStyleProperty *node;
|
||||
const GValue *val;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
|
||||
g_return_val_if_fail (property != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
val = _gtk_style_properties_peek_property (props, property, state, context, &node);
|
||||
|
||||
if (!node)
|
||||
return FALSE;
|
||||
|
||||
g_value_init (value, node->pspec->value_type);
|
||||
|
||||
if (val)
|
||||
g_value_copy (val, value);
|
||||
else if (_gtk_style_property_is_shorthand (node))
|
||||
_gtk_style_property_pack (node, props, state, context, value);
|
||||
else
|
||||
_gtk_style_property_default_value (node, props, state, value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_properties_get_property:
|
||||
* @props: a #GtkStyleProperties
|
||||
@ -695,43 +727,21 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GValue *value)
|
||||
{
|
||||
const GtkStyleProperty *node;
|
||||
const GValue *val;
|
||||
GtkStylePropertyContext context = { 100, 100};
|
||||
|
||||
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
|
||||
g_return_val_if_fail (property != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
val = _gtk_style_properties_peek_property (props, property, state, &node);
|
||||
|
||||
if (!node)
|
||||
return FALSE;
|
||||
|
||||
g_value_init (value, node->pspec->value_type);
|
||||
|
||||
if (val)
|
||||
g_value_copy (val, value);
|
||||
else if (_gtk_style_property_is_shorthand (node))
|
||||
_gtk_style_property_pack (node, props, state, value);
|
||||
else
|
||||
_gtk_style_property_default_value (node, props, state, value);
|
||||
|
||||
return TRUE;
|
||||
return _gtk_style_properties_get_property (props,
|
||||
property,
|
||||
state, &context, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_properties_get_valist:
|
||||
* @props: a #GtkStyleProperties
|
||||
* @state: state to retrieve the property values for
|
||||
* @args: va_list of property name/return location pairs, followed by %NULL
|
||||
*
|
||||
* Retrieves several style property values from @props for a given state.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
void
|
||||
gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
_gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
va_list args)
|
||||
{
|
||||
const gchar *property_name;
|
||||
@ -746,7 +756,7 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
gchar *error = NULL;
|
||||
const GValue *val;
|
||||
|
||||
val = _gtk_style_properties_peek_property (props, property_name, state, &node);
|
||||
val = _gtk_style_properties_peek_property (props, property_name, state, context, &node);
|
||||
if (!node)
|
||||
break;
|
||||
|
||||
@ -759,7 +769,7 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
GValue packed = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&packed, node->pspec->value_type);
|
||||
_gtk_style_property_pack (node, props, state, &packed);
|
||||
_gtk_style_property_pack (node, props, state, context, &packed);
|
||||
G_VALUE_LCOPY (&packed, args, 0, &error);
|
||||
g_value_unset (&packed);
|
||||
}
|
||||
@ -784,6 +794,41 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_properties_get_valist:
|
||||
* @props: a #GtkStyleProperties
|
||||
* @state: state to retrieve the property values for
|
||||
* @args: va_list of property name/return location pairs, followed by %NULL
|
||||
*
|
||||
* Retrieves several style property values from @props for a given state.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
void
|
||||
gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
va_list args)
|
||||
{
|
||||
GtkStylePropertyContext context = { 100, 100};
|
||||
|
||||
return _gtk_style_properties_get_valist (props, state, &context, args);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_style_properties_get (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
||||
|
||||
va_start (args, context);
|
||||
_gtk_style_properties_get_valist (props, state, context, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_properties_get:
|
||||
* @props: a #GtkStyleProperties
|
||||
|
@ -22,13 +22,30 @@
|
||||
|
||||
#include "gtkstyleproperties.h"
|
||||
#include "gtkstylepropertyprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
const GValue * _gtk_style_properties_peek_property (GtkStyleProperties *props,
|
||||
const gchar *prop_name,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
const GtkStyleProperty **property);
|
||||
void _gtk_style_properties_get (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
...);
|
||||
void _gtk_style_properties_get_valist (GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
va_list args);
|
||||
|
||||
const GValue * _gtk_style_properties_resolve_property (GtkStyleProperties *props,
|
||||
const gchar *prop_name,
|
||||
GtkStateFlags state,
|
||||
const GtkStyleProperty **property,
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *value);
|
||||
|
||||
void _gtk_style_properties_set_property_by_property (GtkStyleProperties *props,
|
||||
const GtkStyleProperty *property,
|
||||
|
@ -1855,7 +1855,8 @@ unpack_border_width (const GValue *value,
|
||||
static void
|
||||
pack_border_width (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
pack_border (value, props, state,
|
||||
"border-top-width", "border-left-width",
|
||||
@ -1874,7 +1875,8 @@ unpack_padding (const GValue *value,
|
||||
static void
|
||||
pack_padding (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
pack_border (value, props, state,
|
||||
"padding-top", "padding-left",
|
||||
@ -1893,7 +1895,8 @@ unpack_margin (const GValue *value,
|
||||
static void
|
||||
pack_margin (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
pack_border (value, props, state,
|
||||
"margin-top", "margin-left",
|
||||
@ -1935,7 +1938,8 @@ unpack_border_radius (const GValue *value,
|
||||
static void
|
||||
pack_border_radius (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
GtkCssBorderCornerRadius *top_left;
|
||||
|
||||
@ -2035,7 +2039,8 @@ unpack_font_description (const GValue *value,
|
||||
static void
|
||||
pack_font_description (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
PangoFontDescription *description;
|
||||
char **families;
|
||||
@ -2113,7 +2118,8 @@ unpack_border_color (const GValue *value,
|
||||
static void
|
||||
pack_border_color (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state)
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context)
|
||||
{
|
||||
/* NB: We are a color property, so we have to resolve to a color here.
|
||||
* So we just resolve to a color. We pick one and stick to it.
|
||||
@ -2512,6 +2518,7 @@ void
|
||||
_gtk_style_property_resolve (const GtkStyleProperty *property,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *val)
|
||||
{
|
||||
if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
|
||||
@ -2579,6 +2586,7 @@ void
|
||||
_gtk_style_property_pack (const GtkStyleProperty *property,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *value)
|
||||
{
|
||||
g_return_if_fail (property != NULL);
|
||||
@ -2586,7 +2594,7 @@ _gtk_style_property_pack (const GtkStyleProperty *property,
|
||||
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
||||
g_return_if_fail (G_IS_VALUE (value));
|
||||
|
||||
property->pack_func (value, props, state);
|
||||
property->pack_func (value, props, state, context);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define __GTK_STYLEPROPERTY_PRIVATE_H__
|
||||
|
||||
#include "gtkcssparserprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -33,7 +34,8 @@ typedef GParameter * (* GtkStyleUnpackFunc) (const GValue
|
||||
guint *n_params);
|
||||
typedef void (* GtkStylePackFunc) (GValue *value,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state);
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context);
|
||||
typedef gboolean (* GtkStyleParseFunc) (GtkCssParser *parser,
|
||||
GFile *base,
|
||||
GValue *value);
|
||||
@ -82,7 +84,8 @@ void _gtk_style_property_default_value (const GtkStyleProper
|
||||
void _gtk_style_property_resolve (const GtkStyleProperty *property,
|
||||
GtkStyleProperties *properties,
|
||||
GtkStateFlags state,
|
||||
GValue *value);
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *orig_value);
|
||||
|
||||
gboolean _gtk_style_property_is_shorthand (const GtkStyleProperty *property);
|
||||
GParameter * _gtk_style_property_unpack (const GtkStyleProperty *property,
|
||||
@ -91,6 +94,7 @@ GParameter * _gtk_style_property_unpack (const GtkStyleProper
|
||||
void _gtk_style_property_pack (const GtkStyleProperty *property,
|
||||
GtkStyleProperties *props,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *context,
|
||||
GValue *value);
|
||||
|
||||
gboolean _gtk_style_property_parse_value (const GtkStyleProperty *property,
|
||||
|
@ -450,6 +450,25 @@ gtk_theming_engine_get_valist (GtkThemingEngine *engine,
|
||||
gtk_style_context_get_valist (priv->context, state, args);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_theming_engine_get (GtkThemingEngine *engine,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *property_context,
|
||||
...)
|
||||
{
|
||||
GtkThemingEnginePrivate *priv;
|
||||
va_list args;
|
||||
|
||||
g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
|
||||
|
||||
priv = engine->priv;
|
||||
|
||||
va_start (args, property_context);
|
||||
_gtk_style_context_get_valist (priv->context, state, property_context, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gtk_theming_engine_get:
|
||||
* @engine: a #GtkThemingEngine
|
||||
|
@ -21,6 +21,13 @@
|
||||
#define __GTK_THEMING_ENGINE_PRIVATE_H__
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include "gtkstylecontextprivate.h"
|
||||
|
||||
void _gtk_theming_engine_get (GtkThemingEngine *engine,
|
||||
GtkStateFlags state,
|
||||
GtkStylePropertyContext *property_context,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
|
||||
void _gtk_theming_engine_paint_spinner (cairo_t *cr,
|
||||
gdouble radius,
|
||||
|
Loading…
Reference in New Issue
Block a user