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] = \"#eee1b3\"\n"
665 " fg[NORMAL] = \"#000000\"\n"
668 "style \"gtk-default-progress-bar-style\" {\n"
669 " bg[PRELIGHT] = \"#4b6983\"\n"
670 " fg[PRELIGHT] = \"#ffffff\"\n"
671 " bg[NORMAL] = \"#bab5ab\"\n"
674 "style \"gtk-default-menu-item-style\" {\n"
675 " bg[PRELIGHT] = \"#4b6983\"\n"
676 " fg[PRELIGHT] = \"#ffffff\"\n"
677 " base[PRELIGHT] = \"#4b6983\"\n"
678 " text[PRELIGHT] = \"#ffffff\"\n"
681 "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
682 "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"
683 "class \"GtkMenuItem\" style : gtk \"gtk-default-menu-item-style\"\n"
684 "widget_class \"*.GtkMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
685 "widget_class \"*.GtkAccelMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
686 "widget_class \"*.GtkRadioMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
687 "widget_class \"*.GtkCheckMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
688 "widget_class \"*.GtkImageMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
689 "widget_class \"*.GtkSeparatorMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
694 gtk_rc_context_parse_string (GtkRcContext *context,
695 const gchar *rc_string)
697 gtk_rc_parse_any (context, "-", -1, rc_string);
701 gtk_rc_parse_string (const gchar *rc_string)
706 g_return_if_fail (rc_string != NULL);
708 rc_file = g_new (GtkRcFile, 1);
709 rc_file->is_string = TRUE;
710 rc_file->name = g_strdup (rc_string);
711 rc_file->canonical_name = NULL;
713 rc_file->reload = TRUE;
715 global_rc_files = g_slist_append (global_rc_files, rc_file);
717 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
718 gtk_rc_context_parse_string (tmp_list->data, rc_string);
722 add_to_rc_file_list (GSList **rc_file_list,
723 const char *filename,
729 tmp_list = *rc_file_list;
732 rc_file = tmp_list->data;
733 if (!strcmp (rc_file->name, filename))
736 tmp_list = tmp_list->next;
739 rc_file = g_new (GtkRcFile, 1);
740 rc_file->is_string = FALSE;
741 rc_file->name = g_strdup (filename);
742 rc_file->canonical_name = NULL;
744 rc_file->reload = reload;
746 *rc_file_list = g_slist_append (*rc_file_list, rc_file);
752 gtk_rc_context_parse_one_file (GtkRcContext *context,
753 const gchar *filename,
761 g_return_if_fail (filename != NULL);
763 saved_priority = context->default_priority;
764 context->default_priority = priority;
766 rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
768 if (!rc_file->canonical_name)
770 /* Get the absolute pathname */
772 if (g_path_is_absolute (rc_file->name))
773 rc_file->canonical_name = rc_file->name;
778 cwd = g_get_current_dir ();
779 rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
784 if (!lstat (rc_file->canonical_name, &statbuf))
789 rc_file->mtime = statbuf.st_mtime;
791 fd = open (rc_file->canonical_name, O_RDONLY);
795 /* Temporarily push directory name for this file on
796 * a stack of directory names while parsing it
799 g_slist_prepend (rc_dir_stack,
800 g_path_get_dirname (rc_file->canonical_name));
801 gtk_rc_parse_any (context, filename, fd, NULL);
803 tmp_list = rc_dir_stack;
804 rc_dir_stack = rc_dir_stack->next;
806 g_free (tmp_list->data);
807 g_slist_free_1 (tmp_list);
813 context->default_priority = saved_priority;
817 strchr_len (const gchar *str, gint len, char c)
831 gtk_rc_context_parse_file (GtkRcContext *context,
832 const gchar *filename,
836 gchar *locale_suffixes[2];
837 gint n_locale_suffixes = 0;
841 gboolean found = FALSE;
844 locale = g_win32_getlocale ();
846 locale = setlocale (LC_CTYPE, NULL);
849 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
851 /* Determine locale-specific suffixes for RC files.
853 length = strlen (locale);
855 p = strchr (locale, '@');
859 p = strchr_len (locale, length, '.');
863 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
865 p = strchr_len (locale, length, '_');
869 locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
873 gtk_rc_context_parse_one_file (context, filename, priority, reload);
874 for (j = 0; j < n_locale_suffixes; j++)
878 gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
879 if (g_file_test (name, G_FILE_TEST_EXISTS))
881 gtk_rc_context_parse_one_file (context, name, priority, FALSE);
888 g_free (locale_suffixes[j]);
893 gtk_rc_parse (const gchar *filename)
897 g_return_if_fail (filename != NULL);
899 add_to_rc_file_list (&global_rc_files, filename, TRUE);
901 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
902 gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
905 /* Handling of RC styles */
908 gtk_rc_style_get_type (void)
910 static GType rc_style_type = 0;
914 static const GTypeInfo rc_style_info =
916 sizeof (GtkRcStyleClass),
917 (GBaseInitFunc) NULL,
918 (GBaseFinalizeFunc) NULL,
919 (GClassInitFunc) gtk_rc_style_class_init,
920 NULL, /* class_finalize */
921 NULL, /* class_data */
924 (GInstanceInitFunc) gtk_rc_style_init,
927 rc_style_type = g_type_register_static (G_TYPE_OBJECT, "GtkRcStyle",
931 return rc_style_type;
935 gtk_rc_style_init (GtkRcStyle *style)
940 style->font_desc = NULL;
942 for (i = 0; i < 5; i++)
944 static const GdkColor init_color = { 0, 0, 0, 0, };
946 style->bg_pixmap_name[i] = NULL;
947 style->color_flags[i] = 0;
948 style->fg[i] = init_color;
949 style->bg[i] = init_color;
950 style->text[i] = init_color;
951 style->base[i] = init_color;
953 style->xthickness = -1;
954 style->ythickness = -1;
955 style->rc_properties = NULL;
957 style->rc_style_lists = NULL;
958 style->icon_factories = NULL;
962 gtk_rc_style_class_init (GtkRcStyleClass *klass)
964 GObjectClass *object_class = G_OBJECT_CLASS (klass);
966 parent_class = g_type_class_peek_parent (klass);
968 object_class->finalize = gtk_rc_style_finalize;
971 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
972 klass->merge = gtk_rc_style_real_merge;
973 klass->create_style = gtk_rc_style_real_create_style;
977 gtk_rc_style_finalize (GObject *object)
979 GSList *tmp_list1, *tmp_list2;
980 GtkRcStyle *rc_style;
983 rc_style = GTK_RC_STYLE (object);
986 g_free (rc_style->name);
987 if (rc_style->font_desc)
988 pango_font_description_free (rc_style->font_desc);
990 for (i = 0; i < 5; i++)
991 if (rc_style->bg_pixmap_name[i])
992 g_free (rc_style->bg_pixmap_name[i]);
994 /* Now remove all references to this rc_style from
997 tmp_list1 = rc_style->rc_style_lists;
1000 GSList *rc_styles = tmp_list1->data;
1001 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1002 g_object_unref (style);
1004 /* Remove the list of styles from the other rc_styles
1007 tmp_list2 = rc_styles;
1010 GtkRcStyle *other_style = tmp_list2->data;
1012 if (other_style != rc_style)
1013 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1015 tmp_list2 = tmp_list2->next;
1018 /* And from the hash table itself
1020 g_hash_table_remove (realized_style_ht, rc_styles);
1021 g_slist_free (rc_styles);
1023 tmp_list1 = tmp_list1->next;
1025 g_slist_free (rc_style->rc_style_lists);
1027 if (rc_style->rc_properties)
1031 for (i = 0; i < rc_style->rc_properties->len; i++)
1033 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1035 g_free (node->origin);
1036 g_value_unset (&node->value);
1038 g_array_free (rc_style->rc_properties, TRUE);
1039 rc_style->rc_properties = NULL;
1042 tmp_list1 = rc_style->icon_factories;
1045 g_object_unref (tmp_list1->data);
1046 tmp_list1 = tmp_list1->next;
1048 g_slist_free (rc_style->icon_factories);
1050 G_OBJECT_CLASS (parent_class)->finalize (object);
1054 gtk_rc_style_new (void)
1058 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1064 * gtk_rc_style_copy:
1065 * @orig: the style to copy
1067 * Makes a copy of the specified #GtkRcStyle. This function
1068 * will correctly copy an RC style that is a member of a class
1069 * derived from #GtkRcStyle.
1071 * Return value: the resulting #GtkRcStyle
1074 gtk_rc_style_copy (GtkRcStyle *orig)
1078 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1080 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1081 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1087 gtk_rc_style_ref (GtkRcStyle *rc_style)
1089 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1091 g_object_ref (rc_style);
1095 gtk_rc_style_unref (GtkRcStyle *rc_style)
1097 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
1099 g_object_unref (rc_style);
1103 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1105 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1109 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1110 gconstpointer bsearch_node2)
1112 const GtkRcProperty *prop1 = bsearch_node1;
1113 const GtkRcProperty *prop2 = bsearch_node2;
1115 if (prop1->type_name == prop2->type_name)
1116 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1118 return prop1->type_name < prop2->type_name ? -1 : 1;
1122 insert_rc_property (GtkRcStyle *style,
1123 GtkRcProperty *property,
1127 GtkRcProperty *new_property = NULL;
1128 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1130 key.type_name = property->type_name;
1131 key.property_name = property->property_name;
1133 if (!style->rc_properties)
1134 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1137 while (i < style->rc_properties->len)
1139 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1145 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1147 g_free (new_property->origin);
1148 g_value_unset (&new_property->value);
1150 *new_property = key;
1164 g_array_insert_val (style->rc_properties, i, key);
1165 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1168 new_property->origin = g_strdup (property->origin);
1169 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1170 g_value_copy (&property->value, &new_property->value);
1174 gtk_rc_style_real_merge (GtkRcStyle *dest,
1179 for (i = 0; i < 5; i++)
1181 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1182 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1184 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1185 src->color_flags[i] & GTK_RC_FG)
1187 dest->fg[i] = src->fg[i];
1188 dest->color_flags[i] |= GTK_RC_FG;
1190 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1191 src->color_flags[i] & GTK_RC_BG)
1193 dest->bg[i] = src->bg[i];
1194 dest->color_flags[i] |= GTK_RC_BG;
1196 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1197 src->color_flags[i] & GTK_RC_TEXT)
1199 dest->text[i] = src->text[i];
1200 dest->color_flags[i] |= GTK_RC_TEXT;
1202 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1203 src->color_flags[i] & GTK_RC_BASE)
1205 dest->base[i] = src->base[i];
1206 dest->color_flags[i] |= GTK_RC_BASE;
1210 if (dest->xthickness < 0 && src->xthickness >= 0)
1211 dest->xthickness = src->xthickness;
1212 if (dest->ythickness < 0 && src->ythickness >= 0)
1213 dest->ythickness = src->ythickness;
1217 if (!dest->font_desc)
1218 dest->font_desc = pango_font_description_copy (src->font_desc);
1220 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1223 if (src->rc_properties)
1227 for (i = 0; i < src->rc_properties->len; i++)
1228 insert_rc_property (dest,
1229 &g_array_index (src->rc_properties, GtkRcProperty, i),
1235 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1237 return gtk_style_new ();
1241 gtk_rc_clear_hash_node (gpointer key,
1245 gtk_rc_style_unref (data);
1249 gtk_rc_free_rc_sets (GSList *slist)
1255 rc_set = slist->data;
1256 g_pattern_spec_free (rc_set->pspec);
1259 slist = slist->next;
1264 gtk_rc_clear_styles (GtkRcContext *context)
1266 /* Clear out all old rc_styles */
1268 if (context->rc_style_ht)
1270 g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
1271 g_hash_table_destroy (context->rc_style_ht);
1272 context->rc_style_ht = NULL;
1275 gtk_rc_free_rc_sets (context->rc_sets_widget);
1276 g_slist_free (context->rc_sets_widget);
1277 context->rc_sets_widget = NULL;
1279 gtk_rc_free_rc_sets (context->rc_sets_widget_class);
1280 g_slist_free (context->rc_sets_widget_class);
1281 context->rc_sets_widget_class = NULL;
1283 gtk_rc_free_rc_sets (context->rc_sets_class);
1284 g_slist_free (context->rc_sets_class);
1285 context->rc_sets_class = NULL;
1288 /* Reset all our widgets. Also, we have to invalidate cached icons in
1289 * icon sets so they get re-rendered.
1292 gtk_rc_reset_widgets (GtkSettings *settings)
1294 GList *list, *toplevels;
1296 _gtk_icon_set_invalidate_caches ();
1298 toplevels = gtk_window_list_toplevels ();
1299 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
1301 for (list = toplevels; list; list = list->next)
1303 if (gtk_widget_get_screen (list->data) == settings->screen)
1305 gtk_widget_reset_rc_styles (list->data);
1306 g_object_unref (list->data);
1309 g_list_free (toplevels);
1313 gtk_rc_clear_realized_style (gpointer key,
1317 GSList *rc_styles = key;
1318 GSList *tmp_list = rc_styles;
1322 GtkRcStyle *rc_style = tmp_list->data;
1324 rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
1326 tmp_list = tmp_list->next;
1329 g_slist_free (rc_styles);
1333 * _gtk_rc_reset_styles:
1334 * @settings: a #GtkSettings
1336 * This setting resets all of our styles; we use it when the font
1337 * rendering parameters or the icon sizes have changed. It's both less
1338 * and more comprehensive then we actually need:
1340 * Less comprehensive: it doesn't affect widgets that have a style
1343 * More comprehensive: it resets the styles, but the styles haven't
1344 * changed. The main reason for resetting the styles is becaues
1345 * most widgets will redo all their font stuff when their style
1349 _gtk_rc_reset_styles (GtkSettings *settings)
1351 GtkRcContext *context;
1352 gboolean reset = FALSE;
1354 g_return_if_fail (GTK_IS_SETTINGS (settings));
1356 context = gtk_rc_context_get (settings);
1358 if (context->default_style)
1360 g_object_unref (context->default_style);
1361 context->default_style = NULL;
1365 /* Clear out styles that have been looked up already
1367 if (realized_style_ht)
1369 g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
1370 g_hash_table_destroy (realized_style_ht);
1371 realized_style_ht = NULL;
1376 gtk_rc_reset_widgets (settings);
1380 _gtk_rc_context_get_default_font_name (GtkSettings *settings)
1382 GtkRcContext *context;
1383 gchar *new_font_name;
1385 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1387 context = gtk_rc_context_get (settings);
1389 g_object_get (context->settings,
1390 "gtk-font-name", &new_font_name,
1393 if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
1395 g_free (context->font_name);
1396 context->font_name = g_strdup (new_font_name);
1398 _gtk_rc_reset_styles (settings);
1401 g_free (new_font_name);
1403 return context->font_name;
1407 * gtk_rc_reparse_all_for_settings:
1408 * @settings: a #GtkSettings
1409 * @force_load: load whether or not anything changed
1411 * If the modification time on any previously read file
1412 * for the given #GtkSettings has changed, discard all style information
1413 * and then reread all previously read RC files.
1415 * Return value: %TRUE if the files were reread.
1418 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1419 gboolean force_load)
1421 gboolean mtime_modified = FALSE;
1424 GtkRcContext *context;
1426 struct stat statbuf;
1428 g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
1430 context = gtk_rc_context_get (settings);
1434 /* Check through and see if any of the RC's have had their
1435 * mtime modified. If so, reparse everything.
1437 tmp_list = context->rc_files;
1440 rc_file = tmp_list->data;
1442 if (!rc_file->is_string)
1444 if (!lstat (rc_file->name, &statbuf) &&
1445 (statbuf.st_mtime > rc_file->mtime))
1447 mtime_modified = TRUE;
1452 tmp_list = tmp_list->next;
1456 if (force_load || mtime_modified)
1458 _gtk_binding_reset_parsed ();
1459 gtk_rc_clear_styles (context);
1460 g_object_freeze_notify (G_OBJECT (context->settings));
1462 _gtk_settings_reset_rc_values (context->settings);
1463 tmp_list = context->rc_files;
1466 rc_file = tmp_list->data;
1468 if (rc_file->canonical_name != rc_file->name)
1469 g_free (rc_file->canonical_name);
1470 g_free (rc_file->name);
1473 tmp_list = tmp_list->next;
1476 g_slist_free (context->rc_files);
1477 context->rc_files = NULL;
1479 gtk_rc_parse_default_files (context);
1481 tmp_list = global_rc_files;
1484 rc_file = tmp_list->data;
1486 if (rc_file->is_string)
1487 gtk_rc_context_parse_string (context, rc_file->name);
1489 gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
1491 tmp_list = tmp_list->next;
1494 g_free (context->theme_name);
1495 g_free (context->key_theme_name);
1497 g_object_get (context->settings,
1498 "gtk-theme-name", &context->theme_name,
1499 "gtk-key-theme-name", &context->key_theme_name,
1502 if (context->theme_name && context->theme_name[0])
1503 gtk_rc_parse_named (context, context->theme_name, NULL);
1504 if (context->key_theme_name && context->key_theme_name[0])
1505 gtk_rc_parse_named (context, context->key_theme_name, "key");
1507 g_object_thaw_notify (G_OBJECT (context->settings));
1509 gtk_rc_reset_widgets (context->settings);
1512 return force_load || mtime_modified;
1516 * gtk_rc_reparse_all:
1518 * If the modification time on any previously read file for the
1519 * default #GtkSettings has changed, discard all style information
1520 * and then reread all previously read RC files.
1522 * Return value: %TRUE if the files were reread.
1525 gtk_rc_reparse_all (void)
1528 gboolean result = FALSE;
1530 for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
1532 GtkRcContext *context = tmp_list->data;
1533 if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
1541 gtk_rc_styles_match (GSList *rc_styles,
1545 const gchar *path_reversed)
1552 rc_set = sets->data;
1555 if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
1556 rc_styles = g_slist_append (rc_styles, rc_set);
1563 rc_set_compare (gconstpointer a, gconstpointer b)
1565 const GtkRcSet *set_a = a;
1566 const GtkRcSet *set_b = b;
1568 return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
1572 sort_and_dereference_sets (GSList *styles)
1576 /* At this point, the list of sets is ordered by:
1578 * a) 'widget' patterns are earlier than 'widget_class' patterns
1579 * which are ealier than 'class' patterns.
1580 * a) For two matches for class patterns, a match to a child type
1581 * is before a match to a parent type
1582 * c) a match later in the RC file (or in a later RC file) is before a
1583 * match earlier in the RC file.
1585 * With a) taking precedence over b) which takes precendence over c).
1587 * Now sort by priority, which has the highest precendence for sort order
1589 styles = g_slist_sort (styles, rc_set_compare);
1591 /* Make styles->data = styles->data->rc_style
1596 GtkRcSet *set = tmp_list->data;
1597 tmp_list->data = set->rc_style;
1598 tmp_list = tmp_list->next;
1606 * @widget: a #GtkWidget
1608 * Finds all matching RC styles for a given widget,
1609 * composites them together, and then creates a
1610 * #GtkStyle representing the composite appearance.
1611 * (GTK+ actually keeps a cache of previously
1612 * created styles, so a new style may not be
1615 * Returns: the resulting style. No refcount is added
1616 * to the returned style, so if you want to save this
1617 * style around, you should add a reference yourself.
1620 gtk_rc_get_style (GtkWidget *widget)
1622 GtkRcStyle *widget_rc_style;
1623 GSList *rc_styles = NULL;
1624 GtkRcContext *context;
1626 static guint rc_style_key_id = 0;
1628 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1630 context = gtk_rc_context_get (gtk_widget_get_settings (widget));
1632 /* We allow the specification of a single rc style to be bound
1633 * tightly to a widget, for application modifications
1635 if (!rc_style_key_id)
1636 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1638 if (context->rc_sets_widget)
1640 gchar *path, *path_reversed;
1643 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1644 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
1646 g_free (path_reversed);
1649 if (context->rc_sets_widget_class)
1651 gchar *path, *path_reversed;
1654 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1655 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
1657 g_free (path_reversed);
1660 if (context->rc_sets_class)
1664 type = G_TYPE_FROM_INSTANCE (widget);
1668 gchar *path_reversed;
1671 path = g_type_name (type);
1672 path_length = strlen (path);
1673 path_reversed = g_strdup (path);
1674 g_strreverse (path_reversed);
1676 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1677 g_free (path_reversed);
1679 type = g_type_parent (type);
1683 rc_styles = sort_and_dereference_sets (rc_styles);
1685 widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
1687 if (widget_rc_style)
1688 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1691 return gtk_rc_init_style (context, rc_styles);
1694 if (!context->default_style)
1696 context->default_style = gtk_style_new ();
1697 _gtk_style_init_for_settings (context->default_style, context->settings);
1700 return context->default_style;
1705 * gtk_rc_get_style_by_paths:
1706 * @settings: a #GtkSettings object
1707 * @widget_path: the widget path to use when looking up the style, or %NULL
1708 * if no matching against the widget path should be done
1709 * @class_path: the class path to use when looking up the style, or %NULL
1710 * if no matching against the class path should be done.
1711 * @type: a type that will be used along with parent types of this type
1712 * when matching against class styles, or #G_TYPE_NONE
1714 * Creates up a #GtkStyle from styles defined in a RC file by providing
1715 * the raw components used in matching. This function may be useful
1716 * when creating pseudo-widgets that should be themed like widgets but
1717 * don't actually have corresponding GTK+ widgets. An example of this
1718 * would be items inside a GNOME canvas widget.
1720 * The action of gtk_rc_get_style() is similar to:
1721 * <informalexample><programlisting>
1722 * gtk_widget_path (widget, NULL, &path, NULL);
1723 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1724 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
1725 * G_OBJECT_TYPE (widget));
1726 * </programlisting></informalexample>
1728 * Return value: A style created by matching with the supplied paths,
1729 * or %NULL if nothing matching was specified and the default style should
1730 * be used. The returned value is owned by GTK+ as part of an internal cache,
1731 * so you must call g_object_ref() on the returned value if you want to
1732 * keep a reference to it.
1735 gtk_rc_get_style_by_paths (GtkSettings *settings,
1736 const char *widget_path,
1737 const char *class_path,
1740 /* We duplicate the code from above to avoid slowing down the above
1741 * by generating paths when we don't need them. I don't know if
1742 * this is really worth it.
1744 GSList *rc_styles = NULL;
1745 GtkRcContext *context;
1747 g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
1749 context = gtk_rc_context_get (settings);
1751 if (widget_path && context->rc_sets_widget)
1753 gchar *path_reversed;
1756 path_length = strlen (widget_path);
1757 path_reversed = g_strdup (widget_path);
1758 g_strreverse (path_reversed);
1760 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, widget_path, path_reversed);
1761 g_free (path_reversed);
1764 if (class_path && context->rc_sets_widget_class)
1766 gchar *path_reversed;
1769 path_length = strlen (class_path);
1770 path_reversed = g_strdup (class_path);
1771 g_strreverse (path_reversed);
1773 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, class_path, path_reversed);
1774 g_free (path_reversed);
1777 if (type != G_TYPE_NONE && context->rc_sets_class)
1782 gchar *path_reversed;
1785 path = g_type_name (type);
1786 path_length = strlen (path);
1787 path_reversed = g_strdup (path);
1788 g_strreverse (path_reversed);
1790 rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
1791 g_free (path_reversed);
1793 type = g_type_parent (type);
1797 rc_styles = sort_and_dereference_sets (rc_styles);
1800 return gtk_rc_init_style (context, rc_styles);
1806 gtk_rc_add_rc_sets (GSList *slist,
1807 GtkRcStyle *rc_style,
1808 const gchar *pattern)
1810 GtkRcStyle *new_style;
1814 new_style = gtk_rc_style_new ();
1815 *new_style = *rc_style;
1816 new_style->name = g_strdup (rc_style->name);
1817 if (rc_style->font_desc)
1818 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1820 for (i = 0; i < 5; i++)
1821 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1823 rc_set = g_new (GtkRcSet, 1);
1824 rc_set->pspec = g_pattern_spec_new (pattern);
1825 rc_set->rc_style = rc_style;
1827 return g_slist_prepend (slist, rc_set);
1831 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1832 const gchar *pattern)
1834 GtkRcContext *context;
1836 g_return_if_fail (rc_style != NULL);
1837 g_return_if_fail (pattern != NULL);
1839 context = gtk_rc_context_get (gtk_settings_get_default ());
1841 context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern);
1845 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1846 const gchar *pattern)
1848 GtkRcContext *context;
1850 g_return_if_fail (rc_style != NULL);
1851 g_return_if_fail (pattern != NULL);
1853 context = gtk_rc_context_get (gtk_settings_get_default ());
1855 context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern);
1859 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1860 const gchar *pattern)
1862 GtkRcContext *context;
1864 g_return_if_fail (rc_style != NULL);
1865 g_return_if_fail (pattern != NULL);
1867 context = gtk_rc_context_get (gtk_settings_get_default ());
1869 context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern);
1873 gtk_rc_scanner_new (void)
1875 return g_scanner_new (>k_rc_scanner_config);
1879 gtk_rc_parse_any (GtkRcContext *context,
1880 const gchar *input_name,
1882 const gchar *input_string)
1888 scanner = gtk_rc_scanner_new ();
1892 g_assert (input_string == NULL);
1894 g_scanner_input_file (scanner, input_fd);
1898 g_assert (input_string != NULL);
1900 g_scanner_input_text (scanner, input_string, strlen (input_string));
1902 scanner->input_name = input_name;
1904 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1905 g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1910 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1914 guint expected_token;
1916 expected_token = gtk_rc_parse_statement (context, scanner);
1918 if (expected_token != G_TOKEN_NONE)
1925 if (scanner->scope_id == 0)
1927 /* if we are in scope 0, we know the symbol names
1928 * that are associated with certain token values.
1929 * so we look them up to make the error messages
1932 if (expected_token > GTK_RC_TOKEN_INVALID &&
1933 expected_token < GTK_RC_TOKEN_LAST)
1935 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1936 if (symbols[i].token == expected_token)
1937 msg = symbols[i].name;
1939 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1941 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1942 scanner->token < GTK_RC_TOKEN_LAST)
1944 symbol_name = "???";
1945 for (i = 0; i < G_N_ELEMENTS (symbols); i++)
1946 if (symbols[i].token == scanner->token)
1947 symbol_name = symbols[i].name;
1950 g_scanner_unexp_token (scanner,
1963 g_scanner_destroy (scanner);
1967 gtk_rc_styles_hash (const GSList *rc_styles)
1974 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1975 rc_styles = rc_styles->next;
1982 gtk_rc_styles_equal (const GSList *a,
1987 if (a->data != b->data)
1997 gtk_rc_style_hash (const gchar *name)
2003 result += (result << 3) + *name++;
2009 gtk_rc_style_equal (const gchar *a,
2012 return (strcmp (a, b) == 0);
2016 gtk_rc_style_find (GtkRcContext *context,
2019 if (context->rc_style_ht)
2020 return g_hash_table_lookup (context->rc_style_ht, (gpointer) name);
2026 gtk_rc_style_to_style (GtkRcContext *context,
2027 GtkRcStyle *rc_style)
2031 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
2032 _gtk_style_init_for_settings (style, context->settings);
2034 style->rc_style = rc_style;
2036 gtk_rc_style_ref (rc_style);
2038 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
2043 /* Reuses or frees rc_styles */
2045 gtk_rc_init_style (GtkRcContext *context,
2048 GtkStyle *style = NULL;
2051 g_return_val_if_fail (rc_styles != NULL, NULL);
2053 if (!realized_style_ht)
2054 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
2055 (GEqualFunc) gtk_rc_styles_equal);
2057 style = g_hash_table_lookup (realized_style_ht, rc_styles);
2061 GtkRcStyle *base_style = NULL;
2062 GtkRcStyle *proto_style;
2063 GtkRcStyleClass *proto_style_class;
2065 GType rc_style_type = GTK_TYPE_RC_STYLE;
2067 /* Find the the first style where the RC file specified engine "" {}
2068 * or the first derived style and use that to create the
2069 * merged style. If we only have raw GtkRcStyles, use the first
2070 * style to create the merged style.
2072 base_style = rc_styles->data;
2073 tmp_styles = rc_styles;
2076 GtkRcStyle *rc_style = tmp_styles->data;
2078 if (rc_style->engine_specified ||
2079 G_OBJECT_TYPE (rc_style) != rc_style_type)
2081 base_style = rc_style;
2085 tmp_styles = tmp_styles->next;
2088 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
2089 proto_style = proto_style_class->create_rc_style (base_style);
2091 tmp_styles = rc_styles;
2094 GtkRcStyle *rc_style = tmp_styles->data;
2097 proto_style_class->merge (proto_style, rc_style);
2099 /* Point from each rc_style to the list of styles */
2100 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
2101 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
2103 factories = g_slist_copy (rc_style->icon_factories);
2109 while (iter != NULL)
2111 g_object_ref (iter->data);
2112 iter = g_slist_next (iter);
2115 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
2120 tmp_styles = tmp_styles->next;
2123 for (i = 0; i < 5; i++)
2124 if (proto_style->bg_pixmap_name[i] &&
2125 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
2127 g_free (proto_style->bg_pixmap_name[i]);
2128 proto_style->bg_pixmap_name[i] = NULL;
2131 style = gtk_rc_style_to_style (context, proto_style);
2132 gtk_rc_style_unref (proto_style);
2134 g_hash_table_insert (realized_style_ht, rc_styles, style);
2137 g_slist_free (rc_styles);
2142 /*********************
2143 * Parsing functions *
2144 *********************/
2147 rc_parse_token_or_compound (GScanner *scanner,
2149 GTokenType delimiter)
2151 guint token = g_scanner_get_next_token (scanner);
2153 /* we either scan a single token (skipping comments)
2154 * or a compund statement.
2155 * compunds are enclosed in (), [] or {} braces, we read
2156 * them in via deep recursion.
2163 g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
2166 g_string_append_printf (gstring, " %f", scanner->value.v_float);
2168 case G_TOKEN_STRING:
2169 string = g_strescape (scanner->value.v_string, NULL);
2170 g_string_append (gstring, " \"");
2171 g_string_append (gstring, string);
2172 g_string_append_c (gstring, '"');
2175 case G_TOKEN_IDENTIFIER:
2176 g_string_append_c (gstring, ' ');
2177 g_string_append (gstring, scanner->value.v_identifier);
2179 case G_TOKEN_COMMENT_SINGLE:
2180 case G_TOKEN_COMMENT_MULTI:
2181 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2182 case G_TOKEN_LEFT_PAREN:
2183 g_string_append_c (gstring, ' ');
2184 g_string_append_c (gstring, token);
2185 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_PAREN);
2186 if (token != G_TOKEN_NONE)
2189 case G_TOKEN_LEFT_CURLY:
2190 g_string_append_c (gstring, ' ');
2191 g_string_append_c (gstring, token);
2192 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_CURLY);
2193 if (token != G_TOKEN_NONE)
2196 case G_TOKEN_LEFT_BRACE:
2197 g_string_append_c (gstring, ' ');
2198 g_string_append_c (gstring, token);
2199 token = rc_parse_token_or_compound (scanner, gstring, G_TOKEN_RIGHT_BRACE);
2200 if (token != G_TOKEN_NONE)
2204 if (token >= 256 || token < 1)
2205 return delimiter ? delimiter : G_TOKEN_STRING;
2206 g_string_append_c (gstring, ' ');
2207 g_string_append_c (gstring, token);
2208 if (token == delimiter)
2209 return G_TOKEN_NONE;
2213 return G_TOKEN_NONE;
2215 return rc_parse_token_or_compound (scanner, gstring, delimiter);
2219 gtk_rc_parse_assignment (GScanner *scanner,
2220 GtkRcProperty *prop)
2222 gboolean scan_identifier = scanner->config->scan_identifier;
2223 gboolean scan_symbols = scanner->config->scan_symbols;
2224 gboolean identifier_2_string = scanner->config->identifier_2_string;
2225 gboolean char_2_token = scanner->config->char_2_token;
2226 gboolean scan_identifier_NULL = scanner->config->scan_identifier_NULL;
2227 gboolean numbers_2_int = scanner->config->numbers_2_int;
2228 gboolean negate = FALSE;
2231 /* check that this is an assignment */
2232 if (g_scanner_get_next_token (scanner) != '=')
2235 /* adjust scanner mode */
2236 scanner->config->scan_identifier = TRUE;
2237 scanner->config->scan_symbols = FALSE;
2238 scanner->config->identifier_2_string = FALSE;
2239 scanner->config->char_2_token = TRUE;
2240 scanner->config->scan_identifier_NULL = FALSE;
2241 scanner->config->numbers_2_int = TRUE;
2243 /* record location */
2244 prop->origin = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
2246 /* parse optional sign */
2247 if (g_scanner_peek_next_token (scanner) == '-')
2249 g_scanner_get_next_token (scanner); /* eat sign */
2253 /* parse one of LONG, DOUBLE and STRING or, if that fails, create an unparsed compund */
2254 token = g_scanner_peek_next_token (scanner);
2258 g_scanner_get_next_token (scanner);
2259 g_value_init (&prop->value, G_TYPE_LONG);
2260 g_value_set_long (&prop->value, negate ? -scanner->value.v_int : scanner->value.v_int);
2261 token = G_TOKEN_NONE;
2264 g_scanner_get_next_token (scanner);
2265 g_value_init (&prop->value, G_TYPE_DOUBLE);
2266 g_value_set_double (&prop->value, negate ? -scanner->value.v_float : scanner->value.v_float);
2267 token = G_TOKEN_NONE;
2269 case G_TOKEN_STRING:
2270 g_scanner_get_next_token (scanner);
2272 token = G_TOKEN_INT;
2275 g_value_init (&prop->value, G_TYPE_STRING);
2276 g_value_set_string (&prop->value, scanner->value.v_string);
2277 token = G_TOKEN_NONE;
2280 case G_TOKEN_IDENTIFIER:
2281 case G_TOKEN_LEFT_PAREN:
2282 case G_TOKEN_LEFT_CURLY:
2283 case G_TOKEN_LEFT_BRACE:
2286 GString *gstring = g_string_new (NULL);
2288 token = rc_parse_token_or_compound (scanner, gstring, 0);
2289 if (token == G_TOKEN_NONE)
2291 g_string_append_c (gstring, ' ');
2292 g_value_init (&prop->value, G_TYPE_GSTRING);
2293 g_value_set_static_boxed (&prop->value, gstring);
2296 g_string_free (gstring, TRUE);
2301 g_scanner_get_next_token (scanner);
2302 token = G_TOKEN_INT;
2306 /* restore scanner mode */
2307 scanner->config->scan_identifier = scan_identifier;
2308 scanner->config->scan_symbols = scan_symbols;
2309 scanner->config->identifier_2_string = identifier_2_string;
2310 scanner->config->char_2_token = char_2_token;
2311 scanner->config->scan_identifier_NULL = scan_identifier_NULL;
2312 scanner->config->numbers_2_int = numbers_2_int;
2318 is_c_identifier (const gchar *string)
2321 gboolean is_varname;
2323 is_varname = strchr (G_CSET_a_2_z G_CSET_A_2_Z "_", string[0]) != NULL;
2324 for (p = string + 1; *p && is_varname; p++)
2325 is_varname &= strchr (G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "_-", *p) != NULL;
2331 parse_include_file (GtkRcContext *context,
2333 const gchar *filename)
2335 char *to_parse = NULL;
2337 if (g_path_is_absolute (filename))
2339 /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
2340 * don't print an error in this case.
2342 to_parse = g_strdup (filename);
2346 /* if a relative path, we look relative to all the RC files in the
2347 * include stack. We require the file to be found in this case
2348 * so we can give meaningful error messages, and because on reparsing
2349 * non-absolute paths don't make sense.
2351 GSList *tmp_list = rc_dir_stack;
2354 gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
2356 if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
2364 tmp_list = tmp_list->next;
2370 gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
2375 g_scanner_warn (scanner,
2376 _("Unable to find include file: \"%s\""),
2383 gtk_rc_parse_statement (GtkRcContext *context,
2388 token = g_scanner_peek_next_token (scanner);
2391 case GTK_RC_TOKEN_INCLUDE:
2392 token = g_scanner_get_next_token (scanner);
2393 if (token != GTK_RC_TOKEN_INCLUDE)
2394 return GTK_RC_TOKEN_INCLUDE;
2395 token = g_scanner_get_next_token (scanner);
2396 if (token != G_TOKEN_STRING)
2397 return G_TOKEN_STRING;
2398 parse_include_file (context, scanner, scanner->value.v_string);
2399 return G_TOKEN_NONE;
2401 case GTK_RC_TOKEN_STYLE:
2402 return gtk_rc_parse_style (context, scanner);
2404 case GTK_RC_TOKEN_BINDING:
2405 return gtk_binding_parse_binding (scanner);
2407 case GTK_RC_TOKEN_PIXMAP_PATH:
2408 return gtk_rc_parse_pixmap_path (context, scanner);
2410 case GTK_RC_TOKEN_WIDGET:
2411 return gtk_rc_parse_path_pattern (context, scanner);
2413 case GTK_RC_TOKEN_WIDGET_CLASS:
2414 return gtk_rc_parse_path_pattern (context, scanner);
2416 case GTK_RC_TOKEN_CLASS:
2417 return gtk_rc_parse_path_pattern (context, scanner);
2419 case GTK_RC_TOKEN_MODULE_PATH:
2420 return gtk_rc_parse_module_path (scanner);
2422 case GTK_RC_TOKEN_IM_MODULE_FILE:
2423 return gtk_rc_parse_im_module_file (scanner);
2425 case G_TOKEN_IDENTIFIER:
2426 if (is_c_identifier (scanner->next_value.v_identifier))
2428 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2431 g_scanner_get_next_token (scanner); /* eat identifier */
2432 name = g_strdup (scanner->value.v_identifier);
2434 token = gtk_rc_parse_assignment (scanner, &prop);
2435 if (token == G_TOKEN_NONE)
2437 GtkSettingsValue svalue;
2439 svalue.origin = prop.origin;
2440 memcpy (&svalue.value, &prop.value, sizeof (prop.value));
2441 g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2442 _gtk_settings_set_property_value_from_rc (context->settings,
2446 g_free (prop.origin);
2447 if (G_VALUE_TYPE (&prop.value))
2448 g_value_unset (&prop.value);
2455 g_scanner_get_next_token (scanner);
2456 return G_TOKEN_IDENTIFIER;
2459 g_scanner_get_next_token (scanner);
2460 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
2465 fixup_rc_set (GSList *list,
2471 GtkRcSet *set = list->data;
2472 if (set->rc_style == orig)
2473 set->rc_style = new;
2479 fixup_rc_sets (GtkRcContext *context,
2483 fixup_rc_set (context->rc_sets_widget, orig, new);
2484 fixup_rc_set (context->rc_sets_widget_class, orig, new);
2485 fixup_rc_set (context->rc_sets_class, orig, new);
2489 gtk_rc_parse_style (GtkRcContext *context,
2492 GtkRcStyle *rc_style;
2493 GtkRcStyle *orig_style;
2494 GtkRcStyle *parent_style;
2497 GtkIconFactory *our_factory = NULL;
2499 token = g_scanner_get_next_token (scanner);
2500 if (token != GTK_RC_TOKEN_STYLE)
2501 return GTK_RC_TOKEN_STYLE;
2503 token = g_scanner_get_next_token (scanner);
2504 if (token != G_TOKEN_STRING)
2505 return G_TOKEN_STRING;
2507 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
2509 orig_style = g_object_ref (rc_style);
2513 /* If there's a list, its first member is always the factory belonging
2516 if (rc_style && rc_style->icon_factories)
2517 our_factory = rc_style->icon_factories->data;
2521 rc_style = gtk_rc_style_new ();
2522 rc_style->name = g_strdup (scanner->value.v_string);
2524 for (i = 0; i < 5; i++)
2525 rc_style->bg_pixmap_name[i] = NULL;
2527 for (i = 0; i < 5; i++)
2528 rc_style->color_flags[i] = 0;
2531 token = g_scanner_peek_next_token (scanner);
2532 if (token == G_TOKEN_EQUAL_SIGN)
2534 token = g_scanner_get_next_token (scanner);
2536 token = g_scanner_get_next_token (scanner);
2537 if (token != G_TOKEN_STRING)
2539 token = G_TOKEN_STRING;
2543 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
2548 for (i = 0; i < 5; i++)
2550 rc_style->color_flags[i] = parent_style->color_flags[i];
2551 rc_style->fg[i] = parent_style->fg[i];
2552 rc_style->bg[i] = parent_style->bg[i];
2553 rc_style->text[i] = parent_style->text[i];
2554 rc_style->base[i] = parent_style->base[i];
2557 rc_style->xthickness = parent_style->xthickness;
2558 rc_style->ythickness = parent_style->ythickness;
2560 if (parent_style->font_desc)
2562 if (rc_style->font_desc)
2563 pango_font_description_free (rc_style->font_desc);
2564 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
2567 if (parent_style->rc_properties)
2571 for (i = 0; i < parent_style->rc_properties->len; i++)
2572 insert_rc_property (rc_style,
2573 &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
2577 for (i = 0; i < 5; i++)
2579 if (rc_style->bg_pixmap_name[i])
2580 g_free (rc_style->bg_pixmap_name[i]);
2581 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
2584 /* Append parent's factories, adding a ref to them */
2585 if (parent_style->icon_factories != NULL)
2587 /* Add a factory for ourselves if we have none,
2588 * in case we end up defining more stock icons.
2589 * I see no real way around this; we need to maintain
2590 * the invariant that the first factory in the list
2591 * is always our_factory, the one belonging to us,
2592 * and if we put parent factories in the list we can't
2593 * do that if the style is reopened.
2595 if (our_factory == NULL)
2597 our_factory = gtk_icon_factory_new ();
2598 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2602 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
2603 g_slist_copy (parent_style->icon_factories));
2605 factories = parent_style->icon_factories;
2606 while (factories != NULL)
2608 g_object_ref (factories->data);
2609 factories = factories->next;
2615 token = g_scanner_get_next_token (scanner);
2616 if (token != G_TOKEN_LEFT_CURLY)
2618 token = G_TOKEN_LEFT_CURLY;
2622 token = g_scanner_peek_next_token (scanner);
2623 while (token != G_TOKEN_RIGHT_CURLY)
2627 case GTK_RC_TOKEN_BG:
2628 token = gtk_rc_parse_bg (scanner, rc_style);
2630 case GTK_RC_TOKEN_FG:
2631 token = gtk_rc_parse_fg (scanner, rc_style);
2633 case GTK_RC_TOKEN_TEXT:
2634 token = gtk_rc_parse_text (scanner, rc_style);
2636 case GTK_RC_TOKEN_BASE:
2637 token = gtk_rc_parse_base (scanner, rc_style);
2639 case GTK_RC_TOKEN_XTHICKNESS:
2640 token = gtk_rc_parse_xthickness (scanner, rc_style);
2642 case GTK_RC_TOKEN_YTHICKNESS:
2643 token = gtk_rc_parse_ythickness (scanner, rc_style);
2645 case GTK_RC_TOKEN_BG_PIXMAP:
2646 token = gtk_rc_parse_bg_pixmap (context, scanner, rc_style);
2648 case GTK_RC_TOKEN_FONT:
2649 token = gtk_rc_parse_font (scanner, rc_style);
2651 case GTK_RC_TOKEN_FONTSET:
2652 token = gtk_rc_parse_fontset (scanner, rc_style);
2654 case GTK_RC_TOKEN_FONT_NAME:
2655 token = gtk_rc_parse_font_name (scanner, rc_style);
2657 case GTK_RC_TOKEN_ENGINE:
2658 token = gtk_rc_parse_engine (context, scanner, &rc_style);
2660 case GTK_RC_TOKEN_STOCK:
2661 if (our_factory == NULL)
2663 our_factory = gtk_icon_factory_new ();
2664 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
2667 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
2669 case G_TOKEN_IDENTIFIER:
2670 if (is_c_identifier (scanner->next_value.v_identifier) &&
2671 scanner->next_value.v_identifier[0] >= 'A' &&
2672 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
2674 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
2676 g_scanner_get_next_token (scanner); /* eat type name */
2677 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
2678 if (g_scanner_get_next_token (scanner) != ':' ||
2679 g_scanner_get_next_token (scanner) != ':')
2684 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER ||
2685 !is_c_identifier (scanner->value.v_identifier))
2687 token = G_TOKEN_IDENTIFIER;
2691 /* it's important that we do the same canonification as GParamSpecPool here */
2692 g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
2693 prop.property_name = g_quark_from_string (scanner->value.v_identifier);
2695 token = gtk_rc_parse_assignment (scanner, &prop);
2696 if (token == G_TOKEN_NONE)
2698 g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
2699 insert_rc_property (rc_style, &prop, TRUE);
2702 g_free (prop.origin);
2703 if (G_VALUE_TYPE (&prop.value))
2704 g_value_unset (&prop.value);
2708 g_scanner_get_next_token (scanner);
2709 token = G_TOKEN_IDENTIFIER;
2713 g_scanner_get_next_token (scanner);
2714 token = G_TOKEN_RIGHT_CURLY;
2718 if (token != G_TOKEN_NONE)
2721 token = g_scanner_peek_next_token (scanner);
2722 } /* while (token != G_TOKEN_RIGHT_CURLY) */
2724 token = g_scanner_get_next_token (scanner);
2725 if (token != G_TOKEN_RIGHT_CURLY)
2727 token = G_TOKEN_RIGHT_CURLY;
2731 if (rc_style != orig_style)
2733 if (!context->rc_style_ht)
2734 context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
2735 (GEqualFunc) gtk_rc_style_equal);
2737 g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
2739 /* If we copied the data into a new rc style, fix up references to the old rc style
2740 * in bindings that we have.
2743 fixup_rc_sets (context, orig_style, rc_style);
2747 g_object_unref (orig_style);
2749 return G_TOKEN_NONE;
2752 if (rc_style != orig_style)
2753 gtk_rc_style_unref (rc_style);
2756 g_object_unref (orig_style);
2761 const GtkRcProperty*
2762 _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
2764 GQuark property_name)
2766 GtkRcProperty *node = NULL;
2768 g_return_val_if_fail (GTK_IS_RC_STYLE (rc_style), NULL);
2770 if (rc_style->rc_properties)
2774 key.type_name = type_name;
2775 key.property_name = property_name;
2777 node = bsearch (&key,
2778 rc_style->rc_properties->data, rc_style->rc_properties->len,
2779 sizeof (GtkRcProperty), gtk_rc_properties_cmp);
2786 gtk_rc_parse_bg (GScanner *scanner,
2792 token = g_scanner_get_next_token (scanner);
2793 if (token != GTK_RC_TOKEN_BG)
2794 return GTK_RC_TOKEN_BG;
2796 token = gtk_rc_parse_state (scanner, &state);
2797 if (token != G_TOKEN_NONE)
2800 token = g_scanner_get_next_token (scanner);
2801 if (token != G_TOKEN_EQUAL_SIGN)
2802 return G_TOKEN_EQUAL_SIGN;
2804 style->color_flags[state] |= GTK_RC_BG;
2805 return gtk_rc_parse_color (scanner, &style->bg[state]);
2809 gtk_rc_parse_fg (GScanner *scanner,
2815 token = g_scanner_get_next_token (scanner);
2816 if (token != GTK_RC_TOKEN_FG)
2817 return GTK_RC_TOKEN_FG;
2819 token = gtk_rc_parse_state (scanner, &state);
2820 if (token != G_TOKEN_NONE)
2823 token = g_scanner_get_next_token (scanner);
2824 if (token != G_TOKEN_EQUAL_SIGN)
2825 return G_TOKEN_EQUAL_SIGN;
2827 style->color_flags[state] |= GTK_RC_FG;
2828 return gtk_rc_parse_color (scanner, &style->fg[state]);
2832 gtk_rc_parse_text (GScanner *scanner,
2838 token = g_scanner_get_next_token (scanner);
2839 if (token != GTK_RC_TOKEN_TEXT)
2840 return GTK_RC_TOKEN_TEXT;
2842 token = gtk_rc_parse_state (scanner, &state);
2843 if (token != G_TOKEN_NONE)
2846 token = g_scanner_get_next_token (scanner);
2847 if (token != G_TOKEN_EQUAL_SIGN)
2848 return G_TOKEN_EQUAL_SIGN;
2850 style->color_flags[state] |= GTK_RC_TEXT;
2851 return gtk_rc_parse_color (scanner, &style->text[state]);
2855 gtk_rc_parse_base (GScanner *scanner,
2861 token = g_scanner_get_next_token (scanner);
2862 if (token != GTK_RC_TOKEN_BASE)
2863 return GTK_RC_TOKEN_BASE;
2865 token = gtk_rc_parse_state (scanner, &state);
2866 if (token != G_TOKEN_NONE)
2869 token = g_scanner_get_next_token (scanner);
2870 if (token != G_TOKEN_EQUAL_SIGN)
2871 return G_TOKEN_EQUAL_SIGN;
2873 style->color_flags[state] |= GTK_RC_BASE;
2874 return gtk_rc_parse_color (scanner, &style->base[state]);
2878 gtk_rc_parse_xthickness (GScanner *scanner,
2881 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
2882 return GTK_RC_TOKEN_XTHICKNESS;
2884 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2885 return G_TOKEN_EQUAL_SIGN;
2887 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2890 style->xthickness = scanner->value.v_int;
2892 return G_TOKEN_NONE;
2896 gtk_rc_parse_ythickness (GScanner *scanner,
2899 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
2900 return GTK_RC_TOKEN_YTHICKNESS;
2902 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
2903 return G_TOKEN_EQUAL_SIGN;
2905 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
2908 style->ythickness = scanner->value.v_int;
2910 return G_TOKEN_NONE;
2914 gtk_rc_parse_bg_pixmap (GtkRcContext *context,
2916 GtkRcStyle *rc_style)
2922 token = g_scanner_get_next_token (scanner);
2923 if (token != GTK_RC_TOKEN_BG_PIXMAP)
2924 return GTK_RC_TOKEN_BG_PIXMAP;
2926 token = gtk_rc_parse_state (scanner, &state);
2927 if (token != G_TOKEN_NONE)
2930 token = g_scanner_get_next_token (scanner);
2931 if (token != G_TOKEN_EQUAL_SIGN)
2932 return G_TOKEN_EQUAL_SIGN;
2934 token = g_scanner_get_next_token (scanner);
2935 if (token != G_TOKEN_STRING)
2936 return G_TOKEN_STRING;
2938 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
2939 (strcmp (scanner->value.v_string, "<none>") == 0))
2940 pixmap_file = g_strdup (scanner->value.v_string);
2942 pixmap_file = gtk_rc_find_pixmap_in_path (context->settings,
2943 scanner, scanner->value.v_string);
2947 if (rc_style->bg_pixmap_name[state])
2948 g_free (rc_style->bg_pixmap_name[state]);
2949 rc_style->bg_pixmap_name[state] = pixmap_file;
2952 return G_TOKEN_NONE;
2956 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2961 buf = g_build_filename (dir, pixmap_file, NULL);
2963 fd = open (buf, O_RDONLY);
2976 * gtk_rc_find_pixmap_in_path:
2977 * @settings: a #GtkSettings
2978 * @scanner: Scanner used to get line number information for the
2979 * warning message, or %NULL
2980 * @pixmap_file: name of the pixmap file to locate.
2982 * Looks up a file in pixmap path for the specified #GtkSettings.
2983 * If the file is not found, it outputs a warning message using
2984 * g_warning() and returns %NULL.
2986 * Return value: the filename.
2989 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
2991 const gchar *pixmap_file)
2997 GtkRcContext *context = gtk_rc_context_get (settings);
2999 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (context->pixmap_path[i] != NULL); i++)
3001 filename = gtk_rc_check_pixmap_dir (context->pixmap_path[i], pixmap_file);
3006 tmp_list = rc_dir_stack;
3009 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
3013 tmp_list = tmp_list->next;
3017 g_scanner_warn (scanner,
3018 _("Unable to locate image file in pixmap_path: \"%s\""),
3021 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
3028 * gtk_rc_find_module_in_path:
3029 * @module_file: name of a theme engine
3031 * Searches for a theme engine in the GTK+ search path. This function
3032 * is not useful for applications and should not be used.
3034 * Return value: The filename, if found (must be freed with g_free()),
3038 gtk_rc_find_module_in_path (const gchar *module_file)
3040 return _gtk_find_module (module_file, "engines");
3044 gtk_rc_parse_font (GScanner *scanner,
3045 GtkRcStyle *rc_style)
3049 token = g_scanner_get_next_token (scanner);
3050 if (token != GTK_RC_TOKEN_FONT)
3051 return GTK_RC_TOKEN_FONT;
3053 token = g_scanner_get_next_token (scanner);
3054 if (token != G_TOKEN_EQUAL_SIGN)
3055 return G_TOKEN_EQUAL_SIGN;
3057 token = g_scanner_get_next_token (scanner);
3058 if (token != G_TOKEN_STRING)
3059 return G_TOKEN_STRING;
3061 /* Ignore, do nothing */
3063 return G_TOKEN_NONE;
3067 gtk_rc_parse_fontset (GScanner *scanner,
3068 GtkRcStyle *rc_style)
3072 token = g_scanner_get_next_token (scanner);
3073 if (token != GTK_RC_TOKEN_FONTSET)
3074 return GTK_RC_TOKEN_FONTSET;
3076 token = g_scanner_get_next_token (scanner);
3077 if (token != G_TOKEN_EQUAL_SIGN)
3078 return G_TOKEN_EQUAL_SIGN;
3080 token = g_scanner_get_next_token (scanner);
3081 if (token != G_TOKEN_STRING)
3082 return G_TOKEN_STRING;
3084 /* Do nothing - silently ignore */
3086 return G_TOKEN_NONE;
3090 gtk_rc_parse_font_name (GScanner *scanner,
3091 GtkRcStyle *rc_style)
3095 token = g_scanner_get_next_token (scanner);
3096 if (token != GTK_RC_TOKEN_FONT_NAME)
3097 return GTK_RC_TOKEN_FONT;
3099 token = g_scanner_get_next_token (scanner);
3100 if (token != G_TOKEN_EQUAL_SIGN)
3101 return G_TOKEN_EQUAL_SIGN;
3103 token = g_scanner_get_next_token (scanner);
3104 if (token != G_TOKEN_STRING)
3105 return G_TOKEN_STRING;
3107 if (rc_style->font_desc)
3108 pango_font_description_free (rc_style->font_desc);
3110 rc_style->font_desc =
3111 pango_font_description_from_string (scanner->value.v_string);
3113 return G_TOKEN_NONE;
3117 gtk_rc_parse_engine (GtkRcContext *context,
3119 GtkRcStyle **rc_style)
3122 GtkThemeEngine *engine;
3123 guint result = G_TOKEN_NONE;
3124 GtkRcStyle *new_style = NULL;
3125 gboolean parsed_curlies = FALSE;
3127 token = g_scanner_get_next_token (scanner);
3128 if (token != GTK_RC_TOKEN_ENGINE)
3129 return GTK_RC_TOKEN_ENGINE;
3131 token = g_scanner_get_next_token (scanner);
3132 if (token != G_TOKEN_STRING)
3133 return G_TOKEN_STRING;
3135 if (!scanner->value.v_string[0])
3137 /* Support engine "" {} to mean override to the default engine
3139 token = g_scanner_get_next_token (scanner);
3140 if (token != G_TOKEN_LEFT_CURLY)
3141 return G_TOKEN_LEFT_CURLY;
3143 token = g_scanner_get_next_token (scanner);
3144 if (token != G_TOKEN_RIGHT_CURLY)
3145 return G_TOKEN_RIGHT_CURLY;
3147 parsed_curlies = TRUE;
3149 if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
3151 new_style = gtk_rc_style_new ();
3152 gtk_rc_style_real_merge (new_style, *rc_style);
3154 if ((*rc_style)->name)
3155 new_style->name = g_strdup ((*rc_style)->name);
3158 (*rc_style)->engine_specified = TRUE;
3162 engine = gtk_theme_engine_get (scanner->value.v_string);
3164 token = g_scanner_get_next_token (scanner);
3165 if (token != G_TOKEN_LEFT_CURLY)
3166 return G_TOKEN_LEFT_CURLY;
3170 GtkRcStyleClass *new_class;
3172 new_style = gtk_theme_engine_create_rc_style (engine);
3173 g_type_module_unuse (G_TYPE_MODULE (engine));
3175 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
3177 new_class->merge (new_style, *rc_style);
3178 if ((*rc_style)->name)
3179 new_style->name = g_strdup ((*rc_style)->name);
3181 if (new_class->parse)
3183 parsed_curlies = TRUE;
3184 result = new_class->parse (new_style, context->settings, scanner);
3186 if (result != G_TOKEN_NONE)
3188 g_object_unref (new_style);
3195 if (!parsed_curlies)
3197 /* Skip over remainder, looking for nested {}'s
3201 result = G_TOKEN_RIGHT_CURLY;
3202 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
3204 if (token == G_TOKEN_LEFT_CURLY)
3206 else if (token == G_TOKEN_RIGHT_CURLY)
3211 result = G_TOKEN_NONE;
3219 new_style->engine_specified = TRUE;
3221 g_object_unref (*rc_style);
3222 *rc_style = new_style;
3229 gtk_rc_parse_state (GScanner *scanner,
3230 GtkStateType *state)
3235 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3236 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
3238 /* we don't know where we got called from, so we reset the scope here.
3239 * if we bail out due to errors, we *don't* reset the scope, so the
3240 * error messaging code can make sense of our tokens.
3242 old_scope = g_scanner_set_scope (scanner, 0);
3244 token = g_scanner_get_next_token (scanner);
3245 if (token != G_TOKEN_LEFT_BRACE)
3246 return G_TOKEN_LEFT_BRACE;
3248 token = g_scanner_get_next_token (scanner);
3251 case GTK_RC_TOKEN_ACTIVE:
3252 *state = GTK_STATE_ACTIVE;
3254 case GTK_RC_TOKEN_INSENSITIVE:
3255 *state = GTK_STATE_INSENSITIVE;
3257 case GTK_RC_TOKEN_NORMAL:
3258 *state = GTK_STATE_NORMAL;
3260 case GTK_RC_TOKEN_PRELIGHT:
3261 *state = GTK_STATE_PRELIGHT;
3263 case GTK_RC_TOKEN_SELECTED:
3264 *state = GTK_STATE_SELECTED;
3267 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
3270 token = g_scanner_get_next_token (scanner);
3271 if (token != G_TOKEN_RIGHT_BRACE)
3272 return G_TOKEN_RIGHT_BRACE;
3274 g_scanner_set_scope (scanner, old_scope);
3276 return G_TOKEN_NONE;
3280 gtk_rc_parse_priority (GScanner *scanner,
3281 GtkPathPriorityType *priority)
3286 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3287 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
3289 /* we don't know where we got called from, so we reset the scope here.
3290 * if we bail out due to errors, we *don't* reset the scope, so the
3291 * error messaging code can make sense of our tokens.
3293 old_scope = g_scanner_set_scope (scanner, 0);
3295 token = g_scanner_get_next_token (scanner);
3299 token = g_scanner_get_next_token (scanner);
3302 case GTK_RC_TOKEN_LOWEST:
3303 *priority = GTK_PATH_PRIO_LOWEST;
3305 case GTK_RC_TOKEN_GTK:
3306 *priority = GTK_PATH_PRIO_GTK;
3308 case GTK_RC_TOKEN_APPLICATION:
3309 *priority = GTK_PATH_PRIO_APPLICATION;
3311 case GTK_RC_TOKEN_THEME:
3312 *priority = GTK_PATH_PRIO_THEME;
3314 case GTK_RC_TOKEN_RC:
3315 *priority = GTK_PATH_PRIO_RC;
3317 case GTK_RC_TOKEN_HIGHEST:
3318 *priority = GTK_PATH_PRIO_HIGHEST;
3321 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
3324 g_scanner_set_scope (scanner, old_scope);
3326 return G_TOKEN_NONE;
3330 gtk_rc_parse_color (GScanner *scanner,
3335 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
3337 /* we don't need to set our own scope here, because
3338 * we don't need own symbols
3341 token = g_scanner_get_next_token (scanner);
3346 case G_TOKEN_LEFT_CURLY:
3347 token = g_scanner_get_next_token (scanner);
3348 if (token == G_TOKEN_INT)
3349 token_int = scanner->value.v_int;
3350 else if (token == G_TOKEN_FLOAT)
3351 token_int = scanner->value.v_float * 65535.0;
3353 return G_TOKEN_FLOAT;
3354 color->red = CLAMP (token_int, 0, 65535);
3356 token = g_scanner_get_next_token (scanner);
3357 if (token != G_TOKEN_COMMA)
3358 return G_TOKEN_COMMA;
3360 token = g_scanner_get_next_token (scanner);
3361 if (token == G_TOKEN_INT)
3362 token_int = scanner->value.v_int;
3363 else if (token == G_TOKEN_FLOAT)
3364 token_int = scanner->value.v_float * 65535.0;
3366 return G_TOKEN_FLOAT;
3367 color->green = CLAMP (token_int, 0, 65535);
3369 token = g_scanner_get_next_token (scanner);
3370 if (token != G_TOKEN_COMMA)
3371 return G_TOKEN_COMMA;
3373 token = g_scanner_get_next_token (scanner);
3374 if (token == G_TOKEN_INT)
3375 token_int = scanner->value.v_int;
3376 else if (token == G_TOKEN_FLOAT)
3377 token_int = scanner->value.v_float * 65535.0;
3379 return G_TOKEN_FLOAT;
3380 color->blue = CLAMP (token_int, 0, 65535);
3382 token = g_scanner_get_next_token (scanner);
3383 if (token != G_TOKEN_RIGHT_CURLY)
3384 return G_TOKEN_RIGHT_CURLY;
3385 return G_TOKEN_NONE;
3387 case G_TOKEN_STRING:
3388 if (!gdk_color_parse (scanner->value.v_string, color))
3390 g_scanner_warn (scanner, "Invalid color constant '%s'",
3391 scanner->value.v_string);
3392 return G_TOKEN_STRING;
3395 return G_TOKEN_NONE;
3398 return G_TOKEN_STRING;
3403 gtk_rc_parse_pixmap_path (GtkRcContext *context,
3408 token = g_scanner_get_next_token (scanner);
3409 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
3410 return GTK_RC_TOKEN_PIXMAP_PATH;
3412 token = g_scanner_get_next_token (scanner);
3413 if (token != G_TOKEN_STRING)
3414 return G_TOKEN_STRING;
3416 gtk_rc_parse_pixmap_path_string (context, scanner, scanner->value.v_string);
3418 return G_TOKEN_NONE;
3422 gtk_rc_parse_pixmap_path_string (GtkRcContext *context,
3424 const gchar *pix_path)
3427 gint start_offset = 0;
3431 /* free the old one, or just add to the old one ? */
3432 for (path_num = 0; context->pixmap_path[path_num]; path_num++)
3434 g_free (context->pixmap_path[path_num]);
3435 context->pixmap_path[path_num] = NULL;
3440 path_len = strlen (pix_path);
3442 for (end_offset = 0; end_offset <= path_len; end_offset++)
3444 if ((pix_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
3445 (end_offset == path_len))
3447 gchar *path_element = g_strndup (pix_path + start_offset, end_offset - start_offset);
3448 if (g_path_is_absolute (path_element))
3450 context->pixmap_path[path_num] = path_element;
3452 context->pixmap_path[path_num] = NULL;
3456 g_warning (_("Pixmap path element: \"%s\" must be absolute, %s, line %d"),
3457 path_element, scanner->input_name, scanner->line);
3458 g_free (path_element);
3461 start_offset = end_offset + 1;
3467 gtk_rc_parse_module_path (GScanner *scanner)
3471 token = g_scanner_get_next_token (scanner);
3472 if (token != GTK_RC_TOKEN_MODULE_PATH)
3473 return GTK_RC_TOKEN_MODULE_PATH;
3475 token = g_scanner_get_next_token (scanner);
3476 if (token != G_TOKEN_STRING)
3477 return G_TOKEN_STRING;
3479 g_warning ("module_path directive is now ignored\n");
3481 return G_TOKEN_NONE;
3485 gtk_rc_parse_im_module_file (GScanner *scanner)
3489 token = g_scanner_get_next_token (scanner);
3490 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
3491 return GTK_RC_TOKEN_IM_MODULE_FILE;
3493 token = g_scanner_get_next_token (scanner);
3494 if (token != G_TOKEN_STRING)
3495 return G_TOKEN_STRING;
3498 g_free (im_module_file);
3500 im_module_file = g_strdup (scanner->value.v_string);
3502 return G_TOKEN_NONE;
3506 gtk_rc_parse_path_pattern (GtkRcContext *context,
3510 GtkPathType path_type;
3512 gboolean is_binding;
3513 GtkPathPriorityType priority = context->default_priority;
3515 token = g_scanner_get_next_token (scanner);
3518 case GTK_RC_TOKEN_WIDGET:
3519 path_type = GTK_PATH_WIDGET;
3521 case GTK_RC_TOKEN_WIDGET_CLASS:
3522 path_type = GTK_PATH_WIDGET_CLASS;
3524 case GTK_RC_TOKEN_CLASS:
3525 path_type = GTK_PATH_CLASS;
3528 return GTK_RC_TOKEN_WIDGET_CLASS;
3531 token = g_scanner_get_next_token (scanner);
3532 if (token != G_TOKEN_STRING)
3533 return G_TOKEN_STRING;
3535 pattern = g_strdup (scanner->value.v_string);
3537 token = g_scanner_get_next_token (scanner);
3538 if (token == GTK_RC_TOKEN_STYLE)
3540 else if (token == GTK_RC_TOKEN_BINDING)
3545 return GTK_RC_TOKEN_STYLE;
3548 if (g_scanner_peek_next_token (scanner) == ':')
3550 token = gtk_rc_parse_priority (scanner, &priority);
3551 if (token != G_TOKEN_NONE)
3558 token = g_scanner_get_next_token (scanner);
3559 if (token != G_TOKEN_STRING)
3562 return G_TOKEN_STRING;
3567 GtkBindingSet *binding;
3569 binding = gtk_binding_set_find (scanner->value.v_string);
3573 return G_TOKEN_STRING;
3575 gtk_binding_set_add_path (binding, path_type, pattern, priority);
3579 GtkRcStyle *rc_style;
3582 rc_style = gtk_rc_style_find (context, scanner->value.v_string);
3587 return G_TOKEN_STRING;
3590 rc_set = g_new (GtkRcSet, 1);
3591 rc_set->pspec = g_pattern_spec_new (pattern);
3592 rc_set->rc_style = rc_style;
3593 rc_set->priority = priority;
3595 if (path_type == GTK_PATH_WIDGET)
3596 context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
3597 else if (path_type == GTK_PATH_WIDGET_CLASS)
3598 context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
3600 context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
3604 return G_TOKEN_NONE;
3608 gtk_rc_parse_stock_id (GScanner *scanner,
3613 token = g_scanner_get_next_token (scanner);
3614 if (token != G_TOKEN_LEFT_BRACE)
3615 return G_TOKEN_LEFT_BRACE;
3617 token = g_scanner_get_next_token (scanner);
3619 if (token != G_TOKEN_STRING)
3620 return G_TOKEN_STRING;
3622 *stock_id = g_strdup (scanner->value.v_string);
3624 token = g_scanner_get_next_token (scanner);
3625 if (token != G_TOKEN_RIGHT_BRACE)
3628 return G_TOKEN_RIGHT_BRACE;
3631 return G_TOKEN_NONE;
3635 gtk_rc_parse_icon_source (GtkRcContext *context,
3637 GtkIconSet *icon_set,
3638 gboolean *icon_set_valid)
3641 GtkIconSource *source;
3642 gchar *full_filename;
3644 token = g_scanner_get_next_token (scanner);
3645 if (token != G_TOKEN_LEFT_CURLY)
3646 return G_TOKEN_LEFT_CURLY;
3648 token = g_scanner_get_next_token (scanner);
3650 if (token != G_TOKEN_STRING && token != '@')
3651 return G_TOKEN_STRING;
3653 source = gtk_icon_source_new ();
3655 if (token == G_TOKEN_STRING)
3659 full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
3662 gtk_icon_source_set_filename (source, full_filename);
3663 g_free (full_filename);
3670 token = g_scanner_get_next_token (scanner);
3672 if (token != G_TOKEN_STRING)
3673 return G_TOKEN_STRING;
3675 gtk_icon_source_set_icon_name (source, scanner->value.v_string);
3678 /* We continue parsing even if we didn't find the pixmap so that rest of the
3679 * file is read, even if the syntax is bad. However we don't validate the
3680 * icon_set so the caller can choose not to install it.
3682 token = g_scanner_get_next_token (scanner);
3684 if (token == G_TOKEN_RIGHT_CURLY)
3686 else if (token != G_TOKEN_COMMA)
3688 gtk_icon_source_free (source);
3689 return G_TOKEN_COMMA;
3692 /* Get the direction */
3694 token = g_scanner_get_next_token (scanner);
3698 case GTK_RC_TOKEN_RTL:
3699 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3700 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
3703 case GTK_RC_TOKEN_LTR:
3704 gtk_icon_source_set_direction_wildcarded (source, FALSE);
3705 gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
3712 gtk_icon_source_free (source);
3713 return GTK_RC_TOKEN_RTL;
3717 token = g_scanner_get_next_token (scanner);
3719 if (token == G_TOKEN_RIGHT_CURLY)
3721 else if (token != G_TOKEN_COMMA)
3723 gtk_icon_source_free (source);
3724 return G_TOKEN_COMMA;
3729 token = g_scanner_get_next_token (scanner);
3733 case GTK_RC_TOKEN_NORMAL:
3734 gtk_icon_source_set_state_wildcarded (source, FALSE);
3735 gtk_icon_source_set_state (source, GTK_STATE_NORMAL);
3738 case GTK_RC_TOKEN_PRELIGHT:
3739 gtk_icon_source_set_state_wildcarded (source, FALSE);
3740 gtk_icon_source_set_state (source, GTK_STATE_PRELIGHT);
3744 case GTK_RC_TOKEN_INSENSITIVE:
3745 gtk_icon_source_set_state_wildcarded (source, FALSE);
3746 gtk_icon_source_set_state (source, GTK_STATE_INSENSITIVE);
3749 case GTK_RC_TOKEN_ACTIVE:
3750 gtk_icon_source_set_state_wildcarded (source, FALSE);
3751 gtk_icon_source_set_state (source, GTK_STATE_ACTIVE);
3754 case GTK_RC_TOKEN_SELECTED:
3755 gtk_icon_source_set_state_wildcarded (source, FALSE);
3756 gtk_icon_source_set_state (source, GTK_STATE_SELECTED);
3763 gtk_icon_source_free (source);
3764 return GTK_RC_TOKEN_PRELIGHT;
3768 token = g_scanner_get_next_token (scanner);
3770 if (token == G_TOKEN_RIGHT_CURLY)
3772 else if (token != G_TOKEN_COMMA)
3774 gtk_icon_source_free (source);
3775 return G_TOKEN_COMMA;
3780 token = g_scanner_get_next_token (scanner);
3786 if (token != G_TOKEN_STRING)
3788 gtk_icon_source_free (source);
3789 return G_TOKEN_STRING;
3792 size = gtk_icon_size_from_name (scanner->value.v_string);
3794 if (size != GTK_ICON_SIZE_INVALID)
3796 gtk_icon_source_set_size_wildcarded (source, FALSE);
3797 gtk_icon_source_set_size (source, size);
3801 /* Check the close brace */
3803 token = g_scanner_get_next_token (scanner);
3804 if (token != G_TOKEN_RIGHT_CURLY)
3806 gtk_icon_source_free (source);
3807 return G_TOKEN_RIGHT_CURLY;
3811 if (gtk_icon_source_get_filename (source) ||
3812 gtk_icon_source_get_icon_name (source))
3814 gtk_icon_set_add_source (icon_set, source);
3815 *icon_set_valid = TRUE;
3817 gtk_icon_source_free (source);
3819 return G_TOKEN_NONE;
3823 gtk_rc_parse_stock (GtkRcContext *context,
3825 GtkRcStyle *rc_style,
3826 GtkIconFactory *factory)
3828 GtkIconSet *icon_set = NULL;
3829 gboolean icon_set_valid = FALSE;
3830 gchar *stock_id = NULL;
3833 token = g_scanner_get_next_token (scanner);
3834 if (token != GTK_RC_TOKEN_STOCK)
3835 return GTK_RC_TOKEN_STOCK;
3837 token = gtk_rc_parse_stock_id (scanner, &stock_id);
3838 if (token != G_TOKEN_NONE)
3841 token = g_scanner_get_next_token (scanner);
3842 if (token != G_TOKEN_EQUAL_SIGN)
3845 return G_TOKEN_EQUAL_SIGN;
3848 token = g_scanner_get_next_token (scanner);
3849 if (token != G_TOKEN_LEFT_CURLY)
3852 return G_TOKEN_LEFT_CURLY;
3855 token = g_scanner_peek_next_token (scanner);
3856 while (token != G_TOKEN_RIGHT_CURLY)
3858 if (icon_set == NULL)
3859 icon_set = gtk_icon_set_new ();
3861 token = gtk_rc_parse_icon_source (context,
3862 scanner, icon_set, &icon_set_valid);
3863 if (token != G_TOKEN_NONE)
3866 gtk_icon_set_unref (icon_set);
3870 token = g_scanner_get_next_token (scanner);
3872 if (token != G_TOKEN_COMMA &&
3873 token != G_TOKEN_RIGHT_CURLY)
3876 gtk_icon_set_unref (icon_set);
3877 return G_TOKEN_RIGHT_CURLY;
3884 gtk_icon_factory_add (factory,
3888 gtk_icon_set_unref (icon_set);
3893 return G_TOKEN_NONE;