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/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
47 #include "gdkconfig.h"
49 #include "gtkversion.h"
51 #include "gtkbindings.h"
52 #include "gtkthemes.h"
54 #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;
101 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
103 gint default_priority;
106 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
108 static guint gtk_rc_style_hash (const gchar *name);
109 static gboolean gtk_rc_style_equal (const gchar *a,
111 static guint gtk_rc_styles_hash (const GSList *rc_styles);
112 static gboolean gtk_rc_styles_equal (const GSList *a,
114 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
116 static GSList * gtk_rc_styles_match (GSList *rc_styles,
120 const gchar *path_reversed);
121 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
122 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
123 static void gtk_rc_parse_default_files (GtkRcContext *context);
124 static void gtk_rc_parse_named (GtkRcContext *context,
127 static void gtk_rc_parse_file (GtkRcContext *context,
128 const gchar *filename,
131 static void gtk_rc_parse_any (GtkRcContext *context,
132 const gchar *input_name,
134 const gchar *input_string);
135 static guint gtk_rc_parse_statement (GtkRcContext *context,
137 static guint gtk_rc_parse_style (GtkRcContext *context,
139 static guint gtk_rc_parse_assignment (GScanner *scanner,
140 GtkRcProperty *prop);
141 static guint gtk_rc_parse_bg (GScanner *scanner,
143 static guint gtk_rc_parse_fg (GScanner *scanner,
145 static guint gtk_rc_parse_text (GScanner *scanner,
147 static guint gtk_rc_parse_base (GScanner *scanner,
149 static guint gtk_rc_parse_xthickness (GScanner *scanner,
151 static guint gtk_rc_parse_ythickness (GScanner *scanner,
153 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
155 GtkRcStyle *rc_style);
156 static guint gtk_rc_parse_font (GScanner *scanner,
157 GtkRcStyle *rc_style);
158 static guint gtk_rc_parse_fontset (GScanner *scanner,
159 GtkRcStyle *rc_style);
160 static guint gtk_rc_parse_font_name (GScanner *scanner,
161 GtkRcStyle *rc_style);
162 static guint gtk_rc_parse_engine (GtkRcContext *context,
164 GtkRcStyle **rc_style);
165 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
167 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
169 const gchar *pix_path);
170 static guint gtk_rc_parse_module_path (GScanner *scanner);
171 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
172 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
174 static guint gtk_rc_parse_stock (GtkRcContext *context,
176 GtkRcStyle *rc_style,
177 GtkIconFactory *factory);
178 static void gtk_rc_clear_hash_node (gpointer key,
181 static void gtk_rc_clear_styles (GtkRcContext *context);
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_file", GTK_RC_TOKEN_IM_MODULE_FILE },
275 { "LTR", GTK_RC_TOKEN_LTR },
276 { "RTL", GTK_RC_TOKEN_RTL }
279 static GHashTable *realized_style_ht = NULL;
281 static gchar *im_module_file = NULL;
283 #define GTK_RC_MAX_DEFAULT_FILES 128
284 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
286 /* A stack of directories for RC files we are parsing currently.
287 * these are implicitely added to the end of PIXMAP_PATHS
289 static GSList *rc_dir_stack = NULL;
291 /* RC file handling */
294 gtk_rc_make_default_dir (const gchar *type)
299 var = g_getenv ("GTK_EXE_PREFIX");
301 path = g_build_filename (var, "lib", "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
303 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
309 * gtk_rc_get_im_module_path:
310 * @returns: a newly-allocated string containing the path in which to
311 * look for IM modules.
313 * Obtains the path in which to look for IM modules. See the documentation
314 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
315 * environment variable for more details about looking up modules. This
316 * function is useful solely for utilities supplied with GTK+ and should
317 * not be used by applications under normal circumstances.
320 gtk_rc_get_im_module_path (void)
322 gchar **paths = _gtk_get_module_path ("immodules");
323 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
330 * gtk_rc_get_im_module_file:
331 * @returns: a newly-allocated string containing the name of the file
332 * listing the IM modules available for loading
334 * Obtains the path to the IM modules file. See the documentation
335 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
336 * environment variable for more details.
339 gtk_rc_get_im_module_file (void)
341 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
346 result = g_strdup (im_module_file);
348 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
355 gtk_rc_get_theme_dir (void)
360 var = g_getenv ("GTK_DATA_PREFIX");
362 path = g_build_filename (var, "share", "themes", NULL);
364 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
370 gtk_rc_get_module_dir (void)
372 return gtk_rc_make_default_dir ("engines");
376 gtk_rc_add_initial_default_files (void)
378 static gint init = FALSE;
387 gtk_rc_default_files[0] = NULL;
390 var = g_getenv ("GTK_RC_FILES");
393 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
397 gtk_rc_add_default_file (files[i]);
404 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
406 gtk_rc_add_default_file (str);
409 var = g_get_home_dir ();
412 str = g_build_filename (var, ".gtkrc-2.0", NULL);
413 gtk_rc_add_default_file (str);
420 * gtk_rc_add_default_file:
421 * @filename: the pathname to the file. If @filename is not absolute, it
422 * is searched in the current directory.
424 * Adds a file to the list of files to be parsed at the
428 gtk_rc_add_default_file (const gchar *filename)
432 gtk_rc_add_initial_default_files ();
434 for (n = 0; gtk_rc_default_files[n]; n++) ;
435 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
438 gtk_rc_default_files[n++] = g_strdup (filename);
439 gtk_rc_default_files[n] = NULL;
443 * gtk_rc_set_default_files:
444 * @filenames: A %NULL-terminated list of filenames.
446 * Sets the list of files that GTK+ will read at the
450 gtk_rc_set_default_files (gchar **filenames)
454 gtk_rc_add_initial_default_files ();
457 while (gtk_rc_default_files[i])
459 g_free (gtk_rc_default_files[i]);
463 gtk_rc_default_files[0] = NULL;
466 while (filenames[i] != NULL)
468 gtk_rc_add_default_file (filenames[i]);
474 * gtk_rc_get_default_files:
476 * Retrieves the current list of RC files that will be parsed
477 * at the end of gtk_init().
479 * Return value: A %NULL-terminated array of filenames. This memory
480 * is owned by GTK+ and must not be freed by the application.
481 * If you want to store this information, you should make a copy.
484 gtk_rc_get_default_files (void)
486 gtk_rc_add_initial_default_files ();
488 return gtk_rc_default_files;
492 gtk_rc_settings_changed (GtkSettings *settings,
494 GtkRcContext *context)
496 gchar *new_theme_name;
497 gchar *new_key_theme_name;
499 g_object_get (settings,
500 "gtk-theme-name", &new_theme_name,
501 "gtk-key-theme-name", &new_key_theme_name,
504 if ((new_theme_name != context->theme_name &&
505 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
506 (new_key_theme_name != context->key_theme_name &&
507 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
509 gtk_rc_reparse_all_for_settings (settings, TRUE);
512 g_free (new_theme_name);
513 g_free (new_key_theme_name);
517 gtk_rc_font_name_changed (GtkSettings *settings,
519 GtkRcContext *context)
521 _gtk_rc_context_get_default_font_name (settings);
524 static GtkRcContext *
525 gtk_rc_context_get (GtkSettings *settings)
527 if (!settings->rc_context)
529 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
531 context->settings = settings;
532 context->rc_style_ht = NULL;
533 context->rc_sets_widget = NULL;
534 context->rc_sets_widget_class = NULL;
535 context->rc_sets_class = NULL;
536 context->rc_files = NULL;
538 g_object_get (settings,
539 "gtk-theme-name", &context->theme_name,
540 "gtk-key-theme-name", &context->key_theme_name,
541 "gtk-font-name", &context->font_name,
544 g_signal_connect (settings,
545 "notify::gtk-theme-name",
546 G_CALLBACK (gtk_rc_settings_changed),
548 g_signal_connect (settings,
549 "notify::gtk-key-theme-name",
550 G_CALLBACK (gtk_rc_settings_changed),
552 g_signal_connect (settings,
553 "notify::gtk-font-name",
554 G_CALLBACK (gtk_rc_font_name_changed),
558 context->pixmap_path[0] = NULL;
560 context->default_priority = GTK_PATH_PRIO_RC;
563 return settings->rc_context;
567 gtk_rc_parse_named (GtkRcContext *context,
572 const gchar *home_dir;
576 subpath = g_strconcat ("gtk-2.0-", type,
577 G_DIR_SEPARATOR_S "gtkrc",
580 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
582 /* First look in the users home directory
584 home_dir = g_get_home_dir ();
587 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
588 if (!g_file_test (path, G_FILE_TEST_EXISTS))
597 gchar *theme_dir = gtk_rc_get_theme_dir ();
598 path = g_build_filename (theme_dir, name, subpath, NULL);
601 if (!g_file_test (path, G_FILE_TEST_EXISTS))
610 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
618 gtk_rc_parse_default_files (GtkRcContext *context)
622 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
623 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
629 static gboolean initialized = FALSE;
635 gtk_rc_add_initial_default_files ();
638 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
640 /* Default RC string */
641 gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
642 " bg[NORMAL] = \"#ffffc0\"\n"
643 " fg[NORMAL] = \"#000000\"\n"
646 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n");
650 gtk_rc_parse_string (const gchar *rc_string)
653 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
654 * string in all contexts, and in fact, in future contexts as well.
656 GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
658 g_return_if_fail (rc_string != NULL);
660 rc_file = g_new (GtkRcFile, 1);
661 rc_file->is_string = TRUE;
662 rc_file->name = g_strdup (rc_string);
663 rc_file->canonical_name = NULL;
665 rc_file->reload = TRUE;
667 context->rc_files = g_slist_append (context->rc_files, rc_file);
669 gtk_rc_parse_any (context, "-", -1, rc_string);
673 gtk_rc_parse_one_file (GtkRcContext *context,
674 const gchar *filename,
678 GtkRcFile *rc_file = NULL;
683 g_return_if_fail (filename != NULL);
685 saved_priority = context->default_priority;
686 context->default_priority = priority;
688 tmp_list = context->rc_files;
691 rc_file = tmp_list->data;
692 if (!strcmp (rc_file->name, filename))
695 tmp_list = tmp_list->next;
700 rc_file = g_new (GtkRcFile, 1);
701 rc_file->is_string = FALSE;
702 rc_file->name = g_strdup (filename);
703 rc_file->canonical_name = NULL;
705 rc_file->reload = reload;
707 context->rc_files = g_slist_append (context->rc_files, rc_file);
710 if (!rc_file->canonical_name)
712 /* Get the absolute pathname */
714 if (g_path_is_absolute (rc_file->name))
715 rc_file->canonical_name = rc_file->name;
720 cwd = g_get_current_dir ();
721 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
726 if (!lstat (rc_file->canonical_name, &statbuf))
731 rc_file->mtime = statbuf.st_mtime;
733 fd = open (rc_file->canonical_name, O_RDONLY);
737 /* Temporarily push directory name for this file on
738 * a stack of directory names while parsing it
741 g_slist_prepend (rc_dir_stack,
742 g_path_get_dirname (rc_file->canonical_name));
743 gtk_rc_parse_any (context, filename, fd, NULL);
745 tmp_list = rc_dir_stack;
746 rc_dir_stack = rc_dir_stack->next;
748 g_free (tmp_list->data);
749 g_slist_free_1 (tmp_list);
755 context->default_priority = saved_priority;
759 strchr_len (const gchar *str, gint len, char c)
773 gtk_rc_parse_file (GtkRcContext *context,
774 const gchar *filename,
778 gchar *locale_suffixes[2];
779 gint n_locale_suffixes = 0;
783 gboolean found = FALSE;
786 locale = g_win32_getlocale ();
788 locale = setlocale (LC_CTYPE, NULL);
791 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
793 /* Determine locale-specific suffixes for RC files.
795 length = strlen (locale);
797 p = strchr (locale, '@');
801 p = strchr_len (locale, length, '.');
805 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
807 p = strchr_len (locale, length, '_');
811 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
815 gtk_rc_parse_one_file (context, filename, priority, reload);
816 for (j = 0; j < n_locale_suffixes; j++)
820 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
821 if (g_file_test (name, G_FILE_TEST_EXISTS))
823 gtk_rc_parse_one_file (context, name, priority, FALSE);
830 g_free (locale_suffixes[j]);
835 gtk_rc_parse (const gchar *filename)
837 g_return_if_fail (filename != NULL);
839 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
840 * file in all contexts, and in fact, in future contexts as well.
842 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
843 filename, GTK_PATH_PRIO_RC, TRUE);
846 /* Handling of RC styles */
849 gtk_rc_style_get_type (void)
851 static GType object_type = 0;
855 static const GTypeInfo object_info =
857 sizeof (GtkRcStyleClass),
858 (GBaseInitFunc) NULL,
859 (GBaseFinalizeFunc) NULL,
860 (GClassInitFunc) gtk_rc_style_class_init,
861 NULL, /* class_finalize */
862 NULL, /* class_data */
865 (GInstanceInitFunc) gtk_rc_style_init,
868 object_type = g_type_register_static (G_TYPE_OBJECT,
877 gtk_rc_style_init (GtkRcStyle *style)
882 style->font_desc = NULL;
884 for (i = 0; i < 5; i++)
886 static const GdkColor init_color = { 0, 0, 0, 0, };
888 style->bg_pixmap_name[i] = NULL;
889 style->color_flags[i] = 0;
890 style->fg[i] = init_color;
891 style->bg[i] = init_color;
892 style->text[i] = init_color;
893 style->base[i] = init_color;
895 style->xthickness = -1;
896 style->ythickness = -1;
897 style->rc_properties = NULL;
899 style->rc_style_lists = NULL;
900 style->icon_factories = NULL;
904 gtk_rc_style_class_init (GtkRcStyleClass *klass)
906 GObjectClass *object_class = G_OBJECT_CLASS (klass);
908 parent_class = g_type_class_peek_parent (klass);
910 object_class->finalize = gtk_rc_style_finalize;
913 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
914 klass->merge = gtk_rc_style_real_merge;
915 klass->create_style = gtk_rc_style_real_create_style;
919 gtk_rc_style_finalize (GObject *object)
921 GSList *tmp_list1, *tmp_list2;
922 GtkRcStyle *rc_style;
925 rc_style = GTK_RC_STYLE (object);
928 g_free (rc_style->name);
929 if (rc_style->font_desc)
930 pango_font_description_free (rc_style->font_desc);
932 for (i = 0; i < 5; i++)
933 if (rc_style->bg_pixmap_name[i])
934 g_free (rc_style->bg_pixmap_name[i]);
936 /* Now remove all references to this rc_style from
939 tmp_list1 = rc_style->rc_style_lists;
942 GSList *rc_styles = tmp_list1->data;
943 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
944 gtk_style_unref (style);
946 /* Remove the list of styles from the other rc_styles
949 tmp_list2 = rc_styles;
952 GtkRcStyle *other_style = tmp_list2->data;
954 if (other_style != rc_style)
955 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
957 tmp_list2 = tmp_list2->next;
960 /* And from the hash table itself
962 g_hash_table_remove (realized_style_ht, rc_styles);
963 g_slist_free (rc_styles);
965 tmp_list1 = tmp_list1->next;
967 g_slist_free (rc_style->rc_style_lists);
969 if (rc_style->rc_properties)
973 for (i = 0; i < rc_style->rc_properties->len; i++)
975 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
977 g_free (node->origin);
978 g_value_unset (&node->value);
980 g_array_free (rc_style->rc_properties, TRUE);
981 rc_style->rc_properties = NULL;
984 tmp_list1 = rc_style->icon_factories;
987 g_object_unref (G_OBJECT (tmp_list1->data));
989 tmp_list1 = tmp_list1->next;
991 g_slist_free (rc_style->icon_factories);
993 G_OBJECT_CLASS (parent_class)->finalize (object);
997 gtk_rc_style_new (void)
1001 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1007 * gtk_rc_style_copy:
1008 * @orig: the style to copy
1010 * Makes a copy of the specified #GtkRcStyle. This function
1011 * will correctly copy an RC style that is a member of a class
1012 * derived from #GtkRcStyle.
1014 * Return value: the resulting #GtkRcStyle
1017 gtk_rc_style_copy (GtkRcStyle *orig)
1021 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1023 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1024 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1030 gtk_rc_style_ref (GtkRcStyle *rc_style)
1032 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1034 g_object_ref (G_OBJECT (rc_style));
1038 gtk_rc_style_unref (GtkRcStyle *rc_style)
1040 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1042 g_object_unref (G_OBJECT (rc_style));
1046 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1048 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1052 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1053 gconstpointer bsearch_node2)
1055 const GtkRcProperty *prop1 = bsearch_node1;
1056 const GtkRcProperty *prop2 = bsearch_node2;
1058 if (prop1->type_name == prop2->type_name)
1059 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1061 return prop1->type_name < prop2->type_name ? -1 : 1;
1065 insert_rc_property (GtkRcStyle *style,
1066 GtkRcProperty *property,
1070 GtkRcProperty *new_property = NULL;
1071 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1073 key.type_name = property->type_name;
1074 key.property_name = property->property_name;
1076 if (!style->rc_properties)
1077 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1080 while (i < style->rc_properties->len)
1082 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1088 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1090 g_free (new_property->origin);
1091 g_value_unset (&new_property->value);
1093 *new_property = key;
1107 g_array_insert_val (style->rc_properties, i, key);
1108 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1111 new_property->origin = g_strdup (property->origin);
1112 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1113 g_value_copy (&property->value, &new_property->value);
1117 gtk_rc_style_real_merge (GtkRcStyle *dest,
1122 for (i = 0; i < 5; i++)
1124 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1125 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1127 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1128 src->color_flags[i] & GTK_RC_FG)
1130 dest->fg[i] = src->fg[i];
1131 dest->color_flags[i] |= GTK_RC_FG;
1133 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1134 src->color_flags[i] & GTK_RC_BG)
1136 dest->bg[i] = src->bg[i];
1137 dest->color_flags[i] |= GTK_RC_BG;
1139 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1140 src->color_flags[i] & GTK_RC_TEXT)
1142 dest->text[i] = src->text[i];
1143 dest->color_flags[i] |= GTK_RC_TEXT;
1145 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1146 src->color_flags[i] & GTK_RC_BASE)
1148 dest->base[i] = src->base[i];
1149 dest->color_flags[i] |= GTK_RC_BASE;
1153 if (dest->xthickness < 0 && src->xthickness >= 0)
1154 dest->xthickness = src->xthickness;
1155 if (dest->ythickness < 0 && src->ythickness >= 0)
1156 dest->ythickness = src->ythickness;
1160 if (!dest->font_desc)
1161 dest->font_desc = pango_font_description_copy (src->font_desc);
1163 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1166 if (src->rc_properties)
1170 for (i = 0; i < src->rc_properties->len; i++)
1171 insert_rc_property (dest,
1172 &g_array_index (src->rc_properties, GtkRcProperty, i),
1178 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1180 return gtk_style_new ();
1184 gtk_rc_clear_hash_node (gpointer key,
1188 gtk_rc_style_unref (data);
1192 gtk_rc_free_rc_sets (GSList *slist)
1198 rc_set = slist->data;
1199 g_pattern_spec_free (rc_set->pspec);
1202 slist = slist->next;
1207 gtk_rc_clear_styles (GtkRcContext *context)
1209 /* Clear out all old rc_styles */
1211 if (context->rc_style_ht)
1213 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1214 g_hash_table_destroy (context->rc_style_ht);
1215 context->rc_style_ht = NULL;
1218 gtk_rc_free_rc_sets (context->rc_sets_widget);
1219 g_slist_free (context->rc_sets_widget);
1220 context->rc_sets_widget = NULL;
1222 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1223 g_slist_free (context->rc_sets_widget_class);
1224 context->rc_sets_widget_class = NULL;
1226 gtk_rc_free_rc_sets (context->rc_sets_class);
1227 g_slist_free (context->rc_sets_class);
1228 context->rc_sets_class = NULL;
1231 /* Reset all our widgets. Also, we have to invalidate cached icons in
1232 * icon sets so they get re-rendered.
1235 gtk_rc_reset_widgets (GtkRcContext *context)
1237 GList *list, *toplevels;
1239 _gtk_icon_set_invalidate_caches ();
1241 toplevels = gtk_window_list_toplevels ();
1242 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1244 for (list = toplevels; list; list = list->next)
1246 gtk_widget_reset_rc_styles (list->data);
1247 gtk_widget_unref (list->data);
1249 g_list_free (toplevels);
1253 gtk_rc_clear_realized_style (gpointer key,
1257 GSList *rc_styles = key;
1258 GSList *tmp_list = rc_styles;
1262 GtkRcStyle *rc_style = tmp_list->data;
1264 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1266 tmp_list = tmp_list->next;
1269 g_slist_free (rc_styles);
1273 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1275 GtkRcContext *context;
1276 gchar *new_font_name;
1278 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1280 context = gtk_rc_context_get (settings);
1282 g_object_get (context->settings,
1283 "gtk-font-name", &new_font_name,
1286 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1288 g_free (context->font_name);
1289 context->font_name = g_strdup (new_font_name);
1291 /* Clear out styles that have been looked up already
1293 if (realized_style_ht)
1295 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1296 g_hash_table_destroy (realized_style_ht);
1297 realized_style_ht = NULL;
1299 gtk_rc_reset_widgets (context);
1303 g_free (new_font_name);
1305 return context->font_name;
1309 * gtk_rc_reparse_all_for_settings:
1310 * @settings: a #GtkSettings
1311 * @force_load: load whether or not anything changed
1313 * If the modification time on any previously read file
1314 * for the given #GtkSettings has changed, discard all style information
1315 * and then reread all previously read RC files.
1317 * Return value: %TRUE if the files were reread.
1320 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1321 gboolean force_load)
1323 gboolean mtime_modified = FALSE;
1326 GtkRcContext *context;
1328 struct stat statbuf;
1330 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1332 context = gtk_rc_context_get (settings);
1336 /* Check through and see if any of the RC's have had their
1337 * mtime modified. If so, reparse everything.
1339 tmp_list = context->rc_files;
1342 rc_file = tmp_list->data;
1344 if (!rc_file->is_string)
1346 if (!lstat (rc_file->name, &statbuf) &&
1347 (statbuf.st_mtime > rc_file->mtime))
1349 mtime_modified = TRUE;
1354 tmp_list = tmp_list->next;
1358 if (force_load || mtime_modified)
1362 _gtk_binding_reset_parsed ();
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);
1396 g_object_get (context->settings,
1397 "gtk-theme-name", &context->theme_name,
1398 "gtk-key-theme-name", &context->key_theme_name,
1401 if (context->theme_name && context->theme_name[0])
1402 gtk_rc_parse_named (context, context->theme_name, NULL);
1403 if (context->key_theme_name && context->key_theme_name[0])
1404 gtk_rc_parse_named (context, context->key_theme_name, "key");
1406 g_object_thaw_notify (G_OBJECT (context->settings));
1408 gtk_rc_reset_widgets (context);
1411 return mtime_modified;
1415 * gtk_rc_reparse_all:
1417 * If the modification time on any previously read file for the
1418 * default #GtkSettings has changed, discard all style information
1419 * and then reread all previously read RC files.
1421 * Return value: %TRUE if the files were reread.
1424 gtk_rc_reparse_all (void)
1426 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1430 gtk_rc_styles_match (GSList *rc_styles,
1434 const gchar *path_reversed)
1441 rc_set = sets->data;
1444 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1445 rc_styles = g_slist_append (rc_styles, rc_set);
1452 rc_set_compare (gconstpointer a, gconstpointer b)
1454 const GtkRcSet *set_a = a;
1455 const GtkRcSet *set_b = b;
1457 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1461 sort_and_dereference_sets (GSList *styles)
1465 /* At this point, the list of sets is ordered by:
1467 * a) 'widget' patterns are earlier than 'widget_class' patterns
1468 * which are ealier than 'class' patterns.
1469 * a) For two matches for class patterns, a match to a child type
1470 * is before a match to a parent type
1471 * c) a match later in the RC file (or in a later RC file) is before a
1472 * match earlier in the RC file.
1474 * With a) taking precedence over b) which takes precendence over c).
1476 * Now sort by priority, which has the highest precendence for sort order
1478 styles = g_slist_sort (styles, rc_set_compare);
1480 /* Make styles->data = styles->data->rc_style
1485 GtkRcSet *set = tmp_list->data;
1486 tmp_list->data = set->rc_style;
1487 tmp_list = tmp_list->next;
1495 * @widget: a #GtkWidget
1497 * Finds all matching RC styles for a given widget,
1498 * composites them together, and then creates a
1499 * #GtkStyle representing the composite appearance.
1500 * (GTK+ actually keeps a cache of previously
1501 * created styles, so a new style may not be
1504 * Returns: the resulting style. No refcount is added
1505 * to the returned style, so if you want to save this
1506 * style around, you should add a reference yourself.
1509 gtk_rc_get_style (GtkWidget *widget)
1511 GtkRcStyle *widget_rc_style;
1512 GSList *rc_styles = NULL;
1513 GtkRcContext *context;
1515 static guint rc_style_key_id = 0;
1517 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1519 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1521 /* We allow the specification of a single rc style to be bound
1522 * tightly to a widget, for application modifications
1524 if (!rc_style_key_id)
1525 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1527 if (context->rc_sets_widget)
1529 gchar *path, *path_reversed;
1532 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1533 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1535 g_free (path_reversed);
1538 if (context->rc_sets_widget_class)
1540 gchar *path, *path_reversed;
1543 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1544 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1546 g_free (path_reversed);
1549 if (context->rc_sets_class)
1553 type = GTK_OBJECT_TYPE (widget);
1557 gchar *path_reversed;
1560 path = gtk_type_name (type);
1561 path_length = strlen (path);
1562 path_reversed = g_strdup (path);
1563 g_strreverse (path_reversed);
1565 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1566 g_free (path_reversed);
1568 type = gtk_type_parent (type);
1572 rc_styles = sort_and_dereference_sets (rc_styles);
1574 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1577 if (widget_rc_style)
1578 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1581 return gtk_rc_init_style (rc_styles);
1587 * gtk_rc_get_style_by_paths:
1588 * @settings: a #GtkSettings object
1589 * @widget_path: the widget path to use when looking up the style, or %NULL
1590 * @class_path: the class path to use when looking up the style, or %NULL
1591 * @type: a type that will be used along with parent types of this type
1592 * when matching against class styles, or #G_TYPE_NONE
1594 * Creates up a #GtkStyle from styles defined in a RC file by providing
1595 * the raw components used in matching. This function may be useful
1596 * when creating pseudo-widgets that should be themed like widgets but
1597 * don't actually have corresponding GTK+ widgets. An example of this
1598 * would be items inside a GNOME canvas widget.
1600 * The action of gtk_rc_get_style() is similar to:
1601 * <informalexample><programlisting>
1602 * <!> gtk_widget_path (widget, NULL, &path, NULL);
1603 * <!> gtk_widget_class_path (widget, NULL, &class_path, NULL);
1604 * <!> gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1605 * <!> G_OBJECT_TYPE (widget));
1606 * </programlisting></informalexample>
1608 * Return value: A style created by matching with the supplied paths,
1609 * or %NULL if nothing matching was specified and the default style should
1610 * be used. The returned value is owned by GTK+ as part of an internal cache,
1611 * so you must call g_object_ref() on the returned value if you want to
1612 * keep a reference to it.
1615 gtk_rc_get_style_by_paths (GtkSettings *settings,
1616 const char *widget_path,
1617 const char *class_path,
1620 /* We duplicate the code from above to avoid slowing down the above
1621 * by generating paths when we don't need them. I don't know if
1622 * this is really worth it.
1624 GSList *rc_styles = NULL;
1625 GtkRcContext *context;
1627 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1629 context = gtk_rc_context_get (settings);
1631 if (context->rc_sets_widget)
1633 gchar *path_reversed;
1636 path_length = strlen (widget_path);
1637 path_reversed = g_strdup (widget_path);
1638 g_strreverse (path_reversed);
1640 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1641 g_free (path_reversed);
1644 if (context->rc_sets_widget_class)
1646 gchar *path_reversed;
1649 path_length = strlen (class_path);
1650 path_reversed = g_strdup (class_path);
1651 g_strreverse (path_reversed);
1653 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1654 g_free (path_reversed);
1657 if (type != G_TYPE_NONE && context->rc_sets_class)
1662 gchar *path_reversed;
1665 path = g_type_name (type);
1666 path_length = strlen (path);
1667 path_reversed = g_strdup (path);
1668 g_strreverse (path_reversed);
1670 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1671 g_free (path_reversed);
1673 type = g_type_parent (type);
1677 rc_styles = sort_and_dereference_sets (rc_styles);
1680 return gtk_rc_init_style (rc_styles);
1686 gtk_rc_add_rc_sets (GSList *slist,
1687 GtkRcStyle *rc_style,
1688 const gchar *pattern)
1690 GtkRcStyle *new_style;
1694 new_style = gtk_rc_style_new ();
1695 *new_style = *rc_style;
1696 new_style->name = g_strdup (rc_style->name);
1697 if (rc_style->font_desc)
1698 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1700 for (i = 0; i < 5; i++)
1701 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1703 rc_set = g_new (GtkRcSet, 1);
1704 rc_set->pspec = g_pattern_spec_new (pattern);
1705 rc_set->rc_style = rc_style;
1707 return g_slist_prepend (slist, rc_set);
1711 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1712 const gchar *pattern)
1714 GtkRcContext *context;
1716 g_return_if_fail (rc_style != NULL);
1717 g_return_if_fail (pattern != NULL);
1719 context = gtk_rc_context_get (gtk_settings_get_default ());
1721 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1725 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1726 const gchar *pattern)
1728 GtkRcContext *context;
1730 g_return_if_fail (rc_style != NULL);
1731 g_return_if_fail (pattern != NULL);
1733 context = gtk_rc_context_get (gtk_settings_get_default ());
1735 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1739 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1740 const gchar *pattern)
1742 GtkRcContext *context;
1744 g_return_if_fail (rc_style != NULL);
1745 g_return_if_fail (pattern != NULL);
1747 context = gtk_rc_context_get (gtk_settings_get_default ());
1749 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1753 gtk_rc_scanner_new (void)
1755 return g_scanner_new (>k_rc_scanner_config);
1759 gtk_rc_parse_any (GtkRcContext *context,
1760 const gchar *input_name,
1762 const gchar *input_string)
1768 scanner = gtk_rc_scanner_new ();
1772 g_assert (input_string == NULL);
1774 g_scanner_input_file (scanner, input_fd);
1778 g_assert (input_string != NULL);
1780 g_scanner_input_text (scanner, input_string, strlen (input_string));
1782 scanner->input_name = input_name;
1784 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1785 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1790 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1794 guint expected_token;
1796 expected_token = gtk_rc_parse_statement (context, scanner);
1798 if (expected_token != G_TOKEN_NONE)
1805 if (scanner->scope_id == 0)
1807 /* if we are in scope 0, we know the symbol names
1808 * that are associated with certain token values.
1809 * so we look them up to make the error messages
1812 if (expected_token > GTK_RC_TOKEN_INVALID &&
1813 expected_token < GTK_RC_TOKEN_LAST)
1815 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1816 if (symbols[i].token == expected_token)
1817 msg = symbols[i].name;
1819 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1821 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1822 scanner->token < GTK_RC_TOKEN_LAST)
1824 symbol_name = "???";
1825 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1826 if (symbols[i].token == scanner->token)
1827 symbol_name = symbols[i].name;
1830 g_scanner_unexp_token (scanner,
1843 g_scanner_destroy (scanner);
1847 gtk_rc_styles_hash (const GSList *rc_styles)
1854 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1855 rc_styles = rc_styles->next;
1862 gtk_rc_styles_equal (const GSList *a,
1867 if (a->data != b->data)
1877 gtk_rc_style_hash (const gchar *name)
1883 result += (result << 3) + *name++;
1889 gtk_rc_style_equal (const gchar *a,
1892 return (strcmp (a, b) == 0);
1896 gtk_rc_style_find (GtkRcContext *context,
1899 if (context->rc_style_ht)
1900 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1906 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1910 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1912 style->rc_style = rc_style;
1914 gtk_rc_style_ref (rc_style);
1916 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1921 /* Reuses or frees rc_styles */
1923 gtk_rc_init_style (GSList *rc_styles)
1925 GtkStyle *style = NULL;
1928 g_return_val_if_fail (rc_styles != NULL, NULL);
1930 if (!realized_style_ht)
1931 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1932 (GEqualFunc) gtk_rc_styles_equal);
1934 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1938 GtkRcStyle *base_style = NULL;
1939 GtkRcStyle *proto_style;
1940 GtkRcStyleClass *proto_style_class;
1942 GType rc_style_type = GTK_TYPE_RC_STYLE;
1944 /* Find the the first style where the RC file specified engine "" {}
1945 * or the first derived style and use that to create the
1946 * merged style. If we only have raw GtkRcStyles, use the first
1947 * style to create the merged style.
1949 base_style = rc_styles->data;
1950 tmp_styles = rc_styles;
1953 GtkRcStyle *rc_style = tmp_styles->data;
1955 if (rc_style->engine_specified ||
1956 G_OBJECT_TYPE (rc_style) != rc_style_type)
1958 base_style = rc_style;
1962 tmp_styles = tmp_styles->next;
1965 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1966 proto_style = proto_style_class->create_rc_style (base_style);
1968 tmp_styles = rc_styles;
1971 GtkRcStyle *rc_style = tmp_styles->data;
1974 proto_style_class->merge (proto_style, rc_style);
1976 /* Point from each rc_style to the list of styles */
1977 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1978 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1980 factories = g_slist_copy (rc_style->icon_factories);
1986 while (iter != NULL)
1988 g_object_ref (G_OBJECT (iter->data));
1989 iter = g_slist_next (iter);
1992 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1997 tmp_styles = tmp_styles->next;
2000 for (i = 0; i < 5; i++)
2001 if (proto_style->bg_pixmap_name[i] &&
2002 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2004 g_free (proto_style->bg_pixmap_name[i]);
2005 proto_style->bg_pixmap_name[i] = NULL;
2008 style = gtk_rc_style_to_style (proto_style);
2009 gtk_rc_style_unref (proto_style);
2011 g_hash_table_insert (realized_style_ht, rc_styles, style);
2014 g_slist_free (rc_styles);
2019 /*********************
2020 * Parsing functions *
2021 *********************/
2024 rc_parse_token_or_compound (GScanner *scanner,
2026 GTokenType delimiter)
2028 guint token = g_scanner_get_next_token (scanner);
2030 /* we either scan a single token (skipping comments)
2031 * or a compund statement.
2032 * compunds are enclosed in (), [] or {} braces, we read
2033 * them in via deep recursion.
2040 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2043 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2045 case G_TOKEN_STRING:
2046 string = g_strescape (scanner->value.v_string, NULL);
2047 g_string_append (gstring, " \"");
2048 g_string_append (gstring, string);
2049 g_string_append_c (gstring, '"');
2052 case G_TOKEN_IDENTIFIER:
2053 g_string_append_c (gstring, ' ');
2054 g_string_append (gstring, scanner->value.v_identifier);
2056 case G_TOKEN_COMMENT_SINGLE:
2057 case G_TOKEN_COMMENT_MULTI:
2058 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2059 case G_TOKEN_LEFT_PAREN:
2060 g_string_append_c (gstring, ' ');
2061 g_string_append_c (gstring, token);
2062 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2063 if (token != G_TOKEN_NONE)
2066 case G_TOKEN_LEFT_CURLY:
2067 g_string_append_c (gstring, ' ');
2068 g_string_append_c (gstring, token);
2069 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2070 if (token != G_TOKEN_NONE)
2073 case G_TOKEN_LEFT_BRACE:
2074 g_string_append_c (gstring, ' ');
2075 g_string_append_c (gstring, token);
2076 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2077 if (token != G_TOKEN_NONE)
2081 if (token >= 256 || token < 1)
2082 return delimiter ? delimiter : G_TOKEN_STRING;
2083 g_string_append_c (gstring, ' ');
2084 g_string_append_c (gstring, token);
2085 if (token == delimiter)
2086 return G_TOKEN_NONE;
2090 return G_TOKEN_NONE;
2092 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2096 gtk_rc_parse_assignment (GScanner *scanner,
2097 GtkRcProperty *prop)
2099 gboolean scan_identifier = scanner->config->scan_identifier;
2100 gboolean scan_symbols = scanner->config->scan_symbols;
2101 gboolean identifier_2_string = scanner->config->identifier_2_string;
2102 gboolean char_2_token = scanner->config->char_2_token;
2103 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2104 gboolean numbers_2_int = scanner->config->numbers_2_int;
2105 gboolean negate = FALSE;
2108 /* check that this is an assignment */
2109 if (g_scanner_get_next_token (scanner) != '=')
2112 /* adjust scanner mode */
2113 scanner->config->scan_identifier = TRUE;
2114 scanner->config->scan_symbols = FALSE;
2115 scanner->config->identifier_2_string = FALSE;
2116 scanner->config->char_2_token = TRUE;
2117 scanner->config->scan_identifier_NULL = FALSE;
2118 scanner->config->numbers_2_int = TRUE;
2120 /* record location */
2121 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2123 /* parse optional sign */
2124 if (g_scanner_peek_next_token (scanner) == '-')
2126 g_scanner_get_next_token (scanner); /* eat sign */
2130 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2131 token = g_scanner_peek_next_token (scanner);
2135 g_scanner_get_next_token (scanner);
2136 g_value_init (&prop->value, G_TYPE_LONG);
2137 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2138 token = G_TOKEN_NONE;
2141 g_scanner_get_next_token (scanner);
2142 g_value_init (&prop->value, G_TYPE_DOUBLE);
2143 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2144 token = G_TOKEN_NONE;
2146 case G_TOKEN_STRING:
2147 g_scanner_get_next_token (scanner);
2149 token = G_TOKEN_INT;
2152 g_value_init (&prop->value, G_TYPE_STRING);
2153 g_value_set_string (&prop->value, scanner->value.v_string);
2154 token = G_TOKEN_NONE;
2157 case G_TOKEN_IDENTIFIER:
2158 case G_TOKEN_LEFT_PAREN:
2159 case G_TOKEN_LEFT_CURLY:
2160 case G_TOKEN_LEFT_BRACE:
2163 GString *gstring = g_string_new ("");
2165 token = rc_parse_token_or_compound (scanner, gstring, 0);
2166 if (token == G_TOKEN_NONE)
2168 g_string_append_c (gstring, ' ');
2169 g_value_init (&prop->value, G_TYPE_GSTRING);
2170 g_value_set_static_boxed (&prop->value, gstring);
2173 g_string_free (gstring, TRUE);
2178 g_scanner_get_next_token (scanner);
2179 token = G_TOKEN_INT;
2183 /* restore scanner mode */
2184 scanner->config->scan_identifier = scan_identifier;
2185 scanner->config->scan_symbols = scan_symbols;
2186 scanner->config->identifier_2_string = identifier_2_string;
2187 scanner->config->char_2_token = char_2_token;
2188 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2189 scanner->config->numbers_2_int = numbers_2_int;
2195 is_c_identifier (const gchar *string)
2198 gboolean is_varname;
2200 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2201 for (p = string + 1; *p && is_varname; p++)
2202 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2208 parse_include_file (GtkRcContext *context,
2210 const gchar *filename)
2212 char *to_parse = NULL;
2214 if (g_path_is_absolute (filename))
2216 /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
2217 * don't print an error in this case.
2219 to_parse = g_strdup (filename);
2223 /* if a relative path, we look relative to all the RC files in the
2224 * include stack. We require the file to be found in this case
2225 * so we can give meaningful error messages, and because on reparsing
2226 * non-absolute paths don't make sense.
2228 GSList *tmp_list = rc_dir_stack;
2231 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2233 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2241 tmp_list = tmp_list->next;
2247 gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
2252 g_scanner_warn (scanner,
2253 _("Unable to find include file: \"%s\""),
2260 gtk_rc_parse_statement (GtkRcContext *context,
2265 token = g_scanner_peek_next_token (scanner);
2268 case GTK_RC_TOKEN_INCLUDE:
2269 token = g_scanner_get_next_token (scanner);
2270 if (token != GTK_RC_TOKEN_INCLUDE)
2271 return GTK_RC_TOKEN_INCLUDE;
2272 token = g_scanner_get_next_token (scanner);
2273 if (token != G_TOKEN_STRING)
2274 return G_TOKEN_STRING;
2275 parse_include_file (context, scanner, scanner->value.v_string);
2276 return G_TOKEN_NONE;
2278 case GTK_RC_TOKEN_STYLE:
2279 return gtk_rc_parse_style (context, scanner);
2281 case GTK_RC_TOKEN_BINDING:
2282 return gtk_binding_parse_binding (scanner);
2284 case GTK_RC_TOKEN_PIXMAP_PATH:
2285 return gtk_rc_parse_pixmap_path (context, scanner);
2287 case GTK_RC_TOKEN_WIDGET:
2288 return gtk_rc_parse_path_pattern (context, scanner);
2290 case GTK_RC_TOKEN_WIDGET_CLASS:
2291 return gtk_rc_parse_path_pattern (context, scanner);
2293 case GTK_RC_TOKEN_CLASS:
2294 return gtk_rc_parse_path_pattern (context, scanner);
2296 case GTK_RC_TOKEN_MODULE_PATH:
2297 return gtk_rc_parse_module_path (scanner);
2299 case GTK_RC_TOKEN_IM_MODULE_FILE:
2300 return gtk_rc_parse_im_module_file (scanner);
2302 case G_TOKEN_IDENTIFIER:
2303 if (is_c_identifier (scanner->next_value.v_identifier))
2305 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2308 g_scanner_get_next_token (scanner); /* eat identifier */
2309 name = g_strdup (scanner->value.v_identifier);
2311 token = gtk_rc_parse_assignment (scanner, &prop);
2312 if (token == G_TOKEN_NONE)
2314 GtkSettingsValue svalue;
2316 svalue.origin = prop.origin;
2317 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2318 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2319 gtk_settings_set_property_value (context->settings,
2323 g_free (prop.origin);
2324 if (G_VALUE_TYPE (&prop.value))
2325 g_value_unset (&prop.value);
2332 g_scanner_get_next_token (scanner);
2333 return G_TOKEN_IDENTIFIER;
2336 g_scanner_get_next_token (scanner);
2337 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2342 fixup_rc_set (GSList *list,
2348 GtkRcSet *set = list->data;
2349 if (set->rc_style == orig)
2350 set->rc_style = new;
2356 fixup_rc_sets (GtkRcContext *context,
2360 fixup_rc_set (context->rc_sets_widget, orig, new);
2361 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2362 fixup_rc_set (context->rc_sets_class, orig, new);
2366 gtk_rc_parse_style (GtkRcContext *context,
2369 GtkRcStyle *rc_style;
2370 GtkRcStyle *orig_style;
2371 GtkRcStyle *parent_style;
2374 GtkIconFactory *our_factory = NULL;
2376 token = g_scanner_get_next_token (scanner);
2377 if (token != GTK_RC_TOKEN_STYLE)
2378 return GTK_RC_TOKEN_STYLE;
2380 token = g_scanner_get_next_token (scanner);
2381 if (token != G_TOKEN_STRING)
2382 return G_TOKEN_STRING;
2384 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2386 orig_style = g_object_ref (rc_style);
2390 /* If there's a list, its first member is always the factory belonging
2393 if (rc_style && rc_style->icon_factories)
2394 our_factory = rc_style->icon_factories->data;
2398 rc_style = gtk_rc_style_new ();
2399 rc_style->name = g_strdup (scanner->value.v_string);
2401 for (i = 0; i < 5; i++)
2402 rc_style->bg_pixmap_name[i] = NULL;
2404 for (i = 0; i < 5; i++)
2405 rc_style->color_flags[i] = 0;
2408 token = g_scanner_peek_next_token (scanner);
2409 if (token == G_TOKEN_EQUAL_SIGN)
2411 token = g_scanner_get_next_token (scanner);
2413 token = g_scanner_get_next_token (scanner);
2414 if (token != G_TOKEN_STRING)
2416 token = G_TOKEN_STRING;
2420 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2425 for (i = 0; i < 5; i++)
2427 rc_style->color_flags[i] = parent_style->color_flags[i];
2428 rc_style->fg[i] = parent_style->fg[i];
2429 rc_style->bg[i] = parent_style->bg[i];
2430 rc_style->text[i] = parent_style->text[i];
2431 rc_style->base[i] = parent_style->base[i];
2434 rc_style->xthickness = parent_style->xthickness;
2435 rc_style->ythickness = parent_style->ythickness;
2437 if (parent_style->font_desc)
2439 if (rc_style->font_desc)
2440 pango_font_description_free (rc_style->font_desc);
2441 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2444 if (parent_style->rc_properties)
2448 for (i = 0; i < parent_style->rc_properties->len; i++)
2449 insert_rc_property (rc_style,
2450 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2454 for (i = 0; i < 5; i++)
2456 if (rc_style->bg_pixmap_name[i])
2457 g_free (rc_style->bg_pixmap_name[i]);
2458 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2461 /* Append parent's factories, adding a ref to them */
2462 if (parent_style->icon_factories != NULL)
2464 /* Add a factory for ourselves if we have none,
2465 * in case we end up defining more stock icons.
2466 * I see no real way around this; we need to maintain
2467 * the invariant that the first factory in the list
2468 * is always our_factory, the one belonging to us,
2469 * and if we put parent factories in the list we can't
2470 * do that if the style is reopened.
2472 if (our_factory == NULL)
2474 our_factory = gtk_icon_factory_new ();
2475 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2479 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2480 g_slist_copy (parent_style->icon_factories));
2482 factories = parent_style->icon_factories;
2483 while (factories != NULL)
2485 g_object_ref (G_OBJECT (factories->data));
2486 factories = factories->next;
2492 token = g_scanner_get_next_token (scanner);
2493 if (token != G_TOKEN_LEFT_CURLY)
2495 token = G_TOKEN_LEFT_CURLY;
2499 token = g_scanner_peek_next_token (scanner);
2500 while (token != G_TOKEN_RIGHT_CURLY)
2504 case GTK_RC_TOKEN_BG:
2505 token = gtk_rc_parse_bg (scanner, rc_style);
2507 case GTK_RC_TOKEN_FG:
2508 token = gtk_rc_parse_fg (scanner, rc_style);
2510 case GTK_RC_TOKEN_TEXT:
2511 token = gtk_rc_parse_text (scanner, rc_style);
2513 case GTK_RC_TOKEN_BASE:
2514 token = gtk_rc_parse_base (scanner, rc_style);
2516 case GTK_RC_TOKEN_XTHICKNESS:
2517 token = gtk_rc_parse_xthickness (scanner, rc_style);
2519 case GTK_RC_TOKEN_YTHICKNESS:
2520 token = gtk_rc_parse_ythickness (scanner, rc_style);
2522 case GTK_RC_TOKEN_BG_PIXMAP:
2523 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2525 case GTK_RC_TOKEN_FONT:
2526 token = gtk_rc_parse_font (scanner, rc_style);
2528 case GTK_RC_TOKEN_FONTSET:
2529 token = gtk_rc_parse_fontset (scanner, rc_style);
2531 case GTK_RC_TOKEN_FONT_NAME:
2532 token = gtk_rc_parse_font_name (scanner, rc_style);
2534 case GTK_RC_TOKEN_ENGINE:
2535 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2537 case GTK_RC_TOKEN_STOCK:
2538 if (our_factory == NULL)
2540 our_factory = gtk_icon_factory_new ();
2541 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2544 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2546 case G_TOKEN_IDENTIFIER:
2547 if (is_c_identifier (scanner->next_value.v_identifier) &&
2548 scanner->next_value.v_identifier[0] >= 'A' &&
2549 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2551 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2553 g_scanner_get_next_token (scanner); /* eat type name */
2554 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2555 if (g_scanner_get_next_token (scanner) != ':' ||
2556 g_scanner_get_next_token (scanner) != ':')
2561 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2562 !is_c_identifier (scanner->value.v_identifier))
2564 token = G_TOKEN_IDENTIFIER;
2568 /* it's important that we do the same canonification as GParamSpecPool here */
2569 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2570 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2572 token = gtk_rc_parse_assignment (scanner, &prop);
2573 if (token == G_TOKEN_NONE)
2575 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2576 insert_rc_property (rc_style, &prop, TRUE);
2579 g_free (prop.origin);
2580 if (G_VALUE_TYPE (&prop.value))
2581 g_value_unset (&prop.value);
2585 g_scanner_get_next_token (scanner);
2586 token = G_TOKEN_IDENTIFIER;
2590 g_scanner_get_next_token (scanner);
2591 token = G_TOKEN_RIGHT_CURLY;
2595 if (token != G_TOKEN_NONE)
2598 token = g_scanner_peek_next_token (scanner);
2599 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2601 token = g_scanner_get_next_token (scanner);
2602 if (token != G_TOKEN_RIGHT_CURLY)
2604 token = G_TOKEN_RIGHT_CURLY;
2608 if (rc_style != orig_style)
2610 if (!context->rc_style_ht)
2611 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2612 (GEqualFunc) gtk_rc_style_equal);
2614 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2616 /* If we copied the data into a new rc style, fix up references to the old rc style
2617 * in bindings that we have.
2620 fixup_rc_sets (context, orig_style, rc_style);
2624 g_object_unref (orig_style);
2626 return G_TOKEN_NONE;
2629 if (rc_style != orig_style)
2630 gtk_rc_style_unref (rc_style);
2633 g_object_unref (orig_style);
2638 const GtkRcProperty*
2639 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2641 GQuark property_name)
2643 GtkRcProperty *node = NULL;
2645 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2647 if (rc_style->rc_properties)
2651 key.type_name = type_name;
2652 key.property_name = property_name;
2654 node = bsearch (&key,
2655 rc_style->rc_properties->data, rc_style->rc_properties->len,
2656 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2663 gtk_rc_parse_bg (GScanner *scanner,
2669 token = g_scanner_get_next_token (scanner);
2670 if (token != GTK_RC_TOKEN_BG)
2671 return GTK_RC_TOKEN_BG;
2673 token = gtk_rc_parse_state (scanner, &state);
2674 if (token != G_TOKEN_NONE)
2677 token = g_scanner_get_next_token (scanner);
2678 if (token != G_TOKEN_EQUAL_SIGN)
2679 return G_TOKEN_EQUAL_SIGN;
2681 style->color_flags[state] |= GTK_RC_BG;
2682 return gtk_rc_parse_color (scanner, &style->bg[state]);
2686 gtk_rc_parse_fg (GScanner *scanner,
2692 token = g_scanner_get_next_token (scanner);
2693 if (token != GTK_RC_TOKEN_FG)
2694 return GTK_RC_TOKEN_FG;
2696 token = gtk_rc_parse_state (scanner, &state);
2697 if (token != G_TOKEN_NONE)
2700 token = g_scanner_get_next_token (scanner);
2701 if (token != G_TOKEN_EQUAL_SIGN)
2702 return G_TOKEN_EQUAL_SIGN;
2704 style->color_flags[state] |= GTK_RC_FG;
2705 return gtk_rc_parse_color (scanner, &style->fg[state]);
2709 gtk_rc_parse_text (GScanner *scanner,
2715 token = g_scanner_get_next_token (scanner);
2716 if (token != GTK_RC_TOKEN_TEXT)
2717 return GTK_RC_TOKEN_TEXT;
2719 token = gtk_rc_parse_state (scanner, &state);
2720 if (token != G_TOKEN_NONE)
2723 token = g_scanner_get_next_token (scanner);
2724 if (token != G_TOKEN_EQUAL_SIGN)
2725 return G_TOKEN_EQUAL_SIGN;
2727 style->color_flags[state] |= GTK_RC_TEXT;
2728 return gtk_rc_parse_color (scanner, &style->text[state]);
2732 gtk_rc_parse_base (GScanner *scanner,
2738 token = g_scanner_get_next_token (scanner);
2739 if (token != GTK_RC_TOKEN_BASE)
2740 return GTK_RC_TOKEN_BASE;
2742 token = gtk_rc_parse_state (scanner, &state);
2743 if (token != G_TOKEN_NONE)
2746 token = g_scanner_get_next_token (scanner);
2747 if (token != G_TOKEN_EQUAL_SIGN)
2748 return G_TOKEN_EQUAL_SIGN;
2750 style->color_flags[state] |= GTK_RC_BASE;
2751 return gtk_rc_parse_color (scanner, &style->base[state]);
2755 gtk_rc_parse_xthickness (GScanner *scanner,
2758 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2759 return GTK_RC_TOKEN_XTHICKNESS;
2761 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2762 return G_TOKEN_EQUAL_SIGN;
2764 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2767 style->xthickness = scanner->value.v_int;
2769 return G_TOKEN_NONE;
2773 gtk_rc_parse_ythickness (GScanner *scanner,
2776 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2777 return GTK_RC_TOKEN_YTHICKNESS;
2779 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2780 return G_TOKEN_EQUAL_SIGN;
2782 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2785 style->ythickness = scanner->value.v_int;
2787 return G_TOKEN_NONE;
2791 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2793 GtkRcStyle *rc_style)
2799 token = g_scanner_get_next_token (scanner);
2800 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2801 return GTK_RC_TOKEN_BG_PIXMAP;
2803 token = gtk_rc_parse_state (scanner, &state);
2804 if (token != G_TOKEN_NONE)
2807 token = g_scanner_get_next_token (scanner);
2808 if (token != G_TOKEN_EQUAL_SIGN)
2809 return G_TOKEN_EQUAL_SIGN;
2811 token = g_scanner_get_next_token (scanner);
2812 if (token != G_TOKEN_STRING)
2813 return G_TOKEN_STRING;
2815 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2816 (strcmp (scanner->value.v_string, "<none>") == 0))
2817 pixmap_file = g_strdup (scanner->value.v_string);
2819 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2820 scanner, scanner->value.v_string);
2824 if (rc_style->bg_pixmap_name[state])
2825 g_free (rc_style->bg_pixmap_name[state]);
2826 rc_style->bg_pixmap_name[state] = pixmap_file;
2829 return G_TOKEN_NONE;
2833 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2838 buf = g_build_filename (dir, pixmap_file, NULL);
2840 fd = open (buf, O_RDONLY);
2853 * gtk_rc_find_pixmap_in_path:
2854 * @settings: a #GtkSettings
2855 * @scanner: Scanner used to get line number information for the
2856 * warning message, or %NULL
2857 * @pixmap_file: name of the pixmap file to locate.
2859 * Looks up a file in pixmap path for the specified #GtkSettings.
2860 * If the file is not found, it outputs a warning message using
2861 * g_warning() and returns %NULL.
2863 * Return value: the filename.
2866 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2868 const gchar *pixmap_file)
2874 GtkRcContext *context = gtk_rc_context_get (settings);
2876 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2878 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2883 tmp_list = rc_dir_stack;
2886 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2890 tmp_list = tmp_list->next;
2894 g_scanner_warn (scanner,
2895 _("Unable to locate image file in pixmap_path: \"%s\""),
2898 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2905 * gtk_rc_find_module_in_path:
2906 * @module_file: name of a theme engine
2908 * Searches for a theme engine in the GTK+ search path. This function
2909 * is not useful for applications and should not be used.
2911 * Return value: The filename, if found (must be freed with g_free()),
2915 gtk_rc_find_module_in_path (const gchar *module_file)
2917 return _gtk_find_module (module_file, "engines");
2921 gtk_rc_parse_font (GScanner *scanner,
2922 GtkRcStyle *rc_style)
2926 token = g_scanner_get_next_token (scanner);
2927 if (token != GTK_RC_TOKEN_FONT)
2928 return GTK_RC_TOKEN_FONT;
2930 token = g_scanner_get_next_token (scanner);
2931 if (token != G_TOKEN_EQUAL_SIGN)
2932 return G_TOKEN_EQUAL_SIGN;
2934 token = g_scanner_get_next_token (scanner);
2935 if (token != G_TOKEN_STRING)
2936 return G_TOKEN_STRING;
2938 /* Ignore, do nothing */
2940 return G_TOKEN_NONE;
2944 gtk_rc_parse_fontset (GScanner *scanner,
2945 GtkRcStyle *rc_style)
2949 token = g_scanner_get_next_token (scanner);
2950 if (token != GTK_RC_TOKEN_FONTSET)
2951 return GTK_RC_TOKEN_FONTSET;
2953 token = g_scanner_get_next_token (scanner);
2954 if (token != G_TOKEN_EQUAL_SIGN)
2955 return G_TOKEN_EQUAL_SIGN;
2957 token = g_scanner_get_next_token (scanner);
2958 if (token != G_TOKEN_STRING)
2959 return G_TOKEN_STRING;
2961 /* Do nothing - silently ignore */
2963 return G_TOKEN_NONE;
2967 gtk_rc_parse_font_name (GScanner *scanner,
2968 GtkRcStyle *rc_style)
2972 token = g_scanner_get_next_token (scanner);
2973 if (token != GTK_RC_TOKEN_FONT_NAME)
2974 return GTK_RC_TOKEN_FONT;
2976 token = g_scanner_get_next_token (scanner);
2977 if (token != G_TOKEN_EQUAL_SIGN)
2978 return G_TOKEN_EQUAL_SIGN;
2980 token = g_scanner_get_next_token (scanner);
2981 if (token != G_TOKEN_STRING)
2982 return G_TOKEN_STRING;
2984 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2986 return G_TOKEN_NONE;
2990 gtk_rc_parse_engine (GtkRcContext *context,
2992 GtkRcStyle **rc_style)
2995 GtkThemeEngine *engine;
2996 guint result = G_TOKEN_NONE;
2997 GtkRcStyle *new_style = NULL;
2998 gboolean parsed_curlies = FALSE;
3000 token = g_scanner_get_next_token (scanner);
3001 if (token != GTK_RC_TOKEN_ENGINE)
3002 return GTK_RC_TOKEN_ENGINE;
3004 token = g_scanner_get_next_token (scanner);
3005 if (token != G_TOKEN_STRING)
3006 return G_TOKEN_STRING;
3008 if (!scanner->value.v_string[0])
3010 /* Support engine "" {} to mean override to the default engine
3012 token = g_scanner_get_next_token (scanner);
3013 if (token != G_TOKEN_LEFT_CURLY)
3014 return G_TOKEN_LEFT_CURLY;
3016 token = g_scanner_get_next_token (scanner);
3017 if (token != G_TOKEN_RIGHT_CURLY)
3018 return G_TOKEN_RIGHT_CURLY;
3020 parsed_curlies = TRUE;
3022 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3024 new_style = gtk_rc_style_new ();
3025 gtk_rc_style_real_merge (new_style, *rc_style);
3027 if ((*rc_style)->name)
3028 new_style->name = g_strdup ((*rc_style)->name);
3031 (*rc_style)->engine_specified = TRUE;
3035 engine = gtk_theme_engine_get (scanner->value.v_string);
3037 token = g_scanner_get_next_token (scanner);
3038 if (token != G_TOKEN_LEFT_CURLY)
3039 return G_TOKEN_LEFT_CURLY;
3043 GtkRcStyleClass *new_class;
3045 new_style = gtk_theme_engine_create_rc_style (engine);
3046 g_type_module_unuse (G_TYPE_MODULE (engine));
3048 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3050 new_class->merge (new_style, *rc_style);
3051 if ((*rc_style)->name)
3052 new_style->name = g_strdup ((*rc_style)->name);
3054 if (new_class->parse)
3056 parsed_curlies = TRUE;
3057 result = new_class->parse (new_style, context->settings, scanner);
3059 if (result != G_TOKEN_NONE)
3061 g_object_unref (G_OBJECT (new_style));
3068 if (!parsed_curlies)
3070 /* Skip over remainder, looking for nested {}'s
3074 result = G_TOKEN_RIGHT_CURLY;
3075 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3077 if (token == G_TOKEN_LEFT_CURLY)
3079 else if (token == G_TOKEN_RIGHT_CURLY)
3084 result = G_TOKEN_NONE;
3092 new_style->engine_specified = TRUE;
3094 g_object_unref (G_OBJECT (*rc_style));
3095 *rc_style = new_style;
3102 gtk_rc_parse_state (GScanner *scanner,
3103 GtkStateType *state)
3108 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3109 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3111 /* we don't know where we got called from, so we reset the scope here.
3112 * if we bail out due to errors, we *don't* reset the scope, so the
3113 * error messaging code can make sense of our tokens.
3115 old_scope = g_scanner_set_scope (scanner, 0);
3117 token = g_scanner_get_next_token (scanner);
3118 if (token != G_TOKEN_LEFT_BRACE)
3119 return G_TOKEN_LEFT_BRACE;
3121 token = g_scanner_get_next_token (scanner);
3124 case GTK_RC_TOKEN_ACTIVE:
3125 *state = GTK_STATE_ACTIVE;
3127 case GTK_RC_TOKEN_INSENSITIVE:
3128 *state = GTK_STATE_INSENSITIVE;
3130 case GTK_RC_TOKEN_NORMAL:
3131 *state = GTK_STATE_NORMAL;
3133 case GTK_RC_TOKEN_PRELIGHT:
3134 *state = GTK_STATE_PRELIGHT;
3136 case GTK_RC_TOKEN_SELECTED:
3137 *state = GTK_STATE_SELECTED;
3140 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3143 token = g_scanner_get_next_token (scanner);
3144 if (token != G_TOKEN_RIGHT_BRACE)
3145 return G_TOKEN_RIGHT_BRACE;
3147 g_scanner_set_scope (scanner, old_scope);
3149 return G_TOKEN_NONE;
3153 gtk_rc_parse_priority (GScanner *scanner,
3154 GtkPathPriorityType *priority)
3159 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3160 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3162 /* we don't know where we got called from, so we reset the scope here.
3163 * if we bail out due to errors, we *don't* reset the scope, so the
3164 * error messaging code can make sense of our tokens.
3166 old_scope = g_scanner_set_scope (scanner, 0);
3168 token = g_scanner_get_next_token (scanner);
3172 token = g_scanner_get_next_token (scanner);
3175 case GTK_RC_TOKEN_LOWEST:
3176 *priority = GTK_PATH_PRIO_LOWEST;
3178 case GTK_RC_TOKEN_GTK:
3179 *priority = GTK_PATH_PRIO_GTK;
3181 case GTK_RC_TOKEN_APPLICATION:
3182 *priority = GTK_PATH_PRIO_APPLICATION;
3184 case GTK_RC_TOKEN_THEME:
3185 *priority = GTK_PATH_PRIO_THEME;
3187 case GTK_RC_TOKEN_RC:
3188 *priority = GTK_PATH_PRIO_RC;
3190 case GTK_RC_TOKEN_HIGHEST:
3191 *priority = GTK_PATH_PRIO_HIGHEST;
3194 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3197 g_scanner_set_scope (scanner, old_scope);
3199 return G_TOKEN_NONE;
3203 gtk_rc_parse_color (GScanner *scanner,
3208 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3210 /* we don't need to set our own scope here, because
3211 * we don't need own symbols
3214 token = g_scanner_get_next_token (scanner);
3219 case G_TOKEN_LEFT_CURLY:
3220 token = g_scanner_get_next_token (scanner);
3221 if (token == G_TOKEN_INT)
3222 token_int = scanner->value.v_int;
3223 else if (token == G_TOKEN_FLOAT)
3224 token_int = scanner->value.v_float * 65535.0;
3226 return G_TOKEN_FLOAT;
3227 color->red = CLAMP (token_int, 0, 65535);
3229 token = g_scanner_get_next_token (scanner);
3230 if (token != G_TOKEN_COMMA)
3231 return G_TOKEN_COMMA;
3233 token = g_scanner_get_next_token (scanner);
3234 if (token == G_TOKEN_INT)
3235 token_int = scanner->value.v_int;
3236 else if (token == G_TOKEN_FLOAT)
3237 token_int = scanner->value.v_float * 65535.0;
3239 return G_TOKEN_FLOAT;
3240 color->green = CLAMP (token_int, 0, 65535);
3242 token = g_scanner_get_next_token (scanner);
3243 if (token != G_TOKEN_COMMA)
3244 return G_TOKEN_COMMA;
3246 token = g_scanner_get_next_token (scanner);
3247 if (token == G_TOKEN_INT)
3248 token_int = scanner->value.v_int;
3249 else if (token == G_TOKEN_FLOAT)
3250 token_int = scanner->value.v_float * 65535.0;
3252 return G_TOKEN_FLOAT;
3253 color->blue = CLAMP (token_int, 0, 65535);
3255 token = g_scanner_get_next_token (scanner);
3256 if (token != G_TOKEN_RIGHT_CURLY)
3257 return G_TOKEN_RIGHT_CURLY;
3258 return G_TOKEN_NONE;
3260 case G_TOKEN_STRING:
3261 if (!gdk_color_parse (scanner->value.v_string, color))
3263 g_scanner_warn (scanner, "Invalid color constant '%s'",
3264 scanner->value.v_string);
3265 return G_TOKEN_STRING;
3268 return G_TOKEN_NONE;
3271 return G_TOKEN_STRING;
3276 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3281 token = g_scanner_get_next_token (scanner);
3282 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3283 return GTK_RC_TOKEN_PIXMAP_PATH;
3285 token = g_scanner_get_next_token (scanner);
3286 if (token != G_TOKEN_STRING)
3287 return G_TOKEN_STRING;
3289 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3291 return G_TOKEN_NONE;
3295 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3297 const gchar *pix_path)
3300 gint start_offset = 0;
3304 /* free the old one, or just add to the old one ? */
3305 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3307 g_free (context->pixmap_path[path_num]);
3308 context->pixmap_path[path_num] = NULL;
3313 path_len = strlen (pix_path);
3315 for (end_offset = 0; end_offset <= path_len; end_offset++)
3317 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3318 (end_offset == path_len))
3320 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3321 if (g_path_is_absolute (path_element))
3323 context->pixmap_path[path_num] = path_element;
3325 context->pixmap_path[path_num] = NULL;
3329 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3330 path_element, scanner->input_name, scanner->line);
3331 g_free (path_element);
3334 start_offset = end_offset + 1;
3340 gtk_rc_parse_module_path (GScanner *scanner)
3344 token = g_scanner_get_next_token (scanner);
3345 if (token != GTK_RC_TOKEN_MODULE_PATH)
3346 return GTK_RC_TOKEN_MODULE_PATH;
3348 token = g_scanner_get_next_token (scanner);
3349 if (token != G_TOKEN_STRING)
3350 return G_TOKEN_STRING;
3352 g_warning ("module_path directive is now ignored\n");
3354 return G_TOKEN_NONE;
3358 gtk_rc_parse_im_module_file (GScanner *scanner)
3362 token = g_scanner_get_next_token (scanner);
3363 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3364 return GTK_RC_TOKEN_IM_MODULE_FILE;
3366 token = g_scanner_get_next_token (scanner);
3367 if (token != G_TOKEN_STRING)
3368 return G_TOKEN_STRING;
3371 g_free (im_module_file);
3373 im_module_file = g_strdup (scanner->value.v_string);
3375 return G_TOKEN_NONE;
3379 gtk_rc_parse_path_pattern (GtkRcContext *context,
3383 GtkPathType path_type;
3385 gboolean is_binding;
3386 GtkPathPriorityType priority = context->default_priority;
3388 token = g_scanner_get_next_token (scanner);
3391 case GTK_RC_TOKEN_WIDGET:
3392 path_type = GTK_PATH_WIDGET;
3394 case GTK_RC_TOKEN_WIDGET_CLASS:
3395 path_type = GTK_PATH_WIDGET_CLASS;
3397 case GTK_RC_TOKEN_CLASS:
3398 path_type = GTK_PATH_CLASS;
3401 return GTK_RC_TOKEN_WIDGET_CLASS;
3404 token = g_scanner_get_next_token (scanner);
3405 if (token != G_TOKEN_STRING)
3406 return G_TOKEN_STRING;
3408 pattern = g_strdup (scanner->value.v_string);
3410 token = g_scanner_get_next_token (scanner);
3411 if (token == GTK_RC_TOKEN_STYLE)
3413 else if (token == GTK_RC_TOKEN_BINDING)
3418 return GTK_RC_TOKEN_STYLE;
3421 if (g_scanner_peek_next_token (scanner) == ':')
3423 token = gtk_rc_parse_priority (scanner, &priority);
3424 if (token != G_TOKEN_NONE)
3431 token = g_scanner_get_next_token (scanner);
3432 if (token != G_TOKEN_STRING)
3435 return G_TOKEN_STRING;
3440 GtkBindingSet *binding;
3442 binding = gtk_binding_set_find (scanner->value.v_string);
3446 return G_TOKEN_STRING;
3448 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3452 GtkRcStyle *rc_style;
3455 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3460 return G_TOKEN_STRING;
3463 rc_set = g_new (GtkRcSet, 1);
3464 rc_set->pspec = g_pattern_spec_new (pattern);
3465 rc_set->rc_style = rc_style;
3466 rc_set->priority = priority;
3468 if (path_type == GTK_PATH_WIDGET)
3469 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3470 else if (path_type == GTK_PATH_WIDGET_CLASS)
3471 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3473 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3477 return G_TOKEN_NONE;
3481 gtk_rc_parse_stock_id (GScanner *scanner,
3486 token = g_scanner_get_next_token (scanner);
3487 if (token != G_TOKEN_LEFT_BRACE)
3488 return G_TOKEN_LEFT_BRACE;
3490 token = g_scanner_get_next_token (scanner);
3492 if (token != G_TOKEN_STRING)
3493 return G_TOKEN_STRING;
3495 *stock_id = g_strdup (scanner->value.v_string);
3497 token = g_scanner_get_next_token (scanner);
3498 if (token != G_TOKEN_RIGHT_BRACE)
3501 return G_TOKEN_RIGHT_BRACE;
3504 return G_TOKEN_NONE;
3508 gtk_rc_parse_icon_source (GtkRcContext *context,
3510 GtkIconSet *icon_set,
3511 gboolean *icon_set_valid)
3514 GtkIconSource *source;
3515 gchar *full_filename;
3517 token = g_scanner_get_next_token (scanner);
3518 if (token != G_TOKEN_LEFT_CURLY)
3519 return G_TOKEN_LEFT_CURLY;
3521 token = g_scanner_get_next_token (scanner);
3523 if (token != G_TOKEN_STRING)
3524 return G_TOKEN_STRING;
3527 source = gtk_icon_source_new ();
3529 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3532 gtk_icon_source_set_filename (source, full_filename);
3533 g_free (full_filename);
3536 /* We continue parsing even if we didn't find the pixmap so that rest of the
3537 * file is read, even if the syntax is bad. However we don't validate the
3538 * icon_set so the caller can choose not to install it.
3540 token = g_scanner_get_next_token (scanner);
3542 if (token == G_TOKEN_RIGHT_CURLY)
3544 else if (token != G_TOKEN_COMMA)
3546 gtk_icon_source_free (source);
3547 return G_TOKEN_COMMA;
3550 /* Get the direction */
3552 token = g_scanner_get_next_token (scanner);
3556 case GTK_RC_TOKEN_RTL:
3557 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3558 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3561 case GTK_RC_TOKEN_LTR:
3562 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3563 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3570 gtk_icon_source_free (source);
3571 return GTK_RC_TOKEN_RTL;
3575 token = g_scanner_get_next_token (scanner);
3577 if (token == G_TOKEN_RIGHT_CURLY)
3579 else if (token != G_TOKEN_COMMA)
3581 gtk_icon_source_free (source);
3582 return G_TOKEN_COMMA;
3587 token = g_scanner_get_next_token (scanner);
3591 case GTK_RC_TOKEN_NORMAL:
3592 gtk_icon_source_set_state_wildcarded (source, FALSE);
3593 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3596 case GTK_RC_TOKEN_PRELIGHT:
3597 gtk_icon_source_set_state_wildcarded (source, FALSE);
3598 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3602 case GTK_RC_TOKEN_INSENSITIVE:
3603 gtk_icon_source_set_state_wildcarded (source, FALSE);
3604 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3607 case GTK_RC_TOKEN_ACTIVE:
3608 gtk_icon_source_set_state_wildcarded (source, FALSE);
3609 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3612 case GTK_RC_TOKEN_SELECTED:
3613 gtk_icon_source_set_state_wildcarded (source, FALSE);
3614 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3621 gtk_icon_source_free (source);
3622 return GTK_RC_TOKEN_PRELIGHT;
3626 token = g_scanner_get_next_token (scanner);
3628 if (token == G_TOKEN_RIGHT_CURLY)
3630 else if (token != G_TOKEN_COMMA)
3632 gtk_icon_source_free (source);
3633 return G_TOKEN_COMMA;
3638 token = g_scanner_get_next_token (scanner);
3644 if (token != G_TOKEN_STRING)
3646 gtk_icon_source_free (source);
3647 return G_TOKEN_STRING;
3650 size = gtk_icon_size_from_name (scanner->value.v_string);
3652 if (size != GTK_ICON_SIZE_INVALID)
3654 gtk_icon_source_set_size_wildcarded (source, FALSE);
3655 gtk_icon_source_set_size (source, size);
3659 /* Check the close brace */
3661 token = g_scanner_get_next_token (scanner);
3662 if (token != G_TOKEN_RIGHT_CURLY)
3664 gtk_icon_source_free (source);
3665 return G_TOKEN_RIGHT_CURLY;
3669 if (gtk_icon_source_get_filename (source))
3671 gtk_icon_set_add_source (icon_set, source);
3672 *icon_set_valid = TRUE;
3674 gtk_icon_source_free (source);
3676 return G_TOKEN_NONE;
3680 gtk_rc_parse_stock (GtkRcContext *context,
3682 GtkRcStyle *rc_style,
3683 GtkIconFactory *factory)
3685 GtkIconSet *icon_set = NULL;
3686 gboolean icon_set_valid = FALSE;
3687 gchar *stock_id = NULL;
3690 token = g_scanner_get_next_token (scanner);
3691 if (token != GTK_RC_TOKEN_STOCK)
3692 return GTK_RC_TOKEN_STOCK;
3694 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3695 if (token != G_TOKEN_NONE)
3698 token = g_scanner_get_next_token (scanner);
3699 if (token != G_TOKEN_EQUAL_SIGN)
3702 return G_TOKEN_EQUAL_SIGN;
3705 token = g_scanner_get_next_token (scanner);
3706 if (token != G_TOKEN_LEFT_CURLY)
3709 return G_TOKEN_LEFT_CURLY;
3712 token = g_scanner_peek_next_token (scanner);
3713 while (token != G_TOKEN_RIGHT_CURLY)
3715 if (icon_set == NULL)
3716 icon_set = gtk_icon_set_new ();
3718 token = gtk_rc_parse_icon_source (context,
3719 scanner, icon_set, &icon_set_valid);
3720 if (token != G_TOKEN_NONE)
3723 gtk_icon_set_unref (icon_set);
3727 token = g_scanner_get_next_token (scanner);
3729 if (token != G_TOKEN_COMMA &&
3730 token != G_TOKEN_RIGHT_CURLY)
3733 gtk_icon_set_unref (icon_set);
3734 return G_TOKEN_RIGHT_CURLY;
3738 if (icon_set && icon_set_valid)
3740 gtk_icon_factory_add (factory,
3744 gtk_icon_set_unref (icon_set);
3749 return G_TOKEN_NONE;