]> Pileus Git - ~andy/gtk/blob - gtk/deprecated/gtkrc.c
9ec2046d4e897d5b052c858d188cff4f5f7a4ae0
[~andy/gtk] / gtk / deprecated / 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 #define GDK_DISABLE_DEPRECATION_WARNINGS
43
44 #include <glib.h>
45 #include <glib/gstdio.h>
46 #include "gdk/gdk.h"
47
48 #include "gtkversion.h"
49 #include "gtkrc.h"
50 #include "gtkstyle.h"
51 #include "gtkbindings.h"
52 #include "gtkintl.h"
53 #include "gtkiconfactory.h"
54 #include "gtkmain.h"
55 #include "gtkmodules.h"
56 #include "gtkmodulesprivate.h"
57 #include "gtkprivate.h"
58 #include "gtksettingsprivate.h"
59 #include "gtkwindow.h"
60
61 #ifdef G_OS_WIN32
62 #include <io.h>
63 #endif
64
65
66 /**
67  * SECTION:gtkrc
68  * @Short_description: Deprecated routines for handling resource files
69  * @Title: Resource Files
70  *
71  * GTK+ provides resource file mechanism for configuring
72  * various aspects of the operation of a GTK+ program
73  * at runtime.
74  *
75  * <warning>
76  * In GTK+ 3.0, resource files have been deprecated and replaced
77  * by CSS-like style sheets, which are understood by #GtkCssProvider.
78  * </warning>
79  *
80  * <refsect2>
81  * <title>Default files</title>
82  * <para>
83  * An application can cause GTK+ to parse a specific RC
84  * file by calling gtk_rc_parse(). In addition to this,
85  * certain files will be read at the end of gtk_init().
86  * Unless modified, the files looked for will be
87  * <filename>&lt;SYSCONFDIR&gt;/gtk-2.0/gtkrc</filename>
88  * and <filename>.gtkrc-3.0</filename> in the users home directory.
89  * (<filename>&lt;SYSCONFDIR&gt;</filename> defaults to
90  * <filename>/usr/local/etc</filename>. It can be changed with the
91  * <option>--prefix</option> or <option>--sysconfdir</option> options when
92  * configuring GTK+.)
93  *
94  * The set of these <firstterm>default</firstterm> files
95  * can be retrieved with gtk_rc_get_default_files()
96  * and modified with gtk_rc_add_default_file() and
97  * gtk_rc_set_default_files().
98  * Additionally, the <envar>GTK2_RC_FILES</envar> environment variable
99  * can be set to a #G_SEARCHPATH_SEPARATOR_S-separated list of files
100  * in order to overwrite the set of default files at runtime.
101  * <para><anchor id="locale-specific-rc"/>
102  * For each RC file, in addition to the file itself, GTK+ will look for
103  * a locale-specific file that will be parsed after the main file.
104  * For instance, if <envar>LANG</envar> is set to <literal>ja_JP.ujis</literal>,
105  * when loading the default file <filename>~/.gtkrc</filename> then GTK+ looks
106  * for <filename>~/.gtkrc.ja_JP</filename> and <filename>~/.gtkrc.ja</filename>,
107  * and parses the first of those that exists.</para>
108  * </para>
109  * </refsect2>
110  * <refsect2>
111  * <title>Pathnames and patterns</title>
112  * <anchor id="gtkrc-pathnames-and-patterns"/>
113  * <para>
114  * A resource file defines a number of styles and key bindings and
115  * attaches them to particular widgets. The attachment is done
116  * by the <literal>widget</literal>, <literal>widget_class</literal>,
117  * and <literal>class</literal> declarations. As an example
118  * of such a statement:
119  *
120  * <informalexample><programlisting>
121  * widget "mywindow.*.GtkEntry" style "my-entry-class"
122  * </programlisting></informalexample>
123  *
124  * attaches the style <literal>"my-entry-class"</literal> to all
125  * widgets  whose <firstterm>widget path</firstterm> matches the
126  * <firstterm>pattern</firstterm> <literal>"mywindow.*.GtkEntry"</literal>.
127  * That is, all #GtkEntry widgets which are part of a #GtkWindow named
128  * <literal>"mywindow"</literal>.
129  *
130  * The patterns here are given in the standard shell glob syntax.
131  * The <literal>"?"</literal> wildcard matches any character, while
132  * <literal>"*"</literal> matches zero or more of any character.
133  * The three types of matching are against the widget path, the
134  * <firstterm>class path</firstterm> and the class hierarchy. Both the
135  * widget path and the class path consist of a <literal>"."</literal>
136  * separated list of all the parents of the widget and the widget itself
137  * from outermost to innermost. The difference is that in the widget path,
138  * the name assigned by gtk_widget_set_name() is used if present, otherwise
139  * the class name of the widget, while for the class path, the class name is
140  * always used.
141  *
142  * Since GTK+ 2.10, <literal>widget_class</literal> paths can also contain
143  * <literal>&lt;classname&gt;</literal> substrings, which are matching
144  * the class with the given name and any derived classes. For instance,
145  * <informalexample><programlisting>
146  * widget_class "*&lt;GtkMenuItem&gt;.GtkLabel" style "my-style"
147  * </programlisting></informalexample>
148  * will match #GtkLabel widgets which are contained in any kind of menu item.
149  *
150  * So, if you have a #GtkEntry named <literal>"myentry"</literal>, inside of a
151  * horizontal box in a window named <literal>"mywindow"</literal>, then the
152  * widget path is: <literal>"mywindow.GtkHBox.myentry"</literal>
153  * while the class path is: <literal>"GtkWindow.GtkHBox.GtkEntry"</literal>.
154  *
155  * Matching against class is a little different. The pattern match is done
156  * against all class names in the widgets class hierarchy (not the layout
157  * hierarchy) in sequence, so the pattern:
158  * <informalexample><programlisting>
159  * class "GtkButton" style "my-style"
160  * </programlisting></informalexample>
161  * will match not just #GtkButton widgets, but also #GtkToggleButton and
162  * #GtkCheckButton widgets, since those classes derive from #GtkButton.
163  *
164  * Additionally, a priority can be specified for each pattern, and styles
165  * override other styles first by priority, then by pattern type and then
166  * by order of specification (later overrides earlier). The priorities
167  * that can be specified are (highest to lowest):
168  * <simplelist>
169  * <member><literal>highest</literal></member>
170  * <member><literal>rc</literal></member>
171  * <member><literal>theme</literal></member>
172  * <member><literal>application</literal></member>
173  * <member><literal>gtk</literal></member>
174  * <member><literal>lowest</literal></member>
175  * </simplelist>
176  * <literal>rc</literal> is the default for styles
177  * read from an RC file, <literal>theme</literal>
178  * is the default for styles read from theme RC files,
179  * <literal>application</literal>
180  * should be used for styles an application sets
181  * up, and <literal>gtk</literal> is used for styles
182  * that GTK+ creates internally.
183  * </para>
184  * </refsect2>
185  * <refsect2>
186  * <title>Theme gtkrc files</title>
187  * <anchor id="theme-gtkrc-files"/>
188  * <para>
189  * Theme RC files are loaded first from under the <filename>~/.themes/</filename>,
190  * then from the directory from gtk_rc_get_theme_dir(). The files looked at will
191  * be <filename>gtk-3.0/gtkrc</filename>.
192  *
193  * When the application prefers dark themes
194  * (see the #GtkSettings:gtk-application-prefer-dark-theme property for details),
195  * <filename>gtk-3.0/gtkrc-dark</filename> will be loaded first, and if not present
196  * <filename>gtk-3.0/gtkrc</filename> will be loaded.
197  * </para>
198  * </refsect2>
199  * <refsect2>
200  * <title>Optimizing RC Style Matches</title>
201  * <anchor id="optimizing-rc-style-matches"/>
202  * <para>
203  * Everytime a widget is created and added to the layout hierarchy of a #GtkWindow
204  * ("anchored" to be exact), a list of matching RC styles out of all RC styles read
205  * in so far is composed.
206  * For this, every RC style is matched against the widgets class path,
207  * the widgets name path and widgets inheritance hierarchy.
208  * As a consequence, significant slowdown can be caused by utilization of many
209  * RC styles and by using RC style patterns that are slow or complicated to match
210  * against a given widget.
211  * The following ordered list provides a number of advices (prioritized by
212  * effectiveness) to reduce the performance overhead associated with RC style
213  * matches:
214  *
215  * <orderedlist>
216  *   <listitem><para>
217  *   Move RC styles for specific applications into RC files dedicated to those
218  *   applications and parse application specific RC files only from
219  *   applications that are affected by them.
220  *   This reduces the overall amount of RC styles that have to be considered
221  *   for a match across a group of applications.
222  *   </para></listitem>
223  *   <listitem><para>
224  *   Merge multiple styles which use the same matching rule, for instance:
225  *   <informalexample><programlisting>
226  *      style "Foo" { foo_content }
227  *      class "X" style "Foo"
228  *      style "Bar" { bar_content }
229  *      class "X" style "Bar"
230  *   </programlisting></informalexample>
231  *   is faster to match as:
232  *   <informalexample><programlisting>
233  *      style "FooBar" { foo_content bar_content }
234  *      class "X" style "FooBar"
235  *   </programlisting></informalexample>
236  *   </para></listitem>
237  *   <listitem><para>
238  *   Use of wildcards should be avoided, this can reduce the individual RC style
239  *   match to a single integer comparison in most cases.
240  *   </para></listitem>
241  *   <listitem><para>
242  *   To avoid complex recursive matching, specification of full class names
243  *   (for <literal>class</literal> matches) or full path names (for
244  *   <literal>widget</literal> and <literal>widget_class</literal> matches)
245  *   is to be preferred over shortened names
246  *   containing <literal>"*"</literal> or <literal>"?"</literal>.
247  *   </para></listitem>
248  *   <listitem><para>
249  *   If at all necessary, wildcards should only be used at the tail or head
250  *   of a pattern. This reduces the match complexity to a string comparison
251  *   per RC style.
252  *   </para></listitem>
253  *   <listitem><para>
254  *   When using wildcards, use of <literal>"?"</literal> should be preferred
255  *   over <literal>"*"</literal>. This can reduce the matching complexity from
256  *   O(n^2) to O(n). For example <literal>"Gtk*Box"</literal> can be turned into
257  *   <literal>"Gtk?Box"</literal> and will still match #GtkHBox and #GtkVBox.
258  *   </para></listitem>
259  *  <listitem><para>
260  *   The use of <literal>"*"</literal> wildcards should be restricted as much
261  *   as possible, because matching <literal>"A*B*C*RestString"</literal> can
262  *   result in matching complexities of O(n^2) worst case.
263  *   </para></listitem>
264  * </orderedlist>
265  * </para>
266  * </refsect2>
267  * <refsect2>
268  * <title>Toplevel declarations</title>
269  * <para>
270  * An RC file is a text file which is composed of a sequence
271  * of declarations. <literal>'#'</literal> characters delimit comments and
272  * the portion of a line after a <literal>'#'</literal> is ignored when parsing
273  * an RC file.
274  *
275  * The possible toplevel declarations are:
276  *
277  * <variablelist>
278  *   <varlistentry>
279  *     <term><literal>binding <replaceable>name</replaceable>
280  *      { ... }</literal></term>
281  *     <listitem>
282  *       <para>Declares a binding set.</para>
283  *     </listitem>
284  *   </varlistentry>
285  *   <varlistentry>
286  *     <term><literal>class <replaceable>pattern</replaceable>
287  *           [ style | binding ][ : <replaceable>priority</replaceable> ]
288  *           <replaceable>name</replaceable></literal></term>
289  *     <listitem>
290  *      <para>Specifies a style or binding set for a particular
291  *      branch of the inheritance hierarchy.</para>
292  *     </listitem>
293  *   </varlistentry>
294  *   <varlistentry>
295  *     <term><literal>include <replaceable>filename</replaceable></literal></term>
296  *     <listitem>
297  *       <para>Parses another file at this point. If
298  *         <replaceable>filename</replaceable> is not an absolute filename,
299  *         it is searched in the directories of the currently open RC files.</para>
300  *       <para>GTK+ also tries to load a
301  *         <link linkend="locale-specific-rc">locale-specific variant</link> of
302  *         the included file.</para>
303  *     </listitem>
304  *   </varlistentry>
305  *   <varlistentry>
306  *     <term><literal>module_path <replaceable>path</replaceable></literal></term>
307  *     <listitem>
308  *       <para>Sets a path (a list of directories separated
309  *       by colons) that will be searched for theme engines referenced in
310  *       RC files.</para>
311  *     </listitem>
312  *   </varlistentry>
313  *   <varlistentry>
314  *     <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
315  *     <listitem>
316  *       <para>Sets a path (a list of directories separated
317  *       by colons) that will be searched for pixmaps referenced in
318  *       RC files.</para>
319  *     </listitem>
320  *   </varlistentry>
321  *   <varlistentry>
322  *     <term><literal>im_module_file <replaceable>pathname</replaceable></literal></term>
323  *     <listitem>
324  *       <para>Sets the pathname for the IM modules file. Setting this from RC files
325  *       is deprecated; you should use the environment variable <envar>GTK_IM_MODULE_FILE</envar>
326  *       instead.</para>
327  *     </listitem>
328  *   </varlistentry>
329  *   <varlistentry>
330  *     <term><literal>style <replaceable>name</replaceable> [ =
331  *     <replaceable>parent</replaceable> ] { ... }</literal></term>
332  *     <listitem>
333  *       <para>Declares a style.</para>
334  *     </listitem>
335  *   </varlistentry>
336  *   <varlistentry>
337  *     <term><literal>widget <replaceable>pattern</replaceable>
338  *           [ style | binding ][ : <replaceable>priority</replaceable> ]
339  *           <replaceable>name</replaceable></literal></term>
340  *     <listitem>
341  *      <para>Specifies a style or binding set for a particular
342  *      group of widgets by matching on the widget pathname.</para>
343  *     </listitem>
344  *   </varlistentry>
345  *   <varlistentry>
346  *     <term><literal>widget_class <replaceable>pattern</replaceable>
347  *           [ style | binding ][ : <replaceable>priority</replaceable> ]
348  *           <replaceable>name</replaceable></literal></term>
349  *     <listitem>
350  *      <para>Specifies a style or binding set for a particular
351  *      group of widgets by matching on the class pathname.</para>
352  *     </listitem>
353  *   </varlistentry>
354  *   <varlistentry>
355  *     <term><replaceable>setting</replaceable> = <replaceable>value</replaceable></term>
356  *     <listitem>
357  *       <para>Specifies a value for a <link linkend="GtkSettings">setting</link>.
358  *         Note that settings in RC files are overwritten by system-wide settings
359  *         (which are managed by an XSettings manager on X11).</para>
360  *     </listitem>
361  *   </varlistentry>
362  * </variablelist>
363  * </para>
364  * </refsect2>
365  * <refsect2>
366  * <title>Styles</title>
367  * <para>
368  * A RC style is specified by a <literal>style</literal>
369  * declaration in a RC file, and then bound to widgets
370  * with a <literal>widget</literal>, <literal>widget_class</literal>,
371  * or <literal>class</literal> declaration. All styles
372  * applying to a particular widget are composited together
373  * with <literal>widget</literal> declarations overriding
374  * <literal>widget_class</literal> declarations which, in
375  * turn, override <literal>class</literal> declarations.
376  * Within each type of declaration, later declarations override
377  * earlier ones.
378  *
379  * Within a <literal>style</literal> declaration, the possible
380  * elements are:
381  *
382  * <variablelist>
383  *   <varlistentry>
384  *     <term><literal>bg[<replaceable>state</replaceable>] =
385  *       <replaceable>color</replaceable></literal></term>
386  *      <listitem>
387  *          Sets the color used for the background of most widgets.
388  *      </listitem>
389  *   </varlistentry>
390  *   <varlistentry>
391  *     <term><literal>fg[<replaceable>state</replaceable>] =
392  *       <replaceable>color</replaceable></literal></term>
393  *      <listitem>
394  *          Sets the color used for the foreground of most widgets.
395  *      </listitem>
396  *   </varlistentry>
397  *   <varlistentry>
398  *     <term><literal>base[<replaceable>state</replaceable>] =
399  *       <replaceable>color</replaceable></literal></term>
400  *      <listitem>
401  *          Sets the color used for the background of widgets displaying
402  *          editable text. This color is used for the background
403  *          of, among others, #GtkText, #GtkEntry, #GtkList, and #GtkCList.
404  *      </listitem>
405  *   </varlistentry>
406  *   <varlistentry>
407  *     <term><literal>text[<replaceable>state</replaceable>] =
408  *       <replaceable>color</replaceable></literal></term>
409  *      <listitem>
410  *          Sets the color used for foreground of widgets using
411  *          <literal>base</literal> for the background color.
412  *      </listitem>
413  *   </varlistentry>
414  *   <varlistentry>
415  *     <term><literal>xthickness =
416  *       <replaceable>number</replaceable></literal></term>
417  *      <listitem>
418  *          Sets the xthickness, which is used for various horizontal padding
419  *          values in GTK+.
420  *      </listitem>
421  *   </varlistentry>
422  *   <varlistentry>
423  *     <term><literal>ythickness =
424  *       <replaceable>number</replaceable></literal></term>
425  *      <listitem>
426  *          Sets the ythickness, which is used for various vertical padding
427  *          values in GTK+.
428  *      </listitem>
429  *   </varlistentry>
430  *   <varlistentry>
431  *     <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
432  *       <replaceable>pixmap</replaceable></literal></term>
433  *      <listitem>
434  *          Sets a background pixmap to be used in place of
435  *          the <literal>bg</literal> color (or for #GtkText,
436  *          in place of the <literal>base</literal> color. The special
437  *          value <literal>"&lt;parent&gt;"</literal> may be used to indicate that the widget should
438  *          use the same background pixmap as its parent. The special value
439  *          <literal>"&lt;none&gt;"</literal> may be used to indicate no background pixmap.
440  *      </listitem>
441  *   </varlistentry>
442  *   <varlistentry>
443  *     <term><literal>font = <replaceable>font</replaceable></literal></term>
444  *      <listitem>
445  *          Starting with GTK+ 2.0, the "font" and "fontset"
446  *          declarations are ignored; use "font_name" declarations instead.
447  *      </listitem>
448  *   </varlistentry>
449  *   <varlistentry>
450  *     <term><literal>fontset = <replaceable>font</replaceable></literal></term>
451  *      <listitem>
452  *          Starting with GTK+ 2.0, the "font" and "fontset"
453  *          declarations are ignored; use "font_name" declarations instead.
454  *      </listitem>
455  *   </varlistentry>
456  *   <varlistentry>
457  *     <term><literal>font_name = <replaceable>font</replaceable></literal></term>
458  *      <listitem>
459  *          Sets the font for a widget. <replaceable>font</replaceable> must be
460  *          a Pango font name, e.g. <literal>"Sans Italic 10"</literal>.
461  *          For details about Pango font names, see
462  *          pango_font_description_from_string().
463  *      </listitem>
464  *   </varlistentry>
465  *   <varlistentry>
466  *     <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
467  *      <listitem>
468  *         Defines the icon for a stock item.
469  *      </listitem>
470  *   </varlistentry>
471  *   <varlistentry>
472  *     <term><literal>color[<replaceable>"color-name"</replaceable>] = <replaceable>color specification</replaceable></literal></term>
473  *      <listitem>
474  *         Since 2.10, this element can be used to defines symbolic colors. See below for
475  *         the syntax of color specifications.
476  *      </listitem>
477  *   </varlistentry>
478  *   <varlistentry>
479  *     <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
480  * settings</replaceable> }</literal></term>
481  *      <listitem>
482  *         Defines the engine to be used when drawing with this style.
483  *      </listitem>
484  *   </varlistentry>
485  *   <varlistentry>
486  *     <term><literal><replaceable>class</replaceable>::<replaceable>property</replaceable> = <replaceable>value</replaceable></literal></term>
487  *      <listitem>
488  *         Sets a <link linkend="style-properties">style property</link> for a widget class.
489  *      </listitem>
490  *   </varlistentry>
491  * </variablelist>
492  *
493  * The colors and background pixmaps are specified as a function of the
494  * state of the widget. The states are:
495  *
496  * <variablelist>
497  *   <varlistentry>
498  *     <term><literal>NORMAL</literal></term>
499  *     <listitem>
500  *         A color used for a widget in its normal state.
501  *     </listitem>
502  *   </varlistentry>
503  *   <varlistentry>
504  *     <term><literal>ACTIVE</literal></term>
505  *     <listitem>
506  *         A variant of the <literal>NORMAL</literal> color used when the
507  *         widget is in the %GTK_STATE_ACTIVE state, and also for
508  *         the trough of a ScrollBar, tabs of a NoteBook
509  *         other than the current tab and similar areas.
510  *         Frequently, this should be a darker variant
511  *         of the <literal>NORMAL</literal> color.
512  *     </listitem>
513  *   </varlistentry>
514  *   <varlistentry>
515  *     <term><literal>PRELIGHT</literal></term>
516  *     <listitem>
517  *         A color used for widgets in the %GTK_STATE_PRELIGHT state. This
518  *         state is the used for Buttons and MenuItems
519  *         that have the mouse cursor over them, and for
520  *         their children.
521  *     </listitem>
522  *   </varlistentry>
523  *   <varlistentry>
524  *     <term><literal>SELECTED</literal></term>
525  *     <listitem>
526  *         A color used to highlight data selected by the user.
527  *         for instance, the selected items in a list widget, and the
528  *         selection in an editable widget.
529  *     </listitem>
530  *   </varlistentry>
531  *   <varlistentry>
532  *     <term><literal>INSENSITIVE</literal></term>
533  *     <listitem>
534  *         A color used for the background of widgets that have
535  *         been set insensitive with gtk_widget_set_sensitive().
536  *     </listitem>
537  *   </varlistentry>
538  * </variablelist>
539  *
540  * <anchor id="color-format"/>
541  * Colors can be specified as a string containing a color name (GTK+ knows
542  * all names from the X color database <filename>/usr/lib/X11/rgb.txt</filename>),
543  * in one of the hexadecimal forms <literal>#rrrrggggbbbb</literal>,
544  * <literal>#rrrgggbbb</literal>, <literal>#rrggbb</literal>,
545  * or <literal>#rgb</literal>, where <literal>r</literal>,
546  * <literal>g</literal> and <literal>b</literal> are
547  * hex digits, or they can be specified as a triplet
548  * <literal>{ <replaceable>r</replaceable>, <replaceable>g</replaceable>,
549  * <replaceable>b</replaceable>}</literal>, where <literal>r</literal>,
550  * <literal>g</literal> and <literal>b</literal> are either integers in
551  * the range 0-65535 or floats in the range 0.0-1.0.
552  *
553  * Since 2.10, colors can also be specified by refering to a symbolic color, as
554  * follows: <literal>@<!-- -->color-name</literal>, or by using expressions to combine
555  * colors. The following expressions are currently supported:
556  *   <variablelist>
557  *     <varlistentry>
558  *       <term>mix (<replaceable>factor</replaceable>, <replaceable>color1</replaceable>, <replaceable>color2</replaceable>)</term>
559  *       <listitem><para>
560  *         Computes a new color by mixing <replaceable>color1</replaceable> and
561  *         <replaceable>color2</replaceable>. The <replaceable>factor</replaceable>
562  *         determines how close the new color is to <replaceable>color1</replaceable>.
563  *         A factor of 1.0 gives pure <replaceable>color1</replaceable>, a factor of
564  *         0.0 gives pure <replaceable>color2</replaceable>.
565  *       </para></listitem>
566  *     </varlistentry>
567  *     <varlistentry>
568  *       <term>shade (<replaceable>factor</replaceable>, <replaceable>color</replaceable>)</term>
569  *       <listitem><para>
570  *         Computes a lighter or darker variant of <replaceable>color</replaceable>.
571  *         A <replaceable>factor</replaceable> of 1.0 leaves the color unchanged, smaller
572  *         factors yield darker colors, larger factors yield lighter colors.
573  *       </para></listitem>
574  *     </varlistentry>
575  *     <varlistentry>
576  *       <term>lighter (<replaceable>color</replaceable>)</term>
577  *       <listitem><para>
578  *         This is an abbreviation for
579  *         <literal>shade (1.3, <replaceable>color</replaceable>)</literal>.
580  *       </para></listitem>
581  *     </varlistentry>
582  *     <varlistentry>
583  *       <term>darker (<replaceable>color</replaceable>)</term>
584  *       <listitem><para>
585  *         This is an abbreviation for
586  *         <literal>shade (0.7, <replaceable>color</replaceable>)</literal>.
587  *       </para></listitem>
588  *     </varlistentry>
589  *   </variablelist>
590  *
591  * Here are some examples of color expressions:
592  *
593  * <informalexample><programlisting>
594  *  mix (0.5, "red", "blue")
595  *  shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 }))
596  *  lighter (@<!-- -->foreground)
597  * </programlisting></informalexample>
598  *
599  * In a <literal>stock</literal> definition, icon sources are specified as a
600  * 4-tuple of image filename or icon name, text direction, widget state, and size, in that
601  * order.  Each icon source specifies an image filename or icon name to use with a given
602  * direction, state, and size. Filenames are specified as a string such
603  * as <literal>"itemltr.png"</literal>, while icon names (looked up
604  * in the current icon theme), are specified with a leading
605  * <literal>@</literal>, such as <literal>@"item-ltr"</literal>.
606  * The <literal>*</literal> character can be used as a
607  * wildcard, and if direction/state/size are omitted they default to
608  * <literal>*</literal>. So for example, the following specifies different icons to
609  * use for left-to-right and right-to-left languages:
610  *
611  * <informalexample><programlisting>
612  * stock["my-stock-item"] =
613  * {
614  *   { "itemltr.png", LTR, *, * },
615  *   { "itemrtl.png", RTL, *, * }
616  * }
617  * </programlisting></informalexample>
618  *
619  * This could be abbreviated as follows:
620  *
621  * <informalexample><programlisting>
622  * stock["my-stock-item"] =
623  * {
624  *   { "itemltr.png", LTR },
625  *   { "itemrtl.png", RTL }
626  * }
627  * </programlisting></informalexample>
628  *
629  * You can specify custom icons for specific sizes, as follows:
630  *
631  * <informalexample><programlisting>
632  * stock["my-stock-item"] =
633  * {
634  *   { "itemmenusize.png", *, *, "gtk-menu" },
635  *   { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
636  *   { "itemgeneric.png" } // implicit *, *, * as a fallback
637  * }
638  * </programlisting></informalexample>
639  *
640  * The sizes that come with GTK+ itself are <literal>"gtk-menu"</literal>,
641  * <literal>"gtk-small-toolbar"</literal>, <literal>"gtk-large-toolbar"</literal>,
642  * <literal>"gtk-button"</literal>, <literal>"gtk-dialog"</literal>. Applications
643  * can define other sizes.
644  *
645  * It's also possible to use custom icons for a given state, for example:
646  *
647  * <informalexample><programlisting>
648  * stock["my-stock-item"] =
649  * {
650  *   { "itemprelight.png", *, PRELIGHT },
651  *   { "iteminsensitive.png", *, INSENSITIVE },
652  *   { "itemgeneric.png" } // implicit *, *, * as a fallback
653  * }
654  * </programlisting></informalexample>
655  *
656  * When selecting an icon source to use, GTK+ will consider text direction most
657  * important, state second, and size third. It will select the best match based on
658  * those criteria. If an attribute matches exactly (e.g. you specified
659  * <literal>PRELIGHT</literal> or specified the size), GTK+ won't modify the image;
660  * if the attribute matches with a wildcard, GTK+ will scale or modify the image to
661  * match the state and size the user requested.
662  * </para>
663  * </refsect2>
664  * <refsect2>
665  * <title>Key bindings</title>
666  * <para>
667  * Key bindings allow the user to specify actions to be
668  * taken on particular key presses. The form of a binding
669  * set declaration is:
670  *
671  * <informalexample><programlisting>
672  * binding <replaceable>name</replaceable> {
673  *   bind <replaceable>key</replaceable> {
674  *     <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
675  *     ...
676  *   }
677  *   ...
678  * }
679  * </programlisting></informalexample>
680  *
681  * <replaceable>key</replaceable> is a string consisting of a
682  * series of modifiers followed by the name of a key. The
683  * modifiers can be:
684  * <simplelist>
685  * <member><literal>&lt;alt&gt;</literal></member>
686  * <member><literal>&lt;ctl&gt;</literal></member>
687  * <member><literal>&lt;control&gt;</literal></member>
688  * <member><literal>&lt;meta&gt;</literal></member>
689  * <member><literal>&lt;hyper&gt;</literal></member>
690  * <member><literal>&lt;super&gt;</literal></member>
691  * <member><literal>&lt;mod1&gt;</literal></member>
692  * <member><literal>&lt;mod2&gt;</literal></member>
693  * <member><literal>&lt;mod3&gt;</literal></member>
694  * <member><literal>&lt;mod4&gt;</literal></member>
695  * <member><literal>&lt;mod5&gt;</literal></member>
696  * <member><literal>&lt;release&gt;</literal></member>
697  * <member><literal>&lt;shft&gt;</literal></member>
698  * <member><literal>&lt;shift&gt;</literal></member>
699  * </simplelist>
700  * <literal>&lt;shft&gt;</literal> is an alias for
701  * <literal>&lt;shift&gt;</literal>,
702  * <literal>&lt;ctl&gt;</literal> is an alias for
703  * <literal>&lt;control&gt;</literal>,
704  *  and
705  * <literal>&lt;alt&gt;</literal> is an alias for
706  * <literal>&lt;mod1&gt;</literal>.
707  *
708  * The action that is bound to the key is a sequence
709  * of signal names (strings) followed by parameters for
710  * each signal. The signals must be action signals.
711  * (See g_signal_new()). Each parameter can be
712  * a float, integer, string, or unquoted string
713  * representing an enumeration value. The types of
714  * the parameters specified must match the types of the
715  * parameters of the signal.
716  *
717  * Binding sets are connected to widgets in the same manner as styles,
718  * with one difference: Binding sets override other binding sets first
719  * by pattern type, then by priority and then by order of specification.
720  * The priorities that can be specified and their default values are the
721  * same as for styles.
722  * </para>
723  * </refsect2>
724  */
725
726
727 enum 
728 {
729   PATH_ELT_PSPEC,
730   PATH_ELT_UNRESOLVED,
731   PATH_ELT_TYPE
732 };
733
734 typedef struct
735 {
736   gint type;
737   union 
738   {
739     GType         class_type;
740     gchar        *class_name;
741     GPatternSpec *pspec;
742   } elt;
743 } PathElt;
744
745 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
746
747 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
748
749 struct _GtkRcStylePrivate
750 {
751   GSList *color_hashes;
752 };
753
754 static void        gtk_rc_style_finalize             (GObject         *object);
755 static void        gtk_rc_style_real_merge           (GtkRcStyle      *dest,
756                                                       GtkRcStyle      *src);
757 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle      *rc_style);
758 static GtkStyle*   gtk_rc_style_real_create_style    (GtkRcStyle      *rc_style);
759 static gint        gtk_rc_properties_cmp             (gconstpointer    bsearch_node1,
760                                                       gconstpointer    bsearch_node2);
761
762 static void        insert_rc_property                (GtkRcStyle      *style,
763                                                       GtkRcProperty   *property,
764                                                       gboolean         replace);
765
766
767 static const GScannerConfig gtk_rc_scanner_config =
768 {
769   (
770    " \t\r\n"
771    )                    /* cset_skip_characters */,
772   (
773    "_"
774    G_CSET_a_2_z
775    G_CSET_A_2_Z
776    )                    /* cset_identifier_first */,
777   (
778    G_CSET_DIGITS
779    "-_"
780    G_CSET_a_2_z
781    G_CSET_A_2_Z
782    )                    /* cset_identifier_nth */,
783   ( "#\n" )             /* cpair_comment_single */,
784   
785   TRUE                  /* case_sensitive */,
786   
787   TRUE                  /* skip_comment_multi */,
788   TRUE                  /* skip_comment_single */,
789   TRUE                  /* scan_comment_multi */,
790   TRUE                  /* scan_identifier */,
791   FALSE                 /* scan_identifier_1char */,
792   FALSE                 /* scan_identifier_NULL */,
793   TRUE                  /* scan_symbols */,
794   TRUE                  /* scan_binary */,
795   TRUE                  /* scan_octal */,
796   TRUE                  /* scan_float */,
797   TRUE                  /* scan_hex */,
798   TRUE                  /* scan_hex_dollar */,
799   TRUE                  /* scan_string_sq */,
800   TRUE                  /* scan_string_dq */,
801   TRUE                  /* numbers_2_int */,
802   FALSE                 /* int_2_float */,
803   FALSE                 /* identifier_2_string */,
804   TRUE                  /* char_2_token */,
805   TRUE                  /* symbol_2_token */,
806   FALSE                 /* scope_0_fallback */,
807 };
808  
809 static const gchar symbol_names[] = 
810   "include\0"
811   "NORMAL\0"
812   "ACTIVE\0"
813   "PRELIGHT\0"
814   "SELECTED\0"
815   "INSENSITIVE\0"
816   "fg\0"
817   "bg\0"
818   "text\0"
819   "base\0"
820   "xthickness\0"
821   "ythickness\0"
822   "font\0"
823   "fontset\0"
824   "font_name\0"
825   "bg_pixmap\0"
826   "pixmap_path\0"
827   "style\0"
828   "binding\0"
829   "bind\0"
830   "widget\0"
831   "widget_class\0"
832   "class\0"
833   "lowest\0"
834   "gtk\0"
835   "application\0"
836   "theme\0"
837   "rc\0"
838   "highest\0"
839   "engine\0"
840   "module_path\0"
841   "stock\0"
842   "im_module_file\0"
843   "LTR\0"
844   "RTL\0"
845   "color\0"
846   "unbind\0";
847
848 static const struct
849 {
850   guint name_offset;
851   guint token;
852 } symbols[] = {
853   {   0, GTK_RC_TOKEN_INCLUDE },
854   {   8, GTK_RC_TOKEN_NORMAL },
855   {  15, GTK_RC_TOKEN_ACTIVE },
856   {  22, GTK_RC_TOKEN_PRELIGHT },
857   {  31, GTK_RC_TOKEN_SELECTED },
858   {  40, GTK_RC_TOKEN_INSENSITIVE },
859   {  52, GTK_RC_TOKEN_FG },
860   {  55, GTK_RC_TOKEN_BG },
861   {  58, GTK_RC_TOKEN_TEXT },
862   {  63, GTK_RC_TOKEN_BASE },
863   {  68, GTK_RC_TOKEN_XTHICKNESS },
864   {  79, GTK_RC_TOKEN_YTHICKNESS },
865   {  90, GTK_RC_TOKEN_FONT },
866   {  95, GTK_RC_TOKEN_FONTSET },
867   { 103, GTK_RC_TOKEN_FONT_NAME },
868   { 113, GTK_RC_TOKEN_BG_PIXMAP },
869   { 123, GTK_RC_TOKEN_PIXMAP_PATH },
870   { 135, GTK_RC_TOKEN_STYLE },
871   { 141, GTK_RC_TOKEN_BINDING },
872   { 149, GTK_RC_TOKEN_BIND },
873   { 154, GTK_RC_TOKEN_WIDGET },
874   { 161, GTK_RC_TOKEN_WIDGET_CLASS },
875   { 174, GTK_RC_TOKEN_CLASS },
876   { 180, GTK_RC_TOKEN_LOWEST },
877   { 187, GTK_RC_TOKEN_GTK },
878   { 191, GTK_RC_TOKEN_APPLICATION },
879   { 203, GTK_RC_TOKEN_THEME },
880   { 209, GTK_RC_TOKEN_RC },
881   { 212, GTK_RC_TOKEN_HIGHEST },
882   { 220, GTK_RC_TOKEN_ENGINE },
883   { 227, GTK_RC_TOKEN_MODULE_PATH },
884   { 239, GTK_RC_TOKEN_STOCK },
885   { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
886   { 260, GTK_RC_TOKEN_LTR },
887   { 264, GTK_RC_TOKEN_RTL },
888   { 268, GTK_RC_TOKEN_COLOR },
889   { 274, GTK_RC_TOKEN_UNBIND }
890 };
891
892 static GHashTable *realized_style_ht = NULL;
893
894 static gchar *im_module_file = NULL;
895
896 static gchar **gtk_rc_default_files = NULL;
897
898 /* RC file handling */
899
900 static gchar *
901 gtk_rc_make_default_dir (const gchar *type)
902 {
903   const gchar *var;
904   gchar *path;
905
906   var = g_getenv ("GTK_EXE_PREFIX");
907
908   if (var)
909     path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
910   else
911     path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
912
913   return path;
914 }
915
916 /**
917  * gtk_rc_get_im_module_path:
918  *
919  * Obtains the path in which to look for IM modules. See the documentation
920  * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
921  * environment variable for more details about looking up modules. This
922  * function is useful solely for utilities supplied with GTK+ and should
923  * not be used by applications under normal circumstances.
924  *
925  * Returns: (type filename): a newly-allocated string containing the
926  *    path in which to look for IM modules.
927  *
928  * Deprecated: 3.0: Use #GtkCssProvider instead.
929  */
930 gchar *
931 gtk_rc_get_im_module_path (void)
932 {
933   gchar **paths = _gtk_get_module_path ("immodules");
934   gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
935   g_strfreev (paths);
936
937   return result;
938 }
939
940 /**
941  * gtk_rc_get_im_module_file:
942  *
943  * Obtains the path to the IM modules file. See the documentation
944  * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
945  * environment variable for more details.
946  *
947  * Returns: (type filename): a newly-allocated string containing the
948  *    name of the file listing the IM modules available for loading
949  *
950  * Deprecated: 3.0: Use #GtkCssProvider instead.
951  */
952 gchar *
953 gtk_rc_get_im_module_file (void)
954 {
955   const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
956   gchar *result = NULL;
957
958   if (var)
959     result = g_strdup (var);
960
961   if (!result)
962     {
963       if (im_module_file)
964         result = g_strdup (im_module_file);
965       else
966         result = gtk_rc_make_default_dir ("immodules.cache");
967     }
968
969   return result;
970 }
971
972 /**
973  * gtk_rc_get_theme_dir:
974  *
975  * Returns the standard directory in which themes should
976  * be installed. (GTK+ does not actually use this directory
977  * itself.)
978  *
979  * Returns: The directory (must be freed with g_free()).
980  *
981  * Deprecated: 3.0: Use #GtkCssProvider instead.
982  */
983 gchar *
984 gtk_rc_get_theme_dir (void)
985 {
986   const gchar *var;
987   gchar *path;
988
989   var = g_getenv ("GTK_DATA_PREFIX");
990
991   if (var)
992     path = g_build_filename (var, "share", "themes", NULL);
993   else
994     path = g_build_filename (_gtk_get_data_prefix (), "share", "themes", NULL);
995
996   return path;
997 }
998
999 /**
1000  * gtk_rc_get_module_dir:
1001  *
1002  * Returns a directory in which GTK+ looks for theme engines.
1003  * For full information about the search for theme engines,
1004  * see the docs for <envar>GTK_PATH</envar> in
1005  * <xref linkend="gtk-running"/>.
1006  *
1007  * return value: (type filename): the directory. (Must be freed with g_free())
1008  *
1009  * Deprecated: 3.0: Use #GtkCssProvider instead.
1010  **/
1011 gchar *
1012 gtk_rc_get_module_dir (void)
1013 {
1014   return gtk_rc_make_default_dir ("engines");
1015 }
1016
1017 /**
1018  * gtk_rc_add_default_file:
1019  * @filename: (type filename): the pathname to the file. If @filename
1020  *    is not absolute, it is searched in the current directory.
1021  *
1022  * Adds a file to the list of files to be parsed at the
1023  * end of gtk_init().
1024  *
1025  * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1026  **/
1027 void
1028 gtk_rc_add_default_file (const gchar *filename)
1029 {
1030 }
1031
1032 /**
1033  * gtk_rc_set_default_files:
1034  * @filenames: (array zero-terminated=1) (element-type filename): A
1035  *     %NULL-terminated list of filenames.
1036  *
1037  * Sets the list of files that GTK+ will read at the
1038  * end of gtk_init().
1039  *
1040  * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1041  **/
1042 void
1043 gtk_rc_set_default_files (gchar **filenames)
1044 {
1045 }
1046
1047 /**
1048  * gtk_rc_get_default_files:
1049  *
1050  * Retrieves the current list of RC files that will be parsed
1051  * at the end of gtk_init().
1052  *
1053  * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
1054  *      A %NULL-terminated array of filenames.  This memory is owned
1055  *     by GTK+ and must not be freed by the application.  If you want
1056  *     to store this information, you should make a copy.
1057  *
1058  * Deprecated:3.0: Use #GtkStyleContext instead
1059  **/
1060 gchar **
1061 gtk_rc_get_default_files (void)
1062 {
1063   return gtk_rc_default_files;
1064 }
1065
1066 /**
1067  * gtk_rc_parse_string:
1068  * @rc_string: a string to parse.
1069  *
1070  * Parses resource information directly from a string.
1071  *
1072  * Deprecated: 3.0: Use #GtkCssProvider instead.
1073  */
1074 void
1075 gtk_rc_parse_string (const gchar *rc_string)
1076 {
1077   g_return_if_fail (rc_string != NULL);
1078 }
1079
1080 /**
1081  * gtk_rc_parse:
1082  * @filename: the filename of a file to parse. If @filename is not absolute, it
1083  *  is searched in the current directory.
1084  *
1085  * Parses a given resource file.
1086  *
1087  * Deprecated: 3.0: Use #GtkCssProvider instead.
1088  */
1089 void
1090 gtk_rc_parse (const gchar *filename)
1091 {
1092   g_return_if_fail (filename != NULL);
1093 }
1094
1095 /* Handling of RC styles */
1096
1097 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
1098
1099 static void
1100 gtk_rc_style_init (GtkRcStyle *style)
1101 {
1102   GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1103   guint i;
1104
1105   style->name = NULL;
1106   style->font_desc = NULL;
1107
1108   for (i = 0; i < 5; i++)
1109     {
1110       static const GdkColor init_color = { 0, 0, 0, 0, };
1111
1112       style->bg_pixmap_name[i] = NULL;
1113       style->color_flags[i] = 0;
1114       style->fg[i] = init_color;
1115       style->bg[i] = init_color;
1116       style->text[i] = init_color;
1117       style->base[i] = init_color;
1118     }
1119   style->xthickness = -1;
1120   style->ythickness = -1;
1121   style->rc_properties = NULL;
1122
1123   style->rc_style_lists = NULL;
1124   style->icon_factories = NULL;
1125
1126   priv->color_hashes = NULL;
1127 }
1128
1129 static void
1130 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1131 {
1132   GObjectClass *object_class = G_OBJECT_CLASS (klass);
1133
1134   object_class->finalize = gtk_rc_style_finalize;
1135
1136   klass->parse = NULL;
1137   klass->create_rc_style = gtk_rc_style_real_create_rc_style;
1138   klass->merge = gtk_rc_style_real_merge;
1139   klass->create_style = gtk_rc_style_real_create_style;
1140
1141   g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
1142 }
1143
1144 static void
1145 gtk_rc_style_finalize (GObject *object)
1146 {
1147   GSList *tmp_list1, *tmp_list2;
1148   GtkRcStyle *rc_style;
1149   GtkRcStylePrivate *rc_priv;
1150   gint i;
1151
1152   rc_style = GTK_RC_STYLE (object);
1153   rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
1154
1155   g_free (rc_style->name);
1156   if (rc_style->font_desc)
1157     pango_font_description_free (rc_style->font_desc);
1158
1159   for (i = 0; i < 5; i++)
1160     g_free (rc_style->bg_pixmap_name[i]);
1161
1162   /* Now remove all references to this rc_style from
1163    * realized_style_ht
1164    */
1165   tmp_list1 = rc_style->rc_style_lists;
1166   while (tmp_list1)
1167     {
1168       GSList *rc_styles = tmp_list1->data;
1169       GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1170       g_object_unref (style);
1171
1172       /* Remove the list of styles from the other rc_styles
1173        * in the list
1174        */
1175       tmp_list2 = rc_styles;
1176       while (tmp_list2)
1177         {
1178           GtkRcStyle *other_style = tmp_list2->data;
1179
1180           if (other_style != rc_style)
1181             other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1182                                                               rc_styles);
1183           tmp_list2 = tmp_list2->next;
1184         }
1185
1186       /* And from the hash table itself
1187        */
1188       g_hash_table_remove (realized_style_ht, rc_styles);
1189       g_slist_free (rc_styles);
1190
1191       tmp_list1 = tmp_list1->next;
1192     }
1193   g_slist_free (rc_style->rc_style_lists);
1194
1195   if (rc_style->rc_properties)
1196     {
1197       guint i;
1198
1199       for (i = 0; i < rc_style->rc_properties->len; i++)
1200         {
1201           GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1202
1203           g_free (node->origin);
1204           g_value_unset (&node->value);
1205         }
1206       g_array_free (rc_style->rc_properties, TRUE);
1207       rc_style->rc_properties = NULL;
1208     }
1209
1210   g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
1211   g_slist_free (rc_style->icon_factories);
1212
1213   g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1214   g_slist_free (rc_priv->color_hashes);
1215
1216   G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
1217 }
1218
1219 /**
1220  * gtk_rc_style_new:
1221  *
1222  * Creates a new #GtkRcStyle with no fields set and
1223  * a reference count of 1.
1224  *
1225  * Returns: the newly-created #GtkRcStyle
1226  *
1227  * Deprecated: 3.0: Use #GtkCssProvider instead.
1228  */
1229 GtkRcStyle *
1230 gtk_rc_style_new (void)
1231 {
1232   GtkRcStyle *style;
1233
1234   style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1235
1236   return style;
1237 }
1238
1239 /**
1240  * gtk_rc_style_copy:
1241  * @orig: the style to copy
1242  *
1243  * Makes a copy of the specified #GtkRcStyle. This function
1244  * will correctly copy an RC style that is a member of a class
1245  * derived from #GtkRcStyle.
1246  *
1247  * Return value: (transfer full): the resulting #GtkRcStyle
1248  *
1249  * Deprecated: 3.0: Use #GtkCssProvider instead.
1250  **/
1251 GtkRcStyle *
1252 gtk_rc_style_copy (GtkRcStyle *orig)
1253 {
1254   GtkRcStyle *style;
1255
1256   g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1257   
1258   style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1259   GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1260
1261   return style;
1262 }
1263
1264 static GtkRcStyle *
1265 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1266 {
1267   return g_object_new (G_OBJECT_TYPE (style), NULL);
1268 }
1269
1270 static gint
1271 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1272                        gconstpointer bsearch_node2)
1273 {
1274   const GtkRcProperty *prop1 = bsearch_node1;
1275   const GtkRcProperty *prop2 = bsearch_node2;
1276
1277   if (prop1->type_name == prop2->type_name)
1278     return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1279   else
1280     return prop1->type_name < prop2->type_name ? -1 : 1;
1281 }
1282
1283 static void
1284 insert_rc_property (GtkRcStyle    *style,
1285                     GtkRcProperty *property,
1286                     gboolean       replace)
1287 {
1288   guint i;
1289   GtkRcProperty *new_property = NULL;
1290   GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1291
1292   key.type_name = property->type_name;
1293   key.property_name = property->property_name;
1294
1295   if (!style->rc_properties)
1296     style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1297
1298   i = 0;
1299   while (i < style->rc_properties->len)
1300     {
1301       gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1302
1303       if (cmp == 0)
1304         {
1305           if (replace)
1306             {
1307               new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1308               
1309               g_free (new_property->origin);
1310               g_value_unset (&new_property->value);
1311               
1312               *new_property = key;
1313               break;
1314             }
1315           else
1316             return;
1317         }
1318       else if (cmp < 0)
1319         break;
1320
1321       i++;
1322     }
1323
1324   if (!new_property)
1325     {
1326       g_array_insert_val (style->rc_properties, i, key);
1327       new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1328     }
1329
1330   new_property->origin = g_strdup (property->origin);
1331   g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1332   g_value_copy (&property->value, &new_property->value);
1333 }
1334
1335 static void
1336 gtk_rc_style_real_merge (GtkRcStyle *dest,
1337                          GtkRcStyle *src)
1338 {
1339   gint i;
1340
1341   for (i = 0; i < 5; i++)
1342     {
1343       if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1344         dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1345       
1346       if (!(dest->color_flags[i] & GTK_RC_FG) && 
1347           src->color_flags[i] & GTK_RC_FG)
1348         {
1349           dest->fg[i] = src->fg[i];
1350           dest->color_flags[i] |= GTK_RC_FG;
1351         }
1352       if (!(dest->color_flags[i] & GTK_RC_BG) && 
1353           src->color_flags[i] & GTK_RC_BG)
1354         {
1355           dest->bg[i] = src->bg[i];
1356           dest->color_flags[i] |= GTK_RC_BG;
1357         }
1358       if (!(dest->color_flags[i] & GTK_RC_TEXT) && 
1359           src->color_flags[i] & GTK_RC_TEXT)
1360         {
1361           dest->text[i] = src->text[i];
1362           dest->color_flags[i] |= GTK_RC_TEXT;
1363         }
1364       if (!(dest->color_flags[i] & GTK_RC_BASE) && 
1365           src->color_flags[i] & GTK_RC_BASE)
1366         {
1367           dest->base[i] = src->base[i];
1368           dest->color_flags[i] |= GTK_RC_BASE;
1369         }
1370     }
1371
1372   if (dest->xthickness < 0 && src->xthickness >= 0)
1373     dest->xthickness = src->xthickness;
1374   if (dest->ythickness < 0 && src->ythickness >= 0)
1375     dest->ythickness = src->ythickness;
1376
1377   if (src->font_desc)
1378     {
1379       if (!dest->font_desc)
1380         dest->font_desc = pango_font_description_copy (src->font_desc);
1381       else
1382         pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1383     }
1384
1385   if (src->rc_properties)
1386     {
1387       guint i;
1388
1389       for (i = 0; i < src->rc_properties->len; i++)
1390         insert_rc_property (dest,
1391                             &g_array_index (src->rc_properties, GtkRcProperty, i),
1392                             FALSE);
1393     }
1394 }
1395
1396 static GtkStyle *
1397 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1398 {
1399   return gtk_style_new ();
1400 }
1401
1402 /**
1403  * gtk_rc_reset_styles:
1404  * @settings: a #GtkSettings
1405  *
1406  * This function recomputes the styles for all widgets that use a
1407  * particular #GtkSettings object. (There is one #GtkSettings object
1408  * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1409  * when some global parameter has changed that affects the appearance
1410  * of all widgets, because when a widget gets a new style, it will
1411  * both redraw and recompute any cached information about its
1412  * appearance. As an example, it is used when the default font size
1413  * set by the operating system changes. Note that this function
1414  * doesn't affect widgets that have a style set explicitely on them
1415  * with gtk_widget_set_style().
1416  *
1417  * Since: 2.4
1418  *
1419  * Deprecated: 3.0: Use #GtkCssProvider instead.
1420  **/
1421 void
1422 gtk_rc_reset_styles (GtkSettings *settings)
1423 {
1424   gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
1425 }
1426
1427 /**
1428  * gtk_rc_reparse_all_for_settings:
1429  * @settings: a #GtkSettings
1430  * @force_load: load whether or not anything changed
1431  *
1432  * If the modification time on any previously read file
1433  * for the given #GtkSettings has changed, discard all style information
1434  * and then reread all previously read RC files.
1435  *
1436  * Return value: %TRUE if the files were reread.
1437  *
1438  * Deprecated: 3.0: Use #GtkCssProvider instead.
1439  **/
1440 gboolean
1441 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1442                                  gboolean     force_load)
1443 {
1444   return FALSE;
1445 }
1446
1447 /**
1448  * gtk_rc_reparse_all:
1449  *
1450  * If the modification time on any previously read file for the
1451  * default #GtkSettings has changed, discard all style information
1452  * and then reread all previously read RC files.
1453  *
1454  * Return value:  %TRUE if the files were reread.
1455  *
1456  * Deprecated: 3.0: Use #GtkCssProvider instead.
1457  **/
1458 gboolean
1459 gtk_rc_reparse_all (void)
1460 {
1461   return FALSE;
1462 }
1463
1464 /**
1465  * gtk_rc_get_style:
1466  * @widget: a #GtkWidget
1467  *
1468  * Finds all matching RC styles for a given widget,
1469  * composites them together, and then creates a
1470  * #GtkStyle representing the composite appearance.
1471  * (GTK+ actually keeps a cache of previously
1472  * created styles, so a new style may not be
1473  * created.)
1474  *
1475  * Returns: (transfer none): the resulting style. No refcount is added
1476  *   to the returned style, so if you want to save this style around,
1477  *   you should add a reference yourself.
1478  *
1479  * Deprecated:3.0: Use #GtkStyleContext instead
1480  **/
1481 GtkStyle *
1482 gtk_rc_get_style (GtkWidget *widget)
1483 {
1484   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1485
1486   gtk_widget_ensure_style (widget);
1487
1488   return gtk_widget_get_style (widget);
1489 }
1490
1491 /**
1492  * gtk_rc_get_style_by_paths:
1493  * @settings: a #GtkSettings object
1494  * @widget_path: (allow-none): the widget path to use when looking up the
1495  *     style, or %NULL if no matching against the widget path should be done
1496  * @class_path: (allow-none): the class path to use when looking up the style,
1497  *     or %NULL if no matching against the class path should be done.
1498  * @type: a type that will be used along with parent types of this type
1499  *     when matching against class styles, or #G_TYPE_NONE
1500  *
1501  * Creates up a #GtkStyle from styles defined in a RC file by providing
1502  * the raw components used in matching. This function may be useful
1503  * when creating pseudo-widgets that should be themed like widgets but
1504  * don't actually have corresponding GTK+ widgets. An example of this
1505  * would be items inside a GNOME canvas widget.
1506  *
1507  * The action of gtk_rc_get_style() is similar to:
1508  * |[
1509  *  gtk_widget_path (widget, NULL, &path, NULL);
1510  *  gtk_widget_class_path (widget, NULL, &class_path, NULL);
1511  *  gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
1512  *                             path, class_path,
1513  *                             G_OBJECT_TYPE (widget));
1514  * ]|
1515  *
1516  * Return value: (transfer none): A style created by matching with the
1517  *     supplied paths, or %NULL if nothing matching was specified and the
1518  *     default style should be used. The returned value is owned by GTK+
1519  *     as part of an internal cache, so you must call g_object_ref() on
1520  *     the returned value if you want to keep a reference to it.
1521  *
1522  * Deprecated:3.0: Use #GtkStyleContext instead
1523  **/
1524 GtkStyle *
1525 gtk_rc_get_style_by_paths (GtkSettings *settings,
1526                            const char  *widget_path,
1527                            const char  *class_path,
1528                            GType        type)
1529 {
1530   GtkWidgetPath *path;
1531   GtkStyle *style;
1532
1533   path = gtk_widget_path_new ();
1534
1535   /* For compatibility, we return a GtkStyle based on a GtkStyleContext
1536    * with a GtkWidgetPath appropriate for the supplied information.
1537    *
1538    * GtkWidgetPath is composed of a list of GTypes with optional names;
1539    * In GTK+-2.0, widget_path consisted of the widget names, or
1540    * the class names for unnamed widgets, while class_path had the
1541    * class names always. So, use class_path to determine the GTypes
1542    * and extract widget names from widget_path as applicable.
1543    */
1544   if (class_path == NULL)
1545     {
1546       gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
1547     }
1548   else
1549     {
1550       const gchar *widget_p, *widget_next;
1551       const gchar *class_p, *class_next;
1552
1553       widget_next = widget_path;
1554       class_next = class_path;
1555
1556       while (*class_next)
1557         {
1558           GType component_type;
1559           gchar *component_class;
1560           gchar *component_name;
1561           gint pos;
1562
1563           class_p = class_next;
1564           if (*class_p == '.')
1565             class_p++;
1566
1567           widget_p = widget_next; /* Might be NULL */
1568           if (widget_p && *widget_p == '.')
1569             widget_p++;
1570
1571           class_next = strchr (class_p, '.');
1572           if (class_next == NULL)
1573             class_next = class_p + strlen (class_p);
1574
1575           if (widget_p)
1576             {
1577               widget_next = strchr (widget_p, '.');
1578               if (widget_next == NULL)
1579                 widget_next = widget_p + strlen (widget_p);
1580             }
1581
1582           component_class = g_strndup (class_p, class_next - class_p);
1583           if (widget_p && *widget_p)
1584             component_name = g_strndup (widget_p, widget_next - widget_p);
1585           else
1586             component_name = NULL;
1587
1588           component_type = g_type_from_name (component_class);
1589           if (component_type == G_TYPE_INVALID)
1590             component_type = GTK_TYPE_WIDGET;
1591
1592           pos = gtk_widget_path_append_type (path, component_type);
1593           if (component_name != NULL && strcmp (component_name, component_name) != 0)
1594             gtk_widget_path_iter_set_name (path, pos, component_name);
1595
1596           g_free (component_class);
1597           g_free (component_name);
1598         }
1599     }
1600
1601   style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
1602                                    path);
1603
1604   gtk_widget_path_free (path);
1605
1606   return style;
1607 }
1608
1609 /**
1610  * gtk_rc_scanner_new: (skip)
1611  *
1612  * Deprecated:3.0: Use #GtkCssProvider instead
1613  */
1614 GScanner*
1615 gtk_rc_scanner_new (void)
1616 {
1617   return g_scanner_new (&gtk_rc_scanner_config);
1618 }
1619
1620 /*********************
1621  * Parsing functions *
1622  *********************/
1623
1624 static gboolean
1625 lookup_color (GtkRcStyle *style,
1626               const char *color_name,
1627               GdkColor   *color)
1628 {
1629   GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1630   GSList *iter;
1631
1632   for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
1633     {
1634       GHashTable *hash  = iter->data;
1635       GdkColor   *match = g_hash_table_lookup (hash, color_name);
1636
1637       if (match)
1638         {
1639           color->red = match->red;
1640           color->green = match->green;
1641           color->blue = match->blue;
1642           return TRUE;
1643         }
1644     }
1645
1646   return FALSE;
1647 }
1648
1649 /**
1650  * gtk_rc_find_pixmap_in_path:
1651  * @settings: a #GtkSettings
1652  * @scanner: Scanner used to get line number information for the
1653  *   warning message, or %NULL
1654  * @pixmap_file: name of the pixmap file to locate.
1655  *
1656  * Looks up a file in pixmap path for the specified #GtkSettings.
1657  * If the file is not found, it outputs a warning message using
1658  * g_warning() and returns %NULL.
1659  *
1660  * Return value: (type filename): the filename.
1661  *
1662  * Deprecated: 3.0: Use #GtkCssProvider instead.
1663  **/
1664 gchar*
1665 gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
1666                             GScanner     *scanner,
1667                             const gchar  *pixmap_file)
1668 {
1669   g_warning ("Unable to locate image file in pixmap_path: \"%s\"",
1670              pixmap_file);
1671   return NULL;
1672 }
1673
1674 /**
1675  * gtk_rc_find_module_in_path:
1676  * @module_file: name of a theme engine
1677  *
1678  * Searches for a theme engine in the GTK+ search path. This function
1679  * is not useful for applications and should not be used.
1680  *
1681  * Return value: (type filename): The filename, if found (must be
1682  *   freed with g_free()), otherwise %NULL.
1683  *
1684  * Deprecated: 3.0: Use #GtkCssProvider instead.
1685  **/
1686 gchar*
1687 gtk_rc_find_module_in_path (const gchar *module_file)
1688 {
1689   return _gtk_find_module (module_file, "engines");
1690 }
1691
1692 /**
1693  * gtk_rc_parse_state:
1694  * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1695  * @state: (out): A pointer to a #GtkStateType variable in which to
1696  *  store the result.
1697  *
1698  * Parses a #GtkStateType variable from the format expected
1699  * in a RC file.
1700  *
1701  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1702  *   that was expected but not found.
1703  *
1704  * Deprecated: 3.0: Use #GtkCssProvider instead
1705  */
1706 guint
1707 gtk_rc_parse_state (GScanner     *scanner,
1708                     GtkStateType *state)
1709 {
1710   guint old_scope;
1711   guint token;
1712
1713   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1714   g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
1715   
1716   /* we don't know where we got called from, so we reset the scope here.
1717    * if we bail out due to errors, we *don't* reset the scope, so the
1718    * error messaging code can make sense of our tokens.
1719    */
1720   old_scope = g_scanner_set_scope (scanner, 0);
1721   
1722   token = g_scanner_get_next_token (scanner);
1723   if (token != G_TOKEN_LEFT_BRACE)
1724     return G_TOKEN_LEFT_BRACE;
1725   
1726   token = g_scanner_get_next_token (scanner);
1727   switch (token)
1728     {
1729     case GTK_RC_TOKEN_ACTIVE:
1730       *state = GTK_STATE_ACTIVE;
1731       break;
1732     case GTK_RC_TOKEN_INSENSITIVE:
1733       *state = GTK_STATE_INSENSITIVE;
1734       break;
1735     case GTK_RC_TOKEN_NORMAL:
1736       *state = GTK_STATE_NORMAL;
1737       break;
1738     case GTK_RC_TOKEN_PRELIGHT:
1739       *state = GTK_STATE_PRELIGHT;
1740       break;
1741     case GTK_RC_TOKEN_SELECTED:
1742       *state = GTK_STATE_SELECTED;
1743       break;
1744     default:
1745       return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1746     }
1747   
1748   token = g_scanner_get_next_token (scanner);
1749   if (token != G_TOKEN_RIGHT_BRACE)
1750     return G_TOKEN_RIGHT_BRACE;
1751   
1752   g_scanner_set_scope (scanner, old_scope);
1753
1754   return G_TOKEN_NONE;
1755 }
1756
1757 /**
1758  * gtk_rc_parse_priority:
1759  * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1760  * @priority: A pointer to #GtkPathPriorityType variable in which
1761  *  to store the result.
1762  *
1763  * Parses a #GtkPathPriorityType variable from the format expected
1764  * in a RC file.
1765  *
1766  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1767  *   that was expected but not found.
1768  *
1769  * Deprecated:3.0: Use #GtkCssProvider instead
1770  */
1771 guint
1772 gtk_rc_parse_priority (GScanner            *scanner,
1773                        GtkPathPriorityType *priority)
1774 {
1775   guint old_scope;
1776   guint token;
1777
1778   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1779   g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1780
1781   /* we don't know where we got called from, so we reset the scope here.
1782    * if we bail out due to errors, we *don't* reset the scope, so the
1783    * error messaging code can make sense of our tokens.
1784    */
1785   old_scope = g_scanner_set_scope (scanner, 0);
1786   
1787   token = g_scanner_get_next_token (scanner);
1788   if (token != ':')
1789     return ':';
1790   
1791   token = g_scanner_get_next_token (scanner);
1792   switch (token)
1793     {
1794     case GTK_RC_TOKEN_LOWEST:
1795       *priority = GTK_PATH_PRIO_LOWEST;
1796       break;
1797     case GTK_RC_TOKEN_GTK:
1798       *priority = GTK_PATH_PRIO_GTK;
1799       break;
1800     case GTK_RC_TOKEN_APPLICATION:
1801       *priority = GTK_PATH_PRIO_APPLICATION;
1802       break;
1803     case GTK_RC_TOKEN_THEME:
1804       *priority = GTK_PATH_PRIO_THEME;
1805       break;
1806     case GTK_RC_TOKEN_RC:
1807       *priority = GTK_PATH_PRIO_RC;
1808       break;
1809     case GTK_RC_TOKEN_HIGHEST:
1810       *priority = GTK_PATH_PRIO_HIGHEST;
1811       break;
1812     default:
1813       return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1814     }
1815   
1816   g_scanner_set_scope (scanner, old_scope);
1817
1818   return G_TOKEN_NONE;
1819 }
1820
1821 /**
1822  * gtk_rc_parse_color:
1823  * @scanner: a #GScanner
1824  * @color: (out): a pointer to a #GdkColor structure in which to store
1825  *     the result
1826  *
1827  * Parses a color in the <link linkend="color=format">format</link> expected
1828  * in a RC file.
1829  *
1830  * Note that theme engines should use gtk_rc_parse_color_full() in
1831  * order to support symbolic colors.
1832  *
1833  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1834  *     that was expected but not found
1835  *
1836  * Deprecated:3.0: Use #GtkCssProvider instead
1837  */
1838 guint
1839 gtk_rc_parse_color (GScanner *scanner,
1840                     GdkColor *color)
1841 {
1842   return gtk_rc_parse_color_full (scanner, NULL, color);
1843 }
1844
1845 /**
1846  * gtk_rc_parse_color_full:
1847  * @scanner: a #GScanner
1848  * @style: (allow-none): a #GtkRcStyle, or %NULL
1849  * @color: (out): a pointer to a #GdkColor structure in which to store
1850  *     the result
1851  *
1852  * Parses a color in the <link linkend="color=format">format</link> expected
1853  * in a RC file. If @style is not %NULL, it will be consulted to resolve
1854  * references to symbolic colors.
1855  *
1856  * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1857  *     that was expected but not found
1858  *
1859  * Since: 2.12
1860  *
1861  * Deprecated:3.0: Use #GtkCssProvider instead
1862  */
1863 guint
1864 gtk_rc_parse_color_full (GScanner   *scanner,
1865                          GtkRcStyle *style,
1866                          GdkColor   *color)
1867 {
1868   guint token;
1869
1870   g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1871
1872   /* we don't need to set our own scope here, because
1873    * we don't need own symbols
1874    */
1875   
1876   token = g_scanner_get_next_token (scanner);
1877   switch (token)
1878     {
1879       gint token_int;
1880       GdkColor c1, c2;
1881       gboolean negate;
1882       gdouble l;
1883
1884     case G_TOKEN_LEFT_CURLY:
1885       token = g_scanner_get_next_token (scanner);
1886       if (token == G_TOKEN_INT)
1887         token_int = scanner->value.v_int;
1888       else if (token == G_TOKEN_FLOAT)
1889         token_int = scanner->value.v_float * 65535.0;
1890       else
1891         return G_TOKEN_FLOAT;
1892       color->red = CLAMP (token_int, 0, 65535);
1893       
1894       token = g_scanner_get_next_token (scanner);
1895       if (token != G_TOKEN_COMMA)
1896         return G_TOKEN_COMMA;
1897       
1898       token = g_scanner_get_next_token (scanner);
1899       if (token == G_TOKEN_INT)
1900         token_int = scanner->value.v_int;
1901       else if (token == G_TOKEN_FLOAT)
1902         token_int = scanner->value.v_float * 65535.0;
1903       else
1904         return G_TOKEN_FLOAT;
1905       color->green = CLAMP (token_int, 0, 65535);
1906       
1907       token = g_scanner_get_next_token (scanner);
1908       if (token != G_TOKEN_COMMA)
1909         return G_TOKEN_COMMA;
1910       
1911       token = g_scanner_get_next_token (scanner);
1912       if (token == G_TOKEN_INT)
1913         token_int = scanner->value.v_int;
1914       else if (token == G_TOKEN_FLOAT)
1915         token_int = scanner->value.v_float * 65535.0;
1916       else
1917         return G_TOKEN_FLOAT;
1918       color->blue = CLAMP (token_int, 0, 65535);
1919       
1920       token = g_scanner_get_next_token (scanner);
1921       if (token != G_TOKEN_RIGHT_CURLY)
1922         return G_TOKEN_RIGHT_CURLY;
1923       return G_TOKEN_NONE;
1924       
1925     case G_TOKEN_STRING:
1926       if (!gdk_color_parse (scanner->value.v_string, color))
1927         {
1928           g_scanner_warn (scanner, "Invalid color constant '%s'",
1929                           scanner->value.v_string);
1930           return G_TOKEN_STRING;
1931         }
1932       return G_TOKEN_NONE;
1933
1934     case '@':
1935       token = g_scanner_get_next_token (scanner);
1936       if (token != G_TOKEN_IDENTIFIER)
1937         return G_TOKEN_IDENTIFIER;
1938
1939       if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1940         {
1941           g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1942                           scanner->value.v_identifier);
1943           return G_TOKEN_IDENTIFIER;
1944         }
1945
1946       return G_TOKEN_NONE;
1947
1948     case G_TOKEN_IDENTIFIER:
1949       if (strcmp (scanner->value.v_identifier, "mix") == 0)
1950         {
1951           token = g_scanner_get_next_token (scanner);
1952           if (token != G_TOKEN_LEFT_PAREN)
1953             return G_TOKEN_LEFT_PAREN;
1954
1955           negate = FALSE;
1956           if (g_scanner_peek_next_token (scanner) == '-')
1957             {
1958               g_scanner_get_next_token (scanner); /* eat sign */
1959               negate = TRUE;
1960             }
1961
1962           token = g_scanner_get_next_token (scanner);
1963           if (token != G_TOKEN_FLOAT)
1964             return G_TOKEN_FLOAT;
1965
1966           l = negate ? -scanner->value.v_float : scanner->value.v_float;
1967
1968           token = g_scanner_get_next_token (scanner);
1969           if (token != G_TOKEN_COMMA)
1970             return G_TOKEN_COMMA;
1971
1972           token = gtk_rc_parse_color_full (scanner, style, &c1);
1973           if (token != G_TOKEN_NONE)
1974             return token;
1975
1976           token = g_scanner_get_next_token (scanner);
1977           if (token != G_TOKEN_COMMA)
1978             return G_TOKEN_COMMA;
1979
1980           token = gtk_rc_parse_color_full (scanner, style, &c2);
1981           if (token != G_TOKEN_NONE)
1982             return token;
1983
1984           token = g_scanner_get_next_token (scanner);
1985           if (token != G_TOKEN_RIGHT_PAREN)
1986             return G_TOKEN_RIGHT_PAREN;
1987
1988           color->red   = l * c1.red   + (1.0 - l) * c2.red;
1989           color->green = l * c1.green + (1.0 - l) * c2.green;
1990           color->blue  = l * c1.blue  + (1.0 - l) * c2.blue;
1991
1992           return G_TOKEN_NONE;
1993         }
1994       else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1995         {
1996           token = g_scanner_get_next_token (scanner);
1997           if (token != G_TOKEN_LEFT_PAREN)
1998             return G_TOKEN_LEFT_PAREN;
1999
2000           negate = FALSE;
2001           if (g_scanner_peek_next_token (scanner) == '-')
2002             {
2003               g_scanner_get_next_token (scanner); /* eat sign */
2004               negate = TRUE;
2005             }
2006
2007           token = g_scanner_get_next_token (scanner);
2008           if (token != G_TOKEN_FLOAT)
2009             return G_TOKEN_FLOAT;
2010
2011           l = negate ? -scanner->value.v_float : scanner->value.v_float;
2012
2013           token = g_scanner_get_next_token (scanner);
2014           if (token != G_TOKEN_COMMA)
2015             return G_TOKEN_COMMA;
2016
2017           token = gtk_rc_parse_color_full (scanner, style, &c1);
2018           if (token != G_TOKEN_NONE)
2019             return token;
2020
2021           token = g_scanner_get_next_token (scanner);
2022           if (token != G_TOKEN_RIGHT_PAREN)
2023             return G_TOKEN_RIGHT_PAREN;
2024
2025           _gtk_style_shade (&c1, color, l);
2026
2027           return G_TOKEN_NONE;
2028         }
2029       else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
2030                strcmp (scanner->value.v_identifier, "darker") == 0)
2031         {
2032           if (scanner->value.v_identifier[0] == 'l')
2033             l = 1.3;
2034           else
2035             l = 0.7;
2036
2037           token = g_scanner_get_next_token (scanner);
2038           if (token != G_TOKEN_LEFT_PAREN)
2039             return G_TOKEN_LEFT_PAREN;
2040
2041           token = gtk_rc_parse_color_full (scanner, style, &c1);
2042           if (token != G_TOKEN_NONE)
2043             return token;
2044
2045           token = g_scanner_get_next_token (scanner);
2046           if (token != G_TOKEN_RIGHT_PAREN)
2047             return G_TOKEN_RIGHT_PAREN;
2048
2049           _gtk_style_shade (&c1, color, l);
2050
2051           return G_TOKEN_NONE;
2052         }
2053       else
2054         return G_TOKEN_IDENTIFIER;
2055
2056     default:
2057       return G_TOKEN_STRING;
2058     }
2059 }