Cocoa :
authorDamien Plisson <damien.plisson@yahoo.fr>
Thu, 15 Oct 2009 08:27:31 +0000 (08:27 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Thu, 15 Oct 2009 08:27:31 +0000 (08:27 +0000)
- 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
intern/ghost/intern/GHOST_WindowCocoa.mm

index 072b2dfee865f14fc40c52821d164ab08f78464d..62f0c538e7e2b62b270915151dd4e0652875eac8 100644 (file)
@@ -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;
index 999ec0de9c1600743cad0e8ec8733600f54b8c58..f86fa49b31c29deb76821113b46f440e624c53c9 100644 (file)
 
 
 // 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]];