[gtk+/wip/css: 51/154] styleproperty: Move id handling
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 51/154] styleproperty: Move id handling
- Date: Sat, 7 Jan 2012 14:52:13 +0000 (UTC)
commit a1b84e6f897f6de1a28d51b2e2be309e17e819b1
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 31 19:28:59 2011 +0100
styleproperty: Move id handling
only real style properties can have an id, so let
GtkCssStylePropertyClass handle it.
gtk/gtkcssstyleproperty.c | 108 ++++++++++++++++++++++++++++++++++++++
gtk/gtkcssstylepropertyprivate.h | 8 +++
gtk/gtkstyleproperty.c | 24 ++------
gtk/gtkstylepropertyprivate.h | 1 -
4 files changed, 122 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 45b3125..1f29052 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -22,15 +22,123 @@
#include "gtkcssstylepropertyprivate.h"
+#include "gtkintl.h"
+
+enum {
+ PROP_0,
+ PROP_ID,
+};
+
G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY)
static void
+gtk_css_style_property_constructed (GObject *object)
+{
+ GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
+ GtkCssStylePropertyClass *klass = GTK_CSS_STYLE_PROPERTY_GET_CLASS (property);
+
+ property->id = klass->style_properties->len;
+ g_ptr_array_add (klass->style_properties, property);
+
+ G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object);
+}
+
+static void
+gtk_css_style_property_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ g_value_set_boolean (value, property->id);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
_gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = gtk_css_style_property_constructed;
+ object_class->get_property = gtk_css_style_property_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_uint ("id",
+ P_("ID"),
+ P_("The numeric id for quick access"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE));
+
+ klass->style_properties = g_ptr_array_new ();
}
+
static void
_gtk_css_style_property_init (GtkCssStyleProperty *style_property)
{
}
+/**
+ * _gtk_css_style_property_get_n_properties:
+ *
+ * Gets the number of style properties. This number can increase when new
+ * theme engines are loaded. Shorthand properties are not included here.
+ *
+ * Returns: The number of style properties.
+ **/
+guint
+_gtk_css_style_property_get_n_properties (void)
+{
+ GtkCssStylePropertyClass *klass;
+
+ klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
+
+ return klass->style_properties->len;
+}
+
+/**
+ * _gtk_css_style_property_lookup_by_id:
+ * @id: the id of the property
+ *
+ * Gets the style property with the given id. All style properties (but not
+ * shorthand properties) are indexable by id so that it's easy to use arrays
+ * when doing style lookups.
+ *
+ * Returns: (transfer none): The style property with the given id
+ **/
+GtkCssStyleProperty *
+_gtk_css_style_property_lookup_by_id (guint id)
+{
+ GtkCssStylePropertyClass *klass;
+
+ klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
+
+ return g_ptr_array_index (klass->style_properties, id);
+}
+
+/**
+ * _gtk_css_style_property_get_id:
+ * @property: the property
+ *
+ * Gets the id for the given property. IDs are used to allow using arrays
+ * for style lookups.
+ *
+ * Returns: The id of the property
+ **/
+guint
+_gtk_css_style_property_get_id (GtkCssStyleProperty *property)
+{
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+
+ return property->id;
+}
+
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 923bd23..797c826 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -38,15 +38,23 @@ typedef struct _GtkCssStylePropertyClass GtkCssStylePropertyClass;
struct _GtkCssStyleProperty
{
GtkStyleProperty parent;
+
+ guint id;
};
struct _GtkCssStylePropertyClass
{
GtkStylePropertyClass parent_class;
+
+ GPtrArray *style_properties;
};
GType _gtk_css_style_property_get_type (void) G_GNUC_CONST;
+guint _gtk_css_style_property_get_n_properties(void);
+GtkCssStyleProperty * _gtk_css_style_property_lookup_by_id (guint id);
+
+guint _gtk_css_style_property_get_id (GtkCssStyleProperty *property);
G_END_DECLS
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 69a16f2..842a1ce 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -60,7 +60,6 @@ enum {
static GHashTable *parse_funcs = NULL;
static GHashTable *print_funcs = NULL;
-static GPtrArray *__style_property_array = NULL;
G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
@@ -1616,25 +1615,13 @@ transparent_color_value_parse (GtkCssParser *parser,
guint
_gtk_style_property_get_count (void)
{
- return __style_property_array ? __style_property_array->len : 0;
+ return _gtk_css_style_property_get_n_properties ();
}
GtkStyleProperty *
_gtk_style_property_get (guint id)
{
- g_assert (__style_property_array);
-
- return g_ptr_array_index (__style_property_array, id);
-}
-
-static void
-_gtk_style_property_generate_id (GtkStyleProperty *node)
-{
- if (__style_property_array == NULL)
- __style_property_array = g_ptr_array_new ();
-
- node->id = __style_property_array->len;
- g_ptr_array_add (__style_property_array, node);
+ return GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (id));
}
static void
@@ -1842,7 +1829,10 @@ _gtk_style_property_get_id (GtkStyleProperty *property)
{
g_return_val_if_fail (property != NULL, FALSE);
- return property->id;
+ if (GTK_IS_CSS_STYLE_PROPERTY (property))
+ return _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (property));
+ else
+ return 0;
}
static gboolean
@@ -2545,8 +2535,6 @@ _gtk_style_property_register (GParamSpec *pspec,
node->parse_func = parse_func;
node->print_func = print_func;
- _gtk_style_property_generate_id (node);
-
/* initialize the initial value */
if (initial_value)
{
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index cc03728..420f432 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -62,7 +62,6 @@ struct _GtkStyleProperty
GParamSpec *pspec;
GtkStylePropertyFlags flags;
- guint id;
GValue initial_value;
GtkStylePropertyParser property_parse_func;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]