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 "gdkconfig.h"
55 #include "gtkbindings.h"
56 #include "gtkthemes.h"
58 #include "gtkiconfactory.h"
61 #include <windows.h> /* For GetWindowsDirectory */
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 gboolean gtk_rc_style_equal (const char *a,
86 static guint gtk_rc_styles_hash (const GSList *rc_styles);
87 static gboolean gtk_rc_styles_equal (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 = g_strdup (im_module_file);
359 result = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtk.immodules");
361 result = g_strdup_printf ("%s\\gtk.immodules", gtk_win32_get_installation_directory ());
369 gtk_rc_get_theme_dir(void)
374 var = getenv("GTK_DATA_PREFIX");
376 path = g_strdup_printf("%s%s", var, "/share/themes");
378 path = g_strdup_printf("%s%s", GTK_DATA_PREFIX, "/share/themes");
380 path = g_strdup (get_themes_directory ());
387 gtk_rc_get_module_dir(void)
389 return gtk_rc_make_default_dir ("engines");
393 gtk_rc_append_default_module_path(void)
398 for (n = 0; module_path[n]; n++) ;
399 if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
403 var = getenv("GTK_EXE_PREFIX");
405 path = g_strdup_printf("%s%s", var, "/lib/gtk-2.0/" GTK_VERSION "/engines");
407 path = g_strdup_printf("%s%s", GTK_EXE_PREFIX, "/lib/gtk-2.0/" GTK_VERSION "/engines");
409 path = g_strdup_printf ("%s%s", get_themes_directory (), "\\engines");
411 module_path[n++] = path;
413 var = g_get_home_dir ();
417 /* Don't duplicate the directory separator, causes trouble at
420 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
421 sep = G_DIR_SEPARATOR_S;
424 /* This produces something like ~/.gtk-2.0/2.0/engines */
425 path = g_strdup_printf ("%s%s%s", var, sep,
426 ".gtk-2.0" G_DIR_SEPARATOR_S
427 GTK_VERSION G_DIR_SEPARATOR_S
429 module_path[n++] = path;
431 module_path[n] = NULL;
435 gtk_rc_add_initial_default_files (void)
437 static gint init = FALSE;
445 gtk_rc_default_files[0] = NULL;
448 var = g_getenv("GTK_RC_FILES");
451 files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
455 gtk_rc_add_default_file (files[i]);
463 str = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
465 str = g_strdup_printf ("%s\\gtkrc", gtk_win32_get_installation_directory ());
468 gtk_rc_add_default_file (str);
471 var = g_get_home_dir ();
475 if (var[strlen (var) -1] != G_DIR_SEPARATOR)
476 sep = G_DIR_SEPARATOR_S;
479 str = g_strdup_printf ("%s%s.gtkrc-2.0", var, sep);
480 gtk_rc_add_default_file (str);
487 gtk_rc_add_default_file (const gchar *file)
491 gtk_rc_add_initial_default_files ();
493 for (n = 0; gtk_rc_default_files[n]; n++) ;
494 if (n >= GTK_RC_MAX_DEFAULT_FILES - 1)
497 gtk_rc_default_files[n++] = g_strdup (file);
498 gtk_rc_default_files[n] = NULL;
502 gtk_rc_set_default_files (gchar **files)
506 gtk_rc_add_initial_default_files ();
509 while (gtk_rc_default_files[i])
511 g_free (gtk_rc_default_files[i]);
515 gtk_rc_default_files[0] = NULL;
516 gtk_rc_auto_parse = FALSE;
519 while (files[i] != NULL)
521 gtk_rc_add_default_file (files[i]);
527 gtk_rc_get_default_files (void)
529 gtk_rc_add_initial_default_files ();
531 return gtk_rc_default_files;
534 /* The following routine is based on _nl_normalize_codeset from
535 * the GNU C library. Contributed by
537 * Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
538 * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
540 * Normalize codeset name. There is no standard for the codeset
541 * names. Normalization allows the user to use any of the common
545 _gtk_normalize_codeset (const char *codeset, int name_len)
553 for (cnt = 0; cnt < name_len; ++cnt)
554 if (isalnum (codeset[cnt]))
558 if (isalpha (codeset[cnt]))
562 retval = g_malloc ((only_digit ? 3 : 0) + len + 1);
566 strcpy (retval, "iso");
572 for (cnt = 0; cnt < name_len; ++cnt)
573 if (isalpha (codeset[cnt]))
574 *wp++ = isupper(codeset[cnt]) ? tolower (codeset[cnt]) : codeset[cnt];
575 else if (isdigit (codeset[cnt]))
576 *wp++ = codeset[cnt];
586 static gchar *locale_suffixes[3];
587 static gint n_locale_suffixes = 0;
591 static gboolean initted = FALSE;
600 locale = g_win32_getlocale ();
602 locale = setlocale (LC_CTYPE, NULL);
607 pixmap_path[0] = NULL;
608 module_path[0] = NULL;
609 gtk_rc_append_default_module_path();
611 gtk_rc_add_initial_default_files ();
613 if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
615 /* Determine locale-specific suffixes for RC files
617 * We normalize the charset into a standard form,
618 * which has all '-' and '_' characters removed,
621 gchar *normalized_locale;
623 p = strchr (locale, '@');
624 length = p ? (p -locale) : strlen (locale);
626 p = strchr (locale, '.');
629 gchar *tmp1 = g_strndup (locale, p - locale + 1);
630 gchar *tmp2 = _gtk_normalize_codeset (p + 1, length - (p - locale + 1));
632 normalized_locale = g_strconcat (tmp1, tmp2, NULL);
636 locale_suffixes[n_locale_suffixes++] = g_strdup (normalized_locale);
640 normalized_locale = g_strndup (locale, length);
642 p = strchr (normalized_locale, '_');
645 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
646 length = p - normalized_locale;
649 locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
651 g_free (normalized_locale);
656 while (gtk_rc_default_files[i] != NULL)
658 /* Try to find a locale specific RC file corresponding to
659 * to parse before the default file.
661 for (j=n_locale_suffixes-1; j>=0; j--)
663 gchar *name = g_strconcat (gtk_rc_default_files[i],
671 gtk_rc_parse (gtk_rc_default_files[i]);
677 gtk_rc_parse_string (const gchar *rc_string)
679 g_return_if_fail (rc_string != NULL);
681 gtk_rc_parse_any ("-", -1, rc_string);
685 gtk_rc_parse_file (const gchar *filename, gboolean reload)
687 GtkRcFile *rc_file = NULL;
691 g_return_if_fail (filename != NULL);
696 rc_file = tmp_list->data;
697 if (!strcmp (rc_file->name, filename))
700 tmp_list = tmp_list->next;
705 rc_file = g_new (GtkRcFile, 1);
706 rc_file->name = g_strdup (filename);
707 rc_file->canonical_name = NULL;
709 rc_file->reload = reload;
711 rc_files = g_slist_append (rc_files, rc_file);
714 if (!rc_file->canonical_name)
716 /* Get the absolute pathname */
718 if (g_path_is_absolute (rc_file->name))
719 rc_file->canonical_name = rc_file->name;
725 cwd = g_get_current_dir ();
727 str = g_string_new (cwd);
729 g_string_append_c (str, G_DIR_SEPARATOR);
730 g_string_append (str, rc_file->name);
732 rc_file->canonical_name = str->str;
733 g_string_free (str, FALSE);
737 if (!lstat (rc_file->canonical_name, &statbuf))
742 rc_file->mtime = statbuf.st_mtime;
744 fd = open (rc_file->canonical_name, O_RDONLY);
748 /* Temporarily push directory name for this file on
749 * a stack of directory names while parsing it
752 g_slist_prepend (rc_dir_stack,
753 g_path_get_dirname (rc_file->canonical_name));
754 gtk_rc_parse_any (filename, fd, NULL);
756 tmp_list = rc_dir_stack;
757 rc_dir_stack = rc_dir_stack->next;
759 g_free (tmp_list->data);
760 g_slist_free_1 (tmp_list);
767 gtk_rc_parse (const gchar *filename)
769 g_return_if_fail (filename != NULL);
771 gtk_rc_parse_file (filename, TRUE);
774 /* Handling of RC styles */
777 gtk_rc_style_get_type (void)
779 static GType object_type = 0;
783 static const GTypeInfo object_info =
785 sizeof (GtkRcStyleClass),
786 (GBaseInitFunc) NULL,
787 (GBaseFinalizeFunc) NULL,
788 (GClassInitFunc) gtk_rc_style_class_init,
789 NULL, /* class_finalize */
790 NULL, /* class_data */
793 (GInstanceInitFunc) gtk_rc_style_init,
796 object_type = g_type_register_static (G_TYPE_OBJECT,
805 gtk_rc_style_init (GtkRcStyle *style)
810 for (i = 0; i < 5; i++)
812 static const GdkColor init_color = { 0, 0, 0, 0, };
814 style->bg_pixmap_name[i] = NULL;
815 style->color_flags[i] = 0;
816 style->fg[i] = init_color;
817 style->bg[i] = init_color;
818 style->text[i] = init_color;
819 style->base[i] = init_color;
821 style->xthickness = -1;
822 style->ythickness = -1;
823 style->rc_style_lists = NULL;
827 gtk_rc_style_class_init (GtkRcStyleClass *klass)
829 GObjectClass *object_class = G_OBJECT_CLASS (klass);
831 parent_class = g_type_class_peek_parent (klass);
833 object_class->finalize = gtk_rc_style_finalize;
836 klass->clone = gtk_rc_style_real_clone;
837 klass->merge = gtk_rc_style_real_merge;
838 klass->create_style = gtk_rc_style_real_create_style;
841 /* Like g_slist_remove, but remove all copies of data */
843 gtk_rc_slist_remove_all (GSList *list,
854 if (tmp->data == data)
860 prev->next = tmp->next;
862 g_slist_free_1 (tmp);
880 gtk_rc_style_finalize (GObject *object)
883 GSList *tmp_list1, *tmp_list2;
884 GtkRcStyle *rc_style;
886 rc_style = GTK_RC_STYLE (object);
889 g_free (rc_style->name);
890 if (rc_style->font_desc)
891 pango_font_description_free (rc_style->font_desc);
893 for (i=0 ; i < 5 ; i++)
894 if (rc_style->bg_pixmap_name[i])
895 g_free (rc_style->bg_pixmap_name[i]);
897 /* Now remove all references to this rc_style from
900 tmp_list1 = rc_style->rc_style_lists;
903 GSList *rc_styles = tmp_list1->data;
904 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
905 gtk_style_unref (style);
907 /* Remove the list of styles from the other rc_styles
910 tmp_list2 = rc_styles;
913 GtkRcStyle *other_style = tmp_list2->data;
915 if (other_style != rc_style)
916 other_style->rc_style_lists =
917 gtk_rc_slist_remove_all (other_style->rc_style_lists, rc_styles);
919 tmp_list2 = tmp_list2->next;
922 /* And from the hash table itself
924 g_hash_table_remove (realized_style_ht, rc_styles);
925 g_slist_free (rc_styles);
927 tmp_list1 = tmp_list1->next;
930 g_slist_free (rc_style->rc_style_lists);
932 tmp_list1 = rc_style->icon_factories;
935 g_object_unref (G_OBJECT (tmp_list1->data));
937 tmp_list1 = tmp_list1->next;
940 g_slist_free (rc_style->icon_factories);
942 G_OBJECT_CLASS (parent_class)->finalize (object);
946 gtk_rc_style_new (void)
950 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
957 * @orig: the style to copy
959 * Make a copy of the specified #GtkRcStyle. This function
960 * will correctly copy an rc style that is a member of a class
961 * derived from #GtkRcStyle.
963 * Return value: the resulting #GtkRcStyle
966 gtk_rc_style_copy (GtkRcStyle *orig)
970 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
972 style = GTK_RC_STYLE_GET_CLASS (orig)->clone (orig);
973 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
979 gtk_rc_style_ref (GtkRcStyle *rc_style)
981 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
983 g_object_ref (G_OBJECT (rc_style));
987 gtk_rc_style_unref (GtkRcStyle *rc_style)
989 g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
991 g_object_unref (G_OBJECT (rc_style));
995 gtk_rc_style_real_clone (GtkRcStyle *style)
997 return GTK_RC_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1001 gtk_rc_style_real_merge (GtkRcStyle *dest,
1006 for (i = 0; i < 5; i++)
1008 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1009 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1011 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1012 src->color_flags[i] & GTK_RC_FG)
1014 dest->fg[i] = src->fg[i];
1015 dest->color_flags[i] |= GTK_RC_FG;
1017 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1018 src->color_flags[i] & GTK_RC_BG)
1020 dest->bg[i] = src->bg[i];
1021 dest->color_flags[i] |= GTK_RC_BG;
1023 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1024 src->color_flags[i] & GTK_RC_TEXT)
1026 dest->text[i] = src->text[i];
1027 dest->color_flags[i] |= GTK_RC_TEXT;
1029 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1030 src->color_flags[i] & GTK_RC_BASE)
1032 dest->base[i] = src->base[i];
1033 dest->color_flags[i] |= GTK_RC_BASE;
1037 if (dest->xthickness < 0 && src->xthickness >= 0)
1038 dest->xthickness = src->xthickness;
1039 if (dest->ythickness < 0 && src->ythickness >= 0)
1040 dest->ythickness = src->ythickness;
1042 if (!dest->font_desc && src->font_desc)
1043 dest->font_desc = pango_font_description_copy (src->font_desc);
1047 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1049 return gtk_style_new ();
1053 gtk_rc_clear_hash_node (gpointer key,
1057 gtk_rc_style_unref (data);
1061 gtk_rc_free_rc_sets (GSList *slist)
1067 rc_set = slist->data;
1068 gtk_pattern_spec_free_segs (&rc_set->pspec);
1071 slist = slist->next;
1076 gtk_rc_clear_styles (void)
1078 /* Clear out all old rc_styles */
1082 g_hash_table_foreach (rc_style_ht, gtk_rc_clear_hash_node, NULL);
1083 g_hash_table_destroy (rc_style_ht);
1087 gtk_rc_free_rc_sets (gtk_rc_sets_widget);
1088 g_slist_free (gtk_rc_sets_widget);
1089 gtk_rc_sets_widget = NULL;
1091 gtk_rc_free_rc_sets (gtk_rc_sets_widget_class);
1092 g_slist_free (gtk_rc_sets_widget_class);
1093 gtk_rc_sets_widget_class = NULL;
1095 gtk_rc_free_rc_sets (gtk_rc_sets_class);
1096 g_slist_free (gtk_rc_sets_class);
1097 gtk_rc_sets_class = NULL;
1101 gtk_rc_reparse_all (void)
1104 gboolean mtime_modified = FALSE;
1107 struct stat statbuf;
1109 /* Check through and see if any of the RC's have had their
1110 * mtime modified. If so, reparse everything.
1112 tmp_list = rc_files;
1115 rc_file = tmp_list->data;
1117 if (!lstat (rc_file->name, &statbuf) &&
1118 (statbuf.st_mtime > rc_file->mtime))
1120 mtime_modified = TRUE;
1124 tmp_list = tmp_list->next;
1129 gtk_rc_clear_styles();
1131 tmp_list = rc_files;
1134 rc_file = tmp_list->data;
1135 if (rc_file->reload)
1136 gtk_rc_parse_file (rc_file->name, FALSE);
1138 tmp_list = tmp_list->next;
1142 return mtime_modified;
1146 gtk_rc_styles_match (GSList *rc_styles,
1150 gchar *path_reversed)
1157 rc_set = sets->data;
1160 if (gtk_pattern_match (&rc_set->pspec, path_length, path, path_reversed))
1161 rc_styles = g_slist_append (rc_styles, rc_set->rc_style);
1168 gtk_rc_get_style (GtkWidget *widget)
1170 GtkRcStyle *widget_rc_style;
1171 GSList *rc_styles = NULL;
1173 static guint rc_style_key_id = 0;
1175 /* We allow the specification of a single rc style to be bound
1176 * tightly to a widget, for application modifications
1178 if (!rc_style_key_id)
1179 rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
1181 widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
1184 if (widget_rc_style)
1185 rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
1187 if (gtk_rc_sets_widget)
1189 gchar *path, *path_reversed;
1192 gtk_widget_path (widget, &path_length, &path, &path_reversed);
1193 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget, path_length, path, path_reversed);
1195 g_free (path_reversed);
1199 if (gtk_rc_sets_widget_class)
1201 gchar *path, *path_reversed;
1204 gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
1205 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget_class, path_length, path, path_reversed);
1207 g_free (path_reversed);
1210 if (gtk_rc_sets_class)
1214 type = GTK_OBJECT_TYPE (widget);
1217 gchar *path, *path_reversed;
1220 path = gtk_type_name (type);
1221 path_length = strlen (path);
1222 path_reversed = g_strdup (path);
1223 g_strreverse (path_reversed);
1225 rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_class, path_length, path, path_reversed);
1226 g_free (path_reversed);
1228 type = gtk_type_parent (type);
1233 return gtk_rc_init_style (rc_styles);
1239 gtk_rc_add_rc_sets (GSList *slist,
1240 GtkRcStyle *rc_style,
1241 const char *pattern)
1243 GtkRcStyle *new_style;
1247 new_style = gtk_rc_style_new ();
1248 *new_style = *rc_style;
1249 new_style->name = g_strdup (rc_style->name);
1250 if (rc_style->font_desc)
1251 new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
1253 for (i = 0; i < 5; i++)
1254 new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
1256 rc_set = g_new (GtkRcSet, 1);
1257 gtk_pattern_spec_init (&rc_set->pspec, pattern);
1258 rc_set->rc_style = rc_style;
1260 return g_slist_prepend (slist, rc_set);
1264 gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
1265 const gchar *pattern)
1267 g_return_if_fail (rc_style != NULL);
1268 g_return_if_fail (pattern != NULL);
1270 gtk_rc_sets_widget = gtk_rc_add_rc_sets (gtk_rc_sets_widget, rc_style, pattern);
1274 gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
1275 const gchar *pattern)
1277 g_return_if_fail (rc_style != NULL);
1278 g_return_if_fail (pattern != NULL);
1280 gtk_rc_sets_widget_class = gtk_rc_add_rc_sets (gtk_rc_sets_widget_class, rc_style, pattern);
1284 gtk_rc_add_class_style (GtkRcStyle *rc_style,
1285 const gchar *pattern)
1287 g_return_if_fail (rc_style != NULL);
1288 g_return_if_fail (pattern != NULL);
1290 gtk_rc_sets_class = gtk_rc_add_rc_sets (gtk_rc_sets_class, rc_style, pattern);
1294 gtk_rc_parse_any (const gchar *input_name,
1296 const gchar *input_string)
1302 scanner = g_scanner_new ((GScannerConfig *) >k_rc_scanner_config);
1306 g_assert (input_string == NULL);
1308 g_scanner_input_file (scanner, input_fd);
1312 g_assert (input_string != NULL);
1314 g_scanner_input_text (scanner, input_string, strlen (input_string));
1316 scanner->input_name = input_name;
1318 for (i = 0; i < n_symbols; i++)
1319 g_scanner_add_symbol (scanner, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
1324 if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1328 guint expected_token;
1330 expected_token = gtk_rc_parse_statement (scanner);
1332 if (expected_token != G_TOKEN_NONE)
1339 if (scanner->scope_id == 0)
1341 /* if we are in scope 0, we know the symbol names
1342 * that are associated with certaintoken values.
1343 * so we look them up to make the error messages
1346 if (expected_token > GTK_RC_TOKEN_INVALID &&
1347 expected_token < GTK_RC_TOKEN_LAST)
1349 for (i = 0; i < n_symbols; i++)
1350 if (symbols[i].token == expected_token)
1351 msg = symbols[i].name;
1353 msg = g_strconcat ("e.g. `", msg, "'", NULL);
1355 if (scanner->token > GTK_RC_TOKEN_INVALID &&
1356 scanner->token < GTK_RC_TOKEN_LAST)
1358 symbol_name = "???";
1359 for (i = 0; i < n_symbols; i++)
1360 if (symbols[i].token == scanner->token)
1361 symbol_name = symbols[i].name;
1364 g_scanner_unexp_token (scanner,
1377 g_scanner_destroy (scanner);
1381 gtk_rc_styles_hash (const GSList *rc_styles)
1388 result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data);
1389 rc_styles = rc_styles->next;
1396 gtk_rc_styles_equal (const GSList *a,
1401 if (a->data != b->data)
1411 gtk_rc_style_hash (const char *name)
1417 result += (result << 3) + *name++;
1423 gtk_rc_style_equal (const char *a,
1426 return (strcmp (a, b) == 0);
1430 gtk_rc_style_find (const char *name)
1433 return g_hash_table_lookup (rc_style_ht, (gpointer) name);
1439 gtk_rc_style_to_style (GtkRcStyle *rc_style)
1443 style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
1445 style->rc_style = rc_style;
1447 gtk_rc_style_ref (rc_style);
1449 GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);
1454 /* Reuses or frees rc_styles */
1456 gtk_rc_init_style (GSList *rc_styles)
1458 GtkStyle *style = NULL;
1461 g_return_val_if_fail (rc_styles != NULL, NULL);
1463 if (!realized_style_ht)
1464 realized_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_styles_hash,
1465 (GEqualFunc) gtk_rc_styles_equal);
1467 style = g_hash_table_lookup (realized_style_ht, rc_styles);
1471 GtkRcStyle *base_style = NULL;
1472 GtkRcStyle *proto_style;
1473 GtkRcStyleClass *proto_style_class;
1475 GType rc_style_type = GTK_TYPE_RC_STYLE;
1477 /* Find the first derived style in the list, and use that to
1478 * create the merged style. If we only have raw GtkRcStyles, use
1479 * the first style to create the merged style.
1481 base_style = rc_styles->data;
1482 tmp_styles = rc_styles;
1485 GtkRcStyle *rc_style = tmp_styles->data;
1487 if (G_OBJECT_TYPE (rc_style) != rc_style_type)
1489 base_style = rc_style;
1493 tmp_styles = tmp_styles->next;
1496 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
1497 proto_style = proto_style_class->clone (base_style);
1499 tmp_styles = rc_styles;
1502 GtkRcStyle *rc_style = tmp_styles->data;
1505 proto_style_class->merge (proto_style, rc_style);
1507 /* Point from each rc_style to the list of styles */
1508 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
1509 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
1511 factories = g_slist_copy (rc_style->icon_factories);
1517 while (iter != NULL)
1519 g_object_ref (G_OBJECT (iter->data));
1520 iter = g_slist_next (iter);
1523 proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
1528 tmp_styles = tmp_styles->next;
1531 for (i = 0; i < 5; i++)
1532 if (proto_style->bg_pixmap_name[i] &&
1533 (strcmp (proto_style->bg_pixmap_name[i], "<none>") == 0))
1535 g_free (proto_style->bg_pixmap_name[i]);
1536 proto_style->bg_pixmap_name[i] = NULL;
1539 style = gtk_rc_style_to_style (proto_style);
1540 gtk_rc_style_unref (proto_style);
1542 g_hash_table_insert (realized_style_ht, rc_styles, style);
1545 g_slist_free (rc_styles);
1550 /*********************
1551 * Parsing functions *
1552 *********************/
1555 gtk_rc_parse_statement (GScanner *scanner)
1559 token = g_scanner_peek_next_token (scanner);
1563 case GTK_RC_TOKEN_INCLUDE:
1564 token = g_scanner_get_next_token (scanner);
1565 if (token != GTK_RC_TOKEN_INCLUDE)
1566 return GTK_RC_TOKEN_INCLUDE;
1568 token = g_scanner_get_next_token (scanner);
1569 if (token != G_TOKEN_STRING)
1570 return G_TOKEN_STRING;
1572 gtk_rc_parse_file (scanner->value.v_string, FALSE);
1573 return G_TOKEN_NONE;
1575 case GTK_RC_TOKEN_STYLE:
1576 return gtk_rc_parse_style (scanner);
1578 case GTK_RC_TOKEN_BINDING:
1579 return gtk_binding_parse_binding (scanner);
1581 case GTK_RC_TOKEN_PIXMAP_PATH:
1582 return gtk_rc_parse_pixmap_path (scanner);
1584 case GTK_RC_TOKEN_WIDGET:
1585 return gtk_rc_parse_path_pattern (scanner);
1587 case GTK_RC_TOKEN_WIDGET_CLASS:
1588 return gtk_rc_parse_path_pattern (scanner);
1590 case GTK_RC_TOKEN_CLASS:
1591 return gtk_rc_parse_path_pattern (scanner);
1593 case GTK_RC_TOKEN_MODULE_PATH:
1594 return gtk_rc_parse_module_path (scanner);
1596 case GTK_RC_TOKEN_IM_MODULE_PATH:
1597 return gtk_rc_parse_im_module_path (scanner);
1599 case GTK_RC_TOKEN_IM_MODULE_FILE:
1600 return gtk_rc_parse_im_module_file (scanner);
1603 g_scanner_get_next_token (scanner);
1604 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_STYLE;
1609 gtk_rc_parse_style (GScanner *scanner)
1611 GtkRcStyle *rc_style;
1612 GtkRcStyle *parent_style;
1616 GtkIconFactory *our_factory = NULL;
1618 token = g_scanner_get_next_token (scanner);
1619 if (token != GTK_RC_TOKEN_STYLE)
1620 return GTK_RC_TOKEN_STYLE;
1622 token = g_scanner_get_next_token (scanner);
1623 if (token != G_TOKEN_STRING)
1624 return G_TOKEN_STRING;
1627 rc_style = gtk_rc_style_find (scanner->value.v_string);
1629 /* If there's a list, its first member is always the factory belonging
1632 if (rc_style && rc_style->icon_factories)
1633 our_factory = rc_style->icon_factories->data;
1638 rc_style = gtk_rc_style_new ();
1639 rc_style->name = g_strdup (scanner->value.v_string);
1641 for (i = 0; i < 5; i++)
1642 rc_style->bg_pixmap_name[i] = NULL;
1644 for (i = 0; i < 5; i++)
1645 rc_style->color_flags[i] = 0;
1648 token = g_scanner_peek_next_token (scanner);
1649 if (token == G_TOKEN_EQUAL_SIGN)
1651 token = g_scanner_get_next_token (scanner);
1653 token = g_scanner_get_next_token (scanner);
1654 if (token != G_TOKEN_STRING)
1659 return G_TOKEN_STRING;
1662 parent_style = gtk_rc_style_find (scanner->value.v_string);
1667 for (i = 0; i < 5; i++)
1669 rc_style->color_flags[i] = parent_style->color_flags[i];
1670 rc_style->fg[i] = parent_style->fg[i];
1671 rc_style->bg[i] = parent_style->bg[i];
1672 rc_style->text[i] = parent_style->text[i];
1673 rc_style->base[i] = parent_style->base[i];
1676 rc_style->xthickness = parent_style->xthickness;
1677 rc_style->ythickness = parent_style->ythickness;
1679 if (parent_style->font_desc)
1681 if (rc_style->font_desc)
1682 pango_font_description_free (rc_style->font_desc);
1683 rc_style->font_desc = pango_font_description_copy (parent_style->font_desc);
1686 for (i = 0; i < 5; i++)
1688 if (rc_style->bg_pixmap_name[i])
1689 g_free (rc_style->bg_pixmap_name[i]);
1690 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
1693 /* Append parent's factories, adding a ref to them */
1694 if (parent_style->icon_factories != NULL)
1696 /* Add a factory for ourselves if we have none,
1697 * in case we end up defining more stock icons.
1698 * I see no real way around this; we need to maintain
1699 * the invariant that the first factory in the list
1700 * is always our_factory, the one belonging to us,
1701 * and if we put parent factories in the list we can't
1702 * do that if the style is reopened.
1704 if (our_factory == NULL)
1706 our_factory = gtk_icon_factory_new ();
1707 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
1711 rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
1712 g_slist_copy (parent_style->icon_factories));
1714 factories = parent_style->icon_factories;
1715 while (factories != NULL)
1717 g_object_ref (G_OBJECT (factories->data));
1718 factories = factories->next;
1724 token = g_scanner_get_next_token (scanner);
1725 if (token != G_TOKEN_LEFT_CURLY)
1730 return G_TOKEN_LEFT_CURLY;
1733 token = g_scanner_peek_next_token (scanner);
1734 while (token != G_TOKEN_RIGHT_CURLY)
1738 case GTK_RC_TOKEN_BG:
1739 token = gtk_rc_parse_bg (scanner, rc_style);
1741 case GTK_RC_TOKEN_FG:
1742 token = gtk_rc_parse_fg (scanner, rc_style);
1744 case GTK_RC_TOKEN_TEXT:
1745 token = gtk_rc_parse_text (scanner, rc_style);
1747 case GTK_RC_TOKEN_BASE:
1748 token = gtk_rc_parse_base (scanner, rc_style);
1750 case GTK_RC_TOKEN_XTHICKNESS:
1751 token = gtk_rc_parse_xthickness (scanner, rc_style);
1753 case GTK_RC_TOKEN_YTHICKNESS:
1754 token = gtk_rc_parse_ythickness (scanner, rc_style);
1756 case GTK_RC_TOKEN_BG_PIXMAP:
1757 token = gtk_rc_parse_bg_pixmap (scanner, rc_style);
1759 case GTK_RC_TOKEN_FONT:
1760 token = gtk_rc_parse_font (scanner, rc_style);
1762 case GTK_RC_TOKEN_FONTSET:
1763 token = gtk_rc_parse_fontset (scanner, rc_style);
1765 case GTK_RC_TOKEN_FONT_NAME:
1766 token = gtk_rc_parse_font_name (scanner, rc_style);
1768 case GTK_RC_TOKEN_ENGINE:
1769 token = gtk_rc_parse_engine (scanner, &rc_style);
1771 case GTK_RC_TOKEN_STOCK:
1772 if (our_factory == NULL)
1774 our_factory = gtk_icon_factory_new ();
1775 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
1778 token = gtk_rc_parse_stock (scanner, rc_style, our_factory);
1781 g_scanner_get_next_token (scanner);
1782 token = G_TOKEN_RIGHT_CURLY;
1786 if (token != G_TOKEN_NONE)
1790 if (rc_style->font_desc)
1791 pango_font_description_free (rc_style->font_desc);
1793 for (i = 0; i < 5; i++)
1794 if (rc_style->bg_pixmap_name[i])
1795 g_free (rc_style->bg_pixmap_name[i]);
1800 token = g_scanner_peek_next_token (scanner);
1803 token = g_scanner_get_next_token (scanner);
1804 if (token != G_TOKEN_RIGHT_CURLY)
1808 if (rc_style->font_desc)
1809 pango_font_description_free (rc_style->font_desc);
1811 for (i = 0; i < 5; i++)
1812 if (rc_style->bg_pixmap_name[i])
1813 g_free (rc_style->bg_pixmap_name[i]);
1817 return G_TOKEN_RIGHT_CURLY;
1823 rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
1824 (GEqualFunc) gtk_rc_style_equal);
1826 g_hash_table_insert (rc_style_ht, rc_style->name, rc_style);
1829 return G_TOKEN_NONE;
1833 gtk_rc_parse_bg (GScanner *scanner,
1839 token = g_scanner_get_next_token (scanner);
1840 if (token != GTK_RC_TOKEN_BG)
1841 return GTK_RC_TOKEN_BG;
1843 token = gtk_rc_parse_state (scanner, &state);
1844 if (token != G_TOKEN_NONE)
1847 token = g_scanner_get_next_token (scanner);
1848 if (token != G_TOKEN_EQUAL_SIGN)
1849 return G_TOKEN_EQUAL_SIGN;
1851 style->color_flags[state] |= GTK_RC_BG;
1852 return gtk_rc_parse_color (scanner, &style->bg[state]);
1856 gtk_rc_parse_fg (GScanner *scanner,
1862 token = g_scanner_get_next_token (scanner);
1863 if (token != GTK_RC_TOKEN_FG)
1864 return GTK_RC_TOKEN_FG;
1866 token = gtk_rc_parse_state (scanner, &state);
1867 if (token != G_TOKEN_NONE)
1870 token = g_scanner_get_next_token (scanner);
1871 if (token != G_TOKEN_EQUAL_SIGN)
1872 return G_TOKEN_EQUAL_SIGN;
1874 style->color_flags[state] |= GTK_RC_FG;
1875 return gtk_rc_parse_color (scanner, &style->fg[state]);
1879 gtk_rc_parse_text (GScanner *scanner,
1885 token = g_scanner_get_next_token (scanner);
1886 if (token != GTK_RC_TOKEN_TEXT)
1887 return GTK_RC_TOKEN_TEXT;
1889 token = gtk_rc_parse_state (scanner, &state);
1890 if (token != G_TOKEN_NONE)
1893 token = g_scanner_get_next_token (scanner);
1894 if (token != G_TOKEN_EQUAL_SIGN)
1895 return G_TOKEN_EQUAL_SIGN;
1897 style->color_flags[state] |= GTK_RC_TEXT;
1898 return gtk_rc_parse_color (scanner, &style->text[state]);
1902 gtk_rc_parse_base (GScanner *scanner,
1908 token = g_scanner_get_next_token (scanner);
1909 if (token != GTK_RC_TOKEN_BASE)
1910 return GTK_RC_TOKEN_BASE;
1912 token = gtk_rc_parse_state (scanner, &state);
1913 if (token != G_TOKEN_NONE)
1916 token = g_scanner_get_next_token (scanner);
1917 if (token != G_TOKEN_EQUAL_SIGN)
1918 return G_TOKEN_EQUAL_SIGN;
1920 style->color_flags[state] |= GTK_RC_BASE;
1921 return gtk_rc_parse_color (scanner, &style->base[state]);
1925 gtk_rc_parse_xthickness (GScanner *scanner,
1928 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
1929 return GTK_RC_TOKEN_XTHICKNESS;
1931 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
1932 return G_TOKEN_EQUAL_SIGN;
1934 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
1937 style->xthickness = scanner->value.v_int;
1939 return G_TOKEN_NONE;
1943 gtk_rc_parse_ythickness (GScanner *scanner,
1946 if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
1947 return GTK_RC_TOKEN_YTHICKNESS;
1949 if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
1950 return G_TOKEN_EQUAL_SIGN;
1952 if (g_scanner_get_next_token (scanner) != G_TOKEN_INT)
1955 style->ythickness = scanner->value.v_int;
1957 return G_TOKEN_NONE;
1961 gtk_rc_parse_bg_pixmap (GScanner *scanner,
1962 GtkRcStyle *rc_style)
1968 token = g_scanner_get_next_token (scanner);
1969 if (token != GTK_RC_TOKEN_BG_PIXMAP)
1970 return GTK_RC_TOKEN_BG_PIXMAP;
1972 token = gtk_rc_parse_state (scanner, &state);
1973 if (token != G_TOKEN_NONE)
1976 token = g_scanner_get_next_token (scanner);
1977 if (token != G_TOKEN_EQUAL_SIGN)
1978 return G_TOKEN_EQUAL_SIGN;
1980 token = g_scanner_get_next_token (scanner);
1981 if (token != G_TOKEN_STRING)
1982 return G_TOKEN_STRING;
1984 if ((strcmp (scanner->value.v_string, "<parent>") == 0) ||
1985 (strcmp (scanner->value.v_string, "<none>") == 0))
1986 pixmap_file = g_strdup (scanner->value.v_string);
1988 pixmap_file = gtk_rc_find_pixmap_in_path (scanner, scanner->value.v_string);
1992 if (rc_style->bg_pixmap_name[state])
1993 g_free (rc_style->bg_pixmap_name[state]);
1994 rc_style->bg_pixmap_name[state] = pixmap_file;
1997 return G_TOKEN_NONE;
2001 gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
2006 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s", dir, pixmap_file);
2008 fd = open (buf, O_RDONLY);
2021 gtk_rc_find_pixmap_in_path (GScanner *scanner,
2022 const gchar *pixmap_file)
2028 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (pixmap_path[i] != NULL); i++)
2030 filename = gtk_rc_check_pixmap_dir (pixmap_path[i], pixmap_file);
2035 tmp_list = rc_dir_stack;
2038 filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
2042 tmp_list = tmp_list->next;
2046 g_warning (_("Unable to locate image file in pixmap_path: \"%s\" line %d"),
2047 pixmap_file, scanner->line);
2049 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
2056 gtk_rc_find_module_in_path (const gchar *module_file)
2062 for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
2064 buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s",
2065 module_path[i], module_file);
2067 fd = open (buf, O_RDONLY);
2081 gtk_rc_parse_font (GScanner *scanner,
2082 GtkRcStyle *rc_style)
2086 token = g_scanner_get_next_token (scanner);
2087 if (token != GTK_RC_TOKEN_FONT)
2088 return GTK_RC_TOKEN_FONT;
2090 token = g_scanner_get_next_token (scanner);
2091 if (token != G_TOKEN_EQUAL_SIGN)
2092 return G_TOKEN_EQUAL_SIGN;
2094 token = g_scanner_get_next_token (scanner);
2095 if (token != G_TOKEN_STRING)
2096 return G_TOKEN_STRING;
2098 /* Ignore, do nothing */
2100 return G_TOKEN_NONE;
2104 gtk_rc_parse_fontset (GScanner *scanner,
2105 GtkRcStyle *rc_style)
2109 token = g_scanner_get_next_token (scanner);
2110 if (token != GTK_RC_TOKEN_FONTSET)
2111 return GTK_RC_TOKEN_FONTSET;
2113 token = g_scanner_get_next_token (scanner);
2114 if (token != G_TOKEN_EQUAL_SIGN)
2115 return G_TOKEN_EQUAL_SIGN;
2117 token = g_scanner_get_next_token (scanner);
2118 if (token != G_TOKEN_STRING)
2119 return G_TOKEN_STRING;
2121 /* Do nothing - silently ignore */
2123 return G_TOKEN_NONE;
2127 gtk_rc_parse_font_name (GScanner *scanner,
2128 GtkRcStyle *rc_style)
2132 token = g_scanner_get_next_token (scanner);
2133 if (token != GTK_RC_TOKEN_FONT_NAME)
2134 return GTK_RC_TOKEN_FONT;
2136 token = g_scanner_get_next_token (scanner);
2137 if (token != G_TOKEN_EQUAL_SIGN)
2138 return G_TOKEN_EQUAL_SIGN;
2140 token = g_scanner_get_next_token (scanner);
2141 if (token != G_TOKEN_STRING)
2142 return G_TOKEN_STRING;
2144 rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
2146 return G_TOKEN_NONE;
2150 gtk_rc_parse_engine (GScanner *scanner,
2151 GtkRcStyle **rc_style)
2154 GtkThemeEngine *engine;
2155 guint result = G_TOKEN_NONE;
2156 GtkRcStyle *new_style = NULL;
2157 gboolean parsed_curlies = FALSE;
2159 token = g_scanner_get_next_token (scanner);
2160 if (token != GTK_RC_TOKEN_ENGINE)
2161 return GTK_RC_TOKEN_ENGINE;
2163 token = g_scanner_get_next_token (scanner);
2164 if (token != G_TOKEN_STRING)
2165 return G_TOKEN_STRING;
2167 engine = gtk_theme_engine_get (scanner->value.v_string);
2169 token = g_scanner_get_next_token (scanner);
2170 if (token != G_TOKEN_LEFT_CURLY)
2171 return G_TOKEN_LEFT_CURLY;
2175 GtkRcStyleClass *new_class;
2177 new_style = gtk_theme_engine_create_rc_style (engine);
2178 g_type_module_unuse (G_TYPE_MODULE (engine));
2180 new_class = GTK_RC_STYLE_GET_CLASS (new_style);
2182 new_class->merge (new_style, *rc_style);
2183 if ((*rc_style)->name)
2184 new_style->name = g_strdup ((*rc_style)->name);
2186 if (new_class->parse)
2188 parsed_curlies = TRUE;
2189 result = new_class->parse (new_style, scanner);
2191 if (result != G_TOKEN_NONE)
2193 g_object_unref (G_OBJECT (new_style));
2199 if (!parsed_curlies)
2201 /* Skip over remainder, looking for nested {}'s
2205 result = G_TOKEN_RIGHT_CURLY;
2206 while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
2208 if (token == G_TOKEN_LEFT_CURLY)
2210 else if (token == G_TOKEN_RIGHT_CURLY)
2215 result = G_TOKEN_NONE;
2223 g_object_unref (G_OBJECT (*rc_style));
2224 *rc_style = new_style;
2231 gtk_rc_parse_state (GScanner *scanner,
2232 GtkStateType *state)
2237 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2238 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
2240 /* we don't know where we got called from, so we reset the scope here.
2241 * if we bail out due to errors, we *don't* reset the scope, so the
2242 * error messaging code can make sense of our tokens.
2244 old_scope = g_scanner_set_scope (scanner, 0);
2246 token = g_scanner_get_next_token (scanner);
2247 if (token != G_TOKEN_LEFT_BRACE)
2248 return G_TOKEN_LEFT_BRACE;
2250 token = g_scanner_get_next_token (scanner);
2253 case GTK_RC_TOKEN_ACTIVE:
2254 *state = GTK_STATE_ACTIVE;
2256 case GTK_RC_TOKEN_INSENSITIVE:
2257 *state = GTK_STATE_INSENSITIVE;
2259 case GTK_RC_TOKEN_NORMAL:
2260 *state = GTK_STATE_NORMAL;
2262 case GTK_RC_TOKEN_PRELIGHT:
2263 *state = GTK_STATE_PRELIGHT;
2265 case GTK_RC_TOKEN_SELECTED:
2266 *state = GTK_STATE_SELECTED;
2269 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
2272 token = g_scanner_get_next_token (scanner);
2273 if (token != G_TOKEN_RIGHT_BRACE)
2274 return G_TOKEN_RIGHT_BRACE;
2276 g_scanner_set_scope (scanner, old_scope);
2278 return G_TOKEN_NONE;
2282 gtk_rc_parse_priority (GScanner *scanner,
2283 GtkPathPriorityType *priority)
2288 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2289 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
2291 /* we don't know where we got called from, so we reset the scope here.
2292 * if we bail out due to errors, we *don't* reset the scope, so the
2293 * error messaging code can make sense of our tokens.
2295 old_scope = g_scanner_set_scope (scanner, 0);
2297 token = g_scanner_get_next_token (scanner);
2301 token = g_scanner_get_next_token (scanner);
2304 case GTK_RC_TOKEN_LOWEST:
2305 *priority = GTK_PATH_PRIO_LOWEST;
2307 case GTK_RC_TOKEN_GTK:
2308 *priority = GTK_PATH_PRIO_GTK;
2310 case GTK_RC_TOKEN_APPLICATION:
2311 *priority = GTK_PATH_PRIO_APPLICATION;
2313 case GTK_RC_TOKEN_RC:
2314 *priority = GTK_PATH_PRIO_RC;
2316 case GTK_RC_TOKEN_HIGHEST:
2317 *priority = GTK_PATH_PRIO_HIGHEST;
2320 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
2323 g_scanner_set_scope (scanner, old_scope);
2325 return G_TOKEN_NONE;
2329 gtk_rc_parse_color (GScanner *scanner,
2334 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
2336 /* we don't need to set our own scop here, because
2337 * we don't need own symbols
2340 token = g_scanner_get_next_token (scanner);
2349 case G_TOKEN_LEFT_CURLY:
2350 token = g_scanner_get_next_token (scanner);
2351 if (token == G_TOKEN_INT)
2352 token_int = scanner->value.v_int;
2353 else if (token == G_TOKEN_FLOAT)
2354 token_int = scanner->value.v_float * 65535.0;
2356 return G_TOKEN_FLOAT;
2357 color->red = CLAMP (token_int, 0, 65535);
2359 token = g_scanner_get_next_token (scanner);
2360 if (token != G_TOKEN_COMMA)
2361 return G_TOKEN_COMMA;
2363 token = g_scanner_get_next_token (scanner);
2364 if (token == G_TOKEN_INT)
2365 token_int = scanner->value.v_int;
2366 else if (token == G_TOKEN_FLOAT)
2367 token_int = scanner->value.v_float * 65535.0;
2369 return G_TOKEN_FLOAT;
2370 color->green = CLAMP (token_int, 0, 65535);
2372 token = g_scanner_get_next_token (scanner);
2373 if (token != G_TOKEN_COMMA)
2374 return G_TOKEN_COMMA;
2376 token = g_scanner_get_next_token (scanner);
2377 if (token == G_TOKEN_INT)
2378 token_int = scanner->value.v_int;
2379 else if (token == G_TOKEN_FLOAT)
2380 token_int = scanner->value.v_float * 65535.0;
2382 return G_TOKEN_FLOAT;
2383 color->blue = CLAMP (token_int, 0, 65535);
2385 token = g_scanner_get_next_token (scanner);
2386 if (token != G_TOKEN_RIGHT_CURLY)
2387 return G_TOKEN_RIGHT_CURLY;
2388 return G_TOKEN_NONE;
2390 case G_TOKEN_STRING:
2391 if (scanner->value.v_string[0] != '#')
2392 return G_TOKEN_STRING;
2394 length = strlen (scanner->value.v_string) - 1;
2395 if (((length % 3) != 0) || (length > 12))
2396 return G_TOKEN_STRING;
2399 for (i = 0, j = 1; i < length; i++, j++)
2400 buf[i] = scanner->value.v_string[j];
2403 sscanf (buf, "%x", &temp);
2406 for (i = 0; i < length; i++, j++)
2407 buf[i] = scanner->value.v_string[j];
2410 sscanf (buf, "%x", &temp);
2411 color->green = temp;
2413 for (i = 0; i < length; i++, j++)
2414 buf[i] = scanner->value.v_string[j];
2417 sscanf (buf, "%x", &temp);
2423 color->green *= 4369;
2424 color->blue *= 4369;
2426 else if (length == 2)
2429 color->green *= 257;
2432 else if (length == 3)
2438 return G_TOKEN_NONE;
2441 return G_TOKEN_STRING;
2446 gtk_rc_parse_pixmap_path (GScanner *scanner)
2450 token = g_scanner_get_next_token (scanner);
2451 if (token != GTK_RC_TOKEN_PIXMAP_PATH)
2452 return GTK_RC_TOKEN_PIXMAP_PATH;
2454 token = g_scanner_get_next_token (scanner);
2455 if (token != G_TOKEN_STRING)
2456 return G_TOKEN_STRING;
2458 gtk_rc_parse_pixmap_path_string (scanner->value.v_string);
2460 return G_TOKEN_NONE;
2464 gtk_rc_parse_pixmap_path_string (gchar *pix_path)
2468 gint start_offset = 0;
2472 /* free the old one, or just add to the old one ? */
2473 for (path_num=0; pixmap_path[path_num]; path_num++)
2475 g_free (pixmap_path[path_num]);
2476 pixmap_path[path_num] = NULL;
2481 path_len = strlen (pix_path);
2483 buf = g_strdup (pix_path);
2485 for (end_offset = 0; end_offset <= path_len; end_offset++)
2487 if ((buf[end_offset] == G_SEARCHPATH_SEPARATOR) ||
2488 (end_offset == path_len))
2490 buf[end_offset] = '\0';
2491 pixmap_path[path_num] = g_strdup (buf + start_offset);
2493 pixmap_path[path_num] = NULL;
2494 start_offset = end_offset + 1;
2501 gtk_rc_parse_module_path (GScanner *scanner)
2505 token = g_scanner_get_next_token (scanner);
2506 if (token != GTK_RC_TOKEN_MODULE_PATH)
2507 return GTK_RC_TOKEN_MODULE_PATH;
2509 token = g_scanner_get_next_token (scanner);
2510 if (token != G_TOKEN_STRING)
2511 return G_TOKEN_STRING;
2513 gtk_rc_parse_module_path_string (scanner->value.v_string);
2515 return G_TOKEN_NONE;
2519 gtk_rc_parse_im_module_path (GScanner *scanner)
2523 token = g_scanner_get_next_token (scanner);
2524 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
2525 return GTK_RC_TOKEN_IM_MODULE_FILE;
2527 token = g_scanner_get_next_token (scanner);
2528 if (token != G_TOKEN_STRING)
2529 return G_TOKEN_STRING;
2532 g_free (im_module_path);
2534 im_module_path = g_strdup (scanner->value.v_string);
2536 return G_TOKEN_NONE;
2540 gtk_rc_parse_im_module_file (GScanner *scanner)
2544 token = g_scanner_get_next_token (scanner);
2545 if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
2546 return GTK_RC_TOKEN_IM_MODULE_FILE;
2548 token = g_scanner_get_next_token (scanner);
2549 if (token != G_TOKEN_STRING)
2550 return G_TOKEN_STRING;
2553 g_free (im_module_file);
2555 im_module_file = g_strdup (scanner->value.v_string);
2557 return G_TOKEN_NONE;
2561 gtk_rc_parse_module_path_string (gchar *mod_path)
2565 gint start_offset = 0;
2569 /* free the old one, or just add to the old one ? */
2570 for (path_num=0; module_path[path_num]; path_num++)
2572 g_free (module_path[path_num]);
2573 module_path[path_num] = NULL;
2578 path_len = strlen (mod_path);
2580 buf = g_strdup (mod_path);
2582 for (end_offset = 0; end_offset <= path_len; end_offset++)
2584 if ((buf[end_offset] == G_SEARCHPATH_SEPARATOR) ||
2585 (end_offset == path_len))
2587 buf[end_offset] = '\0';
2588 module_path[path_num] = g_strdup (buf + start_offset);
2590 module_path[path_num] = NULL;
2591 start_offset = end_offset + 1;
2595 gtk_rc_append_default_module_path();
2599 gtk_rc_parse_path_pattern (GScanner *scanner)
2602 GtkPathType path_type;
2604 gboolean is_binding;
2605 GtkPathPriorityType priority = GTK_PATH_PRIO_RC;
2607 token = g_scanner_get_next_token (scanner);
2610 case GTK_RC_TOKEN_WIDGET:
2611 path_type = GTK_PATH_WIDGET;
2613 case GTK_RC_TOKEN_WIDGET_CLASS:
2614 path_type = GTK_PATH_WIDGET_CLASS;
2616 case GTK_RC_TOKEN_CLASS:
2617 path_type = GTK_PATH_CLASS;
2620 return GTK_RC_TOKEN_WIDGET_CLASS;
2623 token = g_scanner_get_next_token (scanner);
2624 if (token != G_TOKEN_STRING)
2625 return G_TOKEN_STRING;
2627 pattern = g_strdup (scanner->value.v_string);
2629 token = g_scanner_get_next_token (scanner);
2630 if (token == GTK_RC_TOKEN_STYLE)
2632 else if (token == GTK_RC_TOKEN_BINDING)
2635 if (g_scanner_peek_next_token (scanner) == ':')
2637 token = gtk_rc_parse_priority (scanner, &priority);
2638 if (token != G_TOKEN_NONE)
2648 return GTK_RC_TOKEN_STYLE;
2651 token = g_scanner_get_next_token (scanner);
2652 if (token != G_TOKEN_STRING)
2655 return G_TOKEN_STRING;
2660 GtkBindingSet *binding;
2662 binding = gtk_binding_set_find (scanner->value.v_string);
2666 return G_TOKEN_STRING;
2668 gtk_binding_set_add_path (binding, path_type, pattern, priority);
2672 GtkRcStyle *rc_style;
2675 rc_style = gtk_rc_style_find (scanner->value.v_string);
2680 return G_TOKEN_STRING;
2683 rc_set = g_new (GtkRcSet, 1);
2684 gtk_pattern_spec_init (&rc_set->pspec, pattern);
2685 rc_set->rc_style = rc_style;
2687 if (path_type == GTK_PATH_WIDGET)
2688 gtk_rc_sets_widget = g_slist_prepend (gtk_rc_sets_widget, rc_set);
2689 else if (path_type == GTK_PATH_WIDGET_CLASS)
2690 gtk_rc_sets_widget_class = g_slist_prepend (gtk_rc_sets_widget_class, rc_set);
2692 gtk_rc_sets_class = g_slist_prepend (gtk_rc_sets_class, rc_set);
2696 return G_TOKEN_NONE;
2700 gtk_rc_parse_stock_id (GScanner *scanner,
2705 token = g_scanner_get_next_token (scanner);
2706 if (token != G_TOKEN_LEFT_BRACE)
2707 return G_TOKEN_LEFT_BRACE;
2709 token = g_scanner_get_next_token (scanner);
2711 if (token != G_TOKEN_STRING)
2712 return G_TOKEN_STRING;
2714 *stock_id = g_strdup (scanner->value.v_string);
2716 token = g_scanner_get_next_token (scanner);
2717 if (token != G_TOKEN_RIGHT_BRACE)
2720 return G_TOKEN_RIGHT_BRACE;
2723 return G_TOKEN_NONE;
2727 cleanup_source (GtkIconSource *source)
2729 g_free (source->filename);
2730 g_free (source->size);
2734 gtk_rc_parse_icon_source (GScanner *scanner,
2735 GtkIconSet *icon_set)
2738 GtkIconSource source = { NULL, NULL,
2742 token = g_scanner_get_next_token (scanner);
2743 if (token != G_TOKEN_LEFT_CURLY)
2744 return G_TOKEN_LEFT_CURLY;
2746 token = g_scanner_get_next_token (scanner);
2748 if (token != G_TOKEN_STRING)
2749 return G_TOKEN_STRING;
2751 source.filename = g_strdup (scanner->value.v_string);
2753 token = g_scanner_get_next_token (scanner);
2755 if (token == G_TOKEN_RIGHT_CURLY)
2757 gtk_icon_set_add_source (icon_set, &source);
2758 cleanup_source (&source);
2759 return G_TOKEN_NONE;
2761 else if (token != G_TOKEN_COMMA)
2763 cleanup_source (&source);
2764 return G_TOKEN_COMMA;
2767 /* Get the direction */
2769 token = g_scanner_get_next_token (scanner);
2773 case GTK_RC_TOKEN_RTL:
2774 source.any_direction = FALSE;
2775 source.direction = GTK_TEXT_DIR_RTL;
2778 case GTK_RC_TOKEN_LTR:
2779 source.any_direction = FALSE;
2780 source.direction = GTK_TEXT_DIR_LTR;
2787 cleanup_source (&source);
2788 return GTK_RC_TOKEN_RTL;
2792 token = g_scanner_get_next_token (scanner);
2794 if (token == G_TOKEN_RIGHT_CURLY)
2796 gtk_icon_set_add_source (icon_set, &source);
2797 cleanup_source (&source);
2798 return G_TOKEN_NONE;
2800 else if (token != G_TOKEN_COMMA)
2802 cleanup_source (&source);
2803 return G_TOKEN_COMMA;
2808 token = g_scanner_get_next_token (scanner);
2812 case GTK_RC_TOKEN_NORMAL:
2813 source.any_state = FALSE;
2814 source.state = GTK_STATE_NORMAL;
2817 case GTK_RC_TOKEN_PRELIGHT:
2818 source.any_state = FALSE;
2819 source.state = GTK_STATE_PRELIGHT;
2823 case GTK_RC_TOKEN_INSENSITIVE:
2824 source.any_state = FALSE;
2825 source.state = GTK_STATE_INSENSITIVE;
2828 case GTK_RC_TOKEN_ACTIVE:
2829 source.any_state = FALSE;
2830 source.state = GTK_STATE_ACTIVE;
2833 case GTK_RC_TOKEN_SELECTED:
2834 source.any_state = FALSE;
2835 source.state = GTK_STATE_SELECTED;
2842 cleanup_source (&source);
2843 return GTK_RC_TOKEN_PRELIGHT;
2847 token = g_scanner_get_next_token (scanner);
2849 if (token == G_TOKEN_RIGHT_CURLY)
2851 gtk_icon_set_add_source (icon_set, &source);
2852 cleanup_source (&source);
2853 return G_TOKEN_NONE;
2855 else if (token != G_TOKEN_COMMA)
2857 cleanup_source (&source);
2858 return G_TOKEN_COMMA;
2863 token = g_scanner_get_next_token (scanner);
2867 if (token != G_TOKEN_STRING)
2869 cleanup_source (&source);
2870 return G_TOKEN_STRING;
2873 source.size = g_strdup (scanner->value.v_string);
2874 source.any_size = FALSE;
2877 /* Check the close brace */
2879 token = g_scanner_get_next_token (scanner);
2880 if (token != G_TOKEN_RIGHT_CURLY)
2882 cleanup_source (&source);
2883 return G_TOKEN_RIGHT_CURLY;
2886 gtk_icon_set_add_source (icon_set, &source);
2888 cleanup_source (&source);
2890 return G_TOKEN_NONE;
2894 gtk_rc_parse_stock (GScanner *scanner,
2895 GtkRcStyle *rc_style,
2896 GtkIconFactory *factory)
2898 GtkIconSet *icon_set = NULL;
2899 gchar *stock_id = NULL;
2902 token = g_scanner_get_next_token (scanner);
2903 if (token != GTK_RC_TOKEN_STOCK)
2904 return GTK_RC_TOKEN_STOCK;
2906 token = gtk_rc_parse_stock_id (scanner, &stock_id);
2907 if (token != G_TOKEN_NONE)
2910 token = g_scanner_get_next_token (scanner);
2911 if (token != G_TOKEN_EQUAL_SIGN)
2914 return G_TOKEN_EQUAL_SIGN;
2917 token = g_scanner_get_next_token (scanner);
2918 if (token != G_TOKEN_LEFT_CURLY)
2921 return G_TOKEN_LEFT_CURLY;
2924 token = g_scanner_peek_next_token (scanner);
2925 while (token != G_TOKEN_RIGHT_CURLY)
2927 if (icon_set == NULL)
2928 icon_set = gtk_icon_set_new ();
2930 token = gtk_rc_parse_icon_source (scanner, icon_set);
2931 if (token != G_TOKEN_NONE)
2934 gtk_icon_set_unref (icon_set);
2938 token = g_scanner_get_next_token (scanner);
2940 if (token != G_TOKEN_COMMA &&
2941 token != G_TOKEN_RIGHT_CURLY)
2944 gtk_icon_set_unref (icon_set);
2945 return G_TOKEN_RIGHT_CURLY;
2951 gtk_icon_factory_add (factory,
2955 gtk_icon_set_unref (icon_set);
2960 return G_TOKEN_NONE;
2964 typedef GdkPixmap * (*GtkImageLoader) (GdkWindow *window,
2965 GdkColormap *colormap,
2967 GdkColor *transparent_color,
2968 const gchar *filename);
2972 gtk_rc_set_image_loader(GtkImageLoader loader)
2974 image_loader = loader;
2978 gtk_rc_load_image (GdkColormap *colormap,
2979 GdkColor *transparent_color,
2980 const gchar *filename)
2982 if (strcmp (filename, "<parent>") == 0)
2983 return (GdkPixmap*) GDK_PARENT_RELATIVE;
2987 return image_loader(NULL, colormap, NULL,
2991 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,