From 1665389a9ab7359c164069a31f231f121e4afd8e Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Fri, 25 Dec 2009 20:43:43 +0000 Subject: [PATCH] Remove the native toolbar from the frame in Destroy() rather than the destructor, as removing it in the destructor causes resize / repaint events to fire on the native control, which then goes to wx controls being deleted. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62988 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/toolbar.h | 3 +++ src/osx/carbon/toolbar.cpp | 35 ++++++++++++++++++----------------- src/osx/cocoa/toolbar.mm | 29 +++++++++++++++-------------- src/osx/toolbar_osx.cpp | 8 +++++++- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/include/wx/osx/toolbar.h b/include/wx/osx/toolbar.h index 46d94b5edc..df388af6eb 100644 --- a/include/wx/osx/toolbar.h +++ b/include/wx/osx/toolbar.h @@ -44,6 +44,8 @@ class WXDLLIMPEXP_CORE wxToolBar: public wxToolBarBase 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; @@ -73,6 +75,7 @@ class WXDLLIMPEXP_CORE wxToolBar: public wxToolBarBase #if wxOSX_USE_NATIVE_TOOLBAR bool MacInstallNativeToolbar(bool usesNative); + void MacUninstallNativeToolbar(); bool MacWantsNativeToolbar(); bool MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const; #endif diff --git a/src/osx/carbon/toolbar.cpp b/src/osx/carbon/toolbar.cpp index 9f969bea5c..58cc4af000 100644 --- a/src/osx/carbon/toolbar.cpp +++ b/src/osx/carbon/toolbar.cpp @@ -926,26 +926,17 @@ bool wxToolBar::Create( 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 ) @@ -1135,7 +1126,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) ShowHideWindowToolbar( tlw, false, false ); ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute ); - SetWindowToolbar( tlw, NULL ); + MacUninstallNativeToolbar(); m_peer->SetVisibility( true ); } @@ -1147,6 +1138,16 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) // 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() diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index b6362a6e53..b0d451a171 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -631,19 +631,10 @@ bool wxToolBar::Create( } 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 ) @@ -824,7 +815,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bResult = true; [(NSToolbar*) m_macToolbar setVisible:NO]; - [tlw setToolbar:nil]; + MacUninstallNativeToolbar(); m_peer->SetVisibility( true ); } } @@ -835,6 +826,16 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) // 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() diff --git a/src/osx/toolbar_osx.cpp b/src/osx/toolbar_osx.cpp index 310eb916b5..bc613ada68 100644 --- a/src/osx/toolbar_osx.cpp +++ b/src/osx/toolbar_osx.cpp @@ -26,6 +26,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) -// no common implementation +bool wxToolBar::Destroy() +{ +#if wxOSX_USE_NATIVE_TOOLBAR + MacUninstallNativeToolbar(); +#endif + return wxToolBarBase::Destroy(); +} #endif // wxUSE_TOOLBAR -- 2.47.2