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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 TOKEN_INVALID = G_TOKEN_LAST,
61 typedef struct _GtkRcStyle GtkRcStyle;
62 typedef struct _GtkRcSet GtkRcSet;
63 typedef struct _GtkRcNode GtkRcNode;
76 char *bg_pixmap_name[5];
77 GtkStyle *proto_style;
88 static guint gtk_rc_style_hash (const char *name);
89 static gint gtk_rc_style_compare (const char *a,
91 static GtkRcStyle* gtk_rc_style_find (const char *name);
92 static GtkRcStyle* gtk_rc_styles_match (GSList *sets,
94 static gint gtk_rc_style_match (const char *set,
96 static GtkStyle* gtk_rc_style_init (GtkRcStyle *rc_style,
98 static void gtk_rc_parse_any (const gchar *input_name,
100 const gchar *input_string);
101 static gint gtk_rc_parse_statement (GScanner *scanner);
102 static gint gtk_rc_parse_style (GScanner *scanner);
103 static gint gtk_rc_parse_style_option (GScanner *scanner,
104 GtkRcStyle *rc_style);
105 static gint gtk_rc_parse_base (GScanner *scanner,
107 static gint gtk_rc_parse_bg (GScanner *scanner,
109 static gint gtk_rc_parse_fg (GScanner *scanner,
111 static gint gtk_rc_parse_text (GScanner *scanner,
113 static gint gtk_rc_parse_bg_pixmap (GScanner *scanner,
114 GtkRcStyle *rc_style);
115 static gint gtk_rc_parse_font (GScanner *scanner,
116 GtkRcStyle *rc_style);
117 static gint gtk_rc_parse_fontset (GScanner *scanner,
118 GtkRcStyle *rc_style);
119 static gint gtk_rc_parse_state (GScanner *scanner,
120 GtkStateType *state);
121 static gint gtk_rc_parse_color (GScanner *scanner,
123 static gint gtk_rc_parse_pixmap_path (GScanner *scanner);
124 static void gtk_rc_parse_pixmap_path_string (gchar *pix_path);
125 static char* gtk_rc_find_pixmap_in_path (GScanner *scanner,
127 static gint gtk_rc_parse_widget_style (GScanner *scanner);
128 static gint gtk_rc_parse_widget_class_style (GScanner *scanner);
129 static char* gtk_rc_widget_path (GtkWidget *widget);
130 static char* gtk_rc_widget_class_path (GtkWidget *widget);
133 static GScannerConfig gtk_rc_scanner_config =
137 ) /* cset_skip_characters */,
142 ) /* cset_identifier_first */,
149 ) /* cset_identifier_nth */,
150 ( "#\n" ) /* cpair_comment_single */,
152 TRUE /* case_sensitive */,
154 TRUE /* skip_comment_multi */,
155 TRUE /* skip_comment_single */,
156 TRUE /* scan_comment_multi */,
157 TRUE /* scan_identifier */,
158 FALSE /* scan_identifier_1char */,
159 FALSE /* scan_identifier_NULL */,
160 TRUE /* scan_symbols */,
161 TRUE /* scan_binary */,
162 TRUE /* scan_octal */,
163 TRUE /* scan_float */,
165 TRUE /* scan_hex_dollar */,
166 TRUE /* scan_string_sq */,
167 TRUE /* scan_string_dq */,
168 TRUE /* numbers_2_int */,
169 FALSE /* int_2_float */,
170 TRUE /* identifier_2_string */,
171 TRUE /* char_2_token */,
172 TRUE /* symbol_2_token */,
181 { "ACTIVE", TOKEN_ACTIVE },
182 { "base", TOKEN_BASE },
184 { "bg_pixmap", TOKEN_BG_PIXMAP },
186 { "font", TOKEN_FONT },
187 { "fontset", TOKEN_FONTSET },
188 { "INSENSITIVE", TOKEN_INSENSITIVE },
189 { "NORMAL", TOKEN_NORMAL },
190 { "pixmap_path", TOKEN_PIXMAP_PATH },
191 { "PRELIGHT", TOKEN_PRELIGHT },
192 { "SELECTED", TOKEN_SELECTED },
193 { "style", TOKEN_STYLE },
194 { "text", TOKEN_TEXT },
195 { "widget", TOKEN_WIDGET },
196 { "widget_class", TOKEN_WIDGET_CLASS },
198 static int nsymbols = sizeof (symbols) / sizeof (symbols[0]);
202 static GHashTable *rc_style_ht = NULL;
203 static GSList *widget_sets = NULL;
204 static GSList *widget_class_sets = NULL;
206 #define GTK_RC_MAX_PIXMAP_PATHS 128
207 static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
213 rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
214 (GCompareFunc) gtk_rc_style_compare);
218 gtk_rc_parse_string (const gchar *rc_string)
220 g_return_if_fail (rc_string != NULL);
222 gtk_rc_parse_any ("-", -1, rc_string);
226 gtk_rc_parse (const gchar *filename)
230 g_return_if_fail (filename != NULL);
232 fd = open (filename, O_RDONLY);
236 gtk_rc_parse_any (filename, fd, NULL);
242 gtk_rc_get_style (GtkWidget *widget)
244 GtkRcStyle *rc_style;
249 path = gtk_rc_widget_path (widget);
252 rc_style = gtk_rc_styles_match (widget_sets, path);
257 return gtk_rc_style_init (rc_style,
258 gtk_widget_get_colormap (widget));
263 if (widget_class_sets)
265 path = gtk_rc_widget_class_path (widget);
268 rc_style = gtk_rc_styles_match (widget_class_sets, path);
273 return gtk_rc_style_init (rc_style,
274 gtk_widget_get_colormap (widget));
283 gtk_rc_add_widget_name_style (GtkStyle *style,
286 GtkRcStyle *rc_style;
290 gtk_style_ref (style);
292 rc_style = g_new (GtkRcStyle, 1);
293 rc_style->name = NULL;
294 rc_style->font_name = NULL;
295 rc_style->fontset_name = NULL;
297 for (i = 0; i < 5; i++)
298 rc_style->bg_pixmap_name[i] = NULL;
300 rc_style->styles = g_list_append (NULL, style);
302 rc_set = g_new (GtkRcSet, 1);
303 rc_set->set = g_strdup (pattern);
304 rc_set->rc_style = rc_style;
306 widget_sets = g_slist_append (widget_sets, rc_set);
310 gtk_rc_add_widget_class_style (GtkStyle *style,
313 GtkRcStyle *rc_style;
317 gtk_style_ref (style);
319 rc_style = g_new (GtkRcStyle, 1);
320 rc_style->name = NULL;
321 rc_style->font_name = NULL;
322 rc_style->fontset_name = NULL;
324 for (i = 0; i < 5; i++)
325 rc_style->bg_pixmap_name[i] = NULL;
327 rc_style->styles = g_list_append (NULL, style);
329 rc_set = g_new (GtkRcSet, 1);
330 rc_set->set = g_strdup (pattern);
331 rc_set->rc_style = rc_style;
333 widget_class_sets = g_slist_append (widget_class_sets, rc_set);
337 gtk_rc_parse_any (const gchar *input_name,
339 const gchar *input_string)
344 scanner = g_scanner_new (>k_rc_scanner_config);
348 g_assert (input_string == NULL);
350 g_scanner_input_file (scanner, input_fd);
354 g_assert (input_string != NULL);
356 g_scanner_input_text (scanner, input_string, strlen (input_string));
359 for (i = 0; i < nsymbols; i++)
360 g_scanner_add_symbol (scanner, symbols[i].name, (gpointer) symbols[i].token);
365 if (gtk_rc_parse_statement (scanner) != PARSE_OK)
367 if (scanner->next_token != G_TOKEN_NONE)
368 g_scanner_get_next_token (scanner);
371 g_warning ("rc string parse error: line %d",
374 g_warning ("rc file parse error: \"%s\" line %d",
381 g_scanner_destroy (scanner);
385 gtk_rc_style_hash (const char *name)
391 result += (result << 3) + *name++;
397 gtk_rc_style_compare (const char *a,
400 return (strcmp (a, b) == 0);
404 gtk_rc_style_find (const char *name)
406 GtkRcStyle *rc_style;
408 rc_style = g_hash_table_lookup (rc_style_ht, (gpointer) name);
414 gtk_rc_styles_match (GSList *sets,
424 if (gtk_rc_style_match (rc_set->set, path))
425 return rc_set->rc_style;
432 gtk_rc_style_match (const char *set,
441 return (*path == '\0');
455 while (*path && (ch != *path))
462 if (gtk_rc_style_match (set, path))
483 gtk_rc_style_init (GtkRcStyle *rc_style, GdkColormap *cmap)
486 gboolean match_cmap = FALSE;
490 GtkStyle *style = NULL;
493 tmp_list = rc_style->styles;
496 if (rc_style->bg_pixmap_name[i])
501 node = (GtkRcNode *)tmp_list->data;
503 if (!match_cmap || (node->cmap == cmap))
509 tmp_list = tmp_list->next;
514 node = g_new (GtkRcNode, 1);
515 style = gtk_style_copy (rc_style->proto_style);
517 /* FIXME, this leaks colormaps, but if we don't do this, then we'll
518 * be screwed, because we identify colormaps by address equality
520 gdk_colormap_ref (cmap);
525 if (rc_style->fontset_name)
527 old_font = style->font;
528 style->font = gdk_fontset_load (rc_style->fontset_name);
530 gdk_font_unref (old_font);
532 style->font = old_font;
534 else if (rc_style->font_name)
536 old_font = style->font;
537 style->font = gdk_font_load (rc_style->font_name);
539 gdk_font_unref (old_font);
541 style->font = old_font;
544 for (i = 0; i < 5; i++)
545 if (rc_style->bg_pixmap_name[i])
547 if (strcmp (rc_style->bg_pixmap_name[i], "<parent>") == 0)
548 style->bg_pixmap[i] = (GdkPixmap*) GDK_PARENT_RELATIVE;
550 style->bg_pixmap[i] =
551 gdk_pixmap_colormap_create_from_xpm (NULL, cmap,
554 rc_style->bg_pixmap_name[i]);
557 rc_style->styles = g_list_append (rc_style->styles, node);
564 gtk_rc_parse_statement (GScanner *scanner)
569 token = g_scanner_peek_next_token (scanner);
570 if (token == G_TOKEN_EOF)
576 error = gtk_rc_parse_style (scanner);
577 if (error != PARSE_SYNTAX)
580 error = gtk_rc_parse_pixmap_path (scanner);
581 if (error != PARSE_SYNTAX)
584 error = gtk_rc_parse_widget_style (scanner);
585 if (error != PARSE_SYNTAX)
588 error = gtk_rc_parse_widget_class_style (scanner);
594 gtk_rc_parse_style (GScanner *scanner)
596 GtkRcStyle *rc_style;
597 GtkRcStyle *parent_style;
603 token = g_scanner_peek_next_token (scanner);
604 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
606 if (token != TOKEN_STYLE)
608 token = g_scanner_get_next_token (scanner);
610 token = g_scanner_get_next_token (scanner);
611 if (token != G_TOKEN_STRING)
615 rc_style = g_hash_table_lookup (rc_style_ht, scanner->value.v_string);
620 rc_style = g_new (GtkRcStyle, 1);
621 rc_style->name = g_strdup (scanner->value.v_string);
622 rc_style->font_name = NULL;
623 rc_style->fontset_name = NULL;
625 for (i = 0; i < 5; i++)
626 rc_style->bg_pixmap_name[i] = NULL;
628 rc_style->proto_style = gtk_style_new();
629 rc_style->styles = NULL;
632 token = g_scanner_peek_next_token (scanner);
633 if (token == G_TOKEN_EQUAL_SIGN)
635 token = g_scanner_get_next_token (scanner);
637 token = g_scanner_get_next_token (scanner);
638 if (token != G_TOKEN_STRING)
642 gtk_style_unref (rc_style->proto_style);
648 parent_style = g_hash_table_lookup (rc_style_ht, scanner->value.v_string);
651 for (i = 0; i < 5; i++)
653 rc_style->proto_style->fg[i] = parent_style->proto_style->fg[i];
654 rc_style->proto_style->bg[i] = parent_style->proto_style->bg[i];
655 rc_style->proto_style->light[i] = parent_style->proto_style->light[i];
656 rc_style->proto_style->dark[i] = parent_style->proto_style->dark[i];
657 rc_style->proto_style->mid[i] = parent_style->proto_style->mid[i];
658 rc_style->proto_style->text[i] = parent_style->proto_style->text[i];
659 rc_style->proto_style->base[i] = parent_style->proto_style->base[i];
662 rc_style->proto_style->black = parent_style->proto_style->black;
663 rc_style->proto_style->white = parent_style->proto_style->white;
665 if (rc_style->fontset_name)
667 g_free (rc_style->fontset_name);
668 rc_style->fontset_name = g_strdup (parent_style->fontset_name);
670 else if (rc_style->font_name)
672 g_free (rc_style->font_name);
673 rc_style->font_name = g_strdup (parent_style->font_name);
676 for (i = 0; i < 5; i++)
678 if (rc_style->bg_pixmap_name[i])
679 g_free (rc_style->bg_pixmap_name[i]);
680 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
685 token = g_scanner_get_next_token (scanner);
686 if (token != G_TOKEN_LEFT_CURLY)
690 gtk_style_unref (rc_style->proto_style);
698 error = gtk_rc_parse_style_option (scanner, rc_style);
699 if (error == PARSE_SYNTAX)
701 if (error == PARSE_ERROR)
705 gtk_style_unref (rc_style->proto_style);
712 token = g_scanner_get_next_token (scanner);
713 if (token != G_TOKEN_RIGHT_CURLY)
717 if (rc_style->fontset_name)
718 g_free (rc_style->fontset_name);
719 else if (rc_style->font_name)
720 g_free (rc_style->font_name);
722 for (i = 0; i < 5; i++)
723 if (rc_style->bg_pixmap_name[i])
724 g_free (rc_style->bg_pixmap_name[i]);
726 gtk_style_unref (rc_style->proto_style);
733 g_hash_table_insert (rc_style_ht, rc_style->name, rc_style);
739 gtk_rc_parse_style_option (GScanner *scanner,
740 GtkRcStyle *rc_style)
745 token = g_scanner_peek_next_token (scanner);
746 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
749 error = gtk_rc_parse_base (scanner, rc_style->proto_style);
750 if (error != PARSE_SYNTAX)
753 error = gtk_rc_parse_bg (scanner, rc_style->proto_style);
754 if (error != PARSE_SYNTAX)
757 error = gtk_rc_parse_fg (scanner, rc_style->proto_style);
758 if (error != PARSE_SYNTAX)
761 error = gtk_rc_parse_text (scanner, rc_style->proto_style);
762 if (error != PARSE_SYNTAX)
765 error = gtk_rc_parse_bg_pixmap (scanner, rc_style);
766 if (error != PARSE_SYNTAX)
769 error = gtk_rc_parse_font (scanner, rc_style);
770 if (error != PARSE_SYNTAX)
773 error = gtk_rc_parse_fontset (scanner, rc_style);
779 gtk_rc_parse_base (GScanner *scanner,
786 token = g_scanner_peek_next_token (scanner);
787 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
789 if (token != TOKEN_BASE)
791 token = g_scanner_get_next_token (scanner);
793 error = gtk_rc_parse_state (scanner, &state);
794 if (error != PARSE_OK)
797 token = g_scanner_get_next_token (scanner);
798 if (token != G_TOKEN_EQUAL_SIGN)
801 error = gtk_rc_parse_color (scanner, &style->base[state]);
807 gtk_rc_parse_bg (GScanner *scanner,
814 token = g_scanner_peek_next_token (scanner);
815 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
817 if (token != TOKEN_BG)
819 token = g_scanner_get_next_token (scanner);
821 error = gtk_rc_parse_state (scanner, &state);
822 if (error != PARSE_OK)
825 token = g_scanner_get_next_token (scanner);
826 if (token != G_TOKEN_EQUAL_SIGN)
829 error = gtk_rc_parse_color (scanner, &style->bg[state]);
835 gtk_rc_parse_fg (GScanner *scanner,
842 token = g_scanner_peek_next_token (scanner);
843 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
845 if (token != TOKEN_FG)
847 token = g_scanner_get_next_token (scanner);
849 error = gtk_rc_parse_state (scanner, &state);
850 if (error != PARSE_OK)
853 token = g_scanner_get_next_token (scanner);
854 if (token != G_TOKEN_EQUAL_SIGN)
857 error = gtk_rc_parse_color (scanner, &style->fg[state]);
863 gtk_rc_parse_text (GScanner *scanner,
870 token = g_scanner_peek_next_token (scanner);
871 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
873 if (token != TOKEN_TEXT)
875 token = g_scanner_get_next_token (scanner);
877 error = gtk_rc_parse_state (scanner, &state);
878 if (error != PARSE_OK)
881 token = g_scanner_get_next_token (scanner);
882 if (token != G_TOKEN_EQUAL_SIGN)
885 error = gtk_rc_parse_color (scanner, &style->text[state]);
891 gtk_rc_parse_bg_pixmap (GScanner *scanner,
892 GtkRcStyle *rc_style)
899 token = g_scanner_peek_next_token (scanner);
900 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
902 if (token != TOKEN_BG_PIXMAP)
904 token = g_scanner_get_next_token (scanner);
906 error = gtk_rc_parse_state (scanner, &state);
907 if (error != PARSE_OK)
910 token = g_scanner_get_next_token (scanner);
911 if (token != G_TOKEN_EQUAL_SIGN)
914 token = g_scanner_get_next_token (scanner);
915 if (token != G_TOKEN_STRING)
918 if (strcmp (scanner->value.v_string, "<parent>"))
919 pixmap_file = gtk_rc_find_pixmap_in_path (scanner, scanner->value.v_string);
921 pixmap_file = g_strdup (scanner->value.v_string);
925 if (rc_style->bg_pixmap_name[state])
926 g_free (rc_style->bg_pixmap_name[state]);
927 rc_style->bg_pixmap_name[state] = pixmap_file;
934 gtk_rc_find_pixmap_in_path (GScanner *scanner,
941 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (pixmap_path[i] != NULL); i++)
943 buf = g_malloc (strlen (pixmap_path[i]) + strlen (pixmap_file) + 2);
944 sprintf (buf, "%s%c%s", pixmap_path[i], '/', pixmap_file);
946 fd = open (buf, O_RDONLY);
956 g_warning ("Unable to locate image file in pixmap_path: \"%s\" line %d",
957 pixmap_file, scanner->line);
963 gtk_rc_parse_font (GScanner *scanner,
964 GtkRcStyle *rc_style)
968 token = g_scanner_peek_next_token (scanner);
969 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
971 if (token != TOKEN_FONT)
973 token = g_scanner_get_next_token (scanner);
975 token = g_scanner_get_next_token (scanner);
976 if (token != G_TOKEN_EQUAL_SIGN)
979 token = g_scanner_get_next_token (scanner);
980 if (token != G_TOKEN_STRING)
983 if (rc_style->font_name)
984 g_free (rc_style->font_name);
985 rc_style->font_name = g_strdup (scanner->value.v_string);
991 gtk_rc_parse_fontset (GScanner *scanner,
992 GtkRcStyle *rc_style)
996 token = g_scanner_peek_next_token (scanner);
997 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
999 if (token != TOKEN_FONTSET)
1000 return PARSE_SYNTAX;
1001 token = g_scanner_get_next_token (scanner);
1003 token = g_scanner_get_next_token (scanner);
1004 if (token != G_TOKEN_EQUAL_SIGN)
1007 token = g_scanner_get_next_token (scanner);
1008 if (token != G_TOKEN_STRING)
1011 if (rc_style->fontset_name)
1012 g_free (rc_style->fontset_name);
1013 rc_style->fontset_name = g_strdup (scanner->value.v_string);
1019 gtk_rc_parse_state (GScanner *scanner,
1020 GtkStateType *state)
1024 token = g_scanner_peek_next_token (scanner);
1025 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
1027 if (token != G_TOKEN_LEFT_BRACE)
1028 return PARSE_SYNTAX;
1029 token = g_scanner_get_next_token (scanner);
1031 token = g_scanner_get_next_token (scanner);
1032 if (token == TOKEN_ACTIVE)
1033 *state = GTK_STATE_ACTIVE;
1034 else if (token == TOKEN_INSENSITIVE)
1035 *state = GTK_STATE_INSENSITIVE;
1036 else if (token == TOKEN_NORMAL)
1037 *state = GTK_STATE_NORMAL;
1038 else if (token == TOKEN_PRELIGHT)
1039 *state = GTK_STATE_PRELIGHT;
1040 else if (token == TOKEN_SELECTED)
1041 *state = GTK_STATE_SELECTED;
1045 token = g_scanner_get_next_token (scanner);
1046 if (token != G_TOKEN_RIGHT_BRACE)
1053 gtk_rc_parse_color (GScanner *scanner,
1063 token = g_scanner_peek_next_token (scanner);
1064 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
1069 case G_TOKEN_LEFT_CURLY:
1070 token = g_scanner_get_next_token (scanner);
1072 token = g_scanner_get_next_token (scanner);
1073 if (token == G_TOKEN_INT)
1074 token_int = scanner->value.v_int;
1075 else if (token == G_TOKEN_FLOAT)
1076 token_int = scanner->value.v_float * 65535.0;
1079 color->red = CLAMP (token_int, 0, 65535);
1081 token = g_scanner_get_next_token (scanner);
1082 if (token != G_TOKEN_COMMA)
1085 token = g_scanner_get_next_token (scanner);
1086 if (token == G_TOKEN_INT)
1087 token_int = scanner->value.v_int;
1088 else if (token == G_TOKEN_FLOAT)
1089 token_int = scanner->value.v_float * 65535.0;
1092 color->green = CLAMP (token_int, 0, 65535);
1094 token = g_scanner_get_next_token (scanner);
1095 if (token != G_TOKEN_COMMA)
1098 token = g_scanner_get_next_token (scanner);
1099 if (token == G_TOKEN_INT)
1100 token_int = scanner->value.v_int;
1101 else if (token == G_TOKEN_FLOAT)
1102 token_int = scanner->value.v_float * 65535.0;
1105 color->blue = CLAMP (token_int, 0, 65535);
1107 token = g_scanner_get_next_token (scanner);
1108 if (token != G_TOKEN_RIGHT_CURLY)
1112 case G_TOKEN_STRING:
1113 token = g_scanner_get_next_token (scanner);
1115 if (scanner->value.v_string[0] != '#')
1118 length = strlen (scanner->value.v_string) - 1;
1119 if (((length % 3) != 0) || (length > 12))
1123 for (i = 0, j = 1; i < length; i++, j++)
1124 buf[i] = scanner->value.v_string[j];
1127 sscanf (buf, "%x", &temp);
1130 for (i = 0; i < length; i++, j++)
1131 buf[i] = scanner->value.v_string[j];
1134 sscanf (buf, "%x", &temp);
1135 color->green = temp;
1137 for (i = 0; i < length; i++, j++)
1138 buf[i] = scanner->value.v_string[j];
1141 sscanf (buf, "%x", &temp);
1147 color->green *= 4369;
1148 color->blue *= 4369;
1150 else if (length == 2)
1153 color->green *= 257;
1156 else if (length == 3)
1168 return PARSE_SYNTAX;
1175 gtk_rc_parse_pixmap_path (GScanner *scanner)
1179 token = g_scanner_peek_next_token (scanner);
1180 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
1182 if (token != TOKEN_PIXMAP_PATH)
1183 return PARSE_SYNTAX;
1184 token = g_scanner_get_next_token (scanner);
1186 token = g_scanner_get_next_token (scanner);
1188 if (token != G_TOKEN_STRING)
1191 gtk_rc_parse_pixmap_path_string (scanner->value.v_string);
1197 gtk_rc_parse_pixmap_path_string (gchar *pix_path)
1201 gint start_offset = 0;
1205 /* free the old one, or just add to the old one ? */
1206 for (path_num=0; pixmap_path[path_num]; path_num++)
1208 g_free (pixmap_path[path_num]);
1209 pixmap_path[path_num] = NULL;
1214 path_len = strlen (pix_path);
1216 buf = g_strdup (pix_path);
1218 for (end_offset = 0; end_offset <= path_len; end_offset++)
1220 if ((buf[end_offset] == ':') ||
1221 (end_offset == path_len))
1223 buf[end_offset] = '\0';
1224 pixmap_path[path_num] = g_strdup (buf + start_offset);
1226 pixmap_path[path_num] = NULL;
1227 start_offset = end_offset + 1;
1234 gtk_rc_parse_widget_style (GScanner *scanner)
1239 token = g_scanner_peek_next_token (scanner);
1240 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
1242 if (token != TOKEN_WIDGET)
1243 return PARSE_SYNTAX;
1244 token = g_scanner_get_next_token (scanner);
1246 token = g_scanner_get_next_token (scanner);
1247 if (token != G_TOKEN_STRING)
1250 rc_set = g_new (GtkRcSet, 1);
1251 rc_set->set = g_strdup (scanner->value.v_string);
1253 token = g_scanner_get_next_token (scanner);
1254 if (token != TOKEN_STYLE)
1256 g_free (rc_set->set);
1261 token = g_scanner_get_next_token (scanner);
1262 if (token != G_TOKEN_STRING)
1264 g_free (rc_set->set);
1269 rc_set->rc_style = gtk_rc_style_find (scanner->value.v_string);
1270 if (!rc_set->rc_style)
1272 g_free (rc_set->set);
1277 widget_sets = g_slist_append (widget_sets, rc_set);
1283 gtk_rc_parse_widget_class_style (GScanner *scanner)
1288 token = g_scanner_peek_next_token (scanner);
1289 if (token == G_TOKEN_EOF || token == G_TOKEN_ERROR)
1291 if (token != TOKEN_WIDGET_CLASS)
1292 return PARSE_SYNTAX;
1293 token = g_scanner_get_next_token (scanner);
1295 token = g_scanner_get_next_token (scanner);
1296 if (token != G_TOKEN_STRING)
1299 rc_set = g_new (GtkRcSet, 1);
1300 rc_set->set = g_strdup (scanner->value.v_string);
1302 token = g_scanner_get_next_token (scanner);
1303 if (token != TOKEN_STYLE)
1305 g_free (rc_set->set);
1310 token = g_scanner_get_next_token (scanner);
1311 if (token != G_TOKEN_STRING)
1313 g_free (rc_set->set);
1318 rc_set->rc_style = gtk_rc_style_find (scanner->value.v_string);
1319 if (!rc_set->rc_style)
1321 g_free (rc_set->set);
1326 widget_class_sets = g_slist_append (widget_class_sets, rc_set);
1332 gtk_rc_widget_path (GtkWidget *widget)
1334 GtkWidget *tmp_widget;
1343 tmp_widget = widget;
1346 name = gtk_widget_get_name (tmp_widget);
1347 pathlength += strlen (name);
1349 tmp_widget = tmp_widget->parent;
1355 path = g_new (char, pathlength + 1);
1356 path[pathlength] = '\0';
1358 tmp_widget = widget;
1361 name = gtk_widget_get_name (tmp_widget);
1362 namelength = strlen (name);
1364 strncpy (&path[pathlength - namelength], name, namelength);
1365 pathlength -= namelength;
1367 tmp_widget = tmp_widget->parent;
1372 path[pathlength] = '.';
1380 gtk_rc_widget_class_path (GtkWidget *widget)
1382 GtkWidget *tmp_widget;
1391 tmp_widget = widget;
1394 name = gtk_type_name (GTK_WIDGET_TYPE (tmp_widget));
1395 pathlength += strlen (name);
1397 tmp_widget = tmp_widget->parent;
1403 path = g_new (char, pathlength + 1);
1404 path[pathlength] = '\0';
1406 tmp_widget = widget;
1409 name = gtk_type_name (GTK_WIDGET_TYPE (tmp_widget));
1410 namelength = strlen (name);
1412 strncpy (&path[pathlength - namelength], name, namelength);
1413 pathlength -= namelength;
1415 tmp_widget = tmp_widget->parent;
1420 path[pathlength] = '.';