From 58862dfa1ae7c8882331c00260025aac1a5e2a45 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 7 Apr 2007 21:59:56 +0000 Subject: [PATCH 1/1] don't remove the tools we hadn't added to the toolbar (replaces patch 1660201) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45313 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/toolbar.cpp | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 897527f997..9d0bf0cb1d 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -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 ); -- 2.45.2