From 3c49e2ef629a51f43287e0763fd2a43d14ea126e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 8 Jun 2007 05:02:13 +0000 Subject: [PATCH] Make it possible for theme engines to support symbolic colors. (#426192, 2007-06-08 Matthias Clasen Make it possible for theme engines to support symbolic colors. (#426192, Andrea Cimitan, patch by Olivier Samyn) * gtk/gtk.symbols: * gtk/gtkrc.h: * gtk/gtkrc.c (gtk_rc_parse_color_full): Export this function * gtk/gtkrc.c (gtk_rc_parse_engine): Copy color hashes to new style before parsing engine section. svn path=/trunk/; revision=18081 --- ChangeLog | 12 ++++ docs/reference/ChangeLog | 4 ++ docs/reference/gtk/gtk-sections.txt | 1 + gtk/gtk.symbols | 1 + gtk/gtkrc.c | 90 +++++++++++++++++++++-------- gtk/gtkrc.h | 5 +- 6 files changed, 87 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d52f33ea4..1999228e00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-06-08 Matthias Clasen + + Make it possible for theme engines to support symbolic + colors. (#426192, Andrea Cimitan, patch by Olivier Samyn) + + * gtk/gtk.symbols: + * gtk/gtkrc.h: + * gtk/gtkrc.c (gtk_rc_parse_color_full): Export this function + + * gtk/gtkrc.c (gtk_rc_parse_engine): Copy color hashes + to new style before parsing engine section. + 2007-06-08 Michael Natterer * gdk/quartz/gdkdrawable-quartz.c: add utility function diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 8ba9473743..5772e19019 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2007-06-08 Matthias Clasen + + * gtk/gtk-sections.txt: Add gtk_rc_parse_color_full + 2007-06-06 Matthias Clasen * === Released 2.11.2 === diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 4cdb79f7a1..9da0b3bfb8 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -5563,6 +5563,7 @@ gtk_rc_add_default_file gtk_rc_get_default_files gtk_rc_set_default_files gtk_rc_parse_color +gtk_rc_parse_color_full gtk_rc_parse_state gtk_rc_parse_priority gtk_rc_find_module_in_path diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 69694376fa..5355e25592 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -3041,6 +3041,7 @@ gtk_rc_parse PRIVATE gtk_rc_parse_utf8 #endif gtk_rc_parse_color +gtk_rc_parse_color_full gtk_rc_parse_priority gtk_rc_parse_state gtk_rc_parse_string diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c index 324b37a49b..ae5cdd5239 100644 --- a/gtk/gtkrc.c +++ b/gtk/gtkrc.c @@ -218,9 +218,6 @@ static guint gtk_rc_parse_stock (GtkRcContext *context, static guint gtk_rc_parse_logical_color (GScanner *scanner, GtkRcStyle *rc_style, GHashTable *hash); -static guint gtk_rc_parse_color_full (GScanner *scanner, - GtkRcStyle *style, - GdkColor *color); static void gtk_rc_clear_hash_node (gpointer key, gpointer data, @@ -1550,9 +1547,8 @@ gtk_rc_style_copy_icons_and_colors (GtkRcStyle *rc_style, { gtk_rc_style_prepend_empty_color_hash (rc_style); - priv->color_hashes = - g_slist_append (priv->color_hashes, - g_hash_table_ref (context->color_hash)); + priv->color_hashes = g_slist_append (priv->color_hashes, + g_hash_table_ref (context->color_hash)); } } @@ -3605,6 +3601,7 @@ gtk_rc_parse_engine (GtkRcContext *context, guint result = G_TOKEN_NONE; GtkRcStyle *new_style = NULL; gboolean parsed_curlies = FALSE; + GtkRcStylePrivate *rc_priv, *new_priv; token = g_scanner_get_next_token (scanner); if (token != GTK_RC_TOKEN_ENGINE) @@ -3628,13 +3625,23 @@ gtk_rc_parse_engine (GtkRcContext *context, parsed_curlies = TRUE; + rc_priv = GTK_RC_STYLE_GET_PRIVATE (*rc_style); + if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE) { new_style = gtk_rc_style_new (); gtk_rc_style_real_merge (new_style, *rc_style); - - if ((*rc_style)->name) - new_style->name = g_strdup ((*rc_style)->name); + + new_style->name = g_strdup ((*rc_style)->name); + + /* take over icon factories and color hashes + * from the to-be-deleted style + */ + new_style->icon_factories = (*rc_style)->icon_factories; + (*rc_style)->icon_factories = NULL; + new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style); + new_priv->color_hashes = rc_priv->color_hashes; + rc_priv->color_hashes = NULL; } else (*rc_style)->engine_specified = TRUE; @@ -3655,10 +3662,19 @@ gtk_rc_parse_engine (GtkRcContext *context, g_type_module_unuse (G_TYPE_MODULE (engine)); new_class = GTK_RC_STYLE_GET_CLASS (new_style); - + new_class->merge (new_style, *rc_style); - if ((*rc_style)->name) - new_style->name = g_strdup ((*rc_style)->name); + + new_style->name = g_strdup ((*rc_style)->name); + + /* take over icon factories and color hashes + * from the to-be-deleted style + */ + new_style->icon_factories = (*rc_style)->icon_factories; + (*rc_style)->icon_factories = NULL; + new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style); + new_priv->color_hashes = rc_priv->color_hashes; + rc_priv->color_hashes = NULL; if (new_class->parse) { @@ -3667,6 +3683,13 @@ gtk_rc_parse_engine (GtkRcContext *context, if (result != G_TOKEN_NONE) { + /* copy icon factories and color hashes back + */ + (*rc_style)->icon_factories = new_style->icon_factories; + new_style->icon_factories = NULL; + rc_priv->color_hashes = new_priv->color_hashes; + new_priv->color_hashes = NULL; + g_object_unref (new_style); new_style = NULL; } @@ -3698,18 +3721,6 @@ gtk_rc_parse_engine (GtkRcContext *context, if (new_style) { - GtkRcStylePrivate *rc_priv = GTK_RC_STYLE_GET_PRIVATE (*rc_style); - GtkRcStylePrivate *new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style); - - /* take over icon factories and color hashes from the to-be-deleted style - */ - - new_style->icon_factories = (*rc_style)->icon_factories; - (*rc_style)->icon_factories = NULL; - - new_priv->color_hashes = rc_priv->color_hashes; - rc_priv->color_hashes = NULL; - new_style->engine_specified = TRUE; g_object_unref (*rc_style); @@ -3820,6 +3831,20 @@ gtk_rc_parse_priority (GScanner *scanner, return G_TOKEN_NONE; } +/** + * gtk_rc_parse_color: + * @scanner: a #GScanner + * @color: a pointer to a #GtkColor structure in which to store the result + * + * Parses a color in the format expected + * in a RC file. + * + * Note that theme engines should use gtk_rc_parse_color_full() in + * order to support symbolic colors. + * + * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token + * that was expected but not found + */ guint gtk_rc_parse_color (GScanner *scanner, GdkColor *color) @@ -3827,7 +3852,22 @@ gtk_rc_parse_color (GScanner *scanner, return gtk_rc_parse_color_full (scanner, NULL, color); } -static guint +/** + * gtk_rc_parse_color_full: + * @scanner: a #GScanner + * @style: a #GtkRcStyle, or %NULL + * @color: a pointer to a #GtkColor structure in which to store the result + * + * Parses a color in the format expected + * in a RC file. If @style is not %NULL, it will be consulted to resolve + * references to symbolic colors. + * + * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token + * that was expected but not found + * + * Since: 2.12 + */ +guint gtk_rc_parse_color_full (GScanner *scanner, GtkRcStyle *style, GdkColor *color) diff --git a/gtk/gtkrc.h b/gtk/gtkrc.h index a64343c45e..c6880af272 100644 --- a/gtk/gtkrc.h +++ b/gtk/gtkrc.h @@ -102,7 +102,7 @@ struct _GtkRcStyleClass GtkSettings *settings, GScanner *scanner); - /* Combine RC style data from src into dest. If overriden, this + /* Combine RC style data from src into dest. If overridden, this * function should chain to the parent. */ void (*merge) (GtkRcStyle *dest, @@ -227,6 +227,9 @@ typedef enum { GScanner* gtk_rc_scanner_new (void); guint gtk_rc_parse_color (GScanner *scanner, GdkColor *color); +guint gtk_rc_parse_color_full (GScanner *scanner, + GtkRcStyle *style, + GdkColor *color); guint gtk_rc_parse_state (GScanner *scanner, GtkStateType *state); guint gtk_rc_parse_priority (GScanner *scanner,