Add support for fixed spacers and labels to wxAuiToolBar XRC handler.

Allow specifying "width" and "proportion" attributes for the "space" elements
and add "label" element support.

Closes #15964.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-02-18 15:05:52 +00:00
parent d64c74160b
commit 0206eb6161
5 changed files with 76 additions and 8 deletions

View File

@@ -25,7 +25,7 @@ All:
All (GUI): All (GUI):
- XRC handler for wxAuiToolBar added (Kinaou Hervé). - XRC handler for wxAuiToolBar added (Kinaou Hervé, David Hart).
- Add support for sorting wxDataViewCtrl by multiple columns (Trigve). - Add support for sorting wxDataViewCtrl by multiple columns (Trigve).
- Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr). - Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr).
- Add default ctor and Create() to wxContextHelpButton (Hanmac). - Add default ctor and Create() to wxContextHelpButton (Hanmac).

View File

@@ -597,6 +597,13 @@ Building an XRC for wxAuiToolBar is quite similar to wxToolBar.
The only significant differences are: The only significant differences are:
@li the use of the class name wxAuiToolBar @li the use of the class name wxAuiToolBar
@li the styles supported are the ones described in the wxAuiToolBar class definition @li the styles supported are the ones described in the wxAuiToolBar class definition
@li the 'space' pseudo-class has two optional, mutually exclusive,
integer properties: 'proportion' and 'width'. If 'width' is specified, a space
is added using wxAuiToolBar::AddSpacer(); if 'proportion', the value is used in
wxAuiToolBar::AddStretchSpacer(). If neither are provided, the default is a
stretch-spacer with a proportion of 1.
@li there is an additional pseudo-class, 'label', that has a string property.
See wxAuiToolBar::AddLabel().
Refer to the section @ref xrc_wxtoolbar for more details. Refer to the section @ref xrc_wxtoolbar for more details.

View File

@@ -326,6 +326,7 @@ builtinNestedClassesNames =
| "separator" | "separator"
| "break" | "break"
| "space" | "space"
| "label"
| "tool" | "tool"
| "panewindow" | "panewindow"
| "notebookpage" | "notebookpage"
@@ -540,11 +541,24 @@ wxAuiToolBar =
( (
windowNode | windowNode |
wxToolBar_tool | wxToolBar_tool |
wxAuiToolBar_label |
element object { attribute class { "separator" }, platform } | element object { attribute class { "separator" }, platform } |
element object { attribute class { "space" }, platform } element object { attribute class { "space" } &
platform &
[xrc:p="o"] element width {_, t_integer }* &
[xrc:p="o"] element proportion {_, t_integer }*
}
)* )*
} }
wxAuiToolBar_label =
element object {
attribute class { "label" } &
platform &
attribute name { t_identifier }? &
[xrc:p="important"] element label {_, t_text }* &
[xrc:p="o"] element width {_, t_integer }*
}
wxBannerWindow = wxBannerWindow =
element object { element object {

View File

@@ -4,16 +4,24 @@
<title>AUI XRC demo</title> <title>AUI XRC demo</title>
<centered>1</centered> <centered>1</centered>
<style>wxCAPTION|wxRESIZE_BORDER</style> <style>wxCAPTION|wxRESIZE_BORDER</style>
<size>-1,300</size> <size>500,300</size>
<object class="wxBoxSizer"> <object class="wxBoxSizer">
<orient>wxVERTICAL</orient> <orient>wxVERTICAL</orient>
<object class="sizeritem"> <object class="sizeritem">
<flag>wxEXPAND</flag>
<object class="wxAuiToolBar" name="aui_toolbar"> <object class="wxAuiToolBar" name="aui_toolbar">
<style>wxAUI_TB_TEXT|wxAUI_TB_GRIPPER</style> <style>wxAUI_TB_TEXT|wxAUI_TB_GRIPPER</style>
<object class="label" name="label1">
<label>Tools:</label>
<width>-1</width>
</object>
<object class="tool" name="tool1"> <object class="tool" name="tool1">
<bitmap stock_id="wxART_NEW"/> <bitmap stock_id="wxART_NEW"/>
<label>Tool 1</label> <label>Tool 1</label>
</object> </object>
<object class="space">
<width>25</width>
</object>
<object class="tool" name="tool2"> <object class="tool" name="tool2">
<bitmap stock_id="wxART_FILE_OPEN"/> <bitmap stock_id="wxART_FILE_OPEN"/>
<label>Tool 2</label> <label>Tool 2</label>
@@ -34,7 +42,9 @@
</dropdown> </dropdown>
</object> </object>
<object class="separator"/> <object class="separator"/>
<object class="space"/> <object class="space">
<proportion>3</proportion>
</object>
<object class="wxComboBox"> <object class="wxComboBox">
<content> <content>
<item>Just a</item> <item>Just a</item>
@@ -43,7 +53,7 @@
</content> </content>
</object> </object>
<object class="space"/> <object class="space"/>
</object> </object>
</object> </object>
<object class="sizeritem"> <object class="sizeritem">
<option>1</option> <option>1</option>

View File

@@ -136,7 +136,7 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource()
return m_toolbar; // must return non-NULL return m_toolbar; // must return non-NULL
} }
else if (m_class == wxS("separator") || m_class == wxS("space")) else if (m_class == wxS("separator") || m_class == wxS("space") || m_class == wxS("label"))
{ {
if ( !m_toolbar ) if ( !m_toolbar )
{ {
@@ -146,8 +146,43 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource()
if ( m_class == wxS("separator") ) if ( m_class == wxS("separator") )
m_toolbar->AddSeparator(); m_toolbar->AddSeparator();
else
m_toolbar->AddStretchSpacer(); else if (m_class == wxS("space"))
{
// This may be a stretch spacer (the default) or a non-stretch one
bool hasProportion = HasParam(wxS("proportion"));
bool hasWidth = HasParam(wxS("width"));
if (hasProportion && hasWidth)
{
ReportError("A space can't both stretch and have width");
return NULL;
}
if (hasWidth)
{
m_toolbar->AddSpacer
(
GetLong(wxS("width"))
);
}
else
{
m_toolbar->AddStretchSpacer
(
GetLong(wxS("proportion"), 1l)
);
}
}
else if (m_class == wxS("label"))
{
m_toolbar->AddLabel
(
GetID(),
GetText(wxS("label")),
GetLong(wxS("width"), -1l)
);
}
return m_toolbar; // must return non-NULL return m_toolbar; // must return non-NULL
} }
@@ -201,6 +236,7 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource()
wxControl *control = wxDynamicCast(created, wxControl); wxControl *control = wxDynamicCast(created, wxControl);
if (!IsOfClass(n, wxS("tool")) && if (!IsOfClass(n, wxS("tool")) &&
!IsOfClass(n, wxS("separator")) && !IsOfClass(n, wxS("separator")) &&
!IsOfClass(n, wxS("label")) &&
!IsOfClass(n, wxS("space")) && !IsOfClass(n, wxS("space")) &&
control != NULL) control != NULL)
toolbar->AddControl(control); toolbar->AddControl(control);
@@ -221,6 +257,7 @@ bool wxAuiToolBarXmlHandler::CanHandle(wxXmlNode *node)
{ {
return ((!m_isInside && IsOfClass(node, wxS("wxAuiToolBar"))) || return ((!m_isInside && IsOfClass(node, wxS("wxAuiToolBar"))) ||
(m_isInside && IsOfClass(node, wxS("tool"))) || (m_isInside && IsOfClass(node, wxS("tool"))) ||
(m_isInside && IsOfClass(node, wxS("label"))) ||
(m_isInside && IsOfClass(node, wxS("space"))) || (m_isInside && IsOfClass(node, wxS("space"))) ||
(m_isInside && IsOfClass(node, wxS("separator")))); (m_isInside && IsOfClass(node, wxS("separator"))));
} }