Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemCocoa.mm
| Context not available. | |||||
| #include "GHOST_NDOFManagerCocoa.h" | #include "GHOST_NDOFManagerCocoa.h" | ||||
| #endif | #endif | ||||
| #include "GHOST_UtilsCocoa.h" | |||||
| #include "AssertMacros.h" | #include "AssertMacros.h" | ||||
| #import <Cocoa/Cocoa.h> | #import <Cocoa/Cocoa.h> | ||||
| Context not available. | |||||
| GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const | GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const | ||||
| { | { | ||||
| //Note that OS X supports monitor hot plug | // Note that OS X supports monitor hot plug | ||||
| // We do not support multiple monitors at the moment | |||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| GHOST_TUns8 count = [[NSScreen screens] count]; | GHOST_TUns8 count = [[NSScreen screens] count]; | ||||
| Context not available. | |||||
| return count; | return count; | ||||
| } | } | ||||
| void GHOST_SystemCocoa::getDisplayDimensions( | |||||
| void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const | GHOST_TUns8 num, | ||||
| GHOST_TUns32& x, GHOST_TUns32& y, | |||||
| GHOST_TUns32& width, GHOST_TUns32& height) const | |||||
| { | { | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| //Get visible frame, that is frame excluding dock and top menu bar | |||||
| NSRect frame = [[NSScreen mainScreen] visibleFrame]; | |||||
| //Returns max window contents (excluding title bar...) | NSArray *screens = [NSScreen screens]; | ||||
| NSRect contentRect = [NSWindow contentRectForFrameRect:frame | GHOST_ASSERT(num < [screens count], | ||||
| styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)]; | "GHOST_SystemCocoa::getDisplayDimensions(): invalid display num\n"); | ||||
| NSScreen *screen = [screens objectAtIndex:num]; | |||||
| NSRect rect = screen.visibleFrame; | |||||
| width = rect.size.width; | |||||
| height = rect.size.height; | |||||
| x = rect.origin.x; | |||||
| y = rect.origin.y; | |||||
| [pool drain]; | |||||
| } | |||||
| void GHOST_SystemCocoa::getMainDisplayDimensions( | |||||
| GHOST_TUns32& x, GHOST_TUns32& y, | |||||
| GHOST_TUns32& width, GHOST_TUns32& height) const | |||||
| { | |||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |||||
| NSScreen *mainScreen = [GHOST_UtilsCocoa mainScreen]; | |||||
| NSRect contentRect = mainScreen.visibleFrame; | |||||
| width = contentRect.size.width; | width = contentRect.size.width; | ||||
| height = contentRect.size.height; | height = contentRect.size.height; | ||||
| x = contentRect.origin.x; | |||||
| y = contentRect.origin.y; | |||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| void GHOST_SystemCocoa::getAllDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const | void GHOST_SystemCocoa::getAllDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const | ||||
| { | { | ||||
| /* TODO! */ | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| getMainDisplayDimensions(width, height); | NSRect bounds = NSZeroRect; | ||||
| // get the bounding rectangle of all screens | |||||
| for (NSScreen *screen in [NSScreen screens]) { | |||||
| NSRect contentRect = screen.visibleFrame; | |||||
| bounds = NSUnionRect(bounds, contentRect); | |||||
| } | |||||
| width = bounds.size.width; | |||||
| height = bounds.size.height; | |||||
| [pool drain]; | |||||
| } | } | ||||
| GHOST_IWindow* GHOST_SystemCocoa::createWindow( | GHOST_IWindow* GHOST_SystemCocoa::createWindow( | ||||
| Context not available. | |||||
| ) | ) | ||||
| { | { | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| GHOST_IWindow* window = NULL; | GHOST_IWindow *window = NULL; | ||||
| GHOST_TInt32 bottom = top + height; | |||||
| //Get the available rect for including window contents | //NSLog(@"cocoa: origin:(%d,%d) size:(%d,%d)\n", left, bottom, width, height); | ||||
| NSRect frame = [[NSScreen mainScreen] visibleFrame]; | window = new GHOST_WindowCocoa(this, title, left, bottom, width, height, state, type, | ||||
| NSRect contentRect = [NSWindow contentRectForFrameRect:frame | glSettings.flags & GHOST_glStereoVisual, glSettings.numOfAASamples, | ||||
| styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)]; | glSettings.flags & GHOST_glDebugContext); | ||||
| GHOST_TInt32 bottom = (contentRect.size.height - 1) - height - top; | |||||
| //Ensures window top left is inside this available rect | |||||
| left = left > contentRect.origin.x ? left : contentRect.origin.x; | |||||
| // Add contentRect.origin.y to respect docksize | |||||
| bottom = bottom > contentRect.origin.y ? bottom + contentRect.origin.y : contentRect.origin.y; | |||||
| window = new GHOST_WindowCocoa(this, title, left, bottom, width, height, state, type, glSettings.flags & GHOST_glStereoVisual, glSettings.numOfAASamples, glSettings.flags & GHOST_glDebugContext); | |||||
| if (window->getValid()) { | if (window->getValid()) { | ||||
| // Store the pointer to the window | // Store the pointer to the window | ||||
| GHOST_ASSERT(m_windowManager, "m_windowManager not initialized"); | GHOST_ASSERT(m_windowManager, "m_windowManager not initialized"); | ||||
| m_windowManager->addWindow(window); | m_windowManager->addWindow(window); | ||||
| m_windowManager->setActiveWindow(window); | m_windowManager->setActiveWindow(window); | ||||
| //Need to tell window manager the new window is the active one (Cocoa does not send the event activate upon window creation) | // Need to tell window manager the new window is the active one | ||||
| // (Cocoa does not send the event activate upon window creation) | |||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow(); | GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow(); | ||||
| //Discard quit event if we are in cursor grab sequence | // Discard quit event if we are in cursor grab sequence | ||||
| 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()) | ||||
| { | { | ||||
| int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved.\nDo you really want to quit?", | int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved.\nDo you really want to quit?", | ||||
| Context not available. | |||||