X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/25af884d93f0ec95640b0d07a2aab348a15d9ac2..b53aea81d2e102224b452ef5bf7aee1132f37c6f:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index abb467f5ca..97fe65f631 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -62,6 +62,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBarToolBase, wxObject) wxToolBarToolBase::~wxToolBarToolBase() { delete m_dropdownMenu; + if ( IsControl() ) + GetControl()->Destroy(); } @@ -175,7 +177,7 @@ wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, const wxString& longHelp, wxObject *clientData) { - wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, + wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertTool()") ); wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind, @@ -199,7 +201,7 @@ wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool) wxToolBarToolBase * wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) { - wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, + wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertTool()") ); if ( !tool || !DoInsertTool(pos, tool) ) @@ -208,6 +210,7 @@ wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) } m_tools.Insert(pos, tool); + tool->Attach(this); return tool; } @@ -223,13 +226,13 @@ wxToolBarBase::InsertControl(size_t pos, wxControl *control, const wxString& label) { - wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, + wxCHECK_MSG( control, NULL, _T("toolbar: can't insert NULL control") ); - wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL, + wxCHECK_MSG( control->GetParent() == this, NULL, _T("control must have toolbar as parent") ); - wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, + wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertControl()") ); wxToolBarToolBase *tool = CreateTool(control, label); @@ -277,13 +280,13 @@ wxToolBarToolBase *wxToolBarBase::AddSeparator() wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) { - wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, + wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertSeparator()") ); wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap, - wxITEM_SEPARATOR, (wxObject *)NULL, + wxITEM_SEPARATOR, NULL, wxEmptyString, wxEmptyString); if ( !tool || !DoInsertTool(pos, tool) ) @@ -314,17 +317,19 @@ wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) { // don't give any error messages - sometimes we might call RemoveTool() // without knowing whether the tool is or not in the toolbar - return (wxToolBarToolBase *)NULL; + return NULL; } wxToolBarToolBase *tool = node->GetData(); + wxCHECK_MSG( tool, NULL, "NULL tool in the tools list?" ); + if ( !DoDeleteTool(pos, tool) ) - { - return (wxToolBarToolBase *)NULL; - } + return NULL; m_tools.Erase(node); + tool->Detach(); + return tool; } @@ -371,7 +376,7 @@ bool wxToolBarBase::DeleteTool(int id) wxToolBarToolBase *wxToolBarBase::FindById(int id) const { - wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; + wxToolBarToolBase *tool = NULL; for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; @@ -522,7 +527,7 @@ wxObject *wxToolBarBase::GetToolClientData(int id) const { wxToolBarToolBase *tool = FindById(id); - return tool ? tool->GetClientData() : (wxObject *)NULL; + return tool ? tool->GetClientData() : NULL; } void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) @@ -620,7 +625,7 @@ bool wxToolBarBase::OnLeftClick(int id, bool toggleDown) event.SetExtraLong((long)toggleDown); // Send events to this toolbar instead (and thence up the window hierarchy) - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); return true; } @@ -692,7 +697,11 @@ void wxToolBarBase::UpdateWindowUI(long flags) node; node = node->GetNext() ) { - int id = node->GetData()->GetId(); + wxToolBarToolBase * const tool = node->GetData(); + if ( tool->IsSeparator() ) + continue; + + int id = tool->GetId(); wxUpdateUIEvent event(id); event.SetEventObject(this);