X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d3734d65e66f0b8c7a7aafcbdba922e0f0516d62..f1e269209afbcbec4e46ab5df4ba43d902a6bf2f:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index 5f4b02fa90..1438c9f3c6 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -5,8 +5,8 @@ // Modified by: VZ at 11.12.99 (wxScrollableToolBar splitted off) // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "tbarbase.h" #endif @@ -38,16 +38,13 @@ #include "wx/image.h" #include "wx/settings.h" -#include "wx/tbarbase.h" +#include "wx/toolbar.h" // ---------------------------------------------------------------------------- // wxWindows macros // ---------------------------------------------------------------------------- -IMPLEMENT_CLASS(wxToolBarBase, wxControl) - BEGIN_EVENT_TABLE(wxToolBarBase, wxControl) - EVT_IDLE(wxToolBarBase::OnIdle) END_EVENT_TABLE() #include "wx/listimpl.cpp" @@ -126,8 +123,6 @@ wxToolBarToolBase::~wxToolBarToolBase() wxToolBarBase::wxToolBarBase() { // the list owns the pointers - m_tools.DeleteContents(TRUE); - m_xMargin = m_yMargin = 0; m_maxRows = m_maxCols = 0; @@ -164,13 +159,32 @@ wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind, clientData, shortHelp, longHelp); - if ( !tool || !DoInsertTool(pos, tool) ) + if ( !InsertTool(pos, tool) ) { delete tool; return NULL; } + return tool; +} + +wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool) +{ + return InsertTool(GetToolsCount(), tool); +} + +wxToolBarToolBase * +wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) +{ + wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, + _T("invalid position in wxToolBar::InsertTool()") ); + + if ( !tool || !DoInsertTool(pos, tool) ) + { + return NULL; + } + m_tools.Insert(pos, tool); return tool; @@ -194,30 +208,36 @@ wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) wxToolBarToolBase *tool = CreateTool(control); - if ( !tool || !DoInsertTool(pos, tool) ) + if ( !InsertTool(pos, tool) ) { delete tool; return NULL; } - m_tools.Insert(pos, tool); - return tool; } wxControl *wxToolBarBase::FindControl( int id ) { - for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { - wxControl *control = node->GetData()->GetControl(); - - if (control) + const wxToolBarToolBase * const tool = node->GetData(); + if ( tool->IsControl() ) { - if (control->GetId() == id) + wxControl * const control = tool->GetControl(); + + if ( !control ) + { + wxFAIL_MSG( _T("NULL control in toolbar?") ); + } + else if ( control->GetId() == id ) + { + // found return control; + } } } @@ -255,7 +275,7 @@ wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) { size_t pos = 0; - wxToolBarToolsList::Node *node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { if ( node->GetData()->GetId() == id ) @@ -277,10 +297,7 @@ wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) return (wxToolBarToolBase *)NULL; } - // the node would delete the data, so set it to NULL to avoid this - node->SetData(NULL); - - m_tools.DeleteNode(node); + m_tools.Erase(node); return tool; } @@ -290,14 +307,15 @@ bool wxToolBarBase::DeleteToolByPos(size_t pos) wxCHECK_MSG( pos < GetToolsCount(), FALSE, _T("invalid position in wxToolBar::DeleteToolByPos()") ); - wxToolBarToolsList::Node *node = m_tools.Item(pos); + wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos); if ( !DoDeleteTool(pos, node->GetData()) ) { return FALSE; } - m_tools.DeleteNode(node); + delete node->GetData(); + m_tools.Erase(node); return TRUE; } @@ -305,7 +323,7 @@ bool wxToolBarBase::DeleteToolByPos(size_t pos) bool wxToolBarBase::DeleteTool(int id) { size_t pos = 0; - wxToolBarToolsList::Node *node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { if ( node->GetData()->GetId() == id ) @@ -319,7 +337,8 @@ bool wxToolBarBase::DeleteTool(int id) return FALSE; } - m_tools.DeleteNode(node); + delete node->GetData(); + m_tools.Erase(node); return TRUE; } @@ -328,7 +347,7 @@ wxToolBarToolBase *wxToolBarBase::FindById(int id) const { wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -347,7 +366,7 @@ wxToolBarToolBase *wxToolBarBase::FindById(int id) const void wxToolBarBase::ClearTools() { - m_tools.Clear(); + WX_CLEAR_LIST(wxToolBarToolsList, m_tools); } bool wxToolBarBase::Realize() @@ -357,6 +376,7 @@ bool wxToolBarBase::Realize() wxToolBarBase::~wxToolBarBase() { + WX_CLEAR_LIST(wxToolBarToolsList, m_tools); } // ---------------------------------------------------------------------------- @@ -433,6 +453,22 @@ void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) tool->SetClientData(clientData); } +int wxToolBarBase::GetToolPos(int id) const +{ + size_t pos = 0; + wxToolBarToolsList::compatibility_iterator node; + + for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) + { + if ( node->GetData()->GetId() == id ) + return pos; + + pos++; + } + + return wxNOT_FOUND; +} + bool wxToolBarBase::GetToolState(int id) const { wxToolBarToolBase *tool = FindById(id); @@ -540,33 +576,14 @@ void wxToolBarBase::OnMouseEnter(int id) // UI updates // ---------------------------------------------------------------------------- -void wxToolBarBase::OnIdle(wxIdleEvent& event) -{ - DoToolbarUpdates(); - - event.Skip(); -} - // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) -void wxToolBarBase::DoToolbarUpdates() +void wxToolBarBase::UpdateWindowUI(long flags) { - wxWindow* parent = this; - while (parent->GetParent()) - parent = parent->GetParent(); - -// This kind of #ifdef is a good way to annoy people. It breaks -// apps, but only on one platform and due to a hack in officially -// platform independent code. It took me hours to fix this. RR. -// -// #ifdef __WXMSW__ -// wxWindow* focusWin = wxFindFocusDescendant(parent); -// #else - wxWindow* focusWin = (wxWindow*) NULL; -// #endif + wxWindowBase::UpdateWindowUI(flags); - wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ; + wxEvtHandler* evtHandler = GetEventHandler() ; - for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) {