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. If @filename is not absolute, it
460 * is searched in the current directory.
462 * Adds a file to the list of files to be parsed at the
466 gtk_rc_add_default_file (const gchar *filename)
470 gtk_rc_add_initial_default_files ();
472 for (n = 0; gtk_rc_default_files[n]; n++) ;
473 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
476 gtk_rc_default_files[n++] = g_strdup (filename);
477 gtk_rc_default_files[n] = NULL;
481 * gtk_rc_set_default_files:
482 * @filenames: A %NULL-terminated list of filenames.
484 * Sets the list of files that GTK+ will read at the
488 gtk_rc_set_default_files (gchar **filenames)
492 gtk_rc_add_initial_default_files ();
495 while (gtk_rc_default_files[i])
497 g_free (gtk_rc_default_files[i]);
501 gtk_rc_default_files[0] = NULL;
504 while (filenames[i] != NULL)
506 gtk_rc_add_default_file (filenames[i]);
512 * gtk_rc_get_default_files:
514 * Retrieves the current list of RC files that will be parsed
515 * at the end of gtk_init().
517 * Return value: A %NULL-terminated array of filenames. This memory
518 * is owned by GTK+ and must not be freed by the application.
519 * If you want to store this information, you should make a copy.
522 gtk_rc_get_default_files (void)
524 gtk_rc_add_initial_default_files ();
526 return gtk_rc_default_files;
530 gtk_rc_settings_changed (GtkSettings *settings,
532 GtkRcContext *context)
534 gchar *new_theme_name;
535 gchar *new_key_theme_name;
537 g_object_get (settings,
538 "gtk-theme-name", &new_theme_name,
539 "gtk-key-theme-name", &new_key_theme_name,
542 if ((new_theme_name != context->theme_name &&
543 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
544 (new_key_theme_name != context->key_theme_name &&
545 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
547 gtk_rc_reparse_all_for_settings (settings, TRUE);
550 g_free (new_theme_name);
551 g_free (new_key_theme_name);
554 static GtkRcContext *
555 gtk_rc_context_get (GtkSettings *settings)
557 if (!settings->rc_context)
559 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
561 context->settings = settings;
562 context->rc_style_ht = NULL;
563 context->rc_sets_widget = NULL;
564 context->rc_sets_widget_class = NULL;
565 context->rc_sets_class = NULL;
566 context->rc_files = NULL;
568 g_object_get (settings,
569 "gtk-theme-name", &context->theme_name,
570 "gtk-key-theme-name", &context->key_theme_name,
573 g_signal_connect (settings,
574 "notify::gtk-theme-name",
575 G_CALLBACK (gtk_rc_settings_changed),
577 g_signal_connect (settings,
578 "notify::gtk-key-theme-name",
579 G_CALLBACK (gtk_rc_settings_changed),
582 context->pixmap_path[0] = NULL;
584 context->default_priority = GTK_PATH_PRIO_RC;
587 return settings->rc_context;
591 gtk_rc_parse_named (GtkRcContext *context,
596 const gchar *home_dir;
600 subpath = g_strconcat ("gtk-2.0-", type,
601 G_DIR_SEPARATOR_S "gtkrc",
604 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
606 /* First look in the users home directory
608 home_dir = g_get_home_dir ();
611 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
612 if (!g_file_test (path, G_FILE_TEST_EXISTS))
621 gchar *theme_dir = gtk_rc_get_theme_dir ();
622 path = g_build_filename (theme_dir, name, subpath, NULL);
625 if (!g_file_test (path, G_FILE_TEST_EXISTS))
634 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
642 gtk_rc_parse_default_files (GtkRcContext *context)
646 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
647 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
653 static gboolean initialized = FALSE;
659 module_path[0] = NULL;
660 gtk_rc_append_default_module_path();
662 gtk_rc_add_initial_default_files ();
665 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
669 gtk_rc_parse_string (const gchar *rc_string)
672 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
673 * string in all contexts, and in fact, in future contexts as well.
675 GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
677 g_return_if_fail (rc_string != NULL);
679 rc_file = g_new (GtkRcFile, 1);
680 rc_file->is_string = TRUE;
681 rc_file->name = g_strdup (rc_string);
682 rc_file->canonical_name = NULL;
684 rc_file->reload = TRUE;
686 context->rc_files = g_slist_append (context->rc_files, rc_file);
688 gtk_rc_parse_any (context, "-", -1, rc_string);
692 gtk_rc_parse_one_file (GtkRcContext *context,
693 const gchar *filename,
697 GtkRcFile *rc_file = NULL;
702 g_return_if_fail (filename != NULL);
704 saved_priority = context->default_priority;
705 context->default_priority = priority;
707 tmp_list = context->rc_files;
710 rc_file = tmp_list->data;
711 if (!strcmp (rc_file->name, filename))
714 tmp_list = tmp_list->next;
719 rc_file = g_new (GtkRcFile, 1);
720 rc_file->is_string = FALSE;
721 rc_file->name = g_strdup (filename);
722 rc_file->canonical_name = NULL;
724 rc_file->reload = reload;
726 context->rc_files = g_slist_append (context->rc_files, rc_file);
729 if (!rc_file->canonical_name)
731 /* Get the absolute pathname */
733 if (g_path_is_absolute (rc_file->name))
734 rc_file->canonical_name = rc_file->name;
739 cwd = g_get_current_dir ();
740 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
745 if (!lstat (rc_file->canonical_name, &statbuf))
750 rc_file->mtime = statbuf.st_mtime;
752 fd = open (rc_file->canonical_name, O_RDONLY);
756 /* Temporarily push directory name for this file on
757 * a stack of directory names while parsing it
760 g_slist_prepend (rc_dir_stack,
761 g_path_get_dirname (rc_file->canonical_name));
762 gtk_rc_parse_any (context, filename, fd, NULL);
764 tmp_list = rc_dir_stack;
765 rc_dir_stack = rc_dir_stack->next;
767 g_free (tmp_list->data);
768 g_slist_free_1 (tmp_list);
774 context->default_priority = saved_priority;
778 strchr_len (const gchar *str, gint len, char c)
792 gtk_rc_parse_file (GtkRcContext *context,
793 const gchar *filename,
797 gchar *locale_suffixes[2];
798 gint n_locale_suffixes = 0;
802 gboolean found = FALSE;
805 locale = g_win32_getlocale ();
807 locale = setlocale (LC_CTYPE, NULL);
810 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
812 /* Determine locale-specific suffixes for RC files.
814 length = strlen (locale);
816 p = strchr (locale, '@');
820 p = strchr_len (locale, length, '.');
824 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
826 p = strchr_len (locale, length, '_');
830 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
834 gtk_rc_parse_one_file (context, filename, priority, reload);
835 for (j = 0; j < n_locale_suffixes; j++)
839 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
840 if (g_file_test (name, G_FILE_TEST_EXISTS))
842 gtk_rc_parse_one_file (context, name, priority, FALSE);
849 g_free (locale_suffixes[j]);
854 gtk_rc_parse (const gchar *filename)
856 g_return_if_fail (filename != NULL);
858 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
859 * file in all contexts, and in fact, in future contexts as well.
861 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
862 filename, GTK_PATH_PRIO_RC, TRUE);
865 /* Handling of RC styles */
868 gtk_rc_style_get_type (void)
870 static GType object_type = 0;
874 static const GTypeInfo object_info =
876 sizeof (GtkRcStyleClass),
877 (GBaseInitFunc) NULL,
878 (GBaseFinalizeFunc) NULL,
879 (GClassInitFunc) gtk_rc_style_class_init,
880 NULL, /* class_finalize */
881 NULL, /* class_data */
884 (GInstanceInitFunc) gtk_rc_style_init,
887 object_type = g_type_register_static (G_TYPE_OBJECT,
896 gtk_rc_style_init (GtkRcStyle *style)
901 style->font_desc = NULL;
903 for (i = 0; i < 5; i++)
905 static const GdkColor init_color = { 0, 0, 0, 0, };
907 style->bg_pixmap_name[i] = NULL;
908 style->color_flags[i] = 0;
909 style->fg[i] = init_color;
910 style->bg[i] = init_color;
911 style->text[i] = init_color;
912 style->base[i] = init_color;
914 style->xthickness = -1;
915 style->ythickness = -1;
916 style->rc_properties = NULL;
918 style->rc_style_lists = NULL;
919 style->icon_factories = NULL;
923 gtk_rc_style_class_init (GtkRcStyleClass *klass)
925 GObjectClass *object_class = G_OBJECT_CLASS (klass);
927 parent_class = g_type_class_peek_parent (klass);
929 object_class->finalize = gtk_rc_style_finalize;
932 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
933 klass->merge = gtk_rc_style_real_merge;
934 klass->create_style = gtk_rc_style_real_create_style;
938 gtk_rc_style_finalize (GObject *object)
940 GSList *tmp_list1, *tmp_list2;
941 GtkRcStyle *rc_style;
944 rc_style = GTK_RC_STYLE (object);
947 g_free (rc_style->name);
948 if (rc_style->font_desc)
949 pango_font_description_free (rc_style->font_desc);
951 for (i = 0; i < 5; i++)
952 if (rc_style->bg_pixmap_name[i])
953 g_free (rc_style->bg_pixmap_name[i]);
955 /* Now remove all references to this rc_style from
958 tmp_list1 = rc_style->rc_style_lists;
961 GSList *rc_styles = tmp_list1->data;
962 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
963 gtk_style_unref (style);
965 /* Remove the list of styles from the other rc_styles
968 tmp_list2 = rc_styles;
971 GtkRcStyle *other_style = tmp_list2->data;
973 if (other_style != rc_style)
974 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
976 tmp_list2 = tmp_list2->next;
979 /* And from the hash table itself
981 g_hash_table_remove (realized_style_ht, rc_styles);
982 g_slist_free (rc_styles);
984 tmp_list1 = tmp_list1->next;
986 g_slist_free (rc_style->rc_style_lists);
988 if (rc_style->rc_properties)
992 for (i = 0; i < rc_style->rc_properties->len; i++)
994 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
996 g_free (node->origin);
997 g_value_unset (&node->value);
999 g_array_free (rc_style->rc_properties, TRUE);
1000 rc_style->rc_properties = NULL;
1003 tmp_list1 = rc_style->icon_factories;
1006 g_object_unref (G_OBJECT (tmp_list1->data));
1008 tmp_list1 = tmp_list1->next;
1010 g_slist_free (rc_style->icon_factories);
1012 G_OBJECT_CLASS (parent_class)->finalize (object);
1016 gtk_rc_style_new (void)
1020 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1026 * gtk_rc_style_copy:
1027 * @orig: the style to copy
1029 * Makes a copy of the specified #GtkRcStyle. This function
1030 * will correctly copy an RC style that is a member of a class
1031 * derived from #GtkRcStyle.
1033 * Return value: the resulting #GtkRcStyle
1036 gtk_rc_style_copy (GtkRcStyle *orig)
1040 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1042 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1043 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1049 gtk_rc_style_ref (GtkRcStyle *rc_style)
1051 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1053 g_object_ref (G_OBJECT (rc_style));
1057 gtk_rc_style_unref (GtkRcStyle *rc_style)
1059 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1061 g_object_unref (G_OBJECT (rc_style));
1065 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1067 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1071 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1072 gconstpointer bsearch_node2)
1074 const GtkRcProperty *prop1 = bsearch_node1;
1075 const GtkRcProperty *prop2 = bsearch_node2;
1077 if (prop1->type_name == prop2->type_name)
1078 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1080 return prop1->type_name < prop2->type_name ? -1 : 1;
1084 insert_rc_property (GtkRcStyle *style,
1085 GtkRcProperty *property,
1089 GtkRcProperty *new_property = NULL;
1090 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1092 key.type_name = property->type_name;
1093 key.property_name = property->property_name;
1095 if (!style->rc_properties)
1096 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1099 while (i < style->rc_properties->len)
1101 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1107 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1109 g_free (new_property->origin);
1110 g_value_unset (&new_property->value);
1112 *new_property = key;
1126 g_array_insert_val (style->rc_properties, i, key);
1127 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1130 new_property->origin = g_strdup (property->origin);
1131 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1132 g_value_copy (&property->value, &new_property->value);
1136 gtk_rc_style_real_merge (GtkRcStyle *dest,
1141 for (i = 0; i < 5; i++)
1143 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1144 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1146 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1147 src->color_flags[i] & GTK_RC_FG)
1149 dest->fg[i] = src->fg[i];
1150 dest->color_flags[i] |= GTK_RC_FG;
1152 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1153 src->color_flags[i] & GTK_RC_BG)
1155 dest->bg[i] = src->bg[i];
1156 dest->color_flags[i] |= GTK_RC_BG;
1158 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1159 src->color_flags[i] & GTK_RC_TEXT)
1161 dest->text[i] = src->text[i];
1162 dest->color_flags[i] |= GTK_RC_TEXT;
1164 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1165 src->color_flags[i] & GTK_RC_BASE)
1167 dest->base[i] = src->base[i];
1168 dest->color_flags[i] |= GTK_RC_BASE;
1172 if (dest->xthickness < 0 && src->xthickness >= 0)
1173 dest->xthickness = src->xthickness;
1174 if (dest->ythickness < 0 && src->ythickness >= 0)
1175 dest->ythickness = src->ythickness;
1179 if (!dest->font_desc)
1180 dest->font_desc = pango_font_description_copy (src->font_desc);
1182 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1185 if (src->rc_properties)
1189 for (i = 0; i < src->rc_properties->len; i++)
1190 insert_rc_property (dest,
1191 &g_array_index (src->rc_properties, GtkRcProperty, i),
1197 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1199 return gtk_style_new ();
1203 gtk_rc_clear_hash_node (gpointer key,
1207 gtk_rc_style_unref (data);
1211 gtk_rc_free_rc_sets (GSList *slist)
1217 rc_set = slist->data;
1218 g_pattern_spec_free (rc_set->pspec);
1221 slist = slist->next;
1226 gtk_rc_clear_styles (GtkRcContext *context)
1228 /* Clear out all old rc_styles */
1230 if (context->rc_style_ht)
1232 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1233 g_hash_table_destroy (context->rc_style_ht);
1234 context->rc_style_ht = NULL;
1237 gtk_rc_free_rc_sets (context->rc_sets_widget);
1238 g_slist_free (context->rc_sets_widget);
1239 context->rc_sets_widget = NULL;
1241 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1242 g_slist_free (context->rc_sets_widget_class);
1243 context->rc_sets_widget_class = NULL;
1245 gtk_rc_free_rc_sets (context->rc_sets_class);
1246 g_slist_free (context->rc_sets_class);
1247 context->rc_sets_class = NULL;
1250 /* Reset all our widgets. Also, we have to invalidate cached icons in
1251 * icon sets so they get re-rendered.
1254 gtk_rc_reset_widgets (GtkRcContext *context)
1256 GList *list, *toplevels;
1258 _gtk_icon_set_invalidate_caches ();
1260 toplevels = gtk_window_list_toplevels ();
1261 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1263 for (list = toplevels; list; list = list->next)
1265 gtk_widget_reset_rc_styles (list->data);
1266 gtk_widget_unref (list->data);
1268 g_list_free (toplevels);
1272 * gtk_rc_reparse_all_for_settings:
1273 * @settings: a #GtkSettings
1274 * @force_load: load whether or not anything changed
1276 * If the modification time on any previously read file
1277 * for the given #GtkSettings has changed, discard all style information
1278 * and then reread all previously read RC files.
1280 * Return value: %TRUE if the files were reread.
1283 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1284 gboolean force_load)
1286 gboolean mtime_modified = FALSE;
1289 GtkRcContext *context;
1291 struct stat statbuf;
1293 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1295 context = gtk_rc_context_get (settings);
1299 /* Check through and see if any of the RC's have had their
1300 * mtime modified. If so, reparse everything.
1302 tmp_list = context->rc_files;
1305 rc_file = tmp_list->data;
1307 if (!rc_file->is_string)
1309 if (!lstat (rc_file->name, &statbuf) &&
1310 (statbuf.st_mtime > rc_file->mtime))
1312 mtime_modified = TRUE;
1317 tmp_list = tmp_list->next;
1321 if (force_load || mtime_modified)
1325 gtk_rc_clear_styles (context);
1326 g_object_freeze_notify (G_OBJECT (context->settings));
1328 old_files = context->rc_files;
1329 context->rc_files = NULL;
1331 gtk_rc_parse_default_files (context);
1333 tmp_list = old_files;
1336 rc_file = tmp_list->data;
1337 if (rc_file->reload)
1339 if (rc_file->is_string)
1340 gtk_rc_parse_string (rc_file->name);
1342 gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
1345 if (rc_file->canonical_name != rc_file->name)
1346 g_free (rc_file->canonical_name);
1347 g_free (rc_file->name);
1350 tmp_list = tmp_list->next;
1353 g_slist_free (old_files);;
1355 g_free (context->theme_name);
1356 g_free (context->key_theme_name);
1357 g_object_get (context->settings,
1358 "gtk-theme-name", &context->theme_name,
1359 "gtk-key-theme-name", &context->key_theme_name,
1362 if (context->theme_name && context->theme_name[0])
1363 gtk_rc_parse_named (context, context->theme_name, NULL);
1364 if (context->key_theme_name && context->key_theme_name[0])
1365 gtk_rc_parse_named (context, context->key_theme_name, "key");
1367 g_object_thaw_notify (G_OBJECT (context->settings));
1369 gtk_rc_reset_widgets (context);
1372 return mtime_modified;
1376 * gtk_rc_reparse_all:
1378 * If the modification time on any previously read file for the
1379 * default #GtkSettings has changed, discard all style information
1380 * and then reread all previously read RC files.
1382 * Return value: %TRUE if the files were reread.
1385 gtk_rc_reparse_all (void)
1387 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1391 gtk_rc_styles_match (GSList *rc_styles,
1395 const gchar *path_reversed)
1402 rc_set = sets->data;
1405 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1406 rc_styles = g_slist_append (rc_styles, rc_set);
1413 rc_set_compare (gconstpointer a, gconstpointer b)
1415 const GtkRcSet *set_a = a;
1416 const GtkRcSet *set_b = b;
1418 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1422 sort_and_dereference_sets (GSList *styles)
1426 /* At this point, the list of sets is ordered by:
1428 * a) 'widget' patterns are earlier than 'widget_class' patterns
1429 * which are ealier than 'class' patterns.
1430 * a) For two matches for class patterns, a match to a child type
1431 * is before a match to a parent type
1432 * c) a match later in the RC file (or in a later RC file) is before a
1433 * match earlier in the RC file.
1435 * With a) taking precedence over b) which takes precendence over c).
1437 * Now sort by priority, which has the highest precendence for sort order
1439 styles = g_slist_sort (styles, rc_set_compare);
1441 /* Make styles->data = styles->data->rc_style
1446 GtkRcSet *set = tmp_list->data;
1447 tmp_list->data = set->rc_style;
1448 tmp_list = tmp_list->next;
1456 * @widget: a #GtkWidget
1458 * Finds all matching RC styles for a given widget,
1459 * composites them together, and then creates a
1460 * #GtkStyle representing the composite appearance.
1461 * (GTK+ actually keeps a cache of previously
1462 * created styles, so a new style may not be
1465 * Returns: the resulting style. No refcount is added
1466 * to the returned style, so if you want to save this
1467 * style around, you should add a reference yourself.
1470 gtk_rc_get_style (GtkWidget *widget)
1472 GtkRcStyle *widget_rc_style;
1473 GSList *rc_styles = NULL;
1474 GtkRcContext *context;
1476 static guint rc_style_key_id = 0;
1478 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1480 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1482 /* We allow the specification of a single rc style to be bound
1483 * tightly to a widget, for application modifications
1485 if (!rc_style_key_id)
1486 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1488 if (context->rc_sets_widget)
1490 gchar *path, *path_reversed;
1493 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1494 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1496 g_free (path_reversed);
1499 if (context->rc_sets_widget_class)
1501 gchar *path, *path_reversed;
1504 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1505 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1507 g_free (path_reversed);
1510 if (context->rc_sets_class)
1514 type = GTK_OBJECT_TYPE (widget);
1518 gchar *path_reversed;
1521 path = gtk_type_name (type);
1522 path_length = strlen (path);
1523 path_reversed = g_strdup (path);
1524 g_strreverse (path_reversed);
1526 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1527 g_free (path_reversed);
1529 type = gtk_type_parent (type);
1533 rc_styles = sort_and_dereference_sets (rc_styles);
1535 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1538 if (widget_rc_style)
1539 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1542 return gtk_rc_init_style (rc_styles);
1548 * gtk_rc_get_style_by_paths:
1549 * @settings: a #GtkSettings object
1550 * @widget_path: the widget path to use when looking up the style, or %NULL
1551 * @class_path: the class path to use when looking up the style, or %NULL
1552 * @type: a type that will be used along with parent types of this type
1553 * when matching against class styles, or #G_TYPE_NONE
1555 * Creates up a #GtkStyle from styles defined in a RC file by providing
1556 * the raw components used in matching. This function may be useful
1557 * when creating pseudo-widgets that should be themed like widgets but
1558 * don't actually have corresponding GTK+ widgets. An example of this
1559 * would be items inside a GNOME canvas widget.
1561 * The action of gtk_rc_get_style() is similar to:
1562 * <informalexample><programlisting>
1563 * <!> gtk_widget_path (widget, NULL, &path, NULL);
1564 * <!> gtk_widget_class_path (widget, NULL, &class_path, NULL);
1565 * <!> gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1566 * <!> G_OBJECT_TYPE (widget));
1567 * </programlisting></informalexample>
1569 * Return value: A style created by matching with the supplied paths,
1570 * or %NULL if nothing matching was specified and the default style should
1571 * be used. The returned value is owned by GTK+ as part of an internal cache,
1572 * so you must call g_object_ref() on the returned value if you want to
1573 * keep a reference to it.
1576 gtk_rc_get_style_by_paths (GtkSettings *settings,
1577 const char *widget_path,
1578 const char *class_path,
1581 /* We duplicate the code from above to avoid slowing down the above
1582 * by generating paths when we don't need them. I don't know if
1583 * this is really worth it.
1585 GSList *rc_styles = NULL;
1586 GtkRcContext *context;
1588 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1590 context = gtk_rc_context_get (settings);
1592 if (context->rc_sets_widget)
1594 gchar *path_reversed;
1597 path_length = strlen (widget_path);
1598 path_reversed = g_strdup (widget_path);
1599 g_strreverse (path_reversed);
1601 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1602 g_free (path_reversed);
1605 if (context->rc_sets_widget_class)
1607 gchar *path_reversed;
1610 path_length = strlen (class_path);
1611 path_reversed = g_strdup (class_path);
1612 g_strreverse (path_reversed);
1614 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1615 g_free (path_reversed);
1618 if (type != G_TYPE_NONE && context->rc_sets_class)
1623 gchar *path_reversed;
1626 path = g_type_name (type);
1627 path_length = strlen (path);
1628 path_reversed = g_strdup (path);
1629 g_strreverse (path_reversed);
1631 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1632 g_free (path_reversed);
1634 type = g_type_parent (type);
1638 rc_styles = sort_and_dereference_sets (rc_styles);
1641 return gtk_rc_init_style (rc_styles);
1647 gtk_rc_add_rc_sets (GSList *slist,
1648 GtkRcStyle *rc_style,
1649 const gchar *pattern)
1651 GtkRcStyle *new_style;
1655 new_style = gtk_rc_style_new ();
1656 *new_style = *rc_style;
1657 new_style->name = g_strdup (rc_style->name);
1658 if (rc_style->font_desc)
1659 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1661 for (i = 0; i < 5; i++)
1662 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1664 rc_set = g_new (GtkRcSet, 1);
1665 rc_set->pspec = g_pattern_spec_new (pattern);
1666 rc_set->rc_style = rc_style;
1668 return g_slist_prepend (slist, rc_set);
1672 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1673 const gchar *pattern)
1675 GtkRcContext *context;
1677 g_return_if_fail (rc_style != NULL);
1678 g_return_if_fail (pattern != NULL);
1680 context = gtk_rc_context_get (gtk_settings_get_default ());
1682 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1686 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1687 const gchar *pattern)
1689 GtkRcContext *context;
1691 g_return_if_fail (rc_style != NULL);
1692 g_return_if_fail (pattern != NULL);
1694 context = gtk_rc_context_get (gtk_settings_get_default ());
1696 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1700 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1701 const gchar *pattern)
1703 GtkRcContext *context;
1705 g_return_if_fail (rc_style != NULL);
1706 g_return_if_fail (pattern != NULL);
1708 context = gtk_rc_context_get (gtk_settings_get_default ());
1710 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1714 gtk_rc_scanner_new (void)
1716 return g_scanner_new (>k_rc_scanner_config);
1720 gtk_rc_parse_any (GtkRcContext *context,
1721 const gchar *input_name,
1723 const gchar *input_string)
1729 scanner = gtk_rc_scanner_new ();
1733 g_assert (input_string == NULL);
1735 g_scanner_input_file (scanner, input_fd);
1739 g_assert (input_string != NULL);
1741 g_scanner_input_text (scanner, input_string, strlen (input_string));
1743 scanner->input_name = input_name;
1745 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1746 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1751 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1755 guint expected_token;
1757 expected_token = gtk_rc_parse_statement (context, scanner);
1759 if (expected_token != G_TOKEN_NONE)
1766 if (scanner->scope_id == 0)
1768 /* if we are in scope 0, we know the symbol names
1769 * that are associated with certain token values.
1770 * so we look them up to make the error messages
1773 if (expected_token > GTK_RC_TOKEN_INVALID &&
1774 expected_token < GTK_RC_TOKEN_LAST)
1776 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1777 if (symbols[i].token == expected_token)
1778 msg = symbols[i].name;
1780 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1782 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1783 scanner->token < GTK_RC_TOKEN_LAST)
1785 symbol_name = "???";
1786 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1787 if (symbols[i].token == scanner->token)
1788 symbol_name = symbols[i].name;
1791 g_scanner_unexp_token (scanner,
1804 g_scanner_destroy (scanner);
1808 gtk_rc_styles_hash (const GSList *rc_styles)
1815 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1816 rc_styles = rc_styles->next;
1823 gtk_rc_styles_equal (const GSList *a,
1828 if (a->data != b->data)
1838 gtk_rc_style_hash (const gchar *name)
1844 result += (result << 3) + *name++;
1850 gtk_rc_style_equal (const gchar *a,
1853 return (strcmp (a, b) == 0);
1857 gtk_rc_style_find (GtkRcContext *context,
1860 if (context->rc_style_ht)
1861 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1867 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1871 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1873 style->rc_style = rc_style;
1875 gtk_rc_style_ref (rc_style);
1877 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1882 /* Reuses or frees rc_styles */
1884 gtk_rc_init_style (GSList *rc_styles)
1886 GtkStyle *style = NULL;
1889 g_return_val_if_fail (rc_styles != NULL, NULL);
1891 if (!realized_style_ht)
1892 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1893 (GEqualFunc) gtk_rc_styles_equal);
1895 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1899 GtkRcStyle *base_style = NULL;
1900 GtkRcStyle *proto_style;
1901 GtkRcStyleClass *proto_style_class;
1903 GType rc_style_type = GTK_TYPE_RC_STYLE;
1905 /* Find the the first style where the RC file specified engine "" {}
1906 * or the first derived style and use that to create the
1907 * merged style. If we only have raw GtkRcStyles, use the first
1908 * style to create the merged style.
1910 base_style = rc_styles->data;
1911 tmp_styles = rc_styles;
1914 GtkRcStyle *rc_style = tmp_styles->data;
1916 if (rc_style->engine_specified ||
1917 G_OBJECT_TYPE (rc_style) != rc_style_type)
1919 base_style = rc_style;
1923 tmp_styles = tmp_styles->next;
1926 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1927 proto_style = proto_style_class->create_rc_style (base_style);
1929 tmp_styles = rc_styles;
1932 GtkRcStyle *rc_style = tmp_styles->data;
1935 proto_style_class->merge (proto_style, rc_style);
1937 /* Point from each rc_style to the list of styles */
1938 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1939 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1941 factories = g_slist_copy (rc_style->icon_factories);
1947 while (iter != NULL)
1949 g_object_ref (G_OBJECT (iter->data));
1950 iter = g_slist_next (iter);
1953 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1958 tmp_styles = tmp_styles->next;
1961 for (i = 0; i < 5; i++)
1962 if (proto_style->bg_pixmap_name[i] &&
1963 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
1965 g_free (proto_style->bg_pixmap_name[i]);
1966 proto_style->bg_pixmap_name[i] = NULL;
1969 style = gtk_rc_style_to_style (proto_style);
1970 gtk_rc_style_unref (proto_style);
1972 g_hash_table_insert (realized_style_ht, rc_styles, style);
1975 g_slist_free (rc_styles);
1980 /*********************
1981 * Parsing functions *
1982 *********************/
1985 rc_parse_token_or_compound (GScanner *scanner,
1987 GTokenType delimiter)
1989 guint token = g_scanner_get_next_token (scanner);
1991 /* we either scan a single token (skipping comments)
1992 * or a compund statement.
1993 * compunds are enclosed in (), [] or {} braces, we read
1994 * them in via deep recursion.
2001 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2004 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2006 case G_TOKEN_STRING:
2007 string = g_strescape (scanner->value.v_string, NULL);
2008 g_string_append (gstring, " \"");
2009 g_string_append (gstring, string);
2010 g_string_append_c (gstring, '"');
2013 case G_TOKEN_IDENTIFIER:
2014 g_string_append_c (gstring, ' ');
2015 g_string_append (gstring, scanner->value.v_identifier);
2017 case G_TOKEN_COMMENT_SINGLE:
2018 case G_TOKEN_COMMENT_MULTI:
2019 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2020 case G_TOKEN_LEFT_PAREN:
2021 g_string_append_c (gstring, ' ');
2022 g_string_append_c (gstring, token);
2023 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2024 if (token != G_TOKEN_NONE)
2027 case G_TOKEN_LEFT_CURLY:
2028 g_string_append_c (gstring, ' ');
2029 g_string_append_c (gstring, token);
2030 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2031 if (token != G_TOKEN_NONE)
2034 case G_TOKEN_LEFT_BRACE:
2035 g_string_append_c (gstring, ' ');
2036 g_string_append_c (gstring, token);
2037 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2038 if (token != G_TOKEN_NONE)
2042 if (token >= 256 || token < 1)
2043 return delimiter ? delimiter : G_TOKEN_STRING;
2044 g_string_append_c (gstring, ' ');
2045 g_string_append_c (gstring, token);
2046 if (token == delimiter)
2047 return G_TOKEN_NONE;
2051 return G_TOKEN_NONE;
2053 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2057 gtk_rc_parse_assignment (GScanner *scanner,
2058 GtkRcProperty *prop)
2060 gboolean scan_identifier = scanner->config->scan_identifier;
2061 gboolean scan_symbols = scanner->config->scan_symbols;
2062 gboolean identifier_2_string = scanner->config->identifier_2_string;
2063 gboolean char_2_token = scanner->config->char_2_token;
2064 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2065 gboolean numbers_2_int = scanner->config->numbers_2_int;
2066 gboolean negate = FALSE;
2069 /* check that this is an assignment */
2070 if (g_scanner_get_next_token (scanner) != '=')
2073 /* adjust scanner mode */
2074 scanner->config->scan_identifier = TRUE;
2075 scanner->config->scan_symbols = FALSE;
2076 scanner->config->identifier_2_string = FALSE;
2077 scanner->config->char_2_token = TRUE;
2078 scanner->config->scan_identifier_NULL = FALSE;
2079 scanner->config->numbers_2_int = TRUE;
2081 /* record location */
2082 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2084 /* parse optional sign */
2085 if (g_scanner_peek_next_token (scanner) == '-')
2087 g_scanner_get_next_token (scanner); /* eat sign */
2091 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2092 token = g_scanner_peek_next_token (scanner);
2096 g_scanner_get_next_token (scanner);
2097 g_value_init (&prop->value, G_TYPE_LONG);
2098 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2099 token = G_TOKEN_NONE;
2102 g_scanner_get_next_token (scanner);
2103 g_value_init (&prop->value, G_TYPE_DOUBLE);
2104 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2105 token = G_TOKEN_NONE;
2107 case G_TOKEN_STRING:
2108 g_scanner_get_next_token (scanner);
2110 token = G_TOKEN_INT;
2113 g_value_init (&prop->value, G_TYPE_STRING);
2114 g_value_set_string (&prop->value, scanner->value.v_string);
2115 token = G_TOKEN_NONE;
2118 case G_TOKEN_IDENTIFIER:
2119 case G_TOKEN_LEFT_PAREN:
2120 case G_TOKEN_LEFT_CURLY:
2121 case G_TOKEN_LEFT_BRACE:
2124 GString *gstring = g_string_new ("");
2126 token = rc_parse_token_or_compound (scanner, gstring, 0);
2127 if (token == G_TOKEN_NONE)
2129 g_string_append_c (gstring, ' ');
2130 g_value_init (&prop->value, G_TYPE_GSTRING);
2131 g_value_set_static_boxed (&prop->value, gstring);
2134 g_string_free (gstring, TRUE);
2139 g_scanner_get_next_token (scanner);
2140 token = G_TOKEN_INT;
2144 /* restore scanner mode */
2145 scanner->config->scan_identifier = scan_identifier;
2146 scanner->config->scan_symbols = scan_symbols;
2147 scanner->config->identifier_2_string = identifier_2_string;
2148 scanner->config->char_2_token = char_2_token;
2149 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2150 scanner->config->numbers_2_int = numbers_2_int;
2156 is_c_identifier (const gchar *string)
2159 gboolean is_varname;
2161 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2162 for (p = string + 1; *p && is_varname; p++)
2163 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2169 parse_include_file (GtkRcContext *context,
2171 const gchar *filename)
2173 char *to_parse = NULL;
2175 if (g_path_is_absolute (filename))
2177 /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
2178 * don't print an error in this case.
2180 to_parse = g_strdup (filename);
2184 /* if a relative path, we look relative to all the RC files in the
2185 * include stack. We require the file to be found in this case
2186 * so we can give meaningful error messages, and because on reparsing
2187 * non-absolute paths don't make sense.
2189 GSList *tmp_list = rc_dir_stack;
2192 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2194 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2202 tmp_list = tmp_list->next;
2208 gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
2213 g_scanner_warn (scanner,
2214 _("Unable to find include file: \"%s\""),
2221 gtk_rc_parse_statement (GtkRcContext *context,
2226 token = g_scanner_peek_next_token (scanner);
2229 case GTK_RC_TOKEN_INCLUDE:
2230 token = g_scanner_get_next_token (scanner);
2231 if (token != GTK_RC_TOKEN_INCLUDE)
2232 return GTK_RC_TOKEN_INCLUDE;
2233 token = g_scanner_get_next_token (scanner);
2234 if (token != G_TOKEN_STRING)
2235 return G_TOKEN_STRING;
2236 parse_include_file (context, scanner, scanner->value.v_string);
2237 return G_TOKEN_NONE;
2239 case GTK_RC_TOKEN_STYLE:
2240 return gtk_rc_parse_style (context, scanner);
2242 case GTK_RC_TOKEN_BINDING:
2243 return gtk_binding_parse_binding (scanner);
2245 case GTK_RC_TOKEN_PIXMAP_PATH:
2246 return gtk_rc_parse_pixmap_path (context, scanner);
2248 case GTK_RC_TOKEN_WIDGET:
2249 return gtk_rc_parse_path_pattern (context, scanner);
2251 case GTK_RC_TOKEN_WIDGET_CLASS:
2252 return gtk_rc_parse_path_pattern (context, scanner);
2254 case GTK_RC_TOKEN_CLASS:
2255 return gtk_rc_parse_path_pattern (context, scanner);
2257 case GTK_RC_TOKEN_MODULE_PATH:
2258 return gtk_rc_parse_module_path (scanner);
2260 case GTK_RC_TOKEN_IM_MODULE_PATH:
2261 return gtk_rc_parse_im_module_path (scanner);
2263 case GTK_RC_TOKEN_IM_MODULE_FILE:
2264 return gtk_rc_parse_im_module_file (scanner);
2266 case G_TOKEN_IDENTIFIER:
2267 if (is_c_identifier (scanner->next_value.v_identifier))
2269 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2272 g_scanner_get_next_token (scanner); /* eat identifier */
2273 name = g_strdup (scanner->value.v_identifier);
2275 token = gtk_rc_parse_assignment (scanner, &prop);
2276 if (token == G_TOKEN_NONE)
2278 GtkSettingsValue svalue;
2280 svalue.origin = prop.origin;
2281 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2282 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2283 gtk_settings_set_property_value (context->settings,
2287 g_free (prop.origin);
2288 if (G_VALUE_TYPE (&prop.value))
2289 g_value_unset (&prop.value);
2296 g_scanner_get_next_token (scanner);
2297 return G_TOKEN_IDENTIFIER;
2300 g_scanner_get_next_token (scanner);
2301 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2306 fixup_rc_set (GSList *list,
2312 GtkRcSet *set = list->data;
2313 if (set->rc_style == orig)
2314 set->rc_style = new;
2320 fixup_rc_sets (GtkRcContext *context,
2324 fixup_rc_set (context->rc_sets_widget, orig, new);
2325 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2326 fixup_rc_set (context->rc_sets_class, orig, new);
2330 gtk_rc_parse_style (GtkRcContext *context,
2333 GtkRcStyle *rc_style;
2334 GtkRcStyle *orig_style;
2335 GtkRcStyle *parent_style;
2338 GtkIconFactory *our_factory = NULL;
2340 token = g_scanner_get_next_token (scanner);
2341 if (token != GTK_RC_TOKEN_STYLE)
2342 return GTK_RC_TOKEN_STYLE;
2344 token = g_scanner_get_next_token (scanner);
2345 if (token != G_TOKEN_STRING)
2346 return G_TOKEN_STRING;
2348 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2350 orig_style = g_object_ref (rc_style);
2354 /* If there's a list, its first member is always the factory belonging
2357 if (rc_style && rc_style->icon_factories)
2358 our_factory = rc_style->icon_factories->data;
2362 rc_style = gtk_rc_style_new ();
2363 rc_style->name = g_strdup (scanner->value.v_string);
2365 for (i = 0; i < 5; i++)
2366 rc_style->bg_pixmap_name[i] = NULL;
2368 for (i = 0; i < 5; i++)
2369 rc_style->color_flags[i] = 0;
2372 token = g_scanner_peek_next_token (scanner);
2373 if (token == G_TOKEN_EQUAL_SIGN)
2375 token = g_scanner_get_next_token (scanner);
2377 token = g_scanner_get_next_token (scanner);
2378 if (token != G_TOKEN_STRING)
2380 token = G_TOKEN_STRING;
2384 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2389 for (i = 0; i < 5; i++)
2391 rc_style->color_flags[i] = parent_style->color_flags[i];
2392 rc_style->fg[i] = parent_style->fg[i];
2393 rc_style->bg[i] = parent_style->bg[i];
2394 rc_style->text[i] = parent_style->text[i];
2395 rc_style->base[i] = parent_style->base[i];
2398 rc_style->xthickness = parent_style->xthickness;
2399 rc_style->ythickness = parent_style->ythickness;
2401 if (parent_style->font_desc)
2403 if (rc_style->font_desc)
2404 pango_font_description_free (rc_style->font_desc);
2405 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2408 if (parent_style->rc_properties)
2412 for (i = 0; i < parent_style->rc_properties->len; i++)
2413 insert_rc_property (rc_style,
2414 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2418 for (i = 0; i < 5; i++)
2420 if (rc_style->bg_pixmap_name[i])
2421 g_free (rc_style->bg_pixmap_name[i]);
2422 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2425 /* Append parent's factories, adding a ref to them */
2426 if (parent_style->icon_factories != NULL)
2428 /* Add a factory for ourselves if we have none,
2429 * in case we end up defining more stock icons.
2430 * I see no real way around this; we need to maintain
2431 * the invariant that the first factory in the list
2432 * is always our_factory, the one belonging to us,
2433 * and if we put parent factories in the list we can't
2434 * do that if the style is reopened.
2436 if (our_factory == NULL)
2438 our_factory = gtk_icon_factory_new ();
2439 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2443 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2444 g_slist_copy (parent_style->icon_factories));
2446 factories = parent_style->icon_factories;
2447 while (factories != NULL)
2449 g_object_ref (G_OBJECT (factories->data));
2450 factories = factories->next;
2456 token = g_scanner_get_next_token (scanner);
2457 if (token != G_TOKEN_LEFT_CURLY)
2459 token = G_TOKEN_LEFT_CURLY;
2463 token = g_scanner_peek_next_token (scanner);
2464 while (token != G_TOKEN_RIGHT_CURLY)
2468 case GTK_RC_TOKEN_BG:
2469 token = gtk_rc_parse_bg (scanner, rc_style);
2471 case GTK_RC_TOKEN_FG:
2472 token = gtk_rc_parse_fg (scanner, rc_style);
2474 case GTK_RC_TOKEN_TEXT:
2475 token = gtk_rc_parse_text (scanner, rc_style);
2477 case GTK_RC_TOKEN_BASE:
2478 token = gtk_rc_parse_base (scanner, rc_style);
2480 case GTK_RC_TOKEN_XTHICKNESS:
2481 token = gtk_rc_parse_xthickness (scanner, rc_style);
2483 case GTK_RC_TOKEN_YTHICKNESS:
2484 token = gtk_rc_parse_ythickness (scanner, rc_style);
2486 case GTK_RC_TOKEN_BG_PIXMAP:
2487 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2489 case GTK_RC_TOKEN_FONT:
2490 token = gtk_rc_parse_font (scanner, rc_style);
2492 case GTK_RC_TOKEN_FONTSET:
2493 token = gtk_rc_parse_fontset (scanner, rc_style);
2495 case GTK_RC_TOKEN_FONT_NAME:
2496 token = gtk_rc_parse_font_name (scanner, rc_style);
2498 case GTK_RC_TOKEN_ENGINE:
2499 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2501 case GTK_RC_TOKEN_STOCK:
2502 if (our_factory == NULL)
2504 our_factory = gtk_icon_factory_new ();
2505 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2508 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2510 case G_TOKEN_IDENTIFIER:
2511 if (is_c_identifier (scanner->next_value.v_identifier) &&
2512 scanner->next_value.v_identifier[0] >= 'A' &&
2513 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2515 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2517 g_scanner_get_next_token (scanner); /* eat type name */
2518 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2519 if (g_scanner_get_next_token (scanner) != ':' ||
2520 g_scanner_get_next_token (scanner) != ':')
2525 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2526 !is_c_identifier (scanner->value.v_identifier))
2528 token = G_TOKEN_IDENTIFIER;
2532 /* it's important that we do the same canonification as GParamSpecPool here */
2533 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2534 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2536 token = gtk_rc_parse_assignment (scanner, &prop);
2537 if (token == G_TOKEN_NONE)
2539 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2540 insert_rc_property (rc_style, &prop, TRUE);
2543 g_free (prop.origin);
2544 if (G_VALUE_TYPE (&prop.value))
2545 g_value_unset (&prop.value);
2549 g_scanner_get_next_token (scanner);
2550 token = G_TOKEN_IDENTIFIER;
2554 g_scanner_get_next_token (scanner);
2555 token = G_TOKEN_RIGHT_CURLY;
2559 if (token != G_TOKEN_NONE)
2562 token = g_scanner_peek_next_token (scanner);
2563 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2565 token = g_scanner_get_next_token (scanner);
2566 if (token != G_TOKEN_RIGHT_CURLY)
2568 token = G_TOKEN_RIGHT_CURLY;
2572 if (rc_style != orig_style)
2574 if (!context->rc_style_ht)
2575 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2576 (GEqualFunc) gtk_rc_style_equal);
2578 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2580 /* If we copied the data into a new rc style, fix up references to the old rc style
2581 * in bindings that we have.
2584 fixup_rc_sets (context, orig_style, rc_style);
2588 g_object_unref (orig_style);
2590 return G_TOKEN_NONE;
2593 if (rc_style != orig_style)
2594 gtk_rc_style_unref (rc_style);
2597 g_object_unref (orig_style);
2602 const GtkRcProperty*
2603 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2605 GQuark property_name)
2607 GtkRcProperty *node = NULL;
2609 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2611 if (rc_style->rc_properties)
2615 key.type_name = type_name;
2616 key.property_name = property_name;
2618 node = bsearch (&key,
2619 rc_style->rc_properties->data, rc_style->rc_properties->len,
2620 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2627 gtk_rc_parse_bg (GScanner *scanner,
2633 token = g_scanner_get_next_token (scanner);
2634 if (token != GTK_RC_TOKEN_BG)
2635 return GTK_RC_TOKEN_BG;
2637 token = gtk_rc_parse_state (scanner, &state);
2638 if (token != G_TOKEN_NONE)
2641 token = g_scanner_get_next_token (scanner);
2642 if (token != G_TOKEN_EQUAL_SIGN)
2643 return G_TOKEN_EQUAL_SIGN;
2645 style->color_flags[state] |= GTK_RC_BG;
2646 return gtk_rc_parse_color (scanner, &style->bg[state]);
2650 gtk_rc_parse_fg (GScanner *scanner,
2656 token = g_scanner_get_next_token (scanner);
2657 if (token != GTK_RC_TOKEN_FG)
2658 return GTK_RC_TOKEN_FG;
2660 token = gtk_rc_parse_state (scanner, &state);
2661 if (token != G_TOKEN_NONE)
2664 token = g_scanner_get_next_token (scanner);
2665 if (token != G_TOKEN_EQUAL_SIGN)
2666 return G_TOKEN_EQUAL_SIGN;
2668 style->color_flags[state] |= GTK_RC_FG;
2669 return gtk_rc_parse_color (scanner, &style->fg[state]);
2673 gtk_rc_parse_text (GScanner *scanner,
2679 token = g_scanner_get_next_token (scanner);
2680 if (token != GTK_RC_TOKEN_TEXT)
2681 return GTK_RC_TOKEN_TEXT;
2683 token = gtk_rc_parse_state (scanner, &state);
2684 if (token != G_TOKEN_NONE)
2687 token = g_scanner_get_next_token (scanner);
2688 if (token != G_TOKEN_EQUAL_SIGN)
2689 return G_TOKEN_EQUAL_SIGN;
2691 style->color_flags[state] |= GTK_RC_TEXT;
2692 return gtk_rc_parse_color (scanner, &style->text[state]);
2696 gtk_rc_parse_base (GScanner *scanner,
2702 token = g_scanner_get_next_token (scanner);
2703 if (token != GTK_RC_TOKEN_BASE)
2704 return GTK_RC_TOKEN_BASE;
2706 token = gtk_rc_parse_state (scanner, &state);
2707 if (token != G_TOKEN_NONE)
2710 token = g_scanner_get_next_token (scanner);
2711 if (token != G_TOKEN_EQUAL_SIGN)
2712 return G_TOKEN_EQUAL_SIGN;
2714 style->color_flags[state] |= GTK_RC_BASE;
2715 return gtk_rc_parse_color (scanner, &style->base[state]);
2719 gtk_rc_parse_xthickness (GScanner *scanner,
2722 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2723 return GTK_RC_TOKEN_XTHICKNESS;
2725 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2726 return G_TOKEN_EQUAL_SIGN;
2728 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2731 style->xthickness = scanner->value.v_int;
2733 return G_TOKEN_NONE;
2737 gtk_rc_parse_ythickness (GScanner *scanner,
2740 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2741 return GTK_RC_TOKEN_YTHICKNESS;
2743 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2744 return G_TOKEN_EQUAL_SIGN;
2746 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2749 style->ythickness = scanner->value.v_int;
2751 return G_TOKEN_NONE;
2755 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2757 GtkRcStyle *rc_style)
2763 token = g_scanner_get_next_token (scanner);
2764 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2765 return GTK_RC_TOKEN_BG_PIXMAP;
2767 token = gtk_rc_parse_state (scanner, &state);
2768 if (token != G_TOKEN_NONE)
2771 token = g_scanner_get_next_token (scanner);
2772 if (token != G_TOKEN_EQUAL_SIGN)
2773 return G_TOKEN_EQUAL_SIGN;
2775 token = g_scanner_get_next_token (scanner);
2776 if (token != G_TOKEN_STRING)
2777 return G_TOKEN_STRING;
2779 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2780 (strcmp (scanner->value.v_string, "<none>") == 0))
2781 pixmap_file = g_strdup (scanner->value.v_string);
2783 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2784 scanner, scanner->value.v_string);
2788 if (rc_style->bg_pixmap_name[state])
2789 g_free (rc_style->bg_pixmap_name[state]);
2790 rc_style->bg_pixmap_name[state] = pixmap_file;
2793 return G_TOKEN_NONE;
2797 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2802 buf = g_build_filename (dir, pixmap_file, NULL);
2804 fd = open (buf, O_RDONLY);
2817 * gtk_rc_find_pixmap_in_path:
2818 * @settings: a #GtkSettings
2819 * @scanner: Scanner used to get line number information for the
2820 * warning message, or %NULL
2821 * @pixmap_file: name of the pixmap file to locate.
2823 * Looks up a file in pixmap path for the specified #GtkSettings.
2824 * If the file is not found, it outputs a warning message using
2825 * g_warning() and returns %NULL.
2827 * Return value: the filename.
2830 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2832 const gchar *pixmap_file)
2838 GtkRcContext *context = gtk_rc_context_get (settings);
2840 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2842 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2847 tmp_list = rc_dir_stack;
2850 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2854 tmp_list = tmp_list->next;
2858 g_scanner_warn (scanner,
2859 _("Unable to locate image file in pixmap_path: \"%s\""),
2862 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2869 gtk_rc_find_module_in_path (const gchar *module_file)
2875 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2877 buf = g_build_filename (module_path[i], module_file, NULL);
2879 fd = open (buf, O_RDONLY);
2893 gtk_rc_parse_font (GScanner *scanner,
2894 GtkRcStyle *rc_style)
2898 token = g_scanner_get_next_token (scanner);
2899 if (token != GTK_RC_TOKEN_FONT)
2900 return GTK_RC_TOKEN_FONT;
2902 token = g_scanner_get_next_token (scanner);
2903 if (token != G_TOKEN_EQUAL_SIGN)
2904 return G_TOKEN_EQUAL_SIGN;
2906 token = g_scanner_get_next_token (scanner);
2907 if (token != G_TOKEN_STRING)
2908 return G_TOKEN_STRING;
2910 /* Ignore, do nothing */
2912 return G_TOKEN_NONE;
2916 gtk_rc_parse_fontset (GScanner *scanner,
2917 GtkRcStyle *rc_style)
2921 token = g_scanner_get_next_token (scanner);
2922 if (token != GTK_RC_TOKEN_FONTSET)
2923 return GTK_RC_TOKEN_FONTSET;
2925 token = g_scanner_get_next_token (scanner);
2926 if (token != G_TOKEN_EQUAL_SIGN)
2927 return G_TOKEN_EQUAL_SIGN;
2929 token = g_scanner_get_next_token (scanner);
2930 if (token != G_TOKEN_STRING)
2931 return G_TOKEN_STRING;
2933 /* Do nothing - silently ignore */
2935 return G_TOKEN_NONE;
2939 gtk_rc_parse_font_name (GScanner *scanner,
2940 GtkRcStyle *rc_style)
2944 token = g_scanner_get_next_token (scanner);
2945 if (token != GTK_RC_TOKEN_FONT_NAME)
2946 return GTK_RC_TOKEN_FONT;
2948 token = g_scanner_get_next_token (scanner);
2949 if (token != G_TOKEN_EQUAL_SIGN)
2950 return G_TOKEN_EQUAL_SIGN;
2952 token = g_scanner_get_next_token (scanner);
2953 if (token != G_TOKEN_STRING)
2954 return G_TOKEN_STRING;
2956 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2958 return G_TOKEN_NONE;
2962 gtk_rc_parse_engine (GtkRcContext *context,
2964 GtkRcStyle **rc_style)
2967 GtkThemeEngine *engine;
2968 guint result = G_TOKEN_NONE;
2969 GtkRcStyle *new_style = NULL;
2970 gboolean parsed_curlies = FALSE;
2972 token = g_scanner_get_next_token (scanner);
2973 if (token != GTK_RC_TOKEN_ENGINE)
2974 return GTK_RC_TOKEN_ENGINE;
2976 token = g_scanner_get_next_token (scanner);
2977 if (token != G_TOKEN_STRING)
2978 return G_TOKEN_STRING;
2980 if (!scanner->value.v_string[0])
2982 /* Support engine "" {} to mean override to the default engine
2984 token = g_scanner_get_next_token (scanner);
2985 if (token != G_TOKEN_LEFT_CURLY)
2986 return G_TOKEN_LEFT_CURLY;
2988 token = g_scanner_get_next_token (scanner);
2989 if (token != G_TOKEN_RIGHT_CURLY)
2990 return G_TOKEN_RIGHT_CURLY;
2992 parsed_curlies = TRUE;
2994 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
2996 new_style = gtk_rc_style_new ();
2997 gtk_rc_style_real_merge (new_style, *rc_style);
2999 if ((*rc_style)->name)
3000 new_style->name = g_strdup ((*rc_style)->name);
3003 (*rc_style)->engine_specified = TRUE;
3007 engine = gtk_theme_engine_get (scanner->value.v_string);
3009 token = g_scanner_get_next_token (scanner);
3010 if (token != G_TOKEN_LEFT_CURLY)
3011 return G_TOKEN_LEFT_CURLY;
3015 GtkRcStyleClass *new_class;
3017 new_style = gtk_theme_engine_create_rc_style (engine);
3018 g_type_module_unuse (G_TYPE_MODULE (engine));
3020 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3022 new_class->merge (new_style, *rc_style);
3023 if ((*rc_style)->name)
3024 new_style->name = g_strdup ((*rc_style)->name);
3026 if (new_class->parse)
3028 parsed_curlies = TRUE;
3029 result = new_class->parse (new_style, context->settings, scanner);
3031 if (result != G_TOKEN_NONE)
3033 g_object_unref (G_OBJECT (new_style));
3040 if (!parsed_curlies)
3042 /* Skip over remainder, looking for nested {}'s
3046 result = G_TOKEN_RIGHT_CURLY;
3047 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3049 if (token == G_TOKEN_LEFT_CURLY)
3051 else if (token == G_TOKEN_RIGHT_CURLY)
3056 result = G_TOKEN_NONE;
3064 new_style->engine_specified = TRUE;
3066 g_object_unref (G_OBJECT (*rc_style));
3067 *rc_style = new_style;
3074 gtk_rc_parse_state (GScanner *scanner,
3075 GtkStateType *state)
3080 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3081 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3083 /* we don't know where we got called from, so we reset the scope here.
3084 * if we bail out due to errors, we *don't* reset the scope, so the
3085 * error messaging code can make sense of our tokens.
3087 old_scope = g_scanner_set_scope (scanner, 0);
3089 token = g_scanner_get_next_token (scanner);
3090 if (token != G_TOKEN_LEFT_BRACE)
3091 return G_TOKEN_LEFT_BRACE;
3093 token = g_scanner_get_next_token (scanner);
3096 case GTK_RC_TOKEN_ACTIVE:
3097 *state = GTK_STATE_ACTIVE;
3099 case GTK_RC_TOKEN_INSENSITIVE:
3100 *state = GTK_STATE_INSENSITIVE;
3102 case GTK_RC_TOKEN_NORMAL:
3103 *state = GTK_STATE_NORMAL;
3105 case GTK_RC_TOKEN_PRELIGHT:
3106 *state = GTK_STATE_PRELIGHT;
3108 case GTK_RC_TOKEN_SELECTED:
3109 *state = GTK_STATE_SELECTED;
3112 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3115 token = g_scanner_get_next_token (scanner);
3116 if (token != G_TOKEN_RIGHT_BRACE)
3117 return G_TOKEN_RIGHT_BRACE;
3119 g_scanner_set_scope (scanner, old_scope);
3121 return G_TOKEN_NONE;
3125 gtk_rc_parse_priority (GScanner *scanner,
3126 GtkPathPriorityType *priority)
3131 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3132 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3134 /* we don't know where we got called from, so we reset the scope here.
3135 * if we bail out due to errors, we *don't* reset the scope, so the
3136 * error messaging code can make sense of our tokens.
3138 old_scope = g_scanner_set_scope (scanner, 0);
3140 token = g_scanner_get_next_token (scanner);
3144 token = g_scanner_get_next_token (scanner);
3147 case GTK_RC_TOKEN_LOWEST:
3148 *priority = GTK_PATH_PRIO_LOWEST;
3150 case GTK_RC_TOKEN_GTK:
3151 *priority = GTK_PATH_PRIO_GTK;
3153 case GTK_RC_TOKEN_APPLICATION:
3154 *priority = GTK_PATH_PRIO_APPLICATION;
3156 case GTK_RC_TOKEN_THEME:
3157 *priority = GTK_PATH_PRIO_THEME;
3159 case GTK_RC_TOKEN_RC:
3160 *priority = GTK_PATH_PRIO_RC;
3162 case GTK_RC_TOKEN_HIGHEST:
3163 *priority = GTK_PATH_PRIO_HIGHEST;
3166 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3169 g_scanner_set_scope (scanner, old_scope);
3171 return G_TOKEN_NONE;
3175 gtk_rc_parse_color (GScanner *scanner,
3180 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3182 /* we don't need to set our own scope here, because
3183 * we don't need own symbols
3186 token = g_scanner_get_next_token (scanner);
3191 case G_TOKEN_LEFT_CURLY:
3192 token = g_scanner_get_next_token (scanner);
3193 if (token == G_TOKEN_INT)
3194 token_int = scanner->value.v_int;
3195 else if (token == G_TOKEN_FLOAT)
3196 token_int = scanner->value.v_float * 65535.0;
3198 return G_TOKEN_FLOAT;
3199 color->red = CLAMP (token_int, 0, 65535);
3201 token = g_scanner_get_next_token (scanner);
3202 if (token != G_TOKEN_COMMA)
3203 return G_TOKEN_COMMA;
3205 token = g_scanner_get_next_token (scanner);
3206 if (token == G_TOKEN_INT)
3207 token_int = scanner->value.v_int;
3208 else if (token == G_TOKEN_FLOAT)
3209 token_int = scanner->value.v_float * 65535.0;
3211 return G_TOKEN_FLOAT;
3212 color->green = CLAMP (token_int, 0, 65535);
3214 token = g_scanner_get_next_token (scanner);
3215 if (token != G_TOKEN_COMMA)
3216 return G_TOKEN_COMMA;
3218 token = g_scanner_get_next_token (scanner);
3219 if (token == G_TOKEN_INT)
3220 token_int = scanner->value.v_int;
3221 else if (token == G_TOKEN_FLOAT)
3222 token_int = scanner->value.v_float * 65535.0;
3224 return G_TOKEN_FLOAT;
3225 color->blue = CLAMP (token_int, 0, 65535);
3227 token = g_scanner_get_next_token (scanner);
3228 if (token != G_TOKEN_RIGHT_CURLY)
3229 return G_TOKEN_RIGHT_CURLY;
3230 return G_TOKEN_NONE;
3232 case G_TOKEN_STRING:
3233 if (!gdk_color_parse (scanner->value.v_string, color))
3235 g_scanner_warn (scanner, "Invalid color constant '%s'",
3236 scanner->value.v_string);
3237 return G_TOKEN_STRING;
3240 return G_TOKEN_NONE;
3243 return G_TOKEN_STRING;
3248 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3253 token = g_scanner_get_next_token (scanner);
3254 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3255 return GTK_RC_TOKEN_PIXMAP_PATH;
3257 token = g_scanner_get_next_token (scanner);
3258 if (token != G_TOKEN_STRING)
3259 return G_TOKEN_STRING;
3261 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3263 return G_TOKEN_NONE;
3267 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3269 const gchar *pix_path)
3272 gint start_offset = 0;
3276 /* free the old one, or just add to the old one ? */
3277 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3279 g_free (context->pixmap_path[path_num]);
3280 context->pixmap_path[path_num] = NULL;
3285 path_len = strlen (pix_path);
3287 for (end_offset = 0; end_offset <= path_len; end_offset++)
3289 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3290 (end_offset == path_len))
3292 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3293 if (g_path_is_absolute (path_element))
3295 context->pixmap_path[path_num] = path_element;
3297 context->pixmap_path[path_num] = NULL;
3301 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3302 path_element, scanner->input_name, scanner->line);
3303 g_free (path_element);
3306 start_offset = end_offset + 1;
3312 gtk_rc_parse_module_path (GScanner *scanner)
3316 token = g_scanner_get_next_token (scanner);
3317 if (token != GTK_RC_TOKEN_MODULE_PATH)
3318 return GTK_RC_TOKEN_MODULE_PATH;
3320 token = g_scanner_get_next_token (scanner);
3321 if (token != G_TOKEN_STRING)
3322 return G_TOKEN_STRING;
3324 gtk_rc_parse_module_path_string (scanner->value.v_string);
3326 return G_TOKEN_NONE;
3330 gtk_rc_parse_im_module_path (GScanner *scanner)
3334 token = g_scanner_get_next_token (scanner);
3335 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3336 return GTK_RC_TOKEN_IM_MODULE_FILE;
3338 token = g_scanner_get_next_token (scanner);
3339 if (token != G_TOKEN_STRING)
3340 return G_TOKEN_STRING;
3343 g_free (im_module_path);
3345 im_module_path = g_strdup (scanner->value.v_string);
3347 return G_TOKEN_NONE;
3351 gtk_rc_parse_im_module_file (GScanner *scanner)
3355 token = g_scanner_get_next_token (scanner);
3356 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3357 return GTK_RC_TOKEN_IM_MODULE_FILE;
3359 token = g_scanner_get_next_token (scanner);
3360 if (token != G_TOKEN_STRING)
3361 return G_TOKEN_STRING;
3364 g_free (im_module_file);
3366 im_module_file = g_strdup (scanner->value.v_string);
3368 return G_TOKEN_NONE;
3372 gtk_rc_parse_module_path_string (const gchar *mod_path)
3375 gint start_offset = 0;
3379 /* free the old one, or just add to the old one ? */
3380 for (path_num=0; module_path[path_num]; path_num++)
3382 g_free (module_path[path_num]);
3383 module_path[path_num] = NULL;
3388 path_len = strlen (mod_path);
3390 for (end_offset = 0; end_offset <= path_len; end_offset++)
3392 if ((mod_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3393 (end_offset == path_len))
3395 module_path[path_num] = g_strndup (mod_path + start_offset, end_offset - start_offset);
3397 module_path[path_num] = NULL;
3398 start_offset = end_offset + 1;
3401 gtk_rc_append_default_module_path();
3405 gtk_rc_parse_path_pattern (GtkRcContext *context,
3409 GtkPathType path_type;
3411 gboolean is_binding;
3412 GtkPathPriorityType priority = context->default_priority;
3414 token = g_scanner_get_next_token (scanner);
3417 case GTK_RC_TOKEN_WIDGET:
3418 path_type = GTK_PATH_WIDGET;
3420 case GTK_RC_TOKEN_WIDGET_CLASS:
3421 path_type = GTK_PATH_WIDGET_CLASS;
3423 case GTK_RC_TOKEN_CLASS:
3424 path_type = GTK_PATH_CLASS;
3427 return GTK_RC_TOKEN_WIDGET_CLASS;
3430 token = g_scanner_get_next_token (scanner);
3431 if (token != G_TOKEN_STRING)
3432 return G_TOKEN_STRING;
3434 pattern = g_strdup (scanner->value.v_string);
3436 token = g_scanner_get_next_token (scanner);
3437 if (token == GTK_RC_TOKEN_STYLE)
3439 else if (token == GTK_RC_TOKEN_BINDING)
3444 return GTK_RC_TOKEN_STYLE;
3447 if (g_scanner_peek_next_token (scanner) == ':')
3449 token = gtk_rc_parse_priority (scanner, &priority);
3450 if (token != G_TOKEN_NONE)
3457 token = g_scanner_get_next_token (scanner);
3458 if (token != G_TOKEN_STRING)
3461 return G_TOKEN_STRING;
3466 GtkBindingSet *binding;
3468 binding = gtk_binding_set_find (scanner->value.v_string);
3472 return G_TOKEN_STRING;
3474 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3478 GtkRcStyle *rc_style;
3481 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3486 return G_TOKEN_STRING;
3489 rc_set = g_new (GtkRcSet, 1);
3490 rc_set->pspec = g_pattern_spec_new (pattern);
3491 rc_set->rc_style = rc_style;
3492 rc_set->priority = priority;
3494 if (path_type == GTK_PATH_WIDGET)
3495 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3496 else if (path_type == GTK_PATH_WIDGET_CLASS)
3497 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3499 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3503 return G_TOKEN_NONE;
3507 gtk_rc_parse_stock_id (GScanner *scanner,
3512 token = g_scanner_get_next_token (scanner);
3513 if (token != G_TOKEN_LEFT_BRACE)
3514 return G_TOKEN_LEFT_BRACE;
3516 token = g_scanner_get_next_token (scanner);
3518 if (token != G_TOKEN_STRING)
3519 return G_TOKEN_STRING;
3521 *stock_id = g_strdup (scanner->value.v_string);
3523 token = g_scanner_get_next_token (scanner);
3524 if (token != G_TOKEN_RIGHT_BRACE)
3527 return G_TOKEN_RIGHT_BRACE;
3530 return G_TOKEN_NONE;
3534 gtk_rc_parse_icon_source (GtkRcContext *context,
3536 GtkIconSet *icon_set,
3537 gboolean *icon_set_valid)
3540 GtkIconSource *source;
3541 gchar *full_filename;
3543 token = g_scanner_get_next_token (scanner);
3544 if (token != G_TOKEN_LEFT_CURLY)
3545 return G_TOKEN_LEFT_CURLY;
3547 token = g_scanner_get_next_token (scanner);
3549 if (token != G_TOKEN_STRING)
3550 return G_TOKEN_STRING;
3553 source = gtk_icon_source_new ();
3555 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3558 gtk_icon_source_set_filename (source, full_filename);
3559 g_free (full_filename);
3562 /* We continue parsing even if we didn't find the pixmap so that rest of the
3563 * file is read, even if the syntax is bad. However we don't validate the
3564 * icon_set so the caller can choose not to install it.
3566 token = g_scanner_get_next_token (scanner);
3568 if (token == G_TOKEN_RIGHT_CURLY)
3570 else if (token != G_TOKEN_COMMA)
3572 gtk_icon_source_free (source);
3573 return G_TOKEN_COMMA;
3576 /* Get the direction */
3578 token = g_scanner_get_next_token (scanner);
3582 case GTK_RC_TOKEN_RTL:
3583 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3584 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3587 case GTK_RC_TOKEN_LTR:
3588 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3589 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3596 gtk_icon_source_free (source);
3597 return GTK_RC_TOKEN_RTL;
3601 token = g_scanner_get_next_token (scanner);
3603 if (token == G_TOKEN_RIGHT_CURLY)
3605 else if (token != G_TOKEN_COMMA)
3607 gtk_icon_source_free (source);
3608 return G_TOKEN_COMMA;
3613 token = g_scanner_get_next_token (scanner);
3617 case GTK_RC_TOKEN_NORMAL:
3618 gtk_icon_source_set_state_wildcarded (source, FALSE);
3619 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3622 case GTK_RC_TOKEN_PRELIGHT:
3623 gtk_icon_source_set_state_wildcarded (source, FALSE);
3624 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3628 case GTK_RC_TOKEN_INSENSITIVE:
3629 gtk_icon_source_set_state_wildcarded (source, FALSE);
3630 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3633 case GTK_RC_TOKEN_ACTIVE:
3634 gtk_icon_source_set_state_wildcarded (source, FALSE);
3635 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3638 case GTK_RC_TOKEN_SELECTED:
3639 gtk_icon_source_set_state_wildcarded (source, FALSE);
3640 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3647 gtk_icon_source_free (source);
3648 return GTK_RC_TOKEN_PRELIGHT;
3652 token = g_scanner_get_next_token (scanner);
3654 if (token == G_TOKEN_RIGHT_CURLY)
3656 else if (token != G_TOKEN_COMMA)
3658 gtk_icon_source_free (source);
3659 return G_TOKEN_COMMA;
3664 token = g_scanner_get_next_token (scanner);
3670 if (token != G_TOKEN_STRING)
3672 gtk_icon_source_free (source);
3673 return G_TOKEN_STRING;
3676 size = gtk_icon_size_from_name (scanner->value.v_string);
3678 if (size != GTK_ICON_SIZE_INVALID)
3680 gtk_icon_source_set_size_wildcarded (source, FALSE);
3681 gtk_icon_source_set_size (source, size);
3685 /* Check the close brace */
3687 token = g_scanner_get_next_token (scanner);
3688 if (token != G_TOKEN_RIGHT_CURLY)
3690 gtk_icon_source_free (source);
3691 return G_TOKEN_RIGHT_CURLY;
3695 if (gtk_icon_source_get_filename (source))
3697 gtk_icon_set_add_source (icon_set, source);
3698 *icon_set_valid = TRUE;
3700 gtk_icon_source_free (source);
3702 return G_TOKEN_NONE;
3706 gtk_rc_parse_stock (GtkRcContext *context,
3708 GtkRcStyle *rc_style,
3709 GtkIconFactory *factory)
3711 GtkIconSet *icon_set = NULL;
3712 gboolean icon_set_valid = FALSE;
3713 gchar *stock_id = NULL;
3716 token = g_scanner_get_next_token (scanner);
3717 if (token != GTK_RC_TOKEN_STOCK)
3718 return GTK_RC_TOKEN_STOCK;
3720 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3721 if (token != G_TOKEN_NONE)
3724 token = g_scanner_get_next_token (scanner);
3725 if (token != G_TOKEN_EQUAL_SIGN)
3728 return G_TOKEN_EQUAL_SIGN;
3731 token = g_scanner_get_next_token (scanner);
3732 if (token != G_TOKEN_LEFT_CURLY)
3735 return G_TOKEN_LEFT_CURLY;
3738 token = g_scanner_peek_next_token (scanner);
3739 while (token != G_TOKEN_RIGHT_CURLY)
3741 if (icon_set == NULL)
3742 icon_set = gtk_icon_set_new ();
3744 token = gtk_rc_parse_icon_source (context,
3745 scanner, icon_set, &icon_set_valid);
3746 if (token != G_TOKEN_NONE)
3749 gtk_icon_set_unref (icon_set);
3753 token = g_scanner_get_next_token (scanner);
3755 if (token != G_TOKEN_COMMA &&
3756 token != G_TOKEN_RIGHT_CURLY)
3759 gtk_icon_set_unref (icon_set);
3760 return G_TOKEN_RIGHT_CURLY;
3764 if (icon_set && icon_set_valid)
3766 gtk_icon_factory_add (factory,
3770 gtk_icon_set_unref (icon_set);
3775 return G_TOKEN_NONE;