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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
42 #define GDK_DISABLE_DEPRECATION_WARNINGS
45 #include <glib/gstdio.h>
48 #include "gtkversion.h"
51 #include "gtkbindings.h"
53 #include "gtkiconfactory.h"
55 #include "gtkmodules.h"
56 #include "gtkmodulesprivate.h"
57 #include "gtkprivate.h"
58 #include "gtksettingsprivate.h"
59 #include "gtkwindow.h"
68 * @Short_description: Deprecated routines for handling resource files
69 * @Title: Resource Files
71 * GTK+ provides resource file mechanism for configuring
72 * various aspects of the operation of a GTK+ program
76 * In GTK+ 3.0, resource files have been deprecated and replaced
77 * by CSS-like style sheets, which are understood by #GtkCssProvider.
81 * <title>Default files</title>
83 * An application can cause GTK+ to parse a specific RC
84 * file by calling gtk_rc_parse(). In addition to this,
85 * certain files will be read at the end of gtk_init().
86 * Unless modified, the files looked for will be
87 * <filename><SYSCONFDIR>/gtk-2.0/gtkrc</filename>
88 * and <filename>.gtkrc-3.0</filename> in the users home directory.
89 * (<filename><SYSCONFDIR></filename> defaults to
90 * <filename>/usr/local/etc</filename>. It can be changed with the
91 * <option>--prefix</option> or <option>--sysconfdir</option> options when
94 * The set of these <firstterm>default</firstterm> files
95 * can be retrieved with gtk_rc_get_default_files()
96 * and modified with gtk_rc_add_default_file() and
97 * gtk_rc_set_default_files().
98 * Additionally, the <envar>GTK2_RC_FILES</envar> environment variable
99 * can be set to a #G_SEARCHPATH_SEPARATOR_S-separated list of files
100 * in order to overwrite the set of default files at runtime.
101 * <para><anchor id="locale-specific-rc"/>
102 * For each RC file, in addition to the file itself, GTK+ will look for
103 * a locale-specific file that will be parsed after the main file.
104 * For instance, if <envar>LANG</envar> is set to <literal>ja_JP.ujis</literal>,
105 * when loading the default file <filename>~/.gtkrc</filename> then GTK+ looks
106 * for <filename>~/.gtkrc.ja_JP</filename> and <filename>~/.gtkrc.ja</filename>,
107 * and parses the first of those that exists.</para>
111 * <title>Pathnames and patterns</title>
112 * <anchor id="gtkrc-pathnames-and-patterns"/>
114 * A resource file defines a number of styles and key bindings and
115 * attaches them to particular widgets. The attachment is done
116 * by the <literal>widget</literal>, <literal>widget_class</literal>,
117 * and <literal>class</literal> declarations. As an example
118 * of such a statement:
120 * <informalexample><programlisting>
121 * widget "mywindow.*.GtkEntry" style "my-entry-class"
122 * </programlisting></informalexample>
124 * attaches the style <literal>"my-entry-class"</literal> to all
125 * widgets whose <firstterm>widget path</firstterm> matches the
126 * <firstterm>pattern</firstterm> <literal>"mywindow.*.GtkEntry"</literal>.
127 * That is, all #GtkEntry widgets which are part of a #GtkWindow named
128 * <literal>"mywindow"</literal>.
130 * The patterns here are given in the standard shell glob syntax.
131 * The <literal>"?"</literal> wildcard matches any character, while
132 * <literal>"*"</literal> matches zero or more of any character.
133 * The three types of matching are against the widget path, the
134 * <firstterm>class path</firstterm> and the class hierarchy. Both the
135 * widget path and the class path consist of a <literal>"."</literal>
136 * separated list of all the parents of the widget and the widget itself
137 * from outermost to innermost. The difference is that in the widget path,
138 * the name assigned by gtk_widget_set_name() is used if present, otherwise
139 * the class name of the widget, while for the class path, the class name is
142 * Since GTK+ 2.10, <literal>widget_class</literal> paths can also contain
143 * <literal><classname></literal> substrings, which are matching
144 * the class with the given name and any derived classes. For instance,
145 * <informalexample><programlisting>
146 * widget_class "*<GtkMenuItem>.GtkLabel" style "my-style"
147 * </programlisting></informalexample>
148 * will match #GtkLabel widgets which are contained in any kind of menu item.
150 * So, if you have a #GtkEntry named <literal>"myentry"</literal>, inside of a
151 * horizontal box in a window named <literal>"mywindow"</literal>, then the
152 * widget path is: <literal>"mywindow.GtkHBox.myentry"</literal>
153 * while the class path is: <literal>"GtkWindow.GtkHBox.GtkEntry"</literal>.
155 * Matching against class is a little different. The pattern match is done
156 * against all class names in the widgets class hierarchy (not the layout
157 * hierarchy) in sequence, so the pattern:
158 * <informalexample><programlisting>
159 * class "GtkButton" style "my-style"
160 * </programlisting></informalexample>
161 * will match not just #GtkButton widgets, but also #GtkToggleButton and
162 * #GtkCheckButton widgets, since those classes derive from #GtkButton.
164 * Additionally, a priority can be specified for each pattern, and styles
165 * override other styles first by priority, then by pattern type and then
166 * by order of specification (later overrides earlier). The priorities
167 * that can be specified are (highest to lowest):
169 * <member><literal>highest</literal></member>
170 * <member><literal>rc</literal></member>
171 * <member><literal>theme</literal></member>
172 * <member><literal>application</literal></member>
173 * <member><literal>gtk</literal></member>
174 * <member><literal>lowest</literal></member>
176 * <literal>rc</literal> is the default for styles
177 * read from an RC file, <literal>theme</literal>
178 * is the default for styles read from theme RC files,
179 * <literal>application</literal>
180 * should be used for styles an application sets
181 * up, and <literal>gtk</literal> is used for styles
182 * that GTK+ creates internally.
186 * <title>Theme gtkrc files</title>
187 * <anchor id="theme-gtkrc-files"/>
189 * Theme RC files are loaded first from under the <filename>~/.themes/</filename>,
190 * then from the directory from gtk_rc_get_theme_dir(). The files looked at will
191 * be <filename>gtk-3.0/gtkrc</filename>.
193 * When the application prefers dark themes
194 * (see the #GtkSettings:gtk-application-prefer-dark-theme property for details),
195 * <filename>gtk-3.0/gtkrc-dark</filename> will be loaded first, and if not present
196 * <filename>gtk-3.0/gtkrc</filename> will be loaded.
200 * <title>Optimizing RC Style Matches</title>
201 * <anchor id="optimizing-rc-style-matches"/>
203 * Everytime a widget is created and added to the layout hierarchy of a #GtkWindow
204 * ("anchored" to be exact), a list of matching RC styles out of all RC styles read
205 * in so far is composed.
206 * For this, every RC style is matched against the widgets class path,
207 * the widgets name path and widgets inheritance hierarchy.
208 * As a consequence, significant slowdown can be caused by utilization of many
209 * RC styles and by using RC style patterns that are slow or complicated to match
210 * against a given widget.
211 * The following ordered list provides a number of advices (prioritized by
212 * effectiveness) to reduce the performance overhead associated with RC style
217 * Move RC styles for specific applications into RC files dedicated to those
218 * applications and parse application specific RC files only from
219 * applications that are affected by them.
220 * This reduces the overall amount of RC styles that have to be considered
221 * for a match across a group of applications.
224 * Merge multiple styles which use the same matching rule, for instance:
225 * <informalexample><programlisting>
226 * style "Foo" { foo_content }
227 * class "X" style "Foo"
228 * style "Bar" { bar_content }
229 * class "X" style "Bar"
230 * </programlisting></informalexample>
231 * is faster to match as:
232 * <informalexample><programlisting>
233 * style "FooBar" { foo_content bar_content }
234 * class "X" style "FooBar"
235 * </programlisting></informalexample>
238 * Use of wildcards should be avoided, this can reduce the individual RC style
239 * match to a single integer comparison in most cases.
242 * To avoid complex recursive matching, specification of full class names
243 * (for <literal>class</literal> matches) or full path names (for
244 * <literal>widget</literal> and <literal>widget_class</literal> matches)
245 * is to be preferred over shortened names
246 * containing <literal>"*"</literal> or <literal>"?"</literal>.
249 * If at all necessary, wildcards should only be used at the tail or head
250 * of a pattern. This reduces the match complexity to a string comparison
254 * When using wildcards, use of <literal>"?"</literal> should be preferred
255 * over <literal>"*"</literal>. This can reduce the matching complexity from
256 * O(n^2) to O(n). For example <literal>"Gtk*Box"</literal> can be turned into
257 * <literal>"Gtk?Box"</literal> and will still match #GtkHBox and #GtkVBox.
260 * The use of <literal>"*"</literal> wildcards should be restricted as much
261 * as possible, because matching <literal>"A*B*C*RestString"</literal> can
262 * result in matching complexities of O(n^2) worst case.
268 * <title>Toplevel declarations</title>
270 * An RC file is a text file which is composed of a sequence
271 * of declarations. <literal>'#'</literal> characters delimit comments and
272 * the portion of a line after a <literal>'#'</literal> is ignored when parsing
275 * The possible toplevel declarations are:
279 * <term><literal>binding <replaceable>name</replaceable>
280 * { ... }</literal></term>
282 * <para>Declares a binding set.</para>
286 * <term><literal>class <replaceable>pattern</replaceable>
287 * [ style | binding ][ : <replaceable>priority</replaceable> ]
288 * <replaceable>name</replaceable></literal></term>
290 * <para>Specifies a style or binding set for a particular
291 * branch of the inheritance hierarchy.</para>
295 * <term><literal>include <replaceable>filename</replaceable></literal></term>
297 * <para>Parses another file at this point. If
298 * <replaceable>filename</replaceable> is not an absolute filename,
299 * it is searched in the directories of the currently open RC files.</para>
300 * <para>GTK+ also tries to load a
301 * <link linkend="locale-specific-rc">locale-specific variant</link> of
302 * the included file.</para>
306 * <term><literal>module_path <replaceable>path</replaceable></literal></term>
308 * <para>Sets a path (a list of directories separated
309 * by colons) that will be searched for theme engines referenced in
314 * <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
316 * <para>Sets a path (a list of directories separated
317 * by colons) that will be searched for pixmaps referenced in
322 * <term><literal>im_module_file <replaceable>pathname</replaceable></literal></term>
324 * <para>Sets the pathname for the IM modules file. Setting this from RC files
325 * is deprecated; you should use the environment variable <envar>GTK_IM_MODULE_FILE</envar>
330 * <term><literal>style <replaceable>name</replaceable> [ =
331 * <replaceable>parent</replaceable> ] { ... }</literal></term>
333 * <para>Declares a style.</para>
337 * <term><literal>widget <replaceable>pattern</replaceable>
338 * [ style | binding ][ : <replaceable>priority</replaceable> ]
339 * <replaceable>name</replaceable></literal></term>
341 * <para>Specifies a style or binding set for a particular
342 * group of widgets by matching on the widget pathname.</para>
346 * <term><literal>widget_class <replaceable>pattern</replaceable>
347 * [ style | binding ][ : <replaceable>priority</replaceable> ]
348 * <replaceable>name</replaceable></literal></term>
350 * <para>Specifies a style or binding set for a particular
351 * group of widgets by matching on the class pathname.</para>
355 * <term><replaceable>setting</replaceable> = <replaceable>value</replaceable></term>
357 * <para>Specifies a value for a <link linkend="GtkSettings">setting</link>.
358 * Note that settings in RC files are overwritten by system-wide settings
359 * (which are managed by an XSettings manager on X11).</para>
366 * <title>Styles</title>
368 * A RC style is specified by a <literal>style</literal>
369 * declaration in a RC file, and then bound to widgets
370 * with a <literal>widget</literal>, <literal>widget_class</literal>,
371 * or <literal>class</literal> declaration. All styles
372 * applying to a particular widget are composited together
373 * with <literal>widget</literal> declarations overriding
374 * <literal>widget_class</literal> declarations which, in
375 * turn, override <literal>class</literal> declarations.
376 * Within each type of declaration, later declarations override
379 * Within a <literal>style</literal> declaration, the possible
384 * <term><literal>bg[<replaceable>state</replaceable>] =
385 * <replaceable>color</replaceable></literal></term>
387 * Sets the color used for the background of most widgets.
391 * <term><literal>fg[<replaceable>state</replaceable>] =
392 * <replaceable>color</replaceable></literal></term>
394 * Sets the color used for the foreground of most widgets.
398 * <term><literal>base[<replaceable>state</replaceable>] =
399 * <replaceable>color</replaceable></literal></term>
401 * Sets the color used for the background of widgets displaying
402 * editable text. This color is used for the background
403 * of, among others, #GtkText, #GtkEntry, #GtkList, and #GtkCList.
407 * <term><literal>text[<replaceable>state</replaceable>] =
408 * <replaceable>color</replaceable></literal></term>
410 * Sets the color used for foreground of widgets using
411 * <literal>base</literal> for the background color.
415 * <term><literal>xthickness =
416 * <replaceable>number</replaceable></literal></term>
418 * Sets the xthickness, which is used for various horizontal padding
423 * <term><literal>ythickness =
424 * <replaceable>number</replaceable></literal></term>
426 * Sets the ythickness, which is used for various vertical padding
431 * <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
432 * <replaceable>pixmap</replaceable></literal></term>
434 * Sets a background pixmap to be used in place of
435 * the <literal>bg</literal> color (or for #GtkText,
436 * in place of the <literal>base</literal> color. The special
437 * value <literal>"<parent>"</literal> may be used to indicate that the widget should
438 * use the same background pixmap as its parent. The special value
439 * <literal>"<none>"</literal> may be used to indicate no background pixmap.
443 * <term><literal>font = <replaceable>font</replaceable></literal></term>
445 * Starting with GTK+ 2.0, the "font" and "fontset"
446 * declarations are ignored; use "font_name" declarations instead.
450 * <term><literal>fontset = <replaceable>font</replaceable></literal></term>
452 * Starting with GTK+ 2.0, the "font" and "fontset"
453 * declarations are ignored; use "font_name" declarations instead.
457 * <term><literal>font_name = <replaceable>font</replaceable></literal></term>
459 * Sets the font for a widget. <replaceable>font</replaceable> must be
460 * a Pango font name, e.g. <literal>"Sans Italic 10"</literal>.
461 * For details about Pango font names, see
462 * pango_font_description_from_string().
466 * <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
468 * Defines the icon for a stock item.
472 * <term><literal>color[<replaceable>"color-name"</replaceable>] = <replaceable>color specification</replaceable></literal></term>
474 * Since 2.10, this element can be used to defines symbolic colors. See below for
475 * the syntax of color specifications.
479 * <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
480 * settings</replaceable> }</literal></term>
482 * Defines the engine to be used when drawing with this style.
486 * <term><literal><replaceable>class</replaceable>::<replaceable>property</replaceable> = <replaceable>value</replaceable></literal></term>
488 * Sets a <link linkend="style-properties">style property</link> for a widget class.
493 * The colors and background pixmaps are specified as a function of the
494 * state of the widget. The states are:
498 * <term><literal>NORMAL</literal></term>
500 * A color used for a widget in its normal state.
504 * <term><literal>ACTIVE</literal></term>
506 * A variant of the <literal>NORMAL</literal> color used when the
507 * widget is in the %GTK_STATE_ACTIVE state, and also for
508 * the trough of a ScrollBar, tabs of a NoteBook
509 * other than the current tab and similar areas.
510 * Frequently, this should be a darker variant
511 * of the <literal>NORMAL</literal> color.
515 * <term><literal>PRELIGHT</literal></term>
517 * A color used for widgets in the %GTK_STATE_PRELIGHT state. This
518 * state is the used for Buttons and MenuItems
519 * that have the mouse cursor over them, and for
524 * <term><literal>SELECTED</literal></term>
526 * A color used to highlight data selected by the user.
527 * for instance, the selected items in a list widget, and the
528 * selection in an editable widget.
532 * <term><literal>INSENSITIVE</literal></term>
534 * A color used for the background of widgets that have
535 * been set insensitive with gtk_widget_set_sensitive().
540 * <anchor id="color-format"/>
541 * Colors can be specified as a string containing a color name (GTK+ knows
542 * all names from the X color database <filename>/usr/lib/X11/rgb.txt</filename>),
543 * in one of the hexadecimal forms <literal>#rrrrggggbbbb</literal>,
544 * <literal>#rrrgggbbb</literal>, <literal>#rrggbb</literal>,
545 * or <literal>#rgb</literal>, where <literal>r</literal>,
546 * <literal>g</literal> and <literal>b</literal> are
547 * hex digits, or they can be specified as a triplet
548 * <literal>{ <replaceable>r</replaceable>, <replaceable>g</replaceable>,
549 * <replaceable>b</replaceable>}</literal>, where <literal>r</literal>,
550 * <literal>g</literal> and <literal>b</literal> are either integers in
551 * the range 0-65535 or floats in the range 0.0-1.0.
553 * Since 2.10, colors can also be specified by refering to a symbolic color, as
554 * follows: <literal>@<!-- -->color-name</literal>, or by using expressions to combine
555 * colors. The following expressions are currently supported:
558 * <term>mix (<replaceable>factor</replaceable>, <replaceable>color1</replaceable>, <replaceable>color2</replaceable>)</term>
560 * Computes a new color by mixing <replaceable>color1</replaceable> and
561 * <replaceable>color2</replaceable>. The <replaceable>factor</replaceable>
562 * determines how close the new color is to <replaceable>color1</replaceable>.
563 * A factor of 1.0 gives pure <replaceable>color1</replaceable>, a factor of
564 * 0.0 gives pure <replaceable>color2</replaceable>.
568 * <term>shade (<replaceable>factor</replaceable>, <replaceable>color</replaceable>)</term>
570 * Computes a lighter or darker variant of <replaceable>color</replaceable>.
571 * A <replaceable>factor</replaceable> of 1.0 leaves the color unchanged, smaller
572 * factors yield darker colors, larger factors yield lighter colors.
576 * <term>lighter (<replaceable>color</replaceable>)</term>
578 * This is an abbreviation for
579 * <literal>shade (1.3, <replaceable>color</replaceable>)</literal>.
583 * <term>darker (<replaceable>color</replaceable>)</term>
585 * This is an abbreviation for
586 * <literal>shade (0.7, <replaceable>color</replaceable>)</literal>.
591 * Here are some examples of color expressions:
593 * <informalexample><programlisting>
594 * mix (0.5, "red", "blue")
595 * shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 }))
596 * lighter (@<!-- -->foreground)
597 * </programlisting></informalexample>
599 * In a <literal>stock</literal> definition, icon sources are specified as a
600 * 4-tuple of image filename or icon name, text direction, widget state, and size, in that
601 * order. Each icon source specifies an image filename or icon name to use with a given
602 * direction, state, and size. Filenames are specified as a string such
603 * as <literal>"itemltr.png"</literal>, while icon names (looked up
604 * in the current icon theme), are specified with a leading
605 * <literal>@</literal>, such as <literal>@"item-ltr"</literal>.
606 * The <literal>*</literal> character can be used as a
607 * wildcard, and if direction/state/size are omitted they default to
608 * <literal>*</literal>. So for example, the following specifies different icons to
609 * use for left-to-right and right-to-left languages:
611 * <informalexample><programlisting>
612 * stock["my-stock-item"] =
614 * { "itemltr.png", LTR, *, * },
615 * { "itemrtl.png", RTL, *, * }
617 * </programlisting></informalexample>
619 * This could be abbreviated as follows:
621 * <informalexample><programlisting>
622 * stock["my-stock-item"] =
624 * { "itemltr.png", LTR },
625 * { "itemrtl.png", RTL }
627 * </programlisting></informalexample>
629 * You can specify custom icons for specific sizes, as follows:
631 * <informalexample><programlisting>
632 * stock["my-stock-item"] =
634 * { "itemmenusize.png", *, *, "gtk-menu" },
635 * { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
636 * { "itemgeneric.png" } // implicit *, *, * as a fallback
638 * </programlisting></informalexample>
640 * The sizes that come with GTK+ itself are <literal>"gtk-menu"</literal>,
641 * <literal>"gtk-small-toolbar"</literal>, <literal>"gtk-large-toolbar"</literal>,
642 * <literal>"gtk-button"</literal>, <literal>"gtk-dialog"</literal>. Applications
643 * can define other sizes.
645 * It's also possible to use custom icons for a given state, for example:
647 * <informalexample><programlisting>
648 * stock["my-stock-item"] =
650 * { "itemprelight.png", *, PRELIGHT },
651 * { "iteminsensitive.png", *, INSENSITIVE },
652 * { "itemgeneric.png" } // implicit *, *, * as a fallback
654 * </programlisting></informalexample>
656 * When selecting an icon source to use, GTK+ will consider text direction most
657 * important, state second, and size third. It will select the best match based on
658 * those criteria. If an attribute matches exactly (e.g. you specified
659 * <literal>PRELIGHT</literal> or specified the size), GTK+ won't modify the image;
660 * if the attribute matches with a wildcard, GTK+ will scale or modify the image to
661 * match the state and size the user requested.
665 * <title>Key bindings</title>
667 * Key bindings allow the user to specify actions to be
668 * taken on particular key presses. The form of a binding
669 * set declaration is:
671 * <informalexample><programlisting>
672 * binding <replaceable>name</replaceable> {
673 * bind <replaceable>key</replaceable> {
674 * <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
679 * </programlisting></informalexample>
681 * <replaceable>key</replaceable> is a string consisting of a
682 * series of modifiers followed by the name of a key. The
685 * <member><literal><alt></literal></member>
686 * <member><literal><ctl></literal></member>
687 * <member><literal><control></literal></member>
688 * <member><literal><meta></literal></member>
689 * <member><literal><hyper></literal></member>
690 * <member><literal><super></literal></member>
691 * <member><literal><mod1></literal></member>
692 * <member><literal><mod2></literal></member>
693 * <member><literal><mod3></literal></member>
694 * <member><literal><mod4></literal></member>
695 * <member><literal><mod5></literal></member>
696 * <member><literal><release></literal></member>
697 * <member><literal><shft></literal></member>
698 * <member><literal><shift></literal></member>
700 * <literal><shft></literal> is an alias for
701 * <literal><shift></literal>,
702 * <literal><ctl></literal> is an alias for
703 * <literal><control></literal>,
705 * <literal><alt></literal> is an alias for
706 * <literal><mod1></literal>.
708 * The action that is bound to the key is a sequence
709 * of signal names (strings) followed by parameters for
710 * each signal. The signals must be action signals.
711 * (See g_signal_new()). Each parameter can be
712 * a float, integer, string, or unquoted string
713 * representing an enumeration value. The types of
714 * the parameters specified must match the types of the
715 * parameters of the signal.
717 * Binding sets are connected to widgets in the same manner as styles,
718 * with one difference: Binding sets override other binding sets first
719 * by pattern type, then by priority and then by order of specification.
720 * The priorities that can be specified and their default values are the
721 * same as for styles.
745 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
747 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
749 struct _GtkRcStylePrivate
751 GSList *color_hashes;
754 static void gtk_rc_style_finalize (GObject *object);
755 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
757 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
758 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
759 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
760 gconstpointer bsearch_node2);
762 static void insert_rc_property (GtkRcStyle *style,
763 GtkRcProperty *property,
767 static const GScannerConfig gtk_rc_scanner_config =
771 ) /* cset_skip_characters */,
776 ) /* cset_identifier_first */,
782 ) /* cset_identifier_nth */,
783 ( "#\n" ) /* cpair_comment_single */,
785 TRUE /* case_sensitive */,
787 TRUE /* skip_comment_multi */,
788 TRUE /* skip_comment_single */,
789 TRUE /* scan_comment_multi */,
790 TRUE /* scan_identifier */,
791 FALSE /* scan_identifier_1char */,
792 FALSE /* scan_identifier_NULL */,
793 TRUE /* scan_symbols */,
794 TRUE /* scan_binary */,
795 TRUE /* scan_octal */,
796 TRUE /* scan_float */,
798 TRUE /* scan_hex_dollar */,
799 TRUE /* scan_string_sq */,
800 TRUE /* scan_string_dq */,
801 TRUE /* numbers_2_int */,
802 FALSE /* int_2_float */,
803 FALSE /* identifier_2_string */,
804 TRUE /* char_2_token */,
805 TRUE /* symbol_2_token */,
806 FALSE /* scope_0_fallback */,
809 static const gchar symbol_names[] =
853 { 0, GTK_RC_TOKEN_INCLUDE },
854 { 8, GTK_RC_TOKEN_NORMAL },
855 { 15, GTK_RC_TOKEN_ACTIVE },
856 { 22, GTK_RC_TOKEN_PRELIGHT },
857 { 31, GTK_RC_TOKEN_SELECTED },
858 { 40, GTK_RC_TOKEN_INSENSITIVE },
859 { 52, GTK_RC_TOKEN_FG },
860 { 55, GTK_RC_TOKEN_BG },
861 { 58, GTK_RC_TOKEN_TEXT },
862 { 63, GTK_RC_TOKEN_BASE },
863 { 68, GTK_RC_TOKEN_XTHICKNESS },
864 { 79, GTK_RC_TOKEN_YTHICKNESS },
865 { 90, GTK_RC_TOKEN_FONT },
866 { 95, GTK_RC_TOKEN_FONTSET },
867 { 103, GTK_RC_TOKEN_FONT_NAME },
868 { 113, GTK_RC_TOKEN_BG_PIXMAP },
869 { 123, GTK_RC_TOKEN_PIXMAP_PATH },
870 { 135, GTK_RC_TOKEN_STYLE },
871 { 141, GTK_RC_TOKEN_BINDING },
872 { 149, GTK_RC_TOKEN_BIND },
873 { 154, GTK_RC_TOKEN_WIDGET },
874 { 161, GTK_RC_TOKEN_WIDGET_CLASS },
875 { 174, GTK_RC_TOKEN_CLASS },
876 { 180, GTK_RC_TOKEN_LOWEST },
877 { 187, GTK_RC_TOKEN_GTK },
878 { 191, GTK_RC_TOKEN_APPLICATION },
879 { 203, GTK_RC_TOKEN_THEME },
880 { 209, GTK_RC_TOKEN_RC },
881 { 212, GTK_RC_TOKEN_HIGHEST },
882 { 220, GTK_RC_TOKEN_ENGINE },
883 { 227, GTK_RC_TOKEN_MODULE_PATH },
884 { 239, GTK_RC_TOKEN_STOCK },
885 { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
886 { 260, GTK_RC_TOKEN_LTR },
887 { 264, GTK_RC_TOKEN_RTL },
888 { 268, GTK_RC_TOKEN_COLOR },
889 { 274, GTK_RC_TOKEN_UNBIND }
892 static GHashTable *realized_style_ht = NULL;
894 static gchar *im_module_file = NULL;
896 static gchar **gtk_rc_default_files = NULL;
898 /* RC file handling */
901 gtk_rc_make_default_dir (const gchar *type)
906 var = g_getenv ("GTK_EXE_PREFIX");
909 path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
911 path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
917 * gtk_rc_get_im_module_path:
919 * Obtains the path in which to look for IM modules. See the documentation
920 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
921 * environment variable for more details about looking up modules. This
922 * function is useful solely for utilities supplied with GTK+ and should
923 * not be used by applications under normal circumstances.
925 * Returns: (type filename): a newly-allocated string containing the
926 * path in which to look for IM modules.
928 * Deprecated: 3.0: Use #GtkCssProvider instead.
931 gtk_rc_get_im_module_path (void)
933 gchar **paths = _gtk_get_module_path ("immodules");
934 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
941 * gtk_rc_get_im_module_file:
943 * Obtains the path to the IM modules file. See the documentation
944 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
945 * environment variable for more details.
947 * Returns: (type filename): a newly-allocated string containing the
948 * name of the file listing the IM modules available for loading
950 * Deprecated: 3.0: Use #GtkCssProvider instead.
953 gtk_rc_get_im_module_file (void)
955 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
956 gchar *result = NULL;
959 result = g_strdup (var);
964 result = g_strdup (im_module_file);
966 result = gtk_rc_make_default_dir ("immodules.cache");
973 * gtk_rc_get_theme_dir:
975 * Returns the standard directory in which themes should
976 * be installed. (GTK+ does not actually use this directory
979 * Returns: The directory (must be freed with g_free()).
981 * Deprecated: 3.0: Use #GtkCssProvider instead.
984 gtk_rc_get_theme_dir (void)
989 var = g_getenv ("GTK_DATA_PREFIX");
992 path = g_build_filename (var, "share", "themes", NULL);
994 path = g_build_filename (_gtk_get_data_prefix (), "share", "themes", NULL);
1000 * gtk_rc_get_module_dir:
1002 * Returns a directory in which GTK+ looks for theme engines.
1003 * For full information about the search for theme engines,
1004 * see the docs for <envar>GTK_PATH</envar> in
1005 * <xref linkend="gtk-running"/>.
1007 * return value: (type filename): the directory. (Must be freed with g_free())
1009 * Deprecated: 3.0: Use #GtkCssProvider instead.
1012 gtk_rc_get_module_dir (void)
1014 return gtk_rc_make_default_dir ("engines");
1018 * gtk_rc_add_default_file:
1019 * @filename: (type filename): the pathname to the file. If @filename
1020 * is not absolute, it is searched in the current directory.
1022 * Adds a file to the list of files to be parsed at the
1023 * end of gtk_init().
1025 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1028 gtk_rc_add_default_file (const gchar *filename)
1033 * gtk_rc_set_default_files:
1034 * @filenames: (array zero-terminated=1) (element-type filename): A
1035 * %NULL-terminated list of filenames.
1037 * Sets the list of files that GTK+ will read at the
1038 * end of gtk_init().
1040 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1043 gtk_rc_set_default_files (gchar **filenames)
1048 * gtk_rc_get_default_files:
1050 * Retrieves the current list of RC files that will be parsed
1051 * at the end of gtk_init().
1053 * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
1054 * A %NULL-terminated array of filenames. This memory is owned
1055 * by GTK+ and must not be freed by the application. If you want
1056 * to store this information, you should make a copy.
1058 * Deprecated:3.0: Use #GtkStyleContext instead
1061 gtk_rc_get_default_files (void)
1063 return gtk_rc_default_files;
1067 * gtk_rc_parse_string:
1068 * @rc_string: a string to parse.
1070 * Parses resource information directly from a string.
1072 * Deprecated: 3.0: Use #GtkCssProvider instead.
1075 gtk_rc_parse_string (const gchar *rc_string)
1077 g_return_if_fail (rc_string != NULL);
1082 * @filename: the filename of a file to parse. If @filename is not absolute, it
1083 * is searched in the current directory.
1085 * Parses a given resource file.
1087 * Deprecated: 3.0: Use #GtkCssProvider instead.
1090 gtk_rc_parse (const gchar *filename)
1092 g_return_if_fail (filename != NULL);
1095 /* Handling of RC styles */
1097 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
1100 gtk_rc_style_init (GtkRcStyle *style)
1102 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1106 style->font_desc = NULL;
1108 for (i = 0; i < 5; i++)
1110 static const GdkColor init_color = { 0, 0, 0, 0, };
1112 style->bg_pixmap_name[i] = NULL;
1113 style->color_flags[i] = 0;
1114 style->fg[i] = init_color;
1115 style->bg[i] = init_color;
1116 style->text[i] = init_color;
1117 style->base[i] = init_color;
1119 style->xthickness = -1;
1120 style->ythickness = -1;
1121 style->rc_properties = NULL;
1123 style->rc_style_lists = NULL;
1124 style->icon_factories = NULL;
1126 priv->color_hashes = NULL;
1130 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1134 object_class->finalize = gtk_rc_style_finalize;
1136 klass->parse = NULL;
1137 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
1138 klass->merge = gtk_rc_style_real_merge;
1139 klass->create_style = gtk_rc_style_real_create_style;
1141 g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
1145 gtk_rc_style_finalize (GObject *object)
1147 GSList *tmp_list1, *tmp_list2;
1148 GtkRcStyle *rc_style;
1149 GtkRcStylePrivate *rc_priv;
1152 rc_style = GTK_RC_STYLE (object);
1153 rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
1155 g_free (rc_style->name);
1156 if (rc_style->font_desc)
1157 pango_font_description_free (rc_style->font_desc);
1159 for (i = 0; i < 5; i++)
1160 g_free (rc_style->bg_pixmap_name[i]);
1162 /* Now remove all references to this rc_style from
1165 tmp_list1 = rc_style->rc_style_lists;
1168 GSList *rc_styles = tmp_list1->data;
1169 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1170 g_object_unref (style);
1172 /* Remove the list of styles from the other rc_styles
1175 tmp_list2 = rc_styles;
1178 GtkRcStyle *other_style = tmp_list2->data;
1180 if (other_style != rc_style)
1181 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1183 tmp_list2 = tmp_list2->next;
1186 /* And from the hash table itself
1188 g_hash_table_remove (realized_style_ht, rc_styles);
1189 g_slist_free (rc_styles);
1191 tmp_list1 = tmp_list1->next;
1193 g_slist_free (rc_style->rc_style_lists);
1195 if (rc_style->rc_properties)
1199 for (i = 0; i < rc_style->rc_properties->len; i++)
1201 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1203 g_free (node->origin);
1204 g_value_unset (&node->value);
1206 g_array_free (rc_style->rc_properties, TRUE);
1207 rc_style->rc_properties = NULL;
1210 g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
1211 g_slist_free (rc_style->icon_factories);
1213 g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1214 g_slist_free (rc_priv->color_hashes);
1216 G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
1222 * Creates a new #GtkRcStyle with no fields set and
1223 * a reference count of 1.
1225 * Returns: the newly-created #GtkRcStyle
1227 * Deprecated: 3.0: Use #GtkCssProvider instead.
1230 gtk_rc_style_new (void)
1234 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1240 * gtk_rc_style_copy:
1241 * @orig: the style to copy
1243 * Makes a copy of the specified #GtkRcStyle. This function
1244 * will correctly copy an RC style that is a member of a class
1245 * derived from #GtkRcStyle.
1247 * Return value: (transfer full): the resulting #GtkRcStyle
1249 * Deprecated: 3.0: Use #GtkCssProvider instead.
1252 gtk_rc_style_copy (GtkRcStyle *orig)
1256 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1258 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1259 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1265 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1267 return g_object_new (G_OBJECT_TYPE (style), NULL);
1271 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1272 gconstpointer bsearch_node2)
1274 const GtkRcProperty *prop1 = bsearch_node1;
1275 const GtkRcProperty *prop2 = bsearch_node2;
1277 if (prop1->type_name == prop2->type_name)
1278 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1280 return prop1->type_name < prop2->type_name ? -1 : 1;
1284 insert_rc_property (GtkRcStyle *style,
1285 GtkRcProperty *property,
1289 GtkRcProperty *new_property = NULL;
1290 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1292 key.type_name = property->type_name;
1293 key.property_name = property->property_name;
1295 if (!style->rc_properties)
1296 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1299 while (i < style->rc_properties->len)
1301 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1307 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1309 g_free (new_property->origin);
1310 g_value_unset (&new_property->value);
1312 *new_property = key;
1326 g_array_insert_val (style->rc_properties, i, key);
1327 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1330 new_property->origin = g_strdup (property->origin);
1331 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1332 g_value_copy (&property->value, &new_property->value);
1336 gtk_rc_style_real_merge (GtkRcStyle *dest,
1341 for (i = 0; i < 5; i++)
1343 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1344 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1346 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1347 src->color_flags[i] & GTK_RC_FG)
1349 dest->fg[i] = src->fg[i];
1350 dest->color_flags[i] |= GTK_RC_FG;
1352 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1353 src->color_flags[i] & GTK_RC_BG)
1355 dest->bg[i] = src->bg[i];
1356 dest->color_flags[i] |= GTK_RC_BG;
1358 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1359 src->color_flags[i] & GTK_RC_TEXT)
1361 dest->text[i] = src->text[i];
1362 dest->color_flags[i] |= GTK_RC_TEXT;
1364 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1365 src->color_flags[i] & GTK_RC_BASE)
1367 dest->base[i] = src->base[i];
1368 dest->color_flags[i] |= GTK_RC_BASE;
1372 if (dest->xthickness < 0 && src->xthickness >= 0)
1373 dest->xthickness = src->xthickness;
1374 if (dest->ythickness < 0 && src->ythickness >= 0)
1375 dest->ythickness = src->ythickness;
1379 if (!dest->font_desc)
1380 dest->font_desc = pango_font_description_copy (src->font_desc);
1382 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1385 if (src->rc_properties)
1389 for (i = 0; i < src->rc_properties->len; i++)
1390 insert_rc_property (dest,
1391 &g_array_index (src->rc_properties, GtkRcProperty, i),
1397 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1399 return gtk_style_new ();
1403 * gtk_rc_reset_styles:
1404 * @settings: a #GtkSettings
1406 * This function recomputes the styles for all widgets that use a
1407 * particular #GtkSettings object. (There is one #GtkSettings object
1408 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1409 * when some global parameter has changed that affects the appearance
1410 * of all widgets, because when a widget gets a new style, it will
1411 * both redraw and recompute any cached information about its
1412 * appearance. As an example, it is used when the default font size
1413 * set by the operating system changes. Note that this function
1414 * doesn't affect widgets that have a style set explicitely on them
1415 * with gtk_widget_set_style().
1419 * Deprecated: 3.0: Use #GtkCssProvider instead.
1422 gtk_rc_reset_styles (GtkSettings *settings)
1424 gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
1428 * gtk_rc_reparse_all_for_settings:
1429 * @settings: a #GtkSettings
1430 * @force_load: load whether or not anything changed
1432 * If the modification time on any previously read file
1433 * for the given #GtkSettings has changed, discard all style information
1434 * and then reread all previously read RC files.
1436 * Return value: %TRUE if the files were reread.
1438 * Deprecated: 3.0: Use #GtkCssProvider instead.
1441 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1442 gboolean force_load)
1448 * gtk_rc_reparse_all:
1450 * If the modification time on any previously read file for the
1451 * default #GtkSettings has changed, discard all style information
1452 * and then reread all previously read RC files.
1454 * Return value: %TRUE if the files were reread.
1456 * Deprecated: 3.0: Use #GtkCssProvider instead.
1459 gtk_rc_reparse_all (void)
1466 * @widget: a #GtkWidget
1468 * Finds all matching RC styles for a given widget,
1469 * composites them together, and then creates a
1470 * #GtkStyle representing the composite appearance.
1471 * (GTK+ actually keeps a cache of previously
1472 * created styles, so a new style may not be
1475 * Returns: (transfer none): the resulting style. No refcount is added
1476 * to the returned style, so if you want to save this style around,
1477 * you should add a reference yourself.
1479 * Deprecated:3.0: Use #GtkStyleContext instead
1482 gtk_rc_get_style (GtkWidget *widget)
1484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1486 gtk_widget_ensure_style (widget);
1488 return gtk_widget_get_style (widget);
1492 * gtk_rc_get_style_by_paths:
1493 * @settings: a #GtkSettings object
1494 * @widget_path: (allow-none): the widget path to use when looking up the
1495 * style, or %NULL if no matching against the widget path should be done
1496 * @class_path: (allow-none): the class path to use when looking up the style,
1497 * or %NULL if no matching against the class path should be done.
1498 * @type: a type that will be used along with parent types of this type
1499 * when matching against class styles, or #G_TYPE_NONE
1501 * Creates up a #GtkStyle from styles defined in a RC file by providing
1502 * the raw components used in matching. This function may be useful
1503 * when creating pseudo-widgets that should be themed like widgets but
1504 * don't actually have corresponding GTK+ widgets. An example of this
1505 * would be items inside a GNOME canvas widget.
1507 * The action of gtk_rc_get_style() is similar to:
1509 * gtk_widget_path (widget, NULL, &path, NULL);
1510 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1511 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
1513 * G_OBJECT_TYPE (widget));
1516 * Return value: (transfer none): A style created by matching with the
1517 * supplied paths, or %NULL if nothing matching was specified and the
1518 * default style should be used. The returned value is owned by GTK+
1519 * as part of an internal cache, so you must call g_object_ref() on
1520 * the returned value if you want to keep a reference to it.
1522 * Deprecated:3.0: Use #GtkStyleContext instead
1525 gtk_rc_get_style_by_paths (GtkSettings *settings,
1526 const char *widget_path,
1527 const char *class_path,
1530 GtkWidgetPath *path;
1533 path = gtk_widget_path_new ();
1535 /* For compatibility, we return a GtkStyle based on a GtkStyleContext
1536 * with a GtkWidgetPath appropriate for the supplied information.
1538 * GtkWidgetPath is composed of a list of GTypes with optional names;
1539 * In GTK+-2.0, widget_path consisted of the widget names, or
1540 * the class names for unnamed widgets, while class_path had the
1541 * class names always. So, use class_path to determine the GTypes
1542 * and extract widget names from widget_path as applicable.
1544 if (class_path == NULL)
1546 gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
1550 const gchar *widget_p, *widget_next;
1551 const gchar *class_p, *class_next;
1553 widget_next = widget_path;
1554 class_next = class_path;
1558 GType component_type;
1559 gchar *component_class;
1560 gchar *component_name;
1563 class_p = class_next;
1564 if (*class_p == '.')
1567 widget_p = widget_next; /* Might be NULL */
1568 if (widget_p && *widget_p == '.')
1571 class_next = strchr (class_p, '.');
1572 if (class_next == NULL)
1573 class_next = class_p + strlen (class_p);
1577 widget_next = strchr (widget_p, '.');
1578 if (widget_next == NULL)
1579 widget_next = widget_p + strlen (widget_p);
1582 component_class = g_strndup (class_p, class_next - class_p);
1583 if (widget_p && *widget_p)
1584 component_name = g_strndup (widget_p, widget_next - widget_p);
1586 component_name = NULL;
1588 component_type = g_type_from_name (component_class);
1589 if (component_type == G_TYPE_INVALID)
1590 component_type = GTK_TYPE_WIDGET;
1592 pos = gtk_widget_path_append_type (path, component_type);
1593 if (component_name != NULL && strcmp (component_name, component_name) != 0)
1594 gtk_widget_path_iter_set_name (path, pos, component_name);
1596 g_free (component_class);
1597 g_free (component_name);
1601 style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
1604 gtk_widget_path_free (path);
1610 * gtk_rc_scanner_new: (skip)
1612 * Deprecated:3.0: Use #GtkCssProvider instead
1615 gtk_rc_scanner_new (void)
1617 return g_scanner_new (>k_rc_scanner_config);
1620 /*********************
1621 * Parsing functions *
1622 *********************/
1625 lookup_color (GtkRcStyle *style,
1626 const char *color_name,
1629 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1632 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
1634 GHashTable *hash = iter->data;
1635 GdkColor *match = g_hash_table_lookup (hash, color_name);
1639 color->red = match->red;
1640 color->green = match->green;
1641 color->blue = match->blue;
1650 * gtk_rc_find_pixmap_in_path:
1651 * @settings: a #GtkSettings
1652 * @scanner: Scanner used to get line number information for the
1653 * warning message, or %NULL
1654 * @pixmap_file: name of the pixmap file to locate.
1656 * Looks up a file in pixmap path for the specified #GtkSettings.
1657 * If the file is not found, it outputs a warning message using
1658 * g_warning() and returns %NULL.
1660 * Return value: (type filename): the filename.
1662 * Deprecated: 3.0: Use #GtkCssProvider instead.
1665 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
1667 const gchar *pixmap_file)
1669 g_warning ("Unable to locate image file in pixmap_path: \"%s\"",
1675 * gtk_rc_find_module_in_path:
1676 * @module_file: name of a theme engine
1678 * Searches for a theme engine in the GTK+ search path. This function
1679 * is not useful for applications and should not be used.
1681 * Return value: (type filename): The filename, if found (must be
1682 * freed with g_free()), otherwise %NULL.
1684 * Deprecated: 3.0: Use #GtkCssProvider instead.
1687 gtk_rc_find_module_in_path (const gchar *module_file)
1689 return _gtk_find_module (module_file, "engines");
1693 * gtk_rc_parse_state:
1694 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1695 * @state: (out): A pointer to a #GtkStateType variable in which to
1698 * Parses a #GtkStateType variable from the format expected
1701 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1702 * that was expected but not found.
1704 * Deprecated: 3.0: Use #GtkCssProvider instead
1707 gtk_rc_parse_state (GScanner *scanner,
1708 GtkStateType *state)
1713 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1714 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
1716 /* we don't know where we got called from, so we reset the scope here.
1717 * if we bail out due to errors, we *don't* reset the scope, so the
1718 * error messaging code can make sense of our tokens.
1720 old_scope = g_scanner_set_scope (scanner, 0);
1722 token = g_scanner_get_next_token (scanner);
1723 if (token != G_TOKEN_LEFT_BRACE)
1724 return G_TOKEN_LEFT_BRACE;
1726 token = g_scanner_get_next_token (scanner);
1729 case GTK_RC_TOKEN_ACTIVE:
1730 *state = GTK_STATE_ACTIVE;
1732 case GTK_RC_TOKEN_INSENSITIVE:
1733 *state = GTK_STATE_INSENSITIVE;
1735 case GTK_RC_TOKEN_NORMAL:
1736 *state = GTK_STATE_NORMAL;
1738 case GTK_RC_TOKEN_PRELIGHT:
1739 *state = GTK_STATE_PRELIGHT;
1741 case GTK_RC_TOKEN_SELECTED:
1742 *state = GTK_STATE_SELECTED;
1745 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1748 token = g_scanner_get_next_token (scanner);
1749 if (token != G_TOKEN_RIGHT_BRACE)
1750 return G_TOKEN_RIGHT_BRACE;
1752 g_scanner_set_scope (scanner, old_scope);
1754 return G_TOKEN_NONE;
1758 * gtk_rc_parse_priority:
1759 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1760 * @priority: A pointer to #GtkPathPriorityType variable in which
1761 * to store the result.
1763 * Parses a #GtkPathPriorityType variable from the format expected
1766 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1767 * that was expected but not found.
1769 * Deprecated:3.0: Use #GtkCssProvider instead
1772 gtk_rc_parse_priority (GScanner *scanner,
1773 GtkPathPriorityType *priority)
1778 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1779 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1781 /* we don't know where we got called from, so we reset the scope here.
1782 * if we bail out due to errors, we *don't* reset the scope, so the
1783 * error messaging code can make sense of our tokens.
1785 old_scope = g_scanner_set_scope (scanner, 0);
1787 token = g_scanner_get_next_token (scanner);
1791 token = g_scanner_get_next_token (scanner);
1794 case GTK_RC_TOKEN_LOWEST:
1795 *priority = GTK_PATH_PRIO_LOWEST;
1797 case GTK_RC_TOKEN_GTK:
1798 *priority = GTK_PATH_PRIO_GTK;
1800 case GTK_RC_TOKEN_APPLICATION:
1801 *priority = GTK_PATH_PRIO_APPLICATION;
1803 case GTK_RC_TOKEN_THEME:
1804 *priority = GTK_PATH_PRIO_THEME;
1806 case GTK_RC_TOKEN_RC:
1807 *priority = GTK_PATH_PRIO_RC;
1809 case GTK_RC_TOKEN_HIGHEST:
1810 *priority = GTK_PATH_PRIO_HIGHEST;
1813 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1816 g_scanner_set_scope (scanner, old_scope);
1818 return G_TOKEN_NONE;
1822 * gtk_rc_parse_color:
1823 * @scanner: a #GScanner
1824 * @color: (out): a pointer to a #GdkColor structure in which to store
1827 * Parses a color in the <link linkend="color=format">format</link> expected
1830 * Note that theme engines should use gtk_rc_parse_color_full() in
1831 * order to support symbolic colors.
1833 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1834 * that was expected but not found
1836 * Deprecated:3.0: Use #GtkCssProvider instead
1839 gtk_rc_parse_color (GScanner *scanner,
1842 return gtk_rc_parse_color_full (scanner, NULL, color);
1846 * gtk_rc_parse_color_full:
1847 * @scanner: a #GScanner
1848 * @style: (allow-none): a #GtkRcStyle, or %NULL
1849 * @color: (out): a pointer to a #GdkColor structure in which to store
1852 * Parses a color in the <link linkend="color=format">format</link> expected
1853 * in a RC file. If @style is not %NULL, it will be consulted to resolve
1854 * references to symbolic colors.
1856 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1857 * that was expected but not found
1861 * Deprecated:3.0: Use #GtkCssProvider instead
1864 gtk_rc_parse_color_full (GScanner *scanner,
1870 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1872 /* we don't need to set our own scope here, because
1873 * we don't need own symbols
1876 token = g_scanner_get_next_token (scanner);
1884 case G_TOKEN_LEFT_CURLY:
1885 token = g_scanner_get_next_token (scanner);
1886 if (token == G_TOKEN_INT)
1887 token_int = scanner->value.v_int;
1888 else if (token == G_TOKEN_FLOAT)
1889 token_int = scanner->value.v_float * 65535.0;
1891 return G_TOKEN_FLOAT;
1892 color->red = CLAMP (token_int, 0, 65535);
1894 token = g_scanner_get_next_token (scanner);
1895 if (token != G_TOKEN_COMMA)
1896 return G_TOKEN_COMMA;
1898 token = g_scanner_get_next_token (scanner);
1899 if (token == G_TOKEN_INT)
1900 token_int = scanner->value.v_int;
1901 else if (token == G_TOKEN_FLOAT)
1902 token_int = scanner->value.v_float * 65535.0;
1904 return G_TOKEN_FLOAT;
1905 color->green = CLAMP (token_int, 0, 65535);
1907 token = g_scanner_get_next_token (scanner);
1908 if (token != G_TOKEN_COMMA)
1909 return G_TOKEN_COMMA;
1911 token = g_scanner_get_next_token (scanner);
1912 if (token == G_TOKEN_INT)
1913 token_int = scanner->value.v_int;
1914 else if (token == G_TOKEN_FLOAT)
1915 token_int = scanner->value.v_float * 65535.0;
1917 return G_TOKEN_FLOAT;
1918 color->blue = CLAMP (token_int, 0, 65535);
1920 token = g_scanner_get_next_token (scanner);
1921 if (token != G_TOKEN_RIGHT_CURLY)
1922 return G_TOKEN_RIGHT_CURLY;
1923 return G_TOKEN_NONE;
1925 case G_TOKEN_STRING:
1926 if (!gdk_color_parse (scanner->value.v_string, color))
1928 g_scanner_warn (scanner, "Invalid color constant '%s'",
1929 scanner->value.v_string);
1930 return G_TOKEN_STRING;
1932 return G_TOKEN_NONE;
1935 token = g_scanner_get_next_token (scanner);
1936 if (token != G_TOKEN_IDENTIFIER)
1937 return G_TOKEN_IDENTIFIER;
1939 if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1941 g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1942 scanner->value.v_identifier);
1943 return G_TOKEN_IDENTIFIER;
1946 return G_TOKEN_NONE;
1948 case G_TOKEN_IDENTIFIER:
1949 if (strcmp (scanner->value.v_identifier, "mix") == 0)
1951 token = g_scanner_get_next_token (scanner);
1952 if (token != G_TOKEN_LEFT_PAREN)
1953 return G_TOKEN_LEFT_PAREN;
1956 if (g_scanner_peek_next_token (scanner) == '-')
1958 g_scanner_get_next_token (scanner); /* eat sign */
1962 token = g_scanner_get_next_token (scanner);
1963 if (token != G_TOKEN_FLOAT)
1964 return G_TOKEN_FLOAT;
1966 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1968 token = g_scanner_get_next_token (scanner);
1969 if (token != G_TOKEN_COMMA)
1970 return G_TOKEN_COMMA;
1972 token = gtk_rc_parse_color_full (scanner, style, &c1);
1973 if (token != G_TOKEN_NONE)
1976 token = g_scanner_get_next_token (scanner);
1977 if (token != G_TOKEN_COMMA)
1978 return G_TOKEN_COMMA;
1980 token = gtk_rc_parse_color_full (scanner, style, &c2);
1981 if (token != G_TOKEN_NONE)
1984 token = g_scanner_get_next_token (scanner);
1985 if (token != G_TOKEN_RIGHT_PAREN)
1986 return G_TOKEN_RIGHT_PAREN;
1988 color->red = l * c1.red + (1.0 - l) * c2.red;
1989 color->green = l * c1.green + (1.0 - l) * c2.green;
1990 color->blue = l * c1.blue + (1.0 - l) * c2.blue;
1992 return G_TOKEN_NONE;
1994 else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1996 token = g_scanner_get_next_token (scanner);
1997 if (token != G_TOKEN_LEFT_PAREN)
1998 return G_TOKEN_LEFT_PAREN;
2001 if (g_scanner_peek_next_token (scanner) == '-')
2003 g_scanner_get_next_token (scanner); /* eat sign */
2007 token = g_scanner_get_next_token (scanner);
2008 if (token != G_TOKEN_FLOAT)
2009 return G_TOKEN_FLOAT;
2011 l = negate ? -scanner->value.v_float : scanner->value.v_float;
2013 token = g_scanner_get_next_token (scanner);
2014 if (token != G_TOKEN_COMMA)
2015 return G_TOKEN_COMMA;
2017 token = gtk_rc_parse_color_full (scanner, style, &c1);
2018 if (token != G_TOKEN_NONE)
2021 token = g_scanner_get_next_token (scanner);
2022 if (token != G_TOKEN_RIGHT_PAREN)
2023 return G_TOKEN_RIGHT_PAREN;
2025 _gtk_style_shade (&c1, color, l);
2027 return G_TOKEN_NONE;
2029 else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
2030 strcmp (scanner->value.v_identifier, "darker") == 0)
2032 if (scanner->value.v_identifier[0] == 'l')
2037 token = g_scanner_get_next_token (scanner);
2038 if (token != G_TOKEN_LEFT_PAREN)
2039 return G_TOKEN_LEFT_PAREN;
2041 token = gtk_rc_parse_color_full (scanner, style, &c1);
2042 if (token != G_TOKEN_NONE)
2045 token = g_scanner_get_next_token (scanner);
2046 if (token != G_TOKEN_RIGHT_PAREN)
2047 return G_TOKEN_RIGHT_PAREN;
2049 _gtk_style_shade (&c1, color, l);
2051 return G_TOKEN_NONE;
2054 return G_TOKEN_IDENTIFIER;
2057 return G_TOKEN_STRING;