1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
48 #include "gdkconfig.h"
50 #include "gtkversion.h"
52 #include "gtkbindings.h"
53 #include "gtkthemes.h"
55 #include "gtkiconfactory.h"
56 #include "gtkprivate.h"
57 #include "gtksettings.h"
58 #include "gtkwindow.h"
64 typedef struct _GtkRcSet GtkRcSet;
65 typedef struct _GtkRcNode GtkRcNode;
66 typedef struct _GtkRcFile GtkRcFile;
77 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
80 gchar *canonical_name;
84 #define GTK_RC_MAX_PIXMAP_PATHS 128
88 GHashTable *rc_style_ht;
89 GtkSettings *settings;
90 GSList *rc_sets_widget;
91 GSList *rc_sets_widget_class;
92 GSList *rc_sets_class;
94 /* The files we have parsed, to reread later if necessary */
98 gchar *key_theme_name;
100 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
102 gint default_priority;
105 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
107 static guint gtk_rc_style_hash (const gchar *name);
108 static gboolean gtk_rc_style_equal (const gchar *a,
110 static guint gtk_rc_styles_hash (const GSList *rc_styles);
111 static gboolean gtk_rc_styles_equal (const GSList *a,
113 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
115 static GSList * gtk_rc_styles_match (GSList *rc_styles,
119 const gchar *path_reversed);
120 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
121 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
122 static void gtk_rc_parse_default_files (GtkRcContext *context);
123 static void gtk_rc_parse_named (GtkRcContext *context,
126 static void gtk_rc_parse_file (GtkRcContext *context,
127 const gchar *filename,
130 static void gtk_rc_parse_any (GtkRcContext *context,
131 const gchar *input_name,
133 const gchar *input_string);
134 static guint gtk_rc_parse_statement (GtkRcContext *context,
136 static guint gtk_rc_parse_style (GtkRcContext *context,
138 static guint gtk_rc_parse_assignment (GScanner *scanner,
139 GtkRcProperty *prop);
140 static guint gtk_rc_parse_bg (GScanner *scanner,
142 static guint gtk_rc_parse_fg (GScanner *scanner,
144 static guint gtk_rc_parse_text (GScanner *scanner,
146 static guint gtk_rc_parse_base (GScanner *scanner,
148 static guint gtk_rc_parse_xthickness (GScanner *scanner,
150 static guint gtk_rc_parse_ythickness (GScanner *scanner,
152 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
154 GtkRcStyle *rc_style);
155 static guint gtk_rc_parse_font (GScanner *scanner,
156 GtkRcStyle *rc_style);
157 static guint gtk_rc_parse_fontset (GScanner *scanner,
158 GtkRcStyle *rc_style);
159 static guint gtk_rc_parse_font_name (GScanner *scanner,
160 GtkRcStyle *rc_style);
161 static guint gtk_rc_parse_engine (GtkRcContext *context,
163 GtkRcStyle **rc_style);
164 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
166 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
168 const gchar *pix_path);
169 static guint gtk_rc_parse_module_path (GScanner *scanner);
170 static void gtk_rc_parse_module_path_string (const gchar *mod_path);
171 static guint gtk_rc_parse_im_module_path (GScanner *scanner);
172 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
173 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
175 static guint gtk_rc_parse_stock (GtkRcContext *context,
177 GtkRcStyle *rc_style,
178 GtkIconFactory *factory);
179 static void gtk_rc_clear_hash_node (gpointer key,
182 static void gtk_rc_clear_styles (GtkRcContext *context);
183 static void gtk_rc_append_default_module_path (void);
184 static void gtk_rc_add_initial_default_files (void);
186 static void gtk_rc_style_init (GtkRcStyle *style);
187 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
188 static void gtk_rc_style_finalize (GObject *object);
189 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
191 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
192 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
193 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
194 gconstpointer bsearch_node2);
196 static gpointer parent_class = NULL;
198 static const GScannerConfig gtk_rc_scanner_config =
202 ) /* cset_skip_characters */,
207 ) /* cset_identifier_first */,
212 ) /* cset_identifier_nth */,
213 ( "#\n" ) /* cpair_comment_single */,
215 TRUE /* case_sensitive */,
217 TRUE /* skip_comment_multi */,
218 TRUE /* skip_comment_single */,
219 TRUE /* scan_comment_multi */,
220 TRUE /* scan_identifier */,
221 FALSE /* scan_identifier_1char */,
222 FALSE /* scan_identifier_NULL */,
223 TRUE /* scan_symbols */,
224 TRUE /* scan_binary */,
225 TRUE /* scan_octal */,
226 TRUE /* scan_float */,
228 TRUE /* scan_hex_dollar */,
229 TRUE /* scan_string_sq */,
230 TRUE /* scan_string_dq */,
231 TRUE /* numbers_2_int */,
232 FALSE /* int_2_float */,
233 FALSE /* identifier_2_string */,
234 TRUE /* char_2_token */,
235 TRUE /* symbol_2_token */,
236 FALSE /* scope_0_fallback */,
244 { "include", GTK_RC_TOKEN_INCLUDE },
245 { "NORMAL", GTK_RC_TOKEN_NORMAL },
246 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
247 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
248 { "SELECTED", GTK_RC_TOKEN_SELECTED },
249 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
250 { "fg", GTK_RC_TOKEN_FG },
251 { "bg", GTK_RC_TOKEN_BG },
252 { "text", GTK_RC_TOKEN_TEXT },
253 { "base", GTK_RC_TOKEN_BASE },
254 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
255 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
256 { "font", GTK_RC_TOKEN_FONT },
257 { "fontset", GTK_RC_TOKEN_FONTSET },
258 { "font_name", GTK_RC_TOKEN_FONT_NAME },
259 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
260 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
261 { "style", GTK_RC_TOKEN_STYLE },
262 { "binding", GTK_RC_TOKEN_BINDING },
263 { "bind", GTK_RC_TOKEN_BIND },
264 { "widget", GTK_RC_TOKEN_WIDGET },
265 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
266 { "class", GTK_RC_TOKEN_CLASS },
267 { "lowest", GTK_RC_TOKEN_LOWEST },
268 { "gtk", GTK_RC_TOKEN_GTK },
269 { "application", GTK_RC_TOKEN_APPLICATION },
270 { "theme", GTK_RC_TOKEN_THEME },
271 { "rc", GTK_RC_TOKEN_RC },
272 { "highest", GTK_RC_TOKEN_HIGHEST },
273 { "engine", GTK_RC_TOKEN_ENGINE },
274 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
275 { "stock", GTK_RC_TOKEN_STOCK },
276 { "im_module_path", GTK_RC_TOKEN_IM_MODULE_PATH },
277 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
278 { "LTR", GTK_RC_TOKEN_LTR },
279 { "RTL", GTK_RC_TOKEN_RTL }
282 static GHashTable *realized_style_ht = NULL;
284 static gchar *im_module_path = NULL;
285 static gchar *im_module_file = NULL;
287 #define GTK_RC_MAX_DEFAULT_FILES 128
288 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
290 #define GTK_RC_MAX_MODULE_PATHS 128
291 static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
293 /* A stack of directories for RC files we are parsing currently.
294 * these are implicitely added to the end of PIXMAP_PATHS
296 static GSList *rc_dir_stack = NULL;
298 /* RC file handling */
301 gtk_rc_make_default_dir (const gchar *type)
306 var = g_getenv ("GTK_EXE_PREFIX");
308 path = g_build_filename (var, "lib", "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
310 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
316 * gtk_rc_get_im_module_path:
317 * @returns: a newly-allocated string containing the path in which to
318 * look for IM modules.
320 * Obtains the path in which to look for IM modules. See the documentation
321 * of the <link linkend="im-module-path"><envar>GTK_IM_MODULE_PATH</envar></link>
322 * environment variable for more details.
325 gtk_rc_get_im_module_path (void)
327 const gchar *result = g_getenv ("GTK_IM_MODULE_PATH");
332 result = im_module_path;
334 return gtk_rc_make_default_dir ("immodules");
337 return g_strdup (result);
341 * gtk_rc_get_im_module_file:
342 * @returns: a newly-allocated string containing the name of the file
343 * listing the IM modules to load
345 * Obtains the path to the IM modules file. See the documentation
346 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
347 * environment variable for more details.
350 gtk_rc_get_im_module_file (void)
352 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
357 result = g_strdup (im_module_file);
359 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
366 gtk_rc_get_theme_dir (void)
371 var = g_getenv ("GTK_DATA_PREFIX");
373 path = g_build_filename (var, "share", "themes", NULL);
375 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
381 gtk_rc_get_module_dir (void)
383 return gtk_rc_make_default_dir ("engines");
387 gtk_rc_append_default_module_path (void)
393 for (n = 0; module_path[n]; n++) ;
394 if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
397 var = g_getenv ("GTK_EXE_PREFIX");
399 path = g_build_filename (var, "lib", "gtk-2.0", GTK_VERSION, "engines", NULL);
401 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_VERSION, "engines", NULL);
402 module_path[n++] = path;
404 var = g_get_home_dir ();
407 path = g_build_filename (var, ".gtk-2.0", GTK_VERSION, "engines", NULL);
408 module_path[n++] = path;
410 module_path[n] = NULL;
414 gtk_rc_add_initial_default_files (void)
416 static gint init = FALSE;
425 gtk_rc_default_files[0] = NULL;
428 var = g_getenv ("GTK_RC_FILES");
431 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
435 gtk_rc_add_default_file (files[i]);
442 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
444 gtk_rc_add_default_file (str);
447 var = g_get_home_dir ();
450 str = g_build_filename (var, ".gtkrc-2.0", NULL);
451 gtk_rc_add_default_file (str);
458 * gtk_rc_add_default_file:
459 * @filename: the pathname to the file.
461 * Adds a file to the list of files to be parsed at the
465 gtk_rc_add_default_file (const gchar *filename)
469 gtk_rc_add_initial_default_files ();
471 for (n = 0; gtk_rc_default_files[n]; n++) ;
472 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
475 gtk_rc_default_files[n++] = g_strdup (filename);
476 gtk_rc_default_files[n] = NULL;
480 * gtk_rc_set_default_files:
481 * @filenames: A %NULL-terminated list of filenames.
483 * Sets the list of files that GTK+ will read at the
487 gtk_rc_set_default_files (gchar **filenames)
491 gtk_rc_add_initial_default_files ();
494 while (gtk_rc_default_files[i])
496 g_free (gtk_rc_default_files[i]);
500 gtk_rc_default_files[0] = NULL;
503 while (filenames[i] != NULL)
505 gtk_rc_add_default_file (filenames[i]);
511 * gtk_rc_get_default_files:
513 * Retrieves the current list of RC files that will be parsed
514 * at the end of gtk_init().
516 * Return value: A %NULL-terminated array of filenames. This memory
517 * is owned by GTK+ and must not be freed by the application.
518 * If you want to store this information, you should make a copy.
521 gtk_rc_get_default_files (void)
523 gtk_rc_add_initial_default_files ();
525 return gtk_rc_default_files;
528 /* The following routine is based on _nl_normalize_codeset from
529 * the GNU C library. Contributed by
531 * Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
532 * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
534 * Normalize codeset name. There is no standard for the codeset
535 * names. Normalization allows the user to use any of the common
539 _gtk_normalize_codeset (const gchar *codeset, gint name_len)
547 for (cnt = 0; cnt < name_len; ++cnt)
548 if (isalnum (codeset[cnt]))
552 if (isalpha (codeset[cnt]))
556 retval = g_malloc ((only_digit ? 3 : 0) + len + 1);
560 memcpy (retval, "iso", 4);
566 for (cnt = 0; cnt < name_len; ++cnt)
567 if (isalpha (codeset[cnt]))
568 *wp++ = isupper(codeset[cnt]) ? tolower (codeset[cnt]) : codeset[cnt];
569 else if (isdigit (codeset[cnt]))
570 *wp++ = codeset[cnt];
578 gtk_rc_settings_changed (GtkSettings *settings,
580 GtkRcContext *context)
582 gchar *new_theme_name;
583 gchar *new_key_theme_name;
585 g_object_get (settings,
586 "gtk-theme-name", &new_theme_name,
587 "gtk-key-theme-name", &new_key_theme_name,
590 if ((new_theme_name != context->theme_name &&
591 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
592 (new_key_theme_name != context->key_theme_name &&
593 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
595 gtk_rc_reparse_all_for_settings (settings, TRUE);
598 g_free (new_theme_name);
599 g_free (new_key_theme_name);
602 static GtkRcContext *
603 gtk_rc_context_get (GtkSettings *settings)
605 if (!settings->rc_context)
607 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
609 context->settings = settings;
610 context->rc_style_ht = NULL;
611 context->rc_sets_widget = NULL;
612 context->rc_sets_widget_class = NULL;
613 context->rc_sets_class = NULL;
614 context->rc_files = NULL;
616 g_object_get (settings,
617 "gtk-theme-name", &context->theme_name,
618 "gtk-key-theme-name", &context->key_theme_name,
621 g_signal_connect (settings,
622 "notify::gtk-theme-name",
623 G_CALLBACK (gtk_rc_settings_changed),
625 g_signal_connect (settings,
626 "notify::gtk-key-theme-name",
627 G_CALLBACK (gtk_rc_settings_changed),
630 context->pixmap_path[0] = NULL;
632 context->default_priority = GTK_PATH_PRIO_RC;
635 return settings->rc_context;
639 gtk_rc_parse_named (GtkRcContext *context,
644 const gchar *home_dir;
648 subpath = g_strconcat ("gtk-2.0-", type,
649 G_DIR_SEPARATOR_S "gtkrc",
652 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
654 /* First look in the users home directory
656 home_dir = g_get_home_dir ();
659 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
660 if (!g_file_test (path, G_FILE_TEST_EXISTS))
669 gchar *theme_dir = gtk_rc_get_theme_dir ();
670 path = g_build_filename (theme_dir, name, subpath, NULL);
673 if (!g_file_test (path, G_FILE_TEST_EXISTS))
682 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
690 gtk_rc_parse_default_files (GtkRcContext *context)
692 gchar *locale_suffixes[3];
693 gint n_locale_suffixes = 0;
700 locale = g_win32_getlocale ();
702 locale = setlocale (LC_CTYPE, NULL);
705 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
707 /* Determine locale-specific suffixes for RC files
709 * We normalize the charset into a standard form,
710 * which has all '-' and '_' characters removed,
713 gchar *normalized_locale;
715 p = strchr (locale, '@');
716 length = p ? (p - locale) : strlen (locale);
718 p = strchr (locale, '.');
721 gchar *tmp1 = g_strndup (locale, p - locale + 1);
722 gchar *tmp2 = _gtk_normalize_codeset (p + 1, length - (p - locale + 1));
724 normalized_locale = g_strconcat (tmp1, tmp2, NULL);
728 locale_suffixes[n_locale_suffixes++] = g_strdup (normalized_locale);
732 normalized_locale = g_strndup (locale, length);
734 p = strchr (normalized_locale, '_');
737 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
738 length = p - normalized_locale;
741 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
743 g_free (normalized_locale);
746 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
748 /* Try to find a locale specific RC file corresponding to the
749 * current locale to parse before the default file.
751 for (j = n_locale_suffixes - 1; j >= 0; j--)
753 gchar *name = g_strconcat (gtk_rc_default_files[i],
757 gtk_rc_parse_file (context, name, GTK_PATH_PRIO_RC, FALSE);
760 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
763 for (j = 0; j < n_locale_suffixes; j++)
764 g_free (locale_suffixes[j]);
770 static gboolean initialized = FALSE;
776 module_path[0] = NULL;
777 gtk_rc_append_default_module_path();
779 gtk_rc_add_initial_default_files ();
782 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
786 gtk_rc_parse_string (const gchar *rc_string)
789 /* This is wrong; once we have meaingful RC context, we need to parse the
790 * string in all contexts, and in fact, in future contexts as well.
792 GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
794 g_return_if_fail (rc_string != NULL);
796 rc_file = g_new (GtkRcFile, 1);
797 rc_file->is_string = TRUE;
798 rc_file->name = g_strdup (rc_string);
799 rc_file->canonical_name = NULL;
801 rc_file->reload = TRUE;
803 context->rc_files = g_slist_append (context->rc_files, rc_file);
805 gtk_rc_parse_any (context, "-", -1, rc_string);
809 gtk_rc_parse_file (GtkRcContext *context,
810 const gchar *filename,
814 GtkRcFile *rc_file = NULL;
819 g_return_if_fail (filename != NULL);
821 saved_priority = context->default_priority;
822 context->default_priority = priority;
824 tmp_list = context->rc_files;
827 rc_file = tmp_list->data;
828 if (!strcmp (rc_file->name, filename))
831 tmp_list = tmp_list->next;
836 rc_file = g_new (GtkRcFile, 1);
837 rc_file->is_string = FALSE;
838 rc_file->name = g_strdup (filename);
839 rc_file->canonical_name = NULL;
841 rc_file->reload = reload;
843 context->rc_files = g_slist_append (context->rc_files, rc_file);
846 if (!rc_file->canonical_name)
848 /* Get the absolute pathname */
850 if (g_path_is_absolute (rc_file->name))
851 rc_file->canonical_name = rc_file->name;
856 cwd = g_get_current_dir ();
857 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
862 if (!lstat (rc_file->canonical_name, &statbuf))
867 rc_file->mtime = statbuf.st_mtime;
869 fd = open (rc_file->canonical_name, O_RDONLY);
873 /* Temporarily push directory name for this file on
874 * a stack of directory names while parsing it
877 g_slist_prepend (rc_dir_stack,
878 g_path_get_dirname (rc_file->canonical_name));
879 gtk_rc_parse_any (context, filename, fd, NULL);
881 tmp_list = rc_dir_stack;
882 rc_dir_stack = rc_dir_stack->next;
884 g_free (tmp_list->data);
885 g_slist_free_1 (tmp_list);
891 context->default_priority = saved_priority;
895 gtk_rc_parse (const gchar *filename)
897 g_return_if_fail (filename != NULL);
899 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
900 filename, GTK_PATH_PRIO_RC, TRUE); /* FIXME */
903 /* Handling of RC styles */
906 gtk_rc_style_get_type (void)
908 static GType object_type = 0;
912 static const GTypeInfo object_info =
914 sizeof (GtkRcStyleClass),
915 (GBaseInitFunc) NULL,
916 (GBaseFinalizeFunc) NULL,
917 (GClassInitFunc) gtk_rc_style_class_init,
918 NULL, /* class_finalize */
919 NULL, /* class_data */
922 (GInstanceInitFunc) gtk_rc_style_init,
925 object_type = g_type_register_static (G_TYPE_OBJECT,
934 gtk_rc_style_init (GtkRcStyle *style)
939 style->font_desc = NULL;
941 for (i = 0; i < 5; i++)
943 static const GdkColor init_color = { 0, 0, 0, 0, };
945 style->bg_pixmap_name[i] = NULL;
946 style->color_flags[i] = 0;
947 style->fg[i] = init_color;
948 style->bg[i] = init_color;
949 style->text[i] = init_color;
950 style->base[i] = init_color;
952 style->xthickness = -1;
953 style->ythickness = -1;
954 style->rc_properties = NULL;
956 style->rc_style_lists = NULL;
957 style->icon_factories = NULL;
961 gtk_rc_style_class_init (GtkRcStyleClass *klass)
963 GObjectClass *object_class = G_OBJECT_CLASS (klass);
965 parent_class = g_type_class_peek_parent (klass);
967 object_class->finalize = gtk_rc_style_finalize;
970 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
971 klass->merge = gtk_rc_style_real_merge;
972 klass->create_style = gtk_rc_style_real_create_style;
976 gtk_rc_style_finalize (GObject *object)
978 GSList *tmp_list1, *tmp_list2;
979 GtkRcStyle *rc_style;
982 rc_style = GTK_RC_STYLE (object);
985 g_free (rc_style->name);
986 if (rc_style->font_desc)
987 pango_font_description_free (rc_style->font_desc);
989 for (i = 0; i < 5; i++)
990 if (rc_style->bg_pixmap_name[i])
991 g_free (rc_style->bg_pixmap_name[i]);
993 /* Now remove all references to this rc_style from
996 tmp_list1 = rc_style->rc_style_lists;
999 GSList *rc_styles = tmp_list1->data;
1000 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1001 gtk_style_unref (style);
1003 /* Remove the list of styles from the other rc_styles
1006 tmp_list2 = rc_styles;
1009 GtkRcStyle *other_style = tmp_list2->data;
1011 if (other_style != rc_style)
1012 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1014 tmp_list2 = tmp_list2->next;
1017 /* And from the hash table itself
1019 g_hash_table_remove (realized_style_ht, rc_styles);
1020 g_slist_free (rc_styles);
1022 tmp_list1 = tmp_list1->next;
1024 g_slist_free (rc_style->rc_style_lists);
1026 if (rc_style->rc_properties)
1030 for (i = 0; i < rc_style->rc_properties->len; i++)
1032 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1034 g_free (node->origin);
1035 g_value_unset (&node->value);
1037 g_array_free (rc_style->rc_properties, TRUE);
1038 rc_style->rc_properties = NULL;
1041 tmp_list1 = rc_style->icon_factories;
1044 g_object_unref (G_OBJECT (tmp_list1->data));
1046 tmp_list1 = tmp_list1->next;
1048 g_slist_free (rc_style->icon_factories);
1050 G_OBJECT_CLASS (parent_class)->finalize (object);
1054 gtk_rc_style_new (void)
1058 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1064 * gtk_rc_style_copy:
1065 * @orig: the style to copy
1067 * Makes a copy of the specified #GtkRcStyle. This function
1068 * will correctly copy an RC style that is a member of a class
1069 * derived from #GtkRcStyle.
1071 * Return value: the resulting #GtkRcStyle
1074 gtk_rc_style_copy (GtkRcStyle *orig)
1078 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1080 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1081 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1087 gtk_rc_style_ref (GtkRcStyle *rc_style)
1089 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1091 g_object_ref (G_OBJECT (rc_style));
1095 gtk_rc_style_unref (GtkRcStyle *rc_style)
1097 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1099 g_object_unref (G_OBJECT (rc_style));
1103 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1105 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1109 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1110 gconstpointer bsearch_node2)
1112 const GtkRcProperty *prop1 = bsearch_node1;
1113 const GtkRcProperty *prop2 = bsearch_node2;
1115 if (prop1->type_name == prop2->type_name)
1116 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1118 return prop1->type_name < prop2->type_name ? -1 : 1;
1122 insert_rc_property (GtkRcStyle *style,
1123 GtkRcProperty *property,
1127 GtkRcProperty *new_property = NULL;
1128 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1130 key.type_name = property->type_name;
1131 key.property_name = property->property_name;
1133 if (!style->rc_properties)
1134 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1137 while (i < style->rc_properties->len)
1139 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1145 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1147 g_free (new_property->origin);
1148 g_value_unset (&new_property->value);
1150 *new_property = key;
1164 g_array_insert_val (style->rc_properties, i, key);
1165 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1168 new_property->origin = g_strdup (property->origin);
1169 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1170 g_value_copy (&property->value, &new_property->value);
1174 gtk_rc_style_real_merge (GtkRcStyle *dest,
1179 for (i = 0; i < 5; i++)
1181 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1182 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1184 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1185 src->color_flags[i] & GTK_RC_FG)
1187 dest->fg[i] = src->fg[i];
1188 dest->color_flags[i] |= GTK_RC_FG;
1190 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1191 src->color_flags[i] & GTK_RC_BG)
1193 dest->bg[i] = src->bg[i];
1194 dest->color_flags[i] |= GTK_RC_BG;
1196 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1197 src->color_flags[i] & GTK_RC_TEXT)
1199 dest->text[i] = src->text[i];
1200 dest->color_flags[i] |= GTK_RC_TEXT;
1202 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1203 src->color_flags[i] & GTK_RC_BASE)
1205 dest->base[i] = src->base[i];
1206 dest->color_flags[i] |= GTK_RC_BASE;
1210 if (dest->xthickness < 0 && src->xthickness >= 0)
1211 dest->xthickness = src->xthickness;
1212 if (dest->ythickness < 0 && src->ythickness >= 0)
1213 dest->ythickness = src->ythickness;
1217 if (!dest->font_desc)
1218 dest->font_desc = pango_font_description_copy (src->font_desc);
1220 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1223 if (src->rc_properties)
1227 for (i = 0; i < src->rc_properties->len; i++)
1228 insert_rc_property (dest,
1229 &g_array_index (src->rc_properties, GtkRcProperty, i),
1235 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1237 return gtk_style_new ();
1241 gtk_rc_clear_hash_node (gpointer key,
1245 gtk_rc_style_unref (data);
1249 gtk_rc_free_rc_sets (GSList *slist)
1255 rc_set = slist->data;
1256 g_pattern_spec_free (rc_set->pspec);
1259 slist = slist->next;
1264 gtk_rc_clear_styles (GtkRcContext *context)
1266 /* Clear out all old rc_styles */
1268 if (context->rc_style_ht)
1270 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1271 g_hash_table_destroy (context->rc_style_ht);
1272 context->rc_style_ht = NULL;
1275 gtk_rc_free_rc_sets (context->rc_sets_widget);
1276 g_slist_free (context->rc_sets_widget);
1277 context->rc_sets_widget = NULL;
1279 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1280 g_slist_free (context->rc_sets_widget_class);
1281 context->rc_sets_widget_class = NULL;
1283 gtk_rc_free_rc_sets (context->rc_sets_class);
1284 g_slist_free (context->rc_sets_class);
1285 context->rc_sets_class = NULL;
1288 /* Reset all our widgets. Also, we have to invalidate cached icons in
1289 * icon sets so they get re-rendered.
1292 gtk_rc_reset_widgets (GtkRcContext *context)
1294 GList *list, *toplevels;
1296 _gtk_icon_set_invalidate_caches ();
1298 toplevels = gtk_window_list_toplevels ();
1299 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1301 for (list = toplevels; list; list = list->next)
1303 gtk_widget_reset_rc_styles (list->data);
1304 gtk_widget_unref (list->data);
1306 g_list_free (toplevels);
1310 * gtk_rc_reparse_all_for_settings:
1311 * @settings: a #GtkSettings
1312 * @force_load: load whether or not anything changed
1314 * If the modification time on any previously read file
1315 * for the given #GtkSettings has changed, discard all style information
1316 * and then reread all previously read RC files.
1318 * Return value: %TRUE if the files were reread.
1321 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1322 gboolean force_load)
1324 gboolean mtime_modified = FALSE;
1327 GtkRcContext *context;
1329 struct stat statbuf;
1331 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1333 context = gtk_rc_context_get (settings);
1337 /* Check through and see if any of the RC's have had their
1338 * mtime modified. If so, reparse everything.
1340 tmp_list = context->rc_files;
1343 rc_file = tmp_list->data;
1345 if (!rc_file->is_string)
1347 if (!lstat (rc_file->name, &statbuf) &&
1348 (statbuf.st_mtime > rc_file->mtime))
1350 mtime_modified = TRUE;
1355 tmp_list = tmp_list->next;
1359 if (force_load || mtime_modified)
1363 gtk_rc_clear_styles (context);
1364 g_object_freeze_notify (G_OBJECT (context->settings));
1366 old_files = context->rc_files;
1367 context->rc_files = NULL;
1369 gtk_rc_parse_default_files (context);
1371 tmp_list = old_files;
1374 rc_file = tmp_list->data;
1375 if (rc_file->reload)
1377 if (rc_file->is_string)
1378 gtk_rc_parse_string (rc_file->name);
1380 gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
1383 if (rc_file->canonical_name != rc_file->name)
1384 g_free (rc_file->canonical_name);
1385 g_free (rc_file->name);
1388 tmp_list = tmp_list->next;
1391 g_slist_free (old_files);;
1393 g_free (context->theme_name);
1394 g_free (context->key_theme_name);
1395 g_object_get (context->settings,
1396 "gtk-theme-name", &context->theme_name,
1397 "gtk-key-theme-name", &context->key_theme_name,
1400 if (context->theme_name && context->theme_name[0])
1401 gtk_rc_parse_named (context, context->theme_name, NULL);
1402 if (context->key_theme_name && context->key_theme_name[0])
1403 gtk_rc_parse_named (context, context->key_theme_name, "key");
1405 g_object_thaw_notify (G_OBJECT (context->settings));
1407 gtk_rc_reset_widgets (context);
1410 return mtime_modified;
1414 * gtk_rc_reparse_all:
1416 * If the modification time on any previously read file for the
1417 * default #GtkSettings has changed, discard all style information
1418 * and then reread all previously read RC files.
1420 * Return value: %TRUE if the files were reread.
1423 gtk_rc_reparse_all (void)
1425 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1429 gtk_rc_styles_match (GSList *rc_styles,
1433 const gchar *path_reversed)
1440 rc_set = sets->data;
1443 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1444 rc_styles = g_slist_append (rc_styles, rc_set);
1451 rc_set_compare (gconstpointer a, gconstpointer b)
1453 const GtkRcSet *set_a = a;
1454 const GtkRcSet *set_b = b;
1456 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1460 sort_and_dereference_sets (GSList *styles)
1464 /* At this point, the list of sets is ordered by:
1466 * a) 'widget' patterns are earlier than 'widget_class' patterns
1467 * which are ealier than 'class' patterns.
1468 * a) For two matches for class patterns, a match to a child type
1469 * is before a match to a parent type
1470 * c) a match later in the RC file (or in a later RC file) is before a
1471 * match earlier in the RC file.
1473 * With a) taking precedence over b) which takes precendence over c).
1475 * Now sort by priority, which has the highest precendence for sort order
1477 styles = g_slist_sort (styles, rc_set_compare);
1479 /* Make styles->data = styles->data->rc_style
1484 GtkRcSet *set = tmp_list->data;
1485 tmp_list->data = set->rc_style;
1486 tmp_list = tmp_list->next;
1494 * @widget: a #GtkWidget
1496 * Finds all matching RC styles for a given widget,
1497 * composites them together, and then creates a
1498 * #GtkStyle representing the composite appearance.
1499 * (GTK+ actually keeps a cache of previously
1500 * created styles, so a new style may not be
1503 * Returns: the resulting style. No refcount is added
1504 * to the returned style, so if you want to save this
1505 * style around, you should add a reference yourself.
1508 gtk_rc_get_style (GtkWidget *widget)
1510 GtkRcStyle *widget_rc_style;
1511 GSList *rc_styles = NULL;
1512 GtkRcContext *context;
1514 static guint rc_style_key_id = 0;
1516 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1518 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1520 /* We allow the specification of a single rc style to be bound
1521 * tightly to a widget, for application modifications
1523 if (!rc_style_key_id)
1524 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1526 if (context->rc_sets_widget)
1528 gchar *path, *path_reversed;
1531 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1532 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1534 g_free (path_reversed);
1537 if (context->rc_sets_widget_class)
1539 gchar *path, *path_reversed;
1542 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1543 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1545 g_free (path_reversed);
1548 if (context->rc_sets_class)
1552 type = GTK_OBJECT_TYPE (widget);
1556 gchar *path_reversed;
1559 path = gtk_type_name (type);
1560 path_length = strlen (path);
1561 path_reversed = g_strdup (path);
1562 g_strreverse (path_reversed);
1564 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1565 g_free (path_reversed);
1567 type = gtk_type_parent (type);
1571 rc_styles = sort_and_dereference_sets (rc_styles);
1573 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1576 if (widget_rc_style)
1577 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1580 return gtk_rc_init_style (rc_styles);
1586 * gtk_rc_get_style_by_paths:
1587 * @settings: a #GtkSettings object
1588 * @widget_path: the widget path to use when looking up the style, or %NULL
1589 * @class_path: the class path to use when looking up the style, or %NULL
1590 * @type: a type that will be used along with parent types of this type
1591 * when matching against class styles, or #G_TYPE_NONE
1593 * Creates up a #GtkStyle from styles defined in a RC file by providing
1594 * the raw components used in matching. This function may be useful
1595 * when creating pseudo-widgets that should be themed like widgets but
1596 * don't actually have corresponding GTK+ widgets. An example of this
1597 * would be items inside a GNOME canvas widget.
1599 * The action of gtk_rc_get_style() is similar to:
1600 * <informalexample><programlisting>
1601 * <!> gtk_widget_path (widget, NULL, &path, NULL);
1602 * <!> gtk_widget_class_path (widget, NULL, &class_path, NULL);
1603 * <!> gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1604 * <!> G_OBJECT_TYPE (widget));
1605 * </programlisting></informalexample>
1607 * Return value: A style created by matching with the supplied paths,
1608 * or %NULL if nothing matching was specified and the default style should
1609 * be used. The returned value is owned by GTK+ as part of an internal cache,
1610 * so you must call g_object_ref() on the returned value if you want to
1611 * keep a reference to it.
1614 gtk_rc_get_style_by_paths (GtkSettings *settings,
1615 const char *widget_path,
1616 const char *class_path,
1619 /* We duplicate the code from above to avoid slowing down the above
1620 * by generating paths when we don't need them. I don't know if
1621 * this is really worth it.
1623 GSList *rc_styles = NULL;
1624 GtkRcContext *context;
1626 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1628 context = gtk_rc_context_get (settings);
1630 if (context->rc_sets_widget)
1632 gchar *path_reversed;
1635 path_length = strlen (widget_path);
1636 path_reversed = g_strdup (widget_path);
1637 g_strreverse (path_reversed);
1639 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1640 g_free (path_reversed);
1643 if (context->rc_sets_widget_class)
1645 gchar *path_reversed;
1648 path_length = strlen (class_path);
1649 path_reversed = g_strdup (class_path);
1650 g_strreverse (path_reversed);
1652 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1653 g_free (path_reversed);
1656 if (type != G_TYPE_NONE && context->rc_sets_class)
1661 gchar *path_reversed;
1664 path = g_type_name (type);
1665 path_length = strlen (path);
1666 path_reversed = g_strdup (path);
1667 g_strreverse (path_reversed);
1669 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1670 g_free (path_reversed);
1672 type = g_type_parent (type);
1676 rc_styles = sort_and_dereference_sets (rc_styles);
1679 return gtk_rc_init_style (rc_styles);
1685 gtk_rc_add_rc_sets (GSList *slist,
1686 GtkRcStyle *rc_style,
1687 const gchar *pattern)
1689 GtkRcStyle *new_style;
1693 new_style = gtk_rc_style_new ();
1694 *new_style = *rc_style;
1695 new_style->name = g_strdup (rc_style->name);
1696 if (rc_style->font_desc)
1697 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1699 for (i = 0; i < 5; i++)
1700 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1702 rc_set = g_new (GtkRcSet, 1);
1703 rc_set->pspec = g_pattern_spec_new (pattern);
1704 rc_set->rc_style = rc_style;
1706 return g_slist_prepend (slist, rc_set);
1710 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1711 const gchar *pattern)
1713 GtkRcContext *context;
1715 g_return_if_fail (rc_style != NULL);
1716 g_return_if_fail (pattern != NULL);
1718 context = gtk_rc_context_get (gtk_settings_get_default ());
1720 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1724 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1725 const gchar *pattern)
1727 GtkRcContext *context;
1729 g_return_if_fail (rc_style != NULL);
1730 g_return_if_fail (pattern != NULL);
1732 context = gtk_rc_context_get (gtk_settings_get_default ());
1734 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1738 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1739 const gchar *pattern)
1741 GtkRcContext *context;
1743 g_return_if_fail (rc_style != NULL);
1744 g_return_if_fail (pattern != NULL);
1746 context = gtk_rc_context_get (gtk_settings_get_default ());
1748 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1752 gtk_rc_scanner_new (void)
1754 return g_scanner_new (>k_rc_scanner_config);
1758 gtk_rc_parse_any (GtkRcContext *context,
1759 const gchar *input_name,
1761 const gchar *input_string)
1767 scanner = gtk_rc_scanner_new ();
1771 g_assert (input_string == NULL);
1773 g_scanner_input_file (scanner, input_fd);
1777 g_assert (input_string != NULL);
1779 g_scanner_input_text (scanner, input_string, strlen (input_string));
1781 scanner->input_name = input_name;
1783 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1784 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1789 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1793 guint expected_token;
1795 expected_token = gtk_rc_parse_statement (context, scanner);
1797 if (expected_token != G_TOKEN_NONE)
1804 if (scanner->scope_id == 0)
1806 /* if we are in scope 0, we know the symbol names
1807 * that are associated with certain token values.
1808 * so we look them up to make the error messages
1811 if (expected_token > GTK_RC_TOKEN_INVALID &&
1812 expected_token < GTK_RC_TOKEN_LAST)
1814 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1815 if (symbols[i].token == expected_token)
1816 msg = symbols[i].name;
1818 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1820 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1821 scanner->token < GTK_RC_TOKEN_LAST)
1823 symbol_name = "???";
1824 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1825 if (symbols[i].token == scanner->token)
1826 symbol_name = symbols[i].name;
1829 g_scanner_unexp_token (scanner,
1842 g_scanner_destroy (scanner);
1846 gtk_rc_styles_hash (const GSList *rc_styles)
1853 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1854 rc_styles = rc_styles->next;
1861 gtk_rc_styles_equal (const GSList *a,
1866 if (a->data != b->data)
1876 gtk_rc_style_hash (const gchar *name)
1882 result += (result << 3) + *name++;
1888 gtk_rc_style_equal (const gchar *a,
1891 return (strcmp (a, b) == 0);
1895 gtk_rc_style_find (GtkRcContext *context,
1898 if (context->rc_style_ht)
1899 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1905 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1909 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1911 style->rc_style = rc_style;
1913 gtk_rc_style_ref (rc_style);
1915 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1920 /* Reuses or frees rc_styles */
1922 gtk_rc_init_style (GSList *rc_styles)
1924 GtkStyle *style = NULL;
1927 g_return_val_if_fail (rc_styles != NULL, NULL);
1929 if (!realized_style_ht)
1930 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1931 (GEqualFunc) gtk_rc_styles_equal);
1933 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1937 GtkRcStyle *base_style = NULL;
1938 GtkRcStyle *proto_style;
1939 GtkRcStyleClass *proto_style_class;
1941 GType rc_style_type = GTK_TYPE_RC_STYLE;
1943 /* Find the the first style where the RC file specified engine "" {}
1944 * or the first derived style and use that to create the
1945 * merged style. If we only have raw GtkRcStyles, use the first
1946 * style to create the merged style.
1948 base_style = rc_styles->data;
1949 tmp_styles = rc_styles;
1952 GtkRcStyle *rc_style = tmp_styles->data;
1954 if (rc_style->engine_specified ||
1955 G_OBJECT_TYPE (rc_style) != rc_style_type)
1957 base_style = rc_style;
1961 tmp_styles = tmp_styles->next;
1964 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1965 proto_style = proto_style_class->create_rc_style (base_style);
1967 tmp_styles = rc_styles;
1970 GtkRcStyle *rc_style = tmp_styles->data;
1973 proto_style_class->merge (proto_style, rc_style);
1975 /* Point from each rc_style to the list of styles */
1976 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1977 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1979 factories = g_slist_copy (rc_style->icon_factories);
1985 while (iter != NULL)
1987 g_object_ref (G_OBJECT (iter->data));
1988 iter = g_slist_next (iter);
1991 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1996 tmp_styles = tmp_styles->next;
1999 for (i = 0; i < 5; i++)
2000 if (proto_style->bg_pixmap_name[i] &&
2001 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2003 g_free (proto_style->bg_pixmap_name[i]);
2004 proto_style->bg_pixmap_name[i] = NULL;
2007 style = gtk_rc_style_to_style (proto_style);
2008 gtk_rc_style_unref (proto_style);
2010 g_hash_table_insert (realized_style_ht, rc_styles, style);
2013 g_slist_free (rc_styles);
2018 /*********************
2019 * Parsing functions *
2020 *********************/
2023 rc_parse_token_or_compound (GScanner *scanner,
2025 GTokenType delimiter)
2027 guint token = g_scanner_get_next_token (scanner);
2029 /* we either scan a single token (skipping comments)
2030 * or a compund statement.
2031 * compunds are enclosed in (), [] or {} braces, we read
2032 * them in via deep recursion.
2039 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2042 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2044 case G_TOKEN_STRING:
2045 string = g_strescape (scanner->value.v_string, NULL);
2046 g_string_append (gstring, " \"");
2047 g_string_append (gstring, string);
2048 g_string_append_c (gstring, '"');
2051 case G_TOKEN_IDENTIFIER:
2052 g_string_append_c (gstring, ' ');
2053 g_string_append (gstring, scanner->value.v_identifier);
2055 case G_TOKEN_COMMENT_SINGLE:
2056 case G_TOKEN_COMMENT_MULTI:
2057 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2058 case G_TOKEN_LEFT_PAREN:
2059 g_string_append_c (gstring, ' ');
2060 g_string_append_c (gstring, token);
2061 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2062 if (token != G_TOKEN_NONE)
2065 case G_TOKEN_LEFT_CURLY:
2066 g_string_append_c (gstring, ' ');
2067 g_string_append_c (gstring, token);
2068 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2069 if (token != G_TOKEN_NONE)
2072 case G_TOKEN_LEFT_BRACE:
2073 g_string_append_c (gstring, ' ');
2074 g_string_append_c (gstring, token);
2075 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2076 if (token != G_TOKEN_NONE)
2080 if (token >= 256 || token < 1)
2081 return delimiter ? delimiter : G_TOKEN_STRING;
2082 g_string_append_c (gstring, ' ');
2083 g_string_append_c (gstring, token);
2084 if (token == delimiter)
2085 return G_TOKEN_NONE;
2089 return G_TOKEN_NONE;
2091 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2095 gtk_rc_parse_assignment (GScanner *scanner,
2096 GtkRcProperty *prop)
2098 gboolean scan_identifier = scanner->config->scan_identifier;
2099 gboolean scan_symbols = scanner->config->scan_symbols;
2100 gboolean identifier_2_string = scanner->config->identifier_2_string;
2101 gboolean char_2_token = scanner->config->char_2_token;
2102 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2103 gboolean numbers_2_int = scanner->config->numbers_2_int;
2104 gboolean negate = FALSE;
2107 /* check that this is an assignment */
2108 if (g_scanner_get_next_token (scanner) != '=')
2111 /* adjust scanner mode */
2112 scanner->config->scan_identifier = TRUE;
2113 scanner->config->scan_symbols = FALSE;
2114 scanner->config->identifier_2_string = FALSE;
2115 scanner->config->char_2_token = TRUE;
2116 scanner->config->scan_identifier_NULL = FALSE;
2117 scanner->config->numbers_2_int = TRUE;
2119 /* record location */
2120 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2122 /* parse optional sign */
2123 if (g_scanner_peek_next_token (scanner) == '-')
2125 g_scanner_get_next_token (scanner); /* eat sign */
2129 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2130 token = g_scanner_peek_next_token (scanner);
2134 g_scanner_get_next_token (scanner);
2135 g_value_init (&prop->value, G_TYPE_LONG);
2136 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2137 token = G_TOKEN_NONE;
2140 g_scanner_get_next_token (scanner);
2141 g_value_init (&prop->value, G_TYPE_DOUBLE);
2142 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2143 token = G_TOKEN_NONE;
2145 case G_TOKEN_STRING:
2146 g_scanner_get_next_token (scanner);
2148 token = G_TOKEN_INT;
2151 g_value_init (&prop->value, G_TYPE_STRING);
2152 g_value_set_string (&prop->value, scanner->value.v_string);
2153 token = G_TOKEN_NONE;
2156 case G_TOKEN_IDENTIFIER:
2157 case G_TOKEN_LEFT_PAREN:
2158 case G_TOKEN_LEFT_CURLY:
2159 case G_TOKEN_LEFT_BRACE:
2162 GString *gstring = g_string_new ("");
2164 token = rc_parse_token_or_compound (scanner, gstring, 0);
2165 if (token == G_TOKEN_NONE)
2167 g_string_append_c (gstring, ' ');
2168 g_value_init (&prop->value, G_TYPE_GSTRING);
2169 g_value_set_static_boxed (&prop->value, gstring);
2172 g_string_free (gstring, TRUE);
2177 g_scanner_get_next_token (scanner);
2178 token = G_TOKEN_INT;
2182 /* restore scanner mode */
2183 scanner->config->scan_identifier = scan_identifier;
2184 scanner->config->scan_symbols = scan_symbols;
2185 scanner->config->identifier_2_string = identifier_2_string;
2186 scanner->config->char_2_token = char_2_token;
2187 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2188 scanner->config->numbers_2_int = numbers_2_int;
2194 is_c_identifier (const gchar *string)
2197 gboolean is_varname;
2199 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2200 for (p = string + 1; *p && is_varname; p++)
2201 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2207 parse_include_file (GtkRcContext *context,
2209 const gchar *filename)
2211 char *to_parse = NULL;
2213 if (g_path_is_absolute (filename))
2215 /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
2216 * don't print an error in this case.
2218 to_parse = g_strdup (filename);
2222 /* if a relative path, we look relative to all the RC files in the
2223 * include stack. We require the file to be found in this case
2224 * so we can give meaningful error messages, and because on reparsing
2225 * non-absolute paths don't make sense.
2227 GSList *tmp_list = rc_dir_stack;
2230 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2232 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2240 tmp_list = tmp_list->next;
2246 gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
2251 g_scanner_warn (scanner,
2252 _("Unable to find include file: \"%s\""),
2259 gtk_rc_parse_statement (GtkRcContext *context,
2264 token = g_scanner_peek_next_token (scanner);
2267 case GTK_RC_TOKEN_INCLUDE:
2268 token = g_scanner_get_next_token (scanner);
2269 if (token != GTK_RC_TOKEN_INCLUDE)
2270 return GTK_RC_TOKEN_INCLUDE;
2271 token = g_scanner_get_next_token (scanner);
2272 if (token != G_TOKEN_STRING)
2273 return G_TOKEN_STRING;
2274 parse_include_file (context, scanner, scanner->value.v_string);
2275 return G_TOKEN_NONE;
2277 case GTK_RC_TOKEN_STYLE:
2278 return gtk_rc_parse_style (context, scanner);
2280 case GTK_RC_TOKEN_BINDING:
2281 return gtk_binding_parse_binding (scanner);
2283 case GTK_RC_TOKEN_PIXMAP_PATH:
2284 return gtk_rc_parse_pixmap_path (context, scanner);
2286 case GTK_RC_TOKEN_WIDGET:
2287 return gtk_rc_parse_path_pattern (context, scanner);
2289 case GTK_RC_TOKEN_WIDGET_CLASS:
2290 return gtk_rc_parse_path_pattern (context, scanner);
2292 case GTK_RC_TOKEN_CLASS:
2293 return gtk_rc_parse_path_pattern (context, scanner);
2295 case GTK_RC_TOKEN_MODULE_PATH:
2296 return gtk_rc_parse_module_path (scanner);
2298 case GTK_RC_TOKEN_IM_MODULE_PATH:
2299 return gtk_rc_parse_im_module_path (scanner);
2301 case GTK_RC_TOKEN_IM_MODULE_FILE:
2302 return gtk_rc_parse_im_module_file (scanner);
2304 case G_TOKEN_IDENTIFIER:
2305 if (is_c_identifier (scanner->next_value.v_identifier))
2307 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2310 g_scanner_get_next_token (scanner); /* eat identifier */
2311 name = g_strdup (scanner->value.v_identifier);
2313 token = gtk_rc_parse_assignment (scanner, &prop);
2314 if (token == G_TOKEN_NONE)
2316 GtkSettingsValue svalue;
2318 svalue.origin = prop.origin;
2319 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2320 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2321 gtk_settings_set_property_value (context->settings,
2325 g_free (prop.origin);
2326 if (G_VALUE_TYPE (&prop.value))
2327 g_value_unset (&prop.value);
2334 g_scanner_get_next_token (scanner);
2335 return G_TOKEN_IDENTIFIER;
2338 g_scanner_get_next_token (scanner);
2339 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2344 fixup_rc_set (GSList *list,
2350 GtkRcSet *set = list->data;
2351 if (set->rc_style == orig)
2352 set->rc_style = new;
2358 fixup_rc_sets (GtkRcContext *context,
2362 fixup_rc_set (context->rc_sets_widget, orig, new);
2363 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2364 fixup_rc_set (context->rc_sets_class, orig, new);
2368 gtk_rc_parse_style (GtkRcContext *context,
2371 GtkRcStyle *rc_style;
2372 GtkRcStyle *orig_style;
2373 GtkRcStyle *parent_style;
2376 GtkIconFactory *our_factory = NULL;
2378 token = g_scanner_get_next_token (scanner);
2379 if (token != GTK_RC_TOKEN_STYLE)
2380 return GTK_RC_TOKEN_STYLE;
2382 token = g_scanner_get_next_token (scanner);
2383 if (token != G_TOKEN_STRING)
2384 return G_TOKEN_STRING;
2386 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2388 orig_style = g_object_ref (rc_style);
2392 /* If there's a list, its first member is always the factory belonging
2395 if (rc_style && rc_style->icon_factories)
2396 our_factory = rc_style->icon_factories->data;
2400 rc_style = gtk_rc_style_new ();
2401 rc_style->name = g_strdup (scanner->value.v_string);
2403 for (i = 0; i < 5; i++)
2404 rc_style->bg_pixmap_name[i] = NULL;
2406 for (i = 0; i < 5; i++)
2407 rc_style->color_flags[i] = 0;
2410 token = g_scanner_peek_next_token (scanner);
2411 if (token == G_TOKEN_EQUAL_SIGN)
2413 token = g_scanner_get_next_token (scanner);
2415 token = g_scanner_get_next_token (scanner);
2416 if (token != G_TOKEN_STRING)
2418 token = G_TOKEN_STRING;
2422 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2427 for (i = 0; i < 5; i++)
2429 rc_style->color_flags[i] = parent_style->color_flags[i];
2430 rc_style->fg[i] = parent_style->fg[i];
2431 rc_style->bg[i] = parent_style->bg[i];
2432 rc_style->text[i] = parent_style->text[i];
2433 rc_style->base[i] = parent_style->base[i];
2436 rc_style->xthickness = parent_style->xthickness;
2437 rc_style->ythickness = parent_style->ythickness;
2439 if (parent_style->font_desc)
2441 if (rc_style->font_desc)
2442 pango_font_description_free (rc_style->font_desc);
2443 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2446 if (parent_style->rc_properties)
2450 for (i = 0; i < parent_style->rc_properties->len; i++)
2451 insert_rc_property (rc_style,
2452 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2456 for (i = 0; i < 5; i++)
2458 if (rc_style->bg_pixmap_name[i])
2459 g_free (rc_style->bg_pixmap_name[i]);
2460 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2463 /* Append parent's factories, adding a ref to them */
2464 if (parent_style->icon_factories != NULL)
2466 /* Add a factory for ourselves if we have none,
2467 * in case we end up defining more stock icons.
2468 * I see no real way around this; we need to maintain
2469 * the invariant that the first factory in the list
2470 * is always our_factory, the one belonging to us,
2471 * and if we put parent factories in the list we can't
2472 * do that if the style is reopened.
2474 if (our_factory == NULL)
2476 our_factory = gtk_icon_factory_new ();
2477 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2481 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2482 g_slist_copy (parent_style->icon_factories));
2484 factories = parent_style->icon_factories;
2485 while (factories != NULL)
2487 g_object_ref (G_OBJECT (factories->data));
2488 factories = factories->next;
2494 token = g_scanner_get_next_token (scanner);
2495 if (token != G_TOKEN_LEFT_CURLY)
2497 token = G_TOKEN_LEFT_CURLY;
2501 token = g_scanner_peek_next_token (scanner);
2502 while (token != G_TOKEN_RIGHT_CURLY)
2506 case GTK_RC_TOKEN_BG:
2507 token = gtk_rc_parse_bg (scanner, rc_style);
2509 case GTK_RC_TOKEN_FG:
2510 token = gtk_rc_parse_fg (scanner, rc_style);
2512 case GTK_RC_TOKEN_TEXT:
2513 token = gtk_rc_parse_text (scanner, rc_style);
2515 case GTK_RC_TOKEN_BASE:
2516 token = gtk_rc_parse_base (scanner, rc_style);
2518 case GTK_RC_TOKEN_XTHICKNESS:
2519 token = gtk_rc_parse_xthickness (scanner, rc_style);
2521 case GTK_RC_TOKEN_YTHICKNESS:
2522 token = gtk_rc_parse_ythickness (scanner, rc_style);
2524 case GTK_RC_TOKEN_BG_PIXMAP:
2525 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2527 case GTK_RC_TOKEN_FONT:
2528 token = gtk_rc_parse_font (scanner, rc_style);
2530 case GTK_RC_TOKEN_FONTSET:
2531 token = gtk_rc_parse_fontset (scanner, rc_style);
2533 case GTK_RC_TOKEN_FONT_NAME:
2534 token = gtk_rc_parse_font_name (scanner, rc_style);
2536 case GTK_RC_TOKEN_ENGINE:
2537 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2539 case GTK_RC_TOKEN_STOCK:
2540 if (our_factory == NULL)
2542 our_factory = gtk_icon_factory_new ();
2543 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2546 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2548 case G_TOKEN_IDENTIFIER:
2549 if (is_c_identifier (scanner->next_value.v_identifier) &&
2550 scanner->next_value.v_identifier[0] >= 'A' &&
2551 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2553 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2555 g_scanner_get_next_token (scanner); /* eat type name */
2556 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2557 if (g_scanner_get_next_token (scanner) != ':' ||
2558 g_scanner_get_next_token (scanner) != ':')
2563 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2564 !is_c_identifier (scanner->value.v_identifier))
2566 token = G_TOKEN_IDENTIFIER;
2570 /* it's important that we do the same canonification as GParamSpecPool here */
2571 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2572 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2574 token = gtk_rc_parse_assignment (scanner, &prop);
2575 if (token == G_TOKEN_NONE)
2577 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2578 insert_rc_property (rc_style, &prop, TRUE);
2581 g_free (prop.origin);
2582 if (G_VALUE_TYPE (&prop.value))
2583 g_value_unset (&prop.value);
2587 g_scanner_get_next_token (scanner);
2588 token = G_TOKEN_IDENTIFIER;
2592 g_scanner_get_next_token (scanner);
2593 token = G_TOKEN_RIGHT_CURLY;
2597 if (token != G_TOKEN_NONE)
2600 token = g_scanner_peek_next_token (scanner);
2601 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2603 token = g_scanner_get_next_token (scanner);
2604 if (token != G_TOKEN_RIGHT_CURLY)
2606 token = G_TOKEN_RIGHT_CURLY;
2610 if (rc_style != orig_style)
2612 if (!context->rc_style_ht)
2613 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2614 (GEqualFunc) gtk_rc_style_equal);
2616 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2618 /* If we copied the data into a new rc style, fix up references to the old rc style
2619 * in bindings that we have.
2622 fixup_rc_sets (context, orig_style, rc_style);
2626 g_object_unref (orig_style);
2628 return G_TOKEN_NONE;
2631 if (rc_style != orig_style)
2632 gtk_rc_style_unref (rc_style);
2635 g_object_unref (orig_style);
2640 const GtkRcProperty*
2641 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2643 GQuark property_name)
2645 GtkRcProperty *node = NULL;
2647 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2649 if (rc_style->rc_properties)
2653 key.type_name = type_name;
2654 key.property_name = property_name;
2656 node = bsearch (&key,
2657 rc_style->rc_properties->data, rc_style->rc_properties->len,
2658 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2665 gtk_rc_parse_bg (GScanner *scanner,
2671 token = g_scanner_get_next_token (scanner);
2672 if (token != GTK_RC_TOKEN_BG)
2673 return GTK_RC_TOKEN_BG;
2675 token = gtk_rc_parse_state (scanner, &state);
2676 if (token != G_TOKEN_NONE)
2679 token = g_scanner_get_next_token (scanner);
2680 if (token != G_TOKEN_EQUAL_SIGN)
2681 return G_TOKEN_EQUAL_SIGN;
2683 style->color_flags[state] |= GTK_RC_BG;
2684 return gtk_rc_parse_color (scanner, &style->bg[state]);
2688 gtk_rc_parse_fg (GScanner *scanner,
2694 token = g_scanner_get_next_token (scanner);
2695 if (token != GTK_RC_TOKEN_FG)
2696 return GTK_RC_TOKEN_FG;
2698 token = gtk_rc_parse_state (scanner, &state);
2699 if (token != G_TOKEN_NONE)
2702 token = g_scanner_get_next_token (scanner);
2703 if (token != G_TOKEN_EQUAL_SIGN)
2704 return G_TOKEN_EQUAL_SIGN;
2706 style->color_flags[state] |= GTK_RC_FG;
2707 return gtk_rc_parse_color (scanner, &style->fg[state]);
2711 gtk_rc_parse_text (GScanner *scanner,
2717 token = g_scanner_get_next_token (scanner);
2718 if (token != GTK_RC_TOKEN_TEXT)
2719 return GTK_RC_TOKEN_TEXT;
2721 token = gtk_rc_parse_state (scanner, &state);
2722 if (token != G_TOKEN_NONE)
2725 token = g_scanner_get_next_token (scanner);
2726 if (token != G_TOKEN_EQUAL_SIGN)
2727 return G_TOKEN_EQUAL_SIGN;
2729 style->color_flags[state] |= GTK_RC_TEXT;
2730 return gtk_rc_parse_color (scanner, &style->text[state]);
2734 gtk_rc_parse_base (GScanner *scanner,
2740 token = g_scanner_get_next_token (scanner);
2741 if (token != GTK_RC_TOKEN_BASE)
2742 return GTK_RC_TOKEN_BASE;
2744 token = gtk_rc_parse_state (scanner, &state);
2745 if (token != G_TOKEN_NONE)
2748 token = g_scanner_get_next_token (scanner);
2749 if (token != G_TOKEN_EQUAL_SIGN)
2750 return G_TOKEN_EQUAL_SIGN;
2752 style->color_flags[state] |= GTK_RC_BASE;
2753 return gtk_rc_parse_color (scanner, &style->base[state]);
2757 gtk_rc_parse_xthickness (GScanner *scanner,
2760 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2761 return GTK_RC_TOKEN_XTHICKNESS;
2763 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2764 return G_TOKEN_EQUAL_SIGN;
2766 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2769 style->xthickness = scanner->value.v_int;
2771 return G_TOKEN_NONE;
2775 gtk_rc_parse_ythickness (GScanner *scanner,
2778 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2779 return GTK_RC_TOKEN_YTHICKNESS;
2781 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2782 return G_TOKEN_EQUAL_SIGN;
2784 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2787 style->ythickness = scanner->value.v_int;
2789 return G_TOKEN_NONE;
2793 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2795 GtkRcStyle *rc_style)
2801 token = g_scanner_get_next_token (scanner);
2802 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2803 return GTK_RC_TOKEN_BG_PIXMAP;
2805 token = gtk_rc_parse_state (scanner, &state);
2806 if (token != G_TOKEN_NONE)
2809 token = g_scanner_get_next_token (scanner);
2810 if (token != G_TOKEN_EQUAL_SIGN)
2811 return G_TOKEN_EQUAL_SIGN;
2813 token = g_scanner_get_next_token (scanner);
2814 if (token != G_TOKEN_STRING)
2815 return G_TOKEN_STRING;
2817 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2818 (strcmp (scanner->value.v_string, "<none>") == 0))
2819 pixmap_file = g_strdup (scanner->value.v_string);
2821 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2822 scanner, scanner->value.v_string);
2826 if (rc_style->bg_pixmap_name[state])
2827 g_free (rc_style->bg_pixmap_name[state]);
2828 rc_style->bg_pixmap_name[state] = pixmap_file;
2831 return G_TOKEN_NONE;
2835 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2840 buf = g_build_filename (dir, pixmap_file, NULL);
2842 fd = open (buf, O_RDONLY);
2855 * gtk_rc_find_pixmap_in_path:
2856 * @settings: a #GtkSettings
2857 * @scanner: Scanner used to get line number information for the
2858 * warning message, or %NULL
2859 * @pixmap_file: name of the pixmap file to locate.
2861 * Looks up a file in pixmap path for the specified #GtkSettings.
2862 * If the file is not found, it outputs a warning message using
2863 * g_warning() and returns %NULL.
2865 * Return value: the filename.
2868 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2870 const gchar *pixmap_file)
2876 GtkRcContext *context = gtk_rc_context_get (settings);
2878 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2880 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2885 tmp_list = rc_dir_stack;
2888 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2892 tmp_list = tmp_list->next;
2896 g_scanner_warn (scanner,
2897 _("Unable to locate image file in pixmap_path: \"%s\""),
2900 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2907 gtk_rc_find_module_in_path (const gchar *module_file)
2913 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2915 buf = g_build_filename (module_path[i], module_file, NULL);
2917 fd = open (buf, O_RDONLY);
2931 gtk_rc_parse_font (GScanner *scanner,
2932 GtkRcStyle *rc_style)
2936 token = g_scanner_get_next_token (scanner);
2937 if (token != GTK_RC_TOKEN_FONT)
2938 return GTK_RC_TOKEN_FONT;
2940 token = g_scanner_get_next_token (scanner);
2941 if (token != G_TOKEN_EQUAL_SIGN)
2942 return G_TOKEN_EQUAL_SIGN;
2944 token = g_scanner_get_next_token (scanner);
2945 if (token != G_TOKEN_STRING)
2946 return G_TOKEN_STRING;
2948 /* Ignore, do nothing */
2950 return G_TOKEN_NONE;
2954 gtk_rc_parse_fontset (GScanner *scanner,
2955 GtkRcStyle *rc_style)
2959 token = g_scanner_get_next_token (scanner);
2960 if (token != GTK_RC_TOKEN_FONTSET)
2961 return GTK_RC_TOKEN_FONTSET;
2963 token = g_scanner_get_next_token (scanner);
2964 if (token != G_TOKEN_EQUAL_SIGN)
2965 return G_TOKEN_EQUAL_SIGN;
2967 token = g_scanner_get_next_token (scanner);
2968 if (token != G_TOKEN_STRING)
2969 return G_TOKEN_STRING;
2971 /* Do nothing - silently ignore */
2973 return G_TOKEN_NONE;
2977 gtk_rc_parse_font_name (GScanner *scanner,
2978 GtkRcStyle *rc_style)
2982 token = g_scanner_get_next_token (scanner);
2983 if (token != GTK_RC_TOKEN_FONT_NAME)
2984 return GTK_RC_TOKEN_FONT;
2986 token = g_scanner_get_next_token (scanner);
2987 if (token != G_TOKEN_EQUAL_SIGN)
2988 return G_TOKEN_EQUAL_SIGN;
2990 token = g_scanner_get_next_token (scanner);
2991 if (token != G_TOKEN_STRING)
2992 return G_TOKEN_STRING;
2994 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2996 return G_TOKEN_NONE;
3000 gtk_rc_parse_engine (GtkRcContext *context,
3002 GtkRcStyle **rc_style)
3005 GtkThemeEngine *engine;
3006 guint result = G_TOKEN_NONE;
3007 GtkRcStyle *new_style = NULL;
3008 gboolean parsed_curlies = FALSE;
3010 token = g_scanner_get_next_token (scanner);
3011 if (token != GTK_RC_TOKEN_ENGINE)
3012 return GTK_RC_TOKEN_ENGINE;
3014 token = g_scanner_get_next_token (scanner);
3015 if (token != G_TOKEN_STRING)
3016 return G_TOKEN_STRING;
3018 if (!scanner->value.v_string[0])
3020 /* Support engine "" {} to mean override to the default engine
3022 token = g_scanner_get_next_token (scanner);
3023 if (token != G_TOKEN_LEFT_CURLY)
3024 return G_TOKEN_LEFT_CURLY;
3026 token = g_scanner_get_next_token (scanner);
3027 if (token != G_TOKEN_RIGHT_CURLY)
3028 return G_TOKEN_RIGHT_CURLY;
3030 parsed_curlies = TRUE;
3032 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3034 new_style = gtk_rc_style_new ();
3035 gtk_rc_style_real_merge (new_style, *rc_style);
3037 if ((*rc_style)->name)
3038 new_style->name = g_strdup ((*rc_style)->name);
3041 (*rc_style)->engine_specified = TRUE;
3045 engine = gtk_theme_engine_get (scanner->value.v_string);
3047 token = g_scanner_get_next_token (scanner);
3048 if (token != G_TOKEN_LEFT_CURLY)
3049 return G_TOKEN_LEFT_CURLY;
3053 GtkRcStyleClass *new_class;
3055 new_style = gtk_theme_engine_create_rc_style (engine);
3056 g_type_module_unuse (G_TYPE_MODULE (engine));
3058 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3060 new_class->merge (new_style, *rc_style);
3061 if ((*rc_style)->name)
3062 new_style->name = g_strdup ((*rc_style)->name);
3064 if (new_class->parse)
3066 parsed_curlies = TRUE;
3067 result = new_class->parse (new_style, context->settings, scanner);
3069 if (result != G_TOKEN_NONE)
3071 g_object_unref (G_OBJECT (new_style));
3078 if (!parsed_curlies)
3080 /* Skip over remainder, looking for nested {}'s
3084 result = G_TOKEN_RIGHT_CURLY;
3085 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3087 if (token == G_TOKEN_LEFT_CURLY)
3089 else if (token == G_TOKEN_RIGHT_CURLY)
3094 result = G_TOKEN_NONE;
3102 new_style->engine_specified = TRUE;
3104 g_object_unref (G_OBJECT (*rc_style));
3105 *rc_style = new_style;
3112 gtk_rc_parse_state (GScanner *scanner,
3113 GtkStateType *state)
3118 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3119 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3121 /* we don't know where we got called from, so we reset the scope here.
3122 * if we bail out due to errors, we *don't* reset the scope, so the
3123 * error messaging code can make sense of our tokens.
3125 old_scope = g_scanner_set_scope (scanner, 0);
3127 token = g_scanner_get_next_token (scanner);
3128 if (token != G_TOKEN_LEFT_BRACE)
3129 return G_TOKEN_LEFT_BRACE;
3131 token = g_scanner_get_next_token (scanner);
3134 case GTK_RC_TOKEN_ACTIVE:
3135 *state = GTK_STATE_ACTIVE;
3137 case GTK_RC_TOKEN_INSENSITIVE:
3138 *state = GTK_STATE_INSENSITIVE;
3140 case GTK_RC_TOKEN_NORMAL:
3141 *state = GTK_STATE_NORMAL;
3143 case GTK_RC_TOKEN_PRELIGHT:
3144 *state = GTK_STATE_PRELIGHT;
3146 case GTK_RC_TOKEN_SELECTED:
3147 *state = GTK_STATE_SELECTED;
3150 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3153 token = g_scanner_get_next_token (scanner);
3154 if (token != G_TOKEN_RIGHT_BRACE)
3155 return G_TOKEN_RIGHT_BRACE;
3157 g_scanner_set_scope (scanner, old_scope);
3159 return G_TOKEN_NONE;
3163 gtk_rc_parse_priority (GScanner *scanner,
3164 GtkPathPriorityType *priority)
3169 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3170 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3172 /* we don't know where we got called from, so we reset the scope here.
3173 * if we bail out due to errors, we *don't* reset the scope, so the
3174 * error messaging code can make sense of our tokens.
3176 old_scope = g_scanner_set_scope (scanner, 0);
3178 token = g_scanner_get_next_token (scanner);
3182 token = g_scanner_get_next_token (scanner);
3185 case GTK_RC_TOKEN_LOWEST:
3186 *priority = GTK_PATH_PRIO_LOWEST;
3188 case GTK_RC_TOKEN_GTK:
3189 *priority = GTK_PATH_PRIO_GTK;
3191 case GTK_RC_TOKEN_APPLICATION:
3192 *priority = GTK_PATH_PRIO_APPLICATION;
3194 case GTK_RC_TOKEN_THEME:
3195 *priority = GTK_PATH_PRIO_THEME;
3197 case GTK_RC_TOKEN_RC:
3198 *priority = GTK_PATH_PRIO_RC;
3200 case GTK_RC_TOKEN_HIGHEST:
3201 *priority = GTK_PATH_PRIO_HIGHEST;
3204 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3207 g_scanner_set_scope (scanner, old_scope);
3209 return G_TOKEN_NONE;
3213 gtk_rc_parse_color (GScanner *scanner,
3218 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3220 /* we don't need to set our own scope here, because
3221 * we don't need own symbols
3224 token = g_scanner_get_next_token (scanner);
3229 case G_TOKEN_LEFT_CURLY:
3230 token = g_scanner_get_next_token (scanner);
3231 if (token == G_TOKEN_INT)
3232 token_int = scanner->value.v_int;
3233 else if (token == G_TOKEN_FLOAT)
3234 token_int = scanner->value.v_float * 65535.0;
3236 return G_TOKEN_FLOAT;
3237 color->red = CLAMP (token_int, 0, 65535);
3239 token = g_scanner_get_next_token (scanner);
3240 if (token != G_TOKEN_COMMA)
3241 return G_TOKEN_COMMA;
3243 token = g_scanner_get_next_token (scanner);
3244 if (token == G_TOKEN_INT)
3245 token_int = scanner->value.v_int;
3246 else if (token == G_TOKEN_FLOAT)
3247 token_int = scanner->value.v_float * 65535.0;
3249 return G_TOKEN_FLOAT;
3250 color->green = CLAMP (token_int, 0, 65535);
3252 token = g_scanner_get_next_token (scanner);
3253 if (token != G_TOKEN_COMMA)
3254 return G_TOKEN_COMMA;
3256 token = g_scanner_get_next_token (scanner);
3257 if (token == G_TOKEN_INT)
3258 token_int = scanner->value.v_int;
3259 else if (token == G_TOKEN_FLOAT)
3260 token_int = scanner->value.v_float * 65535.0;
3262 return G_TOKEN_FLOAT;
3263 color->blue = CLAMP (token_int, 0, 65535);
3265 token = g_scanner_get_next_token (scanner);
3266 if (token != G_TOKEN_RIGHT_CURLY)
3267 return G_TOKEN_RIGHT_CURLY;
3268 return G_TOKEN_NONE;
3270 case G_TOKEN_STRING:
3271 if (!gdk_color_parse (scanner->value.v_string, color))
3273 g_scanner_warn (scanner, "Invalid color constant '%s'",
3274 scanner->value.v_string);
3275 return G_TOKEN_STRING;
3278 return G_TOKEN_NONE;
3281 return G_TOKEN_STRING;
3286 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3291 token = g_scanner_get_next_token (scanner);
3292 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3293 return GTK_RC_TOKEN_PIXMAP_PATH;
3295 token = g_scanner_get_next_token (scanner);
3296 if (token != G_TOKEN_STRING)
3297 return G_TOKEN_STRING;
3299 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3301 return G_TOKEN_NONE;
3305 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3307 const gchar *pix_path)
3310 gint start_offset = 0;
3314 /* free the old one, or just add to the old one ? */
3315 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3317 g_free (context->pixmap_path[path_num]);
3318 context->pixmap_path[path_num] = NULL;
3323 path_len = strlen (pix_path);
3325 for (end_offset = 0; end_offset <= path_len; end_offset++)
3327 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3328 (end_offset == path_len))
3330 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3331 if (g_path_is_absolute (path_element))
3333 context->pixmap_path[path_num] = path_element;
3335 context->pixmap_path[path_num] = NULL;
3339 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3340 path_element, scanner->input_name, scanner->line);
3341 g_free (path_element);
3344 start_offset = end_offset + 1;
3350 gtk_rc_parse_module_path (GScanner *scanner)
3354 token = g_scanner_get_next_token (scanner);
3355 if (token != GTK_RC_TOKEN_MODULE_PATH)
3356 return GTK_RC_TOKEN_MODULE_PATH;
3358 token = g_scanner_get_next_token (scanner);
3359 if (token != G_TOKEN_STRING)
3360 return G_TOKEN_STRING;
3362 gtk_rc_parse_module_path_string (scanner->value.v_string);
3364 return G_TOKEN_NONE;
3368 gtk_rc_parse_im_module_path (GScanner *scanner)
3372 token = g_scanner_get_next_token (scanner);
3373 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3374 return GTK_RC_TOKEN_IM_MODULE_FILE;
3376 token = g_scanner_get_next_token (scanner);
3377 if (token != G_TOKEN_STRING)
3378 return G_TOKEN_STRING;
3381 g_free (im_module_path);
3383 im_module_path = g_strdup (scanner->value.v_string);
3385 return G_TOKEN_NONE;
3389 gtk_rc_parse_im_module_file (GScanner *scanner)
3393 token = g_scanner_get_next_token (scanner);
3394 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3395 return GTK_RC_TOKEN_IM_MODULE_FILE;
3397 token = g_scanner_get_next_token (scanner);
3398 if (token != G_TOKEN_STRING)
3399 return G_TOKEN_STRING;
3402 g_free (im_module_file);
3404 im_module_file = g_strdup (scanner->value.v_string);
3406 return G_TOKEN_NONE;
3410 gtk_rc_parse_module_path_string (const gchar *mod_path)
3413 gint start_offset = 0;
3417 /* free the old one, or just add to the old one ? */
3418 for (path_num=0; module_path[path_num]; path_num++)
3420 g_free (module_path[path_num]);
3421 module_path[path_num] = NULL;
3426 path_len = strlen (mod_path);
3428 for (end_offset = 0; end_offset <= path_len; end_offset++)
3430 if ((mod_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3431 (end_offset == path_len))
3433 module_path[path_num] = g_strndup (mod_path + start_offset, end_offset - start_offset);
3435 module_path[path_num] = NULL;
3436 start_offset = end_offset + 1;
3439 gtk_rc_append_default_module_path();
3443 gtk_rc_parse_path_pattern (GtkRcContext *context,
3447 GtkPathType path_type;
3449 gboolean is_binding;
3450 GtkPathPriorityType priority = context->default_priority;
3452 token = g_scanner_get_next_token (scanner);
3455 case GTK_RC_TOKEN_WIDGET:
3456 path_type = GTK_PATH_WIDGET;
3458 case GTK_RC_TOKEN_WIDGET_CLASS:
3459 path_type = GTK_PATH_WIDGET_CLASS;
3461 case GTK_RC_TOKEN_CLASS:
3462 path_type = GTK_PATH_CLASS;
3465 return GTK_RC_TOKEN_WIDGET_CLASS;
3468 token = g_scanner_get_next_token (scanner);
3469 if (token != G_TOKEN_STRING)
3470 return G_TOKEN_STRING;
3472 pattern = g_strdup (scanner->value.v_string);
3474 token = g_scanner_get_next_token (scanner);
3475 if (token == GTK_RC_TOKEN_STYLE)
3477 else if (token == GTK_RC_TOKEN_BINDING)
3482 return GTK_RC_TOKEN_STYLE;
3485 if (g_scanner_peek_next_token (scanner) == ':')
3487 token = gtk_rc_parse_priority (scanner, &priority);
3488 if (token != G_TOKEN_NONE)
3495 token = g_scanner_get_next_token (scanner);
3496 if (token != G_TOKEN_STRING)
3499 return G_TOKEN_STRING;
3504 GtkBindingSet *binding;
3506 binding = gtk_binding_set_find (scanner->value.v_string);
3510 return G_TOKEN_STRING;
3512 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3516 GtkRcStyle *rc_style;
3519 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3524 return G_TOKEN_STRING;
3527 rc_set = g_new (GtkRcSet, 1);
3528 rc_set->pspec = g_pattern_spec_new (pattern);
3529 rc_set->rc_style = rc_style;
3530 rc_set->priority = priority;
3532 if (path_type == GTK_PATH_WIDGET)
3533 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3534 else if (path_type == GTK_PATH_WIDGET_CLASS)
3535 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3537 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3541 return G_TOKEN_NONE;
3545 gtk_rc_parse_stock_id (GScanner *scanner,
3550 token = g_scanner_get_next_token (scanner);
3551 if (token != G_TOKEN_LEFT_BRACE)
3552 return G_TOKEN_LEFT_BRACE;
3554 token = g_scanner_get_next_token (scanner);
3556 if (token != G_TOKEN_STRING)
3557 return G_TOKEN_STRING;
3559 *stock_id = g_strdup (scanner->value.v_string);
3561 token = g_scanner_get_next_token (scanner);
3562 if (token != G_TOKEN_RIGHT_BRACE)
3565 return G_TOKEN_RIGHT_BRACE;
3568 return G_TOKEN_NONE;
3572 gtk_rc_parse_icon_source (GtkRcContext *context,
3574 GtkIconSet *icon_set,
3575 gboolean *icon_set_valid)
3578 GtkIconSource *source;
3579 gchar *full_filename;
3581 token = g_scanner_get_next_token (scanner);
3582 if (token != G_TOKEN_LEFT_CURLY)
3583 return G_TOKEN_LEFT_CURLY;
3585 token = g_scanner_get_next_token (scanner);
3587 if (token != G_TOKEN_STRING)
3588 return G_TOKEN_STRING;
3591 source = gtk_icon_source_new ();
3593 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3596 gtk_icon_source_set_filename (source, full_filename);
3597 g_free (full_filename);
3600 /* We continue parsing even if we didn't find the pixmap so that rest of the
3601 * file is read, even if the syntax is bad. However we don't validate the
3602 * icon_set so the caller can choose not to install it.
3604 token = g_scanner_get_next_token (scanner);
3606 if (token == G_TOKEN_RIGHT_CURLY)
3608 else if (token != G_TOKEN_COMMA)
3610 gtk_icon_source_free (source);
3611 return G_TOKEN_COMMA;
3614 /* Get the direction */
3616 token = g_scanner_get_next_token (scanner);
3620 case GTK_RC_TOKEN_RTL:
3621 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3622 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3625 case GTK_RC_TOKEN_LTR:
3626 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3627 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3634 gtk_icon_source_free (source);
3635 return GTK_RC_TOKEN_RTL;
3639 token = g_scanner_get_next_token (scanner);
3641 if (token == G_TOKEN_RIGHT_CURLY)
3643 else if (token != G_TOKEN_COMMA)
3645 gtk_icon_source_free (source);
3646 return G_TOKEN_COMMA;
3651 token = g_scanner_get_next_token (scanner);
3655 case GTK_RC_TOKEN_NORMAL:
3656 gtk_icon_source_set_state_wildcarded (source, FALSE);
3657 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3660 case GTK_RC_TOKEN_PRELIGHT:
3661 gtk_icon_source_set_state_wildcarded (source, FALSE);
3662 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3666 case GTK_RC_TOKEN_INSENSITIVE:
3667 gtk_icon_source_set_state_wildcarded (source, FALSE);
3668 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3671 case GTK_RC_TOKEN_ACTIVE:
3672 gtk_icon_source_set_state_wildcarded (source, FALSE);
3673 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3676 case GTK_RC_TOKEN_SELECTED:
3677 gtk_icon_source_set_state_wildcarded (source, FALSE);
3678 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3685 gtk_icon_source_free (source);
3686 return GTK_RC_TOKEN_PRELIGHT;
3690 token = g_scanner_get_next_token (scanner);
3692 if (token == G_TOKEN_RIGHT_CURLY)
3694 else if (token != G_TOKEN_COMMA)
3696 gtk_icon_source_free (source);
3697 return G_TOKEN_COMMA;
3702 token = g_scanner_get_next_token (scanner);
3708 if (token != G_TOKEN_STRING)
3710 gtk_icon_source_free (source);
3711 return G_TOKEN_STRING;
3714 size = gtk_icon_size_from_name (scanner->value.v_string);
3716 if (size != GTK_ICON_SIZE_INVALID)
3718 gtk_icon_source_set_size_wildcarded (source, FALSE);
3719 gtk_icon_source_set_size (source, size);
3723 /* Check the close brace */
3725 token = g_scanner_get_next_token (scanner);
3726 if (token != G_TOKEN_RIGHT_CURLY)
3728 gtk_icon_source_free (source);
3729 return G_TOKEN_RIGHT_CURLY;
3733 if (gtk_icon_source_get_filename (source))
3735 gtk_icon_set_add_source (icon_set, source);
3736 *icon_set_valid = TRUE;
3738 gtk_icon_source_free (source);
3740 return G_TOKEN_NONE;
3744 gtk_rc_parse_stock (GtkRcContext *context,
3746 GtkRcStyle *rc_style,
3747 GtkIconFactory *factory)
3749 GtkIconSet *icon_set = NULL;
3750 gboolean icon_set_valid = FALSE;
3751 gchar *stock_id = NULL;
3754 token = g_scanner_get_next_token (scanner);
3755 if (token != GTK_RC_TOKEN_STOCK)
3756 return GTK_RC_TOKEN_STOCK;
3758 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3759 if (token != G_TOKEN_NONE)
3762 token = g_scanner_get_next_token (scanner);
3763 if (token != G_TOKEN_EQUAL_SIGN)
3766 return G_TOKEN_EQUAL_SIGN;
3769 token = g_scanner_get_next_token (scanner);
3770 if (token != G_TOKEN_LEFT_CURLY)
3773 return G_TOKEN_LEFT_CURLY;
3776 token = g_scanner_peek_next_token (scanner);
3777 while (token != G_TOKEN_RIGHT_CURLY)
3779 if (icon_set == NULL)
3780 icon_set = gtk_icon_set_new ();
3782 token = gtk_rc_parse_icon_source (context,
3783 scanner, icon_set, &icon_set_valid);
3784 if (token != G_TOKEN_NONE)
3787 gtk_icon_set_unref (icon_set);
3791 token = g_scanner_get_next_token (scanner);
3793 if (token != G_TOKEN_COMMA &&
3794 token != G_TOKEN_RIGHT_CURLY)
3797 gtk_icon_set_unref (icon_set);
3798 return G_TOKEN_RIGHT_CURLY;
3802 if (icon_set && icon_set_valid)
3804 gtk_icon_factory_add (factory,
3808 gtk_icon_set_unref (icon_set);
3813 return G_TOKEN_NONE;