[ruby-gnome2-doc-cvs] [Hiki] create - Gtk::RC

Zurück zum Archiv-Index

ruby-****@sourc***** ruby-****@sourc*****
2005年 3月 24日 (木) 19:12:47 JST


-------------------------
REMOTE_ADDR = 15.211.169.100
REMOTE_HOST = 
REMOTE_USER = ruby-gnome2-hiki        URL = http://ruby-gnome2.sourceforge.jp/cgi-bin/hiki/hiki.cgi?Gtk%3A%3ARC
-------------------------
TITLE       = Gtk::RC
KEYWORD     = 
= module Gtk::RC
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 Gtk::RC.parse. In addition to this, certain files will be read at the end of Gtk.init. 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 Gtk::RC.default_files and modified with Gtk::RC.add_default_file and Gtk::RC.default_files=. Additionally, the GTK2_RC_FILES environment variable can be set to a G_SEARCHPATH_SEPARATOR_S-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.eucJP, 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: 

 widget "mywindow.*.GtkEntry" style "my-entry-class"

attaches the style "my-entry-class" to all widgets whose widget class matches the pattern "mywindow.*.GtkEntry". 

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 and the class paths consists 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 Gtk::Widget#name= is used if present, otherwise the class name of the widget, while for the class path, the class name is always used. 

So, if you have a Gtk::Entry named "myentry", inside of a of a window named "mywindow", then the widget path is: "mwindow.GtkHBox.myentry" while the class path is: "GtkWindow.GtkHBox.GtkEntry". Note "::" should be omitted.

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 Gtk::Button widgets, but also Gtk::ToggleButton and Gtk::CheckButton widgets, since those classes derive from Gtk::Button. 

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): 

* (highest)
* rc 
* theme 
* application 
* gtk 
* (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. 

=== 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: 

--- binding name { ... }
    Declares a binding set.

--- class pattern [ style | binding ][ : priority ] name
    Specifies a style or binding set for a particular branch of the inheritance hierarchy.

--- include filename
    Parses another file at this point. If filename is not an absolute filename, it is searched in the directories of the currently open RC files. GTK+ also tries to load a locale-specific variant of the included file. 

--- module_path path
    Sets a path (a list of directories separated by colons) that will be searched for theme engines referenced in RC files.

--- pixmap_path path
    Sets a path (a list of directories separated by colons) that will be searched for pixmaps referenced in RC files.

--- im_module_file pathname
    Sets the pathname for the IM modules file. Setting this from RC files is deprecated; you should use the environment variable GTK_IM_MODULE_FILE instead.

--- style name [ = parent ] { ... } 
    Declares a style.

--- widget pattern [ style | binding ][ : priority ] name
    Specifies a style or binding set for a particular group of widgets by matching on the widget pathname.
 
--- widget_class pattern [ style | binding ][ : priority ] name
    Specifies a style or binding set for a particular group of widgets by matching on the class pathname.
 
--- setting = value
    Specifies a value for a setting. Note that settings in RC files are overwritten by system-wide settings which are managed by an XSettings manager.
 

=== 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: 

--- bg[state] = color
    Sets the color used for the background of most widgets. 
 
--- fg[state] = color
    Sets the color used for the foreground of most widgets. 

--- base[state] = color
    Sets the color used for the background of widgets displaying editable text.
 
--- text[state] = color
    Sets the color used for foreground of widgets using base for the background color. 
 
--- xthickness = number
    Sets the xthickness, which is used for various horizontal padding values in GTK+. 

--- ythickness = number
    Sets the ythickness, which is used for various vertical padding values in GTK+. 
 
--- bg_pixmap[state] = pixmap
    Sets a background pixmap to be used in place of the bg color. The special value "<parent>" may be used to indicate that the widget should use the same background pixmap as its parent. The special value "<none>" may be used to indicate no background pixmap. 
 
--- font_name = font
    Sets the font for a widget. font must be a Pango font name, e.g. "Sans Italic 10". For details about Pango font names, see Pango::FontDescription.new. 
 
--- stock["stock-id"] = { icon source specifications } 
    Defines the icon for a stock item. 
 
--- engine "engine" { engine-specific settings }
    Defines the engine to be used when drawing with this style. 
 
--- class::property = value
    Sets a style property for a widget class. 

The colors and background pixmaps are specified as a function of the state of the widget. The states are: 

--- NORMAL
    A color used for a widget in its normal state. 
 
--- ACTIVE
    A variant of the NORMAL color used when the widget is in the Gtk::STATE_ACTIVE state, and also for the trough of a ScrollBar, tabs of a NoteBook other than the current tab and similar areas. Frequently, this should be a darker variant of the NORMAL color. 

--- PRELIGHT
    A color used for widgets in the Gtk::STATE_PRELIGHT state. This state is the used for Buttons and MenuItems that have the mouse cursor over them, and for their children. 
 
--- SELECTED
    A color used to highlight data selected by the user. for instance, the selected items in a list widget, and the selection in an editable widget. 
 
--- INSENSITIVE
    A color used for the background of widgets that have been set insensitive with Gtk::Widget#sensitive=. 
 

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 #rrrrggggbbbb, #rrrgggbbb, #rrggbb, or #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. 

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: 

 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 "gtk-menu", "gtk-small-toolbar", "gtk-large-toolbar", "gtk-button", "gtk-dialog". Applications can define other sizes. 

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 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: 

 binding name {
   bind key { 
     signalname (param, ...)
     ...
   }
   ...
 }

key is a string consisting of a series of modifiers followed by the name of a key. The modifiers can be: 

* <alt> 
* <control> 
* <mod1> 
* <mod2> 
* <mod3> 
* <mod4> 
* <mod5> 
* <release> 
* <shft> 
* <shift> 

<shft> is an alias for <shift> 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 GLib::Signal.new). 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. 


== Module Functions
--- Gtk::RC.get_style(widget)
    Finds all matching RC styles for a given widget, composites them together, and then creates a Gtk::Style representing the composite appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.)
    * widget: a Gtk::Widget  
    * Returns: the resulting Gtk::Style

--- Gtk::RC.get_style_by_paths(settings, widget_path = nil, klass_path = nil, klass = nil)
    Creates up a Gtk::Style 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. 
    * settings: a Gtk::Settings object  
    * widget_path: the widget path to use when looking up the style, or nil if no matching against the widget path should be done  
    * class_path: the class path to use when looking up the style, or nil if no matching against the class path should be done.  
    * klass: a subclass of GLib::Instantiatable that will be used along with parent class of this class when matching against class styles, or nil
    * Returns: A style created by matching with the supplied paths, or nil if nothing matching was specified and the default style should be used. 

--- Gtk::RC.parse(filename)
    Parses a given resource file. 
    * filename: the filename of a file to parse. If filename is not absolute, it is searched in the current directory.
    * Returns: filename

--- Gtk::RC.parse_string(rc_string)
    Parses resource information directly from a string. 
    * rc_string: a String to parse. 
    * Returns: rc_string

--- Gtk::RC.reparse_all
    If the modification time on any previously read file for the default Gtk::Settings has changed, discard all style information and then reread all previously read RC files.
    * Returns: true if the files were reread.  

--- Gtk::RC.reparse_all_for_settings(settings, force_load)
    If the modification time on any previously read file for the given Gtk::Settings has changed, discard all style information and then reread all previously read RC files.
    * settings: a Gtk::Settings  
    * force_load: load whether or not anything changed  
    * Returns: true if the files were reread.  

--- Gtk::RC.reset_styles(settings)
    This function recomputes the styles for all widgets that use a particular Gtk::Settings object. (There is one Gtk::Settings object per Gdk::Screen, see Gtk::Settings.get_for_screen); 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 Gtk::Widget#style=. ((* Since 2.4 *))
    * settings: a Gtk::Settings
    * Returns: settings

--- Gtk::RC.add_default_file(filename)
    Adds a file to the list of files to be parsed at the end of Gtk.init.
    * filename: the pathname to the file. If filename is not absolute, it is searched in the current directory.  
    * Returns: filename

--- Gtk::RC.default_files
    Retrieves the current list of RC files that will be parsed at the end of Gtk.init.
    * Returns: An Array of filenames.

--- Gtk::RC.default_files=(filenames)
    Sets the list of files that GTK+ will read at the end of Gtk.init.
    * filenames: An array of filenames.  
    * Returns: filenames
--- Gtk::RC.set_default_files(filenames)
    Same as default_files=.
    * filenames: An Array of filenames.  
    * Returns: self

--- Gtk::RC.find_module_in_path(module_file)
    Searches for a theme engine in the GTK+ search path. This function is not useful for applications and should not be used.
    * module_file: name of a theme engine  
    * Returns: The filename, if found, otherwise nil.  

--- Gtk::RC.module_dir
    Returns a directory in which GTK+ looks for theme engines. For full information about the search for theme engines.
    * Returns: The directory

--- Gtk::RC.im_module_file
    Obtains the path to the IM modules file. See the documentation of the GTK_IM_MODULE_FILE environment variable for more details.
    * Returns: the name of the file listing the IM modules available for loading  
--- Gtk::RC.im_module_path
    Obtains the path in which to look for IM modules. See the documentation of the GTK_PATH environment variable for more details about looking up modules. This function is useful solely for utilities supplied with GTK+ and should not be used by applications under normal circumstances.
    * Returns: The path in which to look for IM modules.  

--- Gtk::RC.theme_dir
    Returns the standard directory in which themes should be installed. (GTK+ does not actually use this directory itself.) 
    * Returns: The directory.  

== Constants
=== GtkRcFlags
The Gtk::RC::Flags is used as a bitmask to specify which fields of a Gtk::RcStyle have been set for each state. 
--- FG
    If present, the foreground color has been set for this state.
--- BG
    If present, the background color has been set for this state.
--- TEXT
    If present, the text color has been set for this state. 
--- BASE
    If present, the base color has been set for this state. 

=== GtkRcTokenType
The Gtk::RC::TokenType 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. 

--- TOKEN_INVALID
    = TOKEN_LAST
--- TOKEN_ACTIVE
--- TOKEN_APPLICATION
--- TOKEN_BASE
--- TOKEN_BG
--- TOKEN_BG_PIXMAP
--- TOKEN_BIND
--- TOKEN_BINDING
--- TOKEN_CLASS
--- TOKEN_ENGINE
--- TOKEN_FG
--- TOKEN_FONT
--- TOKEN_FONTSET
--- TOKEN_FONT_NAME
--- TOKEN_GTK
--- TOKEN_HIGHEST
--- TOKEN_IM_MODULE_FILE
--- TOKEN_IM_MODULE_PATH
--- TOKEN_INCLUDE
--- TOKEN_INSENSITIVE
--- TOKEN_LOWEST
--- TOKEN_LTR
--- TOKEN_MODULE_PATH
--- TOKEN_NORMAL
--- TOKEN_PIXMAP_PATH
--- TOKEN_PRELIGHT
--- TOKEN_RC
--- TOKEN_RTL
--- TOKEN_SELECTED
--- TOKEN_STOCK
--- TOKEN_STYLE
--- TOKEN_TEXT
--- TOKEN_THEME
--- TOKEN_WIDGET
--- TOKEN_WIDGET_CLASS
--- TOKEN_XTHICKNESS
--- TOKEN_YTHICKNESS
--- TOKEN_LAST

== See Also
Gtk::RcStyle

== ChangeLog
* 2005-03-24 Added - ((<Masao>))






ruby-gnome2-cvs メーリングリストの案内
Zurück zum Archiv-Index