| |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
Description | |||||||||||||||||||||||||||||||||||||||
Routines for handling resource files | |||||||||||||||||||||||||||||||||||||||
Synopsis | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
Detail | |||||||||||||||||||||||||||||||||||||||
Gtk+ provides resource file mechanism for configuring various aspects of the operation of a Gtk+ program at runtime. | |||||||||||||||||||||||||||||||||||||||
Default files | |||||||||||||||||||||||||||||||||||||||
An application can cause Gtk+ to parse a specific RC file by calling rcParse. In addition to this, certain files will be read at the end of initGUI. Unless modified, the files looked for will be <SYSCONFDIR>/gtk-2.0/gtkrc and .gtkrc-2.0 in the users home directory. (<SYSCONFDIR> defaults to /usr/local/etc. It can be changed with the --prefix or --sysconfdir options when configuring Gtk+.) Note that although the filenames contain the version number 2.0, all 2.x versions of Gtk+ look for these files. The set of these default files can be retrieved with rcGetDefaultFiles and modified with rcAddDefaultFile and rcSetDefaultFiles. Additionally, the GTK2_RC_FILES environment variable can be set to a :-separated list of files in order to overwrite the set of default files at runtime. For each RC file, in addition to the file itself, Gtk+ will look for a locale-specific file that will be parsed after the main file. For instance, if LANG is set to ja_JP.ujis, when loading the default file ~/.gtkrc then Gtk+ looks for ~/.gtkrc.ja_JP and ~/.gtkrc.ja, and parses the first of those that exists. | |||||||||||||||||||||||||||||||||||||||
Pathnames and patterns | |||||||||||||||||||||||||||||||||||||||
A resource file defines a number of styles and key bindings and attaches them to particular widgets. The attachment is done by the widget, widget_class, and class declarations. As an example of such a statement: attaches the style "my-entry-class" to all widgets whose widget path matches the pattern "mywindow.*.GtkEntry". That is, all Entry widgets which are part of a Window named "mywindow". widget "mywindow.*.GtkEntry" style "my-entry-class" The patterns here are given in the standard shell glob syntax. The "?" wildcard matches any character, while "*" matches zero or more of any character. The three types of matching are against the widget path, the class path and the class hierarchy. Both the widget path and the class path consist of a "." separated list of all the parents of the widget and the widget itself from outermost to innermost. The difference is that in the widget path, the name assigned by widgetSetName is used if present, otherwise the class name of the widget, while for the class path, the class name is always used. Since Gtk+ 2.10, widget_class paths can also contain <classname> substrings, which are matching the class with the given name and any derived classes. For instance, will match Label widgets which are contained in any kind of menu item. widget_class "*GtkMenuItem.GtkLabel" style "my-style" So, if you have a Entry named "myentry", inside of a horizontal box in a window named "mywindow", then the widget path is: "mywindow.GtkHBox.myentry" while the class path is: "GtkWindow.GtkHBox.GtkEntry". Matching against class is a little different. The pattern match is done against all class names in the widgets class hierarchy (not the layout hierarchy) in sequence, so the pattern: will match not just Button widgets, but also ToggleButton and CheckButton widgets, since those classes derive from Button. class "GtkButton" style "my-style" Additionally, a priority can be specified for each pattern, and styles override other styles first by priority, then by pattern type and then by order of specification (later overrides earlier). The priorities that can be specified are (highest to lowest):
rc is the default for styles read from an RC file, theme is the default for styles read from theme RC files, application should be used for styles an application sets up, and gtk is used for styles that Gtk+ creates internally. | |||||||||||||||||||||||||||||||||||||||
Optimizing RC Style Matches | |||||||||||||||||||||||||||||||||||||||
Everytime a widget is created and added to the layout hierarchy of a Window ("anchored" to be exact), a list of matching RC styles out of all RC styles read in so far is composed. For this, every RC style is matched against the widgets class path, the widgets name path and widgets inheritance hierarchy. As a consequence, significant slowdown can be caused by utilization of many RC styles and by using RC style patterns that are slow or complicated to match against a given widget. The following ordered list provides a number of advices (prioritized by effectiveness) to reduce the performance overhead associated with RC style matches: Move RC styles for specific applications into RC files dedicated to those applications and parse application specific RC files only from applications that are affected by them. This reduces the overall amount of RC styles that have to be considered for a match across a group of applications. Merge multiple styles which use the same matching rule, for instance: is faster to match as: style "Foo" { foo_content } class "X" style "Foo" style "Bar" { bar_content } class "X" style "Bar" style "FooBar" { foo_content bar_content } class "X" style "FooBar" Use of wildcards should be avoided, this can reduce the individual RC style match to a single integer comparison in most cases. To avoid complex recursive matching, specification of full class names (for class matches) or full path names (for widget and widget_class matches) is to be preferred over shortened names containing "*" or "?". If at all necessary, wildcards should only be used at the tail or head of a pattern. This reduces the match complexity to a string comparison per RC style. When using wildcards, use of "?" should be preferred over "*". This can reduce the matching complexity from O(n^2) to O(n). For example "Gtk*Box" can be turned into "Gtk?Box" and will still match HBox and VBox. The use of "*" wildcards should be restricted as much as possible, because matching "A*B*C*RestString" can result in matching complexities of O(n^2) worst case. | |||||||||||||||||||||||||||||||||||||||
Toplevel declarations | |||||||||||||||||||||||||||||||||||||||
An RC file is a text file which is composed of a sequence of declarations. '#' characters delimit comments and the portion of a line after a '#' is ignored when parsing an RC file. The possible toplevel declarations are:
| |||||||||||||||||||||||||||||||||||||||
Styles | |||||||||||||||||||||||||||||||||||||||
A RC style is specified by a style declaration in a RC file, and then bound to widgets with a widget, widget_class, or class declaration. All styles applying to a particular widget are composited together with widget declarations overriding widget_class declarations which, in turn, override class declarations. Within each type of declaration, later declarations override earlier ones. Within a style declaration, the possible elements are:
The colors and background pixmaps are specified as a function of the state of the widget. The states are:
Colors can be specified as a string containing a color name (GTK+ knows all names from the X color database /usr/lib/X11/rgb.txt), in one of the hexadecimal forms rgb, where r, g and b are hex digits, or they can be specified as a triplet { r, g, b}, where r, g and b are either integers in the range 0-65535 or floats in the range 0.0-1.0. Since 2.10, colors can also be specified by refering to a symbolic color, as follows: @color-name, or by using expressions to combine colors. The following expressions are currently supported:
Here are some examples of color expressions: mix (0.5, "red", "blue") shade (1.5, mix (0.3, "#0abbc0", { 0.3, 0.5, 0.9 })) lighter (@foreground) In a stock definition, icon sources are specified as a 4-tuple of image filename or icon name, text direction, widget state, and size, in that order. Each icon source specifies an image filename or icon name to use with a given direction, state, and size. Filenames are specified as a string such as "itemltr.png", while icon names (looked up in the current icon theme), are specified with a leading @, such as @"item-ltr". The * character can be used as a wildcard, and if direction/state/size are omitted they default to *. So for example, the following specifies different icons to use for left-to-right and right-to-left languages: This could be abbreviated as follows: stock["my-stock-item"] = { { "itemltr.png", LTR, *, * }, { "itemrtl.png", RTL, *, * } } stock["my-stock-item"] = { { "itemltr.png", LTR }, { "itemrtl.png", RTL } } You can specify custom icons for specific sizes, as follows: The sizes that come with Gtk+ itself are "gtk-menu", "gtk-small-toolbar", "gtk-large-toolbar", "gtk-button", "gtk-dialog". Applications can define other sizes. stock["my-stock-item"] = { { "itemmenusize.png", *, *, "gtk-menu" }, { "itemtoolbarsize.png", *, *, "gtk-large-toolbar" } { "itemgeneric.png" } } It's also possible to use custom icons for a given state, for example: stock["my-stock-item"] = { { "itemprelight.png", *, PRELIGHT }, { "iteminsensitive.png", *, INSENSITIVE }, { "itemgeneric.png" } } When selecting an icon source to use, Gtk+ will consider text direction most important, state second, and size third. It will select the best match based on those criteria. If an attribute matches exactly (e.g. you specified PRELIGHT or specified the size), Gtk+ won't modify the image; if the attribute matches with a wildcard, Gtk+ will scale or modify the image to match the state and size the user requested. | |||||||||||||||||||||||||||||||||||||||
Key bindings | |||||||||||||||||||||||||||||||||||||||
Key bindings allow the user to specify actions to be taken on particular key presses. The form of a binding set declaration is: key is a string consisting of a series of modifiers followed by the name of a key. The modifiers can be:
<shft> is an alias for <shift>, <ctl> is an alias for <control>, and <alt> is an alias for <mod1>. The action that is bound to the key is a sequence of signal names (strings) followed by parameters for each signal. The signals must be action signals. (See gSignalNew). Each parameter can be a float, integer, string, or unquoted string representing an enumeration value. The types of the parameters specified must match the types of the parameters of the signal. Binding sets are connected to widgets in the same manner as styles, with one difference: Binding sets override other binding sets first by pattern type, then by priority and then by order of specification. The priorities that can be specified and their default values are the same as for styles. | |||||||||||||||||||||||||||||||||||||||
Class Hierarchy | |||||||||||||||||||||||||||||||||||||||
| GObject | +----RcStyle | |||||||||||||||||||||||||||||||||||||||
Types | |||||||||||||||||||||||||||||||||||||||
data RcStyle | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
class GObjectClass o => RcStyleClass o | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
castToRcStyle :: GObjectClass obj => obj -> RcStyle | |||||||||||||||||||||||||||||||||||||||
gTypeRcStyle :: GType | |||||||||||||||||||||||||||||||||||||||
toRcStyle :: RcStyleClass o => o -> RcStyle | |||||||||||||||||||||||||||||||||||||||
Constructors | |||||||||||||||||||||||||||||||||||||||
rcStyleNew :: IO RcStyle | |||||||||||||||||||||||||||||||||||||||
Creates a new RcStyle with no fields set. The RcStyle structure is used to represent a set of information about the appearance of a widget. This can later be composited together with other RcStyle structures to form a Style. | |||||||||||||||||||||||||||||||||||||||
Methods | |||||||||||||||||||||||||||||||||||||||
rcStyleCopy | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
rcAddDefaultFile :: String -> IO () | |||||||||||||||||||||||||||||||||||||||
Adds a file to the list of files to be parsed at the end of initGUI. | |||||||||||||||||||||||||||||||||||||||
rcGetDefaultFiles :: IO [String] | |||||||||||||||||||||||||||||||||||||||
etrieves the current list of RC files that will be parsed at the end of initGUI. | |||||||||||||||||||||||||||||||||||||||
rcGetImModuleFile :: IO String | |||||||||||||||||||||||||||||||||||||||
Obtains the path to the IM modules file. See the documentation of the GTK_IM_MODULE_FILE environment variable for more details. | |||||||||||||||||||||||||||||||||||||||
rcGetModuleDir :: IO String | |||||||||||||||||||||||||||||||||||||||
Returns a directory in which GTK+ looks for theme engines. | |||||||||||||||||||||||||||||||||||||||
rcGetStyle :: WidgetClass widget => widget -> IO Style | |||||||||||||||||||||||||||||||||||||||
Finds all matching RC styles for a given widget, composites them together, and then creates a GtkStyle representing the composite appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.) | |||||||||||||||||||||||||||||||||||||||
rcGetStyleByPaths | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
rcGetThemeDir :: IO String | |||||||||||||||||||||||||||||||||||||||
Returns the standard directory in which themes should be installed. (GTK+ does not actually use this directory itself.) | |||||||||||||||||||||||||||||||||||||||
rcParse | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
rcParseString :: String -> IO () | |||||||||||||||||||||||||||||||||||||||
Parses resource information directly from a string. | |||||||||||||||||||||||||||||||||||||||
rcReparseAll | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
rcReparseAllForSettings | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
rcResetStyles :: Settings -> IO () | |||||||||||||||||||||||||||||||||||||||
This function recomputes the styles for all widgets that use a particular Settings object. (There is one Settings object per Screen, see settingsGetForScreen.) It is useful when some global parameter has changed that affects the appearance of all widgets, because when a widget gets a new style, it will both redraw and recompute any cached information about its appearance. As an example, it is used when the default font size set by the operating system changes. Note that this function doesn't affect widgets that have a style set explicitely on them with widgetSetStyle. | |||||||||||||||||||||||||||||||||||||||
rcSetDefaultFiles :: [String] -> IO () | |||||||||||||||||||||||||||||||||||||||
Sets the list of files that GTK+ will read at the end of initGUI. | |||||||||||||||||||||||||||||||||||||||
Produced by Haddock version 2.4.2 |