From be136f073819d425818049008ca286ff39c4cb10 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 9 Feb 2009 17:59:37 +0000 Subject: [PATCH] make sure no delegates/impl ptrs are still set during destruction git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58815 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/menu.mm | 20 +++++++++++--------- src/osx/cocoa/menuitem.mm | 8 ++++---- src/osx/cocoa/nonownedwnd.mm | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 705fdc8947..628f38ecfb 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -39,6 +39,7 @@ - (id) init { [super init]; + impl = NULL; return self; } @@ -123,8 +124,15 @@ class wxMenuCocoaImpl : public wxMenuImpl { public : - wxMenuCocoaImpl( wxMenu* peer , NSMenu* menu) : wxMenuImpl(peer), m_osxMenu(menu) + wxMenuCocoaImpl( wxMenu* peer , wxNSMenu* menu) : wxMenuImpl(peer), m_osxMenu(menu) { + static wxNSMenuController* controller = NULL; + if ( controller == NULL ) + { + controller = [[wxNSMenuController alloc] init]; + } + [menu setDelegate:controller]; + [m_osxMenu setImplementation:this]; } virtual ~wxMenuCocoaImpl(); @@ -181,26 +189,20 @@ public : static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); static wxMenuImpl* CreateRootMenu( wxMenu* peer ); protected : - NSMenu* m_osxMenu; + wxNSMenu* m_osxMenu; } ; wxMenuCocoaImpl::~wxMenuCocoaImpl() { [m_osxMenu setDelegate:nil]; + [m_osxMenu setImplementation:nil]; [m_osxMenu release]; } wxMenuImpl* wxMenuImpl::Create( wxMenu* peer, const wxString& title ) { - static wxNSMenuController* controller = NULL; - if ( controller == NULL ) - { - controller = [[wxNSMenuController alloc] init]; - } wxCFStringRef cfText( title ); wxNSMenu* menu = [[wxNSMenu alloc] initWithTitle:cfText.AsNSString()]; wxMenuImpl* c = new wxMenuCocoaImpl( peer, menu ); - [menu setDelegate:controller]; - [menu setImplementation:c]; return c; } diff --git a/src/osx/cocoa/menuitem.mm b/src/osx/cocoa/menuitem.mm index 6b05d359fb..8a81661f54 100644 --- a/src/osx/cocoa/menuitem.mm +++ b/src/osx/cocoa/menuitem.mm @@ -170,6 +170,8 @@ class wxMenuItemCocoaImpl : public wxMenuItemImpl public : wxMenuItemCocoaImpl( wxMenuItem* peer, NSMenuItem* item ) : wxMenuItemImpl(peer), m_osxMenuItem(item) { + if ( ![m_osxMenuItem isSeparatorItem] ) + [(wxNSMenuItem*)m_osxMenuItem setImplementation:this]; } ~wxMenuItemCocoaImpl(); @@ -212,6 +214,8 @@ protected : wxMenuItemCocoaImpl::~wxMenuItemCocoaImpl() { + if ( ![m_osxMenuItem isSeparatorItem] ) + [(wxNSMenuItem*)m_osxMenuItem setImplementation:nil]; } @@ -253,9 +257,5 @@ wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, wxMenu *pParentMenu, item = temp; } c = new wxMenuItemCocoaImpl( peer, item ); - if ( kind != wxITEM_SEPARATOR ) - { - [(wxNSMenuItem*)item setImplementation:c]; - } return c; } diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index ac233c8e19..e2ce53b5a6 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -227,6 +227,7 @@ wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl() wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() { + [m_macWindow setImplementation:nil]; [m_macWindow setDelegate:nil]; [m_macWindow release]; } -- 2.45.2