1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Routines for handling resource files
7 <!-- ##### SECTION Long_Description ##### -->
9 GTK+ provides resource file mechanism for configuring
10 various aspects of the operation of a GTK+ program
14 <refsect2><title>Default files</title>
16 An application can cause GTK+ to parse a specific RC
17 file by calling gtk_rc_parse(). In addition to this,
18 certain files will be read at the end of gtk_init().
19 Unless modified, the files looked for will be
20 <filename><SYSCONFDIR>/gtk-2.0/gtkrc</filename>
21 and <filename>.gtkrc-2.0</filename> in the users home directory.
22 (<filename><SYSCONFDIR></filename> defaults to
23 <filename>/usr/local/etc</filename>. It can be changed with the
24 <option>--prefix</option> or <option>--sysconfdir</option> options when
28 The set of these <firstterm>default</firstterm> files
29 can be retrieved with gtk_rc_get_default_files()
30 and modified with gtk_rc_add_default_file() and
31 gtk_rc_set_default_files().
32 Additionally, the <envar>GTK_RC_FILES</envar> environment variable
33 can be set to a #G_SEARCHPATH_SEPARATOR_S-separated list of files
34 in order to overwrite the set of default files at runtime.
36 <para><anchor id="locale-specific-rc">
37 For each RC file, in addition to the file itself, GTK+ will look for
38 a locale-specific file that will be parsed after the main file.
39 For instance, if <envar>LANG</envar> is set to <literal>ja_JP.ujis</literal>,
40 when loading the default file <filename>~/.gtkrc</filename> then GTK+ looks
41 for <filename>~/.gtkrc.ja_JP</filename> and <filename>~/.gtkrc.ja</filename>,
42 and parses the first of those that exists.
46 <refsect2><title>Pathnames and patterns</title>
48 A resource file defines a number of styles and key bindings and
49 attaches them to particular widgets. The attachment is done
50 by the <literal>widget</literal>, <literal>widget_class</literal>,
51 and <literal>class</literal> declarations. As an example
53 <informalexample><programlisting>
54 widget "mywindow.*.GtkEntry" style "my-entry-class"
55 </programlisting></informalexample>
56 attaches the style <literal>"my-entry-class"</literal>
57 to all widgets whose <firstterm>widget class</firstterm>
58 matches the <firstterm>pattern</firstterm>
59 <literal>"mywindow.*.GtkEntry"</literal>.
62 The patterns here are given in the standard shell glob
63 syntax. The <literal>"?"</literal> wildcard matches
64 any character, while <literal>"*"</literal> matches
65 zero or more of any character. The three types of
66 matching are against the widget path, the
67 <firstterm>class path</firstterm> and the class
68 hierarchy. Both the widget and the class paths consists of a
69 <literal>"."</literal> separated list of all the
70 parents of the widget and the widget itself from
71 outermost to innermost. The difference is that in
72 the widget path, the name assigned by
73 gtk_widget_set_name() is used
74 if present, otherwise the class name of the widget, while
75 for the widget path, the class name is always used.
78 So, if you have a #GtkEntry named
79 <literal>"myentry"</literal>, inside of a of a window
80 named <literal>"mywindow"</literal>, then the
81 widget path is: <literal>"mwindow.GtkHBox.myentry"</literal>
82 while the class path is: <literal>"GtkWindow.GtkHBox.GtkEntry"</literal>.
85 Matching against class is a little different. The pattern
86 match is done against all class names in the widgets
87 class hierarchy (not the layout hierarchy) in sequence, so the
89 <informalexample><programlisting>
90 class "GtkButton" style "my-style"
91 </programlisting></informalexample>
92 will match not just #GtkButton widgets,
93 but also #GtkToggleButton and
94 #GtkCheckButton widgets, since
95 those classes derive from #GtkButton.
99 <refsect2><title>Toplevel declarations</title>
101 An RC file is a text file which is composed of a sequence
102 of declarations. <literal>'#'</literal> characters delimit comments and
103 the portion of a line after a <literal>'#'</literal> is ignored when parsing
108 The possible toplevel declarations are:
112 <term><literal>binding <replaceable>name</replaceable>
113 { ... }</literal></term>
115 <para>Declares a binding set.</para>
119 <term><literal>class <replaceable>pattern</replaceable>
120 [ style | binding [ : <replaceable>priority</replaceable> ]]
121 <replaceable>name</replaceable></literal></term>
123 <para>Specifies a style or binding set for a particular
124 branch of the inheritance hierarchy.</para>
128 <term><literal>include <replaceable>filename</replaceable></literal></term>
130 <para>Parses another file at this point. If
131 <replaceable>filename</replaceable> is not an absolute filename,
132 it is searched in the directories of the currently open RC files.
134 <para>GTK+ also tries to load a
135 <link linkend="locale-specific-rc">locale-specific variant</link> of
141 <term><literal>module_path <replaceable>path</replaceable></literal></term>
143 <para>Sets a path (a list of directories separated
144 by colons) that will be searched for theme engines referenced in
149 <term><literal>pixmap_path <replaceable>path</replaceable></literal></term>
151 <para>Sets a path (a list of directories separated
152 by colons) that will be searched for pixmaps referenced in
157 <term><literal>style <replaceable>name</replaceable> [ =
158 <replaceable>parent</replaceable> ] { ... }</literal></term>
160 <para>Declares a style.</para>
164 <term><literal>widget <replaceable>pattern</replaceable>
165 [ style | binding [ : <replaceable>priority</replaceable> ]]
166 <replaceable>name</replaceable></literal></term>
168 <para>Specifies a style or binding set for a particular
169 group of widgets by matching on the widget pathname.</para>
173 <term><literal>widget_class <replaceable>pattern</replaceable>
174 [ style | binding [ : <replaceable>priority</replaceable> ]]
175 <replaceable>name</replaceable></literal></term>
177 <para>Specifies a style or binding set for a particular
178 group of widgets by matching on the class pathname.</para>
185 <refsect2><title>Styles</title>
187 A RC style is specified by a <literal>style</literal>
188 declaration in a RC file, and then bound to widgets
189 with a <literal>widget</literal>, <literal>widget_class</literal>,
190 or <literal>class</literal> declaration. All styles
191 applying to a particular widget are composited together
192 with <literal>widget</literal> declarations overriding
193 <literal>widget_class</literal> declarations which, in
194 turn, override <literal>class</literal> declarations.
195 Within each type of declaration, later declarations override
200 Within a <literal>style</literal> declaration, the possible
205 <term><literal>bg[<replaceable>state</replaceable>] =
206 <replaceable>color</replaceable></literal></term>
209 Sets the color used for the background of most widgets.
214 <term><literal>fg[<replaceable>state</replaceable>] =
215 <replaceable>color</replaceable></literal></term>
218 Sets the color used for the foreground of most widgets.
223 <term><literal>base[<replaceable>state</replaceable>] =
224 <replaceable>color</replaceable></literal></term>
227 Sets the color used for the background of widgets displaying
228 editable text. This color is used for the background
229 of, among others, #GtkText, #GtkEntry, #GtkList, and #GtkClist.
234 <term><literal>text[<replaceable>state</replaceable>] =
235 <replaceable>color</replaceable></literal></term>
238 Sets the color used for foreground of widgets using
239 <literal>base</literal> for the background color.
244 <term><literal>bg_pixmap[<replaceable>state</replaceable>] =
245 <replaceable>pixmap</replaceable></literal></term>
248 Sets a background pixmap to be used in place of
249 the <literal>bg</literal> color (or for #GtkText,
250 in place of the <literal>base</literal> color. The special
251 value <literal>"<parent>"</literal> may be used to indicate that the widget should
252 use the same background pixmap as its parent. The special value
253 <literal>"<none>"</literal> may be used to indicate no background pixmap.
258 <term><literal>font = <replaceable>font</replaceable></literal></term>
261 Sets the font for a widget. <replaceable>font</replaceable> must be
262 a XLFD font description, e.g.
263 <literal>"-*-helvetica-medium-r-normal--10-*-*-*-*-*-*-*"</literal>.
268 <term><literal>fontset = <replaceable>font</replaceable></literal></term>
271 Sets the fontset for a widget. Overrides any
272 <literal>font</literal> declarations. <replaceable>font</replaceable>
273 must be a comma-separated list of XLFD font descriptions, e.g.
274 <literal>"-JIS-Fixed-Medium-R-Normal--26-180-100-100-C-240,
275 -JIS-Fixed-Medium-R-Normal--26-180-100-100-C-120,
276 -GB-Fixed-Medium-R-Normal--26-180-100-100-C-240,
277 -Adobe-Courier-Bold-R-Normal--25-180-100-100-M-150"</literal>.
282 <term><literal>font_name = <replaceable>font</replaceable></literal></term>
285 Sets the font for a widget. Overrides any
286 <literal>font</literal> or <literal>fontset</literal> declarations.
287 <replaceable>font</replaceable> must be a Pango font name, e.g.
288 <literal>"Sans Italic 10"</literal>.
293 <term><literal>stock[<replaceable>"stock-id"</replaceable>] = { <replaceable>icon source specifications</replaceable> }</literal></term>
296 Defines the icon for a stock item.
301 <term><literal>engine <replaceable>"engine"</replaceable> { <replaceable>engine-specific
302 settings</replaceable> }</literal></term>
305 Defines the engine to be used when drawing with this style.
312 The colors and background pixmaps are specified as a function of the
313 state of the widget. The states are:
317 <term><literal>NORMAL</literal></term>
320 A color used for a widget in its normal state.
325 <term><literal>ACTIVE</literal></term>
328 A variant of the <literal>NORMAL</literal> color used when the
329 widget is in the %GTK_STATE_ACTIVE state, and also for
330 the trough of a ScrollBar, tabs of a NoteBook
331 other than the current tab and similar areas.
332 Frequently, this should be a darker variant
333 of the <literal>NORMAL</literal> color.
338 <term><literal>PRELIGHT</literal></term>
341 A color used for widgets in the %GTK_STATE_PRELIGHT state. This
342 state is the used for Buttons and MenuItems
343 that have the mouse cursor over them, and for
349 <term><literal>SELECTED</literal></term>
352 A color used to highlight data selected by the user.
353 for instance, the selected items in a list widget, and the
354 selection in an editable widget.
359 <term><literal>INSENSITIVE</literal></term>
362 A color used for the background of widgets that have
363 been set insensitive with gtk_widget_set_sensitive().
370 <para><anchor id="color-format">
371 Colors can be specified as a string containing a color name (GTK+ knows
372 all names from the X color database
373 <filename>/usr/lib/X11/rgb.txt</filename>),
374 in one of the hexadecimal forms <literal>&hash;rrrrggggbbbb</literal>,
375 <literal>&hash;rrrgggbbb</literal>, <literal>&hash;rrggbb</literal>,
376 or <literal>&hash;rgb</literal>, where <literal>r</literal>,
377 <literal>g</literal> and <literal>b</literal> are
378 hex digits, or they can be specified as a triplet
379 <literal>{ <replaceable>r</replaceable>, <replaceable>g</replaceable>,
380 <replaceable>b</replaceable>}</literal>, where <literal>r</literal>,
381 <literal>g</literal> and <literal>b</literal> are either integers in
382 the range 0-65635 or floats in the range 0.0-1.0.
386 In a <literal>stock</literal> definition, icon sources are specified as a
387 4-tuple of image filename, text direction, widget state, and size, in that
388 order. Each icon source specifies an image filename to use with a given
389 direction, state, and size. The <literal>*</literal> character can be used as a
390 wildcard, and if direction/state/size are omitted they default to
391 <literal>*</literal>. So for example, the following specifies different icons to
392 use for left-to-right and right-to-left languages:
393 <informalexample><programlisting>
394 stock["my-stock-item"] =
396 { "itemltr.png", LTR, *, * },
397 { "itemrtl.png", RTL, *, * }
399 </programlisting></informalexample>
400 This could be abbreviated as follows:
401 <informalexample><programlisting>
402 stock["my-stock-item"] =
404 { "itemltr.png", LTR },
405 { "itemrtl.png", RTL }
407 </programlisting></informalexample>
411 You can specify custom icons for specific sizes, as follows:
412 <informalexample><programlisting>
413 stock["my-stock-item"] =
415 { "itemmenusize.png", *, *, "gtk-menu" },
416 { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
417 { "itemgeneric.png" } /* implicit *, *, * as a fallback */
419 </programlisting></informalexample>
420 The sizes that come with GTK+ itself are <literal>"gtk-menu"</literal>,
421 <literal>"gtk-small-toolbar"</literal>, <literal>"gtk-large-toolbar"</literal>,
422 <literal>"gtk-button"</literal>, <literal>"gtk-dialog"</literal>. Applications
423 can define other sizes.
427 It's also possible to use custom icons for a given state, for example:
428 <informalexample><programlisting>
429 stock["my-stock-item"] =
431 { "itemprelight.png", *, PRELIGHT },
432 { "iteminsensitive.png", *, INSENSITIVE },
433 { "itemgeneric.png" } /* implicit *, *, * as a fallback */
435 </programlisting></informalexample>
439 When selecting an icon source to use, GTK+ will consider text direction most
440 important, state second, and size third. It will select the best match based on
441 those criteria. If an attribute matches exactly (e.g. you specified
442 <literal>PRELIGHT</literal> or specified the size), GTK+ won't modify the image;
443 if the attribute matches with a wildcard, GTK+ will scale or modify the image to
444 match the state and size the user requested.
449 <refsect2><title>Key bindings</title>
451 Key bindings allow the user to specify actions to be
452 taken on particular key presses. The form of a binding
456 <informalexample><programlisting>
457 binding <replaceable>name</replaceable> {
458 bind <replaceable>key</replaceable> {
459 <replaceable>signalname</replaceable> (<replaceable>param</replaceable>, ...)
464 </programlisting></informalexample>
467 <replaceable>key</replaceable> is a string consisting of a
468 series of modifiers followed by the name of a key. The
471 <member><literal><alt></literal></member>
472 <member><literal><control></literal></member>
473 <member><literal><mod1></literal></member>
474 <member><literal><mod2></literal></member>
475 <member><literal><mod3></literal></member>
476 <member><literal><mod4></literal></member>
477 <member><literal><mod5></literal></member>
478 <member><literal><release></literal></member>
479 <member><literal><shft></literal></member>
480 <member><literal><shift></literal></member>
482 <literal><shft></literal> is an alias for
483 <literal><shift></literal> and
484 <literal><alt></literal> is an alias for
485 <literal><mod1></literal>.
489 The action that is bound to the key is a sequence
490 of signal names (strings) followed by parameters for
491 each signal. The signals must be action signals.
492 (See g_signal_new()). Each parameter can be
493 a float, integer, string, or unquoted string
494 representing an enumeration value. The types of
495 the parameters specified must match the types of the
496 parameters of the signal.
500 Binding sets are connected to widgets in the
501 same manner as styles, with one addition.
502 A priority can be specified for each pattern,
503 and within each type of pattern, binding sets
504 override other binding sets first by priority,
505 and only then by order of specification. (Later
506 overrides earlier). The priorities that can
507 be specified are (highest to lowest):
509 <member><literal>highest</literal></member>
510 <member><literal>rc</literal></member>
511 <member><literal>theme</literal></member>
512 <member><literal>application</literal></member>
513 <member><literal>gtk</literal></member>
514 <member><literal>lowest</literal></member>
516 <literal>rc</literal> is the default for bindings
517 read from an RC file, <literal>theme</literal>
518 is the default for bindings read from theme RC files,
519 <literal>application</literal>
520 should be used for bindings an application sets
521 up, and <literal>gtk</literal> is used for bindings
522 that GTK+ creates internally.
526 <!-- ##### SECTION See_Also ##### -->
531 <!-- ##### STRUCT GtkRcStyle ##### -->
533 The #GtkRcStyle structure is used to represent a set
534 of information about the appearance of a widget.
535 This can later be composited together with other
536 #GtkRcStyle structures to form a #GtkStyle.
550 <!-- ##### ENUM GtkRcFlags ##### -->
552 The #GtkRcFlags enumeration is used as a bitmask
553 to specify which fields of a #GtkRcStyle have been
557 @GTK_RC_FG: If present, the foreground color has been set for this state.
558 @GTK_RC_BG: If present, the background color has been set for this state.
559 @GTK_RC_TEXT: If present, the text color has been set for this state.
560 @GTK_RC_BASE: If present, the base color has been set for this state.
562 <!-- ##### ENUM GtkRcTokenType ##### -->
564 The #GtkRcTokenType enumeration represents the tokens
565 in the RC file. It is exposed so that theme engines
566 can reuse these tokens when parsing the theme-engine
567 specific portions of a RC file.
570 @GTK_RC_TOKEN_INVALID:
571 @GTK_RC_TOKEN_INCLUDE:
572 @GTK_RC_TOKEN_NORMAL:
573 @GTK_RC_TOKEN_ACTIVE:
574 @GTK_RC_TOKEN_PRELIGHT:
575 @GTK_RC_TOKEN_SELECTED:
576 @GTK_RC_TOKEN_INSENSITIVE:
581 @GTK_RC_TOKEN_XTHICKNESS:
582 @GTK_RC_TOKEN_YTHICKNESS:
584 @GTK_RC_TOKEN_FONTSET:
585 @GTK_RC_TOKEN_FONT_NAME:
586 @GTK_RC_TOKEN_BG_PIXMAP:
587 @GTK_RC_TOKEN_PIXMAP_PATH:
589 @GTK_RC_TOKEN_BINDING:
591 @GTK_RC_TOKEN_WIDGET:
592 @GTK_RC_TOKEN_WIDGET_CLASS:
594 @GTK_RC_TOKEN_LOWEST:
596 @GTK_RC_TOKEN_APPLICATION:
599 @GTK_RC_TOKEN_HIGHEST:
600 @GTK_RC_TOKEN_ENGINE:
601 @GTK_RC_TOKEN_MODULE_PATH:
602 @GTK_RC_TOKEN_IM_MODULE_PATH:
603 @GTK_RC_TOKEN_IM_MODULE_FILE:
609 <!-- ##### FUNCTION gtk_rc_scanner_new ##### -->
617 <!-- ##### FUNCTION gtk_rc_get_style ##### -->
625 <!-- ##### FUNCTION gtk_rc_get_style_by_paths ##### -->
637 <!-- ##### FUNCTION gtk_rc_add_widget_name_style ##### -->
639 Adds a #GtkRcStyle that will be looked up by a match against
640 the widget's pathname. This is equivalent to a:
642 widget PATTERN style STYLE
644 statement in a RC file.
647 @rc_style: the #GtkRcStyle to use for widgets matching @pattern
648 @pattern: the pattern
651 <!-- ##### FUNCTION gtk_rc_add_widget_class_style ##### -->
653 Adds a #GtkRcStyle that will be looked up by a match against
654 the widget's class pathname. This is equivalent to a:
656 widget_class PATTERN style STYLE
658 statement in a RC file.
661 @rc_style: the #GtkRcStyle to use for widgets matching @pattern
662 @pattern: the pattern
665 <!-- ##### FUNCTION gtk_rc_add_class_style ##### -->
667 Adds a #GtkRcStyle that will be looked up by a matching against
668 the class hierarchy of the widget. This is equivalent to a:
670 class PATTERN style STYLE
672 statement in a RC file.
675 @rc_style: the #GtkRcStyle to use for widgets deriving from @pattern
676 @pattern: the pattern
679 <!-- ##### FUNCTION gtk_rc_parse ##### -->
681 Parses a given resource file.
684 @filename: the filename of a file to parse. If @filename is not absolute, it
685 is searched in the current directory.
688 <!-- ##### FUNCTION gtk_rc_parse_string ##### -->
690 Parses resource information directly from a string.
693 @rc_string: a string to parse.
696 <!-- ##### FUNCTION gtk_rc_reparse_all ##### -->
703 <!-- ##### FUNCTION gtk_rc_reparse_all_for_settings ##### -->
713 <!-- ##### FUNCTION gtk_rc_add_default_file ##### -->
720 <!-- ##### FUNCTION gtk_rc_get_default_files ##### -->
727 <!-- ##### FUNCTION gtk_rc_set_default_files ##### -->
734 <!-- ##### FUNCTION gtk_rc_parse_color ##### -->
736 Parses a color in the <link linkend="color-format">format</link> expected in a RC file.
739 @scanner: a #GtkScanner
740 @color: a pointer to a #GtkColor structure in which to store the result
741 @Returns: %G_TOKEN_NONE if parsing suceeded, otherwise the token
742 that was expected but not found.
745 <!-- ##### FUNCTION gtk_rc_parse_state ##### -->
747 Parses a #GtkStateType variable from the format expected
751 @scanner: a #GtkScanner (must be initialized for parsing an RC file)
752 @state: A pointer to a #GtkStateType variable in which to
754 @Returns: %G_TOKEN_NONE if parsing suceeded, otherwise the token
755 that was expected but not found.
758 <!-- ##### FUNCTION gtk_rc_parse_priority ##### -->
760 Parses a #GtkPathPriorityType variable from the format expected
764 @scanner: a #GtkScanner (must be initialized for parsing an RC file)
765 @priority: A pointer to #GtkPathPriorityType variable in which
767 @Returns: %G_TOKEN_NONE if parsing suceeded, otherwise the token
768 that was expected but not found.
771 <!-- ##### FUNCTION gtk_rc_find_module_in_path ##### -->
775 @module_file: The name of the module to search for.
779 <!-- ##### FUNCTION gtk_rc_find_pixmap_in_path ##### -->
784 @scanner: a #GtkScanner. Used for printing out warning messages
785 if the file is not found.
786 @pixmap_file: The name of the file to search for.
787 @Returns: The filename, if found (must be freed with g_free()),
789 <!-- # Unused Parameters # -->
793 <!-- ##### FUNCTION gtk_rc_get_module_dir ##### -->
795 Returns the directory in which GTK+ will look for
799 @Returns: The directory. (Must be freed with g_free())
802 <!-- ##### FUNCTION gtk_rc_get_im_module_path ##### -->
810 <!-- ##### FUNCTION gtk_rc_get_im_module_file ##### -->
818 <!-- ##### FUNCTION gtk_rc_get_theme_dir ##### -->
820 Returns the standard directory in which themes should
821 be installed. (GTK+ does not actually use this directory
825 @Returns: The directory (must be freed with g_free()).
828 <!-- ##### FUNCTION gtk_rc_style_new ##### -->
830 Creates a new #GtkRcStyle with no fields set and
831 a reference count of 1.
834 @Returns: the newly-created #GtkRcStyle
837 <!-- ##### FUNCTION gtk_rc_style_copy ##### -->
846 <!-- ##### FUNCTION gtk_rc_style_ref ##### -->
848 Increments the reference count of a #GtkRcStyle.
851 @rc_style: a #GtkRcStyle
854 <!-- ##### FUNCTION gtk_rc_style_unref ##### -->
856 Decrements the reference count of a #GtkRcStyle and
857 frees if the result is 0.
860 @rc_style: a #GtkRcStyle