[gtk+/gtk-style-context: 106/251] GtkStyleSet: Add API to map symbolic colors.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 106/251] GtkStyleSet: Add API to map symbolic colors.
- Date: Tue, 12 Oct 2010 02:04:01 +0000 (UTC)
commit f9981e0103cfdb1141288c4fe4e3217464bceaac
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jun 25 19:37:54 2010 +0200
GtkStyleSet: Add API to map symbolic colors.
gtk/gtkstyleset.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkstyleset.h | 10 +++++--
2 files changed, 74 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkstyleset.c b/gtk/gtkstyleset.c
index 5d8a856..be07f63 100644
--- a/gtk/gtkstyleset.c
+++ b/gtk/gtkstyleset.c
@@ -48,6 +48,7 @@ struct PropertyData
struct GtkStyleSetPrivate
{
+ GHashTable *color_map;
GHashTable *properties;
};
@@ -126,6 +127,9 @@ gtk_style_set_finalize (GObject *object)
priv = GTK_STYLE_SET_GET_PRIVATE (object);
g_hash_table_destroy (priv->properties);
+ if (priv->color_map)
+ g_hash_table_destroy (priv->color_map);
+
G_OBJECT_CLASS (gtk_style_set_parent_class)->finalize (object);
}
@@ -260,6 +264,47 @@ gtk_style_set_new (void)
return g_object_new (GTK_TYPE_STYLE_SET, NULL);
}
+void
+gtk_style_set_map_color (GtkStyleSet *set,
+ const gchar *name,
+ GtkSymbolicColor *color)
+{
+ GtkStyleSetPrivate *priv;
+
+ g_return_if_fail (GTK_IS_STYLE_SET (set));
+ g_return_if_fail (name != NULL);
+ g_return_if_fail (color != NULL);
+
+ priv = GTK_STYLE_SET_GET_PRIVATE (set);
+
+ if (G_UNLIKELY (!priv->color_map))
+ priv->color_map = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) gtk_symbolic_color_unref);
+
+ g_hash_table_replace (priv->color_map,
+ g_strdup (name),
+ gtk_symbolic_color_ref (color));
+}
+
+GtkSymbolicColor *
+gtk_style_set_lookup_color (GtkStyleSet *set,
+ const gchar *name)
+{
+ GtkStyleSetPrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_STYLE_SET (set), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ priv = GTK_STYLE_SET_GET_PRIVATE (set);
+
+ if (!priv->color_map)
+ return NULL;
+
+ return g_hash_table_lookup (priv->color_map, name);
+}
+
static void
set_property_internal (GtkStyleSet *set,
const gchar *property,
@@ -570,6 +615,28 @@ gtk_style_set_merge (GtkStyleSet *set,
priv = GTK_STYLE_SET_GET_PRIVATE (set);
priv_to_merge = GTK_STYLE_SET_GET_PRIVATE (set_to_merge);
+ /* Merge symbolic color map */
+ if (priv_to_merge->color_map)
+ {
+ g_hash_table_iter_init (&iter, priv_to_merge->color_map);
+
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ const gchar *name;
+ GtkSymbolicColor *color;
+
+ name = key;
+ color = value;
+
+ if (!replace &&
+ g_hash_table_lookup (priv->color_map, name))
+ continue;
+
+ gtk_style_set_map_color (set, name, color);
+ }
+ }
+
+ /* Merge symbolic style properties */
g_hash_table_iter_init (&iter, priv_to_merge->properties);
while (g_hash_table_iter_next (&iter, &key, &value))
diff --git a/gtk/gtkstyleset.h b/gtk/gtkstyleset.h
index d14deb8..88a11ae 100644
--- a/gtk/gtkstyleset.h
+++ b/gtk/gtkstyleset.h
@@ -23,9 +23,7 @@
#include <glib-object.h>
#include <gdk/gdk.h>
#include "gtkenums.h"
-
-/* GtkBorder is defined there */
-#include "gtkstyle.h"
+#include "gtksymboliccolor.h"
G_BEGIN_DECLS
@@ -59,6 +57,12 @@ gboolean gtk_style_set_lookup_property (const gchar *property_name,
GtkStyleSet * gtk_style_set_new (void);
+void gtk_style_set_map_color (GtkStyleSet *set,
+ const gchar *name,
+ GtkSymbolicColor *color);
+GtkSymbolicColor * gtk_style_set_lookup_color (GtkStyleSet *set,
+ const gchar *name);
+
void gtk_style_set_set_default (GtkStyleSet *set,
const gchar *property,
const GValue *value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]