Difference between revisions of "Using XML Resources with XRC"

From WxWiki
Jump to: navigation, search
(initial page import, 30% cleaned up, 70% to go)
 
(60% cleaned up, another 40% to go)
Line 17: Line 17:
 
The two main advantages of XML resources, except that it is XML, is that it is quite readable and runtime processed.
 
The two main advantages of XML resources, except that it is XML, is that it is quite readable and runtime processed.
  
<div style="margin-left: 0.5in; margin-right: 0.5in">
+
<div style="background: #fcc; margin: 1em 3em; padding: 0.2em 0.5em;">
=== Warning ===
+
'''Warning'''
  
 
This document is not a C/C++ tutorial for wxWidgets as other tutorials are available including the wxWidgets documentation and samples which is a good starting point.
 
This document is not a C/C++ tutorial for wxWidgets as other tutorials are available including the wxWidgets documentation and samples which is a good starting point.
Line 39: Line 39:
 
A simple way to initialize the resource system is to call <tt>InitAllHandlers</tt> method of <tt>wxXmlResource</tt> class so you don't have to worry about all the handlers you could add.
 
A simple way to initialize the resource system is to call <tt>InitAllHandlers</tt> method of <tt>wxXmlResource</tt> class so you don't have to worry about all the handlers you could add.
  
'''Example 1. <tt>wxXmlResource</tt> initialization'''
+
<source title="wxXmlResource Initialization Example">
 
+
wxXmlResource::Get()->InitAllHandlers();
<pre>wxXmlResource::Get()->InitAllHandlers();
 
 
bRet = wxXmlResource::Get()->Load( Path );
 
bRet = wxXmlResource::Get()->Load( Path );
 
if( !bRet )
 
if( !bRet )
Line 47: Line 46:
 
     cout  << "Could not load resource file" << Path << endl;
 
     cout  << "Could not load resource file" << Path << endl;
 
     return false;
 
     return false;
}</pre>
+
}
 +
</source>
  
 
The individual resource handlers available (depending on compilation options in <tt>setup.h</tt>) are:
 
The individual resource handlers available (depending on compilation options in <tt>setup.h</tt>) are:
Line 91: Line 91:
 
Now that handlers are added to the resource handler you have to specify which '''XRC''' file(s) you want to load by calling the <tt>Load</tt> method. The parameter you pass to this method must be a valid path to the file you wand to load.
 
Now that handlers are added to the resource handler you have to specify which '''XRC''' file(s) you want to load by calling the <tt>Load</tt> method. The parameter you pass to this method must be a valid path to the file you wand to load.
  
=== Using the <tt>wxXmlResource</tt> Class to Create UI Elements ===
+
=== Using wxXmlResource to Create UI Elements ===
  
 
There are 8 top level resource types that you can describe in a '''XRC''' file.
 
There are 8 top level resource types that you can describe in a '''XRC''' file.
Line 110: Line 110:
 
For example there are three ways to create a dialog :
 
For example there are three ways to create a dialog :
  
* Directly by using the following form wxDialog *Dlg;
+
1. Directly by using the following form wxDialog *Dlg;
  
 
<pre>Dlg = wxXmlResource::Get()->LoadDialog( FrameObjectPointer, "dialog_resource" );
 
<pre>Dlg = wxXmlResource::Get()->LoadDialog( FrameObjectPointer, "dialog_resource" );
 
Dlg->ShowModal();</pre>
 
Dlg->ShowModal();</pre>
  
* Indirectly by using the following form wxDialog Dlg;
+
2. Indirectly by using the following form wxDialog Dlg;
  
 
<pre>wxXmlResource::Get()->LoadDialog( &Dlg, FrameObjectPointer, "dialog_resource" );
 
<pre>wxXmlResource::Get()->LoadDialog( &Dlg, FrameObjectPointer, "dialog_resource" );
Line 126: Line 126:
 
Dlg.ShowModal();</pre>
 
Dlg.ShowModal();</pre>
  
* Indirectly in a derived class of <tt>wxDialog</tt>  
+
3. Indirectly in a derived class of <tt>wxDialog</tt>  
  
 
<pre>MyDerivedDialog::MyDerivedDialog( wxWindow *p_Parent )
 
<pre>MyDerivedDialog::MyDerivedDialog( wxWindow *p_Parent )
Line 133: Line 133:
 
}</pre>
 
}</pre>
  
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in">
+
<div style="background: #fcc; margin: 1em 3em; padding: 0.2em 0.5em;">
=== Important ===
+
'''Important'''
  
 
Note that in the last example the <tt>wxDialog</tt> base class constructor is not called, and should not be.
 
Note that in the last example the <tt>wxDialog</tt> base class constructor is not called, and should not be.
Line 143: Line 143:
 
'''XRC''' files are standard XML files. The format should be the following :
 
'''XRC''' files are standard XML files. The format should be the following :
  
'''Example 2. XRC resource file'''
+
<source lang="xml">
 
+
<?xml version="1.0"?>
<pre><?xml version="1.0"?>
 
 
<resource version="2.3.0.1">
 
<resource version="2.3.0.1">
<object class="wxFrame" name="my_main_frame">
+
    <object class="wxFrame" name="my_main_frame">
<size>200,300</size>
+
        <size>200,300</size>
...
+
        ...
</object>
+
    </object>
</resource></pre>
+
</resource>
 +
</source>
  
 
== Internationalization (i18n) ==
 
== Internationalization (i18n) ==
Line 163: Line 163:
 
== XRC Object Descriptions ==
 
== XRC Object Descriptions ==
  
This part describes each resource type available in '''XRC''' files.
+
This part describes each resource type available in '''XRC''' files.  All "object" nodes have an optional "name" parameter used as an ID for that object, which can be retieved with the <tt>XRCID()</tt> macro in code.
  
 
=== wxWindow Derived Elements ===
 
=== wxWindow Derived Elements ===
  
 
Many of the elements (windows, controls) that are described in an '''XRC''' file are derived from the <tt>wxWindow</tt> class. The all have common properties available:
 
Many of the elements (windows, controls) that are described in an '''XRC''' file are derived from the <tt>wxWindow</tt> class. The all have common properties available:
 
'''Common properties for <tt>wxWindow</tt> derived elements'''
 
  
 
; exstyle
 
; exstyle
: extended window style: wxSIMPLE_BORDER, wxSUNKEN_BORDER, wxDOUBLE_BORDER, wxRAISED_BORDER, wxSTATIC_BORDER, wxNO_BORDER, wxWANTS_CHARS, wxNO_FULL_REPAINT_ON_RESIZE
+
: window styles, see the [http://www.wxwidgets.org/manuals/stable/wx_wxwindow.html wxWindow documentation] for possible styles (separate multiple styles with the "|" (pipe) character)
 
; bg
 
; bg
 
: background window color: RGB color in the #RRGGBB format (HTML like)
 
: background window color: RGB color in the #RRGGBB format (HTML like)
Line 190: Line 188:
 
:: font size in points
 
:: font size in points
 
:; style
 
:; style
:: font style: italic, slant
+
:: font style: normal, italic, slant
 
:; weight
 
:; weight
:: font weight: bold, light
+
:: font weight: normal, bold, light
 
;; family
 
;; family
:: font family: decorative, roman, script, swiss, modern
+
:: font family: decorative, modern, roman, script, swiss, teletype
 
;; underlined
 
;; underlined
 
:: should the font be underlined? bool value (0/1)
 
:: should the font be underlined? bool value (0/1)
Line 209: Line 207:
  
 
All sizer types contain one or more <tt>sizeritem</tt>. A <tt>sizeritem</tt> contains one object (control).
 
All sizer types contain one or more <tt>sizeritem</tt>. A <tt>sizeritem</tt> contains one object (control).
 
<div class="variablelist">
 
  
 
; flag
 
; flag
Line 224: Line 220:
  
 
The box sizer divides the layout into two components either horizontally or vertically. It contains one or more <tt>sizeritem</tt> tags.
 
The box sizer divides the layout into two components either horizontally or vertically. It contains one or more <tt>sizeritem</tt> tags.
 
'''Properties (as XML sub-elements)'''
 
  
 
; orient
 
; orient
 
: wxBoxSizer orientation: wxVERTICAL, wxHORIZONTAL
 
: wxBoxSizer orientation: wxVERTICAL, wxHORIZONTAL
  
'''Example 3. wxBoxSizer sample'''
+
<source lang="xml">
 
+
<object class="wxBoxSizer">
<pre><object class="wxBoxSizer">
 
 
     <orient>wxHORIZONTAL</orient>
 
     <orient>wxHORIZONTAL</orient>
 
     <object class="sizeritem">Left control</object>
 
     <object class="sizeritem">Left control</object>
 
     <object class="sizeritem">Right control</object>
 
     <object class="sizeritem">Right control</object>
</object></pre>
+
</object>
 +
</source>
  
 
==== wxStaticBoxSizer ====
 
==== wxStaticBoxSizer ====
  
 
A static box sizer is a box sizer with a surrounding box and a label.
 
A static box sizer is a box sizer with a surrounding box and a label.
 
'''Properties (as XML sub-elements)'''
 
  
 
; orient
 
; orient
Line 253: Line 245:
 
A grid sizer divides the layout into rows and cols of identical sizes.
 
A grid sizer divides the layout into rows and cols of identical sizes.
  
'''Properties (as XML sub-elements)'''
+
; rows
 
 
; rows</span>
 
 
: Number of rows.
 
: Number of rows.
; cols</span>
+
; cols
 
: Number of cols.
 
: Number of cols.
; vgap</span>
+
; vgap
 
: vertical space between to elements.
 
: vertical space between to elements.
; hgap</span>
+
; hgap
 
: horizontal space between to elements.
 
: horizontal space between to elements.
  
<pre><object class="wxGridSizer">
+
<source lang="xml">
 +
<object class="wxGridSizer">
 
     <rows>2</rows>
 
     <rows>2</rows>
 
     <cols>2</cols>
 
     <cols>2</cols>
Line 271: Line 262:
 
     <object class="sizeritem">control in 1,0 (row,col)</object>
 
     <object class="sizeritem">control in 1,0 (row,col)</object>
 
     <object class="sizeritem">control in 1,1 (row,col)</object>
 
     <object class="sizeritem">control in 1,1 (row,col)</object>
</object></pre>
+
</object>
 +
</source>
  
 
==== wxFlexGridSizer ====
 
==== wxFlexGridSizer ====
Line 277: Line 269:
 
A grid sizer divides the layout into rows and cols of identical sizes.
 
A grid sizer divides the layout into rows and cols of identical sizes.
  
<div class="variablelist">
+
; rows
 
 
'''Properties (as XML sub-elements)'''
 
 
 
; rows</span>
 
 
: Number of rows.
 
: Number of rows.
; cols</span>
+
; cols
 
: Number of cols.
 
: Number of cols.
; vgap</span>
+
; vgap
 
: vertical space between to elements.
 
: vertical space between to elements.
; hgap</span>
+
; hgap
 
: horizontal space between to elements.
 
: horizontal space between to elements.
; growablecols</span>
+
; growablecols
 
: list: comma separated list of cols indexes that will grow with the container.
 
: list: comma separated list of cols indexes that will grow with the container.
; growablerows</span>
+
; growablerows
 
: list: comma separated list of rows indexes that will grow with the container.
 
: list: comma separated list of rows indexes that will grow with the container.
  
</div></div><div class="sect2" lang="en"><div class="titlepage">
+
=== wxBitmapButton ===
  
===5.3. wxBitmapButton===
+
Inherits <tt>wxWindow</tt> properties.
 
 
</div>
 
 
 
Inherits <tt>wxWindow</tt> properties
 
 
 
<div class="variablelist">
 
 
 
'''Attributes'''
 
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
  
</div><div class="variablelist">
+
; style
 
+
: button style: wxBU_AUTODRAW, wxBU_LEFT, wxBU_RIGHT, wxBU_TOP, wxBU_BOTTOM
'''Properties(as XML sub-elements)'''
+
; bitmap
 
 
; style</span>
 
: {| class="simplelist" summary="Simple list"
 
| wxBU_AUTODRAW
 
| wxBU_LEFT
 
| wxBU_RIGHT
 
| wxBU_TOP
 
| wxBU_BOTTOM
 
|}Button styles
 
; bitmap</span>
 
 
: The bitmap path and filename
 
: The bitmap path and filename
; default</span>
+
; default
: bool value (0/1) : 1 if this button is the default button of the dialog or panel.
+
: bool value (0/1) - 1 if this button is the default button of the dialog or panel.
; selected</span>
+
; selected
 
: This is the selected bitmap specifier. Contains a bitmap tag
 
: This is the selected bitmap specifier. Contains a bitmap tag
; focus</span>
+
; focus
 
: This is the focused bitmap specifier. Contains a bitmap tag
 
: This is the focused bitmap specifier. Contains a bitmap tag
; disabled</span>
+
; disabled
 
: This is the disabled bitmap specifier. Contains a bitmap tag
 
: This is the disabled bitmap specifier. Contains a bitmap tag
  
</div><div class="example">
+
<source lang="xml">
 
+
<?xml version="1.0"?>
'''Example 4. wxBitmapButton sample'''
+
<resource version="2.4.0">
 
+
<object class="wxFrame" name="main_frame">
<?xml version="1.0"?>
+
<title>Testing the XRC resource system</title>
<resource version="2.4.0">
+
    <object class="wxPanel" name="main_panel">
<object class="wxFrame" name="main_frame">
+
        <object class="wxBoxSizer">
<title>Testing the XRC resource system</title>
+
        <orient>wxVERTICAL</orient>
    <object class="wxPanel" name="main_panel">
+
            <object class="sizeritem">
        <object class="wxBoxSizer">
+
            <flag>wxALL|wxGROW</flag>
        <orient>wxVERTICAL</orient>
+
            <option>1</option>
            <object class="sizeritem">
+
            <object class="wxBitmapButton" name="bt_bitmapbutton">
            <flag>wxALL|wxGROW</flag>
+
                <style>wxBU_LEFT</style>
            <option>1</option>
+
                <bitmap>bt_buttonbitmap.xpm</bitmap>
              <object class="wxBitmapButton" name="bt_bitmapbutton">
+
                <selected>
                  <style>wxBU_LEFT</style>
+
                    <bitmap>bt_buttonbitmaps.xpm</bitmap>
                  <bitmap>bt_buttonbitmap.xpm</bitmap>
+
                </selected>
                  <selected>
+
                <focus>
                      <bitmap>bt_buttonbitmaps.xpm</bitmap>
+
                    <bitmap>bt_buttonbitmapf.xpm</bitmap>
                  </selected>
+
                </focus>
                  <focus>
+
                <disabled>
                      <bitmap>bt_buttonbitmapf.xpm</bitmap>
+
                    <bitmap>bt_buttonbitmapd.xpm</bitmap>
                  </focus>
+
                </disabled>
                  <disabled>
+
              </object>
                      <bitmap>bt_buttonbitmapd.xpm</bitmap>
+
          </object>
                  </disabled>
+
          <object class="sizeritem">
              </object>
+
          <flag>wxALL</flag>
          </object>
+
              <object class="wxStaticText" name="st_description">
          <object class="sizeritem">
+
                  <label>wxBitmapButton test</label>
          <flag>wxALL</flag>
+
              </object>
              <object class="wxStaticText" name="st_description">
+
          </object>
                  <label>wxBitmapButton test</label>
+
      </object>
              </object>
+
  </object>
          </object>
+
</object>
        </object>
+
</resource>
    </object>
+
</source>
</object>
 
</resource>
 
 
 
</div></div><div class="sect2" lang="en"><div class="titlepage">
 
 
 
===5.4. wxButton===
 
  
</div>
+
=== wxButton ===
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties
  
<div class="variablelist">
+
; style
 
+
: The button style: wxBU_LEFT, wxBU_RIGHT, wxBU_TOP, wxBU_BOTTOM
'''Attributes'''
+
; label
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
 
 
'''Properties(as XML sub-elements)'''
 
 
 
; style</span>
 
: {| class="simplelist" summary="Simple list"
 
| wxBU_LEFT
 
| wxBU_RIGHT
 
| wxBU_TOP
 
| wxBU_BOTTOM
 
|}The button style
 
; label</span>
 
 
: The label of the button
 
: The label of the button
; default</span>
+
; default
 
: bool value (0/1): 1 if this button is the default button of the dialog or panel.
 
: bool value (0/1): 1 if this button is the default button of the dialog or panel.
  
</div><div class="example">
+
<source lang="xml">
 
+
<resource version="2.4.0">
'''Example 5. wxButton sample'''
+
<object class="wxFrame" name="main_frame">
 
+
<title>Testing the XRC resource system</title>
+
    <object class="wxPanel" name="main_panel">
<resource version="2.4.0">
+
        <object class="wxBoxSizer">
<object class="wxFrame" name="main_frame">
+
        <orient>wxVERTICAL</orient>
<title>Testing the XRC resource system</title>
+
            <object class="sizeritem">
    <object class="wxPanel" name="main_panel">
+
            <flag>wxALL|wxGROW</flag>
        <object class="wxBoxSizer">
+
            <option>1</option>
        <orient>wxVERTICAL</orient>
+
                <object class="wxButton" name="bt_button">
            <object class="sizeritem">
+
                    <style>wxBU_LEFT</style>
            <flag>wxALL|wxGROW</flag>
+
                    <label>Button label</label>
            <option>1</option>
+
                </object>
                <object class="wxButton" name="bt_button">
+
            </object>
                    <style>wxBU_LEFT</style>
+
            <object class="sizeritem">
                    <label>Button label</label>
+
            <flag>wxALL</flag>
                </object>
+
                <object class="wxStaticText" name="st_description">
            </object>
+
                    <label>wxButton test</label>
            <object class="sizeritem">
+
                </object>
            <flag>wxALL</flag>
+
            </object>
                <object class="wxStaticText" name="st_description">
+
        </object>
                    <label>wxButton test</label>
+
    </object>
                </object>
+
</object>
            </object>
+
</resource>
        </object>
+
</source>
    </object>
 
</object>
 
</resource>
 
 
 
</div></div><div class="sect2" lang="en"><div class="titlepage">
 
 
 
===5.5. wxCalendarCtrl===
 
  
</div>
+
=== wxCalendarCtrl ===
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties
  
<div class="variablelist">
+
; style
 +
: Calendar styles defining how the calendar control should work: wxCAL_SUNDAY_FIRST, wxCAL_MONDAY_FIRST, wxCAL_SHOW_HOLIDAYS, wxCAL_NO_YEAR_CHANGE, wxCAL_NO_MONTH_CHANGE
  
'''Attributes'''
+
<source lang="xml">
 
+
<resource version="2.4.0">
; name</span>
+
<object class="wxFrame" name="main_frame">
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
+
<title>Testing the XRC resource system</title>
 
+
<object class="wxPanel" name="main_panel">
</div><div class="variablelist">
+
  <object class="wxBoxSizer">
 
+
  <orient>wxVERTICAL</orient>
'''Properties(as XML sub-elements)'''
+
  <object class="sizeritem">
 
+
  <flag>wxALL|wxGROW</flag>
; style</span>
+
  <option>1</option>
: {| class="simplelist" summary="Simple list"
+
    <object class="wxCalendarCtrl" name="calendar">
| wxCAL_SUNDAY_FIRST
+
    <style>wxCAL_MONDAY_FIRST|wxCAL_SHOW_HOLIDAYS</style>
| wxCAL_MONDAY_FIRST
 
| wxCAL_SHOW_HOLIDAYS
 
| wxCAL_NO_YEAR_CHANGE
 
| wxCAL_NO_MONTH_CHANGE
 
|}Calendar styles defining how the calendar control should work.
 
 
 
</div><div class="example">
 
 
 
'''Example 6. wxCalendarCtrl sample'''
 
 
 
<resource version="2.4.0">
 
<object class="wxFrame" name="main_frame">
 
<title>Testing the XRC resource system</title>
 
  <object class="wxPanel" name="main_panel">
 
  <object class="wxBoxSizer">
 
  <orient>wxVERTICAL</orient>
 
    <object class="sizeritem">
 
    <flag>wxALL|wxGROW</flag>
 
    <option>1</option>
 
    <object class="wxCalendarCtrl" name="calendar">
 
      <style>wxCAL_MONDAY_FIRST|wxCAL_SHOW_HOLIDAYS</style>
 
    </object>
 
 
     </object>
 
     </object>
    <object class="sizeritem">
+
  </object>
    <flag>wxALL</flag>
+
  <object class="sizeritem">
    <object class="wxStaticText" name="st_description">
+
  <flag>wxALL</flag>
      <label>wxCalendarCtrl test</label>
+
    <object class="wxStaticText" name="st_description">
    </object>
+
    <label>wxCalendarCtrl test</label>
 
     </object>
 
     </object>
 
   </object>
 
   </object>
 
   </object>
 
   </object>
 
  </object>
 
  </object>
</resource>
+
</object>
 +
</resource>
 +
</source>
  
<div class="mediaobject">[[Image:wxCalendarCtrl.png]]</div></div></div><div class="sect2" lang="en"><div class="titlepage">
+
[[Image:wxCalendarCtrl.png]]
  
===5.6. wxCheckBox===
+
=== wxCheckBox ===
 
 
</div>
 
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties
  
<div class="variablelist">
+
; label
 
 
'''Attributes'''
 
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
 
 
'''Properties(as XML sub-elements)'''
 
 
 
; label</span>
 
 
: Label of the check box
 
: Label of the check box
; checked</span>
+
; checked
 
: bool value (1/0): 1 if the check box is checked on creation
 
: bool value (1/0): 1 if the check box is checked on creation
  
</div><div class="example">
+
<source lang="xml">
 
+
<resource version="2.4.0">
'''Example 7. wxCheckBox sample'''
+
<object class="wxFrame" name="main_frame">
 
+
<title>Testing the XRC resource system</title>
<resource version="2.4.0">
+
<object class="wxPanel" name="main_panel">
<object class="wxFrame" name="main_frame">
+
  <object class="wxBoxSizer">
<title>Testing the XRC resource system</title>
+
  <orient>wxVERTICAL</orient>
  <object class="wxPanel" name="main_panel">
+
    <object class="sizeritem">
  <object class="wxBoxSizer">
+
      <flag>wxALL|wxGROW</flag>
    <orient>wxVERTICAL</orient>
+
      <object class="wxCheckBox" name="checkbox_id">
    <object class="sizeritem">
+
      <size>200,50</size>
      <flag>wxALL|wxGROW</flag>
+
      <label>CheckBoxItem</label>
      <object class="wxCheckBox" name="checkbox_id">
+
      <checked>1</checked>
        <size>200,50</size>
+
      </object>
        <label>CheckBoxItem</label>
+
    </object>
        <checked>1</checked>
+
    <object class="sizeritem">
      </object>
+
      <flag>wxALL</flag>
    </object>
+
      <object class="wxStaticText" name="st_description">
    <object class="sizeritem">
+
        <label>wxCheckBox test</label>
      <flag>wxALL</flag>
+
      </object>
        <object class="wxStaticText" name="st_description">
 
        <label>wxCheckBox test</label>
 
      </object>
 
    </object>
 
 
     </object>
 
     </object>
 
   </object>
 
   </object>
</object>
+
  </object>
</resource>
+
</object>
 +
</resource>
 +
</source>
  
</div></div><div class="sect2" lang="en"><div class="titlepage">
+
=== wxCheckList ===
 
 
===5.7. wxCheckList===
 
 
 
</div>
 
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties
  
<div class="variablelist">
+
; content
 +
: list of '''item''' tags describing the elements in the control, '''item''' tag attributes:
 +
;; checked
 +
:: bool value (0/1) : 1 if the element is checked
  
'''Attributes'''
+
<source lang="xml">
 +
<object class="wxCheckList" name="checklistbox_id">
 +
<size>200,100</size>
 +
<content>
 +
<item checked="1">Item value 1</item>
 +
<item checked="0">Item value 2</item>
 +
<item checked="1">Item value 3</item>
 +
<item checked="0">Item value 4</item>
 +
<item checked="1">Item value 5</item>
 +
</content>
 +
</object>
 +
</source>
  
; name</span>
+
[[Image:wxCheckListSample.png]]
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
  
</div><div class="variablelist">
+
=== wxChoice ===
  
'''Properties(as XML sub-elements)'''
+
Inherits <tt>wxWindow</tt> properties
  
; content</span>
+
; selection
: list of <span class="emphasis">''item''</span> tags describing the elements in the "checklist" control.<div class="variablelist">'''item tag attribute'''
+
: integer value: index (0 based) of the selected entry
;; checked</span>
+
; content
:: bool value (0/1) : 1 if the element is checked</div>
+
: list of '''item''' tags describing the elements in the control, '''item''' tag attributes:
 +
;; checked
 +
:: bool value (0/1) : 1 if the element is checked
  
</div><div class="example">
+
<source lang="xml">
 
+
<object class="wxChoice" name="choice_id">
'''Example 8. wxCheckList sample'''
+
<size>200,100</size>
 
+
<selection>2</selection>
<object class="wxCheckList" name="checklistbox_id">
 
<size>200,100</size>
 
 
  <content>
 
  <content>
 
   <item checked="1">Item value 1</item>
 
   <item checked="1">Item value 1</item>
Line 578: Line 491:
 
   <item checked="1">Item value 5</item>
 
   <item checked="1">Item value 5</item>
 
  </content>
 
  </content>
</object>
+
</object>
 
+
</source>
<div class="mediaobject">[[Image:wxCheckListSample.png]]</div></div></div><div class="sect2" lang="en"><div class="titlepage">
 
 
 
===5.8. wxChoice===
 
  
</div>
+
=== wxComboBox ===
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties
  
<div class="variablelist">
+
; style
 
+
: combo style: wxCB_SIMPLE, wxCB_SORT, wxCB_READONLY, wxCB_DROPDOWN
'''Attributes'''
+
; value
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
 
 
'''Properties(as XML sub-elements)'''
 
 
 
; selection</span>
 
: integer value: index ( 0 based ) of the selected entry
 
; content</span>
 
: list of <span class="emphasis">''item''</span> tags describing the elements in the "checklist" control.<div class="variablelist">'''item tag attribute'''
 
;; checked</span>
 
:: bool value (0/1) : 1 if the element is checked</div>
 
 
 
</div><div class="example">
 
 
 
'''Example 9. wxChoice sample'''
 
 
 
<object class="wxChoice" name="choice_id">
 
<size>200,100</size>
 
<selection>2</selection>
 
  <content>
 
  <item checked="1">Item value 1</item>
 
  <item checked="0">Item value 2</item>
 
  <item checked="1">Item value 3</item>
 
  <item checked="0">Item value 4</item>
 
  <item checked="1">Item value 5</item>
 
  </content>
 
</object>
 
 
 
</div><div class="sect2" lang="en"><div class="titlepage">
 
 
 
===5.9. wxComboBox===
 
 
 
</div>
 
 
 
Inherits <tt>wxWindow</tt> properties
 
 
 
<div class="variablelist">
 
 
 
'''Attributes'''
 
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
 
 
'''Properties(as XML sub-elements)'''
 
 
 
; style</span>
 
: {| class="simplelist" summary="Simple list"
 
| wxCB_SIMPLE
 
| wxCB_SORT
 
| wxCB_READONLY
 
| wxCB_DROPDOWN
 
|}combo style
 
; value</span>
 
 
: initial value of the combo as text
 
: initial value of the combo as text
; selection</span>
+
; selection
 
: integer value: index ( 0 based ) of the selected entry
 
: integer value: index ( 0 based ) of the selected entry
; content</span>
+
; content
: list of <span class="emphasis">''item''</span> tags describing the elements in the "checklist" control.<div class="variablelist">'''item tag attribute'''
+
: list of '''item''' tags describing the elements in the control, '''item''' tag attributes:
;; checked</span>
+
;; checked
:: bool value (0/1) : this has no meaning in a combo</div>
+
:: bool value (0/1) : 1 if the element is checked
  
</div><div class="example">
+
<source lang="xml">
 
+
<object class="wxComboBox" name="combo_id">
'''Example 10. wxComboBox sample'''
+
<size>200,100</size>
 
+
<style>wxCB_DROPDOWN</style>
<object class="wxComboBox" name="combo_id">
+
<selection>2</selection>
<size>200,100</size>
+
<content>
<style>wxCB_DROPDOWN</style>
+
  <item checked="1">Item value 1</item>
<selection>2</selection>
+
  <item checked="0">Item value 2</item>
  <content>
+
  <item checked="1">Item value 3</item>
  <item checked="1">Item value 1</item>
+
  <item checked="0">Item value 4</item>
  <item checked="0">Item value 2</item>
+
  <item checked="1">Item value 5</item>
  <item checked="1">Item value 3</item>
+
</content>
  <item checked="0">Item value 4</item>
+
</object>
  <item checked="1">Item value 5</item>
+
</source>
  </content>
 
</object>
 
 
 
<div class="mediaobject">[[Image:wxComboBoxSample.png]]</div></div><div class="sect2" lang="en"><div class="titlepage">
 
  
===5.10. wxDialog===
+
[[Image:wxComboBoxSample.png]]
  
</div>
+
=== wxDialog ===
  
Inherits <tt>wxWindow</tt> properties.
+
Inherits <tt>wxWindow</tt> properties.  This is a top-level component, and it can have multiple sub elements (sizers, controls).
  
This is a top-level component, and it can have multiple sub elements ( sizers, controls).
+
; title
 
 
<div class="variablelist">
 
 
 
'''Attributes'''
 
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
 
 
'''Properties(as XML sub-elements)'''
 
 
 
; title</span>
 
 
: Title of the dialog as text
 
: Title of the dialog as text
; style</span>
+
; style
: {| class="simplelist" summary="Simple list"
+
: see the [http://www.wxwidgets.org/manuals/stable/wx_wxdialog.html wxDialog documentation] for a list of styles
| wxSTAY_ON_TOP
+
; centered
| wxCAPTION
 
| wxDEFAULT_DIALOG_STYLE
 
| wxTHICK_FRAME
 
| wxSYSTEM_MENU
 
|-
 
| wxRESIZE_BORDER
 
| wxRESIZE_BOX
 
| wxDIALOG_MODAL
 
| wxDIALOG_MODELESS
 
| wxNO_3D
 
|-
 
| wxTAB_TRAVERSAL
 
| wxWS_EX_VALIDATE_RECURSIVELY
 
| wxCLIP_CHILDREN
 
| wxMAXIMIZE_BOX
 
| wxMINIMIZE_BOX
 
|}Dialog styles
 
; centered</span>
 
 
: bool value(0/1) : 1 if the dialog should be centered on it's parent screen.
 
: bool value(0/1) : 1 if the dialog should be centered on it's parent screen.
  
</div><div class="example">
+
<source lang="xml">
 
+
<object class="wxDialog" name="test_dialog">
'''Example 11. wxDialog sample'''
+
<title>My Dialog</title>
 
+
<style>wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX</style>
<object class="wxDialog" name="test_dialog">
+
<object class="wxBoxSizer">
<title>My Dialog</title>
+
<orient>wxVERTICAL</orient>
<style>wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX</style>
+
  <object class="sizeritem">
  <object class="wxBoxSizer">
+
  <flag>wxALL</flag>
  <orient>wxVERTICAL</orient>
+
  <object class="wxTextCtrl" name="textctrl_id">
  <object class="sizeritem">
+
  <value>Hello World !!!!</value>
  <flag>wxALL</flag>
 
    <object class="wxTextCtrl" name="textctrl_id">
 
    <value>Hello World !!!!</value>
 
    </object>
 
 
   </object>
 
   </object>
  <object class="sizeritem">
+
  </object>
  <flag>wxALL</flag>
+
  <object class="sizeritem">
    <object class="wxStaticText" name="st_description">
+
  <flag>wxALL</flag>
    <label>wxComboBox test</label>
+
  <object class="wxStaticText" name="st_description">
    </object>
+
  <label>wxComboBox test</label>
 
   </object>
 
   </object>
 
   </object>
 
   </object>
 
  </object>
 
  </object>
 +
</object>
 +
</source>
  
</div><div class="sect2" lang="en"><div class="titlepage">
+
=== wxFrame ===
 
 
===5.11. wxFrame===
 
 
 
</div>
 
 
 
Inherits <tt>wxWindow</tt> properties.
 
 
 
This is a top-level component, and it can have multiple sub elements ( sizers, controls ).
 
 
 
<div class="variablelist">
 
 
 
'''Attributes'''
 
 
 
; name</span>
 
: <span class="type">string</span><nowiki>:unique identifier for the resource</nowiki>
 
 
 
</div><div class="variablelist">
 
  
'''Properties(as XML sub-elements)'''
+
Inherits <tt>wxWindow</tt> properties.  This is a top-level component, and it can have multiple sub elements (sizers, controls ).
  
; title</span>
+
; title
 
: Title of the frame as text
 
: Title of the frame as text
; style</span>
+
; style
: {| class="simplelist" summary="Simple list"
+
: see the [http://www.wxwidgets.org/manuals/stable/wx_wxframe.html wxFrame documentation] for a list of styles.
| wxSTAY_ON_TOP
+
; centered
| wxCAPTION
 
| wxDEFAULT_DIALOG_STYLE
 
| wxDEFAULT_FRAME_STYLE
 
| wxTHICK_FRAME
 
|-
 
| wxSYSTEM_MENU
 
| wxRESIZE_BORDER
 
| wxRESIZE_BOX
 
| wxFRAME_TOOL_WINDOW
 
| wxFRAME_FLOAT_ON_PARENT
 
|-
 
| wxMAXIMIZE_BOX
 
| wxMINIMIZE_BOX
 
| wxSTAY_ON_TOP
 
| wxNO_3D
 
| wxTAB_TRAVERSAL
 
|-
 
| wxWS_EX_VALIDATE_RECURSIVELY
 
| wxCLIP_CHILDREN
 
|}Frame style
 
; centered</span>
 
 
: bool value(0/1) : 1 if the frame should be centered on it's parent screen.
 
: bool value(0/1) : 1 if the frame should be centered on it's parent screen.
  
</div><div class="example">
+
<source lang="xml">
 
+
<object class="wxFrame" name="main_frame">
'''Example 12. wxFrame sample'''
+
<title>Testing the XRC resource system</title>
 
+
<object class="wxPanel" name="main_panel">
<object class="wxFrame" name="main_frame">
+
  <object class="wxBoxSizer">
<title>Testing the XRC resource system</title>
+
  <orient>wxVERTICAL</orient>
  <object class="wxPanel" name="main_panel">
+
  <object class="sizeritem">
  <object class="wxBoxSizer">
+
    <flag>wxALL</flag>
  <orient>wxVERTICAL</orient>
+
    <object class="wxTextCtrl" name="textctrl_id">
    <object class="sizeritem">
+
      <value>Hello World !!!!</value>
    <flag>wxALL</flag>
 
      <object class="wxTextCtrl" name="textctrl_id">
 
      <value>Hello World !!!!</value>
 
      </object>
 
 
     </object>
 
     </object>
     <object class="sizeritem">
+
     </object>
    <flag>wxALL</flag>
+
  <object class="sizeritem">
      <object class="wxStaticText" name="st_description">
+
    <flag>wxALL</flag>
      <label>wxComboBox test</label>
+
    <object class="wxStaticText" name="st_description">
      </object>
+
      <label>wxComboBox test</label>
 
     </object>
 
     </object>
  </object>
+
    </object>
 
   </object>
 
   </object>
 
  </object>
 
  </object>
 +
</object>
 +
</source>
  
<div class="mediaobject">[[Image:wxFrameSample.png]]</div></div><div class="sect2" lang="en"><div class="titlepage">
+
[[Image:wxFrameSample.png]]
  
===5.12. wxGauge===
+
=== wxGauge ===
 
 
</div>
 
  
 
Inherits <tt>wxWindow</tt> properties
 
Inherits <tt>wxWindow</tt> properties

Revision as of 20:14, 24 February 2007

This article has been rescued from this archive, and has not been completely reformatted for this wiki. Please be patient, and use the original article for now.

Introduction

Building a user interface with wxWidgets is quite easy, and three non exclusive solutions are available:

  1. you can directly handle graphical objects and layout in your code
  2. you can make use of the wxWidgets standard resource files (wxr)
  3. you can make use of XML resource files (XRC files)

This document deals with the third solution in a C/C++ application context.

This resource system in not a part of the standard wxWidgets library, but is delivered with the standard source packages in the contrib directory as a library.

To build the "wxrc" library refer to the wxWidgets documentation.

The two main advantages of XML resources, except that it is XML, is that it is quite readable and runtime processed.

Warning

This document is not a C/C++ tutorial for wxWidgets as other tutorials are available including the wxWidgets documentation and samples which is a good starting point.

Using the wxXmlResource Class

The wxXmlResource is the only class you have to deal with in order to make use of XRC files in your C/C++ application. A typical use is the following

Initialization

wxXmlResource handles a reference to a unique resource handler (smart pointer), which must be initialized before you can use it. It is accessed in the following manner :

wxXmlResource::Get()->methodname

This initialization could be done in the OnInit method of your wxApp derived class.

Each resource type has its own handler, and if you intend to use it in your application you should add it to the wxXmlResource object.

A simple way to initialize the resource system is to call InitAllHandlers method of wxXmlResource class so you don't have to worry about all the handlers you could add.

wxXmlResource::Get()->InitAllHandlers();
bRet = wxXmlResource::Get()->Load( Path );
if( !bRet )
{
    cout  << "Could not load resource file" << Path << endl;
    return false;
}

The individual resource handlers available (depending on compilation options in setup.h) are:

  • wxBitmapXmlHandler
  • wxIconXmlHandler
  • wxMenuXmlHandler
  • wxMenuBarXmlHandler
  • wxDialogXmlHandler
  • wxPanelXmlHandler
  • wxSizerXmlHandler
  • wxButtonXmlHandler
  • wxBitmapButtonXmlHandler
  • wxStaticTextXmlHandler
  • wxStaticBitmapXmlHandler
  • wxTreeCtrlXmlHandler
  • wxCalendarCtrlXmlHandler
  • wxListCtrlXmlHandler
  • wxCheckListXmlHandler
  • wxChoiceXmlHandler
  • wxSliderXmlHandler
  • wxGaugeXmlHandler
  • wxCheckBoxXmlHandler
  • wxHtmlWindowXmlHandler
  • wxSpinButtonXmlHandler
  • wxSpinCtrlXmlHandler
  • wxScrollBarXmlHandler
  • wxRadioBoxXmlHandler
  • wxRadioButtonXmlHandler
  • wxComboBoxXmlHandler
  • wxNotebookXmlHandler
  • wxTextCtrlXmlHandler
  • wxListBoxXmlHandler
  • wxToolBarXmlHandler
  • wxStaticLineXmlHandler
  • wxUnknownWidgetXmlHandler
  • wxGenericDirCtrlXmlHandler
  • wxFrameXmlHandler
  • wxScrolledWindowXmlHandler

wxWidgets controls and windows that are not listed here are not handled in XRC files. But however you can write your own handler to handle them by deriving wxUnknownWidgetXmlHandler

Now that handlers are added to the resource handler you have to specify which XRC file(s) you want to load by calling the Load method. The parameter you pass to this method must be a valid path to the file you wand to load.

Using wxXmlResource to Create UI Elements

There are 8 top level resource types that you can describe in a XRC file.

  • Frames (LoadFrame method)
  • Dialogs (LoadDialog method)
  • Panels (LoadPanel method)
  • MenuBars (LoadMenuBar method)
  • Menus (LoadMenu method)
  • Toolbars (LoadToolBar method)
  • Bitmaps (LoadBitmap method)
  • Icons (LoadIcon method)

Except for bitmaps and icons, the resource system handles all the resource types contained in the resource description, but you cannot directly load an wxTextCtrl for example.

LoadBitmap, LoadIcon, LoadMenu, LoadMenuBar, LoadToolBar methods return new created objects. The cannot be used to initialize existing object as LoadFrame, LoadDialog and LoadPanel do.

For example there are three ways to create a dialog :

1. Directly by using the following form wxDialog *Dlg;

Dlg = wxXmlResource::Get()->LoadDialog( FrameObjectPointer, "dialog_resource" );
Dlg->ShowModal();

2. Indirectly by using the following form wxDialog Dlg;

wxXmlResource::Get()->LoadDialog( &Dlg, FrameObjectPointer, "dialog_resource" );
Dlg.ShowModal();

where "dialog_resource" is the name of the resource in the XML file, or

MyDerivedDialog Dlg;
wxXmlResource::Get()->LoadDialog( &Dlg, FrameObjectPointer, "dialog_resource" );
Dlg.ShowModal();

3. Indirectly in a derived class of wxDialog

MyDerivedDialog::MyDerivedDialog( wxWindow *p_Parent )
{
    wxXmlResource::Get()->LoadDialog( this, p_Parent, "dialog_resource" );
}

Important

Note that in the last example the wxDialog base class constructor is not called, and should not be.

XML Resource File (XRC) Format

XRC files are standard XML files. The format should be the following :

<?xml version="1.0"?>
<resource version="2.3.0.1">
    <object class="wxFrame" name="my_main_frame">
        <size>200,300</size>
        ...
    </object>
</resource>

Internationalization (i18n)

The wxWidgets source distribution contains a project name wxrc in the contrib/utils directory. This utility is used to produce zipped XRC resource files, but can also extract strings for i18n:

wxrc.exe [/g] [-o] [outputfile] [resourcefile]

outputfile will contain strings in the wxWidgets classical i18n compatible form _("string") and which can be processed by xgettext.

XRC Object Descriptions

This part describes each resource type available in XRC files. All "object" nodes have an optional "name" parameter used as an ID for that object, which can be retieved with the XRCID() macro in code.

wxWindow Derived Elements

Many of the elements (windows, controls) that are described in an XRC file are derived from the wxWindow class. The all have common properties available:

exstyle
window styles, see the wxWindow documentation for possible styles (separate multiple styles with the "|" (pipe) character)
bg
background window color: RGB color in the #RRGGBB format (HTML like)
fg
foreground window color: RGB color in the #RRGGBB format (HTML like)
enabled
is the window enabled? bool value (0/1)
focused
should this window have the focus? bool value (0/1)
hidden
should this window be hidden? bool value (0/1)
tooltip
free texttooltip text associated to the window (must have been enabled in setup.h)
font
font description
size
font size in points
style
font style: normal, italic, slant
weight
font weight: normal, bold, light
family
font family: decorative, modern, roman, script, swiss, teletype
underlined
should the font be underlined? bool value (0/1)
encoding
CHARSET in text formatfont encoding
face
font for this window: FACENAME in text formatfont face

Sizers

Sizers are a very important part of the XRC resources. Their goal is to let you lay out the controls you need in a panel, a window or a frame.

sizeritem

All sizer types contain one or more sizeritem. A sizeritem contains one object (control).

flag
See the wxSizer documentation for a list of possible values.
minsize
pair: minimum size of the sizer (200,200 for example).
option
long: used to tell the sizer item it has a certain "weight" in the proportions among all sizer items.
border
long: border size (for borders specified in "flag").

wxBoxSizer

The box sizer divides the layout into two components either horizontally or vertically. It contains one or more sizeritem tags.

orient
wxBoxSizer orientation: wxVERTICAL, wxHORIZONTAL
<object class="wxBoxSizer">
    <orient>wxHORIZONTAL</orient>
    <object class="sizeritem">Left control</object>
    <object class="sizeritem">Right control</object>
</object>

wxStaticBoxSizer

A static box sizer is a box sizer with a surrounding box and a label.

orient
wxBoxSizer orientation: wxVERTICAL, wxHORIZONTAL
label
Text: label of the static box.

wxGridSizer

A grid sizer divides the layout into rows and cols of identical sizes.

rows
Number of rows.
cols
Number of cols.
vgap
vertical space between to elements.
hgap
horizontal space between to elements.
<object class="wxGridSizer">
    <rows>2</rows>
    <cols>2</cols>
    <object class="sizeritem">control in 0,0 (row,col)</object>
    <object class="sizeritem">control in 0,1 (row,col)</object>
    <object class="sizeritem">control in 1,0 (row,col)</object>
    <object class="sizeritem">control in 1,1 (row,col)</object>
</object>

wxFlexGridSizer

A grid sizer divides the layout into rows and cols of identical sizes.

rows
Number of rows.
cols
Number of cols.
vgap
vertical space between to elements.
hgap
horizontal space between to elements.
growablecols
list: comma separated list of cols indexes that will grow with the container.
growablerows
list: comma separated list of rows indexes that will grow with the container.

wxBitmapButton

Inherits wxWindow properties.

style
button style: wxBU_AUTODRAW, wxBU_LEFT, wxBU_RIGHT, wxBU_TOP, wxBU_BOTTOM
bitmap
The bitmap path and filename
default
bool value (0/1) - 1 if this button is the default button of the dialog or panel.
selected
This is the selected bitmap specifier. Contains a bitmap tag
focus
This is the focused bitmap specifier. Contains a bitmap tag
disabled
This is the disabled bitmap specifier. Contains a bitmap tag
<?xml version="1.0"?>
<resource version="2.4.0">
<object class="wxFrame" name="main_frame">
<title>Testing the XRC resource system</title>
    <object class="wxPanel" name="main_panel">
        <object class="wxBoxSizer">
        <orient>wxVERTICAL</orient>
            <object class="sizeritem">
            <flag>wxALL|wxGROW</flag>
            <option>1</option>
             <object class="wxBitmapButton" name="bt_bitmapbutton">
                 <style>wxBU_LEFT</style>
                 <bitmap>bt_buttonbitmap.xpm</bitmap>
                 <selected>
                     <bitmap>bt_buttonbitmaps.xpm</bitmap>
                 </selected>
                 <focus>
                     <bitmap>bt_buttonbitmapf.xpm</bitmap>
                 </focus>
                 <disabled>
                     <bitmap>bt_buttonbitmapd.xpm</bitmap>
                 </disabled>
              </object>
          </object>
          <object class="sizeritem">
          <flag>wxALL</flag>
              <object class="wxStaticText" name="st_description">
                  <label>wxBitmapButton test</label>
              </object>
          </object>
       </object>
   </object>
</object>
</resource>

wxButton

Inherits wxWindow properties

style
The button style: wxBU_LEFT, wxBU_RIGHT, wxBU_TOP, wxBU_BOTTOM
label
The label of the button
default
bool value (0/1): 1 if this button is the default button of the dialog or panel.
<resource version="2.4.0">
<object class="wxFrame" name="main_frame">
<title>Testing the XRC resource system</title>
    <object class="wxPanel" name="main_panel">
        <object class="wxBoxSizer">
        <orient>wxVERTICAL</orient>
            <object class="sizeritem">
            <flag>wxALL|wxGROW</flag>
            <option>1</option>
                <object class="wxButton" name="bt_button">
                    <style>wxBU_LEFT</style>
                    <label>Button label</label>
                </object>
            </object>
            <object class="sizeritem">
            <flag>wxALL</flag>
                <object class="wxStaticText" name="st_description">
                    <label>wxButton test</label>
                </object>
            </object>
        </object>
    </object>
</object>
</resource>

wxCalendarCtrl

Inherits wxWindow properties

style
Calendar styles defining how the calendar control should work: wxCAL_SUNDAY_FIRST, wxCAL_MONDAY_FIRST, wxCAL_SHOW_HOLIDAYS, wxCAL_NO_YEAR_CHANGE, wxCAL_NO_MONTH_CHANGE
<resource version="2.4.0">
<object class="wxFrame" name="main_frame">
<title>Testing the XRC resource system</title>
 <object class="wxPanel" name="main_panel">
  <object class="wxBoxSizer">
  <orient>wxVERTICAL</orient>
   <object class="sizeritem">
   <flag>wxALL|wxGROW</flag>
   <option>1</option>
    <object class="wxCalendarCtrl" name="calendar">
     <style>wxCAL_MONDAY_FIRST|wxCAL_SHOW_HOLIDAYS</style>
    </object>
   </object>
   <object class="sizeritem">
   <flag>wxALL</flag>
    <object class="wxStaticText" name="st_description">
     <label>wxCalendarCtrl test</label>
    </object>
   </object>
  </object>
 </object>
</object>
</resource>

File:WxCalendarCtrl.png

wxCheckBox

Inherits wxWindow properties

label
Label of the check box
checked
bool value (1/0): 1 if the check box is checked on creation
<resource version="2.4.0">
<object class="wxFrame" name="main_frame">
<title>Testing the XRC resource system</title>
 <object class="wxPanel" name="main_panel">
  <object class="wxBoxSizer">
   <orient>wxVERTICAL</orient>
    <object class="sizeritem">
      <flag>wxALL|wxGROW</flag>
      <object class="wxCheckBox" name="checkbox_id">
       <size>200,50</size>
       <label>CheckBoxItem</label>
       <checked>1</checked>
      </object>
    </object>
    <object class="sizeritem">
      <flag>wxALL</flag>
       <object class="wxStaticText" name="st_description">
        <label>wxCheckBox test</label>
      </object>
    </object>
   </object>
  </object>
</object>
</resource>

wxCheckList

Inherits wxWindow properties

content
list of item tags describing the elements in the control, item tag attributes:
checked
bool value (0/1) : 1 if the element is checked
<object class="wxCheckList" name="checklistbox_id">
<size>200,100</size>
<content>
 <item checked="1">Item value 1</item>
 <item checked="0">Item value 2</item>
 <item checked="1">Item value 3</item>
 <item checked="0">Item value 4</item>
 <item checked="1">Item value 5</item>
</content>
</object>

File:WxCheckListSample.png

wxChoice

Inherits wxWindow properties

selection
integer value: index (0 based) of the selected entry
content
list of item tags describing the elements in the control, item tag attributes:
checked
bool value (0/1) : 1 if the element is checked
<object class="wxChoice" name="choice_id">
<size>200,100</size>
<selection>2</selection>
 <content>
  <item checked="1">Item value 1</item>
  <item checked="0">Item value 2</item>
  <item checked="1">Item value 3</item>
  <item checked="0">Item value 4</item>
  <item checked="1">Item value 5</item>
 </content>
</object>

wxComboBox

Inherits wxWindow properties

style
combo style: wxCB_SIMPLE, wxCB_SORT, wxCB_READONLY, wxCB_DROPDOWN
value
initial value of the combo as text
selection
integer value: index ( 0 based ) of the selected entry
content
list of item tags describing the elements in the control, item tag attributes:
checked
bool value (0/1) : 1 if the element is checked
<object class="wxComboBox" name="combo_id">
<size>200,100</size>
<style>wxCB_DROPDOWN</style>
<selection>2</selection>
 <content>
  <item checked="1">Item value 1</item>
  <item checked="0">Item value 2</item>
  <item checked="1">Item value 3</item>
  <item checked="0">Item value 4</item>
  <item checked="1">Item value 5</item>
 </content>
</object>

File:WxComboBoxSample.png

wxDialog

Inherits wxWindow properties. This is a top-level component, and it can have multiple sub elements (sizers, controls).

title
Title of the dialog as text
style
see the wxDialog documentation for a list of styles
centered
bool value(0/1) : 1 if the dialog should be centered on it's parent screen.
<object class="wxDialog" name="test_dialog">
<title>My Dialog</title>
<style>wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX</style>
 <object class="wxBoxSizer">
 <orient>wxVERTICAL</orient>
  <object class="sizeritem">
  <flag>wxALL</flag>
   <object class="wxTextCtrl" name="textctrl_id">
   <value>Hello World !!!!</value>
   </object>
  </object>
  <object class="sizeritem">
  <flag>wxALL</flag>
   <object class="wxStaticText" name="st_description">
   <label>wxComboBox test</label>
   </object>
  </object>
 </object>
</object>

wxFrame

Inherits wxWindow properties. This is a top-level component, and it can have multiple sub elements (sizers, controls ).

title
Title of the frame as text
style
see the wxFrame documentation for a list of styles.
centered
bool value(0/1) : 1 if the frame should be centered on it's parent screen.
<object class="wxFrame" name="main_frame">
<title>Testing the XRC resource system</title>
 <object class="wxPanel" name="main_panel">
  <object class="wxBoxSizer">
  <orient>wxVERTICAL</orient>
   <object class="sizeritem">
    <flag>wxALL</flag>
     <object class="wxTextCtrl" name="textctrl_id">
      <value>Hello World !!!!</value>
     </object>
    </object>
   <object class="sizeritem">
    <flag>wxALL</flag>
     <object class="wxStaticText" name="st_description">
      <label>wxComboBox test</label>
     </object>
    </object>
  </object>
 </object>
</object>

File:WxFrameSample.png

wxGauge

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxGA_HORIZONTAL wxGA_VERTICAL wxGA_PROGRESSBAR wxGA_SMOOTH
Gauge style
range</span>
integer value: maximum value for the gauge.
value</span>
integer value: initial value for the gauge position.
shadow</span>
integer value: width of the shadow.
bezel</span>
integer value: width of the bezel face.

Example 13. wxGauge sample

<object class="wxGauge" name="gauge_id">
<style>wxGA_HORIZONTAL|wxGA_PROGRESSBAR|wxGA_SMOOTH</style>
<shadow>20</shadow>
<bezel>40</bezel>
<range>100</range>
<value>33</value>
</object>

5.13. wxGenericDirCtrl

Inherits wxWindow properties

Tip

default size of this control seems to be 0,0. So you should always put a size tag.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxDIRCTRL_DIR_ONLY wxDIRCTRL_3D_INTERNAL wxDIRCTRL_SELECT_FIRST wxDIRCTRL_SHOW_FILTERS
Control style
defaultfolder</span>
Text value: path of the default directory.
filter</span>
Text value: expression of the files to be displayed (wild card enabled).
defaultfilter</span>
long value: index of the default filter.

Example 14. wxGenericDirCtrl sample

<object class="wxGenericDirCtrl" name="dirctrl_id">
<size>200,200</size>
<style>wxDIRCTRL_SHOW_FILTERS</style>
<defaultfolder>e:/temp</defaultfolder>
<defaultfilter>1</defaultfilter>
<filter>*.txt</filter>
<filter>*.jpg</filter>
<filter>*.zip</filter>
</object>

5.14. wxHtmlWindow

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxHW_SCROLLBAR_NEVER wxHW_SCROLLBAR_AUTO
HTML window style
borders</span>
integer value: border size to leave between the left and top border of the window, and the HTML display.
htmlcode</span>
text value: the HTML the control should display.
url</span>
text: path to an HTML file to display.

Example 15. xwHtmlWindow sample

<object class="wxHtmlWindow" name="htmlid_id">
<size>200,200</size>
<borders>20d</borders>
<htmlcode><b>This is a simple text</b></htmlcode>
</object>

5.15. wxListBox

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxLB_SINGLE wxLB_MULTIPLE wxLB_EXTENDED wxLB_HSCROLL wxLB_ALWAYS_SB
wxLB_NEEDED_SB wxLB_SORT
List box style
selection</span>
integer value: index ( 0 based ) of the selected entry
content</span>
list of item tags describing the elements in the "list box" control.

Example 16. wxListBox sample

<object class="wxListBox" name="listbox_id">
<selection>2</selection>
<content>
 <item>Item value 1</item>
 <item>Item value 2</item>
 <item>Item value 3</item>
 <item>Item value 4</item>
 <item>Item value 5</item>
</content>
</object>

5.16. wxListCtrl

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxLC_LIST wxLC_REPORT wxLC_ICON wxLC_SMALL_ICON wxLC_ALIGN_TOP
wxLC_ALIGN_LEFT wxLC_AUTOARRANGE wxLC_USER_TEXT wxLC_EDIT_LABELS wxLC_NO_HEADER
wxLC_SINGLE_SEL wxLC_SORT_DESCENDING wxLC_SORT_ASCENDING
List control style

Example 17. wxListCtrl sample

<object class="wxListCtrl" name="listctrl_id">
<style>wxLC_REPORT|wxLC_ICON</style>
</object>

5.17. wxMenuBar

Does not inherit wxWindow properties. A wxMenuBar can contain one or more wxMenu sub-elements.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxMB_DOCKABLE
Menu bar style

Example 18. wxMenuBar sample

<object class="wxMenuBar" name="main_menu_bar">
 <object class="wxMenu" name="file_menu">
 <label>File</label>
 <help>File menu</help>
 <style>wxMENU_TEAROFF</style>
  <object class="wxMenuItem" name="open_menu_item">
   <label>Open</label>
   <help>Opens a file</help>
   <accel>Alt-O</accel>
  </object>
  <object class="wxMenuItem" name="radio_menu_item">
   <label>Radio</label>
   <radio>1</radio>
  </object>
  <object class="wxMenuItem" name="check_menu_item">
   <label>Check</label>
   <checkable>1</checkable>
   <enabled>1</enabled>
   <checked>1</checked>
  </object>
  <object class="break" />
  <object class="wxMenuItem" name="close_menu_item">
   <label>Close</label>
   <help>Closes a file</help>
   <bitmap>bt_buttonbitmap.xpm</bitmap>
  </object>
  <object class="separator" />
  <object class="wxMenuItem" name="exit_menu_item">
   <label>Exit</label>
   <help>Exits the program</help>
   <accel>Alt-X</accel>
  </object>
</object>

5.18. wxMenu

Does not inherit wxWindow properties. A menu contains one or more wxMenuItem tags.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxMENU_TEAROFF
Menu style
label</span>
Text: label of the menu.
help</span>
Text: displayed help string.

5.19. wxMenuItem

Does not inherit wxWindow properties.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxMENU_TEAROFF
Menu style
label</span>
Text: label of the menu.
accel</span>
Text: accelerator associated to this item ( Alt-X for example ).
help</span>
Text: displayed help string.
radio</span>
bool value(0/1): 1 if this item is a radio menu item.
checkable</span>
bool value(0/1): 1 if this item is a check menu item.
enabled</span>
bool value(0/1): 1 if this item is initially enabled.
checked</span>
bool value(0/1): 1 if this (check) item is initially checked.
bitmap</span>
Text: path to a bitmap to draw at the left of the item.

5.20. wxNotebook

Does not Inherit wxWindow properties. A wxNotebook tag contains one or more notebookpage tags.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxNB_FIXEDWIDTH wxNB_LEFT wxNB_RIGHT wxNB_BOTTOM
Notebook style
usenotebooksizer</span>
bool value(0/1): 1 if a notebook sizer is to be used to handle notebook pages.

Example 19. wxNotebook sample

<object class="wxNotebook" name="main_notebook">
 <object class="notebookpage" name="firstnotepage">
 <label>First</label>
 <selected>1</selected>
  <object class="wxPanel" name="main_panel">
   <object class="wxBoxSizer">
   <orient>wxVERTICAL</orient>
    <object class="sizeritem">
    <flag>wxALL</flag>
     <object class="wxTextCtrl" name="textctrl_id">
      <value>Hello World !!!</value>
     </object>
    </object>
    <object class="sizeritem">
    <flag>wxALL</flag>
     <object class="wxStaticText" name="st_description">
      <label>wxListCtrl test</label>
     </object>
    </object>
   </object>
  </object>
 </object>
 <object class="notebookpage" name="secondnotepage">
 <label>Second</label>
  <object class="wxPanel" name=" secondpanel">
   <object class="wxFlexGridSizer">
   <cols>1</cols>
   <rows>0</rows>
   <growablerows>0</growablerows>
   <growablecols>1</growablecols>
    <object class="sizeritem">
     <flag>wxALL</flag>
      <object class="wxTextCtrl" name="st_second_text">
       <value>Static text</value>
      </object>
     </object>
    </object>
   </object>
  </object>
 </object>
</object>

5.21. notebookpage

A notebookpage can only appear inside a wxNotebook. It contains one or more objects like panels and controls.

label</span>
Text: label of the page.
selected</span>
bool value(0/1): is this page the selected one.

5.22. wxPanel

Inherits wxWindow properties. A panel contains zero or more sizers and controls.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxNO_3D wxTAB_TRAVERSAL wxWS_EX_VALIDATE_RECURSIVELY wxCLIP_CHILDREN
Panel style.

5.23. wxRadioButton

Inherits wxWindow properties.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxRB_GROUP
Radio button style
label</span>
Text: label of the button.
value</span>
bool value(0/1): 1 if the button is selected.

Example 20. wxRadioButton sample

<object class="wxRadioButton" name="radiobutton_id">
<label>Radio button</label>
<value>1</value>
</object>

5.24. wxRadioBox

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxRA_SPECIFY_COLS wxRA_HORIZONTAL wxRA_SPECIFY_ROWS wxRA_VERTICAL
Radio box style
selection</span>
integer value: index ( 0 based ) of the selected entry
content</span>
list of item tags describing the elements in the "radiobox" control.

Example 21. wxRadioBox sample

<object class="wxRadioBox" name="radiobox_id">
<label>Radio box</label>
<selection>1</selection>
<dimension>2</dimension>
<content>
 <item>Value 1</item>
 <item>Value 2</item>
 <item>Value 3</item>
 <item>Value 4</item>
 <item>Value 5</item>
 <item>Value 6</item>
</content>
</object>

5.25. wxScrollBar

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxSB_HORIZONTAL wxSB_VERTICAL
Scroll bar style
value</span>
long: current position
thumbsize</span>
long: view size
range</span>
long: max value of the scrollbar
pagesize</span>
long: size of one scrolled page

Example 22. wxScrollBar sample

<object class="wxScrollBar" name="scrollbar_id">
<size>-1,100</size>
<value>50</value>
<range>100</range>
<thumbsize>30</thumbsize>
<style>wxSB_VERTICAL</style>
</object>

5.26. wxScrolledWindow

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxHSCROLL wxVSCROLL
Scrolled window style

Example 23. wxScrolledWindow sample

<object class="wxScrolledWindow" name="scrolledwindow_id">
<bg>#FFFFFF</bg>
<style>wxHSCROLL|wxVSCROLL</style>
<size>200,200</size>
</object>

5.27. wxSlider

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxSL_HORIZONTAL wxSL_VERTICAL wxSL_AUTOTICKS wxSL_LABELS wxSL_LEFT
wxSL_RIGHT wxSL_BOTTOM wxSL_BOTH wxSL_SELRANGE
Slider style
value</span>
long: current position of the slider
min</span>
long: minimum position of the slider
max</span>
long: maximum position of the slider
tickfreq</span>
long: tick frequency
pagesize</span>
long: The number of steps the slider moves when the user pages up or down
linesize</span>
long: the number of steps the slider moves when the user moves it up or down a line
thumb</span>
long: sets the thumb length
tick</span>
long: position of a tick
selmin, </span>selmax</span>
long: sets minimum and maximum selection position

Example 24. wxSlider sample

<object class="wxSlider" name="slider_id">
<style>wxSL_HORIZONTAL|wxSL_AUTOTICKS</style>
<size>200,200</size>
<tickfreq>10</tickfreq>
<value>50</value>
<min>10</min>
<max>200</max>
</object>

5.28. wxSpinButton

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxSP_HORIZONTAL wxSP_VERTICAL wxSP_ARROW_KEYS wxSP_WRAP
Spin button style
value</span>
long: current value of the spin button
min</span>
long: minimum value of the spin button
max</span>
long: maximum value of the spin button

Example 25. wxSpinButton sample

<object class="wxSpinButton" name="spinbutton_id">
<style>wxSP_HORIZONTAL|wxSP_ARROW_KEYS</style>
<value>50</value>
<min>10</min>
<max>200</max>
</object>

5.29. wxSpinCtrl

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxSP_HORIZONTAL wxSP_VERTICAL wxSP_ARROW_KEYS wxSP_WRAP
Spin control style
value</span>
long: current value of the spin control
min</span>
long: minimum value of the spin control
max</span>
long: maximum value of the spin control

Example 26. wxSpinCtrl sample

<object class="wxSpinCtrl" name="spincontrol_id">
<style>wxSP_HORIZONTAL|wxSP_ARROW_KEYS</style>
<value>50</value>
<min>10</min>
<max>200</max>
</object>

5.30. wxStaticBitmap

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

bitmap</span>
Text: Bitmap file name

Example 27. wxStaticBitmap sample

<object class="wxStaticBitmap" name="bitmap_id">
<bitmap>bt_buttonbitmap.xpm</bitmap>
</object>

5.31. wxStaticBox

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

label</span>
Text: label of the static box

Example 28. wxStaticBox sample

<object class="wxStaticBox" name="stbox_id">
<size>200,200</size>
<label>Static box sample</label>
</object>

5.32. wxStaticLine

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxLI_HORIZONTAL wxLI_VERTICAL
Static line style

Tip

The size property should be present to size the static line. Default size is 0,0.

Example 29. wxStaticLine sample

<object class="wxStaticLine" name="stline_id">
<size>200,5</size>
<style>wxLI_HORIZONTAL</style>
</object>

5.33. wxStaticText

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxST_NO_AUTORESIZE wxALIGN_LEFT wxALIGN_RIGHT wxALIGN_CENTRE
Static text style
label</span>
Text: label of the static text

Example 30. wxStaticText sample

<object class="wxStaticText" name="sttext_id">
<style>wxALIGN_CENTRE</style>
<label>Hello, World!!!</label>
</object>

5.34. wxTextCtrl

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxTE_PROCESS_ENTER wxTE_PROCESS_TAB wxTE_MULTILINE wxTE_PASSWORD wxTE_READONLY
wxHSCROLL wxTE_RICH wxTE_RICH2 wxTE_AUTO_URL wxTE_NOHIDESEL
wxTE_LEFT wxTE_CENTRE wxTE_RIGHT wxTE_DONTWRAP wxTE_LINEWRAP
wxTE_WORDWRAP
Text control style
value</span>
Text: initial value of the text control

Example 31. wxTextCtrl sample

<object class="wxTextCtrl" name="textctrl_id">
<style>wxTE_MULTILINE</style>
<value>Hello, World!!!</value>
</object>

5.35. wxToolBar

A wxToolBar contains zero or more tool and separator tags.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxTB_FLAT wxTB_DOCKABLE wxTB_VERTICAL wxTB_HORIZONTAL
Toolbar style
bitmapsize</span>
size: size of the tools bitmaps ( 16,16 for example )
margins</span>
size: margins size
packing</span>
long: space between tools
separation</span>
long: size of the separator

Example 32. wxToolBar sample

<object class="wxToolBar" name="main_toolbar">
<bitmapsize>50,50</bitmapsize>
<style>wxTB_DOCKABLE|wxTB_HORIZONTAL</style>
 <object class="tool" name="tool1">
  <bitmap>bt_buttonbitmap.xpm</bitmap>
  <bitmap2>bt_buttonbitmapd.xpm</bitmap2>
  <toggle>1</toggle>
  <tooltip>first button</tooltip>
  <longhelp>long help first button</longhelp>
 </object>
 <object class="separator"/>
 <object class="tool" name="tool2">
  <bitmap>bt_buttonbitmap.xpm</bitmap>
  <bitmap2>bt_buttonbitmapd.xpm</bitmap2>
  <toggle>0</toggle>
  <tooltip>second button</tooltip>
  <longhelp>long help second button</longhelp>
 </object>
</object>

5.36. tool

A tool can only appear in a wxToolBar tag and describes a item of this tool bar.

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

bitmap</span>
Text: path to the main bitmap file
bitmap2</span>
Text: path to the second bitmap file (pressed)
toggle</span>
bool value(0/1): 1 if the button should toggle when pressed
tooltip</span>
Text: tooltip associated to the tool
longhelp</span>
Text: help string associated to the tool

5.37. separator

A separator tag can only appear inside a wxToolBar tag and has not properties and no attributes.

5.38. wxTreeCtrl

Inherits wxWindow properties

Attributes

name</span>
string:unique identifier for the resource

Properties(as XML sub-elements)

style</span>
wxTR_EDIT_LABELS wxTR_NO_BUTTONS wxTR_HAS_BUTTONS wxTR_TWIST_BUTTONS wxTR_NO_LINES
wxTR_FULL_ROW_HIGHLIGHT wxTR_LINES_AT_ROOT wxTR_HIDE_ROOT wxTR_ROW_LINES wxTR_HAS_VARIABLE_ROW_HEIGHT
wxTR_SINGLE wxTR_MULTIPLE wxTR_EXTENDED wxTR_DEFAULT_STYLE
Tree control style

Example 33. wxTreeCtrl sample

<object class="wxTreeCtrl" name="treectrl_id">
<style>wxTR_EDIT_LABELS|wxTR_HAS_BUTTONS|wxTR_HAS_VARIABLE_ROW_HEIGHT</style>
</object>