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)
|
while (scanner->token == G_TOKEN_IDENTIFIER)
|
||||||
{
|
{
|
||||||
const gchar *value_str = NULL;
|
const gchar *value_str = NULL;
|
||||||
|
GtkStylePropertyParser parse_func = NULL;
|
||||||
GType prop_type;
|
GType prop_type;
|
||||||
|
GError *error = NULL;
|
||||||
gchar *prop;
|
gchar *prop;
|
||||||
|
|
||||||
prop = g_strdup (scanner->value.v_identifier);
|
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);
|
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;
|
GValue *val;
|
||||||
|
|
||||||
@ -1444,10 +1446,17 @@ parse_rule (GtkCssProvider *css_provider,
|
|||||||
g_value_set_string (val, value_str);
|
g_value_set_string (val, value_str);
|
||||||
g_hash_table_insert (priv->cur_properties, prop, val);
|
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);
|
g_hash_table_insert (priv->cur_properties, prop, val);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_warning ("Error parsing property value: %s\n", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
|
||||||
g_value_unset (val);
|
g_value_unset (val);
|
||||||
g_slice_free (GValue, val);
|
g_slice_free (GValue, val);
|
||||||
g_free (prop);
|
g_free (prop);
|
||||||
|
@ -39,6 +39,7 @@ struct PropertyNode
|
|||||||
GQuark property_quark;
|
GQuark property_quark;
|
||||||
GType property_type;
|
GType property_type;
|
||||||
GValue default_value;
|
GValue default_value;
|
||||||
|
GtkStylePropertyParser parse_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PropertyData
|
struct PropertyData
|
||||||
@ -72,19 +73,19 @@ gtk_style_set_class_init (GtkStyleSetClass *klass)
|
|||||||
object_class->finalize = gtk_style_set_finalize;
|
object_class->finalize = gtk_style_set_finalize;
|
||||||
|
|
||||||
/* Initialize default property set */
|
/* Initialize default property set */
|
||||||
gtk_style_set_register_property ("foreground-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);
|
gtk_style_set_register_property ("background-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||||
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR, NULL);
|
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR, NULL, NULL);
|
||||||
gtk_style_set_register_property ("base-color", GDK_TYPE_COLOR, 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 ("padding", GTK_TYPE_BORDER, NULL, NULL);
|
||||||
gtk_style_set_register_property ("border", G_TYPE_INT, NULL);
|
gtk_style_set_register_property ("border", G_TYPE_INT, NULL, NULL);
|
||||||
|
|
||||||
g_value_init (&val, GTK_TYPE_THEMING_ENGINE);
|
g_value_init (&val, GTK_TYPE_THEMING_ENGINE);
|
||||||
g_value_set_object (&val, (GObject *) gtk_theming_engine_load (NULL));
|
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_value_unset (&val);
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (GtkStyleSetPrivate));
|
g_type_class_add_private (object_class, sizeof (GtkStyleSetPrivate));
|
||||||
@ -186,9 +187,10 @@ property_node_lookup (GQuark quark)
|
|||||||
|
|
||||||
/* Property registration functions */
|
/* Property registration functions */
|
||||||
void
|
void
|
||||||
gtk_style_set_register_property (const gchar *property_name,
|
gtk_style_set_register_property (const gchar *property_name,
|
||||||
GType type,
|
GType type,
|
||||||
const GValue *default_value)
|
const GValue *default_value,
|
||||||
|
GtkStylePropertyParser parse_func)
|
||||||
{
|
{
|
||||||
PropertyNode *node, new = { 0 };
|
PropertyNode *node, new = { 0 };
|
||||||
GQuark quark;
|
GQuark quark;
|
||||||
@ -220,6 +222,9 @@ gtk_style_set_register_property (const gchar *property_name,
|
|||||||
g_value_copy (default_value, &new.default_value);
|
g_value_copy (default_value, &new.default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parse_func)
|
||||||
|
new.parse_func = parse_func;
|
||||||
|
|
||||||
for (i = 0; i < properties->len; i++)
|
for (i = 0; i < properties->len; i++)
|
||||||
{
|
{
|
||||||
node = &g_array_index (properties, PropertyNode, i);
|
node = &g_array_index (properties, PropertyNode, i);
|
||||||
@ -232,8 +237,9 @@ gtk_style_set_register_property (const gchar *property_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gtk_style_set_lookup_property (const gchar *property_name,
|
gtk_style_set_lookup_property (const gchar *property_name,
|
||||||
GType *type)
|
GType *type,
|
||||||
|
GtkStylePropertyParser *parse_func)
|
||||||
{
|
{
|
||||||
PropertyNode *node;
|
PropertyNode *node;
|
||||||
GtkStyleSetClass *klass;
|
GtkStyleSetClass *klass;
|
||||||
@ -261,6 +267,9 @@ gtk_style_set_lookup_property (const gchar *property_name,
|
|||||||
if (type)
|
if (type)
|
||||||
*type = node->property_type;
|
*type = node->property_type;
|
||||||
|
|
||||||
|
if (parse_func)
|
||||||
|
*parse_func = node->parse_func;
|
||||||
|
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,20 @@ struct GtkStyleSetClass
|
|||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef gboolean (* GtkStylePropertyParser) (const gchar *string,
|
||||||
|
GValue *value,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
GType gtk_style_set_get_type (void) G_GNUC_CONST;
|
GType gtk_style_set_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
/* Functions to register style properties */
|
/* Functions to register style properties */
|
||||||
void gtk_style_set_register_property (const gchar *property_name,
|
void gtk_style_set_register_property (const gchar *property_name,
|
||||||
GType type,
|
GType type,
|
||||||
const GValue *default_value);
|
const GValue *default_value,
|
||||||
gboolean gtk_style_set_lookup_property (const gchar *property_name,
|
GtkStylePropertyParser parse_func);
|
||||||
GType *type);
|
gboolean gtk_style_set_lookup_property (const gchar *property_name,
|
||||||
|
GType *type,
|
||||||
|
GtkStylePropertyParser *parse_func);
|
||||||
|
|
||||||
GtkStyleSet * gtk_style_set_new (void);
|
GtkStyleSet * gtk_style_set_new (void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user