Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemCocoa.mm
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Converts Mac rawkey codes (same for Cocoa & Carbon) | * Converts Mac rawkey codes (same for Cocoa & Carbon) | ||||
| * into GHOST key codes | * into GHOST key codes | ||||
| * \param rawCode The raw physical key code | * \param rawCode The raw physical key code | ||||
| * \param recvChar the character ignoring modifiers (except for shift) | * \param recvChar the character ignoring modifiers (except for shift) | ||||
| * \return Ghost key code | * \return Ghost key code | ||||
| */ | */ | ||||
| static GHOST_TKey convertKey(int rawCode, unichar recvChar, UInt16 keyAction) | static GHOST_TKey convertKey(int rawCode, int modifierFlags, unichar recvChar, UInt16 keyAction) | ||||
| { | { | ||||
| // printf("\nrecvchar %c 0x%x",recvChar,recvChar); | // printf("\nrecvchar %c 0x%x",recvChar,recvChar); | ||||
| switch (rawCode) { | switch (rawCode) { | ||||
| /*Physical keycodes not used due to map changes in int'l keyboards | /*Physical keycodes not used due to map changes in int'l keyboards | ||||
| case kVK_ANSI_A: return GHOST_kKeyA; | case kVK_ANSI_A: return GHOST_kKeyA; | ||||
| case kVK_ANSI_B: return GHOST_kKeyB; | case kVK_ANSI_B: return GHOST_kKeyB; | ||||
| case kVK_ANSI_C: return GHOST_kKeyC; | case kVK_ANSI_C: return GHOST_kKeyC; | ||||
| case kVK_ANSI_D: return GHOST_kKeyD; | case kVK_ANSI_D: return GHOST_kKeyD; | ||||
| ▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | switch (rawCode) { | ||||
| case kVK_ANSI_Grave: return GHOST_kKeyAccentGrave;*/ | case kVK_ANSI_Grave: return GHOST_kKeyAccentGrave;*/ | ||||
| case kVK_VolumeUp: | case kVK_VolumeUp: | ||||
| case kVK_VolumeDown: | case kVK_VolumeDown: | ||||
| case kVK_Mute: | case kVK_Mute: | ||||
| return GHOST_kKeyUnknown; | return GHOST_kKeyUnknown; | ||||
| default: { | default: { | ||||
| /* alphanumerical or punctuation key that is remappable in int'l keyboards */ | /* Leopard and Snow Leopard 64bit compatible API. */ | ||||
| if ((recvChar >= 'A') && (recvChar <= 'Z')) { | CFDataRef uchrHandle; /* The keyboard layout. */ | ||||
| return (GHOST_TKey)(recvChar - 'A' + GHOST_kKeyA); | |||||
| } | |||||
| else if ((recvChar >= 'a') && (recvChar <= 'z')) { | |||||
| return (GHOST_TKey)(recvChar - 'a' + GHOST_kKeyA); | |||||
| } | |||||
| else { | |||||
| /* Leopard and Snow Leopard 64bit compatible API*/ | |||||
| CFDataRef uchrHandle; /*the keyboard layout*/ | |||||
| TISInputSourceRef kbdTISHandle; | TISInputSourceRef kbdTISHandle; | ||||
| kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource(); | kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource(); | ||||
| uchrHandle = (CFDataRef)TISGetInputSourceProperty(kbdTISHandle, | uchrHandle = (CFDataRef)TISGetInputSourceProperty(kbdTISHandle, | ||||
| kTISPropertyUnicodeKeyLayoutData); | kTISPropertyUnicodeKeyLayoutData); | ||||
| CFRelease(kbdTISHandle); | CFRelease(kbdTISHandle); | ||||
| /*get actual character value of the "remappable" keys in int'l keyboards, | /* Get actual character value of the "remappable" keys in int'l keyboards, | ||||
| if keyboard layout is not correctly reported (e.g. some non Apple keyboards in Tiger), | * if keyboard layout is not correctly reported (e.g. some non Apple keyboards in Tiger), | ||||
| then fallback on using the received charactersIgnoringModifiers */ | * then fallback on using the received charactersIgnoringModifiers. */ | ||||
| if (uchrHandle) { | if (uchrHandle) { | ||||
| UInt32 deadKeyState = 0; | UInt32 deadKeyState = 0; | ||||
| UniCharCount actualStrLength = 0; | UniCharCount actualStrLength = 0; | ||||
| UCKeyTranslate((UCKeyboardLayout *)CFDataGetBytePtr(uchrHandle), | UCKeyTranslate((UCKeyboardLayout *)CFDataGetBytePtr(uchrHandle), | ||||
| rawCode, | rawCode, | ||||
| keyAction, | keyAction, | ||||
| 0, | (modifierFlags >> 8) & 0xFF, | ||||
| LMGetKbdType(), | LMGetKbdType(), | ||||
| kUCKeyTranslateNoDeadKeysBit, | kUCKeyTranslateNoDeadKeysBit, | ||||
| &deadKeyState, | &deadKeyState, | ||||
| 1, | 1, | ||||
| &actualStrLength, | &actualStrLength, | ||||
| &recvChar); | &recvChar); | ||||
| } | } | ||||
| /* alphanumerical or punctuation key that is remappable in int'l keyboards */ | |||||
| if ((recvChar >= 'A') && (recvChar <= 'Z')) { | |||||
| return (GHOST_TKey)(recvChar - 'A' + GHOST_kKeyA); | |||||
| } | |||||
| else if ((recvChar >= 'a') && (recvChar <= 'z')) { | |||||
| return (GHOST_TKey)(recvChar - 'a' + GHOST_kKeyA); | |||||
| } | |||||
| switch (recvChar) { | switch (recvChar) { | ||||
| case '-': | case '-': | ||||
| return GHOST_kKeyMinus; | return GHOST_kKeyMinus; | ||||
| case '+': | case '+': | ||||
| return GHOST_kKeyPlus; | return GHOST_kKeyPlus; | ||||
| case '=': | case '=': | ||||
| return GHOST_kKeyEqual; | return GHOST_kKeyEqual; | ||||
| case ',': | case ',': | ||||
| return GHOST_kKeyComma; | return GHOST_kKeyComma; | ||||
| case '.': | case '.': | ||||
| return GHOST_kKeyPeriod; | return GHOST_kKeyPeriod; | ||||
| case '/': | case '/': | ||||
| return GHOST_kKeySlash; | return GHOST_kKeySlash; | ||||
| case ';': | case ';': | ||||
| return GHOST_kKeySemicolon; | return GHOST_kKeySemicolon; | ||||
| case '\'': | case '\'': | ||||
| return GHOST_kKeyQuote; | return GHOST_kKeyQuote; | ||||
| case '\\': | case '\\': | ||||
| return GHOST_kKeyBackslash; | return GHOST_kKeyBackslash; | ||||
| case '[': | case '[': | ||||
| return GHOST_kKeyLeftBracket; | return GHOST_kKeyLeftBracket; | ||||
| case ']': | case ']': | ||||
| return GHOST_kKeyRightBracket; | return GHOST_kKeyRightBracket; | ||||
| case '`': | case '`': | ||||
| return GHOST_kKeyAccentGrave; | return GHOST_kKeyAccentGrave; | ||||
| default: | default: | ||||
| return GHOST_kKeyUnknown; | return GHOST_kKeyUnknown; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| return GHOST_kKeyUnknown; | return GHOST_kKeyUnknown; | ||||
| } | } | ||||
| #pragma mark Utility functions | #pragma mark Utility functions | ||||
| #define FIRSTFILEBUFLG 512 | #define FIRSTFILEBUFLG 512 | ||||
| static bool g_hasFirstFile = false; | static bool g_hasFirstFile = false; | ||||
| static char g_firstFileBuf[512]; | static char g_firstFileBuf[512]; | ||||
| ▲ Show 20 Lines • Show All 1,441 Lines • ▼ Show 20 Lines | GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr) | ||||
| switch ([event type]) { | switch ([event type]) { | ||||
| case NSEventTypeKeyDown: | case NSEventTypeKeyDown: | ||||
| case NSEventTypeKeyUp: | case NSEventTypeKeyUp: | ||||
| charsIgnoringModifiers = [event charactersIgnoringModifiers]; | charsIgnoringModifiers = [event charactersIgnoringModifiers]; | ||||
| if ([charsIgnoringModifiers length] > 0) { | if ([charsIgnoringModifiers length] > 0) { | ||||
| keyCode = convertKey([event keyCode], | keyCode = convertKey([event keyCode], | ||||
| [event modifierFlags], | |||||
| [charsIgnoringModifiers characterAtIndex:0], | [charsIgnoringModifiers characterAtIndex:0], | ||||
| [event type] == NSEventTypeKeyDown ? kUCKeyActionDown : | [event type] == NSEventTypeKeyDown ? kUCKeyActionDown : | ||||
| kUCKeyActionUp); | kUCKeyActionUp); | ||||
| } | } | ||||
| else { | else { | ||||
| keyCode = convertKey([event keyCode], | keyCode = convertKey([event keyCode], | ||||
| [event modifierFlags], | |||||
| 0, | 0, | ||||
| [event type] == NSEventTypeKeyDown ? kUCKeyActionDown : | [event type] == NSEventTypeKeyDown ? kUCKeyActionDown : | ||||
| kUCKeyActionUp); | kUCKeyActionUp); | ||||
| } | } | ||||
| /* handling both unicode or ascii */ | /* handling both unicode or ascii */ | ||||
| characters = [event characters]; | characters = [event characters]; | ||||
| if ([characters length] > 0) { | if ([characters length] > 0) { | ||||
| ▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines | |||||