+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( m_macHIToolbarRef )
+ {
+ // if this is the installed toolbar, then deinstall it
+ if (m_macUsesNativeToolbar)
+ MacInstallNativeToolbar( false );
+
+ CFRelease( (HIToolbarRef) m_macHIToolbarRef );
+ m_macHIToolbarRef = NULL;
+ }
+#endif
+}
+
+bool wxToolBar::Show( bool show )
+{
+ bool bResult, ownToolbarInstalled = false;
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+
+ bResult = (tlw != NULL);
+ if (bResult)
+ {
+#if wxMAC_USE_NATIVE_TOOLBAR
+ MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
+ if (ownToolbarInstalled)
+ {
+ bResult = (HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ) != show);
+ ShowHideWindowToolbar( tlw, show, false );
+ }
+ else
+#endif
+ bResult = wxToolBarBase::Show( show );
+ }
+
+ return bResult;
+}
+
+bool wxToolBar::IsShown() const
+{
+ bool bResult;
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ bool ownToolbarInstalled ;
+ MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
+ if (ownToolbarInstalled)
+ bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef );
+ else
+#endif
+ bResult = wxToolBarBase::IsShown();
+
+ return bResult;
+}
+
+void wxToolBar::DoGetSize( int *width, int *height ) const
+{
+#if wxMAC_USE_NATIVE_TOOLBAR
+ Rect boundsR;
+ bool ownToolbarInstalled;
+
+ MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
+ if ( ownToolbarInstalled )
+ {
+ // TODO is this really a control ?
+ GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR );
+ if ( width != NULL )
+ *width = boundsR.right - boundsR.left;
+ if ( height != NULL )
+ *height = boundsR.bottom - boundsR.top;
+ }
+ else
+#endif
+ wxToolBarBase::DoGetSize( width, height );
+}
+
+void wxToolBar::SetWindowStyleFlag( long style )
+{
+ wxToolBarBase::SetWindowStyleFlag( style );
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if (m_macHIToolbarRef != NULL)
+ {
+ HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
+
+ if ( style & wxTB_NOICONS )
+ mode = kHIToolbarDisplayModeLabelOnly;
+ else if ( style & wxTB_TEXT )
+ mode = kHIToolbarDisplayModeIconAndLabel;
+ else
+ mode = kHIToolbarDisplayModeIconOnly;
+
+ HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
+ }
+#endif
+}
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+bool wxToolBar::MacWantsNativeToolbar()
+{
+ return m_macUsesNativeToolbar;
+}
+
+bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const
+{
+ bool bResultV = false;
+
+ if (ownToolbarInstalled != NULL)
+ *ownToolbarInstalled = false;
+
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ if (tlw != NULL)
+ {
+ HIToolbarRef curToolbarRef = NULL;
+ OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
+ bResultV = ((err == 0) && (curToolbarRef != NULL));
+ if (bResultV && (ownToolbarInstalled != NULL))
+ *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
+ }
+
+ return bResultV;
+}
+
+bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
+{
+ bool bResult = false;
+
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ if (tlw == NULL)
+ return bResult;
+
+ if (usesNative && (m_macHIToolbarRef == NULL))
+ return bResult;
+
+ if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
+ return bResult;
+
+ // check the existing toolbar
+ HIToolbarRef curToolbarRef = NULL;
+ OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
+ if (err != 0)
+ curToolbarRef = NULL;
+
+ m_macUsesNativeToolbar = usesNative;
+
+ if (m_macUsesNativeToolbar)
+ {
+ // only install toolbar if there isn't one installed already
+ if (curToolbarRef == NULL)
+ {
+ bResult = true;
+
+ SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef );
+ ShowHideWindowToolbar( tlw, true, false );
+ ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
+ SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
+
+ // FIXME: which is best, which is necessary?
+ //
+ // m_peer->SetVisibility( false, true );
+ //
+ //
+ Rect r = { 0 , 0 , 0 , 0 };
+ //
+ //
+ m_peer->SetRect( &r );
+ //
+ // FIXME: which is best, which is necessary?
+ //
+ SetSize( wxSIZE_AUTO_WIDTH, 0 );
+ //
+ m_peer->SetVisibility( false, true );
+ wxToolBarBase::Show( false );
+ }
+ }
+ else
+ {
+ // only deinstall toolbar if this is the installed one
+ if (m_macHIToolbarRef == curToolbarRef)
+ {
+ bResult = true;
+
+ ShowHideWindowToolbar( tlw, false, false );
+ ChangeWindowAttributes( tlw, 0 , kWindowToolbarButtonAttribute );
+ SetWindowToolbar( tlw, NULL );
+
+ // FIXME: which is best, which is necessary?
+ m_peer->SetVisibility( true, true );
+
+ //
+ // wxToolBarBase::Show( true );
+ //
+ }
+ }
+
+ if (bResult)
+ InvalidateBestSize();
+
+// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
+ return bResult;