X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6d99eb3e379fc5cdb835f9a87f92b612ec58dd1c..b53aea81d2e102224b452ef5bf7aee1132f37c6f:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 1e427b825f..97fe65f631 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,14 @@ WX_DEFINE_LIST(wxToolBarToolsList) IMPLEMENT_DYNAMIC_CLASS(wxToolBarToolBase, wxObject) +wxToolBarToolBase::~wxToolBarToolBase() +{ + delete m_dropdownMenu; + if ( IsControl() ) + GetControl()->Destroy(); +} + + bool wxToolBarToolBase::Enable(bool enable) { if ( m_enabled == enable ) @@ -111,6 +120,14 @@ bool wxToolBarToolBase::SetLongHelp(const wxString& help) return true; } + +void wxToolBarToolBase::SetDropdownMenu(wxMenu* menu) +{ + delete m_dropdownMenu; + m_dropdownMenu = menu; +} + + // ---------------------------------------------------------------------------- // wxToolBarBase adding/deleting items // ---------------------------------------------------------------------------- @@ -160,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, @@ -184,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) ) @@ -193,6 +210,7 @@ wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) } m_tools.Insert(pos, tool); + tool->Attach(this); return tool; } @@ -208,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); @@ -262,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) ) @@ -299,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; } @@ -356,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; @@ -507,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) @@ -582,6 +602,12 @@ void wxToolBarBase::SetRows(int WXUNUSED(nRows)) // nothing } +bool wxToolBarBase::IsVertical() const +{ + return HasFlag(wxTB_LEFT | wxTB_RIGHT); +} + + // ---------------------------------------------------------------------------- // event processing // ---------------------------------------------------------------------------- @@ -599,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; } @@ -671,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); @@ -690,6 +720,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) @@ -699,7 +742,6 @@ bool wxCreateGreyedImage(const wxImage& in, wxImage& out) if ( out.Ok() ) return true; #endif // wxUSE_IMAGE - return false; }