Add the gtk-key-bindings CSS parser property.

This property takes a list of binding set names to have these
stored as a GPtrArray containing GtkBindingSets. this property
is handled so merging GtkStyleProperties will merge both
GtkBindingSet lists.
This commit is contained in:
Carlos Garnacho 2011-01-28 09:59:02 +01:00 committed by Matthias Clasen
parent dbff92fd9f
commit d39f0411be
2 changed files with 54 additions and 0 deletions

View File

@ -2762,6 +2762,32 @@ border_parse_str (const gchar *str,
return border;
}
static void
resolve_binding_sets (const gchar *value_str,
GValue *value)
{
GPtrArray *array;
gchar **bindings, **str;
bindings = g_strsplit (value_str, ",", -1);
array = g_ptr_array_new ();
for (str = bindings; *str; str++)
{
GtkBindingSet *binding_set;
binding_set = gtk_binding_set_find (g_strstrip (*str));
if (!binding_set)
continue;
g_ptr_array_add (array, binding_set);
}
g_value_take_boxed (value, array);
g_strfreev (bindings);
}
static gboolean
css_provider_parse_value (GtkCssProvider *css_provider,
const gchar *value_str,
@ -3378,6 +3404,12 @@ parse_rule (GtkCssProvider *css_provider,
g_param_value_set_default (pspec, val);
g_hash_table_insert (priv->cur_properties, prop, val);
}
else if (strcmp (prop, "gtk-key-bindings") == 0)
{
/* Private property holding the binding sets */
resolve_binding_sets (value_str, val);
g_hash_table_insert (priv->cur_properties, prop, val);
}
else if (pspec->value_type == G_TYPE_STRING)
{
g_value_set_string (val, value_str);

View File

@ -171,6 +171,13 @@ gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
"Transition animation description",
GTK_TYPE_ANIMATION_DESCRIPTION, 0));
/* Private property holding the binding sets */
gtk_style_properties_register_property (NULL,
g_param_spec_boxed ("gtk-key-bindings",
"Key bindings",
"Key bindings",
G_TYPE_PTR_ARRAY, 0));
g_type_class_add_private (object_class, sizeof (GtkStylePropertiesPrivate));
}
@ -1239,6 +1246,21 @@ gtk_style_properties_merge (GtkStyleProperties *props,
pango_font_description_merge (font_desc, font_desc_to_merge, replace);
}
else if (G_VALUE_TYPE (&data->value) == G_TYPE_PTR_ARRAY &&
G_IS_VALUE (value))
{
GPtrArray *array, *array_to_merge;
gint i;
/* Append the array, mainly thought
* for the gtk-key-bindings property
*/
array = g_value_get_boxed (value);
array_to_merge = g_value_get_boxed (&data->value);
for (i = 0; i < array_to_merge->len; i++)
g_ptr_array_add (array, g_ptr_array_index (array_to_merge, i));
}
else if (replace || !G_IS_VALUE (value))
{
if (!G_IS_VALUE (value))