// Licence: The wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "toolbar.h"
-#endif
-
#include "wx/wxprec.h"
#if wxUSE_TOOLBAR
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
bool ownToolbarInstalled ;
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
- bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef );
+ {
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ bResult = IsWindowToolbarVisible(tlw) ;
+ }
else
#endif
bResult = wxToolBarBase::IsShown();
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 );
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;
#if wxMAC_USE_NATIVE_TOOLBAR
CFIndex currentPosition = 0 ;
+ bool insertAll = false ;
#endif // wxMAC_USE_NATIVE_TOOLBAR
while ( node != NULL )
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
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 );