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>
44 #include <glib/gstdio.h>
45 #include "gdkconfig.h"
47 #include "gtkversion.h"
49 #include "gtkbindings.h"
50 #include "gtkthemes.h"
52 #include "gtkiconfactory.h"
54 #include "gtkmodules.h"
55 #include "gtkprivate.h"
56 #include "gtksettings.h"
57 #include "gtkwindow.h"
65 typedef struct _GtkRcSet GtkRcSet;
66 typedef struct _GtkRcNode GtkRcNode;
67 typedef struct _GtkRcFile GtkRcFile;
78 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
81 gchar *canonical_name;
86 #define GTK_RC_MAX_PIXMAP_PATHS 128
90 GHashTable *rc_style_ht;
91 GtkSettings *settings;
92 GSList *rc_sets_widget;
93 GSList *rc_sets_widget_class;
94 GSList *rc_sets_class;
96 /* The files we have parsed, to reread later if necessary */
100 gchar *key_theme_name;
103 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
105 gint default_priority;
106 GtkStyle *default_style;
109 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
111 static guint gtk_rc_style_hash (const gchar *name);
112 static gboolean gtk_rc_style_equal (const gchar *a,
114 static guint gtk_rc_styles_hash (const GSList *rc_styles);
115 static gboolean gtk_rc_styles_equal (const GSList *a,
117 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
119 static GSList * gtk_rc_styles_match (GSList *rc_styles,
123 const gchar *path_reversed);
124 static GtkStyle * gtk_rc_style_to_style (GtkRcContext *context,
125 GtkRcStyle *rc_style);
126 static GtkStyle* gtk_rc_init_style (GtkRcContext *context,
128 static void gtk_rc_parse_default_files (GtkRcContext *context);
129 static void gtk_rc_parse_named (GtkRcContext *context,
132 static void gtk_rc_context_parse_file (GtkRcContext *context,
133 const gchar *filename,
136 static void gtk_rc_parse_any (GtkRcContext *context,
137 const gchar *input_name,
139 const gchar *input_string);
140 static guint gtk_rc_parse_statement (GtkRcContext *context,
142 static guint gtk_rc_parse_style (GtkRcContext *context,
144 static guint gtk_rc_parse_assignment (GScanner *scanner,
145 GtkRcProperty *prop);
146 static guint gtk_rc_parse_bg (GScanner *scanner,
148 static guint gtk_rc_parse_fg (GScanner *scanner,
150 static guint gtk_rc_parse_text (GScanner *scanner,
152 static guint gtk_rc_parse_base (GScanner *scanner,
154 static guint gtk_rc_parse_xthickness (GScanner *scanner,
156 static guint gtk_rc_parse_ythickness (GScanner *scanner,
158 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
160 GtkRcStyle *rc_style);
161 static guint gtk_rc_parse_font (GScanner *scanner,
162 GtkRcStyle *rc_style);
163 static guint gtk_rc_parse_fontset (GScanner *scanner,
164 GtkRcStyle *rc_style);
165 static guint gtk_rc_parse_font_name (GScanner *scanner,
166 GtkRcStyle *rc_style);
167 static guint gtk_rc_parse_engine (GtkRcContext *context,
169 GtkRcStyle **rc_style);
170 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
172 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
174 const gchar *pix_path);
175 static guint gtk_rc_parse_module_path (GScanner *scanner);
176 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
177 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
179 static guint gtk_rc_parse_stock (GtkRcContext *context,
181 GtkRcStyle *rc_style,
182 GtkIconFactory *factory);
183 static void gtk_rc_clear_hash_node (gpointer key,
186 static void gtk_rc_clear_styles (GtkRcContext *context);
187 static void gtk_rc_add_initial_default_files (void);
189 static void gtk_rc_style_init (GtkRcStyle *style);
190 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
191 static void gtk_rc_style_finalize (GObject *object);
192 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
194 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
195 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
196 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
197 gconstpointer bsearch_node2);
199 static gpointer parent_class = NULL;
201 static const GScannerConfig gtk_rc_scanner_config =
205 ) /* cset_skip_characters */,
210 ) /* cset_identifier_first */,
215 ) /* cset_identifier_nth */,
216 ( "#\n" ) /* cpair_comment_single */,
218 TRUE /* case_sensitive */,
220 TRUE /* skip_comment_multi */,
221 TRUE /* skip_comment_single */,
222 TRUE /* scan_comment_multi */,
223 TRUE /* scan_identifier */,
224 FALSE /* scan_identifier_1char */,
225 FALSE /* scan_identifier_NULL */,
226 TRUE /* scan_symbols */,
227 TRUE /* scan_binary */,
228 TRUE /* scan_octal */,
229 TRUE /* scan_float */,
231 TRUE /* scan_hex_dollar */,
232 TRUE /* scan_string_sq */,
233 TRUE /* scan_string_dq */,
234 TRUE /* numbers_2_int */,
235 FALSE /* int_2_float */,
236 FALSE /* identifier_2_string */,
237 TRUE /* char_2_token */,
238 TRUE /* symbol_2_token */,
239 FALSE /* scope_0_fallback */,
247 { "include", GTK_RC_TOKEN_INCLUDE },
248 { "NORMAL", GTK_RC_TOKEN_NORMAL },
249 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
250 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
251 { "SELECTED", GTK_RC_TOKEN_SELECTED },
252 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
253 { "fg", GTK_RC_TOKEN_FG },
254 { "bg", GTK_RC_TOKEN_BG },
255 { "text", GTK_RC_TOKEN_TEXT },
256 { "base", GTK_RC_TOKEN_BASE },
257 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
258 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
259 { "font", GTK_RC_TOKEN_FONT },
260 { "fontset", GTK_RC_TOKEN_FONTSET },
261 { "font_name", GTK_RC_TOKEN_FONT_NAME },
262 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
263 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
264 { "style", GTK_RC_TOKEN_STYLE },
265 { "binding", GTK_RC_TOKEN_BINDING },
266 { "bind", GTK_RC_TOKEN_BIND },
267 { "widget", GTK_RC_TOKEN_WIDGET },
268 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
269 { "class", GTK_RC_TOKEN_CLASS },
270 { "lowest", GTK_RC_TOKEN_LOWEST },
271 { "gtk", GTK_RC_TOKEN_GTK },
272 { "application", GTK_RC_TOKEN_APPLICATION },
273 { "theme", GTK_RC_TOKEN_THEME },
274 { "rc", GTK_RC_TOKEN_RC },
275 { "highest", GTK_RC_TOKEN_HIGHEST },
276 { "engine", GTK_RC_TOKEN_ENGINE },
277 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
278 { "stock", GTK_RC_TOKEN_STOCK },
279 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
280 { "LTR", GTK_RC_TOKEN_LTR },
281 { "RTL", GTK_RC_TOKEN_RTL }
284 static GHashTable *realized_style_ht = NULL;
286 static gchar *im_module_file = NULL;
288 #define GTK_RC_MAX_DEFAULT_FILES 128
289 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
291 /* A stack of information of RC files we are parsing currently.
292 * The directories for these files are implicitely added to the end of
295 static GSList *current_files_stack = NULL;
297 /* RC files and strings that are parsed for every context
299 static GSList *global_rc_files = NULL;
301 /* Keep list of all current RC contexts for convenience
303 static GSList *rc_contexts;
305 /* RC file handling */
308 gtk_rc_make_default_dir (const gchar *type)
313 var = g_getenv ("GTK_EXE_PREFIX");
316 path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
318 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
324 * gtk_rc_get_im_module_path:
325 * @returns: a newly-allocated string containing the path in which to
326 * look for IM modules.
328 * Obtains the path in which to look for IM modules. See the documentation
329 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
330 * environment variable for more details about looking up modules. This
331 * function is useful solely for utilities supplied with GTK+ and should
332 * not be used by applications under normal circumstances.
335 gtk_rc_get_im_module_path (void)
337 gchar **paths = _gtk_get_module_path ("immodules");
338 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
345 * gtk_rc_get_im_module_file:
346 * @returns: a newly-allocated string containing the name of the file
347 * listing the IM modules available for loading
349 * Obtains the path to the IM modules file. See the documentation
350 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
351 * environment variable for more details.
354 gtk_rc_get_im_module_file (void)
356 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
357 gchar *result = NULL;
360 result = g_strdup (var);
365 result = g_strdup (im_module_file);
367 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
374 gtk_rc_get_theme_dir (void)
379 var = g_getenv ("GTK_DATA_PREFIX");
382 path = g_build_filename (var, "share", "themes", NULL);
384 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
390 * gtk_rc_get_module_dir:
392 * Returns a directory in which GTK+ looks for theme engines.
393 * For full information about the search for theme engines,
394 * see the docs for <envar>GTK_PATH</envar> in
395 * <xref linkend="gtk-running"/>.
397 * return value: the directory. (Must be freed with g_free())
400 gtk_rc_get_module_dir (void)
402 return gtk_rc_make_default_dir ("engines");
406 gtk_rc_add_initial_default_files (void)
408 static gint init = FALSE;
417 gtk_rc_default_files[0] = NULL;
420 var = g_getenv ("GTK2_RC_FILES");
424 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
428 gtk_rc_add_default_file (files[i]);
436 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
438 gtk_rc_add_default_file (str);
441 home = g_get_home_dir ();
444 str = g_build_filename (home, ".gtkrc-2.0", NULL);
445 gtk_rc_add_default_file (str);
452 * gtk_rc_add_default_file:
453 * @filename: the pathname to the file. If @filename is not absolute, it
454 * is searched in the current directory.
456 * Adds a file to the list of files to be parsed at the
460 gtk_rc_add_default_file (const gchar *filename)
464 gtk_rc_add_initial_default_files ();
466 for (n = 0; gtk_rc_default_files[n]; n++) ;
467 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
470 gtk_rc_default_files[n++] = g_strdup (filename);
471 gtk_rc_default_files[n] = NULL;
475 * gtk_rc_set_default_files:
476 * @filenames: A %NULL-terminated list of filenames.
478 * Sets the list of files that GTK+ will read at the
482 gtk_rc_set_default_files (gchar **filenames)
486 gtk_rc_add_initial_default_files ();
489 while (gtk_rc_default_files[i])
491 g_free (gtk_rc_default_files[i]);
495 gtk_rc_default_files[0] = NULL;
498 while (filenames[i] != NULL)
500 gtk_rc_add_default_file (filenames[i]);
506 * gtk_rc_get_default_files:
508 * Retrieves the current list of RC files that will be parsed
509 * at the end of gtk_init().
511 * Return value: A %NULL-terminated array of filenames. This memory
512 * is owned by GTK+ and must not be freed by the application.
513 * If you want to store this information, you should make a copy.
516 gtk_rc_get_default_files (void)
518 gtk_rc_add_initial_default_files ();
520 return gtk_rc_default_files;
524 gtk_rc_settings_changed (GtkSettings *settings,
526 GtkRcContext *context)
528 gchar *new_theme_name;
529 gchar *new_key_theme_name;
531 g_object_get (settings,
532 "gtk-theme-name", &new_theme_name,
533 "gtk-key-theme-name", &new_key_theme_name,
536 if ((new_theme_name != context->theme_name &&
537 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
538 (new_key_theme_name != context->key_theme_name &&
539 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
541 gtk_rc_reparse_all_for_settings (settings, TRUE);
544 g_free (new_theme_name);
545 g_free (new_key_theme_name);
549 gtk_rc_font_name_changed (GtkSettings *settings,
551 GtkRcContext *context)
553 _gtk_rc_context_get_default_font_name (settings);
556 static GtkRcContext *
557 gtk_rc_context_get (GtkSettings *settings)
559 if (!settings->rc_context)
561 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
563 context->settings = settings;
564 context->rc_style_ht = NULL;
565 context->rc_sets_widget = NULL;
566 context->rc_sets_widget_class = NULL;
567 context->rc_sets_class = NULL;
568 context->rc_files = NULL;
569 context->default_style = NULL;
571 g_object_get (settings,
572 "gtk-theme-name", &context->theme_name,
573 "gtk-key-theme-name", &context->key_theme_name,
574 "gtk-font-name", &context->font_name,
577 g_signal_connect (settings,
578 "notify::gtk-theme-name",
579 G_CALLBACK (gtk_rc_settings_changed),
581 g_signal_connect (settings,
582 "notify::gtk-key-theme-name",
583 G_CALLBACK (gtk_rc_settings_changed),
585 g_signal_connect (settings,
586 "notify::gtk-font-name",
587 G_CALLBACK (gtk_rc_font_name_changed),
591 context->pixmap_path[0] = NULL;
593 context->default_priority = GTK_PATH_PRIO_RC;
595 rc_contexts = g_slist_prepend (rc_contexts, settings->rc_context);
598 return settings->rc_context;
602 gtk_rc_parse_named (GtkRcContext *context,
607 const gchar *home_dir;
611 subpath = g_strconcat ("gtk-2.0-", type,
612 G_DIR_SEPARATOR_S "gtkrc",
615 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
617 /* First look in the users home directory
619 home_dir = g_get_home_dir ();
622 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
623 if (!g_file_test (path, G_FILE_TEST_EXISTS))
632 gchar *theme_dir = gtk_rc_get_theme_dir ();
633 path = g_build_filename (theme_dir, name, subpath, NULL);
636 if (!g_file_test (path, G_FILE_TEST_EXISTS))
645 gtk_rc_context_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
653 gtk_rc_parse_default_files (GtkRcContext *context)
657 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
658 gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
664 static gboolean initialized = FALSE;
670 gtk_rc_add_initial_default_files ();
673 /* Default RC string */
674 gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
675 " bg[NORMAL] = \"#eee1b3\"\n"
676 " fg[NORMAL] = \"#000000\"\n"
679 "style \"gtk-default-progress-bar-style\" {\n"
680 " bg[PRELIGHT] = \"#4b6983\"\n"
681 " fg[PRELIGHT] = \"#ffffff\"\n"
682 " bg[NORMAL] = \"#c4c2bd\"\n"
685 "style \"gtk-default-menu-bar-item-style\" {\n"
686 " GtkMenuItem::horizontal_padding = 5\n"
689 "style \"gtk-default-menu-item-style\" {\n"
690 " bg[PRELIGHT] = \"#4b6983\"\n"
691 " fg[PRELIGHT] = \"#ffffff\"\n"
692 " base[PRELIGHT] = \"#4b6983\"\n"
693 " text[PRELIGHT] = \"#ffffff\"\n"
696 "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
697 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"
698 "class \"GtkMenuItem\" style : gtk \"gtk-default-menu-item-style\"\n"
699 "widget_class \"*.GtkMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
700 "widget_class \"*.GtkAccelMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
701 "widget_class \"*.GtkRadioMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
702 "widget_class \"*.GtkCheckMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
703 "widget_class \"*.GtkImageMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
704 "widget_class \"*.GtkSeparatorMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
705 "widget_class \"*.GtkCellViewMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
706 "widget_class \"*GtkMenuBar*GtkMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
707 "widget_class \"*GtkMenuBar*GtkAccelMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
708 "widget_class \"*GtkMenuBar*GtkRadioMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
709 "widget_class \"*GtkMenuBar*GtkCheckMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
710 "widget_class \"*GtkMenuBar*GtkImageMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
715 gtk_rc_context_parse_string (GtkRcContext *context,
716 const gchar *rc_string)
718 gtk_rc_parse_any (context, "-", -1, rc_string);
722 gtk_rc_parse_string (const gchar *rc_string)
727 g_return_if_fail (rc_string != NULL);
729 rc_file = g_new (GtkRcFile, 1);
730 rc_file->is_string = TRUE;
731 rc_file->name = g_strdup (rc_string);
732 rc_file->canonical_name = NULL;
733 rc_file->directory = NULL;
735 rc_file->reload = TRUE;
737 global_rc_files = g_slist_append (global_rc_files, rc_file);
739 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
740 gtk_rc_context_parse_string (tmp_list->data, rc_string);
744 add_to_rc_file_list (GSList **rc_file_list,
745 const char *filename,
751 tmp_list = *rc_file_list;
754 rc_file = tmp_list->data;
755 if (!strcmp (rc_file->name, filename))
758 tmp_list = tmp_list->next;
761 rc_file = g_new (GtkRcFile, 1);
762 rc_file->is_string = FALSE;
763 rc_file->name = g_strdup (filename);
764 rc_file->canonical_name = NULL;
765 rc_file->directory = NULL;
767 rc_file->reload = reload;
769 *rc_file_list = g_slist_append (*rc_file_list, rc_file);
775 gtk_rc_context_parse_one_file (GtkRcContext *context,
776 const gchar *filename,
784 g_return_if_fail (filename != NULL);
786 saved_priority = context->default_priority;
787 context->default_priority = priority;
789 rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
791 if (!rc_file->canonical_name)
793 /* Get the absolute pathname */
795 if (g_path_is_absolute (rc_file->name))
796 rc_file->canonical_name = rc_file->name;
801 cwd = g_get_current_dir ();
802 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
806 rc_file->directory = g_path_get_dirname (rc_file->canonical_name);
809 /* If the file is already being parsed (recursion), do nothing
811 if (g_slist_find (current_files_stack, rc_file))
814 if (!g_lstat (rc_file->canonical_name, &statbuf))
818 rc_file->mtime = statbuf.st_mtime;
820 fd = g_open (rc_file->canonical_name, O_RDONLY, 0);
824 /* Temporarily push information for this file on
825 * a stack of current files while parsing it.
827 current_files_stack = g_slist_prepend (current_files_stack, rc_file);
828 gtk_rc_parse_any (context, filename, fd, NULL);
829 current_files_stack = g_slist_delete_link (current_files_stack,
830 current_files_stack);
836 context->default_priority = saved_priority;
840 strchr_len (const gchar *str, gint len, char c)
854 gtk_rc_context_parse_file (GtkRcContext *context,
855 const gchar *filename,
859 gchar *locale_suffixes[2];
860 gint n_locale_suffixes = 0;
864 gboolean found = FALSE;
866 locale = _gtk_get_lc_ctype ();
868 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
870 /* Determine locale-specific suffixes for RC files.
872 length = strlen (locale);
874 p = strchr (locale, '@');
878 p = strchr_len (locale, length, '.');
882 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
884 p = strchr_len (locale, length, '_');
888 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
894 gtk_rc_context_parse_one_file (context, filename, priority, reload);
895 for (j = 0; j < n_locale_suffixes; j++)
899 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
900 if (g_file_test (name, G_FILE_TEST_EXISTS))
902 gtk_rc_context_parse_one_file (context, name, priority, FALSE);
909 g_free (locale_suffixes[j]);
914 gtk_rc_parse (const gchar *filename)
918 g_return_if_fail (filename != NULL);
920 add_to_rc_file_list (&global_rc_files, filename, TRUE);
922 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
923 gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
926 /* Handling of RC styles */
929 gtk_rc_style_get_type (void)
931 static GType rc_style_type = 0;
935 static const GTypeInfo rc_style_info =
937 sizeof (GtkRcStyleClass),
938 (GBaseInitFunc) NULL,
939 (GBaseFinalizeFunc) NULL,
940 (GClassInitFunc) gtk_rc_style_class_init,
941 NULL, /* class_finalize */
942 NULL, /* class_data */
945 (GInstanceInitFunc) gtk_rc_style_init,
948 rc_style_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkRcStyle"),
952 return rc_style_type;
956 gtk_rc_style_init (GtkRcStyle *style)
961 style->font_desc = NULL;
963 for (i = 0; i < 5; i++)
965 static const GdkColor init_color = { 0, 0, 0, 0, };
967 style->bg_pixmap_name[i] = NULL;
968 style->color_flags[i] = 0;
969 style->fg[i] = init_color;
970 style->bg[i] = init_color;
971 style->text[i] = init_color;
972 style->base[i] = init_color;
974 style->xthickness = -1;
975 style->ythickness = -1;
976 style->rc_properties = NULL;
978 style->rc_style_lists = NULL;
979 style->icon_factories = NULL;
983 gtk_rc_style_class_init (GtkRcStyleClass *klass)
985 GObjectClass *object_class = G_OBJECT_CLASS (klass);
987 parent_class = g_type_class_peek_parent (klass);
989 object_class->finalize = gtk_rc_style_finalize;
992 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
993 klass->merge = gtk_rc_style_real_merge;
994 klass->create_style = gtk_rc_style_real_create_style;
998 gtk_rc_style_finalize (GObject *object)
1000 GSList *tmp_list1, *tmp_list2;
1001 GtkRcStyle *rc_style;
1004 rc_style = GTK_RC_STYLE (object);
1007 g_free (rc_style->name);
1008 if (rc_style->font_desc)
1009 pango_font_description_free (rc_style->font_desc);
1011 for (i = 0; i < 5; i++)
1012 if (rc_style->bg_pixmap_name[i])
1013 g_free (rc_style->bg_pixmap_name[i]);
1015 /* Now remove all references to this rc_style from
1018 tmp_list1 = rc_style->rc_style_lists;
1021 GSList *rc_styles = tmp_list1->data;
1022 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1023 g_object_unref (style);
1025 /* Remove the list of styles from the other rc_styles
1028 tmp_list2 = rc_styles;
1031 GtkRcStyle *other_style = tmp_list2->data;
1033 if (other_style != rc_style)
1034 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1036 tmp_list2 = tmp_list2->next;
1039 /* And from the hash table itself
1041 g_hash_table_remove (realized_style_ht, rc_styles);
1042 g_slist_free (rc_styles);
1044 tmp_list1 = tmp_list1->next;
1046 g_slist_free (rc_style->rc_style_lists);
1048 if (rc_style->rc_properties)
1052 for (i = 0; i < rc_style->rc_properties->len; i++)
1054 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1056 g_free (node->origin);
1057 g_value_unset (&node->value);
1059 g_array_free (rc_style->rc_properties, TRUE);
1060 rc_style->rc_properties = NULL;
1063 tmp_list1 = rc_style->icon_factories;
1066 g_object_unref (tmp_list1->data);
1067 tmp_list1 = tmp_list1->next;
1069 g_slist_free (rc_style->icon_factories);
1071 G_OBJECT_CLASS (parent_class)->finalize (object);
1075 gtk_rc_style_new (void)
1079 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1085 * gtk_rc_style_copy:
1086 * @orig: the style to copy
1088 * Makes a copy of the specified #GtkRcStyle. This function
1089 * will correctly copy an RC style that is a member of a class
1090 * derived from #GtkRcStyle.
1092 * Return value: the resulting #GtkRcStyle
1095 gtk_rc_style_copy (GtkRcStyle *orig)
1099 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1101 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1102 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1108 gtk_rc_style_ref (GtkRcStyle *rc_style)
1110 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1112 g_object_ref (rc_style);
1116 gtk_rc_style_unref (GtkRcStyle *rc_style)
1118 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1120 g_object_unref (rc_style);
1124 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1126 return g_object_new (G_OBJECT_TYPE (style), NULL);
1130 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1131 gconstpointer bsearch_node2)
1133 const GtkRcProperty *prop1 = bsearch_node1;
1134 const GtkRcProperty *prop2 = bsearch_node2;
1136 if (prop1->type_name == prop2->type_name)
1137 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1139 return prop1->type_name < prop2->type_name ? -1 : 1;
1143 insert_rc_property (GtkRcStyle *style,
1144 GtkRcProperty *property,
1148 GtkRcProperty *new_property = NULL;
1149 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1151 key.type_name = property->type_name;
1152 key.property_name = property->property_name;
1154 if (!style->rc_properties)
1155 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1158 while (i < style->rc_properties->len)
1160 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1166 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1168 g_free (new_property->origin);
1169 g_value_unset (&new_property->value);
1171 *new_property = key;
1185 g_array_insert_val (style->rc_properties, i, key);
1186 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1189 new_property->origin = g_strdup (property->origin);
1190 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1191 g_value_copy (&property->value, &new_property->value);
1195 gtk_rc_style_real_merge (GtkRcStyle *dest,
1200 for (i = 0; i < 5; i++)
1202 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1203 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1205 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1206 src->color_flags[i] & GTK_RC_FG)
1208 dest->fg[i] = src->fg[i];
1209 dest->color_flags[i] |= GTK_RC_FG;
1211 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1212 src->color_flags[i] & GTK_RC_BG)
1214 dest->bg[i] = src->bg[i];
1215 dest->color_flags[i] |= GTK_RC_BG;
1217 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1218 src->color_flags[i] & GTK_RC_TEXT)
1220 dest->text[i] = src->text[i];
1221 dest->color_flags[i] |= GTK_RC_TEXT;
1223 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1224 src->color_flags[i] & GTK_RC_BASE)
1226 dest->base[i] = src->base[i];
1227 dest->color_flags[i] |= GTK_RC_BASE;
1231 if (dest->xthickness < 0 && src->xthickness >= 0)
1232 dest->xthickness = src->xthickness;
1233 if (dest->ythickness < 0 && src->ythickness >= 0)
1234 dest->ythickness = src->ythickness;
1238 if (!dest->font_desc)
1239 dest->font_desc = pango_font_description_copy (src->font_desc);
1241 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1244 if (src->rc_properties)
1248 for (i = 0; i < src->rc_properties->len; i++)
1249 insert_rc_property (dest,
1250 &g_array_index (src->rc_properties, GtkRcProperty, i),
1256 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1258 return gtk_style_new ();
1262 gtk_rc_clear_hash_node (gpointer key,
1266 gtk_rc_style_unref (data);
1270 gtk_rc_free_rc_sets (GSList *slist)
1276 rc_set = slist->data;
1277 g_pattern_spec_free (rc_set->pspec);
1280 slist = slist->next;
1285 gtk_rc_clear_styles (GtkRcContext *context)
1287 /* Clear out all old rc_styles */
1289 if (context->rc_style_ht)
1291 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1292 g_hash_table_destroy (context->rc_style_ht);
1293 context->rc_style_ht = NULL;
1296 gtk_rc_free_rc_sets (context->rc_sets_widget);
1297 g_slist_free (context->rc_sets_widget);
1298 context->rc_sets_widget = NULL;
1300 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1301 g_slist_free (context->rc_sets_widget_class);
1302 context->rc_sets_widget_class = NULL;
1304 gtk_rc_free_rc_sets (context->rc_sets_class);
1305 g_slist_free (context->rc_sets_class);
1306 context->rc_sets_class = NULL;
1309 /* Reset all our widgets. Also, we have to invalidate cached icons in
1310 * icon sets so they get re-rendered.
1313 gtk_rc_reset_widgets (GtkSettings *settings)
1315 GList *list, *toplevels;
1317 _gtk_icon_set_invalidate_caches ();
1319 toplevels = gtk_window_list_toplevels ();
1320 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1322 for (list = toplevels; list; list = list->next)
1324 if (gtk_widget_get_screen (list->data) == settings->screen)
1326 gtk_widget_reset_rc_styles (list->data);
1327 g_object_unref (list->data);
1330 g_list_free (toplevels);
1334 gtk_rc_clear_realized_style (gpointer key,
1338 GSList *rc_styles = key;
1339 GSList *tmp_list = rc_styles;
1343 GtkRcStyle *rc_style = tmp_list->data;
1345 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1347 tmp_list = tmp_list->next;
1350 g_slist_free (rc_styles);
1354 * gtk_rc_reset_styles:
1355 * @settings: a #GtkSettings
1357 * This function recomputes the styles for all widgets that use a
1358 * particular #GtkSettings object. (There is one #GtkSettings object
1359 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1360 * when some global parameter has changed that affects the appearance
1361 * of all widgets, because when a widget gets a new style, it will
1362 * both redraw and recompute any cached information about its
1363 * appearance. As an example, it is used when the default font size
1364 * set by the operating system changes. Note that this function
1365 * doesn't affect widgets that have a style set explicitely on them
1366 * with gtk_widget_set_style().
1371 gtk_rc_reset_styles (GtkSettings *settings)
1373 GtkRcContext *context;
1374 gboolean reset = FALSE;
1376 g_return_if_fail (GTK_IS_SETTINGS (settings));
1378 context = gtk_rc_context_get (settings);
1380 if (context->default_style)
1382 g_object_unref (context->default_style);
1383 context->default_style = NULL;
1387 /* Clear out styles that have been looked up already
1389 if (realized_style_ht)
1391 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1392 g_hash_table_destroy (realized_style_ht);
1393 realized_style_ht = NULL;
1398 gtk_rc_reset_widgets (settings);
1402 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1404 GtkRcContext *context;
1405 gchar *new_font_name;
1407 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1409 context = gtk_rc_context_get (settings);
1411 g_object_get (context->settings,
1412 "gtk-font-name", &new_font_name,
1415 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1417 g_free (context->font_name);
1418 context->font_name = g_strdup (new_font_name);
1420 gtk_rc_reset_styles (settings);
1423 g_free (new_font_name);
1425 return context->font_name;
1429 * gtk_rc_reparse_all_for_settings:
1430 * @settings: a #GtkSettings
1431 * @force_load: load whether or not anything changed
1433 * If the modification time on any previously read file
1434 * for the given #GtkSettings has changed, discard all style information
1435 * and then reread all previously read RC files.
1437 * Return value: %TRUE if the files were reread.
1440 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1441 gboolean force_load)
1443 gboolean mtime_modified = FALSE;
1446 GtkRcContext *context;
1448 struct stat statbuf;
1450 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1452 context = gtk_rc_context_get (settings);
1456 /* Check through and see if any of the RC's have had their
1457 * mtime modified. If so, reparse everything.
1459 tmp_list = context->rc_files;
1462 rc_file = tmp_list->data;
1464 if (!rc_file->is_string)
1466 if (!g_lstat (rc_file->name, &statbuf) &&
1467 (statbuf.st_mtime > rc_file->mtime))
1469 mtime_modified = TRUE;
1474 tmp_list = tmp_list->next;
1478 if (force_load || mtime_modified)
1480 _gtk_binding_reset_parsed ();
1481 gtk_rc_clear_styles (context);
1482 g_object_freeze_notify (G_OBJECT (context->settings));
1484 _gtk_settings_reset_rc_values (context->settings);
1485 tmp_list = context->rc_files;
1488 rc_file = tmp_list->data;
1490 if (rc_file->canonical_name != rc_file->name)
1491 g_free (rc_file->canonical_name);
1492 g_free (rc_file->directory);
1493 g_free (rc_file->name);
1496 tmp_list = tmp_list->next;
1499 g_slist_free (context->rc_files);
1500 context->rc_files = NULL;
1502 gtk_rc_parse_default_files (context);
1504 tmp_list = global_rc_files;
1507 rc_file = tmp_list->data;
1509 if (rc_file->is_string)
1510 gtk_rc_context_parse_string (context, rc_file->name);
1512 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1514 tmp_list = tmp_list->next;
1517 g_free (context->theme_name);
1518 g_free (context->key_theme_name);
1520 g_object_get (context->settings,
1521 "gtk-theme-name", &context->theme_name,
1522 "gtk-key-theme-name", &context->key_theme_name,
1525 if (context->theme_name && context->theme_name[0])
1526 gtk_rc_parse_named (context, context->theme_name, NULL);
1527 if (context->key_theme_name && context->key_theme_name[0])
1528 gtk_rc_parse_named (context, context->key_theme_name, "key");
1530 g_object_thaw_notify (G_OBJECT (context->settings));
1532 gtk_rc_reset_widgets (context->settings);
1535 return force_load || mtime_modified;
1539 * gtk_rc_reparse_all:
1541 * If the modification time on any previously read file for the
1542 * default #GtkSettings has changed, discard all style information
1543 * and then reread all previously read RC files.
1545 * Return value: %TRUE if the files were reread.
1548 gtk_rc_reparse_all (void)
1551 gboolean result = FALSE;
1553 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1555 GtkRcContext *context = tmp_list->data;
1556 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1564 gtk_rc_styles_match (GSList *rc_styles,
1568 const gchar *path_reversed)
1575 rc_set = sets->data;
1578 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1579 rc_styles = g_slist_append (rc_styles, rc_set);
1586 rc_set_compare (gconstpointer a, gconstpointer b)
1588 const GtkRcSet *set_a = a;
1589 const GtkRcSet *set_b = b;
1591 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1595 sort_and_dereference_sets (GSList *styles)
1599 /* At this point, the list of sets is ordered by:
1601 * a) 'widget' patterns are earlier than 'widget_class' patterns
1602 * which are ealier than 'class' patterns.
1603 * a) For two matches for class patterns, a match to a child type
1604 * is before a match to a parent type
1605 * c) a match later in the RC file (or in a later RC file) is before a
1606 * match earlier in the RC file.
1608 * With a) taking precedence over b) which takes precendence over c).
1610 * Now sort by priority, which has the highest precendence for sort order
1612 styles = g_slist_sort (styles, rc_set_compare);
1614 /* Make styles->data = styles->data->rc_style
1619 GtkRcSet *set = tmp_list->data;
1620 tmp_list->data = set->rc_style;
1621 tmp_list = tmp_list->next;
1629 * @widget: a #GtkWidget
1631 * Finds all matching RC styles for a given widget,
1632 * composites them together, and then creates a
1633 * #GtkStyle representing the composite appearance.
1634 * (GTK+ actually keeps a cache of previously
1635 * created styles, so a new style may not be
1638 * Returns: the resulting style. No refcount is added
1639 * to the returned style, so if you want to save this
1640 * style around, you should add a reference yourself.
1643 gtk_rc_get_style (GtkWidget *widget)
1645 GtkRcStyle *widget_rc_style;
1646 GSList *rc_styles = NULL;
1647 GtkRcContext *context;
1649 static guint rc_style_key_id = 0;
1651 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1653 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1655 /* We allow the specification of a single rc style to be bound
1656 * tightly to a widget, for application modifications
1658 if (!rc_style_key_id)
1659 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1661 if (context->rc_sets_widget)
1663 gchar *path, *path_reversed;
1666 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1667 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1669 g_free (path_reversed);
1672 if (context->rc_sets_widget_class)
1674 gchar *path, *path_reversed;
1677 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1678 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1680 g_free (path_reversed);
1683 if (context->rc_sets_class)
1687 type = G_TYPE_FROM_INSTANCE (widget);
1691 gchar *path_reversed;
1694 path = g_type_name (type);
1695 path_length = strlen (path);
1696 path_reversed = g_strdup (path);
1697 g_strreverse (path_reversed);
1699 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1700 g_free (path_reversed);
1702 type = g_type_parent (type);
1706 rc_styles = sort_and_dereference_sets (rc_styles);
1708 widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
1710 if (widget_rc_style)
1711 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1714 return gtk_rc_init_style (context, rc_styles);
1717 if (!context->default_style)
1719 context->default_style = gtk_style_new ();
1720 _gtk_style_init_for_settings (context->default_style, context->settings);
1723 return context->default_style;
1728 * gtk_rc_get_style_by_paths:
1729 * @settings: a #GtkSettings object
1730 * @widget_path: the widget path to use when looking up the style, or %NULL
1731 * if no matching against the widget path should be done
1732 * @class_path: the class path to use when looking up the style, or %NULL
1733 * if no matching against the class path should be done.
1734 * @type: a type that will be used along with parent types of this type
1735 * when matching against class styles, or #G_TYPE_NONE
1737 * Creates up a #GtkStyle from styles defined in a RC file by providing
1738 * the raw components used in matching. This function may be useful
1739 * when creating pseudo-widgets that should be themed like widgets but
1740 * don't actually have corresponding GTK+ widgets. An example of this
1741 * would be items inside a GNOME canvas widget.
1743 * The action of gtk_rc_get_style() is similar to:
1744 * <informalexample><programlisting>
1745 * gtk_widget_path (widget, NULL, &path, NULL);
1746 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1747 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1748 * G_OBJECT_TYPE (widget));
1749 * </programlisting></informalexample>
1751 * Return value: A style created by matching with the supplied paths,
1752 * or %NULL if nothing matching was specified and the default style should
1753 * be used. The returned value is owned by GTK+ as part of an internal cache,
1754 * so you must call g_object_ref() on the returned value if you want to
1755 * keep a reference to it.
1758 gtk_rc_get_style_by_paths (GtkSettings *settings,
1759 const char *widget_path,
1760 const char *class_path,
1763 /* We duplicate the code from above to avoid slowing down the above
1764 * by generating paths when we don't need them. I don't know if
1765 * this is really worth it.
1767 GSList *rc_styles = NULL;
1768 GtkRcContext *context;
1770 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1772 context = gtk_rc_context_get (settings);
1774 if (widget_path && context->rc_sets_widget)
1776 gchar *path_reversed;
1779 path_length = strlen (widget_path);
1780 path_reversed = g_strdup (widget_path);
1781 g_strreverse (path_reversed);
1783 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1784 g_free (path_reversed);
1787 if (class_path && context->rc_sets_widget_class)
1789 gchar *path_reversed;
1792 path_length = strlen (class_path);
1793 path_reversed = g_strdup (class_path);
1794 g_strreverse (path_reversed);
1796 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1797 g_free (path_reversed);
1800 if (type != G_TYPE_NONE && context->rc_sets_class)
1805 gchar *path_reversed;
1808 path = g_type_name (type);
1809 path_length = strlen (path);
1810 path_reversed = g_strdup (path);
1811 g_strreverse (path_reversed);
1813 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1814 g_free (path_reversed);
1816 type = g_type_parent (type);
1820 rc_styles = sort_and_dereference_sets (rc_styles);
1823 return gtk_rc_init_style (context, rc_styles);
1829 gtk_rc_add_rc_sets (GSList *slist,
1830 GtkRcStyle *rc_style,
1831 const gchar *pattern)
1833 GtkRcStyle *new_style;
1837 new_style = gtk_rc_style_new ();
1838 *new_style = *rc_style;
1839 new_style->name = g_strdup (rc_style->name);
1840 if (rc_style->font_desc)
1841 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1843 for (i = 0; i < 5; i++)
1844 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1846 rc_set = g_new (GtkRcSet, 1);
1847 rc_set->pspec = g_pattern_spec_new (pattern);
1848 rc_set->rc_style = rc_style;
1850 return g_slist_prepend (slist, rc_set);
1854 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1855 const gchar *pattern)
1857 GtkRcContext *context;
1859 g_return_if_fail (rc_style != NULL);
1860 g_return_if_fail (pattern != NULL);
1862 context = gtk_rc_context_get (gtk_settings_get_default ());
1864 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1868 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1869 const gchar *pattern)
1871 GtkRcContext *context;
1873 g_return_if_fail (rc_style != NULL);
1874 g_return_if_fail (pattern != NULL);
1876 context = gtk_rc_context_get (gtk_settings_get_default ());
1878 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1882 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1883 const gchar *pattern)
1885 GtkRcContext *context;
1887 g_return_if_fail (rc_style != NULL);
1888 g_return_if_fail (pattern != NULL);
1890 context = gtk_rc_context_get (gtk_settings_get_default ());
1892 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1896 gtk_rc_scanner_new (void)
1898 return g_scanner_new (>k_rc_scanner_config);
1902 gtk_rc_parse_any (GtkRcContext *context,
1903 const gchar *input_name,
1905 const gchar *input_string)
1911 scanner = gtk_rc_scanner_new ();
1915 g_assert (input_string == NULL);
1917 g_scanner_input_file (scanner, input_fd);
1921 g_assert (input_string != NULL);
1923 g_scanner_input_text (scanner, input_string, strlen (input_string));
1925 scanner->input_name = input_name;
1927 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1928 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1933 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1937 guint expected_token;
1939 expected_token = gtk_rc_parse_statement (context, scanner);
1941 if (expected_token != G_TOKEN_NONE)
1948 if (scanner->scope_id == 0)
1950 /* if we are in scope 0, we know the symbol names
1951 * that are associated with certain token values.
1952 * so we look them up to make the error messages
1955 if (expected_token > GTK_RC_TOKEN_INVALID &&
1956 expected_token < GTK_RC_TOKEN_LAST)
1958 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1959 if (symbols[i].token == expected_token)
1960 msg = symbols[i].name;
1962 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1964 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1965 scanner->token < GTK_RC_TOKEN_LAST)
1967 symbol_name = "???";
1968 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1969 if (symbols[i].token == scanner->token)
1970 symbol_name = symbols[i].name;
1973 g_scanner_unexp_token (scanner,
1986 g_scanner_destroy (scanner);
1990 gtk_rc_styles_hash (const GSList *rc_styles)
1997 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1998 rc_styles = rc_styles->next;
2005 gtk_rc_styles_equal (const GSList *a,
2010 if (a->data != b->data)
2020 gtk_rc_style_hash (const gchar *name)
2026 result += (result << 3) + *name++;
2032 gtk_rc_style_equal (const gchar *a,
2035 return (strcmp (a, b) == 0);
2039 gtk_rc_style_find (GtkRcContext *context,
2042 if (context->rc_style_ht)
2043 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2049 gtk_rc_style_to_style (GtkRcContext *context,
2050 GtkRcStyle *rc_style)
2054 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2055 _gtk_style_init_for_settings (style, context->settings);
2057 style->rc_style = rc_style;
2059 gtk_rc_style_ref (rc_style);
2061 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2066 /* Reuses or frees rc_styles */
2068 gtk_rc_init_style (GtkRcContext *context,
2071 GtkStyle *style = NULL;
2074 g_return_val_if_fail (rc_styles != NULL, NULL);
2076 if (!realized_style_ht)
2077 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2078 (GEqualFunc) gtk_rc_styles_equal);
2080 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2084 GtkRcStyle *base_style = NULL;
2085 GtkRcStyle *proto_style;
2086 GtkRcStyleClass *proto_style_class;
2088 GType rc_style_type = GTK_TYPE_RC_STYLE;
2090 /* Find the first style where the RC file specified engine "" {}
2091 * or the first derived style and use that to create the
2092 * merged style. If we only have raw GtkRcStyles, use the first
2093 * style to create the merged style.
2095 base_style = rc_styles->data;
2096 tmp_styles = rc_styles;
2099 GtkRcStyle *rc_style = tmp_styles->data;
2101 if (rc_style->engine_specified ||
2102 G_OBJECT_TYPE (rc_style) != rc_style_type)
2104 base_style = rc_style;
2108 tmp_styles = tmp_styles->next;
2111 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2112 proto_style = proto_style_class->create_rc_style (base_style);
2114 tmp_styles = rc_styles;
2117 GtkRcStyle *rc_style = tmp_styles->data;
2120 proto_style_class->merge (proto_style, rc_style);
2122 /* Point from each rc_style to the list of styles */
2123 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2124 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2126 factories = g_slist_copy (rc_style->icon_factories);
2132 while (iter != NULL)
2134 g_object_ref (iter->data);
2135 iter = g_slist_next (iter);
2138 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2143 tmp_styles = tmp_styles->next;
2146 for (i = 0; i < 5; i++)
2147 if (proto_style->bg_pixmap_name[i] &&
2148 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2150 g_free (proto_style->bg_pixmap_name[i]);
2151 proto_style->bg_pixmap_name[i] = NULL;
2154 style = gtk_rc_style_to_style (context, proto_style);
2155 gtk_rc_style_unref (proto_style);
2157 g_hash_table_insert (realized_style_ht, rc_styles, style);
2160 g_slist_free (rc_styles);
2165 /*********************
2166 * Parsing functions *
2167 *********************/
2170 rc_parse_token_or_compound (GScanner *scanner,
2172 GTokenType delimiter)
2174 guint token = g_scanner_get_next_token (scanner);
2176 /* we either scan a single token (skipping comments)
2177 * or a compund statement.
2178 * compunds are enclosed in (), [] or {} braces, we read
2179 * them in via deep recursion.
2186 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2189 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2191 case G_TOKEN_STRING:
2192 string = g_strescape (scanner->value.v_string, NULL);
2193 g_string_append (gstring, " \"");
2194 g_string_append (gstring, string);
2195 g_string_append_c (gstring, '"');
2198 case G_TOKEN_IDENTIFIER:
2199 g_string_append_c (gstring, ' ');
2200 g_string_append (gstring, scanner->value.v_identifier);
2202 case G_TOKEN_COMMENT_SINGLE:
2203 case G_TOKEN_COMMENT_MULTI:
2204 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2205 case G_TOKEN_LEFT_PAREN:
2206 g_string_append_c (gstring, ' ');
2207 g_string_append_c (gstring, token);
2208 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2209 if (token != G_TOKEN_NONE)
2212 case G_TOKEN_LEFT_CURLY:
2213 g_string_append_c (gstring, ' ');
2214 g_string_append_c (gstring, token);
2215 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2216 if (token != G_TOKEN_NONE)
2219 case G_TOKEN_LEFT_BRACE:
2220 g_string_append_c (gstring, ' ');
2221 g_string_append_c (gstring, token);
2222 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2223 if (token != G_TOKEN_NONE)
2227 if (token >= 256 || token < 1)
2228 return delimiter ? delimiter : G_TOKEN_STRING;
2229 g_string_append_c (gstring, ' ');
2230 g_string_append_c (gstring, token);
2231 if (token == delimiter)
2232 return G_TOKEN_NONE;
2236 return G_TOKEN_NONE;
2238 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2242 gtk_rc_parse_assignment (GScanner *scanner,
2243 GtkRcProperty *prop)
2245 gboolean scan_identifier = scanner->config->scan_identifier;
2246 gboolean scan_symbols = scanner->config->scan_symbols;
2247 gboolean identifier_2_string = scanner->config->identifier_2_string;
2248 gboolean char_2_token = scanner->config->char_2_token;
2249 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2250 gboolean numbers_2_int = scanner->config->numbers_2_int;
2251 gboolean negate = FALSE;
2254 /* check that this is an assignment */
2255 if (g_scanner_get_next_token (scanner) != '=')
2258 /* adjust scanner mode */
2259 scanner->config->scan_identifier = TRUE;
2260 scanner->config->scan_symbols = FALSE;
2261 scanner->config->identifier_2_string = FALSE;
2262 scanner->config->char_2_token = TRUE;
2263 scanner->config->scan_identifier_NULL = FALSE;
2264 scanner->config->numbers_2_int = TRUE;
2266 /* record location */
2267 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2269 /* parse optional sign */
2270 if (g_scanner_peek_next_token (scanner) == '-')
2272 g_scanner_get_next_token (scanner); /* eat sign */
2276 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2277 token = g_scanner_peek_next_token (scanner);
2281 g_scanner_get_next_token (scanner);
2282 g_value_init (&prop->value, G_TYPE_LONG);
2283 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2284 token = G_TOKEN_NONE;
2287 g_scanner_get_next_token (scanner);
2288 g_value_init (&prop->value, G_TYPE_DOUBLE);
2289 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2290 token = G_TOKEN_NONE;
2292 case G_TOKEN_STRING:
2293 g_scanner_get_next_token (scanner);
2295 token = G_TOKEN_INT;
2298 g_value_init (&prop->value, G_TYPE_STRING);
2299 g_value_set_string (&prop->value, scanner->value.v_string);
2300 token = G_TOKEN_NONE;
2303 case G_TOKEN_IDENTIFIER:
2304 case G_TOKEN_LEFT_PAREN:
2305 case G_TOKEN_LEFT_CURLY:
2306 case G_TOKEN_LEFT_BRACE:
2309 GString *gstring = g_string_new (NULL);
2311 token = rc_parse_token_or_compound (scanner, gstring, 0);
2312 if (token == G_TOKEN_NONE)
2314 g_string_append_c (gstring, ' ');
2315 g_value_init (&prop->value, G_TYPE_GSTRING);
2316 g_value_take_boxed (&prop->value, gstring);
2319 g_string_free (gstring, TRUE);
2324 g_scanner_get_next_token (scanner);
2325 token = G_TOKEN_INT;
2329 /* restore scanner mode */
2330 scanner->config->scan_identifier = scan_identifier;
2331 scanner->config->scan_symbols = scan_symbols;
2332 scanner->config->identifier_2_string = identifier_2_string;
2333 scanner->config->char_2_token = char_2_token;
2334 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2335 scanner->config->numbers_2_int = numbers_2_int;
2341 is_c_identifier (const gchar *string)
2344 gboolean is_varname;
2346 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2347 for (p = string + 1; *p && is_varname; p++)
2348 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2354 parse_include_file (GtkRcContext *context,
2356 const gchar *filename)
2358 char *to_parse = NULL;
2360 if (g_path_is_absolute (filename))
2362 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2363 * don't print an error in this case.
2365 to_parse = g_strdup (filename);
2369 /* if a relative path, we look relative to all the RC files in the
2370 * include stack. We require the file to be found in this case
2371 * so we can give meaningful error messages, and because on reparsing
2372 * non-absolute paths don't make sense.
2374 GSList *tmp_list = current_files_stack;
2377 GtkRcFile *curfile = tmp_list->data;
2378 gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
2380 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2388 tmp_list = tmp_list->next;
2394 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2399 g_scanner_warn (scanner,
2400 _("Unable to find include file: \"%s\""),
2407 gtk_rc_parse_statement (GtkRcContext *context,
2412 token = g_scanner_peek_next_token (scanner);
2415 case GTK_RC_TOKEN_INCLUDE:
2416 token = g_scanner_get_next_token (scanner);
2417 if (token != GTK_RC_TOKEN_INCLUDE)
2418 return GTK_RC_TOKEN_INCLUDE;
2419 token = g_scanner_get_next_token (scanner);
2420 if (token != G_TOKEN_STRING)
2421 return G_TOKEN_STRING;
2422 parse_include_file (context, scanner, scanner->value.v_string);
2423 return G_TOKEN_NONE;
2425 case GTK_RC_TOKEN_STYLE:
2426 return gtk_rc_parse_style (context, scanner);
2428 case GTK_RC_TOKEN_BINDING:
2429 return gtk_binding_parse_binding (scanner);
2431 case GTK_RC_TOKEN_PIXMAP_PATH:
2432 return gtk_rc_parse_pixmap_path (context, scanner);
2434 case GTK_RC_TOKEN_WIDGET:
2435 return gtk_rc_parse_path_pattern (context, scanner);
2437 case GTK_RC_TOKEN_WIDGET_CLASS:
2438 return gtk_rc_parse_path_pattern (context, scanner);
2440 case GTK_RC_TOKEN_CLASS:
2441 return gtk_rc_parse_path_pattern (context, scanner);
2443 case GTK_RC_TOKEN_MODULE_PATH:
2444 return gtk_rc_parse_module_path (scanner);
2446 case GTK_RC_TOKEN_IM_MODULE_FILE:
2447 return gtk_rc_parse_im_module_file (scanner);
2449 case G_TOKEN_IDENTIFIER:
2450 if (is_c_identifier (scanner->next_value.v_identifier))
2452 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2455 g_scanner_get_next_token (scanner); /* eat identifier */
2456 name = g_strdup (scanner->value.v_identifier);
2458 token = gtk_rc_parse_assignment (scanner, &prop);
2459 if (token == G_TOKEN_NONE)
2461 GtkSettingsValue svalue;
2463 svalue.origin = prop.origin;
2464 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2465 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2466 _gtk_settings_set_property_value_from_rc (context->settings,
2470 g_free (prop.origin);
2471 if (G_VALUE_TYPE (&prop.value))
2472 g_value_unset (&prop.value);
2479 g_scanner_get_next_token (scanner);
2480 return G_TOKEN_IDENTIFIER;
2483 g_scanner_get_next_token (scanner);
2484 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2489 fixup_rc_set (GSList *list,
2495 GtkRcSet *set = list->data;
2496 if (set->rc_style == orig)
2497 set->rc_style = new;
2503 fixup_rc_sets (GtkRcContext *context,
2507 fixup_rc_set (context->rc_sets_widget, orig, new);
2508 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2509 fixup_rc_set (context->rc_sets_class, orig, new);
2513 gtk_rc_parse_style (GtkRcContext *context,
2516 GtkRcStyle *rc_style;
2517 GtkRcStyle *orig_style;
2518 GtkRcStyle *parent_style;
2521 GtkIconFactory *our_factory = NULL;
2523 token = g_scanner_get_next_token (scanner);
2524 if (token != GTK_RC_TOKEN_STYLE)
2525 return GTK_RC_TOKEN_STYLE;
2527 token = g_scanner_get_next_token (scanner);
2528 if (token != G_TOKEN_STRING)
2529 return G_TOKEN_STRING;
2531 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2533 orig_style = g_object_ref (rc_style);
2537 /* If there's a list, its first member is always the factory belonging
2540 if (rc_style && rc_style->icon_factories)
2541 our_factory = rc_style->icon_factories->data;
2545 rc_style = gtk_rc_style_new ();
2546 rc_style->name = g_strdup (scanner->value.v_string);
2548 for (i = 0; i < 5; i++)
2549 rc_style->bg_pixmap_name[i] = NULL;
2551 for (i = 0; i < 5; i++)
2552 rc_style->color_flags[i] = 0;
2555 token = g_scanner_peek_next_token (scanner);
2556 if (token == G_TOKEN_EQUAL_SIGN)
2558 token = g_scanner_get_next_token (scanner);
2560 token = g_scanner_get_next_token (scanner);
2561 if (token != G_TOKEN_STRING)
2563 token = G_TOKEN_STRING;
2567 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2572 for (i = 0; i < 5; i++)
2574 rc_style->color_flags[i] = parent_style->color_flags[i];
2575 rc_style->fg[i] = parent_style->fg[i];
2576 rc_style->bg[i] = parent_style->bg[i];
2577 rc_style->text[i] = parent_style->text[i];
2578 rc_style->base[i] = parent_style->base[i];
2581 rc_style->xthickness = parent_style->xthickness;
2582 rc_style->ythickness = parent_style->ythickness;
2584 if (parent_style->font_desc)
2586 if (rc_style->font_desc)
2587 pango_font_description_free (rc_style->font_desc);
2588 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2591 if (parent_style->rc_properties)
2595 for (i = 0; i < parent_style->rc_properties->len; i++)
2596 insert_rc_property (rc_style,
2597 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2601 for (i = 0; i < 5; i++)
2603 if (rc_style->bg_pixmap_name[i])
2604 g_free (rc_style->bg_pixmap_name[i]);
2605 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2608 /* Append parent's factories, adding a ref to them */
2609 if (parent_style->icon_factories != NULL)
2611 /* Add a factory for ourselves if we have none,
2612 * in case we end up defining more stock icons.
2613 * I see no real way around this; we need to maintain
2614 * the invariant that the first factory in the list
2615 * is always our_factory, the one belonging to us,
2616 * and if we put parent factories in the list we can't
2617 * do that if the style is reopened.
2619 if (our_factory == NULL)
2621 our_factory = gtk_icon_factory_new ();
2622 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2626 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2627 g_slist_copy (parent_style->icon_factories));
2629 factories = parent_style->icon_factories;
2630 while (factories != NULL)
2632 g_object_ref (factories->data);
2633 factories = factories->next;
2639 token = g_scanner_get_next_token (scanner);
2640 if (token != G_TOKEN_LEFT_CURLY)
2642 token = G_TOKEN_LEFT_CURLY;
2646 token = g_scanner_peek_next_token (scanner);
2647 while (token != G_TOKEN_RIGHT_CURLY)
2651 case GTK_RC_TOKEN_BG:
2652 token = gtk_rc_parse_bg (scanner, rc_style);
2654 case GTK_RC_TOKEN_FG:
2655 token = gtk_rc_parse_fg (scanner, rc_style);
2657 case GTK_RC_TOKEN_TEXT:
2658 token = gtk_rc_parse_text (scanner, rc_style);
2660 case GTK_RC_TOKEN_BASE:
2661 token = gtk_rc_parse_base (scanner, rc_style);
2663 case GTK_RC_TOKEN_XTHICKNESS:
2664 token = gtk_rc_parse_xthickness (scanner, rc_style);
2666 case GTK_RC_TOKEN_YTHICKNESS:
2667 token = gtk_rc_parse_ythickness (scanner, rc_style);
2669 case GTK_RC_TOKEN_BG_PIXMAP:
2670 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2672 case GTK_RC_TOKEN_FONT:
2673 token = gtk_rc_parse_font (scanner, rc_style);
2675 case GTK_RC_TOKEN_FONTSET:
2676 token = gtk_rc_parse_fontset (scanner, rc_style);
2678 case GTK_RC_TOKEN_FONT_NAME:
2679 token = gtk_rc_parse_font_name (scanner, rc_style);
2681 case GTK_RC_TOKEN_ENGINE:
2682 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2684 case GTK_RC_TOKEN_STOCK:
2685 if (our_factory == NULL)
2687 our_factory = gtk_icon_factory_new ();
2688 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2691 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2693 case G_TOKEN_IDENTIFIER:
2694 if (is_c_identifier (scanner->next_value.v_identifier) &&
2695 scanner->next_value.v_identifier[0] >= 'A' &&
2696 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2698 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2701 g_scanner_get_next_token (scanner); /* eat type name */
2702 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2703 if (g_scanner_get_next_token (scanner) != ':' ||
2704 g_scanner_get_next_token (scanner) != ':')
2709 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2710 !is_c_identifier (scanner->value.v_identifier))
2712 token = G_TOKEN_IDENTIFIER;
2716 /* it's important that we do the same canonification as GParamSpecPool here */
2717 name = g_strdup (scanner->value.v_identifier);
2718 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2719 prop.property_name = g_quark_from_string (name);
2722 token = gtk_rc_parse_assignment (scanner, &prop);
2723 if (token == G_TOKEN_NONE)
2725 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2726 insert_rc_property (rc_style, &prop, TRUE);
2729 g_free (prop.origin);
2730 if (G_VALUE_TYPE (&prop.value))
2731 g_value_unset (&prop.value);
2735 g_scanner_get_next_token (scanner);
2736 token = G_TOKEN_IDENTIFIER;
2740 g_scanner_get_next_token (scanner);
2741 token = G_TOKEN_RIGHT_CURLY;
2745 if (token != G_TOKEN_NONE)
2748 token = g_scanner_peek_next_token (scanner);
2749 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2751 token = g_scanner_get_next_token (scanner);
2752 if (token != G_TOKEN_RIGHT_CURLY)
2754 token = G_TOKEN_RIGHT_CURLY;
2758 if (rc_style != orig_style)
2760 if (!context->rc_style_ht)
2761 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2762 (GEqualFunc) gtk_rc_style_equal);
2764 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2766 /* If we copied the data into a new rc style, fix up references to the old rc style
2767 * in bindings that we have.
2770 fixup_rc_sets (context, orig_style, rc_style);
2774 g_object_unref (orig_style);
2776 return G_TOKEN_NONE;
2779 if (rc_style != orig_style)
2780 gtk_rc_style_unref (rc_style);
2783 g_object_unref (orig_style);
2788 const GtkRcProperty*
2789 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2791 GQuark property_name)
2793 GtkRcProperty *node = NULL;
2795 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2797 if (rc_style->rc_properties)
2801 key.type_name = type_name;
2802 key.property_name = property_name;
2804 node = bsearch (&key,
2805 rc_style->rc_properties->data, rc_style->rc_properties->len,
2806 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2813 gtk_rc_parse_bg (GScanner *scanner,
2819 token = g_scanner_get_next_token (scanner);
2820 if (token != GTK_RC_TOKEN_BG)
2821 return GTK_RC_TOKEN_BG;
2823 token = gtk_rc_parse_state (scanner, &state);
2824 if (token != G_TOKEN_NONE)
2827 token = g_scanner_get_next_token (scanner);
2828 if (token != G_TOKEN_EQUAL_SIGN)
2829 return G_TOKEN_EQUAL_SIGN;
2831 style->color_flags[state] |= GTK_RC_BG;
2832 return gtk_rc_parse_color (scanner, &style->bg[state]);
2836 gtk_rc_parse_fg (GScanner *scanner,
2842 token = g_scanner_get_next_token (scanner);
2843 if (token != GTK_RC_TOKEN_FG)
2844 return GTK_RC_TOKEN_FG;
2846 token = gtk_rc_parse_state (scanner, &state);
2847 if (token != G_TOKEN_NONE)
2850 token = g_scanner_get_next_token (scanner);
2851 if (token != G_TOKEN_EQUAL_SIGN)
2852 return G_TOKEN_EQUAL_SIGN;
2854 style->color_flags[state] |= GTK_RC_FG;
2855 return gtk_rc_parse_color (scanner, &style->fg[state]);
2859 gtk_rc_parse_text (GScanner *scanner,
2865 token = g_scanner_get_next_token (scanner);
2866 if (token != GTK_RC_TOKEN_TEXT)
2867 return GTK_RC_TOKEN_TEXT;
2869 token = gtk_rc_parse_state (scanner, &state);
2870 if (token != G_TOKEN_NONE)
2873 token = g_scanner_get_next_token (scanner);
2874 if (token != G_TOKEN_EQUAL_SIGN)
2875 return G_TOKEN_EQUAL_SIGN;
2877 style->color_flags[state] |= GTK_RC_TEXT;
2878 return gtk_rc_parse_color (scanner, &style->text[state]);
2882 gtk_rc_parse_base (GScanner *scanner,
2888 token = g_scanner_get_next_token (scanner);
2889 if (token != GTK_RC_TOKEN_BASE)
2890 return GTK_RC_TOKEN_BASE;
2892 token = gtk_rc_parse_state (scanner, &state);
2893 if (token != G_TOKEN_NONE)
2896 token = g_scanner_get_next_token (scanner);
2897 if (token != G_TOKEN_EQUAL_SIGN)
2898 return G_TOKEN_EQUAL_SIGN;
2900 style->color_flags[state] |= GTK_RC_BASE;
2901 return gtk_rc_parse_color (scanner, &style->base[state]);
2905 gtk_rc_parse_xthickness (GScanner *scanner,
2908 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2909 return GTK_RC_TOKEN_XTHICKNESS;
2911 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2912 return G_TOKEN_EQUAL_SIGN;
2914 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2917 style->xthickness = scanner->value.v_int;
2919 return G_TOKEN_NONE;
2923 gtk_rc_parse_ythickness (GScanner *scanner,
2926 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2927 return GTK_RC_TOKEN_YTHICKNESS;
2929 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2930 return G_TOKEN_EQUAL_SIGN;
2932 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2935 style->ythickness = scanner->value.v_int;
2937 return G_TOKEN_NONE;
2941 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2943 GtkRcStyle *rc_style)
2949 token = g_scanner_get_next_token (scanner);
2950 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2951 return GTK_RC_TOKEN_BG_PIXMAP;
2953 token = gtk_rc_parse_state (scanner, &state);
2954 if (token != G_TOKEN_NONE)
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 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2966 (strcmp (scanner->value.v_string, "<none>") == 0))
2967 pixmap_file = g_strdup (scanner->value.v_string);
2969 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2970 scanner, scanner->value.v_string);
2974 if (rc_style->bg_pixmap_name[state])
2975 g_free (rc_style->bg_pixmap_name[state]);
2976 rc_style->bg_pixmap_name[state] = pixmap_file;
2979 return G_TOKEN_NONE;
2983 gtk_rc_check_pixmap_dir (const gchar *dir,
2984 const gchar *pixmap_file)
2988 buf = g_build_filename (dir, pixmap_file, NULL);
2990 if (g_file_test (buf, G_FILE_TEST_EXISTS))
2999 * gtk_rc_find_pixmap_in_path:
3000 * @settings: a #GtkSettings
3001 * @scanner: Scanner used to get line number information for the
3002 * warning message, or %NULL
3003 * @pixmap_file: name of the pixmap file to locate.
3005 * Looks up a file in pixmap path for the specified #GtkSettings.
3006 * If the file is not found, it outputs a warning message using
3007 * g_warning() and returns %NULL.
3009 * Return value: the filename.
3012 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
3014 const gchar *pixmap_file)
3020 GtkRcContext *context = gtk_rc_context_get (settings);
3022 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
3024 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
3029 tmp_list = current_files_stack;
3032 GtkRcFile *curfile = tmp_list->data;
3033 filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
3037 tmp_list = tmp_list->next;
3041 g_scanner_warn (scanner,
3042 _("Unable to locate image file in pixmap_path: \"%s\""),
3045 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3052 * gtk_rc_find_module_in_path:
3053 * @module_file: name of a theme engine
3055 * Searches for a theme engine in the GTK+ search path. This function
3056 * is not useful for applications and should not be used.
3058 * Return value: The filename, if found (must be freed with g_free()),
3062 gtk_rc_find_module_in_path (const gchar *module_file)
3064 return _gtk_find_module (module_file, "engines");
3068 gtk_rc_parse_font (GScanner *scanner,
3069 GtkRcStyle *rc_style)
3073 token = g_scanner_get_next_token (scanner);
3074 if (token != GTK_RC_TOKEN_FONT)
3075 return GTK_RC_TOKEN_FONT;
3077 token = g_scanner_get_next_token (scanner);
3078 if (token != G_TOKEN_EQUAL_SIGN)
3079 return G_TOKEN_EQUAL_SIGN;
3081 token = g_scanner_get_next_token (scanner);
3082 if (token != G_TOKEN_STRING)
3083 return G_TOKEN_STRING;
3085 /* Ignore, do nothing */
3087 return G_TOKEN_NONE;
3091 gtk_rc_parse_fontset (GScanner *scanner,
3092 GtkRcStyle *rc_style)
3096 token = g_scanner_get_next_token (scanner);
3097 if (token != GTK_RC_TOKEN_FONTSET)
3098 return GTK_RC_TOKEN_FONTSET;
3100 token = g_scanner_get_next_token (scanner);
3101 if (token != G_TOKEN_EQUAL_SIGN)
3102 return G_TOKEN_EQUAL_SIGN;
3104 token = g_scanner_get_next_token (scanner);
3105 if (token != G_TOKEN_STRING)
3106 return G_TOKEN_STRING;
3108 /* Do nothing - silently ignore */
3110 return G_TOKEN_NONE;
3114 gtk_rc_parse_font_name (GScanner *scanner,
3115 GtkRcStyle *rc_style)
3119 token = g_scanner_get_next_token (scanner);
3120 if (token != GTK_RC_TOKEN_FONT_NAME)
3121 return GTK_RC_TOKEN_FONT;
3123 token = g_scanner_get_next_token (scanner);
3124 if (token != G_TOKEN_EQUAL_SIGN)
3125 return G_TOKEN_EQUAL_SIGN;
3127 token = g_scanner_get_next_token (scanner);
3128 if (token != G_TOKEN_STRING)
3129 return G_TOKEN_STRING;
3131 if (rc_style->font_desc)
3132 pango_font_description_free (rc_style->font_desc);
3134 rc_style->font_desc =
3135 pango_font_description_from_string (scanner->value.v_string);
3137 return G_TOKEN_NONE;
3141 gtk_rc_parse_engine (GtkRcContext *context,
3143 GtkRcStyle **rc_style)
3146 GtkThemeEngine *engine;
3147 guint result = G_TOKEN_NONE;
3148 GtkRcStyle *new_style = NULL;
3149 gboolean parsed_curlies = FALSE;
3151 token = g_scanner_get_next_token (scanner);
3152 if (token != GTK_RC_TOKEN_ENGINE)
3153 return GTK_RC_TOKEN_ENGINE;
3155 token = g_scanner_get_next_token (scanner);
3156 if (token != G_TOKEN_STRING)
3157 return G_TOKEN_STRING;
3159 if (!scanner->value.v_string[0])
3161 /* Support engine "" {} to mean override to the default engine
3163 token = g_scanner_get_next_token (scanner);
3164 if (token != G_TOKEN_LEFT_CURLY)
3165 return G_TOKEN_LEFT_CURLY;
3167 token = g_scanner_get_next_token (scanner);
3168 if (token != G_TOKEN_RIGHT_CURLY)
3169 return G_TOKEN_RIGHT_CURLY;
3171 parsed_curlies = TRUE;
3173 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3175 new_style = gtk_rc_style_new ();
3176 gtk_rc_style_real_merge (new_style, *rc_style);
3178 if ((*rc_style)->name)
3179 new_style->name = g_strdup ((*rc_style)->name);
3182 (*rc_style)->engine_specified = TRUE;
3186 engine = gtk_theme_engine_get (scanner->value.v_string);
3188 token = g_scanner_get_next_token (scanner);
3189 if (token != G_TOKEN_LEFT_CURLY)
3190 return G_TOKEN_LEFT_CURLY;
3194 GtkRcStyleClass *new_class;
3196 new_style = gtk_theme_engine_create_rc_style (engine);
3197 g_type_module_unuse (G_TYPE_MODULE (engine));
3199 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3201 new_class->merge (new_style, *rc_style);
3202 if ((*rc_style)->name)
3203 new_style->name = g_strdup ((*rc_style)->name);
3205 if (new_class->parse)
3207 parsed_curlies = TRUE;
3208 result = new_class->parse (new_style, context->settings, scanner);
3210 if (result != G_TOKEN_NONE)
3212 g_object_unref (new_style);
3219 if (!parsed_curlies)
3221 /* Skip over remainder, looking for nested {}'s
3225 result = G_TOKEN_RIGHT_CURLY;
3226 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3228 if (token == G_TOKEN_LEFT_CURLY)
3230 else if (token == G_TOKEN_RIGHT_CURLY)
3235 result = G_TOKEN_NONE;
3243 new_style->engine_specified = TRUE;
3245 g_object_unref (*rc_style);
3246 *rc_style = new_style;
3253 gtk_rc_parse_state (GScanner *scanner,
3254 GtkStateType *state)
3259 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3260 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3262 /* we don't know where we got called from, so we reset the scope here.
3263 * if we bail out due to errors, we *don't* reset the scope, so the
3264 * error messaging code can make sense of our tokens.
3266 old_scope = g_scanner_set_scope (scanner, 0);
3268 token = g_scanner_get_next_token (scanner);
3269 if (token != G_TOKEN_LEFT_BRACE)
3270 return G_TOKEN_LEFT_BRACE;
3272 token = g_scanner_get_next_token (scanner);
3275 case GTK_RC_TOKEN_ACTIVE:
3276 *state = GTK_STATE_ACTIVE;
3278 case GTK_RC_TOKEN_INSENSITIVE:
3279 *state = GTK_STATE_INSENSITIVE;
3281 case GTK_RC_TOKEN_NORMAL:
3282 *state = GTK_STATE_NORMAL;
3284 case GTK_RC_TOKEN_PRELIGHT:
3285 *state = GTK_STATE_PRELIGHT;
3287 case GTK_RC_TOKEN_SELECTED:
3288 *state = GTK_STATE_SELECTED;
3291 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3294 token = g_scanner_get_next_token (scanner);
3295 if (token != G_TOKEN_RIGHT_BRACE)
3296 return G_TOKEN_RIGHT_BRACE;
3298 g_scanner_set_scope (scanner, old_scope);
3300 return G_TOKEN_NONE;
3304 gtk_rc_parse_priority (GScanner *scanner,
3305 GtkPathPriorityType *priority)
3310 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3311 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3313 /* we don't know where we got called from, so we reset the scope here.
3314 * if we bail out due to errors, we *don't* reset the scope, so the
3315 * error messaging code can make sense of our tokens.
3317 old_scope = g_scanner_set_scope (scanner, 0);
3319 token = g_scanner_get_next_token (scanner);
3323 token = g_scanner_get_next_token (scanner);
3326 case GTK_RC_TOKEN_LOWEST:
3327 *priority = GTK_PATH_PRIO_LOWEST;
3329 case GTK_RC_TOKEN_GTK:
3330 *priority = GTK_PATH_PRIO_GTK;
3332 case GTK_RC_TOKEN_APPLICATION:
3333 *priority = GTK_PATH_PRIO_APPLICATION;
3335 case GTK_RC_TOKEN_THEME:
3336 *priority = GTK_PATH_PRIO_THEME;
3338 case GTK_RC_TOKEN_RC:
3339 *priority = GTK_PATH_PRIO_RC;
3341 case GTK_RC_TOKEN_HIGHEST:
3342 *priority = GTK_PATH_PRIO_HIGHEST;
3345 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3348 g_scanner_set_scope (scanner, old_scope);
3350 return G_TOKEN_NONE;
3354 gtk_rc_parse_color (GScanner *scanner,
3359 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3361 /* we don't need to set our own scope here, because
3362 * we don't need own symbols
3365 token = g_scanner_get_next_token (scanner);
3370 case G_TOKEN_LEFT_CURLY:
3371 token = g_scanner_get_next_token (scanner);
3372 if (token == G_TOKEN_INT)
3373 token_int = scanner->value.v_int;
3374 else if (token == G_TOKEN_FLOAT)
3375 token_int = scanner->value.v_float * 65535.0;
3377 return G_TOKEN_FLOAT;
3378 color->red = CLAMP (token_int, 0, 65535);
3380 token = g_scanner_get_next_token (scanner);
3381 if (token != G_TOKEN_COMMA)
3382 return G_TOKEN_COMMA;
3384 token = g_scanner_get_next_token (scanner);
3385 if (token == G_TOKEN_INT)
3386 token_int = scanner->value.v_int;
3387 else if (token == G_TOKEN_FLOAT)
3388 token_int = scanner->value.v_float * 65535.0;
3390 return G_TOKEN_FLOAT;
3391 color->green = CLAMP (token_int, 0, 65535);
3393 token = g_scanner_get_next_token (scanner);
3394 if (token != G_TOKEN_COMMA)
3395 return G_TOKEN_COMMA;
3397 token = g_scanner_get_next_token (scanner);
3398 if (token == G_TOKEN_INT)
3399 token_int = scanner->value.v_int;
3400 else if (token == G_TOKEN_FLOAT)
3401 token_int = scanner->value.v_float * 65535.0;
3403 return G_TOKEN_FLOAT;
3404 color->blue = CLAMP (token_int, 0, 65535);
3406 token = g_scanner_get_next_token (scanner);
3407 if (token != G_TOKEN_RIGHT_CURLY)
3408 return G_TOKEN_RIGHT_CURLY;
3409 return G_TOKEN_NONE;
3411 case G_TOKEN_STRING:
3412 if (!gdk_color_parse (scanner->value.v_string, color))
3414 g_scanner_warn (scanner, "Invalid color constant '%s'",
3415 scanner->value.v_string);
3416 return G_TOKEN_STRING;
3419 return G_TOKEN_NONE;
3422 return G_TOKEN_STRING;
3427 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3432 token = g_scanner_get_next_token (scanner);
3433 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3434 return GTK_RC_TOKEN_PIXMAP_PATH;
3436 token = g_scanner_get_next_token (scanner);
3437 if (token != G_TOKEN_STRING)
3438 return G_TOKEN_STRING;
3440 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3442 return G_TOKEN_NONE;
3446 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3448 const gchar *pix_path)
3451 gint start_offset = 0;
3455 /* free the old one, or just add to the old one ? */
3456 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3458 g_free (context->pixmap_path[path_num]);
3459 context->pixmap_path[path_num] = NULL;
3464 path_len = strlen (pix_path);
3466 for (end_offset = 0; end_offset <= path_len; end_offset++)
3468 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3469 (end_offset == path_len))
3471 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3472 if (g_path_is_absolute (path_element))
3474 context->pixmap_path[path_num] = path_element;
3476 context->pixmap_path[path_num] = NULL;
3480 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3481 path_element, scanner->input_name, scanner->line);
3482 g_free (path_element);
3485 start_offset = end_offset + 1;
3491 gtk_rc_parse_module_path (GScanner *scanner)
3495 token = g_scanner_get_next_token (scanner);
3496 if (token != GTK_RC_TOKEN_MODULE_PATH)
3497 return GTK_RC_TOKEN_MODULE_PATH;
3499 token = g_scanner_get_next_token (scanner);
3500 if (token != G_TOKEN_STRING)
3501 return G_TOKEN_STRING;
3503 g_warning ("module_path directive is now ignored\n");
3505 return G_TOKEN_NONE;
3509 gtk_rc_parse_im_module_file (GScanner *scanner)
3513 token = g_scanner_get_next_token (scanner);
3514 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3515 return GTK_RC_TOKEN_IM_MODULE_FILE;
3517 token = g_scanner_get_next_token (scanner);
3518 if (token != G_TOKEN_STRING)
3519 return G_TOKEN_STRING;
3522 g_free (im_module_file);
3524 im_module_file = g_strdup (scanner->value.v_string);
3526 return G_TOKEN_NONE;
3530 gtk_rc_parse_path_pattern (GtkRcContext *context,
3534 GtkPathType path_type;
3536 gboolean is_binding;
3537 GtkPathPriorityType priority = context->default_priority;
3539 token = g_scanner_get_next_token (scanner);
3542 case GTK_RC_TOKEN_WIDGET:
3543 path_type = GTK_PATH_WIDGET;
3545 case GTK_RC_TOKEN_WIDGET_CLASS:
3546 path_type = GTK_PATH_WIDGET_CLASS;
3548 case GTK_RC_TOKEN_CLASS:
3549 path_type = GTK_PATH_CLASS;
3552 return GTK_RC_TOKEN_WIDGET_CLASS;
3555 token = g_scanner_get_next_token (scanner);
3556 if (token != G_TOKEN_STRING)
3557 return G_TOKEN_STRING;
3559 pattern = g_strdup (scanner->value.v_string);
3561 token = g_scanner_get_next_token (scanner);
3562 if (token == GTK_RC_TOKEN_STYLE)
3564 else if (token == GTK_RC_TOKEN_BINDING)
3569 return GTK_RC_TOKEN_STYLE;
3572 if (g_scanner_peek_next_token (scanner) == ':')
3574 token = gtk_rc_parse_priority (scanner, &priority);
3575 if (token != G_TOKEN_NONE)
3582 token = g_scanner_get_next_token (scanner);
3583 if (token != G_TOKEN_STRING)
3586 return G_TOKEN_STRING;
3591 GtkBindingSet *binding;
3593 binding = gtk_binding_set_find (scanner->value.v_string);
3597 return G_TOKEN_STRING;
3599 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3603 GtkRcStyle *rc_style;
3606 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3611 return G_TOKEN_STRING;
3614 rc_set = g_new (GtkRcSet, 1);
3615 rc_set->pspec = g_pattern_spec_new (pattern);
3616 rc_set->rc_style = rc_style;
3617 rc_set->priority = priority;
3619 if (path_type == GTK_PATH_WIDGET)
3620 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3621 else if (path_type == GTK_PATH_WIDGET_CLASS)
3622 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3624 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3628 return G_TOKEN_NONE;
3632 gtk_rc_parse_stock_id (GScanner *scanner,
3637 token = g_scanner_get_next_token (scanner);
3638 if (token != G_TOKEN_LEFT_BRACE)
3639 return G_TOKEN_LEFT_BRACE;
3641 token = g_scanner_get_next_token (scanner);
3643 if (token != G_TOKEN_STRING)
3644 return G_TOKEN_STRING;
3646 *stock_id = g_strdup (scanner->value.v_string);
3648 token = g_scanner_get_next_token (scanner);
3649 if (token != G_TOKEN_RIGHT_BRACE)
3652 return G_TOKEN_RIGHT_BRACE;
3655 return G_TOKEN_NONE;
3659 gtk_rc_parse_icon_source (GtkRcContext *context,
3661 GtkIconSet *icon_set,
3662 gboolean *icon_set_valid)
3665 GtkIconSource *source;
3666 gchar *full_filename;
3668 token = g_scanner_get_next_token (scanner);
3669 if (token != G_TOKEN_LEFT_CURLY)
3670 return G_TOKEN_LEFT_CURLY;
3672 token = g_scanner_get_next_token (scanner);
3674 if (token != G_TOKEN_STRING && token != '@')
3675 return G_TOKEN_STRING;
3677 source = gtk_icon_source_new ();
3679 if (token == G_TOKEN_STRING)
3683 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3686 gtk_icon_source_set_filename (source, full_filename);
3687 g_free (full_filename);
3694 token = g_scanner_get_next_token (scanner);
3696 if (token != G_TOKEN_STRING)
3697 return G_TOKEN_STRING;
3699 gtk_icon_source_set_icon_name (source, scanner->value.v_string);
3702 /* We continue parsing even if we didn't find the pixmap so that rest of the
3703 * file is read, even if the syntax is bad. However we don't validate the
3704 * icon_set so the caller can choose not to install it.
3706 token = g_scanner_get_next_token (scanner);
3708 if (token == G_TOKEN_RIGHT_CURLY)
3710 else if (token != G_TOKEN_COMMA)
3712 gtk_icon_source_free (source);
3713 return G_TOKEN_COMMA;
3716 /* Get the direction */
3718 token = g_scanner_get_next_token (scanner);
3722 case GTK_RC_TOKEN_RTL:
3723 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3724 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3727 case GTK_RC_TOKEN_LTR:
3728 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3729 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3736 gtk_icon_source_free (source);
3737 return GTK_RC_TOKEN_RTL;
3741 token = g_scanner_get_next_token (scanner);
3743 if (token == G_TOKEN_RIGHT_CURLY)
3745 else if (token != G_TOKEN_COMMA)
3747 gtk_icon_source_free (source);
3748 return G_TOKEN_COMMA;
3753 token = g_scanner_get_next_token (scanner);
3757 case GTK_RC_TOKEN_NORMAL:
3758 gtk_icon_source_set_state_wildcarded (source, FALSE);
3759 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3762 case GTK_RC_TOKEN_PRELIGHT:
3763 gtk_icon_source_set_state_wildcarded (source, FALSE);
3764 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3768 case GTK_RC_TOKEN_INSENSITIVE:
3769 gtk_icon_source_set_state_wildcarded (source, FALSE);
3770 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3773 case GTK_RC_TOKEN_ACTIVE:
3774 gtk_icon_source_set_state_wildcarded (source, FALSE);
3775 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3778 case GTK_RC_TOKEN_SELECTED:
3779 gtk_icon_source_set_state_wildcarded (source, FALSE);
3780 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3787 gtk_icon_source_free (source);
3788 return GTK_RC_TOKEN_PRELIGHT;
3792 token = g_scanner_get_next_token (scanner);
3794 if (token == G_TOKEN_RIGHT_CURLY)
3796 else if (token != G_TOKEN_COMMA)
3798 gtk_icon_source_free (source);
3799 return G_TOKEN_COMMA;
3804 token = g_scanner_get_next_token (scanner);
3810 if (token != G_TOKEN_STRING)
3812 gtk_icon_source_free (source);
3813 return G_TOKEN_STRING;
3816 size = gtk_icon_size_from_name (scanner->value.v_string);
3818 if (size != GTK_ICON_SIZE_INVALID)
3820 gtk_icon_source_set_size_wildcarded (source, FALSE);
3821 gtk_icon_source_set_size (source, size);
3825 /* Check the close brace */
3827 token = g_scanner_get_next_token (scanner);
3828 if (token != G_TOKEN_RIGHT_CURLY)
3830 gtk_icon_source_free (source);
3831 return G_TOKEN_RIGHT_CURLY;
3835 if (gtk_icon_source_get_filename (source) ||
3836 gtk_icon_source_get_icon_name (source))
3838 gtk_icon_set_add_source (icon_set, source);
3839 *icon_set_valid = TRUE;
3841 gtk_icon_source_free (source);
3843 return G_TOKEN_NONE;
3847 gtk_rc_parse_stock (GtkRcContext *context,
3849 GtkRcStyle *rc_style,
3850 GtkIconFactory *factory)
3852 GtkIconSet *icon_set = NULL;
3853 gboolean icon_set_valid = FALSE;
3854 gchar *stock_id = NULL;
3857 token = g_scanner_get_next_token (scanner);
3858 if (token != GTK_RC_TOKEN_STOCK)
3859 return GTK_RC_TOKEN_STOCK;
3861 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3862 if (token != G_TOKEN_NONE)
3865 token = g_scanner_get_next_token (scanner);
3866 if (token != G_TOKEN_EQUAL_SIGN)
3869 return G_TOKEN_EQUAL_SIGN;
3872 token = g_scanner_get_next_token (scanner);
3873 if (token != G_TOKEN_LEFT_CURLY)
3876 return G_TOKEN_LEFT_CURLY;
3879 token = g_scanner_peek_next_token (scanner);
3880 while (token != G_TOKEN_RIGHT_CURLY)
3882 if (icon_set == NULL)
3883 icon_set = gtk_icon_set_new ();
3885 token = gtk_rc_parse_icon_source (context,
3886 scanner, icon_set, &icon_set_valid);
3887 if (token != G_TOKEN_NONE)
3890 gtk_icon_set_unref (icon_set);
3894 token = g_scanner_get_next_token (scanner);
3896 if (token != G_TOKEN_COMMA &&
3897 token != G_TOKEN_RIGHT_CURLY)
3900 gtk_icon_set_unref (icon_set);
3901 return G_TOKEN_RIGHT_CURLY;
3908 gtk_icon_factory_add (factory,
3912 gtk_icon_set_unref (icon_set);
3917 return G_TOKEN_NONE;
3922 /* DLL ABI stability backward compatibility versions */
3924 #undef gtk_rc_add_default_file
3927 gtk_rc_add_default_file (const gchar *filename)
3929 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
3931 gtk_rc_add_default_file_utf8 (utf8_filename);
3933 g_free (utf8_filename);
3936 #undef gtk_rc_set_default_files
3939 gtk_rc_set_default_files (gchar **filenames)
3941 gchar **utf8_filenames;
3944 while (filenames[n++] != NULL)
3947 utf8_filenames = g_new (gchar *, n + 1);
3949 for (i = 0; i < n; i++)
3950 utf8_filenames[i] = g_locale_to_utf8 (filenames[i], -1, NULL, NULL, NULL);
3952 utf8_filenames[n] = NULL;
3954 gtk_rc_set_default_files_utf8 (utf8_filenames);
3956 g_strfreev (utf8_filenames);
3962 gtk_rc_parse (const gchar *filename)
3964 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
3966 gtk_rc_parse_utf8 (utf8_filename);
3968 g_free (utf8_filename);
3973 #define __GTK_RC_C__
3974 #include "gtkaliasdef.c"