X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2daf63c4ebd3f1254baabdf21aa74ff5ea39d95a..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/cocoa/menuitem.mm diff --git a/src/osx/cocoa/menuitem.mm b/src/osx/cocoa/menuitem.mm index 8599af3a61..05179eca9e 100644 --- a/src/osx/cocoa/menuitem.mm +++ b/src/osx/cocoa/menuitem.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: menuitem.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -33,8 +33,11 @@ struct Mapping Mapping sActionToWXMapping[] = { +// as we don't have NSUndoManager support we must not use the native actions +#if 0 { wxID_UNDO, @selector(undo:) }, { wxID_REDO, @selector(redo:) }, +#endif { wxID_CUT, @selector(cut:) }, { wxID_COPY, @selector(copy:) }, { wxID_PASTE, @selector(paste:) }, @@ -74,8 +77,8 @@ SEL wxOSXGetSelectorFromID(int menuId ) - (id) initWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)charCode { - [super initWithTitle:aString action:aSelector keyEquivalent:charCode]; - return self; + self = [super initWithTitle:aString action:aSelector keyEquivalent:charCode]; + return self; } - (void) clickedAction: (id) sender @@ -100,8 +103,12 @@ SEL wxOSXGetSelectorFromID(int menuId ) wxUnusedVar(menuItem); if( impl ) { - if ( impl->GetWXPeer()->GetMenu()->HandleCommandUpdateStatus(impl->GetWXPeer()) ) - return impl->GetWXPeer()->IsEnabled(); + wxMenuItem* wxmenuitem = impl->GetWXPeer(); + if ( wxmenuitem ) + { + wxmenuitem->GetMenu()->HandleCommandUpdateStatus(wxmenuitem); + return wxmenuitem->IsEnabled(); + } } return YES ; } @@ -120,6 +127,12 @@ SEL wxOSXGetSelectorFromID(int menuId ) void wxMacCocoaMenuItemSetAccelerator( NSMenuItem* menuItem, wxAcceleratorEntry* entry ) { + if ( entry == NULL ) + { + [menuItem setKeyEquivalent:@""]; + return; + } + unsigned int modifiers = 0 ; int key = entry->GetKeyCode() ; if ( key ) @@ -127,6 +140,9 @@ void wxMacCocoaMenuItemSetAccelerator( NSMenuItem* menuItem, wxAcceleratorEntry* if (entry->GetFlags() & wxACCEL_CTRL) modifiers |= NSCommandKeyMask; + if (entry->GetFlags() & wxACCEL_RAW_CTRL) + modifiers |= NSControlKeyMask; + if (entry->GetFlags() & wxACCEL_ALT) modifiers |= NSAlternateKeyMask ; @@ -145,71 +161,59 @@ void wxMacCocoaMenuItemSetAccelerator( NSMenuItem* menuItem, wxAcceleratorEntry* { switch ( key ) { -/* - // standard function keys from here - case WXK_TAB : - modifiers |= NSFunctionKeyMask ; - shortcut = NSTabCharacter ; - break ; - - case kEnterCharCode : - modifiers |= NSFunctionKeyMask ; - cocoaKey = NSTabCharacter ; - break ; - - case WXK_RETURN : - modifiers |= NSFunctionKeyMask ; - cocoaKey = NSTabCharacter ; - break ; - - case WXK_ESCAPE : - modifiers |= NSFunctionKeyMask ; - cocoaKey = kEscapeCharCode ; - break ; - - case WXK_SPACE : - shortcut = ' ' ; - break ; - - case WXK_CLEAR : - cocoaKey = kClearCharCode ; + modifiers |= NSFunctionKeyMask; + shortcut = NSDeleteCharacter ; break ; case WXK_PAGEUP : - cocoaKey = kPageUpCharCode ; + modifiers |= NSFunctionKeyMask; + shortcut = NSPageUpFunctionKey ; break ; case WXK_PAGEDOWN : - cocoaKey = kPageDownCharCode ; + modifiers |= NSFunctionKeyMask; + shortcut = NSPageDownFunctionKey ; break ; case WXK_LEFT : - cocoaKey = kLeftArrowCharCode ; + modifiers |= NSNumericPadKeyMask | NSFunctionKeyMask; + shortcut = NSLeftArrowFunctionKey ; break ; case WXK_UP : - cocoaKey = kUpArrowCharCode ; + modifiers |= NSNumericPadKeyMask | NSFunctionKeyMask; + shortcut = NSUpArrowFunctionKey ; break ; case WXK_RIGHT : - cocoaKey = kRightArrowCharCode ; + modifiers |= NSNumericPadKeyMask | NSFunctionKeyMask; + shortcut = NSRightArrowFunctionKey ; break ; case WXK_DOWN : - cocoaKey = kDownArrowCharCode ; + modifiers |= NSNumericPadKeyMask | NSFunctionKeyMask; + shortcut = NSDownArrowFunctionKey ; break ; case WXK_HOME : - cocoaKey = kHomeCharCode ; + modifiers |= NSFunctionKeyMask; + shortcut = NSHomeFunctionKey ; break ; case WXK_END : - cocoaKey = kEndCharCode ; + modifiers |= NSFunctionKeyMask; + shortcut = NSEndFunctionKey ; break ; -*/ - // TODO Test all above with their function key equiv. - // from NSEvent.h + + case WXK_NUMPAD_ENTER : + shortcut = NSEnterCharacter; + break; + + case WXK_BACK : + case WXK_RETURN : + case WXK_TAB : + case WXK_ESCAPE : default : if(entry->GetFlags() & wxACCEL_SHIFT) shortcut = toupper(key); @@ -224,6 +228,10 @@ void wxMacCocoaMenuItemSetAccelerator( NSMenuItem* menuItem, wxAcceleratorEntry* } } +@interface NSMenuItem(PossibleMethods) +- (void)setHidden:(BOOL)hidden; +@end + class wxMenuItemCocoaImpl : public wxMenuItemImpl { public : @@ -264,9 +272,7 @@ public : wxCFStringRef cfText(text); [m_osxMenuItem setTitle:cfText.AsNSString()]; - if ( entry ) - wxMacCocoaMenuItemSetAccelerator( m_osxMenuItem, entry ); - + wxMacCocoaMenuItemSetAccelerator( m_osxMenuItem, entry ); } bool DoDefault(); @@ -305,6 +311,10 @@ bool wxMenuItemCocoaImpl::DoDefault() [theNSApplication unhideAllApplications:nil]; handled=true; } + else if (menuid == wxApp::s_macExitMenuItemId) + { + wxTheApp->ExitMainLoop(); + } return handled; } @@ -328,7 +338,7 @@ wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, wxMenu *pParentMenu, wxCFStringRef cfText(text); SEL selector = nil; bool targetSelf = false; - if ( ! pParentMenu->GetNoEventsMode() && pSubMenu == NULL ) + if ( (pParentMenu == NULL || !pParentMenu->GetNoEventsMode()) && pSubMenu == NULL ) { selector = wxOSXGetSelectorFromID(menuid); @@ -350,8 +360,7 @@ wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, wxMenu *pParentMenu, } else { - if ( entry ) - wxMacCocoaMenuItemSetAccelerator( menuitem, entry ); + wxMacCocoaMenuItemSetAccelerator( menuitem, entry ); } item = menuitem; }