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 "gtksettings.h"
57 #include "gtkwindow.h"
63 typedef struct _GtkRcSet GtkRcSet;
64 typedef struct _GtkRcNode GtkRcNode;
65 typedef struct _GtkRcFile GtkRcFile;
78 gchar *canonical_name;
82 #define GTK_RC_MAX_PIXMAP_PATHS 128
86 GHashTable *rc_style_ht;
87 GtkSettings *settings;
88 GSList *rc_sets_widget;
89 GSList *rc_sets_widget_class;
90 GSList *rc_sets_class;
92 /* The files we have parsed, to reread later if necessary */
96 gchar *key_theme_name;
98 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
100 gint default_priority;
103 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
105 static guint gtk_rc_style_hash (const gchar *name);
106 static gboolean gtk_rc_style_equal (const gchar *a,
108 static guint gtk_rc_styles_hash (const GSList *rc_styles);
109 static gboolean gtk_rc_styles_equal (const GSList *a,
111 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
113 static GSList * gtk_rc_styles_match (GSList *rc_styles,
117 const gchar *path_reversed);
118 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
119 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
120 static void gtk_rc_parse_default_files (GtkRcContext *context);
121 static void gtk_rc_parse_named (GtkRcContext *context,
124 static void gtk_rc_parse_file (GtkRcContext *context,
125 const gchar *filename,
128 static void gtk_rc_parse_any (GtkRcContext *context,
129 const gchar *input_name,
131 const gchar *input_string);
132 static guint gtk_rc_parse_statement (GtkRcContext *context,
134 static guint gtk_rc_parse_style (GtkRcContext *context,
136 static guint gtk_rc_parse_assignment (GScanner *scanner,
137 GtkRcProperty *prop);
138 static guint gtk_rc_parse_bg (GScanner *scanner,
140 static guint gtk_rc_parse_fg (GScanner *scanner,
142 static guint gtk_rc_parse_text (GScanner *scanner,
144 static guint gtk_rc_parse_base (GScanner *scanner,
146 static guint gtk_rc_parse_xthickness (GScanner *scanner,
148 static guint gtk_rc_parse_ythickness (GScanner *scanner,
150 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
152 GtkRcStyle *rc_style);
153 static guint gtk_rc_parse_font (GScanner *scanner,
154 GtkRcStyle *rc_style);
155 static guint gtk_rc_parse_fontset (GScanner *scanner,
156 GtkRcStyle *rc_style);
157 static guint gtk_rc_parse_font_name (GScanner *scanner,
158 GtkRcStyle *rc_style);
159 static guint gtk_rc_parse_engine (GtkRcContext *context,
161 GtkRcStyle **rc_style);
162 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
164 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
166 const gchar *pix_path);
167 static guint gtk_rc_parse_module_path (GScanner *scanner);
168 static void gtk_rc_parse_module_path_string (const gchar *mod_path);
169 static guint gtk_rc_parse_im_module_path (GScanner *scanner);
170 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
171 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
173 static guint gtk_rc_parse_stock (GtkRcContext *context,
175 GtkRcStyle *rc_style,
176 GtkIconFactory *factory);
177 static void gtk_rc_clear_hash_node (gpointer key,
180 static void gtk_rc_clear_styles (GtkRcContext *context);
181 static void gtk_rc_append_default_module_path (void);
182 static void gtk_rc_add_initial_default_files (void);
184 static void gtk_rc_style_init (GtkRcStyle *style);
185 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
186 static void gtk_rc_style_finalize (GObject *object);
187 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
189 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
190 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
191 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
192 gconstpointer bsearch_node2);
194 static gpointer parent_class = NULL;
196 static const GScannerConfig gtk_rc_scanner_config =
200 ) /* cset_skip_characters */,
205 ) /* cset_identifier_first */,
210 ) /* cset_identifier_nth */,
211 ( "#\n" ) /* cpair_comment_single */,
213 TRUE /* case_sensitive */,
215 TRUE /* skip_comment_multi */,
216 TRUE /* skip_comment_single */,
217 TRUE /* scan_comment_multi */,
218 TRUE /* scan_identifier */,
219 FALSE /* scan_identifier_1char */,
220 FALSE /* scan_identifier_NULL */,
221 TRUE /* scan_symbols */,
222 TRUE /* scan_binary */,
223 TRUE /* scan_octal */,
224 TRUE /* scan_float */,
226 TRUE /* scan_hex_dollar */,
227 TRUE /* scan_string_sq */,
228 TRUE /* scan_string_dq */,
229 TRUE /* numbers_2_int */,
230 FALSE /* int_2_float */,
231 FALSE /* identifier_2_string */,
232 TRUE /* char_2_token */,
233 TRUE /* symbol_2_token */,
234 FALSE /* scope_0_fallback */,
242 { "include", GTK_RC_TOKEN_INCLUDE },
243 { "NORMAL", GTK_RC_TOKEN_NORMAL },
244 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
245 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
246 { "SELECTED", GTK_RC_TOKEN_SELECTED },
247 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
248 { "fg", GTK_RC_TOKEN_FG },
249 { "bg", GTK_RC_TOKEN_BG },
250 { "text", GTK_RC_TOKEN_TEXT },
251 { "base", GTK_RC_TOKEN_BASE },
252 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
253 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
254 { "font", GTK_RC_TOKEN_FONT },
255 { "fontset", GTK_RC_TOKEN_FONTSET },
256 { "font_name", GTK_RC_TOKEN_FONT_NAME },
257 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
258 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
259 { "style", GTK_RC_TOKEN_STYLE },
260 { "binding", GTK_RC_TOKEN_BINDING },
261 { "bind", GTK_RC_TOKEN_BIND },
262 { "widget", GTK_RC_TOKEN_WIDGET },
263 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
264 { "class", GTK_RC_TOKEN_CLASS },
265 { "lowest", GTK_RC_TOKEN_LOWEST },
266 { "gtk", GTK_RC_TOKEN_GTK },
267 { "application", GTK_RC_TOKEN_APPLICATION },
268 { "theme", GTK_RC_TOKEN_THEME },
269 { "rc", GTK_RC_TOKEN_RC },
270 { "highest", GTK_RC_TOKEN_HIGHEST },
271 { "engine", GTK_RC_TOKEN_ENGINE },
272 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
273 { "stock", GTK_RC_TOKEN_STOCK },
274 { "im_module_path", GTK_RC_TOKEN_IM_MODULE_PATH },
275 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
276 { "LTR", GTK_RC_TOKEN_LTR },
277 { "RTL", GTK_RC_TOKEN_RTL }
280 static GHashTable *realized_style_ht = NULL;
282 static gchar *im_module_path = NULL;
283 static gchar *im_module_file = NULL;
285 #define GTK_RC_MAX_DEFAULT_FILES 128
286 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
288 #define GTK_RC_MAX_MODULE_PATHS 128
289 static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
291 /* A stack of directories for RC files we are parsing currently.
292 * these are implicitely added to the end of PIXMAP_PATHS
294 static GSList *rc_dir_stack = NULL;
296 /* RC file handling */
300 get_gtk_dll_name (void)
302 static gchar *gtk_dll = NULL;
305 gtk_dll = g_strdup_printf ("gtk-%d.%d.dll", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
311 get_themes_directory (void)
313 return g_win32_get_package_installation_subdirectory (GETTEXT_PACKAGE,
317 #endif /* G_OS_WIN32 */
320 gtk_rc_make_default_dir (const gchar *type)
325 var = getenv("GTK_EXE_PREFIX");
327 path = g_strconcat (var, "/lib/gtk-2.0/" GTK_VERSION "/", type, NULL);
329 path = g_strconcat (GTK_LIBDIR "/gtk-2.0/" GTK_VERSION "/", type, NULL);
331 path = g_strconcat ("%s\\%s", get_themes_directory (), type);
338 gtk_rc_get_im_module_path (void)
340 const gchar *result = g_getenv ("GTK_IM_MODULE_PATH");
345 result = im_module_path;
347 return gtk_rc_make_default_dir ("immodules");
350 return g_strdup (result);
354 gtk_rc_get_im_module_file (void)
356 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
361 result = g_strdup (im_module_file);
364 result = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtk.immodules");
366 result = g_strdup_printf ("%s\\gtk.immodules", g_win32_get_package_installation_directory (GETTEXT_PACKAGE, get_gtk_dll_name ()));
374 gtk_rc_get_theme_dir(void)
379 var = getenv("GTK_DATA_PREFIX");
381 path = g_strconcat (var, "/share/themes", NULL);
383 path = g_strconcat (GTK_DATA_PREFIX, "/share/themes", NULL);
385 path = g_strdup (get_themes_directory ());
392 gtk_rc_get_module_dir(void)
394 return gtk_rc_make_default_dir ("engines");
398 gtk_rc_append_default_module_path(void)
404 for (n = 0; module_path[n]; n++) ;
405 if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
409 var = getenv("GTK_EXE_PREFIX");
411 path = g_strconcat(var, "/lib/gtk-2.0/" GTK_VERSION "/engines", NULL);
413 path = g_strdup (GTK_LIBDIR "/gtk-2.0/" GTK_VERSION "/engines");
415 path = g_strconcat (get_themes_directory (), "\\engines", NULL);
417 module_path[n++] = path;
419 var = g_get_home_dir ();
423 /* Don't duplicate the directory separator, causes trouble at
426 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
427 sep = G_DIR_SEPARATOR_S;
430 /* This produces something like ~/.gtk-2.0/2.0/engines */
431 path = g_strconcat (var, sep,
432 ".gtk-2.0" G_DIR_SEPARATOR_S
433 GTK_VERSION G_DIR_SEPARATOR_S
435 module_path[n++] = path;
437 module_path[n] = NULL;
441 gtk_rc_add_initial_default_files (void)
443 static gint init = FALSE;
452 gtk_rc_default_files[0] = NULL;
455 var = g_getenv("GTK_RC_FILES");
458 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
462 gtk_rc_add_default_file (files[i]);
470 str = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
472 str = g_strdup_printf ("%s\\gtkrc", g_win32_get_package_installation_directory (GETTEXT_PACKAGE, get_gtk_dll_name ()));
475 gtk_rc_add_default_file (str);
478 var = g_get_home_dir ();
482 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
483 sep = G_DIR_SEPARATOR_S;
486 str = g_strdup_printf ("%s%s.gtkrc-2.0", var, sep);
487 gtk_rc_add_default_file (str);
494 * gtk_rc_add_default_file:
495 * @file: the pathname to the file.
497 * Adds a file to the list of files to be parsed at the
501 gtk_rc_add_default_file (const gchar *file)
505 gtk_rc_add_initial_default_files ();
507 for (n = 0; gtk_rc_default_files[n]; n++) ;
508 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
511 gtk_rc_default_files[n++] = g_strdup (file);
512 gtk_rc_default_files[n] = NULL;
516 * gtk_rc_set_default_files:
517 * @files: A %NULL terminated list of filenames.
519 * Sets the list of files that GTK+ will read at the
523 gtk_rc_set_default_files (gchar **files)
527 gtk_rc_add_initial_default_files ();
530 while (gtk_rc_default_files[i])
532 g_free (gtk_rc_default_files[i]);
536 gtk_rc_default_files[0] = NULL;
539 while (files[i] != NULL)
541 gtk_rc_add_default_file (files[i]);
547 * gtk_rc_get_default_files:
550 * Retrieves the current list of RC files that will be parsed
551 * at the end of gtk_init()
553 * Return value: A NULL terminated array of filenames. This memory
554 * is owned by GTK+ and must not be freed by the application.
555 * If you want to store this information, you should make a
559 gtk_rc_get_default_files (void)
561 gtk_rc_add_initial_default_files ();
563 return gtk_rc_default_files;
566 /* The following routine is based on _nl_normalize_codeset from
567 * the GNU C library. Contributed by
569 * Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
570 * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
572 * Normalize codeset name. There is no standard for the codeset
573 * names. Normalization allows the user to use any of the common
577 _gtk_normalize_codeset (const gchar *codeset, gint name_len)
585 for (cnt = 0; cnt < name_len; ++cnt)
586 if (isalnum (codeset[cnt]))
590 if (isalpha (codeset[cnt]))
594 retval = g_malloc ((only_digit ? 3 : 0) + len + 1);
598 memcpy (retval, "iso", 4);
604 for (cnt = 0; cnt < name_len; ++cnt)
605 if (isalpha (codeset[cnt]))
606 *wp++ = isupper(codeset[cnt]) ? tolower (codeset[cnt]) : codeset[cnt];
607 else if (isdigit (codeset[cnt]))
608 *wp++ = codeset[cnt];
616 gtk_rc_settings_changed (GtkSettings *settings,
618 GtkRcContext *context)
620 gchar *new_theme_name;
621 gchar *new_key_theme_name;
623 g_object_get (settings,
624 "gtk-theme-name", &new_theme_name,
625 "gtk-key-theme-name", &new_key_theme_name,
628 if ((new_theme_name != context->theme_name &&
629 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
630 (new_key_theme_name != context->key_theme_name &&
631 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
633 gtk_rc_reparse_all_for_settings (settings, TRUE);
636 g_free (new_theme_name);
637 g_free (new_key_theme_name);
640 static GtkRcContext *
641 gtk_rc_context_get (GtkSettings *settings)
643 if (!settings->rc_context)
645 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
647 context->settings = settings;
648 context->rc_style_ht = NULL;
649 context->rc_sets_widget = NULL;
650 context->rc_sets_widget_class = NULL;
651 context->rc_sets_class = NULL;
652 context->rc_files = NULL;
654 g_object_get (settings,
655 "gtk-theme-name", &context->theme_name,
656 "gtk-key-theme-name", &context->key_theme_name,
659 g_signal_connect (settings,
660 "notify::gtk-theme-name",
661 G_CALLBACK (gtk_rc_settings_changed),
663 g_signal_connect (settings,
664 "notify::gtk-key-theme-name",
665 G_CALLBACK (gtk_rc_settings_changed),
668 context->pixmap_path[0] = NULL;
670 context->default_priority = GTK_PATH_PRIO_RC;
673 return settings->rc_context;
677 gtk_rc_parse_named (GtkRcContext *context,
686 subpath = g_strconcat (G_DIR_SEPARATOR_S "gtk-2.0-",
688 G_DIR_SEPARATOR_S "gtkrc",
691 subpath = g_strdup (G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
693 /* First look in the users home directory
695 home_dir = g_get_home_dir ();
699 /* Don't duplicate the directory separator, causes trouble at
702 if (home_dir[strlen (home_dir) -1] != G_DIR_SEPARATOR)
703 sep = G_DIR_SEPARATOR_S;
706 path = g_strconcat (home_dir, sep,
707 ".themes" G_DIR_SEPARATOR_S ,
712 if (!g_file_test (path, G_FILE_TEST_EXISTS))
721 gchar *theme_dir = gtk_rc_get_theme_dir ();
722 gchar *path = g_strconcat (theme_dir, G_DIR_SEPARATOR_S, name, subpath);
725 if (!g_file_test (path, G_FILE_TEST_EXISTS))
734 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
742 gtk_rc_parse_default_files (GtkRcContext *context)
744 gchar *locale_suffixes[3];
745 gint n_locale_suffixes = 0;
752 locale = g_win32_getlocale ();
754 locale = setlocale (LC_CTYPE, NULL);
757 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
759 /* Determine locale-specific suffixes for RC files
761 * We normalize the charset into a standard form,
762 * which has all '-' and '_' characters removed,
765 gchar *normalized_locale;
767 p = strchr (locale, '@');
768 length = p ? (p -locale) : strlen (locale);
770 p = strchr (locale, '.');
773 gchar *tmp1 = g_strndup (locale, p - locale + 1);
774 gchar *tmp2 = _gtk_normalize_codeset (p + 1, length - (p - locale + 1));
776 normalized_locale = g_strconcat (tmp1, tmp2, NULL);
780 locale_suffixes[n_locale_suffixes++] = g_strdup (normalized_locale);
784 normalized_locale = g_strndup (locale, length);
786 p = strchr (normalized_locale, '_');
789 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
790 length = p - normalized_locale;
793 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
795 g_free (normalized_locale);
798 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
800 /* Try to find a locale specific RC file corresponding to the
801 * current locale to parse before the default file.
803 for (j = n_locale_suffixes - 1; j >= 0; j--)
805 gchar *name = g_strconcat (gtk_rc_default_files[i],
809 gtk_rc_parse_file (context, name, GTK_PATH_PRIO_RC, FALSE);
812 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
815 for (j = 0; j < n_locale_suffixes; j++)
816 g_free (locale_suffixes[j]);
822 static gboolean initialized = FALSE;
828 module_path[0] = NULL;
829 gtk_rc_append_default_module_path();
831 gtk_rc_add_initial_default_files ();
834 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
838 gtk_rc_parse_string (const gchar *rc_string)
840 g_return_if_fail (rc_string != NULL);
842 gtk_rc_parse_any (gtk_rc_context_get (gtk_settings_get_default ()),
843 "-", -1, rc_string); /* FIXME */
847 gtk_rc_parse_file (GtkRcContext *context,
848 const gchar *filename,
852 GtkRcFile *rc_file = NULL;
857 g_return_if_fail (filename != NULL);
859 saved_priority = context->default_priority;
860 context->default_priority = priority;
862 tmp_list = context->rc_files;
865 rc_file = tmp_list->data;
866 if (!strcmp (rc_file->name, filename))
869 tmp_list = tmp_list->next;
874 rc_file = g_new (GtkRcFile, 1);
875 rc_file->name = g_strdup (filename);
876 rc_file->canonical_name = NULL;
878 rc_file->reload = reload;
880 context->rc_files = g_slist_append (context->rc_files, rc_file);
883 if (!rc_file->canonical_name)
885 /* Get the absolute pathname */
887 if (g_path_is_absolute (rc_file->name))
888 rc_file->canonical_name = rc_file->name;
894 cwd = g_get_current_dir ();
896 str = g_string_new (cwd);
898 g_string_append_c (str, G_DIR_SEPARATOR);
899 g_string_append (str, rc_file->name);
901 rc_file->canonical_name = str->str;
902 g_string_free (str, FALSE);
906 if (!lstat (rc_file->canonical_name, &statbuf))
911 rc_file->mtime = statbuf.st_mtime;
913 fd = open (rc_file->canonical_name, O_RDONLY);
917 /* Temporarily push directory name for this file on
918 * a stack of directory names while parsing it
921 g_slist_prepend (rc_dir_stack,
922 g_path_get_dirname (rc_file->canonical_name));
923 gtk_rc_parse_any (context, filename, fd, NULL);
925 tmp_list = rc_dir_stack;
926 rc_dir_stack = rc_dir_stack->next;
928 g_free (tmp_list->data);
929 g_slist_free_1 (tmp_list);
935 context->default_priority = saved_priority;
939 gtk_rc_parse (const gchar *filename)
941 g_return_if_fail (filename != NULL);
943 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
944 filename, GTK_PATH_PRIO_RC, TRUE); /* FIXME */
947 /* Handling of RC styles */
950 gtk_rc_style_get_type (void)
952 static GType object_type = 0;
956 static const GTypeInfo object_info =
958 sizeof (GtkRcStyleClass),
959 (GBaseInitFunc) NULL,
960 (GBaseFinalizeFunc) NULL,
961 (GClassInitFunc) gtk_rc_style_class_init,
962 NULL, /* class_finalize */
963 NULL, /* class_data */
966 (GInstanceInitFunc) gtk_rc_style_init,
969 object_type = g_type_register_static (G_TYPE_OBJECT,
978 gtk_rc_style_init (GtkRcStyle *style)
983 style->font_desc = NULL;
985 for (i = 0; i < 5; i++)
987 static const GdkColor init_color = { 0, 0, 0, 0, };
989 style->bg_pixmap_name[i] = NULL;
990 style->color_flags[i] = 0;
991 style->fg[i] = init_color;
992 style->bg[i] = init_color;
993 style->text[i] = init_color;
994 style->base[i] = init_color;
996 style->xthickness = -1;
997 style->ythickness = -1;
998 style->rc_properties = NULL;
1000 style->rc_style_lists = NULL;
1001 style->icon_factories = NULL;
1005 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1007 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1009 parent_class = g_type_class_peek_parent (klass);
1011 object_class->finalize = gtk_rc_style_finalize;
1013 klass->parse = NULL;
1014 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
1015 klass->merge = gtk_rc_style_real_merge;
1016 klass->create_style = gtk_rc_style_real_create_style;
1020 gtk_rc_style_finalize (GObject *object)
1022 GSList *tmp_list1, *tmp_list2;
1023 GtkRcStyle *rc_style;
1026 rc_style = GTK_RC_STYLE (object);
1029 g_free (rc_style->name);
1030 if (rc_style->font_desc)
1031 pango_font_description_free (rc_style->font_desc);
1033 for (i = 0; i < 5; i++)
1034 if (rc_style->bg_pixmap_name[i])
1035 g_free (rc_style->bg_pixmap_name[i]);
1037 /* Now remove all references to this rc_style from
1040 tmp_list1 = rc_style->rc_style_lists;
1043 GSList *rc_styles = tmp_list1->data;
1044 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1045 gtk_style_unref (style);
1047 /* Remove the list of styles from the other rc_styles
1050 tmp_list2 = rc_styles;
1053 GtkRcStyle *other_style = tmp_list2->data;
1055 if (other_style != rc_style)
1056 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1058 tmp_list2 = tmp_list2->next;
1061 /* And from the hash table itself
1063 g_hash_table_remove (realized_style_ht, rc_styles);
1064 g_slist_free (rc_styles);
1066 tmp_list1 = tmp_list1->next;
1068 g_slist_free (rc_style->rc_style_lists);
1070 if (rc_style->rc_properties)
1074 for (i = 0; i < rc_style->rc_properties->n_nodes; i++)
1076 GtkRcProperty *node = g_bsearch_array_get_nth (rc_style->rc_properties, i);
1078 g_free (node->origin);
1079 g_value_unset (&node->value);
1081 g_bsearch_array_destroy (rc_style->rc_properties);
1082 rc_style->rc_properties = NULL;
1085 tmp_list1 = rc_style->icon_factories;
1088 g_object_unref (G_OBJECT (tmp_list1->data));
1090 tmp_list1 = tmp_list1->next;
1092 g_slist_free (rc_style->icon_factories);
1094 G_OBJECT_CLASS (parent_class)->finalize (object);
1098 gtk_rc_style_new (void)
1102 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1108 * gtk_rc_style_copy:
1109 * @orig: the style to copy
1111 * Make a copy of the specified #GtkRcStyle. This function
1112 * will correctly copy an rc style that is a member of a class
1113 * derived from #GtkRcStyle.
1115 * Return value: the resulting #GtkRcStyle
1118 gtk_rc_style_copy (GtkRcStyle *orig)
1122 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1124 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1125 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1131 gtk_rc_style_ref (GtkRcStyle *rc_style)
1133 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1135 g_object_ref (G_OBJECT (rc_style));
1139 gtk_rc_style_unref (GtkRcStyle *rc_style)
1141 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1143 g_object_unref (G_OBJECT (rc_style));
1147 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1149 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1153 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1154 gconstpointer bsearch_node2)
1156 const GtkRcProperty *prop1 = bsearch_node1;
1157 const GtkRcProperty *prop2 = bsearch_node2;
1160 cmp = G_BSEARCH_ARRAY_CMP (prop1->type_name, prop2->type_name);
1162 cmp = G_BSEARCH_ARRAY_CMP (prop1->property_name, prop2->property_name);
1168 gtk_rc_style_real_merge (GtkRcStyle *dest,
1173 for (i = 0; i < 5; i++)
1175 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1176 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1178 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1179 src->color_flags[i] & GTK_RC_FG)
1181 dest->fg[i] = src->fg[i];
1182 dest->color_flags[i] |= GTK_RC_FG;
1184 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1185 src->color_flags[i] & GTK_RC_BG)
1187 dest->bg[i] = src->bg[i];
1188 dest->color_flags[i] |= GTK_RC_BG;
1190 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1191 src->color_flags[i] & GTK_RC_TEXT)
1193 dest->text[i] = src->text[i];
1194 dest->color_flags[i] |= GTK_RC_TEXT;
1196 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1197 src->color_flags[i] & GTK_RC_BASE)
1199 dest->base[i] = src->base[i];
1200 dest->color_flags[i] |= GTK_RC_BASE;
1204 if (dest->xthickness < 0 && src->xthickness >= 0)
1205 dest->xthickness = src->xthickness;
1206 if (dest->ythickness < 0 && src->ythickness >= 0)
1207 dest->ythickness = src->ythickness;
1209 if (!dest->font_desc && src->font_desc)
1210 dest->font_desc = pango_font_description_copy (src->font_desc);
1212 if (src->rc_properties)
1216 if (!dest->rc_properties)
1217 dest->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
1218 gtk_rc_properties_cmp,
1220 for (i = 0; i < src->rc_properties->n_nodes; i++)
1222 GtkRcProperty *node = g_bsearch_array_get_nth (src->rc_properties, i);
1223 GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
1225 key.type_name = node->type_name;
1226 key.property_name = node->property_name;
1227 prop = g_bsearch_array_insert (dest->rc_properties, &key, FALSE);
1230 prop->origin = g_strdup (node->origin);
1231 g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
1232 g_value_copy (&node->value, &prop->value);
1239 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1241 return gtk_style_new ();
1245 gtk_rc_clear_hash_node (gpointer key,
1249 gtk_rc_style_unref (data);
1253 gtk_rc_free_rc_sets (GSList *slist)
1259 rc_set = slist->data;
1260 g_pattern_spec_free (rc_set->pspec);
1263 slist = slist->next;
1268 gtk_rc_clear_styles (GtkRcContext *context)
1270 /* Clear out all old rc_styles */
1272 if (context->rc_style_ht)
1274 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1275 g_hash_table_destroy (context->rc_style_ht);
1276 context->rc_style_ht = NULL;
1279 gtk_rc_free_rc_sets (context->rc_sets_widget);
1280 g_slist_free (context->rc_sets_widget);
1281 context->rc_sets_widget = NULL;
1283 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1284 g_slist_free (context->rc_sets_widget_class);
1285 context->rc_sets_widget_class = NULL;
1287 gtk_rc_free_rc_sets (context->rc_sets_class);
1288 g_slist_free (context->rc_sets_class);
1289 context->rc_sets_class = NULL;
1292 /* Reset all our widgets. Also, we have to invalidate cached icons in
1293 * icon sets so they get re-rendered.
1296 gtk_rc_reset_widgets (GtkRcContext *context)
1298 GList *list, *toplevels;
1300 _gtk_icon_set_invalidate_caches ();
1302 toplevels = gtk_window_list_toplevels ();
1303 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1305 for (list = toplevels; list; list = list->next)
1307 gtk_widget_reset_rc_styles (list->data);
1308 gtk_widget_unref (list->data);
1310 g_list_free (toplevels);
1314 * gtk_rc_reparse_all_for_settings:
1315 * @settings: a #GtkSettings
1316 * @force_load: load whether or not anything changed
1318 * If the modification time on any previously read file
1319 * for the given GtkSettings has changed, discard all style information
1320 * and then reread all previously read RC files.
1322 * Return value: %TRUE if the files were reread.
1325 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1326 gboolean force_load)
1328 gboolean mtime_modified = FALSE;
1331 GtkRcContext *context;
1333 struct stat statbuf;
1335 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1337 context = gtk_rc_context_get (settings);
1341 /* Check through and see if any of the RC's have had their
1342 * mtime modified. If so, reparse everything.
1344 tmp_list = context->rc_files;
1347 rc_file = tmp_list->data;
1349 if (!lstat (rc_file->name, &statbuf) &&
1350 (statbuf.st_mtime > rc_file->mtime))
1352 mtime_modified = TRUE;
1356 tmp_list = tmp_list->next;
1360 if (force_load || mtime_modified)
1364 gtk_rc_clear_styles (context);
1365 g_object_freeze_notify (G_OBJECT (context->settings));
1367 old_files = context->rc_files;
1368 context->rc_files = NULL;
1370 gtk_rc_parse_default_files (context);
1372 tmp_list = old_files;
1375 rc_file = tmp_list->data;
1376 if (rc_file->reload)
1377 gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
1379 if (rc_file->canonical_name != rc_file->name)
1380 g_free (rc_file->canonical_name);
1381 g_free (rc_file->name);
1384 tmp_list = tmp_list->next;
1387 g_slist_free (old_files);;
1389 g_free (context->theme_name);
1390 g_free (context->key_theme_name);
1391 g_object_get (context->settings,
1392 "gtk-theme-name", &context->theme_name,
1393 "gtk-key-theme-name", &context->key_theme_name,
1396 if (context->theme_name && context->theme_name[0])
1397 gtk_rc_parse_named (context, context->theme_name, NULL);
1398 if (context->key_theme_name && context->key_theme_name[0])
1399 gtk_rc_parse_named (context, context->key_theme_name, "key");
1401 g_object_thaw_notify (G_OBJECT (context->settings));
1403 gtk_rc_reset_widgets (context);
1406 return mtime_modified;
1410 * gtk_rc_reparse_all:
1412 * If the modification time on any previously read file for the
1413 * default #GtkSettings has changed, discard all style information
1414 * and then reread all previously read RC files.
1416 * Return value: %TRUE if the files were reread.
1419 gtk_rc_reparse_all (void)
1421 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1425 gtk_rc_styles_match (GSList *rc_styles,
1429 const gchar *path_reversed)
1436 rc_set = sets->data;
1439 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1440 rc_styles = g_slist_append (rc_styles, rc_set->rc_style);
1448 * @widget: a #GtkWidget
1450 * Finds all matching RC styles for a given widget,
1451 * composites them together, and then creates a
1452 * #GtkStyle representing the composite appearance.
1453 * (GTK+ actually keeps a cache of previously
1454 * created styles, so a new style may not be
1457 * @Returns: the resulting style. No refcount is added
1458 * to the returned style, so if you want to save this
1459 * style around, you should add a reference yourself.
1462 gtk_rc_get_style (GtkWidget *widget)
1464 GtkRcStyle *widget_rc_style;
1465 GSList *rc_styles = NULL;
1466 GtkRcContext *context;
1468 static guint rc_style_key_id = 0;
1470 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1472 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1474 /* We allow the specification of a single rc style to be bound
1475 * tightly to a widget, for application modifications
1477 if (!rc_style_key_id)
1478 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1480 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1483 if (widget_rc_style)
1484 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1486 if (context->rc_sets_widget)
1488 gchar *path, *path_reversed;
1491 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1492 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1494 g_free (path_reversed);
1497 if (context->rc_sets_widget_class)
1499 gchar *path, *path_reversed;
1502 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1503 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1505 g_free (path_reversed);
1508 if (context->rc_sets_class)
1512 type = GTK_OBJECT_TYPE (widget);
1516 gchar *path_reversed;
1519 path = gtk_type_name (type);
1520 path_length = strlen (path);
1521 path_reversed = g_strdup (path);
1522 g_strreverse (path_reversed);
1524 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1525 g_free (path_reversed);
1527 type = gtk_type_parent (type);
1532 return gtk_rc_init_style (rc_styles);
1538 * gtk_rc_get_style_by_paths:
1539 * @settings: a #GtkSettings object
1540 * @widget_path: the widget path to use when looking up the style, or %NULL
1541 * @class_path: the class path to use when looking up the style, or %NULL
1542 * @type: a type that will be used along with parent types of this type
1543 * when matching against class styles, or G_TYPE_NONE
1545 * Creates up a #GtkStyle from styles defined in a RC file by providing
1546 * the raw components used in matching. This function may be useful
1547 * when creating pseudo-widgets that should be themed like widgets but
1548 * don't actually have corresponding GTK+ widgets. An example of this
1549 * would be items inside a GNOME canvas widget.
1551 * The action of gtk_rc_get_style() is similar to:
1553 * gtk_widget_path (widget, NULL, &path, NULL);
1554 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1555 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1556 * G_OBJECT_TYPE (widget));
1558 * Return value: A style created by matching with the supplied paths,
1559 * or %NULL if nothign matching was specified and the default style should
1560 * be used. The returned value is owned by GTK+ as part of an internal cache,
1561 * so you must call g_object_ref() on the returned value if you want to
1562 * keep a reference to it.
1565 gtk_rc_get_style_by_paths (GtkSettings *settings,
1566 const char *widget_path,
1567 const char *class_path,
1570 /* We duplicate the code from above to avoid slowing down the above
1571 * by generating paths when we don't need them. I don't know if
1572 * this is really worth it.
1574 GSList *rc_styles = NULL;
1575 GtkRcContext *context;
1577 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1579 context = gtk_rc_context_get (settings);
1581 if (context->rc_sets_widget)
1583 gchar *path_reversed;
1586 path_length = strlen (widget_path);
1587 path_reversed = g_strdup (widget_path);
1588 g_strreverse (path_reversed);
1590 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1591 g_free (path_reversed);
1594 if (context->rc_sets_widget_class)
1596 gchar *path_reversed;
1599 path_length = strlen (class_path);
1600 path_reversed = g_strdup (class_path);
1601 g_strreverse (path_reversed);
1603 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1604 g_free (path_reversed);
1607 if (type != G_TYPE_NONE && context->rc_sets_class)
1612 gchar *path_reversed;
1615 path = g_type_name (type);
1616 path_length = strlen (path);
1617 path_reversed = g_strdup (path);
1618 g_strreverse (path_reversed);
1620 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1621 g_free (path_reversed);
1623 type = g_type_parent (type);
1628 return gtk_rc_init_style (rc_styles);
1634 gtk_rc_add_rc_sets (GSList *slist,
1635 GtkRcStyle *rc_style,
1636 const gchar *pattern)
1638 GtkRcStyle *new_style;
1642 new_style = gtk_rc_style_new ();
1643 *new_style = *rc_style;
1644 new_style->name = g_strdup (rc_style->name);
1645 if (rc_style->font_desc)
1646 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1648 for (i = 0; i < 5; i++)
1649 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1651 rc_set = g_new (GtkRcSet, 1);
1652 rc_set->pspec = g_pattern_spec_new (pattern);
1653 rc_set->rc_style = rc_style;
1655 return g_slist_prepend (slist, rc_set);
1659 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1660 const gchar *pattern)
1662 GtkRcContext *context;
1664 g_return_if_fail (rc_style != NULL);
1665 g_return_if_fail (pattern != NULL);
1667 context = gtk_rc_context_get (gtk_settings_get_default ());
1669 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1673 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1674 const gchar *pattern)
1676 GtkRcContext *context;
1678 g_return_if_fail (rc_style != NULL);
1679 g_return_if_fail (pattern != NULL);
1681 context = gtk_rc_context_get (gtk_settings_get_default ());
1683 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1687 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1688 const gchar *pattern)
1690 GtkRcContext *context;
1692 g_return_if_fail (rc_style != NULL);
1693 g_return_if_fail (pattern != NULL);
1695 context = gtk_rc_context_get (gtk_settings_get_default ());
1697 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1701 gtk_rc_scanner_new (void)
1703 return g_scanner_new (>k_rc_scanner_config);
1707 gtk_rc_parse_any (GtkRcContext *context,
1708 const gchar *input_name,
1710 const gchar *input_string)
1716 scanner = gtk_rc_scanner_new ();
1720 g_assert (input_string == NULL);
1722 g_scanner_input_file (scanner, input_fd);
1726 g_assert (input_string != NULL);
1728 g_scanner_input_text (scanner, input_string, strlen (input_string));
1730 scanner->input_name = input_name;
1732 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1733 g_scanner_add_symbol (scanner, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1738 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1742 guint expected_token;
1744 expected_token = gtk_rc_parse_statement (context, scanner);
1746 if (expected_token != G_TOKEN_NONE)
1753 if (scanner->scope_id == 0)
1755 /* if we are in scope 0, we know the symbol names
1756 * that are associated with certaintoken values.
1757 * so we look them up to make the error messages
1760 if (expected_token > GTK_RC_TOKEN_INVALID &&
1761 expected_token < GTK_RC_TOKEN_LAST)
1763 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1764 if (symbols[i].token == expected_token)
1765 msg = symbols[i].name;
1767 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1769 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1770 scanner->token < GTK_RC_TOKEN_LAST)
1772 symbol_name = "???";
1773 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1774 if (symbols[i].token == scanner->token)
1775 symbol_name = symbols[i].name;
1778 g_scanner_unexp_token (scanner,
1791 g_scanner_destroy (scanner);
1795 gtk_rc_styles_hash (const GSList *rc_styles)
1802 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1803 rc_styles = rc_styles->next;
1810 gtk_rc_styles_equal (const GSList *a,
1815 if (a->data != b->data)
1825 gtk_rc_style_hash (const gchar *name)
1831 result += (result << 3) + *name++;
1837 gtk_rc_style_equal (const gchar *a,
1840 return (strcmp (a, b) == 0);
1844 gtk_rc_style_find (GtkRcContext *context,
1847 if (context->rc_style_ht)
1848 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1854 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1858 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1860 style->rc_style = rc_style;
1862 gtk_rc_style_ref (rc_style);
1864 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1869 /* Reuses or frees rc_styles */
1871 gtk_rc_init_style (GSList *rc_styles)
1873 GtkStyle *style = NULL;
1876 g_return_val_if_fail (rc_styles != NULL, NULL);
1878 if (!realized_style_ht)
1879 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1880 (GEqualFunc) gtk_rc_styles_equal);
1882 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1886 GtkRcStyle *base_style = NULL;
1887 GtkRcStyle *proto_style;
1888 GtkRcStyleClass *proto_style_class;
1890 GType rc_style_type = GTK_TYPE_RC_STYLE;
1892 /* Find the first derived style in the list, and use that to
1893 * create the merged style. If we only have raw GtkRcStyles, use
1894 * the first style to create the merged style.
1896 base_style = rc_styles->data;
1897 tmp_styles = rc_styles;
1900 GtkRcStyle *rc_style = tmp_styles->data;
1902 if (G_OBJECT_TYPE (rc_style) != rc_style_type)
1904 base_style = rc_style;
1908 tmp_styles = tmp_styles->next;
1911 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1912 proto_style = proto_style_class->create_rc_style (base_style);
1914 tmp_styles = rc_styles;
1917 GtkRcStyle *rc_style = tmp_styles->data;
1920 proto_style_class->merge (proto_style, rc_style);
1922 /* Point from each rc_style to the list of styles */
1923 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1924 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1926 factories = g_slist_copy (rc_style->icon_factories);
1932 while (iter != NULL)
1934 g_object_ref (G_OBJECT (iter->data));
1935 iter = g_slist_next (iter);
1938 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1943 tmp_styles = tmp_styles->next;
1946 for (i = 0; i < 5; i++)
1947 if (proto_style->bg_pixmap_name[i] &&
1948 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
1950 g_free (proto_style->bg_pixmap_name[i]);
1951 proto_style->bg_pixmap_name[i] = NULL;
1954 style = gtk_rc_style_to_style (proto_style);
1955 gtk_rc_style_unref (proto_style);
1957 g_hash_table_insert (realized_style_ht, rc_styles, style);
1960 g_slist_free (rc_styles);
1965 /*********************
1966 * Parsing functions *
1967 *********************/
1970 rc_parse_token_or_compound (GScanner *scanner,
1972 GTokenType delimiter)
1974 guint token = g_scanner_get_next_token (scanner);
1976 /* we either scan a single token (skipping comments)
1977 * or a compund statement.
1978 * compunds are enclosed in (), [] or {} braces, we read
1979 * them in via deep recursion.
1986 g_string_printfa (gstring, " 0x%lx", scanner->value.v_int);
1989 g_string_printfa (gstring, " %f", scanner->value.v_float);
1991 case G_TOKEN_STRING:
1992 string = g_strescape (scanner->value.v_string, NULL);
1993 g_string_append (gstring, " \"");
1994 g_string_append (gstring, string);
1995 g_string_append_c (gstring, '"');
1998 case G_TOKEN_IDENTIFIER:
1999 g_string_append_c (gstring, ' ');
2000 g_string_append (gstring, scanner->value.v_identifier);
2002 case G_TOKEN_COMMENT_SINGLE:
2003 case G_TOKEN_COMMENT_MULTI:
2004 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2005 case G_TOKEN_LEFT_PAREN:
2006 g_string_append_c (gstring, ' ');
2007 g_string_append_c (gstring, token);
2008 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2009 if (token != G_TOKEN_NONE)
2012 case G_TOKEN_LEFT_CURLY:
2013 g_string_append_c (gstring, ' ');
2014 g_string_append_c (gstring, token);
2015 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2016 if (token != G_TOKEN_NONE)
2019 case G_TOKEN_LEFT_BRACE:
2020 g_string_append_c (gstring, ' ');
2021 g_string_append_c (gstring, token);
2022 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2023 if (token != G_TOKEN_NONE)
2027 if (token >= 256 || token < 1)
2028 return delimiter ? delimiter : G_TOKEN_STRING;
2029 g_string_append_c (gstring, ' ');
2030 g_string_append_c (gstring, token);
2031 if (token == delimiter)
2032 return G_TOKEN_NONE;
2036 return G_TOKEN_NONE;
2038 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2042 gtk_rc_parse_assignment (GScanner *scanner,
2043 GtkRcProperty *prop)
2045 gboolean scan_identifier = scanner->config->scan_identifier;
2046 gboolean scan_symbols = scanner->config->scan_symbols;
2047 gboolean identifier_2_string = scanner->config->identifier_2_string;
2048 gboolean char_2_token = scanner->config->char_2_token;
2049 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2050 gboolean numbers_2_int = scanner->config->numbers_2_int;
2051 gboolean negate = FALSE;
2054 /* check that this is an assignment */
2055 if (g_scanner_get_next_token (scanner) != '=')
2058 /* adjust scanner mode */
2059 scanner->config->scan_identifier = TRUE;
2060 scanner->config->scan_symbols = FALSE;
2061 scanner->config->identifier_2_string = FALSE;
2062 scanner->config->char_2_token = TRUE;
2063 scanner->config->scan_identifier_NULL = FALSE;
2064 scanner->config->numbers_2_int = TRUE;
2066 /* record location */
2067 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2069 /* parse optional sign */
2070 if (g_scanner_peek_next_token (scanner) == '-')
2072 g_scanner_get_next_token (scanner); /* eat sign */
2076 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2077 token = g_scanner_peek_next_token (scanner);
2081 g_scanner_get_next_token (scanner);
2082 g_value_init (&prop->value, G_TYPE_LONG);
2083 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2084 token = G_TOKEN_NONE;
2087 g_scanner_get_next_token (scanner);
2088 g_value_init (&prop->value, G_TYPE_DOUBLE);
2089 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2090 token = G_TOKEN_NONE;
2092 case G_TOKEN_STRING:
2093 g_scanner_get_next_token (scanner);
2095 token = G_TOKEN_INT;
2098 g_value_init (&prop->value, G_TYPE_STRING);
2099 g_value_set_string (&prop->value, scanner->value.v_string);
2100 token = G_TOKEN_NONE;
2103 case G_TOKEN_IDENTIFIER:
2104 case G_TOKEN_LEFT_PAREN:
2105 case G_TOKEN_LEFT_CURLY:
2106 case G_TOKEN_LEFT_BRACE:
2109 GString *gstring = g_string_new ("");
2111 token = rc_parse_token_or_compound (scanner, gstring, 0);
2112 if (token == G_TOKEN_NONE)
2114 g_string_append_c (gstring, ' ');
2115 g_value_init (&prop->value, G_TYPE_GSTRING);
2116 g_value_set_static_boxed (&prop->value, gstring);
2119 g_string_free (gstring, TRUE);
2124 g_scanner_get_next_token (scanner);
2125 token = G_TOKEN_INT;
2129 /* restore scanner mode */
2130 scanner->config->scan_identifier = scan_identifier;
2131 scanner->config->scan_symbols = scan_symbols;
2132 scanner->config->identifier_2_string = identifier_2_string;
2133 scanner->config->char_2_token = char_2_token;
2134 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2135 scanner->config->numbers_2_int = numbers_2_int;
2141 is_c_identifier (const gchar *string)
2144 gboolean is_varname;
2146 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2147 for (p = string + 1; *p && is_varname; p++)
2148 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2154 gtk_rc_parse_statement (GtkRcContext *context,
2159 token = g_scanner_peek_next_token (scanner);
2162 case GTK_RC_TOKEN_INCLUDE:
2163 token = g_scanner_get_next_token (scanner);
2164 if (token != GTK_RC_TOKEN_INCLUDE)
2165 return GTK_RC_TOKEN_INCLUDE;
2166 token = g_scanner_get_next_token (scanner);
2167 if (token != G_TOKEN_STRING)
2168 return G_TOKEN_STRING;
2169 gtk_rc_parse_file (context, scanner->value.v_string, context->default_priority, FALSE);
2170 return G_TOKEN_NONE;
2172 case GTK_RC_TOKEN_STYLE:
2173 return gtk_rc_parse_style (context, scanner);
2175 case GTK_RC_TOKEN_BINDING:
2176 return gtk_binding_parse_binding (scanner);
2178 case GTK_RC_TOKEN_PIXMAP_PATH:
2179 return gtk_rc_parse_pixmap_path (context, scanner);
2181 case GTK_RC_TOKEN_WIDGET:
2182 return gtk_rc_parse_path_pattern (context, scanner);
2184 case GTK_RC_TOKEN_WIDGET_CLASS:
2185 return gtk_rc_parse_path_pattern (context, scanner);
2187 case GTK_RC_TOKEN_CLASS:
2188 return gtk_rc_parse_path_pattern (context, scanner);
2190 case GTK_RC_TOKEN_MODULE_PATH:
2191 return gtk_rc_parse_module_path (scanner);
2193 case GTK_RC_TOKEN_IM_MODULE_PATH:
2194 return gtk_rc_parse_im_module_path (scanner);
2196 case GTK_RC_TOKEN_IM_MODULE_FILE:
2197 return gtk_rc_parse_im_module_file (scanner);
2199 case G_TOKEN_IDENTIFIER:
2200 if (is_c_identifier (scanner->next_value.v_identifier))
2202 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2205 g_scanner_get_next_token (scanner); /* eat identifier */
2206 name = g_strdup (scanner->value.v_identifier);
2208 token = gtk_rc_parse_assignment (scanner, &prop);
2209 if (token == G_TOKEN_NONE)
2211 GtkSettingsValue svalue;
2213 svalue.origin = prop.origin;
2214 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2215 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2216 gtk_settings_set_property_value (context->settings,
2220 g_free (prop.origin);
2221 if (G_VALUE_TYPE (&prop.value))
2222 g_value_unset (&prop.value);
2229 g_scanner_get_next_token (scanner);
2230 return G_TOKEN_IDENTIFIER;
2233 g_scanner_get_next_token (scanner);
2234 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2239 gtk_rc_parse_style (GtkRcContext *context,
2242 GtkRcStyle *rc_style;
2243 GtkRcStyle *parent_style;
2247 GtkIconFactory *our_factory = NULL;
2249 token = g_scanner_get_next_token (scanner);
2250 if (token != GTK_RC_TOKEN_STYLE)
2251 return GTK_RC_TOKEN_STYLE;
2253 token = g_scanner_get_next_token (scanner);
2254 if (token != G_TOKEN_STRING)
2255 return G_TOKEN_STRING;
2258 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2260 /* If there's a list, its first member is always the factory belonging
2263 if (rc_style && rc_style->icon_factories)
2264 our_factory = rc_style->icon_factories->data;
2269 rc_style = gtk_rc_style_new ();
2270 rc_style->name = g_strdup (scanner->value.v_string);
2272 for (i = 0; i < 5; i++)
2273 rc_style->bg_pixmap_name[i] = NULL;
2275 for (i = 0; i < 5; i++)
2276 rc_style->color_flags[i] = 0;
2279 token = g_scanner_peek_next_token (scanner);
2280 if (token == G_TOKEN_EQUAL_SIGN)
2282 token = g_scanner_get_next_token (scanner);
2284 token = g_scanner_get_next_token (scanner);
2285 if (token != G_TOKEN_STRING)
2290 return G_TOKEN_STRING;
2293 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2298 for (i = 0; i < 5; i++)
2300 rc_style->color_flags[i] = parent_style->color_flags[i];
2301 rc_style->fg[i] = parent_style->fg[i];
2302 rc_style->bg[i] = parent_style->bg[i];
2303 rc_style->text[i] = parent_style->text[i];
2304 rc_style->base[i] = parent_style->base[i];
2307 rc_style->xthickness = parent_style->xthickness;
2308 rc_style->ythickness = parent_style->ythickness;
2310 if (parent_style->font_desc)
2312 if (rc_style->font_desc)
2313 pango_font_description_free (rc_style->font_desc);
2314 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2317 if (parent_style->rc_properties)
2321 if (!rc_style->rc_properties)
2322 rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
2323 gtk_rc_properties_cmp,
2325 for (i = 0; i < parent_style->rc_properties->n_nodes; i++)
2327 GtkRcProperty *node = g_bsearch_array_get_nth (parent_style->rc_properties, i);
2328 GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
2330 key.type_name = node->type_name;
2331 key.property_name = node->property_name;
2332 prop = g_bsearch_array_insert (rc_style->rc_properties, &key, FALSE);
2335 g_free (prop->origin);
2336 g_value_unset (&prop->value);
2338 prop->origin = g_strdup (node->origin);
2339 g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
2340 g_value_copy (&node->value, &prop->value);
2344 for (i = 0; i < 5; i++)
2346 if (rc_style->bg_pixmap_name[i])
2347 g_free (rc_style->bg_pixmap_name[i]);
2348 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2351 /* Append parent's factories, adding a ref to them */
2352 if (parent_style->icon_factories != NULL)
2354 /* Add a factory for ourselves if we have none,
2355 * in case we end up defining more stock icons.
2356 * I see no real way around this; we need to maintain
2357 * the invariant that the first factory in the list
2358 * is always our_factory, the one belonging to us,
2359 * and if we put parent factories in the list we can't
2360 * do that if the style is reopened.
2362 if (our_factory == NULL)
2364 our_factory = gtk_icon_factory_new ();
2365 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2369 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2370 g_slist_copy (parent_style->icon_factories));
2372 factories = parent_style->icon_factories;
2373 while (factories != NULL)
2375 g_object_ref (G_OBJECT (factories->data));
2376 factories = factories->next;
2382 token = g_scanner_get_next_token (scanner);
2383 if (token != G_TOKEN_LEFT_CURLY)
2388 return G_TOKEN_LEFT_CURLY;
2391 token = g_scanner_peek_next_token (scanner);
2392 while (token != G_TOKEN_RIGHT_CURLY)
2396 case GTK_RC_TOKEN_BG:
2397 token = gtk_rc_parse_bg (scanner, rc_style);
2399 case GTK_RC_TOKEN_FG:
2400 token = gtk_rc_parse_fg (scanner, rc_style);
2402 case GTK_RC_TOKEN_TEXT:
2403 token = gtk_rc_parse_text (scanner, rc_style);
2405 case GTK_RC_TOKEN_BASE:
2406 token = gtk_rc_parse_base (scanner, rc_style);
2408 case GTK_RC_TOKEN_XTHICKNESS:
2409 token = gtk_rc_parse_xthickness (scanner, rc_style);
2411 case GTK_RC_TOKEN_YTHICKNESS:
2412 token = gtk_rc_parse_ythickness (scanner, rc_style);
2414 case GTK_RC_TOKEN_BG_PIXMAP:
2415 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2417 case GTK_RC_TOKEN_FONT:
2418 token = gtk_rc_parse_font (scanner, rc_style);
2420 case GTK_RC_TOKEN_FONTSET:
2421 token = gtk_rc_parse_fontset (scanner, rc_style);
2423 case GTK_RC_TOKEN_FONT_NAME:
2424 token = gtk_rc_parse_font_name (scanner, rc_style);
2426 case GTK_RC_TOKEN_ENGINE:
2427 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2429 case GTK_RC_TOKEN_STOCK:
2430 if (our_factory == NULL)
2432 our_factory = gtk_icon_factory_new ();
2433 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2436 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2438 case G_TOKEN_IDENTIFIER:
2439 if (is_c_identifier (scanner->next_value.v_identifier) &&
2440 scanner->next_value.v_identifier[0] >= 'A' &&
2441 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2443 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2445 g_scanner_get_next_token (scanner); /* eat type name */
2446 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2447 if (g_scanner_get_next_token (scanner) != ':' ||
2448 g_scanner_get_next_token (scanner) != ':')
2453 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2454 !is_c_identifier (scanner->value.v_identifier))
2456 token = G_TOKEN_IDENTIFIER;
2460 /* it's important that we do the same canonification as GParamSpecPool here */
2461 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2462 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2464 token = gtk_rc_parse_assignment (scanner, &prop);
2465 if (token == G_TOKEN_NONE)
2469 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2471 if (!rc_style->rc_properties)
2472 rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
2473 gtk_rc_properties_cmp,
2475 tmp = g_bsearch_array_insert (rc_style->rc_properties, &prop, FALSE);
2476 if (prop.origin != tmp->origin)
2478 g_free (tmp->origin);
2479 g_value_unset (&tmp->value);
2480 tmp->origin = prop.origin;
2481 memcpy (&tmp->value, &prop.value, sizeof (prop.value));
2486 g_free (prop.origin);
2487 if (G_VALUE_TYPE (&prop.value))
2488 g_value_unset (&prop.value);
2493 g_scanner_get_next_token (scanner);
2494 token = G_TOKEN_IDENTIFIER;
2498 g_scanner_get_next_token (scanner);
2499 token = G_TOKEN_RIGHT_CURLY;
2503 if (token != G_TOKEN_NONE)
2506 gtk_rc_style_unref (rc_style);
2510 token = g_scanner_peek_next_token (scanner);
2511 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2513 token = g_scanner_get_next_token (scanner);
2514 if (token != G_TOKEN_RIGHT_CURLY)
2518 if (rc_style->font_desc)
2519 pango_font_description_free (rc_style->font_desc);
2521 for (i = 0; i < 5; i++)
2522 if (rc_style->bg_pixmap_name[i])
2523 g_free (rc_style->bg_pixmap_name[i]);
2527 return G_TOKEN_RIGHT_CURLY;
2532 if (!context->rc_style_ht)
2533 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2534 (GEqualFunc) gtk_rc_style_equal);
2536 g_hash_table_insert (context->rc_style_ht, rc_style->name, rc_style);
2539 return G_TOKEN_NONE;
2542 const GtkRcProperty*
2543 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2545 GQuark property_name)
2547 GtkRcProperty *node = NULL;
2549 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2551 if (rc_style->rc_properties)
2555 key.type_name = type_name;
2556 key.property_name = property_name;
2558 node = g_bsearch_array_lookup (rc_style->rc_properties, &key);
2565 gtk_rc_parse_bg (GScanner *scanner,
2571 token = g_scanner_get_next_token (scanner);
2572 if (token != GTK_RC_TOKEN_BG)
2573 return GTK_RC_TOKEN_BG;
2575 token = gtk_rc_parse_state (scanner, &state);
2576 if (token != G_TOKEN_NONE)
2579 token = g_scanner_get_next_token (scanner);
2580 if (token != G_TOKEN_EQUAL_SIGN)
2581 return G_TOKEN_EQUAL_SIGN;
2583 style->color_flags[state] |= GTK_RC_BG;
2584 return gtk_rc_parse_color (scanner, &style->bg[state]);
2588 gtk_rc_parse_fg (GScanner *scanner,
2594 token = g_scanner_get_next_token (scanner);
2595 if (token != GTK_RC_TOKEN_FG)
2596 return GTK_RC_TOKEN_FG;
2598 token = gtk_rc_parse_state (scanner, &state);
2599 if (token != G_TOKEN_NONE)
2602 token = g_scanner_get_next_token (scanner);
2603 if (token != G_TOKEN_EQUAL_SIGN)
2604 return G_TOKEN_EQUAL_SIGN;
2606 style->color_flags[state] |= GTK_RC_FG;
2607 return gtk_rc_parse_color (scanner, &style->fg[state]);
2611 gtk_rc_parse_text (GScanner *scanner,
2617 token = g_scanner_get_next_token (scanner);
2618 if (token != GTK_RC_TOKEN_TEXT)
2619 return GTK_RC_TOKEN_TEXT;
2621 token = gtk_rc_parse_state (scanner, &state);
2622 if (token != G_TOKEN_NONE)
2625 token = g_scanner_get_next_token (scanner);
2626 if (token != G_TOKEN_EQUAL_SIGN)
2627 return G_TOKEN_EQUAL_SIGN;
2629 style->color_flags[state] |= GTK_RC_TEXT;
2630 return gtk_rc_parse_color (scanner, &style->text[state]);
2634 gtk_rc_parse_base (GScanner *scanner,
2640 token = g_scanner_get_next_token (scanner);
2641 if (token != GTK_RC_TOKEN_BASE)
2642 return GTK_RC_TOKEN_BASE;
2644 token = gtk_rc_parse_state (scanner, &state);
2645 if (token != G_TOKEN_NONE)
2648 token = g_scanner_get_next_token (scanner);
2649 if (token != G_TOKEN_EQUAL_SIGN)
2650 return G_TOKEN_EQUAL_SIGN;
2652 style->color_flags[state] |= GTK_RC_BASE;
2653 return gtk_rc_parse_color (scanner, &style->base[state]);
2657 gtk_rc_parse_xthickness (GScanner *scanner,
2660 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2661 return GTK_RC_TOKEN_XTHICKNESS;
2663 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2664 return G_TOKEN_EQUAL_SIGN;
2666 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2669 style->xthickness = scanner->value.v_int;
2671 return G_TOKEN_NONE;
2675 gtk_rc_parse_ythickness (GScanner *scanner,
2678 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2679 return GTK_RC_TOKEN_YTHICKNESS;
2681 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2682 return G_TOKEN_EQUAL_SIGN;
2684 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2687 style->ythickness = scanner->value.v_int;
2689 return G_TOKEN_NONE;
2693 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2695 GtkRcStyle *rc_style)
2701 token = g_scanner_get_next_token (scanner);
2702 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2703 return GTK_RC_TOKEN_BG_PIXMAP;
2705 token = gtk_rc_parse_state (scanner, &state);
2706 if (token != G_TOKEN_NONE)
2709 token = g_scanner_get_next_token (scanner);
2710 if (token != G_TOKEN_EQUAL_SIGN)
2711 return G_TOKEN_EQUAL_SIGN;
2713 token = g_scanner_get_next_token (scanner);
2714 if (token != G_TOKEN_STRING)
2715 return G_TOKEN_STRING;
2717 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2718 (strcmp (scanner->value.v_string, "<none>") == 0))
2719 pixmap_file = g_strdup (scanner->value.v_string);
2721 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2722 scanner, scanner->value.v_string);
2726 if (rc_style->bg_pixmap_name[state])
2727 g_free (rc_style->bg_pixmap_name[state]);
2728 rc_style->bg_pixmap_name[state] = pixmap_file;
2731 return G_TOKEN_NONE;
2735 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2740 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s", dir, pixmap_file);
2742 fd = open (buf, O_RDONLY);
2755 * gtk_rc_context_find_pixmap_in_path:
2756 * @settings: a #GtkSettinsg
2757 * @scanner: Scanner used to get line number information for the
2758 * warning message, or %NULL
2759 * @pixmap_file: name of the pixmap file to locate.
2761 * Looks up a file in pixmap path for the specified #GtkSettings.
2762 * If the file is not found, it outputs a warning message using
2763 * g_warning() and returns %NULL.
2768 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2770 const gchar *pixmap_file)
2776 GtkRcContext *context = gtk_rc_context_get (settings);
2778 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2780 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2785 tmp_list = rc_dir_stack;
2788 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2792 tmp_list = tmp_list->next;
2796 g_warning (_("Unable to locate image file in pixmap_path: \"%s\" line %d"),
2797 pixmap_file, scanner->line);
2799 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2806 gtk_rc_find_module_in_path (const gchar *module_file)
2812 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2814 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s",
2815 module_path[i], module_file);
2817 fd = open (buf, O_RDONLY);
2831 gtk_rc_parse_font (GScanner *scanner,
2832 GtkRcStyle *rc_style)
2836 token = g_scanner_get_next_token (scanner);
2837 if (token != GTK_RC_TOKEN_FONT)
2838 return GTK_RC_TOKEN_FONT;
2840 token = g_scanner_get_next_token (scanner);
2841 if (token != G_TOKEN_EQUAL_SIGN)
2842 return G_TOKEN_EQUAL_SIGN;
2844 token = g_scanner_get_next_token (scanner);
2845 if (token != G_TOKEN_STRING)
2846 return G_TOKEN_STRING;
2848 /* Ignore, do nothing */
2850 return G_TOKEN_NONE;
2854 gtk_rc_parse_fontset (GScanner *scanner,
2855 GtkRcStyle *rc_style)
2859 token = g_scanner_get_next_token (scanner);
2860 if (token != GTK_RC_TOKEN_FONTSET)
2861 return GTK_RC_TOKEN_FONTSET;
2863 token = g_scanner_get_next_token (scanner);
2864 if (token != G_TOKEN_EQUAL_SIGN)
2865 return G_TOKEN_EQUAL_SIGN;
2867 token = g_scanner_get_next_token (scanner);
2868 if (token != G_TOKEN_STRING)
2869 return G_TOKEN_STRING;
2871 /* Do nothing - silently ignore */
2873 return G_TOKEN_NONE;
2877 gtk_rc_parse_font_name (GScanner *scanner,
2878 GtkRcStyle *rc_style)
2882 token = g_scanner_get_next_token (scanner);
2883 if (token != GTK_RC_TOKEN_FONT_NAME)
2884 return GTK_RC_TOKEN_FONT;
2886 token = g_scanner_get_next_token (scanner);
2887 if (token != G_TOKEN_EQUAL_SIGN)
2888 return G_TOKEN_EQUAL_SIGN;
2890 token = g_scanner_get_next_token (scanner);
2891 if (token != G_TOKEN_STRING)
2892 return G_TOKEN_STRING;
2894 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2896 return G_TOKEN_NONE;
2900 gtk_rc_parse_engine (GtkRcContext *context,
2902 GtkRcStyle **rc_style)
2905 GtkThemeEngine *engine;
2906 guint result = G_TOKEN_NONE;
2907 GtkRcStyle *new_style = NULL;
2908 gboolean parsed_curlies = FALSE;
2910 token = g_scanner_get_next_token (scanner);
2911 if (token != GTK_RC_TOKEN_ENGINE)
2912 return GTK_RC_TOKEN_ENGINE;
2914 token = g_scanner_get_next_token (scanner);
2915 if (token != G_TOKEN_STRING)
2916 return G_TOKEN_STRING;
2918 engine = gtk_theme_engine_get (scanner->value.v_string);
2920 token = g_scanner_get_next_token (scanner);
2921 if (token != G_TOKEN_LEFT_CURLY)
2922 return G_TOKEN_LEFT_CURLY;
2926 GtkRcStyleClass *new_class;
2928 new_style = gtk_theme_engine_create_rc_style (engine);
2929 g_type_module_unuse (G_TYPE_MODULE (engine));
2931 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
2933 new_class->merge (new_style, *rc_style);
2934 if ((*rc_style)->name)
2935 new_style->name = g_strdup ((*rc_style)->name);
2937 if (new_class->parse)
2939 parsed_curlies = TRUE;
2940 result = new_class->parse (new_style, context->settings, scanner);
2942 if (result != G_TOKEN_NONE)
2944 g_object_unref (G_OBJECT (new_style));
2950 if (!parsed_curlies)
2952 /* Skip over remainder, looking for nested {}'s
2956 result = G_TOKEN_RIGHT_CURLY;
2957 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
2959 if (token == G_TOKEN_LEFT_CURLY)
2961 else if (token == G_TOKEN_RIGHT_CURLY)
2966 result = G_TOKEN_NONE;
2974 g_object_unref (G_OBJECT (*rc_style));
2975 *rc_style = new_style;
2982 gtk_rc_parse_state (GScanner *scanner,
2983 GtkStateType *state)
2988 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2989 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
2991 /* we don't know where we got called from, so we reset the scope here.
2992 * if we bail out due to errors, we *don't* reset the scope, so the
2993 * error messaging code can make sense of our tokens.
2995 old_scope = g_scanner_set_scope (scanner, 0);
2997 token = g_scanner_get_next_token (scanner);
2998 if (token != G_TOKEN_LEFT_BRACE)
2999 return G_TOKEN_LEFT_BRACE;
3001 token = g_scanner_get_next_token (scanner);
3004 case GTK_RC_TOKEN_ACTIVE:
3005 *state = GTK_STATE_ACTIVE;
3007 case GTK_RC_TOKEN_INSENSITIVE:
3008 *state = GTK_STATE_INSENSITIVE;
3010 case GTK_RC_TOKEN_NORMAL:
3011 *state = GTK_STATE_NORMAL;
3013 case GTK_RC_TOKEN_PRELIGHT:
3014 *state = GTK_STATE_PRELIGHT;
3016 case GTK_RC_TOKEN_SELECTED:
3017 *state = GTK_STATE_SELECTED;
3020 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3023 token = g_scanner_get_next_token (scanner);
3024 if (token != G_TOKEN_RIGHT_BRACE)
3025 return G_TOKEN_RIGHT_BRACE;
3027 g_scanner_set_scope (scanner, old_scope);
3029 return G_TOKEN_NONE;
3033 gtk_rc_parse_priority (GScanner *scanner,
3034 GtkPathPriorityType *priority)
3039 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3040 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3042 /* we don't know where we got called from, so we reset the scope here.
3043 * if we bail out due to errors, we *don't* reset the scope, so the
3044 * error messaging code can make sense of our tokens.
3046 old_scope = g_scanner_set_scope (scanner, 0);
3048 token = g_scanner_get_next_token (scanner);
3052 token = g_scanner_get_next_token (scanner);
3055 case GTK_RC_TOKEN_LOWEST:
3056 *priority = GTK_PATH_PRIO_LOWEST;
3058 case GTK_RC_TOKEN_GTK:
3059 *priority = GTK_PATH_PRIO_GTK;
3061 case GTK_RC_TOKEN_APPLICATION:
3062 *priority = GTK_PATH_PRIO_APPLICATION;
3064 case GTK_RC_TOKEN_THEME:
3065 *priority = GTK_PATH_PRIO_THEME;
3067 case GTK_RC_TOKEN_RC:
3068 *priority = GTK_PATH_PRIO_RC;
3070 case GTK_RC_TOKEN_HIGHEST:
3071 *priority = GTK_PATH_PRIO_HIGHEST;
3074 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3077 g_scanner_set_scope (scanner, old_scope);
3079 return G_TOKEN_NONE;
3083 gtk_rc_parse_color (GScanner *scanner,
3088 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3090 /* we don't need to set our own scope here, because
3091 * we don't need own symbols
3094 token = g_scanner_get_next_token (scanner);
3099 case G_TOKEN_LEFT_CURLY:
3100 token = g_scanner_get_next_token (scanner);
3101 if (token == G_TOKEN_INT)
3102 token_int = scanner->value.v_int;
3103 else if (token == G_TOKEN_FLOAT)
3104 token_int = scanner->value.v_float * 65535.0;
3106 return G_TOKEN_FLOAT;
3107 color->red = CLAMP (token_int, 0, 65535);
3109 token = g_scanner_get_next_token (scanner);
3110 if (token != G_TOKEN_COMMA)
3111 return G_TOKEN_COMMA;
3113 token = g_scanner_get_next_token (scanner);
3114 if (token == G_TOKEN_INT)
3115 token_int = scanner->value.v_int;
3116 else if (token == G_TOKEN_FLOAT)
3117 token_int = scanner->value.v_float * 65535.0;
3119 return G_TOKEN_FLOAT;
3120 color->green = CLAMP (token_int, 0, 65535);
3122 token = g_scanner_get_next_token (scanner);
3123 if (token != G_TOKEN_COMMA)
3124 return G_TOKEN_COMMA;
3126 token = g_scanner_get_next_token (scanner);
3127 if (token == G_TOKEN_INT)
3128 token_int = scanner->value.v_int;
3129 else if (token == G_TOKEN_FLOAT)
3130 token_int = scanner->value.v_float * 65535.0;
3132 return G_TOKEN_FLOAT;
3133 color->blue = CLAMP (token_int, 0, 65535);
3135 token = g_scanner_get_next_token (scanner);
3136 if (token != G_TOKEN_RIGHT_CURLY)
3137 return G_TOKEN_RIGHT_CURLY;
3138 return G_TOKEN_NONE;
3140 case G_TOKEN_STRING:
3141 if (!gdk_color_parse (scanner->value.v_string, color))
3143 g_scanner_warn (scanner, "Invalid color constant '%s'",
3144 scanner->value.v_string);
3145 return G_TOKEN_STRING;
3148 return G_TOKEN_NONE;
3151 return G_TOKEN_STRING;
3156 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3161 token = g_scanner_get_next_token (scanner);
3162 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3163 return GTK_RC_TOKEN_PIXMAP_PATH;
3165 token = g_scanner_get_next_token (scanner);
3166 if (token != G_TOKEN_STRING)
3167 return G_TOKEN_STRING;
3169 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3171 return G_TOKEN_NONE;
3175 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3177 const gchar *pix_path)
3180 gint start_offset = 0;
3184 /* free the old one, or just add to the old one ? */
3185 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3187 g_free (context->pixmap_path[path_num]);
3188 context->pixmap_path[path_num] = NULL;
3193 path_len = strlen (pix_path);
3195 for (end_offset = 0; end_offset <= path_len; end_offset++)
3197 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3198 (end_offset == path_len))
3200 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3201 if (g_path_is_absolute (path_element))
3203 context->pixmap_path[path_num] = path_element;
3205 context->pixmap_path[path_num] = NULL;
3209 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3210 path_element, scanner->input_name, scanner->line);
3211 g_free (path_element);
3214 start_offset = end_offset + 1;
3220 gtk_rc_parse_module_path (GScanner *scanner)
3224 token = g_scanner_get_next_token (scanner);
3225 if (token != GTK_RC_TOKEN_MODULE_PATH)
3226 return GTK_RC_TOKEN_MODULE_PATH;
3228 token = g_scanner_get_next_token (scanner);
3229 if (token != G_TOKEN_STRING)
3230 return G_TOKEN_STRING;
3232 gtk_rc_parse_module_path_string (scanner->value.v_string);
3234 return G_TOKEN_NONE;
3238 gtk_rc_parse_im_module_path (GScanner *scanner)
3242 token = g_scanner_get_next_token (scanner);
3243 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3244 return GTK_RC_TOKEN_IM_MODULE_FILE;
3246 token = g_scanner_get_next_token (scanner);
3247 if (token != G_TOKEN_STRING)
3248 return G_TOKEN_STRING;
3251 g_free (im_module_path);
3253 im_module_path = g_strdup (scanner->value.v_string);
3255 return G_TOKEN_NONE;
3259 gtk_rc_parse_im_module_file (GScanner *scanner)
3263 token = g_scanner_get_next_token (scanner);
3264 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3265 return GTK_RC_TOKEN_IM_MODULE_FILE;
3267 token = g_scanner_get_next_token (scanner);
3268 if (token != G_TOKEN_STRING)
3269 return G_TOKEN_STRING;
3272 g_free (im_module_file);
3274 im_module_file = g_strdup (scanner->value.v_string);
3276 return G_TOKEN_NONE;
3280 gtk_rc_parse_module_path_string (const gchar *mod_path)
3283 gint start_offset = 0;
3287 /* free the old one, or just add to the old one ? */
3288 for (path_num=0; module_path[path_num]; path_num++)
3290 g_free (module_path[path_num]);
3291 module_path[path_num] = NULL;
3296 path_len = strlen (mod_path);
3298 for (end_offset = 0; end_offset <= path_len; end_offset++)
3300 if ((mod_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3301 (end_offset == path_len))
3303 module_path[path_num] = g_strndup (mod_path + start_offset, end_offset - start_offset);
3305 module_path[path_num] = NULL;
3306 start_offset = end_offset + 1;
3309 gtk_rc_append_default_module_path();
3313 rc_set_compare (gconstpointer a, gconstpointer b)
3315 const GtkRcSet *set_a = a;
3316 const GtkRcSet *set_b = b;
3318 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
3322 insert_rc_set (GSList *list, GtkRcSet *set)
3324 return g_slist_insert_sorted (list, set, rc_set_compare);
3328 gtk_rc_parse_path_pattern (GtkRcContext *context,
3332 GtkPathType path_type;
3334 gboolean is_binding;
3335 GtkPathPriorityType priority = context->default_priority;
3337 token = g_scanner_get_next_token (scanner);
3340 case GTK_RC_TOKEN_WIDGET:
3341 path_type = GTK_PATH_WIDGET;
3343 case GTK_RC_TOKEN_WIDGET_CLASS:
3344 path_type = GTK_PATH_WIDGET_CLASS;
3346 case GTK_RC_TOKEN_CLASS:
3347 path_type = GTK_PATH_CLASS;
3350 return GTK_RC_TOKEN_WIDGET_CLASS;
3353 token = g_scanner_get_next_token (scanner);
3354 if (token != G_TOKEN_STRING)
3355 return G_TOKEN_STRING;
3357 pattern = g_strdup (scanner->value.v_string);
3359 token = g_scanner_get_next_token (scanner);
3360 if (token == GTK_RC_TOKEN_STYLE)
3362 else if (token == GTK_RC_TOKEN_BINDING)
3367 return GTK_RC_TOKEN_STYLE;
3370 if (g_scanner_peek_next_token (scanner) == ':')
3372 token = gtk_rc_parse_priority (scanner, &priority);
3373 if (token != G_TOKEN_NONE)
3380 token = g_scanner_get_next_token (scanner);
3381 if (token != G_TOKEN_STRING)
3384 return G_TOKEN_STRING;
3389 GtkBindingSet *binding;
3391 binding = gtk_binding_set_find (scanner->value.v_string);
3395 return G_TOKEN_STRING;
3397 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3401 GtkRcStyle *rc_style;
3404 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3409 return G_TOKEN_STRING;
3412 rc_set = g_new (GtkRcSet, 1);
3413 rc_set->pspec = g_pattern_spec_new (pattern);
3414 rc_set->rc_style = rc_style;
3415 rc_set->priority = priority;
3417 if (path_type == GTK_PATH_WIDGET)
3418 context->rc_sets_widget = insert_rc_set (context->rc_sets_widget, rc_set);
3419 else if (path_type == GTK_PATH_WIDGET_CLASS)
3420 context->rc_sets_widget_class = insert_rc_set (context->rc_sets_widget_class, rc_set);
3422 context->rc_sets_class = insert_rc_set (context->rc_sets_class, rc_set);
3426 return G_TOKEN_NONE;
3430 gtk_rc_parse_stock_id (GScanner *scanner,
3435 token = g_scanner_get_next_token (scanner);
3436 if (token != G_TOKEN_LEFT_BRACE)
3437 return G_TOKEN_LEFT_BRACE;
3439 token = g_scanner_get_next_token (scanner);
3441 if (token != G_TOKEN_STRING)
3442 return G_TOKEN_STRING;
3444 *stock_id = g_strdup (scanner->value.v_string);
3446 token = g_scanner_get_next_token (scanner);
3447 if (token != G_TOKEN_RIGHT_BRACE)
3450 return G_TOKEN_RIGHT_BRACE;
3453 return G_TOKEN_NONE;
3457 gtk_rc_parse_icon_source (GtkRcContext *context,
3459 GtkIconSet *icon_set)
3462 GtkIconSource *source;
3463 gchar *full_filename;
3465 token = g_scanner_get_next_token (scanner);
3466 if (token != G_TOKEN_LEFT_CURLY)
3467 return G_TOKEN_LEFT_CURLY;
3469 token = g_scanner_get_next_token (scanner);
3471 if (token != G_TOKEN_STRING)
3472 return G_TOKEN_STRING;
3475 source = gtk_icon_source_new ();
3477 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3480 gtk_icon_source_set_filename (source, full_filename);
3481 g_free (full_filename);
3484 /* We continue parsing even if we didn't find the pixmap so that rest of the
3485 * file is read, even if the syntax is bad
3487 token = g_scanner_get_next_token (scanner);
3489 if (token == G_TOKEN_RIGHT_CURLY)
3491 else if (token != G_TOKEN_COMMA)
3493 gtk_icon_source_free (source);
3494 return G_TOKEN_COMMA;
3497 /* Get the direction */
3499 token = g_scanner_get_next_token (scanner);
3503 case GTK_RC_TOKEN_RTL:
3504 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3505 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3508 case GTK_RC_TOKEN_LTR:
3509 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3510 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3517 gtk_icon_source_free (source);
3518 return GTK_RC_TOKEN_RTL;
3522 token = g_scanner_get_next_token (scanner);
3524 if (token == G_TOKEN_RIGHT_CURLY)
3526 else if (token != G_TOKEN_COMMA)
3528 gtk_icon_source_free (source);
3529 return G_TOKEN_COMMA;
3534 token = g_scanner_get_next_token (scanner);
3538 case GTK_RC_TOKEN_NORMAL:
3539 gtk_icon_source_set_state_wildcarded (source, FALSE);
3540 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3543 case GTK_RC_TOKEN_PRELIGHT:
3544 gtk_icon_source_set_state_wildcarded (source, FALSE);
3545 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3549 case GTK_RC_TOKEN_INSENSITIVE:
3550 gtk_icon_source_set_state_wildcarded (source, FALSE);
3551 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3554 case GTK_RC_TOKEN_ACTIVE:
3555 gtk_icon_source_set_state_wildcarded (source, FALSE);
3556 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3559 case GTK_RC_TOKEN_SELECTED:
3560 gtk_icon_source_set_state_wildcarded (source, FALSE);
3561 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3568 gtk_icon_source_free (source);
3569 return GTK_RC_TOKEN_PRELIGHT;
3573 token = g_scanner_get_next_token (scanner);
3575 if (token == G_TOKEN_RIGHT_CURLY)
3577 else if (token != G_TOKEN_COMMA)
3579 gtk_icon_source_free (source);
3580 return G_TOKEN_COMMA;
3585 token = g_scanner_get_next_token (scanner);
3591 if (token != G_TOKEN_STRING)
3593 gtk_icon_source_free (source);
3594 return G_TOKEN_STRING;
3597 size = gtk_icon_size_from_name (scanner->value.v_string);
3599 if (size != GTK_ICON_SIZE_INVALID)
3601 gtk_icon_source_set_size_wildcarded (source, FALSE);
3602 gtk_icon_source_set_size (source, size);
3606 /* Check the close brace */
3608 token = g_scanner_get_next_token (scanner);
3609 if (token != G_TOKEN_RIGHT_CURLY)
3611 gtk_icon_source_free (source);
3612 return G_TOKEN_RIGHT_CURLY;
3616 if (gtk_icon_source_get_filename (source))
3617 gtk_icon_set_add_source (icon_set, source);
3618 gtk_icon_source_free (source);
3620 return G_TOKEN_NONE;
3624 gtk_rc_parse_stock (GtkRcContext *context,
3626 GtkRcStyle *rc_style,
3627 GtkIconFactory *factory)
3629 GtkIconSet *icon_set = NULL;
3630 gchar *stock_id = NULL;
3633 token = g_scanner_get_next_token (scanner);
3634 if (token != GTK_RC_TOKEN_STOCK)
3635 return GTK_RC_TOKEN_STOCK;
3637 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3638 if (token != G_TOKEN_NONE)
3641 token = g_scanner_get_next_token (scanner);
3642 if (token != G_TOKEN_EQUAL_SIGN)
3645 return G_TOKEN_EQUAL_SIGN;
3648 token = g_scanner_get_next_token (scanner);
3649 if (token != G_TOKEN_LEFT_CURLY)
3652 return G_TOKEN_LEFT_CURLY;
3655 token = g_scanner_peek_next_token (scanner);
3656 while (token != G_TOKEN_RIGHT_CURLY)
3658 if (icon_set == NULL)
3659 icon_set = gtk_icon_set_new ();
3661 token = gtk_rc_parse_icon_source (context, scanner, icon_set);
3662 if (token != G_TOKEN_NONE)
3665 gtk_icon_set_unref (icon_set);
3669 token = g_scanner_get_next_token (scanner);
3671 if (token != G_TOKEN_COMMA &&
3672 token != G_TOKEN_RIGHT_CURLY)
3675 gtk_icon_set_unref (icon_set);
3676 return G_TOKEN_RIGHT_CURLY;
3682 gtk_icon_factory_add (factory,
3686 gtk_icon_set_unref (icon_set);
3691 return G_TOKEN_NONE;