This document describes the format of XRC resource files, as used by wxXmlResource.
Formal description in the form of a RELAX NG schema is located in the misc/schema
subdirectory of the wxWidgets sources.
XRC file is a XML file with all of its elements in the http://www.wxwidgets.org/wxxrc
namespace. For backward compatibility, http://www.wxwindows.org/wxxrc
namespace is accepted as well (and treated as identical to http://www.wxwidgets.org/wxxrc
), but it shouldn't be used in new XRC files.
XRC file contains definitions for one or more objects – typically windows. The objects may themselves contain child objects.
Objects defined at the top level, under the root element, can be accessed using wxXmlResource::LoadDialog() and other LoadXXX methods. They must have name
attribute that is used as LoadXXX's argument (see Object Element for details).
Child objects are not directly accessible via wxXmlResource, they can only be accessed using XRCCTRL().
The root element is always <resource>
. It has one optional attribute, version
. If set, it specifies version of the file. In absence of version
attribute, the default is "0.0.0.0"
.
The version consists of four integers separated by periods. The first three components are major, minor and release number of the wxWidgets release when the change was introduced, the last one is revision number and is 0 for the first incompatible change in given wxWidgets release, 1 for the second and so on. The version changes only if there was an incompatible change introduced; merely adding new kind of objects does not constitute incompatible change.
At the time of writing, the latest version is "2.5.3.0"
.
Note that even though version
attribute is optional, it should always be specified to take advantage of the latest capabilities:
<resource>
may have arbitrary number of object elements as its children; they are referred to as toplevel objects in the rest of this document. Unlike objects defined deeper in the hierarchy, toplevel objects must have their name
attribute set and it must be set to a value unique among root's children.
The <object>
element represents a single object (typically a GUI element) and it usually maps directly to a wxWidgets class instance. It has one mandatory attribute, class
, and optional name
and subclass
attributes.
The class
attribute must always be present, it tells XRC what wxWidgets object should be created and by which wxXmlResourceHandler.
name
is the identifier used to identify the object. This name serves three purposes:
Name attributes must be unique at the top level (where the name is used to load resources) and should be unique among all controls within the same toplevel window (wxDialog, wxFrame).
The subclass
attribute optional name of class whose constructor will be called instead of the constructor for "class". See Subclassing for more details.
<object>
element may – and almost always do – have children elements. These come in two varieties:
<object>
elements and are can be repeated more than once. The specifics of which object classes are allowed as children are class-specific and are documented below in Supported Controls.Example:
Anywhere an <object>
element can be used, <object_ref>
may be used instead. <object_ref>
is a reference to another named (i.e. with the name
attribute) <object>
element. It has one mandatory attribute, ref
, with value containing the name of a named <object>
element. When an <object_ref>
is encountered, a copy of the referenced <object>
element is made in place of <object_ref>
occurrence and processed as usual.
For example, the following code:
is equivalent to
Additionally, it is possible to override some parts of the referenced object in the <object_ref>
pointing to it. This is useful for putting repetitive parts of XRC definitions into a template that can be reused and customized in several places. The two parts are merged as follows:
<object_ref>
are added to it.<object_ref>
are scanned. If an element with the same name (and, if specified, the name
attribute too) is found in the referred object, they are recursively merged.<object_ref>
that do not have a match in the referred object are appended to the list of children of the resulting element by default. Optionally, they may have insert_at
attribute with two possible values, "begin" or "end". When set to "begin", the element is prepended to the list of children instead of appended.For example, "my_dlg" in this snippet:
is identical to:
There are several property data types that are frequently reused by different properties. Rather than describing their format in the documentation of every property, we list commonly used types in this section and document their format.
Boolean values are expressed using either "1" literal (true) or "0" (false).
Floating point values use POSIX (C locale) formatting – decimal separator is "." regardless of the locale.
Colour specification can be either any string colour representation accepted by wxColour::Set() or any wxSYS_COLOUR_XXX symbolic name accepted by wxSystemSettings::GetColour(). In particular, the following forms are supported:
Some examples:
Sizes and positions have the form of string with two comma-separated integer components, with optional "d" suffix. Semi-formally:
size := x "," y ["d"]
where x and y are integers. Either of the components (or both) may be "-1" to signify default value. As a shortcut, empty string is equivalent to "-1,-1" (= wxDefaultSize or wxDefaultPosition).
When the "d" suffix is used, integer values are interpreted as dialog units in the parent window.
Examples:
Same as Size.
Similarly to sizes, dimensions are expressed as integers with optional "d" suffix. When "d" suffix is used, the integer preceding it is interpreted as dialog units in the parent window.
String properties use several escape sequences that are translated according to the following table:
"_" | "&" (used for accelerators in wxWidgets) |
"__" | "_" |
"\n" | line break |
"\r" | carriage return |
"\t" | tab |
"\\" | "\" |
By default, the text is translated using wxLocale::GetTranslation() before it is used. This can be disabled either globally by not passing wxXRC_USE_LOCALE to wxXmlResource constructor, or by setting the translate
attribute on the property node to "0":
Like Text, but the text is never translated and translate
attribute cannot be used.
An unformatted string. Unlike with Text, no escaping or translations are done.
Any URL accepted by wxFileSystem (typically relative to XRC file's location, but can be absolute too). Unlike with Text, no escaping or translations are done.
Bitmap properties contain specification of a single bitmap or icon. In the most basic form, their text value is simply a relative filename (or another wxFileSystem URL) of the bitmap to use. For example:
The value is interpreted as path relative to the location of XRC file where the reference occurs.
Alternatively, it is possible to specify the bitmap using wxArtProvider IDs. In this case, the property element has no textual value (filename) and instead has the stock_id
XML attribute that contains stock art ID as accepted by wxArtProvider::GetBitmap(). This can be either custom value (if the app uses app-specific art provider) or one of the predefined wxART_XXX constants.
Optionally, stock_client
attribute may be specified too and contain one of the predefined wxArtClient values. If it is not specified, the default client ID most appropriate in the context where the bitmap is referenced will be used. In most cases, specifying stock_client
is not needed.
Examples of stock bitmaps usage:
If both specifications are provided, then stock_id
is used if it is recognized by wxArtProvider and the provided bitmap file is used as a fallback.
Style properties (such as window's style or sizer flags) use syntax similar to C++: the style value is OR-combination of individual flags. Symbolic names identical to those used in C++ code are used for the flags. Flags are separated with "|" (whitespace is allowed but not required around it).
The flags that are allowed for a given property are context-dependent.
Examples:
XRC uses similar, but more flexible, abstract description of fonts to that used by wxFont class. A font can be described either in terms of its elementary properties, or it can be derived from one of system fonts or the parent window font.
The font property element is a "composite" element: unlike majority of properties, it doesn't have text value but contains several child elements instead. These children are handled in the same way as object properties and can be one of the following "sub-properties":
property | type | description |
---|---|---|
size | unsigned integer | Pixel size of the font (default: wxNORMAL_FONT's size or sysfont's size if the sysfont property is used or the current size of the font of the enclosing control if the inherit property is used. |
style | enum | One of "normal", "italic" or "slant" (default: normal). |
weight | enum | One of "normal", "bold" or "light" (default: normal). |
family | enum | One of "roman", "script", "decorative", "swiss", "modern" or "teletype" (default: roman). |
underlined | Boolean | Whether the font should be underlined (default: 0). |
face | Comma-separated list of face names; the first one available is used (default: unspecified). | |
encoding | Charset of the font, unused in Unicode build), as string (default: unspecified). | |
sysfont | Symbolic name of system standard font(one of wxSYS_*_FONT constants). | |
inherit | Boolean | If true, the font of the enclosing control is used. If this property and the sysfont property are specified the sysfont property takes precedence. |
relativesize | float | Float, font size relative to chosen system font's or inherited font's size; can only be used when 'sysfont' or 'inherit' is used and when 'size' is not used. |
All of them are optional, if they are missing, appropriate wxFont default is used. If the sysfont
or inherit
property is used, then the defaults are taken from it instead.
Examples:
inherit
for a font that gets used before the enclosing control is created, e.g. if the control gets the font passed as parameter for its constructor, or if the control is not derived from wxWindow.Defines a wxImageList.
The imagelist property element is a "composite" element: unlike majority of properties, it doesn't have text value but contains several child elements instead. These children are handled similarly to object properties and can be one of the following "sub-properties":
property | type | description |
---|---|---|
mask | Boolean | If masks should be created for all images (default: 1). |
size | Size | The size of the images in the list (default: the size of the first bitmap). |
bitmap | Bitmap | Adds a new image. Unlike normal object properties, bitmap may be used more than once to add multiple images to the list. At least one bitmap value is required. |
Example:
This section describes support wxWindow-derived classes in XRC format.
The following properties are always (unless stated otherwise in control-specific docs) available for windows objects. They are omitted from properties lists below.
property | type | description |
---|---|---|
pos | Position | Initial position of the window (default: wxDefaultPosition). |
size | Size | Initial size of the window (default: wxDefaultSize). |
style | Style | Window style for this control. The allowed values depend on what window is being created, consult respective class' constructor documentation for details (default: window-dependent default, usually wxFOO_DEFAULT_STYLE if defined for class wxFoo, 0 if not). |
exstyle | Style | Extra style for the window, if any. See wxWindow::SetExtraStyle() (default: not set). |
fg | Colour | Foreground colour of the window (default: window's default). |
ownfg | Colour | Non-inheritable foreground colour of the window, see wxWindow::SetOwnForegroundColour() (default: none). |
bg | Colour | Background colour of the window (default: window's default). |
ownbg | Colour | Non-inheritable background colour of the window, see wxWindow::SetOwnBackgroundColour() (default: none). |
enabled | Boolean | If set to 0, the control is disabled (default: 1). |
focused | Boolean | If set to 1, the control has focus initially (default: 0). |
hidden | Boolean | If set to 1, the control is created hidden (default: 0). |
tooltip | Text | Tooltip to use for the control (default: not set). |
font | Font | Font to use for the control (default: window's default). |
ownfont | Font | Non-inheritable font to use for the control, see wxWindow::SetOwnFont() (default: none). |
help | Text | Context-sensitive help for the control, used by wxHelpProvider (default: not set). |
All of these properties are optional.
This section lists all controls supported by default. For each control, its control-specific properties are listed. If the control can have child objects, it is documented there too; unless said otherwise, XRC elements for these controls cannot have children.
property | type | description |
---|---|---|
animation | URL | Animation file to load into the control (default: none). |
inactive-bitmap | Bitmap | Bitmap to use when not playing the animation (default: the default). |
A wxAuiNotebook can have one or more child objects of the notebookpage
pseudo-class. notebookpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Page label (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each notebookpage
must have exactly one non-toplevel window as its child.
Example:
Notice that wxAuiNotebook support in XRC is available in wxWidgets 2.9.5 and later only and you need to explicitly register its handler using
to use it.
Building an XRC for wxAuiToolBar is quite similar to wxToolBar. The only significant differences are:
Refer to the section wxToolBar for more details.
property | type | description |
---|---|---|
direction | wxLEFT|wxRIGHT|wxTOP|wxBOTTOM | The side along which the banner will be positioned (default: wxLEFT). |
bitmap | Bitmap | Bitmap to use as the banner background (default: none). |
title | Text | Banner title, should be single line (default: none). |
message | Text | Possibly multi-line banner message (default: none). |
gradient-start | Colour | Starting colour of the gradient used as banner background. (Optional. Can't be used if a valid bitmap is specified. If used, both gradient values must be set.) |
gradient-end | Colour | End colour of the gradient used as banner background. (Optional. Can't be used if a valid bitmap is specified. If used, both gradient values must be set.) |
property | type | description |
---|---|---|
default | Boolean | Should this button be the default button in dialog (default: 0)? |
bitmap | Bitmap | Bitmap to show on the button (default: none). |
selected | Bitmap | Bitmap to show when the button is selected (default: none, same as bitmap ). |
focus | Bitmap | Bitmap to show when the button has focus (default: none, same as bitmap ). |
disabled | Bitmap | Bitmap to show when the button is disabled (default: none, same as bitmap ). |
hover | Bitmap | Bitmap to show when mouse cursor hovers above the bitmap (default: none, same as bitmap ). |
property | type | description |
---|---|---|
selection | integer | Index of the initially selected item or -1 for no selection (default: -1). |
value | String | Initial value in the control (doesn't have to be one of @ content values; default: empty). |
If both value
and selection
are specified and selection
is not -1, then selection
takes precedence.
A wxBitmapComboBox can have one or more child objects of the ownerdrawnitem
pseudo-class. ownerdrawnitem
objects have the following properties:
property | type | description |
---|---|---|
text | Text | Item's label (default: empty). |
bitmap | Bitmap | Item's bitmap (default: no bitmap). |
Example:
property | type | description |
---|---|---|
bitmap | Bitmap | Label to display on the button (default: none). |
checked | Boolean | Should the button be checked/pressed initially (default: 0)? |
property | type | description |
---|---|---|
label | Text | Label to display on the button (may be omitted if only the bitmap or stock ID is used). |
bitmap | Bitmap | Bitmap to display in the button (optional). |
bitmapposition | wxLEFT|wxRIGHT|wxTOP|wxBOTTOM | Position of the bitmap in the button, see wxButton::SetBitmapPosition() (default: wxLEFT). |
default | Boolean | Should this button be the default button in dialog (default: 0)? |
No additional properties.
property | type | description |
---|---|---|
label | Text | Label to use for the checkbox (default: empty). |
checked | Boolean | Should the checkbox be checked initially (default: 0)? |
property | type | description |
---|---|---|
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (default: empty). |
The <item>
elements have listbox items' labels as their text values. They can also have optional checked
XML attribute – if set to "1", the value is initially checked.
Example:
property | type | description |
---|---|---|
selection | integer | Index of the initially selected item or -1 for no selection (default: -1). |
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (default: empty). |
Example:
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none, built implicitly). |
Additionally, a choicebook can have one or more child objects of the choicebookpage
pseudo-class (similarly to wxNotebook and its notebookpage
).
choicebookpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Sheet page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none, mutually exclusive with image ). |
image | integer | The zero-based index of the image associated with the item into the image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each choicebookpage
has exactly one non-toplevel window as its child.
The wxCommandLinkButton contains a main title-like label
and an optional note
for longer description. The main label
and the note
can be concatenated into a single string using a new line character between them (notice that the note
part can have more new lines in it).
property | type | description |
---|---|---|
label | Text | First line of text on the button, typically the label of an action that will be made when the button is pressed (default: empty). |
note | Text | Second line of text describing the action performed when the button is pressed (default: none). |
property | type | description |
---|---|---|
label | Text | Label to use for the collapsible section (default: empty). |
collapsed | Boolean | Should the pane be collapsed initially (default: 0)? |
wxCollapsiblePane may contain single optional child object of the panewindow
pseudo-class type. panewindow
itself must contain exactly one child that is a sizer or a non-toplevel window object.
property | type | description |
---|---|---|
value | Colour | Initial value of the control (default: wxBLACK). |
property | type | description |
---|---|---|
selection | integer | Index of the initially selected item or -1 for no selection (default: not used). |
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (default: empty). |
value | String | Initial value in the control (doesn't have to be one of @ content values; default: empty). |
If both value
and selection
are specified and selection
is not -1, then selection
takes precedence.
Example:
property | type | description |
---|---|---|
value | String | Initial value in the control (default: empty). |
No additional properties.
property | type | description |
---|---|---|
title | Text | Dialog's title (default: empty). |
icon | Bitmap | Dialog's icon (default: not used). |
centered | Boolean | Whether the dialog should be centered on the screen (default: 0). |
wxDialog may have optional children: either exactly one sizer child or any number of non-toplevel window objects. If sizer child is used, it sets size hints too.
property | type | description |
---|---|---|
value | String | Initial value of the control (default: empty). |
message | Text | Message shown to the user in wxDirDialog shown by the control (default: empty). |
property | type | description |
---|---|---|
label | Text | Label shown above the list (default: empty). |
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (default: empty). |
Example:
property | type | description |
---|---|---|
defaultdirectory | String | Sets the current directory displayed in the control (default: empty). |
defaultfilename | String | Selects a certain file (default: empty). |
wildcard | String | Sets the wildcard, which can contain multiple file types, for example: "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" (default: all files). |
property | type | description |
---|---|---|
value | String | Initial value of the control (default: empty). |
message | Text | Message shown to the user in wxDirDialog shown by the control (default: empty). |
wildcard | String | Sets the wildcard, which can contain multiple file types, for example: "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" (default: all files). |
property | type | description |
---|---|---|
value | Font | Initial value of the control (default: wxNORMAL_FONT). |
property | type | description |
---|---|---|
title | Text | Frame's title (default: empty). |
icon | Bitmap | Frame's icon (default: not used). |
centered | Boolean | Whether the frame should be centered on the screen (default: 0). |
wxFrame may have optional children: either exactly one sizer child or any number of non-toplevel window objects. If sizer child is used, it sets size hints too.
property | type | description |
---|---|---|
range | integer | Maximum value of the gauge (default: 100). |
value | integer | Initial value of the control (default: 0). |
shadow | Dimension | Rendered shadow size (default: none; ignored by most platforms). |
bezel | Dimension | Rendered bezel size (default: none; ignored by most platforms). |
property | type | description |
---|---|---|
defaultfolder | String | Initial folder (default: empty). |
filter | Text | Filter string, using the same syntax as used by wxFileDialog, e.g. "All files (*.*)|*.*|JPEG files (*.jpg)|*.jpg" (default: empty). |
defaultfilter | integer | Zero-based index of default filter (default: 0). |
No additional properties.
property | type | description |
---|---|---|
url | URL | Page to display in the window (default: none). |
htmlcode | Text | HTML markup to display in the window (default: none). |
borders | Dimension | Border around HTML content (default: 0). |
At most one of url
and htmlcode
properties may be specified, they are mutually exclusive. If neither is set, the window is initialized to show empty page.
property | type | description |
---|---|---|
label | Text | Label to display on the control (default: empty). |
url | URL | URL to open when the link is clicked (default: empty). |
property | type | description |
---|---|---|
selection | integer | Index of the initially selected item or -1 for no selection (default: -1). |
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (default: empty). |
Example:
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none, built implicitly). |
Additionally, a listbook can have one or more child objects of the listbookpage
pseudo-class (similarly to wxNotebook and its notebookpage
).
listbookpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Sheet page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none, mutually exclusive with image ). |
image | integer | The zero-based index of the image associated with the item into the image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each listbookpage
has exactly one non-toplevel window as its child.
property | type | description |
---|---|---|
imagelist | Image List | The normal (wxIMAGE_LIST_NORMAL) image list (default: none, built implicitly). |
imagelist-small | Image List | The small (wxIMAGE_LIST_SMALL) image list (default: none, built implicitly). |
A list control can have optional child objects of the listitem class. Report mode list controls (i.e. created with wxLC_REPORT
style) can in addition have optional listcol child objects.
The listcol
class can only be used for wxListCtrl children. It can have the following properties (all of them optional):
property | type | description |
---|---|---|
align | wxListColumnFormat | The alignment for the item. Can be one of wxLIST_FORMAT_LEFT , wxLIST_FORMAT_RIGHT or wxLIST_FORMAT_CENTRE . |
text | Text | The title of the column. |
width | integer | The column width. |
image | integer | The zero-based index of the image associated with the item in the 'small' image list. |
The columns are appended to the control in order of their appearance and may be referenced by 0-based index in the col
attributes of subsequent listitem
objects.
The listitem
is a child object for the class wxListCtrl. It can have the following properties (all of them optional):
property | type | description |
---|---|---|
align | wxListColumnFormat | The alignment for the item. Can be one of wxLIST_FORMAT_LEFT , wxLIST_FORMAT_RIGHT or wxLIST_FORMAT_CENTRE . |
bg | Colour | The background color for the item. |
bitmap | Bitmap | Add a bitmap to the (normal) Image List associated with the wxListCtrl parent and associate it with this item. If the imagelist is not defined it will be created implicitly (default: none, mutually exclusive with image ). |
bitmap-small | Bitmap | Add a bitmap in the 'small' Image List associated with the wxListCtrl parent and associate it with this item. If the 'small' imagelist is not defined it will be created implicitly (default: none, mutually exclusive with image-small ). |
col | integer | The zero-based column index. |
image | integer | The zero-based index of the image associated with the item in the (normal) image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
image-small | integer | The zero-based index of the image associated with the item in the 'small' image list (default: none, mutually exclusive with bitmap-small , only if imagelist-small was set). |
data | integer | The client data for the item. |
font | Font | The font for the item. |
state | Style | The item state. Can be any combination of the following values:
|
text | Text | The text label for the item. |
textcolour | Colour | The text colour for the item. |
Notice that the item position can't be specified here, the items are appended to the list control in order of their appearance.
wxMDIParentFrame supports the same properties that wxFrame does.
wxMDIParentFrame may have optional children. When used, the child objects must be of wxMDIChildFrame type.
wxMDIChildFrame supports the same properties that wxFrame and wxMDIParentFrame do.
wxMDIChildFrame can only be used as as immediate child of wxMDIParentFrame.
wxMDIChildFrame may have optional children: either exactly one sizer child or any number of non-toplevel window objects. If sizer child is used, it sets size hints too.
property | type | description |
---|---|---|
label | Text | Menu's label (default: empty, but required for menus other than popup menus). |
style | Style | Window style for the menu. |
help | Text | Help shown in statusbar when the menu is selected (only for submenus of another wxMenu, default: none). |
enabled | Boolean | Is the submenu item enabled (only for submenus of another wxMenu, default: 1)? |
Note that unlike most controls, wxMenu does not have Standard Properties, with the exception of style
.
A menu object can have one or more child objects of the wxMenuItem or wxMenu classes or break
or separator
pseudo-classes.
The separator
pseudo-class is used to insert separators into the menu and has neither properties nor children. Likewise, break
inserts a break (see wxMenu::Break()).
wxMenuItem objects support the following properties:
property | type | description |
---|---|---|
label | Text | Item's label (may be omitted if stock ID is used). |
accel | Non-Translatable Text | Item's accelerator (default: none). |
radio | Boolean | Item's kind is wxITEM_RADIO (default: 0)? |
checkable | Boolean | Item's kind is wxITEM_CHECK (default: 0)? |
bitmap | Bitmap | Bitmap to show with the item (default: none). |
bitmap2 | Bitmap | Bitmap for the checked state (wxMSW, if checkable; default: none). |
help | Text | Help shown in statusbar when the item is selected (default: none). |
enabled | Boolean | Is the item enabled (default: 1)? |
checked | Boolean | Is the item checked initially (default: 0)? |
Example:
property | type | description |
---|---|---|
style | Style | Window style for the menu bar. |
Note that unlike most controls, wxMenuBar does not have Standard Properties, with the exception of style
.
A menubar can have one or more child objects of the wxMenu class.
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none, built implicitly). |
A notebook can have one or more child objects of the notebookpage
pseudo-class.
notebookpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none, mutually exclusive with image ). |
image | integer | The zero-based index of the image associated with the item into the image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each notebookpage
has exactly one non-toplevel window as its child.
Example:
wxOwnerDrawnComboBox has the same properties as wxComboBox, plus the following additional properties:
property | type | description |
---|---|---|
buttonsize | Size | Size of the dropdown button (default: default). |
No additional properties.
wxPanel may have optional children: either exactly one sizer child or any number of non-toplevel window objects.
property | type | description |
---|---|---|
title | Text | Dialog's title (default: empty). |
icon | Bitmap | Dialog's icon (default: not used). |
centered | Boolean | Whether the dialog should be centered on the screen (default: 0). |
buttons | Style | Buttons to show, combination of flags accepted by wxPropertySheetDialog::CreateButtons() (default: 0). |
A sheet dialog can have one or more child objects of the propertysheetpage
pseudo-class (similarly to wxNotebook and its notebookpage
). propertysheetpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Sheet page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each propertysheetpage
has exactly one non-toplevel window as its child.
property | type | description |
---|---|---|
label | Text | Label shown on the radio button (default: empty). |
value | Boolean | Initial value of the control (default: 0). |
property | type | description |
---|---|---|
label | Text | Label for the whole box (default: empty). |
dimension | integer | Specifies the maximum number of rows (if style contains wxRA_SPECIFY_ROWS ) or columns (if style contains wxRA_SPECIFY_COLS ) for a two-dimensional radiobox (default: 1). |
selection | integer | Index of the initially selected item or -1 for no selection (default: -1). |
content | items | Content of the control; this property has any number of <item> XML elements as its children, with the items text as their text values (see below; default: empty). |
The <item>
elements have radio buttons' labels as their text values. They can also have some optional XML attributes (not properties!):
attribute | type | description |
---|---|---|
tooltip | String | Tooltip to show over this ratio button (default: none). |
helptext | String | Contextual help for this radio button (default: none). |
enabled | Boolean | Is the button enabled (default: 1)? |
hidden | Boolean | Is the button hidden initially (default: 0)? |
Example:
property | type | description |
---|---|---|
art-provider | String | One of default , aui or msw (default: default ). |
A wxRibbonBar may have wxRibbonPage child objects. The page
pseudo-class may be used instead of wxRibbonPage
when used as wxRibbonBar children.
Example:
Notice that wxRibbonBar support in XRC is available in wxWidgets 2.9.5 and later only and you need to explicitly register its handler using
to use it.
No additional properties.
wxRibbonButtonBar can have child objects of the button
pseudo-class. button
objects have the following properties:
property | type | description |
---|---|---|
hybrid | Boolean | If true, the wxRIBBON_BUTTON_HYBRID kind is used (default: false). |
disabled | Boolean | Whether the button should be disabled (default: false). |
label | Text | Item's label (default: empty). |
bitmap | Bitmap | Item's bitmap (default: none). |
small-bitmap | Bitmap | Small bitmap (default: none). |
disabled-bitmap | Bitmap | Disabled bitmap (default: none). |
small-disabled-bitmap | Bitmap | Small disabled bitmap (default: none). |
help | Text | Item's help text (default: none). |
No additional properties.
Objects of this type must be subclassed with the subclass
attribute.
No additional properties.
wxRibbonGallery can have child objects of the item
pseudo-class. item
objects have the following properties:
property | type | description |
---|---|---|
bitmap | Bitmap | Item's bitmap (default: none). |
property | type | description |
---|---|---|
label | Text | Label (default: none). |
icon | Bitmap | Icon (default: none). |
A wxRibbonPage may have children of any type derived from wxRibbonControl. Most commontly, wxRibbonPanel is used. As a special case, the panel
pseudo-class may be used instead of wxRibbonPanel
when used as wxRibbonPage children.
property | type | description |
---|---|---|
label | Text | Label (default: none). |
icon | Bitmap | Icon (default: none). |
A wxRibbonPanel may have children of any type derived from wxRibbonControl or a single wxSizer child with non-ribbon windows in it.
property | type | description |
---|---|---|
value | Text | Initial value of the control (default: empty). |
maxlength | integer | Maximum length of the text entered (default: unlimited). |
Notice that wxRichTextCtrl support in XRC is available in wxWidgets 2.9.5 and later only and you need to explicitly register its handler using
to use it.
property | type | description |
---|---|---|
value | integer | Initial position of the scrollbar (default: 0). |
range | integer | Maximum value of the gauge (default: 10). |
thumbsize | integer | Size of the thumb (default: 1). |
pagesize | integer | Page size (default: 1). |
property | type | description |
---|---|---|
scrollrate | Size | Scroll rate in x and y directions (default: not set; required if the window has a sizer child). |
wxScrolledWindow may have optional children: either exactly one sizer child or any number of non-toplevel window objects. If sizer child is used, wxSizer::FitInside() is used (instead of wxSizer::Fit() as usual) and so the children don't determine scrolled window's minimal size, they only affect virtual size. Usually, both scrollrate
and either size
or minsize
on containing sizer item should be used in this case.
wxSimpleHtmlListBox has same properties as wxListBox. The only difference is that the text contained in <item>
elements is HTML markup. Note that the markup has to be escaped:
(X)HTML markup elements cannot be included directly:
property | type | description |
---|---|---|
value | integer | Initial value of the control (default: 0). |
min | integer | Minimum allowed value (default: 0). |
max | integer | Maximum allowed value (default: 100). |
pagesize | integer | Page size; number of steps the slider moves when the user moves pages up or down (default: unset). |
linesize | integer | Line size; number of steps the slider moves when the user moves it up or down a line (default: unset). |
tickfreq | integer | Tick marks frequency (Windows only; default: unset). |
tick | integer | Tick position (Windows only; default: unset). |
thumb | integer | Thumb length (Windows only; default: unset). |
selmin | integer | Selection start position (Windows only; default: unset). |
selmax | integer | Selection end position (Windows only; default: unset). |
property | type | description |
---|---|---|
value | integer | Initial value of the control (default: 0). |
min | integer | Minimum allowed value (default: 0). |
max | integer | Maximum allowed value (default: 100). |
wxSpinCtrl supports the same properties as wxSpinButton and, since wxWidgets 2.9.5, another one:
base | integer | Numeric base, currently can be only 10 or 16 (default: 10). |
property | type | description |
---|---|---|
orientation | String | Orientation of the splitter, either "vertical" or "horizontal" (default: horizontal). |
sashpos | Dimension | Initial position of the sash (default: 0). |
minsize | Dimension | Minimum child size (default: not set). |
gravity | Floating-point value | Sash gravity, see wxSplitterWindow::SetSashGravity() (default: not set). |
wxSplitterWindow must have one or two children that are non-toplevel window objects. If there's only one child, it is used as wxSplitterWindow's only visible child. If there are two children, the first one is used for left/top child and the second one for right/bottom child window.
property | type | description |
---|---|---|
value | Text | Initial value of the control (default: empty). |
property | type | description |
---|---|---|
fields | integer | Number of status bar fields (default: 1). |
widths | String | Comma-separated list of fields integers. Each value specifies width of one field; the values are interpreted using the same convention used by wxStatusBar::SetStatusWidths() (default: not set). |
styles | String | Comma-separated list of fields style values. Each value specifies style of one field and can be one of wxSB_NORMAL , wxSB_FLAT , wxSB_RAISED or wxSB_SUNKEN (default: not set). |
property | type | description |
---|---|---|
bitmap | Bitmap | Bitmap to display (required). |
property | type | description |
---|---|---|
label | Text | Static box's label (default: empty). |
No additional properties.
property | type | description |
---|---|---|
label | Text | Label to display (default: empty). |
wrap | Dimension | Wrap the text so that each line is at most the given number of pixels, see wxStaticText::Wrap() (default: no wrap). |
property | type | description |
---|---|---|
value | Text | Initial value of the control (default: empty). |
maxlength | integer | Maximum length of the text which can be entered by user (default: unlimited). |
hint | Text | Hint shown in empty control (new since wxWidgets 3.0.1). |
No additional properties.
property | type | description |
---|---|---|
label | Text | Label to display on the button (default: empty). |
checked | Boolean | Should the button be checked/pressed initially (default: 0)? |
property | type | description |
---|---|---|
bitmapsize | Size | Size of toolbar bitmaps (default: not set). |
margins | Size | Margins (default: platform default). |
packing | integer | Packing, see wxToolBar::SetToolPacking() (default: not set). |
separation | integer | Default separator size, see wxToolBar::SetToolSeparation() (default: not set). |
dontattachtoframe | Boolean | If set to 0 and the toolbar object is child of a wxFrame, wxFrame::SetToolBar() is called; otherwise, you have to add it to a frame manually. The toolbar is attached by default, you have to set this property to 1 to disable this behaviour (default: 0). |
A toolbar can have one or more child objects of any wxControl-derived class or one of three pseudo-classes: separator
, space
or tool
.
The separator
pseudo-class is used to insert separators into the toolbar and has neither properties nor children. Similarly, the space
pseudo-class is used for stretchable spaces (see wxToolBar::AddStretchableSpace(), new since wxWidgets 2.9.1).
The tool
pseudo-class objects specify toolbar buttons and have the following properties:
property | type | description |
---|---|---|
bitmap | Bitmap | Tool's bitmap (default: empty). |
bitmap2 | Bitmap | Bitmap for disabled tool (default: derived from bitmap ). |
label | Text | Label to display on the tool (default: no label). |
radio | Boolean | Item's kind is wxITEM_RADIO (default: 0)? |
toggle | Boolean | Item's kind is wxITEM_CHECK (default: 0)? |
dropdown | see below | Item's kind is wxITEM_DROPDOWN (default: 0)? (only available since wxWidgets 2.9.0) |
tooltip | Text | Tooltip to use for the tool (default: none). |
longhelp | Text | Help text shown in statusbar when the mouse is on the tool (default: none). |
disabled | Boolean | Is the tool initially disabled (default: 0)? |
checked | Boolean | Is the tool initially checked (default: 0)? (only available since wxWidgets 2.9.3) |
The presence of a dropdown
property indicates that the tool is of type wxITEM_DROPDOWN. It must be either empty or contain exactly one wxMenu child object defining the drop-down button associated menu.
Notice that radio
, toggle
and dropdown
are mutually exclusive.
Children that are not tool
, space
or separator
must be instances of classes derived from wxControl and are added to the toolbar using wxToolBar::AddControl().
Example:
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none, built implicitly). |
A toolbook can have one or more child objects of the toolbookpage
pseudo-class (similarly to wxNotebook and its notebookpage
).
toolbookpage
objects have the following properties:
property | type | description |
---|---|---|
label | Text | Sheet page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none, mutually exclusive with image ). |
image | integer | The zero-based index of the image associated with the item into the image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
Each toolbookpage
has exactly one non-toplevel window as its child.
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none). |
property | type | description |
---|---|---|
imagelist | Image List | Image list to use for the images (default: none, built implicitly). |
A treebook can have one or more child objects of the treebookpage
pseudo-class (similarly to wxNotebook and its notebookpage
).
treebookpage
objects have the following properties:
property | type | description |
---|---|---|
depth | integer | Page's depth in the labels tree (default: 0; see below). |
label | Text | Sheet page's title (default: empty). |
bitmap | Bitmap | Bitmap shown alongside the label (default: none, mutually exclusive with image ). |
image | integer | The zero-based index of the image associated with the item into the image list (default: none, mutually exclusive with bitmap , only if imagelist was set). |
selected | Boolean | Is the page selected initially (only one page can be selected; default: 0)? |
expanded | Boolean | If set to 1, the page is initially expanded. By default all pages are initially collapsed. |
Each treebookpage
has exactly one non-toplevel window as its child.
The tree of labels is not described using nested treebookpage
objects, but using the depth property. Toplevel pages have depth 0, their child pages have depth 1 and so on. A treebookpage's
label is inserted as child of the latest preceding page with depth equal to depth-1. For example, this XRC markup:
corresponds to the following tree of labels:
property | type | description |
---|---|---|
bitmap | Bitmap | Bitmap to display on the left side of the wizard (default: none). |
A wizard object can have one or more child objects of the wxWizardPage or wxWizardPageSimple classes. They both support the following properties (in addition to Standard Properties):
property | type | description |
---|---|---|
title | Text | Wizard window's title (default: none). |
bitmap | Bitmap | Page-specific bitmap (default: none). |
wxWizardPage and wxWizardPageSimple nodes may have optional children: either exactly one sizer child or any number of non-toplevel window objects.
wxWizardPageSimple pages are automatically chained together; wxWizardPage pages transitions must be handled programmatically.
Sizers are handled slightly differently in XRC resources than they are in wxWindow hierarchy. wxWindow's sizers hierarchy is parallel to the wxWindow children hierarchy: child windows are children of their parent window and the sizer (or sizers) form separate hierarchy attached to the window with wxWindow::SetSizer().
In XRC, the two hierarchies are merged together: sizers are children of other sizers or windows and they can contain child window objects.
If a sizer is child of a window object in the resource, it must be the only child and it will be attached to the parent with wxWindow::SetSizer(). Additionally, if the window doesn't have its size explicitly set, wxSizer::Fit() is used to resize the window. If the parent window is toplevel window, wxSizer::SetSizeHints() is called to set its hints.
A sizer object can have one or more child objects of one of two pseudo-classes: sizeritem
or spacer
(see wxStdDialogButtonSizer for an exception). The former specifies an element (another sizer or a window) to include in the sizer, the latter adds empty space to the sizer.
sizeritem
objects have exactly one child object: either another sizer object, or a window object. spacer
objects don't have any children, but they have one property:
property | type | description |
---|---|---|
size | Size | Size of the empty space (default: wxDefaultSize ). |
Both sizeritem
and spacer
objects can have any of the following properties:
property | type | description |
---|---|---|
option | integer | The "option" value for sizers. Used by wxBoxSizer to set proportion of the item in the growable direction (default: 0). |
flag | Style | wxSizerItem flags (default: 0). |
border | Dimension | Size of the border around the item (directions are specified in flags) (default: 0). |
minsize | Size | Minimal size of this item (default: no min size). |
ratio | Size | Item ratio, see wxSizer::SetRatio() (default: no ratio). |
cellpos | Position | (wxGridBagSizer only) Position, see wxGBSizerItem::SetPos() (required). |
cellspan | Size | (wxGridBagSizer only) Span, see wxGBSizerItem::SetSpan() (required). |
Example of sizers XRC code:
The sizer classes that can be used are listed below, together with their class-specific properties. All classes support the following properties:
property | type | description |
---|---|---|
minsize | Size | Minimal size that this sizer will have, see wxSizer::SetMinSize() (default: no min size). |
property | type | description |
---|---|---|
orient | Style | Sizer orientation, "wxHORIZONTAL" or "wxVERTICAL" (default: wxHORIZONTAL). |
property | type | description |
---|---|---|
orient | Style | Sizer orientation, "wxHORIZONTAL" or "wxVERTICAL" (default: wxHORIZONTAL). |
label | Text | Label to be used for the static box around the sizer (default: empty). |
property | type | description |
---|---|---|
rows | unsigned integer | Number of rows in the grid (default: 0 - determine automatically). |
cols | unsigned integer | Number of columns in the grid (default: 0 - determine automatically). |
vgap | Dimension | Vertical gap between children (default: 0). |
hgap | Dimension | Horizontal gap between children (default: 0). |
property | type | description |
---|---|---|
rows | unsigned integer | Number of rows in the grid (default: 0 - determine automatically). |
cols | unsigned integer | Number of columns in the grid (default: 0 - determine automatically). |
vgap | Dimension | Vertical gap between children (default: 0). |
hgap | Dimension | Horizontal gap between children (default: 0). |
flexibledirection | Style | Flexible direction, wxVERTICAL , wxHORIZONTAL or wxBOTH (default). This property is only available since wxWidgets 2.9.5. |
nonflexiblegrowmode | Style | Grow mode in the non-flexible direction, wxFLEX_GROWMODE_NONE , wxFLEX_GROWMODE_SPECIFIED (default) or wxFLEX_GROWMODE_ALL . This property is only available since wxWidgets 2.9.5. |
growablerows | comma-separated integers list | Comma-separated list of indexes of rows that are growable (none by default). Since wxWidgets 2.9.5 optional proportion can be appended to each number after a colon ( :). |
growablecols | comma-separated integers list | Comma-separated list of indexes of columns that are growable (none by default). Since wxWidgets 2.9.5 optional proportion can be appended to each number after a colon ( :). |
property | type | description |
---|---|---|
vgap | Dimension | Vertical gap between children (default: 0). |
hgap | Dimension | Horizontal gap between children (default: 0). |
flexibledirection | Style | Flexible direction, wxVERTICAL , wxHORIZONTAL , wxBOTH (default: wxBOTH ). |
nonflexiblegrowmode | Style | Grow mode in the non-flexible direction, wxFLEX_GROWMODE_NONE , wxFLEX_GROWMODE_SPECIFIED , wxFLEX_GROWMODE_ALL (default: wxFLEX_GROWMODE_SPECIFIED ). |
growablerows | comma-separated integers list | Comma-separated list of indexes of rows that are growable, optionally the proportion can be appended after each number separated by a : (default: none). |
growablecols | comma-separated integers list | Comma-separated list of indexes of columns that are growable, optionally the proportion can be appended after each number separated by a : (default: none). |
property | type | description |
---|---|---|
orient | Style | Sizer orientation, "wxHORIZONTAL" or "wxVERTICAL" (default: wxHORIZONTAL). |
flag | Style | wxWrapSizer flags (default: 0). |
Unlike other sizers, wxStdDialogButtonSizer has neither sizeritem
nor spacer
children. Instead, it has one or more children of the button
pseudo-class. button
objects have no properties and they must always have exactly one child of the wxButton
class or a class derived from wxButton.
Example:
In addition to describing UI elements, XRC files can contain non-windows objects such as bitmaps or icons. This is a concession to Windows developers used to storing them in Win32 resources.
Note that unlike Win32 resources, bitmaps included in XRC files are not embedded in the XRC file itself. XRC file only contains a reference to another file with bitmap data.
Bitmaps are stored in <object>
element with class set to wxBitmap
. Such bitmaps can then be loaded using wxXmlResource::LoadBitmap(). The content of the element is exactly same as in the case of bitmap properties, except that toplevel <object>
is used.
For example, instead of:
toplevel wxBitmap resources would look like:
wxIcon resources are identical to wxBitmap ones, except that the class is wxIcon
.
It is possible to conditionally process parts of XRC files on some platforms only and ignore them on other platforms. Any element in XRC file, be it toplevel or arbitrarily nested one, can have the platform
attribute. When used, platform
contains |-separated list of platforms that this element should be processed on. It is filtered out and ignored on any other platforms.
Possible elemental values are:
win | Windows |
mac | Mac OS X (or Mac Classic in wxWidgets version supporting it) |
unix | Any Unix platform except OS X |
Examples:
Usually you won't care what value the XRCID macro returns for the ID of an object. Sometimes though it is convenient to have a range of IDs that are guaranteed to be consecutive. An example of this would be connecting a group of similar controls to the same event handler.
The following XRC fragment 'declares' an ID range called foo and another called bar; each with some items.
For the range foo, no size or start parameters were given, so the size will be calculated from the number of range items, and IDs allocated by wxWindow::NewControlId (so they'll be negative). Range bar asked for a size of 30, so this will be its minimum size: should it have more items, the range will automatically expand to fit them. It specified a start ID of 10000, so XRCID("bar[0]") will be 10000, XRCID("bar[1]") 10001 etc. Note that if you choose to supply a start value it must be positive, and it's your responsibility to avoid clashes.
For every ID range, the first item can be referenced either as rangename[0] or rangename[start]. Similarly rangename[end] is the last item. Using [start] and [end] is more descriptive in e.g. a Bind() event range or a for loop, and they don't have to be altered whenever the number of items changes.
Whether a range has positive or negative IDs, [start] is always a smaller number than [end]; so code like this works as expected:
ID ranges can be seen in action in the objref dialog section of the XRC Sample.
The XRC format is designed to be extensible and allows specifying and loading custom controls. The three available mechanisms are described in the rest of this section in the order of increasing complexity.
The simplest way to add custom controls is to set the subclass
attribute of <object>
element:
In that case, wxXmlResource will create an instance of the specified subclass (MyTextCtrl
in the example above) instead of the class (wxTextCtrl
above) when loading the resource. However, the rest of the object's loading (calling its Create() method, setting its properties, loading any children etc.) will proceed in exactly the same way as it would without subclass
attribute. In other words, this approach is only sufficient when the custom class is just a small modification (e.g. overridden methods or customized events handling) of an already supported classes.
The subclass must satisfy a number of requirements:
class
attribute.class'
Create() method (this is because XRC will call Create() of class
, not subclass
). In other words, creation of the control must not be customized.A more flexible solution is to put a placeholder in the XRC file and replace it with custom control after the resource is loaded. This is done by using the unknown
pseudo-class:
The placeholder is inserted as dummy wxPanel that will hold custom control in it. At runtime, after the resource is loaded and a window created from it (using e.g. wxXmlResource::LoadDialog()), use code must call wxXmlResource::AttachUnknownControl() to insert the desired control into placeholder container.
This method makes it possible to insert controls that are not known to XRC at all, but it's also impossible to configure the control in XRC description in any way. The only properties that can be specified are the standard window properties.
unknown
class cannot be combined with subclass
attribute, they are mutually exclusive.Finally, XRC allows adding completely new classes in addition to the ones listed in this document. A class for which wxXmlResourceHandler is implemented can be used as first-class object in XRC simply by passing class name as the value of class
attribute:
The only requirements on the class are that
Child elements of <object>
are handled by the custom handler and there are no limitations on them imposed by XRC format.
This is the only mechanism that works for toplevel objects – custom controls are accessible using the type-unsafe wxXmlResource::LoadObject() method.
In addition to plain XRC files, wxXmlResource supports (if wxFileSystem support is compiled in) compressed XRC resources. Compressed resources have either .zip or .xrs extension and are simply ZIP files that contain arbitrary number of XRC files and their dependencies (bitmaps, icons etc.).
This section describes differences in older revisions of XRC format (i.e. files with older values of version
attribute of <resource>
).
Version 2.5.3.0 introduced C-like handling of "\\" in text. In older versions, "\n", "\t" and "\r" escape sequences were replaced with respective characters in the same matter it's done in C, but "\\" was left intact instead of being replaced with single "\", as one would expect. Starting with 2.5.3.0, all of them are handled in C-like manner.
Prior to version 2.3.0.1, "$" was used for accelerators instead of "_" or "&". For example,
was used in place of current version's
(or "&File").