const wxString& name = wxToolBarNameStr);
virtual void SetWindowStyleFlag(long style);
+
+ virtual bool Destroy();
// override/implement base class virtuals
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
#if wxOSX_USE_NATIVE_TOOLBAR
bool MacInstallNativeToolbar(bool usesNative);
+ void MacUninstallNativeToolbar();
bool MacWantsNativeToolbar();
bool MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const;
#endif
wxToolBar::~wxToolBar()
{
-#if wxOSX_USE_NATIVE_TOOLBAR
- if (m_macToolbar != NULL)
+ CFIndex count = CFGetRetainCount( m_macToolbar ) ;
+ // Leopard seems to have one refcount more, so we cannot check reliably at the moment
+ if ( UMAGetSystemVersion() < 0x1050 )
{
- // if this is the installed toolbar, then deinstall it
- if (m_macUsesNativeToolbar)
- MacInstallNativeToolbar( false );
-
- 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;
}
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()
}
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 );
-
- [(NSToolbar*)m_macToolbar setDelegate:nil];
- [(NSToolbar*)m_macToolbar release];
- m_macToolbar = NULL;
- }
-#endif
+{
+ [(NSToolbar*)m_macToolbar setDelegate:nil];
+ [(NSToolbar*)m_macToolbar release];
+ m_macToolbar = NULL;
}
bool wxToolBar::Show( bool show )
{
bResult = true;
[(NSToolbar*) m_macToolbar setVisible:NO];
- [tlw setToolbar:nil];
+ 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;
+
+ WXWindow tlw = MacGetTopLevelWindowRef();
+ if (tlw)
+ [tlw setToolbar:nil];
+}
#endif
bool wxToolBar::Realize()
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
-// no common implementation
+bool wxToolBar::Destroy()
+{
+#if wxOSX_USE_NATIVE_TOOLBAR
+ MacUninstallNativeToolbar();
+#endif
+ return wxToolBarBase::Destroy();
+}
#endif // wxUSE_TOOLBAR