wxToolBar::~wxToolBar()
{
#if wxOSX_USE_NATIVE_TOOLBAR
- if (m_macToolbar != NULL)
- {
- // if this is the installed toolbar, then deinstall it
- if (m_macUsesNativeToolbar)
- MacInstallNativeToolbar( false );
+ // We could be not using a native tool bar at all, this happens when we're
+ // created with something other than the frame as parent for example.
+ if ( !m_macToolbar )
+ return;
- CFIndex count = CFGetRetainCount( m_macToolbar ) ;
- // Leopard seems to have one refcount more, so we cannot check reliably at the moment
- if ( UMAGetSystemVersion() < 0x1050 )
+ CFIndex count = CFGetRetainCount( m_macToolbar ) ;
+ // Leopard seems to have one refcount more, so we cannot check reliably at the moment
+ if ( UMAGetSystemVersion() < 0x1050 )
+ {
+ if ( count != 1 )
{
- if ( count != 1 )
- {
- wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
- }
+ wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
}
- CFRelease( (HIToolbarRef)m_macToolbar );
- m_macToolbar = NULL;
}
-#endif
+ CFRelease( (HIToolbarRef)m_macToolbar );
+ m_macToolbar = NULL;
+#endif // wxOSX_USE_NATIVE_TOOLBAR
}
bool wxToolBar::Show( bool show )
ShowHideWindowToolbar( tlw, false, false );
ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute );
- SetWindowToolbar( tlw, NULL );
+ MacUninstallNativeToolbar();
m_peer->SetVisibility( true );
}
// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
return bResult;
}
+
+void wxToolBar::MacUninstallNativeToolbar()
+{
+ if (!m_macToolbar)
+ return;
+
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ if (tlw)
+ SetWindowToolbar( tlw, NULL );
+}
#endif
bool wxToolBar::Realize()
wxFAIL_MSG("Reference count of native tool was illegal before removal");
}
wxASSERT( IsValidControlHandle(tool->GetControl()->GetPeer()->GetControlRef() )) ;
+
+ wxString label = tool->GetLabel();
+ if ( !label.empty() )
+ HIToolbarItemSetLabel( hiItemRef, wxCFStringRef(label, GetFont().GetEncoding()) );
}
}
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_macToolbar != NULL)
{
- wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") );
+ wxCHECK_MSG( tool->GetControl(), false, wxT("control must be non-NULL") );
HIToolbarItemRef item;
HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;