]> git.saurik.com Git - wxWidgets.git/commitdiff
don't remove the tools we hadn't added to the toolbar (replaces patch 1660201)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 21:59:56 +0000 (21:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 21:59:56 +0000 (21:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45313 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/toolbar.cpp

index 897527f997a00a947c1a252415ba6ae5a2355dc7..9d0bf0cb1de25253d4ba9724a7aae5be6345434c 100644 (file)
@@ -1103,6 +1103,8 @@ bool wxToolBar::Realize()
 #if wxMAC_USE_NATIVE_TOOLBAR
     CFIndex currentPosition = 0;
     bool insertAll = false;
+
+    HIToolbarRef refTB = (HIToolbarRef)m_macHIToolbarRef;
 #endif
 
     node = m_tools.GetFirst();
@@ -1142,9 +1144,9 @@ bool wxToolBar::Realize()
 
 #if wxMAC_USE_NATIVE_TOOLBAR
         // install in native HIToolbar
-        if ( m_macHIToolbarRef != NULL )
+        if ( refTB )
         {
-            HIToolbarItemRef    hiItemRef = tool->GetToolbarItemRef();
+            HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
             if ( hiItemRef != NULL )
             {
                 if ( insertAll || (tool->GetIndex() != currentPosition) )
@@ -1156,25 +1158,32 @@ bool wxToolBar::Realize()
 
                         // if this is the first tool that gets newly inserted or repositioned
                         // first remove all 'old' tools from here to the right, because of this
-                        // all following tools will have to be reinserted (insertAll). i = 100 because there's
-                        // no way to determine how many there are in a toolbar, so just a high number :-(
-                        for ( CFIndex i = 100; i >= currentPosition; --i )
-                        {
-                            err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, i );
-                        }
-
-                        if (err != noErr)
+                        // all following tools will have to be reinserted (insertAll).
+                        for ( wxToolBarToolsList::compatibility_iterator node2 = m_tools.GetLast();
+                              node2 != node;
+                              node2 = node2->GetPrevious() )
                         {
-                            wxString errMsg = wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err );
-                            wxFAIL_MSG( errMsg.c_str() );
+                            wxToolBarTool *tool2 = (wxToolBarTool*) node2->GetData();
+
+                            const long idx = tool2->GetIndex();
+                            if ( idx != -1 )
+                            {
+                                err = HIToolbarRemoveItemAtIndex(refTB, idx);
+                                if ( err != noErr )
+                                {
+                                    wxLogDebug(wxT("HIToolbarRemoveItemAtIndex(%ld) failed [%ld]"),
+                                               idx, (long)err);
+                                }
+
+                                tool2->SetIndex(-1);
+                            }
                         }
                     }
 
-                    err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef, currentPosition );
+                    err = HIToolbarInsertItemAtIndex( refTB, hiItemRef, currentPosition );
                     if (err != noErr)
                     {
-                        wxString errMsg = wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err );
-                        wxFAIL_MSG( errMsg.c_str() );
+                        wxLogDebug( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err );
                     }
 
                     tool->SetIndex( currentPosition );