1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
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/.
32 #ifdef HAVE_SYS_PARAM_H
33 #include <sys/param.h>
40 #define GDK_DISABLE_DEPRECATION_WARNINGS
43 #include <glib/gstdio.h>
46 #include "gtkversion.h"
49 #include "gtkbindings.h"
51 #include "gtkiconfactory.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"
67 * @Short_description: Deprecated routines for handling resource files
68 * @Title: Resource Files
70 * GTK+ provides resource file mechanism for configuring
71 * various aspects of the operation of a GTK+ program
75 * In GTK+ 3.0, resource files have been deprecated and replaced
76 * by CSS-like style sheets, which are understood by #GtkCssProvider.
80 * <title>Default files</title>
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><SYSCONFDIR>/gtk-2.0/gtkrc</filename>
87 * and <filename>.gtkrc-3.0</filename> in the users home directory.
88 * (<filename><SYSCONFDIR></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
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>
110 * <title>Pathnames and patterns</title>
111 * <anchor id="gtkrc-pathnames-and-patterns"/>
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:
119 * <informalexample><programlisting>
120 * widget "mywindow.*.GtkEntry" style "my-entry-class"
121 * </programlisting></informalexample>
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>.
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
141 * Since GTK+ 2.10, <literal>widget_class</literal> paths can also contain
142 * <literal><classname></literal> substrings, which are matching
143 * the class with the given name and any derived classes. For instance,
144 * <informalexample><programlisting>
145 * widget_class "*<GtkMenuItem>.GtkLabel" style "my-style"
146 * </programlisting></informalexample>
147 * will match #GtkLabel widgets which are contained in any kind of menu item.
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>.
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.
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):
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>
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.
185 * <title>Theme gtkrc files</title>
186 * <anchor id="theme-gtkrc-files"/>
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>.
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.
199 * <title>Optimizing RC Style Matches</title>
200 * <anchor id="optimizing-rc-style-matches"/>
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
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.
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>
237 * Use of wildcards should be avoided, this can reduce the individual RC style
238 * match to a single integer comparison in most cases.
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>.
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
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.
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.
267 * <title>Toplevel declarations</title>
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
274 * The possible toplevel declarations are:
278 * <term><literal>binding <replaceable>name</replaceable>
279 * { ... }</literal></term>
281 * <para>Declares a binding set.</para>
285 * <term><literal>class <replaceable>pattern</replaceable>
286 * [ style | binding ][ : <replaceable>priority</replaceable> ]
287 * <replaceable>name</replaceable></literal></term>
289 * <para>Specifies a style or binding set for a particular
290 * branch of the inheritance hierarchy.</para>
294 * <term><literal>include <replaceable>filename</replaceable></literal></term>
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>
305 * <term><literal>module_path <replaceable>path</replaceable></literal></term>
307 * <para>Sets a path (a list of directories separated
308 * by colons) that will be searched for theme engines referenced in
313 * <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
315 * <para>Sets a path (a list of directories separated
316 * by colons) that will be searched for pixmaps referenced in
321 * <term><literal>im_module_file <replaceable>pathname</replaceable></literal></term>
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>
329 * <term><literal>style <replaceable>name</replaceable> [ =
330 * <replaceable>parent</replaceable> ] { ... }</literal></term>
332 * <para>Declares a style.</para>
336 * <term><literal>widget <replaceable>pattern</replaceable>
337 * [ style | binding ][ : <replaceable>priority</replaceable> ]
338 * <replaceable>name</replaceable></literal></term>
340 * <para>Specifies a style or binding set for a particular
341 * group of widgets by matching on the widget pathname.</para>
345 * <term><literal>widget_class <replaceable>pattern</replaceable>
346 * [ style | binding ][ : <replaceable>priority</replaceable> ]
347 * <replaceable>name</replaceable></literal></term>
349 * <para>Specifies a style or binding set for a particular
350 * group of widgets by matching on the class pathname.</para>
354 * <term><replaceable>setting</replaceable> = <replaceable>value</replaceable></term>
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>
365 * <title>Styles</title>
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
378 * Within a <literal>style</literal> declaration, the possible
383 * <term><literal>bg[<replaceable>state</replaceable>] =
384 * <replaceable>color</replaceable></literal></term>
386 * Sets the color used for the background of most widgets.
390 * <term><literal>fg[<replaceable>state</replaceable>] =
391 * <replaceable>color</replaceable></literal></term>
393 * Sets the color used for the foreground of most widgets.
397 * <term><literal>base[<replaceable>state</replaceable>] =
398 * <replaceable>color</replaceable></literal></term>
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.
406 * <term><literal>text[<replaceable>state</replaceable>] =
407 * <replaceable>color</replaceable></literal></term>
409 * Sets the color used for foreground of widgets using
410 * <literal>base</literal> for the background color.
414 * <term><literal>xthickness =
415 * <replaceable>number</replaceable></literal></term>
417 * Sets the xthickness, which is used for various horizontal padding
422 * <term><literal>ythickness =
423 * <replaceable>number</replaceable></literal></term>
425 * Sets the ythickness, which is used for various vertical padding
430 * <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
431 * <replaceable>pixmap</replaceable></literal></term>
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>"<parent>"</literal> may be used to indicate that the widget should
437 * use the same background pixmap as its parent. The special value
438 * <literal>"<none>"</literal> may be used to indicate no background pixmap.
442 * <term><literal>font = <replaceable>font</replaceable></literal></term>
444 * Starting with GTK+ 2.0, the "font" and "fontset"
445 * declarations are ignored; use "font_name" declarations instead.
449 * <term><literal>fontset = <replaceable>font</replaceable></literal></term>
451 * Starting with GTK+ 2.0, the "font" and "fontset"
452 * declarations are ignored; use "font_name" declarations instead.
456 * <term><literal>font_name = <replaceable>font</replaceable></literal></term>
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().
465 * <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
467 * Defines the icon for a stock item.
471 * <term><literal>color[<replaceable>"color-name"</replaceable>] = <replaceable>color specification</replaceable></literal></term>
473 * Since 2.10, this element can be used to defines symbolic colors. See below for
474 * the syntax of color specifications.
478 * <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
479 * settings</replaceable> }</literal></term>
481 * Defines the engine to be used when drawing with this style.
485 * <term><literal><replaceable>class</replaceable>::<replaceable>property</replaceable> = <replaceable>value</replaceable></literal></term>
487 * Sets a <link linkend="style-properties">style property</link> for a widget class.
492 * The colors and background pixmaps are specified as a function of the
493 * state of the widget. The states are:
497 * <term><literal>NORMAL</literal></term>
499 * A color used for a widget in its normal state.
503 * <term><literal>ACTIVE</literal></term>
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.
514 * <term><literal>PRELIGHT</literal></term>
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
523 * <term><literal>SELECTED</literal></term>
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.
531 * <term><literal>INSENSITIVE</literal></term>
533 * A color used for the background of widgets that have
534 * been set insensitive with gtk_widget_set_sensitive().
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.
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:
557 * <term>mix (<replaceable>factor</replaceable>, <replaceable>color1</replaceable>, <replaceable>color2</replaceable>)</term>
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>.
567 * <term>shade (<replaceable>factor</replaceable>, <replaceable>color</replaceable>)</term>
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.
575 * <term>lighter (<replaceable>color</replaceable>)</term>
577 * This is an abbreviation for
578 * <literal>shade (1.3, <replaceable>color</replaceable>)</literal>.
582 * <term>darker (<replaceable>color</replaceable>)</term>
584 * This is an abbreviation for
585 * <literal>shade (0.7, <replaceable>color</replaceable>)</literal>.
590 * Here are some examples of color expressions:
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>
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:
610 * <informalexample><programlisting>
611 * stock["my-stock-item"] =
613 * { "itemltr.png", LTR, *, * },
614 * { "itemrtl.png", RTL, *, * }
616 * </programlisting></informalexample>
618 * This could be abbreviated as follows:
620 * <informalexample><programlisting>
621 * stock["my-stock-item"] =
623 * { "itemltr.png", LTR },
624 * { "itemrtl.png", RTL }
626 * </programlisting></informalexample>
628 * You can specify custom icons for specific sizes, as follows:
630 * <informalexample><programlisting>
631 * stock["my-stock-item"] =
633 * { "itemmenusize.png", *, *, "gtk-menu" },
634 * { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
635 * { "itemgeneric.png" } // implicit *, *, * as a fallback
637 * </programlisting></informalexample>
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.
644 * It's also possible to use custom icons for a given state, for example:
646 * <informalexample><programlisting>
647 * stock["my-stock-item"] =
649 * { "itemprelight.png", *, PRELIGHT },
650 * { "iteminsensitive.png", *, INSENSITIVE },
651 * { "itemgeneric.png" } // implicit *, *, * as a fallback
653 * </programlisting></informalexample>
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.
664 * <title>Key bindings</title>
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:
670 * <informalexample><programlisting>
671 * binding <replaceable>name</replaceable> {
672 * bind <replaceable>key</replaceable> {
673 * <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
678 * </programlisting></informalexample>
680 * <replaceable>key</replaceable> is a string consisting of a
681 * series of modifiers followed by the name of a key. The
684 * <member><literal><alt></literal></member>
685 * <member><literal><ctl></literal></member>
686 * <member><literal><control></literal></member>
687 * <member><literal><meta></literal></member>
688 * <member><literal><hyper></literal></member>
689 * <member><literal><super></literal></member>
690 * <member><literal><mod1></literal></member>
691 * <member><literal><mod2></literal></member>
692 * <member><literal><mod3></literal></member>
693 * <member><literal><mod4></literal></member>
694 * <member><literal><mod5></literal></member>
695 * <member><literal><release></literal></member>
696 * <member><literal><shft></literal></member>
697 * <member><literal><shift></literal></member>
699 * <literal><shft></literal> is an alias for
700 * <literal><shift></literal>,
701 * <literal><ctl></literal> is an alias for
702 * <literal><control></literal>,
704 * <literal><alt></literal> is an alias for
705 * <literal><mod1></literal>.
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.
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.
744 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
746 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
748 struct _GtkRcStylePrivate
750 GSList *color_hashes;
753 static void gtk_rc_style_finalize (GObject *object);
754 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
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);
761 static void insert_rc_property (GtkRcStyle *style,
762 GtkRcProperty *property,
766 static const GScannerConfig gtk_rc_scanner_config =
770 ) /* cset_skip_characters */,
775 ) /* cset_identifier_first */,
781 ) /* cset_identifier_nth */,
782 ( "#\n" ) /* cpair_comment_single */,
784 TRUE /* case_sensitive */,
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 */,
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 */,
808 static const gchar symbol_names[] =
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 }
891 static GHashTable *realized_style_ht = NULL;
893 static gchar *im_module_file = NULL;
895 static gchar **gtk_rc_default_files = NULL;
897 /* RC file handling */
900 gtk_rc_make_default_dir (const gchar *type)
905 var = g_getenv ("GTK_EXE_PREFIX");
908 path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
910 path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
916 * gtk_rc_get_im_module_path:
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.
924 * Returns: (type filename): a newly-allocated string containing the
925 * path in which to look for IM modules.
927 * Deprecated: 3.0: Use #GtkCssProvider instead.
930 gtk_rc_get_im_module_path (void)
932 gchar **paths = _gtk_get_module_path ("immodules");
933 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
940 * gtk_rc_get_im_module_file:
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.
946 * Returns: (type filename): a newly-allocated string containing the
947 * name of the file listing the IM modules available for loading
949 * Deprecated: 3.0: Use #GtkCssProvider instead.
952 gtk_rc_get_im_module_file (void)
954 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
955 gchar *result = NULL;
958 result = g_strdup (var);
963 result = g_strdup (im_module_file);
965 result = gtk_rc_make_default_dir ("immodules.cache");
972 * gtk_rc_get_theme_dir:
974 * Returns the standard directory in which themes should
975 * be installed. (GTK+ does not actually use this directory
978 * Returns: The directory (must be freed with g_free()).
980 * Deprecated: 3.0: Use #GtkCssProvider instead.
983 gtk_rc_get_theme_dir (void)
988 var = g_getenv ("GTK_DATA_PREFIX");
991 path = g_build_filename (var, "share", "themes", NULL);
993 path = g_build_filename (_gtk_get_data_prefix (), "share", "themes", NULL);
999 * gtk_rc_get_module_dir:
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"/>.
1006 * return value: (type filename): the directory. (Must be freed with g_free())
1008 * Deprecated: 3.0: Use #GtkCssProvider instead.
1011 gtk_rc_get_module_dir (void)
1013 return gtk_rc_make_default_dir ("engines");
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.
1021 * Adds a file to the list of files to be parsed at the
1022 * end of gtk_init().
1024 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1027 gtk_rc_add_default_file (const gchar *filename)
1032 * gtk_rc_set_default_files:
1033 * @filenames: (array zero-terminated=1) (element-type filename): A
1034 * %NULL-terminated list of filenames.
1036 * Sets the list of files that GTK+ will read at the
1037 * end of gtk_init().
1039 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1042 gtk_rc_set_default_files (gchar **filenames)
1047 * gtk_rc_get_default_files:
1049 * Retrieves the current list of RC files that will be parsed
1050 * at the end of gtk_init().
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.
1057 * Deprecated:3.0: Use #GtkStyleContext instead
1060 gtk_rc_get_default_files (void)
1062 return gtk_rc_default_files;
1066 * gtk_rc_parse_string:
1067 * @rc_string: a string to parse.
1069 * Parses resource information directly from a string.
1071 * Deprecated: 3.0: Use #GtkCssProvider instead.
1074 gtk_rc_parse_string (const gchar *rc_string)
1076 g_return_if_fail (rc_string != NULL);
1081 * @filename: the filename of a file to parse. If @filename is not absolute, it
1082 * is searched in the current directory.
1084 * Parses a given resource file.
1086 * Deprecated: 3.0: Use #GtkCssProvider instead.
1089 gtk_rc_parse (const gchar *filename)
1091 g_return_if_fail (filename != NULL);
1094 /* Handling of RC styles */
1096 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
1099 gtk_rc_style_init (GtkRcStyle *style)
1101 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1105 style->font_desc = NULL;
1107 for (i = 0; i < 5; i++)
1109 static const GdkColor init_color = { 0, 0, 0, 0, };
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;
1118 style->xthickness = -1;
1119 style->ythickness = -1;
1120 style->rc_properties = NULL;
1122 style->rc_style_lists = NULL;
1123 style->icon_factories = NULL;
1125 priv->color_hashes = NULL;
1129 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1131 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1133 object_class->finalize = gtk_rc_style_finalize;
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;
1140 g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
1144 gtk_rc_style_finalize (GObject *object)
1146 GSList *tmp_list1, *tmp_list2;
1147 GtkRcStyle *rc_style;
1148 GtkRcStylePrivate *rc_priv;
1151 rc_style = GTK_RC_STYLE (object);
1152 rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
1154 g_free (rc_style->name);
1155 if (rc_style->font_desc)
1156 pango_font_description_free (rc_style->font_desc);
1158 for (i = 0; i < 5; i++)
1159 g_free (rc_style->bg_pixmap_name[i]);
1161 /* Now remove all references to this rc_style from
1164 tmp_list1 = rc_style->rc_style_lists;
1167 GSList *rc_styles = tmp_list1->data;
1168 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1169 g_object_unref (style);
1171 /* Remove the list of styles from the other rc_styles
1174 tmp_list2 = rc_styles;
1177 GtkRcStyle *other_style = tmp_list2->data;
1179 if (other_style != rc_style)
1180 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1182 tmp_list2 = tmp_list2->next;
1185 /* And from the hash table itself
1187 g_hash_table_remove (realized_style_ht, rc_styles);
1188 g_slist_free (rc_styles);
1190 tmp_list1 = tmp_list1->next;
1192 g_slist_free (rc_style->rc_style_lists);
1194 if (rc_style->rc_properties)
1198 for (i = 0; i < rc_style->rc_properties->len; i++)
1200 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1202 g_free (node->origin);
1203 g_value_unset (&node->value);
1205 g_array_free (rc_style->rc_properties, TRUE);
1206 rc_style->rc_properties = NULL;
1209 g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
1210 g_slist_free (rc_style->icon_factories);
1212 g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1213 g_slist_free (rc_priv->color_hashes);
1215 G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
1221 * Creates a new #GtkRcStyle with no fields set and
1222 * a reference count of 1.
1224 * Returns: the newly-created #GtkRcStyle
1226 * Deprecated: 3.0: Use #GtkCssProvider instead.
1229 gtk_rc_style_new (void)
1233 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1239 * gtk_rc_style_copy:
1240 * @orig: the style to copy
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.
1246 * Return value: (transfer full): the resulting #GtkRcStyle
1248 * Deprecated: 3.0: Use #GtkCssProvider instead.
1251 gtk_rc_style_copy (GtkRcStyle *orig)
1255 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1257 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1258 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1264 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1266 return g_object_new (G_OBJECT_TYPE (style), NULL);
1270 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1271 gconstpointer bsearch_node2)
1273 const GtkRcProperty *prop1 = bsearch_node1;
1274 const GtkRcProperty *prop2 = bsearch_node2;
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;
1279 return prop1->type_name < prop2->type_name ? -1 : 1;
1283 insert_rc_property (GtkRcStyle *style,
1284 GtkRcProperty *property,
1288 GtkRcProperty *new_property = NULL;
1289 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1291 key.type_name = property->type_name;
1292 key.property_name = property->property_name;
1294 if (!style->rc_properties)
1295 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1298 while (i < style->rc_properties->len)
1300 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1306 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1308 g_free (new_property->origin);
1309 g_value_unset (&new_property->value);
1311 *new_property = key;
1325 g_array_insert_val (style->rc_properties, i, key);
1326 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
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);
1335 gtk_rc_style_real_merge (GtkRcStyle *dest,
1340 for (i = 0; i < 5; i++)
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]);
1345 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1346 src->color_flags[i] & GTK_RC_FG)
1348 dest->fg[i] = src->fg[i];
1349 dest->color_flags[i] |= GTK_RC_FG;
1351 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1352 src->color_flags[i] & GTK_RC_BG)
1354 dest->bg[i] = src->bg[i];
1355 dest->color_flags[i] |= GTK_RC_BG;
1357 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1358 src->color_flags[i] & GTK_RC_TEXT)
1360 dest->text[i] = src->text[i];
1361 dest->color_flags[i] |= GTK_RC_TEXT;
1363 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1364 src->color_flags[i] & GTK_RC_BASE)
1366 dest->base[i] = src->base[i];
1367 dest->color_flags[i] |= GTK_RC_BASE;
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;
1378 if (!dest->font_desc)
1379 dest->font_desc = pango_font_description_copy (src->font_desc);
1381 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1384 if (src->rc_properties)
1388 for (i = 0; i < src->rc_properties->len; i++)
1389 insert_rc_property (dest,
1390 &g_array_index (src->rc_properties, GtkRcProperty, i),
1396 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1398 return gtk_style_new ();
1402 * gtk_rc_reset_styles:
1403 * @settings: a #GtkSettings
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().
1418 * Deprecated: 3.0: Use #GtkCssProvider instead.
1421 gtk_rc_reset_styles (GtkSettings *settings)
1423 gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
1427 * gtk_rc_reparse_all_for_settings:
1428 * @settings: a #GtkSettings
1429 * @force_load: load whether or not anything changed
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.
1435 * Return value: %TRUE if the files were reread.
1437 * Deprecated: 3.0: Use #GtkCssProvider instead.
1440 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1441 gboolean force_load)
1447 * gtk_rc_reparse_all:
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.
1453 * Return value: %TRUE if the files were reread.
1455 * Deprecated: 3.0: Use #GtkCssProvider instead.
1458 gtk_rc_reparse_all (void)
1465 * @widget: a #GtkWidget
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
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.
1478 * Deprecated:3.0: Use #GtkStyleContext instead
1481 gtk_rc_get_style (GtkWidget *widget)
1483 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1485 gtk_widget_ensure_style (widget);
1487 return gtk_widget_get_style (widget);
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
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.
1506 * The action of gtk_rc_get_style() is similar to:
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),
1512 * G_OBJECT_TYPE (widget));
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.
1521 * Deprecated:3.0: Use #GtkStyleContext instead
1524 gtk_rc_get_style_by_paths (GtkSettings *settings,
1525 const char *widget_path,
1526 const char *class_path,
1529 GtkWidgetPath *path;
1532 path = gtk_widget_path_new ();
1534 /* For compatibility, we return a GtkStyle based on a GtkStyleContext
1535 * with a GtkWidgetPath appropriate for the supplied information.
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.
1543 if (class_path == NULL)
1545 gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
1549 const gchar *widget_p, *widget_next;
1550 const gchar *class_p, *class_next;
1552 widget_next = widget_path;
1553 class_next = class_path;
1557 GType component_type;
1558 gchar *component_class;
1559 gchar *component_name;
1562 class_p = class_next;
1563 if (*class_p == '.')
1566 widget_p = widget_next; /* Might be NULL */
1567 if (widget_p && *widget_p == '.')
1570 class_next = strchr (class_p, '.');
1571 if (class_next == NULL)
1572 class_next = class_p + strlen (class_p);
1576 widget_next = strchr (widget_p, '.');
1577 if (widget_next == NULL)
1578 widget_next = widget_p + strlen (widget_p);
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);
1585 component_name = NULL;
1587 component_type = g_type_from_name (component_class);
1588 if (component_type == G_TYPE_INVALID)
1589 component_type = GTK_TYPE_WIDGET;
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);
1595 g_free (component_class);
1596 g_free (component_name);
1600 style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
1603 gtk_widget_path_free (path);
1609 * gtk_rc_scanner_new: (skip)
1611 * Deprecated:3.0: Use #GtkCssProvider instead
1614 gtk_rc_scanner_new (void)
1616 return g_scanner_new (>k_rc_scanner_config);
1619 /*********************
1620 * Parsing functions *
1621 *********************/
1624 lookup_color (GtkRcStyle *style,
1625 const char *color_name,
1628 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1631 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
1633 GHashTable *hash = iter->data;
1634 GdkColor *match = g_hash_table_lookup (hash, color_name);
1638 color->red = match->red;
1639 color->green = match->green;
1640 color->blue = match->blue;
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.
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.
1659 * Return value: (type filename): the filename.
1661 * Deprecated: 3.0: Use #GtkCssProvider instead.
1664 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
1666 const gchar *pixmap_file)
1668 g_warning ("Unable to locate image file in pixmap_path: \"%s\"",
1674 * gtk_rc_find_module_in_path:
1675 * @module_file: name of a theme engine
1677 * Searches for a theme engine in the GTK+ search path. This function
1678 * is not useful for applications and should not be used.
1680 * Return value: (type filename): The filename, if found (must be
1681 * freed with g_free()), otherwise %NULL.
1683 * Deprecated: 3.0: Use #GtkCssProvider instead.
1686 gtk_rc_find_module_in_path (const gchar *module_file)
1688 return _gtk_find_module (module_file, "engines");
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
1697 * Parses a #GtkStateType variable from the format expected
1700 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1701 * that was expected but not found.
1703 * Deprecated: 3.0: Use #GtkCssProvider instead
1706 gtk_rc_parse_state (GScanner *scanner,
1707 GtkStateType *state)
1712 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1713 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
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.
1719 old_scope = g_scanner_set_scope (scanner, 0);
1721 token = g_scanner_get_next_token (scanner);
1722 if (token != G_TOKEN_LEFT_BRACE)
1723 return G_TOKEN_LEFT_BRACE;
1725 token = g_scanner_get_next_token (scanner);
1728 case GTK_RC_TOKEN_ACTIVE:
1729 *state = GTK_STATE_ACTIVE;
1731 case GTK_RC_TOKEN_INSENSITIVE:
1732 *state = GTK_STATE_INSENSITIVE;
1734 case GTK_RC_TOKEN_NORMAL:
1735 *state = GTK_STATE_NORMAL;
1737 case GTK_RC_TOKEN_PRELIGHT:
1738 *state = GTK_STATE_PRELIGHT;
1740 case GTK_RC_TOKEN_SELECTED:
1741 *state = GTK_STATE_SELECTED;
1744 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1747 token = g_scanner_get_next_token (scanner);
1748 if (token != G_TOKEN_RIGHT_BRACE)
1749 return G_TOKEN_RIGHT_BRACE;
1751 g_scanner_set_scope (scanner, old_scope);
1753 return G_TOKEN_NONE;
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.
1762 * Parses a #GtkPathPriorityType variable from the format expected
1765 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1766 * that was expected but not found.
1768 * Deprecated:3.0: Use #GtkCssProvider instead
1771 gtk_rc_parse_priority (GScanner *scanner,
1772 GtkPathPriorityType *priority)
1777 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1778 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
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.
1784 old_scope = g_scanner_set_scope (scanner, 0);
1786 token = g_scanner_get_next_token (scanner);
1790 token = g_scanner_get_next_token (scanner);
1793 case GTK_RC_TOKEN_LOWEST:
1794 *priority = GTK_PATH_PRIO_LOWEST;
1796 case GTK_RC_TOKEN_GTK:
1797 *priority = GTK_PATH_PRIO_GTK;
1799 case GTK_RC_TOKEN_APPLICATION:
1800 *priority = GTK_PATH_PRIO_APPLICATION;
1802 case GTK_RC_TOKEN_THEME:
1803 *priority = GTK_PATH_PRIO_THEME;
1805 case GTK_RC_TOKEN_RC:
1806 *priority = GTK_PATH_PRIO_RC;
1808 case GTK_RC_TOKEN_HIGHEST:
1809 *priority = GTK_PATH_PRIO_HIGHEST;
1812 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1815 g_scanner_set_scope (scanner, old_scope);
1817 return G_TOKEN_NONE;
1821 * gtk_rc_parse_color:
1822 * @scanner: a #GScanner
1823 * @color: (out): a pointer to a #GdkColor structure in which to store
1826 * Parses a color in the <link linkend="color=format">format</link> expected
1829 * Note that theme engines should use gtk_rc_parse_color_full() in
1830 * order to support symbolic colors.
1832 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1833 * that was expected but not found
1835 * Deprecated:3.0: Use #GtkCssProvider instead
1838 gtk_rc_parse_color (GScanner *scanner,
1841 return gtk_rc_parse_color_full (scanner, NULL, color);
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
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.
1855 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1856 * that was expected but not found
1860 * Deprecated:3.0: Use #GtkCssProvider instead
1863 gtk_rc_parse_color_full (GScanner *scanner,
1869 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1871 /* we don't need to set our own scope here, because
1872 * we don't need own symbols
1875 token = g_scanner_get_next_token (scanner);
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;
1890 return G_TOKEN_FLOAT;
1891 color->red = CLAMP (token_int, 0, 65535);
1893 token = g_scanner_get_next_token (scanner);
1894 if (token != G_TOKEN_COMMA)
1895 return G_TOKEN_COMMA;
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;
1903 return G_TOKEN_FLOAT;
1904 color->green = CLAMP (token_int, 0, 65535);
1906 token = g_scanner_get_next_token (scanner);
1907 if (token != G_TOKEN_COMMA)
1908 return G_TOKEN_COMMA;
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;
1916 return G_TOKEN_FLOAT;
1917 color->blue = CLAMP (token_int, 0, 65535);
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;
1924 case G_TOKEN_STRING:
1925 if (!gdk_color_parse (scanner->value.v_string, color))
1927 g_scanner_warn (scanner, "Invalid color constant '%s'",
1928 scanner->value.v_string);
1929 return G_TOKEN_STRING;
1931 return G_TOKEN_NONE;
1934 token = g_scanner_get_next_token (scanner);
1935 if (token != G_TOKEN_IDENTIFIER)
1936 return G_TOKEN_IDENTIFIER;
1938 if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1940 g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1941 scanner->value.v_identifier);
1942 return G_TOKEN_IDENTIFIER;
1945 return G_TOKEN_NONE;
1947 case G_TOKEN_IDENTIFIER:
1948 if (strcmp (scanner->value.v_identifier, "mix") == 0)
1950 token = g_scanner_get_next_token (scanner);
1951 if (token != G_TOKEN_LEFT_PAREN)
1952 return G_TOKEN_LEFT_PAREN;
1955 if (g_scanner_peek_next_token (scanner) == '-')
1957 g_scanner_get_next_token (scanner); /* eat sign */
1961 token = g_scanner_get_next_token (scanner);
1962 if (token != G_TOKEN_FLOAT)
1963 return G_TOKEN_FLOAT;
1965 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1967 token = g_scanner_get_next_token (scanner);
1968 if (token != G_TOKEN_COMMA)
1969 return G_TOKEN_COMMA;
1971 token = gtk_rc_parse_color_full (scanner, style, &c1);
1972 if (token != G_TOKEN_NONE)
1975 token = g_scanner_get_next_token (scanner);
1976 if (token != G_TOKEN_COMMA)
1977 return G_TOKEN_COMMA;
1979 token = gtk_rc_parse_color_full (scanner, style, &c2);
1980 if (token != G_TOKEN_NONE)
1983 token = g_scanner_get_next_token (scanner);
1984 if (token != G_TOKEN_RIGHT_PAREN)
1985 return G_TOKEN_RIGHT_PAREN;
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;
1991 return G_TOKEN_NONE;
1993 else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1995 token = g_scanner_get_next_token (scanner);
1996 if (token != G_TOKEN_LEFT_PAREN)
1997 return G_TOKEN_LEFT_PAREN;
2000 if (g_scanner_peek_next_token (scanner) == '-')
2002 g_scanner_get_next_token (scanner); /* eat sign */
2006 token = g_scanner_get_next_token (scanner);
2007 if (token != G_TOKEN_FLOAT)
2008 return G_TOKEN_FLOAT;
2010 l = negate ? -scanner->value.v_float : scanner->value.v_float;
2012 token = g_scanner_get_next_token (scanner);
2013 if (token != G_TOKEN_COMMA)
2014 return G_TOKEN_COMMA;
2016 token = gtk_rc_parse_color_full (scanner, style, &c1);
2017 if (token != G_TOKEN_NONE)
2020 token = g_scanner_get_next_token (scanner);
2021 if (token != G_TOKEN_RIGHT_PAREN)
2022 return G_TOKEN_RIGHT_PAREN;
2024 _gtk_style_shade (&c1, color, l);
2026 return G_TOKEN_NONE;
2028 else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
2029 strcmp (scanner->value.v_identifier, "darker") == 0)
2031 if (scanner->value.v_identifier[0] == 'l')
2036 token = g_scanner_get_next_token (scanner);
2037 if (token != G_TOKEN_LEFT_PAREN)
2038 return G_TOKEN_LEFT_PAREN;
2040 token = gtk_rc_parse_color_full (scanner, style, &c1);
2041 if (token != G_TOKEN_NONE)
2044 token = g_scanner_get_next_token (scanner);
2045 if (token != G_TOKEN_RIGHT_PAREN)
2046 return G_TOKEN_RIGHT_PAREN;
2048 _gtk_style_shade (&c1, color, l);
2050 return G_TOKEN_NONE;
2053 return G_TOKEN_IDENTIFIER;
2056 return G_TOKEN_STRING;