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>
44 #include <glib/gstdio.h>
47 #include "gtkversion.h"
49 #include "gtkbindings.h"
51 #include "gtkiconfactory.h"
53 #include "gtkmodules.h"
54 #include "gtkprivate.h"
55 #include "gtksettingsprivate.h"
56 #include "gtkwindow.h"
65 * @Short_description: Deprecated routines for handling resource files
66 * @Title: Resource Files
68 * GTK+ provides resource file mechanism for configuring
69 * various aspects of the operation of a GTK+ program
73 * In GTK+ 3.0, resource files have been deprecated and replaced
74 * by CSS-like style sheets, which are understood by #GtkCssProvider.
78 * <title>Default files</title>
80 * An application can cause GTK+ to parse a specific RC
81 * file by calling gtk_rc_parse(). In addition to this,
82 * certain files will be read at the end of gtk_init().
83 * Unless modified, the files looked for will be
84 * <filename><SYSCONFDIR>/gtk-2.0/gtkrc</filename>
85 * and <filename>.gtkrc-3.0</filename> in the users home directory.
86 * (<filename><SYSCONFDIR></filename> defaults to
87 * <filename>/usr/local/etc</filename>. It can be changed with the
88 * <option>--prefix</option> or <option>--sysconfdir</option> options when
91 * The set of these <firstterm>default</firstterm> files
92 * can be retrieved with gtk_rc_get_default_files()
93 * and modified with gtk_rc_add_default_file() and
94 * gtk_rc_set_default_files().
95 * Additionally, the <envar>GTK2_RC_FILES</envar> environment variable
96 * can be set to a #G_SEARCHPATH_SEPARATOR_S-separated list of files
97 * in order to overwrite the set of default files at runtime.
98 * <para><anchor id="locale-specific-rc"/>
99 * For each RC file, in addition to the file itself, GTK+ will look for
100 * a locale-specific file that will be parsed after the main file.
101 * For instance, if <envar>LANG</envar> is set to <literal>ja_JP.ujis</literal>,
102 * when loading the default file <filename>~/.gtkrc</filename> then GTK+ looks
103 * for <filename>~/.gtkrc.ja_JP</filename> and <filename>~/.gtkrc.ja</filename>,
104 * and parses the first of those that exists.</para>
108 * <title>Pathnames and patterns</title>
109 * <anchor id="gtkrc-pathnames-and-patterns"/>
111 * A resource file defines a number of styles and key bindings and
112 * attaches them to particular widgets. The attachment is done
113 * by the <literal>widget</literal>, <literal>widget_class</literal>,
114 * and <literal>class</literal> declarations. As an example
115 * of such a statement:
117 * <informalexample><programlisting>
118 * widget "mywindow.*.GtkEntry" style "my-entry-class"
119 * </programlisting></informalexample>
121 * attaches the style <literal>"my-entry-class"</literal> to all
122 * widgets whose <firstterm>widget path</firstterm> matches the
123 * <firstterm>pattern</firstterm> <literal>"mywindow.*.GtkEntry"</literal>.
124 * That is, all #GtkEntry widgets which are part of a #GtkWindow named
125 * <literal>"mywindow"</literal>.
127 * The patterns here are given in the standard shell glob syntax.
128 * The <literal>"?"</literal> wildcard matches any character, while
129 * <literal>"*"</literal> matches zero or more of any character.
130 * The three types of matching are against the widget path, the
131 * <firstterm>class path</firstterm> and the class hierarchy. Both the
132 * widget path and the class path consist of a <literal>"."</literal>
133 * separated list of all the parents of the widget and the widget itself
134 * from outermost to innermost. The difference is that in the widget path,
135 * the name assigned by gtk_widget_set_name() is used if present, otherwise
136 * the class name of the widget, while for the class path, the class name is
139 * Since GTK+ 2.10, <literal>widget_class</literal> paths can also contain
140 * <literal><classname></literal> substrings, which are matching
141 * the class with the given name and any derived classes. For instance,
142 * <informalexample><programlisting>
143 * widget_class "*<GtkMenuItem>.GtkLabel" style "my-style"
144 * </programlisting></informalexample>
145 * will match #GtkLabel widgets which are contained in any kind of menu item.
147 * So, if you have a #GtkEntry named <literal>"myentry"</literal>, inside of a
148 * horizontal box in a window named <literal>"mywindow"</literal>, then the
149 * widget path is: <literal>"mywindow.GtkHBox.myentry"</literal>
150 * while the class path is: <literal>"GtkWindow.GtkHBox.GtkEntry"</literal>.
152 * Matching against class is a little different. The pattern match is done
153 * against all class names in the widgets class hierarchy (not the layout
154 * hierarchy) in sequence, so the pattern:
155 * <informalexample><programlisting>
156 * class "GtkButton" style "my-style"
157 * </programlisting></informalexample>
158 * will match not just #GtkButton widgets, but also #GtkToggleButton and
159 * #GtkCheckButton widgets, since those classes derive from #GtkButton.
161 * Additionally, a priority can be specified for each pattern, and styles
162 * override other styles first by priority, then by pattern type and then
163 * by order of specification (later overrides earlier). The priorities
164 * that can be specified are (highest to lowest):
166 * <member><literal>highest</literal></member>
167 * <member><literal>rc</literal></member>
168 * <member><literal>theme</literal></member>
169 * <member><literal>application</literal></member>
170 * <member><literal>gtk</literal></member>
171 * <member><literal>lowest</literal></member>
173 * <literal>rc</literal> is the default for styles
174 * read from an RC file, <literal>theme</literal>
175 * is the default for styles read from theme RC files,
176 * <literal>application</literal>
177 * should be used for styles an application sets
178 * up, and <literal>gtk</literal> is used for styles
179 * that GTK+ creates internally.
183 * <title>Theme gtkrc files</title>
184 * <anchor id="theme-gtkrc-files"/>
186 * Theme RC files are loaded first from under the <filename>~/.themes/</filename>,
187 * then from the directory from gtk_rc_get_theme_dir(). The files looked at will
188 * be <filename>gtk-3.0/gtkrc</filename>.
190 * When the application prefers dark themes
191 * (see the #GtkSettings:gtk-application-prefer-dark-theme property for details),
192 * <filename>gtk-3.0/gtkrc-dark</filename> will be loaded first, and if not present
193 * <filename>gtk-3.0/gtkrc</filename> will be loaded.
197 * <title>Optimizing RC Style Matches</title>
198 * <anchor id="optimizing-rc-style-matches"/>
200 * Everytime a widget is created and added to the layout hierarchy of a #GtkWindow
201 * ("anchored" to be exact), a list of matching RC styles out of all RC styles read
202 * in so far is composed.
203 * For this, every RC style is matched against the widgets class path,
204 * the widgets name path and widgets inheritance hierarchy.
205 * As a consequence, significant slowdown can be caused by utilization of many
206 * RC styles and by using RC style patterns that are slow or complicated to match
207 * against a given widget.
208 * The following ordered list provides a number of advices (prioritized by
209 * effectiveness) to reduce the performance overhead associated with RC style
214 * Move RC styles for specific applications into RC files dedicated to those
215 * applications and parse application specific RC files only from
216 * applications that are affected by them.
217 * This reduces the overall amount of RC styles that have to be considered
218 * for a match across a group of applications.
221 * Merge multiple styles which use the same matching rule, for instance:
222 * <informalexample><programlisting>
223 * style "Foo" { foo_content }
224 * class "X" style "Foo"
225 * style "Bar" { bar_content }
226 * class "X" style "Bar"
227 * </programlisting></informalexample>
228 * is faster to match as:
229 * <informalexample><programlisting>
230 * style "FooBar" { foo_content bar_content }
231 * class "X" style "FooBar"
232 * </programlisting></informalexample>
235 * Use of wildcards should be avoided, this can reduce the individual RC style
236 * match to a single integer comparison in most cases.
239 * To avoid complex recursive matching, specification of full class names
240 * (for <literal>class</literal> matches) or full path names (for
241 * <literal>widget</literal> and <literal>widget_class</literal> matches)
242 * is to be preferred over shortened names
243 * containing <literal>"*"</literal> or <literal>"?"</literal>.
246 * If at all necessary, wildcards should only be used at the tail or head
247 * of a pattern. This reduces the match complexity to a string comparison
251 * When using wildcards, use of <literal>"?"</literal> should be preferred
252 * over <literal>"*"</literal>. This can reduce the matching complexity from
253 * O(n^2) to O(n). For example <literal>"Gtk*Box"</literal> can be turned into
254 * <literal>"Gtk?Box"</literal> and will still match #GtkHBox and #GtkVBox.
257 * The use of <literal>"*"</literal> wildcards should be restricted as much
258 * as possible, because matching <literal>"A*B*C*RestString"</literal> can
259 * result in matching complexities of O(n^2) worst case.
265 * <title>Toplevel declarations</title>
267 * An RC file is a text file which is composed of a sequence
268 * of declarations. <literal>'#'</literal> characters delimit comments and
269 * the portion of a line after a <literal>'#'</literal> is ignored when parsing
272 * The possible toplevel declarations are:
276 * <term><literal>binding <replaceable>name</replaceable>
277 * { ... }</literal></term>
279 * <para>Declares a binding set.</para>
283 * <term><literal>class <replaceable>pattern</replaceable>
284 * [ style | binding ][ : <replaceable>priority</replaceable> ]
285 * <replaceable>name</replaceable></literal></term>
287 * <para>Specifies a style or binding set for a particular
288 * branch of the inheritance hierarchy.</para>
292 * <term><literal>include <replaceable>filename</replaceable></literal></term>
294 * <para>Parses another file at this point. If
295 * <replaceable>filename</replaceable> is not an absolute filename,
296 * it is searched in the directories of the currently open RC files.</para>
297 * <para>GTK+ also tries to load a
298 * <link linkend="locale-specific-rc">locale-specific variant</link> of
299 * the included file.</para>
303 * <term><literal>module_path <replaceable>path</replaceable></literal></term>
305 * <para>Sets a path (a list of directories separated
306 * by colons) that will be searched for theme engines referenced in
311 * <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
313 * <para>Sets a path (a list of directories separated
314 * by colons) that will be searched for pixmaps referenced in
319 * <term><literal>im_module_file <replaceable>pathname</replaceable></literal></term>
321 * <para>Sets the pathname for the IM modules file. Setting this from RC files
322 * is deprecated; you should use the environment variable <envar>GTK_IM_MODULE_FILE</envar>
327 * <term><literal>style <replaceable>name</replaceable> [ =
328 * <replaceable>parent</replaceable> ] { ... }</literal></term>
330 * <para>Declares a style.</para>
334 * <term><literal>widget <replaceable>pattern</replaceable>
335 * [ style | binding ][ : <replaceable>priority</replaceable> ]
336 * <replaceable>name</replaceable></literal></term>
338 * <para>Specifies a style or binding set for a particular
339 * group of widgets by matching on the widget pathname.</para>
343 * <term><literal>widget_class <replaceable>pattern</replaceable>
344 * [ style | binding ][ : <replaceable>priority</replaceable> ]
345 * <replaceable>name</replaceable></literal></term>
347 * <para>Specifies a style or binding set for a particular
348 * group of widgets by matching on the class pathname.</para>
352 * <term><replaceable>setting</replaceable> = <replaceable>value</replaceable></term>
354 * <para>Specifies a value for a <link linkend="GtkSettings">setting</link>.
355 * Note that settings in RC files are overwritten by system-wide settings
356 * (which are managed by an XSettings manager on X11).</para>
363 * <title>Styles</title>
365 * A RC style is specified by a <literal>style</literal>
366 * declaration in a RC file, and then bound to widgets
367 * with a <literal>widget</literal>, <literal>widget_class</literal>,
368 * or <literal>class</literal> declaration. All styles
369 * applying to a particular widget are composited together
370 * with <literal>widget</literal> declarations overriding
371 * <literal>widget_class</literal> declarations which, in
372 * turn, override <literal>class</literal> declarations.
373 * Within each type of declaration, later declarations override
376 * Within a <literal>style</literal> declaration, the possible
381 * <term><literal>bg[<replaceable>state</replaceable>] =
382 * <replaceable>color</replaceable></literal></term>
384 * Sets the color used for the background of most widgets.
388 * <term><literal>fg[<replaceable>state</replaceable>] =
389 * <replaceable>color</replaceable></literal></term>
391 * Sets the color used for the foreground of most widgets.
395 * <term><literal>base[<replaceable>state</replaceable>] =
396 * <replaceable>color</replaceable></literal></term>
398 * Sets the color used for the background of widgets displaying
399 * editable text. This color is used for the background
400 * of, among others, #GtkText, #GtkEntry, #GtkList, and #GtkCList.
404 * <term><literal>text[<replaceable>state</replaceable>] =
405 * <replaceable>color</replaceable></literal></term>
407 * Sets the color used for foreground of widgets using
408 * <literal>base</literal> for the background color.
412 * <term><literal>xthickness =
413 * <replaceable>number</replaceable></literal></term>
415 * Sets the xthickness, which is used for various horizontal padding
420 * <term><literal>ythickness =
421 * <replaceable>number</replaceable></literal></term>
423 * Sets the ythickness, which is used for various vertical padding
428 * <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
429 * <replaceable>pixmap</replaceable></literal></term>
431 * Sets a background pixmap to be used in place of
432 * the <literal>bg</literal> color (or for #GtkText,
433 * in place of the <literal>base</literal> color. The special
434 * value <literal>"<parent>"</literal> may be used to indicate that the widget should
435 * use the same background pixmap as its parent. The special value
436 * <literal>"<none>"</literal> may be used to indicate no background pixmap.
440 * <term><literal>font = <replaceable>font</replaceable></literal></term>
442 * Starting with GTK+ 2.0, the "font" and "fontset"
443 * declarations are ignored; use "font_name" declarations instead.
447 * <term><literal>fontset = <replaceable>font</replaceable></literal></term>
449 * Starting with GTK+ 2.0, the "font" and "fontset"
450 * declarations are ignored; use "font_name" declarations instead.
454 * <term><literal>font_name = <replaceable>font</replaceable></literal></term>
456 * Sets the font for a widget. <replaceable>font</replaceable> must be
457 * a Pango font name, e.g. <literal>"Sans Italic 10"</literal>.
458 * For details about Pango font names, see
459 * pango_font_description_from_string().
463 * <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
465 * Defines the icon for a stock item.
469 * <term><literal>color[<replaceable>"color-name"</replaceable>] = <replaceable>color specification</replaceable></literal></term>
471 * Since 2.10, this element can be used to defines symbolic colors. See below for
472 * the syntax of color specifications.
476 * <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
477 * settings</replaceable> }</literal></term>
479 * Defines the engine to be used when drawing with this style.
483 * <term><literal><replaceable>class</replaceable>::<replaceable>property</replaceable> = <replaceable>value</replaceable></literal></term>
485 * Sets a <link linkend="style-properties">style property</link> for a widget class.
490 * The colors and background pixmaps are specified as a function of the
491 * state of the widget. The states are:
495 * <term><literal>NORMAL</literal></term>
497 * A color used for a widget in its normal state.
501 * <term><literal>ACTIVE</literal></term>
503 * A variant of the <literal>NORMAL</literal> color used when the
504 * widget is in the %GTK_STATE_ACTIVE state, and also for
505 * the trough of a ScrollBar, tabs of a NoteBook
506 * other than the current tab and similar areas.
507 * Frequently, this should be a darker variant
508 * of the <literal>NORMAL</literal> color.
512 * <term><literal>PRELIGHT</literal></term>
514 * A color used for widgets in the %GTK_STATE_PRELIGHT state. This
515 * state is the used for Buttons and MenuItems
516 * that have the mouse cursor over them, and for
521 * <term><literal>SELECTED</literal></term>
523 * A color used to highlight data selected by the user.
524 * for instance, the selected items in a list widget, and the
525 * selection in an editable widget.
529 * <term><literal>INSENSITIVE</literal></term>
531 * A color used for the background of widgets that have
532 * been set insensitive with gtk_widget_set_sensitive().
537 * <anchor id="color-format"/>
538 * Colors can be specified as a string containing a color name (GTK+ knows
539 * all names from the X color database <filename>/usr/lib/X11/rgb.txt</filename>),
540 * in one of the hexadecimal forms <literal>#rrrrggggbbbb</literal>,
541 * <literal>#rrrgggbbb</literal>, <literal>#rrggbb</literal>,
542 * or <literal>#rgb</literal>, where <literal>r</literal>,
543 * <literal>g</literal> and <literal>b</literal> are
544 * hex digits, or they can be specified as a triplet
545 * <literal>{ <replaceable>r</replaceable>, <replaceable>g</replaceable>,
546 * <replaceable>b</replaceable>}</literal>, where <literal>r</literal>,
547 * <literal>g</literal> and <literal>b</literal> are either integers in
548 * the range 0-65535 or floats in the range 0.0-1.0.
550 * Since 2.10, colors can also be specified by refering to a symbolic color, as
551 * follows: <literal>@<!-- -->color-name</literal>, or by using expressions to combine
552 * colors. The following expressions are currently supported:
555 * <term>mix (<replaceable>factor</replaceable>, <replaceable>color1</replaceable>, <replaceable>color2</replaceable>)</term>
557 * Computes a new color by mixing <replaceable>color1</replaceable> and
558 * <replaceable>color2</replaceable>. The <replaceable>factor</replaceable>
559 * determines how close the new color is to <replaceable>color1</replaceable>.
560 * A factor of 1.0 gives pure <replaceable>color1</replaceable>, a factor of
561 * 0.0 gives pure <replaceable>color2</replaceable>.
565 * <term>shade (<replaceable>factor</replaceable>, <replaceable>color</replaceable>)</term>
567 * Computes a lighter or darker variant of <replaceable>color</replaceable>.
568 * A <replaceable>factor</replaceable> of 1.0 leaves the color unchanged, smaller
569 * factors yield darker colors, larger factors yield lighter colors.
573 * <term>lighter (<replaceable>color</replaceable>)</term>
575 * This is an abbreviation for
576 * <literal>shade (1.3, <replaceable>color</replaceable>)</literal>.
580 * <term>darker (<replaceable>color</replaceable>)</term>
582 * This is an abbreviation for
583 * <literal>shade (0.7, <replaceable>color</replaceable>)</literal>.
588 * Here are some examples of color expressions:
590 * <informalexample><programlisting>
591 * mix (0.5, "red", "blue")
592 * shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 }))
593 * lighter (@<!-- -->foreground)
594 * </programlisting></informalexample>
596 * In a <literal>stock</literal> definition, icon sources are specified as a
597 * 4-tuple of image filename or icon name, text direction, widget state, and size, in that
598 * order. Each icon source specifies an image filename or icon name to use with a given
599 * direction, state, and size. Filenames are specified as a string such
600 * as <literal>"itemltr.png"</literal>, while icon names (looked up
601 * in the current icon theme), are specified with a leading
602 * <literal>@</literal>, such as <literal>@"item-ltr"</literal>.
603 * The <literal>*</literal> character can be used as a
604 * wildcard, and if direction/state/size are omitted they default to
605 * <literal>*</literal>. So for example, the following specifies different icons to
606 * use for left-to-right and right-to-left languages:
608 * <informalexample><programlisting>
609 * stock["my-stock-item"] =
611 * { "itemltr.png", LTR, *, * },
612 * { "itemrtl.png", RTL, *, * }
614 * </programlisting></informalexample>
616 * This could be abbreviated as follows:
618 * <informalexample><programlisting>
619 * stock["my-stock-item"] =
621 * { "itemltr.png", LTR },
622 * { "itemrtl.png", RTL }
624 * </programlisting></informalexample>
626 * You can specify custom icons for specific sizes, as follows:
628 * <informalexample><programlisting>
629 * stock["my-stock-item"] =
631 * { "itemmenusize.png", *, *, "gtk-menu" },
632 * { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
633 * { "itemgeneric.png" } // implicit *, *, * as a fallback
635 * </programlisting></informalexample>
637 * The sizes that come with GTK+ itself are <literal>"gtk-menu"</literal>,
638 * <literal>"gtk-small-toolbar"</literal>, <literal>"gtk-large-toolbar"</literal>,
639 * <literal>"gtk-button"</literal>, <literal>"gtk-dialog"</literal>. Applications
640 * can define other sizes.
642 * It's also possible to use custom icons for a given state, for example:
644 * <informalexample><programlisting>
645 * stock["my-stock-item"] =
647 * { "itemprelight.png", *, PRELIGHT },
648 * { "iteminsensitive.png", *, INSENSITIVE },
649 * { "itemgeneric.png" } // implicit *, *, * as a fallback
651 * </programlisting></informalexample>
653 * When selecting an icon source to use, GTK+ will consider text direction most
654 * important, state second, and size third. It will select the best match based on
655 * those criteria. If an attribute matches exactly (e.g. you specified
656 * <literal>PRELIGHT</literal> or specified the size), GTK+ won't modify the image;
657 * if the attribute matches with a wildcard, GTK+ will scale or modify the image to
658 * match the state and size the user requested.
662 * <title>Key bindings</title>
664 * Key bindings allow the user to specify actions to be
665 * taken on particular key presses. The form of a binding
666 * set declaration is:
668 * <informalexample><programlisting>
669 * binding <replaceable>name</replaceable> {
670 * bind <replaceable>key</replaceable> {
671 * <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
676 * </programlisting></informalexample>
678 * <replaceable>key</replaceable> is a string consisting of a
679 * series of modifiers followed by the name of a key. The
682 * <member><literal><alt></literal></member>
683 * <member><literal><ctl></literal></member>
684 * <member><literal><control></literal></member>
685 * <member><literal><meta></literal></member>
686 * <member><literal><hyper></literal></member>
687 * <member><literal><super></literal></member>
688 * <member><literal><mod1></literal></member>
689 * <member><literal><mod2></literal></member>
690 * <member><literal><mod3></literal></member>
691 * <member><literal><mod4></literal></member>
692 * <member><literal><mod5></literal></member>
693 * <member><literal><release></literal></member>
694 * <member><literal><shft></literal></member>
695 * <member><literal><shift></literal></member>
697 * <literal><shft></literal> is an alias for
698 * <literal><shift></literal>,
699 * <literal><ctl></literal> is an alias for
700 * <literal><control></literal>,
702 * <literal><alt></literal> is an alias for
703 * <literal><mod1></literal>.
705 * The action that is bound to the key is a sequence
706 * of signal names (strings) followed by parameters for
707 * each signal. The signals must be action signals.
708 * (See g_signal_new()). Each parameter can be
709 * a float, integer, string, or unquoted string
710 * representing an enumeration value. The types of
711 * the parameters specified must match the types of the
712 * parameters of the signal.
714 * Binding sets are connected to widgets in the same manner as styles,
715 * with one difference: Binding sets override other binding sets first
716 * by pattern type, then by priority and then by order of specification.
717 * The priorities that can be specified and their default values are the
718 * same as for styles.
742 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
744 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
746 struct _GtkRcStylePrivate
748 GSList *color_hashes;
751 static void gtk_rc_style_finalize (GObject *object);
752 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
754 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
755 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
756 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
757 gconstpointer bsearch_node2);
759 static void insert_rc_property (GtkRcStyle *style,
760 GtkRcProperty *property,
764 static const GScannerConfig gtk_rc_scanner_config =
768 ) /* cset_skip_characters */,
773 ) /* cset_identifier_first */,
779 ) /* cset_identifier_nth */,
780 ( "#\n" ) /* cpair_comment_single */,
782 TRUE /* case_sensitive */,
784 TRUE /* skip_comment_multi */,
785 TRUE /* skip_comment_single */,
786 TRUE /* scan_comment_multi */,
787 TRUE /* scan_identifier */,
788 FALSE /* scan_identifier_1char */,
789 FALSE /* scan_identifier_NULL */,
790 TRUE /* scan_symbols */,
791 TRUE /* scan_binary */,
792 TRUE /* scan_octal */,
793 TRUE /* scan_float */,
795 TRUE /* scan_hex_dollar */,
796 TRUE /* scan_string_sq */,
797 TRUE /* scan_string_dq */,
798 TRUE /* numbers_2_int */,
799 FALSE /* int_2_float */,
800 FALSE /* identifier_2_string */,
801 TRUE /* char_2_token */,
802 TRUE /* symbol_2_token */,
803 FALSE /* scope_0_fallback */,
806 static const gchar symbol_names[] =
850 { 0, GTK_RC_TOKEN_INCLUDE },
851 { 8, GTK_RC_TOKEN_NORMAL },
852 { 15, GTK_RC_TOKEN_ACTIVE },
853 { 22, GTK_RC_TOKEN_PRELIGHT },
854 { 31, GTK_RC_TOKEN_SELECTED },
855 { 40, GTK_RC_TOKEN_INSENSITIVE },
856 { 52, GTK_RC_TOKEN_FG },
857 { 55, GTK_RC_TOKEN_BG },
858 { 58, GTK_RC_TOKEN_TEXT },
859 { 63, GTK_RC_TOKEN_BASE },
860 { 68, GTK_RC_TOKEN_XTHICKNESS },
861 { 79, GTK_RC_TOKEN_YTHICKNESS },
862 { 90, GTK_RC_TOKEN_FONT },
863 { 95, GTK_RC_TOKEN_FONTSET },
864 { 103, GTK_RC_TOKEN_FONT_NAME },
865 { 113, GTK_RC_TOKEN_BG_PIXMAP },
866 { 123, GTK_RC_TOKEN_PIXMAP_PATH },
867 { 135, GTK_RC_TOKEN_STYLE },
868 { 141, GTK_RC_TOKEN_BINDING },
869 { 149, GTK_RC_TOKEN_BIND },
870 { 154, GTK_RC_TOKEN_WIDGET },
871 { 161, GTK_RC_TOKEN_WIDGET_CLASS },
872 { 174, GTK_RC_TOKEN_CLASS },
873 { 180, GTK_RC_TOKEN_LOWEST },
874 { 187, GTK_RC_TOKEN_GTK },
875 { 191, GTK_RC_TOKEN_APPLICATION },
876 { 203, GTK_RC_TOKEN_THEME },
877 { 209, GTK_RC_TOKEN_RC },
878 { 212, GTK_RC_TOKEN_HIGHEST },
879 { 220, GTK_RC_TOKEN_ENGINE },
880 { 227, GTK_RC_TOKEN_MODULE_PATH },
881 { 239, GTK_RC_TOKEN_STOCK },
882 { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
883 { 260, GTK_RC_TOKEN_LTR },
884 { 264, GTK_RC_TOKEN_RTL },
885 { 268, GTK_RC_TOKEN_COLOR },
886 { 274, GTK_RC_TOKEN_UNBIND }
889 static GHashTable *realized_style_ht = NULL;
891 static gchar *im_module_file = NULL;
893 static gchar **gtk_rc_default_files = NULL;
895 /* RC file handling */
898 gtk_rc_make_default_dir (const gchar *type)
903 var = g_getenv ("GTK_EXE_PREFIX");
906 path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
908 path = g_build_filename (GTK_LIBDIR, "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
914 * gtk_rc_get_im_module_path:
915 * @returns: (type filename): a newly-allocated string containing the
916 * path in which to look for IM modules.
918 * Obtains the path in which to look for IM modules. See the documentation
919 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
920 * environment variable for more details about looking up modules. This
921 * function is useful solely for utilities supplied with GTK+ and should
922 * not be used by applications under normal circumstances.
924 * Deprecated: 3.0: Use #GtkCssProvider instead.
927 gtk_rc_get_im_module_path (void)
929 gchar **paths = _gtk_get_module_path ("immodules");
930 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
937 * gtk_rc_get_im_module_file:
938 * @returns: (type filename): a newly-allocated string containing the
939 * name of the file listing the IM modules available for loading
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 * Deprecated: 3.0: Use #GtkCssProvider instead.
948 gtk_rc_get_im_module_file (void)
950 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
951 gchar *result = NULL;
954 result = g_strdup (var);
959 result = g_strdup (im_module_file);
961 result = gtk_rc_make_default_dir ("immodules.cache");
968 * gtk_rc_get_theme_dir:
970 * Returns the standard directory in which themes should
971 * be installed. (GTK+ does not actually use this directory
974 * Returns: The directory (must be freed with g_free()).
976 * Deprecated: 3.0: Use #GtkCssProvider instead.
979 gtk_rc_get_theme_dir (void)
984 var = g_getenv ("GTK_DATA_PREFIX");
987 path = g_build_filename (var, "share", "themes", NULL);
989 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
995 * gtk_rc_get_module_dir:
997 * Returns a directory in which GTK+ looks for theme engines.
998 * For full information about the search for theme engines,
999 * see the docs for <envar>GTK_PATH</envar> in
1000 * <xref linkend="gtk-running"/>.
1002 * return value: (type filename): the directory. (Must be freed with g_free())
1004 * Deprecated: 3.0: Use #GtkCssProvider instead.
1007 gtk_rc_get_module_dir (void)
1009 return gtk_rc_make_default_dir ("engines");
1013 * gtk_rc_add_default_file:
1014 * @filename: (type filename): the pathname to the file. If @filename
1015 * is not absolute, it is searched in the current directory.
1017 * Adds a file to the list of files to be parsed at the
1018 * end of gtk_init().
1020 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1023 gtk_rc_add_default_file (const gchar *filename)
1028 * gtk_rc_set_default_files:
1029 * @filenames: (array zero-terminated=1) (element-type filename): A
1030 * %NULL-terminated list of filenames.
1032 * Sets the list of files that GTK+ will read at the
1033 * end of gtk_init().
1035 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
1038 gtk_rc_set_default_files (gchar **filenames)
1043 * gtk_rc_get_default_files:
1045 * Retrieves the current list of RC files that will be parsed
1046 * at the end of gtk_init().
1048 * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
1049 * A %NULL-terminated array of filenames. This memory is owned
1050 * by GTK+ and must not be freed by the application. If you want
1051 * to store this information, you should make a copy.
1053 * Deprecated:3.0: Use #GtkStyleContext instead
1056 gtk_rc_get_default_files (void)
1058 return gtk_rc_default_files;
1062 * gtk_rc_parse_string:
1063 * @rc_string: a string to parse.
1065 * Parses resource information directly from a string.
1067 * Deprecated: 3.0: Use #GtkCssProvider instead.
1070 gtk_rc_parse_string (const gchar *rc_string)
1072 g_return_if_fail (rc_string != NULL);
1077 * @filename: the filename of a file to parse. If @filename is not absolute, it
1078 * is searched in the current directory.
1080 * Parses a given resource file.
1082 * Deprecated: 3.0: Use #GtkCssProvider instead.
1085 gtk_rc_parse (const gchar *filename)
1087 g_return_if_fail (filename != NULL);
1090 /* Handling of RC styles */
1092 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
1095 gtk_rc_style_init (GtkRcStyle *style)
1097 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1101 style->font_desc = NULL;
1103 for (i = 0; i < 5; i++)
1105 static const GdkColor init_color = { 0, 0, 0, 0, };
1107 style->bg_pixmap_name[i] = NULL;
1108 style->color_flags[i] = 0;
1109 style->fg[i] = init_color;
1110 style->bg[i] = init_color;
1111 style->text[i] = init_color;
1112 style->base[i] = init_color;
1114 style->xthickness = -1;
1115 style->ythickness = -1;
1116 style->rc_properties = NULL;
1118 style->rc_style_lists = NULL;
1119 style->icon_factories = NULL;
1121 priv->color_hashes = NULL;
1125 gtk_rc_style_class_init (GtkRcStyleClass *klass)
1127 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1129 object_class->finalize = gtk_rc_style_finalize;
1131 klass->parse = NULL;
1132 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
1133 klass->merge = gtk_rc_style_real_merge;
1134 klass->create_style = gtk_rc_style_real_create_style;
1136 g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
1140 gtk_rc_style_finalize (GObject *object)
1142 GSList *tmp_list1, *tmp_list2;
1143 GtkRcStyle *rc_style;
1144 GtkRcStylePrivate *rc_priv;
1147 rc_style = GTK_RC_STYLE (object);
1148 rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
1150 g_free (rc_style->name);
1151 if (rc_style->font_desc)
1152 pango_font_description_free (rc_style->font_desc);
1154 for (i = 0; i < 5; i++)
1155 g_free (rc_style->bg_pixmap_name[i]);
1157 /* Now remove all references to this rc_style from
1160 tmp_list1 = rc_style->rc_style_lists;
1163 GSList *rc_styles = tmp_list1->data;
1164 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
1165 g_object_unref (style);
1167 /* Remove the list of styles from the other rc_styles
1170 tmp_list2 = rc_styles;
1173 GtkRcStyle *other_style = tmp_list2->data;
1175 if (other_style != rc_style)
1176 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
1178 tmp_list2 = tmp_list2->next;
1181 /* And from the hash table itself
1183 g_hash_table_remove (realized_style_ht, rc_styles);
1184 g_slist_free (rc_styles);
1186 tmp_list1 = tmp_list1->next;
1188 g_slist_free (rc_style->rc_style_lists);
1190 if (rc_style->rc_properties)
1194 for (i = 0; i < rc_style->rc_properties->len; i++)
1196 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
1198 g_free (node->origin);
1199 g_value_unset (&node->value);
1201 g_array_free (rc_style->rc_properties, TRUE);
1202 rc_style->rc_properties = NULL;
1205 g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
1206 g_slist_free (rc_style->icon_factories);
1208 g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1209 g_slist_free (rc_priv->color_hashes);
1211 G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
1217 * Creates a new #GtkRcStyle with no fields set and
1218 * a reference count of 1.
1220 * Returns: the newly-created #GtkRcStyle
1222 * Deprecated: 3.0: Use #GtkCssProvider instead.
1225 gtk_rc_style_new (void)
1229 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
1235 * gtk_rc_style_copy:
1236 * @orig: the style to copy
1238 * Makes a copy of the specified #GtkRcStyle. This function
1239 * will correctly copy an RC style that is a member of a class
1240 * derived from #GtkRcStyle.
1242 * Return value: (transfer full): the resulting #GtkRcStyle
1244 * Deprecated: 3.0: Use #GtkCssProvider instead.
1247 gtk_rc_style_copy (GtkRcStyle *orig)
1251 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
1253 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
1254 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
1260 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
1262 return g_object_new (G_OBJECT_TYPE (style), NULL);
1266 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
1267 gconstpointer bsearch_node2)
1269 const GtkRcProperty *prop1 = bsearch_node1;
1270 const GtkRcProperty *prop2 = bsearch_node2;
1272 if (prop1->type_name == prop2->type_name)
1273 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
1275 return prop1->type_name < prop2->type_name ? -1 : 1;
1279 insert_rc_property (GtkRcStyle *style,
1280 GtkRcProperty *property,
1284 GtkRcProperty *new_property = NULL;
1285 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
1287 key.type_name = property->type_name;
1288 key.property_name = property->property_name;
1290 if (!style->rc_properties)
1291 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
1294 while (i < style->rc_properties->len)
1296 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
1302 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1304 g_free (new_property->origin);
1305 g_value_unset (&new_property->value);
1307 *new_property = key;
1321 g_array_insert_val (style->rc_properties, i, key);
1322 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
1325 new_property->origin = g_strdup (property->origin);
1326 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
1327 g_value_copy (&property->value, &new_property->value);
1331 gtk_rc_style_real_merge (GtkRcStyle *dest,
1336 for (i = 0; i < 5; i++)
1338 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
1339 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
1341 if (!(dest->color_flags[i] & GTK_RC_FG) &&
1342 src->color_flags[i] & GTK_RC_FG)
1344 dest->fg[i] = src->fg[i];
1345 dest->color_flags[i] |= GTK_RC_FG;
1347 if (!(dest->color_flags[i] & GTK_RC_BG) &&
1348 src->color_flags[i] & GTK_RC_BG)
1350 dest->bg[i] = src->bg[i];
1351 dest->color_flags[i] |= GTK_RC_BG;
1353 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
1354 src->color_flags[i] & GTK_RC_TEXT)
1356 dest->text[i] = src->text[i];
1357 dest->color_flags[i] |= GTK_RC_TEXT;
1359 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
1360 src->color_flags[i] & GTK_RC_BASE)
1362 dest->base[i] = src->base[i];
1363 dest->color_flags[i] |= GTK_RC_BASE;
1367 if (dest->xthickness < 0 && src->xthickness >= 0)
1368 dest->xthickness = src->xthickness;
1369 if (dest->ythickness < 0 && src->ythickness >= 0)
1370 dest->ythickness = src->ythickness;
1374 if (!dest->font_desc)
1375 dest->font_desc = pango_font_description_copy (src->font_desc);
1377 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
1380 if (src->rc_properties)
1384 for (i = 0; i < src->rc_properties->len; i++)
1385 insert_rc_property (dest,
1386 &g_array_index (src->rc_properties, GtkRcProperty, i),
1392 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
1394 return gtk_style_new ();
1398 * gtk_rc_reset_styles:
1399 * @settings: a #GtkSettings
1401 * This function recomputes the styles for all widgets that use a
1402 * particular #GtkSettings object. (There is one #GtkSettings object
1403 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
1404 * when some global parameter has changed that affects the appearance
1405 * of all widgets, because when a widget gets a new style, it will
1406 * both redraw and recompute any cached information about its
1407 * appearance. As an example, it is used when the default font size
1408 * set by the operating system changes. Note that this function
1409 * doesn't affect widgets that have a style set explicitely on them
1410 * with gtk_widget_set_style().
1414 * Deprecated: 3.0: Use #GtkCssProvider instead.
1417 gtk_rc_reset_styles (GtkSettings *settings)
1419 gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
1423 * gtk_rc_reparse_all_for_settings:
1424 * @settings: a #GtkSettings
1425 * @force_load: load whether or not anything changed
1427 * If the modification time on any previously read file
1428 * for the given #GtkSettings has changed, discard all style information
1429 * and then reread all previously read RC files.
1431 * Return value: %TRUE if the files were reread.
1433 * Deprecated: 3.0: Use #GtkCssProvider instead.
1436 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
1437 gboolean force_load)
1443 * gtk_rc_reparse_all:
1445 * If the modification time on any previously read file for the
1446 * default #GtkSettings has changed, discard all style information
1447 * and then reread all previously read RC files.
1449 * Return value: %TRUE if the files were reread.
1451 * Deprecated: 3.0: Use #GtkCssProvider instead.
1454 gtk_rc_reparse_all (void)
1461 * @widget: a #GtkWidget
1463 * Finds all matching RC styles for a given widget,
1464 * composites them together, and then creates a
1465 * #GtkStyle representing the composite appearance.
1466 * (GTK+ actually keeps a cache of previously
1467 * created styles, so a new style may not be
1470 * Returns: (transfer none): the resulting style. No refcount is added
1471 * to the returned style, so if you want to save this style around,
1472 * you should add a reference yourself.
1474 * Deprecated:3.0: Use #GtkStyleContext instead
1477 gtk_rc_get_style (GtkWidget *widget)
1479 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1481 gtk_widget_ensure_style (widget);
1483 return gtk_widget_get_style (widget);
1487 * gtk_rc_get_style_by_paths:
1488 * @settings: a #GtkSettings object
1489 * @widget_path: (allow-none): the widget path to use when looking up the
1490 * style, or %NULL if no matching against the widget path should be done
1491 * @class_path: (allow-none): the class path to use when looking up the style,
1492 * or %NULL if no matching against the class path should be done.
1493 * @type: a type that will be used along with parent types of this type
1494 * when matching against class styles, or #G_TYPE_NONE
1496 * Creates up a #GtkStyle from styles defined in a RC file by providing
1497 * the raw components used in matching. This function may be useful
1498 * when creating pseudo-widgets that should be themed like widgets but
1499 * don't actually have corresponding GTK+ widgets. An example of this
1500 * would be items inside a GNOME canvas widget.
1502 * The action of gtk_rc_get_style() is similar to:
1504 * gtk_widget_path (widget, NULL, &path, NULL);
1505 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
1506 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
1508 * G_OBJECT_TYPE (widget));
1511 * Return value: (transfer none): A style created by matching with the
1512 * supplied paths, or %NULL if nothing matching was specified and the
1513 * default style should be used. The returned value is owned by GTK+
1514 * as part of an internal cache, so you must call g_object_ref() on
1515 * the returned value if you want to keep a reference to it.
1517 * Deprecated:3.0: Use #GtkStyleContext instead
1520 gtk_rc_get_style_by_paths (GtkSettings *settings,
1521 const char *widget_path,
1522 const char *class_path,
1525 GtkWidgetPath *path;
1528 path = gtk_widget_path_new ();
1530 /* For compatibility, we return a GtkStyle based on a GtkStyleContext
1531 * with a GtkWidgetPath appropriate for the supplied information.
1533 * GtkWidgetPath is composed of a list of GTypes with optional names;
1534 * In GTK+-2.0, widget_path consisted of the widget names, or
1535 * the class names for unnamed widgets, while class_path had the
1536 * class names always. So, use class_path to determine the GTypes
1537 * and extract widget names from widget_path as applicable.
1539 if (class_path == NULL)
1541 gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
1545 const gchar *widget_p, *widget_next;
1546 const gchar *class_p, *class_next;
1548 widget_next = widget_path;
1549 class_next = class_path;
1553 GType component_type;
1554 gchar *component_class;
1555 gchar *component_name;
1558 class_p = class_next;
1559 if (*class_p == '.')
1562 widget_p = widget_next; /* Might be NULL */
1563 if (widget_p && *widget_p == '.')
1566 class_next = strchr (class_p, '.');
1567 if (class_next == NULL)
1568 class_next = class_p + strlen (class_p);
1572 widget_next = strchr (widget_p, '.');
1573 if (widget_next == NULL)
1574 widget_next = widget_p + strlen (widget_p);
1577 component_class = g_strndup (class_p, class_next - class_p);
1578 if (widget_p && *widget_p)
1579 component_name = g_strndup (widget_p, widget_next - widget_p);
1581 component_name = NULL;
1583 component_type = g_type_from_name (component_class);
1584 if (component_type == G_TYPE_INVALID)
1585 component_type = GTK_TYPE_WIDGET;
1587 pos = gtk_widget_path_append_type (path, component_type);
1588 if (component_name != NULL && strcmp (component_name, component_name) != 0)
1589 gtk_widget_path_iter_set_name (path, pos, component_name);
1591 g_free (component_class);
1592 g_free (component_name);
1596 style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
1599 gtk_widget_path_free (path);
1605 * gtk_rc_scanner_new: (skip)
1607 * Deprecated:3.0: Use #GtkCssProvider instead
1610 gtk_rc_scanner_new (void)
1612 return g_scanner_new (>k_rc_scanner_config);
1615 /*********************
1616 * Parsing functions *
1617 *********************/
1620 lookup_color (GtkRcStyle *style,
1621 const char *color_name,
1624 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
1627 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
1629 GHashTable *hash = iter->data;
1630 GdkColor *match = g_hash_table_lookup (hash, color_name);
1634 color->red = match->red;
1635 color->green = match->green;
1636 color->blue = match->blue;
1645 * gtk_rc_find_pixmap_in_path:
1646 * @settings: a #GtkSettings
1647 * @scanner: Scanner used to get line number information for the
1648 * warning message, or %NULL
1649 * @pixmap_file: name of the pixmap file to locate.
1651 * Looks up a file in pixmap path for the specified #GtkSettings.
1652 * If the file is not found, it outputs a warning message using
1653 * g_warning() and returns %NULL.
1655 * Return value: (type filename): the filename.
1657 * Deprecated: 3.0: Use #GtkCssProvider instead.
1660 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
1662 const gchar *pixmap_file)
1664 g_warning ("Unable to locate image file in pixmap_path: \"%s\"",
1670 * gtk_rc_find_module_in_path:
1671 * @module_file: name of a theme engine
1673 * Searches for a theme engine in the GTK+ search path. This function
1674 * is not useful for applications and should not be used.
1676 * Return value: (type filename): The filename, if found (must be
1677 * freed with g_free()), otherwise %NULL.
1679 * Deprecated: 3.0: Use #GtkCssProvider instead.
1682 gtk_rc_find_module_in_path (const gchar *module_file)
1684 return _gtk_find_module (module_file, "engines");
1688 * gtk_rc_parse_state:
1689 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1690 * @state: (out): A pointer to a #GtkStateType variable in which to
1693 * Parses a #GtkStateType variable from the format expected
1696 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1697 * that was expected but not found.
1699 * Deprecated: 3.0: Use #GtkCssProvider instead
1702 gtk_rc_parse_state (GScanner *scanner,
1703 GtkStateType *state)
1708 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1709 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
1711 /* we don't know where we got called from, so we reset the scope here.
1712 * if we bail out due to errors, we *don't* reset the scope, so the
1713 * error messaging code can make sense of our tokens.
1715 old_scope = g_scanner_set_scope (scanner, 0);
1717 token = g_scanner_get_next_token (scanner);
1718 if (token != G_TOKEN_LEFT_BRACE)
1719 return G_TOKEN_LEFT_BRACE;
1721 token = g_scanner_get_next_token (scanner);
1724 case GTK_RC_TOKEN_ACTIVE:
1725 *state = GTK_STATE_ACTIVE;
1727 case GTK_RC_TOKEN_INSENSITIVE:
1728 *state = GTK_STATE_INSENSITIVE;
1730 case GTK_RC_TOKEN_NORMAL:
1731 *state = GTK_STATE_NORMAL;
1733 case GTK_RC_TOKEN_PRELIGHT:
1734 *state = GTK_STATE_PRELIGHT;
1736 case GTK_RC_TOKEN_SELECTED:
1737 *state = GTK_STATE_SELECTED;
1740 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1743 token = g_scanner_get_next_token (scanner);
1744 if (token != G_TOKEN_RIGHT_BRACE)
1745 return G_TOKEN_RIGHT_BRACE;
1747 g_scanner_set_scope (scanner, old_scope);
1749 return G_TOKEN_NONE;
1753 * gtk_rc_parse_priority:
1754 * @scanner: a #GtkScanner (must be initialized for parsing an RC file)
1755 * @priority: A pointer to #GtkPathPriorityType variable in which
1756 * to store the result.
1758 * Parses a #GtkPathPriorityType variable from the format expected
1761 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1762 * that was expected but not found.
1764 * Deprecated:3.0: Use #GtkCssProvider instead
1767 gtk_rc_parse_priority (GScanner *scanner,
1768 GtkPathPriorityType *priority)
1773 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1774 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1776 /* we don't know where we got called from, so we reset the scope here.
1777 * if we bail out due to errors, we *don't* reset the scope, so the
1778 * error messaging code can make sense of our tokens.
1780 old_scope = g_scanner_set_scope (scanner, 0);
1782 token = g_scanner_get_next_token (scanner);
1786 token = g_scanner_get_next_token (scanner);
1789 case GTK_RC_TOKEN_LOWEST:
1790 *priority = GTK_PATH_PRIO_LOWEST;
1792 case GTK_RC_TOKEN_GTK:
1793 *priority = GTK_PATH_PRIO_GTK;
1795 case GTK_RC_TOKEN_APPLICATION:
1796 *priority = GTK_PATH_PRIO_APPLICATION;
1798 case GTK_RC_TOKEN_THEME:
1799 *priority = GTK_PATH_PRIO_THEME;
1801 case GTK_RC_TOKEN_RC:
1802 *priority = GTK_PATH_PRIO_RC;
1804 case GTK_RC_TOKEN_HIGHEST:
1805 *priority = GTK_PATH_PRIO_HIGHEST;
1808 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1811 g_scanner_set_scope (scanner, old_scope);
1813 return G_TOKEN_NONE;
1817 * gtk_rc_parse_color:
1818 * @scanner: a #GScanner
1819 * @color: (out): a pointer to a #GdkColor structure in which to store
1822 * Parses a color in the <link linkend="color=format">format</link> expected
1825 * Note that theme engines should use gtk_rc_parse_color_full() in
1826 * order to support symbolic colors.
1828 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1829 * that was expected but not found
1831 * Deprecated:3.0: Use #GtkCssProvider instead
1834 gtk_rc_parse_color (GScanner *scanner,
1837 return gtk_rc_parse_color_full (scanner, NULL, color);
1841 * gtk_rc_parse_color_full:
1842 * @scanner: a #GScanner
1843 * @style: (allow-none): a #GtkRcStyle, or %NULL
1844 * @color: (out): a pointer to a #GdkColor structure in which to store
1847 * Parses a color in the <link linkend="color=format">format</link> expected
1848 * in a RC file. If @style is not %NULL, it will be consulted to resolve
1849 * references to symbolic colors.
1851 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1852 * that was expected but not found
1856 * Deprecated:3.0: Use #GtkCssProvider instead
1859 gtk_rc_parse_color_full (GScanner *scanner,
1865 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1867 /* we don't need to set our own scope here, because
1868 * we don't need own symbols
1871 token = g_scanner_get_next_token (scanner);
1879 case G_TOKEN_LEFT_CURLY:
1880 token = g_scanner_get_next_token (scanner);
1881 if (token == G_TOKEN_INT)
1882 token_int = scanner->value.v_int;
1883 else if (token == G_TOKEN_FLOAT)
1884 token_int = scanner->value.v_float * 65535.0;
1886 return G_TOKEN_FLOAT;
1887 color->red = CLAMP (token_int, 0, 65535);
1889 token = g_scanner_get_next_token (scanner);
1890 if (token != G_TOKEN_COMMA)
1891 return G_TOKEN_COMMA;
1893 token = g_scanner_get_next_token (scanner);
1894 if (token == G_TOKEN_INT)
1895 token_int = scanner->value.v_int;
1896 else if (token == G_TOKEN_FLOAT)
1897 token_int = scanner->value.v_float * 65535.0;
1899 return G_TOKEN_FLOAT;
1900 color->green = CLAMP (token_int, 0, 65535);
1902 token = g_scanner_get_next_token (scanner);
1903 if (token != G_TOKEN_COMMA)
1904 return G_TOKEN_COMMA;
1906 token = g_scanner_get_next_token (scanner);
1907 if (token == G_TOKEN_INT)
1908 token_int = scanner->value.v_int;
1909 else if (token == G_TOKEN_FLOAT)
1910 token_int = scanner->value.v_float * 65535.0;
1912 return G_TOKEN_FLOAT;
1913 color->blue = CLAMP (token_int, 0, 65535);
1915 token = g_scanner_get_next_token (scanner);
1916 if (token != G_TOKEN_RIGHT_CURLY)
1917 return G_TOKEN_RIGHT_CURLY;
1918 return G_TOKEN_NONE;
1920 case G_TOKEN_STRING:
1921 if (!gdk_color_parse (scanner->value.v_string, color))
1923 g_scanner_warn (scanner, "Invalid color constant '%s'",
1924 scanner->value.v_string);
1925 return G_TOKEN_STRING;
1927 return G_TOKEN_NONE;
1930 token = g_scanner_get_next_token (scanner);
1931 if (token != G_TOKEN_IDENTIFIER)
1932 return G_TOKEN_IDENTIFIER;
1934 if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1936 g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1937 scanner->value.v_identifier);
1938 return G_TOKEN_IDENTIFIER;
1941 return G_TOKEN_NONE;
1943 case G_TOKEN_IDENTIFIER:
1944 if (strcmp (scanner->value.v_identifier, "mix") == 0)
1946 token = g_scanner_get_next_token (scanner);
1947 if (token != G_TOKEN_LEFT_PAREN)
1948 return G_TOKEN_LEFT_PAREN;
1951 if (g_scanner_peek_next_token (scanner) == '-')
1953 g_scanner_get_next_token (scanner); /* eat sign */
1957 token = g_scanner_get_next_token (scanner);
1958 if (token != G_TOKEN_FLOAT)
1959 return G_TOKEN_FLOAT;
1961 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1963 token = g_scanner_get_next_token (scanner);
1964 if (token != G_TOKEN_COMMA)
1965 return G_TOKEN_COMMA;
1967 token = gtk_rc_parse_color_full (scanner, style, &c1);
1968 if (token != G_TOKEN_NONE)
1971 token = g_scanner_get_next_token (scanner);
1972 if (token != G_TOKEN_COMMA)
1973 return G_TOKEN_COMMA;
1975 token = gtk_rc_parse_color_full (scanner, style, &c2);
1976 if (token != G_TOKEN_NONE)
1979 token = g_scanner_get_next_token (scanner);
1980 if (token != G_TOKEN_RIGHT_PAREN)
1981 return G_TOKEN_RIGHT_PAREN;
1983 color->red = l * c1.red + (1.0 - l) * c2.red;
1984 color->green = l * c1.green + (1.0 - l) * c2.green;
1985 color->blue = l * c1.blue + (1.0 - l) * c2.blue;
1987 return G_TOKEN_NONE;
1989 else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1991 token = g_scanner_get_next_token (scanner);
1992 if (token != G_TOKEN_LEFT_PAREN)
1993 return G_TOKEN_LEFT_PAREN;
1996 if (g_scanner_peek_next_token (scanner) == '-')
1998 g_scanner_get_next_token (scanner); /* eat sign */
2002 token = g_scanner_get_next_token (scanner);
2003 if (token != G_TOKEN_FLOAT)
2004 return G_TOKEN_FLOAT;
2006 l = negate ? -scanner->value.v_float : scanner->value.v_float;
2008 token = g_scanner_get_next_token (scanner);
2009 if (token != G_TOKEN_COMMA)
2010 return G_TOKEN_COMMA;
2012 token = gtk_rc_parse_color_full (scanner, style, &c1);
2013 if (token != G_TOKEN_NONE)
2016 token = g_scanner_get_next_token (scanner);
2017 if (token != G_TOKEN_RIGHT_PAREN)
2018 return G_TOKEN_RIGHT_PAREN;
2020 _gtk_style_shade (&c1, color, l);
2022 return G_TOKEN_NONE;
2024 else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
2025 strcmp (scanner->value.v_identifier, "darker") == 0)
2027 if (scanner->value.v_identifier[0] == 'l')
2032 token = g_scanner_get_next_token (scanner);
2033 if (token != G_TOKEN_LEFT_PAREN)
2034 return G_TOKEN_LEFT_PAREN;
2036 token = gtk_rc_parse_color_full (scanner, style, &c1);
2037 if (token != G_TOKEN_NONE)
2040 token = g_scanner_get_next_token (scanner);
2041 if (token != G_TOKEN_RIGHT_PAREN)
2042 return G_TOKEN_RIGHT_PAREN;
2044 _gtk_style_shade (&c1, color, l);
2046 return G_TOKEN_NONE;
2049 return G_TOKEN_IDENTIFIER;
2052 return G_TOKEN_STRING;