X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2cb5d2d2b70566c40be5578fe3db29cb3c3a34ad..55410bb4f67febe1ca20654f078ea4fb9a6223ae:/src/osx/cocoa/menu.mm?ds=sidebyside diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 2222793676..628f38ecfb 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -34,23 +34,12 @@ // ---------------------- #include -@class wxNSMenuItem; - -@interface wxNSMenu : NSMenu -{ - wxMenuImpl* impl; -} - -- (void) setImplementation:(wxMenuImpl*) item; -- (wxMenuImpl*) implementation; - -@end - @implementation wxNSMenu - (id) init { [super init]; + impl = NULL; return self; } @@ -91,7 +80,8 @@ if ( menuimpl ) { wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer(); - wxpeer->HandleMenuOpened(); + if ( wxpeer ) + wxpeer->HandleMenuOpened(); } } @@ -102,7 +92,8 @@ if ( menuimpl ) { wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer(); - wxpeer->HandleMenuClosed(); + if ( wxpeer ) + wxpeer->HandleMenuClosed(); } } @@ -126,11 +117,22 @@ @end +@interface NSApplication(MissingAppleMenuCall) +- (void)setAppleMenu:(NSMenu *)menu; +@end + 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(); @@ -187,25 +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; }