Version: 2.9.4
XRC File Format

目次:

This document describes the format of XRC resource files, as used by wxXmlResource.


Overview

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().

Resource Root Element

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 xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
    ...
</resource>

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

Defining Objects

Object Element

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:

  1. It is used by wxXmlResource's various LoadXXX() methods to find the resource by name passed as argument.
  2. wxWindow's name (see wxWindow::GetName()) is set to it.
  3. Numeric ID of a window or menu item is derived from the name. If the value represents an integer (in decimal notation), it is used for the numeric ID unmodified. If it is one of the wxID_XXX literals defined by wxWidgets (see Stock items), its respective value is used. Otherwise, the name is transformed into dynamically generated ID. See wxXmlResource::GetXRCID() for more information.

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:

  1. Object's properties. A property is a value describing part of object's behaviour, for example the "label" property on wxButton defines its label. In the most common form, property is a single element with text content ("\<label\>Cancel\</label\>"), but they may use nested subelements too (e.g. font property). A property can only be listed once in an object's definition.
  2. Child objects. Window childs, sizers, sizer items or notebook pages are all examples of child objects. They are represented using nested <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.

例:

<object class="wxDialog" name="example_dialog">
    <!-- properties: -->
    <title>Non-Derived Dialog Example</title>
    <centered>1</centered>
    <!-- child objects: -->
    <object class="wxBoxSizer">
        <orient>wxVERTICAL</orient>
        <cols>1</cols>
        <rows>0</rows>
        ...
    </object>
</object>

Object References

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:

<object class="wxDialog" name="my_dlg">
    ...
</object>
<object_ref name="my_dlg_alias" ref="my_dlg"/>

is equivalent to

<object class="wxDialog" name="my_dlg">
    ...
</object>
<object class="wxDialog" name="my_dlg_alias">
    ... <!-- same as in my_dlg -->
</object>

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:

  1. The referred object is used as the initial content.
  2. All attributes set on <object_ref> are added to it.
  3. All child elements of <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.
  4. Child elements in <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:

<object class="wxDialog" name="template">
    <title>Dummy dialog</title>
    <size>400,400</size>
</object>
<object_ref ref="template" name="my_dlg">
    <title>My dialog</title>
    <centered>1</centered>
</object_ref>

is identical to:

<object class="wxDialog" name="my_dlg">
    <title>My dialog</title>
    <size>400,400</size>
    <centered>1</centered>
</object>

Data Types

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

Boolean values are expressed using either "1" literal (true) or "0" (false).

Floating-point value

Floating point values use POSIX (C locale) formatting -- decimal separator is "." regardless of the locale.

Colour

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:

<fg>red</fg>
<fg>#ff0000</fg>
<fg>rgb(255,0,0)</fg>
<fg>wxSYS_COLOUR_HIGHLIGHT</fg>

Size

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:

42,-1
100,100
100,50d

Position

Same as Size.

Dimension

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.

Text

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

<!-- this is not translated: -->
<label translate="0">_Unix</label>
<!-- but this is: -->
<help>Use Unix-style newlines</help>
注:
Even though the "_" character is used instead of "&" for accelerators, it is still possible to use "&". The latter has to be encoded as "&amp;", though, so using "_" is more convenient.
参照:
Versions Before 2.5.3.0, Versions Before 2.3.0.1

Non-Translatable Text

Like Text, but the text is never translated and translate attribute cannot be used.

String

An unformatted string. Unlike with Text, no escaping or translations are done.

URL

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

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. 以下に例を示します:

<object class="tool" name="wxID_NEW">
    <tooltip>New</tooltip>
    <bitmap>new.png</bitmap>
</object>

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:

<bitmap stock_id="fixed-width"/>        <!-- custom app-specific art -->
<bitmap stock_id="wxART_FILE_OPEN"/>    <!-- standard art -->

Specifying the bitmap directly and using stock_id are mutually exclusive.

Style

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:

<style>wxCAPTION|wxSYSTEM_MENU | wxRESIZE_BORDER</style>
<exstyle>wxDIALOG_EX_CONTEXTHELP</exstyle>

Font

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.

The font property element is "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.
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).
relativesize float Float, font size relative to chosen system font's size; can only be used when 'sysfont' 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 property is used, then the defaults are taken from it instead.

Examples:

<font>
    <!-- fixed font: Arial if available, fall back to Helvetica -->
    <face>arial,helvetica</face>
    <size>12</size>
</font>

<font>
    <!-- enlarged, enboldened standard font: -->
    <sysfont>wxSYS_DEFAULT_GUI_FONT</sysfont>
    <weight>bold</weight>
    <relativesize>1.5</relativesize>
</font>

Controls and Windows

This section describes support wxWindow-derived classes in XRC format.

Standard Properties

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

Supported Controls

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.

wxAnimationCtrl

property type description
animation URL Animation file to load into the control (required).

wxBannerWindow

property type description
direction wxLEFT|wxRIGHT|wxTOP|wxBOTTOM The side along which the banner will be positioned.
bitmap Bitmap Bitmap to use as the banner background.
title Text Banner title, should be single line.
message Text Possibly multi-line banner message.
gradient-start Colour Starting colour of the gradient used as banner background. Can't be used if a valid bitmap is specified.
gradient-end Colour End colour of the gradient used as banner background. Can't be used if a valid bitmap is specified.

wxBitmapButton

property type description
default Boolean Should this button be the default button in dialog (default: 0)?
bitmap Bitmap Bitmap to show on the button (required).
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).

wxBitmapComboBox

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 (required).
bitmap Bitmap Item's bitmap (default: no bitmap).

例:

<object class="wxBitmapComboBox">
    <selection>1</selection>
    <object class="ownerdrawnitem">
        <text>Foo</text>
        <bitmap>foo.png</bitmap>
    </object>
    <object class="ownerdrawnitem">
        <text>Bar</text>
        <bitmap>bar.png</bitmap>
    </object>
</object>

wxBitmapToggleButton

property type description
bitmap Bitmap Label to display on the button (required).
checked Boolean Should the button be checked/pressed initially (default: 0)?

wxButton

property type description
label Text Label to display on the button (may be empty if only bitmap 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 Boolean Should this button be the default button in dialog (default: 0)?

wxCalendarCtrl

No additional properties.

wxCheckBox

property type description
label Text Label to use for the checkbox (required).
checked Boolean Should the checkbox be checked initially (default: 0)?

wxCheckListBox

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.

例:

<object class="wxCheckListBox">
    <content>
        <item checked="1">Download library</item>
        <item checked="1">Compile samples</item>
        <item checked="1">Skim docs</item>
        <item checked="1">Finish project</item>
        <item>Wash car</item>
    </content>
</object>

wxChoice

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

例:

<object class="wxChoice" name="controls_choice">
    <content>
        <item>See</item>
        <item>Hear</item>
        <item>Feel</item>
        <item>Smell</item>
        <item>Taste</item>
        <item>The Sixth Sense!</item>
    </content>
</object>

wxChoicebook

A choicebook can have one or more child objects of the choicebookpage pseudo-class (similarly to wxNotebook and its notebookpage) and one child object of the wxImageList class. choicebookpage objects have the following properties:

property type description
label Text Sheet page's title (required).
bitmap Bitmap Bitmap shown alongside the label (default: none).
image integer The zero-based index of the image associated with the item into the image list.
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.

wxCommandLinkButton

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.
note Text Second line of text describing the action performed when the button is pressed.

wxCollapsiblePane

property type description
label Text Label to use for the collapsible section (required).
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.

wxColourPickerCtrl

property type description
value Colour Initial value of the control (default: wxBLACK).

wxComboBox

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.

例:

<object class="wxComboBox" name="controls_combobox">
    <style>wxCB_DROPDOWN</style>
    <value>nedit</value>
    <content>
        <item>vim</item>
        <item>emacs</item>
        <item>notepad.exe</item>
        <item>bbedit</item>
    </content>
</object>

wxDatePickerCtrl

No additional properties.

wxDialog

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.

wxDirPickerCtrl

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 (required).

wxFileCtrl

property type description
defaultdirectory String Sets the current directory displayed in the control.
defaultfilename String Selects a certain file.
wildcard String Sets the wildcard, which can contain multiple file types, for example: "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".

wxFilePickerCtrl

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 (required).
wildcard String Sets the wildcard, which can contain multiple file types, for example: "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".

wxFontPickerCtrl

property type description
value Font Initial value of the control (default: wxNORMAL_FONT).

wxFrame

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.

wxGauge

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

wxGenericDirCtrl

property type description
defaultfolder Text 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).

wxGrid

No additional properties.

wxHtmlWindow

property type description
url URL Page to display in the window.
htmlcode Text HTML markup to display in the window.
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.

wxHyperlinkCtrl

property type description
label Text Label to display on the control (required).
url URL URL to open when the link is clicked (required).

wxImageList

The imagelist can be used as a child object for the following classes:

The available properties are:

property type description
bitmap Bitmap Adds a new image by keeping its optional mask bitmap (see below).
mask Boolean If masks should be created for all images (default: true).
size Size The size of the images in the list (default: the size of the first bitmap).

例:

<imagelist>
    <size>32,32</size>
    <bitmap stock_id="wxART_QUESTION"/>
    <bitmap stock_id="wxART_INFORMATION"/>
</imagelist>

In the specific case of the wxListCtrl, the tag can take the name <imagelist-small> to define the 'small' image list, related to the flag wxIMAGE_LIST_SMALL (see wxListCtrl documentation).

wxListBox

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

例:

<object class="wxListBox" name="controls_listbox">
    <size>250,160</size>
    <style>wxLB_SINGLE</style>
    <content>
        <item>Milk</item>
        <item>Pizza</item>
        <item>Bread</item>
        <item>Orange juice</item>
        <item>Paper towels</item>
    </content>
</object>

wxListbook

A listbook can have one or more child objects of the listbookpage pseudo-class (similarly to wxNotebook and its notebookpage) and one child object of the wxImageList class. listbookpage objects have the following properties:

property type description
label Text Sheet page's title (required).
bitmap Bitmap Bitmap shown alongside the label (default: none).
image integer The zero-based index of the image associated with the item into the image list.
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.

wxListCtrl

A list control can have one or more child objects of the class listitem and one or more objects of the wxImageList class. The latter is defined either using <imagelist> tag for the control with wxLC_ICON style or using <imagelist-small> tag for the control with wxLC_SMALL_ICON style.

Report mode list controls (i.e. created with wxLC_REPORT style) can in addition have one or more listcol child elements.

listcol

The listcol class can only be used for wxListCtrl children. It can have the following properties:

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 String 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.

listitem

The listitem is a child object for the class wxListCtrl. It can have the following properties:

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) wxImageList associated with the wxListCtrl parent and associate it with this item. If the imagelist is not defined it will be created implicitly.
bitmap-small Bitmap Add a bitmap in the 'small' wxImageList associated with the wxListCtrl parent and associate it with this item. If the 'small' imagelist is not defined it will be created implicitly.
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.
image-small integer The zero-based index of the image associated with the item in the 'small' image list.
data integer The client data for the item.
font Font The font for the item.
image integer The zero-based index of the image associated with the item into the image list.
state Style The item state. Can be any combination of the following values:
  • wxLIST_STATE_FOCUSED: The item has the focus.
  • wxLIST_STATE_SELECTED: The item is selected.
text String 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

wxMDIParentFrame supports the same properties that wxFrame does.

wxMDIParentFrame may have optional children. When used, the child objects must be of wxMDIChildFrame type.

wxMDIChildFrame

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.

wxMenu

property type description
label Text Menu's label (default: empty, but required for menus other than popup menus).
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.

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 (required).
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)?

例:

<object class="wxMenu" name="menu_edit">
  <style>wxMENU_TEAROFF</style>
  <label>_Edit</label>
  <object class="wxMenuItem" name="wxID_FIND">
    <label>_Find...</label>
    <accel>Ctrl-F</accel>
  </object>
  <object class="separator"/>
  <object class="wxMenuItem" name="menu_fuzzy">
    <label>Translation is _fuzzy</label>
    <checkable>1</checkable>
  </object>
  <object class="wxMenu" name="submenu">
    <label>A submenu</label>
    <object class="wxMenuItem" name="foo">...</object>
    ...
  </object>
  <object class="separator" platform="unix"/>
  <object class="wxMenuItem" name="wxID_PREFERENCES" platform="unix">
    <label>_Preferences</label>
  </object>
</object>

wxMenuBar

No properties. Note that unlike most controls, wxMenuBar does not have Standard Properties.

A menubar can have one or more child objects of the wxMenu class.

wxNotebook

A notebook can have one or more child objects of the notebookpage pseudo-class and one child object of the wxImageList class. notebookpage objects have the following properties:

property type description
label Text Page's title (required).
bitmap Bitmap Bitmap shown alongside the label (default: none).
image integer The zero-based index of the image associated with the item into the image list.
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.

例:

<object class="wxNotebook">
    <style>wxBK_BOTTOM</style>
    <object class="notebookpage">
        <label>Page 1</label>
        <object class="wxPanel" name="page_1">
            ...
        </object>
    </object>
    <object class="notebookpage">
        <label>Page 2</label>
        <object class="wxPanel" name="page_2">
            ...
        </object>
    </object>
</object>

wxOwnerDrawnComboBox

wxOwnerDrawnComboBox has the same properties as wxComboBox, plus the following additional properties:

property type description
buttonsize Size Size of the dropdown button (default: default).

wxPanel

No additional properties.

wxPanel may have optional children: either exactly one sizer child or any number of non-toplevel window objects.

wxPropertySheetDialog

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 (required).
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.

wxRadioButton

property type description
label Text Label shown on the radio button (required).
value Boolean Initial value of the control (default: 0).

wxRadioBox

property type description
label Text Label for the whole box (required).
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)?

例:

<object class="wxRadioBox" name="controls_radiobox">
    <style>wxRA_SPECIFY_COLS</style>
    <label>Radio stations</label>
    <dimension>1</dimension>
    <selection>0</selection>
    <content>
        <item tooltip="Powerful radio station" helptext="This station is for amateurs of hard rock and heavy metal">Power 108</item>
        <item tooltip="Disabled radio station" enabled="0">Power 0</item>
        <item tooltip="">WMMS 100.7</item>
        <item tooltip="E=mc^2">Energy 98.3</item>
        <item helptext="Favourite chukcha's radio">CHUM FM</item>
        <item>92FM</item>
        <item hidden="1">Very quit station</item>
    </content>
</object>

wxRichTextCtrl

property type description
value Text Initial value of the control (default: empty).
maxlength integer Maximum length of the text entered (default: unlimited).

wxScrollBar

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

wxScrolledWindow

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

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:

<object class="wxSimpleHtmlListBox">
    <content>
        <item>&lt;b&gt;Bold&lt;/b&gt; Milk</item>
    </content>
</object>

(X)HTML markup elements cannot be included directly:

<object class="wxSimpleHtmlListBox">
    <content>
        <!-- This is incorrect, doesn't work! -->
        <item><b>Bold</b> Milk</item>
    </content>
</object>

wxSlider

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

wxSpinButton

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

wxSpinCtrl supports the properties as wxSpinButton.

wxSplitterWindow

property type description
orientation String Orientation of the splitter, either "vertical" or "horizontal" (default: horizontal).
sashpos integer Initial position of the sash (default: 0).
minsize integer 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.

wxSearchCtrl

property type description
value Text Initial value of the control (default: empty).

wxStatusBar

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().
styles String Comma-separated list of fields flags. Each value specifies status bar fieldd style and can be one of wxSB_NORMAL, wxSB_FLAT or wxSB_RAISED. See wxStatusBar::SetStatusStyles() for their description.

wxStaticBitmap

property type description
bitmap Bitmap Bitmap to display (required).

wxStaticBox

property type description
label Text Static box's label (required).

wxStaticLine

No additional properties.

wxStaticText

property type description
label Text Label to display (required).
wrap integer Wrap the text so that each line is at most the given number of pixels, see wxStaticText::Wrap() (default: no wrap).

wxTextCtrl

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

wxTimePickerCtrl

No additional properties.

wxToggleButton

property type description
label Text Label to display on the button (required).
checked Boolean Should the button be checked/pressed initially (default: 0)?

wxToolBar

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 two pseudo-classes: separator 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 (required).
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 neither tool nor separator must be instances of classes derived from wxControl and are added to the toolbar using wxToolBar::AddControl().

例:

<object class="wxToolBar">
    <style>wxTB_FLAT|wxTB_NODIVIDER</style>
    <object class="tool" name="foo">
        <bitmap>foo.png</bitmap>
        <label>Foo</label>
    </object>
    <object class="tool" name="bar">
        <bitmap>bar.png</bitmap>
        <label>Bar</label>
    </object>
    <object class="separator"/>
    <object class="tool" name="view_auto">
        <bitmap>view.png</bitmap>
        <label>View</label>
        <dropdown>
            <object class="wxMenu">
                <object class="wxMenuItem" name="view_as_text">
                    <label>View as text</label>
                </object>
                <object class="wxMenuItem" name="view_as_hex">
                    <label>View as binary</label>
                </object>
            </object>
        </dropdown>
    </object>
    <object class="space"/>
    <object class="wxComboBox">
        <content>
            <item>Just</item>
            <item>a combobox</item>
            <item>in the toolbar</item>
        </content>
    </object>
</object>

wxToolbook

A toolbook can have one or more child objects of the toolbookpage pseudo-class (similarly to wxNotebook and its notebookpage) and one child object of the wxImageList class. toolbookpage objects have the following properties:

property type description
label Text Sheet page's title (required).
bitmap Bitmap Bitmap shown alongside the label (default: none).
image integer The zero-based index of the image associated with the item into the image list.
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.

wxTreeCtrl

A treectrl can have one child object of the wxImageList class.

No additional properties.

wxTreebook

A treebook can have one or more child objects of the treebookpage pseudo-class (similarly to wxNotebook and its notebookpage) and one child object of the wxImageList class. treebookpage objects have the following properties:

property type description
depth integer Page's depth in the labels tree (required; see below).
label Text Sheet page's title (required).
bitmap Bitmap Bitmap shown alongside the label (default: none).
image integer The zero-based index of the image associated with the item into the image list.
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:

<object class="wxTreebook">
  ...
  <object class="treebookpage">
    <depth>0</depth>
    <label>Page 1</label>
    <object class="wxPanel">...</object>
  </object>
  <object class="treebookpage">
    <depth>1</depth>
    <label>Subpage 1A</label>
    <object class="wxPanel">...</object>
  </object>
  <object class="treebookpage">
    <depth>2</depth>
    <label>Subsubpage 1</label>
    <object class="wxPanel">...</object>
  </object>
  <object class="treebookpage">
    <depth>1</depth>
    <label>Subpage 1B</label>
    <object class="wxPanel">...</object>
  </object>
  <object class="treebookpage">
    <depth>2</depth>
    <label>Subsubpage 2</label>
    <object class="wxPanel">...</object>
  </object>
  <object class="treebookpage">
    <depth>0</depth>
    <label>Page 2</label>
    <object class="wxPanel">...</object>
  </object>
</object>

corresponds to the following tree of labels:

wxWizard

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
bitmap Bitmap Page-specific bitmap (default: none).

wxWizardPageSimple pages are automatically chained together; wxWizardPage pages transitions must be handled programmatically.

Sizers

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 (required).

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:

<object class="wxDialog" name="derived_dialog">
    <title>Derived Dialog Example</title>
    <centered>1</centered>
    <!-- this sizer is set to be this dialog's sizer: -->
    <object class="wxFlexGridSizer">
        <cols>1</cols>
        <rows>0</rows>
        <vgap>0</vgap>
        <hgap>0</hgap>
        <growablecols>0</growablecols>
        <growablerows>0</growablerows>
        <object class="sizeritem">
            <flag>wxALIGN_CENTRE|wxALL</flag>
            <border>5</border>
            <object class="wxButton" name="my_button">
                <label>My Button</label>
            </object>
        </object>
        <object class="sizeritem">
            <flag>wxALIGN_CENTRE|wxALL</flag>
            <border>5</border>
            <object class="wxBoxSizer">
                <orient>wxHORIZONTAL</orient>
                <object class="sizeritem">
                    <flag>wxALIGN_CENTRE|wxALL</flag>
                    <border>5</border>
                    <object class="wxCheckBox" name="my_checkbox">
                        <label>Enable this text control:</label>
                    </object>
                </object>
                <object class="sizeritem">
                    <flag>wxALIGN_CENTRE|wxALL</flag>
                    <border>5</border>
                    <object class="wxTextCtrl" name="my_textctrl">
                        <size>80,-1</size>
                        <value></value>
                    </object>
                </object>
            </object>
        </object>
        ...
    </object>
</object>

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

wxBoxSizer

property type description
orient Style Sizer orientation, "wxHORIZONTAL" or "wxVERTICAL" (default: wxHORIZONTAL).

wxStaticBoxSizer

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 (required).

wxGridSizer

property type description
rows integer Number of rows in the grid (default: 0 - determine automatically).
cols integer Number of columns in the grid (default: 0 - determine automatically).
vgap integer Vertical gap between children (default: 0).
hgap integer Horizontal gap between children (default: 0).

wxFlexGridSizer

property type description
rows integer Number of rows in the grid (default: 0 - determine automatically).
cols integer Number of columns in the grid (default: 0 - determine automatically).
vgap integer Vertical gap between children (default: 0).
hgap integer Horizontal gap between children (default: 0).
growablerows comma-separated integers list Comma-separated list of indexes of rows that are growable (default: none).
growablecols comma-separated integers list Comma-separated list of indexes of columns that are growable (default: none).

wxGridBagSizer

property type description
vgap integer Vertical gap between children (default: 0).
hgap integer Horizontal gap between children (default: 0).
growablerows comma-separated integers list Comma-separated list of indexes of rows that are growable (default: none).
growablecols comma-separated integers list Comma-separated list of indexes of columns that are growable (default: none).

wxWrapSizer

property type description
orient Style Sizer orientation, "wxHORIZONTAL" or "wxVERTICAL" (required).
flag Style wxWrapSizer flags (default: 0).

wxStdDialogButtonSizer

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.

例:

<object class="wxStdDialogButtonSizer">
    <object class="button">
        <object class="wxButton" name="wxID_OK">
            <label>OK</label>
        </object>
    </object>
    <object class="button">
        <object class="wxButton" name="wxID_CANCEL">
            <label>Cancel</label>
        </object>
    </object>
</object>

Other Objects

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.

wxBitmap

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:

<bitmap>mybmp.png</bitmap>
<bitmap stock_id="wxART_NEW"/>

toplevel wxBitmap resources would look like:

<object class="wxBitmap" name="my_bitmap">mybmp.png</object>
<object class="wxBitmap" name="my_new_bitmap" stock_id="wxART_NEW"/>

wxIcon

wxIcon resources are identical to wxBitmap ones, except that the class is wxIcon.

Platform Specific Content

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
os2 OS/2

Examples:

<label platform="win">Windows</label>
<label platform="unix">Unix</label>
<label platform="mac">Mac OS X</label>
<help platform="mac|unix">Not a Windows machine</help>

ID Ranges

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.

    <object class="wxButton" name="foo[start]">
    <object class="wxButton" name="foo[end]">
    <object class="wxButton" name="foo[2]">
    ...
    <object class="wxButton" name="bar[0]">
    <object class="wxButton" name="bar[2]">
    <object class="wxButton" name="bar[1]">
    ...
<ids-range name="foo" />
<ids-range name="bar" size="30" start="10000" />

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:

for (int n=XRCID("foo[start]"); n <= XRCID("foo[end]"); ++n)
    ...

ID ranges can be seen in action in the objref dialog section of the XRC Sample.

注:
  • All the items in an ID range must be contained in the same XRC file.
  • You can't use an ID range in a situation where static initialisation occurs; in particular, they won't work as expected in an event table. This is because the event table's IDs are set to their integer values before the XRC file is loaded, and aren't subsequently altered when the XRCID value changes.
Since:
2.9.2

Extending the XRC Format

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.

Subclassing

The simplest way to add custom controls is to set the subclass attribute of <object> element:

<object name="my_value" class="wxTextCtrl" subclass="MyTextCtrl">
  <style>wxTE_MULTILINE</style>
  ...etc., setup wxTextCtrl as usual...
</object>

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:

  1. It must be derived from the class specified in class attribute.
  2. It must be visible in wxWidget's pseudo-RTTI mechanism, i.e. there must be a DECLARE_DYNAMIC_CLASS() entry for it.
  3. It must support two-phase creation. In particular, this means that it has to have default constructor.
  4. It cannot provide custom Create() method and must be constructible using base 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.

Unknown Objects

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:

<object class="unknown" name="my_placeholder"/>

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.

Adding Custom Classes

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:

<object name="my_ctrl" class="MyWidget">
  <my_prop>foo</my_prop>
  ...etc., whatever MyWidget handler accepts...
</object>

The only requirements on the class are that

  1. the class must derive from wxObject
  2. it must support wxWidget's pseudo-RTTI mechanism

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.

Packed XRC Files

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

Older Format Versions

This section describes differences in older revisions of XRC format (i.e. files with older values of version attribute of <resource>).

Versions Before 2.5.3.0

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.

Versions Before 2.3.0.1

Prior to version 2.3.0.1, "$" was used for accelerators instead of "_" or "&amp;". 以下に例を示します。

<label>$File</label>

was used in place of current version's

<label>_File</label>

(or "&amp;File").

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines