1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
47 #include "gdkconfig.h"
49 #include "gtkversion.h"
51 #include "gtkbindings.h"
52 #include "gtkthemes.h"
54 #include "gtkiconfactory.h"
56 #include "gtkprivate.h"
57 #include "gtksettings.h"
58 #include "gtkwindow.h"
64 typedef struct _GtkRcSet GtkRcSet;
65 typedef struct _GtkRcNode GtkRcNode;
66 typedef struct _GtkRcFile GtkRcFile;
77 gboolean is_string; /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
80 gchar *canonical_name;
84 #define GTK_RC_MAX_PIXMAP_PATHS 128
88 GHashTable *rc_style_ht;
89 GtkSettings *settings;
90 GSList *rc_sets_widget;
91 GSList *rc_sets_widget_class;
92 GSList *rc_sets_class;
94 /* The files we have parsed, to reread later if necessary */
98 gchar *key_theme_name;
101 gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
103 gint default_priority;
104 GtkStyle *default_style;
107 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
109 static guint gtk_rc_style_hash (const gchar *name);
110 static gboolean gtk_rc_style_equal (const gchar *a,
112 static guint gtk_rc_styles_hash (const GSList *rc_styles);
113 static gboolean gtk_rc_styles_equal (const GSList *a,
115 static GtkRcStyle* gtk_rc_style_find (GtkRcContext *context,
117 static GSList * gtk_rc_styles_match (GSList *rc_styles,
121 const gchar *path_reversed);
122 static GtkStyle * gtk_rc_style_to_style (GtkRcContext *context,
123 GtkRcStyle *rc_style);
124 static GtkStyle* gtk_rc_init_style (GtkRcContext *context,
126 static void gtk_rc_parse_default_files (GtkRcContext *context);
127 static void gtk_rc_parse_named (GtkRcContext *context,
130 static void gtk_rc_context_parse_file (GtkRcContext *context,
131 const gchar *filename,
134 static void gtk_rc_parse_any (GtkRcContext *context,
135 const gchar *input_name,
137 const gchar *input_string);
138 static guint gtk_rc_parse_statement (GtkRcContext *context,
140 static guint gtk_rc_parse_style (GtkRcContext *context,
142 static guint gtk_rc_parse_assignment (GScanner *scanner,
143 GtkRcProperty *prop);
144 static guint gtk_rc_parse_bg (GScanner *scanner,
146 static guint gtk_rc_parse_fg (GScanner *scanner,
148 static guint gtk_rc_parse_text (GScanner *scanner,
150 static guint gtk_rc_parse_base (GScanner *scanner,
152 static guint gtk_rc_parse_xthickness (GScanner *scanner,
154 static guint gtk_rc_parse_ythickness (GScanner *scanner,
156 static guint gtk_rc_parse_bg_pixmap (GtkRcContext *context,
158 GtkRcStyle *rc_style);
159 static guint gtk_rc_parse_font (GScanner *scanner,
160 GtkRcStyle *rc_style);
161 static guint gtk_rc_parse_fontset (GScanner *scanner,
162 GtkRcStyle *rc_style);
163 static guint gtk_rc_parse_font_name (GScanner *scanner,
164 GtkRcStyle *rc_style);
165 static guint gtk_rc_parse_engine (GtkRcContext *context,
167 GtkRcStyle **rc_style);
168 static guint gtk_rc_parse_pixmap_path (GtkRcContext *context,
170 static void gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
172 const gchar *pix_path);
173 static guint gtk_rc_parse_module_path (GScanner *scanner);
174 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
175 static guint gtk_rc_parse_path_pattern (GtkRcContext *context,
177 static guint gtk_rc_parse_stock (GtkRcContext *context,
179 GtkRcStyle *rc_style,
180 GtkIconFactory *factory);
181 static void gtk_rc_clear_hash_node (gpointer key,
184 static void gtk_rc_clear_styles (GtkRcContext *context);
185 static void gtk_rc_add_initial_default_files (void);
187 static void gtk_rc_style_init (GtkRcStyle *style);
188 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
189 static void gtk_rc_style_finalize (GObject *object);
190 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
192 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
193 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
194 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
195 gconstpointer bsearch_node2);
197 static gpointer parent_class = NULL;
199 static const GScannerConfig gtk_rc_scanner_config =
203 ) /* cset_skip_characters */,
208 ) /* cset_identifier_first */,
213 ) /* cset_identifier_nth */,
214 ( "#\n" ) /* cpair_comment_single */,
216 TRUE /* case_sensitive */,
218 TRUE /* skip_comment_multi */,
219 TRUE /* skip_comment_single */,
220 TRUE /* scan_comment_multi */,
221 TRUE /* scan_identifier */,
222 FALSE /* scan_identifier_1char */,
223 FALSE /* scan_identifier_NULL */,
224 TRUE /* scan_symbols */,
225 TRUE /* scan_binary */,
226 TRUE /* scan_octal */,
227 TRUE /* scan_float */,
229 TRUE /* scan_hex_dollar */,
230 TRUE /* scan_string_sq */,
231 TRUE /* scan_string_dq */,
232 TRUE /* numbers_2_int */,
233 FALSE /* int_2_float */,
234 FALSE /* identifier_2_string */,
235 TRUE /* char_2_token */,
236 TRUE /* symbol_2_token */,
237 FALSE /* scope_0_fallback */,
245 { "include", GTK_RC_TOKEN_INCLUDE },
246 { "NORMAL", GTK_RC_TOKEN_NORMAL },
247 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
248 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
249 { "SELECTED", GTK_RC_TOKEN_SELECTED },
250 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
251 { "fg", GTK_RC_TOKEN_FG },
252 { "bg", GTK_RC_TOKEN_BG },
253 { "text", GTK_RC_TOKEN_TEXT },
254 { "base", GTK_RC_TOKEN_BASE },
255 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
256 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
257 { "font", GTK_RC_TOKEN_FONT },
258 { "fontset", GTK_RC_TOKEN_FONTSET },
259 { "font_name", GTK_RC_TOKEN_FONT_NAME },
260 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
261 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
262 { "style", GTK_RC_TOKEN_STYLE },
263 { "binding", GTK_RC_TOKEN_BINDING },
264 { "bind", GTK_RC_TOKEN_BIND },
265 { "widget", GTK_RC_TOKEN_WIDGET },
266 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
267 { "class", GTK_RC_TOKEN_CLASS },
268 { "lowest", GTK_RC_TOKEN_LOWEST },
269 { "gtk", GTK_RC_TOKEN_GTK },
270 { "application", GTK_RC_TOKEN_APPLICATION },
271 { "theme", GTK_RC_TOKEN_THEME },
272 { "rc", GTK_RC_TOKEN_RC },
273 { "highest", GTK_RC_TOKEN_HIGHEST },
274 { "engine", GTK_RC_TOKEN_ENGINE },
275 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
276 { "stock", GTK_RC_TOKEN_STOCK },
277 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
278 { "LTR", GTK_RC_TOKEN_LTR },
279 { "RTL", GTK_RC_TOKEN_RTL }
282 static GHashTable *realized_style_ht = NULL;
284 static gchar *im_module_file = NULL;
286 #define GTK_RC_MAX_DEFAULT_FILES 128
287 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
289 /* A stack of directories for RC files we are parsing currently.
290 * these are implicitely added to the end of PIXMAP_PATHS
292 static GSList *rc_dir_stack = NULL;
294 /* RC files and strings that are parsed for every context
296 static GSList *global_rc_files = NULL;
298 /* Keep list of all current RC contexts for convenience
300 static GSList *rc_contexts;
302 /* RC file handling */
305 gtk_rc_make_default_dir (const gchar *type)
310 var = g_getenv ("GTK_EXE_PREFIX");
312 path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
314 path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
320 * gtk_rc_get_im_module_path:
321 * @returns: a newly-allocated string containing the path in which to
322 * look for IM modules.
324 * Obtains the path in which to look for IM modules. See the documentation
325 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
326 * environment variable for more details about looking up modules. This
327 * function is useful solely for utilities supplied with GTK+ and should
328 * not be used by applications under normal circumstances.
331 gtk_rc_get_im_module_path (void)
333 gchar **paths = _gtk_get_module_path ("immodules");
334 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
341 * gtk_rc_get_im_module_file:
342 * @returns: a newly-allocated string containing the name of the file
343 * listing the IM modules available for loading
345 * Obtains the path to the IM modules file. See the documentation
346 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
347 * environment variable for more details.
350 gtk_rc_get_im_module_file (void)
352 gchar *result = g_strdup (g_getenv ("GTK_IM_MODULE_FILE"));
357 result = g_strdup (im_module_file);
359 result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
366 gtk_rc_get_theme_dir (void)
371 var = g_getenv ("GTK_DATA_PREFIX");
373 path = g_build_filename (var, "share", "themes", NULL);
375 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
381 * gtk_rc_get_module_dir:
383 * Returns a directory in which GTK+ looks for theme engines.
384 * For full information about the search for theme engines,
385 * see the docs for <envar>GTK_PATH</envar> in
386 * <xref linkend="gtk-running"/>.
388 * return value: the directory. (Must be freed with g_free())
391 gtk_rc_get_module_dir (void)
393 return gtk_rc_make_default_dir ("engines");
397 gtk_rc_add_initial_default_files (void)
399 static gint init = FALSE;
408 gtk_rc_default_files[0] = NULL;
411 var = g_getenv ("GTK2_RC_FILES");
414 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
418 gtk_rc_add_default_file (files[i]);
425 str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
427 gtk_rc_add_default_file (str);
430 var = g_get_home_dir ();
433 str = g_build_filename (var, ".gtkrc-2.0", NULL);
434 gtk_rc_add_default_file (str);
441 * gtk_rc_add_default_file:
442 * @filename: the pathname to the file. If @filename is not absolute, it
443 * is searched in the current directory.
445 * Adds a file to the list of files to be parsed at the
449 gtk_rc_add_default_file (const gchar *filename)
453 gtk_rc_add_initial_default_files ();
455 for (n = 0; gtk_rc_default_files[n]; n++) ;
456 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
459 gtk_rc_default_files[n++] = g_strdup (filename);
460 gtk_rc_default_files[n] = NULL;
464 * gtk_rc_set_default_files:
465 * @filenames: A %NULL-terminated list of filenames.
467 * Sets the list of files that GTK+ will read at the
471 gtk_rc_set_default_files (gchar **filenames)
475 gtk_rc_add_initial_default_files ();
478 while (gtk_rc_default_files[i])
480 g_free (gtk_rc_default_files[i]);
484 gtk_rc_default_files[0] = NULL;
487 while (filenames[i] != NULL)
489 gtk_rc_add_default_file (filenames[i]);
495 * gtk_rc_get_default_files:
497 * Retrieves the current list of RC files that will be parsed
498 * at the end of gtk_init().
500 * Return value: A %NULL-terminated array of filenames. This memory
501 * is owned by GTK+ and must not be freed by the application.
502 * If you want to store this information, you should make a copy.
505 gtk_rc_get_default_files (void)
507 gtk_rc_add_initial_default_files ();
509 return gtk_rc_default_files;
513 gtk_rc_settings_changed (GtkSettings *settings,
515 GtkRcContext *context)
517 gchar *new_theme_name;
518 gchar *new_key_theme_name;
520 g_object_get (settings,
521 "gtk-theme-name", &new_theme_name,
522 "gtk-key-theme-name", &new_key_theme_name,
525 if ((new_theme_name != context->theme_name &&
526 !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
527 (new_key_theme_name != context->key_theme_name &&
528 !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
530 gtk_rc_reparse_all_for_settings (settings, TRUE);
533 g_free (new_theme_name);
534 g_free (new_key_theme_name);
538 gtk_rc_font_name_changed (GtkSettings *settings,
540 GtkRcContext *context)
542 _gtk_rc_context_get_default_font_name (settings);
545 static GtkRcContext *
546 gtk_rc_context_get (GtkSettings *settings)
548 if (!settings->rc_context)
550 GtkRcContext *context = settings->rc_context = g_new (GtkRcContext, 1);
552 context->settings = settings;
553 context->rc_style_ht = NULL;
554 context->rc_sets_widget = NULL;
555 context->rc_sets_widget_class = NULL;
556 context->rc_sets_class = NULL;
557 context->rc_files = NULL;
558 context->default_style = NULL;
560 g_object_get (settings,
561 "gtk-theme-name", &context->theme_name,
562 "gtk-key-theme-name", &context->key_theme_name,
563 "gtk-font-name", &context->font_name,
566 g_signal_connect (settings,
567 "notify::gtk-theme-name",
568 G_CALLBACK (gtk_rc_settings_changed),
570 g_signal_connect (settings,
571 "notify::gtk-key-theme-name",
572 G_CALLBACK (gtk_rc_settings_changed),
574 g_signal_connect (settings,
575 "notify::gtk-font-name",
576 G_CALLBACK (gtk_rc_font_name_changed),
580 context->pixmap_path[0] = NULL;
582 context->default_priority = GTK_PATH_PRIO_RC;
584 rc_contexts = g_slist_prepend (rc_contexts, settings->rc_context);
587 return settings->rc_context;
591 gtk_rc_parse_named (GtkRcContext *context,
596 const gchar *home_dir;
600 subpath = g_strconcat ("gtk-2.0-", type,
601 G_DIR_SEPARATOR_S "gtkrc",
604 subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
606 /* First look in the users home directory
608 home_dir = g_get_home_dir ();
611 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
612 if (!g_file_test (path, G_FILE_TEST_EXISTS))
621 gchar *theme_dir = gtk_rc_get_theme_dir ();
622 path = g_build_filename (theme_dir, name, subpath, NULL);
625 if (!g_file_test (path, G_FILE_TEST_EXISTS))
634 gtk_rc_context_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
642 gtk_rc_parse_default_files (GtkRcContext *context)
646 for (i = 0; gtk_rc_default_files[i] != NULL; i++)
647 gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
653 static gboolean initialized = FALSE;
659 gtk_rc_add_initial_default_files ();
662 /* Default RC string */
663 gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
664 " bg[NORMAL] = \"#ffffc0\"\n"
665 " fg[NORMAL] = \"#000000\"\n"
668 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n");
672 gtk_rc_context_parse_string (GtkRcContext *context,
673 const gchar *rc_string)
675 gtk_rc_parse_any (context, "-", -1, rc_string);
679 gtk_rc_parse_string (const gchar *rc_string)
684 g_return_if_fail (rc_string != NULL);
686 rc_file = g_new (GtkRcFile, 1);
687 rc_file->is_string = TRUE;
688 rc_file->name = g_strdup (rc_string);
689 rc_file->canonical_name = NULL;
691 rc_file->reload = TRUE;
693 global_rc_files = g_slist_append (global_rc_files, rc_file);
695 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
696 gtk_rc_context_parse_string (tmp_list->data, rc_string);
700 add_to_rc_file_list (GSList **rc_file_list,
701 const char *filename,
707 tmp_list = *rc_file_list;
710 rc_file = tmp_list->data;
711 if (!strcmp (rc_file->name, filename))
714 tmp_list = tmp_list->next;
717 rc_file = g_new (GtkRcFile, 1);
718 rc_file->is_string = FALSE;
719 rc_file->name = g_strdup (filename);
720 rc_file->canonical_name = NULL;
722 rc_file->reload = reload;
724 *rc_file_list = g_slist_append (*rc_file_list, rc_file);
730 gtk_rc_context_parse_one_file (GtkRcContext *context,
731 const gchar *filename,
739 g_return_if_fail (filename != NULL);
741 saved_priority = context->default_priority;
742 context->default_priority = priority;
744 rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
746 if (!rc_file->canonical_name)
748 /* Get the absolute pathname */
750 if (g_path_is_absolute (rc_file->name))
751 rc_file->canonical_name = rc_file->name;
756 cwd = g_get_current_dir ();
757 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
762 if (!lstat (rc_file->canonical_name, &statbuf))
767 rc_file->mtime = statbuf.st_mtime;
769 fd = open (rc_file->canonical_name, O_RDONLY);
773 /* Temporarily push directory name for this file on
774 * a stack of directory names while parsing it
777 g_slist_prepend (rc_dir_stack,
778 g_path_get_dirname (rc_file->canonical_name));
779 gtk_rc_parse_any (context, filename, fd, NULL);
781 tmp_list = rc_dir_stack;
782 rc_dir_stack = rc_dir_stack->next;
784 g_free (tmp_list->data);
785 g_slist_free_1 (tmp_list);
791 context->default_priority = saved_priority;
795 strchr_len (const gchar *str, gint len, char c)
809 gtk_rc_context_parse_file (GtkRcContext *context,
810 const gchar *filename,
814 gchar *locale_suffixes[2];
815 gint n_locale_suffixes = 0;
819 gboolean found = FALSE;
822 locale = g_win32_getlocale ();
824 locale = setlocale (LC_CTYPE, NULL);
827 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
829 /* Determine locale-specific suffixes for RC files.
831 length = strlen (locale);
833 p = strchr (locale, '@');
837 p = strchr_len (locale, length, '.');
841 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
843 p = strchr_len (locale, length, '_');
847 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
851 gtk_rc_context_parse_one_file (context, filename, priority, reload);
852 for (j = 0; j < n_locale_suffixes; j++)
856 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
857 if (g_file_test (name, G_FILE_TEST_EXISTS))
859 gtk_rc_context_parse_one_file (context, name, priority, FALSE);
866 g_free (locale_suffixes[j]);
871 gtk_rc_parse (const gchar *filename)
875 g_return_if_fail (filename != NULL);
877 add_to_rc_file_list (&global_rc_files, filename, TRUE);
879 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
880 gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
883 /* Handling of RC styles */
886 gtk_rc_style_get_type (void)
888 static GType object_type = 0;
892 static const GTypeInfo object_info =
894 sizeof (GtkRcStyleClass),
895 (GBaseInitFunc) NULL,
896 (GBaseFinalizeFunc) NULL,
897 (GClassInitFunc) gtk_rc_style_class_init,
898 NULL, /* class_finalize */
899 NULL, /* class_data */
902 (GInstanceInitFunc) gtk_rc_style_init,
905 object_type = g_type_register_static (G_TYPE_OBJECT,
914 gtk_rc_style_init (GtkRcStyle *style)
919 style->font_desc = NULL;
921 for (i = 0; i < 5; i++)
923 static const GdkColor init_color = { 0, 0, 0, 0, };
925 style->bg_pixmap_name[i] = NULL;
926 style->color_flags[i] = 0;
927 style->fg[i] = init_color;
928 style->bg[i] = init_color;
929 style->text[i] = init_color;
930 style->base[i] = init_color;
932 style->xthickness = -1;
933 style->ythickness = -1;
934 style->rc_properties = NULL;
936 style->rc_style_lists = NULL;
937 style->icon_factories = NULL;
941 gtk_rc_style_class_init (GtkRcStyleClass *klass)
943 GObjectClass *object_class = G_OBJECT_CLASS (klass);
945 parent_class = g_type_class_peek_parent (klass);
947 object_class->finalize = gtk_rc_style_finalize;
950 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
951 klass->merge = gtk_rc_style_real_merge;
952 klass->create_style = gtk_rc_style_real_create_style;
956 gtk_rc_style_finalize (GObject *object)
958 GSList *tmp_list1, *tmp_list2;
959 GtkRcStyle *rc_style;
962 rc_style = GTK_RC_STYLE (object);
965 g_free (rc_style->name);
966 if (rc_style->font_desc)
967 pango_font_description_free (rc_style->font_desc);
969 for (i = 0; i < 5; i++)
970 if (rc_style->bg_pixmap_name[i])
971 g_free (rc_style->bg_pixmap_name[i]);
973 /* Now remove all references to this rc_style from
976 tmp_list1 = rc_style->rc_style_lists;
979 GSList *rc_styles = tmp_list1->data;
980 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
981 gtk_style_unref (style);
983 /* Remove the list of styles from the other rc_styles
986 tmp_list2 = rc_styles;
989 GtkRcStyle *other_style = tmp_list2->data;
991 if (other_style != rc_style)
992 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
994 tmp_list2 = tmp_list2->next;
997 /* And from the hash table itself
999 g_hash_table_remove (realized_style_ht, rc_styles);
1000 g_slist_free (rc_styles);
1002 tmp_list1 = tmp_list1->next;
1004 g_slist_free (rc_style->rc_style_lists);
1006 if (rc_style->rc_properties)
1010 for (i = 0; i < rc_style->rc_properties->len; i++)
1012 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1014 g_free (node->origin);
1015 g_value_unset (&node->value);
1017 g_array_free (rc_style->rc_properties, TRUE);
1018 rc_style->rc_properties = NULL;
1021 tmp_list1 = rc_style->icon_factories;
1024 g_object_unref (G_OBJECT (tmp_list1->data));
1026 tmp_list1 = tmp_list1->next;
1028 g_slist_free (rc_style->icon_factories);
1030 G_OBJECT_CLASS (parent_class)->finalize (object);
1034 gtk_rc_style_new (void)
1038 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1044 * gtk_rc_style_copy:
1045 * @orig: the style to copy
1047 * Makes a copy of the specified #GtkRcStyle. This function
1048 * will correctly copy an RC style that is a member of a class
1049 * derived from #GtkRcStyle.
1051 * Return value: the resulting #GtkRcStyle
1054 gtk_rc_style_copy (GtkRcStyle *orig)
1058 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1060 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1061 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1067 gtk_rc_style_ref (GtkRcStyle *rc_style)
1069 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1071 g_object_ref (G_OBJECT (rc_style));
1075 gtk_rc_style_unref (GtkRcStyle *rc_style)
1077 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1079 g_object_unref (G_OBJECT (rc_style));
1083 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1085 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1089 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1090 gconstpointer bsearch_node2)
1092 const GtkRcProperty *prop1 = bsearch_node1;
1093 const GtkRcProperty *prop2 = bsearch_node2;
1095 if (prop1->type_name == prop2->type_name)
1096 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1098 return prop1->type_name < prop2->type_name ? -1 : 1;
1102 insert_rc_property (GtkRcStyle *style,
1103 GtkRcProperty *property,
1107 GtkRcProperty *new_property = NULL;
1108 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1110 key.type_name = property->type_name;
1111 key.property_name = property->property_name;
1113 if (!style->rc_properties)
1114 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1117 while (i < style->rc_properties->len)
1119 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1125 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1127 g_free (new_property->origin);
1128 g_value_unset (&new_property->value);
1130 *new_property = key;
1144 g_array_insert_val (style->rc_properties, i, key);
1145 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1148 new_property->origin = g_strdup (property->origin);
1149 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1150 g_value_copy (&property->value, &new_property->value);
1154 gtk_rc_style_real_merge (GtkRcStyle *dest,
1159 for (i = 0; i < 5; i++)
1161 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1162 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1164 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1165 src->color_flags[i] & GTK_RC_FG)
1167 dest->fg[i] = src->fg[i];
1168 dest->color_flags[i] |= GTK_RC_FG;
1170 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1171 src->color_flags[i] & GTK_RC_BG)
1173 dest->bg[i] = src->bg[i];
1174 dest->color_flags[i] |= GTK_RC_BG;
1176 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1177 src->color_flags[i] & GTK_RC_TEXT)
1179 dest->text[i] = src->text[i];
1180 dest->color_flags[i] |= GTK_RC_TEXT;
1182 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1183 src->color_flags[i] & GTK_RC_BASE)
1185 dest->base[i] = src->base[i];
1186 dest->color_flags[i] |= GTK_RC_BASE;
1190 if (dest->xthickness < 0 && src->xthickness >= 0)
1191 dest->xthickness = src->xthickness;
1192 if (dest->ythickness < 0 && src->ythickness >= 0)
1193 dest->ythickness = src->ythickness;
1197 if (!dest->font_desc)
1198 dest->font_desc = pango_font_description_copy (src->font_desc);
1200 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1203 if (src->rc_properties)
1207 for (i = 0; i < src->rc_properties->len; i++)
1208 insert_rc_property (dest,
1209 &g_array_index (src->rc_properties, GtkRcProperty, i),
1215 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1217 return gtk_style_new ();
1221 gtk_rc_clear_hash_node (gpointer key,
1225 gtk_rc_style_unref (data);
1229 gtk_rc_free_rc_sets (GSList *slist)
1235 rc_set = slist->data;
1236 g_pattern_spec_free (rc_set->pspec);
1239 slist = slist->next;
1244 gtk_rc_clear_styles (GtkRcContext *context)
1246 /* Clear out all old rc_styles */
1248 if (context->rc_style_ht)
1250 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1251 g_hash_table_destroy (context->rc_style_ht);
1252 context->rc_style_ht = NULL;
1255 gtk_rc_free_rc_sets (context->rc_sets_widget);
1256 g_slist_free (context->rc_sets_widget);
1257 context->rc_sets_widget = NULL;
1259 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1260 g_slist_free (context->rc_sets_widget_class);
1261 context->rc_sets_widget_class = NULL;
1263 gtk_rc_free_rc_sets (context->rc_sets_class);
1264 g_slist_free (context->rc_sets_class);
1265 context->rc_sets_class = NULL;
1268 /* Reset all our widgets. Also, we have to invalidate cached icons in
1269 * icon sets so they get re-rendered.
1272 gtk_rc_reset_widgets (GtkSettings *settings)
1274 GList *list, *toplevels;
1276 _gtk_icon_set_invalidate_caches ();
1278 toplevels = gtk_window_list_toplevels ();
1279 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1281 for (list = toplevels; list; list = list->next)
1283 gtk_widget_reset_rc_styles (list->data);
1284 gtk_widget_unref (list->data);
1286 g_list_free (toplevels);
1290 gtk_rc_clear_realized_style (gpointer key,
1294 GSList *rc_styles = key;
1295 GSList *tmp_list = rc_styles;
1299 GtkRcStyle *rc_style = tmp_list->data;
1301 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1303 tmp_list = tmp_list->next;
1306 g_slist_free (rc_styles);
1310 * _gtk_rc_reset_styles:
1311 * @settings: a #GtkSettings
1313 * This setting resets all of our styles; we use it when the font
1314 * rendering parameters or the icon sizes have changed. It's both less
1315 * and more comprehensive then we actually need:
1317 * Less comprehensive: it doesn't affect widgets that have a style
1320 * More comprehensive: it resets the styles, but the styles haven't
1321 * changed. The main reason for resetting the styles is becaues
1322 * most widgets will redo all their font stuff when their style
1326 _gtk_rc_reset_styles (GtkSettings *settings)
1328 GtkRcContext *context;
1329 gboolean reset = FALSE;
1331 g_return_if_fail (GTK_IS_SETTINGS (settings));
1333 context = gtk_rc_context_get (settings);
1335 if (context->default_style)
1337 g_object_unref (G_OBJECT (context->default_style));
1338 context->default_style = NULL;
1342 /* Clear out styles that have been looked up already
1344 if (realized_style_ht)
1346 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1347 g_hash_table_destroy (realized_style_ht);
1348 realized_style_ht = NULL;
1353 gtk_rc_reset_widgets (settings);
1357 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1359 GtkRcContext *context;
1360 gchar *new_font_name;
1362 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1364 context = gtk_rc_context_get (settings);
1366 g_object_get (context->settings,
1367 "gtk-font-name", &new_font_name,
1370 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1372 g_free (context->font_name);
1373 context->font_name = g_strdup (new_font_name);
1375 _gtk_rc_reset_styles (settings);
1378 g_free (new_font_name);
1380 return context->font_name;
1384 * gtk_rc_reparse_all_for_settings:
1385 * @settings: a #GtkSettings
1386 * @force_load: load whether or not anything changed
1388 * If the modification time on any previously read file
1389 * for the given #GtkSettings has changed, discard all style information
1390 * and then reread all previously read RC files.
1392 * Return value: %TRUE if the files were reread.
1395 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1396 gboolean force_load)
1398 gboolean mtime_modified = FALSE;
1401 GtkRcContext *context;
1403 struct stat statbuf;
1405 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1407 context = gtk_rc_context_get (settings);
1411 /* Check through and see if any of the RC's have had their
1412 * mtime modified. If so, reparse everything.
1414 tmp_list = context->rc_files;
1417 rc_file = tmp_list->data;
1419 if (!rc_file->is_string)
1421 if (!lstat (rc_file->name, &statbuf) &&
1422 (statbuf.st_mtime > rc_file->mtime))
1424 mtime_modified = TRUE;
1429 tmp_list = tmp_list->next;
1433 if (force_load || mtime_modified)
1435 _gtk_binding_reset_parsed ();
1436 gtk_rc_clear_styles (context);
1437 g_object_freeze_notify (G_OBJECT (context->settings));
1439 _gtk_settings_reset_rc_values (context->settings);
1440 tmp_list = context->rc_files;
1443 rc_file = tmp_list->data;
1445 if (rc_file->canonical_name != rc_file->name)
1446 g_free (rc_file->canonical_name);
1447 g_free (rc_file->name);
1450 tmp_list = tmp_list->next;
1453 g_slist_free (context->rc_files);
1454 context->rc_files = NULL;
1456 gtk_rc_parse_default_files (context);
1458 tmp_list = global_rc_files;
1461 rc_file = tmp_list->data;
1463 if (rc_file->is_string)
1464 gtk_rc_context_parse_string (context, rc_file->name);
1466 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1468 tmp_list = tmp_list->next;
1471 g_free (context->theme_name);
1472 g_free (context->key_theme_name);
1474 g_object_get (context->settings,
1475 "gtk-theme-name", &context->theme_name,
1476 "gtk-key-theme-name", &context->key_theme_name,
1479 if (context->theme_name && context->theme_name[0])
1480 gtk_rc_parse_named (context, context->theme_name, NULL);
1481 if (context->key_theme_name && context->key_theme_name[0])
1482 gtk_rc_parse_named (context, context->key_theme_name, "key");
1484 g_object_thaw_notify (G_OBJECT (context->settings));
1486 gtk_rc_reset_widgets (context->settings);
1489 return force_load || mtime_modified;
1493 * gtk_rc_reparse_all:
1495 * If the modification time on any previously read file for the
1496 * default #GtkSettings has changed, discard all style information
1497 * and then reread all previously read RC files.
1499 * Return value: %TRUE if the files were reread.
1502 gtk_rc_reparse_all (void)
1505 gboolean result = FALSE;
1507 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1509 GtkRcContext *context = tmp_list->data;
1510 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1518 gtk_rc_styles_match (GSList *rc_styles,
1522 const gchar *path_reversed)
1529 rc_set = sets->data;
1532 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1533 rc_styles = g_slist_append (rc_styles, rc_set);
1540 rc_set_compare (gconstpointer a, gconstpointer b)
1542 const GtkRcSet *set_a = a;
1543 const GtkRcSet *set_b = b;
1545 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1549 sort_and_dereference_sets (GSList *styles)
1553 /* At this point, the list of sets is ordered by:
1555 * a) 'widget' patterns are earlier than 'widget_class' patterns
1556 * which are ealier than 'class' patterns.
1557 * a) For two matches for class patterns, a match to a child type
1558 * is before a match to a parent type
1559 * c) a match later in the RC file (or in a later RC file) is before a
1560 * match earlier in the RC file.
1562 * With a) taking precedence over b) which takes precendence over c).
1564 * Now sort by priority, which has the highest precendence for sort order
1566 styles = g_slist_sort (styles, rc_set_compare);
1568 /* Make styles->data = styles->data->rc_style
1573 GtkRcSet *set = tmp_list->data;
1574 tmp_list->data = set->rc_style;
1575 tmp_list = tmp_list->next;
1583 * @widget: a #GtkWidget
1585 * Finds all matching RC styles for a given widget,
1586 * composites them together, and then creates a
1587 * #GtkStyle representing the composite appearance.
1588 * (GTK+ actually keeps a cache of previously
1589 * created styles, so a new style may not be
1592 * Returns: the resulting style. No refcount is added
1593 * to the returned style, so if you want to save this
1594 * style around, you should add a reference yourself.
1597 gtk_rc_get_style (GtkWidget *widget)
1599 GtkRcStyle *widget_rc_style;
1600 GSList *rc_styles = NULL;
1601 GtkRcContext *context;
1603 static guint rc_style_key_id = 0;
1605 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1607 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1609 /* We allow the specification of a single rc style to be bound
1610 * tightly to a widget, for application modifications
1612 if (!rc_style_key_id)
1613 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1615 if (context->rc_sets_widget)
1617 gchar *path, *path_reversed;
1620 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1621 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1623 g_free (path_reversed);
1626 if (context->rc_sets_widget_class)
1628 gchar *path, *path_reversed;
1631 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1632 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1634 g_free (path_reversed);
1637 if (context->rc_sets_class)
1641 type = GTK_OBJECT_TYPE (widget);
1645 gchar *path_reversed;
1648 path = gtk_type_name (type);
1649 path_length = strlen (path);
1650 path_reversed = g_strdup (path);
1651 g_strreverse (path_reversed);
1653 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1654 g_free (path_reversed);
1656 type = gtk_type_parent (type);
1660 rc_styles = sort_and_dereference_sets (rc_styles);
1662 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1665 if (widget_rc_style)
1666 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1669 return gtk_rc_init_style (context, rc_styles);
1672 if (!context->default_style)
1674 context->default_style = gtk_style_new ();
1675 _gtk_style_init_for_settings (context->default_style, context->settings);
1678 return context->default_style;
1683 * gtk_rc_get_style_by_paths:
1684 * @settings: a #GtkSettings object
1685 * @widget_path: the widget path to use when looking up the style, or %NULL
1686 * if no matching against the widget path should be done
1687 * @class_path: the class path to use when looking up the style, or %NULL
1688 * if no matching against the class path should be done.
1689 * @type: a type that will be used along with parent types of this type
1690 * when matching against class styles, or #G_TYPE_NONE
1692 * Creates up a #GtkStyle from styles defined in a RC file by providing
1693 * the raw components used in matching. This function may be useful
1694 * when creating pseudo-widgets that should be themed like widgets but
1695 * don't actually have corresponding GTK+ widgets. An example of this
1696 * would be items inside a GNOME canvas widget.
1698 * The action of gtk_rc_get_style() is similar to:
1699 * <informalexample><programlisting>
1700 * gtk_widget_path (widget, NULL, &path, NULL);
1701 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1702 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1703 * G_OBJECT_TYPE (widget));
1704 * </programlisting></informalexample>
1706 * Return value: A style created by matching with the supplied paths,
1707 * or %NULL if nothing matching was specified and the default style should
1708 * be used. The returned value is owned by GTK+ as part of an internal cache,
1709 * so you must call g_object_ref() on the returned value if you want to
1710 * keep a reference to it.
1713 gtk_rc_get_style_by_paths (GtkSettings *settings,
1714 const char *widget_path,
1715 const char *class_path,
1718 /* We duplicate the code from above to avoid slowing down the above
1719 * by generating paths when we don't need them. I don't know if
1720 * this is really worth it.
1722 GSList *rc_styles = NULL;
1723 GtkRcContext *context;
1725 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1727 context = gtk_rc_context_get (settings);
1729 if (widget_path && context->rc_sets_widget)
1731 gchar *path_reversed;
1734 path_length = strlen (widget_path);
1735 path_reversed = g_strdup (widget_path);
1736 g_strreverse (path_reversed);
1738 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1739 g_free (path_reversed);
1742 if (class_path && context->rc_sets_widget_class)
1744 gchar *path_reversed;
1747 path_length = strlen (class_path);
1748 path_reversed = g_strdup (class_path);
1749 g_strreverse (path_reversed);
1751 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1752 g_free (path_reversed);
1755 if (type != G_TYPE_NONE && context->rc_sets_class)
1760 gchar *path_reversed;
1763 path = g_type_name (type);
1764 path_length = strlen (path);
1765 path_reversed = g_strdup (path);
1766 g_strreverse (path_reversed);
1768 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1769 g_free (path_reversed);
1771 type = g_type_parent (type);
1775 rc_styles = sort_and_dereference_sets (rc_styles);
1778 return gtk_rc_init_style (context, rc_styles);
1784 gtk_rc_add_rc_sets (GSList *slist,
1785 GtkRcStyle *rc_style,
1786 const gchar *pattern)
1788 GtkRcStyle *new_style;
1792 new_style = gtk_rc_style_new ();
1793 *new_style = *rc_style;
1794 new_style->name = g_strdup (rc_style->name);
1795 if (rc_style->font_desc)
1796 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1798 for (i = 0; i < 5; i++)
1799 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1801 rc_set = g_new (GtkRcSet, 1);
1802 rc_set->pspec = g_pattern_spec_new (pattern);
1803 rc_set->rc_style = rc_style;
1805 return g_slist_prepend (slist, rc_set);
1809 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1810 const gchar *pattern)
1812 GtkRcContext *context;
1814 g_return_if_fail (rc_style != NULL);
1815 g_return_if_fail (pattern != NULL);
1817 context = gtk_rc_context_get (gtk_settings_get_default ());
1819 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1823 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1824 const gchar *pattern)
1826 GtkRcContext *context;
1828 g_return_if_fail (rc_style != NULL);
1829 g_return_if_fail (pattern != NULL);
1831 context = gtk_rc_context_get (gtk_settings_get_default ());
1833 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1837 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1838 const gchar *pattern)
1840 GtkRcContext *context;
1842 g_return_if_fail (rc_style != NULL);
1843 g_return_if_fail (pattern != NULL);
1845 context = gtk_rc_context_get (gtk_settings_get_default ());
1847 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1851 gtk_rc_scanner_new (void)
1853 return g_scanner_new (>k_rc_scanner_config);
1857 gtk_rc_parse_any (GtkRcContext *context,
1858 const gchar *input_name,
1860 const gchar *input_string)
1866 scanner = gtk_rc_scanner_new ();
1870 g_assert (input_string == NULL);
1872 g_scanner_input_file (scanner, input_fd);
1876 g_assert (input_string != NULL);
1878 g_scanner_input_text (scanner, input_string, strlen (input_string));
1880 scanner->input_name = input_name;
1882 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1883 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1888 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1892 guint expected_token;
1894 expected_token = gtk_rc_parse_statement (context, scanner);
1896 if (expected_token != G_TOKEN_NONE)
1903 if (scanner->scope_id == 0)
1905 /* if we are in scope 0, we know the symbol names
1906 * that are associated with certain token values.
1907 * so we look them up to make the error messages
1910 if (expected_token > GTK_RC_TOKEN_INVALID &&
1911 expected_token < GTK_RC_TOKEN_LAST)
1913 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1914 if (symbols[i].token == expected_token)
1915 msg = symbols[i].name;
1917 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1919 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1920 scanner->token < GTK_RC_TOKEN_LAST)
1922 symbol_name = "???";
1923 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1924 if (symbols[i].token == scanner->token)
1925 symbol_name = symbols[i].name;
1928 g_scanner_unexp_token (scanner,
1941 g_scanner_destroy (scanner);
1945 gtk_rc_styles_hash (const GSList *rc_styles)
1952 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1953 rc_styles = rc_styles->next;
1960 gtk_rc_styles_equal (const GSList *a,
1965 if (a->data != b->data)
1975 gtk_rc_style_hash (const gchar *name)
1981 result += (result << 3) + *name++;
1987 gtk_rc_style_equal (const gchar *a,
1990 return (strcmp (a, b) == 0);
1994 gtk_rc_style_find (GtkRcContext *context,
1997 if (context->rc_style_ht)
1998 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2004 gtk_rc_style_to_style (GtkRcContext *context,
2005 GtkRcStyle *rc_style)
2009 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2010 _gtk_style_init_for_settings (style, context->settings);
2012 style->rc_style = rc_style;
2014 gtk_rc_style_ref (rc_style);
2016 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2021 /* Reuses or frees rc_styles */
2023 gtk_rc_init_style (GtkRcContext *context,
2026 GtkStyle *style = NULL;
2029 g_return_val_if_fail (rc_styles != NULL, NULL);
2031 if (!realized_style_ht)
2032 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2033 (GEqualFunc) gtk_rc_styles_equal);
2035 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2039 GtkRcStyle *base_style = NULL;
2040 GtkRcStyle *proto_style;
2041 GtkRcStyleClass *proto_style_class;
2043 GType rc_style_type = GTK_TYPE_RC_STYLE;
2045 /* Find the the first style where the RC file specified engine "" {}
2046 * or the first derived style and use that to create the
2047 * merged style. If we only have raw GtkRcStyles, use the first
2048 * style to create the merged style.
2050 base_style = rc_styles->data;
2051 tmp_styles = rc_styles;
2054 GtkRcStyle *rc_style = tmp_styles->data;
2056 if (rc_style->engine_specified ||
2057 G_OBJECT_TYPE (rc_style) != rc_style_type)
2059 base_style = rc_style;
2063 tmp_styles = tmp_styles->next;
2066 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2067 proto_style = proto_style_class->create_rc_style (base_style);
2069 tmp_styles = rc_styles;
2072 GtkRcStyle *rc_style = tmp_styles->data;
2075 proto_style_class->merge (proto_style, rc_style);
2077 /* Point from each rc_style to the list of styles */
2078 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2079 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2081 factories = g_slist_copy (rc_style->icon_factories);
2087 while (iter != NULL)
2089 g_object_ref (G_OBJECT (iter->data));
2090 iter = g_slist_next (iter);
2093 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2098 tmp_styles = tmp_styles->next;
2101 for (i = 0; i < 5; i++)
2102 if (proto_style->bg_pixmap_name[i] &&
2103 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2105 g_free (proto_style->bg_pixmap_name[i]);
2106 proto_style->bg_pixmap_name[i] = NULL;
2109 style = gtk_rc_style_to_style (context, proto_style);
2110 gtk_rc_style_unref (proto_style);
2112 g_hash_table_insert (realized_style_ht, rc_styles, style);
2115 g_slist_free (rc_styles);
2120 /*********************
2121 * Parsing functions *
2122 *********************/
2125 rc_parse_token_or_compound (GScanner *scanner,
2127 GTokenType delimiter)
2129 guint token = g_scanner_get_next_token (scanner);
2131 /* we either scan a single token (skipping comments)
2132 * or a compund statement.
2133 * compunds are enclosed in (), [] or {} braces, we read
2134 * them in via deep recursion.
2141 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2144 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2146 case G_TOKEN_STRING:
2147 string = g_strescape (scanner->value.v_string, NULL);
2148 g_string_append (gstring, " \"");
2149 g_string_append (gstring, string);
2150 g_string_append_c (gstring, '"');
2153 case G_TOKEN_IDENTIFIER:
2154 g_string_append_c (gstring, ' ');
2155 g_string_append (gstring, scanner->value.v_identifier);
2157 case G_TOKEN_COMMENT_SINGLE:
2158 case G_TOKEN_COMMENT_MULTI:
2159 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2160 case G_TOKEN_LEFT_PAREN:
2161 g_string_append_c (gstring, ' ');
2162 g_string_append_c (gstring, token);
2163 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2164 if (token != G_TOKEN_NONE)
2167 case G_TOKEN_LEFT_CURLY:
2168 g_string_append_c (gstring, ' ');
2169 g_string_append_c (gstring, token);
2170 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2171 if (token != G_TOKEN_NONE)
2174 case G_TOKEN_LEFT_BRACE:
2175 g_string_append_c (gstring, ' ');
2176 g_string_append_c (gstring, token);
2177 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2178 if (token != G_TOKEN_NONE)
2182 if (token >= 256 || token < 1)
2183 return delimiter ? delimiter : G_TOKEN_STRING;
2184 g_string_append_c (gstring, ' ');
2185 g_string_append_c (gstring, token);
2186 if (token == delimiter)
2187 return G_TOKEN_NONE;
2191 return G_TOKEN_NONE;
2193 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2197 gtk_rc_parse_assignment (GScanner *scanner,
2198 GtkRcProperty *prop)
2200 gboolean scan_identifier = scanner->config->scan_identifier;
2201 gboolean scan_symbols = scanner->config->scan_symbols;
2202 gboolean identifier_2_string = scanner->config->identifier_2_string;
2203 gboolean char_2_token = scanner->config->char_2_token;
2204 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2205 gboolean numbers_2_int = scanner->config->numbers_2_int;
2206 gboolean negate = FALSE;
2209 /* check that this is an assignment */
2210 if (g_scanner_get_next_token (scanner) != '=')
2213 /* adjust scanner mode */
2214 scanner->config->scan_identifier = TRUE;
2215 scanner->config->scan_symbols = FALSE;
2216 scanner->config->identifier_2_string = FALSE;
2217 scanner->config->char_2_token = TRUE;
2218 scanner->config->scan_identifier_NULL = FALSE;
2219 scanner->config->numbers_2_int = TRUE;
2221 /* record location */
2222 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2224 /* parse optional sign */
2225 if (g_scanner_peek_next_token (scanner) == '-')
2227 g_scanner_get_next_token (scanner); /* eat sign */
2231 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2232 token = g_scanner_peek_next_token (scanner);
2236 g_scanner_get_next_token (scanner);
2237 g_value_init (&prop->value, G_TYPE_LONG);
2238 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2239 token = G_TOKEN_NONE;
2242 g_scanner_get_next_token (scanner);
2243 g_value_init (&prop->value, G_TYPE_DOUBLE);
2244 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2245 token = G_TOKEN_NONE;
2247 case G_TOKEN_STRING:
2248 g_scanner_get_next_token (scanner);
2250 token = G_TOKEN_INT;
2253 g_value_init (&prop->value, G_TYPE_STRING);
2254 g_value_set_string (&prop->value, scanner->value.v_string);
2255 token = G_TOKEN_NONE;
2258 case G_TOKEN_IDENTIFIER:
2259 case G_TOKEN_LEFT_PAREN:
2260 case G_TOKEN_LEFT_CURLY:
2261 case G_TOKEN_LEFT_BRACE:
2264 GString *gstring = g_string_new ("");
2266 token = rc_parse_token_or_compound (scanner, gstring, 0);
2267 if (token == G_TOKEN_NONE)
2269 g_string_append_c (gstring, ' ');
2270 g_value_init (&prop->value, G_TYPE_GSTRING);
2271 g_value_set_static_boxed (&prop->value, gstring);
2274 g_string_free (gstring, TRUE);
2279 g_scanner_get_next_token (scanner);
2280 token = G_TOKEN_INT;
2284 /* restore scanner mode */
2285 scanner->config->scan_identifier = scan_identifier;
2286 scanner->config->scan_symbols = scan_symbols;
2287 scanner->config->identifier_2_string = identifier_2_string;
2288 scanner->config->char_2_token = char_2_token;
2289 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2290 scanner->config->numbers_2_int = numbers_2_int;
2296 is_c_identifier (const gchar *string)
2299 gboolean is_varname;
2301 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2302 for (p = string + 1; *p && is_varname; p++)
2303 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2309 parse_include_file (GtkRcContext *context,
2311 const gchar *filename)
2313 char *to_parse = NULL;
2315 if (g_path_is_absolute (filename))
2317 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2318 * don't print an error in this case.
2320 to_parse = g_strdup (filename);
2324 /* if a relative path, we look relative to all the RC files in the
2325 * include stack. We require the file to be found in this case
2326 * so we can give meaningful error messages, and because on reparsing
2327 * non-absolute paths don't make sense.
2329 GSList *tmp_list = rc_dir_stack;
2332 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2334 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2342 tmp_list = tmp_list->next;
2348 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2353 g_scanner_warn (scanner,
2354 _("Unable to find include file: \"%s\""),
2361 gtk_rc_parse_statement (GtkRcContext *context,
2366 token = g_scanner_peek_next_token (scanner);
2369 case GTK_RC_TOKEN_INCLUDE:
2370 token = g_scanner_get_next_token (scanner);
2371 if (token != GTK_RC_TOKEN_INCLUDE)
2372 return GTK_RC_TOKEN_INCLUDE;
2373 token = g_scanner_get_next_token (scanner);
2374 if (token != G_TOKEN_STRING)
2375 return G_TOKEN_STRING;
2376 parse_include_file (context, scanner, scanner->value.v_string);
2377 return G_TOKEN_NONE;
2379 case GTK_RC_TOKEN_STYLE:
2380 return gtk_rc_parse_style (context, scanner);
2382 case GTK_RC_TOKEN_BINDING:
2383 return gtk_binding_parse_binding (scanner);
2385 case GTK_RC_TOKEN_PIXMAP_PATH:
2386 return gtk_rc_parse_pixmap_path (context, scanner);
2388 case GTK_RC_TOKEN_WIDGET:
2389 return gtk_rc_parse_path_pattern (context, scanner);
2391 case GTK_RC_TOKEN_WIDGET_CLASS:
2392 return gtk_rc_parse_path_pattern (context, scanner);
2394 case GTK_RC_TOKEN_CLASS:
2395 return gtk_rc_parse_path_pattern (context, scanner);
2397 case GTK_RC_TOKEN_MODULE_PATH:
2398 return gtk_rc_parse_module_path (scanner);
2400 case GTK_RC_TOKEN_IM_MODULE_FILE:
2401 return gtk_rc_parse_im_module_file (scanner);
2403 case G_TOKEN_IDENTIFIER:
2404 if (is_c_identifier (scanner->next_value.v_identifier))
2406 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2409 g_scanner_get_next_token (scanner); /* eat identifier */
2410 name = g_strdup (scanner->value.v_identifier);
2412 token = gtk_rc_parse_assignment (scanner, &prop);
2413 if (token == G_TOKEN_NONE)
2415 GtkSettingsValue svalue;
2417 svalue.origin = prop.origin;
2418 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2419 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2420 _gtk_settings_set_property_value_from_rc (context->settings,
2424 g_free (prop.origin);
2425 if (G_VALUE_TYPE (&prop.value))
2426 g_value_unset (&prop.value);
2433 g_scanner_get_next_token (scanner);
2434 return G_TOKEN_IDENTIFIER;
2437 g_scanner_get_next_token (scanner);
2438 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2443 fixup_rc_set (GSList *list,
2449 GtkRcSet *set = list->data;
2450 if (set->rc_style == orig)
2451 set->rc_style = new;
2457 fixup_rc_sets (GtkRcContext *context,
2461 fixup_rc_set (context->rc_sets_widget, orig, new);
2462 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2463 fixup_rc_set (context->rc_sets_class, orig, new);
2467 gtk_rc_parse_style (GtkRcContext *context,
2470 GtkRcStyle *rc_style;
2471 GtkRcStyle *orig_style;
2472 GtkRcStyle *parent_style;
2475 GtkIconFactory *our_factory = NULL;
2477 token = g_scanner_get_next_token (scanner);
2478 if (token != GTK_RC_TOKEN_STYLE)
2479 return GTK_RC_TOKEN_STYLE;
2481 token = g_scanner_get_next_token (scanner);
2482 if (token != G_TOKEN_STRING)
2483 return G_TOKEN_STRING;
2485 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2487 orig_style = g_object_ref (rc_style);
2491 /* If there's a list, its first member is always the factory belonging
2494 if (rc_style && rc_style->icon_factories)
2495 our_factory = rc_style->icon_factories->data;
2499 rc_style = gtk_rc_style_new ();
2500 rc_style->name = g_strdup (scanner->value.v_string);
2502 for (i = 0; i < 5; i++)
2503 rc_style->bg_pixmap_name[i] = NULL;
2505 for (i = 0; i < 5; i++)
2506 rc_style->color_flags[i] = 0;
2509 token = g_scanner_peek_next_token (scanner);
2510 if (token == G_TOKEN_EQUAL_SIGN)
2512 token = g_scanner_get_next_token (scanner);
2514 token = g_scanner_get_next_token (scanner);
2515 if (token != G_TOKEN_STRING)
2517 token = G_TOKEN_STRING;
2521 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2526 for (i = 0; i < 5; i++)
2528 rc_style->color_flags[i] = parent_style->color_flags[i];
2529 rc_style->fg[i] = parent_style->fg[i];
2530 rc_style->bg[i] = parent_style->bg[i];
2531 rc_style->text[i] = parent_style->text[i];
2532 rc_style->base[i] = parent_style->base[i];
2535 rc_style->xthickness = parent_style->xthickness;
2536 rc_style->ythickness = parent_style->ythickness;
2538 if (parent_style->font_desc)
2540 if (rc_style->font_desc)
2541 pango_font_description_free (rc_style->font_desc);
2542 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2545 if (parent_style->rc_properties)
2549 for (i = 0; i < parent_style->rc_properties->len; i++)
2550 insert_rc_property (rc_style,
2551 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2555 for (i = 0; i < 5; i++)
2557 if (rc_style->bg_pixmap_name[i])
2558 g_free (rc_style->bg_pixmap_name[i]);
2559 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2562 /* Append parent's factories, adding a ref to them */
2563 if (parent_style->icon_factories != NULL)
2565 /* Add a factory for ourselves if we have none,
2566 * in case we end up defining more stock icons.
2567 * I see no real way around this; we need to maintain
2568 * the invariant that the first factory in the list
2569 * is always our_factory, the one belonging to us,
2570 * and if we put parent factories in the list we can't
2571 * do that if the style is reopened.
2573 if (our_factory == NULL)
2575 our_factory = gtk_icon_factory_new ();
2576 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2580 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2581 g_slist_copy (parent_style->icon_factories));
2583 factories = parent_style->icon_factories;
2584 while (factories != NULL)
2586 g_object_ref (G_OBJECT (factories->data));
2587 factories = factories->next;
2593 token = g_scanner_get_next_token (scanner);
2594 if (token != G_TOKEN_LEFT_CURLY)
2596 token = G_TOKEN_LEFT_CURLY;
2600 token = g_scanner_peek_next_token (scanner);
2601 while (token != G_TOKEN_RIGHT_CURLY)
2605 case GTK_RC_TOKEN_BG:
2606 token = gtk_rc_parse_bg (scanner, rc_style);
2608 case GTK_RC_TOKEN_FG:
2609 token = gtk_rc_parse_fg (scanner, rc_style);
2611 case GTK_RC_TOKEN_TEXT:
2612 token = gtk_rc_parse_text (scanner, rc_style);
2614 case GTK_RC_TOKEN_BASE:
2615 token = gtk_rc_parse_base (scanner, rc_style);
2617 case GTK_RC_TOKEN_XTHICKNESS:
2618 token = gtk_rc_parse_xthickness (scanner, rc_style);
2620 case GTK_RC_TOKEN_YTHICKNESS:
2621 token = gtk_rc_parse_ythickness (scanner, rc_style);
2623 case GTK_RC_TOKEN_BG_PIXMAP:
2624 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2626 case GTK_RC_TOKEN_FONT:
2627 token = gtk_rc_parse_font (scanner, rc_style);
2629 case GTK_RC_TOKEN_FONTSET:
2630 token = gtk_rc_parse_fontset (scanner, rc_style);
2632 case GTK_RC_TOKEN_FONT_NAME:
2633 token = gtk_rc_parse_font_name (scanner, rc_style);
2635 case GTK_RC_TOKEN_ENGINE:
2636 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2638 case GTK_RC_TOKEN_STOCK:
2639 if (our_factory == NULL)
2641 our_factory = gtk_icon_factory_new ();
2642 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2645 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2647 case G_TOKEN_IDENTIFIER:
2648 if (is_c_identifier (scanner->next_value.v_identifier) &&
2649 scanner->next_value.v_identifier[0] >= 'A' &&
2650 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2652 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2654 g_scanner_get_next_token (scanner); /* eat type name */
2655 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2656 if (g_scanner_get_next_token (scanner) != ':' ||
2657 g_scanner_get_next_token (scanner) != ':')
2662 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2663 !is_c_identifier (scanner->value.v_identifier))
2665 token = G_TOKEN_IDENTIFIER;
2669 /* it's important that we do the same canonification as GParamSpecPool here */
2670 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2671 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2673 token = gtk_rc_parse_assignment (scanner, &prop);
2674 if (token == G_TOKEN_NONE)
2676 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2677 insert_rc_property (rc_style, &prop, TRUE);
2680 g_free (prop.origin);
2681 if (G_VALUE_TYPE (&prop.value))
2682 g_value_unset (&prop.value);
2686 g_scanner_get_next_token (scanner);
2687 token = G_TOKEN_IDENTIFIER;
2691 g_scanner_get_next_token (scanner);
2692 token = G_TOKEN_RIGHT_CURLY;
2696 if (token != G_TOKEN_NONE)
2699 token = g_scanner_peek_next_token (scanner);
2700 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2702 token = g_scanner_get_next_token (scanner);
2703 if (token != G_TOKEN_RIGHT_CURLY)
2705 token = G_TOKEN_RIGHT_CURLY;
2709 if (rc_style != orig_style)
2711 if (!context->rc_style_ht)
2712 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2713 (GEqualFunc) gtk_rc_style_equal);
2715 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2717 /* If we copied the data into a new rc style, fix up references to the old rc style
2718 * in bindings that we have.
2721 fixup_rc_sets (context, orig_style, rc_style);
2725 g_object_unref (orig_style);
2727 return G_TOKEN_NONE;
2730 if (rc_style != orig_style)
2731 gtk_rc_style_unref (rc_style);
2734 g_object_unref (orig_style);
2739 const GtkRcProperty*
2740 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2742 GQuark property_name)
2744 GtkRcProperty *node = NULL;
2746 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2748 if (rc_style->rc_properties)
2752 key.type_name = type_name;
2753 key.property_name = property_name;
2755 node = bsearch (&key,
2756 rc_style->rc_properties->data, rc_style->rc_properties->len,
2757 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2764 gtk_rc_parse_bg (GScanner *scanner,
2770 token = g_scanner_get_next_token (scanner);
2771 if (token != GTK_RC_TOKEN_BG)
2772 return GTK_RC_TOKEN_BG;
2774 token = gtk_rc_parse_state (scanner, &state);
2775 if (token != G_TOKEN_NONE)
2778 token = g_scanner_get_next_token (scanner);
2779 if (token != G_TOKEN_EQUAL_SIGN)
2780 return G_TOKEN_EQUAL_SIGN;
2782 style->color_flags[state] |= GTK_RC_BG;
2783 return gtk_rc_parse_color (scanner, &style->bg[state]);
2787 gtk_rc_parse_fg (GScanner *scanner,
2793 token = g_scanner_get_next_token (scanner);
2794 if (token != GTK_RC_TOKEN_FG)
2795 return GTK_RC_TOKEN_FG;
2797 token = gtk_rc_parse_state (scanner, &state);
2798 if (token != G_TOKEN_NONE)
2801 token = g_scanner_get_next_token (scanner);
2802 if (token != G_TOKEN_EQUAL_SIGN)
2803 return G_TOKEN_EQUAL_SIGN;
2805 style->color_flags[state] |= GTK_RC_FG;
2806 return gtk_rc_parse_color (scanner, &style->fg[state]);
2810 gtk_rc_parse_text (GScanner *scanner,
2816 token = g_scanner_get_next_token (scanner);
2817 if (token != GTK_RC_TOKEN_TEXT)
2818 return GTK_RC_TOKEN_TEXT;
2820 token = gtk_rc_parse_state (scanner, &state);
2821 if (token != G_TOKEN_NONE)
2824 token = g_scanner_get_next_token (scanner);
2825 if (token != G_TOKEN_EQUAL_SIGN)
2826 return G_TOKEN_EQUAL_SIGN;
2828 style->color_flags[state] |= GTK_RC_TEXT;
2829 return gtk_rc_parse_color (scanner, &style->text[state]);
2833 gtk_rc_parse_base (GScanner *scanner,
2839 token = g_scanner_get_next_token (scanner);
2840 if (token != GTK_RC_TOKEN_BASE)
2841 return GTK_RC_TOKEN_BASE;
2843 token = gtk_rc_parse_state (scanner, &state);
2844 if (token != G_TOKEN_NONE)
2847 token = g_scanner_get_next_token (scanner);
2848 if (token != G_TOKEN_EQUAL_SIGN)
2849 return G_TOKEN_EQUAL_SIGN;
2851 style->color_flags[state] |= GTK_RC_BASE;
2852 return gtk_rc_parse_color (scanner, &style->base[state]);
2856 gtk_rc_parse_xthickness (GScanner *scanner,
2859 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2860 return GTK_RC_TOKEN_XTHICKNESS;
2862 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2863 return G_TOKEN_EQUAL_SIGN;
2865 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2868 style->xthickness = scanner->value.v_int;
2870 return G_TOKEN_NONE;
2874 gtk_rc_parse_ythickness (GScanner *scanner,
2877 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2878 return GTK_RC_TOKEN_YTHICKNESS;
2880 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2881 return G_TOKEN_EQUAL_SIGN;
2883 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2886 style->ythickness = scanner->value.v_int;
2888 return G_TOKEN_NONE;
2892 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2894 GtkRcStyle *rc_style)
2900 token = g_scanner_get_next_token (scanner);
2901 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2902 return GTK_RC_TOKEN_BG_PIXMAP;
2904 token = gtk_rc_parse_state (scanner, &state);
2905 if (token != G_TOKEN_NONE)
2908 token = g_scanner_get_next_token (scanner);
2909 if (token != G_TOKEN_EQUAL_SIGN)
2910 return G_TOKEN_EQUAL_SIGN;
2912 token = g_scanner_get_next_token (scanner);
2913 if (token != G_TOKEN_STRING)
2914 return G_TOKEN_STRING;
2916 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2917 (strcmp (scanner->value.v_string, "<none>") == 0))
2918 pixmap_file = g_strdup (scanner->value.v_string);
2920 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2921 scanner, scanner->value.v_string);
2925 if (rc_style->bg_pixmap_name[state])
2926 g_free (rc_style->bg_pixmap_name[state]);
2927 rc_style->bg_pixmap_name[state] = pixmap_file;
2930 return G_TOKEN_NONE;
2934 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2939 buf = g_build_filename (dir, pixmap_file, NULL);
2941 fd = open (buf, O_RDONLY);
2954 * gtk_rc_find_pixmap_in_path:
2955 * @settings: a #GtkSettings
2956 * @scanner: Scanner used to get line number information for the
2957 * warning message, or %NULL
2958 * @pixmap_file: name of the pixmap file to locate.
2960 * Looks up a file in pixmap path for the specified #GtkSettings.
2961 * If the file is not found, it outputs a warning message using
2962 * g_warning() and returns %NULL.
2964 * Return value: the filename.
2967 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2969 const gchar *pixmap_file)
2975 GtkRcContext *context = gtk_rc_context_get (settings);
2977 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
2979 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
2984 tmp_list = rc_dir_stack;
2987 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2991 tmp_list = tmp_list->next;
2995 g_scanner_warn (scanner,
2996 _("Unable to locate image file in pixmap_path: \"%s\""),
2999 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3006 * gtk_rc_find_module_in_path:
3007 * @module_file: name of a theme engine
3009 * Searches for a theme engine in the GTK+ search path. This function
3010 * is not useful for applications and should not be used.
3012 * Return value: The filename, if found (must be freed with g_free()),
3016 gtk_rc_find_module_in_path (const gchar *module_file)
3018 return _gtk_find_module (module_file, "engines");
3022 gtk_rc_parse_font (GScanner *scanner,
3023 GtkRcStyle *rc_style)
3027 token = g_scanner_get_next_token (scanner);
3028 if (token != GTK_RC_TOKEN_FONT)
3029 return GTK_RC_TOKEN_FONT;
3031 token = g_scanner_get_next_token (scanner);
3032 if (token != G_TOKEN_EQUAL_SIGN)
3033 return G_TOKEN_EQUAL_SIGN;
3035 token = g_scanner_get_next_token (scanner);
3036 if (token != G_TOKEN_STRING)
3037 return G_TOKEN_STRING;
3039 /* Ignore, do nothing */
3041 return G_TOKEN_NONE;
3045 gtk_rc_parse_fontset (GScanner *scanner,
3046 GtkRcStyle *rc_style)
3050 token = g_scanner_get_next_token (scanner);
3051 if (token != GTK_RC_TOKEN_FONTSET)
3052 return GTK_RC_TOKEN_FONTSET;
3054 token = g_scanner_get_next_token (scanner);
3055 if (token != G_TOKEN_EQUAL_SIGN)
3056 return G_TOKEN_EQUAL_SIGN;
3058 token = g_scanner_get_next_token (scanner);
3059 if (token != G_TOKEN_STRING)
3060 return G_TOKEN_STRING;
3062 /* Do nothing - silently ignore */
3064 return G_TOKEN_NONE;
3068 gtk_rc_parse_font_name (GScanner *scanner,
3069 GtkRcStyle *rc_style)
3073 token = g_scanner_get_next_token (scanner);
3074 if (token != GTK_RC_TOKEN_FONT_NAME)
3075 return GTK_RC_TOKEN_FONT;
3077 token = g_scanner_get_next_token (scanner);
3078 if (token != G_TOKEN_EQUAL_SIGN)
3079 return G_TOKEN_EQUAL_SIGN;
3081 token = g_scanner_get_next_token (scanner);
3082 if (token != G_TOKEN_STRING)
3083 return G_TOKEN_STRING;
3085 if (rc_style->font_desc)
3086 pango_font_description_free (rc_style->font_desc);
3088 rc_style->font_desc =
3089 pango_font_description_from_string (scanner->value.v_string);
3091 return G_TOKEN_NONE;
3095 gtk_rc_parse_engine (GtkRcContext *context,
3097 GtkRcStyle **rc_style)
3100 GtkThemeEngine *engine;
3101 guint result = G_TOKEN_NONE;
3102 GtkRcStyle *new_style = NULL;
3103 gboolean parsed_curlies = FALSE;
3105 token = g_scanner_get_next_token (scanner);
3106 if (token != GTK_RC_TOKEN_ENGINE)
3107 return GTK_RC_TOKEN_ENGINE;
3109 token = g_scanner_get_next_token (scanner);
3110 if (token != G_TOKEN_STRING)
3111 return G_TOKEN_STRING;
3113 if (!scanner->value.v_string[0])
3115 /* Support engine "" {} to mean override to the default engine
3117 token = g_scanner_get_next_token (scanner);
3118 if (token != G_TOKEN_LEFT_CURLY)
3119 return G_TOKEN_LEFT_CURLY;
3121 token = g_scanner_get_next_token (scanner);
3122 if (token != G_TOKEN_RIGHT_CURLY)
3123 return G_TOKEN_RIGHT_CURLY;
3125 parsed_curlies = TRUE;
3127 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3129 new_style = gtk_rc_style_new ();
3130 gtk_rc_style_real_merge (new_style, *rc_style);
3132 if ((*rc_style)->name)
3133 new_style->name = g_strdup ((*rc_style)->name);
3136 (*rc_style)->engine_specified = TRUE;
3140 engine = gtk_theme_engine_get (scanner->value.v_string);
3142 token = g_scanner_get_next_token (scanner);
3143 if (token != G_TOKEN_LEFT_CURLY)
3144 return G_TOKEN_LEFT_CURLY;
3148 GtkRcStyleClass *new_class;
3150 new_style = gtk_theme_engine_create_rc_style (engine);
3151 g_type_module_unuse (G_TYPE_MODULE (engine));
3153 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3155 new_class->merge (new_style, *rc_style);
3156 if ((*rc_style)->name)
3157 new_style->name = g_strdup ((*rc_style)->name);
3159 if (new_class->parse)
3161 parsed_curlies = TRUE;
3162 result = new_class->parse (new_style, context->settings, scanner);
3164 if (result != G_TOKEN_NONE)
3166 g_object_unref (G_OBJECT (new_style));
3173 if (!parsed_curlies)
3175 /* Skip over remainder, looking for nested {}'s
3179 result = G_TOKEN_RIGHT_CURLY;
3180 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3182 if (token == G_TOKEN_LEFT_CURLY)
3184 else if (token == G_TOKEN_RIGHT_CURLY)
3189 result = G_TOKEN_NONE;
3197 new_style->engine_specified = TRUE;
3199 g_object_unref (G_OBJECT (*rc_style));
3200 *rc_style = new_style;
3207 gtk_rc_parse_state (GScanner *scanner,
3208 GtkStateType *state)
3213 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3214 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3216 /* we don't know where we got called from, so we reset the scope here.
3217 * if we bail out due to errors, we *don't* reset the scope, so the
3218 * error messaging code can make sense of our tokens.
3220 old_scope = g_scanner_set_scope (scanner, 0);
3222 token = g_scanner_get_next_token (scanner);
3223 if (token != G_TOKEN_LEFT_BRACE)
3224 return G_TOKEN_LEFT_BRACE;
3226 token = g_scanner_get_next_token (scanner);
3229 case GTK_RC_TOKEN_ACTIVE:
3230 *state = GTK_STATE_ACTIVE;
3232 case GTK_RC_TOKEN_INSENSITIVE:
3233 *state = GTK_STATE_INSENSITIVE;
3235 case GTK_RC_TOKEN_NORMAL:
3236 *state = GTK_STATE_NORMAL;
3238 case GTK_RC_TOKEN_PRELIGHT:
3239 *state = GTK_STATE_PRELIGHT;
3241 case GTK_RC_TOKEN_SELECTED:
3242 *state = GTK_STATE_SELECTED;
3245 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3248 token = g_scanner_get_next_token (scanner);
3249 if (token != G_TOKEN_RIGHT_BRACE)
3250 return G_TOKEN_RIGHT_BRACE;
3252 g_scanner_set_scope (scanner, old_scope);
3254 return G_TOKEN_NONE;
3258 gtk_rc_parse_priority (GScanner *scanner,
3259 GtkPathPriorityType *priority)
3264 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3265 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3267 /* we don't know where we got called from, so we reset the scope here.
3268 * if we bail out due to errors, we *don't* reset the scope, so the
3269 * error messaging code can make sense of our tokens.
3271 old_scope = g_scanner_set_scope (scanner, 0);
3273 token = g_scanner_get_next_token (scanner);
3277 token = g_scanner_get_next_token (scanner);
3280 case GTK_RC_TOKEN_LOWEST:
3281 *priority = GTK_PATH_PRIO_LOWEST;
3283 case GTK_RC_TOKEN_GTK:
3284 *priority = GTK_PATH_PRIO_GTK;
3286 case GTK_RC_TOKEN_APPLICATION:
3287 *priority = GTK_PATH_PRIO_APPLICATION;
3289 case GTK_RC_TOKEN_THEME:
3290 *priority = GTK_PATH_PRIO_THEME;
3292 case GTK_RC_TOKEN_RC:
3293 *priority = GTK_PATH_PRIO_RC;
3295 case GTK_RC_TOKEN_HIGHEST:
3296 *priority = GTK_PATH_PRIO_HIGHEST;
3299 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3302 g_scanner_set_scope (scanner, old_scope);
3304 return G_TOKEN_NONE;
3308 gtk_rc_parse_color (GScanner *scanner,
3313 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3315 /* we don't need to set our own scope here, because
3316 * we don't need own symbols
3319 token = g_scanner_get_next_token (scanner);
3324 case G_TOKEN_LEFT_CURLY:
3325 token = g_scanner_get_next_token (scanner);
3326 if (token == G_TOKEN_INT)
3327 token_int = scanner->value.v_int;
3328 else if (token == G_TOKEN_FLOAT)
3329 token_int = scanner->value.v_float * 65535.0;
3331 return G_TOKEN_FLOAT;
3332 color->red = CLAMP (token_int, 0, 65535);
3334 token = g_scanner_get_next_token (scanner);
3335 if (token != G_TOKEN_COMMA)
3336 return G_TOKEN_COMMA;
3338 token = g_scanner_get_next_token (scanner);
3339 if (token == G_TOKEN_INT)
3340 token_int = scanner->value.v_int;
3341 else if (token == G_TOKEN_FLOAT)
3342 token_int = scanner->value.v_float * 65535.0;
3344 return G_TOKEN_FLOAT;
3345 color->green = CLAMP (token_int, 0, 65535);
3347 token = g_scanner_get_next_token (scanner);
3348 if (token != G_TOKEN_COMMA)
3349 return G_TOKEN_COMMA;
3351 token = g_scanner_get_next_token (scanner);
3352 if (token == G_TOKEN_INT)
3353 token_int = scanner->value.v_int;
3354 else if (token == G_TOKEN_FLOAT)
3355 token_int = scanner->value.v_float * 65535.0;
3357 return G_TOKEN_FLOAT;
3358 color->blue = CLAMP (token_int, 0, 65535);
3360 token = g_scanner_get_next_token (scanner);
3361 if (token != G_TOKEN_RIGHT_CURLY)
3362 return G_TOKEN_RIGHT_CURLY;
3363 return G_TOKEN_NONE;
3365 case G_TOKEN_STRING:
3366 if (!gdk_color_parse (scanner->value.v_string, color))
3368 g_scanner_warn (scanner, "Invalid color constant '%s'",
3369 scanner->value.v_string);
3370 return G_TOKEN_STRING;
3373 return G_TOKEN_NONE;
3376 return G_TOKEN_STRING;
3381 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3386 token = g_scanner_get_next_token (scanner);
3387 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3388 return GTK_RC_TOKEN_PIXMAP_PATH;
3390 token = g_scanner_get_next_token (scanner);
3391 if (token != G_TOKEN_STRING)
3392 return G_TOKEN_STRING;
3394 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3396 return G_TOKEN_NONE;
3400 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3402 const gchar *pix_path)
3405 gint start_offset = 0;
3409 /* free the old one, or just add to the old one ? */
3410 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3412 g_free (context->pixmap_path[path_num]);
3413 context->pixmap_path[path_num] = NULL;
3418 path_len = strlen (pix_path);
3420 for (end_offset = 0; end_offset <= path_len; end_offset++)
3422 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3423 (end_offset == path_len))
3425 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3426 if (g_path_is_absolute (path_element))
3428 context->pixmap_path[path_num] = path_element;
3430 context->pixmap_path[path_num] = NULL;
3434 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3435 path_element, scanner->input_name, scanner->line);
3436 g_free (path_element);
3439 start_offset = end_offset + 1;
3445 gtk_rc_parse_module_path (GScanner *scanner)
3449 token = g_scanner_get_next_token (scanner);
3450 if (token != GTK_RC_TOKEN_MODULE_PATH)
3451 return GTK_RC_TOKEN_MODULE_PATH;
3453 token = g_scanner_get_next_token (scanner);
3454 if (token != G_TOKEN_STRING)
3455 return G_TOKEN_STRING;
3457 g_warning ("module_path directive is now ignored\n");
3459 return G_TOKEN_NONE;
3463 gtk_rc_parse_im_module_file (GScanner *scanner)
3467 token = g_scanner_get_next_token (scanner);
3468 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3469 return GTK_RC_TOKEN_IM_MODULE_FILE;
3471 token = g_scanner_get_next_token (scanner);
3472 if (token != G_TOKEN_STRING)
3473 return G_TOKEN_STRING;
3476 g_free (im_module_file);
3478 im_module_file = g_strdup (scanner->value.v_string);
3480 return G_TOKEN_NONE;
3484 gtk_rc_parse_path_pattern (GtkRcContext *context,
3488 GtkPathType path_type;
3490 gboolean is_binding;
3491 GtkPathPriorityType priority = context->default_priority;
3493 token = g_scanner_get_next_token (scanner);
3496 case GTK_RC_TOKEN_WIDGET:
3497 path_type = GTK_PATH_WIDGET;
3499 case GTK_RC_TOKEN_WIDGET_CLASS:
3500 path_type = GTK_PATH_WIDGET_CLASS;
3502 case GTK_RC_TOKEN_CLASS:
3503 path_type = GTK_PATH_CLASS;
3506 return GTK_RC_TOKEN_WIDGET_CLASS;
3509 token = g_scanner_get_next_token (scanner);
3510 if (token != G_TOKEN_STRING)
3511 return G_TOKEN_STRING;
3513 pattern = g_strdup (scanner->value.v_string);
3515 token = g_scanner_get_next_token (scanner);
3516 if (token == GTK_RC_TOKEN_STYLE)
3518 else if (token == GTK_RC_TOKEN_BINDING)
3523 return GTK_RC_TOKEN_STYLE;
3526 if (g_scanner_peek_next_token (scanner) == ':')
3528 token = gtk_rc_parse_priority (scanner, &priority);
3529 if (token != G_TOKEN_NONE)
3536 token = g_scanner_get_next_token (scanner);
3537 if (token != G_TOKEN_STRING)
3540 return G_TOKEN_STRING;
3545 GtkBindingSet *binding;
3547 binding = gtk_binding_set_find (scanner->value.v_string);
3551 return G_TOKEN_STRING;
3553 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3557 GtkRcStyle *rc_style;
3560 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3565 return G_TOKEN_STRING;
3568 rc_set = g_new (GtkRcSet, 1);
3569 rc_set->pspec = g_pattern_spec_new (pattern);
3570 rc_set->rc_style = rc_style;
3571 rc_set->priority = priority;
3573 if (path_type == GTK_PATH_WIDGET)
3574 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3575 else if (path_type == GTK_PATH_WIDGET_CLASS)
3576 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3578 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3582 return G_TOKEN_NONE;
3586 gtk_rc_parse_stock_id (GScanner *scanner,
3591 token = g_scanner_get_next_token (scanner);
3592 if (token != G_TOKEN_LEFT_BRACE)
3593 return G_TOKEN_LEFT_BRACE;
3595 token = g_scanner_get_next_token (scanner);
3597 if (token != G_TOKEN_STRING)
3598 return G_TOKEN_STRING;
3600 *stock_id = g_strdup (scanner->value.v_string);
3602 token = g_scanner_get_next_token (scanner);
3603 if (token != G_TOKEN_RIGHT_BRACE)
3606 return G_TOKEN_RIGHT_BRACE;
3609 return G_TOKEN_NONE;
3613 gtk_rc_parse_icon_source (GtkRcContext *context,
3615 GtkIconSet *icon_set,
3616 gboolean *icon_set_valid)
3619 GtkIconSource *source;
3620 gchar *full_filename;
3622 token = g_scanner_get_next_token (scanner);
3623 if (token != G_TOKEN_LEFT_CURLY)
3624 return G_TOKEN_LEFT_CURLY;
3626 token = g_scanner_get_next_token (scanner);
3628 if (token != G_TOKEN_STRING)
3629 return G_TOKEN_STRING;
3632 source = gtk_icon_source_new ();
3634 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3637 gtk_icon_source_set_filename (source, full_filename);
3638 g_free (full_filename);
3641 /* We continue parsing even if we didn't find the pixmap so that rest of the
3642 * file is read, even if the syntax is bad. However we don't validate the
3643 * icon_set so the caller can choose not to install it.
3645 token = g_scanner_get_next_token (scanner);
3647 if (token == G_TOKEN_RIGHT_CURLY)
3649 else if (token != G_TOKEN_COMMA)
3651 gtk_icon_source_free (source);
3652 return G_TOKEN_COMMA;
3655 /* Get the direction */
3657 token = g_scanner_get_next_token (scanner);
3661 case GTK_RC_TOKEN_RTL:
3662 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3663 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3666 case GTK_RC_TOKEN_LTR:
3667 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3668 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3675 gtk_icon_source_free (source);
3676 return GTK_RC_TOKEN_RTL;
3680 token = g_scanner_get_next_token (scanner);
3682 if (token == G_TOKEN_RIGHT_CURLY)
3684 else if (token != G_TOKEN_COMMA)
3686 gtk_icon_source_free (source);
3687 return G_TOKEN_COMMA;
3692 token = g_scanner_get_next_token (scanner);
3696 case GTK_RC_TOKEN_NORMAL:
3697 gtk_icon_source_set_state_wildcarded (source, FALSE);
3698 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3701 case GTK_RC_TOKEN_PRELIGHT:
3702 gtk_icon_source_set_state_wildcarded (source, FALSE);
3703 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3707 case GTK_RC_TOKEN_INSENSITIVE:
3708 gtk_icon_source_set_state_wildcarded (source, FALSE);
3709 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3712 case GTK_RC_TOKEN_ACTIVE:
3713 gtk_icon_source_set_state_wildcarded (source, FALSE);
3714 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3717 case GTK_RC_TOKEN_SELECTED:
3718 gtk_icon_source_set_state_wildcarded (source, FALSE);
3719 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3726 gtk_icon_source_free (source);
3727 return GTK_RC_TOKEN_PRELIGHT;
3731 token = g_scanner_get_next_token (scanner);
3733 if (token == G_TOKEN_RIGHT_CURLY)
3735 else if (token != G_TOKEN_COMMA)
3737 gtk_icon_source_free (source);
3738 return G_TOKEN_COMMA;
3743 token = g_scanner_get_next_token (scanner);
3749 if (token != G_TOKEN_STRING)
3751 gtk_icon_source_free (source);
3752 return G_TOKEN_STRING;
3755 size = gtk_icon_size_from_name (scanner->value.v_string);
3757 if (size != GTK_ICON_SIZE_INVALID)
3759 gtk_icon_source_set_size_wildcarded (source, FALSE);
3760 gtk_icon_source_set_size (source, size);
3764 /* Check the close brace */
3766 token = g_scanner_get_next_token (scanner);
3767 if (token != G_TOKEN_RIGHT_CURLY)
3769 gtk_icon_source_free (source);
3770 return G_TOKEN_RIGHT_CURLY;
3774 if (gtk_icon_source_get_filename (source))
3776 gtk_icon_set_add_source (icon_set, source);
3777 *icon_set_valid = TRUE;
3779 gtk_icon_source_free (source);
3781 return G_TOKEN_NONE;
3785 gtk_rc_parse_stock (GtkRcContext *context,
3787 GtkRcStyle *rc_style,
3788 GtkIconFactory *factory)
3790 GtkIconSet *icon_set = NULL;
3791 gboolean icon_set_valid = FALSE;
3792 gchar *stock_id = NULL;
3795 token = g_scanner_get_next_token (scanner);
3796 if (token != GTK_RC_TOKEN_STOCK)
3797 return GTK_RC_TOKEN_STOCK;
3799 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3800 if (token != G_TOKEN_NONE)
3803 token = g_scanner_get_next_token (scanner);
3804 if (token != G_TOKEN_EQUAL_SIGN)
3807 return G_TOKEN_EQUAL_SIGN;
3810 token = g_scanner_get_next_token (scanner);
3811 if (token != G_TOKEN_LEFT_CURLY)
3814 return G_TOKEN_LEFT_CURLY;
3817 token = g_scanner_peek_next_token (scanner);
3818 while (token != G_TOKEN_RIGHT_CURLY)
3820 if (icon_set == NULL)
3821 icon_set = gtk_icon_set_new ();
3823 token = gtk_rc_parse_icon_source (context,
3824 scanner, icon_set, &icon_set_valid);
3825 if (token != G_TOKEN_NONE)
3828 gtk_icon_set_unref (icon_set);
3832 token = g_scanner_get_next_token (scanner);
3834 if (token != G_TOKEN_COMMA &&
3835 token != G_TOKEN_RIGHT_CURLY)
3838 gtk_icon_set_unref (icon_set);
3839 return G_TOKEN_RIGHT_CURLY;
3846 gtk_icon_factory_add (factory,
3850 gtk_icon_set_unref (icon_set);
3855 return G_TOKEN_NONE;