forked from AuroraMiddleware/gtk
GtkStyleSet: Allow custom parsers on registered properties.
This commit is contained in:
parent
99224c9eec
commit
355f0d69ab
@ -1398,7 +1398,9 @@ parse_rule (GtkCssProvider *css_provider,
|
||||
while (scanner->token == G_TOKEN_IDENTIFIER)
|
||||
{
|
||||
const gchar *value_str = NULL;
|
||||
GtkStylePropertyParser parse_func = NULL;
|
||||
GType prop_type;
|
||||
GError *error = NULL;
|
||||
gchar *prop;
|
||||
|
||||
prop = g_strdup (scanner->value.v_identifier);
|
||||
@ -1432,7 +1434,7 @@ parse_rule (GtkCssProvider *css_provider,
|
||||
|
||||
g_hash_table_insert (priv->cur_properties, prop, val);
|
||||
}
|
||||
else if (gtk_style_set_lookup_property (prop, &prop_type))
|
||||
else if (gtk_style_set_lookup_property (prop, &prop_type, &parse_func))
|
||||
{
|
||||
GValue *val;
|
||||
|
||||
@ -1444,10 +1446,17 @@ parse_rule (GtkCssProvider *css_provider,
|
||||
g_value_set_string (val, value_str);
|
||||
g_hash_table_insert (priv->cur_properties, prop, val);
|
||||
}
|
||||
else if (css_provider_parse_value (value_str, val))
|
||||
else if ((parse_func && (parse_func) (value_str, val, &error)) ||
|
||||
(!parse_func && css_provider_parse_value (value_str, val)))
|
||||
g_hash_table_insert (priv->cur_properties, prop, val);
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Error parsing property value: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_value_unset (val);
|
||||
g_slice_free (GValue, val);
|
||||
g_free (prop);
|
||||
|
@ -39,6 +39,7 @@ struct PropertyNode
|
||||
GQuark property_quark;
|
||||
GType property_type;
|
||||
GValue default_value;
|
||||
GtkStylePropertyParser parse_func;
|
||||
};
|
||||
|
||||
struct PropertyData
|
||||
@ -72,19 +73,19 @@ gtk_style_set_class_init (GtkStyleSetClass *klass)
|
||||
object_class->finalize = gtk_style_set_finalize;
|
||||
|
||||
/* Initialize default property set */
|
||||
gtk_style_set_register_property ("foreground-color", GDK_TYPE_COLOR, NULL);
|
||||
gtk_style_set_register_property ("background-color", GDK_TYPE_COLOR, NULL);
|
||||
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR, NULL);
|
||||
gtk_style_set_register_property ("base-color", GDK_TYPE_COLOR, NULL);
|
||||
gtk_style_set_register_property ("foreground-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||
gtk_style_set_register_property ("background-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||
gtk_style_set_register_property ("base-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||
|
||||
gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL);
|
||||
gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL, NULL);
|
||||
|
||||
gtk_style_set_register_property ("padding", GTK_TYPE_BORDER, NULL);
|
||||
gtk_style_set_register_property ("border", G_TYPE_INT, NULL);
|
||||
gtk_style_set_register_property ("padding", GTK_TYPE_BORDER, NULL, NULL);
|
||||
gtk_style_set_register_property ("border", G_TYPE_INT, NULL, NULL);
|
||||
|
||||
g_value_init (&val, GTK_TYPE_THEMING_ENGINE);
|
||||
g_value_set_object (&val, (GObject *) gtk_theming_engine_load (NULL));
|
||||
gtk_style_set_register_property ("engine", GTK_TYPE_THEMING_ENGINE, &val);
|
||||
gtk_style_set_register_property ("engine", GTK_TYPE_THEMING_ENGINE, &val, NULL);
|
||||
g_value_unset (&val);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (GtkStyleSetPrivate));
|
||||
@ -188,7 +189,8 @@ property_node_lookup (GQuark quark)
|
||||
void
|
||||
gtk_style_set_register_property (const gchar *property_name,
|
||||
GType type,
|
||||
const GValue *default_value)
|
||||
const GValue *default_value,
|
||||
GtkStylePropertyParser parse_func)
|
||||
{
|
||||
PropertyNode *node, new = { 0 };
|
||||
GQuark quark;
|
||||
@ -220,6 +222,9 @@ gtk_style_set_register_property (const gchar *property_name,
|
||||
g_value_copy (default_value, &new.default_value);
|
||||
}
|
||||
|
||||
if (parse_func)
|
||||
new.parse_func = parse_func;
|
||||
|
||||
for (i = 0; i < properties->len; i++)
|
||||
{
|
||||
node = &g_array_index (properties, PropertyNode, i);
|
||||
@ -233,7 +238,8 @@ gtk_style_set_register_property (const gchar *property_name,
|
||||
|
||||
gboolean
|
||||
gtk_style_set_lookup_property (const gchar *property_name,
|
||||
GType *type)
|
||||
GType *type,
|
||||
GtkStylePropertyParser *parse_func)
|
||||
{
|
||||
PropertyNode *node;
|
||||
GtkStyleSetClass *klass;
|
||||
@ -261,6 +267,9 @@ gtk_style_set_lookup_property (const gchar *property_name,
|
||||
if (type)
|
||||
*type = node->property_type;
|
||||
|
||||
if (parse_func)
|
||||
*parse_func = node->parse_func;
|
||||
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -48,14 +48,20 @@ struct GtkStyleSetClass
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
typedef gboolean (* GtkStylePropertyParser) (const gchar *string,
|
||||
GValue *value,
|
||||
GError **error);
|
||||
|
||||
GType gtk_style_set_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* Functions to register style properties */
|
||||
void gtk_style_set_register_property (const gchar *property_name,
|
||||
GType type,
|
||||
const GValue *default_value);
|
||||
const GValue *default_value,
|
||||
GtkStylePropertyParser parse_func);
|
||||
gboolean gtk_style_set_lookup_property (const gchar *property_name,
|
||||
GType *type);
|
||||
GType *type,
|
||||
GtkStylePropertyParser *parse_func);
|
||||
|
||||
GtkStyleSet * gtk_style_set_new (void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user