[gtk+/wip/cssvalue: 113/142] cssstyleproperty: Convert binding sets
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 113/142] cssstyleproperty: Convert binding sets
- Date: Sat, 7 Apr 2012 19:55:51 +0000 (UTC)
commit 890d3b647f790fd9fa241dbb3a611d75a9795e71
Author: Benjamin Otte <otte redhat com>
Date: Tue Apr 3 19:11:41 2012 +0200
cssstyleproperty: Convert binding sets
Instead of keeping a custom GPtrArray, keep it as a GtkCssArrayValue of
GtkCssStringValue. This way, we gain equality comparisons and print
functions for free.
gtk/gtkcssstylepropertyimpl.c | 105 +++++++++++++++++++++++++----------------
1 files changed, 64 insertions(+), 41 deletions(-)
---
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index af88d30..517104c 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -426,60 +426,83 @@ parse_css_area (GtkCssStyleProperty *property,
}
static GtkCssValue *
+bindings_value_parse_one (GtkCssParser *parser)
+{
+ char *name;
+
+ name = _gtk_css_parser_try_ident (parser, TRUE);
+ if (name == NULL)
+ {
+ _gtk_css_parser_error (parser, "Not a valid binding name");
+ return NULL;
+ }
+
+
+ if (!gtk_binding_set_find (name))
+ {
+ _gtk_css_parser_error (parser, "No binding set named '%s'", name);
+ g_free (name);
+ return NULL;
+ }
+
+ return _gtk_css_string_value_new_take (name);
+}
+
+static GtkCssValue *
bindings_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
+ return _gtk_css_array_value_parse (parser, bindings_value_parse_one, TRUE);
+}
+
+static void
+bindings_value_query (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
GPtrArray *array;
- GtkBindingSet *binding_set;
- char *name;
+ guint i;
- array = g_ptr_array_new ();
+ g_value_init (value, G_TYPE_PTR_ARRAY);
- do {
- name = _gtk_css_parser_try_ident (parser, TRUE);
- if (name == NULL)
- {
- _gtk_css_parser_error (parser, "Not a valid binding name");
- g_ptr_array_free (array, TRUE);
- return FALSE;
- }
+ if (_gtk_css_array_value_get_n_values (css_value) == 0)
+ return;
- binding_set = gtk_binding_set_find (name);
+ array = g_ptr_array_new ();
- if (!binding_set)
- {
- _gtk_css_parser_error (parser, "No binding set named '%s'", name);
- g_free (name);
- continue;
- }
+ for (i = 0; i < _gtk_css_array_value_get_n_values (css_value); i++)
+ {
+ GtkBindingSet *binding_set = gtk_binding_set_find (_gtk_css_string_value_get (_gtk_css_array_value_get_nth (css_value, i)));
g_ptr_array_add (array, binding_set);
- g_free (name);
}
- while (_gtk_css_parser_try (parser, ",", TRUE));
- return _gtk_css_value_new_take_binding_sets (array);
+ g_value_take_boxed (value, array);
}
-static void
-bindings_value_print (GtkCssStyleProperty *property,
- const GtkCssValue *value,
- GString *string)
+static GtkCssValue *
+bindings_value_assign (GtkCssStyleProperty *property,
+ const GValue *value)
{
- GPtrArray *array;
+ GPtrArray *binding_sets = g_value_get_boxed (value);
+ GtkCssValue **values, *result;
guint i;
- array = _gtk_css_value_get_boxed (value);
+ if (binding_sets == NULL || binding_sets->len == 0)
+ return _gtk_css_array_value_new (NULL);
- for (i = 0; i < array->len; i++)
- {
- GtkBindingSet *binding_set = g_ptr_array_index (array, i);
+ values = g_new (GtkCssValue *, binding_sets->len);
- if (i > 0)
- g_string_append (string, ", ");
- g_string_append (string, binding_set->set_name);
+ for (i = 0; i < binding_sets->len; i++)
+ {
+ GtkBindingSet *binding_set = g_ptr_array_index (binding_sets, i);
+ values[i] = _gtk_css_string_value_new (binding_set->set_name);
}
+
+ result = _gtk_css_array_value_new_from_array (values, binding_sets->len);
+ g_free (values);
+ return result;
}
static GtkCssValue *
@@ -1508,7 +1531,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("border-top-left-radius",
GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS,
G_TYPE_NONE,
- 0,
+ GTK_STYLE_PROPERTY_ANIMATED,
border_corner_radius_value_parse,
NULL,
border_corner_radius_value_compute,
@@ -1520,7 +1543,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("border-top-right-radius",
GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS,
G_TYPE_NONE,
- 0,
+ GTK_STYLE_PROPERTY_ANIMATED,
border_corner_radius_value_parse,
NULL,
border_corner_radius_value_compute,
@@ -1532,7 +1555,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("border-bottom-right-radius",
GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS,
G_TYPE_NONE,
- 0,
+ GTK_STYLE_PROPERTY_ANIMATED,
border_corner_radius_value_parse,
NULL,
border_corner_radius_value_compute,
@@ -1544,7 +1567,7 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("border-bottom-left-radius",
GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS,
G_TYPE_NONE,
- 0,
+ GTK_STYLE_PROPERTY_ANIMATED,
border_corner_radius_value_parse,
NULL,
border_corner_radius_value_compute,
@@ -1846,11 +1869,11 @@ _gtk_css_style_property_init_properties (void)
G_TYPE_PTR_ARRAY,
0,
bindings_value_parse,
- bindings_value_print,
NULL,
- query_simple,
- assign_simple,
NULL,
- _gtk_css_value_new_take_binding_sets (NULL));
+ bindings_value_query,
+ bindings_value_assign,
+ NULL,
+ _gtk_css_array_value_new (NULL));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]