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 "gtkwindow.h"
66 * @Short_description: Deprecated routines for handling resource files
67 * @Title: Resource Files
69 * GTK+ provides resource file mechanism for configuring
70 * various aspects of the operation of a GTK+ program
74 * In GTK+ 3.0, resource files have been deprecated and replaced
75 * by CSS-like style sheets, which are understood by #GtkCssProvider.
79 * <title>Default files</title>
81 * An application can cause GTK+ to parse a specific RC
82 * file by calling gtk_rc_parse(). In addition to this,
83 * certain files will be read at the end of gtk_init().
84 * Unless modified, the files looked for will be
85 * <filename><SYSCONFDIR>/gtk-2.0/gtkrc</filename>
86 * and <filename>.gtkrc-3.0</filename> in the users home directory.
87 * (<filename><SYSCONFDIR></filename> defaults to
88 * <filename>/usr/local/etc</filename>. It can be changed with the
89 * <option>--prefix</option> or <option>--sysconfdir</option> options when
92 * The set of these <firstterm>default</firstterm> files
93 * can be retrieved with gtk_rc_get_default_files()
94 * and modified with gtk_rc_add_default_file() and
95 * gtk_rc_set_default_files().
96 * Additionally, the <envar>GTK2_RC_FILES</envar> environment variable
97 * can be set to a #G_SEARCHPATH_SEPARATOR_S-separated list of files
98 * in order to overwrite the set of default files at runtime.
99 * <para><anchor id="locale-specific-rc"/>
100 * For each RC file, in addition to the file itself, GTK+ will look for
101 * a locale-specific file that will be parsed after the main file.
102 * For instance, if <envar>LANG</envar> is set to <literal>ja_JP.ujis</literal>,
103 * when loading the default file <filename>~/.gtkrc</filename> then GTK+ looks
104 * for <filename>~/.gtkrc.ja_JP</filename> and <filename>~/.gtkrc.ja</filename>,
105 * and parses the first of those that exists.</para>
109 * <title>Pathnames and patterns</title>
110 * <anchor id="gtkrc-pathnames-and-patterns"/>
112 * A resource file defines a number of styles and key bindings and
113 * attaches them to particular widgets. The attachment is done
114 * by the <literal>widget</literal>, <literal>widget_class</literal>,
115 * and <literal>class</literal> declarations. As an example
116 * of such a statement:
118 * <informalexample><programlisting>
119 * widget "mywindow.*.GtkEntry" style "my-entry-class"
120 * </programlisting></informalexample>
122 * attaches the style <literal>"my-entry-class"</literal> to all
123 * widgets whose <firstterm>widget path</firstterm> matches the
124 * <firstterm>pattern</firstterm> <literal>"mywindow.*.GtkEntry"</literal>.
125 * That is, all #GtkEntry widgets which are part of a #GtkWindow named
126 * <literal>"mywindow"</literal>.
128 * The patterns here are given in the standard shell glob syntax.
129 * The <literal>"?"</literal> wildcard matches any character, while
130 * <literal>"*"</literal> matches zero or more of any character.
131 * The three types of matching are against the widget path, the
132 * <firstterm>class path</firstterm> and the class hierarchy. Both the
133 * widget path and the class path consist of a <literal>"."</literal>
134 * separated list of all the parents of the widget and the widget itself
135 * from outermost to innermost. The difference is that in the widget path,
136 * the name assigned by gtk_widget_set_name() is used if present, otherwise
137 * the class name of the widget, while for the class path, the class name is
140 * Since GTK+ 2.10, <literal>widget_class</literal> paths can also contain
141 * <literal><classname></literal> substrings, which are matching
142 * the class with the given name and any derived classes. For instance,
143 * <informalexample><programlisting>
144 * widget_class "*<GtkMenuItem>.GtkLabel" style "my-style"
145 * </programlisting></informalexample>
146 * will match #GtkLabel widgets which are contained in any kind of menu item.
148 * So, if you have a #GtkEntry named <literal>"myentry"</literal>, inside of a
149 * horizontal box in a window named <literal>"mywindow"</literal>, then the
150 * widget path is: <literal>"mywindow.GtkHBox.myentry"</literal>
151 * while the class path is: <literal>"GtkWindow.GtkHBox.GtkEntry"</literal>.
153 * Matching against class is a little different. The pattern match is done
154 * against all class names in the widgets class hierarchy (not the layout
155 * hierarchy) in sequence, so the pattern:
156 * <informalexample><programlisting>
157 * class "GtkButton" style "my-style"
158 * </programlisting></informalexample>
159 * will match not just #GtkButton widgets, but also #GtkToggleButton and
160 * #GtkCheckButton widgets, since those classes derive from #GtkButton.
162 * Additionally, a priority can be specified for each pattern, and styles
163 * override other styles first by priority, then by pattern type and then
164 * by order of specification (later overrides earlier). The priorities
165 * that can be specified are (highest to lowest):
167 * <member><literal>highest</literal></member>
168 * <member><literal>rc</literal></member>
169 * <member><literal>theme</literal></member>
170 * <member><literal>application</literal></member>
171 * <member><literal>gtk</literal></member>
172 * <member><literal>lowest</literal></member>
174 * <literal>rc</literal> is the default for styles
175 * read from an RC file, <literal>theme</literal>
176 * is the default for styles read from theme RC files,
177 * <literal>application</literal>
178 * should be used for styles an application sets
179 * up, and <literal>gtk</literal> is used for styles
180 * that GTK+ creates internally.
184 * <title>Theme gtkrc files</title>
185 * <anchor id="theme-gtkrc-files"/>
187 * Theme RC files are loaded first from under the <filename>~/.themes/</filename>,
188 * then from the directory from gtk_rc_get_theme_dir(). The files looked at will
189 * be <filename>gtk-3.0/gtkrc</filename>.
191 * When the application prefers dark themes
192 * (see the #GtkSettings:gtk-application-prefer-dark-theme property for details),
193 * <filename>gtk-3.0/gtkrc-dark</filename> will be loaded first, and if not present
194 * <filename>gtk-3.0/gtkrc</filename> will be loaded.
198 * <title>Optimizing RC Style Matches</title>
199 * <anchor id="optimizing-rc-style-matches"/>
201 * Everytime a widget is created and added to the layout hierarchy of a #GtkWindow
202 * ("anchored" to be exact), a list of matching RC styles out of all RC styles read
203 * in so far is composed.
204 * For this, every RC style is matched against the widgets class path,
205 * the widgets name path and widgets inheritance hierarchy.
206 * As a consequence, significant slowdown can be caused by utilization of many
207 * RC styles and by using RC style patterns that are slow or complicated to match
208 * against a given widget.
209 * The following ordered list provides a number of advices (prioritized by
210 * effectiveness) to reduce the performance overhead associated with RC style
215 * Move RC styles for specific applications into RC files dedicated to those
216 * applications and parse application specific RC files only from
217 * applications that are affected by them.
218 * This reduces the overall amount of RC styles that have to be considered
219 * for a match across a group of applications.
222 * Merge multiple styles which use the same matching rule, for instance:
223 * <informalexample><programlisting>
224 * style "Foo" { foo_content }
225 * class "X" style "Foo"
226 * style "Bar" { bar_content }
227 * class "X" style "Bar"
228 * </programlisting></informalexample>
229 * is faster to match as:
230 * <informalexample><programlisting>
231 * style "FooBar" { foo_content bar_content }
232 * class "X" style "FooBar"
233 * </programlisting></informalexample>
236 * Use of wildcards should be avoided, this can reduce the individual RC style
237 * match to a single integer comparison in most cases.
240 * To avoid complex recursive matching, specification of full class names
241 * (for <literal>class</literal> matches) or full path names (for
242 * <literal>widget</literal> and <literal>widget_class</literal> matches)
243 * is to be preferred over shortened names
244 * containing <literal>"*"</literal> or <literal>"?"</literal>.
247 * If at all necessary, wildcards should only be used at the tail or head
248 * of a pattern. This reduces the match complexity to a string comparison
252 * When using wildcards, use of <literal>"?"</literal> should be preferred
253 * over <literal>"*"</literal>. This can reduce the matching complexity from
254 * O(n^2) to O(n). For example <literal>"Gtk*Box"</literal> can be turned into
255 * <literal>"Gtk?Box"</literal> and will still match #GtkHBox and #GtkVBox.
258 * The use of <literal>"*"</literal> wildcards should be restricted as much
259 * as possible, because matching <literal>"A*B*C*RestString"</literal> can
260 * result in matching complexities of O(n^2) worst case.
266 * <title>Toplevel declarations</title>
268 * An RC file is a text file which is composed of a sequence
269 * of declarations. <literal>'#'</literal> characters delimit comments and
270 * the portion of a line after a <literal>'#'</literal> is ignored when parsing
273 * The possible toplevel declarations are:
277 * <term><literal>binding <replaceable>name</replaceable>
278 * { ... }</literal></term>
280 * <para>Declares a binding set.</para>
284 * <term><literal>class <replaceable>pattern</replaceable>
285 * [ style | binding ][ : <replaceable>priority</replaceable> ]
286 * <replaceable>name</replaceable></literal></term>
288 * <para>Specifies a style or binding set for a particular
289 * branch of the inheritance hierarchy.</para>
293 * <term><literal>include <replaceable>filename</replaceable></literal></term>
295 * <para>Parses another file at this point. If
296 * <replaceable>filename</replaceable> is not an absolute filename,
297 * it is searched in the directories of the currently open RC files.</para>
298 * <para>GTK+ also tries to load a
299 * <link linkend="locale-specific-rc">locale-specific variant</link> of
300 * the included file.</para>
304 * <term><literal>module_path <replaceable>path</replaceable></literal></term>
306 * <para>Sets a path (a list of directories separated
307 * by colons) that will be searched for theme engines referenced in
312 * <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
314 * <para>Sets a path (a list of directories separated
315 * by colons) that will be searched for pixmaps referenced in
320 * <term><literal>im_module_file <replaceable>pathname</replaceable></literal></term>
322 * <para>Sets the pathname for the IM modules file. Setting this from RC files
323 * is deprecated; you should use the environment variable <envar>GTK_IM_MODULE_FILE</envar>
328 * <term><literal>style <replaceable>name</replaceable> [ =
329 * <replaceable>parent</replaceable> ] { ... }</literal></term>
331 * <para>Declares a style.</para>
335 * <term><literal>widget <replaceable>pattern</replaceable>
336 * [ style | binding ][ : <replaceable>priority</replaceable> ]
337 * <replaceable>name</replaceable></literal></term>
339 * <para>Specifies a style or binding set for a particular
340 * group of widgets by matching on the widget pathname.</para>
344 * <term><literal>widget_class <replaceable>pattern</replaceable>
345 * [ style | binding ][ : <replaceable>priority</replaceable> ]
346 * <replaceable>name</replaceable></literal></term>
348 * <para>Specifies a style or binding set for a particular
349 * group of widgets by matching on the class pathname.</para>
353 * <term><replaceable>setting</replaceable> = <replaceable>value</replaceable></term>
355 * <para>Specifies a value for a <link linkend="GtkSettings">setting</link>.
356 * Note that settings in RC files are overwritten by system-wide settings
357 * (which are managed by an XSettings manager on X11).</para>
364 * <title>Styles</title>
366 * A RC style is specified by a <literal>style</literal>
367 * declaration in a RC file, and then bound to widgets
368 * with a <literal>widget</literal>, <literal>widget_class</literal>,
369 * or <literal>class</literal> declaration. All styles
370 * applying to a particular widget are composited together
371 * with <literal>widget</literal> declarations overriding
372 * <literal>widget_class</literal> declarations which, in
373 * turn, override <literal>class</literal> declarations.
374 * Within each type of declaration, later declarations override
377 * Within a <literal>style</literal> declaration, the possible
382 * <term><literal>bg[<replaceable>state</replaceable>] =
383 * <replaceable>color</replaceable></literal></term>
385 * Sets the color used for the background of most widgets.
389 * <term><literal>fg[<replaceable>state</replaceable>] =
390 * <replaceable>color</replaceable></literal></term>
392 * Sets the color used for the foreground of most widgets.
396 * <term><literal>base[<replaceable>state</replaceable>] =
397 * <replaceable>color</replaceable></literal></term>
399 * Sets the color used for the background of widgets displaying
400 * editable text. This color is used for the background
401 * of, among others, #GtkText, #GtkEntry, #GtkList, and #GtkCList.
405 * <term><literal>text[<replaceable>state</replaceable>] =
406 * <replaceable>color</replaceable></literal></term>
408 * Sets the color used for foreground of widgets using
409 * <literal>base</literal> for the background color.
413 * <term><literal>xthickness =
414 * <replaceable>number</replaceable></literal></term>
416 * Sets the xthickness, which is used for various horizontal padding
421 * <term><literal>ythickness =
422 * <replaceable>number</replaceable></literal></term>
424 * Sets the ythickness, which is used for various vertical padding
429 * <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
430 * <replaceable>pixmap</replaceable></literal></term>
432 * Sets a background pixmap to be used in place of
433 * the <literal>bg</literal> color (or for #GtkText,
434 * in place of the <literal>base</literal> color. The special
435 * value <literal>"<parent>"</literal> may be used to indicate that the widget should
436 * use the same background pixmap as its parent. The special value
437 * <literal>"<none>"</literal> may be used to indicate no background pixmap.
441 * <term><literal>font = <replaceable>font</replaceable></literal></term>
443 * Starting with GTK+ 2.0, the "font" and "fontset"
444 * declarations are ignored; use "font_name" declarations instead.
448 * <term><literal>fontset = <replaceable>font</replaceable></literal></term>
450 * Starting with GTK+ 2.0, the "font" and "fontset"
451 * declarations are ignored; use "font_name" declarations instead.
455 * <term><literal>font_name = <replaceable>font</replaceable></literal></term>
457 * Sets the font for a widget. <replaceable>font</replaceable> must be
458 * a Pango font name, e.g. <literal>"Sans Italic 10"</literal>.
459 * For details about Pango font names, see
460 * pango_font_description_from_string().
464 * <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
466 * Defines the icon for a stock item.
470 * <term><literal>color[<replaceable>"color-name"</replaceable>] = <replaceable>color specification</replaceable></literal></term>
472 * Since 2.10, this element can be used to defines symbolic colors. See below for
473 * the syntax of color specifications.
477 * <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
478 * settings</replaceable> }</literal></term>
480 * Defines the engine to be used when drawing with this style.
484 * <term><literal><replaceable>class</replaceable>::<replaceable>property</replaceable> = <replaceable>value</replaceable></literal></term>
486 * Sets a <link linkend="style-properties">style property</link> for a widget class.
491 * The colors and background pixmaps are specified as a function of the
492 * state of the widget. The states are:
496 * <term><literal>NORMAL</literal></term>
498 * A color used for a widget in its normal state.
502 * <term><literal>ACTIVE</literal></term>
504 * A variant of the <literal>NORMAL</literal> color used when the
505 * widget is in the %GTK_STATE_ACTIVE state, and also for
506 * the trough of a ScrollBar, tabs of a NoteBook
507 * other than the current tab and similar areas.
508 * Frequently, this should be a darker variant
509 * of the <literal>NORMAL</literal> color.
513 * <term><literal>PRELIGHT</literal></term>
515 * A color used for widgets in the %GTK_STATE_PRELIGHT state. This
516 * state is the used for Buttons and MenuItems
517 * that have the mouse cursor over them, and for
522 * <term><literal>SELECTED</literal></term>
524 * A color used to highlight data selected by the user.
525 * for instance, the selected items in a list widget, and the
526 * selection in an editable widget.
530 * <term><literal>INSENSITIVE</literal></term>
532 * A color used for the background of widgets that have
533 * been set insensitive with gtk_widget_set_sensitive().
538 * <anchor id="color-format"/>
539 * Colors can be specified as a string containing a color name (GTK+ knows
540 * all names from the X color database <filename>/usr/lib/X11/rgb.txt</filename>),
541 * in one of the hexadecimal forms <literal>#rrrrggggbbbb</literal>,
542 * <literal>#rrrgggbbb</literal>, <literal>#rrggbb</literal>,
543 * or <literal>#rgb</literal>, where <literal>r</literal>,
544 * <literal>g</literal> and <literal>b</literal> are
545 * hex digits, or they can be specified as a triplet
546 * <literal>{ <replaceable>r</replaceable>, <replaceable>g</replaceable>,
547 * <replaceable>b</replaceable>}</literal>, where <literal>r</literal>,
548 * <literal>g</literal> and <literal>b</literal> are either integers in
549 * the range 0-65535 or floats in the range 0.0-1.0.
551 * Since 2.10, colors can also be specified by refering to a symbolic color, as
552 * follows: <literal>@<!-- -->color-name</literal>, or by using expressions to combine
553 * colors. The following expressions are currently supported:
556 * <term>mix (<replaceable>factor</replaceable>, <replaceable>color1</replaceable>, <replaceable>color2</replaceable>)</term>
558 * Computes a new color by mixing <replaceable>color1</replaceable> and
559 * <replaceable>color2</replaceable>. The <replaceable>factor</replaceable>
560 * determines how close the new color is to <replaceable>color1</replaceable>.
561 * A factor of 1.0 gives pure <replaceable>color1</replaceable>, a factor of
562 * 0.0 gives pure <replaceable>color2</replaceable>.
566 * <term>shade (<replaceable>factor</replaceable>, <replaceable>color</replaceable>)</term>
568 * Computes a lighter or darker variant of <replaceable>color</replaceable>.
569 * A <replaceable>factor</replaceable> of 1.0 leaves the color unchanged, smaller
570 * factors yield darker colors, larger factors yield lighter colors.
574 * <term>lighter (<replaceable>color</replaceable>)</term>
576 * This is an abbreviation for
577 * <literal>shade (1.3, <replaceable>color</replaceable>)</literal>.
581 * <term>darker (<replaceable>color</replaceable>)</term>
583 * This is an abbreviation for
584 * <literal>shade (0.7, <replaceable>color</replaceable>)</literal>.
589 * Here are some examples of color expressions:
591 * <informalexample><programlisting>
592 * mix (0.5, "red", "blue")
593 * shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 }))
594 * lighter (@<!-- -->foreground)
595 * </programlisting></informalexample>
597 * In a <literal>stock</literal> definition, icon sources are specified as a
598 * 4-tuple of image filename or icon name, text direction, widget state, and size, in that
599 * order. Each icon source specifies an image filename or icon name to use with a given
600 * direction, state, and size. Filenames are specified as a string such
601 * as <literal>"itemltr.png"</literal>, while icon names (looked up
602 * in the current icon theme), are specified with a leading
603 * <literal>@</literal>, such as <literal>@"item-ltr"</literal>.
604 * The <literal>*</literal> character can be used as a
605 * wildcard, and if direction/state/size are omitted they default to
606 * <literal>*</literal>. So for example, the following specifies different icons to
607 * use for left-to-right and right-to-left languages:
609 * <informalexample><programlisting>
610 * stock["my-stock-item"] =
612 * { "itemltr.png", LTR, *, * },
613 * { "itemrtl.png", RTL, *, * }
615 * </programlisting></informalexample>
617 * This could be abbreviated as follows:
619 * <informalexample><programlisting>
620 * stock["my-stock-item"] =
622 * { "itemltr.png", LTR },
623 * { "itemrtl.png", RTL }
625 * </programlisting></informalexample>
627 * You can specify custom icons for specific sizes, as follows:
629 * <informalexample><programlisting>
630 * stock["my-stock-item"] =
632 * { "itemmenusize.png", *, *, "gtk-menu" },
633 * { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
634 * { "itemgeneric.png" } // implicit *, *, * as a fallback
636 * </programlisting></informalexample>
638 * The sizes that come with GTK+ itself are <literal>"gtk-menu"</literal>,
639 * <literal>"gtk-small-toolbar"</literal>, <literal>"gtk-large-toolbar"</literal>,
640 * <literal>"gtk-button"</literal>, <literal>"gtk-dialog"</literal>. Applications
641 * can define other sizes.
643 * It's also possible to use custom icons for a given state, for example:
645 * <informalexample><programlisting>
646 * stock["my-stock-item"] =
648 * { "itemprelight.png", *, PRELIGHT },
649 * { "iteminsensitive.png", *, INSENSITIVE },
650 * { "itemgeneric.png" } // implicit *, *, * as a fallback
652 * </programlisting></informalexample>
654 * When selecting an icon source to use, GTK+ will consider text direction most
655 * important, state second, and size third. It will select the best match based on
656 * those criteria. If an attribute matches exactly (e.g. you specified
657 * <literal>PRELIGHT</literal> or specified the size), GTK+ won't modify the image;
658 * if the attribute matches with a wildcard, GTK+ will scale or modify the image to
659 * match the state and size the user requested.
663 * <title>Key bindings</title>
665 * Key bindings allow the user to specify actions to be
666 * taken on particular key presses. The form of a binding
667 * set declaration is:
669 * <informalexample><programlisting>
670 * binding <replaceable>name</replaceable> {
671 * bind <replaceable>key</replaceable> {
672 * <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
677 * </programlisting></informalexample>
679 * <replaceable>key</replaceable> is a string consisting of a
680 * series of modifiers followed by the name of a key. The
683 * <member><literal><alt></literal></member>
684 * <member><literal><ctl></literal></member>
685 * <member><literal><control></literal></member>
686 * <member><literal><meta></literal></member>
687 * <member><literal><hyper></literal></member>
688 * <member><literal><super></literal></member>
689 * <member><literal><mod1></literal></member>
690 * <member><literal><mod2></literal></member>
691 * <member><literal><mod3></literal></member>
692 * <member><literal><mod4></literal></member>
693 * <member><literal><mod5></literal></member>
694 * <member><literal><release></literal></member>
695 * <member><literal><shft></literal></member>
696 * <member><literal><shift></literal></member>
698 * <literal><shft></literal> is an alias for
699 * <literal><shift></literal>,
700 * <literal><ctl></literal> is an alias for
701 * <literal><control></literal>,
703 * <literal><alt></literal> is an alias for
704 * <literal><mod1></literal>.
706 * The action that is bound to the key is a sequence
707 * of signal names (strings) followed by parameters for
708 * each signal. The signals must be action signals.
709 * (See g_signal_new()). Each parameter can be
710 * a float, integer, string, or unquoted string
711 * representing an enumeration value. The types of
712 * the parameters specified must match the types of the
713 * parameters of the signal.
715 * Binding sets are connected to widgets in the same manner as styles,
716 * with one difference: Binding sets override other binding sets first
717 * by pattern type, then by priority and then by order of specification.
718 * The priorities that can be specified and their default values are the
719 * same as for styles.
743 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
745 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
747 struct _GtkRcStylePrivate
749 GSList *color_hashes;
752 static void gtk_rc_style_finalize (GObject *object);
753 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
755 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
756 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
757 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
758 gconstpointer bsearch_node2);
760 static void insert_rc_property (GtkRcStyle *style,
761 GtkRcProperty *property,
765 static const GScannerConfig gtk_rc_scanner_config =
769 ) /* cset_skip_characters */,
774 ) /* cset_identifier_first */,
780 ) /* cset_identifier_nth */,
781 ( "#\n" ) /* cpair_comment_single */,
783 TRUE /* case_sensitive */,
785 TRUE /* skip_comment_multi */,
786 TRUE /* skip_comment_single */,
787 TRUE /* scan_comment_multi */,
788 TRUE /* scan_identifier */,
789 FALSE /* scan_identifier_1char */,
790 FALSE /* scan_identifier_NULL */,
791 TRUE /* scan_symbols */,
792 TRUE /* scan_binary */,
793 TRUE /* scan_octal */,
794 TRUE /* scan_float */,
796 TRUE /* scan_hex_dollar */,
797 TRUE /* scan_string_sq */,
798 TRUE /* scan_string_dq */,
799 TRUE /* numbers_2_int */,
800 FALSE /* int_2_float */,
801 FALSE /* identifier_2_string */,
802 TRUE /* char_2_token */,
803 TRUE /* symbol_2_token */,
804 FALSE /* scope_0_fallback */,
807 static const gchar symbol_names[] =
851 { 0, GTK_RC_TOKEN_INCLUDE },
852 { 8, GTK_RC_TOKEN_NORMAL },
853 { 15, GTK_RC_TOKEN_ACTIVE },
854 { 22, GTK_RC_TOKEN_PRELIGHT },
855 { 31, GTK_RC_TOKEN_SELECTED },
856 { 40, GTK_RC_TOKEN_INSENSITIVE },
857 { 52, GTK_RC_TOKEN_FG },
858 { 55, GTK_RC_TOKEN_BG },
859 { 58, GTK_RC_TOKEN_TEXT },
860 { 63, GTK_RC_TOKEN_BASE },
861 { 68, GTK_RC_TOKEN_XTHICKNESS },
862 { 79, GTK_RC_TOKEN_YTHICKNESS },
863 { 90, GTK_RC_TOKEN_FONT },
864 { 95, GTK_RC_TOKEN_FONTSET },
865 { 103, GTK_RC_TOKEN_FONT_NAME },
866 { 113, GTK_RC_TOKEN_BG_PIXMAP },
867 { 123, GTK_RC_TOKEN_PIXMAP_PATH },
868 { 135, GTK_RC_TOKEN_STYLE },
869 { 141, GTK_RC_TOKEN_BINDING },
870 { 149, GTK_RC_TOKEN_BIND },
871 { 154, GTK_RC_TOKEN_WIDGET },
872 { 161, GTK_RC_TOKEN_WIDGET_CLASS },
873 { 174, GTK_RC_TOKEN_CLASS },
874 { 180, GTK_RC_TOKEN_LOWEST },
875 { 187, GTK_RC_TOKEN_GTK },
876 { 191, GTK_RC_TOKEN_APPLICATION },
877 { 203, GTK_RC_TOKEN_THEME },
878 { 209, GTK_RC_TOKEN_RC },
879 { 212, GTK_RC_TOKEN_HIGHEST },
880 { 220, GTK_RC_TOKEN_ENGINE },
881 { 227, GTK_RC_TOKEN_MODULE_PATH },
882 { 239, GTK_RC_TOKEN_STOCK },
883 { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
884 { 260, GTK_RC_TOKEN_LTR },
885 { 264, GTK_RC_TOKEN_RTL },
886 { 268, GTK_RC_TOKEN_COLOR },
887 { 274, GTK_RC_TOKEN_UNBIND }
890 static GHashTable *realized_style_ht = NULL;
892 static gchar *im_module_file = NULL;
894 static gchar **gtk_rc_default_files = NULL;
896 /* RC file handling */
899 gtk_rc_make_default_dir (const gchar *type)
904 var = g_getenv ("GTK_EXE_PREFIX");
907 path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
909 path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
915 * gtk_rc_get_im_module_path:
917 * Obtains the path in which to look for IM modules. See the documentation
918 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
919 * environment variable for more details about looking up modules. This
920 * function is useful solely for utilities supplied with GTK+ and should
921 * not be used by applications under normal circumstances.
923 * Returns: (type filename): a newly-allocated string containing the
924 * path in which to look for IM modules.
926 * Deprecated: 3.0: Use #GtkCssProvider instead.
929 gtk_rc_get_im_module_path (void)
931 gchar **paths = _gtk_get_module_path ("immodules");
932 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
939 * gtk_rc_get_im_module_file:
941 * Obtains the path to the IM modules file. See the documentation
942 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
943 * environment variable for more details.
945 * Returns: (type filename): a newly-allocated string containing the
946 * name of the file listing the IM modules available for loading
948 * Deprecated: 3.0: Use #GtkCssProvider instead.
951 gtk_rc_get_im_module_file (void)
953 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
954 gchar *result = NULL;
957 result = g_strdup (var);
962 result = g_strdup (im_module_file);
964 result = gtk_rc_make_default_dir ("immodules.cache");
971 * gtk_rc_get_theme_dir:
973 * Returns the standard directory in which themes should
974 * be installed. (GTK+ does not actually use this directory
977 * Returns: The directory (must be freed with g_free()).
979 * Deprecated: 3.0: Use #GtkCssProvider instead.
982 gtk_rc_get_theme_dir (void)
987 var = g_getenv ("GTK_DATA_PREFIX");
990 path = g_build_filename (var, "share", "themes", NULL);
992 path = g_build_filename (_gtk_get_data_prefix (), "share", "themes", NULL);
998 * gtk_rc_get_module_dir:
1000 * Returns a directory in which GTK+ looks for theme engines.
1001 * For full information about the search for theme engines,
1002 * see the docs for <envar>GTK_PATH</envar> in
1003 * <xref linkend="gtk-running"/>.
1005 * return value: (type filename): the directory. (Must be freed with g_free())
1007 * Deprecated: 3.0: Use #GtkCssProvider instead.
1010 gtk_rc_get_module_dir (void)
1012 return gtk_rc_make_default_dir ("engines");
1016 * gtk_rc_add_default_file:
1017 * @filename: (type filename): the pathname to the file. If @filename
1018 * is not absolute, it is searched in the current directory.
1020 * Adds a file to the list of files to be parsed at the
1021 * end of gtk_init().
1023 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1026 gtk_rc_add_default_file (const gchar *filename)
1031 * gtk_rc_set_default_files:
1032 * @filenames: (array zero-terminated=1) (element-type filename): A
1033 * %NULL-terminated list of filenames.
1035 * Sets the list of files that GTK+ will read at the
1036 * end of gtk_init().
1038 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1041 gtk_rc_set_default_files (gchar **filenames)
1046 * gtk_rc_get_default_files:
1048 * Retrieves the current list of RC files that will be parsed
1049 * at the end of gtk_init().
1051 * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
1052 * A %NULL-terminated array of filenames. This memory is owned
1053 * by GTK+ and must not be freed by the application. If you want
1054 * to store this information, you should make a copy.
1056 * Deprecated:3.0: Use #GtkStyleContext instead
1059 gtk_rc_get_default_files (void)
1061 return gtk_rc_default_files;
1065 * gtk_rc_parse_string:
1066 * @rc_string: a string to parse.
1068 * Parses resource information directly from a string.
1070 * Deprecated: 3.0: Use #GtkCssProvider instead.
1073 gtk_rc_parse_string (const gchar *rc_string)
1075 g_return_if_fail (rc_string != NULL);
1080 * @filename: the filename of a file to parse. If @filename is not absolute, it
1081 * is searched in the current directory.
1083 * Parses a given resource file.
1085 * Deprecated: 3.0: Use #GtkCssProvider instead.
1088 gtk_rc_parse (const gchar *filename)
1090 g_return_if_fail (filename != NULL);
1093 /* Handling of RC styles */
1095 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
1098 gtk_rc_style_init (GtkRcStyle *style)
1100 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1104 style->font_desc = NULL;
1106 for (i = 0; i < 5; i++)
1108 static const GdkColor init_color = { 0, 0, 0, 0, };
1110 style->bg_pixmap_name[i] = NULL;
1111 style->color_flags[i] = 0;
1112 style->fg[i] = init_color;
1113 style->bg[i] = init_color;
1114 style->text[i] = init_color;
1115 style->base[i] = init_color;
1117 style->xthickness = -1;
1118 style->ythickness = -1;
1119 style->rc_properties = NULL;
1121 style->rc_style_lists = NULL;
1122 style->icon_factories = NULL;
1124 priv->color_hashes = NULL;
1128 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1130 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1132 object_class->finalize = gtk_rc_style_finalize;
1134 klass->parse = NULL;
1135 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
1136 klass->merge = gtk_rc_style_real_merge;
1137 klass->create_style = gtk_rc_style_real_create_style;
1139 g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
1143 gtk_rc_style_finalize (GObject *object)
1145 GSList *tmp_list1, *tmp_list2;
1146 GtkRcStyle *rc_style;
1147 GtkRcStylePrivate *rc_priv;
1150 rc_style = GTK_RC_STYLE (object);
1151 rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
1153 g_free (rc_style->name);
1154 if (rc_style->font_desc)
1155 pango_font_description_free (rc_style->font_desc);
1157 for (i = 0; i < 5; i++)
1158 g_free (rc_style->bg_pixmap_name[i]);
1160 /* Now remove all references to this rc_style from
1163 tmp_list1 = rc_style->rc_style_lists;
1166 GSList *rc_styles = tmp_list1->data;
1167 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1168 g_object_unref (style);
1170 /* Remove the list of styles from the other rc_styles
1173 tmp_list2 = rc_styles;
1176 GtkRcStyle *other_style = tmp_list2->data;
1178 if (other_style != rc_style)
1179 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1181 tmp_list2 = tmp_list2->next;
1184 /* And from the hash table itself
1186 g_hash_table_remove (realized_style_ht, rc_styles);
1187 g_slist_free (rc_styles);
1189 tmp_list1 = tmp_list1->next;
1191 g_slist_free (rc_style->rc_style_lists);
1193 if (rc_style->rc_properties)
1197 for (i = 0; i < rc_style->rc_properties->len; i++)
1199 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1201 g_free (node->origin);
1202 g_value_unset (&node->value);
1204 g_array_free (rc_style->rc_properties, TRUE);
1205 rc_style->rc_properties = NULL;
1208 g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
1209 g_slist_free (rc_style->icon_factories);
1211 g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1212 g_slist_free (rc_priv->color_hashes);
1214 G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
1220 * Creates a new #GtkRcStyle with no fields set and
1221 * a reference count of 1.
1223 * Returns: the newly-created #GtkRcStyle
1225 * Deprecated: 3.0: Use #GtkCssProvider instead.
1228 gtk_rc_style_new (void)
1232 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1238 * gtk_rc_style_copy:
1239 * @orig: the style to copy
1241 * Makes a copy of the specified #GtkRcStyle. This function
1242 * will correctly copy an RC style that is a member of a class
1243 * derived from #GtkRcStyle.
1245 * Return value: (transfer full): the resulting #GtkRcStyle
1247 * Deprecated: 3.0: Use #GtkCssProvider instead.
1250 gtk_rc_style_copy (GtkRcStyle *orig)
1254 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1256 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1257 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1263 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1265 return g_object_new (G_OBJECT_TYPE (style), NULL);
1269 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1270 gconstpointer bsearch_node2)
1272 const GtkRcProperty *prop1 = bsearch_node1;
1273 const GtkRcProperty *prop2 = bsearch_node2;
1275 if (prop1->type_name == prop2->type_name)
1276 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1278 return prop1->type_name < prop2->type_name ? -1 : 1;
1282 insert_rc_property (GtkRcStyle *style,
1283 GtkRcProperty *property,
1287 GtkRcProperty *new_property = NULL;
1288 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1290 key.type_name = property->type_name;
1291 key.property_name = property->property_name;
1293 if (!style->rc_properties)
1294 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1297 while (i < style->rc_properties->len)
1299 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1305 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1307 g_free (new_property->origin);
1308 g_value_unset (&new_property->value);
1310 *new_property = key;
1324 g_array_insert_val (style->rc_properties, i, key);
1325 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1328 new_property->origin = g_strdup (property->origin);
1329 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1330 g_value_copy (&property->value, &new_property->value);
1334 gtk_rc_style_real_merge (GtkRcStyle *dest,
1339 for (i = 0; i < 5; i++)
1341 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1342 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1344 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1345 src->color_flags[i] & GTK_RC_FG)
1347 dest->fg[i] = src->fg[i];
1348 dest->color_flags[i] |= GTK_RC_FG;
1350 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1351 src->color_flags[i] & GTK_RC_BG)
1353 dest->bg[i] = src->bg[i];
1354 dest->color_flags[i] |= GTK_RC_BG;
1356 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1357 src->color_flags[i] & GTK_RC_TEXT)
1359 dest->text[i] = src->text[i];
1360 dest->color_flags[i] |= GTK_RC_TEXT;
1362 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1363 src->color_flags[i] & GTK_RC_BASE)
1365 dest->base[i] = src->base[i];
1366 dest->color_flags[i] |= GTK_RC_BASE;
1370 if (dest->xthickness < 0 && src->xthickness >= 0)
1371 dest->xthickness = src->xthickness;
1372 if (dest->ythickness < 0 && src->ythickness >= 0)
1373 dest->ythickness = src->ythickness;
1377 if (!dest->font_desc)
1378 dest->font_desc = pango_font_description_copy (src->font_desc);
1380 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1383 if (src->rc_properties)
1387 for (i = 0; i < src->rc_properties->len; i++)
1388 insert_rc_property (dest,
1389 &g_array_index (src->rc_properties, GtkRcProperty, i),
1395 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1397 return gtk_style_new ();
1401 * gtk_rc_reset_styles:
1402 * @settings: a #GtkSettings
1404 * This function recomputes the styles for all widgets that use a
1405 * particular #GtkSettings object. (There is one #GtkSettings object
1406 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1407 * when some global parameter has changed that affects the appearance
1408 * of all widgets, because when a widget gets a new style, it will
1409 * both redraw and recompute any cached information about its
1410 * appearance. As an example, it is used when the default font size
1411 * set by the operating system changes. Note that this function
1412 * doesn't affect widgets that have a style set explicitely on them
1413 * with gtk_widget_set_style().
1417 * Deprecated: 3.0: Use #GtkCssProvider instead.
1420 gtk_rc_reset_styles (GtkSettings *settings)
1422 gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
1426 * gtk_rc_reparse_all_for_settings:
1427 * @settings: a #GtkSettings
1428 * @force_load: load whether or not anything changed
1430 * If the modification time on any previously read file
1431 * for the given #GtkSettings has changed, discard all style information
1432 * and then reread all previously read RC files.
1434 * Return value: %TRUE if the files were reread.
1436 * Deprecated: 3.0: Use #GtkCssProvider instead.
1439 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1440 gboolean force_load)
1446 * gtk_rc_reparse_all:
1448 * If the modification time on any previously read file for the
1449 * default #GtkSettings has changed, discard all style information
1450 * and then reread all previously read RC files.
1452 * Return value: %TRUE if the files were reread.
1454 * Deprecated: 3.0: Use #GtkCssProvider instead.
1457 gtk_rc_reparse_all (void)
1464 * @widget: a #GtkWidget
1466 * Finds all matching RC styles for a given widget,
1467 * composites them together, and then creates a
1468 * #GtkStyle representing the composite appearance.
1469 * (GTK+ actually keeps a cache of previously
1470 * created styles, so a new style may not be
1473 * Returns: (transfer none): the resulting style. No refcount is added
1474 * to the returned style, so if you want to save this style around,
1475 * you should add a reference yourself.
1477 * Deprecated:3.0: Use #GtkStyleContext instead
1480 gtk_rc_get_style (GtkWidget *widget)
1482 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1484 gtk_widget_ensure_style (widget);
1486 return gtk_widget_get_style (widget);
1490 * gtk_rc_get_style_by_paths:
1491 * @settings: a #GtkSettings object
1492 * @widget_path: (allow-none): the widget path to use when looking up the
1493 * style, or %NULL if no matching against the widget path should be done
1494 * @class_path: (allow-none): the class path to use when looking up the style,
1495 * or %NULL if no matching against the class path should be done.
1496 * @type: a type that will be used along with parent types of this type
1497 * when matching against class styles, or #G_TYPE_NONE
1499 * Creates up a #GtkStyle from styles defined in a RC file by providing
1500 * the raw components used in matching. This function may be useful
1501 * when creating pseudo-widgets that should be themed like widgets but
1502 * don't actually have corresponding GTK+ widgets. An example of this
1503 * would be items inside a GNOME canvas widget.
1505 * The action of gtk_rc_get_style() is similar to:
1507 * gtk_widget_path (widget, NULL, &path, NULL);
1508 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1509 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
1511 * G_OBJECT_TYPE (widget));
1514 * Return value: (transfer none): A style created by matching with the
1515 * supplied paths, or %NULL if nothing matching was specified and the
1516 * default style should be used. The returned value is owned by GTK+
1517 * as part of an internal cache, so you must call g_object_ref() on
1518 * the returned value if you want to keep a reference to it.
1520 * Deprecated:3.0: Use #GtkStyleContext instead
1523 gtk_rc_get_style_by_paths (GtkSettings *settings,
1524 const char *widget_path,
1525 const char *class_path,
1528 GtkWidgetPath *path;
1531 path = gtk_widget_path_new ();
1533 /* For compatibility, we return a GtkStyle based on a GtkStyleContext
1534 * with a GtkWidgetPath appropriate for the supplied information.
1536 * GtkWidgetPath is composed of a list of GTypes with optional names;
1537 * In GTK+-2.0, widget_path consisted of the widget names, or
1538 * the class names for unnamed widgets, while class_path had the
1539 * class names always. So, use class_path to determine the GTypes
1540 * and extract widget names from widget_path as applicable.
1542 if (class_path == NULL)
1544 gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
1548 const gchar *widget_p, *widget_next;
1549 const gchar *class_p, *class_next;
1551 widget_next = widget_path;
1552 class_next = class_path;
1556 GType component_type;
1557 gchar *component_class;
1558 gchar *component_name;
1561 class_p = class_next;
1562 if (*class_p == '.')
1565 widget_p = widget_next; /* Might be NULL */
1566 if (widget_p && *widget_p == '.')
1569 class_next = strchr (class_p, '.');
1570 if (class_next == NULL)
1571 class_next = class_p + strlen (class_p);
1575 widget_next = strchr (widget_p, '.');
1576 if (widget_next == NULL)
1577 widget_next = widget_p + strlen (widget_p);
1580 component_class = g_strndup (class_p, class_next - class_p);
1581 if (widget_p && *widget_p)
1582 component_name = g_strndup (widget_p, widget_next - widget_p);
1584 component_name = NULL;
1586 component_type = g_type_from_name (component_class);
1587 if (component_type == G_TYPE_INVALID)
1588 component_type = GTK_TYPE_WIDGET;
1590 pos = gtk_widget_path_append_type (path, component_type);
1591 if (component_name != NULL && strcmp (component_name, component_name) != 0)
1592 gtk_widget_path_iter_set_name (path, pos, component_name);
1594 g_free (component_class);
1595 g_free (component_name);
1599 style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
1602 gtk_widget_path_free (path);
1608 * gtk_rc_scanner_new: (skip)
1610 * Deprecated:3.0: Use #GtkCssProvider instead
1613 gtk_rc_scanner_new (void)
1615 return g_scanner_new (>k_rc_scanner_config);
1618 /*********************
1619 * Parsing functions *
1620 *********************/
1623 lookup_color (GtkRcStyle *style,
1624 const char *color_name,
1627 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1630 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
1632 GHashTable *hash = iter->data;
1633 GdkColor *match = g_hash_table_lookup (hash, color_name);
1637 color->red = match->red;
1638 color->green = match->green;
1639 color->blue = match->blue;
1648 * gtk_rc_find_pixmap_in_path:
1649 * @settings: a #GtkSettings
1650 * @scanner: Scanner used to get line number information for the
1651 * warning message, or %NULL
1652 * @pixmap_file: name of the pixmap file to locate.
1654 * Looks up a file in pixmap path for the specified #GtkSettings.
1655 * If the file is not found, it outputs a warning message using
1656 * g_warning() and returns %NULL.
1658 * Return value: (type filename): the filename.
1660 * Deprecated: 3.0: Use #GtkCssProvider instead.
1663 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
1665 const gchar *pixmap_file)
1667 g_warning ("Unable to locate image file in pixmap_path: \"%s\"",
1673 * gtk_rc_find_module_in_path:
1674 * @module_file: name of a theme engine
1676 * Searches for a theme engine in the GTK+ search path. This function
1677 * is not useful for applications and should not be used.
1679 * Return value: (type filename): The filename, if found (must be
1680 * freed with g_free()), otherwise %NULL.
1682 * Deprecated: 3.0: Use #GtkCssProvider instead.
1685 gtk_rc_find_module_in_path (const gchar *module_file)
1687 return _gtk_find_module (module_file, "engines");
1691 * gtk_rc_parse_state:
1692 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1693 * @state: (out): A pointer to a #GtkStateType variable in which to
1696 * Parses a #GtkStateType variable from the format expected
1699 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1700 * that was expected but not found.
1702 * Deprecated: 3.0: Use #GtkCssProvider instead
1705 gtk_rc_parse_state (GScanner *scanner,
1706 GtkStateType *state)
1711 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1712 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
1714 /* we don't know where we got called from, so we reset the scope here.
1715 * if we bail out due to errors, we *don't* reset the scope, so the
1716 * error messaging code can make sense of our tokens.
1718 old_scope = g_scanner_set_scope (scanner, 0);
1720 token = g_scanner_get_next_token (scanner);
1721 if (token != G_TOKEN_LEFT_BRACE)
1722 return G_TOKEN_LEFT_BRACE;
1724 token = g_scanner_get_next_token (scanner);
1727 case GTK_RC_TOKEN_ACTIVE:
1728 *state = GTK_STATE_ACTIVE;
1730 case GTK_RC_TOKEN_INSENSITIVE:
1731 *state = GTK_STATE_INSENSITIVE;
1733 case GTK_RC_TOKEN_NORMAL:
1734 *state = GTK_STATE_NORMAL;
1736 case GTK_RC_TOKEN_PRELIGHT:
1737 *state = GTK_STATE_PRELIGHT;
1739 case GTK_RC_TOKEN_SELECTED:
1740 *state = GTK_STATE_SELECTED;
1743 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1746 token = g_scanner_get_next_token (scanner);
1747 if (token != G_TOKEN_RIGHT_BRACE)
1748 return G_TOKEN_RIGHT_BRACE;
1750 g_scanner_set_scope (scanner, old_scope);
1752 return G_TOKEN_NONE;
1756 * gtk_rc_parse_priority:
1757 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1758 * @priority: A pointer to #GtkPathPriorityType variable in which
1759 * to store the result.
1761 * Parses a #GtkPathPriorityType variable from the format expected
1764 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1765 * that was expected but not found.
1767 * Deprecated:3.0: Use #GtkCssProvider instead
1770 gtk_rc_parse_priority (GScanner *scanner,
1771 GtkPathPriorityType *priority)
1776 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1777 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1779 /* we don't know where we got called from, so we reset the scope here.
1780 * if we bail out due to errors, we *don't* reset the scope, so the
1781 * error messaging code can make sense of our tokens.
1783 old_scope = g_scanner_set_scope (scanner, 0);
1785 token = g_scanner_get_next_token (scanner);
1789 token = g_scanner_get_next_token (scanner);
1792 case GTK_RC_TOKEN_LOWEST:
1793 *priority = GTK_PATH_PRIO_LOWEST;
1795 case GTK_RC_TOKEN_GTK:
1796 *priority = GTK_PATH_PRIO_GTK;
1798 case GTK_RC_TOKEN_APPLICATION:
1799 *priority = GTK_PATH_PRIO_APPLICATION;
1801 case GTK_RC_TOKEN_THEME:
1802 *priority = GTK_PATH_PRIO_THEME;
1804 case GTK_RC_TOKEN_RC:
1805 *priority = GTK_PATH_PRIO_RC;
1807 case GTK_RC_TOKEN_HIGHEST:
1808 *priority = GTK_PATH_PRIO_HIGHEST;
1811 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1814 g_scanner_set_scope (scanner, old_scope);
1816 return G_TOKEN_NONE;
1820 * gtk_rc_parse_color:
1821 * @scanner: a #GScanner
1822 * @color: (out): a pointer to a #GdkColor structure in which to store
1825 * Parses a color in the <link linkend="color=format">format</link> expected
1828 * Note that theme engines should use gtk_rc_parse_color_full() in
1829 * order to support symbolic colors.
1831 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1832 * that was expected but not found
1834 * Deprecated:3.0: Use #GtkCssProvider instead
1837 gtk_rc_parse_color (GScanner *scanner,
1840 return gtk_rc_parse_color_full (scanner, NULL, color);
1844 * gtk_rc_parse_color_full:
1845 * @scanner: a #GScanner
1846 * @style: (allow-none): a #GtkRcStyle, or %NULL
1847 * @color: (out): a pointer to a #GdkColor structure in which to store
1850 * Parses a color in the <link linkend="color=format">format</link> expected
1851 * in a RC file. If @style is not %NULL, it will be consulted to resolve
1852 * references to symbolic colors.
1854 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1855 * that was expected but not found
1859 * Deprecated:3.0: Use #GtkCssProvider instead
1862 gtk_rc_parse_color_full (GScanner *scanner,
1868 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1870 /* we don't need to set our own scope here, because
1871 * we don't need own symbols
1874 token = g_scanner_get_next_token (scanner);
1882 case G_TOKEN_LEFT_CURLY:
1883 token = g_scanner_get_next_token (scanner);
1884 if (token == G_TOKEN_INT)
1885 token_int = scanner->value.v_int;
1886 else if (token == G_TOKEN_FLOAT)
1887 token_int = scanner->value.v_float * 65535.0;
1889 return G_TOKEN_FLOAT;
1890 color->red = CLAMP (token_int, 0, 65535);
1892 token = g_scanner_get_next_token (scanner);
1893 if (token != G_TOKEN_COMMA)
1894 return G_TOKEN_COMMA;
1896 token = g_scanner_get_next_token (scanner);
1897 if (token == G_TOKEN_INT)
1898 token_int = scanner->value.v_int;
1899 else if (token == G_TOKEN_FLOAT)
1900 token_int = scanner->value.v_float * 65535.0;
1902 return G_TOKEN_FLOAT;
1903 color->green = CLAMP (token_int, 0, 65535);
1905 token = g_scanner_get_next_token (scanner);
1906 if (token != G_TOKEN_COMMA)
1907 return G_TOKEN_COMMA;
1909 token = g_scanner_get_next_token (scanner);
1910 if (token == G_TOKEN_INT)
1911 token_int = scanner->value.v_int;
1912 else if (token == G_TOKEN_FLOAT)
1913 token_int = scanner->value.v_float * 65535.0;
1915 return G_TOKEN_FLOAT;
1916 color->blue = CLAMP (token_int, 0, 65535);
1918 token = g_scanner_get_next_token (scanner);
1919 if (token != G_TOKEN_RIGHT_CURLY)
1920 return G_TOKEN_RIGHT_CURLY;
1921 return G_TOKEN_NONE;
1923 case G_TOKEN_STRING:
1924 if (!gdk_color_parse (scanner->value.v_string, color))
1926 g_scanner_warn (scanner, "Invalid color constant '%s'",
1927 scanner->value.v_string);
1928 return G_TOKEN_STRING;
1930 return G_TOKEN_NONE;
1933 token = g_scanner_get_next_token (scanner);
1934 if (token != G_TOKEN_IDENTIFIER)
1935 return G_TOKEN_IDENTIFIER;
1937 if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1939 g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1940 scanner->value.v_identifier);
1941 return G_TOKEN_IDENTIFIER;
1944 return G_TOKEN_NONE;
1946 case G_TOKEN_IDENTIFIER:
1947 if (strcmp (scanner->value.v_identifier, "mix") == 0)
1949 token = g_scanner_get_next_token (scanner);
1950 if (token != G_TOKEN_LEFT_PAREN)
1951 return G_TOKEN_LEFT_PAREN;
1954 if (g_scanner_peek_next_token (scanner) == '-')
1956 g_scanner_get_next_token (scanner); /* eat sign */
1960 token = g_scanner_get_next_token (scanner);
1961 if (token != G_TOKEN_FLOAT)
1962 return G_TOKEN_FLOAT;
1964 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1966 token = g_scanner_get_next_token (scanner);
1967 if (token != G_TOKEN_COMMA)
1968 return G_TOKEN_COMMA;
1970 token = gtk_rc_parse_color_full (scanner, style, &c1);
1971 if (token != G_TOKEN_NONE)
1974 token = g_scanner_get_next_token (scanner);
1975 if (token != G_TOKEN_COMMA)
1976 return G_TOKEN_COMMA;
1978 token = gtk_rc_parse_color_full (scanner, style, &c2);
1979 if (token != G_TOKEN_NONE)
1982 token = g_scanner_get_next_token (scanner);
1983 if (token != G_TOKEN_RIGHT_PAREN)
1984 return G_TOKEN_RIGHT_PAREN;
1986 color->red = l * c1.red + (1.0 - l) * c2.red;
1987 color->green = l * c1.green + (1.0 - l) * c2.green;
1988 color->blue = l * c1.blue + (1.0 - l) * c2.blue;
1990 return G_TOKEN_NONE;
1992 else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1994 token = g_scanner_get_next_token (scanner);
1995 if (token != G_TOKEN_LEFT_PAREN)
1996 return G_TOKEN_LEFT_PAREN;
1999 if (g_scanner_peek_next_token (scanner) == '-')
2001 g_scanner_get_next_token (scanner); /* eat sign */
2005 token = g_scanner_get_next_token (scanner);
2006 if (token != G_TOKEN_FLOAT)
2007 return G_TOKEN_FLOAT;
2009 l = negate ? -scanner->value.v_float : scanner->value.v_float;
2011 token = g_scanner_get_next_token (scanner);
2012 if (token != G_TOKEN_COMMA)
2013 return G_TOKEN_COMMA;
2015 token = gtk_rc_parse_color_full (scanner, style, &c1);
2016 if (token != G_TOKEN_NONE)
2019 token = g_scanner_get_next_token (scanner);
2020 if (token != G_TOKEN_RIGHT_PAREN)
2021 return G_TOKEN_RIGHT_PAREN;
2023 _gtk_style_shade (&c1, color, l);
2025 return G_TOKEN_NONE;
2027 else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
2028 strcmp (scanner->value.v_identifier, "darker") == 0)
2030 if (scanner->value.v_identifier[0] == 'l')
2035 token = g_scanner_get_next_token (scanner);
2036 if (token != G_TOKEN_LEFT_PAREN)
2037 return G_TOKEN_LEFT_PAREN;
2039 token = gtk_rc_parse_color_full (scanner, style, &c1);
2040 if (token != G_TOKEN_NONE)
2043 token = g_scanner_get_next_token (scanner);
2044 if (token != G_TOKEN_RIGHT_PAREN)
2045 return G_TOKEN_RIGHT_PAREN;
2047 _gtk_style_shade (&c1, color, l);
2049 return G_TOKEN_NONE;
2052 return G_TOKEN_IDENTIFIER;
2055 return G_TOKEN_STRING;