From db73ca4c92f9fec9bf8ef5ce9595e7bf12695c2e Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Mon, 27 Aug 2012 12:11:47 -0700 Subject: [PATCH] Use 64-bit: stop using Carbon As we are no longer using Carbon functions to set menu key equivalents, this means that bundle menu items which have the same key equivalents as main menu items will unfortunately not display their key equivalents in the menu. --- Frameworks/OakAppKit/src/NSEvent Additions.h | 1 - Frameworks/OakAppKit/src/NSEvent Additions.mm | 10 +-- .../OakAppKit/src/NSMenuItem Additions.mm | 89 +------------------ 3 files changed, 3 insertions(+), 97 deletions(-) diff --git a/Frameworks/OakAppKit/src/NSEvent Additions.h b/Frameworks/OakAppKit/src/NSEvent Additions.h index 448b012e..6d45dddc 100644 --- a/Frameworks/OakAppKit/src/NSEvent Additions.h +++ b/Frameworks/OakAppKit/src/NSEvent Additions.h @@ -1,5 +1,4 @@ @interface NSEvent (SnowLeopardCompatibilityWrappers) -+ (NSTimeInterval)slDoubleClickInterval; + (NSTimeInterval)caretBlinkInterval; + (NSUInteger)slPressedMouseButtons; + (NSUInteger)slModifierFlags; diff --git a/Frameworks/OakAppKit/src/NSEvent Additions.mm b/Frameworks/OakAppKit/src/NSEvent Additions.mm index 5e09c169..f0d4a98d 100644 --- a/Frameworks/OakAppKit/src/NSEvent Additions.mm +++ b/Frameworks/OakAppKit/src/NSEvent Additions.mm @@ -3,7 +3,6 @@ #if !defined(MAC_OS_X_VERSION_10_6) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6) @interface NSEvent (SnowLeopard) -+ (NSTimeInterval)doubleClickInterval; + (NSUInteger)pressedMouseButtons; + (NSUInteger)modifierFlags; @end @@ -18,16 +17,9 @@ static struct conversion_t { UInt32 oldValue; NSUInteger newValue; } const Conve }; @implementation NSEvent (SnowLeopardCompatibilityWrappers) -+ (NSTimeInterval)slDoubleClickInterval -{ - if(![self respondsToSelector:@selector(doubleClickInterval)]) - return GetDblTime() / 60.0; - return [self doubleClickInterval]; -} - + (NSTimeInterval)caretBlinkInterval { - return GetCaretTime() / 60.0; // There is no modern replacement for this one + return [([[NSUserDefaults standardUserDefaults] objectForKey:@"NSTextInsertionPointBlinkPeriod"] ?: @567) doubleValue] / 1000.0; } + (NSUInteger)slPressedMouseButtons diff --git a/Frameworks/OakAppKit/src/NSMenuItem Additions.mm b/Frameworks/OakAppKit/src/NSMenuItem Additions.mm index 8a277bad..0e896bc7 100644 --- a/Frameworks/OakAppKit/src/NSMenuItem Additions.mm +++ b/Frameworks/OakAppKit/src/NSMenuItem Additions.mm @@ -5,84 +5,6 @@ #import #import -extern "C" MenuRef _NSGetCarbonMenu (NSMenu* aMenu); - -static void set_legacy_key_equivalent (MenuRef aMenu, UInt16 anIndex, std::string keyStr, NSUInteger nsModifiers) -{ - std::string const uppercaseKeyStr = text::uppercase(keyStr); - if(keyStr != text::lowercase(keyStr)) - nsModifiers |= NSShiftKeyMask; - if(keyStr != uppercaseKeyStr) - keyStr = uppercaseKeyStr; - - UInt8 modifiers = kMenuNoCommandModifier; - if(nsModifiers & NSShiftKeyMask) modifiers |= kMenuShiftModifier; - if(nsModifiers & NSControlKeyMask) modifiers |= kMenuControlModifier; - if(nsModifiers & NSAlternateKeyMask) modifiers |= kMenuOptionModifier; - if(nsModifiers & NSCommandKeyMask) modifiers &= ~kMenuNoCommandModifier; - - uint32_t keyCode = utf8::to_ch(keyStr); - if(keyCode == NSDeleteFunctionKey) - { - SetMenuItemKeyGlyph(aMenu, anIndex, kMenuDeleteRightGlyph); - } - else if(keyCode == NSDeleteCharacter) - { - SetMenuItemKeyGlyph(aMenu, anIndex, kMenuDeleteLeftGlyph); - } - else - { - uint16_t code = 0; - if(nsModifiers & NSNumericPadKeyMask) - { - switch(keyCode) - { - case '0': code = 82; break; - case '1': code = 83; break; - case '2': code = 84; break; - case '3': code = 85; break; - case '4': code = 86; break; - case '5': code = 87; break; - case '6': code = 88; break; - case '7': code = 89; break; - case '8': code = 91; break; - case '9': code = 92; break; - case '=': code = 81; break; - case '/': code = 75; break; - case '*': code = 67; break; - case '+': code = 69; break; - case '-': code = 78; break; - case ',': code = 65; break; - case '.': code = 65; break; - case NSEnterCharacter: code = 76; break; // could also use kMenuEnterGlyph - } - } - - if(code) - { - SetMenuItemCommandKey(aMenu, anIndex, true, code); - } - else - { - if(keyCode > 0x7F) - { - NSString* key = [NSString stringWithCxxString:keyStr]; - if([key canBeConvertedToEncoding:NSMacOSRomanStringEncoding]) - { - if(NSData* data = [key dataUsingEncoding:NSMacOSRomanStringEncoding]) - { - if([data length] == 1) - keyCode = *(char const*)[data bytes]; - } - } - } - - SetMenuItemCommandKey(aMenu, anIndex, false, keyCode); - } - } - SetMenuItemModifiers(aMenu, anIndex, modifiers); -} - @interface MenuMutableAttributedString : NSMutableAttributedString { NSMutableAttributedString* contents; @@ -231,15 +153,8 @@ static void set_legacy_key_equivalent (MenuRef aMenu, UInt16 anIndex, std::strin } } - if(MenuRef menu = _NSGetCarbonMenu([self menu])) - { - set_legacy_key_equivalent(menu, [[self menu] indexOfItem:self] + 1, aKeyEquivalent.substr(i), modifiers); - } - else - { - [self setKeyEquivalent:[NSString stringWithCxxString:aKeyEquivalent.substr(i)]]; - [self setKeyEquivalentModifierMask:modifiers]; - } + [self setKeyEquivalent:[NSString stringWithCxxString:aKeyEquivalent.substr(i)]]; + [self setKeyEquivalentModifierMask:modifiers]; } - (void)setTabTriggerCxxString:(std::string const&)aTabTrigger