X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df7998fce5569c46a0f14456966adcef6521efc9..2ddb4d13585d5235556119fb1937273da9e433a3:/src/mac/carbon/toolbar.cpp diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 33d8c6aaad..b7c55f0812 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -9,10 +9,6 @@ // Licence: The wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "toolbar.h" -#endif - #include "wx/wxprec.h" #if wxUSE_TOOLBAR @@ -597,8 +593,9 @@ bool wxToolBar::Show( bool show ) MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); if (ownToolbarInstalled) { - bResult = (HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ) != show); - ShowHideWindowToolbar( tlw, show, false ); + bResult = ( IsWindowToolbarVisible(tlw) != show); + if ( bResult ) + ShowHideWindowToolbar( tlw, show, false ); } else #endif @@ -616,7 +613,10 @@ bool wxToolBar::IsShown() const bool ownToolbarInstalled ; MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); if (ownToolbarInstalled) - bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ); + { + WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); + bResult = IsWindowToolbarVisible(tlw) ; + } else #endif bResult = wxToolBarBase::IsShown(); @@ -645,6 +645,13 @@ void wxToolBar::DoGetSize( int *width, int *height ) const wxToolBarBase::DoGetSize( width, height ); } +wxSize wxToolBar::DoGetBestSize() const +{ + int width , height ; + DoGetSize( &width , &height ) ; + return wxSize( width , height ) ; +} + void wxToolBar::SetWindowStyleFlag( long style ) { wxToolBarBase::SetWindowStyleFlag( style ); @@ -776,20 +783,6 @@ bool wxToolBar::Realize() if (m_tools.GetCount() == 0) return false; -#if wxMAC_USE_NATIVE_TOOLBAR - // remove all tools, no way to determine how many there are in a toolbar, so just a high number :-( - OSStatus err = noErr ; - if ( m_macHIToolbarRef != NULL ) - { - for ( CFIndex i = 0 ; i < 100 ; ++i ) - { - err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef , i ) ; - } - } - - wxASSERT_MSG( err == noErr, _T("HIToolbarRemoveItemAtIndex failed") ); -#endif // wxMAC_USE_NATIVE_TOOLBAR - int x = m_xMargin + kwxMacToolBarLeftMargin; int y = m_yMargin + kwxMacToolBarTopMargin; @@ -829,6 +822,7 @@ bool wxToolBar::Realize() #if wxMAC_USE_NATIVE_TOOLBAR CFIndex currentPosition = 0 ; + bool insertAll = false ; #endif // wxMAC_USE_NATIVE_TOOLBAR while ( node != NULL ) @@ -873,14 +867,27 @@ bool wxToolBar::Realize() HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef(); if ( hiItemRef != NULL ) { - OSStatus result = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef , currentPosition ) ; - if ( result == 0 ) + if ( tool->GetIndex() != currentPosition || insertAll == true ) { + OSStatus err = noErr ; + if ( !insertAll ) + { + // 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 ) ; + } + wxASSERT_MSG( err == noErr, _T("HIToolbarRemoveItemAtIndex failed") ); + insertAll = true ; + } + err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef , currentPosition ) ; + wxASSERT_MSG( err == noErr, _T("HIToolbarInsertItemAtIndex failed") ); tool->SetIndex( currentPosition ) ; - currentPosition++ ; - InstallEventHandler( HIObjectGetEventTarget(hiItemRef), GetwxMacToolBarEventHandlerUPP(), - GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL ); } + currentPosition++ ; } } #endif // wxMAC_USE_NATIVE_TOOLBAR @@ -1133,6 +1140,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item ); if (err == noErr) { + InstallEventHandler( HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(), + GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL ); HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) ); HIToolbarItemSetIconRef( item, info.u.iconRef ); HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );