1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
48 #include "gdkconfig.h"
50 #include "gtkversion.h"
52 #include "gtkbindings.h"
53 #include "gtkthemes.h"
55 #include "gtkiconfactory.h"
56 #include "gtkprivate.h"
57 #include "gtksettings.h"
58 #include "gtkwindow.h"
64 typedef struct _GtkRcSet GtkRcSet;
65 typedef struct _GtkRcNode GtkRcNode;
66 typedef struct _GtkRcFile GtkRcFile;
77 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
80 gchar *canonical_name;
84 #define GTK_RC_MAX_PIXMAP_PATHS 128
88 GHashTable *rc_style_ht;
89 GtkSettings *settings;
90 GSList *rc_sets_widget;
91 GSList *rc_sets_widget_class;
92 GSList *rc_sets_class;
94 /* The files we have parsed, to reread later if necessary */
98 gchar *key_theme_name;
100 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
102 gint default_priority;
105 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
107 static guint gtk_rc_style_hash (const gchar *name);
108 static gboolean gtk_rc_style_equal (const gchar *a,
110 static guint gtk_rc_styles_hash (const GSList *rc_styles);
111 static gboolean gtk_rc_styles_equal (const GSList *a,
113 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
115 static GSList * gtk_rc_styles_match (GSList *rc_styles,
119 const gchar *path_reversed);
120 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
121 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
122 static void gtk_rc_parse_default_files (GtkRcContext *context);
123 static void gtk_rc_parse_named (GtkRcContext *context,
126 static void gtk_rc_parse_file (GtkRcContext *context,
127 const gchar *filename,
130 static void gtk_rc_parse_any (GtkRcContext *context,
131 const gchar *input_name,
133 const gchar *input_string);
134 static guint gtk_rc_parse_statement (GtkRcContext *context,
136 static guint gtk_rc_parse_style (GtkRcContext *context,
138 static guint gtk_rc_parse_assignment (GScanner *scanner,
139 GtkRcProperty *prop);
140 static guint gtk_rc_parse_bg (GScanner *scanner,
142 static guint gtk_rc_parse_fg (GScanner *scanner,
144 static guint gtk_rc_parse_text (GScanner *scanner,
146 static guint gtk_rc_parse_base (GScanner *scanner,
148 static guint gtk_rc_parse_xthickness (GScanner *scanner,
150 static guint gtk_rc_parse_ythickness (GScanner *scanner,
152 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
154 GtkRcStyle *rc_style);
155 static guint gtk_rc_parse_font (GScanner *scanner,
156 GtkRcStyle *rc_style);
157 static guint gtk_rc_parse_fontset (GScanner *scanner,
158 GtkRcStyle *rc_style);
159 static guint gtk_rc_parse_font_name (GScanner *scanner,
160 GtkRcStyle *rc_style);
161 static guint gtk_rc_parse_engine (GtkRcContext *context,
163 GtkRcStyle **rc_style);
164 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
166 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
168 const gchar *pix_path);
169 static guint gtk_rc_parse_module_path (GScanner *scanner);
170 static void gtk_rc_parse_module_path_string (const gchar *mod_path);
171 static guint gtk_rc_parse_im_module_path (GScanner *scanner);
172 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
173 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
175 static guint gtk_rc_parse_stock (GtkRcContext *context,
177 GtkRcStyle *rc_style,
178 GtkIconFactory *factory);
179 static void gtk_rc_clear_hash_node (gpointer key,
182 static void gtk_rc_clear_styles (GtkRcContext *context);
183 static void gtk_rc_append_default_module_path (void);
184 static void gtk_rc_add_initial_default_files (void);
186 static void gtk_rc_style_init (GtkRcStyle *style);
187 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
188 static void gtk_rc_style_finalize (GObject *object);
189 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
191 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
192 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
193 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
194 gconstpointer bsearch_node2);
196 static gpointer parent_class = NULL;
198 static const GScannerConfig gtk_rc_scanner_config =
202 ) /* cset_skip_characters */,
207 ) /* cset_identifier_first */,
212 ) /* cset_identifier_nth */,
213 ( "#\n" ) /* cpair_comment_single */,
215 TRUE /* case_sensitive */,
217 TRUE /* skip_comment_multi */,
218 TRUE /* skip_comment_single */,
219 TRUE /* scan_comment_multi */,
220 TRUE /* scan_identifier */,
221 FALSE /* scan_identifier_1char */,
222 FALSE /* scan_identifier_NULL */,
223 TRUE /* scan_symbols */,
224 TRUE /* scan_binary */,
225 TRUE /* scan_octal */,
226 TRUE /* scan_float */,
228 TRUE /* scan_hex_dollar */,
229 TRUE /* scan_string_sq */,
230 TRUE /* scan_string_dq */,
231 TRUE /* numbers_2_int */,
232 FALSE /* int_2_float */,
233 FALSE /* identifier_2_string */,
234 TRUE /* char_2_token */,
235 TRUE /* symbol_2_token */,
236 FALSE /* scope_0_fallback */,
244 { "include", GTK_RC_TOKEN_INCLUDE },
245 { "NORMAL", GTK_RC_TOKEN_NORMAL },
246 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
247 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
248 { "SELECTED", GTK_RC_TOKEN_SELECTED },
249 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
250 { "fg", GTK_RC_TOKEN_FG },
251 { "bg", GTK_RC_TOKEN_BG },
252 { "text", GTK_RC_TOKEN_TEXT },
253 { "base", GTK_RC_TOKEN_BASE },
254 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
255 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
256 { "font", GTK_RC_TOKEN_FONT },
257 { "fontset", GTK_RC_TOKEN_FONTSET },
258 { "font_name", GTK_RC_TOKEN_FONT_NAME },
259 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
260 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
261 { "style", GTK_RC_TOKEN_STYLE },
262 { "binding", GTK_RC_TOKEN_BINDING },
263 { "bind", GTK_RC_TOKEN_BIND },
264 { "widget", GTK_RC_TOKEN_WIDGET },
265 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
266 { "class", GTK_RC_TOKEN_CLASS },
267 { "lowest", GTK_RC_TOKEN_LOWEST },
268 { "gtk", GTK_RC_TOKEN_GTK },
269 { "application", GTK_RC_TOKEN_APPLICATION },
270 { "theme", GTK_RC_TOKEN_THEME },
271 { "rc", GTK_RC_TOKEN_RC },
272 { "highest", GTK_RC_TOKEN_HIGHEST },
273 { "engine", GTK_RC_TOKEN_ENGINE },
274 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
275 { "stock", GTK_RC_TOKEN_STOCK },
276 { "im_module_path", GTK_RC_TOKEN_IM_MODULE_PATH },
277 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
278 { "LTR", GTK_RC_TOKEN_LTR },
279 { "RTL", GTK_RC_TOKEN_RTL }
282 static GHashTable *realized_style_ht = NULL;
284 static gchar *im_module_path = NULL;
285 static gchar *im_module_file = NULL;
287 #define GTK_RC_MAX_DEFAULT_FILES 128
288 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
290 #define GTK_RC_MAX_MODULE_PATHS 128
291 static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
293 /* A stack of directories for RC files we are parsing currently.
294 * these are implicitely added to the end of PIXMAP_PATHS
296 static GSList *rc_dir_stack = NULL;
298 /* RC file handling */
301 gtk_rc_make_default_dir (const gchar *type)
306 var = g_getenv ("GTK_EXE_PREFIX");
308 path = g_build_filename (var, "lib", "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
310 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
316 * gtk_rc_get_im_module_path:
317 * @returns: a newly-allocated string containing the path in which to
318 * look for IM modules.
320 * Obtains the path in which to look for IM modules. See the documentation
321 * of the <link linkend="im-module-path"><envar>GTK_IM_MODULE_PATH</envar></link>
322 * environment variable for more details.
325 gtk_rc_get_im_module_path (void)
327 const gchar *result = g_getenv ("GTK_IM_MODULE_PATH");
332 result = im_module_path;
334 return gtk_rc_make_default_dir ("immodules");
337 return g_strdup (result);
341 * gtk_rc_get_im_module_file:
342 * @returns: a newly-allocated string containing the name of the file
343 * listing the IM modules to load
345 * Obtains the path to the IM modules file. See the documentation
346 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
347 * environment variable for more details.
350 gtk_rc_get_im_module_file (void)
352 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
357 result = g_strdup (im_module_file);
359 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
366 gtk_rc_get_theme_dir (void)
371 var = g_getenv ("GTK_DATA_PREFIX");
373 path = g_build_filename (var, "share", "themes", NULL);
375 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
381 gtk_rc_get_module_dir (void)
383 return gtk_rc_make_default_dir ("engines");
387 gtk_rc_append_default_module_path (void)
393 for (n = 0; module_path[n]; n++) ;
394 if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
397 var = g_getenv ("GTK_EXE_PREFIX");
399 path = g_build_filename (var, "lib", "gtk-2.0", GTK_VERSION, "engines", NULL);
401 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_VERSION, "engines", NULL);
402 module_path[n++] = path;
404 var = g_get_home_dir ();
407 path = g_build_filename (var, ".gtk-2.0", GTK_VERSION, "engines", NULL);
408 module_path[n++] = path;
410 module_path[n] = NULL;
414 gtk_rc_add_initial_default_files (void)
416 static gint init = FALSE;
425 gtk_rc_default_files[0] = NULL;
428 var = g_getenv ("GTK_RC_FILES");
431 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
435 gtk_rc_add_default_file (files[i]);
442 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
444 gtk_rc_add_default_file (str);
447 var = g_get_home_dir ();
450 str = g_build_filename (var, ".gtkrc-2.0", NULL);
451 gtk_rc_add_default_file (str);
458 * gtk_rc_add_default_file:
459 * @filename: the pathname to the file.
461 * Adds a file to the list of files to be parsed at the
465 gtk_rc_add_default_file (const gchar *filename)
469 gtk_rc_add_initial_default_files ();
471 for (n = 0; gtk_rc_default_files[n]; n++) ;
472 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
475 gtk_rc_default_files[n++] = g_strdup (filename);
476 gtk_rc_default_files[n] = NULL;
480 * gtk_rc_set_default_files:
481 * @filenames: A %NULL-terminated list of filenames.
483 * Sets the list of files that GTK+ will read at the
487 gtk_rc_set_default_files (gchar **filenames)
491 gtk_rc_add_initial_default_files ();
494 while (gtk_rc_default_files[i])
496 g_free (gtk_rc_default_files[i]);
500 gtk_rc_default_files[0] = NULL;
503 while (filenames[i] != NULL)
505 gtk_rc_add_default_file (filenames[i]);
511 * gtk_rc_get_default_files:
513 * Retrieves the current list of RC files that will be parsed
514 * at the end of gtk_init().
516 * Return value: A %NULL-terminated array of filenames. This memory
517 * is owned by GTK+ and must not be freed by the application.
518 * If you want to store this information, you should make a copy.
521 gtk_rc_get_default_files (void)
523 gtk_rc_add_initial_default_files ();
525 return gtk_rc_default_files;
529 gtk_rc_settings_changed (GtkSettings *settings,
531 GtkRcContext *context)
533 gchar *new_theme_name;
534 gchar *new_key_theme_name;
536 g_object_get (settings,
537 "gtk-theme-name", &new_theme_name,
538 "gtk-key-theme-name", &new_key_theme_name,
541 if ((new_theme_name != context->theme_name &&
542 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
543 (new_key_theme_name != context->key_theme_name &&
544 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
546 gtk_rc_reparse_all_for_settings (settings, TRUE);
549 g_free (new_theme_name);
550 g_free (new_key_theme_name);
553 static GtkRcContext *
554 gtk_rc_context_get (GtkSettings *settings)
556 if (!settings->rc_context)
558 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
560 context->settings = settings;
561 context->rc_style_ht = NULL;
562 context->rc_sets_widget = NULL;
563 context->rc_sets_widget_class = NULL;
564 context->rc_sets_class = NULL;
565 context->rc_files = NULL;
567 g_object_get (settings,
568 "gtk-theme-name", &context->theme_name,
569 "gtk-key-theme-name", &context->key_theme_name,
572 g_signal_connect (settings,
573 "notify::gtk-theme-name",
574 G_CALLBACK (gtk_rc_settings_changed),
576 g_signal_connect (settings,
577 "notify::gtk-key-theme-name",
578 G_CALLBACK (gtk_rc_settings_changed),
581 context->pixmap_path[0] = NULL;
583 context->default_priority = GTK_PATH_PRIO_RC;
586 return settings->rc_context;
590 gtk_rc_parse_named (GtkRcContext *context,
595 const gchar *home_dir;
599 subpath = g_strconcat ("gtk-2.0-", type,
600 G_DIR_SEPARATOR_S "gtkrc",
603 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
605 /* First look in the users home directory
607 home_dir = g_get_home_dir ();
610 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
611 if (!g_file_test (path, G_FILE_TEST_EXISTS))
620 gchar *theme_dir = gtk_rc_get_theme_dir ();
621 path = g_build_filename (theme_dir, name, subpath, NULL);
624 if (!g_file_test (path, G_FILE_TEST_EXISTS))
633 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
641 gtk_rc_parse_default_files (GtkRcContext *context)
645 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
646 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
652 static gboolean initialized = FALSE;
658 module_path[0] = NULL;
659 gtk_rc_append_default_module_path();
661 gtk_rc_add_initial_default_files ();
664 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
668 gtk_rc_parse_string (const gchar *rc_string)
671 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
672 * string in all contexts, and in fact, in future contexts as well.
674 GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
676 g_return_if_fail (rc_string != NULL);
678 rc_file = g_new (GtkRcFile, 1);
679 rc_file->is_string = TRUE;
680 rc_file->name = g_strdup (rc_string);
681 rc_file->canonical_name = NULL;
683 rc_file->reload = TRUE;
685 context->rc_files = g_slist_append (context->rc_files, rc_file);
687 gtk_rc_parse_any (context, "-", -1, rc_string);
691 gtk_rc_parse_one_file (GtkRcContext *context,
692 const gchar *filename,
696 GtkRcFile *rc_file = NULL;
701 g_return_if_fail (filename != NULL);
703 saved_priority = context->default_priority;
704 context->default_priority = priority;
706 tmp_list = context->rc_files;
709 rc_file = tmp_list->data;
710 if (!strcmp (rc_file->name, filename))
713 tmp_list = tmp_list->next;
718 rc_file = g_new (GtkRcFile, 1);
719 rc_file->is_string = FALSE;
720 rc_file->name = g_strdup (filename);
721 rc_file->canonical_name = NULL;
723 rc_file->reload = reload;
725 context->rc_files = g_slist_append (context->rc_files, rc_file);
728 if (!rc_file->canonical_name)
730 /* Get the absolute pathname */
732 if (g_path_is_absolute (rc_file->name))
733 rc_file->canonical_name = rc_file->name;
738 cwd = g_get_current_dir ();
739 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
744 if (!lstat (rc_file->canonical_name, &statbuf))
749 rc_file->mtime = statbuf.st_mtime;
751 fd = open (rc_file->canonical_name, O_RDONLY);
755 /* Temporarily push directory name for this file on
756 * a stack of directory names while parsing it
759 g_slist_prepend (rc_dir_stack,
760 g_path_get_dirname (rc_file->canonical_name));
761 gtk_rc_parse_any (context, filename, fd, NULL);
763 tmp_list = rc_dir_stack;
764 rc_dir_stack = rc_dir_stack->next;
766 g_free (tmp_list->data);
767 g_slist_free_1 (tmp_list);
773 context->default_priority = saved_priority;
777 strchr_len (const gchar *str, gint len, char c)
791 gtk_rc_parse_file (GtkRcContext *context,
792 const gchar *filename,
796 gchar *locale_suffixes[2];
797 gint n_locale_suffixes = 0;
801 gboolean found = FALSE;
804 locale = g_win32_getlocale ();
806 locale = setlocale (LC_CTYPE, NULL);
809 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
811 /* Determine locale-specific suffixes for RC files
813 * We normalize the charset into a standard form,
814 * which has all '-' and '_' characters removed,
817 length = strlen (locale);
819 p = strchr (locale, '@');
823 p = strchr_len (locale, length, '.');
827 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
829 p = strchr_len (locale, length, '_');
833 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
837 gtk_rc_parse_one_file (context, filename, priority, reload);
838 for (j = 0; j < n_locale_suffixes; j++)
842 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
843 if (g_file_test (name, G_FILE_TEST_EXISTS))
845 gtk_rc_parse_one_file (context, name, priority, FALSE);
852 g_free (locale_suffixes[j]);
857 gtk_rc_parse (const gchar *filename)
859 g_return_if_fail (filename != NULL);
861 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
862 * file in all contexts, and in fact, in future contexts as well.
864 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
865 filename, GTK_PATH_PRIO_RC, TRUE);
868 /* Handling of RC styles */
871 gtk_rc_style_get_type (void)
873 static GType object_type = 0;
877 static const GTypeInfo object_info =
879 sizeof (GtkRcStyleClass),
880 (GBaseInitFunc) NULL,
881 (GBaseFinalizeFunc) NULL,
882 (GClassInitFunc) gtk_rc_style_class_init,
883 NULL, /* class_finalize */
884 NULL, /* class_data */
887 (GInstanceInitFunc) gtk_rc_style_init,
890 object_type = g_type_register_static (G_TYPE_OBJECT,
899 gtk_rc_style_init (GtkRcStyle *style)
904 style->font_desc = NULL;
906 for (i = 0; i < 5; i++)
908 static const GdkColor init_color = { 0, 0, 0, 0, };
910 style->bg_pixmap_name[i] = NULL;
911 style->color_flags[i] = 0;
912 style->fg[i] = init_color;
913 style->bg[i] = init_color;
914 style->text[i] = init_color;
915 style->base[i] = init_color;
917 style->xthickness = -1;
918 style->ythickness = -1;
919 style->rc_properties = NULL;
921 style->rc_style_lists = NULL;
922 style->icon_factories = NULL;
926 gtk_rc_style_class_init (GtkRcStyleClass *klass)
928 GObjectClass *object_class = G_OBJECT_CLASS (klass);
930 parent_class = g_type_class_peek_parent (klass);
932 object_class->finalize = gtk_rc_style_finalize;
935 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
936 klass->merge = gtk_rc_style_real_merge;
937 klass->create_style = gtk_rc_style_real_create_style;
941 gtk_rc_style_finalize (GObject *object)
943 GSList *tmp_list1, *tmp_list2;
944 GtkRcStyle *rc_style;
947 rc_style = GTK_RC_STYLE (object);
950 g_free (rc_style->name);
951 if (rc_style->font_desc)
952 pango_font_description_free (rc_style->font_desc);
954 for (i = 0; i < 5; i++)
955 if (rc_style->bg_pixmap_name[i])
956 g_free (rc_style->bg_pixmap_name[i]);
958 /* Now remove all references to this rc_style from
961 tmp_list1 = rc_style->rc_style_lists;
964 GSList *rc_styles = tmp_list1->data;
965 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
966 gtk_style_unref (style);
968 /* Remove the list of styles from the other rc_styles
971 tmp_list2 = rc_styles;
974 GtkRcStyle *other_style = tmp_list2->data;
976 if (other_style != rc_style)
977 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
979 tmp_list2 = tmp_list2->next;
982 /* And from the hash table itself
984 g_hash_table_remove (realized_style_ht, rc_styles);
985 g_slist_free (rc_styles);
987 tmp_list1 = tmp_list1->next;
989 g_slist_free (rc_style->rc_style_lists);
991 if (rc_style->rc_properties)
995 for (i = 0; i < rc_style->rc_properties->len; i++)
997 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
999 g_free (node->origin);
1000 g_value_unset (&node->value);
1002 g_array_free (rc_style->rc_properties, TRUE);
1003 rc_style->rc_properties = NULL;
1006 tmp_list1 = rc_style->icon_factories;
1009 g_object_unref (G_OBJECT (tmp_list1->data));
1011 tmp_list1 = tmp_list1->next;
1013 g_slist_free (rc_style->icon_factories);
1015 G_OBJECT_CLASS (parent_class)->finalize (object);
1019 gtk_rc_style_new (void)
1023 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1029 * gtk_rc_style_copy:
1030 * @orig: the style to copy
1032 * Makes a copy of the specified #GtkRcStyle. This function
1033 * will correctly copy an RC style that is a member of a class
1034 * derived from #GtkRcStyle.
1036 * Return value: the resulting #GtkRcStyle
1039 gtk_rc_style_copy (GtkRcStyle *orig)
1043 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1045 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1046 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1052 gtk_rc_style_ref (GtkRcStyle *rc_style)
1054 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1056 g_object_ref (G_OBJECT (rc_style));
1060 gtk_rc_style_unref (GtkRcStyle *rc_style)
1062 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1064 g_object_unref (G_OBJECT (rc_style));
1068 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1070 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1074 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1075 gconstpointer bsearch_node2)
1077 const GtkRcProperty *prop1 = bsearch_node1;
1078 const GtkRcProperty *prop2 = bsearch_node2;
1080 if (prop1->type_name == prop2->type_name)
1081 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1083 return prop1->type_name < prop2->type_name ? -1 : 1;
1087 insert_rc_property (GtkRcStyle *style,
1088 GtkRcProperty *property,
1092 GtkRcProperty *new_property = NULL;
1093 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1095 key.type_name = property->type_name;
1096 key.property_name = property->property_name;
1098 if (!style->rc_properties)
1099 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1102 while (i < style->rc_properties->len)
1104 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1110 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1112 g_free (new_property->origin);
1113 g_value_unset (&new_property->value);
1115 *new_property = key;
1129 g_array_insert_val (style->rc_properties, i, key);
1130 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1133 new_property->origin = g_strdup (property->origin);
1134 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1135 g_value_copy (&property->value, &new_property->value);
1139 gtk_rc_style_real_merge (GtkRcStyle *dest,
1144 for (i = 0; i < 5; i++)
1146 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1147 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1149 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1150 src->color_flags[i] & GTK_RC_FG)
1152 dest->fg[i] = src->fg[i];
1153 dest->color_flags[i] |= GTK_RC_FG;
1155 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1156 src->color_flags[i] & GTK_RC_BG)
1158 dest->bg[i] = src->bg[i];
1159 dest->color_flags[i] |= GTK_RC_BG;
1161 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1162 src->color_flags[i] & GTK_RC_TEXT)
1164 dest->text[i] = src->text[i];
1165 dest->color_flags[i] |= GTK_RC_TEXT;
1167 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1168 src->color_flags[i] & GTK_RC_BASE)
1170 dest->base[i] = src->base[i];
1171 dest->color_flags[i] |= GTK_RC_BASE;
1175 if (dest->xthickness < 0 && src->xthickness >= 0)
1176 dest->xthickness = src->xthickness;
1177 if (dest->ythickness < 0 && src->ythickness >= 0)
1178 dest->ythickness = src->ythickness;
1182 if (!dest->font_desc)
1183 dest->font_desc = pango_font_description_copy (src->font_desc);
1185 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1188 if (src->rc_properties)
1192 for (i = 0; i < src->rc_properties->len; i++)
1193 insert_rc_property (dest,
1194 &g_array_index (src->rc_properties, GtkRcProperty, i),
1200 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1202 return gtk_style_new ();
1206 gtk_rc_clear_hash_node (gpointer key,
1210 gtk_rc_style_unref (data);
1214 gtk_rc_free_rc_sets (GSList *slist)
1220 rc_set = slist->data;
1221 g_pattern_spec_free (rc_set->pspec);
1224 slist = slist->next;
1229 gtk_rc_clear_styles (GtkRcContext *context)
1231 /* Clear out all old rc_styles */
1233 if (context->rc_style_ht)
1235 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1236 g_hash_table_destroy (context->rc_style_ht);
1237 context->rc_style_ht = NULL;
1240 gtk_rc_free_rc_sets (context->rc_sets_widget);
1241 g_slist_free (context->rc_sets_widget);
1242 context->rc_sets_widget = NULL;
1244 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1245 g_slist_free (context->rc_sets_widget_class);
1246 context->rc_sets_widget_class = NULL;
1248 gtk_rc_free_rc_sets (context->rc_sets_class);
1249 g_slist_free (context->rc_sets_class);
1250 context->rc_sets_class = NULL;
1253 /* Reset all our widgets. Also, we have to invalidate cached icons in
1254 * icon sets so they get re-rendered.
1257 gtk_rc_reset_widgets (GtkRcContext *context)
1259 GList *list, *toplevels;
1261 _gtk_icon_set_invalidate_caches ();
1263 toplevels = gtk_window_list_toplevels ();
1264 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1266 for (list = toplevels; list; list = list->next)
1268 gtk_widget_reset_rc_styles (list->data);
1269 gtk_widget_unref (list->data);
1271 g_list_free (toplevels);
1275 * gtk_rc_reparse_all_for_settings:
1276 * @settings: a #GtkSettings
1277 * @force_load: load whether or not anything changed
1279 * If the modification time on any previously read file
1280 * for the given #GtkSettings has changed, discard all style information
1281 * and then reread all previously read RC files.
1283 * Return value: %TRUE if the files were reread.
1286 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1287 gboolean force_load)
1289 gboolean mtime_modified = FALSE;
1292 GtkRcContext *context;
1294 struct stat statbuf;
1296 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1298 context = gtk_rc_context_get (settings);
1302 /* Check through and see if any of the RC's have had their
1303 * mtime modified. If so, reparse everything.
1305 tmp_list = context->rc_files;
1308 rc_file = tmp_list->data;
1310 if (!rc_file->is_string)
1312 if (!lstat (rc_file->name, &statbuf) &&
1313 (statbuf.st_mtime > rc_file->mtime))
1315 mtime_modified = TRUE;
1320 tmp_list = tmp_list->next;
1324 if (force_load || mtime_modified)
1328 gtk_rc_clear_styles (context);
1329 g_object_freeze_notify (G_OBJECT (context->settings));
1331 old_files = context->rc_files;
1332 context->rc_files = NULL;
1334 gtk_rc_parse_default_files (context);
1336 tmp_list = old_files;
1339 rc_file = tmp_list->data;
1340 if (rc_file->reload)
1342 if (rc_file->is_string)
1343 gtk_rc_parse_string (rc_file->name);
1345 gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
1348 if (rc_file->canonical_name != rc_file->name)
1349 g_free (rc_file->canonical_name);
1350 g_free (rc_file->name);
1353 tmp_list = tmp_list->next;
1356 g_slist_free (old_files);;
1358 g_free (context->theme_name);
1359 g_free (context->key_theme_name);
1360 g_object_get (context->settings,
1361 "gtk-theme-name", &context->theme_name,
1362 "gtk-key-theme-name", &context->key_theme_name,
1365 if (context->theme_name && context->theme_name[0])
1366 gtk_rc_parse_named (context, context->theme_name, NULL);
1367 if (context->key_theme_name && context->key_theme_name[0])
1368 gtk_rc_parse_named (context, context->key_theme_name, "key");
1370 g_object_thaw_notify (G_OBJECT (context->settings));
1372 gtk_rc_reset_widgets (context);
1375 return mtime_modified;
1379 * gtk_rc_reparse_all:
1381 * If the modification time on any previously read file for the
1382 * default #GtkSettings has changed, discard all style information
1383 * and then reread all previously read RC files.
1385 * Return value: %TRUE if the files were reread.
1388 gtk_rc_reparse_all (void)
1390 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1394 gtk_rc_styles_match (GSList *rc_styles,
1398 const gchar *path_reversed)
1405 rc_set = sets->data;
1408 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1409 rc_styles = g_slist_append (rc_styles, rc_set);
1416 rc_set_compare (gconstpointer a, gconstpointer b)
1418 const GtkRcSet *set_a = a;
1419 const GtkRcSet *set_b = b;
1421 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1425 sort_and_dereference_sets (GSList *styles)
1429 /* At this point, the list of sets is ordered by:
1431 * a) 'widget' patterns are earlier than 'widget_class' patterns
1432 * which are ealier than 'class' patterns.
1433 * a) For two matches for class patterns, a match to a child type
1434 * is before a match to a parent type
1435 * c) a match later in the RC file (or in a later RC file) is before a
1436 * match earlier in the RC file.
1438 * With a) taking precedence over b) which takes precendence over c).
1440 * Now sort by priority, which has the highest precendence for sort order
1442 styles = g_slist_sort (styles, rc_set_compare);
1444 /* Make styles->data = styles->data->rc_style
1449 GtkRcSet *set = tmp_list->data;
1450 tmp_list->data = set->rc_style;
1451 tmp_list = tmp_list->next;
1459 * @widget: a #GtkWidget
1461 * Finds all matching RC styles for a given widget,
1462 * composites them together, and then creates a
1463 * #GtkStyle representing the composite appearance.
1464 * (GTK+ actually keeps a cache of previously
1465 * created styles, so a new style may not be
1468 * Returns: the resulting style. No refcount is added
1469 * to the returned style, so if you want to save this
1470 * style around, you should add a reference yourself.
1473 gtk_rc_get_style (GtkWidget *widget)
1475 GtkRcStyle *widget_rc_style;
1476 GSList *rc_styles = NULL;
1477 GtkRcContext *context;
1479 static guint rc_style_key_id = 0;
1481 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1483 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1485 /* We allow the specification of a single rc style to be bound
1486 * tightly to a widget, for application modifications
1488 if (!rc_style_key_id)
1489 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1491 if (context->rc_sets_widget)
1493 gchar *path, *path_reversed;
1496 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1497 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1499 g_free (path_reversed);
1502 if (context->rc_sets_widget_class)
1504 gchar *path, *path_reversed;
1507 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1508 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1510 g_free (path_reversed);
1513 if (context->rc_sets_class)
1517 type = GTK_OBJECT_TYPE (widget);
1521 gchar *path_reversed;
1524 path = gtk_type_name (type);
1525 path_length = strlen (path);
1526 path_reversed = g_strdup (path);
1527 g_strreverse (path_reversed);
1529 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1530 g_free (path_reversed);
1532 type = gtk_type_parent (type);
1536 rc_styles = sort_and_dereference_sets (rc_styles);
1538 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1541 if (widget_rc_style)
1542 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1545 return gtk_rc_init_style (rc_styles);
1551 * gtk_rc_get_style_by_paths:
1552 * @settings: a #GtkSettings object
1553 * @widget_path: the widget path to use when looking up the style, or %NULL
1554 * @class_path: the class path to use when looking up the style, or %NULL
1555 * @type: a type that will be used along with parent types of this type
1556 * when matching against class styles, or #G_TYPE_NONE
1558 * Creates up a #GtkStyle from styles defined in a RC file by providing
1559 * the raw components used in matching. This function may be useful
1560 * when creating pseudo-widgets that should be themed like widgets but
1561 * don't actually have corresponding GTK+ widgets. An example of this
1562 * would be items inside a GNOME canvas widget.
1564 * The action of gtk_rc_get_style() is similar to:
1565 * <informalexample><programlisting>
1566 * <!> gtk_widget_path (widget, NULL, &path, NULL);
1567 * <!> gtk_widget_class_path (widget, NULL, &class_path, NULL);
1568 * <!> gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1569 * <!> G_OBJECT_TYPE (widget));
1570 * </programlisting></informalexample>
1572 * Return value: A style created by matching with the supplied paths,
1573 * or %NULL if nothing matching was specified and the default style should
1574 * be used. The returned value is owned by GTK+ as part of an internal cache,
1575 * so you must call g_object_ref() on the returned value if you want to
1576 * keep a reference to it.
1579 gtk_rc_get_style_by_paths (GtkSettings *settings,
1580 const char *widget_path,
1581 const char *class_path,
1584 /* We duplicate the code from above to avoid slowing down the above
1585 * by generating paths when we don't need them. I don't know if
1586 * this is really worth it.
1588 GSList *rc_styles = NULL;
1589 GtkRcContext *context;
1591 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1593 context = gtk_rc_context_get (settings);
1595 if (context->rc_sets_widget)
1597 gchar *path_reversed;
1600 path_length = strlen (widget_path);
1601 path_reversed = g_strdup (widget_path);
1602 g_strreverse (path_reversed);
1604 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1605 g_free (path_reversed);
1608 if (context->rc_sets_widget_class)
1610 gchar *path_reversed;
1613 path_length = strlen (class_path);
1614 path_reversed = g_strdup (class_path);
1615 g_strreverse (path_reversed);
1617 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1618 g_free (path_reversed);
1621 if (type != G_TYPE_NONE && context->rc_sets_class)
1626 gchar *path_reversed;
1629 path = g_type_name (type);
1630 path_length = strlen (path);
1631 path_reversed = g_strdup (path);
1632 g_strreverse (path_reversed);
1634 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1635 g_free (path_reversed);
1637 type = g_type_parent (type);
1641 rc_styles = sort_and_dereference_sets (rc_styles);
1644 return gtk_rc_init_style (rc_styles);
1650 gtk_rc_add_rc_sets (GSList *slist,
1651 GtkRcStyle *rc_style,
1652 const gchar *pattern)
1654 GtkRcStyle *new_style;
1658 new_style = gtk_rc_style_new ();
1659 *new_style = *rc_style;
1660 new_style->name = g_strdup (rc_style->name);
1661 if (rc_style->font_desc)
1662 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1664 for (i = 0; i < 5; i++)
1665 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1667 rc_set = g_new (GtkRcSet, 1);
1668 rc_set->pspec = g_pattern_spec_new (pattern);
1669 rc_set->rc_style = rc_style;
1671 return g_slist_prepend (slist, rc_set);
1675 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1676 const gchar *pattern)
1678 GtkRcContext *context;
1680 g_return_if_fail (rc_style != NULL);
1681 g_return_if_fail (pattern != NULL);
1683 context = gtk_rc_context_get (gtk_settings_get_default ());
1685 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1689 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1690 const gchar *pattern)
1692 GtkRcContext *context;
1694 g_return_if_fail (rc_style != NULL);
1695 g_return_if_fail (pattern != NULL);
1697 context = gtk_rc_context_get (gtk_settings_get_default ());
1699 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1703 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1704 const gchar *pattern)
1706 GtkRcContext *context;
1708 g_return_if_fail (rc_style != NULL);
1709 g_return_if_fail (pattern != NULL);
1711 context = gtk_rc_context_get (gtk_settings_get_default ());
1713 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1717 gtk_rc_scanner_new (void)
1719 return g_scanner_new (>k_rc_scanner_config);
1723 gtk_rc_parse_any (GtkRcContext *context,
1724 const gchar *input_name,
1726 const gchar *input_string)
1732 scanner = gtk_rc_scanner_new ();
1736 g_assert (input_string == NULL);
1738 g_scanner_input_file (scanner, input_fd);
1742 g_assert (input_string != NULL);
1744 g_scanner_input_text (scanner, input_string, strlen (input_string));
1746 scanner->input_name = input_name;
1748 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1749 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1754 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1758 guint expected_token;
1760 expected_token = gtk_rc_parse_statement (context, scanner);
1762 if (expected_token != G_TOKEN_NONE)
1769 if (scanner->scope_id == 0)
1771 /* if we are in scope 0, we know the symbol names
1772 * that are associated with certain token values.
1773 * so we look them up to make the error messages
1776 if (expected_token > GTK_RC_TOKEN_INVALID &&
1777 expected_token < GTK_RC_TOKEN_LAST)
1779 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1780 if (symbols[i].token == expected_token)
1781 msg = symbols[i].name;
1783 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1785 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1786 scanner->token < GTK_RC_TOKEN_LAST)
1788 symbol_name = "???";
1789 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1790 if (symbols[i].token == scanner->token)
1791 symbol_name = symbols[i].name;
1794 g_scanner_unexp_token (scanner,
1807 g_scanner_destroy (scanner);
1811 gtk_rc_styles_hash (const GSList *rc_styles)
1818 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1819 rc_styles = rc_styles->next;
1826 gtk_rc_styles_equal (const GSList *a,
1831 if (a->data != b->data)
1841 gtk_rc_style_hash (const gchar *name)
1847 result += (result << 3) + *name++;
1853 gtk_rc_style_equal (const gchar *a,
1856 return (strcmp (a, b) == 0);
1860 gtk_rc_style_find (GtkRcContext *context,
1863 if (context->rc_style_ht)
1864 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1870 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1874 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1876 style->rc_style = rc_style;
1878 gtk_rc_style_ref (rc_style);
1880 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1885 /* Reuses or frees rc_styles */
1887 gtk_rc_init_style (GSList *rc_styles)
1889 GtkStyle *style = NULL;
1892 g_return_val_if_fail (rc_styles != NULL, NULL);
1894 if (!realized_style_ht)
1895 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1896 (GEqualFunc) gtk_rc_styles_equal);
1898 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1902 GtkRcStyle *base_style = NULL;
1903 GtkRcStyle *proto_style;
1904 GtkRcStyleClass *proto_style_class;
1906 GType rc_style_type = GTK_TYPE_RC_STYLE;
1908 /* Find the the first style where the RC file specified engine "" {}
1909 * or the first derived style and use that to create the
1910 * merged style. If we only have raw GtkRcStyles, use the first
1911 * style to create the merged style.
1913 base_style = rc_styles->data;
1914 tmp_styles = rc_styles;
1917 GtkRcStyle *rc_style = tmp_styles->data;
1919 if (rc_style->engine_specified ||
1920 G_OBJECT_TYPE (rc_style) != rc_style_type)
1922 base_style = rc_style;
1926 tmp_styles = tmp_styles->next;
1929 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1930 proto_style = proto_style_class->create_rc_style (base_style);
1932 tmp_styles = rc_styles;
1935 GtkRcStyle *rc_style = tmp_styles->data;
1938 proto_style_class->merge (proto_style, rc_style);
1940 /* Point from each rc_style to the list of styles */
1941 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1942 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1944 factories = g_slist_copy (rc_style->icon_factories);
1950 while (iter != NULL)
1952 g_object_ref (G_OBJECT (iter->data));
1953 iter = g_slist_next (iter);
1956 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1961 tmp_styles = tmp_styles->next;
1964 for (i = 0; i < 5; i++)
1965 if (proto_style->bg_pixmap_name[i] &&
1966 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
1968 g_free (proto_style->bg_pixmap_name[i]);
1969 proto_style->bg_pixmap_name[i] = NULL;
1972 style = gtk_rc_style_to_style (proto_style);
1973 gtk_rc_style_unref (proto_style);
1975 g_hash_table_insert (realized_style_ht, rc_styles, style);
1978 g_slist_free (rc_styles);
1983 /*********************
1984 * Parsing functions *
1985 *********************/
1988 rc_parse_token_or_compound (GScanner *scanner,
1990 GTokenType delimiter)
1992 guint token = g_scanner_get_next_token (scanner);
1994 /* we either scan a single token (skipping comments)
1995 * or a compund statement.
1996 * compunds are enclosed in (), [] or {} braces, we read
1997 * them in via deep recursion.
2004 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2007 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2009 case G_TOKEN_STRING:
2010 string = g_strescape (scanner->value.v_string, NULL);
2011 g_string_append (gstring, " \"");
2012 g_string_append (gstring, string);
2013 g_string_append_c (gstring, '"');
2016 case G_TOKEN_IDENTIFIER:
2017 g_string_append_c (gstring, ' ');
2018 g_string_append (gstring, scanner->value.v_identifier);
2020 case G_TOKEN_COMMENT_SINGLE:
2021 case G_TOKEN_COMMENT_MULTI:
2022 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2023 case G_TOKEN_LEFT_PAREN:
2024 g_string_append_c (gstring, ' ');
2025 g_string_append_c (gstring, token);
2026 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2027 if (token != G_TOKEN_NONE)
2030 case G_TOKEN_LEFT_CURLY:
2031 g_string_append_c (gstring, ' ');
2032 g_string_append_c (gstring, token);
2033 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2034 if (token != G_TOKEN_NONE)
2037 case G_TOKEN_LEFT_BRACE:
2038 g_string_append_c (gstring, ' ');
2039 g_string_append_c (gstring, token);
2040 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2041 if (token != G_TOKEN_NONE)
2045 if (token >= 256 || token < 1)
2046 return delimiter ? delimiter : G_TOKEN_STRING;
2047 g_string_append_c (gstring, ' ');
2048 g_string_append_c (gstring, token);
2049 if (token == delimiter)
2050 return G_TOKEN_NONE;
2054 return G_TOKEN_NONE;
2056 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2060 gtk_rc_parse_assignment (GScanner *scanner,
2061 GtkRcProperty *prop)
2063 gboolean scan_identifier = scanner->config->scan_identifier;
2064 gboolean scan_symbols = scanner->config->scan_symbols;
2065 gboolean identifier_2_string = scanner->config->identifier_2_string;
2066 gboolean char_2_token = scanner->config->char_2_token;
2067 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2068 gboolean numbers_2_int = scanner->config->numbers_2_int;
2069 gboolean negate = FALSE;
2072 /* check that this is an assignment */
2073 if (g_scanner_get_next_token (scanner) != '=')
2076 /* adjust scanner mode */
2077 scanner->config->scan_identifier = TRUE;
2078 scanner->config->scan_symbols = FALSE;
2079 scanner->config->identifier_2_string = FALSE;
2080 scanner->config->char_2_token = TRUE;
2081 scanner->config->scan_identifier_NULL = FALSE;
2082 scanner->config->numbers_2_int = TRUE;
2084 /* record location */
2085 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2087 /* parse optional sign */
2088 if (g_scanner_peek_next_token (scanner) == '-')
2090 g_scanner_get_next_token (scanner); /* eat sign */
2094 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2095 token = g_scanner_peek_next_token (scanner);
2099 g_scanner_get_next_token (scanner);
2100 g_value_init (&prop->value, G_TYPE_LONG);
2101 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2102 token = G_TOKEN_NONE;
2105 g_scanner_get_next_token (scanner);
2106 g_value_init (&prop->value, G_TYPE_DOUBLE);
2107 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2108 token = G_TOKEN_NONE;
2110 case G_TOKEN_STRING:
2111 g_scanner_get_next_token (scanner);
2113 token = G_TOKEN_INT;
2116 g_value_init (&prop->value, G_TYPE_STRING);
2117 g_value_set_string (&prop->value, scanner->value.v_string);
2118 token = G_TOKEN_NONE;
2121 case G_TOKEN_IDENTIFIER:
2122 case G_TOKEN_LEFT_PAREN:
2123 case G_TOKEN_LEFT_CURLY:
2124 case G_TOKEN_LEFT_BRACE:
2127 GString *gstring = g_string_new ("");
2129 token = rc_parse_token_or_compound (scanner, gstring, 0);
2130 if (token == G_TOKEN_NONE)
2132 g_string_append_c (gstring, ' ');
2133 g_value_init (&prop->value, G_TYPE_GSTRING);
2134 g_value_set_static_boxed (&prop->value, gstring);
2137 g_string_free (gstring, TRUE);
2142 g_scanner_get_next_token (scanner);
2143 token = G_TOKEN_INT;
2147 /* restore scanner mode */
2148 scanner->config->scan_identifier = scan_identifier;
2149 scanner->config->scan_symbols = scan_symbols;
2150 scanner->config->identifier_2_string = identifier_2_string;
2151 scanner->config->char_2_token = char_2_token;
2152 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2153 scanner->config->numbers_2_int = numbers_2_int;
2159 is_c_identifier (const gchar *string)
2162 gboolean is_varname;
2164 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2165 for (p = string + 1; *p && is_varname; p++)
2166 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2172 parse_include_file (GtkRcContext *context,
2174 const gchar *filename)
2176 char *to_parse = NULL;
2178 if (g_path_is_absolute (filename))
2180 /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
2181 * don't print an error in this case.
2183 to_parse = g_strdup (filename);
2187 /* if a relative path, we look relative to all the RC files in the
2188 * include stack. We require the file to be found in this case
2189 * so we can give meaningful error messages, and because on reparsing
2190 * non-absolute paths don't make sense.
2192 GSList *tmp_list = rc_dir_stack;
2195 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2197 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2205 tmp_list = tmp_list->next;
2211 gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
2216 g_scanner_warn (scanner,
2217 _("Unable to find include file: \"%s\""),
2224 gtk_rc_parse_statement (GtkRcContext *context,
2229 token = g_scanner_peek_next_token (scanner);
2232 case GTK_RC_TOKEN_INCLUDE:
2233 token = g_scanner_get_next_token (scanner);
2234 if (token != GTK_RC_TOKEN_INCLUDE)
2235 return GTK_RC_TOKEN_INCLUDE;
2236 token = g_scanner_get_next_token (scanner);
2237 if (token != G_TOKEN_STRING)
2238 return G_TOKEN_STRING;
2239 parse_include_file (context, scanner, scanner->value.v_string);
2240 return G_TOKEN_NONE;
2242 case GTK_RC_TOKEN_STYLE:
2243 return gtk_rc_parse_style (context, scanner);
2245 case GTK_RC_TOKEN_BINDING:
2246 return gtk_binding_parse_binding (scanner);
2248 case GTK_RC_TOKEN_PIXMAP_PATH:
2249 return gtk_rc_parse_pixmap_path (context, scanner);
2251 case GTK_RC_TOKEN_WIDGET:
2252 return gtk_rc_parse_path_pattern (context, scanner);
2254 case GTK_RC_TOKEN_WIDGET_CLASS:
2255 return gtk_rc_parse_path_pattern (context, scanner);
2257 case GTK_RC_TOKEN_CLASS:
2258 return gtk_rc_parse_path_pattern (context, scanner);
2260 case GTK_RC_TOKEN_MODULE_PATH:
2261 return gtk_rc_parse_module_path (scanner);
2263 case GTK_RC_TOKEN_IM_MODULE_PATH:
2264 return gtk_rc_parse_im_module_path (scanner);
2266 case GTK_RC_TOKEN_IM_MODULE_FILE:
2267 return gtk_rc_parse_im_module_file (scanner);
2269 case G_TOKEN_IDENTIFIER:
2270 if (is_c_identifier (scanner->next_value.v_identifier))
2272 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2275 g_scanner_get_next_token (scanner); /* eat identifier */
2276 name = g_strdup (scanner->value.v_identifier);
2278 token = gtk_rc_parse_assignment (scanner, &prop);
2279 if (token == G_TOKEN_NONE)
2281 GtkSettingsValue svalue;
2283 svalue.origin = prop.origin;
2284 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2285 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2286 gtk_settings_set_property_value (context->settings,
2290 g_free (prop.origin);
2291 if (G_VALUE_TYPE (&prop.value))
2292 g_value_unset (&prop.value);
2299 g_scanner_get_next_token (scanner);
2300 return G_TOKEN_IDENTIFIER;
2303 g_scanner_get_next_token (scanner);
2304 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2309 fixup_rc_set (GSList *list,
2315 GtkRcSet *set = list->data;
2316 if (set->rc_style == orig)
2317 set->rc_style = new;
2323 fixup_rc_sets (GtkRcContext *context,
2327 fixup_rc_set (context->rc_sets_widget, orig, new);
2328 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2329 fixup_rc_set (context->rc_sets_class, orig, new);
2333 gtk_rc_parse_style (GtkRcContext *context,
2336 GtkRcStyle *rc_style;
2337 GtkRcStyle *orig_style;
2338 GtkRcStyle *parent_style;
2341 GtkIconFactory *our_factory = NULL;
2343 token = g_scanner_get_next_token (scanner);
2344 if (token != GTK_RC_TOKEN_STYLE)
2345 return GTK_RC_TOKEN_STYLE;
2347 token = g_scanner_get_next_token (scanner);
2348 if (token != G_TOKEN_STRING)
2349 return G_TOKEN_STRING;
2351 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2353 orig_style = g_object_ref (rc_style);
2357 /* If there's a list, its first member is always the factory belonging
2360 if (rc_style && rc_style->icon_factories)
2361 our_factory = rc_style->icon_factories->data;
2365 rc_style = gtk_rc_style_new ();
2366 rc_style->name = g_strdup (scanner->value.v_string);
2368 for (i = 0; i < 5; i++)
2369 rc_style->bg_pixmap_name[i] = NULL;
2371 for (i = 0; i < 5; i++)
2372 rc_style->color_flags[i] = 0;
2375 token = g_scanner_peek_next_token (scanner);
2376 if (token == G_TOKEN_EQUAL_SIGN)
2378 token = g_scanner_get_next_token (scanner);
2380 token = g_scanner_get_next_token (scanner);
2381 if (token != G_TOKEN_STRING)
2383 token = G_TOKEN_STRING;
2387 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2392 for (i = 0; i < 5; i++)
2394 rc_style->color_flags[i] = parent_style->color_flags[i];
2395 rc_style->fg[i] = parent_style->fg[i];
2396 rc_style->bg[i] = parent_style->bg[i];
2397 rc_style->text[i] = parent_style->text[i];
2398 rc_style->base[i] = parent_style->base[i];
2401 rc_style->xthickness = parent_style->xthickness;
2402 rc_style->ythickness = parent_style->ythickness;
2404 if (parent_style->font_desc)
2406 if (rc_style->font_desc)
2407 pango_font_description_free (rc_style->font_desc);
2408 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2411 if (parent_style->rc_properties)
2415 for (i = 0; i < parent_style->rc_properties->len; i++)
2416 insert_rc_property (rc_style,
2417 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2421 for (i = 0; i < 5; i++)
2423 if (rc_style->bg_pixmap_name[i])
2424 g_free (rc_style->bg_pixmap_name[i]);
2425 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2428 /* Append parent's factories, adding a ref to them */
2429 if (parent_style->icon_factories != NULL)
2431 /* Add a factory for ourselves if we have none,
2432 * in case we end up defining more stock icons.
2433 * I see no real way around this; we need to maintain
2434 * the invariant that the first factory in the list
2435 * is always our_factory, the one belonging to us,
2436 * and if we put parent factories in the list we can't
2437 * do that if the style is reopened.
2439 if (our_factory == NULL)
2441 our_factory = gtk_icon_factory_new ();
2442 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2446 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2447 g_slist_copy (parent_style->icon_factories));
2449 factories = parent_style->icon_factories;
2450 while (factories != NULL)
2452 g_object_ref (G_OBJECT (factories->data));
2453 factories = factories->next;
2459 token = g_scanner_get_next_token (scanner);
2460 if (token != G_TOKEN_LEFT_CURLY)
2462 token = G_TOKEN_LEFT_CURLY;
2466 token = g_scanner_peek_next_token (scanner);
2467 while (token != G_TOKEN_RIGHT_CURLY)
2471 case GTK_RC_TOKEN_BG:
2472 token = gtk_rc_parse_bg (scanner, rc_style);
2474 case GTK_RC_TOKEN_FG:
2475 token = gtk_rc_parse_fg (scanner, rc_style);
2477 case GTK_RC_TOKEN_TEXT:
2478 token = gtk_rc_parse_text (scanner, rc_style);
2480 case GTK_RC_TOKEN_BASE:
2481 token = gtk_rc_parse_base (scanner, rc_style);
2483 case GTK_RC_TOKEN_XTHICKNESS:
2484 token = gtk_rc_parse_xthickness (scanner, rc_style);
2486 case GTK_RC_TOKEN_YTHICKNESS:
2487 token = gtk_rc_parse_ythickness (scanner, rc_style);
2489 case GTK_RC_TOKEN_BG_PIXMAP:
2490 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2492 case GTK_RC_TOKEN_FONT:
2493 token = gtk_rc_parse_font (scanner, rc_style);
2495 case GTK_RC_TOKEN_FONTSET:
2496 token = gtk_rc_parse_fontset (scanner, rc_style);
2498 case GTK_RC_TOKEN_FONT_NAME:
2499 token = gtk_rc_parse_font_name (scanner, rc_style);
2501 case GTK_RC_TOKEN_ENGINE:
2502 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2504 case GTK_RC_TOKEN_STOCK:
2505 if (our_factory == NULL)
2507 our_factory = gtk_icon_factory_new ();
2508 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2511 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2513 case G_TOKEN_IDENTIFIER:
2514 if (is_c_identifier (scanner->next_value.v_identifier) &&
2515 scanner->next_value.v_identifier[0] >= 'A' &&
2516 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2518 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2520 g_scanner_get_next_token (scanner); /* eat type name */
2521 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2522 if (g_scanner_get_next_token (scanner) != ':' ||
2523 g_scanner_get_next_token (scanner) != ':')
2528 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2529 !is_c_identifier (scanner->value.v_identifier))
2531 token = G_TOKEN_IDENTIFIER;
2535 /* it's important that we do the same canonification as GParamSpecPool here */
2536 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2537 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2539 token = gtk_rc_parse_assignment (scanner, &prop);
2540 if (token == G_TOKEN_NONE)
2542 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2543 insert_rc_property (rc_style, &prop, TRUE);
2546 g_free (prop.origin);
2547 if (G_VALUE_TYPE (&prop.value))
2548 g_value_unset (&prop.value);
2552 g_scanner_get_next_token (scanner);
2553 token = G_TOKEN_IDENTIFIER;
2557 g_scanner_get_next_token (scanner);
2558 token = G_TOKEN_RIGHT_CURLY;
2562 if (token != G_TOKEN_NONE)
2565 token = g_scanner_peek_next_token (scanner);
2566 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2568 token = g_scanner_get_next_token (scanner);
2569 if (token != G_TOKEN_RIGHT_CURLY)
2571 token = G_TOKEN_RIGHT_CURLY;
2575 if (rc_style != orig_style)
2577 if (!context->rc_style_ht)
2578 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2579 (GEqualFunc) gtk_rc_style_equal);
2581 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2583 /* If we copied the data into a new rc style, fix up references to the old rc style
2584 * in bindings that we have.
2587 fixup_rc_sets (context, orig_style, rc_style);
2591 g_object_unref (orig_style);
2593 return G_TOKEN_NONE;
2596 if (rc_style != orig_style)
2597 gtk_rc_style_unref (rc_style);
2600 g_object_unref (orig_style);
2605 const GtkRcProperty*
2606 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2608 GQuark property_name)
2610 GtkRcProperty *node = NULL;
2612 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2614 if (rc_style->rc_properties)
2618 key.type_name = type_name;
2619 key.property_name = property_name;
2621 node = bsearch (&key,
2622 rc_style->rc_properties->data, rc_style->rc_properties->len,
2623 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2630 gtk_rc_parse_bg (GScanner *scanner,
2636 token = g_scanner_get_next_token (scanner);
2637 if (token != GTK_RC_TOKEN_BG)
2638 return GTK_RC_TOKEN_BG;
2640 token = gtk_rc_parse_state (scanner, &state);
2641 if (token != G_TOKEN_NONE)
2644 token = g_scanner_get_next_token (scanner);
2645 if (token != G_TOKEN_EQUAL_SIGN)
2646 return G_TOKEN_EQUAL_SIGN;
2648 style->color_flags[state] |= GTK_RC_BG;
2649 return gtk_rc_parse_color (scanner, &style->bg[state]);
2653 gtk_rc_parse_fg (GScanner *scanner,
2659 token = g_scanner_get_next_token (scanner);
2660 if (token != GTK_RC_TOKEN_FG)
2661 return GTK_RC_TOKEN_FG;
2663 token = gtk_rc_parse_state (scanner, &state);
2664 if (token != G_TOKEN_NONE)
2667 token = g_scanner_get_next_token (scanner);
2668 if (token != G_TOKEN_EQUAL_SIGN)
2669 return G_TOKEN_EQUAL_SIGN;
2671 style->color_flags[state] |= GTK_RC_FG;
2672 return gtk_rc_parse_color (scanner, &style->fg[state]);
2676 gtk_rc_parse_text (GScanner *scanner,
2682 token = g_scanner_get_next_token (scanner);
2683 if (token != GTK_RC_TOKEN_TEXT)
2684 return GTK_RC_TOKEN_TEXT;
2686 token = gtk_rc_parse_state (scanner, &state);
2687 if (token != G_TOKEN_NONE)
2690 token = g_scanner_get_next_token (scanner);
2691 if (token != G_TOKEN_EQUAL_SIGN)
2692 return G_TOKEN_EQUAL_SIGN;
2694 style->color_flags[state] |= GTK_RC_TEXT;
2695 return gtk_rc_parse_color (scanner, &style->text[state]);
2699 gtk_rc_parse_base (GScanner *scanner,
2705 token = g_scanner_get_next_token (scanner);
2706 if (token != GTK_RC_TOKEN_BASE)
2707 return GTK_RC_TOKEN_BASE;
2709 token = gtk_rc_parse_state (scanner, &state);
2710 if (token != G_TOKEN_NONE)
2713 token = g_scanner_get_next_token (scanner);
2714 if (token != G_TOKEN_EQUAL_SIGN)
2715 return G_TOKEN_EQUAL_SIGN;
2717 style->color_flags[state] |= GTK_RC_BASE;
2718 return gtk_rc_parse_color (scanner, &style->base[state]);
2722 gtk_rc_parse_xthickness (GScanner *scanner,
2725 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2726 return GTK_RC_TOKEN_XTHICKNESS;
2728 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2729 return G_TOKEN_EQUAL_SIGN;
2731 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2734 style->xthickness = scanner->value.v_int;
2736 return G_TOKEN_NONE;
2740 gtk_rc_parse_ythickness (GScanner *scanner,
2743 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2744 return GTK_RC_TOKEN_YTHICKNESS;
2746 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2747 return G_TOKEN_EQUAL_SIGN;
2749 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2752 style->ythickness = scanner->value.v_int;
2754 return G_TOKEN_NONE;
2758 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2760 GtkRcStyle *rc_style)
2766 token = g_scanner_get_next_token (scanner);
2767 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2768 return GTK_RC_TOKEN_BG_PIXMAP;
2770 token = gtk_rc_parse_state (scanner, &state);
2771 if (token != G_TOKEN_NONE)
2774 token = g_scanner_get_next_token (scanner);
2775 if (token != G_TOKEN_EQUAL_SIGN)
2776 return G_TOKEN_EQUAL_SIGN;
2778 token = g_scanner_get_next_token (scanner);
2779 if (token != G_TOKEN_STRING)
2780 return G_TOKEN_STRING;
2782 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2783 (strcmp (scanner->value.v_string, "<none>") == 0))
2784 pixmap_file = g_strdup (scanner->value.v_string);
2786 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2787 scanner, scanner->value.v_string);
2791 if (rc_style->bg_pixmap_name[state])
2792 g_free (rc_style->bg_pixmap_name[state]);
2793 rc_style->bg_pixmap_name[state] = pixmap_file;
2796 return G_TOKEN_NONE;
2800 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2805 buf = g_build_filename (dir, pixmap_file, NULL);
2807 fd = open (buf, O_RDONLY);
2820 * gtk_rc_find_pixmap_in_path:
2821 * @settings: a #GtkSettings
2822 * @scanner: Scanner used to get line number information for the
2823 * warning message, or %NULL
2824 * @pixmap_file: name of the pixmap file to locate.
2826 * Looks up a file in pixmap path for the specified #GtkSettings.
2827 * If the file is not found, it outputs a warning message using
2828 * g_warning() and returns %NULL.
2830 * Return value: the filename.
2833 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2835 const gchar *pixmap_file)
2841 GtkRcContext *context = gtk_rc_context_get (settings);
2843 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2845 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2850 tmp_list = rc_dir_stack;
2853 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2857 tmp_list = tmp_list->next;
2861 g_scanner_warn (scanner,
2862 _("Unable to locate image file in pixmap_path: \"%s\""),
2865 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2872 gtk_rc_find_module_in_path (const gchar *module_file)
2878 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2880 buf = g_build_filename (module_path[i], module_file, NULL);
2882 fd = open (buf, O_RDONLY);
2896 gtk_rc_parse_font (GScanner *scanner,
2897 GtkRcStyle *rc_style)
2901 token = g_scanner_get_next_token (scanner);
2902 if (token != GTK_RC_TOKEN_FONT)
2903 return GTK_RC_TOKEN_FONT;
2905 token = g_scanner_get_next_token (scanner);
2906 if (token != G_TOKEN_EQUAL_SIGN)
2907 return G_TOKEN_EQUAL_SIGN;
2909 token = g_scanner_get_next_token (scanner);
2910 if (token != G_TOKEN_STRING)
2911 return G_TOKEN_STRING;
2913 /* Ignore, do nothing */
2915 return G_TOKEN_NONE;
2919 gtk_rc_parse_fontset (GScanner *scanner,
2920 GtkRcStyle *rc_style)
2924 token = g_scanner_get_next_token (scanner);
2925 if (token != GTK_RC_TOKEN_FONTSET)
2926 return GTK_RC_TOKEN_FONTSET;
2928 token = g_scanner_get_next_token (scanner);
2929 if (token != G_TOKEN_EQUAL_SIGN)
2930 return G_TOKEN_EQUAL_SIGN;
2932 token = g_scanner_get_next_token (scanner);
2933 if (token != G_TOKEN_STRING)
2934 return G_TOKEN_STRING;
2936 /* Do nothing - silently ignore */
2938 return G_TOKEN_NONE;
2942 gtk_rc_parse_font_name (GScanner *scanner,
2943 GtkRcStyle *rc_style)
2947 token = g_scanner_get_next_token (scanner);
2948 if (token != GTK_RC_TOKEN_FONT_NAME)
2949 return GTK_RC_TOKEN_FONT;
2951 token = g_scanner_get_next_token (scanner);
2952 if (token != G_TOKEN_EQUAL_SIGN)
2953 return G_TOKEN_EQUAL_SIGN;
2955 token = g_scanner_get_next_token (scanner);
2956 if (token != G_TOKEN_STRING)
2957 return G_TOKEN_STRING;
2959 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2961 return G_TOKEN_NONE;
2965 gtk_rc_parse_engine (GtkRcContext *context,
2967 GtkRcStyle **rc_style)
2970 GtkThemeEngine *engine;
2971 guint result = G_TOKEN_NONE;
2972 GtkRcStyle *new_style = NULL;
2973 gboolean parsed_curlies = FALSE;
2975 token = g_scanner_get_next_token (scanner);
2976 if (token != GTK_RC_TOKEN_ENGINE)
2977 return GTK_RC_TOKEN_ENGINE;
2979 token = g_scanner_get_next_token (scanner);
2980 if (token != G_TOKEN_STRING)
2981 return G_TOKEN_STRING;
2983 if (!scanner->value.v_string[0])
2985 /* Support engine "" {} to mean override to the default engine
2987 token = g_scanner_get_next_token (scanner);
2988 if (token != G_TOKEN_LEFT_CURLY)
2989 return G_TOKEN_LEFT_CURLY;
2991 token = g_scanner_get_next_token (scanner);
2992 if (token != G_TOKEN_RIGHT_CURLY)
2993 return G_TOKEN_RIGHT_CURLY;
2995 parsed_curlies = TRUE;
2997 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
2999 new_style = gtk_rc_style_new ();
3000 gtk_rc_style_real_merge (new_style, *rc_style);
3002 if ((*rc_style)->name)
3003 new_style->name = g_strdup ((*rc_style)->name);
3006 (*rc_style)->engine_specified = TRUE;
3010 engine = gtk_theme_engine_get (scanner->value.v_string);
3012 token = g_scanner_get_next_token (scanner);
3013 if (token != G_TOKEN_LEFT_CURLY)
3014 return G_TOKEN_LEFT_CURLY;
3018 GtkRcStyleClass *new_class;
3020 new_style = gtk_theme_engine_create_rc_style (engine);
3021 g_type_module_unuse (G_TYPE_MODULE (engine));
3023 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3025 new_class->merge (new_style, *rc_style);
3026 if ((*rc_style)->name)
3027 new_style->name = g_strdup ((*rc_style)->name);
3029 if (new_class->parse)
3031 parsed_curlies = TRUE;
3032 result = new_class->parse (new_style, context->settings, scanner);
3034 if (result != G_TOKEN_NONE)
3036 g_object_unref (G_OBJECT (new_style));
3043 if (!parsed_curlies)
3045 /* Skip over remainder, looking for nested {}'s
3049 result = G_TOKEN_RIGHT_CURLY;
3050 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3052 if (token == G_TOKEN_LEFT_CURLY)
3054 else if (token == G_TOKEN_RIGHT_CURLY)
3059 result = G_TOKEN_NONE;
3067 new_style->engine_specified = TRUE;
3069 g_object_unref (G_OBJECT (*rc_style));
3070 *rc_style = new_style;
3077 gtk_rc_parse_state (GScanner *scanner,
3078 GtkStateType *state)
3083 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3084 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3086 /* we don't know where we got called from, so we reset the scope here.
3087 * if we bail out due to errors, we *don't* reset the scope, so the
3088 * error messaging code can make sense of our tokens.
3090 old_scope = g_scanner_set_scope (scanner, 0);
3092 token = g_scanner_get_next_token (scanner);
3093 if (token != G_TOKEN_LEFT_BRACE)
3094 return G_TOKEN_LEFT_BRACE;
3096 token = g_scanner_get_next_token (scanner);
3099 case GTK_RC_TOKEN_ACTIVE:
3100 *state = GTK_STATE_ACTIVE;
3102 case GTK_RC_TOKEN_INSENSITIVE:
3103 *state = GTK_STATE_INSENSITIVE;
3105 case GTK_RC_TOKEN_NORMAL:
3106 *state = GTK_STATE_NORMAL;
3108 case GTK_RC_TOKEN_PRELIGHT:
3109 *state = GTK_STATE_PRELIGHT;
3111 case GTK_RC_TOKEN_SELECTED:
3112 *state = GTK_STATE_SELECTED;
3115 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3118 token = g_scanner_get_next_token (scanner);
3119 if (token != G_TOKEN_RIGHT_BRACE)
3120 return G_TOKEN_RIGHT_BRACE;
3122 g_scanner_set_scope (scanner, old_scope);
3124 return G_TOKEN_NONE;
3128 gtk_rc_parse_priority (GScanner *scanner,
3129 GtkPathPriorityType *priority)
3134 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3135 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3137 /* we don't know where we got called from, so we reset the scope here.
3138 * if we bail out due to errors, we *don't* reset the scope, so the
3139 * error messaging code can make sense of our tokens.
3141 old_scope = g_scanner_set_scope (scanner, 0);
3143 token = g_scanner_get_next_token (scanner);
3147 token = g_scanner_get_next_token (scanner);
3150 case GTK_RC_TOKEN_LOWEST:
3151 *priority = GTK_PATH_PRIO_LOWEST;
3153 case GTK_RC_TOKEN_GTK:
3154 *priority = GTK_PATH_PRIO_GTK;
3156 case GTK_RC_TOKEN_APPLICATION:
3157 *priority = GTK_PATH_PRIO_APPLICATION;
3159 case GTK_RC_TOKEN_THEME:
3160 *priority = GTK_PATH_PRIO_THEME;
3162 case GTK_RC_TOKEN_RC:
3163 *priority = GTK_PATH_PRIO_RC;
3165 case GTK_RC_TOKEN_HIGHEST:
3166 *priority = GTK_PATH_PRIO_HIGHEST;
3169 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3172 g_scanner_set_scope (scanner, old_scope);
3174 return G_TOKEN_NONE;
3178 gtk_rc_parse_color (GScanner *scanner,
3183 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3185 /* we don't need to set our own scope here, because
3186 * we don't need own symbols
3189 token = g_scanner_get_next_token (scanner);
3194 case G_TOKEN_LEFT_CURLY:
3195 token = g_scanner_get_next_token (scanner);
3196 if (token == G_TOKEN_INT)
3197 token_int = scanner->value.v_int;
3198 else if (token == G_TOKEN_FLOAT)
3199 token_int = scanner->value.v_float * 65535.0;
3201 return G_TOKEN_FLOAT;
3202 color->red = CLAMP (token_int, 0, 65535);
3204 token = g_scanner_get_next_token (scanner);
3205 if (token != G_TOKEN_COMMA)
3206 return G_TOKEN_COMMA;
3208 token = g_scanner_get_next_token (scanner);
3209 if (token == G_TOKEN_INT)
3210 token_int = scanner->value.v_int;
3211 else if (token == G_TOKEN_FLOAT)
3212 token_int = scanner->value.v_float * 65535.0;
3214 return G_TOKEN_FLOAT;
3215 color->green = CLAMP (token_int, 0, 65535);
3217 token = g_scanner_get_next_token (scanner);
3218 if (token != G_TOKEN_COMMA)
3219 return G_TOKEN_COMMA;
3221 token = g_scanner_get_next_token (scanner);
3222 if (token == G_TOKEN_INT)
3223 token_int = scanner->value.v_int;
3224 else if (token == G_TOKEN_FLOAT)
3225 token_int = scanner->value.v_float * 65535.0;
3227 return G_TOKEN_FLOAT;
3228 color->blue = CLAMP (token_int, 0, 65535);
3230 token = g_scanner_get_next_token (scanner);
3231 if (token != G_TOKEN_RIGHT_CURLY)
3232 return G_TOKEN_RIGHT_CURLY;
3233 return G_TOKEN_NONE;
3235 case G_TOKEN_STRING:
3236 if (!gdk_color_parse (scanner->value.v_string, color))
3238 g_scanner_warn (scanner, "Invalid color constant '%s'",
3239 scanner->value.v_string);
3240 return G_TOKEN_STRING;
3243 return G_TOKEN_NONE;
3246 return G_TOKEN_STRING;
3251 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3256 token = g_scanner_get_next_token (scanner);
3257 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3258 return GTK_RC_TOKEN_PIXMAP_PATH;
3260 token = g_scanner_get_next_token (scanner);
3261 if (token != G_TOKEN_STRING)
3262 return G_TOKEN_STRING;
3264 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3266 return G_TOKEN_NONE;
3270 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3272 const gchar *pix_path)
3275 gint start_offset = 0;
3279 /* free the old one, or just add to the old one ? */
3280 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3282 g_free (context->pixmap_path[path_num]);
3283 context->pixmap_path[path_num] = NULL;
3288 path_len = strlen (pix_path);
3290 for (end_offset = 0; end_offset <= path_len; end_offset++)
3292 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3293 (end_offset == path_len))
3295 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3296 if (g_path_is_absolute (path_element))
3298 context->pixmap_path[path_num] = path_element;
3300 context->pixmap_path[path_num] = NULL;
3304 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3305 path_element, scanner->input_name, scanner->line);
3306 g_free (path_element);
3309 start_offset = end_offset + 1;
3315 gtk_rc_parse_module_path (GScanner *scanner)
3319 token = g_scanner_get_next_token (scanner);
3320 if (token != GTK_RC_TOKEN_MODULE_PATH)
3321 return GTK_RC_TOKEN_MODULE_PATH;
3323 token = g_scanner_get_next_token (scanner);
3324 if (token != G_TOKEN_STRING)
3325 return G_TOKEN_STRING;
3327 gtk_rc_parse_module_path_string (scanner->value.v_string);
3329 return G_TOKEN_NONE;
3333 gtk_rc_parse_im_module_path (GScanner *scanner)
3337 token = g_scanner_get_next_token (scanner);
3338 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3339 return GTK_RC_TOKEN_IM_MODULE_FILE;
3341 token = g_scanner_get_next_token (scanner);
3342 if (token != G_TOKEN_STRING)
3343 return G_TOKEN_STRING;
3346 g_free (im_module_path);
3348 im_module_path = g_strdup (scanner->value.v_string);
3350 return G_TOKEN_NONE;
3354 gtk_rc_parse_im_module_file (GScanner *scanner)
3358 token = g_scanner_get_next_token (scanner);
3359 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3360 return GTK_RC_TOKEN_IM_MODULE_FILE;
3362 token = g_scanner_get_next_token (scanner);
3363 if (token != G_TOKEN_STRING)
3364 return G_TOKEN_STRING;
3367 g_free (im_module_file);
3369 im_module_file = g_strdup (scanner->value.v_string);
3371 return G_TOKEN_NONE;
3375 gtk_rc_parse_module_path_string (const gchar *mod_path)
3378 gint start_offset = 0;
3382 /* free the old one, or just add to the old one ? */
3383 for (path_num=0; module_path[path_num]; path_num++)
3385 g_free (module_path[path_num]);
3386 module_path[path_num] = NULL;
3391 path_len = strlen (mod_path);
3393 for (end_offset = 0; end_offset <= path_len; end_offset++)
3395 if ((mod_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3396 (end_offset == path_len))
3398 module_path[path_num] = g_strndup (mod_path + start_offset, end_offset - start_offset);
3400 module_path[path_num] = NULL;
3401 start_offset = end_offset + 1;
3404 gtk_rc_append_default_module_path();
3408 gtk_rc_parse_path_pattern (GtkRcContext *context,
3412 GtkPathType path_type;
3414 gboolean is_binding;
3415 GtkPathPriorityType priority = context->default_priority;
3417 token = g_scanner_get_next_token (scanner);
3420 case GTK_RC_TOKEN_WIDGET:
3421 path_type = GTK_PATH_WIDGET;
3423 case GTK_RC_TOKEN_WIDGET_CLASS:
3424 path_type = GTK_PATH_WIDGET_CLASS;
3426 case GTK_RC_TOKEN_CLASS:
3427 path_type = GTK_PATH_CLASS;
3430 return GTK_RC_TOKEN_WIDGET_CLASS;
3433 token = g_scanner_get_next_token (scanner);
3434 if (token != G_TOKEN_STRING)
3435 return G_TOKEN_STRING;
3437 pattern = g_strdup (scanner->value.v_string);
3439 token = g_scanner_get_next_token (scanner);
3440 if (token == GTK_RC_TOKEN_STYLE)
3442 else if (token == GTK_RC_TOKEN_BINDING)
3447 return GTK_RC_TOKEN_STYLE;
3450 if (g_scanner_peek_next_token (scanner) == ':')
3452 token = gtk_rc_parse_priority (scanner, &priority);
3453 if (token != G_TOKEN_NONE)
3460 token = g_scanner_get_next_token (scanner);
3461 if (token != G_TOKEN_STRING)
3464 return G_TOKEN_STRING;
3469 GtkBindingSet *binding;
3471 binding = gtk_binding_set_find (scanner->value.v_string);
3475 return G_TOKEN_STRING;
3477 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3481 GtkRcStyle *rc_style;
3484 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3489 return G_TOKEN_STRING;
3492 rc_set = g_new (GtkRcSet, 1);
3493 rc_set->pspec = g_pattern_spec_new (pattern);
3494 rc_set->rc_style = rc_style;
3495 rc_set->priority = priority;
3497 if (path_type == GTK_PATH_WIDGET)
3498 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3499 else if (path_type == GTK_PATH_WIDGET_CLASS)
3500 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3502 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3506 return G_TOKEN_NONE;
3510 gtk_rc_parse_stock_id (GScanner *scanner,
3515 token = g_scanner_get_next_token (scanner);
3516 if (token != G_TOKEN_LEFT_BRACE)
3517 return G_TOKEN_LEFT_BRACE;
3519 token = g_scanner_get_next_token (scanner);
3521 if (token != G_TOKEN_STRING)
3522 return G_TOKEN_STRING;
3524 *stock_id = g_strdup (scanner->value.v_string);
3526 token = g_scanner_get_next_token (scanner);
3527 if (token != G_TOKEN_RIGHT_BRACE)
3530 return G_TOKEN_RIGHT_BRACE;
3533 return G_TOKEN_NONE;
3537 gtk_rc_parse_icon_source (GtkRcContext *context,
3539 GtkIconSet *icon_set,
3540 gboolean *icon_set_valid)
3543 GtkIconSource *source;
3544 gchar *full_filename;
3546 token = g_scanner_get_next_token (scanner);
3547 if (token != G_TOKEN_LEFT_CURLY)
3548 return G_TOKEN_LEFT_CURLY;
3550 token = g_scanner_get_next_token (scanner);
3552 if (token != G_TOKEN_STRING)
3553 return G_TOKEN_STRING;
3556 source = gtk_icon_source_new ();
3558 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3561 gtk_icon_source_set_filename (source, full_filename);
3562 g_free (full_filename);
3565 /* We continue parsing even if we didn't find the pixmap so that rest of the
3566 * file is read, even if the syntax is bad. However we don't validate the
3567 * icon_set so the caller can choose not to install it.
3569 token = g_scanner_get_next_token (scanner);
3571 if (token == G_TOKEN_RIGHT_CURLY)
3573 else if (token != G_TOKEN_COMMA)
3575 gtk_icon_source_free (source);
3576 return G_TOKEN_COMMA;
3579 /* Get the direction */
3581 token = g_scanner_get_next_token (scanner);
3585 case GTK_RC_TOKEN_RTL:
3586 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3587 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3590 case GTK_RC_TOKEN_LTR:
3591 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3592 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3599 gtk_icon_source_free (source);
3600 return GTK_RC_TOKEN_RTL;
3604 token = g_scanner_get_next_token (scanner);
3606 if (token == G_TOKEN_RIGHT_CURLY)
3608 else if (token != G_TOKEN_COMMA)
3610 gtk_icon_source_free (source);
3611 return G_TOKEN_COMMA;
3616 token = g_scanner_get_next_token (scanner);
3620 case GTK_RC_TOKEN_NORMAL:
3621 gtk_icon_source_set_state_wildcarded (source, FALSE);
3622 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3625 case GTK_RC_TOKEN_PRELIGHT:
3626 gtk_icon_source_set_state_wildcarded (source, FALSE);
3627 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3631 case GTK_RC_TOKEN_INSENSITIVE:
3632 gtk_icon_source_set_state_wildcarded (source, FALSE);
3633 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3636 case GTK_RC_TOKEN_ACTIVE:
3637 gtk_icon_source_set_state_wildcarded (source, FALSE);
3638 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3641 case GTK_RC_TOKEN_SELECTED:
3642 gtk_icon_source_set_state_wildcarded (source, FALSE);
3643 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3650 gtk_icon_source_free (source);
3651 return GTK_RC_TOKEN_PRELIGHT;
3655 token = g_scanner_get_next_token (scanner);
3657 if (token == G_TOKEN_RIGHT_CURLY)
3659 else if (token != G_TOKEN_COMMA)
3661 gtk_icon_source_free (source);
3662 return G_TOKEN_COMMA;
3667 token = g_scanner_get_next_token (scanner);
3673 if (token != G_TOKEN_STRING)
3675 gtk_icon_source_free (source);
3676 return G_TOKEN_STRING;
3679 size = gtk_icon_size_from_name (scanner->value.v_string);
3681 if (size != GTK_ICON_SIZE_INVALID)
3683 gtk_icon_source_set_size_wildcarded (source, FALSE);
3684 gtk_icon_source_set_size (source, size);
3688 /* Check the close brace */
3690 token = g_scanner_get_next_token (scanner);
3691 if (token != G_TOKEN_RIGHT_CURLY)
3693 gtk_icon_source_free (source);
3694 return G_TOKEN_RIGHT_CURLY;
3698 if (gtk_icon_source_get_filename (source))
3700 gtk_icon_set_add_source (icon_set, source);
3701 *icon_set_valid = TRUE;
3703 gtk_icon_source_free (source);
3705 return G_TOKEN_NONE;
3709 gtk_rc_parse_stock (GtkRcContext *context,
3711 GtkRcStyle *rc_style,
3712 GtkIconFactory *factory)
3714 GtkIconSet *icon_set = NULL;
3715 gboolean icon_set_valid = FALSE;
3716 gchar *stock_id = NULL;
3719 token = g_scanner_get_next_token (scanner);
3720 if (token != GTK_RC_TOKEN_STOCK)
3721 return GTK_RC_TOKEN_STOCK;
3723 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3724 if (token != G_TOKEN_NONE)
3727 token = g_scanner_get_next_token (scanner);
3728 if (token != G_TOKEN_EQUAL_SIGN)
3731 return G_TOKEN_EQUAL_SIGN;
3734 token = g_scanner_get_next_token (scanner);
3735 if (token != G_TOKEN_LEFT_CURLY)
3738 return G_TOKEN_LEFT_CURLY;
3741 token = g_scanner_peek_next_token (scanner);
3742 while (token != G_TOKEN_RIGHT_CURLY)
3744 if (icon_set == NULL)
3745 icon_set = gtk_icon_set_new ();
3747 token = gtk_rc_parse_icon_source (context,
3748 scanner, icon_set, &icon_set_valid);
3749 if (token != G_TOKEN_NONE)
3752 gtk_icon_set_unref (icon_set);
3756 token = g_scanner_get_next_token (scanner);
3758 if (token != G_TOKEN_COMMA &&
3759 token != G_TOKEN_RIGHT_CURLY)
3762 gtk_icon_set_unref (icon_set);
3763 return G_TOKEN_RIGHT_CURLY;
3767 if (icon_set && icon_set_valid)
3769 gtk_icon_factory_add (factory,
3773 gtk_icon_set_unref (icon_set);
3778 return G_TOKEN_NONE;