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
This commit is contained in:
Kevin Ollivier
2009-12-25 20:43:43 +00:00
parent 849754a451
commit 1665389a9a
4 changed files with 43 additions and 32 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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