From 3b2d75293333aef42afd2e7c77da855365f8b2cd Mon Sep 17 00:00:00 2001 From: Damien Plisson Date: Thu, 15 Oct 2009 08:27:31 +0000 Subject: Cocoa : - Small changes to make ghost_cocoa compatible with 10.4 + gcc4.0 (the initial goal was to be 10.5+ compatible, but 10.4 is finally also possible) - Main window title is now in Apple document window title style (proxy icon + filename) - fix for top menu "Blender" sub-menu not anchored correctly in 10.5 --- intern/ghost/intern/GHOST_SystemCocoa.mm | 5 ++-- intern/ghost/intern/GHOST_WindowCocoa.mm | 47 ++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 072b2dfee86..62f0c538e7e 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -635,6 +635,7 @@ GHOST_TSuccess GHOST_SystemCocoa::init() [mainMenubar addItem:menuItem]; [menuItem release]; + [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; //Needed for 10.5 [appMenu release]; //Create the window menu @@ -815,7 +816,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const { - NSUInteger modifiers = [[NSApp currentEvent] modifierFlags]; + unsigned int modifiers = [[NSApp currentEvent] modifierFlags]; //Direct query to modifierFlags can be used in 10.6 keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false); @@ -1175,7 +1176,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr) { NSEvent *event = (NSEvent *)eventPtr; GHOST_IWindow* window = m_windowManager->getActiveWindow(); - NSUInteger modifiers; + unsigned int modifiers; NSString *characters; GHOST_TKey keyCode; unsigned char ascii; diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 999ec0de9c1..f86fa49b31c 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -40,13 +40,13 @@ // Pixel Format Attributes for the windowed NSOpenGLContext -static const NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[] = +static NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated, - NSOpenGLPFAAllowOfflineRenderers, // NOTE: Needed to connect to secondary GPUs - NSOpenGLPFADepthSize, 32, - 0 + //NSOpenGLPFAAllowOfflineRenderers, // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway + NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) 32, + (NSOpenGLPixelFormatAttribute) 0 }; #pragma mark Cocoa window delegate object @@ -187,7 +187,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( return; } - [m_window setTitle:[NSString stringWithUTF8String:title]]; + setTitle(title); //Creates the OpenGL View inside the window @@ -271,7 +271,38 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title) NSString *windowTitle = [[NSString alloc] initWithUTF8String:title]; - [m_window setTitle:windowTitle]; + //Set associated file if applicable + if ([windowTitle hasPrefix:@"Blender"]) + { + NSRange fileStrRange; + NSString *associatedFileName; + int len; + + fileStrRange.location = [windowTitle rangeOfString:@"["].location+1; + len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location; + + if (len >0) + { + fileStrRange.length = len; + associatedFileName = [windowTitle substringWithRange:fileStrRange]; + @try { + [m_window setRepresentedFilename:associatedFileName]; + } + @catch (NSException * e) { + printf("\nInvalid file path given in window title"); + } + [m_window setTitle:[associatedFileName lastPathComponent]]; + } + else { + [m_window setTitle:windowTitle]; + [m_window setRepresentedFilename:@""]; + } + + } else { + [m_window setTitle:windowTitle]; + [m_window setRepresentedFilename:@""]; + } + [windowTitle release]; [pool drain]; @@ -501,7 +532,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) defer:YES]; //Copy current window parameters [tmpWindow setTitle:[m_window title]]; - [tmpWindow setRepresentedURL:[m_window representedURL]]; + [tmpWindow setRepresentedFilename:[m_window representedFilename]]; [tmpWindow setReleasedWhenClosed:NO]; [tmpWindow setAcceptsMouseMovedEvents:YES]; [tmpWindow setDelegate:[m_window delegate]]; @@ -557,7 +588,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state) defer:YES]; //Copy current window parameters [tmpWindow setTitle:[m_window title]]; - [tmpWindow setRepresentedURL:[m_window representedURL]]; + [tmpWindow setRepresentedFilename:[m_window representedFilename]]; [tmpWindow setReleasedWhenClosed:NO]; [tmpWindow setAcceptsMouseMovedEvents:YES]; [tmpWindow setDelegate:[m_window delegate]]; -- cgit v1.2.3