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.
70 typedef struct _GtkRcStyle GtkRcStyle;
71 typedef struct _GtkRcSet GtkRcSet;
79 char *bg_pixmap_name[5];
90 static guint gtk_rc_style_hash (const char *name);
91 static gint gtk_rc_style_compare (const char *a,
93 static GtkRcStyle* gtk_rc_style_find (const char *name);
94 static GtkRcStyle* gtk_rc_styles_match (GSList *sets,
96 static gint gtk_rc_style_match (const char *set,
98 static void gtk_rc_style_init (GtkRcStyle *rc_style);
99 static gint gtk_rc_get_token (void);
100 static gint gtk_rc_simple_token (char ch);
101 static gint gtk_rc_symbol_token (const char *sym);
102 static gint gtk_rc_get_next_token (void);
103 static gint gtk_rc_peek_next_token (void);
104 static gint gtk_rc_parse_statement (void);
105 static gint gtk_rc_parse_style (void);
106 static gint gtk_rc_parse_style_option (GtkRcStyle *rc_style);
107 static gint gtk_rc_parse_base (GtkStyle *style);
108 static gint gtk_rc_parse_bg (GtkStyle *style);
109 static gint gtk_rc_parse_fg (GtkStyle *style);
110 static gint gtk_rc_parse_bg_pixmap (GtkRcStyle *rc_style);
111 static gint gtk_rc_parse_font (GtkRcStyle *rc_style);
112 static gint gtk_rc_parse_fontset (GtkRcStyle *rc_style);
113 static gint gtk_rc_parse_state (GtkStateType *state);
114 static gint gtk_rc_parse_color (GdkColor *color);
115 static gint gtk_rc_parse_pixmap_path (void);
116 static void gtk_rc_parse_pixmap_path_string (gchar *pix_path);
117 static char* gtk_rc_find_pixmap_in_path (gchar *pixmap_file);
118 static gint gtk_rc_parse_widget_style (void);
119 static gint gtk_rc_parse_widget_class_style (void);
120 static char* gtk_rc_widget_path (GtkWidget *widget);
121 static char* gtk_rc_widget_class_path (GtkWidget *widget);
130 { "ACTIVE", TOKEN_ACTIVE },
131 { "base", TOKEN_BASE },
133 { "bg_pixmap", TOKEN_BG_PIXMAP },
135 { "font", TOKEN_FONT },
136 { "fontset", TOKEN_FONTSET },
137 { "INSENSITIVE", TOKEN_INSENSITIVE },
138 { "NORMAL", TOKEN_NORMAL },
139 { "pixmap_path", TOKEN_PIXMAP_PATH },
140 { "PRELIGHT", TOKEN_PRELIGHT },
141 { "SELECTED", TOKEN_SELECTED },
142 { "style", TOKEN_STYLE },
143 { "text", TOKEN_TEXT },
144 { "widget", TOKEN_WIDGET },
145 { "widget_class", TOKEN_WIDGET_CLASS },
148 static int nsymbols = sizeof (symbols) / sizeof (symbols[0]);
156 { '{', TOKEN_LEFT_CURLY },
157 { '}', TOKEN_RIGHT_CURLY },
158 { '[', TOKEN_LEFT_BRACE },
159 { ']', TOKEN_RIGHT_BRACE },
160 { '=', TOKEN_EQUAL_SIGN },
161 { ',', TOKEN_COMMA },
164 static int nsimple_tokens = sizeof (simple_tokens) / sizeof (simple_tokens[0]);
166 static FILE *input_fp = NULL;
167 static char *buffer = NULL;
168 static char *tokenbuf = NULL;
169 static int position = 0;
170 static int linenum = 1;
171 static int buffer_size = 1024;
172 static int tokenbuf_size = 1024;
175 static int cur_token;
176 static int next_token;
178 static char *token_str;
179 static double token_float;
180 static int token_int;
182 static GHashTable *rc_style_ht = NULL;
183 static GSList *widget_sets = NULL;
184 static GSList *widget_class_sets = NULL;
186 #define GTK_RC_MAX_PIXMAP_PATHS 128
187 static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
193 rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
194 (GCompareFunc) gtk_rc_style_compare);
198 gtk_rc_parse (const char *filename)
200 input_fp = fopen (filename, "r");
204 buffer = g_new (char, buffer_size + tokenbuf_size);
205 tokenbuf = buffer + buffer_size;
215 if (gtk_rc_parse_statement () != PARSE_OK)
217 g_warning ("rc file parse error: \"%s\" line %d",
234 gtk_rc_get_style (GtkWidget *widget)
236 GtkRcStyle *rc_style;
241 path = gtk_rc_widget_path (widget);
244 rc_style = gtk_rc_styles_match (widget_sets, path);
249 gtk_rc_style_init (rc_style);
250 return rc_style->style;
255 if (widget_class_sets)
257 path = gtk_rc_widget_class_path (widget);
260 rc_style = gtk_rc_styles_match (widget_class_sets, path);
265 gtk_rc_style_init (rc_style);
266 return rc_style->style;
271 return widget->style;
275 gtk_rc_add_widget_name_style (GtkStyle *style,
278 GtkRcStyle *rc_style;
282 gtk_style_ref (style);
284 rc_style = g_new (GtkRcStyle, 1);
285 rc_style->initialize = FALSE;
286 rc_style->name = NULL;
287 rc_style->font_name = NULL;
288 rc_style->fontset_name = NULL;
290 for (i = 0; i < 5; i++)
291 rc_style->bg_pixmap_name[i] = NULL;
293 rc_style->style = style;
295 rc_set = g_new (GtkRcSet, 1);
296 rc_set->set = g_strdup (pattern);
297 rc_set->rc_style = rc_style;
299 widget_sets = g_slist_append (widget_sets, rc_set);
303 gtk_rc_add_widget_class_style (GtkStyle *style,
306 GtkRcStyle *rc_style;
310 gtk_style_ref (style);
312 rc_style = g_new (GtkRcStyle, 1);
313 rc_style->initialize = FALSE;
314 rc_style->name = NULL;
315 rc_style->font_name = NULL;
316 rc_style->fontset_name = NULL;
318 for (i = 0; i < 5; i++)
319 rc_style->bg_pixmap_name[i] = NULL;
321 rc_style->style = style;
323 rc_set = g_new (GtkRcSet, 1);
324 rc_set->set = g_strdup (pattern);
325 rc_set->rc_style = rc_style;
327 widget_class_sets = g_slist_append (widget_class_sets, rc_set);
332 gtk_rc_style_hash (const char *name)
338 result += (result << 3) + *name++;
344 gtk_rc_style_compare (const char *a,
347 return (strcmp (a, b) == 0);
351 gtk_rc_style_find (const char *name)
353 GtkRcStyle *rc_style;
355 rc_style = g_hash_table_lookup (rc_style_ht, (gpointer) name);
361 gtk_rc_styles_match (GSList *sets,
371 if (gtk_rc_style_match (rc_set->set, path))
372 return rc_set->rc_style;
379 gtk_rc_style_match (const char *set,
388 return (*path == '\0');
402 while (*path && (ch != *path))
409 if (gtk_rc_style_match (set, path))
430 gtk_rc_style_init (GtkRcStyle *rc_style)
435 if (rc_style->initialize)
437 rc_style->initialize = FALSE;
439 if (rc_style->fontset_name)
441 old_font = rc_style->style->font;
442 rc_style->style->font = gdk_fontset_load (rc_style->fontset_name);
443 if (rc_style->style->font)
444 gdk_fontset_free (old_font);
446 rc_style->style->font = old_font;
448 else if (rc_style->font_name)
450 old_font = rc_style->style->font;
451 rc_style->style->font = gdk_font_load (rc_style->font_name);
452 if (rc_style->style->font)
453 gdk_font_free (old_font);
455 rc_style->style->font = old_font;
458 for (i = 0; i < 5; i++)
459 if (rc_style->bg_pixmap_name[i])
461 if (strcmp (rc_style->bg_pixmap_name[i], "<parent>") == 0)
462 rc_style->style->bg_pixmap[i] = (GdkPixmap*) GDK_PARENT_RELATIVE;
464 rc_style->style->bg_pixmap[i] = gdk_pixmap_create_from_xpm (NULL, NULL,
465 &rc_style->style->bg[i],
466 rc_style->bg_pixmap_name[i]);
478 int hex_number = FALSE;
479 int float_number = FALSE;
487 if (position >= (buffer_size - 1))
489 if (!position || (buffer[position] == '\0'))
491 count = fread (buffer, sizeof (char), buffer_size - 1, input_fp);
492 if ((count == 0) && feof (input_fp))
494 buffer[count] = '\0';
497 ch = buffer[position++];
504 token = gtk_rc_simple_token (ch);
509 state = PARSE_COMMENT;
511 state = PARSE_STRING;
512 else if ((ch == ' ') || (ch == '\t') || (ch == '\n'))
518 tokenbuf[tokenpos++] = ch;
519 state = PARSE_NUMBER;
521 else if ((ch == '$') || (ch == '#'))
524 float_number = FALSE;
525 state = PARSE_NUMBER;
527 else if (isdigit (ch))
530 float_number = FALSE;
531 tokenbuf[tokenpos++] = ch;
532 state = PARSE_NUMBER;
536 tokenbuf[tokenpos++] = ch;
537 state = PARSE_SYMBOL;
549 tokenbuf[tokenpos++] = ch;
553 tokenbuf[tokenpos] = '\0';
554 token_str = tokenbuf;
560 if ((ch != ' ') && (ch != '\t') && (ch != '\n') &&
561 (gtk_rc_simple_token (ch) == 0))
563 tokenbuf[tokenpos++] = ch;
568 tokenbuf[tokenpos] = '\0';
569 token_str = tokenbuf;
570 return gtk_rc_symbol_token (tokenbuf);
575 if (isdigit (ch) || (hex_number && isxdigit (ch)))
577 tokenbuf[tokenpos++] = ch;
579 else if (!hex_number && !float_number && (ch == '.'))
582 tokenbuf[tokenpos++] = ch;
584 else if (!float_number &&
585 (ch == 'x') && (tokenpos == 1) &&
586 (tokenbuf[0] == '0'))
594 tokenbuf[tokenpos] = '\0';
597 sscanf (tokenbuf, "%lf", &token_float);
602 sscanf (tokenbuf, (hex_number ? "%x" : "%d"), &token_int);
603 return TOKEN_INTEGER;
612 gtk_rc_simple_token (char ch)
616 for (i = 0; i < nsimple_tokens; i++)
617 if (simple_tokens[i].ch == ch)
618 return simple_tokens[i].token;
624 gtk_rc_symbol_token (const char *sym)
628 for (i = 0; i < nsymbols; i++)
629 if (strcmp (symbols[i].name, sym) == 0)
630 return symbols[i].token;
636 gtk_rc_get_next_token ()
638 if (next_token != -1)
640 cur_token = next_token;
645 cur_token = gtk_rc_get_token ();
652 gtk_rc_peek_next_token ()
654 if (next_token == -1)
655 next_token = gtk_rc_get_token ();
661 gtk_rc_parse_statement ()
666 token = gtk_rc_peek_next_token ();
673 error = gtk_rc_parse_style ();
674 if (error != PARSE_SYNTAX)
677 error = gtk_rc_parse_pixmap_path ();
678 if (error != PARSE_SYNTAX)
681 error = gtk_rc_parse_widget_style ();
682 if (error != PARSE_SYNTAX)
685 error = gtk_rc_parse_widget_class_style ();
691 gtk_rc_parse_style ()
693 GtkRcStyle *rc_style;
694 GtkRcStyle *parent_style;
700 token = gtk_rc_peek_next_token ();
703 if (token != TOKEN_STYLE)
705 token = gtk_rc_get_next_token ();
707 token = gtk_rc_get_next_token ();
708 if (!token || (token != TOKEN_STRING))
712 rc_style = g_hash_table_lookup (rc_style_ht, token_str);
717 rc_style = g_new (GtkRcStyle, 1);
718 rc_style->initialize = TRUE;
719 rc_style->name = g_strdup (token_str);
720 rc_style->font_name = NULL;
721 rc_style->fontset_name = NULL;
723 for (i = 0; i < 5; i++)
724 rc_style->bg_pixmap_name[i] = NULL;
726 rc_style->style = gtk_style_new ();
727 gtk_style_ref (rc_style->style);
730 token = gtk_rc_peek_next_token ();
731 if (token == TOKEN_EQUAL_SIGN)
733 token = gtk_rc_get_next_token ();
735 token = gtk_rc_get_next_token ();
736 if (!token || (token != TOKEN_STRING))
740 gtk_style_unref (rc_style->style);
746 parent_style = g_hash_table_lookup (rc_style_ht, token_str);
749 for (i = 0; i < 5; i++)
751 rc_style->style->fg[i] = parent_style->style->fg[i];
752 rc_style->style->bg[i] = parent_style->style->bg[i];
753 rc_style->style->light[i] = parent_style->style->light[i];
754 rc_style->style->dark[i] = parent_style->style->dark[i];
755 rc_style->style->mid[i] = parent_style->style->mid[i];
756 rc_style->style->text[i] = parent_style->style->text[i];
757 rc_style->style->base[i] = parent_style->style->base[i];
760 rc_style->style->black = parent_style->style->black;
761 rc_style->style->white = parent_style->style->white;
763 if (rc_style->fontset_name)
765 g_free (rc_style->fontset_name);
766 rc_style->fontset_name = g_strdup (parent_style->fontset_name);
768 else if (rc_style->font_name)
770 g_free (rc_style->font_name);
771 rc_style->font_name = g_strdup (parent_style->font_name);
774 for (i = 0; i < 5; i++)
776 if (rc_style->bg_pixmap_name[i])
777 g_free (rc_style->bg_pixmap_name[i]);
778 rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
783 token = gtk_rc_get_next_token ();
784 if (!token || (token != TOKEN_LEFT_CURLY))
788 gtk_style_unref (rc_style->style);
796 error = gtk_rc_parse_style_option (rc_style);
797 if (error == PARSE_SYNTAX)
799 if (error == PARSE_ERROR)
803 gtk_style_unref (rc_style->style);
810 token = gtk_rc_get_next_token ();
811 if (!token || (token != TOKEN_RIGHT_CURLY))
815 if (rc_style->fontset_name)
816 g_free (rc_style->fontset_name);
817 else if (rc_style->font_name)
818 g_free (rc_style->font_name);
820 for (i = 0; i < 5; i++)
821 if (rc_style->bg_pixmap_name[i])
822 g_free (rc_style->bg_pixmap_name[i]);
824 gtk_style_unref (rc_style->style);
831 g_hash_table_insert (rc_style_ht, rc_style->name, rc_style);
837 gtk_rc_parse_style_option (GtkRcStyle *rc_style)
842 token = gtk_rc_peek_next_token ();
846 error = gtk_rc_parse_base (rc_style->style);
847 if (error != PARSE_SYNTAX)
850 error = gtk_rc_parse_bg (rc_style->style);
851 if (error != PARSE_SYNTAX)
854 error = gtk_rc_parse_fg (rc_style->style);
855 if (error != PARSE_SYNTAX)
858 error = gtk_rc_parse_bg_pixmap (rc_style);
859 if (error != PARSE_SYNTAX)
862 error = gtk_rc_parse_font (rc_style);
863 if (error != PARSE_SYNTAX)
866 error = gtk_rc_parse_fontset (rc_style);
872 gtk_rc_parse_base (GtkStyle *style)
878 token = gtk_rc_peek_next_token ();
881 if (token != TOKEN_BASE)
883 token = gtk_rc_get_next_token ();
885 error = gtk_rc_parse_state (&state);
886 if (error != PARSE_OK)
889 token = gtk_rc_get_next_token ();
890 if (!token || (token != TOKEN_EQUAL_SIGN))
893 error = gtk_rc_parse_color (&style->base[state]);
899 gtk_rc_parse_bg (GtkStyle *style)
905 token = gtk_rc_peek_next_token ();
908 if (token != TOKEN_BG)
910 token = gtk_rc_get_next_token ();
912 error = gtk_rc_parse_state (&state);
913 if (error != PARSE_OK)
916 token = gtk_rc_get_next_token ();
917 if (!token || (token != TOKEN_EQUAL_SIGN))
920 error = gtk_rc_parse_color (&style->bg[state]);
926 gtk_rc_parse_fg (GtkStyle *style)
932 token = gtk_rc_peek_next_token ();
935 if (token != TOKEN_FG)
937 token = gtk_rc_get_next_token ();
939 error = gtk_rc_parse_state (&state);
940 if (error != PARSE_OK)
943 token = gtk_rc_get_next_token ();
944 if (!token || (token != TOKEN_EQUAL_SIGN))
947 error = gtk_rc_parse_color (&style->fg[state]);
953 gtk_rc_parse_bg_pixmap (GtkRcStyle *rc_style)
960 token = gtk_rc_peek_next_token ();
963 if (token != TOKEN_BG_PIXMAP)
965 token = gtk_rc_get_next_token ();
967 error = gtk_rc_parse_state (&state);
968 if (error != PARSE_OK)
971 token = gtk_rc_get_next_token ();
972 if (!token || (token != TOKEN_EQUAL_SIGN))
975 token = gtk_rc_get_next_token ();
976 if (!token || (token != TOKEN_STRING))
979 if (strcmp (token_str, "<parent>"))
980 pixmap_file = gtk_rc_find_pixmap_in_path (token_str);
982 pixmap_file = g_strdup(token_str);
986 if (rc_style->bg_pixmap_name[state])
987 g_free (rc_style->bg_pixmap_name[state]);
988 rc_style->bg_pixmap_name[state] = pixmap_file;
995 gtk_rc_find_pixmap_in_path (gchar *pixmap_file)
1001 for (i = 0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (pixmap_path[i] != NULL); i++)
1003 buf = g_malloc (strlen (pixmap_path[i]) + strlen (pixmap_file) + 2);
1004 sprintf (buf, "%s%c%s", pixmap_path[i], '/', pixmap_file);
1006 fp = fopen (buf, "r");
1016 g_warning ("Unable to locate image file in pixmap_path: \"%s\" line %d",
1017 pixmap_file, linenum);
1023 gtk_rc_parse_font (GtkRcStyle *rc_style)
1027 token = gtk_rc_peek_next_token ();
1030 if (token != TOKEN_FONT)
1031 return PARSE_SYNTAX;
1032 token = gtk_rc_get_next_token ();
1034 token = gtk_rc_get_next_token ();
1035 if (!token || (token != TOKEN_EQUAL_SIGN))
1038 token = gtk_rc_get_next_token ();
1039 if (!token || (token != TOKEN_STRING))
1042 if (rc_style->font_name)
1043 g_free (rc_style->font_name);
1044 rc_style->font_name = g_strdup (token_str);
1050 gtk_rc_parse_fontset (GtkRcStyle *rc_style)
1054 token = gtk_rc_peek_next_token ();
1057 if (token != TOKEN_FONTSET)
1058 return PARSE_SYNTAX;
1059 token = gtk_rc_get_next_token ();
1061 token = gtk_rc_get_next_token ();
1062 if (!token || (token != TOKEN_EQUAL_SIGN))
1065 token = gtk_rc_get_next_token ();
1066 if (!token || (token != TOKEN_STRING))
1069 if (rc_style->fontset_name)
1070 g_free (rc_style->fontset_name);
1071 rc_style->fontset_name = g_strdup (token_str);
1077 gtk_rc_parse_state (GtkStateType *state)
1081 token = gtk_rc_peek_next_token ();
1084 if (token != TOKEN_LEFT_BRACE)
1085 return PARSE_SYNTAX;
1086 token = gtk_rc_get_next_token ();
1088 token = gtk_rc_get_next_token ();
1089 if (token == TOKEN_ACTIVE)
1090 *state = GTK_STATE_ACTIVE;
1091 else if (token == TOKEN_INSENSITIVE)
1092 *state = GTK_STATE_INSENSITIVE;
1093 else if (token == TOKEN_NORMAL)
1094 *state = GTK_STATE_NORMAL;
1095 else if (token == TOKEN_PRELIGHT)
1096 *state = GTK_STATE_PRELIGHT;
1097 else if (token == TOKEN_SELECTED)
1098 *state = GTK_STATE_SELECTED;
1102 token = gtk_rc_get_next_token ();
1103 if (!token || (token != TOKEN_RIGHT_BRACE))
1110 gtk_rc_parse_color (GdkColor *color)
1118 token = gtk_rc_peek_next_token ();
1124 case TOKEN_LEFT_CURLY:
1125 token = gtk_rc_get_next_token ();
1127 token = gtk_rc_get_next_token ();
1128 if (!token || ((token != TOKEN_INTEGER) && (token != TOKEN_FLOAT)))
1131 if (token == TOKEN_FLOAT)
1132 token_int = token_float * 65535.0;
1135 if (token_int > 65535)
1138 color->red = token_int;
1140 token = gtk_rc_get_next_token ();
1141 if (!token || (token != TOKEN_COMMA))
1144 token = gtk_rc_get_next_token ();
1145 if (!token || ((token != TOKEN_INTEGER) && (token != TOKEN_FLOAT)))
1148 if (token == TOKEN_FLOAT)
1149 token_int = token_float * 65535.0;
1152 if (token_int > 65535)
1155 color->green = token_int;
1157 token = gtk_rc_get_next_token ();
1158 if (!token || (token != TOKEN_COMMA))
1161 token = gtk_rc_get_next_token ();
1162 if (!token || ((token != TOKEN_INTEGER) && (token != TOKEN_FLOAT)))
1165 if (token == TOKEN_FLOAT)
1166 token_int = token_float * 65535.0;
1169 if (token_int > 65535)
1172 color->blue = token_int;
1174 token = gtk_rc_get_next_token ();
1175 if (!token || (token != TOKEN_RIGHT_CURLY))
1180 token = gtk_rc_get_next_token ();
1182 if (token_str[0] != '#')
1185 length = strlen (token_str) - 1;
1186 if (((length % 3) != 0) || (length > 12))
1190 for (i = 0, j = 1; i < length; i++, j++)
1191 buf[i] = token_str[j];
1194 sscanf (buf, "%x", &temp);
1197 for (i = 0; i < length; i++, j++)
1198 buf[i] = token_str[j];
1201 sscanf (buf, "%x", &temp);
1202 color->green = temp;
1204 for (i = 0; i < length; i++, j++)
1205 buf[i] = token_str[j];
1208 sscanf (buf, "%x", &temp);
1214 color->green *= 4369;
1215 color->blue *= 4369;
1217 else if (length == 2)
1220 color->green *= 257;
1223 else if (length == 3)
1232 return PARSE_SYNTAX;
1239 gtk_rc_parse_pixmap_path ()
1243 token = gtk_rc_peek_next_token ();
1246 if (token != TOKEN_PIXMAP_PATH)
1247 return PARSE_SYNTAX;
1248 token = gtk_rc_get_next_token ();
1250 token = gtk_rc_get_next_token ();
1252 if (!token || (token != TOKEN_STRING))
1255 gtk_rc_parse_pixmap_path_string(token_str);
1260 static void gtk_rc_parse_pixmap_path_string(gchar *pix_path)
1264 gint start_offset = 0;
1268 /* free the old one, or just add to the old one ? */
1269 for (path_num=0; pixmap_path[path_num]; path_num++)
1271 g_free(pixmap_path[path_num]);
1272 pixmap_path[path_num] = NULL;
1277 path_len = strlen(pix_path);
1279 buf = g_strdup(pix_path);
1281 for(end_offset = 0; end_offset <= path_len; end_offset++)
1283 if ( (buf[end_offset] == ':') || (end_offset == path_len) )
1285 buf[end_offset] = '\0';
1286 pixmap_path[path_num] = g_strdup(buf + start_offset);
1288 pixmap_path[path_num] = NULL;
1289 start_offset = end_offset + 1;
1291 buf = g_strdup(pix_path);
1298 gtk_rc_parse_widget_style ()
1303 token = gtk_rc_peek_next_token ();
1306 if (token != TOKEN_WIDGET)
1307 return PARSE_SYNTAX;
1308 token = gtk_rc_get_next_token ();
1310 token = gtk_rc_get_next_token ();
1311 if (!token || (token != TOKEN_STRING))
1314 rc_set = g_new (GtkRcSet, 1);
1315 rc_set->set = g_strdup (token_str);
1317 token = gtk_rc_get_next_token ();
1318 if (!token || (token != TOKEN_STYLE))
1320 g_free (rc_set->set);
1325 token = gtk_rc_get_next_token ();
1326 if (!token || (token != TOKEN_STRING))
1328 g_free (rc_set->set);
1333 rc_set->rc_style = gtk_rc_style_find (token_str);
1334 if (!rc_set->rc_style)
1336 g_free (rc_set->set);
1341 widget_sets = g_slist_append (widget_sets, rc_set);
1347 gtk_rc_parse_widget_class_style ()
1352 token = gtk_rc_peek_next_token ();
1355 if (token != TOKEN_WIDGET_CLASS)
1356 return PARSE_SYNTAX;
1357 token = gtk_rc_get_next_token ();
1359 token = gtk_rc_get_next_token ();
1360 if (!token || (token != TOKEN_STRING))
1363 rc_set = g_new (GtkRcSet, 1);
1364 rc_set->set = g_strdup (token_str);
1366 token = gtk_rc_get_next_token ();
1367 if (!token || (token != TOKEN_STYLE))
1369 g_free (rc_set->set);
1374 token = gtk_rc_get_next_token ();
1375 if (!token || (token != TOKEN_STRING))
1377 g_free (rc_set->set);
1382 rc_set->rc_style = gtk_rc_style_find (token_str);
1383 if (!rc_set->rc_style)
1385 g_free (rc_set->set);
1390 widget_class_sets = g_slist_append (widget_class_sets, rc_set);
1396 gtk_rc_widget_path (GtkWidget *widget)
1398 GtkWidget *tmp_widget;
1407 tmp_widget = widget;
1410 name = gtk_widget_get_name (tmp_widget);
1411 pathlength += strlen (name);
1413 tmp_widget = tmp_widget->parent;
1419 path = g_new (char, pathlength + 1);
1420 path[pathlength] = '\0';
1422 tmp_widget = widget;
1425 name = gtk_widget_get_name (tmp_widget);
1426 namelength = strlen (name);
1428 strncpy (&path[pathlength - namelength], name, namelength);
1429 pathlength -= namelength;
1431 tmp_widget = tmp_widget->parent;
1436 path[pathlength] = '.';
1444 gtk_rc_widget_class_path (GtkWidget *widget)
1446 GtkWidget *tmp_widget;
1455 tmp_widget = widget;
1458 name = gtk_type_name (GTK_WIDGET_TYPE (tmp_widget));
1459 pathlength += strlen (name);
1461 tmp_widget = tmp_widget->parent;
1467 path = g_new (char, pathlength + 1);
1468 path[pathlength] = '\0';
1470 tmp_widget = widget;
1473 name = gtk_type_name (GTK_WIDGET_TYPE (tmp_widget));
1474 namelength = strlen (name);
1476 strncpy (&path[pathlength - namelength], name, namelength);
1477 pathlength -= namelength;
1479 tmp_widget = tmp_widget->parent;
1484 path[pathlength] = '.';