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 GtkStyle *style = value;
1340 GSList *tmp_list = rc_styles;
1342 g_object_unref (style);
1346 GtkRcStyle *rc_style = tmp_list->data;
1348 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1350 tmp_list = tmp_list->next;
1353 g_slist_free (rc_styles);
1357 * gtk_rc_reset_styles:
1358 * @settings: a #GtkSettings
1360 * This function recomputes the styles for all widgets that use a
1361 * particular #GtkSettings object. (There is one #GtkSettings object
1362 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1363 * when some global parameter has changed that affects the appearance
1364 * of all widgets, because when a widget gets a new style, it will
1365 * both redraw and recompute any cached information about its
1366 * appearance. As an example, it is used when the default font size
1367 * set by the operating system changes. Note that this function
1368 * doesn't affect widgets that have a style set explicitely on them
1369 * with gtk_widget_set_style().
1374 gtk_rc_reset_styles (GtkSettings *settings)
1376 GtkRcContext *context;
1377 gboolean reset = FALSE;
1379 g_return_if_fail (GTK_IS_SETTINGS (settings));
1381 context = gtk_rc_context_get (settings);
1383 if (context->default_style)
1385 g_object_unref (context->default_style);
1386 context->default_style = NULL;
1390 /* Clear out styles that have been looked up already
1392 if (realized_style_ht)
1394 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1395 g_hash_table_destroy (realized_style_ht);
1396 realized_style_ht = NULL;
1401 gtk_rc_reset_widgets (settings);
1405 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1407 GtkRcContext *context;
1408 gchar *new_font_name;
1410 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1412 context = gtk_rc_context_get (settings);
1414 g_object_get (context->settings,
1415 "gtk-font-name", &new_font_name,
1418 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1420 g_free (context->font_name);
1421 context->font_name = g_strdup (new_font_name);
1423 gtk_rc_reset_styles (settings);
1426 g_free (new_font_name);
1428 return context->font_name;
1432 * gtk_rc_reparse_all_for_settings:
1433 * @settings: a #GtkSettings
1434 * @force_load: load whether or not anything changed
1436 * If the modification time on any previously read file
1437 * for the given #GtkSettings has changed, discard all style information
1438 * and then reread all previously read RC files.
1440 * Return value: %TRUE if the files were reread.
1443 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1444 gboolean force_load)
1446 gboolean mtime_modified = FALSE;
1449 GtkRcContext *context;
1451 struct stat statbuf;
1453 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1455 context = gtk_rc_context_get (settings);
1459 /* Check through and see if any of the RC's have had their
1460 * mtime modified. If so, reparse everything.
1462 tmp_list = context->rc_files;
1465 rc_file = tmp_list->data;
1467 if (!rc_file->is_string)
1469 if (!g_lstat (rc_file->name, &statbuf) &&
1470 (statbuf.st_mtime > rc_file->mtime))
1472 mtime_modified = TRUE;
1477 tmp_list = tmp_list->next;
1481 if (force_load || mtime_modified)
1483 _gtk_binding_reset_parsed ();
1484 gtk_rc_clear_styles (context);
1485 g_object_freeze_notify (G_OBJECT (context->settings));
1487 _gtk_settings_reset_rc_values (context->settings);
1488 tmp_list = context->rc_files;
1491 rc_file = tmp_list->data;
1493 if (rc_file->canonical_name != rc_file->name)
1494 g_free (rc_file->canonical_name);
1495 g_free (rc_file->directory);
1496 g_free (rc_file->name);
1499 tmp_list = tmp_list->next;
1502 g_slist_free (context->rc_files);
1503 context->rc_files = NULL;
1505 gtk_rc_parse_default_files (context);
1507 tmp_list = global_rc_files;
1510 rc_file = tmp_list->data;
1512 if (rc_file->is_string)
1513 gtk_rc_context_parse_string (context, rc_file->name);
1515 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1517 tmp_list = tmp_list->next;
1520 g_free (context->theme_name);
1521 g_free (context->key_theme_name);
1523 g_object_get (context->settings,
1524 "gtk-theme-name", &context->theme_name,
1525 "gtk-key-theme-name", &context->key_theme_name,
1528 if (context->theme_name && context->theme_name[0])
1529 gtk_rc_parse_named (context, context->theme_name, NULL);
1530 if (context->key_theme_name && context->key_theme_name[0])
1531 gtk_rc_parse_named (context, context->key_theme_name, "key");
1533 g_object_thaw_notify (G_OBJECT (context->settings));
1535 gtk_rc_reset_widgets (context->settings);
1538 return force_load || mtime_modified;
1542 * gtk_rc_reparse_all:
1544 * If the modification time on any previously read file for the
1545 * default #GtkSettings has changed, discard all style information
1546 * and then reread all previously read RC files.
1548 * Return value: %TRUE if the files were reread.
1551 gtk_rc_reparse_all (void)
1554 gboolean result = FALSE;
1556 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1558 GtkRcContext *context = tmp_list->data;
1559 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1567 gtk_rc_styles_match (GSList *rc_styles,
1571 const gchar *path_reversed)
1578 rc_set = sets->data;
1581 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1582 rc_styles = g_slist_append (rc_styles, rc_set);
1589 rc_set_compare (gconstpointer a, gconstpointer b)
1591 const GtkRcSet *set_a = a;
1592 const GtkRcSet *set_b = b;
1594 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1598 sort_and_dereference_sets (GSList *styles)
1602 /* At this point, the list of sets is ordered by:
1604 * a) 'widget' patterns are earlier than 'widget_class' patterns
1605 * which are ealier than 'class' patterns.
1606 * a) For two matches for class patterns, a match to a child type
1607 * is before a match to a parent type
1608 * c) a match later in the RC file (or in a later RC file) is before a
1609 * match earlier in the RC file.
1611 * With a) taking precedence over b) which takes precendence over c).
1613 * Now sort by priority, which has the highest precendence for sort order
1615 styles = g_slist_sort (styles, rc_set_compare);
1617 /* Make styles->data = styles->data->rc_style
1622 GtkRcSet *set = tmp_list->data;
1623 tmp_list->data = set->rc_style;
1624 tmp_list = tmp_list->next;
1632 * @widget: a #GtkWidget
1634 * Finds all matching RC styles for a given widget,
1635 * composites them together, and then creates a
1636 * #GtkStyle representing the composite appearance.
1637 * (GTK+ actually keeps a cache of previously
1638 * created styles, so a new style may not be
1641 * Returns: the resulting style. No refcount is added
1642 * to the returned style, so if you want to save this
1643 * style around, you should add a reference yourself.
1646 gtk_rc_get_style (GtkWidget *widget)
1648 GtkRcStyle *widget_rc_style;
1649 GSList *rc_styles = NULL;
1650 GtkRcContext *context;
1652 static guint rc_style_key_id = 0;
1654 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1656 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1658 /* We allow the specification of a single rc style to be bound
1659 * tightly to a widget, for application modifications
1661 if (!rc_style_key_id)
1662 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1664 if (context->rc_sets_widget)
1666 gchar *path, *path_reversed;
1669 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1670 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1672 g_free (path_reversed);
1675 if (context->rc_sets_widget_class)
1677 gchar *path, *path_reversed;
1680 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1681 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1683 g_free (path_reversed);
1686 if (context->rc_sets_class)
1690 type = G_TYPE_FROM_INSTANCE (widget);
1694 gchar *path_reversed;
1697 path = g_type_name (type);
1698 path_length = strlen (path);
1699 path_reversed = g_strdup (path);
1700 g_strreverse (path_reversed);
1702 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1703 g_free (path_reversed);
1705 type = g_type_parent (type);
1709 rc_styles = sort_and_dereference_sets (rc_styles);
1711 widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
1713 if (widget_rc_style)
1714 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1717 return gtk_rc_init_style (context, rc_styles);
1720 if (!context->default_style)
1722 context->default_style = gtk_style_new ();
1723 _gtk_style_init_for_settings (context->default_style, context->settings);
1726 return context->default_style;
1731 * gtk_rc_get_style_by_paths:
1732 * @settings: a #GtkSettings object
1733 * @widget_path: the widget path to use when looking up the style, or %NULL
1734 * if no matching against the widget path should be done
1735 * @class_path: the class path to use when looking up the style, or %NULL
1736 * if no matching against the class path should be done.
1737 * @type: a type that will be used along with parent types of this type
1738 * when matching against class styles, or #G_TYPE_NONE
1740 * Creates up a #GtkStyle from styles defined in a RC file by providing
1741 * the raw components used in matching. This function may be useful
1742 * when creating pseudo-widgets that should be themed like widgets but
1743 * don't actually have corresponding GTK+ widgets. An example of this
1744 * would be items inside a GNOME canvas widget.
1746 * The action of gtk_rc_get_style() is similar to:
1747 * <informalexample><programlisting>
1748 * gtk_widget_path (widget, NULL, &path, NULL);
1749 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1750 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1751 * G_OBJECT_TYPE (widget));
1752 * </programlisting></informalexample>
1754 * Return value: A style created by matching with the supplied paths,
1755 * or %NULL if nothing matching was specified and the default style should
1756 * be used. The returned value is owned by GTK+ as part of an internal cache,
1757 * so you must call g_object_ref() on the returned value if you want to
1758 * keep a reference to it.
1761 gtk_rc_get_style_by_paths (GtkSettings *settings,
1762 const char *widget_path,
1763 const char *class_path,
1766 /* We duplicate the code from above to avoid slowing down the above
1767 * by generating paths when we don't need them. I don't know if
1768 * this is really worth it.
1770 GSList *rc_styles = NULL;
1771 GtkRcContext *context;
1773 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1775 context = gtk_rc_context_get (settings);
1777 if (widget_path && context->rc_sets_widget)
1779 gchar *path_reversed;
1782 path_length = strlen (widget_path);
1783 path_reversed = g_strdup (widget_path);
1784 g_strreverse (path_reversed);
1786 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1787 g_free (path_reversed);
1790 if (class_path && context->rc_sets_widget_class)
1792 gchar *path_reversed;
1795 path_length = strlen (class_path);
1796 path_reversed = g_strdup (class_path);
1797 g_strreverse (path_reversed);
1799 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1800 g_free (path_reversed);
1803 if (type != G_TYPE_NONE && context->rc_sets_class)
1808 gchar *path_reversed;
1811 path = g_type_name (type);
1812 path_length = strlen (path);
1813 path_reversed = g_strdup (path);
1814 g_strreverse (path_reversed);
1816 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1817 g_free (path_reversed);
1819 type = g_type_parent (type);
1823 rc_styles = sort_and_dereference_sets (rc_styles);
1826 return gtk_rc_init_style (context, rc_styles);
1832 gtk_rc_add_rc_sets (GSList *slist,
1833 GtkRcStyle *rc_style,
1834 const gchar *pattern)
1836 GtkRcStyle *new_style;
1840 new_style = gtk_rc_style_new ();
1841 *new_style = *rc_style;
1842 new_style->name = g_strdup (rc_style->name);
1843 if (rc_style->font_desc)
1844 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1846 for (i = 0; i < 5; i++)
1847 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1849 rc_set = g_new (GtkRcSet, 1);
1850 rc_set->pspec = g_pattern_spec_new (pattern);
1851 rc_set->rc_style = rc_style;
1853 return g_slist_prepend (slist, rc_set);
1857 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1858 const gchar *pattern)
1860 GtkRcContext *context;
1862 g_return_if_fail (rc_style != NULL);
1863 g_return_if_fail (pattern != NULL);
1865 context = gtk_rc_context_get (gtk_settings_get_default ());
1867 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1871 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1872 const gchar *pattern)
1874 GtkRcContext *context;
1876 g_return_if_fail (rc_style != NULL);
1877 g_return_if_fail (pattern != NULL);
1879 context = gtk_rc_context_get (gtk_settings_get_default ());
1881 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1885 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1886 const gchar *pattern)
1888 GtkRcContext *context;
1890 g_return_if_fail (rc_style != NULL);
1891 g_return_if_fail (pattern != NULL);
1893 context = gtk_rc_context_get (gtk_settings_get_default ());
1895 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1899 gtk_rc_scanner_new (void)
1901 return g_scanner_new (>k_rc_scanner_config);
1905 gtk_rc_parse_any (GtkRcContext *context,
1906 const gchar *input_name,
1908 const gchar *input_string)
1914 scanner = gtk_rc_scanner_new ();
1918 g_assert (input_string == NULL);
1920 g_scanner_input_file (scanner, input_fd);
1924 g_assert (input_string != NULL);
1926 g_scanner_input_text (scanner, input_string, strlen (input_string));
1928 scanner->input_name = input_name;
1930 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1931 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1936 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1940 guint expected_token;
1942 expected_token = gtk_rc_parse_statement (context, scanner);
1944 if (expected_token != G_TOKEN_NONE)
1951 if (scanner->scope_id == 0)
1953 /* if we are in scope 0, we know the symbol names
1954 * that are associated with certain token values.
1955 * so we look them up to make the error messages
1958 if (expected_token > GTK_RC_TOKEN_INVALID &&
1959 expected_token < GTK_RC_TOKEN_LAST)
1961 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1962 if (symbols[i].token == expected_token)
1963 msg = symbols[i].name;
1965 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1967 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1968 scanner->token < GTK_RC_TOKEN_LAST)
1970 symbol_name = "???";
1971 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1972 if (symbols[i].token == scanner->token)
1973 symbol_name = symbols[i].name;
1976 g_scanner_unexp_token (scanner,
1989 g_scanner_destroy (scanner);
1993 gtk_rc_styles_hash (const GSList *rc_styles)
2000 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
2001 rc_styles = rc_styles->next;
2008 gtk_rc_styles_equal (const GSList *a,
2013 if (a->data != b->data)
2023 gtk_rc_style_hash (const gchar *name)
2029 result += (result << 3) + *name++;
2035 gtk_rc_style_equal (const gchar *a,
2038 return (strcmp (a, b) == 0);
2042 gtk_rc_style_find (GtkRcContext *context,
2045 if (context->rc_style_ht)
2046 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2052 gtk_rc_style_to_style (GtkRcContext *context,
2053 GtkRcStyle *rc_style)
2057 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2058 _gtk_style_init_for_settings (style, context->settings);
2060 style->rc_style = rc_style;
2062 gtk_rc_style_ref (rc_style);
2064 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2069 /* Reuses or frees rc_styles */
2071 gtk_rc_init_style (GtkRcContext *context,
2074 GtkStyle *style = NULL;
2077 g_return_val_if_fail (rc_styles != NULL, NULL);
2079 if (!realized_style_ht)
2080 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2081 (GEqualFunc) gtk_rc_styles_equal);
2083 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2087 GtkRcStyle *base_style = NULL;
2088 GtkRcStyle *proto_style;
2089 GtkRcStyleClass *proto_style_class;
2091 GType rc_style_type = GTK_TYPE_RC_STYLE;
2093 /* Find the first style where the RC file specified engine "" {}
2094 * or the first derived style and use that to create the
2095 * merged style. If we only have raw GtkRcStyles, use the first
2096 * style to create the merged style.
2098 base_style = rc_styles->data;
2099 tmp_styles = rc_styles;
2102 GtkRcStyle *rc_style = tmp_styles->data;
2104 if (rc_style->engine_specified ||
2105 G_OBJECT_TYPE (rc_style) != rc_style_type)
2107 base_style = rc_style;
2111 tmp_styles = tmp_styles->next;
2114 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2115 proto_style = proto_style_class->create_rc_style (base_style);
2117 tmp_styles = rc_styles;
2120 GtkRcStyle *rc_style = tmp_styles->data;
2123 proto_style_class->merge (proto_style, rc_style);
2125 /* Point from each rc_style to the list of styles */
2126 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2127 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2129 factories = g_slist_copy (rc_style->icon_factories);
2135 while (iter != NULL)
2137 g_object_ref (iter->data);
2138 iter = g_slist_next (iter);
2141 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2146 tmp_styles = tmp_styles->next;
2149 for (i = 0; i < 5; i++)
2150 if (proto_style->bg_pixmap_name[i] &&
2151 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2153 g_free (proto_style->bg_pixmap_name[i]);
2154 proto_style->bg_pixmap_name[i] = NULL;
2157 style = gtk_rc_style_to_style (context, proto_style);
2158 gtk_rc_style_unref (proto_style);
2160 g_hash_table_insert (realized_style_ht, rc_styles, style);
2163 g_slist_free (rc_styles);
2168 /*********************
2169 * Parsing functions *
2170 *********************/
2173 rc_parse_token_or_compound (GScanner *scanner,
2175 GTokenType delimiter)
2177 guint token = g_scanner_get_next_token (scanner);
2179 /* we either scan a single token (skipping comments)
2180 * or a compund statement.
2181 * compunds are enclosed in (), [] or {} braces, we read
2182 * them in via deep recursion.
2189 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2192 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2194 case G_TOKEN_STRING:
2195 string = g_strescape (scanner->value.v_string, NULL);
2196 g_string_append (gstring, " \"");
2197 g_string_append (gstring, string);
2198 g_string_append_c (gstring, '"');
2201 case G_TOKEN_IDENTIFIER:
2202 g_string_append_c (gstring, ' ');
2203 g_string_append (gstring, scanner->value.v_identifier);
2205 case G_TOKEN_COMMENT_SINGLE:
2206 case G_TOKEN_COMMENT_MULTI:
2207 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2208 case G_TOKEN_LEFT_PAREN:
2209 g_string_append_c (gstring, ' ');
2210 g_string_append_c (gstring, token);
2211 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2212 if (token != G_TOKEN_NONE)
2215 case G_TOKEN_LEFT_CURLY:
2216 g_string_append_c (gstring, ' ');
2217 g_string_append_c (gstring, token);
2218 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2219 if (token != G_TOKEN_NONE)
2222 case G_TOKEN_LEFT_BRACE:
2223 g_string_append_c (gstring, ' ');
2224 g_string_append_c (gstring, token);
2225 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2226 if (token != G_TOKEN_NONE)
2230 if (token >= 256 || token < 1)
2231 return delimiter ? delimiter : G_TOKEN_STRING;
2232 g_string_append_c (gstring, ' ');
2233 g_string_append_c (gstring, token);
2234 if (token == delimiter)
2235 return G_TOKEN_NONE;
2239 return G_TOKEN_NONE;
2241 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2245 gtk_rc_parse_assignment (GScanner *scanner,
2246 GtkRcProperty *prop)
2248 gboolean scan_identifier = scanner->config->scan_identifier;
2249 gboolean scan_symbols = scanner->config->scan_symbols;
2250 gboolean identifier_2_string = scanner->config->identifier_2_string;
2251 gboolean char_2_token = scanner->config->char_2_token;
2252 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2253 gboolean numbers_2_int = scanner->config->numbers_2_int;
2254 gboolean negate = FALSE;
2257 /* check that this is an assignment */
2258 if (g_scanner_get_next_token (scanner) != '=')
2261 /* adjust scanner mode */
2262 scanner->config->scan_identifier = TRUE;
2263 scanner->config->scan_symbols = FALSE;
2264 scanner->config->identifier_2_string = FALSE;
2265 scanner->config->char_2_token = TRUE;
2266 scanner->config->scan_identifier_NULL = FALSE;
2267 scanner->config->numbers_2_int = TRUE;
2269 /* record location */
2270 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2272 /* parse optional sign */
2273 if (g_scanner_peek_next_token (scanner) == '-')
2275 g_scanner_get_next_token (scanner); /* eat sign */
2279 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2280 token = g_scanner_peek_next_token (scanner);
2284 g_scanner_get_next_token (scanner);
2285 g_value_init (&prop->value, G_TYPE_LONG);
2286 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2287 token = G_TOKEN_NONE;
2290 g_scanner_get_next_token (scanner);
2291 g_value_init (&prop->value, G_TYPE_DOUBLE);
2292 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2293 token = G_TOKEN_NONE;
2295 case G_TOKEN_STRING:
2296 g_scanner_get_next_token (scanner);
2298 token = G_TOKEN_INT;
2301 g_value_init (&prop->value, G_TYPE_STRING);
2302 g_value_set_string (&prop->value, scanner->value.v_string);
2303 token = G_TOKEN_NONE;
2306 case G_TOKEN_IDENTIFIER:
2307 case G_TOKEN_LEFT_PAREN:
2308 case G_TOKEN_LEFT_CURLY:
2309 case G_TOKEN_LEFT_BRACE:
2312 GString *gstring = g_string_new (NULL);
2314 token = rc_parse_token_or_compound (scanner, gstring, 0);
2315 if (token == G_TOKEN_NONE)
2317 g_string_append_c (gstring, ' ');
2318 g_value_init (&prop->value, G_TYPE_GSTRING);
2319 g_value_take_boxed (&prop->value, gstring);
2322 g_string_free (gstring, TRUE);
2327 g_scanner_get_next_token (scanner);
2328 token = G_TOKEN_INT;
2332 /* restore scanner mode */
2333 scanner->config->scan_identifier = scan_identifier;
2334 scanner->config->scan_symbols = scan_symbols;
2335 scanner->config->identifier_2_string = identifier_2_string;
2336 scanner->config->char_2_token = char_2_token;
2337 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2338 scanner->config->numbers_2_int = numbers_2_int;
2344 is_c_identifier (const gchar *string)
2347 gboolean is_varname;
2349 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2350 for (p = string + 1; *p && is_varname; p++)
2351 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2357 parse_include_file (GtkRcContext *context,
2359 const gchar *filename)
2361 char *to_parse = NULL;
2363 if (g_path_is_absolute (filename))
2365 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2366 * don't print an error in this case.
2368 to_parse = g_strdup (filename);
2372 /* if a relative path, we look relative to all the RC files in the
2373 * include stack. We require the file to be found in this case
2374 * so we can give meaningful error messages, and because on reparsing
2375 * non-absolute paths don't make sense.
2377 GSList *tmp_list = current_files_stack;
2380 GtkRcFile *curfile = tmp_list->data;
2381 gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
2383 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2391 tmp_list = tmp_list->next;
2397 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2402 g_scanner_warn (scanner,
2403 _("Unable to find include file: \"%s\""),
2410 gtk_rc_parse_statement (GtkRcContext *context,
2415 token = g_scanner_peek_next_token (scanner);
2418 case GTK_RC_TOKEN_INCLUDE:
2419 token = g_scanner_get_next_token (scanner);
2420 if (token != GTK_RC_TOKEN_INCLUDE)
2421 return GTK_RC_TOKEN_INCLUDE;
2422 token = g_scanner_get_next_token (scanner);
2423 if (token != G_TOKEN_STRING)
2424 return G_TOKEN_STRING;
2425 parse_include_file (context, scanner, scanner->value.v_string);
2426 return G_TOKEN_NONE;
2428 case GTK_RC_TOKEN_STYLE:
2429 return gtk_rc_parse_style (context, scanner);
2431 case GTK_RC_TOKEN_BINDING:
2432 return gtk_binding_parse_binding (scanner);
2434 case GTK_RC_TOKEN_PIXMAP_PATH:
2435 return gtk_rc_parse_pixmap_path (context, scanner);
2437 case GTK_RC_TOKEN_WIDGET:
2438 return gtk_rc_parse_path_pattern (context, scanner);
2440 case GTK_RC_TOKEN_WIDGET_CLASS:
2441 return gtk_rc_parse_path_pattern (context, scanner);
2443 case GTK_RC_TOKEN_CLASS:
2444 return gtk_rc_parse_path_pattern (context, scanner);
2446 case GTK_RC_TOKEN_MODULE_PATH:
2447 return gtk_rc_parse_module_path (scanner);
2449 case GTK_RC_TOKEN_IM_MODULE_FILE:
2450 return gtk_rc_parse_im_module_file (scanner);
2452 case G_TOKEN_IDENTIFIER:
2453 if (is_c_identifier (scanner->next_value.v_identifier))
2455 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2458 g_scanner_get_next_token (scanner); /* eat identifier */
2459 name = g_strdup (scanner->value.v_identifier);
2461 token = gtk_rc_parse_assignment (scanner, &prop);
2462 if (token == G_TOKEN_NONE)
2464 GtkSettingsValue svalue;
2466 svalue.origin = prop.origin;
2467 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2468 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2469 _gtk_settings_set_property_value_from_rc (context->settings,
2473 g_free (prop.origin);
2474 if (G_VALUE_TYPE (&prop.value))
2475 g_value_unset (&prop.value);
2482 g_scanner_get_next_token (scanner);
2483 return G_TOKEN_IDENTIFIER;
2486 g_scanner_get_next_token (scanner);
2487 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2492 fixup_rc_set (GSList *list,
2498 GtkRcSet *set = list->data;
2499 if (set->rc_style == orig)
2500 set->rc_style = new;
2506 fixup_rc_sets (GtkRcContext *context,
2510 fixup_rc_set (context->rc_sets_widget, orig, new);
2511 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2512 fixup_rc_set (context->rc_sets_class, orig, new);
2516 gtk_rc_parse_style (GtkRcContext *context,
2519 GtkRcStyle *rc_style;
2520 GtkRcStyle *orig_style;
2521 GtkRcStyle *parent_style;
2524 GtkIconFactory *our_factory = NULL;
2526 token = g_scanner_get_next_token (scanner);
2527 if (token != GTK_RC_TOKEN_STYLE)
2528 return GTK_RC_TOKEN_STYLE;
2530 token = g_scanner_get_next_token (scanner);
2531 if (token != G_TOKEN_STRING)
2532 return G_TOKEN_STRING;
2534 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2536 orig_style = g_object_ref (rc_style);
2540 /* If there's a list, its first member is always the factory belonging
2543 if (rc_style && rc_style->icon_factories)
2544 our_factory = rc_style->icon_factories->data;
2548 rc_style = gtk_rc_style_new ();
2549 rc_style->name = g_strdup (scanner->value.v_string);
2551 for (i = 0; i < 5; i++)
2552 rc_style->bg_pixmap_name[i] = NULL;
2554 for (i = 0; i < 5; i++)
2555 rc_style->color_flags[i] = 0;
2558 token = g_scanner_peek_next_token (scanner);
2559 if (token == G_TOKEN_EQUAL_SIGN)
2561 token = g_scanner_get_next_token (scanner);
2563 token = g_scanner_get_next_token (scanner);
2564 if (token != G_TOKEN_STRING)
2566 token = G_TOKEN_STRING;
2570 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2575 for (i = 0; i < 5; i++)
2577 rc_style->color_flags[i] = parent_style->color_flags[i];
2578 rc_style->fg[i] = parent_style->fg[i];
2579 rc_style->bg[i] = parent_style->bg[i];
2580 rc_style->text[i] = parent_style->text[i];
2581 rc_style->base[i] = parent_style->base[i];
2584 rc_style->xthickness = parent_style->xthickness;
2585 rc_style->ythickness = parent_style->ythickness;
2587 if (parent_style->font_desc)
2589 if (rc_style->font_desc)
2590 pango_font_description_free (rc_style->font_desc);
2591 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2594 if (parent_style->rc_properties)
2598 for (i = 0; i < parent_style->rc_properties->len; i++)
2599 insert_rc_property (rc_style,
2600 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2604 for (i = 0; i < 5; i++)
2606 if (rc_style->bg_pixmap_name[i])
2607 g_free (rc_style->bg_pixmap_name[i]);
2608 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2611 /* Append parent's factories, adding a ref to them */
2612 if (parent_style->icon_factories != NULL)
2614 /* Add a factory for ourselves if we have none,
2615 * in case we end up defining more stock icons.
2616 * I see no real way around this; we need to maintain
2617 * the invariant that the first factory in the list
2618 * is always our_factory, the one belonging to us,
2619 * and if we put parent factories in the list we can't
2620 * do that if the style is reopened.
2622 if (our_factory == NULL)
2624 our_factory = gtk_icon_factory_new ();
2625 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2629 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2630 g_slist_copy (parent_style->icon_factories));
2632 factories = parent_style->icon_factories;
2633 while (factories != NULL)
2635 g_object_ref (factories->data);
2636 factories = factories->next;
2642 token = g_scanner_get_next_token (scanner);
2643 if (token != G_TOKEN_LEFT_CURLY)
2645 token = G_TOKEN_LEFT_CURLY;
2649 token = g_scanner_peek_next_token (scanner);
2650 while (token != G_TOKEN_RIGHT_CURLY)
2654 case GTK_RC_TOKEN_BG:
2655 token = gtk_rc_parse_bg (scanner, rc_style);
2657 case GTK_RC_TOKEN_FG:
2658 token = gtk_rc_parse_fg (scanner, rc_style);
2660 case GTK_RC_TOKEN_TEXT:
2661 token = gtk_rc_parse_text (scanner, rc_style);
2663 case GTK_RC_TOKEN_BASE:
2664 token = gtk_rc_parse_base (scanner, rc_style);
2666 case GTK_RC_TOKEN_XTHICKNESS:
2667 token = gtk_rc_parse_xthickness (scanner, rc_style);
2669 case GTK_RC_TOKEN_YTHICKNESS:
2670 token = gtk_rc_parse_ythickness (scanner, rc_style);
2672 case GTK_RC_TOKEN_BG_PIXMAP:
2673 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2675 case GTK_RC_TOKEN_FONT:
2676 token = gtk_rc_parse_font (scanner, rc_style);
2678 case GTK_RC_TOKEN_FONTSET:
2679 token = gtk_rc_parse_fontset (scanner, rc_style);
2681 case GTK_RC_TOKEN_FONT_NAME:
2682 token = gtk_rc_parse_font_name (scanner, rc_style);
2684 case GTK_RC_TOKEN_ENGINE:
2685 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2687 case GTK_RC_TOKEN_STOCK:
2688 if (our_factory == NULL)
2690 our_factory = gtk_icon_factory_new ();
2691 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2694 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2696 case G_TOKEN_IDENTIFIER:
2697 if (is_c_identifier (scanner->next_value.v_identifier) &&
2698 scanner->next_value.v_identifier[0] >= 'A' &&
2699 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2701 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2704 g_scanner_get_next_token (scanner); /* eat type name */
2705 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2706 if (g_scanner_get_next_token (scanner) != ':' ||
2707 g_scanner_get_next_token (scanner) != ':')
2712 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2713 !is_c_identifier (scanner->value.v_identifier))
2715 token = G_TOKEN_IDENTIFIER;
2719 /* it's important that we do the same canonification as GParamSpecPool here */
2720 name = g_strdup (scanner->value.v_identifier);
2721 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2722 prop.property_name = g_quark_from_string (name);
2725 token = gtk_rc_parse_assignment (scanner, &prop);
2726 if (token == G_TOKEN_NONE)
2728 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2729 insert_rc_property (rc_style, &prop, TRUE);
2732 g_free (prop.origin);
2733 if (G_VALUE_TYPE (&prop.value))
2734 g_value_unset (&prop.value);
2738 g_scanner_get_next_token (scanner);
2739 token = G_TOKEN_IDENTIFIER;
2743 g_scanner_get_next_token (scanner);
2744 token = G_TOKEN_RIGHT_CURLY;
2748 if (token != G_TOKEN_NONE)
2751 token = g_scanner_peek_next_token (scanner);
2752 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2754 token = g_scanner_get_next_token (scanner);
2755 if (token != G_TOKEN_RIGHT_CURLY)
2757 token = G_TOKEN_RIGHT_CURLY;
2761 if (rc_style != orig_style)
2763 if (!context->rc_style_ht)
2764 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2765 (GEqualFunc) gtk_rc_style_equal);
2767 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2769 /* If we copied the data into a new rc style, fix up references to the old rc style
2770 * in bindings that we have.
2773 fixup_rc_sets (context, orig_style, rc_style);
2777 g_object_unref (orig_style);
2779 return G_TOKEN_NONE;
2782 if (rc_style != orig_style)
2783 gtk_rc_style_unref (rc_style);
2786 g_object_unref (orig_style);
2791 const GtkRcProperty*
2792 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2794 GQuark property_name)
2796 GtkRcProperty *node = NULL;
2798 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2800 if (rc_style->rc_properties)
2804 key.type_name = type_name;
2805 key.property_name = property_name;
2807 node = bsearch (&key,
2808 rc_style->rc_properties->data, rc_style->rc_properties->len,
2809 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2816 gtk_rc_parse_bg (GScanner *scanner,
2822 token = g_scanner_get_next_token (scanner);
2823 if (token != GTK_RC_TOKEN_BG)
2824 return GTK_RC_TOKEN_BG;
2826 token = gtk_rc_parse_state (scanner, &state);
2827 if (token != G_TOKEN_NONE)
2830 token = g_scanner_get_next_token (scanner);
2831 if (token != G_TOKEN_EQUAL_SIGN)
2832 return G_TOKEN_EQUAL_SIGN;
2834 style->color_flags[state] |= GTK_RC_BG;
2835 return gtk_rc_parse_color (scanner, &style->bg[state]);
2839 gtk_rc_parse_fg (GScanner *scanner,
2845 token = g_scanner_get_next_token (scanner);
2846 if (token != GTK_RC_TOKEN_FG)
2847 return GTK_RC_TOKEN_FG;
2849 token = gtk_rc_parse_state (scanner, &state);
2850 if (token != G_TOKEN_NONE)
2853 token = g_scanner_get_next_token (scanner);
2854 if (token != G_TOKEN_EQUAL_SIGN)
2855 return G_TOKEN_EQUAL_SIGN;
2857 style->color_flags[state] |= GTK_RC_FG;
2858 return gtk_rc_parse_color (scanner, &style->fg[state]);
2862 gtk_rc_parse_text (GScanner *scanner,
2868 token = g_scanner_get_next_token (scanner);
2869 if (token != GTK_RC_TOKEN_TEXT)
2870 return GTK_RC_TOKEN_TEXT;
2872 token = gtk_rc_parse_state (scanner, &state);
2873 if (token != G_TOKEN_NONE)
2876 token = g_scanner_get_next_token (scanner);
2877 if (token != G_TOKEN_EQUAL_SIGN)
2878 return G_TOKEN_EQUAL_SIGN;
2880 style->color_flags[state] |= GTK_RC_TEXT;
2881 return gtk_rc_parse_color (scanner, &style->text[state]);
2885 gtk_rc_parse_base (GScanner *scanner,
2891 token = g_scanner_get_next_token (scanner);
2892 if (token != GTK_RC_TOKEN_BASE)
2893 return GTK_RC_TOKEN_BASE;
2895 token = gtk_rc_parse_state (scanner, &state);
2896 if (token != G_TOKEN_NONE)
2899 token = g_scanner_get_next_token (scanner);
2900 if (token != G_TOKEN_EQUAL_SIGN)
2901 return G_TOKEN_EQUAL_SIGN;
2903 style->color_flags[state] |= GTK_RC_BASE;
2904 return gtk_rc_parse_color (scanner, &style->base[state]);
2908 gtk_rc_parse_xthickness (GScanner *scanner,
2911 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2912 return GTK_RC_TOKEN_XTHICKNESS;
2914 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2915 return G_TOKEN_EQUAL_SIGN;
2917 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2920 style->xthickness = scanner->value.v_int;
2922 return G_TOKEN_NONE;
2926 gtk_rc_parse_ythickness (GScanner *scanner,
2929 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2930 return GTK_RC_TOKEN_YTHICKNESS;
2932 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2933 return G_TOKEN_EQUAL_SIGN;
2935 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2938 style->ythickness = scanner->value.v_int;
2940 return G_TOKEN_NONE;
2944 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2946 GtkRcStyle *rc_style)
2952 token = g_scanner_get_next_token (scanner);
2953 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2954 return GTK_RC_TOKEN_BG_PIXMAP;
2956 token = gtk_rc_parse_state (scanner, &state);
2957 if (token != G_TOKEN_NONE)
2960 token = g_scanner_get_next_token (scanner);
2961 if (token != G_TOKEN_EQUAL_SIGN)
2962 return G_TOKEN_EQUAL_SIGN;
2964 token = g_scanner_get_next_token (scanner);
2965 if (token != G_TOKEN_STRING)
2966 return G_TOKEN_STRING;
2968 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2969 (strcmp (scanner->value.v_string, "<none>") == 0))
2970 pixmap_file = g_strdup (scanner->value.v_string);
2972 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2973 scanner, scanner->value.v_string);
2977 if (rc_style->bg_pixmap_name[state])
2978 g_free (rc_style->bg_pixmap_name[state]);
2979 rc_style->bg_pixmap_name[state] = pixmap_file;
2982 return G_TOKEN_NONE;
2986 gtk_rc_check_pixmap_dir (const gchar *dir,
2987 const gchar *pixmap_file)
2991 buf = g_build_filename (dir, pixmap_file, NULL);
2993 if (g_file_test (buf, G_FILE_TEST_EXISTS))
3002 * gtk_rc_find_pixmap_in_path:
3003 * @settings: a #GtkSettings
3004 * @scanner: Scanner used to get line number information for the
3005 * warning message, or %NULL
3006 * @pixmap_file: name of the pixmap file to locate.
3008 * Looks up a file in pixmap path for the specified #GtkSettings.
3009 * If the file is not found, it outputs a warning message using
3010 * g_warning() and returns %NULL.
3012 * Return value: the filename.
3015 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
3017 const gchar *pixmap_file)
3023 GtkRcContext *context = gtk_rc_context_get (settings);
3025 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
3027 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
3032 tmp_list = current_files_stack;
3035 GtkRcFile *curfile = tmp_list->data;
3036 filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
3040 tmp_list = tmp_list->next;
3044 g_scanner_warn (scanner,
3045 _("Unable to locate image file in pixmap_path: \"%s\""),
3048 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3055 * gtk_rc_find_module_in_path:
3056 * @module_file: name of a theme engine
3058 * Searches for a theme engine in the GTK+ search path. This function
3059 * is not useful for applications and should not be used.
3061 * Return value: The filename, if found (must be freed with g_free()),
3065 gtk_rc_find_module_in_path (const gchar *module_file)
3067 return _gtk_find_module (module_file, "engines");
3071 gtk_rc_parse_font (GScanner *scanner,
3072 GtkRcStyle *rc_style)
3076 token = g_scanner_get_next_token (scanner);
3077 if (token != GTK_RC_TOKEN_FONT)
3078 return GTK_RC_TOKEN_FONT;
3080 token = g_scanner_get_next_token (scanner);
3081 if (token != G_TOKEN_EQUAL_SIGN)
3082 return G_TOKEN_EQUAL_SIGN;
3084 token = g_scanner_get_next_token (scanner);
3085 if (token != G_TOKEN_STRING)
3086 return G_TOKEN_STRING;
3088 /* Ignore, do nothing */
3090 return G_TOKEN_NONE;
3094 gtk_rc_parse_fontset (GScanner *scanner,
3095 GtkRcStyle *rc_style)
3099 token = g_scanner_get_next_token (scanner);
3100 if (token != GTK_RC_TOKEN_FONTSET)
3101 return GTK_RC_TOKEN_FONTSET;
3103 token = g_scanner_get_next_token (scanner);
3104 if (token != G_TOKEN_EQUAL_SIGN)
3105 return G_TOKEN_EQUAL_SIGN;
3107 token = g_scanner_get_next_token (scanner);
3108 if (token != G_TOKEN_STRING)
3109 return G_TOKEN_STRING;
3111 /* Do nothing - silently ignore */
3113 return G_TOKEN_NONE;
3117 gtk_rc_parse_font_name (GScanner *scanner,
3118 GtkRcStyle *rc_style)
3122 token = g_scanner_get_next_token (scanner);
3123 if (token != GTK_RC_TOKEN_FONT_NAME)
3124 return GTK_RC_TOKEN_FONT;
3126 token = g_scanner_get_next_token (scanner);
3127 if (token != G_TOKEN_EQUAL_SIGN)
3128 return G_TOKEN_EQUAL_SIGN;
3130 token = g_scanner_get_next_token (scanner);
3131 if (token != G_TOKEN_STRING)
3132 return G_TOKEN_STRING;
3134 if (rc_style->font_desc)
3135 pango_font_description_free (rc_style->font_desc);
3137 rc_style->font_desc =
3138 pango_font_description_from_string (scanner->value.v_string);
3140 return G_TOKEN_NONE;
3144 gtk_rc_parse_engine (GtkRcContext *context,
3146 GtkRcStyle **rc_style)
3149 GtkThemeEngine *engine;
3150 guint result = G_TOKEN_NONE;
3151 GtkRcStyle *new_style = NULL;
3152 gboolean parsed_curlies = FALSE;
3154 token = g_scanner_get_next_token (scanner);
3155 if (token != GTK_RC_TOKEN_ENGINE)
3156 return GTK_RC_TOKEN_ENGINE;
3158 token = g_scanner_get_next_token (scanner);
3159 if (token != G_TOKEN_STRING)
3160 return G_TOKEN_STRING;
3162 if (!scanner->value.v_string[0])
3164 /* Support engine "" {} to mean override to the default engine
3166 token = g_scanner_get_next_token (scanner);
3167 if (token != G_TOKEN_LEFT_CURLY)
3168 return G_TOKEN_LEFT_CURLY;
3170 token = g_scanner_get_next_token (scanner);
3171 if (token != G_TOKEN_RIGHT_CURLY)
3172 return G_TOKEN_RIGHT_CURLY;
3174 parsed_curlies = TRUE;
3176 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3178 new_style = gtk_rc_style_new ();
3179 gtk_rc_style_real_merge (new_style, *rc_style);
3181 if ((*rc_style)->name)
3182 new_style->name = g_strdup ((*rc_style)->name);
3185 (*rc_style)->engine_specified = TRUE;
3189 engine = gtk_theme_engine_get (scanner->value.v_string);
3191 token = g_scanner_get_next_token (scanner);
3192 if (token != G_TOKEN_LEFT_CURLY)
3193 return G_TOKEN_LEFT_CURLY;
3197 GtkRcStyleClass *new_class;
3199 new_style = gtk_theme_engine_create_rc_style (engine);
3200 g_type_module_unuse (G_TYPE_MODULE (engine));
3202 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3204 new_class->merge (new_style, *rc_style);
3205 if ((*rc_style)->name)
3206 new_style->name = g_strdup ((*rc_style)->name);
3208 if (new_class->parse)
3210 parsed_curlies = TRUE;
3211 result = new_class->parse (new_style, context->settings, scanner);
3213 if (result != G_TOKEN_NONE)
3215 g_object_unref (new_style);
3222 if (!parsed_curlies)
3224 /* Skip over remainder, looking for nested {}'s
3228 result = G_TOKEN_RIGHT_CURLY;
3229 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3231 if (token == G_TOKEN_LEFT_CURLY)
3233 else if (token == G_TOKEN_RIGHT_CURLY)
3238 result = G_TOKEN_NONE;
3246 new_style->engine_specified = TRUE;
3248 g_object_unref (*rc_style);
3249 *rc_style = new_style;
3256 gtk_rc_parse_state (GScanner *scanner,
3257 GtkStateType *state)
3262 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3263 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3265 /* we don't know where we got called from, so we reset the scope here.
3266 * if we bail out due to errors, we *don't* reset the scope, so the
3267 * error messaging code can make sense of our tokens.
3269 old_scope = g_scanner_set_scope (scanner, 0);
3271 token = g_scanner_get_next_token (scanner);
3272 if (token != G_TOKEN_LEFT_BRACE)
3273 return G_TOKEN_LEFT_BRACE;
3275 token = g_scanner_get_next_token (scanner);
3278 case GTK_RC_TOKEN_ACTIVE:
3279 *state = GTK_STATE_ACTIVE;
3281 case GTK_RC_TOKEN_INSENSITIVE:
3282 *state = GTK_STATE_INSENSITIVE;
3284 case GTK_RC_TOKEN_NORMAL:
3285 *state = GTK_STATE_NORMAL;
3287 case GTK_RC_TOKEN_PRELIGHT:
3288 *state = GTK_STATE_PRELIGHT;
3290 case GTK_RC_TOKEN_SELECTED:
3291 *state = GTK_STATE_SELECTED;
3294 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3297 token = g_scanner_get_next_token (scanner);
3298 if (token != G_TOKEN_RIGHT_BRACE)
3299 return G_TOKEN_RIGHT_BRACE;
3301 g_scanner_set_scope (scanner, old_scope);
3303 return G_TOKEN_NONE;
3307 gtk_rc_parse_priority (GScanner *scanner,
3308 GtkPathPriorityType *priority)
3313 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3314 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3316 /* we don't know where we got called from, so we reset the scope here.
3317 * if we bail out due to errors, we *don't* reset the scope, so the
3318 * error messaging code can make sense of our tokens.
3320 old_scope = g_scanner_set_scope (scanner, 0);
3322 token = g_scanner_get_next_token (scanner);
3326 token = g_scanner_get_next_token (scanner);
3329 case GTK_RC_TOKEN_LOWEST:
3330 *priority = GTK_PATH_PRIO_LOWEST;
3332 case GTK_RC_TOKEN_GTK:
3333 *priority = GTK_PATH_PRIO_GTK;
3335 case GTK_RC_TOKEN_APPLICATION:
3336 *priority = GTK_PATH_PRIO_APPLICATION;
3338 case GTK_RC_TOKEN_THEME:
3339 *priority = GTK_PATH_PRIO_THEME;
3341 case GTK_RC_TOKEN_RC:
3342 *priority = GTK_PATH_PRIO_RC;
3344 case GTK_RC_TOKEN_HIGHEST:
3345 *priority = GTK_PATH_PRIO_HIGHEST;
3348 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3351 g_scanner_set_scope (scanner, old_scope);
3353 return G_TOKEN_NONE;
3357 gtk_rc_parse_color (GScanner *scanner,
3362 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3364 /* we don't need to set our own scope here, because
3365 * we don't need own symbols
3368 token = g_scanner_get_next_token (scanner);
3373 case G_TOKEN_LEFT_CURLY:
3374 token = g_scanner_get_next_token (scanner);
3375 if (token == G_TOKEN_INT)
3376 token_int = scanner->value.v_int;
3377 else if (token == G_TOKEN_FLOAT)
3378 token_int = scanner->value.v_float * 65535.0;
3380 return G_TOKEN_FLOAT;
3381 color->red = CLAMP (token_int, 0, 65535);
3383 token = g_scanner_get_next_token (scanner);
3384 if (token != G_TOKEN_COMMA)
3385 return G_TOKEN_COMMA;
3387 token = g_scanner_get_next_token (scanner);
3388 if (token == G_TOKEN_INT)
3389 token_int = scanner->value.v_int;
3390 else if (token == G_TOKEN_FLOAT)
3391 token_int = scanner->value.v_float * 65535.0;
3393 return G_TOKEN_FLOAT;
3394 color->green = CLAMP (token_int, 0, 65535);
3396 token = g_scanner_get_next_token (scanner);
3397 if (token != G_TOKEN_COMMA)
3398 return G_TOKEN_COMMA;
3400 token = g_scanner_get_next_token (scanner);
3401 if (token == G_TOKEN_INT)
3402 token_int = scanner->value.v_int;
3403 else if (token == G_TOKEN_FLOAT)
3404 token_int = scanner->value.v_float * 65535.0;
3406 return G_TOKEN_FLOAT;
3407 color->blue = CLAMP (token_int, 0, 65535);
3409 token = g_scanner_get_next_token (scanner);
3410 if (token != G_TOKEN_RIGHT_CURLY)
3411 return G_TOKEN_RIGHT_CURLY;
3412 return G_TOKEN_NONE;
3414 case G_TOKEN_STRING:
3415 if (!gdk_color_parse (scanner->value.v_string, color))
3417 g_scanner_warn (scanner, "Invalid color constant '%s'",
3418 scanner->value.v_string);
3419 return G_TOKEN_STRING;
3422 return G_TOKEN_NONE;
3425 return G_TOKEN_STRING;
3430 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3435 token = g_scanner_get_next_token (scanner);
3436 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3437 return GTK_RC_TOKEN_PIXMAP_PATH;
3439 token = g_scanner_get_next_token (scanner);
3440 if (token != G_TOKEN_STRING)
3441 return G_TOKEN_STRING;
3443 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3445 return G_TOKEN_NONE;
3449 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3451 const gchar *pix_path)
3454 gint start_offset = 0;
3458 /* free the old one, or just add to the old one ? */
3459 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3461 g_free (context->pixmap_path[path_num]);
3462 context->pixmap_path[path_num] = NULL;
3467 path_len = strlen (pix_path);
3469 for (end_offset = 0; end_offset <= path_len; end_offset++)
3471 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3472 (end_offset == path_len))
3474 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3475 if (g_path_is_absolute (path_element))
3477 context->pixmap_path[path_num] = path_element;
3479 context->pixmap_path[path_num] = NULL;
3483 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3484 path_element, scanner->input_name, scanner->line);
3485 g_free (path_element);
3488 start_offset = end_offset + 1;
3494 gtk_rc_parse_module_path (GScanner *scanner)
3498 token = g_scanner_get_next_token (scanner);
3499 if (token != GTK_RC_TOKEN_MODULE_PATH)
3500 return GTK_RC_TOKEN_MODULE_PATH;
3502 token = g_scanner_get_next_token (scanner);
3503 if (token != G_TOKEN_STRING)
3504 return G_TOKEN_STRING;
3506 g_warning ("module_path directive is now ignored\n");
3508 return G_TOKEN_NONE;
3512 gtk_rc_parse_im_module_file (GScanner *scanner)
3516 token = g_scanner_get_next_token (scanner);
3517 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3518 return GTK_RC_TOKEN_IM_MODULE_FILE;
3520 token = g_scanner_get_next_token (scanner);
3521 if (token != G_TOKEN_STRING)
3522 return G_TOKEN_STRING;
3525 g_free (im_module_file);
3527 im_module_file = g_strdup (scanner->value.v_string);
3529 return G_TOKEN_NONE;
3533 gtk_rc_parse_path_pattern (GtkRcContext *context,
3537 GtkPathType path_type;
3539 gboolean is_binding;
3540 GtkPathPriorityType priority = context->default_priority;
3542 token = g_scanner_get_next_token (scanner);
3545 case GTK_RC_TOKEN_WIDGET:
3546 path_type = GTK_PATH_WIDGET;
3548 case GTK_RC_TOKEN_WIDGET_CLASS:
3549 path_type = GTK_PATH_WIDGET_CLASS;
3551 case GTK_RC_TOKEN_CLASS:
3552 path_type = GTK_PATH_CLASS;
3555 return GTK_RC_TOKEN_WIDGET_CLASS;
3558 token = g_scanner_get_next_token (scanner);
3559 if (token != G_TOKEN_STRING)
3560 return G_TOKEN_STRING;
3562 pattern = g_strdup (scanner->value.v_string);
3564 token = g_scanner_get_next_token (scanner);
3565 if (token == GTK_RC_TOKEN_STYLE)
3567 else if (token == GTK_RC_TOKEN_BINDING)
3572 return GTK_RC_TOKEN_STYLE;
3575 if (g_scanner_peek_next_token (scanner) == ':')
3577 token = gtk_rc_parse_priority (scanner, &priority);
3578 if (token != G_TOKEN_NONE)
3585 token = g_scanner_get_next_token (scanner);
3586 if (token != G_TOKEN_STRING)
3589 return G_TOKEN_STRING;
3594 GtkBindingSet *binding;
3596 binding = gtk_binding_set_find (scanner->value.v_string);
3600 return G_TOKEN_STRING;
3602 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3606 GtkRcStyle *rc_style;
3609 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3614 return G_TOKEN_STRING;
3617 rc_set = g_new (GtkRcSet, 1);
3618 rc_set->pspec = g_pattern_spec_new (pattern);
3619 rc_set->rc_style = rc_style;
3620 rc_set->priority = priority;
3622 if (path_type == GTK_PATH_WIDGET)
3623 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3624 else if (path_type == GTK_PATH_WIDGET_CLASS)
3625 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3627 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3631 return G_TOKEN_NONE;
3635 gtk_rc_parse_stock_id (GScanner *scanner,
3640 token = g_scanner_get_next_token (scanner);
3641 if (token != G_TOKEN_LEFT_BRACE)
3642 return G_TOKEN_LEFT_BRACE;
3644 token = g_scanner_get_next_token (scanner);
3646 if (token != G_TOKEN_STRING)
3647 return G_TOKEN_STRING;
3649 *stock_id = g_strdup (scanner->value.v_string);
3651 token = g_scanner_get_next_token (scanner);
3652 if (token != G_TOKEN_RIGHT_BRACE)
3655 return G_TOKEN_RIGHT_BRACE;
3658 return G_TOKEN_NONE;
3662 gtk_rc_parse_icon_source (GtkRcContext *context,
3664 GtkIconSet *icon_set,
3665 gboolean *icon_set_valid)
3668 GtkIconSource *source;
3669 gchar *full_filename;
3671 token = g_scanner_get_next_token (scanner);
3672 if (token != G_TOKEN_LEFT_CURLY)
3673 return G_TOKEN_LEFT_CURLY;
3675 token = g_scanner_get_next_token (scanner);
3677 if (token != G_TOKEN_STRING && token != '@')
3678 return G_TOKEN_STRING;
3680 source = gtk_icon_source_new ();
3682 if (token == G_TOKEN_STRING)
3686 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3689 gtk_icon_source_set_filename (source, full_filename);
3690 g_free (full_filename);
3697 token = g_scanner_get_next_token (scanner);
3699 if (token != G_TOKEN_STRING)
3700 return G_TOKEN_STRING;
3702 gtk_icon_source_set_icon_name (source, scanner->value.v_string);
3705 /* We continue parsing even if we didn't find the pixmap so that rest of the
3706 * file is read, even if the syntax is bad. However we don't validate the
3707 * icon_set so the caller can choose not to install it.
3709 token = g_scanner_get_next_token (scanner);
3711 if (token == G_TOKEN_RIGHT_CURLY)
3713 else if (token != G_TOKEN_COMMA)
3715 gtk_icon_source_free (source);
3716 return G_TOKEN_COMMA;
3719 /* Get the direction */
3721 token = g_scanner_get_next_token (scanner);
3725 case GTK_RC_TOKEN_RTL:
3726 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3727 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3730 case GTK_RC_TOKEN_LTR:
3731 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3732 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3739 gtk_icon_source_free (source);
3740 return GTK_RC_TOKEN_RTL;
3744 token = g_scanner_get_next_token (scanner);
3746 if (token == G_TOKEN_RIGHT_CURLY)
3748 else if (token != G_TOKEN_COMMA)
3750 gtk_icon_source_free (source);
3751 return G_TOKEN_COMMA;
3756 token = g_scanner_get_next_token (scanner);
3760 case GTK_RC_TOKEN_NORMAL:
3761 gtk_icon_source_set_state_wildcarded (source, FALSE);
3762 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3765 case GTK_RC_TOKEN_PRELIGHT:
3766 gtk_icon_source_set_state_wildcarded (source, FALSE);
3767 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3771 case GTK_RC_TOKEN_INSENSITIVE:
3772 gtk_icon_source_set_state_wildcarded (source, FALSE);
3773 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3776 case GTK_RC_TOKEN_ACTIVE:
3777 gtk_icon_source_set_state_wildcarded (source, FALSE);
3778 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3781 case GTK_RC_TOKEN_SELECTED:
3782 gtk_icon_source_set_state_wildcarded (source, FALSE);
3783 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3790 gtk_icon_source_free (source);
3791 return GTK_RC_TOKEN_PRELIGHT;
3795 token = g_scanner_get_next_token (scanner);
3797 if (token == G_TOKEN_RIGHT_CURLY)
3799 else if (token != G_TOKEN_COMMA)
3801 gtk_icon_source_free (source);
3802 return G_TOKEN_COMMA;
3807 token = g_scanner_get_next_token (scanner);
3813 if (token != G_TOKEN_STRING)
3815 gtk_icon_source_free (source);
3816 return G_TOKEN_STRING;
3819 size = gtk_icon_size_from_name (scanner->value.v_string);
3821 if (size != GTK_ICON_SIZE_INVALID)
3823 gtk_icon_source_set_size_wildcarded (source, FALSE);
3824 gtk_icon_source_set_size (source, size);
3828 /* Check the close brace */
3830 token = g_scanner_get_next_token (scanner);
3831 if (token != G_TOKEN_RIGHT_CURLY)
3833 gtk_icon_source_free (source);
3834 return G_TOKEN_RIGHT_CURLY;
3838 if (gtk_icon_source_get_filename (source) ||
3839 gtk_icon_source_get_icon_name (source))
3841 gtk_icon_set_add_source (icon_set, source);
3842 *icon_set_valid = TRUE;
3844 gtk_icon_source_free (source);
3846 return G_TOKEN_NONE;
3850 gtk_rc_parse_stock (GtkRcContext *context,
3852 GtkRcStyle *rc_style,
3853 GtkIconFactory *factory)
3855 GtkIconSet *icon_set = NULL;
3856 gboolean icon_set_valid = FALSE;
3857 gchar *stock_id = NULL;
3860 token = g_scanner_get_next_token (scanner);
3861 if (token != GTK_RC_TOKEN_STOCK)
3862 return GTK_RC_TOKEN_STOCK;
3864 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3865 if (token != G_TOKEN_NONE)
3868 token = g_scanner_get_next_token (scanner);
3869 if (token != G_TOKEN_EQUAL_SIGN)
3872 return G_TOKEN_EQUAL_SIGN;
3875 token = g_scanner_get_next_token (scanner);
3876 if (token != G_TOKEN_LEFT_CURLY)
3879 return G_TOKEN_LEFT_CURLY;
3882 token = g_scanner_peek_next_token (scanner);
3883 while (token != G_TOKEN_RIGHT_CURLY)
3885 if (icon_set == NULL)
3886 icon_set = gtk_icon_set_new ();
3888 token = gtk_rc_parse_icon_source (context,
3889 scanner, icon_set, &icon_set_valid);
3890 if (token != G_TOKEN_NONE)
3893 gtk_icon_set_unref (icon_set);
3897 token = g_scanner_get_next_token (scanner);
3899 if (token != G_TOKEN_COMMA &&
3900 token != G_TOKEN_RIGHT_CURLY)
3903 gtk_icon_set_unref (icon_set);
3904 return G_TOKEN_RIGHT_CURLY;
3911 gtk_icon_factory_add (factory,
3915 gtk_icon_set_unref (icon_set);
3920 return G_TOKEN_NONE;
3925 /* DLL ABI stability backward compatibility versions */
3927 #undef gtk_rc_add_default_file
3930 gtk_rc_add_default_file (const gchar *filename)
3932 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
3934 gtk_rc_add_default_file_utf8 (utf8_filename);
3936 g_free (utf8_filename);
3939 #undef gtk_rc_set_default_files
3942 gtk_rc_set_default_files (gchar **filenames)
3944 gchar **utf8_filenames;
3947 while (filenames[n++] != NULL)
3950 utf8_filenames = g_new (gchar *, n + 1);
3952 for (i = 0; i < n; i++)
3953 utf8_filenames[i] = g_locale_to_utf8 (filenames[i], -1, NULL, NULL, NULL);
3955 utf8_filenames[n] = NULL;
3957 gtk_rc_set_default_files_utf8 (utf8_filenames);
3959 g_strfreev (utf8_filenames);
3965 gtk_rc_parse (const gchar *filename)
3967 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
3969 gtk_rc_parse_utf8 (utf8_filename);
3971 g_free (utf8_filename);
3976 #define __GTK_RC_C__
3977 #include "gtkaliasdef.c"