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, 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 125 Lines • ▼ Show 20 Lines | default: | ||||
| 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), rawCode, keyAction, 0, | UCKeyTranslate((UCKeyboardLayout*)CFDataGetBytePtr(uchrHandle), rawCode, keyAction, 0, | ||||
| LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 1, &actualStrLength, &recvChar); | LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 1, &actualStrLength, &recvChar); | ||||
| } | } | ||||
| switch (recvChar) { | switch (recvChar) { | ||||
| case '-': return GHOST_kKeyMinus; | case '-': return GHOST_kKeyMinus; | ||||
| case '+': return GHOST_kKeyPlus; | case '+': return GHOST_kKeyPlus; | ||||
| case '=': return GHOST_kKeyEqual; | case '=': return GHOST_kKeyEqual; | ||||
| ▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | #endif | ||||
| if ([NSApp delegate] == nil) { | if ([NSApp delegate] == nil) { | ||||
| CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init]; | CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init]; | ||||
| [appDelegate setSystemCocoa:this]; | [appDelegate setSystemCocoa:this]; | ||||
| [NSApp setDelegate:appDelegate]; | [NSApp setDelegate:appDelegate]; | ||||
| } | } | ||||
| [NSApp finishLaunching]; | [NSApp finishLaunching]; | ||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| return success; | return success; | ||||
| } | } | ||||
| #pragma mark window management | #pragma mark window management | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| void GHOST_SystemCocoa::getAllDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const | void GHOST_SystemCocoa::getAllDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const | ||||
| { | { | ||||
| /* TODO! */ | /* TODO! */ | ||||
| getMainDisplayDimensions(width, height); | getMainDisplayDimensions(width, height); | ||||
| } | } | ||||
| GHOST_IWindow* GHOST_SystemCocoa::createWindow( | GHOST_IWindow* GHOST_SystemCocoa::createWindow( | ||||
| const STR_String& title, | const STR_String& title, | ||||
| GHOST_TInt32 left, | GHOST_TInt32 left, | ||||
| GHOST_TInt32 top, | GHOST_TInt32 top, | ||||
| GHOST_TUns32 width, | GHOST_TUns32 width, | ||||
| GHOST_TUns32 height, | GHOST_TUns32 height, | ||||
| GHOST_TWindowState state, | GHOST_TWindowState state, | ||||
| GHOST_TDrawingContextType type, | GHOST_TDrawingContextType type, | ||||
| GHOST_GLSettings glSettings, | GHOST_GLSettings glSettings, | ||||
| const bool exclusive, | const bool exclusive, | ||||
| ▲ Show 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | case GHOST_kEventDraggingDropDone: | ||||
| strArray->strings = (GHOST_TUns8**) malloc(strArray->count*sizeof(GHOST_TUns8*)); | strArray->strings = (GHOST_TUns8**) malloc(strArray->count*sizeof(GHOST_TUns8*)); | ||||
| for (i=0;i<strArray->count;i++) | for (i=0;i<strArray->count;i++) | ||||
| { | { | ||||
| droppedStr = [droppedArray objectAtIndex:i]; | droppedStr = [droppedArray objectAtIndex:i]; | ||||
| pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | ||||
| temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | ||||
| if (!temp_buff) { | if (!temp_buff) { | ||||
| strArray->count = i; | strArray->count = i; | ||||
| break; | break; | ||||
| } | } | ||||
| strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | ||||
| temp_buff[pastedTextSize] = '\0'; | temp_buff[pastedTextSize] = '\0'; | ||||
| strArray->strings[i] = temp_buff; | strArray->strings[i] = temp_buff; | ||||
| } | } | ||||
| eventData = (GHOST_TEventDataPtr) strArray; | eventData = (GHOST_TEventDataPtr) strArray; | ||||
| break; | break; | ||||
| case GHOST_kDragnDropTypeString: | case GHOST_kDragnDropTypeString: | ||||
| droppedStr = (NSString*)data; | droppedStr = (NSString*)data; | ||||
| pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | ||||
| temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | ||||
| if (temp_buff == NULL) { | if (temp_buff == NULL) { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | ||||
| temp_buff[pastedTextSize] = '\0'; | temp_buff[pastedTextSize] = '\0'; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | case GHOST_kEventDraggingDropDone: | ||||
| [bitmapImage setSize:imgSize]; | [bitmapImage setSize:imgSize]; | ||||
| /* Convert the image in a RGBA 32bit format */ | /* Convert the image in a RGBA 32bit format */ | ||||
| /* As Core Graphics does not support contextes with non premutliplied alpha, | /* As Core Graphics does not support contextes with non premutliplied alpha, | ||||
| we need to get alpha key values in a separate batch */ | we need to get alpha key values in a separate batch */ | ||||
| /* First get RGB values w/o Alpha to avoid pre-multiplication, 32bit but last byte is unused */ | /* First get RGB values w/o Alpha to avoid pre-multiplication, 32bit but last byte is unused */ | ||||
| blBitmapFormatImageRGB = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL | blBitmapFormatImageRGB = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL | ||||
| pixelsWide:imgSize.width | pixelsWide:imgSize.width | ||||
| pixelsHigh:imgSize.height | pixelsHigh:imgSize.height | ||||
| bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO | bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO | ||||
| colorSpaceName:NSDeviceRGBColorSpace | colorSpaceName:NSDeviceRGBColorSpace | ||||
| bitmapFormat:(NSBitmapFormat)0 | bitmapFormat:(NSBitmapFormat)0 | ||||
| bytesPerRow:4*imgSize.width | bytesPerRow:4*imgSize.width | ||||
| bitsPerPixel:32/*RGB format padded to 32bits*/]; | bitsPerPixel:32/*RGB format padded to 32bits*/]; | ||||
| [NSGraphicsContext saveGraphicsState]; | [NSGraphicsContext saveGraphicsState]; | ||||
| [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGB]]; | [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGB]]; | ||||
| [bitmapImage draw]; | [bitmapImage draw]; | ||||
| [NSGraphicsContext restoreGraphicsState]; | [NSGraphicsContext restoreGraphicsState]; | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr) | ||||
| int confirmOpen = NSAlertAlternateReturn; | int confirmOpen = NSAlertAlternateReturn; | ||||
| NSArray *windowsList; | NSArray *windowsList; | ||||
| char * temp_buff; | char * temp_buff; | ||||
| size_t filenameTextSize; | size_t filenameTextSize; | ||||
| GHOST_Window* window= (GHOST_Window*)m_windowManager->getActiveWindow(); | GHOST_Window* window= (GHOST_Window*)m_windowManager->getActiveWindow(); | ||||
| if (!window) { | if (!window) { | ||||
| return NO; | return NO; | ||||
| } | } | ||||
| //Discard event if we are in cursor grab sequence, it'll lead to "stuck cursor" situation if the alert panel is raised | //Discard event if we are in cursor grab sequence, it'll lead to "stuck cursor" situation if the alert panel is raised | ||||
| if (window && window->getCursorGrabModeIsWarp()) | if (window && window->getCursorGrabModeIsWarp()) | ||||
| return GHOST_kExitCancel; | return GHOST_kExitCancel; | ||||
| //Check open windows if some changes are not saved | //Check open windows if some changes are not saved | ||||
| if (m_windowManager->getAnyModifiedState()) | if (m_windowManager->getAnyModifiedState()) | ||||
| { | { | ||||
| confirmOpen = NSRunAlertPanel([NSString stringWithFormat:@"Opening %@",[filepath lastPathComponent]], | confirmOpen = NSRunAlertPanel([NSString stringWithFormat:@"Opening %@",[filepath lastPathComponent]], | ||||
| @"Current document has not been saved.\nDo you really want to proceed?", | @"Current document has not been saved.\nDo you really want to proceed?", | ||||
| @"Cancel", @"Open", nil); | @"Cancel", @"Open", nil); | ||||
| } | } | ||||
| //Give back focus to the blender window | //Give back focus to the blender window | ||||
| windowsList = [NSApp orderedWindows]; | windowsList = [NSApp orderedWindows]; | ||||
| if ([windowsList count]) { | if ([windowsList count]) { | ||||
| [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; | [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; | ||||
| } | } | ||||
| if (confirmOpen == NSAlertAlternateReturn) | if (confirmOpen == NSAlertAlternateReturn) | ||||
| { | { | ||||
| filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | ||||
| temp_buff = (char*) malloc(filenameTextSize+1); | temp_buff = (char*) malloc(filenameTextSize+1); | ||||
| if (temp_buff == NULL) { | if (temp_buff == NULL) { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| strncpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize); | strncpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize); | ||||
| temp_buff[filenameTextSize] = '\0'; | temp_buff[filenameTextSize] = '\0'; | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | case NSTabletProximity: | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| // pointer is leaving - return to mouse | // pointer is leaving - return to mouse | ||||
| ct.Active = GHOST_kTabletModeNone; | ct.Active = GHOST_kTabletModeNone; | ||||
| } | } | ||||
| break; | break; | ||||
| default: | default: | ||||
| GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received"); | GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received"); | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| break; | break; | ||||
| } | } | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | case NSOtherMouseUp: | ||||
| break; | break; | ||||
| case NSLeftMouseDragged: | case NSLeftMouseDragged: | ||||
| case NSRightMouseDragged: | case NSRightMouseDragged: | ||||
| case NSOtherMouseDragged: | case NSOtherMouseDragged: | ||||
| //Handle tablet events combined with mouse events | //Handle tablet events combined with mouse events | ||||
| handleTabletEvent(event); | handleTabletEvent(event); | ||||
| case NSMouseMoved: | case NSMouseMoved: | ||||
| { | { | ||||
| GHOST_TGrabCursorMode grab_mode = window->getCursorGrabMode(); | GHOST_TGrabCursorMode grab_mode = window->getCursorGrabMode(); | ||||
| /* TODO: CHECK IF THIS IS A TABLET EVENT */ | /* TODO: CHECK IF THIS IS A TABLET EVENT */ | ||||
| bool is_tablet = false; | bool is_tablet = false; | ||||
| if (is_tablet && window->getCursorGrabModeIsWarp()) { | if (is_tablet && window->getCursorGrabModeIsWarp()) { | ||||
| grab_mode = GHOST_kGrabDisable; | grab_mode = GHOST_kGrabDisable; | ||||
| ▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | case NSKeyUp: | ||||
| } | } | ||||
| else { | else { | ||||
| pushEvent(new GHOST_EventKey([event timestamp] * 1000, GHOST_kEventKeyUp, window, keyCode, 0, NULL)); | pushEvent(new GHOST_EventKey([event timestamp] * 1000, GHOST_kEventKeyUp, window, keyCode, 0, NULL)); | ||||
| //printf("Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u ascii=%i %c utf8=%s\n",[event keyCode],[charsIgnoringModifiers length]>0?[charsIgnoringModifiers characterAtIndex:0]:' ',keyCode,ascii,ascii, utf8_buf); | //printf("Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u ascii=%i %c utf8=%s\n",[event keyCode],[charsIgnoringModifiers length]>0?[charsIgnoringModifiers characterAtIndex:0]:' ',keyCode,ascii,ascii, utf8_buf); | ||||
| } | } | ||||
| m_ignoreMomentumScroll = true; | m_ignoreMomentumScroll = true; | ||||
| break; | break; | ||||
| case NSFlagsChanged: | case NSFlagsChanged: | ||||
| modifiers = [event modifierFlags]; | modifiers = [event modifierFlags]; | ||||
| if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) { | if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) { | ||||
| pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSShiftKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift)); | pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSShiftKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift)); | ||||
| } | } | ||||
| if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) { | if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) { | ||||
| pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSControlKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl)); | pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSControlKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl)); | ||||
| } | } | ||||
| if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) { | if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) { | ||||
| pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSAlternateKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt)); | pushEvent(new GHOST_EventKey([event timestamp] * 1000, (modifiers & NSAlternateKeyMask) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt)); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const | ||||
| if (textPasted == nil) { | if (textPasted == nil) { | ||||
| [pool drain]; | [pool drain]; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; | ||||
| temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); | ||||
| if (temp_buff == NULL) { | if (temp_buff == NULL) { | ||||
| [pool drain]; | [pool drain]; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||