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