[gtk+] styleproperties: Move the style property handling code



commit 727a839d718b65e9129720c946f1dfe924a2ed2c
Author: Benjamin Otte <otte redhat com>
Date:   Sat May 21 04:17:28 2011 +0200

    styleproperties: Move the style property handling code
    
    ... from gtkstyleproperties.c to gtkstyleproperty.c

 gtk/gtkstyleproperties.c        |  137 +-------------------------------------
 gtk/gtkstylepropertiesprivate.h |   10 ---
 gtk/gtkstyleproperty.c          |  135 ++++++++++++++++++++++++++++++++++++++
 gtk/gtkstylepropertyprivate.h   |   13 ++++
 4 files changed, 152 insertions(+), 143 deletions(-)
---
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index fc65f9e..2fd806b 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -25,16 +25,14 @@
 #include <gobject/gvaluecollector.h>
 #include <cairo-gobject.h>
 
-#include "gtktypebuiltins.h"
 #include "gtkstyleprovider.h"
 #include "gtksymboliccolor.h"
-#include "gtkprivate.h"
 #include "gtkthemingengine.h"
 #include "gtkanimationdescription.h"
-#include "gtkborder.h"
 #include "gtkgradient.h"
-#include "gtk9slice.h"
 #include "gtkshadowprivate.h"
+
+#include "gtkstylepropertyprivate.h"
 #include "gtkintl.h"
 
 /**
@@ -77,8 +75,6 @@ struct GtkStylePropertiesPrivate
   GHashTable *properties;
 };
 
-static GHashTable *properties = NULL;
-
 static void gtk_style_properties_provider_init (GtkStyleProviderIface *iface);
 static void gtk_style_properties_finalize      (GObject      *object);
 
@@ -294,115 +290,6 @@ gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
   iface->get_style = gtk_style_properties_get_style;
 }
 
-static void
-gtk_style_property_init (void)
-{
-  GParamSpec *pspec;
-
-  if (G_LIKELY (properties))
-    return;
-
-  /* stuff is never freed, so no need for free functions */
-  properties = g_hash_table_new (g_str_hash, g_str_equal);
-
-  /* note that gtk_style_properties_register_property() calls this function,
-   * so make sure we're sanely inited to avoid infloops */
-
-  pspec = g_param_spec_boxed ("color",
-                              "Foreground color",
-                              "Foreground color",
-                              GDK_TYPE_RGBA, 0);
-  gtk_style_param_set_inherit (pspec, TRUE);
-  gtk_style_properties_register_property (NULL, pspec);
-
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("background-color",
-                                                              "Background color",
-                                                              "Background color",
-                                                              GDK_TYPE_RGBA, 0));
-
-  pspec = g_param_spec_boxed ("font",
-                              "Font Description",
-                              "Font Description",
-                              PANGO_TYPE_FONT_DESCRIPTION, 0);
-  gtk_style_param_set_inherit (pspec, TRUE);
-  gtk_style_properties_register_property (NULL, pspec);
-
-  pspec = g_param_spec_boxed ("text-shadow",
-                              "Text shadow",
-                              "Text shadow",
-                              GTK_TYPE_SHADOW, 0);
-  gtk_style_param_set_inherit (pspec, TRUE);
-  gtk_style_properties_register_property (NULL, pspec);
-
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("margin",
-                                                              "Margin",
-                                                              "Margin",
-                                                              GTK_TYPE_BORDER, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("padding",
-                                                              "Padding",
-                                                              "Padding",
-                                                              GTK_TYPE_BORDER, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("border-width",
-                                                              "Border width",
-                                                              "Border width, in pixels",
-                                                              GTK_TYPE_BORDER, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_int ("border-radius",
-                                                            "Border radius",
-                                                            "Border radius, in pixels",
-                                                            0, G_MAXINT, 0, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_enum ("border-style",
-                                                             "Border style",
-                                                             "Border style",
-                                                             GTK_TYPE_BORDER_STYLE,
-                                                             GTK_BORDER_STYLE_NONE, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("border-color",
-                                                              "Border color",
-                                                              "Border color",
-                                                              GDK_TYPE_RGBA, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("background-image",
-                                                              "Background Image",
-                                                              "Background Image",
-                                                              CAIRO_GOBJECT_TYPE_PATTERN, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("border-image",
-                                                              "Border Image",
-                                                              "Border Image",
-                                                              GTK_TYPE_9SLICE, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_object ("engine",
-                                                               "Theming Engine",
-                                                               "Theming Engine",
-                                                               GTK_TYPE_THEMING_ENGINE, 0));
-  gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("transition",
-                                                              "Transition animation description",
-                                                              "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));
-}
-
-const GtkStyleProperty *
-_gtk_style_property_lookup (const char *name)
-{
-  gtk_style_property_init ();
-
-  return g_hash_table_lookup (properties, name);
-}
-
 /* Property registration functions */
 
 /**
@@ -421,26 +308,10 @@ void
 gtk_style_properties_register_property (GtkStylePropertyParser  parse_func,
                                         GParamSpec             *pspec)
 {
-  const GtkStyleProperty *existing;
-  GtkStyleProperty *node;
-
   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
 
-  gtk_style_property_init ();
-
-  existing = _gtk_style_property_lookup (pspec->name);
-  if (existing != NULL)
-    {
-      g_warning ("Property \"%s\" was already registered with type %s",
-                 pspec->name, g_type_name (existing->pspec->value_type));
-      return;
-    }
-
-  node = g_slice_new0 (GtkStyleProperty);
-  node->pspec = pspec;
-  node->parse_func = parse_func;
-
-  g_hash_table_insert (properties, pspec->name, node);
+  _gtk_style_property_register (pspec,
+                                parse_func);
 }
 
 /**
diff --git a/gtk/gtkstylepropertiesprivate.h b/gtk/gtkstylepropertiesprivate.h
index 3b90e6c..f4cea2d 100644
--- a/gtk/gtkstylepropertiesprivate.h
+++ b/gtk/gtkstylepropertiesprivate.h
@@ -24,16 +24,6 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GtkStyleProperty GtkStyleProperty;
-
-struct _GtkStyleProperty
-{
-  GParamSpec *pspec;
-  GtkStylePropertyParser parse_func;
-};
-
-const GtkStyleProperty * _gtk_style_property_lookup        (const char         *name);
-
 const GValue * _gtk_style_properties_peek_property         (GtkStyleProperties *props,
                                                             const gchar        *prop_name,
                                                             GtkStateFlags       state);
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 39125d2..022e577 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -38,6 +38,7 @@
 #include "gtkgradient.h"
 #include "gtkshadowprivate.h"
 #include "gtkthemingengine.h"
+#include "gtktypebuiltins.h"
 
 typedef gboolean (* ParseFunc)        (GtkCssParser  *parser,
                                        GFile         *base,
@@ -46,6 +47,7 @@ typedef char *   (* ToStringFunc)     (const GValue  *value);
 
 static GHashTable *parse_funcs = NULL;
 static GHashTable *to_string_funcs = NULL;
+static GHashTable *properties = NULL;
 
 static void
 register_conversion_function (GType          type,
@@ -1278,3 +1280,136 @@ _gtk_css_value_to_string (const GValue *value)
 
   return g_strdup_value_contents (value);
 }
+
+static void
+gtk_style_property_init (void)
+{
+  GParamSpec *pspec;
+
+  if (G_LIKELY (properties))
+    return;
+
+  /* stuff is never freed, so no need for free functions */
+  properties = g_hash_table_new (g_str_hash, g_str_equal);
+
+  /* note that gtk_style_properties_register_property() calls this function,
+   * so make sure we're sanely inited to avoid infloops */
+
+  pspec = g_param_spec_boxed ("color",
+                              "Foreground color",
+                              "Foreground color",
+                              GDK_TYPE_RGBA, 0);
+  gtk_style_param_set_inherit (pspec, TRUE);
+  gtk_style_properties_register_property (NULL, pspec);
+
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("background-color",
+                                                              "Background color",
+                                                              "Background color",
+                                                              GDK_TYPE_RGBA, 0));
+
+  pspec = g_param_spec_boxed ("font",
+                              "Font Description",
+                              "Font Description",
+                              PANGO_TYPE_FONT_DESCRIPTION, 0);
+  gtk_style_param_set_inherit (pspec, TRUE);
+  gtk_style_properties_register_property (NULL, pspec);
+
+  pspec = g_param_spec_boxed ("text-shadow",
+                              "Text shadow",
+                              "Text shadow",
+                              GTK_TYPE_SHADOW, 0);
+  gtk_style_param_set_inherit (pspec, TRUE);
+  gtk_style_properties_register_property (NULL, pspec);
+
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("margin",
+                                                              "Margin",
+                                                              "Margin",
+                                                              GTK_TYPE_BORDER, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("padding",
+                                                              "Padding",
+                                                              "Padding",
+                                                              GTK_TYPE_BORDER, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("border-width",
+                                                              "Border width",
+                                                              "Border width, in pixels",
+                                                              GTK_TYPE_BORDER, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("border-radius",
+                                                            "Border radius",
+                                                            "Border radius, in pixels",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_enum ("border-style",
+                                                             "Border style",
+                                                             "Border style",
+                                                             GTK_TYPE_BORDER_STYLE,
+                                                             GTK_BORDER_STYLE_NONE, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("border-color",
+                                                              "Border color",
+                                                              "Border color",
+                                                              GDK_TYPE_RGBA, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("background-image",
+                                                              "Background Image",
+                                                              "Background Image",
+                                                              CAIRO_GOBJECT_TYPE_PATTERN, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("border-image",
+                                                              "Border Image",
+                                                              "Border Image",
+                                                              GTK_TYPE_9SLICE, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_object ("engine",
+                                                               "Theming Engine",
+                                                               "Theming Engine",
+                                                               GTK_TYPE_THEMING_ENGINE, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("transition",
+                                                              "Transition animation description",
+                                                              "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));
+}
+
+const GtkStyleProperty *
+_gtk_style_property_lookup (const char *name)
+{
+  gtk_style_property_init ();
+
+  return g_hash_table_lookup (properties, name);
+}
+
+void
+_gtk_style_property_register (GParamSpec             *pspec,
+                              GtkStylePropertyParser  parse_func)
+{
+  const GtkStyleProperty *existing;
+  GtkStyleProperty *node;
+
+  gtk_style_property_init ();
+
+  existing = _gtk_style_property_lookup (pspec->name);
+  if (existing != NULL)
+    {
+      g_warning ("Property \"%s\" was already registered with type %s",
+                 pspec->name, g_type_name (existing->pspec->value_type));
+      return;
+    }
+
+  node = g_slice_new0 (GtkStyleProperty);
+  node->pspec = pspec;
+  node->parse_func = parse_func;
+
+  g_hash_table_insert (properties, pspec->name, node);
+}
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index 3db8e54..57dd0d9 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -24,6 +24,19 @@
 
 G_BEGIN_DECLS
 
+typedef struct _GtkStyleProperty GtkStyleProperty;
+
+struct _GtkStyleProperty
+{
+  GParamSpec             *pspec;
+  GtkStylePropertyParser  parse_func;
+};
+
+const GtkStyleProperty * _gtk_style_property_lookup        (const char         *name);
+
+void                     _gtk_style_property_register      (GParamSpec             *pspec,
+                                                            GtkStylePropertyParser  parse_func);
+
 gboolean                _gtk_css_value_parse              (GValue        *value,
                                                            GtkCssParser  *parser,
                                                            GFile         *base);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]