Commit d14fbf32 authored by Benjamin Otte's avatar Benjamin Otte

styleproperty: Allow passing in a parse func and a print func

It's not used yet, but it's now possible to specify a custom read or
write func.
parent 715674c4
...@@ -313,6 +313,8 @@ gtk_style_properties_register_property (GtkStylePropertyParser parse_func, ...@@ -313,6 +313,8 @@ gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
_gtk_style_property_register (pspec, _gtk_style_property_register (pspec,
parse_func, parse_func,
NULL, NULL,
NULL,
NULL,
NULL); NULL);
} }
......
...@@ -40,12 +40,6 @@ ...@@ -40,12 +40,6 @@
#include "gtkthemingengine.h" #include "gtkthemingengine.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
typedef gboolean (* GtkStyleParseFunc) (GtkCssParser *parser,
GFile *base,
GValue *value);
typedef void (* GtkStylePrintFunc) (const GValue *value,
GString *string);
static GHashTable *parse_funcs = NULL; static GHashTable *parse_funcs = NULL;
static GHashTable *print_funcs = NULL; static GHashTable *print_funcs = NULL;
static GHashTable *properties = NULL; static GHashTable *properties = NULL;
...@@ -1413,10 +1407,15 @@ _gtk_style_property_parse_value (const GtkStyleProperty *property, ...@@ -1413,10 +1407,15 @@ _gtk_style_property_parse_value (const GtkStyleProperty *property,
return success; return success;
} }
func = property->parse_func;
} }
else
func = NULL;
func = g_hash_table_lookup (parse_funcs, if (func == NULL)
GSIZE_TO_POINTER (G_VALUE_TYPE (value))); func = g_hash_table_lookup (parse_funcs,
GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
if (func == NULL) if (func == NULL)
func = g_hash_table_lookup (parse_funcs, func = g_hash_table_lookup (parse_funcs,
GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value)))); GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
...@@ -1441,8 +1440,14 @@ _gtk_style_property_print_value (const GtkStyleProperty *property, ...@@ -1441,8 +1440,14 @@ _gtk_style_property_print_value (const GtkStyleProperty *property,
css_string_funcs_init (); css_string_funcs_init ();
func = g_hash_table_lookup (print_funcs, if (property)
GSIZE_TO_POINTER (G_VALUE_TYPE (value))); func = property->print_func;
else
func = NULL;
if (func == NULL)
func = g_hash_table_lookup (print_funcs,
GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
if (func == NULL) if (func == NULL)
func = g_hash_table_lookup (print_funcs, func = g_hash_table_lookup (print_funcs,
GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value)))); GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
...@@ -1560,7 +1565,9 @@ gtk_style_property_init (void) ...@@ -1560,7 +1565,9 @@ gtk_style_property_init (void)
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
NULL, NULL,
unpack_margin, unpack_margin,
pack_margin); pack_margin,
NULL,
NULL);
gtk_style_properties_register_property (NULL, gtk_style_properties_register_property (NULL,
g_param_spec_int ("padding-top", g_param_spec_int ("padding-top",
"padding top", "padding top",
...@@ -1587,7 +1594,9 @@ gtk_style_property_init (void) ...@@ -1587,7 +1594,9 @@ gtk_style_property_init (void)
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
NULL, NULL,
unpack_padding, unpack_padding,
pack_padding); pack_padding,
NULL,
NULL);
gtk_style_properties_register_property (NULL, gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-top-width", g_param_spec_int ("border-top-width",
"border top width", "border top width",
...@@ -1614,7 +1623,9 @@ gtk_style_property_init (void) ...@@ -1614,7 +1623,9 @@ gtk_style_property_init (void)
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
NULL, NULL,
unpack_border_width, unpack_border_width,
pack_border_width); pack_border_width,
NULL,
NULL);
gtk_style_properties_register_property (NULL, gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-radius", g_param_spec_int ("border-radius",
"Border radius", "Border radius",
...@@ -1672,7 +1683,9 @@ void ...@@ -1672,7 +1683,9 @@ void
_gtk_style_property_register (GParamSpec *pspec, _gtk_style_property_register (GParamSpec *pspec,
GtkStylePropertyParser property_parse_func, GtkStylePropertyParser property_parse_func,
GtkStyleUnpackFunc unpack_func, GtkStyleUnpackFunc unpack_func,
GtkStylePackFunc pack_func) GtkStylePackFunc pack_func,
GtkStyleParseFunc parse_func,
GtkStylePrintFunc print_func)
{ {
const GtkStyleProperty *existing; const GtkStyleProperty *existing;
GtkStyleProperty *node; GtkStyleProperty *node;
...@@ -1694,6 +1707,8 @@ _gtk_style_property_register (GParamSpec *pspec, ...@@ -1694,6 +1707,8 @@ _gtk_style_property_register (GParamSpec *pspec,
node->property_parse_func = property_parse_func; node->property_parse_func = property_parse_func;
node->pack_func = pack_func; node->pack_func = pack_func;
node->unpack_func = unpack_func; node->unpack_func = unpack_func;
node->parse_func = parse_func;
node->print_func = print_func;
g_hash_table_insert (properties, pspec->name, node); g_hash_table_insert (properties, pspec->name, node);
} }
...@@ -31,6 +31,12 @@ typedef GParameter * (* GtkStyleUnpackFunc) (const GValue ...@@ -31,6 +31,12 @@ typedef GParameter * (* GtkStyleUnpackFunc) (const GValue
typedef void (* GtkStylePackFunc) (GValue *value, typedef void (* GtkStylePackFunc) (GValue *value,
GtkStyleProperties *props, GtkStyleProperties *props,
GtkStateFlags state); GtkStateFlags state);
typedef gboolean (* GtkStyleParseFunc) (GtkCssParser *parser,
GFile *base,
GValue *value);
typedef void (* GtkStylePrintFunc) (const GValue *value,
GString *string);
struct _GtkStyleProperty struct _GtkStyleProperty
{ {
...@@ -38,6 +44,8 @@ struct _GtkStyleProperty ...@@ -38,6 +44,8 @@ struct _GtkStyleProperty
GtkStylePropertyParser property_parse_func; GtkStylePropertyParser property_parse_func;
GtkStyleUnpackFunc unpack_func; GtkStyleUnpackFunc unpack_func;
GtkStylePackFunc pack_func; GtkStylePackFunc pack_func;
GtkStyleParseFunc parse_func;
GtkStylePrintFunc print_func;
}; };
const GtkStyleProperty * _gtk_style_property_lookup (const char *name); const GtkStyleProperty * _gtk_style_property_lookup (const char *name);
...@@ -45,7 +53,9 @@ const GtkStyleProperty * _gtk_style_property_lookup (const char ...@@ -45,7 +53,9 @@ const GtkStyleProperty * _gtk_style_property_lookup (const char
void _gtk_style_property_register (GParamSpec *pspec, void _gtk_style_property_register (GParamSpec *pspec,
GtkStylePropertyParser property_parse_func, GtkStylePropertyParser property_parse_func,
GtkStyleUnpackFunc unpack_func, GtkStyleUnpackFunc unpack_func,
GtkStylePackFunc pack_func); GtkStylePackFunc pack_func,
GtkStyleParseFunc parse_func,
GtkStylePrintFunc print_func);
gboolean _gtk_style_property_is_shorthand (const GtkStyleProperty *property); gboolean _gtk_style_property_is_shorthand (const GtkStyleProperty *property);
GParameter * _gtk_style_property_unpack (const GtkStyleProperty *property, GParameter * _gtk_style_property_unpack (const 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