add support for creating drop down toolbar buttons from XRC

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57073 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-12-02 18:11:54 +00:00
parent cffff062b3
commit e2517f176b
4 changed files with 101 additions and 8 deletions

View File

@ -345,6 +345,7 @@ All (GUI):
- Added wxWindow::AlwaysShowScrollbars() (Julian Scheid).
- Added wxMouseEvent::GetClickCount() (Julian Scheid).
- Added wxBG_STYLE_TRANSPARENT background style (Julian Scheid).
- Added support for drop-down toolbar buttons to XRC.
- Added XRCSIZERITEM() macro for obtaining sizers from XRC (Brian Vanderburg II).
- New and improved wxFileCtrl (Diaa Sami and Marcin Wojdyr).
- Added wxEventBlocker class (Francesco Montorsi).

View File

@ -1441,6 +1441,8 @@ properties:
Item's kind is wxITEM_RADIO (default: 0)?}
@row3col{toggle, @ref overview_xrcformat_type_bool,
Item's kind is wxITEM_CHECK (default: 0)?}
@row3col{dropdown, see below,
Item's kind is wxITEM_DROPDOWN (default: 0)? (@since 2.9.0)}
@row3col{tooltip, @ref overview_xrcformat_type_text,
Tooltip to use for the tool (default: none).}
@row3col{longhelp, @ref overview_xrcformat_type_text,
@ -1449,7 +1451,11 @@ properties:
Is the tool initially disabled (default: 0)?}
@endTable
@c radio and @c toggle are mutually exclusive.
The presence of a @c dropdown property indicates that the tool is of type
wxITEM_DROPDOWN. It must be either empty or contain exactly one wxMenu @ref
xrc_wxmenu child object defining the drop-down button associated menu.
Notice that @c radio, @c toggle and @c dropdown are mutually exclusive.
Children that are neither @c tool nor @c separator must be instances of classes
derived from wxControl and are added to the toolbar using
@ -1467,6 +1473,20 @@ Example:
<bitmap>bar.png</bitmap>
<label>Bar</label>
</object>
<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="separator"/>
<object class="wxComboBox">
<content>

View File

@ -81,6 +81,25 @@
<object class="wxToolBar">
<style>wxTB_FLAT|wxTB_NODIVIDER</style>
<margins>2,2</margins>
<object class="tool" name="New">
<bitmap stock_id="wxART_NEW"/>
<label>New</label>
</object>
<object class="tool" name="view_auto">
<bitmap stock_id="wxART_FILE_OPEN"/>
<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="separator"/>
<object class="tool" name="home">
<toggle>1</toggle>
<bitmap stock_id="wxART_GO_HOME"/>
@ -128,6 +147,24 @@
<style>wxTB_FLAT|wxTB_NODIVIDER</style>
<bg>#bbbbff</bg>
<margins>2,2</margins>
<object class="tool" name="New">
<bitmap stock_id="wxART_NEW"/>
<label>New</label>
</object>
<object class="tool" name="view_auto">
<bitmap stock_id="wxART_FILE_OPEN"/>
<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="tool" name="home">
<toggle>1</toggle>
<bitmap stock_id="wxART_GO_HOME"/>

View File

@ -58,23 +58,58 @@ wxObject *wxToolBarXmlHandler::DoCreateResource()
wxItemKind kind = wxITEM_NORMAL;
if (GetBool(wxT("radio")))
kind = wxITEM_RADIO;
if (GetBool(wxT("toggle")))
{
wxASSERT_MSG( kind == wxITEM_NORMAL,
_T("can't have both toggle and radio button at once") );
kind = wxITEM_CHECK;
}
m_toolbar->AddTool(GetID(),
// check whether we have dropdown tag inside
wxMenu *menu = NULL; // menu for drop down items
wxXmlNode * const nodeDropdown = GetParamNode("dropdown");
if ( nodeDropdown )
{
wxASSERT_MSG( kind == wxITEM_NORMAL,
"drop down button can't be a check/radio "
"button too" );
kind = wxITEM_DROPDOWN;
// also check for the menu specified inside dropdown (it is
// optional and may be absent for e.g. dynamically-created
// menus)
wxXmlNode * const nodeMenu = nodeDropdown->GetChildren();
if ( nodeMenu )
{
wxObject *res = CreateResFromNode(nodeMenu, NULL);
menu = wxDynamicCast(res, wxMenu);
wxASSERT_MSG( menu, "invalid drop down object contents" );
wxASSERT_MSG( !nodeMenu->GetNext(),
"only single menu tag allowed inside dropdown" );
}
}
wxToolBarToolBase * const
tool = m_toolbar->AddTool
(
GetID(),
GetText(wxT("label")),
GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
kind,
GetText(wxT("tooltip")),
GetText(wxT("longhelp")));
GetText(wxT("longhelp"))
);
if ( GetBool(wxT("disabled")) )
m_toolbar->EnableTool(GetID(), false);
if ( menu )
tool->SetDropdownMenu(menu);
return m_toolbar; // must return non-NULL
}