]> Pileus Git - ~andy/gtk/blob - gtk/gtkrc.c
Finish making the GtkSettings object identical on all backends so that it doesn't...
[~andy/gtk] / gtk / gtkrc.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28
29 #include <locale.h>
30 #ifdef HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
33 #include <sys/stat.h>
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
36 #endif
37 #include <fcntl.h>
38 #include <string.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41
42
43 #include <glib.h>
44 #include <glib/gstdio.h>
45 #include "gdk/gdk.h"
46
47 #include "gtkversion.h"
48 #include "gtkrc.h"
49 #include "gtkbindings.h"
50 #include "gtkintl.h"
51 #include "gtkiconfactory.h"
52 #include "gtkmain.h"
53 #include "gtkmodules.h"
54 #include "gtkprivate.h"
55 #include "gtksettingsprivate.h"
56 #include "gtkwindow.h"
57
58 #ifdef G_OS_WIN32
59 #include <io.h>
60 #endif
61
62 enum 
63 {
64   PATH_ELT_PSPEC,
65   PATH_ELT_UNRESOLVED,
66   PATH_ELT_TYPE
67 };
68
69 typedef struct
70 {
71   gint type;
72   union 
73   {
74     GType         class_type;
75     gchar        *class_name;
76     GPatternSpec *pspec;
77   } elt;
78 } PathElt;
79
80 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
81
82 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
83
84 struct _GtkRcStylePrivate
85 {
86   GSList *color_hashes;
87 };
88
89 static void        gtk_rc_style_finalize             (GObject         *object);
90 static void        gtk_rc_style_real_merge           (GtkRcStyle      *dest,
91                                                       GtkRcStyle      *src);
92 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle      *rc_style);
93 static GtkStyle*   gtk_rc_style_real_create_style    (GtkRcStyle      *rc_style);
94 static gint        gtk_rc_properties_cmp             (gconstpointer    bsearch_node1,
95                                                       gconstpointer    bsearch_node2);
96
97 static void        insert_rc_property                (GtkRcStyle      *style,
98                                                       GtkRcProperty   *property,
99                                                       gboolean         replace);
100
101
102 static const GScannerConfig gtk_rc_scanner_config =
103 {
104   (
105    " \t\r\n"
106    )                    /* cset_skip_characters */,
107   (
108    "_"
109    G_CSET_a_2_z
110    G_CSET_A_2_Z
111    )                    /* cset_identifier_first */,
112   (
113    G_CSET_DIGITS
114    "-_"
115    G_CSET_a_2_z
116    G_CSET_A_2_Z
117    )                    /* cset_identifier_nth */,
118   ( "#\n" )             /* cpair_comment_single */,
119   
120   TRUE                  /* case_sensitive */,
121   
122   TRUE                  /* skip_comment_multi */,
123   TRUE                  /* skip_comment_single */,
124   TRUE                  /* scan_comment_multi */,
125   TRUE                  /* scan_identifier */,
126   FALSE                 /* scan_identifier_1char */,
127   FALSE                 /* scan_identifier_NULL */,
128   TRUE                  /* scan_symbols */,
129   TRUE                  /* scan_binary */,
130   TRUE                  /* scan_octal */,
131   TRUE                  /* scan_float */,
132   TRUE                  /* scan_hex */,
133   TRUE                  /* scan_hex_dollar */,
134   TRUE                  /* scan_string_sq */,
135   TRUE                  /* scan_string_dq */,
136   TRUE                  /* numbers_2_int */,
137   FALSE                 /* int_2_float */,
138   FALSE                 /* identifier_2_string */,
139   TRUE                  /* char_2_token */,
140   TRUE                  /* symbol_2_token */,
141   FALSE                 /* scope_0_fallback */,
142 };
143  
144 static const gchar symbol_names[] = 
145   "include\0"
146   "NORMAL\0"
147   "ACTIVE\0"
148   "PRELIGHT\0"
149   "SELECTED\0"
150   "INSENSITIVE\0"
151   "fg\0"
152   "bg\0"
153   "text\0"
154   "base\0"
155   "xthickness\0"
156   "ythickness\0"
157   "font\0"
158   "fontset\0"
159   "font_name\0"
160   "bg_pixmap\0"
161   "pixmap_path\0"
162   "style\0"
163   "binding\0"
164   "bind\0"
165   "widget\0"
166   "widget_class\0"
167   "class\0"
168   "lowest\0"
169   "gtk\0"
170   "application\0"
171   "theme\0"
172   "rc\0"
173   "highest\0"
174   "engine\0"
175   "module_path\0"
176   "stock\0"
177   "im_module_file\0"
178   "LTR\0"
179   "RTL\0"
180   "color\0"
181   "unbind\0";
182
183 static const struct
184 {
185   guint name_offset;
186   guint token;
187 } symbols[] = {
188   {   0, GTK_RC_TOKEN_INCLUDE },
189   {   8, GTK_RC_TOKEN_NORMAL },
190   {  15, GTK_RC_TOKEN_ACTIVE },
191   {  22, GTK_RC_TOKEN_PRELIGHT },
192   {  31, GTK_RC_TOKEN_SELECTED },
193   {  40, GTK_RC_TOKEN_INSENSITIVE },
194   {  52, GTK_RC_TOKEN_FG },
195   {  55, GTK_RC_TOKEN_BG },
196   {  58, GTK_RC_TOKEN_TEXT },
197   {  63, GTK_RC_TOKEN_BASE },
198   {  68, GTK_RC_TOKEN_XTHICKNESS },
199   {  79, GTK_RC_TOKEN_YTHICKNESS },
200   {  90, GTK_RC_TOKEN_FONT },
201   {  95, GTK_RC_TOKEN_FONTSET },
202   { 103, GTK_RC_TOKEN_FONT_NAME },
203   { 113, GTK_RC_TOKEN_BG_PIXMAP },
204   { 123, GTK_RC_TOKEN_PIXMAP_PATH },
205   { 135, GTK_RC_TOKEN_STYLE },
206   { 141, GTK_RC_TOKEN_BINDING },
207   { 149, GTK_RC_TOKEN_BIND },
208   { 154, GTK_RC_TOKEN_WIDGET },
209   { 161, GTK_RC_TOKEN_WIDGET_CLASS },
210   { 174, GTK_RC_TOKEN_CLASS },
211   { 180, GTK_RC_TOKEN_LOWEST },
212   { 187, GTK_RC_TOKEN_GTK },
213   { 191, GTK_RC_TOKEN_APPLICATION },
214   { 203, GTK_RC_TOKEN_THEME },
215   { 209, GTK_RC_TOKEN_RC },
216   { 212, GTK_RC_TOKEN_HIGHEST },
217   { 220, GTK_RC_TOKEN_ENGINE },
218   { 227, GTK_RC_TOKEN_MODULE_PATH },
219   { 239, GTK_RC_TOKEN_STOCK },
220   { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
221   { 260, GTK_RC_TOKEN_LTR },
222   { 264, GTK_RC_TOKEN_RTL },
223   { 268, GTK_RC_TOKEN_COLOR },
224   { 274, GTK_RC_TOKEN_UNBIND }
225 };
226
227 static GHashTable *realized_style_ht = NULL;
228
229 static gchar *im_module_file = NULL;
230
231 static gchar **gtk_rc_default_files = NULL;
232
233 /* RC file handling */
234
235 static gchar *
236 gtk_rc_make_default_dir (const gchar *type)
237 {
238   const gchar *var;
239   gchar *path;
240
241   var = g_getenv ("GTK_EXE_PREFIX");
242
243   if (var)
244     path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
245   else
246     path = g_build_filename (GTK_LIBDIR, "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
247
248   return path;
249 }
250
251 /**
252  * gtk_rc_get_im_module_path:
253  * @returns: (type filename): a newly-allocated string containing the
254  *    path in which to look for IM modules.
255  *
256  * Obtains the path in which to look for IM modules. See the documentation
257  * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
258  * environment variable for more details about looking up modules. This
259  * function is useful solely for utilities supplied with GTK+ and should
260  * not be used by applications under normal circumstances.
261  */
262 gchar *
263 gtk_rc_get_im_module_path (void)
264 {
265   gchar **paths = _gtk_get_module_path ("immodules");
266   gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
267   g_strfreev (paths);
268
269   return result;
270 }
271
272 /**
273  * gtk_rc_get_im_module_file:
274  * @returns: (type filename): a newly-allocated string containing the
275  *    name of the file listing the IM modules available for loading
276  *
277  * Obtains the path to the IM modules file. See the documentation
278  * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
279  * environment variable for more details.
280  */
281 gchar *
282 gtk_rc_get_im_module_file (void)
283 {
284   const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
285   gchar *result = NULL;
286
287   if (var)
288     result = g_strdup (var);
289
290   if (!result)
291     {
292       if (im_module_file)
293         result = g_strdup (im_module_file);
294       else
295         result = gtk_rc_make_default_dir ("immodules.cache");
296     }
297
298   return result;
299 }
300
301 gchar *
302 gtk_rc_get_theme_dir (void)
303 {
304   const gchar *var;
305   gchar *path;
306
307   var = g_getenv ("GTK_DATA_PREFIX");
308
309   if (var)
310     path = g_build_filename (var, "share", "themes", NULL);
311   else
312     path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
313
314   return path;
315 }
316
317 /**
318  * gtk_rc_get_module_dir:
319  * 
320  * Returns a directory in which GTK+ looks for theme engines.
321  * For full information about the search for theme engines,
322  * see the docs for <envar>GTK_PATH</envar> in
323  * <xref linkend="gtk-running"/>.
324  * 
325  * return value: (type filename): the directory. (Must be freed with g_free())
326  **/
327 gchar *
328 gtk_rc_get_module_dir (void)
329 {
330   return gtk_rc_make_default_dir ("engines");
331 }
332
333 /**
334  * gtk_rc_add_default_file:
335  * @filename: (type filename): the pathname to the file. If @filename
336  *    is not absolute, it is searched in the current directory.
337  *
338  * Adds a file to the list of files to be parsed at the
339  * end of gtk_init().
340  *
341  * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
342  **/
343 void
344 gtk_rc_add_default_file (const gchar *filename)
345 {
346 }
347
348 /**
349  * gtk_rc_set_default_files:
350  * @filenames: (array zero-terminated=1) (element-type filename): A
351  *     %NULL-terminated list of filenames.
352  *
353  * Sets the list of files that GTK+ will read at the
354  * end of gtk_init().
355  *
356  * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
357  **/
358 void
359 gtk_rc_set_default_files (gchar **filenames)
360 {
361 }
362
363 /**
364  * gtk_rc_get_default_files:
365  *
366  * Retrieves the current list of RC files that will be parsed
367  * at the end of gtk_init().
368  *
369  * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
370  *      A %NULL-terminated array of filenames.  This memory is owned
371  *     by GTK+ and must not be freed by the application.  If you want
372  *     to store this information, you should make a copy.
373  *
374  * Deprecated:3.0: Use #GtkStyleContext instead
375  **/
376 gchar **
377 gtk_rc_get_default_files (void)
378 {
379   return gtk_rc_default_files;
380 }
381
382 void
383 gtk_rc_parse_string (const gchar *rc_string)
384 {
385   g_return_if_fail (rc_string != NULL);
386 }
387
388 void
389 gtk_rc_parse (const gchar *filename)
390 {
391   g_return_if_fail (filename != NULL);
392 }
393
394 /* Handling of RC styles */
395
396 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
397
398 static void
399 gtk_rc_style_init (GtkRcStyle *style)
400 {
401   GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
402   guint i;
403
404   style->name = NULL;
405   style->font_desc = NULL;
406
407   for (i = 0; i < 5; i++)
408     {
409       static const GdkColor init_color = { 0, 0, 0, 0, };
410
411       style->bg_pixmap_name[i] = NULL;
412       style->color_flags[i] = 0;
413       style->fg[i] = init_color;
414       style->bg[i] = init_color;
415       style->text[i] = init_color;
416       style->base[i] = init_color;
417     }
418   style->xthickness = -1;
419   style->ythickness = -1;
420   style->rc_properties = NULL;
421
422   style->rc_style_lists = NULL;
423   style->icon_factories = NULL;
424
425   priv->color_hashes = NULL;
426 }
427
428 static void
429 gtk_rc_style_class_init (GtkRcStyleClass *klass)
430 {
431   GObjectClass *object_class = G_OBJECT_CLASS (klass);
432   
433   object_class->finalize = gtk_rc_style_finalize;
434
435   klass->parse = NULL;
436   klass->create_rc_style = gtk_rc_style_real_create_rc_style;
437   klass->merge = gtk_rc_style_real_merge;
438   klass->create_style = gtk_rc_style_real_create_style;
439
440   g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
441 }
442
443 static void
444 gtk_rc_style_finalize (GObject *object)
445 {
446   GSList *tmp_list1, *tmp_list2;
447   GtkRcStyle *rc_style;
448   GtkRcStylePrivate *rc_priv;
449   gint i;
450
451   rc_style = GTK_RC_STYLE (object);
452   rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
453
454   g_free (rc_style->name);
455   if (rc_style->font_desc)
456     pango_font_description_free (rc_style->font_desc);
457       
458   for (i = 0; i < 5; i++)
459     g_free (rc_style->bg_pixmap_name[i]);
460   
461   /* Now remove all references to this rc_style from
462    * realized_style_ht
463    */
464   tmp_list1 = rc_style->rc_style_lists;
465   while (tmp_list1)
466     {
467       GSList *rc_styles = tmp_list1->data;
468       GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
469       g_object_unref (style);
470
471       /* Remove the list of styles from the other rc_styles
472        * in the list
473        */
474       tmp_list2 = rc_styles;
475       while (tmp_list2)
476         {
477           GtkRcStyle *other_style = tmp_list2->data;
478
479           if (other_style != rc_style)
480             other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
481                                                               rc_styles);
482           tmp_list2 = tmp_list2->next;
483         }
484
485       /* And from the hash table itself
486        */
487       g_hash_table_remove (realized_style_ht, rc_styles);
488       g_slist_free (rc_styles);
489
490       tmp_list1 = tmp_list1->next;
491     }
492   g_slist_free (rc_style->rc_style_lists);
493
494   if (rc_style->rc_properties)
495     {
496       guint i;
497
498       for (i = 0; i < rc_style->rc_properties->len; i++)
499         {
500           GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
501
502           g_free (node->origin);
503           g_value_unset (&node->value);
504         }
505       g_array_free (rc_style->rc_properties, TRUE);
506       rc_style->rc_properties = NULL;
507     }
508
509   g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
510   g_slist_free (rc_style->icon_factories);
511
512   g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
513   g_slist_free (rc_priv->color_hashes);
514
515   G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
516 }
517
518 GtkRcStyle *
519 gtk_rc_style_new (void)
520 {
521   GtkRcStyle *style;
522   
523   style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
524   
525   return style;
526 }
527
528 /**
529  * gtk_rc_style_copy:
530  * @orig: the style to copy
531  *
532  * Makes a copy of the specified #GtkRcStyle. This function
533  * will correctly copy an RC style that is a member of a class
534  * derived from #GtkRcStyle.
535  *
536  * Return value: (transfer full): the resulting #GtkRcStyle
537  **/
538 GtkRcStyle *
539 gtk_rc_style_copy (GtkRcStyle *orig)
540 {
541   GtkRcStyle *style;
542
543   g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
544   
545   style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
546   GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
547
548   return style;
549 }
550
551 static GtkRcStyle *
552 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
553 {
554   return g_object_new (G_OBJECT_TYPE (style), NULL);
555 }
556
557 static gint
558 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
559                        gconstpointer bsearch_node2)
560 {
561   const GtkRcProperty *prop1 = bsearch_node1;
562   const GtkRcProperty *prop2 = bsearch_node2;
563
564   if (prop1->type_name == prop2->type_name)
565     return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
566   else
567     return prop1->type_name < prop2->type_name ? -1 : 1;
568 }
569
570 static void
571 insert_rc_property (GtkRcStyle    *style,
572                     GtkRcProperty *property,
573                     gboolean       replace)
574 {
575   guint i;
576   GtkRcProperty *new_property = NULL;
577   GtkRcProperty key = { 0, 0, NULL, { 0, }, };
578
579   key.type_name = property->type_name;
580   key.property_name = property->property_name;
581
582   if (!style->rc_properties)
583     style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
584
585   i = 0;
586   while (i < style->rc_properties->len)
587     {
588       gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
589
590       if (cmp == 0)
591         {
592           if (replace)
593             {
594               new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
595               
596               g_free (new_property->origin);
597               g_value_unset (&new_property->value);
598               
599               *new_property = key;
600               break;
601             }
602           else
603             return;
604         }
605       else if (cmp < 0)
606         break;
607
608       i++;
609     }
610
611   if (!new_property)
612     {
613       g_array_insert_val (style->rc_properties, i, key);
614       new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
615     }
616
617   new_property->origin = g_strdup (property->origin);
618   g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
619   g_value_copy (&property->value, &new_property->value);
620 }
621
622 static void
623 gtk_rc_style_real_merge (GtkRcStyle *dest,
624                          GtkRcStyle *src)
625 {
626   gint i;
627
628   for (i = 0; i < 5; i++)
629     {
630       if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
631         dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
632       
633       if (!(dest->color_flags[i] & GTK_RC_FG) && 
634           src->color_flags[i] & GTK_RC_FG)
635         {
636           dest->fg[i] = src->fg[i];
637           dest->color_flags[i] |= GTK_RC_FG;
638         }
639       if (!(dest->color_flags[i] & GTK_RC_BG) && 
640           src->color_flags[i] & GTK_RC_BG)
641         {
642           dest->bg[i] = src->bg[i];
643           dest->color_flags[i] |= GTK_RC_BG;
644         }
645       if (!(dest->color_flags[i] & GTK_RC_TEXT) && 
646           src->color_flags[i] & GTK_RC_TEXT)
647         {
648           dest->text[i] = src->text[i];
649           dest->color_flags[i] |= GTK_RC_TEXT;
650         }
651       if (!(dest->color_flags[i] & GTK_RC_BASE) && 
652           src->color_flags[i] & GTK_RC_BASE)
653         {
654           dest->base[i] = src->base[i];
655           dest->color_flags[i] |= GTK_RC_BASE;
656         }
657     }
658
659   if (dest->xthickness < 0 && src->xthickness >= 0)
660     dest->xthickness = src->xthickness;
661   if (dest->ythickness < 0 && src->ythickness >= 0)
662     dest->ythickness = src->ythickness;
663
664   if (src->font_desc)
665     {
666       if (!dest->font_desc)
667         dest->font_desc = pango_font_description_copy (src->font_desc);
668       else
669         pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
670     }
671
672   if (src->rc_properties)
673     {
674       guint i;
675
676       for (i = 0; i < src->rc_properties->len; i++)
677         insert_rc_property (dest,
678                             &g_array_index (src->rc_properties, GtkRcProperty, i),
679                             FALSE);
680     }
681 }
682
683 static GtkStyle *
684 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
685 {
686   return gtk_style_new ();
687 }
688
689 /**
690  * gtk_rc_reset_styles:
691  * @settings: a #GtkSettings
692  * 
693  * This function recomputes the styles for all widgets that use a
694  * particular #GtkSettings object. (There is one #GtkSettings object
695  * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
696  * when some global parameter has changed that affects the appearance
697  * of all widgets, because when a widget gets a new style, it will
698  * both redraw and recompute any cached information about its
699  * appearance. As an example, it is used when the default font size
700  * set by the operating system changes. Note that this function
701  * doesn't affect widgets that have a style set explicitely on them
702  * with gtk_widget_set_style().
703  *
704  * Since: 2.4
705  **/
706 void
707 gtk_rc_reset_styles (GtkSettings *settings)
708 {
709   gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
710 }
711
712 /**
713  * gtk_rc_reparse_all_for_settings:
714  * @settings: a #GtkSettings
715  * @force_load: load whether or not anything changed
716  * 
717  * If the modification time on any previously read file
718  * for the given #GtkSettings has changed, discard all style information
719  * and then reread all previously read RC files.
720  * 
721  * Return value: %TRUE if the files were reread.
722  **/
723 gboolean
724 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
725                                  gboolean     force_load)
726 {
727   return FALSE;
728 }
729
730 /**
731  * gtk_rc_reparse_all:
732  * 
733  * If the modification time on any previously read file for the
734  * default #GtkSettings has changed, discard all style information
735  * and then reread all previously read RC files.
736  * 
737  * Return value:  %TRUE if the files were reread.
738  **/
739 gboolean
740 gtk_rc_reparse_all (void)
741 {
742   return FALSE;
743 }
744
745 /**
746  * gtk_rc_get_style:
747  * @widget: a #GtkWidget
748  *
749  * Finds all matching RC styles for a given widget,
750  * composites them together, and then creates a
751  * #GtkStyle representing the composite appearance.
752  * (GTK+ actually keeps a cache of previously
753  * created styles, so a new style may not be
754  * created.)
755  *
756  * Returns: (transfer none): the resulting style. No refcount is added
757  *   to the returned style, so if you want to save this style around,
758  *   you should add a reference yourself.
759  *
760  * Deprecated:3.0: Use #GtkStyleContext instead
761  **/
762 GtkStyle *
763 gtk_rc_get_style (GtkWidget *widget)
764 {
765   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
766
767   gtk_widget_ensure_style (widget);
768
769   return gtk_widget_get_style (widget);
770 }
771
772 /**
773  * gtk_rc_get_style_by_paths:
774  * @settings: a #GtkSettings object
775  * @widget_path: (allow-none): the widget path to use when looking up the
776  *     style, or %NULL if no matching against the widget path should be done
777  * @class_path: (allow-none): the class path to use when looking up the style,
778  *     or %NULL if no matching against the class path should be done.
779  * @type: a type that will be used along with parent types of this type
780  *     when matching against class styles, or #G_TYPE_NONE
781  *
782  * Creates up a #GtkStyle from styles defined in a RC file by providing
783  * the raw components used in matching. This function may be useful
784  * when creating pseudo-widgets that should be themed like widgets but
785  * don't actually have corresponding GTK+ widgets. An example of this
786  * would be items inside a GNOME canvas widget.
787  *
788  * The action of gtk_rc_get_style() is similar to:
789  * |[
790  *  gtk_widget_path (widget, NULL, &path, NULL);
791  *  gtk_widget_class_path (widget, NULL, &class_path, NULL);
792  *  gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
793  *                             path, class_path,
794  *                             G_OBJECT_TYPE (widget));
795  * ]|
796  *
797  * Return value: (transfer none): A style created by matching with the
798  *     supplied paths, or %NULL if nothing matching was specified and the
799  *     default style should be used. The returned value is owned by GTK+
800  *     as part of an internal cache, so you must call g_object_ref() on
801  *     the returned value if you want to keep a reference to it.
802  *
803  * Deprecated:3.0: Use #GtkStyleContext instead
804  **/
805 GtkStyle *
806 gtk_rc_get_style_by_paths (GtkSettings *settings,
807                            const char  *widget_path,
808                            const char  *class_path,
809                            GType        type)
810 {
811   GtkWidgetPath *path;
812   GtkStyle *style;
813
814   path = gtk_widget_path_new ();
815
816   /* For compatibility, we return a GtkStyle based on a GtkStyleContext
817    * with a GtkWidgetPath appropriate for the supplied information.
818    *
819    * GtkWidgetPath is composed of a list of GTypes with optional names;
820    * In GTK+-2.0, widget_path consisted of the widget names, or
821    * the class names for unnamed widgets, while class_path had the
822    * class names always. So, use class_path to determine the GTypes
823    * and extract widget names from widget_path as applicable.
824    */
825   if (class_path == NULL)
826     {
827       gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
828     }
829   else
830     {
831       const gchar *widget_p, *widget_next;
832       const gchar *class_p, *class_next;
833
834       widget_next = widget_path;
835       class_next = class_path;
836
837       while (*class_next)
838         {
839           GType component_type;
840           gchar *component_class;
841           gchar *component_name;
842           gint pos;
843
844           class_p = class_next;
845           if (*class_p == '.')
846             class_p++;
847
848           widget_p = widget_next; /* Might be NULL */
849           if (widget_p && *widget_p == '.')
850             widget_p++;
851
852           class_next = strchr (class_p, '.');
853           if (class_next == NULL)
854             class_next = class_p + strlen (class_p);
855
856           if (widget_p)
857             {
858               widget_next = strchr (widget_p, '.');
859               if (widget_next == NULL)
860                 widget_next = widget_p + strlen (widget_p);
861             }
862
863           component_class = g_strndup (class_p, class_next - class_p);
864           if (widget_p && *widget_p)
865             component_name = g_strndup (widget_p, widget_next - widget_p);
866           else
867             component_name = NULL;
868
869           component_type = g_type_from_name (component_class);
870           if (component_type == G_TYPE_INVALID)
871             component_type = GTK_TYPE_WIDGET;
872
873           pos = gtk_widget_path_append_type (path, component_type);
874           if (component_name != NULL && strcmp (component_name, component_name) != 0)
875             gtk_widget_path_iter_set_name (path, pos, component_name);
876
877           g_free (component_class);
878           g_free (component_name);
879         }
880     }
881
882   style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
883                                    path);
884
885   gtk_widget_path_free (path);
886
887   return style;
888 }
889
890 /**
891  * gtk_rc_scanner_new: (skip)
892  *
893  * Deprecated:3.0: Use #GtkCssProvider instead
894  */
895 GScanner*
896 gtk_rc_scanner_new (void)
897 {
898   return g_scanner_new (&gtk_rc_scanner_config);
899 }
900
901 /*********************
902  * Parsing functions *
903  *********************/
904
905 static gboolean
906 lookup_color (GtkRcStyle *style,
907               const char *color_name,
908               GdkColor   *color)
909 {
910   GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
911   GSList *iter;
912
913   for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
914     {
915       GHashTable *hash  = iter->data;
916       GdkColor   *match = g_hash_table_lookup (hash, color_name);
917
918       if (match)
919         {
920           color->red = match->red;
921           color->green = match->green;
922           color->blue = match->blue;
923           return TRUE;
924         }
925     }
926
927   return FALSE;
928 }
929
930 /**
931  * gtk_rc_find_pixmap_in_path:
932  * @settings: a #GtkSettings
933  * @scanner: Scanner used to get line number information for the
934  *   warning message, or %NULL
935  * @pixmap_file: name of the pixmap file to locate.
936  * 
937  * Looks up a file in pixmap path for the specified #GtkSettings.
938  * If the file is not found, it outputs a warning message using
939  * g_warning() and returns %NULL.
940  *
941  * Return value: (type filename): the filename. 
942  **/
943 gchar*
944 gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
945                             GScanner     *scanner,
946                             const gchar  *pixmap_file)
947 {
948   g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
949              pixmap_file);
950   return NULL;
951 }
952
953 /**
954  * gtk_rc_find_module_in_path:
955  * @module_file: name of a theme engine
956  * 
957  * Searches for a theme engine in the GTK+ search path. This function
958  * is not useful for applications and should not be used.
959  * 
960  * Return value: (type filename): The filename, if found (must be
961  *   freed with g_free()), otherwise %NULL.
962  **/
963 gchar*
964 gtk_rc_find_module_in_path (const gchar *module_file)
965 {
966   return _gtk_find_module (module_file, "engines");
967 }
968
969 /**
970  * gtk_rc_parse_state:
971  * @scanner:
972  * @state: (out):
973  *
974  * Deprecated:3.0: Use #GtkCssProvider instead
975  */
976 guint
977 gtk_rc_parse_state (GScanner     *scanner,
978                     GtkStateType *state)
979 {
980   guint old_scope;
981   guint token;
982
983   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
984   g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
985   
986   /* we don't know where we got called from, so we reset the scope here.
987    * if we bail out due to errors, we *don't* reset the scope, so the
988    * error messaging code can make sense of our tokens.
989    */
990   old_scope = g_scanner_set_scope (scanner, 0);
991   
992   token = g_scanner_get_next_token (scanner);
993   if (token != G_TOKEN_LEFT_BRACE)
994     return G_TOKEN_LEFT_BRACE;
995   
996   token = g_scanner_get_next_token (scanner);
997   switch (token)
998     {
999     case GTK_RC_TOKEN_ACTIVE:
1000       *state = GTK_STATE_ACTIVE;
1001       break;
1002     case GTK_RC_TOKEN_INSENSITIVE:
1003       *state = GTK_STATE_INSENSITIVE;
1004       break;
1005     case GTK_RC_TOKEN_NORMAL:
1006       *state = GTK_STATE_NORMAL;
1007       break;
1008     case GTK_RC_TOKEN_PRELIGHT:
1009       *state = GTK_STATE_PRELIGHT;
1010       break;
1011     case GTK_RC_TOKEN_SELECTED:
1012       *state = GTK_STATE_SELECTED;
1013       break;
1014     default:
1015       return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1016     }
1017   
1018   token = g_scanner_get_next_token (scanner);
1019   if (token != G_TOKEN_RIGHT_BRACE)
1020     return G_TOKEN_RIGHT_BRACE;
1021   
1022   g_scanner_set_scope (scanner, old_scope);
1023
1024   return G_TOKEN_NONE;
1025 }
1026
1027 /**
1028  * gtk_rc_parse_priority:
1029  * @scanner:
1030  * @priority: (out):
1031  *
1032  * Deprecated:3.0: Use #GtkCssProvider instead
1033  */
1034 guint
1035 gtk_rc_parse_priority (GScanner            *scanner,
1036                        GtkPathPriorityType *priority)
1037 {
1038   guint old_scope;
1039   guint token;
1040
1041   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1042   g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1043
1044   /* we don't know where we got called from, so we reset the scope here.
1045    * if we bail out due to errors, we *don't* reset the scope, so the
1046    * error messaging code can make sense of our tokens.
1047    */
1048   old_scope = g_scanner_set_scope (scanner, 0);
1049   
1050   token = g_scanner_get_next_token (scanner);
1051   if (token != ':')
1052     return ':';
1053   
1054   token = g_scanner_get_next_token (scanner);
1055   switch (token)
1056     {
1057     case GTK_RC_TOKEN_LOWEST:
1058       *priority = GTK_PATH_PRIO_LOWEST;
1059       break;
1060     case GTK_RC_TOKEN_GTK:
1061       *priority = GTK_PATH_PRIO_GTK;
1062       break;
1063     case GTK_RC_TOKEN_APPLICATION:
1064       *priority = GTK_PATH_PRIO_APPLICATION;
1065       break;
1066     case GTK_RC_TOKEN_THEME:
1067       *priority = GTK_PATH_PRIO_THEME;
1068       break;
1069     case GTK_RC_TOKEN_RC:
1070       *priority = GTK_PATH_PRIO_RC;
1071       break;
1072     case GTK_RC_TOKEN_HIGHEST:
1073       *priority = GTK_PATH_PRIO_HIGHEST;
1074       break;
1075     default:
1076       return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1077     }
1078   
1079   g_scanner_set_scope (scanner, old_scope);
1080
1081   return G_TOKEN_NONE;
1082 }
1083
1084 /**
1085  * gtk_rc_parse_color:
1086  * @scanner: a #GScanner
1087  * @color: (out): a pointer to a #GdkColor structure in which to store
1088  *     the result
1089  *
1090  * Parses a color in the <link linkend="color=format">format</link> expected
1091  * in a RC file. 
1092  *
1093  * Note that theme engines should use gtk_rc_parse_color_full() in 
1094  * order to support symbolic colors.
1095  *
1096  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1097  *     that was expected but not found
1098  *
1099  * Deprecated:3.0: Use #GtkCssProvider instead
1100  */
1101 guint
1102 gtk_rc_parse_color (GScanner *scanner,
1103                     GdkColor *color)
1104 {
1105   return gtk_rc_parse_color_full (scanner, NULL, color);
1106 }
1107
1108 /**
1109  * gtk_rc_parse_color_full:
1110  * @scanner: a #GScanner
1111  * @style: (allow-none): a #GtkRcStyle, or %NULL
1112  * @color: (out): a pointer to a #GdkColor structure in which to store
1113  *     the result
1114  *
1115  * Parses a color in the <link linkend="color=format">format</link> expected
1116  * in a RC file. If @style is not %NULL, it will be consulted to resolve
1117  * references to symbolic colors.
1118  *
1119  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1120  *     that was expected but not found
1121  *
1122  * Since: 2.12
1123  *
1124  * Deprecated:3.0: Use #GtkCssProvider instead
1125  */
1126 guint
1127 gtk_rc_parse_color_full (GScanner   *scanner,
1128                          GtkRcStyle *style,
1129                          GdkColor   *color)
1130 {
1131   guint token;
1132
1133   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1134
1135   /* we don't need to set our own scope here, because
1136    * we don't need own symbols
1137    */
1138   
1139   token = g_scanner_get_next_token (scanner);
1140   switch (token)
1141     {
1142       gint token_int;
1143       GdkColor c1, c2;
1144       gboolean negate;
1145       gdouble l;
1146
1147     case G_TOKEN_LEFT_CURLY:
1148       token = g_scanner_get_next_token (scanner);
1149       if (token == G_TOKEN_INT)
1150         token_int = scanner->value.v_int;
1151       else if (token == G_TOKEN_FLOAT)
1152         token_int = scanner->value.v_float * 65535.0;
1153       else
1154         return G_TOKEN_FLOAT;
1155       color->red = CLAMP (token_int, 0, 65535);
1156       
1157       token = g_scanner_get_next_token (scanner);
1158       if (token != G_TOKEN_COMMA)
1159         return G_TOKEN_COMMA;
1160       
1161       token = g_scanner_get_next_token (scanner);
1162       if (token == G_TOKEN_INT)
1163         token_int = scanner->value.v_int;
1164       else if (token == G_TOKEN_FLOAT)
1165         token_int = scanner->value.v_float * 65535.0;
1166       else
1167         return G_TOKEN_FLOAT;
1168       color->green = CLAMP (token_int, 0, 65535);
1169       
1170       token = g_scanner_get_next_token (scanner);
1171       if (token != G_TOKEN_COMMA)
1172         return G_TOKEN_COMMA;
1173       
1174       token = g_scanner_get_next_token (scanner);
1175       if (token == G_TOKEN_INT)
1176         token_int = scanner->value.v_int;
1177       else if (token == G_TOKEN_FLOAT)
1178         token_int = scanner->value.v_float * 65535.0;
1179       else
1180         return G_TOKEN_FLOAT;
1181       color->blue = CLAMP (token_int, 0, 65535);
1182       
1183       token = g_scanner_get_next_token (scanner);
1184       if (token != G_TOKEN_RIGHT_CURLY)
1185         return G_TOKEN_RIGHT_CURLY;
1186       return G_TOKEN_NONE;
1187       
1188     case G_TOKEN_STRING:
1189       if (!gdk_color_parse (scanner->value.v_string, color))
1190         {
1191           g_scanner_warn (scanner, "Invalid color constant '%s'",
1192                           scanner->value.v_string);
1193           return G_TOKEN_STRING;
1194         }
1195       return G_TOKEN_NONE;
1196
1197     case '@':
1198       token = g_scanner_get_next_token (scanner);
1199       if (token != G_TOKEN_IDENTIFIER)
1200         return G_TOKEN_IDENTIFIER;
1201
1202       if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1203         {
1204           g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1205                           scanner->value.v_identifier);
1206           return G_TOKEN_IDENTIFIER;
1207         }
1208
1209       return G_TOKEN_NONE;
1210
1211     case G_TOKEN_IDENTIFIER:
1212       if (strcmp (scanner->value.v_identifier, "mix") == 0)
1213         {
1214           token = g_scanner_get_next_token (scanner);
1215           if (token != G_TOKEN_LEFT_PAREN)
1216             return G_TOKEN_LEFT_PAREN;
1217
1218           negate = FALSE;
1219           if (g_scanner_peek_next_token (scanner) == '-')
1220             {
1221               g_scanner_get_next_token (scanner); /* eat sign */
1222               negate = TRUE;
1223             }
1224
1225           token = g_scanner_get_next_token (scanner);
1226           if (token != G_TOKEN_FLOAT)
1227             return G_TOKEN_FLOAT;
1228
1229           l = negate ? -scanner->value.v_float : scanner->value.v_float;
1230
1231           token = g_scanner_get_next_token (scanner);
1232           if (token != G_TOKEN_COMMA)
1233             return G_TOKEN_COMMA;
1234
1235           token = gtk_rc_parse_color_full (scanner, style, &c1);
1236           if (token != G_TOKEN_NONE)
1237             return token;
1238
1239           token = g_scanner_get_next_token (scanner);
1240           if (token != G_TOKEN_COMMA)
1241             return G_TOKEN_COMMA;
1242
1243           token = gtk_rc_parse_color_full (scanner, style, &c2);
1244           if (token != G_TOKEN_NONE)
1245             return token;
1246
1247           token = g_scanner_get_next_token (scanner);
1248           if (token != G_TOKEN_RIGHT_PAREN)
1249             return G_TOKEN_RIGHT_PAREN;
1250
1251           color->red   = l * c1.red   + (1.0 - l) * c2.red;
1252           color->green = l * c1.green + (1.0 - l) * c2.green;
1253           color->blue  = l * c1.blue  + (1.0 - l) * c2.blue;
1254
1255           return G_TOKEN_NONE;
1256         }
1257       else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1258         {
1259           token = g_scanner_get_next_token (scanner);
1260           if (token != G_TOKEN_LEFT_PAREN)
1261             return G_TOKEN_LEFT_PAREN;
1262
1263           negate = FALSE;
1264           if (g_scanner_peek_next_token (scanner) == '-')
1265             {
1266               g_scanner_get_next_token (scanner); /* eat sign */
1267               negate = TRUE;
1268             }
1269
1270           token = g_scanner_get_next_token (scanner);
1271           if (token != G_TOKEN_FLOAT)
1272             return G_TOKEN_FLOAT;
1273
1274           l = negate ? -scanner->value.v_float : scanner->value.v_float;
1275
1276           token = g_scanner_get_next_token (scanner);
1277           if (token != G_TOKEN_COMMA)
1278             return G_TOKEN_COMMA;
1279
1280           token = gtk_rc_parse_color_full (scanner, style, &c1);
1281           if (token != G_TOKEN_NONE)
1282             return token;
1283
1284           token = g_scanner_get_next_token (scanner);
1285           if (token != G_TOKEN_RIGHT_PAREN)
1286             return G_TOKEN_RIGHT_PAREN;
1287
1288           _gtk_style_shade (&c1, color, l);
1289
1290           return G_TOKEN_NONE;
1291         }
1292       else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
1293                strcmp (scanner->value.v_identifier, "darker") == 0)
1294         {
1295           if (scanner->value.v_identifier[0] == 'l')
1296             l = 1.3;
1297           else
1298             l = 0.7;
1299
1300           token = g_scanner_get_next_token (scanner);
1301           if (token != G_TOKEN_LEFT_PAREN)
1302             return G_TOKEN_LEFT_PAREN;
1303
1304           token = gtk_rc_parse_color_full (scanner, style, &c1);
1305           if (token != G_TOKEN_NONE)
1306             return token;
1307
1308           token = g_scanner_get_next_token (scanner);
1309           if (token != G_TOKEN_RIGHT_PAREN)
1310             return G_TOKEN_RIGHT_PAREN;
1311
1312           _gtk_style_shade (&c1, color, l);
1313
1314           return G_TOKEN_NONE;
1315         }
1316       else
1317         return G_TOKEN_IDENTIFIER;
1318
1319     default:
1320       return G_TOKEN_STRING;
1321     }
1322 }