1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
47 #include "gdkconfig.h"
49 #include "gtkversion.h"
51 #include "gtkbindings.h"
52 #include "gtkthemes.h"
54 #include "gtkiconfactory.h"
56 #include "gtkprivate.h"
57 #include "gtksettings.h"
58 #include "gtkwindow.h"
64 typedef struct _GtkRcSet GtkRcSet;
65 typedef struct _GtkRcNode GtkRcNode;
66 typedef struct _GtkRcFile GtkRcFile;
77 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
80 gchar *canonical_name;
85 #define GTK_RC_MAX_PIXMAP_PATHS 128
89 GHashTable *rc_style_ht;
90 GtkSettings *settings;
91 GSList *rc_sets_widget;
92 GSList *rc_sets_widget_class;
93 GSList *rc_sets_class;
95 /* The files we have parsed, to reread later if necessary */
99 gchar *key_theme_name;
102 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
104 gint default_priority;
105 GtkStyle *default_style;
108 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
110 static guint gtk_rc_style_hash (const gchar *name);
111 static gboolean gtk_rc_style_equal (const gchar *a,
113 static guint gtk_rc_styles_hash (const GSList *rc_styles);
114 static gboolean gtk_rc_styles_equal (const GSList *a,
116 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
118 static GSList * gtk_rc_styles_match (GSList *rc_styles,
122 const gchar *path_reversed);
123 static GtkStyle * gtk_rc_style_to_style (GtkRcContext *context,
124 GtkRcStyle *rc_style);
125 static GtkStyle* gtk_rc_init_style (GtkRcContext *context,
127 static void gtk_rc_parse_default_files (GtkRcContext *context);
128 static void gtk_rc_parse_named (GtkRcContext *context,
131 static void gtk_rc_context_parse_file (GtkRcContext *context,
132 const gchar *filename,
135 static void gtk_rc_parse_any (GtkRcContext *context,
136 const gchar *input_name,
138 const gchar *input_string);
139 static guint gtk_rc_parse_statement (GtkRcContext *context,
141 static guint gtk_rc_parse_style (GtkRcContext *context,
143 static guint gtk_rc_parse_assignment (GScanner *scanner,
144 GtkRcProperty *prop);
145 static guint gtk_rc_parse_bg (GScanner *scanner,
147 static guint gtk_rc_parse_fg (GScanner *scanner,
149 static guint gtk_rc_parse_text (GScanner *scanner,
151 static guint gtk_rc_parse_base (GScanner *scanner,
153 static guint gtk_rc_parse_xthickness (GScanner *scanner,
155 static guint gtk_rc_parse_ythickness (GScanner *scanner,
157 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
159 GtkRcStyle *rc_style);
160 static guint gtk_rc_parse_font (GScanner *scanner,
161 GtkRcStyle *rc_style);
162 static guint gtk_rc_parse_fontset (GScanner *scanner,
163 GtkRcStyle *rc_style);
164 static guint gtk_rc_parse_font_name (GScanner *scanner,
165 GtkRcStyle *rc_style);
166 static guint gtk_rc_parse_engine (GtkRcContext *context,
168 GtkRcStyle **rc_style);
169 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
171 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
173 const gchar *pix_path);
174 static guint gtk_rc_parse_module_path (GScanner *scanner);
175 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
176 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
178 static guint gtk_rc_parse_stock (GtkRcContext *context,
180 GtkRcStyle *rc_style,
181 GtkIconFactory *factory);
182 static void gtk_rc_clear_hash_node (gpointer key,
185 static void gtk_rc_clear_styles (GtkRcContext *context);
186 static void gtk_rc_add_initial_default_files (void);
188 static void gtk_rc_style_init (GtkRcStyle *style);
189 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
190 static void gtk_rc_style_finalize (GObject *object);
191 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
193 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
194 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
195 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
196 gconstpointer bsearch_node2);
198 static gpointer parent_class = NULL;
200 static const GScannerConfig gtk_rc_scanner_config =
204 ) /* cset_skip_characters */,
209 ) /* cset_identifier_first */,
214 ) /* cset_identifier_nth */,
215 ( "#\n" ) /* cpair_comment_single */,
217 TRUE /* case_sensitive */,
219 TRUE /* skip_comment_multi */,
220 TRUE /* skip_comment_single */,
221 TRUE /* scan_comment_multi */,
222 TRUE /* scan_identifier */,
223 FALSE /* scan_identifier_1char */,
224 FALSE /* scan_identifier_NULL */,
225 TRUE /* scan_symbols */,
226 TRUE /* scan_binary */,
227 TRUE /* scan_octal */,
228 TRUE /* scan_float */,
230 TRUE /* scan_hex_dollar */,
231 TRUE /* scan_string_sq */,
232 TRUE /* scan_string_dq */,
233 TRUE /* numbers_2_int */,
234 FALSE /* int_2_float */,
235 FALSE /* identifier_2_string */,
236 TRUE /* char_2_token */,
237 TRUE /* symbol_2_token */,
238 FALSE /* scope_0_fallback */,
246 { "include", GTK_RC_TOKEN_INCLUDE },
247 { "NORMAL", GTK_RC_TOKEN_NORMAL },
248 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
249 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
250 { "SELECTED", GTK_RC_TOKEN_SELECTED },
251 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
252 { "fg", GTK_RC_TOKEN_FG },
253 { "bg", GTK_RC_TOKEN_BG },
254 { "text", GTK_RC_TOKEN_TEXT },
255 { "base", GTK_RC_TOKEN_BASE },
256 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
257 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
258 { "font", GTK_RC_TOKEN_FONT },
259 { "fontset", GTK_RC_TOKEN_FONTSET },
260 { "font_name", GTK_RC_TOKEN_FONT_NAME },
261 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
262 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
263 { "style", GTK_RC_TOKEN_STYLE },
264 { "binding", GTK_RC_TOKEN_BINDING },
265 { "bind", GTK_RC_TOKEN_BIND },
266 { "widget", GTK_RC_TOKEN_WIDGET },
267 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
268 { "class", GTK_RC_TOKEN_CLASS },
269 { "lowest", GTK_RC_TOKEN_LOWEST },
270 { "gtk", GTK_RC_TOKEN_GTK },
271 { "application", GTK_RC_TOKEN_APPLICATION },
272 { "theme", GTK_RC_TOKEN_THEME },
273 { "rc", GTK_RC_TOKEN_RC },
274 { "highest", GTK_RC_TOKEN_HIGHEST },
275 { "engine", GTK_RC_TOKEN_ENGINE },
276 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
277 { "stock", GTK_RC_TOKEN_STOCK },
278 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
279 { "LTR", GTK_RC_TOKEN_LTR },
280 { "RTL", GTK_RC_TOKEN_RTL }
283 static GHashTable *realized_style_ht = NULL;
285 static gchar *im_module_file = NULL;
287 #define GTK_RC_MAX_DEFAULT_FILES 128
288 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
290 /* A stack of information of RC files we are parsing currently.
291 * The directories for these files are implicitely added to the end of
294 static GSList *current_files_stack = NULL;
296 /* RC files and strings that are parsed for every context
298 static GSList *global_rc_files = NULL;
300 /* Keep list of all current RC contexts for convenience
302 static GSList *rc_contexts;
304 /* RC file handling */
307 gtk_rc_make_default_dir (const gchar *type)
312 var = g_getenv ("GTK_EXE_PREFIX");
314 path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
316 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
322 * gtk_rc_get_im_module_path:
323 * @returns: a newly-allocated string containing the path in which to
324 * look for IM modules.
326 * Obtains the path in which to look for IM modules. See the documentation
327 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
328 * environment variable for more details about looking up modules. This
329 * function is useful solely for utilities supplied with GTK+ and should
330 * not be used by applications under normal circumstances.
333 gtk_rc_get_im_module_path (void)
335 gchar **paths = _gtk_get_module_path ("immodules");
336 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
343 * gtk_rc_get_im_module_file:
344 * @returns: a newly-allocated string containing the name of the file
345 * listing the IM modules available for loading
347 * Obtains the path to the IM modules file. See the documentation
348 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
349 * environment variable for more details.
352 gtk_rc_get_im_module_file (void)
354 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
359 result = g_strdup (im_module_file);
361 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
368 gtk_rc_get_theme_dir (void)
373 var = g_getenv ("GTK_DATA_PREFIX");
375 path = g_build_filename (var, "share", "themes", NULL);
377 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
383 * gtk_rc_get_module_dir:
385 * Returns a directory in which GTK+ looks for theme engines.
386 * For full information about the search for theme engines,
387 * see the docs for <envar>GTK_PATH</envar> in
388 * <xref linkend="gtk-running"/>.
390 * return value: the directory. (Must be freed with g_free())
393 gtk_rc_get_module_dir (void)
395 return gtk_rc_make_default_dir ("engines");
399 gtk_rc_add_initial_default_files (void)
401 static gint init = FALSE;
410 gtk_rc_default_files[0] = NULL;
413 var = g_getenv ("GTK2_RC_FILES");
416 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
420 gtk_rc_add_default_file (files[i]);
427 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
429 gtk_rc_add_default_file (str);
432 var = g_get_home_dir ();
435 str = g_build_filename (var, ".gtkrc-2.0", NULL);
436 gtk_rc_add_default_file (str);
443 * gtk_rc_add_default_file:
444 * @filename: the pathname to the file. If @filename is not absolute, it
445 * is searched in the current directory.
447 * Adds a file to the list of files to be parsed at the
451 gtk_rc_add_default_file (const gchar *filename)
455 gtk_rc_add_initial_default_files ();
457 for (n = 0; gtk_rc_default_files[n]; n++) ;
458 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
461 gtk_rc_default_files[n++] = g_strdup (filename);
462 gtk_rc_default_files[n] = NULL;
466 * gtk_rc_set_default_files:
467 * @filenames: A %NULL-terminated list of filenames.
469 * Sets the list of files that GTK+ will read at the
473 gtk_rc_set_default_files (gchar **filenames)
477 gtk_rc_add_initial_default_files ();
480 while (gtk_rc_default_files[i])
482 g_free (gtk_rc_default_files[i]);
486 gtk_rc_default_files[0] = NULL;
489 while (filenames[i] != NULL)
491 gtk_rc_add_default_file (filenames[i]);
497 * gtk_rc_get_default_files:
499 * Retrieves the current list of RC files that will be parsed
500 * at the end of gtk_init().
502 * Return value: A %NULL-terminated array of filenames. This memory
503 * is owned by GTK+ and must not be freed by the application.
504 * If you want to store this information, you should make a copy.
507 gtk_rc_get_default_files (void)
509 gtk_rc_add_initial_default_files ();
511 return gtk_rc_default_files;
515 gtk_rc_settings_changed (GtkSettings *settings,
517 GtkRcContext *context)
519 gchar *new_theme_name;
520 gchar *new_key_theme_name;
522 g_object_get (settings,
523 "gtk-theme-name", &new_theme_name,
524 "gtk-key-theme-name", &new_key_theme_name,
527 if ((new_theme_name != context->theme_name &&
528 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
529 (new_key_theme_name != context->key_theme_name &&
530 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
532 gtk_rc_reparse_all_for_settings (settings, TRUE);
535 g_free (new_theme_name);
536 g_free (new_key_theme_name);
540 gtk_rc_font_name_changed (GtkSettings *settings,
542 GtkRcContext *context)
544 _gtk_rc_context_get_default_font_name (settings);
547 static GtkRcContext *
548 gtk_rc_context_get (GtkSettings *settings)
550 if (!settings->rc_context)
552 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
554 context->settings = settings;
555 context->rc_style_ht = NULL;
556 context->rc_sets_widget = NULL;
557 context->rc_sets_widget_class = NULL;
558 context->rc_sets_class = NULL;
559 context->rc_files = NULL;
560 context->default_style = NULL;
562 g_object_get (settings,
563 "gtk-theme-name", &context->theme_name,
564 "gtk-key-theme-name", &context->key_theme_name,
565 "gtk-font-name", &context->font_name,
568 g_signal_connect (settings,
569 "notify::gtk-theme-name",
570 G_CALLBACK (gtk_rc_settings_changed),
572 g_signal_connect (settings,
573 "notify::gtk-key-theme-name",
574 G_CALLBACK (gtk_rc_settings_changed),
576 g_signal_connect (settings,
577 "notify::gtk-font-name",
578 G_CALLBACK (gtk_rc_font_name_changed),
582 context->pixmap_path[0] = NULL;
584 context->default_priority = GTK_PATH_PRIO_RC;
586 rc_contexts = g_slist_prepend (rc_contexts, settings->rc_context);
589 return settings->rc_context;
593 gtk_rc_parse_named (GtkRcContext *context,
598 const gchar *home_dir;
602 subpath = g_strconcat ("gtk-2.0-", type,
603 G_DIR_SEPARATOR_S "gtkrc",
606 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
608 /* First look in the users home directory
610 home_dir = g_get_home_dir ();
613 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
614 if (!g_file_test (path, G_FILE_TEST_EXISTS))
623 gchar *theme_dir = gtk_rc_get_theme_dir ();
624 path = g_build_filename (theme_dir, name, subpath, NULL);
627 if (!g_file_test (path, G_FILE_TEST_EXISTS))
636 gtk_rc_context_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
644 gtk_rc_parse_default_files (GtkRcContext *context)
648 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
649 gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
655 static gboolean initialized = FALSE;
661 gtk_rc_add_initial_default_files ();
664 /* Default RC string */
665 gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
666 " bg[NORMAL] = \"#eee1b3\"\n"
667 " fg[NORMAL] = \"#000000\"\n"
670 "style \"gtk-default-progress-bar-style\" {\n"
671 " bg[PRELIGHT] = \"#4b6983\"\n"
672 " fg[PRELIGHT] = \"#ffffff\"\n"
673 " bg[NORMAL] = \"#bab5ab\"\n"
676 "style \"gtk-default-menu-bar-item-style\" {\n"
677 " GtkMenuItem::horizontal_padding = 5\n"
680 "style \"gtk-default-menu-item-style\" {\n"
681 " bg[PRELIGHT] = \"#4b6983\"\n"
682 " fg[PRELIGHT] = \"#ffffff\"\n"
683 " base[PRELIGHT] = \"#4b6983\"\n"
684 " text[PRELIGHT] = \"#ffffff\"\n"
687 "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
688 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"
689 "class \"GtkMenuItem\" style : gtk \"gtk-default-menu-item-style\"\n"
690 "widget_class \"*.GtkMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
691 "widget_class \"*.GtkAccelMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
692 "widget_class \"*.GtkRadioMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
693 "widget_class \"*.GtkCheckMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
694 "widget_class \"*.GtkImageMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
695 "widget_class \"*.GtkSeparatorMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
696 "widget_class \"*GtkMenuBar*GtkMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
697 "widget_class \"*GtkMenuBar*GtkAccelMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
698 "widget_class \"*GtkMenuBar*GtkRadioMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
699 "widget_class \"*GtkMenuBar*GtkCheckMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
700 "widget_class \"*GtkMenuBar*GtkImageMenuItem\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
705 gtk_rc_context_parse_string (GtkRcContext *context,
706 const gchar *rc_string)
708 gtk_rc_parse_any (context, "-", -1, rc_string);
712 gtk_rc_parse_string (const gchar *rc_string)
717 g_return_if_fail (rc_string != NULL);
719 rc_file = g_new (GtkRcFile, 1);
720 rc_file->is_string = TRUE;
721 rc_file->name = g_strdup (rc_string);
722 rc_file->canonical_name = NULL;
723 rc_file->directory = NULL;
725 rc_file->reload = TRUE;
727 global_rc_files = g_slist_append (global_rc_files, rc_file);
729 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
730 gtk_rc_context_parse_string (tmp_list->data, rc_string);
734 add_to_rc_file_list (GSList **rc_file_list,
735 const char *filename,
741 tmp_list = *rc_file_list;
744 rc_file = tmp_list->data;
745 if (!strcmp (rc_file->name, filename))
748 tmp_list = tmp_list->next;
751 rc_file = g_new (GtkRcFile, 1);
752 rc_file->is_string = FALSE;
753 rc_file->name = g_strdup (filename);
754 rc_file->canonical_name = NULL;
755 rc_file->directory = NULL;
757 rc_file->reload = reload;
759 *rc_file_list = g_slist_append (*rc_file_list, rc_file);
765 gtk_rc_context_parse_one_file (GtkRcContext *context,
766 const gchar *filename,
774 g_return_if_fail (filename != NULL);
776 saved_priority = context->default_priority;
777 context->default_priority = priority;
779 rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
781 if (!rc_file->canonical_name)
783 /* Get the absolute pathname */
785 if (g_path_is_absolute (rc_file->name))
786 rc_file->canonical_name = rc_file->name;
791 cwd = g_get_current_dir ();
792 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
796 rc_file->directory = g_path_get_dirname (rc_file->canonical_name);
799 /* If the file is already being parsed (recursion), do nothing
801 if (g_slist_find (current_files_stack, rc_file))
804 if (!lstat (rc_file->canonical_name, &statbuf))
808 rc_file->mtime = statbuf.st_mtime;
810 fd = open (rc_file->canonical_name, O_RDONLY);
814 /* Temporarily push information for this file on
815 * a stack of current files while parsing it.
817 current_files_stack = g_slist_prepend (current_files_stack, rc_file);
818 gtk_rc_parse_any (context, filename, fd, NULL);
819 current_files_stack = g_slist_delete_link (current_files_stack,
820 current_files_stack);
826 context->default_priority = saved_priority;
830 strchr_len (const gchar *str, gint len, char c)
844 gtk_rc_context_parse_file (GtkRcContext *context,
845 const gchar *filename,
849 gchar *locale_suffixes[2];
850 gint n_locale_suffixes = 0;
854 gboolean found = FALSE;
856 locale = _gtk_get_lc_ctype ();
858 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
860 /* Determine locale-specific suffixes for RC files.
862 length = strlen (locale);
864 p = strchr (locale, '@');
868 p = strchr_len (locale, length, '.');
872 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
874 p = strchr_len (locale, length, '_');
878 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
884 gtk_rc_context_parse_one_file (context, filename, priority, reload);
885 for (j = 0; j < n_locale_suffixes; j++)
889 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
890 if (g_file_test (name, G_FILE_TEST_EXISTS))
892 gtk_rc_context_parse_one_file (context, name, priority, FALSE);
899 g_free (locale_suffixes[j]);
904 gtk_rc_parse (const gchar *filename)
908 g_return_if_fail (filename != NULL);
910 add_to_rc_file_list (&global_rc_files, filename, TRUE);
912 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
913 gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
916 /* Handling of RC styles */
919 gtk_rc_style_get_type (void)
921 static GType rc_style_type = 0;
925 static const GTypeInfo rc_style_info =
927 sizeof (GtkRcStyleClass),
928 (GBaseInitFunc) NULL,
929 (GBaseFinalizeFunc) NULL,
930 (GClassInitFunc) gtk_rc_style_class_init,
931 NULL, /* class_finalize */
932 NULL, /* class_data */
935 (GInstanceInitFunc) gtk_rc_style_init,
938 rc_style_type = g_type_register_static (G_TYPE_OBJECT, "GtkRcStyle",
942 return rc_style_type;
946 gtk_rc_style_init (GtkRcStyle *style)
951 style->font_desc = NULL;
953 for (i = 0; i < 5; i++)
955 static const GdkColor init_color = { 0, 0, 0, 0, };
957 style->bg_pixmap_name[i] = NULL;
958 style->color_flags[i] = 0;
959 style->fg[i] = init_color;
960 style->bg[i] = init_color;
961 style->text[i] = init_color;
962 style->base[i] = init_color;
964 style->xthickness = -1;
965 style->ythickness = -1;
966 style->rc_properties = NULL;
968 style->rc_style_lists = NULL;
969 style->icon_factories = NULL;
973 gtk_rc_style_class_init (GtkRcStyleClass *klass)
975 GObjectClass *object_class = G_OBJECT_CLASS (klass);
977 parent_class = g_type_class_peek_parent (klass);
979 object_class->finalize = gtk_rc_style_finalize;
982 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
983 klass->merge = gtk_rc_style_real_merge;
984 klass->create_style = gtk_rc_style_real_create_style;
988 gtk_rc_style_finalize (GObject *object)
990 GSList *tmp_list1, *tmp_list2;
991 GtkRcStyle *rc_style;
994 rc_style = GTK_RC_STYLE (object);
997 g_free (rc_style->name);
998 if (rc_style->font_desc)
999 pango_font_description_free (rc_style->font_desc);
1001 for (i = 0; i < 5; i++)
1002 if (rc_style->bg_pixmap_name[i])
1003 g_free (rc_style->bg_pixmap_name[i]);
1005 /* Now remove all references to this rc_style from
1008 tmp_list1 = rc_style->rc_style_lists;
1011 GSList *rc_styles = tmp_list1->data;
1012 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1013 g_object_unref (style);
1015 /* Remove the list of styles from the other rc_styles
1018 tmp_list2 = rc_styles;
1021 GtkRcStyle *other_style = tmp_list2->data;
1023 if (other_style != rc_style)
1024 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1026 tmp_list2 = tmp_list2->next;
1029 /* And from the hash table itself
1031 g_hash_table_remove (realized_style_ht, rc_styles);
1032 g_slist_free (rc_styles);
1034 tmp_list1 = tmp_list1->next;
1036 g_slist_free (rc_style->rc_style_lists);
1038 if (rc_style->rc_properties)
1042 for (i = 0; i < rc_style->rc_properties->len; i++)
1044 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1046 g_free (node->origin);
1047 g_value_unset (&node->value);
1049 g_array_free (rc_style->rc_properties, TRUE);
1050 rc_style->rc_properties = NULL;
1053 tmp_list1 = rc_style->icon_factories;
1056 g_object_unref (tmp_list1->data);
1057 tmp_list1 = tmp_list1->next;
1059 g_slist_free (rc_style->icon_factories);
1061 G_OBJECT_CLASS (parent_class)->finalize (object);
1065 gtk_rc_style_new (void)
1069 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1075 * gtk_rc_style_copy:
1076 * @orig: the style to copy
1078 * Makes a copy of the specified #GtkRcStyle. This function
1079 * will correctly copy an RC style that is a member of a class
1080 * derived from #GtkRcStyle.
1082 * Return value: the resulting #GtkRcStyle
1085 gtk_rc_style_copy (GtkRcStyle *orig)
1089 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1091 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1092 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1098 gtk_rc_style_ref (GtkRcStyle *rc_style)
1100 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1102 g_object_ref (rc_style);
1106 gtk_rc_style_unref (GtkRcStyle *rc_style)
1108 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1110 g_object_unref (rc_style);
1114 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1116 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1120 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1121 gconstpointer bsearch_node2)
1123 const GtkRcProperty *prop1 = bsearch_node1;
1124 const GtkRcProperty *prop2 = bsearch_node2;
1126 if (prop1->type_name == prop2->type_name)
1127 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1129 return prop1->type_name < prop2->type_name ? -1 : 1;
1133 insert_rc_property (GtkRcStyle *style,
1134 GtkRcProperty *property,
1138 GtkRcProperty *new_property = NULL;
1139 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1141 key.type_name = property->type_name;
1142 key.property_name = property->property_name;
1144 if (!style->rc_properties)
1145 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1148 while (i < style->rc_properties->len)
1150 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1156 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1158 g_free (new_property->origin);
1159 g_value_unset (&new_property->value);
1161 *new_property = key;
1175 g_array_insert_val (style->rc_properties, i, key);
1176 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1179 new_property->origin = g_strdup (property->origin);
1180 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1181 g_value_copy (&property->value, &new_property->value);
1185 gtk_rc_style_real_merge (GtkRcStyle *dest,
1190 for (i = 0; i < 5; i++)
1192 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1193 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1195 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1196 src->color_flags[i] & GTK_RC_FG)
1198 dest->fg[i] = src->fg[i];
1199 dest->color_flags[i] |= GTK_RC_FG;
1201 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1202 src->color_flags[i] & GTK_RC_BG)
1204 dest->bg[i] = src->bg[i];
1205 dest->color_flags[i] |= GTK_RC_BG;
1207 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1208 src->color_flags[i] & GTK_RC_TEXT)
1210 dest->text[i] = src->text[i];
1211 dest->color_flags[i] |= GTK_RC_TEXT;
1213 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1214 src->color_flags[i] & GTK_RC_BASE)
1216 dest->base[i] = src->base[i];
1217 dest->color_flags[i] |= GTK_RC_BASE;
1221 if (dest->xthickness < 0 && src->xthickness >= 0)
1222 dest->xthickness = src->xthickness;
1223 if (dest->ythickness < 0 && src->ythickness >= 0)
1224 dest->ythickness = src->ythickness;
1228 if (!dest->font_desc)
1229 dest->font_desc = pango_font_description_copy (src->font_desc);
1231 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1234 if (src->rc_properties)
1238 for (i = 0; i < src->rc_properties->len; i++)
1239 insert_rc_property (dest,
1240 &g_array_index (src->rc_properties, GtkRcProperty, i),
1246 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1248 return gtk_style_new ();
1252 gtk_rc_clear_hash_node (gpointer key,
1256 gtk_rc_style_unref (data);
1260 gtk_rc_free_rc_sets (GSList *slist)
1266 rc_set = slist->data;
1267 g_pattern_spec_free (rc_set->pspec);
1270 slist = slist->next;
1275 gtk_rc_clear_styles (GtkRcContext *context)
1277 /* Clear out all old rc_styles */
1279 if (context->rc_style_ht)
1281 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1282 g_hash_table_destroy (context->rc_style_ht);
1283 context->rc_style_ht = NULL;
1286 gtk_rc_free_rc_sets (context->rc_sets_widget);
1287 g_slist_free (context->rc_sets_widget);
1288 context->rc_sets_widget = NULL;
1290 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1291 g_slist_free (context->rc_sets_widget_class);
1292 context->rc_sets_widget_class = NULL;
1294 gtk_rc_free_rc_sets (context->rc_sets_class);
1295 g_slist_free (context->rc_sets_class);
1296 context->rc_sets_class = NULL;
1299 /* Reset all our widgets. Also, we have to invalidate cached icons in
1300 * icon sets so they get re-rendered.
1303 gtk_rc_reset_widgets (GtkSettings *settings)
1305 GList *list, *toplevels;
1307 _gtk_icon_set_invalidate_caches ();
1309 toplevels = gtk_window_list_toplevels ();
1310 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1312 for (list = toplevels; list; list = list->next)
1314 if (gtk_widget_get_screen (list->data) == settings->screen)
1316 gtk_widget_reset_rc_styles (list->data);
1317 g_object_unref (list->data);
1320 g_list_free (toplevels);
1324 gtk_rc_clear_realized_style (gpointer key,
1328 GSList *rc_styles = key;
1329 GSList *tmp_list = rc_styles;
1333 GtkRcStyle *rc_style = tmp_list->data;
1335 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1337 tmp_list = tmp_list->next;
1340 g_slist_free (rc_styles);
1344 * gtk_rc_reset_styles:
1345 * @settings: a #GtkSettings
1347 * This function recomputes the styles for all widgets that use a
1348 * particular #GtkSettings object. (There is one #GtkSettings object
1349 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1350 * when some global parameter has changed that affects the appearance
1351 * of all widgets, because when a widget gets a new style, it will
1352 * both redraw and recompute any cached information about its
1353 * appearance. As an example, it is used when the default font size
1354 * set by the operating system changes. Note that this function
1355 * doesn't affect widgets that have a style set explicitely on them
1356 * with gtk_widget_set_style().
1361 gtk_rc_reset_styles (GtkSettings *settings)
1363 GtkRcContext *context;
1364 gboolean reset = FALSE;
1366 g_return_if_fail (GTK_IS_SETTINGS (settings));
1368 context = gtk_rc_context_get (settings);
1370 if (context->default_style)
1372 g_object_unref (context->default_style);
1373 context->default_style = NULL;
1377 /* Clear out styles that have been looked up already
1379 if (realized_style_ht)
1381 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1382 g_hash_table_destroy (realized_style_ht);
1383 realized_style_ht = NULL;
1388 gtk_rc_reset_widgets (settings);
1392 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1394 GtkRcContext *context;
1395 gchar *new_font_name;
1397 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1399 context = gtk_rc_context_get (settings);
1401 g_object_get (context->settings,
1402 "gtk-font-name", &new_font_name,
1405 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1407 g_free (context->font_name);
1408 context->font_name = g_strdup (new_font_name);
1410 gtk_rc_reset_styles (settings);
1413 g_free (new_font_name);
1415 return context->font_name;
1419 * gtk_rc_reparse_all_for_settings:
1420 * @settings: a #GtkSettings
1421 * @force_load: load whether or not anything changed
1423 * If the modification time on any previously read file
1424 * for the given #GtkSettings has changed, discard all style information
1425 * and then reread all previously read RC files.
1427 * Return value: %TRUE if the files were reread.
1430 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1431 gboolean force_load)
1433 gboolean mtime_modified = FALSE;
1436 GtkRcContext *context;
1438 struct stat statbuf;
1440 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1442 context = gtk_rc_context_get (settings);
1446 /* Check through and see if any of the RC's have had their
1447 * mtime modified. If so, reparse everything.
1449 tmp_list = context->rc_files;
1452 rc_file = tmp_list->data;
1454 if (!rc_file->is_string)
1456 if (!lstat (rc_file->name, &statbuf) &&
1457 (statbuf.st_mtime > rc_file->mtime))
1459 mtime_modified = TRUE;
1464 tmp_list = tmp_list->next;
1468 if (force_load || mtime_modified)
1470 _gtk_binding_reset_parsed ();
1471 gtk_rc_clear_styles (context);
1472 g_object_freeze_notify (G_OBJECT (context->settings));
1474 _gtk_settings_reset_rc_values (context->settings);
1475 tmp_list = context->rc_files;
1478 rc_file = tmp_list->data;
1480 if (rc_file->canonical_name != rc_file->name)
1481 g_free (rc_file->canonical_name);
1482 g_free (rc_file->directory);
1483 g_free (rc_file->name);
1486 tmp_list = tmp_list->next;
1489 g_slist_free (context->rc_files);
1490 context->rc_files = NULL;
1492 gtk_rc_parse_default_files (context);
1494 tmp_list = global_rc_files;
1497 rc_file = tmp_list->data;
1499 if (rc_file->is_string)
1500 gtk_rc_context_parse_string (context, rc_file->name);
1502 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1504 tmp_list = tmp_list->next;
1507 g_free (context->theme_name);
1508 g_free (context->key_theme_name);
1510 g_object_get (context->settings,
1511 "gtk-theme-name", &context->theme_name,
1512 "gtk-key-theme-name", &context->key_theme_name,
1515 if (context->theme_name && context->theme_name[0])
1516 gtk_rc_parse_named (context, context->theme_name, NULL);
1517 if (context->key_theme_name && context->key_theme_name[0])
1518 gtk_rc_parse_named (context, context->key_theme_name, "key");
1520 g_object_thaw_notify (G_OBJECT (context->settings));
1522 gtk_rc_reset_widgets (context->settings);
1525 return force_load || mtime_modified;
1529 * gtk_rc_reparse_all:
1531 * If the modification time on any previously read file for the
1532 * default #GtkSettings has changed, discard all style information
1533 * and then reread all previously read RC files.
1535 * Return value: %TRUE if the files were reread.
1538 gtk_rc_reparse_all (void)
1541 gboolean result = FALSE;
1543 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1545 GtkRcContext *context = tmp_list->data;
1546 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1554 gtk_rc_styles_match (GSList *rc_styles,
1558 const gchar *path_reversed)
1565 rc_set = sets->data;
1568 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1569 rc_styles = g_slist_append (rc_styles, rc_set);
1576 rc_set_compare (gconstpointer a, gconstpointer b)
1578 const GtkRcSet *set_a = a;
1579 const GtkRcSet *set_b = b;
1581 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1585 sort_and_dereference_sets (GSList *styles)
1589 /* At this point, the list of sets is ordered by:
1591 * a) 'widget' patterns are earlier than 'widget_class' patterns
1592 * which are ealier than 'class' patterns.
1593 * a) For two matches for class patterns, a match to a child type
1594 * is before a match to a parent type
1595 * c) a match later in the RC file (or in a later RC file) is before a
1596 * match earlier in the RC file.
1598 * With a) taking precedence over b) which takes precendence over c).
1600 * Now sort by priority, which has the highest precendence for sort order
1602 styles = g_slist_sort (styles, rc_set_compare);
1604 /* Make styles->data = styles->data->rc_style
1609 GtkRcSet *set = tmp_list->data;
1610 tmp_list->data = set->rc_style;
1611 tmp_list = tmp_list->next;
1619 * @widget: a #GtkWidget
1621 * Finds all matching RC styles for a given widget,
1622 * composites them together, and then creates a
1623 * #GtkStyle representing the composite appearance.
1624 * (GTK+ actually keeps a cache of previously
1625 * created styles, so a new style may not be
1628 * Returns: the resulting style. No refcount is added
1629 * to the returned style, so if you want to save this
1630 * style around, you should add a reference yourself.
1633 gtk_rc_get_style (GtkWidget *widget)
1635 GtkRcStyle *widget_rc_style;
1636 GSList *rc_styles = NULL;
1637 GtkRcContext *context;
1639 static guint rc_style_key_id = 0;
1641 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1643 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1645 /* We allow the specification of a single rc style to be bound
1646 * tightly to a widget, for application modifications
1648 if (!rc_style_key_id)
1649 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1651 if (context->rc_sets_widget)
1653 gchar *path, *path_reversed;
1656 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1657 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1659 g_free (path_reversed);
1662 if (context->rc_sets_widget_class)
1664 gchar *path, *path_reversed;
1667 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1668 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1670 g_free (path_reversed);
1673 if (context->rc_sets_class)
1677 type = G_TYPE_FROM_INSTANCE (widget);
1681 gchar *path_reversed;
1684 path = g_type_name (type);
1685 path_length = strlen (path);
1686 path_reversed = g_strdup (path);
1687 g_strreverse (path_reversed);
1689 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1690 g_free (path_reversed);
1692 type = g_type_parent (type);
1696 rc_styles = sort_and_dereference_sets (rc_styles);
1698 widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
1700 if (widget_rc_style)
1701 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1704 return gtk_rc_init_style (context, rc_styles);
1707 if (!context->default_style)
1709 context->default_style = gtk_style_new ();
1710 _gtk_style_init_for_settings (context->default_style, context->settings);
1713 return context->default_style;
1718 * gtk_rc_get_style_by_paths:
1719 * @settings: a #GtkSettings object
1720 * @widget_path: the widget path to use when looking up the style, or %NULL
1721 * if no matching against the widget path should be done
1722 * @class_path: the class path to use when looking up the style, or %NULL
1723 * if no matching against the class path should be done.
1724 * @type: a type that will be used along with parent types of this type
1725 * when matching against class styles, or #G_TYPE_NONE
1727 * Creates up a #GtkStyle from styles defined in a RC file by providing
1728 * the raw components used in matching. This function may be useful
1729 * when creating pseudo-widgets that should be themed like widgets but
1730 * don't actually have corresponding GTK+ widgets. An example of this
1731 * would be items inside a GNOME canvas widget.
1733 * The action of gtk_rc_get_style() is similar to:
1734 * <informalexample><programlisting>
1735 * gtk_widget_path (widget, NULL, &path, NULL);
1736 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1737 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1738 * G_OBJECT_TYPE (widget));
1739 * </programlisting></informalexample>
1741 * Return value: A style created by matching with the supplied paths,
1742 * or %NULL if nothing matching was specified and the default style should
1743 * be used. The returned value is owned by GTK+ as part of an internal cache,
1744 * so you must call g_object_ref() on the returned value if you want to
1745 * keep a reference to it.
1748 gtk_rc_get_style_by_paths (GtkSettings *settings,
1749 const char *widget_path,
1750 const char *class_path,
1753 /* We duplicate the code from above to avoid slowing down the above
1754 * by generating paths when we don't need them. I don't know if
1755 * this is really worth it.
1757 GSList *rc_styles = NULL;
1758 GtkRcContext *context;
1760 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1762 context = gtk_rc_context_get (settings);
1764 if (widget_path && context->rc_sets_widget)
1766 gchar *path_reversed;
1769 path_length = strlen (widget_path);
1770 path_reversed = g_strdup (widget_path);
1771 g_strreverse (path_reversed);
1773 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1774 g_free (path_reversed);
1777 if (class_path && context->rc_sets_widget_class)
1779 gchar *path_reversed;
1782 path_length = strlen (class_path);
1783 path_reversed = g_strdup (class_path);
1784 g_strreverse (path_reversed);
1786 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1787 g_free (path_reversed);
1790 if (type != G_TYPE_NONE && context->rc_sets_class)
1795 gchar *path_reversed;
1798 path = g_type_name (type);
1799 path_length = strlen (path);
1800 path_reversed = g_strdup (path);
1801 g_strreverse (path_reversed);
1803 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1804 g_free (path_reversed);
1806 type = g_type_parent (type);
1810 rc_styles = sort_and_dereference_sets (rc_styles);
1813 return gtk_rc_init_style (context, rc_styles);
1819 gtk_rc_add_rc_sets (GSList *slist,
1820 GtkRcStyle *rc_style,
1821 const gchar *pattern)
1823 GtkRcStyle *new_style;
1827 new_style = gtk_rc_style_new ();
1828 *new_style = *rc_style;
1829 new_style->name = g_strdup (rc_style->name);
1830 if (rc_style->font_desc)
1831 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1833 for (i = 0; i < 5; i++)
1834 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1836 rc_set = g_new (GtkRcSet, 1);
1837 rc_set->pspec = g_pattern_spec_new (pattern);
1838 rc_set->rc_style = rc_style;
1840 return g_slist_prepend (slist, rc_set);
1844 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1845 const gchar *pattern)
1847 GtkRcContext *context;
1849 g_return_if_fail (rc_style != NULL);
1850 g_return_if_fail (pattern != NULL);
1852 context = gtk_rc_context_get (gtk_settings_get_default ());
1854 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1858 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1859 const gchar *pattern)
1861 GtkRcContext *context;
1863 g_return_if_fail (rc_style != NULL);
1864 g_return_if_fail (pattern != NULL);
1866 context = gtk_rc_context_get (gtk_settings_get_default ());
1868 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1872 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1873 const gchar *pattern)
1875 GtkRcContext *context;
1877 g_return_if_fail (rc_style != NULL);
1878 g_return_if_fail (pattern != NULL);
1880 context = gtk_rc_context_get (gtk_settings_get_default ());
1882 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1886 gtk_rc_scanner_new (void)
1888 return g_scanner_new (>k_rc_scanner_config);
1892 gtk_rc_parse_any (GtkRcContext *context,
1893 const gchar *input_name,
1895 const gchar *input_string)
1901 scanner = gtk_rc_scanner_new ();
1905 g_assert (input_string == NULL);
1907 g_scanner_input_file (scanner, input_fd);
1911 g_assert (input_string != NULL);
1913 g_scanner_input_text (scanner, input_string, strlen (input_string));
1915 scanner->input_name = input_name;
1917 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1918 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1923 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1927 guint expected_token;
1929 expected_token = gtk_rc_parse_statement (context, scanner);
1931 if (expected_token != G_TOKEN_NONE)
1938 if (scanner->scope_id == 0)
1940 /* if we are in scope 0, we know the symbol names
1941 * that are associated with certain token values.
1942 * so we look them up to make the error messages
1945 if (expected_token > GTK_RC_TOKEN_INVALID &&
1946 expected_token < GTK_RC_TOKEN_LAST)
1948 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1949 if (symbols[i].token == expected_token)
1950 msg = symbols[i].name;
1952 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1954 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1955 scanner->token < GTK_RC_TOKEN_LAST)
1957 symbol_name = "???";
1958 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1959 if (symbols[i].token == scanner->token)
1960 symbol_name = symbols[i].name;
1963 g_scanner_unexp_token (scanner,
1976 g_scanner_destroy (scanner);
1980 gtk_rc_styles_hash (const GSList *rc_styles)
1987 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1988 rc_styles = rc_styles->next;
1995 gtk_rc_styles_equal (const GSList *a,
2000 if (a->data != b->data)
2010 gtk_rc_style_hash (const gchar *name)
2016 result += (result << 3) + *name++;
2022 gtk_rc_style_equal (const gchar *a,
2025 return (strcmp (a, b) == 0);
2029 gtk_rc_style_find (GtkRcContext *context,
2032 if (context->rc_style_ht)
2033 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2039 gtk_rc_style_to_style (GtkRcContext *context,
2040 GtkRcStyle *rc_style)
2044 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2045 _gtk_style_init_for_settings (style, context->settings);
2047 style->rc_style = rc_style;
2049 gtk_rc_style_ref (rc_style);
2051 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2056 /* Reuses or frees rc_styles */
2058 gtk_rc_init_style (GtkRcContext *context,
2061 GtkStyle *style = NULL;
2064 g_return_val_if_fail (rc_styles != NULL, NULL);
2066 if (!realized_style_ht)
2067 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2068 (GEqualFunc) gtk_rc_styles_equal);
2070 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2074 GtkRcStyle *base_style = NULL;
2075 GtkRcStyle *proto_style;
2076 GtkRcStyleClass *proto_style_class;
2078 GType rc_style_type = GTK_TYPE_RC_STYLE;
2080 /* Find the the first style where the RC file specified engine "" {}
2081 * or the first derived style and use that to create the
2082 * merged style. If we only have raw GtkRcStyles, use the first
2083 * style to create the merged style.
2085 base_style = rc_styles->data;
2086 tmp_styles = rc_styles;
2089 GtkRcStyle *rc_style = tmp_styles->data;
2091 if (rc_style->engine_specified ||
2092 G_OBJECT_TYPE (rc_style) != rc_style_type)
2094 base_style = rc_style;
2098 tmp_styles = tmp_styles->next;
2101 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2102 proto_style = proto_style_class->create_rc_style (base_style);
2104 tmp_styles = rc_styles;
2107 GtkRcStyle *rc_style = tmp_styles->data;
2110 proto_style_class->merge (proto_style, rc_style);
2112 /* Point from each rc_style to the list of styles */
2113 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2114 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2116 factories = g_slist_copy (rc_style->icon_factories);
2122 while (iter != NULL)
2124 g_object_ref (iter->data);
2125 iter = g_slist_next (iter);
2128 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2133 tmp_styles = tmp_styles->next;
2136 for (i = 0; i < 5; i++)
2137 if (proto_style->bg_pixmap_name[i] &&
2138 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2140 g_free (proto_style->bg_pixmap_name[i]);
2141 proto_style->bg_pixmap_name[i] = NULL;
2144 style = gtk_rc_style_to_style (context, proto_style);
2145 gtk_rc_style_unref (proto_style);
2147 g_hash_table_insert (realized_style_ht, rc_styles, style);
2150 g_slist_free (rc_styles);
2155 /*********************
2156 * Parsing functions *
2157 *********************/
2160 rc_parse_token_or_compound (GScanner *scanner,
2162 GTokenType delimiter)
2164 guint token = g_scanner_get_next_token (scanner);
2166 /* we either scan a single token (skipping comments)
2167 * or a compund statement.
2168 * compunds are enclosed in (), [] or {} braces, we read
2169 * them in via deep recursion.
2176 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2179 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2181 case G_TOKEN_STRING:
2182 string = g_strescape (scanner->value.v_string, NULL);
2183 g_string_append (gstring, " \"");
2184 g_string_append (gstring, string);
2185 g_string_append_c (gstring, '"');
2188 case G_TOKEN_IDENTIFIER:
2189 g_string_append_c (gstring, ' ');
2190 g_string_append (gstring, scanner->value.v_identifier);
2192 case G_TOKEN_COMMENT_SINGLE:
2193 case G_TOKEN_COMMENT_MULTI:
2194 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2195 case G_TOKEN_LEFT_PAREN:
2196 g_string_append_c (gstring, ' ');
2197 g_string_append_c (gstring, token);
2198 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2199 if (token != G_TOKEN_NONE)
2202 case G_TOKEN_LEFT_CURLY:
2203 g_string_append_c (gstring, ' ');
2204 g_string_append_c (gstring, token);
2205 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2206 if (token != G_TOKEN_NONE)
2209 case G_TOKEN_LEFT_BRACE:
2210 g_string_append_c (gstring, ' ');
2211 g_string_append_c (gstring, token);
2212 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2213 if (token != G_TOKEN_NONE)
2217 if (token >= 256 || token < 1)
2218 return delimiter ? delimiter : G_TOKEN_STRING;
2219 g_string_append_c (gstring, ' ');
2220 g_string_append_c (gstring, token);
2221 if (token == delimiter)
2222 return G_TOKEN_NONE;
2226 return G_TOKEN_NONE;
2228 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2232 gtk_rc_parse_assignment (GScanner *scanner,
2233 GtkRcProperty *prop)
2235 gboolean scan_identifier = scanner->config->scan_identifier;
2236 gboolean scan_symbols = scanner->config->scan_symbols;
2237 gboolean identifier_2_string = scanner->config->identifier_2_string;
2238 gboolean char_2_token = scanner->config->char_2_token;
2239 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2240 gboolean numbers_2_int = scanner->config->numbers_2_int;
2241 gboolean negate = FALSE;
2244 /* check that this is an assignment */
2245 if (g_scanner_get_next_token (scanner) != '=')
2248 /* adjust scanner mode */
2249 scanner->config->scan_identifier = TRUE;
2250 scanner->config->scan_symbols = FALSE;
2251 scanner->config->identifier_2_string = FALSE;
2252 scanner->config->char_2_token = TRUE;
2253 scanner->config->scan_identifier_NULL = FALSE;
2254 scanner->config->numbers_2_int = TRUE;
2256 /* record location */
2257 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2259 /* parse optional sign */
2260 if (g_scanner_peek_next_token (scanner) == '-')
2262 g_scanner_get_next_token (scanner); /* eat sign */
2266 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2267 token = g_scanner_peek_next_token (scanner);
2271 g_scanner_get_next_token (scanner);
2272 g_value_init (&prop->value, G_TYPE_LONG);
2273 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2274 token = G_TOKEN_NONE;
2277 g_scanner_get_next_token (scanner);
2278 g_value_init (&prop->value, G_TYPE_DOUBLE);
2279 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2280 token = G_TOKEN_NONE;
2282 case G_TOKEN_STRING:
2283 g_scanner_get_next_token (scanner);
2285 token = G_TOKEN_INT;
2288 g_value_init (&prop->value, G_TYPE_STRING);
2289 g_value_set_string (&prop->value, scanner->value.v_string);
2290 token = G_TOKEN_NONE;
2293 case G_TOKEN_IDENTIFIER:
2294 case G_TOKEN_LEFT_PAREN:
2295 case G_TOKEN_LEFT_CURLY:
2296 case G_TOKEN_LEFT_BRACE:
2299 GString *gstring = g_string_new (NULL);
2301 token = rc_parse_token_or_compound (scanner, gstring, 0);
2302 if (token == G_TOKEN_NONE)
2304 g_string_append_c (gstring, ' ');
2305 g_value_init (&prop->value, G_TYPE_GSTRING);
2306 g_value_set_static_boxed (&prop->value, gstring);
2309 g_string_free (gstring, TRUE);
2314 g_scanner_get_next_token (scanner);
2315 token = G_TOKEN_INT;
2319 /* restore scanner mode */
2320 scanner->config->scan_identifier = scan_identifier;
2321 scanner->config->scan_symbols = scan_symbols;
2322 scanner->config->identifier_2_string = identifier_2_string;
2323 scanner->config->char_2_token = char_2_token;
2324 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2325 scanner->config->numbers_2_int = numbers_2_int;
2331 is_c_identifier (const gchar *string)
2334 gboolean is_varname;
2336 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2337 for (p = string + 1; *p && is_varname; p++)
2338 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2344 parse_include_file (GtkRcContext *context,
2346 const gchar *filename)
2348 char *to_parse = NULL;
2350 if (g_path_is_absolute (filename))
2352 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2353 * don't print an error in this case.
2355 to_parse = g_strdup (filename);
2359 /* if a relative path, we look relative to all the RC files in the
2360 * include stack. We require the file to be found in this case
2361 * so we can give meaningful error messages, and because on reparsing
2362 * non-absolute paths don't make sense.
2364 GSList *tmp_list = current_files_stack;
2367 GtkRcFile *curfile = tmp_list->data;
2368 gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
2370 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2378 tmp_list = tmp_list->next;
2384 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2389 g_scanner_warn (scanner,
2390 _("Unable to find include file: \"%s\""),
2397 gtk_rc_parse_statement (GtkRcContext *context,
2402 token = g_scanner_peek_next_token (scanner);
2405 case GTK_RC_TOKEN_INCLUDE:
2406 token = g_scanner_get_next_token (scanner);
2407 if (token != GTK_RC_TOKEN_INCLUDE)
2408 return GTK_RC_TOKEN_INCLUDE;
2409 token = g_scanner_get_next_token (scanner);
2410 if (token != G_TOKEN_STRING)
2411 return G_TOKEN_STRING;
2412 parse_include_file (context, scanner, scanner->value.v_string);
2413 return G_TOKEN_NONE;
2415 case GTK_RC_TOKEN_STYLE:
2416 return gtk_rc_parse_style (context, scanner);
2418 case GTK_RC_TOKEN_BINDING:
2419 return gtk_binding_parse_binding (scanner);
2421 case GTK_RC_TOKEN_PIXMAP_PATH:
2422 return gtk_rc_parse_pixmap_path (context, scanner);
2424 case GTK_RC_TOKEN_WIDGET:
2425 return gtk_rc_parse_path_pattern (context, scanner);
2427 case GTK_RC_TOKEN_WIDGET_CLASS:
2428 return gtk_rc_parse_path_pattern (context, scanner);
2430 case GTK_RC_TOKEN_CLASS:
2431 return gtk_rc_parse_path_pattern (context, scanner);
2433 case GTK_RC_TOKEN_MODULE_PATH:
2434 return gtk_rc_parse_module_path (scanner);
2436 case GTK_RC_TOKEN_IM_MODULE_FILE:
2437 return gtk_rc_parse_im_module_file (scanner);
2439 case G_TOKEN_IDENTIFIER:
2440 if (is_c_identifier (scanner->next_value.v_identifier))
2442 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2445 g_scanner_get_next_token (scanner); /* eat identifier */
2446 name = g_strdup (scanner->value.v_identifier);
2448 token = gtk_rc_parse_assignment (scanner, &prop);
2449 if (token == G_TOKEN_NONE)
2451 GtkSettingsValue svalue;
2453 svalue.origin = prop.origin;
2454 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2455 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2456 _gtk_settings_set_property_value_from_rc (context->settings,
2460 g_free (prop.origin);
2461 if (G_VALUE_TYPE (&prop.value))
2462 g_value_unset (&prop.value);
2469 g_scanner_get_next_token (scanner);
2470 return G_TOKEN_IDENTIFIER;
2473 g_scanner_get_next_token (scanner);
2474 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2479 fixup_rc_set (GSList *list,
2485 GtkRcSet *set = list->data;
2486 if (set->rc_style == orig)
2487 set->rc_style = new;
2493 fixup_rc_sets (GtkRcContext *context,
2497 fixup_rc_set (context->rc_sets_widget, orig, new);
2498 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2499 fixup_rc_set (context->rc_sets_class, orig, new);
2503 gtk_rc_parse_style (GtkRcContext *context,
2506 GtkRcStyle *rc_style;
2507 GtkRcStyle *orig_style;
2508 GtkRcStyle *parent_style;
2511 GtkIconFactory *our_factory = NULL;
2513 token = g_scanner_get_next_token (scanner);
2514 if (token != GTK_RC_TOKEN_STYLE)
2515 return GTK_RC_TOKEN_STYLE;
2517 token = g_scanner_get_next_token (scanner);
2518 if (token != G_TOKEN_STRING)
2519 return G_TOKEN_STRING;
2521 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2523 orig_style = g_object_ref (rc_style);
2527 /* If there's a list, its first member is always the factory belonging
2530 if (rc_style && rc_style->icon_factories)
2531 our_factory = rc_style->icon_factories->data;
2535 rc_style = gtk_rc_style_new ();
2536 rc_style->name = g_strdup (scanner->value.v_string);
2538 for (i = 0; i < 5; i++)
2539 rc_style->bg_pixmap_name[i] = NULL;
2541 for (i = 0; i < 5; i++)
2542 rc_style->color_flags[i] = 0;
2545 token = g_scanner_peek_next_token (scanner);
2546 if (token == G_TOKEN_EQUAL_SIGN)
2548 token = g_scanner_get_next_token (scanner);
2550 token = g_scanner_get_next_token (scanner);
2551 if (token != G_TOKEN_STRING)
2553 token = G_TOKEN_STRING;
2557 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2562 for (i = 0; i < 5; i++)
2564 rc_style->color_flags[i] = parent_style->color_flags[i];
2565 rc_style->fg[i] = parent_style->fg[i];
2566 rc_style->bg[i] = parent_style->bg[i];
2567 rc_style->text[i] = parent_style->text[i];
2568 rc_style->base[i] = parent_style->base[i];
2571 rc_style->xthickness = parent_style->xthickness;
2572 rc_style->ythickness = parent_style->ythickness;
2574 if (parent_style->font_desc)
2576 if (rc_style->font_desc)
2577 pango_font_description_free (rc_style->font_desc);
2578 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2581 if (parent_style->rc_properties)
2585 for (i = 0; i < parent_style->rc_properties->len; i++)
2586 insert_rc_property (rc_style,
2587 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2591 for (i = 0; i < 5; i++)
2593 if (rc_style->bg_pixmap_name[i])
2594 g_free (rc_style->bg_pixmap_name[i]);
2595 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2598 /* Append parent's factories, adding a ref to them */
2599 if (parent_style->icon_factories != NULL)
2601 /* Add a factory for ourselves if we have none,
2602 * in case we end up defining more stock icons.
2603 * I see no real way around this; we need to maintain
2604 * the invariant that the first factory in the list
2605 * is always our_factory, the one belonging to us,
2606 * and if we put parent factories in the list we can't
2607 * do that if the style is reopened.
2609 if (our_factory == NULL)
2611 our_factory = gtk_icon_factory_new ();
2612 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2616 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2617 g_slist_copy (parent_style->icon_factories));
2619 factories = parent_style->icon_factories;
2620 while (factories != NULL)
2622 g_object_ref (factories->data);
2623 factories = factories->next;
2629 token = g_scanner_get_next_token (scanner);
2630 if (token != G_TOKEN_LEFT_CURLY)
2632 token = G_TOKEN_LEFT_CURLY;
2636 token = g_scanner_peek_next_token (scanner);
2637 while (token != G_TOKEN_RIGHT_CURLY)
2641 case GTK_RC_TOKEN_BG:
2642 token = gtk_rc_parse_bg (scanner, rc_style);
2644 case GTK_RC_TOKEN_FG:
2645 token = gtk_rc_parse_fg (scanner, rc_style);
2647 case GTK_RC_TOKEN_TEXT:
2648 token = gtk_rc_parse_text (scanner, rc_style);
2650 case GTK_RC_TOKEN_BASE:
2651 token = gtk_rc_parse_base (scanner, rc_style);
2653 case GTK_RC_TOKEN_XTHICKNESS:
2654 token = gtk_rc_parse_xthickness (scanner, rc_style);
2656 case GTK_RC_TOKEN_YTHICKNESS:
2657 token = gtk_rc_parse_ythickness (scanner, rc_style);
2659 case GTK_RC_TOKEN_BG_PIXMAP:
2660 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2662 case GTK_RC_TOKEN_FONT:
2663 token = gtk_rc_parse_font (scanner, rc_style);
2665 case GTK_RC_TOKEN_FONTSET:
2666 token = gtk_rc_parse_fontset (scanner, rc_style);
2668 case GTK_RC_TOKEN_FONT_NAME:
2669 token = gtk_rc_parse_font_name (scanner, rc_style);
2671 case GTK_RC_TOKEN_ENGINE:
2672 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2674 case GTK_RC_TOKEN_STOCK:
2675 if (our_factory == NULL)
2677 our_factory = gtk_icon_factory_new ();
2678 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2681 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2683 case G_TOKEN_IDENTIFIER:
2684 if (is_c_identifier (scanner->next_value.v_identifier) &&
2685 scanner->next_value.v_identifier[0] >= 'A' &&
2686 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2688 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2690 g_scanner_get_next_token (scanner); /* eat type name */
2691 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2692 if (g_scanner_get_next_token (scanner) != ':' ||
2693 g_scanner_get_next_token (scanner) != ':')
2698 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2699 !is_c_identifier (scanner->value.v_identifier))
2701 token = G_TOKEN_IDENTIFIER;
2705 /* it's important that we do the same canonification as GParamSpecPool here */
2706 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2707 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2709 token = gtk_rc_parse_assignment (scanner, &prop);
2710 if (token == G_TOKEN_NONE)
2712 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2713 insert_rc_property (rc_style, &prop, TRUE);
2716 g_free (prop.origin);
2717 if (G_VALUE_TYPE (&prop.value))
2718 g_value_unset (&prop.value);
2722 g_scanner_get_next_token (scanner);
2723 token = G_TOKEN_IDENTIFIER;
2727 g_scanner_get_next_token (scanner);
2728 token = G_TOKEN_RIGHT_CURLY;
2732 if (token != G_TOKEN_NONE)
2735 token = g_scanner_peek_next_token (scanner);
2736 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2738 token = g_scanner_get_next_token (scanner);
2739 if (token != G_TOKEN_RIGHT_CURLY)
2741 token = G_TOKEN_RIGHT_CURLY;
2745 if (rc_style != orig_style)
2747 if (!context->rc_style_ht)
2748 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2749 (GEqualFunc) gtk_rc_style_equal);
2751 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2753 /* If we copied the data into a new rc style, fix up references to the old rc style
2754 * in bindings that we have.
2757 fixup_rc_sets (context, orig_style, rc_style);
2761 g_object_unref (orig_style);
2763 return G_TOKEN_NONE;
2766 if (rc_style != orig_style)
2767 gtk_rc_style_unref (rc_style);
2770 g_object_unref (orig_style);
2775 const GtkRcProperty*
2776 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2778 GQuark property_name)
2780 GtkRcProperty *node = NULL;
2782 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2784 if (rc_style->rc_properties)
2788 key.type_name = type_name;
2789 key.property_name = property_name;
2791 node = bsearch (&key,
2792 rc_style->rc_properties->data, rc_style->rc_properties->len,
2793 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2800 gtk_rc_parse_bg (GScanner *scanner,
2806 token = g_scanner_get_next_token (scanner);
2807 if (token != GTK_RC_TOKEN_BG)
2808 return GTK_RC_TOKEN_BG;
2810 token = gtk_rc_parse_state (scanner, &state);
2811 if (token != G_TOKEN_NONE)
2814 token = g_scanner_get_next_token (scanner);
2815 if (token != G_TOKEN_EQUAL_SIGN)
2816 return G_TOKEN_EQUAL_SIGN;
2818 style->color_flags[state] |= GTK_RC_BG;
2819 return gtk_rc_parse_color (scanner, &style->bg[state]);
2823 gtk_rc_parse_fg (GScanner *scanner,
2829 token = g_scanner_get_next_token (scanner);
2830 if (token != GTK_RC_TOKEN_FG)
2831 return GTK_RC_TOKEN_FG;
2833 token = gtk_rc_parse_state (scanner, &state);
2834 if (token != G_TOKEN_NONE)
2837 token = g_scanner_get_next_token (scanner);
2838 if (token != G_TOKEN_EQUAL_SIGN)
2839 return G_TOKEN_EQUAL_SIGN;
2841 style->color_flags[state] |= GTK_RC_FG;
2842 return gtk_rc_parse_color (scanner, &style->fg[state]);
2846 gtk_rc_parse_text (GScanner *scanner,
2852 token = g_scanner_get_next_token (scanner);
2853 if (token != GTK_RC_TOKEN_TEXT)
2854 return GTK_RC_TOKEN_TEXT;
2856 token = gtk_rc_parse_state (scanner, &state);
2857 if (token != G_TOKEN_NONE)
2860 token = g_scanner_get_next_token (scanner);
2861 if (token != G_TOKEN_EQUAL_SIGN)
2862 return G_TOKEN_EQUAL_SIGN;
2864 style->color_flags[state] |= GTK_RC_TEXT;
2865 return gtk_rc_parse_color (scanner, &style->text[state]);
2869 gtk_rc_parse_base (GScanner *scanner,
2875 token = g_scanner_get_next_token (scanner);
2876 if (token != GTK_RC_TOKEN_BASE)
2877 return GTK_RC_TOKEN_BASE;
2879 token = gtk_rc_parse_state (scanner, &state);
2880 if (token != G_TOKEN_NONE)
2883 token = g_scanner_get_next_token (scanner);
2884 if (token != G_TOKEN_EQUAL_SIGN)
2885 return G_TOKEN_EQUAL_SIGN;
2887 style->color_flags[state] |= GTK_RC_BASE;
2888 return gtk_rc_parse_color (scanner, &style->base[state]);
2892 gtk_rc_parse_xthickness (GScanner *scanner,
2895 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2896 return GTK_RC_TOKEN_XTHICKNESS;
2898 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2899 return G_TOKEN_EQUAL_SIGN;
2901 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2904 style->xthickness = scanner->value.v_int;
2906 return G_TOKEN_NONE;
2910 gtk_rc_parse_ythickness (GScanner *scanner,
2913 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2914 return GTK_RC_TOKEN_YTHICKNESS;
2916 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2917 return G_TOKEN_EQUAL_SIGN;
2919 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2922 style->ythickness = scanner->value.v_int;
2924 return G_TOKEN_NONE;
2928 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2930 GtkRcStyle *rc_style)
2936 token = g_scanner_get_next_token (scanner);
2937 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2938 return GTK_RC_TOKEN_BG_PIXMAP;
2940 token = gtk_rc_parse_state (scanner, &state);
2941 if (token != G_TOKEN_NONE)
2944 token = g_scanner_get_next_token (scanner);
2945 if (token != G_TOKEN_EQUAL_SIGN)
2946 return G_TOKEN_EQUAL_SIGN;
2948 token = g_scanner_get_next_token (scanner);
2949 if (token != G_TOKEN_STRING)
2950 return G_TOKEN_STRING;
2952 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2953 (strcmp (scanner->value.v_string, "<none>") == 0))
2954 pixmap_file = g_strdup (scanner->value.v_string);
2956 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2957 scanner, scanner->value.v_string);
2961 if (rc_style->bg_pixmap_name[state])
2962 g_free (rc_style->bg_pixmap_name[state]);
2963 rc_style->bg_pixmap_name[state] = pixmap_file;
2966 return G_TOKEN_NONE;
2970 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2975 buf = g_build_filename (dir, pixmap_file, NULL);
2977 fd = open (buf, O_RDONLY);
2990 * gtk_rc_find_pixmap_in_path:
2991 * @settings: a #GtkSettings
2992 * @scanner: Scanner used to get line number information for the
2993 * warning message, or %NULL
2994 * @pixmap_file: name of the pixmap file to locate.
2996 * Looks up a file in pixmap path for the specified #GtkSettings.
2997 * If the file is not found, it outputs a warning message using
2998 * g_warning() and returns %NULL.
3000 * Return value: the filename.
3003 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
3005 const gchar *pixmap_file)
3011 GtkRcContext *context = gtk_rc_context_get (settings);
3013 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
3015 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
3020 tmp_list = current_files_stack;
3023 GtkRcFile *curfile = tmp_list->data;
3024 filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
3028 tmp_list = tmp_list->next;
3032 g_scanner_warn (scanner,
3033 _("Unable to locate image file in pixmap_path: \"%s\""),
3036 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3043 * gtk_rc_find_module_in_path:
3044 * @module_file: name of a theme engine
3046 * Searches for a theme engine in the GTK+ search path. This function
3047 * is not useful for applications and should not be used.
3049 * Return value: The filename, if found (must be freed with g_free()),
3053 gtk_rc_find_module_in_path (const gchar *module_file)
3055 return _gtk_find_module (module_file, "engines");
3059 gtk_rc_parse_font (GScanner *scanner,
3060 GtkRcStyle *rc_style)
3064 token = g_scanner_get_next_token (scanner);
3065 if (token != GTK_RC_TOKEN_FONT)
3066 return GTK_RC_TOKEN_FONT;
3068 token = g_scanner_get_next_token (scanner);
3069 if (token != G_TOKEN_EQUAL_SIGN)
3070 return G_TOKEN_EQUAL_SIGN;
3072 token = g_scanner_get_next_token (scanner);
3073 if (token != G_TOKEN_STRING)
3074 return G_TOKEN_STRING;
3076 /* Ignore, do nothing */
3078 return G_TOKEN_NONE;
3082 gtk_rc_parse_fontset (GScanner *scanner,
3083 GtkRcStyle *rc_style)
3087 token = g_scanner_get_next_token (scanner);
3088 if (token != GTK_RC_TOKEN_FONTSET)
3089 return GTK_RC_TOKEN_FONTSET;
3091 token = g_scanner_get_next_token (scanner);
3092 if (token != G_TOKEN_EQUAL_SIGN)
3093 return G_TOKEN_EQUAL_SIGN;
3095 token = g_scanner_get_next_token (scanner);
3096 if (token != G_TOKEN_STRING)
3097 return G_TOKEN_STRING;
3099 /* Do nothing - silently ignore */
3101 return G_TOKEN_NONE;
3105 gtk_rc_parse_font_name (GScanner *scanner,
3106 GtkRcStyle *rc_style)
3110 token = g_scanner_get_next_token (scanner);
3111 if (token != GTK_RC_TOKEN_FONT_NAME)
3112 return GTK_RC_TOKEN_FONT;
3114 token = g_scanner_get_next_token (scanner);
3115 if (token != G_TOKEN_EQUAL_SIGN)
3116 return G_TOKEN_EQUAL_SIGN;
3118 token = g_scanner_get_next_token (scanner);
3119 if (token != G_TOKEN_STRING)
3120 return G_TOKEN_STRING;
3122 if (rc_style->font_desc)
3123 pango_font_description_free (rc_style->font_desc);
3125 rc_style->font_desc =
3126 pango_font_description_from_string (scanner->value.v_string);
3128 return G_TOKEN_NONE;
3132 gtk_rc_parse_engine (GtkRcContext *context,
3134 GtkRcStyle **rc_style)
3137 GtkThemeEngine *engine;
3138 guint result = G_TOKEN_NONE;
3139 GtkRcStyle *new_style = NULL;
3140 gboolean parsed_curlies = FALSE;
3142 token = g_scanner_get_next_token (scanner);
3143 if (token != GTK_RC_TOKEN_ENGINE)
3144 return GTK_RC_TOKEN_ENGINE;
3146 token = g_scanner_get_next_token (scanner);
3147 if (token != G_TOKEN_STRING)
3148 return G_TOKEN_STRING;
3150 if (!scanner->value.v_string[0])
3152 /* Support engine "" {} to mean override to the default engine
3154 token = g_scanner_get_next_token (scanner);
3155 if (token != G_TOKEN_LEFT_CURLY)
3156 return G_TOKEN_LEFT_CURLY;
3158 token = g_scanner_get_next_token (scanner);
3159 if (token != G_TOKEN_RIGHT_CURLY)
3160 return G_TOKEN_RIGHT_CURLY;
3162 parsed_curlies = TRUE;
3164 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3166 new_style = gtk_rc_style_new ();
3167 gtk_rc_style_real_merge (new_style, *rc_style);
3169 if ((*rc_style)->name)
3170 new_style->name = g_strdup ((*rc_style)->name);
3173 (*rc_style)->engine_specified = TRUE;
3177 engine = gtk_theme_engine_get (scanner->value.v_string);
3179 token = g_scanner_get_next_token (scanner);
3180 if (token != G_TOKEN_LEFT_CURLY)
3181 return G_TOKEN_LEFT_CURLY;
3185 GtkRcStyleClass *new_class;
3187 new_style = gtk_theme_engine_create_rc_style (engine);
3188 g_type_module_unuse (G_TYPE_MODULE (engine));
3190 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3192 new_class->merge (new_style, *rc_style);
3193 if ((*rc_style)->name)
3194 new_style->name = g_strdup ((*rc_style)->name);
3196 if (new_class->parse)
3198 parsed_curlies = TRUE;
3199 result = new_class->parse (new_style, context->settings, scanner);
3201 if (result != G_TOKEN_NONE)
3203 g_object_unref (new_style);
3210 if (!parsed_curlies)
3212 /* Skip over remainder, looking for nested {}'s
3216 result = G_TOKEN_RIGHT_CURLY;
3217 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3219 if (token == G_TOKEN_LEFT_CURLY)
3221 else if (token == G_TOKEN_RIGHT_CURLY)
3226 result = G_TOKEN_NONE;
3234 new_style->engine_specified = TRUE;
3236 g_object_unref (*rc_style);
3237 *rc_style = new_style;
3244 gtk_rc_parse_state (GScanner *scanner,
3245 GtkStateType *state)
3250 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3251 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3253 /* we don't know where we got called from, so we reset the scope here.
3254 * if we bail out due to errors, we *don't* reset the scope, so the
3255 * error messaging code can make sense of our tokens.
3257 old_scope = g_scanner_set_scope (scanner, 0);
3259 token = g_scanner_get_next_token (scanner);
3260 if (token != G_TOKEN_LEFT_BRACE)
3261 return G_TOKEN_LEFT_BRACE;
3263 token = g_scanner_get_next_token (scanner);
3266 case GTK_RC_TOKEN_ACTIVE:
3267 *state = GTK_STATE_ACTIVE;
3269 case GTK_RC_TOKEN_INSENSITIVE:
3270 *state = GTK_STATE_INSENSITIVE;
3272 case GTK_RC_TOKEN_NORMAL:
3273 *state = GTK_STATE_NORMAL;
3275 case GTK_RC_TOKEN_PRELIGHT:
3276 *state = GTK_STATE_PRELIGHT;
3278 case GTK_RC_TOKEN_SELECTED:
3279 *state = GTK_STATE_SELECTED;
3282 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3285 token = g_scanner_get_next_token (scanner);
3286 if (token != G_TOKEN_RIGHT_BRACE)
3287 return G_TOKEN_RIGHT_BRACE;
3289 g_scanner_set_scope (scanner, old_scope);
3291 return G_TOKEN_NONE;
3295 gtk_rc_parse_priority (GScanner *scanner,
3296 GtkPathPriorityType *priority)
3301 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3302 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3304 /* we don't know where we got called from, so we reset the scope here.
3305 * if we bail out due to errors, we *don't* reset the scope, so the
3306 * error messaging code can make sense of our tokens.
3308 old_scope = g_scanner_set_scope (scanner, 0);
3310 token = g_scanner_get_next_token (scanner);
3314 token = g_scanner_get_next_token (scanner);
3317 case GTK_RC_TOKEN_LOWEST:
3318 *priority = GTK_PATH_PRIO_LOWEST;
3320 case GTK_RC_TOKEN_GTK:
3321 *priority = GTK_PATH_PRIO_GTK;
3323 case GTK_RC_TOKEN_APPLICATION:
3324 *priority = GTK_PATH_PRIO_APPLICATION;
3326 case GTK_RC_TOKEN_THEME:
3327 *priority = GTK_PATH_PRIO_THEME;
3329 case GTK_RC_TOKEN_RC:
3330 *priority = GTK_PATH_PRIO_RC;
3332 case GTK_RC_TOKEN_HIGHEST:
3333 *priority = GTK_PATH_PRIO_HIGHEST;
3336 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3339 g_scanner_set_scope (scanner, old_scope);
3341 return G_TOKEN_NONE;
3345 gtk_rc_parse_color (GScanner *scanner,
3350 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3352 /* we don't need to set our own scope here, because
3353 * we don't need own symbols
3356 token = g_scanner_get_next_token (scanner);
3361 case G_TOKEN_LEFT_CURLY:
3362 token = g_scanner_get_next_token (scanner);
3363 if (token == G_TOKEN_INT)
3364 token_int = scanner->value.v_int;
3365 else if (token == G_TOKEN_FLOAT)
3366 token_int = scanner->value.v_float * 65535.0;
3368 return G_TOKEN_FLOAT;
3369 color->red = CLAMP (token_int, 0, 65535);
3371 token = g_scanner_get_next_token (scanner);
3372 if (token != G_TOKEN_COMMA)
3373 return G_TOKEN_COMMA;
3375 token = g_scanner_get_next_token (scanner);
3376 if (token == G_TOKEN_INT)
3377 token_int = scanner->value.v_int;
3378 else if (token == G_TOKEN_FLOAT)
3379 token_int = scanner->value.v_float * 65535.0;
3381 return G_TOKEN_FLOAT;
3382 color->green = CLAMP (token_int, 0, 65535);
3384 token = g_scanner_get_next_token (scanner);
3385 if (token != G_TOKEN_COMMA)
3386 return G_TOKEN_COMMA;
3388 token = g_scanner_get_next_token (scanner);
3389 if (token == G_TOKEN_INT)
3390 token_int = scanner->value.v_int;
3391 else if (token == G_TOKEN_FLOAT)
3392 token_int = scanner->value.v_float * 65535.0;
3394 return G_TOKEN_FLOAT;
3395 color->blue = CLAMP (token_int, 0, 65535);
3397 token = g_scanner_get_next_token (scanner);
3398 if (token != G_TOKEN_RIGHT_CURLY)
3399 return G_TOKEN_RIGHT_CURLY;
3400 return G_TOKEN_NONE;
3402 case G_TOKEN_STRING:
3403 if (!gdk_color_parse (scanner->value.v_string, color))
3405 g_scanner_warn (scanner, "Invalid color constant '%s'",
3406 scanner->value.v_string);
3407 return G_TOKEN_STRING;
3410 return G_TOKEN_NONE;
3413 return G_TOKEN_STRING;
3418 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3423 token = g_scanner_get_next_token (scanner);
3424 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3425 return GTK_RC_TOKEN_PIXMAP_PATH;
3427 token = g_scanner_get_next_token (scanner);
3428 if (token != G_TOKEN_STRING)
3429 return G_TOKEN_STRING;
3431 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3433 return G_TOKEN_NONE;
3437 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3439 const gchar *pix_path)
3442 gint start_offset = 0;
3446 /* free the old one, or just add to the old one ? */
3447 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3449 g_free (context->pixmap_path[path_num]);
3450 context->pixmap_path[path_num] = NULL;
3455 path_len = strlen (pix_path);
3457 for (end_offset = 0; end_offset <= path_len; end_offset++)
3459 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3460 (end_offset == path_len))
3462 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3463 if (g_path_is_absolute (path_element))
3465 context->pixmap_path[path_num] = path_element;
3467 context->pixmap_path[path_num] = NULL;
3471 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3472 path_element, scanner->input_name, scanner->line);
3473 g_free (path_element);
3476 start_offset = end_offset + 1;
3482 gtk_rc_parse_module_path (GScanner *scanner)
3486 token = g_scanner_get_next_token (scanner);
3487 if (token != GTK_RC_TOKEN_MODULE_PATH)
3488 return GTK_RC_TOKEN_MODULE_PATH;
3490 token = g_scanner_get_next_token (scanner);
3491 if (token != G_TOKEN_STRING)
3492 return G_TOKEN_STRING;
3494 g_warning ("module_path directive is now ignored\n");
3496 return G_TOKEN_NONE;
3500 gtk_rc_parse_im_module_file (GScanner *scanner)
3504 token = g_scanner_get_next_token (scanner);
3505 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3506 return GTK_RC_TOKEN_IM_MODULE_FILE;
3508 token = g_scanner_get_next_token (scanner);
3509 if (token != G_TOKEN_STRING)
3510 return G_TOKEN_STRING;
3513 g_free (im_module_file);
3515 im_module_file = g_strdup (scanner->value.v_string);
3517 return G_TOKEN_NONE;
3521 gtk_rc_parse_path_pattern (GtkRcContext *context,
3525 GtkPathType path_type;
3527 gboolean is_binding;
3528 GtkPathPriorityType priority = context->default_priority;
3530 token = g_scanner_get_next_token (scanner);
3533 case GTK_RC_TOKEN_WIDGET:
3534 path_type = GTK_PATH_WIDGET;
3536 case GTK_RC_TOKEN_WIDGET_CLASS:
3537 path_type = GTK_PATH_WIDGET_CLASS;
3539 case GTK_RC_TOKEN_CLASS:
3540 path_type = GTK_PATH_CLASS;
3543 return GTK_RC_TOKEN_WIDGET_CLASS;
3546 token = g_scanner_get_next_token (scanner);
3547 if (token != G_TOKEN_STRING)
3548 return G_TOKEN_STRING;
3550 pattern = g_strdup (scanner->value.v_string);
3552 token = g_scanner_get_next_token (scanner);
3553 if (token == GTK_RC_TOKEN_STYLE)
3555 else if (token == GTK_RC_TOKEN_BINDING)
3560 return GTK_RC_TOKEN_STYLE;
3563 if (g_scanner_peek_next_token (scanner) == ':')
3565 token = gtk_rc_parse_priority (scanner, &priority);
3566 if (token != G_TOKEN_NONE)
3573 token = g_scanner_get_next_token (scanner);
3574 if (token != G_TOKEN_STRING)
3577 return G_TOKEN_STRING;
3582 GtkBindingSet *binding;
3584 binding = gtk_binding_set_find (scanner->value.v_string);
3588 return G_TOKEN_STRING;
3590 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3594 GtkRcStyle *rc_style;
3597 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3602 return G_TOKEN_STRING;
3605 rc_set = g_new (GtkRcSet, 1);
3606 rc_set->pspec = g_pattern_spec_new (pattern);
3607 rc_set->rc_style = rc_style;
3608 rc_set->priority = priority;
3610 if (path_type == GTK_PATH_WIDGET)
3611 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3612 else if (path_type == GTK_PATH_WIDGET_CLASS)
3613 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3615 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3619 return G_TOKEN_NONE;
3623 gtk_rc_parse_stock_id (GScanner *scanner,
3628 token = g_scanner_get_next_token (scanner);
3629 if (token != G_TOKEN_LEFT_BRACE)
3630 return G_TOKEN_LEFT_BRACE;
3632 token = g_scanner_get_next_token (scanner);
3634 if (token != G_TOKEN_STRING)
3635 return G_TOKEN_STRING;
3637 *stock_id = g_strdup (scanner->value.v_string);
3639 token = g_scanner_get_next_token (scanner);
3640 if (token != G_TOKEN_RIGHT_BRACE)
3643 return G_TOKEN_RIGHT_BRACE;
3646 return G_TOKEN_NONE;
3650 gtk_rc_parse_icon_source (GtkRcContext *context,
3652 GtkIconSet *icon_set,
3653 gboolean *icon_set_valid)
3656 GtkIconSource *source;
3657 gchar *full_filename;
3659 token = g_scanner_get_next_token (scanner);
3660 if (token != G_TOKEN_LEFT_CURLY)
3661 return G_TOKEN_LEFT_CURLY;
3663 token = g_scanner_get_next_token (scanner);
3665 if (token != G_TOKEN_STRING && token != '@')
3666 return G_TOKEN_STRING;
3668 source = gtk_icon_source_new ();
3670 if (token == G_TOKEN_STRING)
3674 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3677 gtk_icon_source_set_filename (source, full_filename);
3678 g_free (full_filename);
3685 token = g_scanner_get_next_token (scanner);
3687 if (token != G_TOKEN_STRING)
3688 return G_TOKEN_STRING;
3690 gtk_icon_source_set_icon_name (source, scanner->value.v_string);
3693 /* We continue parsing even if we didn't find the pixmap so that rest of the
3694 * file is read, even if the syntax is bad. However we don't validate the
3695 * icon_set so the caller can choose not to install it.
3697 token = g_scanner_get_next_token (scanner);
3699 if (token == G_TOKEN_RIGHT_CURLY)
3701 else if (token != G_TOKEN_COMMA)
3703 gtk_icon_source_free (source);
3704 return G_TOKEN_COMMA;
3707 /* Get the direction */
3709 token = g_scanner_get_next_token (scanner);
3713 case GTK_RC_TOKEN_RTL:
3714 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3715 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3718 case GTK_RC_TOKEN_LTR:
3719 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3720 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3727 gtk_icon_source_free (source);
3728 return GTK_RC_TOKEN_RTL;
3732 token = g_scanner_get_next_token (scanner);
3734 if (token == G_TOKEN_RIGHT_CURLY)
3736 else if (token != G_TOKEN_COMMA)
3738 gtk_icon_source_free (source);
3739 return G_TOKEN_COMMA;
3744 token = g_scanner_get_next_token (scanner);
3748 case GTK_RC_TOKEN_NORMAL:
3749 gtk_icon_source_set_state_wildcarded (source, FALSE);
3750 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3753 case GTK_RC_TOKEN_PRELIGHT:
3754 gtk_icon_source_set_state_wildcarded (source, FALSE);
3755 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3759 case GTK_RC_TOKEN_INSENSITIVE:
3760 gtk_icon_source_set_state_wildcarded (source, FALSE);
3761 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3764 case GTK_RC_TOKEN_ACTIVE:
3765 gtk_icon_source_set_state_wildcarded (source, FALSE);
3766 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3769 case GTK_RC_TOKEN_SELECTED:
3770 gtk_icon_source_set_state_wildcarded (source, FALSE);
3771 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3778 gtk_icon_source_free (source);
3779 return GTK_RC_TOKEN_PRELIGHT;
3783 token = g_scanner_get_next_token (scanner);
3785 if (token == G_TOKEN_RIGHT_CURLY)
3787 else if (token != G_TOKEN_COMMA)
3789 gtk_icon_source_free (source);
3790 return G_TOKEN_COMMA;
3795 token = g_scanner_get_next_token (scanner);
3801 if (token != G_TOKEN_STRING)
3803 gtk_icon_source_free (source);
3804 return G_TOKEN_STRING;
3807 size = gtk_icon_size_from_name (scanner->value.v_string);
3809 if (size != GTK_ICON_SIZE_INVALID)
3811 gtk_icon_source_set_size_wildcarded (source, FALSE);
3812 gtk_icon_source_set_size (source, size);
3816 /* Check the close brace */
3818 token = g_scanner_get_next_token (scanner);
3819 if (token != G_TOKEN_RIGHT_CURLY)
3821 gtk_icon_source_free (source);
3822 return G_TOKEN_RIGHT_CURLY;
3826 if (gtk_icon_source_get_filename (source) ||
3827 gtk_icon_source_get_icon_name (source))
3829 gtk_icon_set_add_source (icon_set, source);
3830 *icon_set_valid = TRUE;
3832 gtk_icon_source_free (source);
3834 return G_TOKEN_NONE;
3838 gtk_rc_parse_stock (GtkRcContext *context,
3840 GtkRcStyle *rc_style,
3841 GtkIconFactory *factory)
3843 GtkIconSet *icon_set = NULL;
3844 gboolean icon_set_valid = FALSE;
3845 gchar *stock_id = NULL;
3848 token = g_scanner_get_next_token (scanner);
3849 if (token != GTK_RC_TOKEN_STOCK)
3850 return GTK_RC_TOKEN_STOCK;
3852 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3853 if (token != G_TOKEN_NONE)
3856 token = g_scanner_get_next_token (scanner);
3857 if (token != G_TOKEN_EQUAL_SIGN)
3860 return G_TOKEN_EQUAL_SIGN;
3863 token = g_scanner_get_next_token (scanner);
3864 if (token != G_TOKEN_LEFT_CURLY)
3867 return G_TOKEN_LEFT_CURLY;
3870 token = g_scanner_peek_next_token (scanner);
3871 while (token != G_TOKEN_RIGHT_CURLY)
3873 if (icon_set == NULL)
3874 icon_set = gtk_icon_set_new ();
3876 token = gtk_rc_parse_icon_source (context,
3877 scanner, icon_set, &icon_set_valid);
3878 if (token != G_TOKEN_NONE)
3881 gtk_icon_set_unref (icon_set);
3885 token = g_scanner_get_next_token (scanner);
3887 if (token != G_TOKEN_COMMA &&
3888 token != G_TOKEN_RIGHT_CURLY)
3891 gtk_icon_set_unref (icon_set);
3892 return G_TOKEN_RIGHT_CURLY;
3899 gtk_icon_factory_add (factory,
3903 gtk_icon_set_unref (icon_set);
3908 return G_TOKEN_NONE;