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