diff --git a/docs/changes.txt b/docs/changes.txt index 973417ae5b..04bce2249d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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). diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index 324ecb909d..042b2f08bb 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -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: bar.png + + view.png + + + + + + + + + + + + diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc index ba6a5288e7..d6b92a1d42 100644 --- a/samples/xrc/rc/controls.xrc +++ b/samples/xrc/rc/controls.xrc @@ -81,6 +81,25 @@ 2,2 + + + + + + + + + + + + + + + + + + + 1 @@ -128,6 +147,24 @@ #bbbbff 2,2 + + + + + + + + + + + + + + + + + + 1 diff --git a/src/xrc/xh_toolb.cpp b/src/xrc/xh_toolb.cpp index c1bda2419f..0fa523baa0 100644 --- a/src/xrc/xh_toolb.cpp +++ b/src/xrc/xh_toolb.cpp @@ -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(), - GetText(wxT("label")), - GetBitmap(wxT("bitmap"), wxART_TOOLBAR), - GetBitmap(wxT("bitmap2"), wxART_TOOLBAR), - kind, - GetText(wxT("tooltip")), - GetText(wxT("longhelp"))); + + // 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")) + ); if ( GetBool(wxT("disabled")) ) m_toolbar->EnableTool(GetID(), false); + if ( menu ) + tool->SetDropdownMenu(menu); + return m_toolbar; // must return non-NULL }