X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..713129f9d34e3027d2be46b134d2f4c490ad145f:/src/osx/cocoa/menu.mm diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 3bac02bfad..34ea162c4d 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; } @@ -66,7 +55,10 @@ @end -@interface wxNSMenuController : NSObject +@interface wxNSMenuController : NSObject +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + +#endif { } @@ -91,7 +83,8 @@ if ( menuimpl ) { wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer(); - wxpeer->HandleMenuOpened(); + if ( wxpeer ) + wxpeer->HandleMenuOpened(); } } @@ -102,7 +95,8 @@ if ( menuimpl ) { wxMenu* wxpeer = (wxMenu*) menuimpl->GetWXPeer(); - wxpeer->HandleMenuClosed(); + if ( wxpeer ) + wxpeer->HandleMenuClosed(); } } @@ -126,68 +120,98 @@ @end -class wxMenuCocoaImpl : public wxMenuImpl +@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]; + // gc aware + if ( m_osxMenu ) + CFRetain(m_osxMenu); + [m_osxMenu release]; } - + virtual ~wxMenuCocoaImpl(); - - virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) + + virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) { if ( pos == (size_t) -1 ) [m_osxMenu addItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() ]; else [m_osxMenu insertItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() atIndex:pos]; } - - virtual void Remove( wxMenuItem *pItem ) + + virtual void Remove( wxMenuItem *pItem ) { [m_osxMenu removeItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem()]; } - + virtual void MakeRoot() { [NSApp setMainMenu:m_osxMenu]; [NSApp setAppleMenu:[[m_osxMenu itemAtIndex:0] submenu]]; } - virtual void Enable( bool enable ) + virtual void Enable( bool WXUNUSED(enable) ) { } - + virtual void SetTitle( const wxString& text ) { wxCFStringRef cfText(text); [m_osxMenu setTitle:cfText.AsNSString()]; } + virtual void PopUp( wxWindow *win, int x, int y ) + { + win->ScreenToClient( &x , &y ) ; + NSView *view = win->GetPeer()->GetWXWidget(); + NSRect frame = [view frame]; + frame.origin.x = x; + frame.origin.y = y; + frame.size.width = 1; + frame.size.height = 1; + NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]; + [popUpButtonCell setAutoenablesItems:NO]; + [popUpButtonCell setAltersStateOfSelectedItem:NO]; + [popUpButtonCell setMenu:m_osxMenu]; + [popUpButtonCell selectItem:nil]; + [popUpButtonCell performClickWithFrame:frame inView:view]; + [popUpButtonCell release]; + } + WXHMENU GetHMenu() { return m_osxMenu; } static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); static wxMenuImpl* CreateRootMenu( wxMenu* peer ); protected : - NSMenu* m_osxMenu; + wxNSMenu* m_osxMenu; } ; wxMenuCocoaImpl::~wxMenuCocoaImpl() { - [m_osxMenu release]; + [m_osxMenu setDelegate:nil]; + [m_osxMenu setImplementation:nil]; + // gc aware + if ( m_osxMenu ) + CFRelease(m_osxMenu); } 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; }