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/.
29 #ifdef GDK_WINDOWING_X11
30 #include <X11/Xlocale.h> /* so we get the right setlocale */
39 #ifdef HAVE_SYS_PARAM_H
40 #include <sys/param.h>
52 #include <windows.h> /* For GetWindowsDirectory */
57 #include "gdkconfig.h"
60 #include "gtkbindings.h"
61 #include "gtkthemes.h"
63 #include "gtkiconfactory.h"
65 typedef struct _GtkRcSet GtkRcSet;
66 typedef struct _GtkRcNode GtkRcNode;
67 typedef struct _GtkRcFile GtkRcFile;
79 gchar *canonical_name;
83 static guint gtk_rc_style_hash (const char *name);
84 static gint gtk_rc_style_compare (const char *a,
86 static guint gtk_rc_styles_hash (const GSList *rc_styles);
87 static gint gtk_rc_styles_compare (const GSList *a,
89 static GtkRcStyle* gtk_rc_style_find (const char *name);
90 static GSList * gtk_rc_styles_match (GSList *rc_styles,
94 gchar *path_reversed);
95 static GtkStyle * gtk_rc_style_to_style (GtkRcStyle *rc_style);
96 static GtkStyle* gtk_rc_init_style (GSList *rc_styles);
97 static void gtk_rc_parse_file (const gchar *filename,
99 static void gtk_rc_parse_any (const gchar *input_name,
101 const gchar *input_string);
102 static guint gtk_rc_parse_statement (GScanner *scanner);
103 static guint gtk_rc_parse_style (GScanner *scanner);
104 static guint gtk_rc_parse_bg (GScanner *scanner,
106 static guint gtk_rc_parse_fg (GScanner *scanner,
108 static guint gtk_rc_parse_text (GScanner *scanner,
110 static guint gtk_rc_parse_base (GScanner *scanner,
112 static guint gtk_rc_parse_xthickness (GScanner *scanner,
114 static guint gtk_rc_parse_ythickness (GScanner *scanner,
116 static guint gtk_rc_parse_bg_pixmap (GScanner *scanner,
117 GtkRcStyle *rc_style);
118 static guint gtk_rc_parse_font (GScanner *scanner,
119 GtkRcStyle *rc_style);
120 static guint gtk_rc_parse_fontset (GScanner *scanner,
121 GtkRcStyle *rc_style);
122 static guint gtk_rc_parse_font_name (GScanner *scanner,
123 GtkRcStyle *rc_style);
124 static guint gtk_rc_parse_engine (GScanner *scanner,
125 GtkRcStyle **rc_style);
126 static guint gtk_rc_parse_pixmap_path (GScanner *scanner);
127 static void gtk_rc_parse_pixmap_path_string (gchar *pix_path);
128 static guint gtk_rc_parse_module_path (GScanner *scanner);
129 static void gtk_rc_parse_module_path_string (gchar *mod_path);
130 static guint gtk_rc_parse_im_module_path (GScanner *scanner);
131 static guint gtk_rc_parse_im_module_file (GScanner *scanner);
132 static guint gtk_rc_parse_path_pattern (GScanner *scanner);
133 static guint gtk_rc_parse_stock (GScanner *scanner,
134 GtkRcStyle *rc_style,
135 GtkIconFactory *factory);
136 static void gtk_rc_clear_hash_node (gpointer key,
139 static void gtk_rc_clear_styles (void);
140 static void gtk_rc_append_default_module_path (void);
141 static void gtk_rc_add_initial_default_files (void);
143 static void gtk_rc_style_init (GtkRcStyle *style);
144 static void gtk_rc_style_class_init (GtkRcStyleClass *klass);
145 static void gtk_rc_style_finalize (GObject *object);
146 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
148 static GtkRcStyle *gtk_rc_style_real_clone (GtkRcStyle *rc_style);
149 static GtkStyle * gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
151 static gpointer parent_class = NULL;
153 static const GScannerConfig gtk_rc_scanner_config =
157 ) /* cset_skip_characters */,
162 ) /* cset_identifier_first */,
167 ) /* cset_identifier_nth */,
168 ( "#\n" ) /* cpair_comment_single */,
170 TRUE /* case_sensitive */,
172 TRUE /* skip_comment_multi */,
173 TRUE /* skip_comment_single */,
174 TRUE /* scan_comment_multi */,
175 TRUE /* scan_identifier */,
176 FALSE /* scan_identifier_1char */,
177 FALSE /* scan_identifier_NULL */,
178 TRUE /* scan_symbols */,
179 TRUE /* scan_binary */,
180 TRUE /* scan_octal */,
181 TRUE /* scan_float */,
183 TRUE /* scan_hex_dollar */,
184 TRUE /* scan_string_sq */,
185 TRUE /* scan_string_dq */,
186 TRUE /* numbers_2_int */,
187 FALSE /* int_2_float */,
188 FALSE /* identifier_2_string */,
189 TRUE /* char_2_token */,
190 TRUE /* symbol_2_token */,
191 FALSE /* scope_0_fallback */,
199 { "include", GTK_RC_TOKEN_INCLUDE },
200 { "NORMAL", GTK_RC_TOKEN_NORMAL },
201 { "ACTIVE", GTK_RC_TOKEN_ACTIVE },
202 { "PRELIGHT", GTK_RC_TOKEN_PRELIGHT },
203 { "SELECTED", GTK_RC_TOKEN_SELECTED },
204 { "INSENSITIVE", GTK_RC_TOKEN_INSENSITIVE },
205 { "fg", GTK_RC_TOKEN_FG },
206 { "bg", GTK_RC_TOKEN_BG },
207 { "text", GTK_RC_TOKEN_TEXT },
208 { "base", GTK_RC_TOKEN_BASE },
209 { "xthickness", GTK_RC_TOKEN_XTHICKNESS },
210 { "ythickness", GTK_RC_TOKEN_YTHICKNESS },
211 { "font", GTK_RC_TOKEN_FONT },
212 { "fontset", GTK_RC_TOKEN_FONTSET },
213 { "font_name", GTK_RC_TOKEN_FONT_NAME },
214 { "bg_pixmap", GTK_RC_TOKEN_BG_PIXMAP },
215 { "pixmap_path", GTK_RC_TOKEN_PIXMAP_PATH },
216 { "style", GTK_RC_TOKEN_STYLE },
217 { "binding", GTK_RC_TOKEN_BINDING },
218 { "bind", GTK_RC_TOKEN_BIND },
219 { "widget", GTK_RC_TOKEN_WIDGET },
220 { "widget_class", GTK_RC_TOKEN_WIDGET_CLASS },
221 { "class", GTK_RC_TOKEN_CLASS },
222 { "lowest", GTK_RC_TOKEN_LOWEST },
223 { "gtk", GTK_RC_TOKEN_GTK },
224 { "application", GTK_RC_TOKEN_APPLICATION },
225 { "rc", GTK_RC_TOKEN_RC },
226 { "highest", GTK_RC_TOKEN_HIGHEST },
227 { "engine", GTK_RC_TOKEN_ENGINE },
228 { "module_path", GTK_RC_TOKEN_MODULE_PATH },
229 { "stock", GTK_RC_TOKEN_STOCK },
230 { "im_module_path", GTK_RC_TOKEN_IM_MODULE_PATH },
231 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
232 { "LTR", GTK_RC_TOKEN_LTR },
233 { "RTL", GTK_RC_TOKEN_RTL }
236 static const guint n_symbols = sizeof (symbols) / sizeof (symbols[0]);
238 static gchar *im_module_path = NULL;
239 static gchar *im_module_file = NULL;
241 static GHashTable *rc_style_ht = NULL;
242 static GHashTable *realized_style_ht = NULL;
243 static GSList *gtk_rc_sets_widget = NULL;
244 static GSList *gtk_rc_sets_widget_class = NULL;
245 static GSList *gtk_rc_sets_class = NULL;
247 #define GTK_RC_MAX_DEFAULT_FILES 128
248 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
249 static gboolean gtk_rc_auto_parse = TRUE;
251 #define GTK_RC_MAX_PIXMAP_PATHS 128
252 static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
253 #define GTK_RC_MAX_MODULE_PATHS 128
254 static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
256 /* A stack of directories for RC files we are parsing currently.
257 * these are implicitely added to the end of PIXMAP_PATHS
259 GSList *rc_dir_stack = NULL;
261 /* The files we have parsed, to reread later if necessary */
262 GSList *rc_files = NULL;
264 static GtkImageLoader image_loader = NULL;
266 /* RC file handling */
272 gtk_win32_get_installation_directory (void)
274 static gboolean been_here = FALSE;
275 static gchar gtk_installation_dir[200];
279 DWORD nbytes = sizeof (gtk_installation_dir);
282 return gtk_installation_dir;
286 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\GNU\\GTk+", 0,
287 KEY_QUERY_VALUE, ®_key) != ERROR_SUCCESS
288 || RegQueryValueEx (reg_key, "InstallationDirectory", 0,
289 &type, gtk_installation_dir, &nbytes) != ERROR_SUCCESS
292 /* Uh oh. Use the old hard-coded %WinDir%\GTk+ value */
293 GetWindowsDirectory (win_dir, sizeof (win_dir));
294 sprintf (gtk_installation_dir, "%s\\gtk+", win_dir);
298 RegCloseKey (reg_key);
300 return gtk_installation_dir;
304 get_themes_directory (void)
306 static gchar themes_dir[200];
308 sprintf (themes_dir, "%s\\themes", gtk_win32_get_installation_directory ());
315 gtk_rc_make_default_dir (const gchar *type)
320 var = getenv("GTK_EXE_PREFIX");
322 path = g_strdup_printf("%s%s%s", var, "/lib/gtk-2.0/" GTK_VERSION "/", type);
324 path = g_strdup_printf("%s%s%s", GTK_EXE_PREFIX, "/lib/gtk-2.0/" GTK_VERSION "/", type);
326 path = g_strdup_printf ("%s\\%s", get_themes_directory (), type);
333 gtk_rc_get_im_module_path (void)
335 gchar *result = g_getenv ("GTK_IM_MODULE_PATH");
340 result = im_module_path;
342 return gtk_rc_make_default_dir ("immodules");
345 return g_strdup (result);
349 gtk_rc_get_im_module_file (void)
351 gchar *result = g_getenv ("GTK_IM_MODULE_FILE");
356 result = im_module_file;
358 result = GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtk.immodules";
361 return g_strdup (result);
365 gtk_rc_get_theme_dir(void)
370 var = getenv("GTK_DATA_PREFIX");
372 path = g_strdup_printf("%s%s", var, "/share/themes");
374 path = g_strdup_printf("%s%s", GTK_DATA_PREFIX, "/share/themes");
376 path = g_strdup (get_themes_directory ());
383 gtk_rc_get_module_dir(void)
385 return gtk_rc_make_default_dir ("engines");
389 gtk_rc_append_default_module_path(void)
394 for (n = 0; module_path[n]; n++) ;
395 if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
399 var = getenv("GTK_EXE_PREFIX");
401 path = g_strdup_printf("%s%s", var, "/lib/gtk-2.0/" GTK_VERSION "/engines");
403 path = g_strdup_printf("%s%s", GTK_EXE_PREFIX, "/lib/gtk-2.0/" GTK_VERSION "/engines");
405 path = g_strdup_printf ("%s%s", get_themes_directory (), "\\engines");
407 module_path[n++] = path;
409 var = g_get_home_dir ();
413 /* Don't duplicate the directory separator, causes trouble at
416 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
417 sep = G_DIR_SEPARATOR_S;
420 /* This produces something like ~/.gtk-2.0/2.0/engines */
421 path = g_strdup_printf ("%s%s%s", var, sep,
422 ".gtk-2.0" G_DIR_SEPARATOR_S
423 GTK_VERSION G_DIR_SEPARATOR_S
425 module_path[n++] = path;
427 module_path[n] = NULL;
431 gtk_rc_add_initial_default_files (void)
433 static gint init = FALSE;
441 gtk_rc_default_files[0] = NULL;
444 var = g_getenv("GTK_RC_FILES");
447 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
451 gtk_rc_add_default_file (files[i]);
459 str = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
461 str = g_strdup_printf ("%s\\gtkrc", gtk_win32_get_installation_directory ());
464 gtk_rc_add_default_file (str);
467 var = g_get_home_dir ();
471 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
472 sep = G_DIR_SEPARATOR_S;
475 str = g_strdup_printf ("%s%s.gtkrc-2.0", var, sep);
476 gtk_rc_add_default_file (str);
483 gtk_rc_add_default_file (const gchar *file)
487 gtk_rc_add_initial_default_files ();
489 for (n = 0; gtk_rc_default_files[n]; n++) ;
490 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
493 gtk_rc_default_files[n++] = g_strdup (file);
494 gtk_rc_default_files[n] = NULL;
498 gtk_rc_set_default_files (gchar **files)
502 gtk_rc_add_initial_default_files ();
505 while (gtk_rc_default_files[i])
507 g_free (gtk_rc_default_files[i]);
511 gtk_rc_default_files[0] = NULL;
512 gtk_rc_auto_parse = FALSE;
515 while (files[i] != NULL)
517 gtk_rc_add_default_file (files[i]);
523 gtk_rc_get_default_files (void)
525 gtk_rc_add_initial_default_files ();
527 return gtk_rc_default_files;
530 /* The following routine is based on _nl_normalize_codeset from
531 * the GNU C library. Contributed by
533 * Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
534 * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
536 * Normalize codeset name. There is no standard for the codeset
537 * names. Normalization allows the user to use any of the common
541 _gtk_normalize_codeset (const char *codeset, int name_len)
549 for (cnt = 0; cnt < name_len; ++cnt)
550 if (isalnum (codeset[cnt]))
554 if (isalpha (codeset[cnt]))
558 retval = g_malloc ((only_digit ? 3 : 0) + len + 1);
562 strcpy (retval, "iso");
568 for (cnt = 0; cnt < name_len; ++cnt)
569 if (isalpha (codeset[cnt]))
570 *wp++ = isupper(codeset[cnt]) ? tolower (codeset[cnt]) : codeset[cnt];
571 else if (isdigit (codeset[cnt]))
572 *wp++ = codeset[cnt];
582 static gchar *locale_suffixes[3];
583 static gint n_locale_suffixes = 0;
587 static gboolean initted = FALSE;
596 locale = g_win32_getlocale ();
598 locale = setlocale (LC_CTYPE, NULL);
603 pixmap_path[0] = NULL;
604 module_path[0] = NULL;
605 gtk_rc_append_default_module_path();
607 gtk_rc_add_initial_default_files ();
609 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
611 /* Determine locale-specific suffixes for RC files
613 * We normalize the charset into a standard form,
614 * which has all '-' and '_' characters removed,
617 gchar *normalized_locale;
619 p = strchr (locale, '@');
620 length = p ? (p -locale) : strlen (locale);
622 p = strchr (locale, '.');
625 gchar *tmp1 = g_strndup (locale, p - locale + 1);
626 gchar *tmp2 = _gtk_normalize_codeset (p + 1, length - (p - locale + 1));
628 normalized_locale = g_strconcat (tmp1, tmp2, NULL);
632 locale_suffixes[n_locale_suffixes++] = g_strdup (normalized_locale);
636 normalized_locale = g_strndup (locale, length);
638 p = strchr (normalized_locale, '_');
641 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
642 length = p - normalized_locale;
645 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
647 g_free (normalized_locale);
652 while (gtk_rc_default_files[i] != NULL)
654 /* Try to find a locale specific RC file corresponding to
655 * to parse before the default file.
657 for (j=n_locale_suffixes-1; j>=0; j--)
659 gchar *name = g_strconcat (gtk_rc_default_files[i],
667 gtk_rc_parse (gtk_rc_default_files[i]);
673 gtk_rc_parse_string (const gchar *rc_string)
675 g_return_if_fail (rc_string != NULL);
677 gtk_rc_parse_any ("-", -1, rc_string);
681 gtk_rc_parse_file (const gchar *filename, gboolean reload)
683 GtkRcFile *rc_file = NULL;
687 g_return_if_fail (filename != NULL);
692 rc_file = tmp_list->data;
693 if (!strcmp (rc_file->name, filename))
696 tmp_list = tmp_list->next;
701 rc_file = g_new (GtkRcFile, 1);
702 rc_file->name = g_strdup (filename);
703 rc_file->canonical_name = NULL;
705 rc_file->reload = reload;
707 rc_files = g_slist_append (rc_files, rc_file);
710 if (!rc_file->canonical_name)
712 /* Get the absolute pathname */
714 if (g_path_is_absolute (rc_file->name))
715 rc_file->canonical_name = rc_file->name;
721 cwd = g_get_current_dir ();
723 str = g_string_new (cwd);
725 g_string_append_c (str, G_DIR_SEPARATOR);
726 g_string_append (str, rc_file->name);
728 rc_file->canonical_name = str->str;
729 g_string_free (str, FALSE);
733 if (!lstat (rc_file->canonical_name, &statbuf))
738 rc_file->mtime = statbuf.st_mtime;
740 fd = open (rc_file->canonical_name, O_RDONLY);
744 /* Temporarily push directory name for this file on
745 * a stack of directory names while parsing it
748 g_slist_prepend (rc_dir_stack,
749 g_path_get_dirname (rc_file->canonical_name));
750 gtk_rc_parse_any (filename, fd, NULL);
752 tmp_list = rc_dir_stack;
753 rc_dir_stack = rc_dir_stack->next;
755 g_free (tmp_list->data);
756 g_slist_free_1 (tmp_list);
763 gtk_rc_parse (const gchar *filename)
765 g_return_if_fail (filename != NULL);
767 gtk_rc_parse_file (filename, TRUE);
770 /* Handling of RC styles */
773 gtk_rc_style_get_type (void)
775 static GType object_type = 0;
779 static const GTypeInfo object_info =
781 sizeof (GtkRcStyleClass),
782 (GBaseInitFunc) NULL,
783 (GBaseFinalizeFunc) NULL,
784 (GClassInitFunc) gtk_rc_style_class_init,
785 NULL, /* class_finalize */
786 NULL, /* class_data */
789 (GInstanceInitFunc) gtk_rc_style_init,
792 object_type = g_type_register_static (G_TYPE_OBJECT,
801 gtk_rc_style_init (GtkRcStyle *style)
806 for (i = 0; i < 5; i++)
808 static const GdkColor init_color = { 0, 0, 0, 0, };
810 style->bg_pixmap_name[i] = NULL;
811 style->color_flags[i] = 0;
812 style->fg[i] = init_color;
813 style->bg[i] = init_color;
814 style->text[i] = init_color;
815 style->base[i] = init_color;
817 style->xthickness = -1;
818 style->ythickness = -1;
819 style->rc_style_lists = NULL;
823 gtk_rc_style_class_init (GtkRcStyleClass *klass)
825 GObjectClass *object_class = G_OBJECT_CLASS (klass);
827 parent_class = g_type_class_peek_parent (klass);
829 object_class->finalize = gtk_rc_style_finalize;
832 klass->clone = gtk_rc_style_real_clone;
833 klass->merge = gtk_rc_style_real_merge;
834 klass->create_style = gtk_rc_style_real_create_style;
837 /* Like g_slist_remove, but remove all copies of data */
839 gtk_rc_slist_remove_all (GSList *list,
850 if (tmp->data == data)
856 prev->next = tmp->next;
858 g_slist_free_1 (tmp);
876 gtk_rc_style_finalize (GObject *object)
879 GSList *tmp_list1, *tmp_list2;
880 GtkRcStyle *rc_style;
882 rc_style = GTK_RC_STYLE (object);
885 g_free (rc_style->name);
886 if (rc_style->font_desc)
887 pango_font_description_free (rc_style->font_desc);
889 for (i=0 ; i < 5 ; i++)
890 if (rc_style->bg_pixmap_name[i])
891 g_free (rc_style->bg_pixmap_name[i]);
893 /* Now remove all references to this rc_style from
896 tmp_list1 = rc_style->rc_style_lists;
899 GSList *rc_styles = tmp_list1->data;
900 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
901 gtk_style_unref (style);
903 /* Remove the list of styles from the other rc_styles
906 tmp_list2 = rc_styles;
909 GtkRcStyle *other_style = tmp_list2->data;
911 if (other_style != rc_style)
912 other_style->rc_style_lists =
913 gtk_rc_slist_remove_all (other_style->rc_style_lists, rc_styles);
915 tmp_list2 = tmp_list2->next;
918 /* And from the hash table itself
920 g_hash_table_remove (realized_style_ht, rc_styles);
921 g_slist_free (rc_styles);
923 tmp_list1 = tmp_list1->next;
926 g_slist_free (rc_style->rc_style_lists);
928 tmp_list1 = rc_style->icon_factories;
931 g_object_unref (G_OBJECT (tmp_list1->data));
933 tmp_list1 = tmp_list1->next;
936 g_slist_free (rc_style->icon_factories);
938 G_OBJECT_CLASS (parent_class)->finalize (object);
942 gtk_rc_style_new (void)
946 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
953 * @orig: the style to copy
955 * Make a copy of the specified #GtkRcStyle. This function
956 * will correctly copy an rc style that is a member of a class
957 * derived from #GtkRcStyle.
959 * Return value: the resulting #GtkRcStyle
962 gtk_rc_style_copy (GtkRcStyle *orig)
966 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
968 style = GTK_RC_STYLE_GET_CLASS (orig)->clone (orig);
969 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
975 gtk_rc_style_ref (GtkRcStyle *rc_style)
977 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
979 g_object_ref (G_OBJECT (rc_style));
983 gtk_rc_style_unref (GtkRcStyle *rc_style)
985 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
987 g_object_unref (G_OBJECT (rc_style));
991 gtk_rc_style_real_clone (GtkRcStyle *style)
993 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
997 gtk_rc_style_real_merge (GtkRcStyle *dest,
1002 for (i = 0; i < 5; i++)
1004 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1005 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1007 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1008 src->color_flags[i] & GTK_RC_FG)
1010 dest->fg[i] = src->fg[i];
1011 dest->color_flags[i] |= GTK_RC_FG;
1013 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1014 src->color_flags[i] & GTK_RC_BG)
1016 dest->bg[i] = src->bg[i];
1017 dest->color_flags[i] |= GTK_RC_BG;
1019 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1020 src->color_flags[i] & GTK_RC_TEXT)
1022 dest->text[i] = src->text[i];
1023 dest->color_flags[i] |= GTK_RC_TEXT;
1025 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1026 src->color_flags[i] & GTK_RC_BASE)
1028 dest->base[i] = src->base[i];
1029 dest->color_flags[i] |= GTK_RC_BASE;
1033 if (dest->xthickness < 0 && src->xthickness >= 0)
1034 dest->xthickness = src->xthickness;
1035 if (dest->ythickness < 0 && src->ythickness >= 0)
1036 dest->ythickness = src->ythickness;
1038 if (!dest->font_desc && src->font_desc)
1039 dest->font_desc = pango_font_description_copy (src->font_desc);
1043 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1045 return gtk_style_new ();
1049 gtk_rc_clear_hash_node (gpointer key,
1053 gtk_rc_style_unref (data);
1057 gtk_rc_free_rc_sets (GSList *slist)
1063 rc_set = slist->data;
1064 gtk_pattern_spec_free_segs (&rc_set->pspec);
1067 slist = slist->next;
1072 gtk_rc_clear_styles (void)
1074 /* Clear out all old rc_styles */
1078 g_hash_table_foreach (rc_style_ht, gtk_rc_clear_hash_node, NULL);
1079 g_hash_table_destroy (rc_style_ht);
1083 gtk_rc_free_rc_sets (gtk_rc_sets_widget);
1084 g_slist_free (gtk_rc_sets_widget);
1085 gtk_rc_sets_widget = NULL;
1087 gtk_rc_free_rc_sets (gtk_rc_sets_widget_class);
1088 g_slist_free (gtk_rc_sets_widget_class);
1089 gtk_rc_sets_widget_class = NULL;
1091 gtk_rc_free_rc_sets (gtk_rc_sets_class);
1092 g_slist_free (gtk_rc_sets_class);
1093 gtk_rc_sets_class = NULL;
1097 gtk_rc_reparse_all (void)
1100 gboolean mtime_modified = FALSE;
1103 struct stat statbuf;
1105 /* Check through and see if any of the RC's have had their
1106 * mtime modified. If so, reparse everything.
1108 tmp_list = rc_files;
1111 rc_file = tmp_list->data;
1113 if (!lstat (rc_file->name, &statbuf) &&
1114 (statbuf.st_mtime > rc_file->mtime))
1116 mtime_modified = TRUE;
1120 tmp_list = tmp_list->next;
1125 gtk_rc_clear_styles();
1127 tmp_list = rc_files;
1130 rc_file = tmp_list->data;
1131 if (rc_file->reload)
1132 gtk_rc_parse_file (rc_file->name, FALSE);
1134 tmp_list = tmp_list->next;
1138 return mtime_modified;
1142 gtk_rc_styles_match (GSList *rc_styles,
1146 gchar *path_reversed)
1153 rc_set = sets->data;
1156 if (gtk_pattern_match (&rc_set->pspec, path_length, path, path_reversed))
1157 rc_styles = g_slist_append (rc_styles, rc_set->rc_style);
1164 gtk_rc_get_style (GtkWidget *widget)
1166 GtkRcStyle *widget_rc_style;
1167 GSList *rc_styles = NULL;
1169 static guint rc_style_key_id = 0;
1171 /* We allow the specification of a single rc style to be bound
1172 * tightly to a widget, for application modifications
1174 if (!rc_style_key_id)
1175 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1177 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1180 if (widget_rc_style)
1181 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1183 if (gtk_rc_sets_widget)
1185 gchar *path, *path_reversed;
1188 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1189 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget, path_length, path, path_reversed);
1191 g_free (path_reversed);
1195 if (gtk_rc_sets_widget_class)
1197 gchar *path, *path_reversed;
1200 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1201 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget_class, path_length, path, path_reversed);
1203 g_free (path_reversed);
1206 if (gtk_rc_sets_class)
1210 type = GTK_OBJECT_TYPE (widget);
1213 gchar *path, *path_reversed;
1216 path = gtk_type_name (type);
1217 path_length = strlen (path);
1218 path_reversed = g_strdup (path);
1219 g_strreverse (path_reversed);
1221 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_class, path_length, path, path_reversed);
1222 g_free (path_reversed);
1224 type = gtk_type_parent (type);
1229 return gtk_rc_init_style (rc_styles);
1235 gtk_rc_add_rc_sets (GSList *slist,
1236 GtkRcStyle *rc_style,
1237 const char *pattern)
1239 GtkRcStyle *new_style;
1243 new_style = gtk_rc_style_new ();
1244 *new_style = *rc_style;
1245 new_style->name = g_strdup (rc_style->name);
1246 if (rc_style->font_desc)
1247 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1249 for (i = 0; i < 5; i++)
1250 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1252 rc_set = g_new (GtkRcSet, 1);
1253 gtk_pattern_spec_init (&rc_set->pspec, pattern);
1254 rc_set->rc_style = rc_style;
1256 return g_slist_prepend (slist, rc_set);
1260 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1261 const gchar *pattern)
1263 g_return_if_fail (rc_style != NULL);
1264 g_return_if_fail (pattern != NULL);
1266 gtk_rc_sets_widget = gtk_rc_add_rc_sets (gtk_rc_sets_widget, rc_style, pattern);
1270 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1271 const gchar *pattern)
1273 g_return_if_fail (rc_style != NULL);
1274 g_return_if_fail (pattern != NULL);
1276 gtk_rc_sets_widget_class = gtk_rc_add_rc_sets (gtk_rc_sets_widget_class, rc_style, pattern);
1280 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1281 const gchar *pattern)
1283 g_return_if_fail (rc_style != NULL);
1284 g_return_if_fail (pattern != NULL);
1286 gtk_rc_sets_class = gtk_rc_add_rc_sets (gtk_rc_sets_class, rc_style, pattern);
1290 gtk_rc_parse_any (const gchar *input_name,
1292 const gchar *input_string)
1298 scanner = g_scanner_new ((GScannerConfig *) >k_rc_scanner_config);
1302 g_assert (input_string == NULL);
1304 g_scanner_input_file (scanner, input_fd);
1308 g_assert (input_string != NULL);
1310 g_scanner_input_text (scanner, input_string, strlen (input_string));
1312 scanner->input_name = input_name;
1314 for (i = 0; i < n_symbols; i++)
1315 g_scanner_add_symbol (scanner, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1320 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1324 guint expected_token;
1326 expected_token = gtk_rc_parse_statement (scanner);
1328 if (expected_token != G_TOKEN_NONE)
1335 if (scanner->scope_id == 0)
1337 /* if we are in scope 0, we know the symbol names
1338 * that are associated with certaintoken values.
1339 * so we look them up to make the error messages
1342 if (expected_token > GTK_RC_TOKEN_INVALID &&
1343 expected_token < GTK_RC_TOKEN_LAST)
1345 for (i = 0; i < n_symbols; i++)
1346 if (symbols[i].token == expected_token)
1347 msg = symbols[i].name;
1349 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1351 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1352 scanner->token < GTK_RC_TOKEN_LAST)
1354 symbol_name = "???";
1355 for (i = 0; i < n_symbols; i++)
1356 if (symbols[i].token == scanner->token)
1357 symbol_name = symbols[i].name;
1360 g_scanner_unexp_token (scanner,
1373 g_scanner_destroy (scanner);
1377 gtk_rc_styles_hash (const GSList *rc_styles)
1384 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1385 rc_styles = rc_styles->next;
1392 gtk_rc_styles_compare (const GSList *a,
1397 if (a->data != b->data)
1407 gtk_rc_style_hash (const char *name)
1413 result += (result << 3) + *name++;
1419 gtk_rc_style_compare (const char *a,
1422 return (strcmp (a, b) == 0);
1426 gtk_rc_style_find (const char *name)
1429 return g_hash_table_lookup (rc_style_ht, (gpointer) name);
1435 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1439 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1441 style->rc_style = rc_style;
1443 gtk_rc_style_ref (rc_style);
1445 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1450 /* Reuses or frees rc_styles */
1452 gtk_rc_init_style (GSList *rc_styles)
1454 GtkStyle *style = NULL;
1457 g_return_val_if_fail (rc_styles != NULL, NULL);
1459 if (!realized_style_ht)
1460 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1461 (GCompareFunc) gtk_rc_styles_compare);
1463 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1467 GtkRcStyle *base_style = NULL;
1468 GtkRcStyle *proto_style;
1469 GtkRcStyleClass *proto_style_class;
1471 GType rc_style_type = GTK_TYPE_RC_STYLE;
1473 /* Find the first derived style in the list, and use that to
1474 * create the merged style. If we only have raw GtkRcStyles, use
1475 * the first style to create the merged style.
1477 base_style = rc_styles->data;
1478 tmp_styles = rc_styles;
1481 GtkRcStyle *rc_style = tmp_styles->data;
1483 if (G_OBJECT_TYPE (rc_style) != rc_style_type)
1485 base_style = rc_style;
1489 tmp_styles = tmp_styles->next;
1492 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1493 proto_style = proto_style_class->clone (base_style);
1495 tmp_styles = rc_styles;
1498 GtkRcStyle *rc_style = tmp_styles->data;
1501 proto_style_class->merge (proto_style, rc_style);
1503 /* Point from each rc_style to the list of styles */
1504 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1505 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1507 factories = g_slist_copy (rc_style->icon_factories);
1513 while (iter != NULL)
1515 g_object_ref (G_OBJECT (iter->data));
1516 iter = g_slist_next (iter);
1519 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1524 tmp_styles = tmp_styles->next;
1527 for (i = 0; i < 5; i++)
1528 if (proto_style->bg_pixmap_name[i] &&
1529 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
1531 g_free (proto_style->bg_pixmap_name[i]);
1532 proto_style->bg_pixmap_name[i] = NULL;
1535 style = gtk_rc_style_to_style (proto_style);
1536 gtk_rc_style_unref (proto_style);
1538 g_hash_table_insert (realized_style_ht, rc_styles, style);
1541 g_slist_free (rc_styles);
1546 /*********************
1547 * Parsing functions *
1548 *********************/
1551 gtk_rc_parse_statement (GScanner *scanner)
1555 token = g_scanner_peek_next_token (scanner);
1559 case GTK_RC_TOKEN_INCLUDE:
1560 token = g_scanner_get_next_token (scanner);
1561 if (token != GTK_RC_TOKEN_INCLUDE)
1562 return GTK_RC_TOKEN_INCLUDE;
1564 token = g_scanner_get_next_token (scanner);
1565 if (token != G_TOKEN_STRING)
1566 return G_TOKEN_STRING;
1568 gtk_rc_parse_file (scanner->value.v_string, FALSE);
1569 return G_TOKEN_NONE;
1571 case GTK_RC_TOKEN_STYLE:
1572 return gtk_rc_parse_style (scanner);
1574 case GTK_RC_TOKEN_BINDING:
1575 return gtk_binding_parse_binding (scanner);
1577 case GTK_RC_TOKEN_PIXMAP_PATH:
1578 return gtk_rc_parse_pixmap_path (scanner);
1580 case GTK_RC_TOKEN_WIDGET:
1581 return gtk_rc_parse_path_pattern (scanner);
1583 case GTK_RC_TOKEN_WIDGET_CLASS:
1584 return gtk_rc_parse_path_pattern (scanner);
1586 case GTK_RC_TOKEN_CLASS:
1587 return gtk_rc_parse_path_pattern (scanner);
1589 case GTK_RC_TOKEN_MODULE_PATH:
1590 return gtk_rc_parse_module_path (scanner);
1592 case GTK_RC_TOKEN_IM_MODULE_PATH:
1593 return gtk_rc_parse_im_module_path (scanner);
1595 case GTK_RC_TOKEN_IM_MODULE_FILE:
1596 return gtk_rc_parse_im_module_file (scanner);
1599 g_scanner_get_next_token (scanner);
1600 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
1605 gtk_rc_parse_style (GScanner *scanner)
1607 GtkRcStyle *rc_style;
1608 GtkRcStyle *parent_style;
1612 GtkIconFactory *our_factory = NULL;
1614 token = g_scanner_get_next_token (scanner);
1615 if (token != GTK_RC_TOKEN_STYLE)
1616 return GTK_RC_TOKEN_STYLE;
1618 token = g_scanner_get_next_token (scanner);
1619 if (token != G_TOKEN_STRING)
1620 return G_TOKEN_STRING;
1623 rc_style = gtk_rc_style_find (scanner->value.v_string);
1625 /* If there's a list, its first member is always the factory belonging
1628 if (rc_style && rc_style->icon_factories)
1629 our_factory = rc_style->icon_factories->data;
1634 rc_style = gtk_rc_style_new ();
1635 rc_style->name = g_strdup (scanner->value.v_string);
1637 for (i = 0; i < 5; i++)
1638 rc_style->bg_pixmap_name[i] = NULL;
1640 for (i = 0; i < 5; i++)
1641 rc_style->color_flags[i] = 0;
1644 token = g_scanner_peek_next_token (scanner);
1645 if (token == G_TOKEN_EQUAL_SIGN)
1647 token = g_scanner_get_next_token (scanner);
1649 token = g_scanner_get_next_token (scanner);
1650 if (token != G_TOKEN_STRING)
1655 return G_TOKEN_STRING;
1658 parent_style = gtk_rc_style_find (scanner->value.v_string);
1663 for (i = 0; i < 5; i++)
1665 rc_style->color_flags[i] = parent_style->color_flags[i];
1666 rc_style->fg[i] = parent_style->fg[i];
1667 rc_style->bg[i] = parent_style->bg[i];
1668 rc_style->text[i] = parent_style->text[i];
1669 rc_style->base[i] = parent_style->base[i];
1672 rc_style->xthickness = parent_style->xthickness;
1673 rc_style->ythickness = parent_style->ythickness;
1675 if (parent_style->font_desc)
1677 if (rc_style->font_desc)
1678 pango_font_description_free (rc_style->font_desc);
1679 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
1682 for (i = 0; i < 5; i++)
1684 if (rc_style->bg_pixmap_name[i])
1685 g_free (rc_style->bg_pixmap_name[i]);
1686 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
1689 /* Append parent's factories, adding a ref to them */
1690 if (parent_style->icon_factories != NULL)
1692 /* Add a factory for ourselves if we have none,
1693 * in case we end up defining more stock icons.
1694 * I see no real way around this; we need to maintain
1695 * the invariant that the first factory in the list
1696 * is always our_factory, the one belonging to us,
1697 * and if we put parent factories in the list we can't
1698 * do that if the style is reopened.
1700 if (our_factory == NULL)
1702 our_factory = gtk_icon_factory_new ();
1703 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
1707 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
1708 g_slist_copy (parent_style->icon_factories));
1710 factories = parent_style->icon_factories;
1711 while (factories != NULL)
1713 g_object_ref (G_OBJECT (factories->data));
1714 factories = factories->next;
1720 token = g_scanner_get_next_token (scanner);
1721 if (token != G_TOKEN_LEFT_CURLY)
1726 return G_TOKEN_LEFT_CURLY;
1729 token = g_scanner_peek_next_token (scanner);
1730 while (token != G_TOKEN_RIGHT_CURLY)
1734 case GTK_RC_TOKEN_BG:
1735 token = gtk_rc_parse_bg (scanner, rc_style);
1737 case GTK_RC_TOKEN_FG:
1738 token = gtk_rc_parse_fg (scanner, rc_style);
1740 case GTK_RC_TOKEN_TEXT:
1741 token = gtk_rc_parse_text (scanner, rc_style);
1743 case GTK_RC_TOKEN_BASE:
1744 token = gtk_rc_parse_base (scanner, rc_style);
1746 case GTK_RC_TOKEN_XTHICKNESS:
1747 token = gtk_rc_parse_xthickness (scanner, rc_style);
1749 case GTK_RC_TOKEN_YTHICKNESS:
1750 token = gtk_rc_parse_ythickness (scanner, rc_style);
1752 case GTK_RC_TOKEN_BG_PIXMAP:
1753 token = gtk_rc_parse_bg_pixmap (scanner, rc_style);
1755 case GTK_RC_TOKEN_FONT:
1756 token = gtk_rc_parse_font (scanner, rc_style);
1758 case GTK_RC_TOKEN_FONTSET:
1759 token = gtk_rc_parse_fontset (scanner, rc_style);
1761 case GTK_RC_TOKEN_FONT_NAME:
1762 token = gtk_rc_parse_font_name (scanner, rc_style);
1764 case GTK_RC_TOKEN_ENGINE:
1765 token = gtk_rc_parse_engine (scanner, &rc_style);
1767 case GTK_RC_TOKEN_STOCK:
1768 if (our_factory == NULL)
1770 our_factory = gtk_icon_factory_new ();
1771 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
1774 token = gtk_rc_parse_stock (scanner, rc_style, our_factory);
1777 g_scanner_get_next_token (scanner);
1778 token = G_TOKEN_RIGHT_CURLY;
1782 if (token != G_TOKEN_NONE)
1786 if (rc_style->font_desc)
1787 pango_font_description_free (rc_style->font_desc);
1789 for (i = 0; i < 5; i++)
1790 if (rc_style->bg_pixmap_name[i])
1791 g_free (rc_style->bg_pixmap_name[i]);
1796 token = g_scanner_peek_next_token (scanner);
1799 token = g_scanner_get_next_token (scanner);
1800 if (token != G_TOKEN_RIGHT_CURLY)
1804 if (rc_style->font_desc)
1805 pango_font_description_free (rc_style->font_desc);
1807 for (i = 0; i < 5; i++)
1808 if (rc_style->bg_pixmap_name[i])
1809 g_free (rc_style->bg_pixmap_name[i]);
1813 return G_TOKEN_RIGHT_CURLY;
1819 rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
1820 (GCompareFunc) gtk_rc_style_compare);
1822 g_hash_table_insert (rc_style_ht, rc_style->name, rc_style);
1825 return G_TOKEN_NONE;
1829 gtk_rc_parse_bg (GScanner *scanner,
1835 token = g_scanner_get_next_token (scanner);
1836 if (token != GTK_RC_TOKEN_BG)
1837 return GTK_RC_TOKEN_BG;
1839 token = gtk_rc_parse_state (scanner, &state);
1840 if (token != G_TOKEN_NONE)
1843 token = g_scanner_get_next_token (scanner);
1844 if (token != G_TOKEN_EQUAL_SIGN)
1845 return G_TOKEN_EQUAL_SIGN;
1847 style->color_flags[state] |= GTK_RC_BG;
1848 return gtk_rc_parse_color (scanner, &style->bg[state]);
1852 gtk_rc_parse_fg (GScanner *scanner,
1858 token = g_scanner_get_next_token (scanner);
1859 if (token != GTK_RC_TOKEN_FG)
1860 return GTK_RC_TOKEN_FG;
1862 token = gtk_rc_parse_state (scanner, &state);
1863 if (token != G_TOKEN_NONE)
1866 token = g_scanner_get_next_token (scanner);
1867 if (token != G_TOKEN_EQUAL_SIGN)
1868 return G_TOKEN_EQUAL_SIGN;
1870 style->color_flags[state] |= GTK_RC_FG;
1871 return gtk_rc_parse_color (scanner, &style->fg[state]);
1875 gtk_rc_parse_text (GScanner *scanner,
1881 token = g_scanner_get_next_token (scanner);
1882 if (token != GTK_RC_TOKEN_TEXT)
1883 return GTK_RC_TOKEN_TEXT;
1885 token = gtk_rc_parse_state (scanner, &state);
1886 if (token != G_TOKEN_NONE)
1889 token = g_scanner_get_next_token (scanner);
1890 if (token != G_TOKEN_EQUAL_SIGN)
1891 return G_TOKEN_EQUAL_SIGN;
1893 style->color_flags[state] |= GTK_RC_TEXT;
1894 return gtk_rc_parse_color (scanner, &style->text[state]);
1898 gtk_rc_parse_base (GScanner *scanner,
1904 token = g_scanner_get_next_token (scanner);
1905 if (token != GTK_RC_TOKEN_BASE)
1906 return GTK_RC_TOKEN_BASE;
1908 token = gtk_rc_parse_state (scanner, &state);
1909 if (token != G_TOKEN_NONE)
1912 token = g_scanner_get_next_token (scanner);
1913 if (token != G_TOKEN_EQUAL_SIGN)
1914 return G_TOKEN_EQUAL_SIGN;
1916 style->color_flags[state] |= GTK_RC_BASE;
1917 return gtk_rc_parse_color (scanner, &style->base[state]);
1921 gtk_rc_parse_xthickness (GScanner *scanner,
1924 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
1925 return GTK_RC_TOKEN_XTHICKNESS;
1927 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
1928 return G_TOKEN_EQUAL_SIGN;
1930 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
1933 style->xthickness = scanner->value.v_int;
1935 return G_TOKEN_NONE;
1939 gtk_rc_parse_ythickness (GScanner *scanner,
1942 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
1943 return GTK_RC_TOKEN_YTHICKNESS;
1945 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
1946 return G_TOKEN_EQUAL_SIGN;
1948 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
1951 style->ythickness = scanner->value.v_int;
1953 return G_TOKEN_NONE;
1957 gtk_rc_parse_bg_pixmap (GScanner *scanner,
1958 GtkRcStyle *rc_style)
1964 token = g_scanner_get_next_token (scanner);
1965 if (token != GTK_RC_TOKEN_BG_PIXMAP)
1966 return GTK_RC_TOKEN_BG_PIXMAP;
1968 token = gtk_rc_parse_state (scanner, &state);
1969 if (token != G_TOKEN_NONE)
1972 token = g_scanner_get_next_token (scanner);
1973 if (token != G_TOKEN_EQUAL_SIGN)
1974 return G_TOKEN_EQUAL_SIGN;
1976 token = g_scanner_get_next_token (scanner);
1977 if (token != G_TOKEN_STRING)
1978 return G_TOKEN_STRING;
1980 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
1981 (strcmp (scanner->value.v_string, "<none>") == 0))
1982 pixmap_file = g_strdup (scanner->value.v_string);
1984 pixmap_file = gtk_rc_find_pixmap_in_path (scanner, scanner->value.v_string);
1988 if (rc_style->bg_pixmap_name[state])
1989 g_free (rc_style->bg_pixmap_name[state]);
1990 rc_style->bg_pixmap_name[state] = pixmap_file;
1993 return G_TOKEN_NONE;
1997 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2002 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s", dir, pixmap_file);
2004 fd = open (buf, O_RDONLY);
2017 gtk_rc_find_pixmap_in_path (GScanner *scanner,
2018 const gchar *pixmap_file)
2024 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (pixmap_path[i] != NULL); i++)
2026 filename = gtk_rc_check_pixmap_dir (pixmap_path[i], pixmap_file);
2031 tmp_list = rc_dir_stack;
2034 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2038 tmp_list = tmp_list->next;
2042 g_warning (_("Unable to locate image file in pixmap_path: \"%s\" line %d"),
2043 pixmap_file, scanner->line);
2045 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2052 gtk_rc_find_module_in_path (const gchar *module_file)
2058 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2060 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s",
2061 module_path[i], module_file);
2063 fd = open (buf, O_RDONLY);
2077 gtk_rc_parse_font (GScanner *scanner,
2078 GtkRcStyle *rc_style)
2082 token = g_scanner_get_next_token (scanner);
2083 if (token != GTK_RC_TOKEN_FONT)
2084 return GTK_RC_TOKEN_FONT;
2086 token = g_scanner_get_next_token (scanner);
2087 if (token != G_TOKEN_EQUAL_SIGN)
2088 return G_TOKEN_EQUAL_SIGN;
2090 token = g_scanner_get_next_token (scanner);
2091 if (token != G_TOKEN_STRING)
2092 return G_TOKEN_STRING;
2094 /* Ignore, do nothing */
2096 return G_TOKEN_NONE;
2100 gtk_rc_parse_fontset (GScanner *scanner,
2101 GtkRcStyle *rc_style)
2105 token = g_scanner_get_next_token (scanner);
2106 if (token != GTK_RC_TOKEN_FONTSET)
2107 return GTK_RC_TOKEN_FONTSET;
2109 token = g_scanner_get_next_token (scanner);
2110 if (token != G_TOKEN_EQUAL_SIGN)
2111 return G_TOKEN_EQUAL_SIGN;
2113 token = g_scanner_get_next_token (scanner);
2114 if (token != G_TOKEN_STRING)
2115 return G_TOKEN_STRING;
2117 /* Do nothing - silently ignore */
2119 return G_TOKEN_NONE;
2123 gtk_rc_parse_font_name (GScanner *scanner,
2124 GtkRcStyle *rc_style)
2128 token = g_scanner_get_next_token (scanner);
2129 if (token != GTK_RC_TOKEN_FONT_NAME)
2130 return GTK_RC_TOKEN_FONT;
2132 token = g_scanner_get_next_token (scanner);
2133 if (token != G_TOKEN_EQUAL_SIGN)
2134 return G_TOKEN_EQUAL_SIGN;
2136 token = g_scanner_get_next_token (scanner);
2137 if (token != G_TOKEN_STRING)
2138 return G_TOKEN_STRING;
2140 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2142 return G_TOKEN_NONE;
2146 gtk_rc_parse_engine (GScanner *scanner,
2147 GtkRcStyle **rc_style)
2150 GtkThemeEngine *engine;
2151 guint result = G_TOKEN_NONE;
2152 GtkRcStyle *new_style = NULL;
2153 gboolean parsed_curlies = FALSE;
2155 token = g_scanner_get_next_token (scanner);
2156 if (token != GTK_RC_TOKEN_ENGINE)
2157 return GTK_RC_TOKEN_ENGINE;
2159 token = g_scanner_get_next_token (scanner);
2160 if (token != G_TOKEN_STRING)
2161 return G_TOKEN_STRING;
2163 engine = gtk_theme_engine_get (scanner->value.v_string);
2165 token = g_scanner_get_next_token (scanner);
2166 if (token != G_TOKEN_LEFT_CURLY)
2167 return G_TOKEN_LEFT_CURLY;
2171 GtkRcStyleClass *new_class;
2173 new_style = gtk_theme_engine_create_rc_style (engine);
2174 g_type_module_unuse (G_TYPE_MODULE (engine));
2176 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
2178 new_class->merge (new_style, *rc_style);
2179 if ((*rc_style)->name)
2180 new_style->name = g_strdup ((*rc_style)->name);
2182 if (new_class->parse)
2184 parsed_curlies = TRUE;
2185 result = new_class->parse (new_style, scanner);
2187 if (result != G_TOKEN_NONE)
2189 g_object_unref (G_OBJECT (new_style));
2195 if (!parsed_curlies)
2197 /* Skip over remainder, looking for nested {}'s
2201 result = G_TOKEN_RIGHT_CURLY;
2202 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
2204 if (token == G_TOKEN_LEFT_CURLY)
2206 else if (token == G_TOKEN_RIGHT_CURLY)
2211 result = G_TOKEN_NONE;
2219 g_object_unref (G_OBJECT (*rc_style));
2220 *rc_style = new_style;
2227 gtk_rc_parse_state (GScanner *scanner,
2228 GtkStateType *state)
2233 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2234 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
2236 /* we don't know where we got called from, so we reset the scope here.
2237 * if we bail out due to errors, we *don't* reset the scope, so the
2238 * error messaging code can make sense of our tokens.
2240 old_scope = g_scanner_set_scope (scanner, 0);
2242 token = g_scanner_get_next_token (scanner);
2243 if (token != G_TOKEN_LEFT_BRACE)
2244 return G_TOKEN_LEFT_BRACE;
2246 token = g_scanner_get_next_token (scanner);
2249 case GTK_RC_TOKEN_ACTIVE:
2250 *state = GTK_STATE_ACTIVE;
2252 case GTK_RC_TOKEN_INSENSITIVE:
2253 *state = GTK_STATE_INSENSITIVE;
2255 case GTK_RC_TOKEN_NORMAL:
2256 *state = GTK_STATE_NORMAL;
2258 case GTK_RC_TOKEN_PRELIGHT:
2259 *state = GTK_STATE_PRELIGHT;
2261 case GTK_RC_TOKEN_SELECTED:
2262 *state = GTK_STATE_SELECTED;
2265 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
2268 token = g_scanner_get_next_token (scanner);
2269 if (token != G_TOKEN_RIGHT_BRACE)
2270 return G_TOKEN_RIGHT_BRACE;
2272 g_scanner_set_scope (scanner, old_scope);
2274 return G_TOKEN_NONE;
2278 gtk_rc_parse_priority (GScanner *scanner,
2279 GtkPathPriorityType *priority)
2284 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2285 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
2287 /* we don't know where we got called from, so we reset the scope here.
2288 * if we bail out due to errors, we *don't* reset the scope, so the
2289 * error messaging code can make sense of our tokens.
2291 old_scope = g_scanner_set_scope (scanner, 0);
2293 token = g_scanner_get_next_token (scanner);
2297 token = g_scanner_get_next_token (scanner);
2300 case GTK_RC_TOKEN_LOWEST:
2301 *priority = GTK_PATH_PRIO_LOWEST;
2303 case GTK_RC_TOKEN_GTK:
2304 *priority = GTK_PATH_PRIO_GTK;
2306 case GTK_RC_TOKEN_APPLICATION:
2307 *priority = GTK_PATH_PRIO_APPLICATION;
2309 case GTK_RC_TOKEN_RC:
2310 *priority = GTK_PATH_PRIO_RC;
2312 case GTK_RC_TOKEN_HIGHEST:
2313 *priority = GTK_PATH_PRIO_HIGHEST;
2316 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
2319 g_scanner_set_scope (scanner, old_scope);
2321 return G_TOKEN_NONE;
2325 gtk_rc_parse_color (GScanner *scanner,
2330 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2332 /* we don't need to set our own scop here, because
2333 * we don't need own symbols
2336 token = g_scanner_get_next_token (scanner);
2345 case G_TOKEN_LEFT_CURLY:
2346 token = g_scanner_get_next_token (scanner);
2347 if (token == G_TOKEN_INT)
2348 token_int = scanner->value.v_int;
2349 else if (token == G_TOKEN_FLOAT)
2350 token_int = scanner->value.v_float * 65535.0;
2352 return G_TOKEN_FLOAT;
2353 color->red = CLAMP (token_int, 0, 65535);
2355 token = g_scanner_get_next_token (scanner);
2356 if (token != G_TOKEN_COMMA)
2357 return G_TOKEN_COMMA;
2359 token = g_scanner_get_next_token (scanner);
2360 if (token == G_TOKEN_INT)
2361 token_int = scanner->value.v_int;
2362 else if (token == G_TOKEN_FLOAT)
2363 token_int = scanner->value.v_float * 65535.0;
2365 return G_TOKEN_FLOAT;
2366 color->green = CLAMP (token_int, 0, 65535);
2368 token = g_scanner_get_next_token (scanner);
2369 if (token != G_TOKEN_COMMA)
2370 return G_TOKEN_COMMA;
2372 token = g_scanner_get_next_token (scanner);
2373 if (token == G_TOKEN_INT)
2374 token_int = scanner->value.v_int;
2375 else if (token == G_TOKEN_FLOAT)
2376 token_int = scanner->value.v_float * 65535.0;
2378 return G_TOKEN_FLOAT;
2379 color->blue = CLAMP (token_int, 0, 65535);
2381 token = g_scanner_get_next_token (scanner);
2382 if (token != G_TOKEN_RIGHT_CURLY)
2383 return G_TOKEN_RIGHT_CURLY;
2384 return G_TOKEN_NONE;
2386 case G_TOKEN_STRING:
2387 if (scanner->value.v_string[0] != '#')
2388 return G_TOKEN_STRING;
2390 length = strlen (scanner->value.v_string) - 1;
2391 if (((length % 3) != 0) || (length > 12))
2392 return G_TOKEN_STRING;
2395 for (i = 0, j = 1; i < length; i++, j++)
2396 buf[i] = scanner->value.v_string[j];
2399 sscanf (buf, "%x", &temp);
2402 for (i = 0; i < length; i++, j++)
2403 buf[i] = scanner->value.v_string[j];
2406 sscanf (buf, "%x", &temp);
2407 color->green = temp;
2409 for (i = 0; i < length; i++, j++)
2410 buf[i] = scanner->value.v_string[j];
2413 sscanf (buf, "%x", &temp);
2419 color->green *= 4369;
2420 color->blue *= 4369;
2422 else if (length == 2)
2425 color->green *= 257;
2428 else if (length == 3)
2434 return G_TOKEN_NONE;
2437 return G_TOKEN_STRING;
2442 gtk_rc_parse_pixmap_path (GScanner *scanner)
2446 token = g_scanner_get_next_token (scanner);
2447 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
2448 return GTK_RC_TOKEN_PIXMAP_PATH;
2450 token = g_scanner_get_next_token (scanner);
2451 if (token != G_TOKEN_STRING)
2452 return G_TOKEN_STRING;
2454 gtk_rc_parse_pixmap_path_string (scanner->value.v_string);
2456 return G_TOKEN_NONE;
2460 gtk_rc_parse_pixmap_path_string (gchar *pix_path)
2464 gint start_offset = 0;
2468 /* free the old one, or just add to the old one ? */
2469 for (path_num=0; pixmap_path[path_num]; path_num++)
2471 g_free (pixmap_path[path_num]);
2472 pixmap_path[path_num] = NULL;
2477 path_len = strlen (pix_path);
2479 buf = g_strdup (pix_path);
2481 for (end_offset = 0; end_offset <= path_len; end_offset++)
2483 if ((buf[end_offset] == G_SEARCHPATH_SEPARATOR) ||
2484 (end_offset == path_len))
2486 buf[end_offset] = '\0';
2487 pixmap_path[path_num] = g_strdup (buf + start_offset);
2489 pixmap_path[path_num] = NULL;
2490 start_offset = end_offset + 1;
2497 gtk_rc_parse_module_path (GScanner *scanner)
2501 token = g_scanner_get_next_token (scanner);
2502 if (token != GTK_RC_TOKEN_MODULE_PATH)
2503 return GTK_RC_TOKEN_MODULE_PATH;
2505 token = g_scanner_get_next_token (scanner);
2506 if (token != G_TOKEN_STRING)
2507 return G_TOKEN_STRING;
2509 gtk_rc_parse_module_path_string (scanner->value.v_string);
2511 return G_TOKEN_NONE;
2515 gtk_rc_parse_im_module_path (GScanner *scanner)
2519 token = g_scanner_get_next_token (scanner);
2520 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
2521 return GTK_RC_TOKEN_IM_MODULE_FILE;
2523 token = g_scanner_get_next_token (scanner);
2524 if (token != G_TOKEN_STRING)
2525 return G_TOKEN_STRING;
2528 g_free (im_module_path);
2530 im_module_path = g_strdup (scanner->value.v_string);
2532 return G_TOKEN_NONE;
2536 gtk_rc_parse_im_module_file (GScanner *scanner)
2540 token = g_scanner_get_next_token (scanner);
2541 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
2542 return GTK_RC_TOKEN_IM_MODULE_FILE;
2544 token = g_scanner_get_next_token (scanner);
2545 if (token != G_TOKEN_STRING)
2546 return G_TOKEN_STRING;
2549 g_free (im_module_file);
2551 im_module_file = g_strdup (scanner->value.v_string);
2553 return G_TOKEN_NONE;
2557 gtk_rc_parse_module_path_string (gchar *mod_path)
2561 gint start_offset = 0;
2565 /* free the old one, or just add to the old one ? */
2566 for (path_num=0; module_path[path_num]; path_num++)
2568 g_free (module_path[path_num]);
2569 module_path[path_num] = NULL;
2574 path_len = strlen (mod_path);
2576 buf = g_strdup (mod_path);
2578 for (end_offset = 0; end_offset <= path_len; end_offset++)
2580 if ((buf[end_offset] == G_SEARCHPATH_SEPARATOR) ||
2581 (end_offset == path_len))
2583 buf[end_offset] = '\0';
2584 module_path[path_num] = g_strdup (buf + start_offset);
2586 module_path[path_num] = NULL;
2587 start_offset = end_offset + 1;
2591 gtk_rc_append_default_module_path();
2595 gtk_rc_parse_path_pattern (GScanner *scanner)
2598 GtkPathType path_type;
2600 gboolean is_binding;
2601 GtkPathPriorityType priority = GTK_PATH_PRIO_RC;
2603 token = g_scanner_get_next_token (scanner);
2606 case GTK_RC_TOKEN_WIDGET:
2607 path_type = GTK_PATH_WIDGET;
2609 case GTK_RC_TOKEN_WIDGET_CLASS:
2610 path_type = GTK_PATH_WIDGET_CLASS;
2612 case GTK_RC_TOKEN_CLASS:
2613 path_type = GTK_PATH_CLASS;
2616 return GTK_RC_TOKEN_WIDGET_CLASS;
2619 token = g_scanner_get_next_token (scanner);
2620 if (token != G_TOKEN_STRING)
2621 return G_TOKEN_STRING;
2623 pattern = g_strdup (scanner->value.v_string);
2625 token = g_scanner_get_next_token (scanner);
2626 if (token == GTK_RC_TOKEN_STYLE)
2628 else if (token == GTK_RC_TOKEN_BINDING)
2631 if (g_scanner_peek_next_token (scanner) == ':')
2633 token = gtk_rc_parse_priority (scanner, &priority);
2634 if (token != G_TOKEN_NONE)
2644 return GTK_RC_TOKEN_STYLE;
2647 token = g_scanner_get_next_token (scanner);
2648 if (token != G_TOKEN_STRING)
2651 return G_TOKEN_STRING;
2656 GtkBindingSet *binding;
2658 binding = gtk_binding_set_find (scanner->value.v_string);
2662 return G_TOKEN_STRING;
2664 gtk_binding_set_add_path (binding, path_type, pattern, priority);
2668 GtkRcStyle *rc_style;
2671 rc_style = gtk_rc_style_find (scanner->value.v_string);
2676 return G_TOKEN_STRING;
2679 rc_set = g_new (GtkRcSet, 1);
2680 gtk_pattern_spec_init (&rc_set->pspec, pattern);
2681 rc_set->rc_style = rc_style;
2683 if (path_type == GTK_PATH_WIDGET)
2684 gtk_rc_sets_widget = g_slist_prepend (gtk_rc_sets_widget, rc_set);
2685 else if (path_type == GTK_PATH_WIDGET_CLASS)
2686 gtk_rc_sets_widget_class = g_slist_prepend (gtk_rc_sets_widget_class, rc_set);
2688 gtk_rc_sets_class = g_slist_prepend (gtk_rc_sets_class, rc_set);
2692 return G_TOKEN_NONE;
2696 gtk_rc_parse_stock_id (GScanner *scanner,
2701 token = g_scanner_get_next_token (scanner);
2702 if (token != G_TOKEN_LEFT_BRACE)
2703 return G_TOKEN_LEFT_BRACE;
2705 token = g_scanner_get_next_token (scanner);
2707 if (token != G_TOKEN_STRING)
2708 return G_TOKEN_STRING;
2710 *stock_id = g_strdup (scanner->value.v_string);
2712 token = g_scanner_get_next_token (scanner);
2713 if (token != G_TOKEN_RIGHT_BRACE)
2716 return G_TOKEN_RIGHT_BRACE;
2719 return G_TOKEN_NONE;
2723 cleanup_source (GtkIconSource *source)
2725 g_free (source->filename);
2726 g_free (source->size);
2730 gtk_rc_parse_icon_source (GScanner *scanner,
2731 GtkIconSet *icon_set)
2734 GtkIconSource source = { NULL, NULL,
2738 token = g_scanner_get_next_token (scanner);
2739 if (token != G_TOKEN_LEFT_CURLY)
2740 return G_TOKEN_LEFT_CURLY;
2742 token = g_scanner_get_next_token (scanner);
2744 if (token != G_TOKEN_STRING)
2745 return G_TOKEN_STRING;
2747 source.filename = g_strdup (scanner->value.v_string);
2749 token = g_scanner_get_next_token (scanner);
2751 if (token == G_TOKEN_RIGHT_CURLY)
2753 gtk_icon_set_add_source (icon_set, &source);
2754 cleanup_source (&source);
2755 return G_TOKEN_NONE;
2757 else if (token != G_TOKEN_COMMA)
2759 cleanup_source (&source);
2760 return G_TOKEN_COMMA;
2763 /* Get the direction */
2765 token = g_scanner_get_next_token (scanner);
2769 case GTK_RC_TOKEN_RTL:
2770 source.any_direction = FALSE;
2771 source.direction = GTK_TEXT_DIR_RTL;
2774 case GTK_RC_TOKEN_LTR:
2775 source.any_direction = FALSE;
2776 source.direction = GTK_TEXT_DIR_LTR;
2783 cleanup_source (&source);
2784 return GTK_RC_TOKEN_RTL;
2788 token = g_scanner_get_next_token (scanner);
2790 if (token == G_TOKEN_RIGHT_CURLY)
2792 gtk_icon_set_add_source (icon_set, &source);
2793 cleanup_source (&source);
2794 return G_TOKEN_NONE;
2796 else if (token != G_TOKEN_COMMA)
2798 cleanup_source (&source);
2799 return G_TOKEN_COMMA;
2804 token = g_scanner_get_next_token (scanner);
2808 case GTK_RC_TOKEN_NORMAL:
2809 source.any_state = FALSE;
2810 source.state = GTK_STATE_NORMAL;
2813 case GTK_RC_TOKEN_PRELIGHT:
2814 source.any_state = FALSE;
2815 source.state = GTK_STATE_PRELIGHT;
2819 case GTK_RC_TOKEN_INSENSITIVE:
2820 source.any_state = FALSE;
2821 source.state = GTK_STATE_INSENSITIVE;
2824 case GTK_RC_TOKEN_ACTIVE:
2825 source.any_state = FALSE;
2826 source.state = GTK_STATE_ACTIVE;
2829 case GTK_RC_TOKEN_SELECTED:
2830 source.any_state = FALSE;
2831 source.state = GTK_STATE_SELECTED;
2838 cleanup_source (&source);
2839 return GTK_RC_TOKEN_PRELIGHT;
2843 token = g_scanner_get_next_token (scanner);
2845 if (token == G_TOKEN_RIGHT_CURLY)
2847 gtk_icon_set_add_source (icon_set, &source);
2848 cleanup_source (&source);
2849 return G_TOKEN_NONE;
2851 else if (token != G_TOKEN_COMMA)
2853 cleanup_source (&source);
2854 return G_TOKEN_COMMA;
2859 token = g_scanner_get_next_token (scanner);
2863 if (token != G_TOKEN_STRING)
2865 cleanup_source (&source);
2866 return G_TOKEN_STRING;
2869 source.size = g_strdup (scanner->value.v_string);
2870 source.any_size = FALSE;
2873 /* Check the close brace */
2875 token = g_scanner_get_next_token (scanner);
2876 if (token != G_TOKEN_RIGHT_CURLY)
2878 cleanup_source (&source);
2879 return G_TOKEN_RIGHT_CURLY;
2882 gtk_icon_set_add_source (icon_set, &source);
2884 cleanup_source (&source);
2886 return G_TOKEN_NONE;
2890 gtk_rc_parse_stock (GScanner *scanner,
2891 GtkRcStyle *rc_style,
2892 GtkIconFactory *factory)
2894 GtkIconSet *icon_set = NULL;
2895 gchar *stock_id = NULL;
2898 token = g_scanner_get_next_token (scanner);
2899 if (token != GTK_RC_TOKEN_STOCK)
2900 return GTK_RC_TOKEN_STOCK;
2902 token = gtk_rc_parse_stock_id (scanner, &stock_id);
2903 if (token != G_TOKEN_NONE)
2906 token = g_scanner_get_next_token (scanner);
2907 if (token != G_TOKEN_EQUAL_SIGN)
2910 return G_TOKEN_EQUAL_SIGN;
2913 token = g_scanner_get_next_token (scanner);
2914 if (token != G_TOKEN_LEFT_CURLY)
2917 return G_TOKEN_LEFT_CURLY;
2920 token = g_scanner_peek_next_token (scanner);
2921 while (token != G_TOKEN_RIGHT_CURLY)
2923 if (icon_set == NULL)
2924 icon_set = gtk_icon_set_new ();
2926 token = gtk_rc_parse_icon_source (scanner, icon_set);
2927 if (token != G_TOKEN_NONE)
2930 gtk_icon_set_unref (icon_set);
2934 token = g_scanner_get_next_token (scanner);
2936 if (token != G_TOKEN_COMMA &&
2937 token != G_TOKEN_RIGHT_CURLY)
2940 gtk_icon_set_unref (icon_set);
2941 return G_TOKEN_RIGHT_CURLY;
2947 gtk_icon_factory_add (factory,
2951 gtk_icon_set_unref (icon_set);
2956 return G_TOKEN_NONE;
2960 typedef GdkPixmap * (*GtkImageLoader) (GdkWindow *window,
2961 GdkColormap *colormap,
2963 GdkColor *transparent_color,
2964 const gchar *filename);
2968 gtk_rc_set_image_loader(GtkImageLoader loader)
2970 image_loader = loader;
2974 gtk_rc_load_image (GdkColormap *colormap,
2975 GdkColor *transparent_color,
2976 const gchar *filename)
2978 if (strcmp (filename, "<parent>") == 0)
2979 return (GdkPixmap*) GDK_PARENT_RELATIVE;
2983 return image_loader(NULL, colormap, NULL,
2987 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,