X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9ac4391323232924d62bcb0a1095949e3eeaca84..541ea80f0ec8a1250981bfaa3452f370e5c42c3b:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 50c80846d5..071dac26d3 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -35,6 +35,7 @@ #if WXWIN_COMPATIBILITY_2_8 #include "wx/image.h" #endif // WXWIN_COMPATIBILITY_2_8 + #include "wx/menu.h" #endif // ---------------------------------------------------------------------------- @@ -58,6 +59,12 @@ WX_DEFINE_LIST(wxToolBarToolsList) IMPLEMENT_DYNAMIC_CLASS(wxToolBarToolBase, wxObject) +wxToolBarToolBase::~wxToolBarToolBase() +{ + delete m_dropdownMenu; +} + + bool wxToolBarToolBase::Enable(bool enable) { if ( m_enabled == enable ) @@ -111,6 +118,13 @@ bool wxToolBarToolBase::SetLongHelp(const wxString& help) return true; } + +void wxToolBarToolBase::SetDropdownMenu(wxMenu* menu) +{ + delete m_dropdownMenu; + m_dropdownMenu = menu; +} + // ---------------------------------------------------------------------------- // wxToolBarBase adding/deleting items // ---------------------------------------------------------------------------- @@ -197,12 +211,16 @@ wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) return tool; } -wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) +wxToolBarToolBase * +wxToolBarBase::AddControl(wxControl *control, const wxString& label) { - return InsertControl(GetToolsCount(), control); + return InsertControl(GetToolsCount(), control, label); } -wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) +wxToolBarToolBase * +wxToolBarBase::InsertControl(size_t pos, + wxControl *control, + const wxString& label) { wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, _T("toolbar: can't insert NULL control") ); @@ -213,7 +231,7 @@ wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, _T("invalid position in wxToolBar::InsertControl()") ); - wxToolBarToolBase *tool = CreateTool(control); + wxToolBarToolBase *tool = CreateTool(control, label); if ( !InsertTool(pos, tool) ) { @@ -624,13 +642,19 @@ void wxToolBarBase::OnMouseEnter(int id) event.SetInt(id); wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if( frame ) + if ( frame ) { wxString help; - wxToolBarToolBase* tool = id == wxID_ANY ? (wxToolBarToolBase*)NULL : FindById(id); - if(tool) - help = tool->GetLongHelp(); - frame->DoGiveHelp( help, id != wxID_ANY ); + if ( id != wxID_ANY ) + { + const wxToolBarToolBase * const tool = FindById(id); + if ( tool ) + help = tool->GetLongHelp(); + } + + // call DoGiveHelp() even if help string is empty to avoid showing the + // help for the previously selected tool when another one is selected + frame->DoGiveHelp(help, id != wxID_ANY); } (void)GetEventHandler()->ProcessEvent(event); @@ -645,6 +669,10 @@ void wxToolBarBase::UpdateWindowUI(long flags) { wxWindowBase::UpdateWindowUI(flags); + // don't waste time updating state of tools in a hidden toolbar + if ( !IsShown() ) + return; + // There is no sense in updating the toolbar UI // if the parent window is about to get destroyed wxWindow *tlw = wxGetTopLevelParent( this ); @@ -676,6 +704,19 @@ void wxToolBarBase::UpdateWindowUI(long flags) } } +bool wxToolBarBase::SetDropdownMenu(int toolid, wxMenu* menu) +{ + wxToolBarToolBase * const tool = FindById(toolid); + wxCHECK_MSG( tool, false, _T("invalid tool id") ); + + wxCHECK_MSG( tool->GetKind() == wxITEM_DROPDOWN, false, + _T("menu can be only associated with drop down tools") ); + + tool->SetDropdownMenu(menu); + + return true; +} + #if WXWIN_COMPATIBILITY_2_8 bool wxCreateGreyedImage(const wxImage& in, wxImage& out) @@ -685,7 +726,6 @@ bool wxCreateGreyedImage(const wxImage& in, wxImage& out) if ( out.Ok() ) return true; #endif // wxUSE_IMAGE - return false; }