Synopsis
#include <gtk/gtk.h>
GtkRcStyle;
enum GtkRcFlags;
enum GtkRcTokenType;
GScanner* gtk_rc_scanner_new (void);
GtkStyle* gtk_rc_get_style (GtkWidget *widget);
GtkStyle* gtk_rc_get_style_by_paths (GtkSettings *settings,
const char *widget_path,
const char *class_path,
GType type);
void gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
const gchar *pattern);
void gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
const gchar *pattern);
void gtk_rc_add_class_style (GtkRcStyle *rc_style,
const gchar *pattern);
void gtk_rc_parse (const gchar *filename);
void gtk_rc_parse_string (const gchar *rc_string);
gboolean gtk_rc_reparse_all (void);
gboolean gtk_rc_reparse_all_for_settings (GtkSettings *settings,
gboolean force_load);
void gtk_rc_reset_styles (GtkSettings *settings);
void gtk_rc_add_default_file (const gchar *filename);
gchar** gtk_rc_get_default_files (void);
void gtk_rc_set_default_files (gchar **filenames);
guint gtk_rc_parse_color (GScanner *scanner,
GdkColor *color);
guint gtk_rc_parse_color_full (GScanner *scanner,
GtkRcStyle *style,
GdkColor *color);
guint gtk_rc_parse_state (GScanner *scanner,
GtkStateType *state);
guint gtk_rc_parse_priority (GScanner *scanner,
GtkPathPriorityType *priority);
gchar* gtk_rc_find_module_in_path (const gchar *module_file);
gchar* gtk_rc_find_pixmap_in_path (GtkSettings *settings,
GScanner *scanner,
const gchar *pixmap_file);
gchar* gtk_rc_get_module_dir (void);
gchar* gtk_rc_get_im_module_path (void);
gchar* gtk_rc_get_im_module_file (void);
gchar* gtk_rc_get_theme_dir (void);
GtkRcStyle* gtk_rc_style_new (void);
GtkRcStyle* gtk_rc_style_copy (GtkRcStyle *orig);
void gtk_rc_style_ref (GtkRcStyle *rc_style);
void gtk_rc_style_unref (GtkRcStyle *rc_style);
DescriptionGTK+ 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
The set of these default files
can be retrieved with
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 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 "mywindow.*.GtkEntry" style "my-entry-class"
attaches the style
The patterns here are given in the standard shell glob syntax.
The
Since GTK+ 2.10, widget_class "*<GtkMenuItem>.GtkLabel" style "my-style" will match GtkLabel widgets which are contained in any kind of menu item.
So, if you have a GtkEntry named 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: class "GtkButton" style "my-style" will match not just GtkButton widgets, but also GtkToggleButton and GtkCheckButton widgets, since those classes derive from GtkButton. 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):
Optimizing RC Style MatchesEverytime a widget is created and added to the layout hierarchy of a GtkWindow ("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:
Toplevel declarations
An RC file is a text file which is composed of a sequence
of declarations. The possible toplevel declarations are:
Styles
A RC style is specified by a
Within a
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
Since 2.10, colors can also be specified by refering to a symbolic color, as
follows:
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["my-stock-item"] =
{
{ "itemltr.png", LTR, *, * },
{ "itemrtl.png", RTL, *, * }
}
This could be abbreviated as follows:
stock["my-stock-item"] =
{
{ "itemltr.png", LTR },
{ "itemrtl.png", RTL }
}
You can specify custom icons for specific sizes, as follows:
stock["my-stock-item"] =
{
{ "itemmenusize.png", *, *, "gtk-menu" },
{ "itemtoolbarsize.png", *, *, "gtk-large-toolbar" }
{ "itemgeneric.png" } /* implicit *, *, * as a fallback */
}
The sizes that come with GTK+ itself are 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" } /* implicit *, *, * as a fallback */
}
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
Key bindingsKey bindings allow the user to specify actions to be taken on particular key presses. The form of a binding set declaration is: binding
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 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. DetailsGtkRcStyletypedef struct {
gchar *name;
gchar *bg_pixmap_name[5];
PangoFontDescription *font_desc;
GtkRcFlags color_flags[5];
GdkColor fg[5];
GdkColor bg[5];
GdkColor text[5];
GdkColor base[5];
gint xthickness;
gint ythickness;
} GtkRcStyle;
The GtkRcStyle structure is used to represent a set of information about the appearance of a widget. This can later be composited together with other GtkRcStyle structures to form a GtkStyle. enum GtkRcFlagstypedef enum
{
GTK_RC_FG = 1 << 0,
GTK_RC_BG = 1 << 1,
GTK_RC_TEXT = 1 << 2,
GTK_RC_BASE = 1 << 3
} GtkRcFlags;
The GtkRcFlags enumeration is used as a bitmask to specify which fields of a GtkRcStyle have been set for each state. enum GtkRcTokenTypetypedef enum {
GTK_RC_TOKEN_INVALID = G_TOKEN_LAST,
GTK_RC_TOKEN_INCLUDE,
GTK_RC_TOKEN_NORMAL,
GTK_RC_TOKEN_ACTIVE,
GTK_RC_TOKEN_PRELIGHT,
GTK_RC_TOKEN_SELECTED,
GTK_RC_TOKEN_INSENSITIVE,
GTK_RC_TOKEN_FG,
GTK_RC_TOKEN_BG,
GTK_RC_TOKEN_TEXT,
GTK_RC_TOKEN_BASE,
GTK_RC_TOKEN_XTHICKNESS,
GTK_RC_TOKEN_YTHICKNESS,
GTK_RC_TOKEN_FONT,
GTK_RC_TOKEN_FONTSET,
GTK_RC_TOKEN_FONT_NAME,
GTK_RC_TOKEN_BG_PIXMAP,
GTK_RC_TOKEN_PIXMAP_PATH,
GTK_RC_TOKEN_STYLE,
GTK_RC_TOKEN_BINDING,
GTK_RC_TOKEN_BIND,
GTK_RC_TOKEN_WIDGET,
GTK_RC_TOKEN_WIDGET_CLASS,
GTK_RC_TOKEN_CLASS,
GTK_RC_TOKEN_LOWEST,
GTK_RC_TOKEN_GTK,
GTK_RC_TOKEN_APPLICATION,
GTK_RC_TOKEN_THEME,
GTK_RC_TOKEN_RC,
GTK_RC_TOKEN_HIGHEST,
GTK_RC_TOKEN_ENGINE,
GTK_RC_TOKEN_MODULE_PATH,
GTK_RC_TOKEN_IM_MODULE_PATH,
GTK_RC_TOKEN_IM_MODULE_FILE,
GTK_RC_TOKEN_STOCK,
GTK_RC_TOKEN_LTR,
GTK_RC_TOKEN_RTL,
GTK_RC_TOKEN_COLOR,
GTK_RC_TOKEN_UNBIND,
GTK_RC_TOKEN_LAST
} GtkRcTokenType;
The GtkRcTokenType enumeration represents the tokens in the RC file. It is exposed so that theme engines can reuse these tokens when parsing the theme-engine specific portions of a RC file. gtk_rc_get_style ()GtkStyle* gtk_rc_get_style (GtkWidget *widget); 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.)
gtk_rc_get_style_by_paths ()GtkStyle* gtk_rc_get_style_by_paths (GtkSettings *settings, const char *widget_path, const char *class_path, GType type); Creates up a GtkStyle from styles defined in a RC file by providing the raw components used in matching. This function may be useful when creating pseudo-widgets that should be themed like widgets but don't actually have corresponding GTK+ widgets. An example of this would be items inside a GNOME canvas widget.
The action of
gtk_widget_path (widget, NULL, &path, NULL);
gtk_widget_class_path (widget, NULL, &class_path, NULL);
gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
path, class_path,
G_OBJECT_TYPE (widget));
gtk_rc_add_widget_name_style ()void gtk_rc_add_widget_name_style (GtkRcStyle *rc_style, const gchar *pattern); Warning
Adds a GtkRcStyle that will be looked up by a match against
the widget's pathname. This is equivalent to a:
gtk_rc_add_widget_class_style ()void gtk_rc_add_widget_class_style (GtkRcStyle *rc_style, const gchar *pattern); Warning
Adds a GtkRcStyle that will be looked up by a match against
the widget's class pathname. This is equivalent to a:
gtk_rc_add_class_style ()void gtk_rc_add_class_style (GtkRcStyle *rc_style, const gchar *pattern); Warning
Adds a GtkRcStyle that will be looked up by a matching against
the class hierarchy of the widget. This is equivalent to a:
gtk_rc_parse ()void gtk_rc_parse (const gchar *filename); Parses a given resource file.
gtk_rc_parse_string ()void gtk_rc_parse_string (const gchar *rc_string); Parses resource information directly from a string.
gtk_rc_reparse_all ()gboolean gtk_rc_reparse_all (void); If the modification time on any previously read file for the default GtkSettings has changed, discard all style information and then reread all previously read RC files.
gtk_rc_reparse_all_for_settings ()gboolean gtk_rc_reparse_all_for_settings (GtkSettings *settings, gboolean force_load); If the modification time on any previously read file for the given GtkSettings has changed, discard all style information and then reread all previously read RC files.
gtk_rc_reset_styles ()void gtk_rc_reset_styles (GtkSettings *settings);
This function recomputes the styles for all widgets that use a
particular GtkSettings object. (There is one GtkSettings object
per GdkScreen, see
Since 2.4 gtk_rc_add_default_file ()void gtk_rc_add_default_file (const gchar *filename);
Adds a file to the list of files to be parsed at the
end of
gtk_rc_get_default_files ()gchar** gtk_rc_get_default_files (void);
Retrieves the current list of RC files that will be parsed
at the end of
gtk_rc_set_default_files ()void gtk_rc_set_default_files (gchar **filenames);
Sets the list of files that GTK+ will read at the
end of
gtk_rc_parse_color ()guint gtk_rc_parse_color (GScanner *scanner,
GdkColor *color);
Parses a color in the format expected in a RC file.
Note that theme engines should use
gtk_rc_parse_color_full ()guint gtk_rc_parse_color_full (GScanner *scanner,
GtkRcStyle *style,
GdkColor *color);
Parses a color in the format expected
in a RC file. If
Since 2.12 gtk_rc_parse_state ()guint gtk_rc_parse_state (GScanner *scanner,
GtkStateType *state);
Parses a GtkStateType variable from the format expected in a RC file.
gtk_rc_parse_priority ()guint gtk_rc_parse_priority (GScanner *scanner,
GtkPathPriorityType *priority);
Parses a GtkPathPriorityType variable from the format expected in a RC file.
gtk_rc_find_module_in_path ()gchar* gtk_rc_find_module_in_path (const gchar *module_file); Searches for a theme engine in the GTK+ search path. This function is not useful for applications and should not be used.
gtk_rc_find_pixmap_in_path ()gchar* gtk_rc_find_pixmap_in_path (GtkSettings *settings, GScanner *scanner, const gchar *pixmap_file);
Looks up a file in pixmap path for the specified GtkSettings.
If the file is not found, it outputs a warning message using
gtk_rc_get_module_dir ()gchar* gtk_rc_get_module_dir (void);
Returns a directory in which GTK+ looks for theme engines.
For full information about the search for theme engines,
see the docs for
gtk_rc_get_im_module_path ()gchar* gtk_rc_get_im_module_path (void);
Obtains the path in which to look for IM modules. See the documentation
of the
gtk_rc_get_im_module_file ()gchar* gtk_rc_get_im_module_file (void);
Obtains the path to the IM modules file. See the documentation
of the
gtk_rc_get_theme_dir ()gchar* gtk_rc_get_theme_dir (void); Returns the standard directory in which themes should be installed. (GTK+ does not actually use this directory itself.)
gtk_rc_style_new ()GtkRcStyle* gtk_rc_style_new (void); Creates a new GtkRcStyle with no fields set and a reference count of 1.
gtk_rc_style_copy ()GtkRcStyle* gtk_rc_style_copy (GtkRcStyle *orig); Makes a copy of the specified GtkRcStyle. This function will correctly copy an RC style that is a member of a class derived from GtkRcStyle.
gtk_rc_style_ref ()void gtk_rc_style_ref (GtkRcStyle *rc_style); Warning
Increments the reference count of a GtkRcStyle.
gtk_rc_style_unref ()void gtk_rc_style_unref (GtkRcStyle *rc_style); Warning
Decrements the reference count of a GtkRcStyle and frees if the result is 0.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||