]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/tbarbase.cpp
warnings fixes
[wxWidgets.git] / src / common / tbarbase.cpp
index 14b0bd80e299853b88f45baf92a68886d3e04e0a..e53657dea2607a3569a0dbb3a24abd5cd4bb9f21 100644 (file)
@@ -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,18 +213,42 @@ 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();
+          node;
+          node = node->GetNext() )
+    {
+        const wxToolBarToolBase * const tool = node->GetData();
+        if ( tool->IsControl() )
+        {
+            wxControl * const control = tool->GetControl();
+
+            if ( !control )
+            {
+                wxFAIL_MSG( _T("NULL control in toolbar?") );
+            }
+            else if ( control->GetId() == id )
+            {
+                // found
+                return control;
+            }
+        }
+    }
+
+   return NULL;
+}
+
 wxToolBarToolBase *wxToolBarBase::AddSeparator()
 {
     return InsertSeparator(GetToolsCount());
@@ -415,6 +458,22 @@ void wxToolBarBase::SetToolClientData(int id, wxObject *clientData)
     tool->SetClientData(clientData);
 }
 
+int wxToolBarBase::GetToolPos(int id) const
+{
+    size_t pos = 0;
+    wxToolBarToolsList::Node *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);
@@ -524,7 +583,8 @@ void wxToolBarBase::OnMouseEnter(int id)
 
 void wxToolBarBase::OnIdle(wxIdleEvent& event)
 {
-    DoToolbarUpdates();
+    if (wxUpdateUIEvent::CanUpdate())
+        DoToolbarUpdates();
 
     event.Skip();
 }
@@ -532,17 +592,7 @@ void wxToolBarBase::OnIdle(wxIdleEvent& event)
 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
 void wxToolBarBase::DoToolbarUpdates()
 {
-    wxWindow* parent = this;
-    while (parent->GetParent())
-        parent = parent->GetParent();
-
-#ifdef __WXMSW__
-    wxWindow* focusWin = wxFindFocusDescendant(parent);
-#else
-    wxWindow* focusWin = (wxWindow*) NULL;
-#endif
-
-    wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ;
+    wxEvtHandler* evtHandler = GetEventHandler() ;
 
     for ( wxToolBarToolsList::Node* node = m_tools.GetFirst();
           node;