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-item-style\" {\n"
677 " bg[PRELIGHT] = \"#4b6983\"\n"
678 " fg[PRELIGHT] = \"#ffffff\"\n"
679 " base[PRELIGHT] = \"#4b6983\"\n"
680 " text[PRELIGHT] = \"#ffffff\"\n"
683 "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
684 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"
685 "class \"GtkMenuItem\" style : gtk \"gtk-default-menu-item-style\"\n"
686 "widget_class \"*.GtkMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
687 "widget_class \"*.GtkAccelMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
688 "widget_class \"*.GtkRadioMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
689 "widget_class \"*.GtkCheckMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
690 "widget_class \"*.GtkImageMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
691 "widget_class \"*.GtkSeparatorMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
696 gtk_rc_context_parse_string (GtkRcContext *context,
697 const gchar *rc_string)
699 gtk_rc_parse_any (context, "-", -1, rc_string);
703 gtk_rc_parse_string (const gchar *rc_string)
708 g_return_if_fail (rc_string != NULL);
710 rc_file = g_new (GtkRcFile, 1);
711 rc_file->is_string = TRUE;
712 rc_file->name = g_strdup (rc_string);
713 rc_file->canonical_name = NULL;
714 rc_file->directory = NULL;
716 rc_file->reload = TRUE;
718 global_rc_files = g_slist_append (global_rc_files, rc_file);
720 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
721 gtk_rc_context_parse_string (tmp_list->data, rc_string);
725 add_to_rc_file_list (GSList **rc_file_list,
726 const char *filename,
732 tmp_list = *rc_file_list;
735 rc_file = tmp_list->data;
736 if (!strcmp (rc_file->name, filename))
739 tmp_list = tmp_list->next;
742 rc_file = g_new (GtkRcFile, 1);
743 rc_file->is_string = FALSE;
744 rc_file->name = g_strdup (filename);
745 rc_file->canonical_name = NULL;
746 rc_file->directory = NULL;
748 rc_file->reload = reload;
750 *rc_file_list = g_slist_append (*rc_file_list, rc_file);
756 gtk_rc_context_parse_one_file (GtkRcContext *context,
757 const gchar *filename,
765 g_return_if_fail (filename != NULL);
767 saved_priority = context->default_priority;
768 context->default_priority = priority;
770 rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
772 if (!rc_file->canonical_name)
774 /* Get the absolute pathname */
776 if (g_path_is_absolute (rc_file->name))
777 rc_file->canonical_name = rc_file->name;
782 cwd = g_get_current_dir ();
783 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
787 rc_file->directory = g_path_get_dirname (rc_file->canonical_name);
790 /* If the file is already being parsed (recursion), do nothing
792 if (g_slist_find (current_files_stack, rc_file))
795 if (!lstat (rc_file->canonical_name, &statbuf))
799 rc_file->mtime = statbuf.st_mtime;
801 fd = open (rc_file->canonical_name, O_RDONLY);
805 /* Temporarily push information for this file on
806 * a stack of current files while parsing it.
808 current_files_stack = g_slist_prepend (current_files_stack, rc_file);
809 gtk_rc_parse_any (context, filename, fd, NULL);
810 current_files_stack = g_slist_delete_link (current_files_stack,
811 current_files_stack);
817 context->default_priority = saved_priority;
821 strchr_len (const gchar *str, gint len, char c)
835 gtk_rc_context_parse_file (GtkRcContext *context,
836 const gchar *filename,
840 gchar *locale_suffixes[2];
841 gint n_locale_suffixes = 0;
845 gboolean found = FALSE;
848 locale = g_win32_getlocale ();
850 locale = setlocale (LC_CTYPE, NULL);
853 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
855 /* Determine locale-specific suffixes for RC files.
857 length = strlen (locale);
859 p = strchr (locale, '@');
863 p = strchr_len (locale, length, '.');
867 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
869 p = strchr_len (locale, length, '_');
873 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
877 gtk_rc_context_parse_one_file (context, filename, priority, reload);
878 for (j = 0; j < n_locale_suffixes; j++)
882 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
883 if (g_file_test (name, G_FILE_TEST_EXISTS))
885 gtk_rc_context_parse_one_file (context, name, priority, FALSE);
892 g_free (locale_suffixes[j]);
897 gtk_rc_parse (const gchar *filename)
901 g_return_if_fail (filename != NULL);
903 add_to_rc_file_list (&global_rc_files, filename, TRUE);
905 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
906 gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
909 /* Handling of RC styles */
912 gtk_rc_style_get_type (void)
914 static GType rc_style_type = 0;
918 static const GTypeInfo rc_style_info =
920 sizeof (GtkRcStyleClass),
921 (GBaseInitFunc) NULL,
922 (GBaseFinalizeFunc) NULL,
923 (GClassInitFunc) gtk_rc_style_class_init,
924 NULL, /* class_finalize */
925 NULL, /* class_data */
928 (GInstanceInitFunc) gtk_rc_style_init,
931 rc_style_type = g_type_register_static (G_TYPE_OBJECT, "GtkRcStyle",
935 return rc_style_type;
939 gtk_rc_style_init (GtkRcStyle *style)
944 style->font_desc = NULL;
946 for (i = 0; i < 5; i++)
948 static const GdkColor init_color = { 0, 0, 0, 0, };
950 style->bg_pixmap_name[i] = NULL;
951 style->color_flags[i] = 0;
952 style->fg[i] = init_color;
953 style->bg[i] = init_color;
954 style->text[i] = init_color;
955 style->base[i] = init_color;
957 style->xthickness = -1;
958 style->ythickness = -1;
959 style->rc_properties = NULL;
961 style->rc_style_lists = NULL;
962 style->icon_factories = NULL;
966 gtk_rc_style_class_init (GtkRcStyleClass *klass)
968 GObjectClass *object_class = G_OBJECT_CLASS (klass);
970 parent_class = g_type_class_peek_parent (klass);
972 object_class->finalize = gtk_rc_style_finalize;
975 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
976 klass->merge = gtk_rc_style_real_merge;
977 klass->create_style = gtk_rc_style_real_create_style;
981 gtk_rc_style_finalize (GObject *object)
983 GSList *tmp_list1, *tmp_list2;
984 GtkRcStyle *rc_style;
987 rc_style = GTK_RC_STYLE (object);
990 g_free (rc_style->name);
991 if (rc_style->font_desc)
992 pango_font_description_free (rc_style->font_desc);
994 for (i = 0; i < 5; i++)
995 if (rc_style->bg_pixmap_name[i])
996 g_free (rc_style->bg_pixmap_name[i]);
998 /* Now remove all references to this rc_style from
1001 tmp_list1 = rc_style->rc_style_lists;
1004 GSList *rc_styles = tmp_list1->data;
1005 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1006 g_object_unref (style);
1008 /* Remove the list of styles from the other rc_styles
1011 tmp_list2 = rc_styles;
1014 GtkRcStyle *other_style = tmp_list2->data;
1016 if (other_style != rc_style)
1017 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1019 tmp_list2 = tmp_list2->next;
1022 /* And from the hash table itself
1024 g_hash_table_remove (realized_style_ht, rc_styles);
1025 g_slist_free (rc_styles);
1027 tmp_list1 = tmp_list1->next;
1029 g_slist_free (rc_style->rc_style_lists);
1031 if (rc_style->rc_properties)
1035 for (i = 0; i < rc_style->rc_properties->len; i++)
1037 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1039 g_free (node->origin);
1040 g_value_unset (&node->value);
1042 g_array_free (rc_style->rc_properties, TRUE);
1043 rc_style->rc_properties = NULL;
1046 tmp_list1 = rc_style->icon_factories;
1049 g_object_unref (tmp_list1->data);
1050 tmp_list1 = tmp_list1->next;
1052 g_slist_free (rc_style->icon_factories);
1054 G_OBJECT_CLASS (parent_class)->finalize (object);
1058 gtk_rc_style_new (void)
1062 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1068 * gtk_rc_style_copy:
1069 * @orig: the style to copy
1071 * Makes a copy of the specified #GtkRcStyle. This function
1072 * will correctly copy an RC style that is a member of a class
1073 * derived from #GtkRcStyle.
1075 * Return value: the resulting #GtkRcStyle
1078 gtk_rc_style_copy (GtkRcStyle *orig)
1082 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1084 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1085 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1091 gtk_rc_style_ref (GtkRcStyle *rc_style)
1093 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1095 g_object_ref (rc_style);
1099 gtk_rc_style_unref (GtkRcStyle *rc_style)
1101 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1103 g_object_unref (rc_style);
1107 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1109 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1113 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1114 gconstpointer bsearch_node2)
1116 const GtkRcProperty *prop1 = bsearch_node1;
1117 const GtkRcProperty *prop2 = bsearch_node2;
1119 if (prop1->type_name == prop2->type_name)
1120 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1122 return prop1->type_name < prop2->type_name ? -1 : 1;
1126 insert_rc_property (GtkRcStyle *style,
1127 GtkRcProperty *property,
1131 GtkRcProperty *new_property = NULL;
1132 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1134 key.type_name = property->type_name;
1135 key.property_name = property->property_name;
1137 if (!style->rc_properties)
1138 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1141 while (i < style->rc_properties->len)
1143 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1149 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1151 g_free (new_property->origin);
1152 g_value_unset (&new_property->value);
1154 *new_property = key;
1168 g_array_insert_val (style->rc_properties, i, key);
1169 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1172 new_property->origin = g_strdup (property->origin);
1173 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1174 g_value_copy (&property->value, &new_property->value);
1178 gtk_rc_style_real_merge (GtkRcStyle *dest,
1183 for (i = 0; i < 5; i++)
1185 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1186 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1188 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1189 src->color_flags[i] & GTK_RC_FG)
1191 dest->fg[i] = src->fg[i];
1192 dest->color_flags[i] |= GTK_RC_FG;
1194 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1195 src->color_flags[i] & GTK_RC_BG)
1197 dest->bg[i] = src->bg[i];
1198 dest->color_flags[i] |= GTK_RC_BG;
1200 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1201 src->color_flags[i] & GTK_RC_TEXT)
1203 dest->text[i] = src->text[i];
1204 dest->color_flags[i] |= GTK_RC_TEXT;
1206 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1207 src->color_flags[i] & GTK_RC_BASE)
1209 dest->base[i] = src->base[i];
1210 dest->color_flags[i] |= GTK_RC_BASE;
1214 if (dest->xthickness < 0 && src->xthickness >= 0)
1215 dest->xthickness = src->xthickness;
1216 if (dest->ythickness < 0 && src->ythickness >= 0)
1217 dest->ythickness = src->ythickness;
1221 if (!dest->font_desc)
1222 dest->font_desc = pango_font_description_copy (src->font_desc);
1224 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1227 if (src->rc_properties)
1231 for (i = 0; i < src->rc_properties->len; i++)
1232 insert_rc_property (dest,
1233 &g_array_index (src->rc_properties, GtkRcProperty, i),
1239 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1241 return gtk_style_new ();
1245 gtk_rc_clear_hash_node (gpointer key,
1249 gtk_rc_style_unref (data);
1253 gtk_rc_free_rc_sets (GSList *slist)
1259 rc_set = slist->data;
1260 g_pattern_spec_free (rc_set->pspec);
1263 slist = slist->next;
1268 gtk_rc_clear_styles (GtkRcContext *context)
1270 /* Clear out all old rc_styles */
1272 if (context->rc_style_ht)
1274 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1275 g_hash_table_destroy (context->rc_style_ht);
1276 context->rc_style_ht = NULL;
1279 gtk_rc_free_rc_sets (context->rc_sets_widget);
1280 g_slist_free (context->rc_sets_widget);
1281 context->rc_sets_widget = NULL;
1283 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1284 g_slist_free (context->rc_sets_widget_class);
1285 context->rc_sets_widget_class = NULL;
1287 gtk_rc_free_rc_sets (context->rc_sets_class);
1288 g_slist_free (context->rc_sets_class);
1289 context->rc_sets_class = NULL;
1292 /* Reset all our widgets. Also, we have to invalidate cached icons in
1293 * icon sets so they get re-rendered.
1296 gtk_rc_reset_widgets (GtkSettings *settings)
1298 GList *list, *toplevels;
1300 _gtk_icon_set_invalidate_caches ();
1302 toplevels = gtk_window_list_toplevels ();
1303 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1305 for (list = toplevels; list; list = list->next)
1307 if (gtk_widget_get_screen (list->data) == settings->screen)
1309 gtk_widget_reset_rc_styles (list->data);
1310 g_object_unref (list->data);
1313 g_list_free (toplevels);
1317 gtk_rc_clear_realized_style (gpointer key,
1321 GSList *rc_styles = key;
1322 GSList *tmp_list = rc_styles;
1326 GtkRcStyle *rc_style = tmp_list->data;
1328 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1330 tmp_list = tmp_list->next;
1333 g_slist_free (rc_styles);
1337 * _gtk_rc_reset_styles:
1338 * @settings: a #GtkSettings
1340 * This setting resets all of our styles; we use it when the font
1341 * rendering parameters or the icon sizes have changed. It's both less
1342 * and more comprehensive then we actually need:
1344 * Less comprehensive: it doesn't affect widgets that have a style
1347 * More comprehensive: it resets the styles, but the styles haven't
1348 * changed. The main reason for resetting the styles is becaues
1349 * most widgets will redo all their font stuff when their style
1353 _gtk_rc_reset_styles (GtkSettings *settings)
1355 GtkRcContext *context;
1356 gboolean reset = FALSE;
1358 g_return_if_fail (GTK_IS_SETTINGS (settings));
1360 context = gtk_rc_context_get (settings);
1362 if (context->default_style)
1364 g_object_unref (context->default_style);
1365 context->default_style = NULL;
1369 /* Clear out styles that have been looked up already
1371 if (realized_style_ht)
1373 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1374 g_hash_table_destroy (realized_style_ht);
1375 realized_style_ht = NULL;
1380 gtk_rc_reset_widgets (settings);
1384 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1386 GtkRcContext *context;
1387 gchar *new_font_name;
1389 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1391 context = gtk_rc_context_get (settings);
1393 g_object_get (context->settings,
1394 "gtk-font-name", &new_font_name,
1397 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1399 g_free (context->font_name);
1400 context->font_name = g_strdup (new_font_name);
1402 _gtk_rc_reset_styles (settings);
1405 g_free (new_font_name);
1407 return context->font_name;
1411 * gtk_rc_reparse_all_for_settings:
1412 * @settings: a #GtkSettings
1413 * @force_load: load whether or not anything changed
1415 * If the modification time on any previously read file
1416 * for the given #GtkSettings has changed, discard all style information
1417 * and then reread all previously read RC files.
1419 * Return value: %TRUE if the files were reread.
1422 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1423 gboolean force_load)
1425 gboolean mtime_modified = FALSE;
1428 GtkRcContext *context;
1430 struct stat statbuf;
1432 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1434 context = gtk_rc_context_get (settings);
1438 /* Check through and see if any of the RC's have had their
1439 * mtime modified. If so, reparse everything.
1441 tmp_list = context->rc_files;
1444 rc_file = tmp_list->data;
1446 if (!rc_file->is_string)
1448 if (!lstat (rc_file->name, &statbuf) &&
1449 (statbuf.st_mtime > rc_file->mtime))
1451 mtime_modified = TRUE;
1456 tmp_list = tmp_list->next;
1460 if (force_load || mtime_modified)
1462 _gtk_binding_reset_parsed ();
1463 gtk_rc_clear_styles (context);
1464 g_object_freeze_notify (G_OBJECT (context->settings));
1466 _gtk_settings_reset_rc_values (context->settings);
1467 tmp_list = context->rc_files;
1470 rc_file = tmp_list->data;
1472 if (rc_file->canonical_name != rc_file->name)
1473 g_free (rc_file->canonical_name);
1474 g_free (rc_file->directory);
1475 g_free (rc_file->name);
1478 tmp_list = tmp_list->next;
1481 g_slist_free (context->rc_files);
1482 context->rc_files = NULL;
1484 gtk_rc_parse_default_files (context);
1486 tmp_list = global_rc_files;
1489 rc_file = tmp_list->data;
1491 if (rc_file->is_string)
1492 gtk_rc_context_parse_string (context, rc_file->name);
1494 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1496 tmp_list = tmp_list->next;
1499 g_free (context->theme_name);
1500 g_free (context->key_theme_name);
1502 g_object_get (context->settings,
1503 "gtk-theme-name", &context->theme_name,
1504 "gtk-key-theme-name", &context->key_theme_name,
1507 if (context->theme_name && context->theme_name[0])
1508 gtk_rc_parse_named (context, context->theme_name, NULL);
1509 if (context->key_theme_name && context->key_theme_name[0])
1510 gtk_rc_parse_named (context, context->key_theme_name, "key");
1512 g_object_thaw_notify (G_OBJECT (context->settings));
1514 gtk_rc_reset_widgets (context->settings);
1517 return force_load || mtime_modified;
1521 * gtk_rc_reparse_all:
1523 * If the modification time on any previously read file for the
1524 * default #GtkSettings has changed, discard all style information
1525 * and then reread all previously read RC files.
1527 * Return value: %TRUE if the files were reread.
1530 gtk_rc_reparse_all (void)
1533 gboolean result = FALSE;
1535 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1537 GtkRcContext *context = tmp_list->data;
1538 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1546 gtk_rc_styles_match (GSList *rc_styles,
1550 const gchar *path_reversed)
1557 rc_set = sets->data;
1560 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1561 rc_styles = g_slist_append (rc_styles, rc_set);
1568 rc_set_compare (gconstpointer a, gconstpointer b)
1570 const GtkRcSet *set_a = a;
1571 const GtkRcSet *set_b = b;
1573 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1577 sort_and_dereference_sets (GSList *styles)
1581 /* At this point, the list of sets is ordered by:
1583 * a) 'widget' patterns are earlier than 'widget_class' patterns
1584 * which are ealier than 'class' patterns.
1585 * a) For two matches for class patterns, a match to a child type
1586 * is before a match to a parent type
1587 * c) a match later in the RC file (or in a later RC file) is before a
1588 * match earlier in the RC file.
1590 * With a) taking precedence over b) which takes precendence over c).
1592 * Now sort by priority, which has the highest precendence for sort order
1594 styles = g_slist_sort (styles, rc_set_compare);
1596 /* Make styles->data = styles->data->rc_style
1601 GtkRcSet *set = tmp_list->data;
1602 tmp_list->data = set->rc_style;
1603 tmp_list = tmp_list->next;
1611 * @widget: a #GtkWidget
1613 * Finds all matching RC styles for a given widget,
1614 * composites them together, and then creates a
1615 * #GtkStyle representing the composite appearance.
1616 * (GTK+ actually keeps a cache of previously
1617 * created styles, so a new style may not be
1620 * Returns: the resulting style. No refcount is added
1621 * to the returned style, so if you want to save this
1622 * style around, you should add a reference yourself.
1625 gtk_rc_get_style (GtkWidget *widget)
1627 GtkRcStyle *widget_rc_style;
1628 GSList *rc_styles = NULL;
1629 GtkRcContext *context;
1631 static guint rc_style_key_id = 0;
1633 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1635 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1637 /* We allow the specification of a single rc style to be bound
1638 * tightly to a widget, for application modifications
1640 if (!rc_style_key_id)
1641 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1643 if (context->rc_sets_widget)
1645 gchar *path, *path_reversed;
1648 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1649 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1651 g_free (path_reversed);
1654 if (context->rc_sets_widget_class)
1656 gchar *path, *path_reversed;
1659 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1660 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1662 g_free (path_reversed);
1665 if (context->rc_sets_class)
1669 type = G_TYPE_FROM_INSTANCE (widget);
1673 gchar *path_reversed;
1676 path = g_type_name (type);
1677 path_length = strlen (path);
1678 path_reversed = g_strdup (path);
1679 g_strreverse (path_reversed);
1681 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1682 g_free (path_reversed);
1684 type = g_type_parent (type);
1688 rc_styles = sort_and_dereference_sets (rc_styles);
1690 widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
1692 if (widget_rc_style)
1693 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1696 return gtk_rc_init_style (context, rc_styles);
1699 if (!context->default_style)
1701 context->default_style = gtk_style_new ();
1702 _gtk_style_init_for_settings (context->default_style, context->settings);
1705 return context->default_style;
1710 * gtk_rc_get_style_by_paths:
1711 * @settings: a #GtkSettings object
1712 * @widget_path: the widget path to use when looking up the style, or %NULL
1713 * if no matching against the widget path should be done
1714 * @class_path: the class path to use when looking up the style, or %NULL
1715 * if no matching against the class path should be done.
1716 * @type: a type that will be used along with parent types of this type
1717 * when matching against class styles, or #G_TYPE_NONE
1719 * Creates up a #GtkStyle from styles defined in a RC file by providing
1720 * the raw components used in matching. This function may be useful
1721 * when creating pseudo-widgets that should be themed like widgets but
1722 * don't actually have corresponding GTK+ widgets. An example of this
1723 * would be items inside a GNOME canvas widget.
1725 * The action of gtk_rc_get_style() is similar to:
1726 * <informalexample><programlisting>
1727 * gtk_widget_path (widget, NULL, &path, NULL);
1728 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1729 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1730 * G_OBJECT_TYPE (widget));
1731 * </programlisting></informalexample>
1733 * Return value: A style created by matching with the supplied paths,
1734 * or %NULL if nothing matching was specified and the default style should
1735 * be used. The returned value is owned by GTK+ as part of an internal cache,
1736 * so you must call g_object_ref() on the returned value if you want to
1737 * keep a reference to it.
1740 gtk_rc_get_style_by_paths (GtkSettings *settings,
1741 const char *widget_path,
1742 const char *class_path,
1745 /* We duplicate the code from above to avoid slowing down the above
1746 * by generating paths when we don't need them. I don't know if
1747 * this is really worth it.
1749 GSList *rc_styles = NULL;
1750 GtkRcContext *context;
1752 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1754 context = gtk_rc_context_get (settings);
1756 if (widget_path && context->rc_sets_widget)
1758 gchar *path_reversed;
1761 path_length = strlen (widget_path);
1762 path_reversed = g_strdup (widget_path);
1763 g_strreverse (path_reversed);
1765 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1766 g_free (path_reversed);
1769 if (class_path && context->rc_sets_widget_class)
1771 gchar *path_reversed;
1774 path_length = strlen (class_path);
1775 path_reversed = g_strdup (class_path);
1776 g_strreverse (path_reversed);
1778 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1779 g_free (path_reversed);
1782 if (type != G_TYPE_NONE && context->rc_sets_class)
1787 gchar *path_reversed;
1790 path = g_type_name (type);
1791 path_length = strlen (path);
1792 path_reversed = g_strdup (path);
1793 g_strreverse (path_reversed);
1795 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1796 g_free (path_reversed);
1798 type = g_type_parent (type);
1802 rc_styles = sort_and_dereference_sets (rc_styles);
1805 return gtk_rc_init_style (context, rc_styles);
1811 gtk_rc_add_rc_sets (GSList *slist,
1812 GtkRcStyle *rc_style,
1813 const gchar *pattern)
1815 GtkRcStyle *new_style;
1819 new_style = gtk_rc_style_new ();
1820 *new_style = *rc_style;
1821 new_style->name = g_strdup (rc_style->name);
1822 if (rc_style->font_desc)
1823 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1825 for (i = 0; i < 5; i++)
1826 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1828 rc_set = g_new (GtkRcSet, 1);
1829 rc_set->pspec = g_pattern_spec_new (pattern);
1830 rc_set->rc_style = rc_style;
1832 return g_slist_prepend (slist, rc_set);
1836 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1837 const gchar *pattern)
1839 GtkRcContext *context;
1841 g_return_if_fail (rc_style != NULL);
1842 g_return_if_fail (pattern != NULL);
1844 context = gtk_rc_context_get (gtk_settings_get_default ());
1846 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1850 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1851 const gchar *pattern)
1853 GtkRcContext *context;
1855 g_return_if_fail (rc_style != NULL);
1856 g_return_if_fail (pattern != NULL);
1858 context = gtk_rc_context_get (gtk_settings_get_default ());
1860 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1864 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1865 const gchar *pattern)
1867 GtkRcContext *context;
1869 g_return_if_fail (rc_style != NULL);
1870 g_return_if_fail (pattern != NULL);
1872 context = gtk_rc_context_get (gtk_settings_get_default ());
1874 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1878 gtk_rc_scanner_new (void)
1880 return g_scanner_new (>k_rc_scanner_config);
1884 gtk_rc_parse_any (GtkRcContext *context,
1885 const gchar *input_name,
1887 const gchar *input_string)
1893 scanner = gtk_rc_scanner_new ();
1897 g_assert (input_string == NULL);
1899 g_scanner_input_file (scanner, input_fd);
1903 g_assert (input_string != NULL);
1905 g_scanner_input_text (scanner, input_string, strlen (input_string));
1907 scanner->input_name = input_name;
1909 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1910 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1915 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1919 guint expected_token;
1921 expected_token = gtk_rc_parse_statement (context, scanner);
1923 if (expected_token != G_TOKEN_NONE)
1930 if (scanner->scope_id == 0)
1932 /* if we are in scope 0, we know the symbol names
1933 * that are associated with certain token values.
1934 * so we look them up to make the error messages
1937 if (expected_token > GTK_RC_TOKEN_INVALID &&
1938 expected_token < GTK_RC_TOKEN_LAST)
1940 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1941 if (symbols[i].token == expected_token)
1942 msg = symbols[i].name;
1944 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1946 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1947 scanner->token < GTK_RC_TOKEN_LAST)
1949 symbol_name = "???";
1950 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1951 if (symbols[i].token == scanner->token)
1952 symbol_name = symbols[i].name;
1955 g_scanner_unexp_token (scanner,
1968 g_scanner_destroy (scanner);
1972 gtk_rc_styles_hash (const GSList *rc_styles)
1979 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1980 rc_styles = rc_styles->next;
1987 gtk_rc_styles_equal (const GSList *a,
1992 if (a->data != b->data)
2002 gtk_rc_style_hash (const gchar *name)
2008 result += (result << 3) + *name++;
2014 gtk_rc_style_equal (const gchar *a,
2017 return (strcmp (a, b) == 0);
2021 gtk_rc_style_find (GtkRcContext *context,
2024 if (context->rc_style_ht)
2025 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2031 gtk_rc_style_to_style (GtkRcContext *context,
2032 GtkRcStyle *rc_style)
2036 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2037 _gtk_style_init_for_settings (style, context->settings);
2039 style->rc_style = rc_style;
2041 gtk_rc_style_ref (rc_style);
2043 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2048 /* Reuses or frees rc_styles */
2050 gtk_rc_init_style (GtkRcContext *context,
2053 GtkStyle *style = NULL;
2056 g_return_val_if_fail (rc_styles != NULL, NULL);
2058 if (!realized_style_ht)
2059 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2060 (GEqualFunc) gtk_rc_styles_equal);
2062 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2066 GtkRcStyle *base_style = NULL;
2067 GtkRcStyle *proto_style;
2068 GtkRcStyleClass *proto_style_class;
2070 GType rc_style_type = GTK_TYPE_RC_STYLE;
2072 /* Find the the first style where the RC file specified engine "" {}
2073 * or the first derived style and use that to create the
2074 * merged style. If we only have raw GtkRcStyles, use the first
2075 * style to create the merged style.
2077 base_style = rc_styles->data;
2078 tmp_styles = rc_styles;
2081 GtkRcStyle *rc_style = tmp_styles->data;
2083 if (rc_style->engine_specified ||
2084 G_OBJECT_TYPE (rc_style) != rc_style_type)
2086 base_style = rc_style;
2090 tmp_styles = tmp_styles->next;
2093 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2094 proto_style = proto_style_class->create_rc_style (base_style);
2096 tmp_styles = rc_styles;
2099 GtkRcStyle *rc_style = tmp_styles->data;
2102 proto_style_class->merge (proto_style, rc_style);
2104 /* Point from each rc_style to the list of styles */
2105 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2106 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2108 factories = g_slist_copy (rc_style->icon_factories);
2114 while (iter != NULL)
2116 g_object_ref (iter->data);
2117 iter = g_slist_next (iter);
2120 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2125 tmp_styles = tmp_styles->next;
2128 for (i = 0; i < 5; i++)
2129 if (proto_style->bg_pixmap_name[i] &&
2130 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2132 g_free (proto_style->bg_pixmap_name[i]);
2133 proto_style->bg_pixmap_name[i] = NULL;
2136 style = gtk_rc_style_to_style (context, proto_style);
2137 gtk_rc_style_unref (proto_style);
2139 g_hash_table_insert (realized_style_ht, rc_styles, style);
2142 g_slist_free (rc_styles);
2147 /*********************
2148 * Parsing functions *
2149 *********************/
2152 rc_parse_token_or_compound (GScanner *scanner,
2154 GTokenType delimiter)
2156 guint token = g_scanner_get_next_token (scanner);
2158 /* we either scan a single token (skipping comments)
2159 * or a compund statement.
2160 * compunds are enclosed in (), [] or {} braces, we read
2161 * them in via deep recursion.
2168 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2171 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2173 case G_TOKEN_STRING:
2174 string = g_strescape (scanner->value.v_string, NULL);
2175 g_string_append (gstring, " \"");
2176 g_string_append (gstring, string);
2177 g_string_append_c (gstring, '"');
2180 case G_TOKEN_IDENTIFIER:
2181 g_string_append_c (gstring, ' ');
2182 g_string_append (gstring, scanner->value.v_identifier);
2184 case G_TOKEN_COMMENT_SINGLE:
2185 case G_TOKEN_COMMENT_MULTI:
2186 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2187 case G_TOKEN_LEFT_PAREN:
2188 g_string_append_c (gstring, ' ');
2189 g_string_append_c (gstring, token);
2190 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2191 if (token != G_TOKEN_NONE)
2194 case G_TOKEN_LEFT_CURLY:
2195 g_string_append_c (gstring, ' ');
2196 g_string_append_c (gstring, token);
2197 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2198 if (token != G_TOKEN_NONE)
2201 case G_TOKEN_LEFT_BRACE:
2202 g_string_append_c (gstring, ' ');
2203 g_string_append_c (gstring, token);
2204 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2205 if (token != G_TOKEN_NONE)
2209 if (token >= 256 || token < 1)
2210 return delimiter ? delimiter : G_TOKEN_STRING;
2211 g_string_append_c (gstring, ' ');
2212 g_string_append_c (gstring, token);
2213 if (token == delimiter)
2214 return G_TOKEN_NONE;
2218 return G_TOKEN_NONE;
2220 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2224 gtk_rc_parse_assignment (GScanner *scanner,
2225 GtkRcProperty *prop)
2227 gboolean scan_identifier = scanner->config->scan_identifier;
2228 gboolean scan_symbols = scanner->config->scan_symbols;
2229 gboolean identifier_2_string = scanner->config->identifier_2_string;
2230 gboolean char_2_token = scanner->config->char_2_token;
2231 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2232 gboolean numbers_2_int = scanner->config->numbers_2_int;
2233 gboolean negate = FALSE;
2236 /* check that this is an assignment */
2237 if (g_scanner_get_next_token (scanner) != '=')
2240 /* adjust scanner mode */
2241 scanner->config->scan_identifier = TRUE;
2242 scanner->config->scan_symbols = FALSE;
2243 scanner->config->identifier_2_string = FALSE;
2244 scanner->config->char_2_token = TRUE;
2245 scanner->config->scan_identifier_NULL = FALSE;
2246 scanner->config->numbers_2_int = TRUE;
2248 /* record location */
2249 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2251 /* parse optional sign */
2252 if (g_scanner_peek_next_token (scanner) == '-')
2254 g_scanner_get_next_token (scanner); /* eat sign */
2258 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2259 token = g_scanner_peek_next_token (scanner);
2263 g_scanner_get_next_token (scanner);
2264 g_value_init (&prop->value, G_TYPE_LONG);
2265 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2266 token = G_TOKEN_NONE;
2269 g_scanner_get_next_token (scanner);
2270 g_value_init (&prop->value, G_TYPE_DOUBLE);
2271 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2272 token = G_TOKEN_NONE;
2274 case G_TOKEN_STRING:
2275 g_scanner_get_next_token (scanner);
2277 token = G_TOKEN_INT;
2280 g_value_init (&prop->value, G_TYPE_STRING);
2281 g_value_set_string (&prop->value, scanner->value.v_string);
2282 token = G_TOKEN_NONE;
2285 case G_TOKEN_IDENTIFIER:
2286 case G_TOKEN_LEFT_PAREN:
2287 case G_TOKEN_LEFT_CURLY:
2288 case G_TOKEN_LEFT_BRACE:
2291 GString *gstring = g_string_new (NULL);
2293 token = rc_parse_token_or_compound (scanner, gstring, 0);
2294 if (token == G_TOKEN_NONE)
2296 g_string_append_c (gstring, ' ');
2297 g_value_init (&prop->value, G_TYPE_GSTRING);
2298 g_value_set_static_boxed (&prop->value, gstring);
2301 g_string_free (gstring, TRUE);
2306 g_scanner_get_next_token (scanner);
2307 token = G_TOKEN_INT;
2311 /* restore scanner mode */
2312 scanner->config->scan_identifier = scan_identifier;
2313 scanner->config->scan_symbols = scan_symbols;
2314 scanner->config->identifier_2_string = identifier_2_string;
2315 scanner->config->char_2_token = char_2_token;
2316 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2317 scanner->config->numbers_2_int = numbers_2_int;
2323 is_c_identifier (const gchar *string)
2326 gboolean is_varname;
2328 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2329 for (p = string + 1; *p && is_varname; p++)
2330 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2336 parse_include_file (GtkRcContext *context,
2338 const gchar *filename)
2340 char *to_parse = NULL;
2342 if (g_path_is_absolute (filename))
2344 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2345 * don't print an error in this case.
2347 to_parse = g_strdup (filename);
2351 /* if a relative path, we look relative to all the RC files in the
2352 * include stack. We require the file to be found in this case
2353 * so we can give meaningful error messages, and because on reparsing
2354 * non-absolute paths don't make sense.
2356 GSList *tmp_list = current_files_stack;
2359 GtkRcFile *curfile = tmp_list->data;
2360 gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
2362 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2370 tmp_list = tmp_list->next;
2376 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2381 g_scanner_warn (scanner,
2382 _("Unable to find include file: \"%s\""),
2389 gtk_rc_parse_statement (GtkRcContext *context,
2394 token = g_scanner_peek_next_token (scanner);
2397 case GTK_RC_TOKEN_INCLUDE:
2398 token = g_scanner_get_next_token (scanner);
2399 if (token != GTK_RC_TOKEN_INCLUDE)
2400 return GTK_RC_TOKEN_INCLUDE;
2401 token = g_scanner_get_next_token (scanner);
2402 if (token != G_TOKEN_STRING)
2403 return G_TOKEN_STRING;
2404 parse_include_file (context, scanner, scanner->value.v_string);
2405 return G_TOKEN_NONE;
2407 case GTK_RC_TOKEN_STYLE:
2408 return gtk_rc_parse_style (context, scanner);
2410 case GTK_RC_TOKEN_BINDING:
2411 return gtk_binding_parse_binding (scanner);
2413 case GTK_RC_TOKEN_PIXMAP_PATH:
2414 return gtk_rc_parse_pixmap_path (context, scanner);
2416 case GTK_RC_TOKEN_WIDGET:
2417 return gtk_rc_parse_path_pattern (context, scanner);
2419 case GTK_RC_TOKEN_WIDGET_CLASS:
2420 return gtk_rc_parse_path_pattern (context, scanner);
2422 case GTK_RC_TOKEN_CLASS:
2423 return gtk_rc_parse_path_pattern (context, scanner);
2425 case GTK_RC_TOKEN_MODULE_PATH:
2426 return gtk_rc_parse_module_path (scanner);
2428 case GTK_RC_TOKEN_IM_MODULE_FILE:
2429 return gtk_rc_parse_im_module_file (scanner);
2431 case G_TOKEN_IDENTIFIER:
2432 if (is_c_identifier (scanner->next_value.v_identifier))
2434 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2437 g_scanner_get_next_token (scanner); /* eat identifier */
2438 name = g_strdup (scanner->value.v_identifier);
2440 token = gtk_rc_parse_assignment (scanner, &prop);
2441 if (token == G_TOKEN_NONE)
2443 GtkSettingsValue svalue;
2445 svalue.origin = prop.origin;
2446 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2447 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2448 _gtk_settings_set_property_value_from_rc (context->settings,
2452 g_free (prop.origin);
2453 if (G_VALUE_TYPE (&prop.value))
2454 g_value_unset (&prop.value);
2461 g_scanner_get_next_token (scanner);
2462 return G_TOKEN_IDENTIFIER;
2465 g_scanner_get_next_token (scanner);
2466 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2471 fixup_rc_set (GSList *list,
2477 GtkRcSet *set = list->data;
2478 if (set->rc_style == orig)
2479 set->rc_style = new;
2485 fixup_rc_sets (GtkRcContext *context,
2489 fixup_rc_set (context->rc_sets_widget, orig, new);
2490 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2491 fixup_rc_set (context->rc_sets_class, orig, new);
2495 gtk_rc_parse_style (GtkRcContext *context,
2498 GtkRcStyle *rc_style;
2499 GtkRcStyle *orig_style;
2500 GtkRcStyle *parent_style;
2503 GtkIconFactory *our_factory = NULL;
2505 token = g_scanner_get_next_token (scanner);
2506 if (token != GTK_RC_TOKEN_STYLE)
2507 return GTK_RC_TOKEN_STYLE;
2509 token = g_scanner_get_next_token (scanner);
2510 if (token != G_TOKEN_STRING)
2511 return G_TOKEN_STRING;
2513 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2515 orig_style = g_object_ref (rc_style);
2519 /* If there's a list, its first member is always the factory belonging
2522 if (rc_style && rc_style->icon_factories)
2523 our_factory = rc_style->icon_factories->data;
2527 rc_style = gtk_rc_style_new ();
2528 rc_style->name = g_strdup (scanner->value.v_string);
2530 for (i = 0; i < 5; i++)
2531 rc_style->bg_pixmap_name[i] = NULL;
2533 for (i = 0; i < 5; i++)
2534 rc_style->color_flags[i] = 0;
2537 token = g_scanner_peek_next_token (scanner);
2538 if (token == G_TOKEN_EQUAL_SIGN)
2540 token = g_scanner_get_next_token (scanner);
2542 token = g_scanner_get_next_token (scanner);
2543 if (token != G_TOKEN_STRING)
2545 token = G_TOKEN_STRING;
2549 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2554 for (i = 0; i < 5; i++)
2556 rc_style->color_flags[i] = parent_style->color_flags[i];
2557 rc_style->fg[i] = parent_style->fg[i];
2558 rc_style->bg[i] = parent_style->bg[i];
2559 rc_style->text[i] = parent_style->text[i];
2560 rc_style->base[i] = parent_style->base[i];
2563 rc_style->xthickness = parent_style->xthickness;
2564 rc_style->ythickness = parent_style->ythickness;
2566 if (parent_style->font_desc)
2568 if (rc_style->font_desc)
2569 pango_font_description_free (rc_style->font_desc);
2570 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2573 if (parent_style->rc_properties)
2577 for (i = 0; i < parent_style->rc_properties->len; i++)
2578 insert_rc_property (rc_style,
2579 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2583 for (i = 0; i < 5; i++)
2585 if (rc_style->bg_pixmap_name[i])
2586 g_free (rc_style->bg_pixmap_name[i]);
2587 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2590 /* Append parent's factories, adding a ref to them */
2591 if (parent_style->icon_factories != NULL)
2593 /* Add a factory for ourselves if we have none,
2594 * in case we end up defining more stock icons.
2595 * I see no real way around this; we need to maintain
2596 * the invariant that the first factory in the list
2597 * is always our_factory, the one belonging to us,
2598 * and if we put parent factories in the list we can't
2599 * do that if the style is reopened.
2601 if (our_factory == NULL)
2603 our_factory = gtk_icon_factory_new ();
2604 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2608 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2609 g_slist_copy (parent_style->icon_factories));
2611 factories = parent_style->icon_factories;
2612 while (factories != NULL)
2614 g_object_ref (factories->data);
2615 factories = factories->next;
2621 token = g_scanner_get_next_token (scanner);
2622 if (token != G_TOKEN_LEFT_CURLY)
2624 token = G_TOKEN_LEFT_CURLY;
2628 token = g_scanner_peek_next_token (scanner);
2629 while (token != G_TOKEN_RIGHT_CURLY)
2633 case GTK_RC_TOKEN_BG:
2634 token = gtk_rc_parse_bg (scanner, rc_style);
2636 case GTK_RC_TOKEN_FG:
2637 token = gtk_rc_parse_fg (scanner, rc_style);
2639 case GTK_RC_TOKEN_TEXT:
2640 token = gtk_rc_parse_text (scanner, rc_style);
2642 case GTK_RC_TOKEN_BASE:
2643 token = gtk_rc_parse_base (scanner, rc_style);
2645 case GTK_RC_TOKEN_XTHICKNESS:
2646 token = gtk_rc_parse_xthickness (scanner, rc_style);
2648 case GTK_RC_TOKEN_YTHICKNESS:
2649 token = gtk_rc_parse_ythickness (scanner, rc_style);
2651 case GTK_RC_TOKEN_BG_PIXMAP:
2652 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2654 case GTK_RC_TOKEN_FONT:
2655 token = gtk_rc_parse_font (scanner, rc_style);
2657 case GTK_RC_TOKEN_FONTSET:
2658 token = gtk_rc_parse_fontset (scanner, rc_style);
2660 case GTK_RC_TOKEN_FONT_NAME:
2661 token = gtk_rc_parse_font_name (scanner, rc_style);
2663 case GTK_RC_TOKEN_ENGINE:
2664 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2666 case GTK_RC_TOKEN_STOCK:
2667 if (our_factory == NULL)
2669 our_factory = gtk_icon_factory_new ();
2670 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2673 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2675 case G_TOKEN_IDENTIFIER:
2676 if (is_c_identifier (scanner->next_value.v_identifier) &&
2677 scanner->next_value.v_identifier[0] >= 'A' &&
2678 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2680 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2682 g_scanner_get_next_token (scanner); /* eat type name */
2683 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2684 if (g_scanner_get_next_token (scanner) != ':' ||
2685 g_scanner_get_next_token (scanner) != ':')
2690 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2691 !is_c_identifier (scanner->value.v_identifier))
2693 token = G_TOKEN_IDENTIFIER;
2697 /* it's important that we do the same canonification as GParamSpecPool here */
2698 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2699 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2701 token = gtk_rc_parse_assignment (scanner, &prop);
2702 if (token == G_TOKEN_NONE)
2704 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2705 insert_rc_property (rc_style, &prop, TRUE);
2708 g_free (prop.origin);
2709 if (G_VALUE_TYPE (&prop.value))
2710 g_value_unset (&prop.value);
2714 g_scanner_get_next_token (scanner);
2715 token = G_TOKEN_IDENTIFIER;
2719 g_scanner_get_next_token (scanner);
2720 token = G_TOKEN_RIGHT_CURLY;
2724 if (token != G_TOKEN_NONE)
2727 token = g_scanner_peek_next_token (scanner);
2728 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2730 token = g_scanner_get_next_token (scanner);
2731 if (token != G_TOKEN_RIGHT_CURLY)
2733 token = G_TOKEN_RIGHT_CURLY;
2737 if (rc_style != orig_style)
2739 if (!context->rc_style_ht)
2740 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2741 (GEqualFunc) gtk_rc_style_equal);
2743 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2745 /* If we copied the data into a new rc style, fix up references to the old rc style
2746 * in bindings that we have.
2749 fixup_rc_sets (context, orig_style, rc_style);
2753 g_object_unref (orig_style);
2755 return G_TOKEN_NONE;
2758 if (rc_style != orig_style)
2759 gtk_rc_style_unref (rc_style);
2762 g_object_unref (orig_style);
2767 const GtkRcProperty*
2768 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2770 GQuark property_name)
2772 GtkRcProperty *node = NULL;
2774 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2776 if (rc_style->rc_properties)
2780 key.type_name = type_name;
2781 key.property_name = property_name;
2783 node = bsearch (&key,
2784 rc_style->rc_properties->data, rc_style->rc_properties->len,
2785 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2792 gtk_rc_parse_bg (GScanner *scanner,
2798 token = g_scanner_get_next_token (scanner);
2799 if (token != GTK_RC_TOKEN_BG)
2800 return GTK_RC_TOKEN_BG;
2802 token = gtk_rc_parse_state (scanner, &state);
2803 if (token != G_TOKEN_NONE)
2806 token = g_scanner_get_next_token (scanner);
2807 if (token != G_TOKEN_EQUAL_SIGN)
2808 return G_TOKEN_EQUAL_SIGN;
2810 style->color_flags[state] |= GTK_RC_BG;
2811 return gtk_rc_parse_color (scanner, &style->bg[state]);
2815 gtk_rc_parse_fg (GScanner *scanner,
2821 token = g_scanner_get_next_token (scanner);
2822 if (token != GTK_RC_TOKEN_FG)
2823 return GTK_RC_TOKEN_FG;
2825 token = gtk_rc_parse_state (scanner, &state);
2826 if (token != G_TOKEN_NONE)
2829 token = g_scanner_get_next_token (scanner);
2830 if (token != G_TOKEN_EQUAL_SIGN)
2831 return G_TOKEN_EQUAL_SIGN;
2833 style->color_flags[state] |= GTK_RC_FG;
2834 return gtk_rc_parse_color (scanner, &style->fg[state]);
2838 gtk_rc_parse_text (GScanner *scanner,
2844 token = g_scanner_get_next_token (scanner);
2845 if (token != GTK_RC_TOKEN_TEXT)
2846 return GTK_RC_TOKEN_TEXT;
2848 token = gtk_rc_parse_state (scanner, &state);
2849 if (token != G_TOKEN_NONE)
2852 token = g_scanner_get_next_token (scanner);
2853 if (token != G_TOKEN_EQUAL_SIGN)
2854 return G_TOKEN_EQUAL_SIGN;
2856 style->color_flags[state] |= GTK_RC_TEXT;
2857 return gtk_rc_parse_color (scanner, &style->text[state]);
2861 gtk_rc_parse_base (GScanner *scanner,
2867 token = g_scanner_get_next_token (scanner);
2868 if (token != GTK_RC_TOKEN_BASE)
2869 return GTK_RC_TOKEN_BASE;
2871 token = gtk_rc_parse_state (scanner, &state);
2872 if (token != G_TOKEN_NONE)
2875 token = g_scanner_get_next_token (scanner);
2876 if (token != G_TOKEN_EQUAL_SIGN)
2877 return G_TOKEN_EQUAL_SIGN;
2879 style->color_flags[state] |= GTK_RC_BASE;
2880 return gtk_rc_parse_color (scanner, &style->base[state]);
2884 gtk_rc_parse_xthickness (GScanner *scanner,
2887 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2888 return GTK_RC_TOKEN_XTHICKNESS;
2890 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2891 return G_TOKEN_EQUAL_SIGN;
2893 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2896 style->xthickness = scanner->value.v_int;
2898 return G_TOKEN_NONE;
2902 gtk_rc_parse_ythickness (GScanner *scanner,
2905 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2906 return GTK_RC_TOKEN_YTHICKNESS;
2908 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2909 return G_TOKEN_EQUAL_SIGN;
2911 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2914 style->ythickness = scanner->value.v_int;
2916 return G_TOKEN_NONE;
2920 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2922 GtkRcStyle *rc_style)
2928 token = g_scanner_get_next_token (scanner);
2929 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2930 return GTK_RC_TOKEN_BG_PIXMAP;
2932 token = gtk_rc_parse_state (scanner, &state);
2933 if (token != G_TOKEN_NONE)
2936 token = g_scanner_get_next_token (scanner);
2937 if (token != G_TOKEN_EQUAL_SIGN)
2938 return G_TOKEN_EQUAL_SIGN;
2940 token = g_scanner_get_next_token (scanner);
2941 if (token != G_TOKEN_STRING)
2942 return G_TOKEN_STRING;
2944 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2945 (strcmp (scanner->value.v_string, "<none>") == 0))
2946 pixmap_file = g_strdup (scanner->value.v_string);
2948 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2949 scanner, scanner->value.v_string);
2953 if (rc_style->bg_pixmap_name[state])
2954 g_free (rc_style->bg_pixmap_name[state]);
2955 rc_style->bg_pixmap_name[state] = pixmap_file;
2958 return G_TOKEN_NONE;
2962 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2967 buf = g_build_filename (dir, pixmap_file, NULL);
2969 fd = open (buf, O_RDONLY);
2982 * gtk_rc_find_pixmap_in_path:
2983 * @settings: a #GtkSettings
2984 * @scanner: Scanner used to get line number information for the
2985 * warning message, or %NULL
2986 * @pixmap_file: name of the pixmap file to locate.
2988 * Looks up a file in pixmap path for the specified #GtkSettings.
2989 * If the file is not found, it outputs a warning message using
2990 * g_warning() and returns %NULL.
2992 * Return value: the filename.
2995 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2997 const gchar *pixmap_file)
3003 GtkRcContext *context = gtk_rc_context_get (settings);
3005 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
3007 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
3012 tmp_list = current_files_stack;
3015 GtkRcFile *curfile = tmp_list->data;
3016 filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
3020 tmp_list = tmp_list->next;
3024 g_scanner_warn (scanner,
3025 _("Unable to locate image file in pixmap_path: \"%s\""),
3028 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3035 * gtk_rc_find_module_in_path:
3036 * @module_file: name of a theme engine
3038 * Searches for a theme engine in the GTK+ search path. This function
3039 * is not useful for applications and should not be used.
3041 * Return value: The filename, if found (must be freed with g_free()),
3045 gtk_rc_find_module_in_path (const gchar *module_file)
3047 return _gtk_find_module (module_file, "engines");
3051 gtk_rc_parse_font (GScanner *scanner,
3052 GtkRcStyle *rc_style)
3056 token = g_scanner_get_next_token (scanner);
3057 if (token != GTK_RC_TOKEN_FONT)
3058 return GTK_RC_TOKEN_FONT;
3060 token = g_scanner_get_next_token (scanner);
3061 if (token != G_TOKEN_EQUAL_SIGN)
3062 return G_TOKEN_EQUAL_SIGN;
3064 token = g_scanner_get_next_token (scanner);
3065 if (token != G_TOKEN_STRING)
3066 return G_TOKEN_STRING;
3068 /* Ignore, do nothing */
3070 return G_TOKEN_NONE;
3074 gtk_rc_parse_fontset (GScanner *scanner,
3075 GtkRcStyle *rc_style)
3079 token = g_scanner_get_next_token (scanner);
3080 if (token != GTK_RC_TOKEN_FONTSET)
3081 return GTK_RC_TOKEN_FONTSET;
3083 token = g_scanner_get_next_token (scanner);
3084 if (token != G_TOKEN_EQUAL_SIGN)
3085 return G_TOKEN_EQUAL_SIGN;
3087 token = g_scanner_get_next_token (scanner);
3088 if (token != G_TOKEN_STRING)
3089 return G_TOKEN_STRING;
3091 /* Do nothing - silently ignore */
3093 return G_TOKEN_NONE;
3097 gtk_rc_parse_font_name (GScanner *scanner,
3098 GtkRcStyle *rc_style)
3102 token = g_scanner_get_next_token (scanner);
3103 if (token != GTK_RC_TOKEN_FONT_NAME)
3104 return GTK_RC_TOKEN_FONT;
3106 token = g_scanner_get_next_token (scanner);
3107 if (token != G_TOKEN_EQUAL_SIGN)
3108 return G_TOKEN_EQUAL_SIGN;
3110 token = g_scanner_get_next_token (scanner);
3111 if (token != G_TOKEN_STRING)
3112 return G_TOKEN_STRING;
3114 if (rc_style->font_desc)
3115 pango_font_description_free (rc_style->font_desc);
3117 rc_style->font_desc =
3118 pango_font_description_from_string (scanner->value.v_string);
3120 return G_TOKEN_NONE;
3124 gtk_rc_parse_engine (GtkRcContext *context,
3126 GtkRcStyle **rc_style)
3129 GtkThemeEngine *engine;
3130 guint result = G_TOKEN_NONE;
3131 GtkRcStyle *new_style = NULL;
3132 gboolean parsed_curlies = FALSE;
3134 token = g_scanner_get_next_token (scanner);
3135 if (token != GTK_RC_TOKEN_ENGINE)
3136 return GTK_RC_TOKEN_ENGINE;
3138 token = g_scanner_get_next_token (scanner);
3139 if (token != G_TOKEN_STRING)
3140 return G_TOKEN_STRING;
3142 if (!scanner->value.v_string[0])
3144 /* Support engine "" {} to mean override to the default engine
3146 token = g_scanner_get_next_token (scanner);
3147 if (token != G_TOKEN_LEFT_CURLY)
3148 return G_TOKEN_LEFT_CURLY;
3150 token = g_scanner_get_next_token (scanner);
3151 if (token != G_TOKEN_RIGHT_CURLY)
3152 return G_TOKEN_RIGHT_CURLY;
3154 parsed_curlies = TRUE;
3156 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3158 new_style = gtk_rc_style_new ();
3159 gtk_rc_style_real_merge (new_style, *rc_style);
3161 if ((*rc_style)->name)
3162 new_style->name = g_strdup ((*rc_style)->name);
3165 (*rc_style)->engine_specified = TRUE;
3169 engine = gtk_theme_engine_get (scanner->value.v_string);
3171 token = g_scanner_get_next_token (scanner);
3172 if (token != G_TOKEN_LEFT_CURLY)
3173 return G_TOKEN_LEFT_CURLY;
3177 GtkRcStyleClass *new_class;
3179 new_style = gtk_theme_engine_create_rc_style (engine);
3180 g_type_module_unuse (G_TYPE_MODULE (engine));
3182 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3184 new_class->merge (new_style, *rc_style);
3185 if ((*rc_style)->name)
3186 new_style->name = g_strdup ((*rc_style)->name);
3188 if (new_class->parse)
3190 parsed_curlies = TRUE;
3191 result = new_class->parse (new_style, context->settings, scanner);
3193 if (result != G_TOKEN_NONE)
3195 g_object_unref (new_style);
3202 if (!parsed_curlies)
3204 /* Skip over remainder, looking for nested {}'s
3208 result = G_TOKEN_RIGHT_CURLY;
3209 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3211 if (token == G_TOKEN_LEFT_CURLY)
3213 else if (token == G_TOKEN_RIGHT_CURLY)
3218 result = G_TOKEN_NONE;
3226 new_style->engine_specified = TRUE;
3228 g_object_unref (*rc_style);
3229 *rc_style = new_style;
3236 gtk_rc_parse_state (GScanner *scanner,
3237 GtkStateType *state)
3242 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3243 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3245 /* we don't know where we got called from, so we reset the scope here.
3246 * if we bail out due to errors, we *don't* reset the scope, so the
3247 * error messaging code can make sense of our tokens.
3249 old_scope = g_scanner_set_scope (scanner, 0);
3251 token = g_scanner_get_next_token (scanner);
3252 if (token != G_TOKEN_LEFT_BRACE)
3253 return G_TOKEN_LEFT_BRACE;
3255 token = g_scanner_get_next_token (scanner);
3258 case GTK_RC_TOKEN_ACTIVE:
3259 *state = GTK_STATE_ACTIVE;
3261 case GTK_RC_TOKEN_INSENSITIVE:
3262 *state = GTK_STATE_INSENSITIVE;
3264 case GTK_RC_TOKEN_NORMAL:
3265 *state = GTK_STATE_NORMAL;
3267 case GTK_RC_TOKEN_PRELIGHT:
3268 *state = GTK_STATE_PRELIGHT;
3270 case GTK_RC_TOKEN_SELECTED:
3271 *state = GTK_STATE_SELECTED;
3274 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3277 token = g_scanner_get_next_token (scanner);
3278 if (token != G_TOKEN_RIGHT_BRACE)
3279 return G_TOKEN_RIGHT_BRACE;
3281 g_scanner_set_scope (scanner, old_scope);
3283 return G_TOKEN_NONE;
3287 gtk_rc_parse_priority (GScanner *scanner,
3288 GtkPathPriorityType *priority)
3293 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3294 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3296 /* we don't know where we got called from, so we reset the scope here.
3297 * if we bail out due to errors, we *don't* reset the scope, so the
3298 * error messaging code can make sense of our tokens.
3300 old_scope = g_scanner_set_scope (scanner, 0);
3302 token = g_scanner_get_next_token (scanner);
3306 token = g_scanner_get_next_token (scanner);
3309 case GTK_RC_TOKEN_LOWEST:
3310 *priority = GTK_PATH_PRIO_LOWEST;
3312 case GTK_RC_TOKEN_GTK:
3313 *priority = GTK_PATH_PRIO_GTK;
3315 case GTK_RC_TOKEN_APPLICATION:
3316 *priority = GTK_PATH_PRIO_APPLICATION;
3318 case GTK_RC_TOKEN_THEME:
3319 *priority = GTK_PATH_PRIO_THEME;
3321 case GTK_RC_TOKEN_RC:
3322 *priority = GTK_PATH_PRIO_RC;
3324 case GTK_RC_TOKEN_HIGHEST:
3325 *priority = GTK_PATH_PRIO_HIGHEST;
3328 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3331 g_scanner_set_scope (scanner, old_scope);
3333 return G_TOKEN_NONE;
3337 gtk_rc_parse_color (GScanner *scanner,
3342 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3344 /* we don't need to set our own scope here, because
3345 * we don't need own symbols
3348 token = g_scanner_get_next_token (scanner);
3353 case G_TOKEN_LEFT_CURLY:
3354 token = g_scanner_get_next_token (scanner);
3355 if (token == G_TOKEN_INT)
3356 token_int = scanner->value.v_int;
3357 else if (token == G_TOKEN_FLOAT)
3358 token_int = scanner->value.v_float * 65535.0;
3360 return G_TOKEN_FLOAT;
3361 color->red = CLAMP (token_int, 0, 65535);
3363 token = g_scanner_get_next_token (scanner);
3364 if (token != G_TOKEN_COMMA)
3365 return G_TOKEN_COMMA;
3367 token = g_scanner_get_next_token (scanner);
3368 if (token == G_TOKEN_INT)
3369 token_int = scanner->value.v_int;
3370 else if (token == G_TOKEN_FLOAT)
3371 token_int = scanner->value.v_float * 65535.0;
3373 return G_TOKEN_FLOAT;
3374 color->green = CLAMP (token_int, 0, 65535);
3376 token = g_scanner_get_next_token (scanner);
3377 if (token != G_TOKEN_COMMA)
3378 return G_TOKEN_COMMA;
3380 token = g_scanner_get_next_token (scanner);
3381 if (token == G_TOKEN_INT)
3382 token_int = scanner->value.v_int;
3383 else if (token == G_TOKEN_FLOAT)
3384 token_int = scanner->value.v_float * 65535.0;
3386 return G_TOKEN_FLOAT;
3387 color->blue = CLAMP (token_int, 0, 65535);
3389 token = g_scanner_get_next_token (scanner);
3390 if (token != G_TOKEN_RIGHT_CURLY)
3391 return G_TOKEN_RIGHT_CURLY;
3392 return G_TOKEN_NONE;
3394 case G_TOKEN_STRING:
3395 if (!gdk_color_parse (scanner->value.v_string, color))
3397 g_scanner_warn (scanner, "Invalid color constant '%s'",
3398 scanner->value.v_string);
3399 return G_TOKEN_STRING;
3402 return G_TOKEN_NONE;
3405 return G_TOKEN_STRING;
3410 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3415 token = g_scanner_get_next_token (scanner);
3416 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3417 return GTK_RC_TOKEN_PIXMAP_PATH;
3419 token = g_scanner_get_next_token (scanner);
3420 if (token != G_TOKEN_STRING)
3421 return G_TOKEN_STRING;
3423 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3425 return G_TOKEN_NONE;
3429 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3431 const gchar *pix_path)
3434 gint start_offset = 0;
3438 /* free the old one, or just add to the old one ? */
3439 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3441 g_free (context->pixmap_path[path_num]);
3442 context->pixmap_path[path_num] = NULL;
3447 path_len = strlen (pix_path);
3449 for (end_offset = 0; end_offset <= path_len; end_offset++)
3451 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3452 (end_offset == path_len))
3454 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3455 if (g_path_is_absolute (path_element))
3457 context->pixmap_path[path_num] = path_element;
3459 context->pixmap_path[path_num] = NULL;
3463 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3464 path_element, scanner->input_name, scanner->line);
3465 g_free (path_element);
3468 start_offset = end_offset + 1;
3474 gtk_rc_parse_module_path (GScanner *scanner)
3478 token = g_scanner_get_next_token (scanner);
3479 if (token != GTK_RC_TOKEN_MODULE_PATH)
3480 return GTK_RC_TOKEN_MODULE_PATH;
3482 token = g_scanner_get_next_token (scanner);
3483 if (token != G_TOKEN_STRING)
3484 return G_TOKEN_STRING;
3486 g_warning ("module_path directive is now ignored\n");
3488 return G_TOKEN_NONE;
3492 gtk_rc_parse_im_module_file (GScanner *scanner)
3496 token = g_scanner_get_next_token (scanner);
3497 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3498 return GTK_RC_TOKEN_IM_MODULE_FILE;
3500 token = g_scanner_get_next_token (scanner);
3501 if (token != G_TOKEN_STRING)
3502 return G_TOKEN_STRING;
3505 g_free (im_module_file);
3507 im_module_file = g_strdup (scanner->value.v_string);
3509 return G_TOKEN_NONE;
3513 gtk_rc_parse_path_pattern (GtkRcContext *context,
3517 GtkPathType path_type;
3519 gboolean is_binding;
3520 GtkPathPriorityType priority = context->default_priority;
3522 token = g_scanner_get_next_token (scanner);
3525 case GTK_RC_TOKEN_WIDGET:
3526 path_type = GTK_PATH_WIDGET;
3528 case GTK_RC_TOKEN_WIDGET_CLASS:
3529 path_type = GTK_PATH_WIDGET_CLASS;
3531 case GTK_RC_TOKEN_CLASS:
3532 path_type = GTK_PATH_CLASS;
3535 return GTK_RC_TOKEN_WIDGET_CLASS;
3538 token = g_scanner_get_next_token (scanner);
3539 if (token != G_TOKEN_STRING)
3540 return G_TOKEN_STRING;
3542 pattern = g_strdup (scanner->value.v_string);
3544 token = g_scanner_get_next_token (scanner);
3545 if (token == GTK_RC_TOKEN_STYLE)
3547 else if (token == GTK_RC_TOKEN_BINDING)
3552 return GTK_RC_TOKEN_STYLE;
3555 if (g_scanner_peek_next_token (scanner) == ':')
3557 token = gtk_rc_parse_priority (scanner, &priority);
3558 if (token != G_TOKEN_NONE)
3565 token = g_scanner_get_next_token (scanner);
3566 if (token != G_TOKEN_STRING)
3569 return G_TOKEN_STRING;
3574 GtkBindingSet *binding;
3576 binding = gtk_binding_set_find (scanner->value.v_string);
3580 return G_TOKEN_STRING;
3582 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3586 GtkRcStyle *rc_style;
3589 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3594 return G_TOKEN_STRING;
3597 rc_set = g_new (GtkRcSet, 1);
3598 rc_set->pspec = g_pattern_spec_new (pattern);
3599 rc_set->rc_style = rc_style;
3600 rc_set->priority = priority;
3602 if (path_type == GTK_PATH_WIDGET)
3603 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3604 else if (path_type == GTK_PATH_WIDGET_CLASS)
3605 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3607 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3611 return G_TOKEN_NONE;
3615 gtk_rc_parse_stock_id (GScanner *scanner,
3620 token = g_scanner_get_next_token (scanner);
3621 if (token != G_TOKEN_LEFT_BRACE)
3622 return G_TOKEN_LEFT_BRACE;
3624 token = g_scanner_get_next_token (scanner);
3626 if (token != G_TOKEN_STRING)
3627 return G_TOKEN_STRING;
3629 *stock_id = g_strdup (scanner->value.v_string);
3631 token = g_scanner_get_next_token (scanner);
3632 if (token != G_TOKEN_RIGHT_BRACE)
3635 return G_TOKEN_RIGHT_BRACE;
3638 return G_TOKEN_NONE;
3642 gtk_rc_parse_icon_source (GtkRcContext *context,
3644 GtkIconSet *icon_set,
3645 gboolean *icon_set_valid)
3648 GtkIconSource *source;
3649 gchar *full_filename;
3651 token = g_scanner_get_next_token (scanner);
3652 if (token != G_TOKEN_LEFT_CURLY)
3653 return G_TOKEN_LEFT_CURLY;
3655 token = g_scanner_get_next_token (scanner);
3657 if (token != G_TOKEN_STRING && token != '@')
3658 return G_TOKEN_STRING;
3660 source = gtk_icon_source_new ();
3662 if (token == G_TOKEN_STRING)
3666 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3669 gtk_icon_source_set_filename (source, full_filename);
3670 g_free (full_filename);
3677 token = g_scanner_get_next_token (scanner);
3679 if (token != G_TOKEN_STRING)
3680 return G_TOKEN_STRING;
3682 gtk_icon_source_set_icon_name (source, scanner->value.v_string);
3685 /* We continue parsing even if we didn't find the pixmap so that rest of the
3686 * file is read, even if the syntax is bad. However we don't validate the
3687 * icon_set so the caller can choose not to install it.
3689 token = g_scanner_get_next_token (scanner);
3691 if (token == G_TOKEN_RIGHT_CURLY)
3693 else if (token != G_TOKEN_COMMA)
3695 gtk_icon_source_free (source);
3696 return G_TOKEN_COMMA;
3699 /* Get the direction */
3701 token = g_scanner_get_next_token (scanner);
3705 case GTK_RC_TOKEN_RTL:
3706 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3707 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3710 case GTK_RC_TOKEN_LTR:
3711 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3712 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3719 gtk_icon_source_free (source);
3720 return GTK_RC_TOKEN_RTL;
3724 token = g_scanner_get_next_token (scanner);
3726 if (token == G_TOKEN_RIGHT_CURLY)
3728 else if (token != G_TOKEN_COMMA)
3730 gtk_icon_source_free (source);
3731 return G_TOKEN_COMMA;
3736 token = g_scanner_get_next_token (scanner);
3740 case GTK_RC_TOKEN_NORMAL:
3741 gtk_icon_source_set_state_wildcarded (source, FALSE);
3742 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3745 case GTK_RC_TOKEN_PRELIGHT:
3746 gtk_icon_source_set_state_wildcarded (source, FALSE);
3747 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3751 case GTK_RC_TOKEN_INSENSITIVE:
3752 gtk_icon_source_set_state_wildcarded (source, FALSE);
3753 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3756 case GTK_RC_TOKEN_ACTIVE:
3757 gtk_icon_source_set_state_wildcarded (source, FALSE);
3758 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3761 case GTK_RC_TOKEN_SELECTED:
3762 gtk_icon_source_set_state_wildcarded (source, FALSE);
3763 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3770 gtk_icon_source_free (source);
3771 return GTK_RC_TOKEN_PRELIGHT;
3775 token = g_scanner_get_next_token (scanner);
3777 if (token == G_TOKEN_RIGHT_CURLY)
3779 else if (token != G_TOKEN_COMMA)
3781 gtk_icon_source_free (source);
3782 return G_TOKEN_COMMA;
3787 token = g_scanner_get_next_token (scanner);
3793 if (token != G_TOKEN_STRING)
3795 gtk_icon_source_free (source);
3796 return G_TOKEN_STRING;
3799 size = gtk_icon_size_from_name (scanner->value.v_string);
3801 if (size != GTK_ICON_SIZE_INVALID)
3803 gtk_icon_source_set_size_wildcarded (source, FALSE);
3804 gtk_icon_source_set_size (source, size);
3808 /* Check the close brace */
3810 token = g_scanner_get_next_token (scanner);
3811 if (token != G_TOKEN_RIGHT_CURLY)
3813 gtk_icon_source_free (source);
3814 return G_TOKEN_RIGHT_CURLY;
3818 if (gtk_icon_source_get_filename (source) ||
3819 gtk_icon_source_get_icon_name (source))
3821 gtk_icon_set_add_source (icon_set, source);
3822 *icon_set_valid = TRUE;
3824 gtk_icon_source_free (source);
3826 return G_TOKEN_NONE;
3830 gtk_rc_parse_stock (GtkRcContext *context,
3832 GtkRcStyle *rc_style,
3833 GtkIconFactory *factory)
3835 GtkIconSet *icon_set = NULL;
3836 gboolean icon_set_valid = FALSE;
3837 gchar *stock_id = NULL;
3840 token = g_scanner_get_next_token (scanner);
3841 if (token != GTK_RC_TOKEN_STOCK)
3842 return GTK_RC_TOKEN_STOCK;
3844 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3845 if (token != G_TOKEN_NONE)
3848 token = g_scanner_get_next_token (scanner);
3849 if (token != G_TOKEN_EQUAL_SIGN)
3852 return G_TOKEN_EQUAL_SIGN;
3855 token = g_scanner_get_next_token (scanner);
3856 if (token != G_TOKEN_LEFT_CURLY)
3859 return G_TOKEN_LEFT_CURLY;
3862 token = g_scanner_peek_next_token (scanner);
3863 while (token != G_TOKEN_RIGHT_CURLY)
3865 if (icon_set == NULL)
3866 icon_set = gtk_icon_set_new ();
3868 token = gtk_rc_parse_icon_source (context,
3869 scanner, icon_set, &icon_set_valid);
3870 if (token != G_TOKEN_NONE)
3873 gtk_icon_set_unref (icon_set);
3877 token = g_scanner_get_next_token (scanner);
3879 if (token != G_TOKEN_COMMA &&
3880 token != G_TOKEN_RIGHT_CURLY)
3883 gtk_icon_set_unref (icon_set);
3884 return G_TOKEN_RIGHT_CURLY;
3891 gtk_icon_factory_add (factory,
3895 gtk_icon_set_unref (icon_set);
3900 return G_TOKEN_NONE;