1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
47 #include "gdkconfig.h"
49 #include "gtkversion.h"
51 #include "gtkbindings.h"
52 #include "gtkthemes.h"
54 #include "gtkiconfactory.h"
56 #include "gtkprivate.h"
57 #include "gtksettings.h"
58 #include "gtkwindow.h"
64 typedef struct _GtkRcSet GtkRcSet;
65 typedef struct _GtkRcNode GtkRcNode;
66 typedef struct _GtkRcFile GtkRcFile;
77 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
80 gchar *canonical_name;
84 #define GTK_RC_MAX_PIXMAP_PATHS 128
88 GHashTable *rc_style_ht;
89 GtkSettings *settings;
90 GSList *rc_sets_widget;
91 GSList *rc_sets_widget_class;
92 GSList *rc_sets_class;
94 /* The files we have parsed, to reread later if necessary */
98 gchar *key_theme_name;
101 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
103 gint default_priority;
104 GtkStyle *default_style;
107 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
109 static guint gtk_rc_style_hash (const gchar *name);
110 static gboolean gtk_rc_style_equal (const gchar *a,
112 static guint gtk_rc_styles_hash (const GSList *rc_styles);
113 static gboolean gtk_rc_styles_equal (const GSList *a,
115 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
117 static GSList * gtk_rc_styles_match (GSList *rc_styles,
121 const gchar *path_reversed);
122 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
123 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
124 static void gtk_rc_parse_default_files (GtkRcContext *context);
125 static void gtk_rc_parse_named (GtkRcContext *context,
128 static void gtk_rc_parse_file (GtkRcContext *context,
129 const gchar *filename,
132 static void gtk_rc_parse_any (GtkRcContext *context,
133 const gchar *input_name,
135 const gchar *input_string);
136 static guint gtk_rc_parse_statement (GtkRcContext *context,
138 static guint gtk_rc_parse_style (GtkRcContext *context,
140 static guint gtk_rc_parse_assignment (GScanner *scanner,
141 GtkRcProperty *prop);
142 static guint gtk_rc_parse_bg (GScanner *scanner,
144 static guint gtk_rc_parse_fg (GScanner *scanner,
146 static guint gtk_rc_parse_text (GScanner *scanner,
148 static guint gtk_rc_parse_base (GScanner *scanner,
150 static guint gtk_rc_parse_xthickness (GScanner *scanner,
152 static guint gtk_rc_parse_ythickness (GScanner *scanner,
154 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
156 GtkRcStyle *rc_style);
157 static guint gtk_rc_parse_font (GScanner *scanner,
158 GtkRcStyle *rc_style);
159 static guint gtk_rc_parse_fontset (GScanner *scanner,
160 GtkRcStyle *rc_style);
161 static guint gtk_rc_parse_font_name (GScanner *scanner,
162 GtkRcStyle *rc_style);
163 static guint gtk_rc_parse_engine (GtkRcContext *context,
165 GtkRcStyle **rc_style);
166 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
168 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
170 const gchar *pix_path);
171 static guint gtk_rc_parse_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_add_initial_default_files (void);
185 static void gtk_rc_style_init (GtkRcStyle *style);
186 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
187 static void gtk_rc_style_finalize (GObject *object);
188 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
190 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
191 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
192 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
193 gconstpointer bsearch_node2);
195 static gpointer parent_class = NULL;
197 static const GScannerConfig gtk_rc_scanner_config =
201 ) /* cset_skip_characters */,
206 ) /* cset_identifier_first */,
211 ) /* cset_identifier_nth */,
212 ( "#\n" ) /* cpair_comment_single */,
214 TRUE /* case_sensitive */,
216 TRUE /* skip_comment_multi */,
217 TRUE /* skip_comment_single */,
218 TRUE /* scan_comment_multi */,
219 TRUE /* scan_identifier */,
220 FALSE /* scan_identifier_1char */,
221 FALSE /* scan_identifier_NULL */,
222 TRUE /* scan_symbols */,
223 TRUE /* scan_binary */,
224 TRUE /* scan_octal */,
225 TRUE /* scan_float */,
227 TRUE /* scan_hex_dollar */,
228 TRUE /* scan_string_sq */,
229 TRUE /* scan_string_dq */,
230 TRUE /* numbers_2_int */,
231 FALSE /* int_2_float */,
232 FALSE /* identifier_2_string */,
233 TRUE /* char_2_token */,
234 TRUE /* symbol_2_token */,
235 FALSE /* scope_0_fallback */,
243 { "include", GTK_RC_TOKEN_INCLUDE },
244 { "NORMAL", GTK_RC_TOKEN_NORMAL },
245 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
246 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
247 { "SELECTED", GTK_RC_TOKEN_SELECTED },
248 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
249 { "fg", GTK_RC_TOKEN_FG },
250 { "bg", GTK_RC_TOKEN_BG },
251 { "text", GTK_RC_TOKEN_TEXT },
252 { "base", GTK_RC_TOKEN_BASE },
253 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
254 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
255 { "font", GTK_RC_TOKEN_FONT },
256 { "fontset", GTK_RC_TOKEN_FONTSET },
257 { "font_name", GTK_RC_TOKEN_FONT_NAME },
258 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
259 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
260 { "style", GTK_RC_TOKEN_STYLE },
261 { "binding", GTK_RC_TOKEN_BINDING },
262 { "bind", GTK_RC_TOKEN_BIND },
263 { "widget", GTK_RC_TOKEN_WIDGET },
264 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
265 { "class", GTK_RC_TOKEN_CLASS },
266 { "lowest", GTK_RC_TOKEN_LOWEST },
267 { "gtk", GTK_RC_TOKEN_GTK },
268 { "application", GTK_RC_TOKEN_APPLICATION },
269 { "theme", GTK_RC_TOKEN_THEME },
270 { "rc", GTK_RC_TOKEN_RC },
271 { "highest", GTK_RC_TOKEN_HIGHEST },
272 { "engine", GTK_RC_TOKEN_ENGINE },
273 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
274 { "stock", GTK_RC_TOKEN_STOCK },
275 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
276 { "LTR", GTK_RC_TOKEN_LTR },
277 { "RTL", GTK_RC_TOKEN_RTL }
280 static GHashTable *realized_style_ht = NULL;
282 static gchar *im_module_file = NULL;
284 #define GTK_RC_MAX_DEFAULT_FILES 128
285 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
287 /* A stack of directories for RC files we are parsing currently.
288 * these are implicitely added to the end of PIXMAP_PATHS
290 static GSList *rc_dir_stack = NULL;
292 /* RC file handling */
295 gtk_rc_make_default_dir (const gchar *type)
300 var = g_getenv ("GTK_EXE_PREFIX");
302 path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
304 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
310 * gtk_rc_get_im_module_path:
311 * @returns: a newly-allocated string containing the path in which to
312 * look for IM modules.
314 * Obtains the path in which to look for IM modules. See the documentation
315 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
316 * environment variable for more details about looking up modules. This
317 * function is useful solely for utilities supplied with GTK+ and should
318 * not be used by applications under normal circumstances.
321 gtk_rc_get_im_module_path (void)
323 gchar **paths = _gtk_get_module_path ("immodules");
324 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
331 * gtk_rc_get_im_module_file:
332 * @returns: a newly-allocated string containing the name of the file
333 * listing the IM modules available for loading
335 * Obtains the path to the IM modules file. See the documentation
336 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
337 * environment variable for more details.
340 gtk_rc_get_im_module_file (void)
342 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
347 result = g_strdup (im_module_file);
349 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
356 gtk_rc_get_theme_dir (void)
361 var = g_getenv ("GTK_DATA_PREFIX");
363 path = g_build_filename (var, "share", "themes", NULL);
365 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
371 * gtk_rc_get_module_dir:
373 * Returns a directory in which GTK+ looks for theme engines.
374 * For full information about the search for theme engines,
375 * see the docs for <envar>GTK_PATH</envar> in
376 * <xref linkend="gtk-running"/>.
378 * return value: the directory. (Must be freed with g_free())
381 gtk_rc_get_module_dir (void)
383 return gtk_rc_make_default_dir ("engines");
387 gtk_rc_add_initial_default_files (void)
389 static gint init = FALSE;
398 gtk_rc_default_files[0] = NULL;
401 var = g_getenv ("GTK_RC_FILES");
404 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
408 gtk_rc_add_default_file (files[i]);
415 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
417 gtk_rc_add_default_file (str);
420 var = g_get_home_dir ();
423 str = g_build_filename (var, ".gtkrc-2.0", NULL);
424 gtk_rc_add_default_file (str);
431 * gtk_rc_add_default_file:
432 * @filename: the pathname to the file. If @filename is not absolute, it
433 * is searched in the current directory.
435 * Adds a file to the list of files to be parsed at the
439 gtk_rc_add_default_file (const gchar *filename)
443 gtk_rc_add_initial_default_files ();
445 for (n = 0; gtk_rc_default_files[n]; n++) ;
446 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
449 gtk_rc_default_files[n++] = g_strdup (filename);
450 gtk_rc_default_files[n] = NULL;
454 * gtk_rc_set_default_files:
455 * @filenames: A %NULL-terminated list of filenames.
457 * Sets the list of files that GTK+ will read at the
461 gtk_rc_set_default_files (gchar **filenames)
465 gtk_rc_add_initial_default_files ();
468 while (gtk_rc_default_files[i])
470 g_free (gtk_rc_default_files[i]);
474 gtk_rc_default_files[0] = NULL;
477 while (filenames[i] != NULL)
479 gtk_rc_add_default_file (filenames[i]);
485 * gtk_rc_get_default_files:
487 * Retrieves the current list of RC files that will be parsed
488 * at the end of gtk_init().
490 * Return value: A %NULL-terminated array of filenames. This memory
491 * is owned by GTK+ and must not be freed by the application.
492 * If you want to store this information, you should make a copy.
495 gtk_rc_get_default_files (void)
497 gtk_rc_add_initial_default_files ();
499 return gtk_rc_default_files;
503 gtk_rc_settings_changed (GtkSettings *settings,
505 GtkRcContext *context)
507 gchar *new_theme_name;
508 gchar *new_key_theme_name;
510 g_object_get (settings,
511 "gtk-theme-name", &new_theme_name,
512 "gtk-key-theme-name", &new_key_theme_name,
515 if ((new_theme_name != context->theme_name &&
516 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
517 (new_key_theme_name != context->key_theme_name &&
518 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
520 gtk_rc_reparse_all_for_settings (settings, TRUE);
523 g_free (new_theme_name);
524 g_free (new_key_theme_name);
528 gtk_rc_font_name_changed (GtkSettings *settings,
530 GtkRcContext *context)
532 _gtk_rc_context_get_default_font_name (settings);
535 static GtkRcContext *
536 gtk_rc_context_get (GtkSettings *settings)
538 if (!settings->rc_context)
540 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
542 context->settings = settings;
543 context->rc_style_ht = NULL;
544 context->rc_sets_widget = NULL;
545 context->rc_sets_widget_class = NULL;
546 context->rc_sets_class = NULL;
547 context->rc_files = NULL;
548 context->default_style = NULL;
550 g_object_get (settings,
551 "gtk-theme-name", &context->theme_name,
552 "gtk-key-theme-name", &context->key_theme_name,
553 "gtk-font-name", &context->font_name,
556 g_signal_connect (settings,
557 "notify::gtk-theme-name",
558 G_CALLBACK (gtk_rc_settings_changed),
560 g_signal_connect (settings,
561 "notify::gtk-key-theme-name",
562 G_CALLBACK (gtk_rc_settings_changed),
564 g_signal_connect (settings,
565 "notify::gtk-font-name",
566 G_CALLBACK (gtk_rc_font_name_changed),
570 context->pixmap_path[0] = NULL;
572 context->default_priority = GTK_PATH_PRIO_RC;
575 return settings->rc_context;
579 gtk_rc_parse_named (GtkRcContext *context,
584 const gchar *home_dir;
588 subpath = g_strconcat ("gtk-2.0-", type,
589 G_DIR_SEPARATOR_S "gtkrc",
592 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
594 /* First look in the users home directory
596 home_dir = g_get_home_dir ();
599 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
600 if (!g_file_test (path, G_FILE_TEST_EXISTS))
609 gchar *theme_dir = gtk_rc_get_theme_dir ();
610 path = g_build_filename (theme_dir, name, subpath, NULL);
613 if (!g_file_test (path, G_FILE_TEST_EXISTS))
622 gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
630 gtk_rc_parse_default_files (GtkRcContext *context)
634 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
635 gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
641 static gboolean initialized = FALSE;
647 gtk_rc_add_initial_default_files ();
650 gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
652 /* Default RC string */
653 gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
654 " bg[NORMAL] = \"#ffffc0\"\n"
655 " fg[NORMAL] = \"#000000\"\n"
658 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n");
662 gtk_rc_parse_string (const gchar *rc_string)
665 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
666 * string in all contexts, and in fact, in future contexts as well.
668 GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
670 g_return_if_fail (rc_string != NULL);
672 rc_file = g_new (GtkRcFile, 1);
673 rc_file->is_string = TRUE;
674 rc_file->name = g_strdup (rc_string);
675 rc_file->canonical_name = NULL;
677 rc_file->reload = TRUE;
679 context->rc_files = g_slist_append (context->rc_files, rc_file);
681 gtk_rc_parse_any (context, "-", -1, rc_string);
685 gtk_rc_parse_one_file (GtkRcContext *context,
686 const gchar *filename,
690 GtkRcFile *rc_file = NULL;
695 g_return_if_fail (filename != NULL);
697 saved_priority = context->default_priority;
698 context->default_priority = priority;
700 tmp_list = context->rc_files;
703 rc_file = tmp_list->data;
704 if (!strcmp (rc_file->name, filename))
707 tmp_list = tmp_list->next;
712 rc_file = g_new (GtkRcFile, 1);
713 rc_file->is_string = FALSE;
714 rc_file->name = g_strdup (filename);
715 rc_file->canonical_name = NULL;
717 rc_file->reload = reload;
719 context->rc_files = g_slist_append (context->rc_files, rc_file);
722 if (!rc_file->canonical_name)
724 /* Get the absolute pathname */
726 if (g_path_is_absolute (rc_file->name))
727 rc_file->canonical_name = rc_file->name;
732 cwd = g_get_current_dir ();
733 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
738 if (!lstat (rc_file->canonical_name, &statbuf))
743 rc_file->mtime = statbuf.st_mtime;
745 fd = open (rc_file->canonical_name, O_RDONLY);
749 /* Temporarily push directory name for this file on
750 * a stack of directory names while parsing it
753 g_slist_prepend (rc_dir_stack,
754 g_path_get_dirname (rc_file->canonical_name));
755 gtk_rc_parse_any (context, filename, fd, NULL);
757 tmp_list = rc_dir_stack;
758 rc_dir_stack = rc_dir_stack->next;
760 g_free (tmp_list->data);
761 g_slist_free_1 (tmp_list);
767 context->default_priority = saved_priority;
771 strchr_len (const gchar *str, gint len, char c)
785 gtk_rc_parse_file (GtkRcContext *context,
786 const gchar *filename,
790 gchar *locale_suffixes[2];
791 gint n_locale_suffixes = 0;
795 gboolean found = FALSE;
798 locale = g_win32_getlocale ();
800 locale = setlocale (LC_CTYPE, NULL);
803 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
805 /* Determine locale-specific suffixes for RC files.
807 length = strlen (locale);
809 p = strchr (locale, '@');
813 p = strchr_len (locale, length, '.');
817 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
819 p = strchr_len (locale, length, '_');
823 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
827 gtk_rc_parse_one_file (context, filename, priority, reload);
828 for (j = 0; j < n_locale_suffixes; j++)
832 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
833 if (g_file_test (name, G_FILE_TEST_EXISTS))
835 gtk_rc_parse_one_file (context, name, priority, FALSE);
842 g_free (locale_suffixes[j]);
847 gtk_rc_parse (const gchar *filename)
849 g_return_if_fail (filename != NULL);
851 /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
852 * file in all contexts, and in fact, in future contexts as well.
854 gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
855 filename, GTK_PATH_PRIO_RC, TRUE);
858 /* Handling of RC styles */
861 gtk_rc_style_get_type (void)
863 static GType object_type = 0;
867 static const GTypeInfo object_info =
869 sizeof (GtkRcStyleClass),
870 (GBaseInitFunc) NULL,
871 (GBaseFinalizeFunc) NULL,
872 (GClassInitFunc) gtk_rc_style_class_init,
873 NULL, /* class_finalize */
874 NULL, /* class_data */
877 (GInstanceInitFunc) gtk_rc_style_init,
880 object_type = g_type_register_static (G_TYPE_OBJECT,
889 gtk_rc_style_init (GtkRcStyle *style)
894 style->font_desc = NULL;
896 for (i = 0; i < 5; i++)
898 static const GdkColor init_color = { 0, 0, 0, 0, };
900 style->bg_pixmap_name[i] = NULL;
901 style->color_flags[i] = 0;
902 style->fg[i] = init_color;
903 style->bg[i] = init_color;
904 style->text[i] = init_color;
905 style->base[i] = init_color;
907 style->xthickness = -1;
908 style->ythickness = -1;
909 style->rc_properties = NULL;
911 style->rc_style_lists = NULL;
912 style->icon_factories = NULL;
916 gtk_rc_style_class_init (GtkRcStyleClass *klass)
918 GObjectClass *object_class = G_OBJECT_CLASS (klass);
920 parent_class = g_type_class_peek_parent (klass);
922 object_class->finalize = gtk_rc_style_finalize;
925 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
926 klass->merge = gtk_rc_style_real_merge;
927 klass->create_style = gtk_rc_style_real_create_style;
931 gtk_rc_style_finalize (GObject *object)
933 GSList *tmp_list1, *tmp_list2;
934 GtkRcStyle *rc_style;
937 rc_style = GTK_RC_STYLE (object);
940 g_free (rc_style->name);
941 if (rc_style->font_desc)
942 pango_font_description_free (rc_style->font_desc);
944 for (i = 0; i < 5; i++)
945 if (rc_style->bg_pixmap_name[i])
946 g_free (rc_style->bg_pixmap_name[i]);
948 /* Now remove all references to this rc_style from
951 tmp_list1 = rc_style->rc_style_lists;
954 GSList *rc_styles = tmp_list1->data;
955 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
956 gtk_style_unref (style);
958 /* Remove the list of styles from the other rc_styles
961 tmp_list2 = rc_styles;
964 GtkRcStyle *other_style = tmp_list2->data;
966 if (other_style != rc_style)
967 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
969 tmp_list2 = tmp_list2->next;
972 /* And from the hash table itself
974 g_hash_table_remove (realized_style_ht, rc_styles);
975 g_slist_free (rc_styles);
977 tmp_list1 = tmp_list1->next;
979 g_slist_free (rc_style->rc_style_lists);
981 if (rc_style->rc_properties)
985 for (i = 0; i < rc_style->rc_properties->len; i++)
987 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
989 g_free (node->origin);
990 g_value_unset (&node->value);
992 g_array_free (rc_style->rc_properties, TRUE);
993 rc_style->rc_properties = NULL;
996 tmp_list1 = rc_style->icon_factories;
999 g_object_unref (G_OBJECT (tmp_list1->data));
1001 tmp_list1 = tmp_list1->next;
1003 g_slist_free (rc_style->icon_factories);
1005 G_OBJECT_CLASS (parent_class)->finalize (object);
1009 gtk_rc_style_new (void)
1013 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1019 * gtk_rc_style_copy:
1020 * @orig: the style to copy
1022 * Makes a copy of the specified #GtkRcStyle. This function
1023 * will correctly copy an RC style that is a member of a class
1024 * derived from #GtkRcStyle.
1026 * Return value: the resulting #GtkRcStyle
1029 gtk_rc_style_copy (GtkRcStyle *orig)
1033 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1035 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1036 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1042 gtk_rc_style_ref (GtkRcStyle *rc_style)
1044 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1046 g_object_ref (G_OBJECT (rc_style));
1050 gtk_rc_style_unref (GtkRcStyle *rc_style)
1052 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1054 g_object_unref (G_OBJECT (rc_style));
1058 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1060 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1064 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1065 gconstpointer bsearch_node2)
1067 const GtkRcProperty *prop1 = bsearch_node1;
1068 const GtkRcProperty *prop2 = bsearch_node2;
1070 if (prop1->type_name == prop2->type_name)
1071 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1073 return prop1->type_name < prop2->type_name ? -1 : 1;
1077 insert_rc_property (GtkRcStyle *style,
1078 GtkRcProperty *property,
1082 GtkRcProperty *new_property = NULL;
1083 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1085 key.type_name = property->type_name;
1086 key.property_name = property->property_name;
1088 if (!style->rc_properties)
1089 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1092 while (i < style->rc_properties->len)
1094 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1100 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1102 g_free (new_property->origin);
1103 g_value_unset (&new_property->value);
1105 *new_property = key;
1119 g_array_insert_val (style->rc_properties, i, key);
1120 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1123 new_property->origin = g_strdup (property->origin);
1124 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1125 g_value_copy (&property->value, &new_property->value);
1129 gtk_rc_style_real_merge (GtkRcStyle *dest,
1134 for (i = 0; i < 5; i++)
1136 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1137 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1139 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1140 src->color_flags[i] & GTK_RC_FG)
1142 dest->fg[i] = src->fg[i];
1143 dest->color_flags[i] |= GTK_RC_FG;
1145 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1146 src->color_flags[i] & GTK_RC_BG)
1148 dest->bg[i] = src->bg[i];
1149 dest->color_flags[i] |= GTK_RC_BG;
1151 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1152 src->color_flags[i] & GTK_RC_TEXT)
1154 dest->text[i] = src->text[i];
1155 dest->color_flags[i] |= GTK_RC_TEXT;
1157 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1158 src->color_flags[i] & GTK_RC_BASE)
1160 dest->base[i] = src->base[i];
1161 dest->color_flags[i] |= GTK_RC_BASE;
1165 if (dest->xthickness < 0 && src->xthickness >= 0)
1166 dest->xthickness = src->xthickness;
1167 if (dest->ythickness < 0 && src->ythickness >= 0)
1168 dest->ythickness = src->ythickness;
1172 if (!dest->font_desc)
1173 dest->font_desc = pango_font_description_copy (src->font_desc);
1175 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1178 if (src->rc_properties)
1182 for (i = 0; i < src->rc_properties->len; i++)
1183 insert_rc_property (dest,
1184 &g_array_index (src->rc_properties, GtkRcProperty, i),
1190 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1192 return gtk_style_new ();
1196 gtk_rc_clear_hash_node (gpointer key,
1200 gtk_rc_style_unref (data);
1204 gtk_rc_free_rc_sets (GSList *slist)
1210 rc_set = slist->data;
1211 g_pattern_spec_free (rc_set->pspec);
1214 slist = slist->next;
1219 gtk_rc_clear_styles (GtkRcContext *context)
1221 /* Clear out all old rc_styles */
1223 if (context->rc_style_ht)
1225 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1226 g_hash_table_destroy (context->rc_style_ht);
1227 context->rc_style_ht = NULL;
1230 gtk_rc_free_rc_sets (context->rc_sets_widget);
1231 g_slist_free (context->rc_sets_widget);
1232 context->rc_sets_widget = NULL;
1234 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1235 g_slist_free (context->rc_sets_widget_class);
1236 context->rc_sets_widget_class = NULL;
1238 gtk_rc_free_rc_sets (context->rc_sets_class);
1239 g_slist_free (context->rc_sets_class);
1240 context->rc_sets_class = NULL;
1243 /* Reset all our widgets. Also, we have to invalidate cached icons in
1244 * icon sets so they get re-rendered.
1247 gtk_rc_reset_widgets (GtkRcContext *context)
1249 GList *list, *toplevels;
1251 _gtk_icon_set_invalidate_caches ();
1253 toplevels = gtk_window_list_toplevels ();
1254 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1256 for (list = toplevels; list; list = list->next)
1258 gtk_widget_reset_rc_styles (list->data);
1259 gtk_widget_unref (list->data);
1261 g_list_free (toplevels);
1265 gtk_rc_clear_realized_style (gpointer key,
1269 GSList *rc_styles = key;
1270 GSList *tmp_list = rc_styles;
1274 GtkRcStyle *rc_style = tmp_list->data;
1276 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1278 tmp_list = tmp_list->next;
1281 g_slist_free (rc_styles);
1285 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1287 GtkRcContext *context;
1288 gchar *new_font_name;
1290 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1292 context = gtk_rc_context_get (settings);
1294 g_object_get (context->settings,
1295 "gtk-font-name", &new_font_name,
1298 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1300 gboolean reset = FALSE;
1301 g_free (context->font_name);
1302 context->font_name = g_strdup (new_font_name);
1304 if (context->default_style)
1306 g_object_unref (G_OBJECT (context->default_style));
1307 context->default_style = NULL;
1311 /* Clear out styles that have been looked up already
1313 if (realized_style_ht)
1315 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1316 g_hash_table_destroy (realized_style_ht);
1317 realized_style_ht = NULL;
1322 gtk_rc_reset_widgets (context);
1325 g_free (new_font_name);
1327 return context->font_name;
1331 * gtk_rc_reparse_all_for_settings:
1332 * @settings: a #GtkSettings
1333 * @force_load: load whether or not anything changed
1335 * If the modification time on any previously read file
1336 * for the given #GtkSettings has changed, discard all style information
1337 * and then reread all previously read RC files.
1339 * Return value: %TRUE if the files were reread.
1342 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1343 gboolean force_load)
1345 gboolean mtime_modified = FALSE;
1348 GtkRcContext *context;
1350 struct stat statbuf;
1352 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1354 context = gtk_rc_context_get (settings);
1358 /* Check through and see if any of the RC's have had their
1359 * mtime modified. If so, reparse everything.
1361 tmp_list = context->rc_files;
1364 rc_file = tmp_list->data;
1366 if (!rc_file->is_string)
1368 if (!lstat (rc_file->name, &statbuf) &&
1369 (statbuf.st_mtime > rc_file->mtime))
1371 mtime_modified = TRUE;
1376 tmp_list = tmp_list->next;
1380 if (force_load || mtime_modified)
1384 _gtk_binding_reset_parsed ();
1385 gtk_rc_clear_styles (context);
1386 g_object_freeze_notify (G_OBJECT (context->settings));
1388 old_files = context->rc_files;
1389 context->rc_files = NULL;
1391 gtk_rc_parse_default_files (context);
1393 tmp_list = old_files;
1396 rc_file = tmp_list->data;
1397 if (rc_file->reload)
1399 if (rc_file->is_string)
1400 gtk_rc_parse_string (rc_file->name);
1402 gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
1405 if (rc_file->canonical_name != rc_file->name)
1406 g_free (rc_file->canonical_name);
1407 g_free (rc_file->name);
1410 tmp_list = tmp_list->next;
1413 g_slist_free (old_files);;
1415 g_free (context->theme_name);
1416 g_free (context->key_theme_name);
1418 g_object_get (context->settings,
1419 "gtk-theme-name", &context->theme_name,
1420 "gtk-key-theme-name", &context->key_theme_name,
1423 if (context->theme_name && context->theme_name[0])
1424 gtk_rc_parse_named (context, context->theme_name, NULL);
1425 if (context->key_theme_name && context->key_theme_name[0])
1426 gtk_rc_parse_named (context, context->key_theme_name, "key");
1428 g_object_thaw_notify (G_OBJECT (context->settings));
1430 gtk_rc_reset_widgets (context);
1433 return mtime_modified;
1437 * gtk_rc_reparse_all:
1439 * If the modification time on any previously read file for the
1440 * default #GtkSettings has changed, discard all style information
1441 * and then reread all previously read RC files.
1443 * Return value: %TRUE if the files were reread.
1446 gtk_rc_reparse_all (void)
1448 return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
1452 gtk_rc_styles_match (GSList *rc_styles,
1456 const gchar *path_reversed)
1463 rc_set = sets->data;
1466 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1467 rc_styles = g_slist_append (rc_styles, rc_set);
1474 rc_set_compare (gconstpointer a, gconstpointer b)
1476 const GtkRcSet *set_a = a;
1477 const GtkRcSet *set_b = b;
1479 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1483 sort_and_dereference_sets (GSList *styles)
1487 /* At this point, the list of sets is ordered by:
1489 * a) 'widget' patterns are earlier than 'widget_class' patterns
1490 * which are ealier than 'class' patterns.
1491 * a) For two matches for class patterns, a match to a child type
1492 * is before a match to a parent type
1493 * c) a match later in the RC file (or in a later RC file) is before a
1494 * match earlier in the RC file.
1496 * With a) taking precedence over b) which takes precendence over c).
1498 * Now sort by priority, which has the highest precendence for sort order
1500 styles = g_slist_sort (styles, rc_set_compare);
1502 /* Make styles->data = styles->data->rc_style
1507 GtkRcSet *set = tmp_list->data;
1508 tmp_list->data = set->rc_style;
1509 tmp_list = tmp_list->next;
1517 * @widget: a #GtkWidget
1519 * Finds all matching RC styles for a given widget,
1520 * composites them together, and then creates a
1521 * #GtkStyle representing the composite appearance.
1522 * (GTK+ actually keeps a cache of previously
1523 * created styles, so a new style may not be
1526 * Returns: the resulting style. No refcount is added
1527 * to the returned style, so if you want to save this
1528 * style around, you should add a reference yourself.
1531 gtk_rc_get_style (GtkWidget *widget)
1533 GtkRcStyle *widget_rc_style;
1534 GSList *rc_styles = NULL;
1535 GtkRcContext *context;
1537 static guint rc_style_key_id = 0;
1539 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1541 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1543 /* We allow the specification of a single rc style to be bound
1544 * tightly to a widget, for application modifications
1546 if (!rc_style_key_id)
1547 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1549 if (context->rc_sets_widget)
1551 gchar *path, *path_reversed;
1554 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1555 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1557 g_free (path_reversed);
1560 if (context->rc_sets_widget_class)
1562 gchar *path, *path_reversed;
1565 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1566 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1568 g_free (path_reversed);
1571 if (context->rc_sets_class)
1575 type = GTK_OBJECT_TYPE (widget);
1579 gchar *path_reversed;
1582 path = gtk_type_name (type);
1583 path_length = strlen (path);
1584 path_reversed = g_strdup (path);
1585 g_strreverse (path_reversed);
1587 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1588 g_free (path_reversed);
1590 type = gtk_type_parent (type);
1594 rc_styles = sort_and_dereference_sets (rc_styles);
1596 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1599 if (widget_rc_style)
1600 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1603 return gtk_rc_init_style (rc_styles);
1606 if (!context->default_style)
1607 context->default_style = gtk_style_new ();
1609 return context->default_style;
1614 * gtk_rc_get_style_by_paths:
1615 * @settings: a #GtkSettings object
1616 * @widget_path: the widget path to use when looking up the style, or %NULL
1617 * @class_path: the class path to use when looking up the style, or %NULL
1618 * @type: a type that will be used along with parent types of this type
1619 * when matching against class styles, or #G_TYPE_NONE
1621 * Creates up a #GtkStyle from styles defined in a RC file by providing
1622 * the raw components used in matching. This function may be useful
1623 * when creating pseudo-widgets that should be themed like widgets but
1624 * don't actually have corresponding GTK+ widgets. An example of this
1625 * would be items inside a GNOME canvas widget.
1627 * The action of gtk_rc_get_style() is similar to:
1628 * <informalexample><programlisting>
1629 * gtk_widget_path (widget, NULL, &path, NULL);
1630 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1631 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1632 * G_OBJECT_TYPE (widget));
1633 * </programlisting></informalexample>
1635 * Return value: A style created by matching with the supplied paths,
1636 * or %NULL if nothing matching was specified and the default style should
1637 * be used. The returned value is owned by GTK+ as part of an internal cache,
1638 * so you must call g_object_ref() on the returned value if you want to
1639 * keep a reference to it.
1642 gtk_rc_get_style_by_paths (GtkSettings *settings,
1643 const char *widget_path,
1644 const char *class_path,
1647 /* We duplicate the code from above to avoid slowing down the above
1648 * by generating paths when we don't need them. I don't know if
1649 * this is really worth it.
1651 GSList *rc_styles = NULL;
1652 GtkRcContext *context;
1654 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1656 context = gtk_rc_context_get (settings);
1658 if (context->rc_sets_widget)
1660 gchar *path_reversed;
1663 path_length = strlen (widget_path);
1664 path_reversed = g_strdup (widget_path);
1665 g_strreverse (path_reversed);
1667 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1668 g_free (path_reversed);
1671 if (context->rc_sets_widget_class)
1673 gchar *path_reversed;
1676 path_length = strlen (class_path);
1677 path_reversed = g_strdup (class_path);
1678 g_strreverse (path_reversed);
1680 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1681 g_free (path_reversed);
1684 if (type != G_TYPE_NONE && context->rc_sets_class)
1689 gchar *path_reversed;
1692 path = g_type_name (type);
1693 path_length = strlen (path);
1694 path_reversed = g_strdup (path);
1695 g_strreverse (path_reversed);
1697 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1698 g_free (path_reversed);
1700 type = g_type_parent (type);
1704 rc_styles = sort_and_dereference_sets (rc_styles);
1707 return gtk_rc_init_style (rc_styles);
1713 gtk_rc_add_rc_sets (GSList *slist,
1714 GtkRcStyle *rc_style,
1715 const gchar *pattern)
1717 GtkRcStyle *new_style;
1721 new_style = gtk_rc_style_new ();
1722 *new_style = *rc_style;
1723 new_style->name = g_strdup (rc_style->name);
1724 if (rc_style->font_desc)
1725 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1727 for (i = 0; i < 5; i++)
1728 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1730 rc_set = g_new (GtkRcSet, 1);
1731 rc_set->pspec = g_pattern_spec_new (pattern);
1732 rc_set->rc_style = rc_style;
1734 return g_slist_prepend (slist, rc_set);
1738 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1739 const gchar *pattern)
1741 GtkRcContext *context;
1743 g_return_if_fail (rc_style != NULL);
1744 g_return_if_fail (pattern != NULL);
1746 context = gtk_rc_context_get (gtk_settings_get_default ());
1748 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1752 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1753 const gchar *pattern)
1755 GtkRcContext *context;
1757 g_return_if_fail (rc_style != NULL);
1758 g_return_if_fail (pattern != NULL);
1760 context = gtk_rc_context_get (gtk_settings_get_default ());
1762 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1766 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1767 const gchar *pattern)
1769 GtkRcContext *context;
1771 g_return_if_fail (rc_style != NULL);
1772 g_return_if_fail (pattern != NULL);
1774 context = gtk_rc_context_get (gtk_settings_get_default ());
1776 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1780 gtk_rc_scanner_new (void)
1782 return g_scanner_new (>k_rc_scanner_config);
1786 gtk_rc_parse_any (GtkRcContext *context,
1787 const gchar *input_name,
1789 const gchar *input_string)
1795 scanner = gtk_rc_scanner_new ();
1799 g_assert (input_string == NULL);
1801 g_scanner_input_file (scanner, input_fd);
1805 g_assert (input_string != NULL);
1807 g_scanner_input_text (scanner, input_string, strlen (input_string));
1809 scanner->input_name = input_name;
1811 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1812 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1817 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1821 guint expected_token;
1823 expected_token = gtk_rc_parse_statement (context, scanner);
1825 if (expected_token != G_TOKEN_NONE)
1832 if (scanner->scope_id == 0)
1834 /* if we are in scope 0, we know the symbol names
1835 * that are associated with certain token values.
1836 * so we look them up to make the error messages
1839 if (expected_token > GTK_RC_TOKEN_INVALID &&
1840 expected_token < GTK_RC_TOKEN_LAST)
1842 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1843 if (symbols[i].token == expected_token)
1844 msg = symbols[i].name;
1846 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1848 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1849 scanner->token < GTK_RC_TOKEN_LAST)
1851 symbol_name = "???";
1852 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1853 if (symbols[i].token == scanner->token)
1854 symbol_name = symbols[i].name;
1857 g_scanner_unexp_token (scanner,
1870 g_scanner_destroy (scanner);
1874 gtk_rc_styles_hash (const GSList *rc_styles)
1881 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1882 rc_styles = rc_styles->next;
1889 gtk_rc_styles_equal (const GSList *a,
1894 if (a->data != b->data)
1904 gtk_rc_style_hash (const gchar *name)
1910 result += (result << 3) + *name++;
1916 gtk_rc_style_equal (const gchar *a,
1919 return (strcmp (a, b) == 0);
1923 gtk_rc_style_find (GtkRcContext *context,
1926 if (context->rc_style_ht)
1927 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
1933 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1937 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1939 style->rc_style = rc_style;
1941 gtk_rc_style_ref (rc_style);
1943 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1948 /* Reuses or frees rc_styles */
1950 gtk_rc_init_style (GSList *rc_styles)
1952 GtkStyle *style = NULL;
1955 g_return_val_if_fail (rc_styles != NULL, NULL);
1957 if (!realized_style_ht)
1958 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1959 (GEqualFunc) gtk_rc_styles_equal);
1961 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1965 GtkRcStyle *base_style = NULL;
1966 GtkRcStyle *proto_style;
1967 GtkRcStyleClass *proto_style_class;
1969 GType rc_style_type = GTK_TYPE_RC_STYLE;
1971 /* Find the the first style where the RC file specified engine "" {}
1972 * or the first derived style and use that to create the
1973 * merged style. If we only have raw GtkRcStyles, use the first
1974 * style to create the merged style.
1976 base_style = rc_styles->data;
1977 tmp_styles = rc_styles;
1980 GtkRcStyle *rc_style = tmp_styles->data;
1982 if (rc_style->engine_specified ||
1983 G_OBJECT_TYPE (rc_style) != rc_style_type)
1985 base_style = rc_style;
1989 tmp_styles = tmp_styles->next;
1992 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1993 proto_style = proto_style_class->create_rc_style (base_style);
1995 tmp_styles = rc_styles;
1998 GtkRcStyle *rc_style = tmp_styles->data;
2001 proto_style_class->merge (proto_style, rc_style);
2003 /* Point from each rc_style to the list of styles */
2004 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2005 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2007 factories = g_slist_copy (rc_style->icon_factories);
2013 while (iter != NULL)
2015 g_object_ref (G_OBJECT (iter->data));
2016 iter = g_slist_next (iter);
2019 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2024 tmp_styles = tmp_styles->next;
2027 for (i = 0; i < 5; i++)
2028 if (proto_style->bg_pixmap_name[i] &&
2029 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2031 g_free (proto_style->bg_pixmap_name[i]);
2032 proto_style->bg_pixmap_name[i] = NULL;
2035 style = gtk_rc_style_to_style (proto_style);
2036 gtk_rc_style_unref (proto_style);
2038 g_hash_table_insert (realized_style_ht, rc_styles, style);
2041 g_slist_free (rc_styles);
2046 /*********************
2047 * Parsing functions *
2048 *********************/
2051 rc_parse_token_or_compound (GScanner *scanner,
2053 GTokenType delimiter)
2055 guint token = g_scanner_get_next_token (scanner);
2057 /* we either scan a single token (skipping comments)
2058 * or a compund statement.
2059 * compunds are enclosed in (), [] or {} braces, we read
2060 * them in via deep recursion.
2067 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2070 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2072 case G_TOKEN_STRING:
2073 string = g_strescape (scanner->value.v_string, NULL);
2074 g_string_append (gstring, " \"");
2075 g_string_append (gstring, string);
2076 g_string_append_c (gstring, '"');
2079 case G_TOKEN_IDENTIFIER:
2080 g_string_append_c (gstring, ' ');
2081 g_string_append (gstring, scanner->value.v_identifier);
2083 case G_TOKEN_COMMENT_SINGLE:
2084 case G_TOKEN_COMMENT_MULTI:
2085 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2086 case G_TOKEN_LEFT_PAREN:
2087 g_string_append_c (gstring, ' ');
2088 g_string_append_c (gstring, token);
2089 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2090 if (token != G_TOKEN_NONE)
2093 case G_TOKEN_LEFT_CURLY:
2094 g_string_append_c (gstring, ' ');
2095 g_string_append_c (gstring, token);
2096 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2097 if (token != G_TOKEN_NONE)
2100 case G_TOKEN_LEFT_BRACE:
2101 g_string_append_c (gstring, ' ');
2102 g_string_append_c (gstring, token);
2103 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2104 if (token != G_TOKEN_NONE)
2108 if (token >= 256 || token < 1)
2109 return delimiter ? delimiter : G_TOKEN_STRING;
2110 g_string_append_c (gstring, ' ');
2111 g_string_append_c (gstring, token);
2112 if (token == delimiter)
2113 return G_TOKEN_NONE;
2117 return G_TOKEN_NONE;
2119 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2123 gtk_rc_parse_assignment (GScanner *scanner,
2124 GtkRcProperty *prop)
2126 gboolean scan_identifier = scanner->config->scan_identifier;
2127 gboolean scan_symbols = scanner->config->scan_symbols;
2128 gboolean identifier_2_string = scanner->config->identifier_2_string;
2129 gboolean char_2_token = scanner->config->char_2_token;
2130 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2131 gboolean numbers_2_int = scanner->config->numbers_2_int;
2132 gboolean negate = FALSE;
2135 /* check that this is an assignment */
2136 if (g_scanner_get_next_token (scanner) != '=')
2139 /* adjust scanner mode */
2140 scanner->config->scan_identifier = TRUE;
2141 scanner->config->scan_symbols = FALSE;
2142 scanner->config->identifier_2_string = FALSE;
2143 scanner->config->char_2_token = TRUE;
2144 scanner->config->scan_identifier_NULL = FALSE;
2145 scanner->config->numbers_2_int = TRUE;
2147 /* record location */
2148 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2150 /* parse optional sign */
2151 if (g_scanner_peek_next_token (scanner) == '-')
2153 g_scanner_get_next_token (scanner); /* eat sign */
2157 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2158 token = g_scanner_peek_next_token (scanner);
2162 g_scanner_get_next_token (scanner);
2163 g_value_init (&prop->value, G_TYPE_LONG);
2164 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2165 token = G_TOKEN_NONE;
2168 g_scanner_get_next_token (scanner);
2169 g_value_init (&prop->value, G_TYPE_DOUBLE);
2170 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2171 token = G_TOKEN_NONE;
2173 case G_TOKEN_STRING:
2174 g_scanner_get_next_token (scanner);
2176 token = G_TOKEN_INT;
2179 g_value_init (&prop->value, G_TYPE_STRING);
2180 g_value_set_string (&prop->value, scanner->value.v_string);
2181 token = G_TOKEN_NONE;
2184 case G_TOKEN_IDENTIFIER:
2185 case G_TOKEN_LEFT_PAREN:
2186 case G_TOKEN_LEFT_CURLY:
2187 case G_TOKEN_LEFT_BRACE:
2190 GString *gstring = g_string_new ("");
2192 token = rc_parse_token_or_compound (scanner, gstring, 0);
2193 if (token == G_TOKEN_NONE)
2195 g_string_append_c (gstring, ' ');
2196 g_value_init (&prop->value, G_TYPE_GSTRING);
2197 g_value_set_static_boxed (&prop->value, gstring);
2200 g_string_free (gstring, TRUE);
2205 g_scanner_get_next_token (scanner);
2206 token = G_TOKEN_INT;
2210 /* restore scanner mode */
2211 scanner->config->scan_identifier = scan_identifier;
2212 scanner->config->scan_symbols = scan_symbols;
2213 scanner->config->identifier_2_string = identifier_2_string;
2214 scanner->config->char_2_token = char_2_token;
2215 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2216 scanner->config->numbers_2_int = numbers_2_int;
2222 is_c_identifier (const gchar *string)
2225 gboolean is_varname;
2227 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2228 for (p = string + 1; *p && is_varname; p++)
2229 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2235 parse_include_file (GtkRcContext *context,
2237 const gchar *filename)
2239 char *to_parse = NULL;
2241 if (g_path_is_absolute (filename))
2243 /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
2244 * don't print an error in this case.
2246 to_parse = g_strdup (filename);
2250 /* if a relative path, we look relative to all the RC files in the
2251 * include stack. We require the file to be found in this case
2252 * so we can give meaningful error messages, and because on reparsing
2253 * non-absolute paths don't make sense.
2255 GSList *tmp_list = rc_dir_stack;
2258 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2260 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2268 tmp_list = tmp_list->next;
2274 gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
2279 g_scanner_warn (scanner,
2280 _("Unable to find include file: \"%s\""),
2287 gtk_rc_parse_statement (GtkRcContext *context,
2292 token = g_scanner_peek_next_token (scanner);
2295 case GTK_RC_TOKEN_INCLUDE:
2296 token = g_scanner_get_next_token (scanner);
2297 if (token != GTK_RC_TOKEN_INCLUDE)
2298 return GTK_RC_TOKEN_INCLUDE;
2299 token = g_scanner_get_next_token (scanner);
2300 if (token != G_TOKEN_STRING)
2301 return G_TOKEN_STRING;
2302 parse_include_file (context, scanner, scanner->value.v_string);
2303 return G_TOKEN_NONE;
2305 case GTK_RC_TOKEN_STYLE:
2306 return gtk_rc_parse_style (context, scanner);
2308 case GTK_RC_TOKEN_BINDING:
2309 return gtk_binding_parse_binding (scanner);
2311 case GTK_RC_TOKEN_PIXMAP_PATH:
2312 return gtk_rc_parse_pixmap_path (context, scanner);
2314 case GTK_RC_TOKEN_WIDGET:
2315 return gtk_rc_parse_path_pattern (context, scanner);
2317 case GTK_RC_TOKEN_WIDGET_CLASS:
2318 return gtk_rc_parse_path_pattern (context, scanner);
2320 case GTK_RC_TOKEN_CLASS:
2321 return gtk_rc_parse_path_pattern (context, scanner);
2323 case GTK_RC_TOKEN_MODULE_PATH:
2324 return gtk_rc_parse_module_path (scanner);
2326 case GTK_RC_TOKEN_IM_MODULE_FILE:
2327 return gtk_rc_parse_im_module_file (scanner);
2329 case G_TOKEN_IDENTIFIER:
2330 if (is_c_identifier (scanner->next_value.v_identifier))
2332 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2335 g_scanner_get_next_token (scanner); /* eat identifier */
2336 name = g_strdup (scanner->value.v_identifier);
2338 token = gtk_rc_parse_assignment (scanner, &prop);
2339 if (token == G_TOKEN_NONE)
2341 GtkSettingsValue svalue;
2343 svalue.origin = prop.origin;
2344 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2345 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2346 gtk_settings_set_property_value (context->settings,
2350 g_free (prop.origin);
2351 if (G_VALUE_TYPE (&prop.value))
2352 g_value_unset (&prop.value);
2359 g_scanner_get_next_token (scanner);
2360 return G_TOKEN_IDENTIFIER;
2363 g_scanner_get_next_token (scanner);
2364 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2369 fixup_rc_set (GSList *list,
2375 GtkRcSet *set = list->data;
2376 if (set->rc_style == orig)
2377 set->rc_style = new;
2383 fixup_rc_sets (GtkRcContext *context,
2387 fixup_rc_set (context->rc_sets_widget, orig, new);
2388 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2389 fixup_rc_set (context->rc_sets_class, orig, new);
2393 gtk_rc_parse_style (GtkRcContext *context,
2396 GtkRcStyle *rc_style;
2397 GtkRcStyle *orig_style;
2398 GtkRcStyle *parent_style;
2401 GtkIconFactory *our_factory = NULL;
2403 token = g_scanner_get_next_token (scanner);
2404 if (token != GTK_RC_TOKEN_STYLE)
2405 return GTK_RC_TOKEN_STYLE;
2407 token = g_scanner_get_next_token (scanner);
2408 if (token != G_TOKEN_STRING)
2409 return G_TOKEN_STRING;
2411 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2413 orig_style = g_object_ref (rc_style);
2417 /* If there's a list, its first member is always the factory belonging
2420 if (rc_style && rc_style->icon_factories)
2421 our_factory = rc_style->icon_factories->data;
2425 rc_style = gtk_rc_style_new ();
2426 rc_style->name = g_strdup (scanner->value.v_string);
2428 for (i = 0; i < 5; i++)
2429 rc_style->bg_pixmap_name[i] = NULL;
2431 for (i = 0; i < 5; i++)
2432 rc_style->color_flags[i] = 0;
2435 token = g_scanner_peek_next_token (scanner);
2436 if (token == G_TOKEN_EQUAL_SIGN)
2438 token = g_scanner_get_next_token (scanner);
2440 token = g_scanner_get_next_token (scanner);
2441 if (token != G_TOKEN_STRING)
2443 token = G_TOKEN_STRING;
2447 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2452 for (i = 0; i < 5; i++)
2454 rc_style->color_flags[i] = parent_style->color_flags[i];
2455 rc_style->fg[i] = parent_style->fg[i];
2456 rc_style->bg[i] = parent_style->bg[i];
2457 rc_style->text[i] = parent_style->text[i];
2458 rc_style->base[i] = parent_style->base[i];
2461 rc_style->xthickness = parent_style->xthickness;
2462 rc_style->ythickness = parent_style->ythickness;
2464 if (parent_style->font_desc)
2466 if (rc_style->font_desc)
2467 pango_font_description_free (rc_style->font_desc);
2468 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2471 if (parent_style->rc_properties)
2475 for (i = 0; i < parent_style->rc_properties->len; i++)
2476 insert_rc_property (rc_style,
2477 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2481 for (i = 0; i < 5; i++)
2483 if (rc_style->bg_pixmap_name[i])
2484 g_free (rc_style->bg_pixmap_name[i]);
2485 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2488 /* Append parent's factories, adding a ref to them */
2489 if (parent_style->icon_factories != NULL)
2491 /* Add a factory for ourselves if we have none,
2492 * in case we end up defining more stock icons.
2493 * I see no real way around this; we need to maintain
2494 * the invariant that the first factory in the list
2495 * is always our_factory, the one belonging to us,
2496 * and if we put parent factories in the list we can't
2497 * do that if the style is reopened.
2499 if (our_factory == NULL)
2501 our_factory = gtk_icon_factory_new ();
2502 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2506 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2507 g_slist_copy (parent_style->icon_factories));
2509 factories = parent_style->icon_factories;
2510 while (factories != NULL)
2512 g_object_ref (G_OBJECT (factories->data));
2513 factories = factories->next;
2519 token = g_scanner_get_next_token (scanner);
2520 if (token != G_TOKEN_LEFT_CURLY)
2522 token = G_TOKEN_LEFT_CURLY;
2526 token = g_scanner_peek_next_token (scanner);
2527 while (token != G_TOKEN_RIGHT_CURLY)
2531 case GTK_RC_TOKEN_BG:
2532 token = gtk_rc_parse_bg (scanner, rc_style);
2534 case GTK_RC_TOKEN_FG:
2535 token = gtk_rc_parse_fg (scanner, rc_style);
2537 case GTK_RC_TOKEN_TEXT:
2538 token = gtk_rc_parse_text (scanner, rc_style);
2540 case GTK_RC_TOKEN_BASE:
2541 token = gtk_rc_parse_base (scanner, rc_style);
2543 case GTK_RC_TOKEN_XTHICKNESS:
2544 token = gtk_rc_parse_xthickness (scanner, rc_style);
2546 case GTK_RC_TOKEN_YTHICKNESS:
2547 token = gtk_rc_parse_ythickness (scanner, rc_style);
2549 case GTK_RC_TOKEN_BG_PIXMAP:
2550 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2552 case GTK_RC_TOKEN_FONT:
2553 token = gtk_rc_parse_font (scanner, rc_style);
2555 case GTK_RC_TOKEN_FONTSET:
2556 token = gtk_rc_parse_fontset (scanner, rc_style);
2558 case GTK_RC_TOKEN_FONT_NAME:
2559 token = gtk_rc_parse_font_name (scanner, rc_style);
2561 case GTK_RC_TOKEN_ENGINE:
2562 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2564 case GTK_RC_TOKEN_STOCK:
2565 if (our_factory == NULL)
2567 our_factory = gtk_icon_factory_new ();
2568 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2571 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2573 case G_TOKEN_IDENTIFIER:
2574 if (is_c_identifier (scanner->next_value.v_identifier) &&
2575 scanner->next_value.v_identifier[0] >= 'A' &&
2576 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2578 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2580 g_scanner_get_next_token (scanner); /* eat type name */
2581 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2582 if (g_scanner_get_next_token (scanner) != ':' ||
2583 g_scanner_get_next_token (scanner) != ':')
2588 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2589 !is_c_identifier (scanner->value.v_identifier))
2591 token = G_TOKEN_IDENTIFIER;
2595 /* it's important that we do the same canonification as GParamSpecPool here */
2596 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2597 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2599 token = gtk_rc_parse_assignment (scanner, &prop);
2600 if (token == G_TOKEN_NONE)
2602 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2603 insert_rc_property (rc_style, &prop, TRUE);
2606 g_free (prop.origin);
2607 if (G_VALUE_TYPE (&prop.value))
2608 g_value_unset (&prop.value);
2612 g_scanner_get_next_token (scanner);
2613 token = G_TOKEN_IDENTIFIER;
2617 g_scanner_get_next_token (scanner);
2618 token = G_TOKEN_RIGHT_CURLY;
2622 if (token != G_TOKEN_NONE)
2625 token = g_scanner_peek_next_token (scanner);
2626 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2628 token = g_scanner_get_next_token (scanner);
2629 if (token != G_TOKEN_RIGHT_CURLY)
2631 token = G_TOKEN_RIGHT_CURLY;
2635 if (rc_style != orig_style)
2637 if (!context->rc_style_ht)
2638 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2639 (GEqualFunc) gtk_rc_style_equal);
2641 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2643 /* If we copied the data into a new rc style, fix up references to the old rc style
2644 * in bindings that we have.
2647 fixup_rc_sets (context, orig_style, rc_style);
2651 g_object_unref (orig_style);
2653 return G_TOKEN_NONE;
2656 if (rc_style != orig_style)
2657 gtk_rc_style_unref (rc_style);
2660 g_object_unref (orig_style);
2665 const GtkRcProperty*
2666 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2668 GQuark property_name)
2670 GtkRcProperty *node = NULL;
2672 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2674 if (rc_style->rc_properties)
2678 key.type_name = type_name;
2679 key.property_name = property_name;
2681 node = bsearch (&key,
2682 rc_style->rc_properties->data, rc_style->rc_properties->len,
2683 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2690 gtk_rc_parse_bg (GScanner *scanner,
2696 token = g_scanner_get_next_token (scanner);
2697 if (token != GTK_RC_TOKEN_BG)
2698 return GTK_RC_TOKEN_BG;
2700 token = gtk_rc_parse_state (scanner, &state);
2701 if (token != G_TOKEN_NONE)
2704 token = g_scanner_get_next_token (scanner);
2705 if (token != G_TOKEN_EQUAL_SIGN)
2706 return G_TOKEN_EQUAL_SIGN;
2708 style->color_flags[state] |= GTK_RC_BG;
2709 return gtk_rc_parse_color (scanner, &style->bg[state]);
2713 gtk_rc_parse_fg (GScanner *scanner,
2719 token = g_scanner_get_next_token (scanner);
2720 if (token != GTK_RC_TOKEN_FG)
2721 return GTK_RC_TOKEN_FG;
2723 token = gtk_rc_parse_state (scanner, &state);
2724 if (token != G_TOKEN_NONE)
2727 token = g_scanner_get_next_token (scanner);
2728 if (token != G_TOKEN_EQUAL_SIGN)
2729 return G_TOKEN_EQUAL_SIGN;
2731 style->color_flags[state] |= GTK_RC_FG;
2732 return gtk_rc_parse_color (scanner, &style->fg[state]);
2736 gtk_rc_parse_text (GScanner *scanner,
2742 token = g_scanner_get_next_token (scanner);
2743 if (token != GTK_RC_TOKEN_TEXT)
2744 return GTK_RC_TOKEN_TEXT;
2746 token = gtk_rc_parse_state (scanner, &state);
2747 if (token != G_TOKEN_NONE)
2750 token = g_scanner_get_next_token (scanner);
2751 if (token != G_TOKEN_EQUAL_SIGN)
2752 return G_TOKEN_EQUAL_SIGN;
2754 style->color_flags[state] |= GTK_RC_TEXT;
2755 return gtk_rc_parse_color (scanner, &style->text[state]);
2759 gtk_rc_parse_base (GScanner *scanner,
2765 token = g_scanner_get_next_token (scanner);
2766 if (token != GTK_RC_TOKEN_BASE)
2767 return GTK_RC_TOKEN_BASE;
2769 token = gtk_rc_parse_state (scanner, &state);
2770 if (token != G_TOKEN_NONE)
2773 token = g_scanner_get_next_token (scanner);
2774 if (token != G_TOKEN_EQUAL_SIGN)
2775 return G_TOKEN_EQUAL_SIGN;
2777 style->color_flags[state] |= GTK_RC_BASE;
2778 return gtk_rc_parse_color (scanner, &style->base[state]);
2782 gtk_rc_parse_xthickness (GScanner *scanner,
2785 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2786 return GTK_RC_TOKEN_XTHICKNESS;
2788 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2789 return G_TOKEN_EQUAL_SIGN;
2791 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2794 style->xthickness = scanner->value.v_int;
2796 return G_TOKEN_NONE;
2800 gtk_rc_parse_ythickness (GScanner *scanner,
2803 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2804 return GTK_RC_TOKEN_YTHICKNESS;
2806 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2807 return G_TOKEN_EQUAL_SIGN;
2809 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2812 style->ythickness = scanner->value.v_int;
2814 return G_TOKEN_NONE;
2818 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2820 GtkRcStyle *rc_style)
2826 token = g_scanner_get_next_token (scanner);
2827 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2828 return GTK_RC_TOKEN_BG_PIXMAP;
2830 token = gtk_rc_parse_state (scanner, &state);
2831 if (token != G_TOKEN_NONE)
2834 token = g_scanner_get_next_token (scanner);
2835 if (token != G_TOKEN_EQUAL_SIGN)
2836 return G_TOKEN_EQUAL_SIGN;
2838 token = g_scanner_get_next_token (scanner);
2839 if (token != G_TOKEN_STRING)
2840 return G_TOKEN_STRING;
2842 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2843 (strcmp (scanner->value.v_string, "<none>") == 0))
2844 pixmap_file = g_strdup (scanner->value.v_string);
2846 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2847 scanner, scanner->value.v_string);
2851 if (rc_style->bg_pixmap_name[state])
2852 g_free (rc_style->bg_pixmap_name[state]);
2853 rc_style->bg_pixmap_name[state] = pixmap_file;
2856 return G_TOKEN_NONE;
2860 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2865 buf = g_build_filename (dir, pixmap_file, NULL);
2867 fd = open (buf, O_RDONLY);
2880 * gtk_rc_find_pixmap_in_path:
2881 * @settings: a #GtkSettings
2882 * @scanner: Scanner used to get line number information for the
2883 * warning message, or %NULL
2884 * @pixmap_file: name of the pixmap file to locate.
2886 * Looks up a file in pixmap path for the specified #GtkSettings.
2887 * If the file is not found, it outputs a warning message using
2888 * g_warning() and returns %NULL.
2890 * Return value: the filename.
2893 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2895 const gchar *pixmap_file)
2901 GtkRcContext *context = gtk_rc_context_get (settings);
2903 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2905 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2910 tmp_list = rc_dir_stack;
2913 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2917 tmp_list = tmp_list->next;
2921 g_scanner_warn (scanner,
2922 _("Unable to locate image file in pixmap_path: \"%s\""),
2925 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2932 * gtk_rc_find_module_in_path:
2933 * @module_file: name of a theme engine
2935 * Searches for a theme engine in the GTK+ search path. This function
2936 * is not useful for applications and should not be used.
2938 * Return value: The filename, if found (must be freed with g_free()),
2942 gtk_rc_find_module_in_path (const gchar *module_file)
2944 return _gtk_find_module (module_file, "engines");
2948 gtk_rc_parse_font (GScanner *scanner,
2949 GtkRcStyle *rc_style)
2953 token = g_scanner_get_next_token (scanner);
2954 if (token != GTK_RC_TOKEN_FONT)
2955 return GTK_RC_TOKEN_FONT;
2957 token = g_scanner_get_next_token (scanner);
2958 if (token != G_TOKEN_EQUAL_SIGN)
2959 return G_TOKEN_EQUAL_SIGN;
2961 token = g_scanner_get_next_token (scanner);
2962 if (token != G_TOKEN_STRING)
2963 return G_TOKEN_STRING;
2965 /* Ignore, do nothing */
2967 return G_TOKEN_NONE;
2971 gtk_rc_parse_fontset (GScanner *scanner,
2972 GtkRcStyle *rc_style)
2976 token = g_scanner_get_next_token (scanner);
2977 if (token != GTK_RC_TOKEN_FONTSET)
2978 return GTK_RC_TOKEN_FONTSET;
2980 token = g_scanner_get_next_token (scanner);
2981 if (token != G_TOKEN_EQUAL_SIGN)
2982 return G_TOKEN_EQUAL_SIGN;
2984 token = g_scanner_get_next_token (scanner);
2985 if (token != G_TOKEN_STRING)
2986 return G_TOKEN_STRING;
2988 /* Do nothing - silently ignore */
2990 return G_TOKEN_NONE;
2994 gtk_rc_parse_font_name (GScanner *scanner,
2995 GtkRcStyle *rc_style)
2999 token = g_scanner_get_next_token (scanner);
3000 if (token != GTK_RC_TOKEN_FONT_NAME)
3001 return GTK_RC_TOKEN_FONT;
3003 token = g_scanner_get_next_token (scanner);
3004 if (token != G_TOKEN_EQUAL_SIGN)
3005 return G_TOKEN_EQUAL_SIGN;
3007 token = g_scanner_get_next_token (scanner);
3008 if (token != G_TOKEN_STRING)
3009 return G_TOKEN_STRING;
3011 if (rc_style->font_desc)
3012 pango_font_description_free (rc_style->font_desc);
3014 rc_style->font_desc =
3015 pango_font_description_from_string (scanner->value.v_string);
3017 return G_TOKEN_NONE;
3021 gtk_rc_parse_engine (GtkRcContext *context,
3023 GtkRcStyle **rc_style)
3026 GtkThemeEngine *engine;
3027 guint result = G_TOKEN_NONE;
3028 GtkRcStyle *new_style = NULL;
3029 gboolean parsed_curlies = FALSE;
3031 token = g_scanner_get_next_token (scanner);
3032 if (token != GTK_RC_TOKEN_ENGINE)
3033 return GTK_RC_TOKEN_ENGINE;
3035 token = g_scanner_get_next_token (scanner);
3036 if (token != G_TOKEN_STRING)
3037 return G_TOKEN_STRING;
3039 if (!scanner->value.v_string[0])
3041 /* Support engine "" {} to mean override to the default engine
3043 token = g_scanner_get_next_token (scanner);
3044 if (token != G_TOKEN_LEFT_CURLY)
3045 return G_TOKEN_LEFT_CURLY;
3047 token = g_scanner_get_next_token (scanner);
3048 if (token != G_TOKEN_RIGHT_CURLY)
3049 return G_TOKEN_RIGHT_CURLY;
3051 parsed_curlies = TRUE;
3053 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3055 new_style = gtk_rc_style_new ();
3056 gtk_rc_style_real_merge (new_style, *rc_style);
3058 if ((*rc_style)->name)
3059 new_style->name = g_strdup ((*rc_style)->name);
3062 (*rc_style)->engine_specified = TRUE;
3066 engine = gtk_theme_engine_get (scanner->value.v_string);
3068 token = g_scanner_get_next_token (scanner);
3069 if (token != G_TOKEN_LEFT_CURLY)
3070 return G_TOKEN_LEFT_CURLY;
3074 GtkRcStyleClass *new_class;
3076 new_style = gtk_theme_engine_create_rc_style (engine);
3077 g_type_module_unuse (G_TYPE_MODULE (engine));
3079 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3081 new_class->merge (new_style, *rc_style);
3082 if ((*rc_style)->name)
3083 new_style->name = g_strdup ((*rc_style)->name);
3085 if (new_class->parse)
3087 parsed_curlies = TRUE;
3088 result = new_class->parse (new_style, context->settings, scanner);
3090 if (result != G_TOKEN_NONE)
3092 g_object_unref (G_OBJECT (new_style));
3099 if (!parsed_curlies)
3101 /* Skip over remainder, looking for nested {}'s
3105 result = G_TOKEN_RIGHT_CURLY;
3106 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3108 if (token == G_TOKEN_LEFT_CURLY)
3110 else if (token == G_TOKEN_RIGHT_CURLY)
3115 result = G_TOKEN_NONE;
3123 new_style->engine_specified = TRUE;
3125 g_object_unref (G_OBJECT (*rc_style));
3126 *rc_style = new_style;
3133 gtk_rc_parse_state (GScanner *scanner,
3134 GtkStateType *state)
3139 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3140 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3142 /* we don't know where we got called from, so we reset the scope here.
3143 * if we bail out due to errors, we *don't* reset the scope, so the
3144 * error messaging code can make sense of our tokens.
3146 old_scope = g_scanner_set_scope (scanner, 0);
3148 token = g_scanner_get_next_token (scanner);
3149 if (token != G_TOKEN_LEFT_BRACE)
3150 return G_TOKEN_LEFT_BRACE;
3152 token = g_scanner_get_next_token (scanner);
3155 case GTK_RC_TOKEN_ACTIVE:
3156 *state = GTK_STATE_ACTIVE;
3158 case GTK_RC_TOKEN_INSENSITIVE:
3159 *state = GTK_STATE_INSENSITIVE;
3161 case GTK_RC_TOKEN_NORMAL:
3162 *state = GTK_STATE_NORMAL;
3164 case GTK_RC_TOKEN_PRELIGHT:
3165 *state = GTK_STATE_PRELIGHT;
3167 case GTK_RC_TOKEN_SELECTED:
3168 *state = GTK_STATE_SELECTED;
3171 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3174 token = g_scanner_get_next_token (scanner);
3175 if (token != G_TOKEN_RIGHT_BRACE)
3176 return G_TOKEN_RIGHT_BRACE;
3178 g_scanner_set_scope (scanner, old_scope);
3180 return G_TOKEN_NONE;
3184 gtk_rc_parse_priority (GScanner *scanner,
3185 GtkPathPriorityType *priority)
3190 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3191 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3193 /* we don't know where we got called from, so we reset the scope here.
3194 * if we bail out due to errors, we *don't* reset the scope, so the
3195 * error messaging code can make sense of our tokens.
3197 old_scope = g_scanner_set_scope (scanner, 0);
3199 token = g_scanner_get_next_token (scanner);
3203 token = g_scanner_get_next_token (scanner);
3206 case GTK_RC_TOKEN_LOWEST:
3207 *priority = GTK_PATH_PRIO_LOWEST;
3209 case GTK_RC_TOKEN_GTK:
3210 *priority = GTK_PATH_PRIO_GTK;
3212 case GTK_RC_TOKEN_APPLICATION:
3213 *priority = GTK_PATH_PRIO_APPLICATION;
3215 case GTK_RC_TOKEN_THEME:
3216 *priority = GTK_PATH_PRIO_THEME;
3218 case GTK_RC_TOKEN_RC:
3219 *priority = GTK_PATH_PRIO_RC;
3221 case GTK_RC_TOKEN_HIGHEST:
3222 *priority = GTK_PATH_PRIO_HIGHEST;
3225 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3228 g_scanner_set_scope (scanner, old_scope);
3230 return G_TOKEN_NONE;
3234 gtk_rc_parse_color (GScanner *scanner,
3239 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3241 /* we don't need to set our own scope here, because
3242 * we don't need own symbols
3245 token = g_scanner_get_next_token (scanner);
3250 case G_TOKEN_LEFT_CURLY:
3251 token = g_scanner_get_next_token (scanner);
3252 if (token == G_TOKEN_INT)
3253 token_int = scanner->value.v_int;
3254 else if (token == G_TOKEN_FLOAT)
3255 token_int = scanner->value.v_float * 65535.0;
3257 return G_TOKEN_FLOAT;
3258 color->red = CLAMP (token_int, 0, 65535);
3260 token = g_scanner_get_next_token (scanner);
3261 if (token != G_TOKEN_COMMA)
3262 return G_TOKEN_COMMA;
3264 token = g_scanner_get_next_token (scanner);
3265 if (token == G_TOKEN_INT)
3266 token_int = scanner->value.v_int;
3267 else if (token == G_TOKEN_FLOAT)
3268 token_int = scanner->value.v_float * 65535.0;
3270 return G_TOKEN_FLOAT;
3271 color->green = CLAMP (token_int, 0, 65535);
3273 token = g_scanner_get_next_token (scanner);
3274 if (token != G_TOKEN_COMMA)
3275 return G_TOKEN_COMMA;
3277 token = g_scanner_get_next_token (scanner);
3278 if (token == G_TOKEN_INT)
3279 token_int = scanner->value.v_int;
3280 else if (token == G_TOKEN_FLOAT)
3281 token_int = scanner->value.v_float * 65535.0;
3283 return G_TOKEN_FLOAT;
3284 color->blue = CLAMP (token_int, 0, 65535);
3286 token = g_scanner_get_next_token (scanner);
3287 if (token != G_TOKEN_RIGHT_CURLY)
3288 return G_TOKEN_RIGHT_CURLY;
3289 return G_TOKEN_NONE;
3291 case G_TOKEN_STRING:
3292 if (!gdk_color_parse (scanner->value.v_string, color))
3294 g_scanner_warn (scanner, "Invalid color constant '%s'",
3295 scanner->value.v_string);
3296 return G_TOKEN_STRING;
3299 return G_TOKEN_NONE;
3302 return G_TOKEN_STRING;
3307 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3312 token = g_scanner_get_next_token (scanner);
3313 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3314 return GTK_RC_TOKEN_PIXMAP_PATH;
3316 token = g_scanner_get_next_token (scanner);
3317 if (token != G_TOKEN_STRING)
3318 return G_TOKEN_STRING;
3320 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3322 return G_TOKEN_NONE;
3326 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3328 const gchar *pix_path)
3331 gint start_offset = 0;
3335 /* free the old one, or just add to the old one ? */
3336 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3338 g_free (context->pixmap_path[path_num]);
3339 context->pixmap_path[path_num] = NULL;
3344 path_len = strlen (pix_path);
3346 for (end_offset = 0; end_offset <= path_len; end_offset++)
3348 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3349 (end_offset == path_len))
3351 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3352 if (g_path_is_absolute (path_element))
3354 context->pixmap_path[path_num] = path_element;
3356 context->pixmap_path[path_num] = NULL;
3360 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3361 path_element, scanner->input_name, scanner->line);
3362 g_free (path_element);
3365 start_offset = end_offset + 1;
3371 gtk_rc_parse_module_path (GScanner *scanner)
3375 token = g_scanner_get_next_token (scanner);
3376 if (token != GTK_RC_TOKEN_MODULE_PATH)
3377 return GTK_RC_TOKEN_MODULE_PATH;
3379 token = g_scanner_get_next_token (scanner);
3380 if (token != G_TOKEN_STRING)
3381 return G_TOKEN_STRING;
3383 g_warning ("module_path directive is now ignored\n");
3385 return G_TOKEN_NONE;
3389 gtk_rc_parse_im_module_file (GScanner *scanner)
3393 token = g_scanner_get_next_token (scanner);
3394 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3395 return GTK_RC_TOKEN_IM_MODULE_FILE;
3397 token = g_scanner_get_next_token (scanner);
3398 if (token != G_TOKEN_STRING)
3399 return G_TOKEN_STRING;
3402 g_free (im_module_file);
3404 im_module_file = g_strdup (scanner->value.v_string);
3406 return G_TOKEN_NONE;
3410 gtk_rc_parse_path_pattern (GtkRcContext *context,
3414 GtkPathType path_type;
3416 gboolean is_binding;
3417 GtkPathPriorityType priority = context->default_priority;
3419 token = g_scanner_get_next_token (scanner);
3422 case GTK_RC_TOKEN_WIDGET:
3423 path_type = GTK_PATH_WIDGET;
3425 case GTK_RC_TOKEN_WIDGET_CLASS:
3426 path_type = GTK_PATH_WIDGET_CLASS;
3428 case GTK_RC_TOKEN_CLASS:
3429 path_type = GTK_PATH_CLASS;
3432 return GTK_RC_TOKEN_WIDGET_CLASS;
3435 token = g_scanner_get_next_token (scanner);
3436 if (token != G_TOKEN_STRING)
3437 return G_TOKEN_STRING;
3439 pattern = g_strdup (scanner->value.v_string);
3441 token = g_scanner_get_next_token (scanner);
3442 if (token == GTK_RC_TOKEN_STYLE)
3444 else if (token == GTK_RC_TOKEN_BINDING)
3449 return GTK_RC_TOKEN_STYLE;
3452 if (g_scanner_peek_next_token (scanner) == ':')
3454 token = gtk_rc_parse_priority (scanner, &priority);
3455 if (token != G_TOKEN_NONE)
3462 token = g_scanner_get_next_token (scanner);
3463 if (token != G_TOKEN_STRING)
3466 return G_TOKEN_STRING;
3471 GtkBindingSet *binding;
3473 binding = gtk_binding_set_find (scanner->value.v_string);
3477 return G_TOKEN_STRING;
3479 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3483 GtkRcStyle *rc_style;
3486 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3491 return G_TOKEN_STRING;
3494 rc_set = g_new (GtkRcSet, 1);
3495 rc_set->pspec = g_pattern_spec_new (pattern);
3496 rc_set->rc_style = rc_style;
3497 rc_set->priority = priority;
3499 if (path_type == GTK_PATH_WIDGET)
3500 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3501 else if (path_type == GTK_PATH_WIDGET_CLASS)
3502 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3504 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3508 return G_TOKEN_NONE;
3512 gtk_rc_parse_stock_id (GScanner *scanner,
3517 token = g_scanner_get_next_token (scanner);
3518 if (token != G_TOKEN_LEFT_BRACE)
3519 return G_TOKEN_LEFT_BRACE;
3521 token = g_scanner_get_next_token (scanner);
3523 if (token != G_TOKEN_STRING)
3524 return G_TOKEN_STRING;
3526 *stock_id = g_strdup (scanner->value.v_string);
3528 token = g_scanner_get_next_token (scanner);
3529 if (token != G_TOKEN_RIGHT_BRACE)
3532 return G_TOKEN_RIGHT_BRACE;
3535 return G_TOKEN_NONE;
3539 gtk_rc_parse_icon_source (GtkRcContext *context,
3541 GtkIconSet *icon_set,
3542 gboolean *icon_set_valid)
3545 GtkIconSource *source;
3546 gchar *full_filename;
3548 token = g_scanner_get_next_token (scanner);
3549 if (token != G_TOKEN_LEFT_CURLY)
3550 return G_TOKEN_LEFT_CURLY;
3552 token = g_scanner_get_next_token (scanner);
3554 if (token != G_TOKEN_STRING)
3555 return G_TOKEN_STRING;
3558 source = gtk_icon_source_new ();
3560 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3563 gtk_icon_source_set_filename (source, full_filename);
3564 g_free (full_filename);
3567 /* We continue parsing even if we didn't find the pixmap so that rest of the
3568 * file is read, even if the syntax is bad. However we don't validate the
3569 * icon_set so the caller can choose not to install it.
3571 token = g_scanner_get_next_token (scanner);
3573 if (token == G_TOKEN_RIGHT_CURLY)
3575 else if (token != G_TOKEN_COMMA)
3577 gtk_icon_source_free (source);
3578 return G_TOKEN_COMMA;
3581 /* Get the direction */
3583 token = g_scanner_get_next_token (scanner);
3587 case GTK_RC_TOKEN_RTL:
3588 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3589 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3592 case GTK_RC_TOKEN_LTR:
3593 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3594 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3601 gtk_icon_source_free (source);
3602 return GTK_RC_TOKEN_RTL;
3606 token = g_scanner_get_next_token (scanner);
3608 if (token == G_TOKEN_RIGHT_CURLY)
3610 else if (token != G_TOKEN_COMMA)
3612 gtk_icon_source_free (source);
3613 return G_TOKEN_COMMA;
3618 token = g_scanner_get_next_token (scanner);
3622 case GTK_RC_TOKEN_NORMAL:
3623 gtk_icon_source_set_state_wildcarded (source, FALSE);
3624 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3627 case GTK_RC_TOKEN_PRELIGHT:
3628 gtk_icon_source_set_state_wildcarded (source, FALSE);
3629 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3633 case GTK_RC_TOKEN_INSENSITIVE:
3634 gtk_icon_source_set_state_wildcarded (source, FALSE);
3635 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3638 case GTK_RC_TOKEN_ACTIVE:
3639 gtk_icon_source_set_state_wildcarded (source, FALSE);
3640 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3643 case GTK_RC_TOKEN_SELECTED:
3644 gtk_icon_source_set_state_wildcarded (source, FALSE);
3645 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3652 gtk_icon_source_free (source);
3653 return GTK_RC_TOKEN_PRELIGHT;
3657 token = g_scanner_get_next_token (scanner);
3659 if (token == G_TOKEN_RIGHT_CURLY)
3661 else if (token != G_TOKEN_COMMA)
3663 gtk_icon_source_free (source);
3664 return G_TOKEN_COMMA;
3669 token = g_scanner_get_next_token (scanner);
3675 if (token != G_TOKEN_STRING)
3677 gtk_icon_source_free (source);
3678 return G_TOKEN_STRING;
3681 size = gtk_icon_size_from_name (scanner->value.v_string);
3683 if (size != GTK_ICON_SIZE_INVALID)
3685 gtk_icon_source_set_size_wildcarded (source, FALSE);
3686 gtk_icon_source_set_size (source, size);
3690 /* Check the close brace */
3692 token = g_scanner_get_next_token (scanner);
3693 if (token != G_TOKEN_RIGHT_CURLY)
3695 gtk_icon_source_free (source);
3696 return G_TOKEN_RIGHT_CURLY;
3700 if (gtk_icon_source_get_filename (source))
3702 gtk_icon_set_add_source (icon_set, source);
3703 *icon_set_valid = TRUE;
3705 gtk_icon_source_free (source);
3707 return G_TOKEN_NONE;
3711 gtk_rc_parse_stock (GtkRcContext *context,
3713 GtkRcStyle *rc_style,
3714 GtkIconFactory *factory)
3716 GtkIconSet *icon_set = NULL;
3717 gboolean icon_set_valid = FALSE;
3718 gchar *stock_id = NULL;
3721 token = g_scanner_get_next_token (scanner);
3722 if (token != GTK_RC_TOKEN_STOCK)
3723 return GTK_RC_TOKEN_STOCK;
3725 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3726 if (token != G_TOKEN_NONE)
3729 token = g_scanner_get_next_token (scanner);
3730 if (token != G_TOKEN_EQUAL_SIGN)
3733 return G_TOKEN_EQUAL_SIGN;
3736 token = g_scanner_get_next_token (scanner);
3737 if (token != G_TOKEN_LEFT_CURLY)
3740 return G_TOKEN_LEFT_CURLY;
3743 token = g_scanner_peek_next_token (scanner);
3744 while (token != G_TOKEN_RIGHT_CURLY)
3746 if (icon_set == NULL)
3747 icon_set = gtk_icon_set_new ();
3749 token = gtk_rc_parse_icon_source (context,
3750 scanner, icon_set, &icon_set_valid);
3751 if (token != G_TOKEN_NONE)
3754 gtk_icon_set_unref (icon_set);
3758 token = g_scanner_get_next_token (scanner);
3760 if (token != G_TOKEN_COMMA &&
3761 token != G_TOKEN_RIGHT_CURLY)
3764 gtk_icon_set_unref (icon_set);
3765 return G_TOKEN_RIGHT_CURLY;
3772 gtk_icon_factory_add (factory,
3776 gtk_icon_set_unref (icon_set);
3781 return G_TOKEN_NONE;