1 --- gtk+-2.6.4/gtk/gtkrc.c 2005-02-01 20:07:40.000000000 +0200
2 +++ gtk+-2.6.4/gtk/gtkrc.c 2005-04-06 16:19:37.848784472 +0300
4 #include "gtkprivate.h"
5 #include "gtksettings.h"
7 +#include "gtkhashtable.h"
12 GtkStyle *default_style;
15 +#define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
17 +typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
19 +struct _GtkRcStylePrivate {
20 + GSList *logical_color_hashes;
23 static GtkRcContext *gtk_rc_context_get (GtkSettings *settings);
25 static guint gtk_rc_style_hash (const gchar *name);
29 GtkIconFactory *factory);
30 +static guint gtk_rc_parse_logical_color (GScanner *scanner,
31 + GtkRcStyle *rc_style,
32 + GtkHashTable *hash);
33 +static guint gtk_rc_parse_color_full (GScanner *scanner,
37 static void gtk_rc_clear_hash_node (gpointer key,
41 { "stock", GTK_RC_TOKEN_STOCK },
42 { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
43 { "LTR", GTK_RC_TOKEN_LTR },
44 - { "RTL", GTK_RC_TOKEN_RTL }
45 + { "RTL", GTK_RC_TOKEN_RTL },
46 + { "logical_color", GTK_RC_TOKEN_LOGICAL_COLOR }
49 static GHashTable *realized_style_ht = NULL;
52 gtk_rc_style_init (GtkRcStyle *style)
54 + GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
60 style->rc_style_lists = NULL;
61 style->icon_factories = NULL;
62 + priv->logical_color_hashes = NULL;
67 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
68 klass->merge = gtk_rc_style_real_merge;
69 klass->create_style = gtk_rc_style_real_create_style;
71 + g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
75 +free_object_list (GSList *list)
77 + GSList *tmp_list = list;
80 + g_object_unref (tmp_list->data);
81 + tmp_list = tmp_list->next;
83 + g_slist_free (list);
90 GSList *tmp_list1, *tmp_list2;
92 + GtkRcStylePrivate *rc_priv;
95 rc_style = GTK_RC_STYLE (object);
96 + rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
99 g_free (rc_style->name);
100 @@ -1059,13 +1095,8 @@
101 rc_style->rc_properties = NULL;
104 - tmp_list1 = rc_style->icon_factories;
107 - g_object_unref (tmp_list1->data);
108 - tmp_list1 = tmp_list1->next;
110 - g_slist_free (rc_style->icon_factories);
111 + free_object_list (rc_style->icon_factories);
112 + free_object_list (rc_priv->logical_color_hashes);
114 G_OBJECT_CLASS (parent_class)->finalize (object);
116 @@ -1125,6 +1156,14 @@
117 return g_object_new (G_OBJECT_TYPE (style), NULL);
121 +_gtk_rc_style_get_logical_color_hashes (GtkRcStyle *rc_style)
123 + GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
125 + return priv->logical_color_hashes;
129 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
130 gconstpointer bsearch_node2)
131 @@ -1499,6 +1538,22 @@
132 context->rc_files = NULL;
134 gtk_rc_parse_default_files (context);
135 +/*Hildon- Swapped these sections of code, so the styles from the
136 + XSettings theme are available when parsing with gtk_rc_context_parse_string*/
137 + g_free (context->theme_name);
138 + g_free (context->key_theme_name);
140 + g_object_get (context->settings,
141 + "gtk-theme-name", &context->theme_name,
142 + "gtk-key-theme-name", &context->key_theme_name,
145 + if (context->theme_name && context->theme_name[0])
146 + gtk_rc_parse_named (context, context->theme_name, NULL);
147 + if (context->key_theme_name && context->key_theme_name[0])
148 + gtk_rc_parse_named (context, context->key_theme_name, "key");
152 tmp_list = global_rc_files;
154 @@ -1512,19 +1567,6 @@
156 tmp_list = tmp_list->next;
159 - g_free (context->theme_name);
160 - g_free (context->key_theme_name);
162 - g_object_get (context->settings,
163 - "gtk-theme-name", &context->theme_name,
164 - "gtk-key-theme-name", &context->key_theme_name,
167 - if (context->theme_name && context->theme_name[0])
168 - gtk_rc_parse_named (context, context->theme_name, NULL);
169 - if (context->key_theme_name && context->key_theme_name[0])
170 - gtk_rc_parse_named (context, context->key_theme_name, "key");
172 g_object_thaw_notify (G_OBJECT (context->settings));
174 @@ -1905,10 +1947,19 @@
181 scanner = gtk_rc_scanner_new ();
183 + if (input_name != NULL)
185 + name_str = (gchar *) g_malloc(strlen(input_name) + 7);
186 + sprintf(name_str, "%s.cache", input_name);
187 + /*osso_g_scanner_cache_open (scanner, name_str);*/
193 g_assert (input_string == NULL);
194 @@ -2062,6 +2113,29 @@
199 +concat_object_lists (GSList *list_a, GSList *list_b)
203 + copy = g_slist_copy (list_b);
209 + while (iter != NULL)
211 + g_object_ref (iter->data);
212 + iter = g_slist_next (iter);
215 + return g_slist_concat (list_a, copy);
221 /* Reuses or frees rc_styles */
223 gtk_rc_init_style (GtkRcContext *context,
224 @@ -2083,6 +2157,7 @@
225 GtkRcStyle *base_style = NULL;
226 GtkRcStyle *proto_style;
227 GtkRcStyleClass *proto_style_class;
228 + GtkRcStylePrivate *proto_priv;
230 GType rc_style_type = GTK_TYPE_RC_STYLE;
232 @@ -2109,12 +2184,13 @@
234 proto_style_class = GTK_RC_STYLE_GET_CLASS (base_style);
235 proto_style = proto_style_class->create_rc_style (base_style);
236 + proto_priv = GTK_RC_STYLE_GET_PRIVATE (proto_style);
238 tmp_styles = rc_styles;
241 GtkRcStyle *rc_style = tmp_styles->data;
243 + GtkRcStylePrivate *rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
245 proto_style_class->merge (proto_style, rc_style);
247 @@ -2122,22 +2198,12 @@
248 if (!g_slist_find (rc_style->rc_style_lists, rc_styles))
249 rc_style->rc_style_lists = g_slist_prepend (rc_style->rc_style_lists, rc_styles);
251 - factories = g_slist_copy (rc_style->icon_factories);
257 - while (iter != NULL)
259 - g_object_ref (iter->data);
260 - iter = g_slist_next (iter);
263 - proto_style->icon_factories = g_slist_concat (proto_style->icon_factories,
267 + proto_style->icon_factories =
268 + concat_object_lists (proto_style->icon_factories,
269 + rc_style->icon_factories);
270 + proto_priv->logical_color_hashes =
271 + concat_object_lists (proto_priv->logical_color_hashes,
272 + rc_priv->logical_color_hashes);
274 tmp_styles = tmp_styles->next;
276 @@ -2515,9 +2581,11 @@
277 GtkRcStyle *rc_style;
278 GtkRcStyle *orig_style;
279 GtkRcStyle *parent_style;
280 + GtkRcStylePrivate *rc_priv = NULL;
283 GtkIconFactory *our_factory = NULL;
284 + GtkHashTable *our_hash = NULL;
286 token = g_scanner_get_next_token (scanner);
287 if (token != GTK_RC_TOKEN_STYLE)
288 @@ -2533,12 +2601,6 @@
292 - /* If there's a list, its first member is always the factory belonging
295 - if (rc_style && rc_style->icon_factories)
296 - our_factory = rc_style->icon_factories->data;
300 rc_style = gtk_rc_style_new ();
301 @@ -2550,6 +2612,16 @@
302 for (i = 0; i < 5; i++)
303 rc_style->color_flags[i] = 0;
306 + rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
308 + /* If there's a list, its first member is always the factory belonging
311 + if (rc_style->icon_factories)
312 + our_factory = rc_style->icon_factories->data;
313 + if (rc_priv->logical_color_hashes)
314 + our_hash = rc_priv->logical_color_hashes->data;
316 token = g_scanner_peek_next_token (scanner);
317 if (token == G_TOKEN_EQUAL_SIGN)
318 @@ -2566,8 +2638,8 @@
319 parent_style = gtk_rc_style_find (context, scanner->value.v_string);
324 + GtkRcStylePrivate *parent_priv = GTK_RC_STYLE_GET_PRIVATE (parent_style);
326 for (i = 0; i < 5; i++)
328 rc_style->color_flags[i] = parent_style->color_flags[i];
329 @@ -2621,17 +2693,24 @@
330 rc_style->icon_factories = g_slist_prepend (rc_style->icon_factories,
334 - rc_style->icon_factories = g_slist_concat (rc_style->icon_factories,
335 - g_slist_copy (parent_style->icon_factories));
337 - factories = parent_style->icon_factories;
338 - while (factories != NULL)
339 + rc_style->icon_factories = concat_object_lists (rc_style->icon_factories,
340 + parent_style->icon_factories);
343 + /* Also append parent's color hashes, adding a ref to them */
344 + if (parent_priv->logical_color_hashes != NULL)
346 + /* See comment above .. */
347 + if (our_hash == NULL)
349 - g_object_ref (factories->data);
350 - factories = factories->next;
351 + our_hash = _gtk_hash_table_new ();
352 + rc_priv->logical_color_hashes = g_slist_prepend (rc_priv->logical_color_hashes,
357 + rc_priv->logical_color_hashes = concat_object_lists (rc_priv->logical_color_hashes,
358 + parent_priv->logical_color_hashes);
363 @@ -2689,12 +2768,22 @@
365 token = gtk_rc_parse_stock (context, scanner, rc_style, our_factory);
367 + case GTK_RC_TOKEN_LOGICAL_COLOR:
368 + if (our_hash == NULL)
370 + our_hash = _gtk_hash_table_new ();
371 + rc_priv->logical_color_hashes = g_slist_prepend (rc_priv->logical_color_hashes,
374 + token = gtk_rc_parse_logical_color (scanner, rc_style, our_hash);
376 case G_TOKEN_IDENTIFIER:
377 if (is_c_identifier (scanner->next_value.v_identifier) &&
378 scanner->next_value.v_identifier[0] >= 'A' &&
379 scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
381 GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
384 g_scanner_get_next_token (scanner); /* eat type name */
385 prop.type_name = g_quark_from_string (scanner->value.v_identifier);
386 @@ -2712,8 +2801,10 @@
389 /* it's important that we do the same canonification as GParamSpecPool here */
390 - g_strcanon (scanner->value.v_identifier, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
391 - prop.property_name = g_quark_from_string (scanner->value.v_identifier);
392 + name = g_strdup (scanner->value.v_identifier);
393 + g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
394 + prop.property_name = g_quark_from_string (name);
397 token = gtk_rc_parse_assignment (scanner, &prop);
398 if (token == G_TOKEN_NONE)
399 @@ -2825,7 +2916,7 @@
400 return G_TOKEN_EQUAL_SIGN;
402 style->color_flags[state] |= GTK_RC_BG;
403 - return gtk_rc_parse_color (scanner, &style->bg[state]);
404 + return gtk_rc_parse_color_full (scanner, &style->bg[state], style);
408 @@ -2848,7 +2939,7 @@
409 return G_TOKEN_EQUAL_SIGN;
411 style->color_flags[state] |= GTK_RC_FG;
412 - return gtk_rc_parse_color (scanner, &style->fg[state]);
413 + return gtk_rc_parse_color_full (scanner, &style->fg[state], style);
417 @@ -2871,7 +2962,7 @@
418 return G_TOKEN_EQUAL_SIGN;
420 style->color_flags[state] |= GTK_RC_TEXT;
421 - return gtk_rc_parse_color (scanner, &style->text[state]);
422 + return gtk_rc_parse_color_full (scanner, &style->text[state], style);
426 @@ -2894,7 +2985,7 @@
427 return G_TOKEN_EQUAL_SIGN;
429 style->color_flags[state] |= GTK_RC_BASE;
430 - return gtk_rc_parse_color (scanner, &style->base[state]);
431 + return gtk_rc_parse_color_full (scanner, &style->base[state], style);
435 @@ -3345,11 +3436,45 @@
440 +lookup_logical_color (GtkRcStyle *style,
441 + const char *color_name,
444 + GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
447 + iter = priv->logical_color_hashes;
448 + while (iter != NULL)
450 + GdkColor *match = g_hash_table_lookup (GTK_HASH_TABLE (iter->data)->hash,
454 + color->red = match->red;
455 + color->green = match->green;
456 + color->blue = match->blue;
460 + iter = g_slist_next (iter);
467 gtk_rc_parse_color (GScanner *scanner,
470 + return gtk_rc_parse_color_full (scanner, color, NULL);
474 +gtk_rc_parse_color_full (GScanner *scanner,
480 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
481 @@ -3407,11 +3532,14 @@
483 if (!gdk_color_parse (scanner->value.v_string, color))
485 - g_scanner_warn (scanner, "Invalid color constant '%s'",
486 - scanner->value.v_string);
487 - return G_TOKEN_STRING;
488 + if (!(style && lookup_logical_color (style, scanner->value.v_string, color)))
490 + g_scanner_warn (scanner, "Invalid color constant '%s'",
491 + scanner->value.v_string);
492 + return G_TOKEN_STRING;
500 @@ -3625,8 +3753,8 @@
504 -gtk_rc_parse_stock_id (GScanner *scanner,
506 +gtk_rc_parse_hash_key (GScanner *scanner,
511 @@ -3639,12 +3767,12 @@
512 if (token != G_TOKEN_STRING)
513 return G_TOKEN_STRING;
515 - *stock_id = g_strdup (scanner->value.v_string);
516 + *hash_key = g_strdup (scanner->value.v_string);
518 token = g_scanner_get_next_token (scanner);
519 if (token != G_TOKEN_RIGHT_BRACE)
521 - g_free (*stock_id);
522 + g_free (*hash_key);
523 return G_TOKEN_RIGHT_BRACE;
526 @@ -3854,7 +3982,7 @@
527 if (token != GTK_RC_TOKEN_STOCK)
528 return GTK_RC_TOKEN_STOCK;
530 - token = gtk_rc_parse_stock_id (scanner, &stock_id);
531 + token = gtk_rc_parse_hash_key (scanner, &stock_id);
532 if (token != G_TOKEN_NONE)
535 @@ -3965,3 +4093,46 @@
541 +gtk_rc_parse_logical_color (GScanner *scanner,
542 + GtkRcStyle *rc_style,
543 + GtkHashTable *hash)
545 + gchar *color_id = NULL;
549 + token = g_scanner_get_next_token (scanner);
550 + if (token != GTK_RC_TOKEN_LOGICAL_COLOR)
551 + return GTK_RC_TOKEN_LOGICAL_COLOR;
553 + token = gtk_rc_parse_hash_key (scanner, &color_id);
554 + if (token != G_TOKEN_NONE)
557 + token = g_scanner_get_next_token (scanner);
558 + if (token != G_TOKEN_EQUAL_SIGN)
561 + return G_TOKEN_EQUAL_SIGN;
564 + color = g_new (GdkColor, 1);
565 + token = gtk_rc_parse_color_full (scanner, color, rc_style);
566 + if (token != G_TOKEN_NONE)
573 + /* Because the hash is created with destroy functions,
574 + * g_hash_table_insert will free any old values for us,
575 + * if a mapping with the specified key already exists. */
576 + g_hash_table_insert (hash->hash, color_id, color);
578 + return G_TOKEN_NONE;