X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fba2d5e6943c1687509cbcfe2e684a88b5878638..642067e02a202feddc97255f1229e4e7378541d9:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index d99e214263..82cc3bd9a3 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 ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -164,13 +164,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,15 +213,13 @@ 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; } @@ -212,12 +229,20 @@ wxControl *wxToolBarBase::FindControl( int id ) 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; + } } } @@ -554,11 +579,15 @@ void wxToolBarBase::DoToolbarUpdates() while (parent->GetParent()) parent = parent->GetParent(); -#ifdef __WXMSW__ - wxWindow* focusWin = wxFindFocusDescendant(parent); -#else +// 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 +// #endif wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ;