merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
[blender-staging.git] / intern / ghost / intern / GHOST_WindowCocoa.mm
index 0b10a02849f2e2afad3b4f7838f7a66428ad1c32..6206388fdaab1496fa865648668d8bb7cc5d047a 100644 (file)
@@ -1,51 +1,51 @@
-/**
- * $Id$
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
+/**\r
+ * $Id: GHOST_WindowCocoa.mm 23873 2009-10-15 20:09:50Z damien78 $\r
+ * ***** BEGIN GPL LICENSE BLOCK *****\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software Foundation,\r
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s):     Maarten Gribnau 05/2001
-                                       Damien Plisson 10/2009
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include <Cocoa/Cocoa.h>
-
-#ifndef MAC_OS_X_VERSION_10_6
-//Use of the SetSystemUIMode function (64bit compatible)
-#include <Carbon/Carbon.h>
-#endif
-
+ *\r
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.\r
+ * All rights reserved.\r
+ *\r
+ * The Original Code is: all of this file.\r
+ *\r
+ * Contributor(s):     Maarten Gribnau 05/2001\r
+                                       Damien Plisson 10/2009\r
+ *\r
+ * ***** END GPL LICENSE BLOCK *****\r
+ */\r
+\r
+#include <Cocoa/Cocoa.h>\r
+\r
+#ifndef MAC_OS_X_VERSION_10_6\r
+//Use of the SetSystemUIMode function (64bit compatible)\r
+#include <Carbon/Carbon.h>\r
+#endif\r
+\r
 #include <OpenGL/gl.h>
 /***** Multithreaded opengl code : uncomment for enabling
 #include <OpenGL/OpenGL.h>
 */
 
  
-#include "GHOST_WindowCocoa.h"
-#include "GHOST_SystemCocoa.h"
-#include "GHOST_Debug.h"
-
-
-#pragma mark Cocoa window delegate object
+#include "GHOST_WindowCocoa.h"\r
+#include "GHOST_SystemCocoa.h"\r
+#include "GHOST_Debug.h"\r
+\r
+\r
+#pragma mark Cocoa window delegate object\r
 /* live resize ugly patch
 extern "C" {
        struct bContext;
@@ -57,52 +57,52 @@ extern "C" {
        extern void wm_event_do_notifiers(bContext *C);
        extern void wm_draw_update(bContext *C);
 };*/
-@interface CocoaWindowDelegate : NSObject
+@interface CocoaWindowDelegate : NSObject\r
 #ifdef MAC_OS_X_VERSION_10_6
 <NSWindowDelegate>
 #endif
-{
-       GHOST_SystemCocoa *systemCocoa;
-       GHOST_WindowCocoa *associatedWindow;
-}
-
+{\r
+       GHOST_SystemCocoa *systemCocoa;\r
+       GHOST_WindowCocoa *associatedWindow;\r
+}\r
+\r
 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
-- (void)windowWillClose:(NSNotification *)notification;
-- (void)windowDidBecomeKey:(NSNotification *)notification;
-- (void)windowDidResignKey:(NSNotification *)notification;
+- (void)windowWillClose:(NSNotification *)notification;\r
+- (void)windowDidBecomeKey:(NSNotification *)notification;\r
+- (void)windowDidResignKey:(NSNotification *)notification;\r
 - (void)windowDidExpose:(NSNotification *)notification;
-- (void)windowDidResize:(NSNotification *)notification;
+- (void)windowDidResize:(NSNotification *)notification;\r
 - (void)windowDidMove:(NSNotification *)notification;
 - (void)windowWillMove:(NSNotification *)notification;
-@end
-
-@implementation CocoaWindowDelegate : NSObject
-- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
-{
-       systemCocoa = sysCocoa;
-       associatedWindow = winCocoa;
-}
-
-- (void)windowWillClose:(NSNotification *)notification
-{
-       systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);
-}
-
-- (void)windowDidBecomeKey:(NSNotification *)notification
-{
-       systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);
-}
-
-- (void)windowDidResignKey:(NSNotification *)notification
-{
-       systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);
-}
-
+@end\r
+\r
+@implementation CocoaWindowDelegate : NSObject\r
+- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa\r
+{\r
+       systemCocoa = sysCocoa;\r
+       associatedWindow = winCocoa;\r
+}\r
+\r
+- (void)windowWillClose:(NSNotification *)notification\r
+{\r
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);\r
+}\r
+\r
+- (void)windowDidBecomeKey:(NSNotification *)notification\r
+{\r
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);\r
+}\r
+\r
+- (void)windowDidResignKey:(NSNotification *)notification\r
+{\r
+               systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);\r
+}\r
+\r
 - (void)windowDidExpose:(NSNotification *)notification
-{
-       systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
-}
-
+{\r
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);\r
+}\r
+\r
 - (void)windowDidMove:(NSNotification *)notification
 {
        systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
@@ -113,8 +113,8 @@ extern "C" {
        systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
 }
 
-- (void)windowDidResize:(NSNotification *)notification
-{
+- (void)windowDidResize:(NSNotification *)notification\r
+{\r
 #ifdef MAC_OS_X_VERSION_10_6
        //if (![[notification object] inLiveResize]) {
                //Send event only once, at end of resize operation (when user has released mouse button)
@@ -131,31 +131,31 @@ extern "C" {
                wm_event_do_notifiers(ghostC);
                wm_draw_update(ghostC);
        }*/
-}
-@end
-
-#pragma mark NSWindow subclass
-//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)
-@interface CocoaWindow: NSWindow
-{
+}\r
+@end\r
+\r
+#pragma mark NSWindow subclass\r
+//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)\r
+@interface CocoaWindow: NSWindow\r
+{\r
        GHOST_SystemCocoa *systemCocoa;
        GHOST_WindowCocoa *associatedWindow;
        GHOST_TDragnDropTypes m_draggedObjectType;
-}
+}\r
 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
-@end
-@implementation CocoaWindow
+@end\r
+@implementation CocoaWindow\r
 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
 {
        systemCocoa = sysCocoa;
        associatedWindow = winCocoa;
 }
-
--(BOOL)canBecomeKeyWindow
-{
-       return YES;
-}
-
+\r
+-(BOOL)canBecomeKeyWindow\r
+{\r
+       return YES;\r
+}\r
+\r
 //The drag'n'drop dragging destination methods
 - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
 {
@@ -228,27 +228,27 @@ extern "C" {
        return YES;
 }
 
-@end
-
-
-
-#pragma mark NSOpenGLView subclass
-//We need to subclass it in order to give Cocoa the feeling key events are trapped
-@interface CocoaOpenGLView : NSOpenGLView
-{
-}
-@end
-@implementation CocoaOpenGLView
-
-- (BOOL)acceptsFirstResponder
-{
-    return YES;
-}
-
-//The trick to prevent Cocoa from complaining (beeping)
-- (void)keyDown:(NSEvent *)theEvent
-{}
-
+@end\r
+\r
+\r
+\r
+#pragma mark NSOpenGLView subclass\r
+//We need to subclass it in order to give Cocoa the feeling key events are trapped\r
+@interface CocoaOpenGLView : NSOpenGLView\r
+{\r
+}\r
+@end\r
+@implementation CocoaOpenGLView\r
+\r
+- (BOOL)acceptsFirstResponder\r
+{\r
+    return YES;\r
+}\r
+\r
+//The trick to prevent Cocoa from complaining (beeping)\r
+- (void)keyDown:(NSEvent *)theEvent\r
+{}\r
+\r
 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
 //Cmd+key are handled differently before 10.5
 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent
@@ -275,59 +275,59 @@ extern "C" {
 }
 #endif
 
-- (BOOL)isOpaque
-{
-    return YES;
-}
-
-@end
-
-
-#pragma mark initialization / finalization
-
-NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
-
-GHOST_WindowCocoa::GHOST_WindowCocoa(
-       GHOST_SystemCocoa *systemCocoa,
-       const STR_String& title,
-       GHOST_TInt32 left,
-       GHOST_TInt32 top,
-       GHOST_TUns32 width,
-       GHOST_TUns32 height,
-       GHOST_TWindowState state,
-       GHOST_TDrawingContextType type,
+- (BOOL)isOpaque\r
+{\r
+    return YES;\r
+}\r
+\r
+@end\r
+\r
+\r
+#pragma mark initialization / finalization\r
+\r
+NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;\r
+\r
+GHOST_WindowCocoa::GHOST_WindowCocoa(\r
+       GHOST_SystemCocoa *systemCocoa,\r
+       const STR_String& title,\r
+       GHOST_TInt32 left,\r
+       GHOST_TInt32 top,\r
+       GHOST_TUns32 width,\r
+       GHOST_TUns32 height,\r
+       GHOST_TWindowState state,\r
+       GHOST_TDrawingContextType type,\r
        const bool stereoVisual, const GHOST_TUns16 numOfAASamples
-) :
+) :\r
        GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, numOfAASamples),
-       m_customCursor(0)
-{
+       m_customCursor(0)\r
+{\r
        NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
        NSOpenGLPixelFormat *pixelFormat = nil;
        int i;
                
-       m_systemCocoa = systemCocoa;
-       m_fullScreen = false;
-       
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-
-       //Creates the window
-       NSRect rect;
+       m_systemCocoa = systemCocoa;\r
+       m_fullScreen = false;\r
+       \r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+\r
+       //Creates the window\r
+       NSRect rect;\r
        NSSize  minSize;
-       
-       rect.origin.x = left;
-       rect.origin.y = top;
-       rect.size.width = width;
-       rect.size.height = height;
-       
-       m_window = [[CocoaWindow alloc] initWithContentRect:rect
-                                                                                  styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
-                                                                                        backing:NSBackingStoreBuffered defer:NO];
-       if (m_window == nil) {
-               [pool drain];
-               return;
-       }
-       
+       \r
+       rect.origin.x = left;\r
+       rect.origin.y = top;\r
+       rect.size.width = width;\r
+       rect.size.height = height;\r
+       \r
+       m_window = [[CocoaWindow alloc] initWithContentRect:rect\r
+                                                                                  styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask\r
+                                                                                        backing:NSBackingStoreBuffered defer:NO];\r
+       if (m_window == nil) {\r
+               [pool drain];\r
+               return;\r
+       }\r
+       \r
        [m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
        
        //Forbid to resize the window below the blender defined minimum one
@@ -335,9 +335,9 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
        minSize.height = 240;
        [m_window setContentMinSize:minSize];
        
-       setTitle(title);
-       
-       
+       setTitle(title);\r
+       \r
+                       \r
        // Pixel Format Attributes for the windowed NSOpenGLContext
        i=0;
        pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
@@ -404,293 +404,293 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
                }
        }
                
-       //Creates the OpenGL View inside the window
-       m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
-                                                                                                pixelFormat:pixelFormat];
-       
-       [pixelFormat release];
-       
-       m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
-       
-       [m_window setContentView:m_openGLView];
-       [m_window setInitialFirstResponder:m_openGLView];
-       
-       [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window
-       
-       [m_window makeKeyAndOrderFront:nil];
-       
-       setDrawingContextType(type);
-       updateDrawingContext();
-       activateDrawingContext();
-       
-       m_tablet.Active = GHOST_kTabletModeNone;
-       
-       CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
-       [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
-       [m_window setDelegate:windowDelegate];
-       
-       [m_window setAcceptsMouseMovedEvents:YES];
-       
+       //Creates the OpenGL View inside the window\r
+       m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect\r
+                                                                                                pixelFormat:pixelFormat];\r
+       \r
+       [pixelFormat release];\r
+       \r
+       m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after\r
+       \r
+       [m_window setContentView:m_openGLView];\r
+       [m_window setInitialFirstResponder:m_openGLView];\r
+       \r
+       [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window\r
+       \r
+       [m_window makeKeyAndOrderFront:nil];\r
+       \r
+       setDrawingContextType(type);\r
+       updateDrawingContext();\r
+       activateDrawingContext();\r
+       \r
+       m_tablet.Active = GHOST_kTabletModeNone;\r
+       \r
+       CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];\r
+       [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];\r
+       [m_window setDelegate:windowDelegate];\r
+       \r
+       [m_window setAcceptsMouseMovedEvents:YES];\r
+       \r
        [m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
                                                                                  NSStringPboardType, NSTIFFPboardType, nil]];
                                                                                  
-       if (state == GHOST_kWindowStateFullScreen)
-               setState(GHOST_kWindowStateFullScreen);
-               
-       [pool drain];
-}
-
-
-GHOST_WindowCocoa::~GHOST_WindowCocoa()
-{
-       if (m_customCursor) delete m_customCursor;
-
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       [m_openGLView release];
-       
-       if (m_window) {
-               [m_window close];
-               [[m_window delegate] release];
-               [m_window release];
-               m_window = nil;
-       }
-       
-       //Check for other blender opened windows and make the frontmost key
-       NSArray *windowsList = [NSApp orderedWindows];
-       if ([windowsList count]) {
-               [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
-       }
-       [pool drain];
-}
-
-#pragma mark accessors
-
-bool GHOST_WindowCocoa::getValid() const
-{
+       if (state == GHOST_kWindowStateFullScreen)\r
+               setState(GHOST_kWindowStateFullScreen);\r
+               \r
+       [pool drain];\r
+}\r
+\r
+\r
+GHOST_WindowCocoa::~GHOST_WindowCocoa()\r
+{\r
+       if (m_customCursor) delete m_customCursor;\r
+\r
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       [m_openGLView release];\r
+       \r
+       if (m_window) {\r
+               [m_window close];\r
+               [[m_window delegate] release];\r
+               [m_window release];\r
+               m_window = nil;\r
+       }\r
+       \r
+       //Check for other blender opened windows and make the frontmost key\r
+       NSArray *windowsList = [NSApp orderedWindows];\r
+       if ([windowsList count]) {\r
+               [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];\r
+       }\r
+       [pool drain];\r
+}\r
+\r
+#pragma mark accessors\r
+\r
+bool GHOST_WindowCocoa::getValid() const\r
+{\r
        return (m_window != 0);
-}
-
+}\r
+\r
 void* GHOST_WindowCocoa::getOSWindow() const
 {
        return (void*)m_window;
 }
-
-void GHOST_WindowCocoa::setTitle(const STR_String& title)
-{
-    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-       NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];
-       
-       //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];
-}
-
-
-void GHOST_WindowCocoa::getTitle(STR_String& title) const
-{
-    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
-
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-       NSString *windowTitle = [m_window title];
-
-       if (windowTitle != nil) {
-               title = [windowTitle UTF8String];               
-       }
-       
-       [pool drain];
-}
-
-
-void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
-{
-       NSRect rect;
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")
-
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       NSRect screenSize = [[m_window screen] visibleFrame];
-
-       rect = [m_window frame];
-
-       bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);
-       bounds.m_l = rect.origin.x -screenSize.origin.x;
-       bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;
-       bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);
-       
-       [pool drain];
-}
-
-
-void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
-{
-       NSRect rect;
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")
-       
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       if (!m_fullScreen)
-       {
-               NSRect screenSize = [[m_window screen] visibleFrame];
-
-               //Max window contents as screen size (excluding title bar...)
-               NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
-                                                                                                        styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
-
-               rect = [m_window contentRectForFrameRect:[m_window frame]];
-               
-               bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);
-               bounds.m_l = rect.origin.x -contentRect.origin.x;
-               bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;
-               bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);
-       }
-       else {
-               NSRect screenSize = [[m_window screen] frame];
-               
-               bounds.m_b = screenSize.origin.y + screenSize.size.height;
-               bounds.m_l = screenSize.origin.x;
-               bounds.m_r = screenSize.origin.x + screenSize.size.width;
-               bounds.m_t = screenSize.origin.y;
-       }
-       [pool drain];
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")
-       GHOST_Rect cBnds, wBnds;
-       getClientBounds(cBnds);
-       if (((GHOST_TUns32)cBnds.getWidth()) != width) {
-               NSSize size;
-               size.width=width;
-               size.height=cBnds.getHeight();
-               [m_window setContentSize:size];
-       }
-       return GHOST_kSuccess;
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")
-       GHOST_Rect cBnds, wBnds;
-       getClientBounds(cBnds);
-       if (((GHOST_TUns32)cBnds.getHeight()) != height) {
-               NSSize size;
-               size.width=cBnds.getWidth();
-               size.height=height;
-               [m_window setContentSize:size];
-       }
-       return GHOST_kSuccess;
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")
-       GHOST_Rect cBnds, wBnds;
-       getClientBounds(cBnds);
-       if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
-           (((GHOST_TUns32)cBnds.getHeight()) != height)) {
-               NSSize size;
-               size.width=width;
-               size.height=height;
-               [m_window setContentSize:size];
-       }
-       return GHOST_kSuccess;
-}
-
-
-GHOST_TWindowState GHOST_WindowCocoa::getState() const
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       GHOST_TWindowState state;
-       if (m_fullScreen) {
-               state = GHOST_kWindowStateFullScreen;
-       } 
-       else if ([m_window isMiniaturized]) {
-               state = GHOST_kWindowStateMinimized;
-       }
-       else if ([m_window isZoomed]) {
-               state = GHOST_kWindowStateMaximized;
-       }
-       else {
-               state = GHOST_kWindowStateNormal;
-       }
-       [pool drain];
-       return state;
-}
-
-
-void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")
-       
-       NSPoint screenCoord;
-       NSPoint baseCoord;
-       
-       screenCoord.x = inX;
-       screenCoord.y = inY;
-       
-       baseCoord = [m_window convertScreenToBase:screenCoord];
-       
-       outX = baseCoord.x;
-       outY = baseCoord.y;
-}
-
-
-void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")
-       
-       NSPoint screenCoord;
-       NSPoint baseCoord;
-       
-       baseCoord.x = inX;
-       baseCoord.y = inY;
-       
-       screenCoord = [m_window convertBaseToScreen:baseCoord];
-       
-       outX = screenCoord.x;
-       outY = screenCoord.y;
-}
-
+\r
+void GHOST_WindowCocoa::setTitle(const STR_String& title)\r
+{\r
+    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+\r
+       NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];\r
+       \r
+       //Set associated file if applicable\r
+       if ([windowTitle hasPrefix:@"Blender"])\r
+       {\r
+               NSRange fileStrRange;\r
+               NSString *associatedFileName;\r
+               int len;\r
+               \r
+               fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;\r
+               len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;\r
+       \r
+               if (len >0)\r
+               {\r
+                       fileStrRange.length = len;\r
+                       associatedFileName = [windowTitle substringWithRange:fileStrRange];\r
+                       @try {\r
+                               [m_window setRepresentedFilename:associatedFileName];\r
+                       }\r
+                       @catch (NSException * e) {\r
+                               printf("\nInvalid file path given in window title");\r
+                       }\r
+                       [m_window setTitle:[associatedFileName lastPathComponent]];\r
+               }\r
+               else {\r
+                       [m_window setTitle:windowTitle];\r
+                       [m_window setRepresentedFilename:@""];\r
+               }\r
+\r
+       } else {\r
+               [m_window setTitle:windowTitle];\r
+               [m_window setRepresentedFilename:@""];\r
+       }\r
+\r
+       \r
+       [windowTitle release];\r
+       [pool drain];\r
+}\r
+\r
+\r
+void GHOST_WindowCocoa::getTitle(STR_String& title) const\r
+{\r
+    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")\r
+\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+\r
+       NSString *windowTitle = [m_window title];\r
+\r
+       if (windowTitle != nil) {\r
+               title = [windowTitle UTF8String];               \r
+       }\r
+       \r
+       [pool drain];\r
+}\r
+\r
+\r
+void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const\r
+{\r
+       NSRect rect;\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")\r
+\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       NSRect screenSize = [[m_window screen] visibleFrame];\r
+\r
+       rect = [m_window frame];\r
+\r
+       bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);\r
+       bounds.m_l = rect.origin.x -screenSize.origin.x;\r
+       bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;\r
+       bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);\r
+       \r
+       [pool drain];\r
+}\r
+\r
+\r
+void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const\r
+{\r
+       NSRect rect;\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")\r
+       \r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       if (!m_fullScreen)\r
+       {\r
+               NSRect screenSize = [[m_window screen] visibleFrame];\r
+\r
+               //Max window contents as screen size (excluding title bar...)\r
+               NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize\r
+                                                                                                        styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
+\r
+               rect = [m_window contentRectForFrameRect:[m_window frame]];\r
+               \r
+               bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);\r
+               bounds.m_l = rect.origin.x -contentRect.origin.x;\r
+               bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;\r
+               bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);\r
+       }\r
+       else {\r
+               NSRect screenSize = [[m_window screen] frame];\r
+               \r
+               bounds.m_b = screenSize.origin.y + screenSize.size.height;\r
+               bounds.m_l = screenSize.origin.x;\r
+               bounds.m_r = screenSize.origin.x + screenSize.size.width;\r
+               bounds.m_t = screenSize.origin.y;\r
+       }\r
+       [pool drain];\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")\r
+       GHOST_Rect cBnds, wBnds;\r
+       getClientBounds(cBnds);\r
+       if (((GHOST_TUns32)cBnds.getWidth()) != width) {\r
+               NSSize size;\r
+               size.width=width;\r
+               size.height=cBnds.getHeight();\r
+               [m_window setContentSize:size];\r
+       }\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")\r
+       GHOST_Rect cBnds, wBnds;\r
+       getClientBounds(cBnds);\r
+       if (((GHOST_TUns32)cBnds.getHeight()) != height) {\r
+               NSSize size;\r
+               size.width=cBnds.getWidth();\r
+               size.height=height;\r
+               [m_window setContentSize:size];\r
+       }\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")\r
+       GHOST_Rect cBnds, wBnds;\r
+       getClientBounds(cBnds);\r
+       if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||\r
+           (((GHOST_TUns32)cBnds.getHeight()) != height)) {\r
+               NSSize size;\r
+               size.width=width;\r
+               size.height=height;\r
+               [m_window setContentSize:size];\r
+       }\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TWindowState GHOST_WindowCocoa::getState() const\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       GHOST_TWindowState state;\r
+       if (m_fullScreen) {\r
+               state = GHOST_kWindowStateFullScreen;\r
+       } \r
+       else if ([m_window isMiniaturized]) {\r
+               state = GHOST_kWindowStateMinimized;\r
+       }\r
+       else if ([m_window isZoomed]) {\r
+               state = GHOST_kWindowStateMaximized;\r
+       }\r
+       else {\r
+               state = GHOST_kWindowStateNormal;\r
+       }\r
+       [pool drain];\r
+       return state;\r
+}\r
+\r
+\r
+void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")\r
+       \r
+       NSPoint screenCoord;\r
+       NSPoint baseCoord;\r
+       \r
+       screenCoord.x = inX;\r
+       screenCoord.y = inY;\r
+       \r
+       baseCoord = [m_window convertScreenToBase:screenCoord];\r
+       \r
+       outX = baseCoord.x;\r
+       outY = baseCoord.y;\r
+}\r
+\r
+\r
+void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")\r
+       \r
+       NSPoint screenCoord;\r
+       NSPoint baseCoord;\r
+       \r
+       baseCoord.x = inX;\r
+       baseCoord.y = inY;\r
+       \r
+       screenCoord = [m_window convertBaseToScreen:baseCoord];\r
+       \r
+       outX = screenCoord.x;\r
+       outY = screenCoord.y;\r
+}\r
+\r
 
 NSScreen* GHOST_WindowCocoa::getScreen()
 {
@@ -698,256 +698,256 @@ NSScreen* GHOST_WindowCocoa::getScreen()
 }
 
 
-/**
- * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.
- * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.
- * Thus, process switch, exposé, spaces, ... still work in fullscreen mode
- */
-GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")
-    switch (state) {
-               case GHOST_kWindowStateMinimized:
-            [m_window miniaturize:nil];
-            break;
-               case GHOST_kWindowStateMaximized:
-                       [m_window zoom:nil];
-                       break;
-               
-               case GHOST_kWindowStateFullScreen:
-                       if (!m_fullScreen)
-                       {
-                               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-                       
-                               //This status change needs to be done before Cocoa call to enter fullscreen mode
-                               //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference
-                               m_fullScreen = true;
-
-#ifdef MAC_OS_X_VERSION_10_6
-                               //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
-                               //Hide menu & dock if needed
-                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])
-                               {
-                                       [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];
-                               }
-                               //Make window borderless and enlarge it
-                               [m_window setStyleMask:NSBorderlessWindowMask];
-                               [m_window setFrame:[[m_window screen] frame] display:YES];
+/**\r
+ * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.\r
+ * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.\r
+ * Thus, process switch, exposé, spaces, ... still work in fullscreen mode\r
+ */\r
+GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")\r
+    switch (state) {\r
+               case GHOST_kWindowStateMinimized:\r
+            [m_window miniaturize:nil];\r
+            break;\r
+               case GHOST_kWindowStateMaximized:\r
+                       [m_window zoom:nil];\r
+                       break;\r
+               \r
+               case GHOST_kWindowStateFullScreen:\r
+                       if (!m_fullScreen)\r
+                       {\r
+                               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+                       \r
+                               //This status change needs to be done before Cocoa call to enter fullscreen mode\r
+                               //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference\r
+                               m_fullScreen = true;\r
+\r
+#ifdef MAC_OS_X_VERSION_10_6\r
+                               //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style\r
+                               //Hide menu & dock if needed\r
+                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
+                               {\r
+                                       [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];\r
+                               }\r
+                               //Make window borderless and enlarge it\r
+                               [m_window setStyleMask:NSBorderlessWindowMask];\r
+                               [m_window setFrame:[[m_window screen] frame] display:YES];\r
                                [m_window makeFirstResponder:m_openGLView];
-#else
-                               //With 10.5, we need to create a new window to change its style to borderless
-                               //Hide menu & dock if needed
-                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])
-                               {
-                                       //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];
-                                       //One of the very few 64bit compatible Carbon function
-                                       SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);
-                               }
-                               //Create a fullscreen borderless window
-                               CocoaWindow *tmpWindow = [[CocoaWindow alloc]
-                                                                                 initWithContentRect:[[m_window screen] frame]
-                                                                                 styleMask:NSBorderlessWindowMask
-                                                                                 backing:NSBackingStoreBuffered
-                                                                                 defer:YES];
-                               //Copy current window parameters
-                               [tmpWindow setTitle:[m_window title]];
-                               [tmpWindow setRepresentedFilename:[m_window representedFilename]];
-                               [tmpWindow setReleasedWhenClosed:NO];
-                               [tmpWindow setAcceptsMouseMovedEvents:YES];
-                               [tmpWindow setDelegate:[m_window delegate]];
-                               
-                               //Assign the openGL view to the new window
-                               [tmpWindow setContentView:m_openGLView];
-                               
-                               //Show the new window
-                               [tmpWindow makeKeyAndOrderFront:nil];
-                               //Close and release old window
-                               [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
-                               [m_window close];
-                               [m_window release];
-                               m_window = tmpWindow;
-#endif
-                       
-                               //Tell WM of view new size
-                               m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
-                               
-                               [pool drain];
-                               }
-                       break;
-               case GHOST_kWindowStateNormal:
-        default:
-                       if (m_fullScreen)
-                       {
-                               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-                               m_fullScreen = false;
-
-                               //Exit fullscreen
-#ifdef MAC_OS_X_VERSION_10_6
-                               //Show again menu & dock if needed
-                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])
-                               {
-                                       [NSApp setPresentationOptions:NSApplicationPresentationDefault];
-                               }
-                               //Make window normal and resize it
-                               [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
-                               [m_window setFrame:[[m_window screen] visibleFrame] display:YES];
+#else\r
+                               //With 10.5, we need to create a new window to change its style to borderless\r
+                               //Hide menu & dock if needed\r
+                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
+                               {\r
+                                       //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];\r
+                                       //One of the very few 64bit compatible Carbon function\r
+                                       SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);\r
+                               }\r
+                               //Create a fullscreen borderless window\r
+                               CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
+                                                                                 initWithContentRect:[[m_window screen] frame]\r
+                                                                                 styleMask:NSBorderlessWindowMask\r
+                                                                                 backing:NSBackingStoreBuffered\r
+                                                                                 defer:YES];\r
+                               //Copy current window parameters\r
+                               [tmpWindow setTitle:[m_window title]];\r
+                               [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
+                               [tmpWindow setReleasedWhenClosed:NO];\r
+                               [tmpWindow setAcceptsMouseMovedEvents:YES];\r
+                               [tmpWindow setDelegate:[m_window delegate]];\r
+                               \r
+                               //Assign the openGL view to the new window\r
+                               [tmpWindow setContentView:m_openGLView];\r
+                               \r
+                               //Show the new window\r
+                               [tmpWindow makeKeyAndOrderFront:nil];\r
+                               //Close and release old window\r
+                               [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
+                               [m_window close];\r
+                               [m_window release];\r
+                               m_window = tmpWindow;\r
+#endif\r
+                       \r
+                               //Tell WM of view new size\r
+                               m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
+                               \r
+                               [pool drain];\r
+                               }\r
+                       break;\r
+               case GHOST_kWindowStateNormal:\r
+        default:\r
+                       if (m_fullScreen)\r
+                       {\r
+                               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+                               m_fullScreen = false;\r
+\r
+                               //Exit fullscreen\r
+#ifdef MAC_OS_X_VERSION_10_6\r
+                               //Show again menu & dock if needed\r
+                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
+                               {\r
+                                       [NSApp setPresentationOptions:NSApplicationPresentationDefault];\r
+                               }\r
+                               //Make window normal and resize it\r
+                               [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
+                               [m_window setFrame:[[m_window screen] visibleFrame] display:YES];\r
                                //TODO for 10.6 only : window title is forgotten after the style change
                                [m_window makeFirstResponder:m_openGLView];
-#else
-                               //With 10.5, we need to create a new window to change its style to borderless
-                               //Show menu & dock if needed
-                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])
-                               {
-                                       //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];
-                                       SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function
-                               }
-                               //Create a fullscreen borderless window
-                               CocoaWindow *tmpWindow = [[CocoaWindow alloc]
-                                                                                 initWithContentRect:[[m_window screen] frame]
-                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
-                                                                                                         backing:NSBackingStoreBuffered
-                                                                                                               defer:YES];
-                               //Copy current window parameters
-                               [tmpWindow setTitle:[m_window title]];
-                               [tmpWindow setRepresentedFilename:[m_window representedFilename]];
-                               [tmpWindow setReleasedWhenClosed:NO];
-                               [tmpWindow setAcceptsMouseMovedEvents:YES];
-                               [tmpWindow setDelegate:[m_window delegate]];
-                               
-                               //Assign the openGL view to the new window
-                               [tmpWindow setContentView:m_openGLView];
-                               
-                               //Show the new window
-                               [tmpWindow makeKeyAndOrderFront:nil];
-                               //Close and release old window
-                               [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
-                               [m_window close];
-                               [m_window release];
-                               m_window = tmpWindow;
-#endif
-                       
-                               //Tell WM of view new size
-                               m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
-                               
-                               [pool drain];
-                       }
-            else if ([m_window isMiniaturized])
-                               [m_window deminiaturize:nil];
-                       else if ([m_window isZoomed])
-                               [m_window zoom:nil];
-            break;
-    }
-    return GHOST_kSuccess;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
-{
+#else\r
+                               //With 10.5, we need to create a new window to change its style to borderless\r
+                               //Show menu & dock if needed\r
+                               if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
+                               {\r
+                                       //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];\r
+                                       SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function\r
+                               }\r
+                               //Create a fullscreen borderless window\r
+                               CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
+                                                                                 initWithContentRect:[[m_window screen] frame]\r
+                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)\r
+                                                                                                         backing:NSBackingStoreBuffered\r
+                                                                                                               defer:YES];\r
+                               //Copy current window parameters\r
+                               [tmpWindow setTitle:[m_window title]];\r
+                               [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
+                               [tmpWindow setReleasedWhenClosed:NO];\r
+                               [tmpWindow setAcceptsMouseMovedEvents:YES];\r
+                               [tmpWindow setDelegate:[m_window delegate]];\r
+                               \r
+                               //Assign the openGL view to the new window\r
+                               [tmpWindow setContentView:m_openGLView];\r
+                               \r
+                               //Show the new window\r
+                               [tmpWindow makeKeyAndOrderFront:nil];\r
+                               //Close and release old window\r
+                               [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
+                               [m_window close];\r
+                               [m_window release];\r
+                               m_window = tmpWindow;\r
+#endif\r
+                       \r
+                               //Tell WM of view new size\r
+                               m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
+                               \r
+                               [pool drain];\r
+                       }\r
+            else if ([m_window isMiniaturized])\r
+                               [m_window deminiaturize:nil];\r
+                       else if ([m_window isZoomed])\r
+                               [m_window zoom:nil];\r
+            break;\r
+    }\r
+    return GHOST_kSuccess;\r
+}\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)\r
+{\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       [m_window setDocumentEdited:isUnsavedChanges];\r
+       \r
+       [pool drain];\r
+       return GHOST_Window::setModifiedState(isUnsavedChanges);\r
+}\r
+\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)\r
+{\r
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
-       [m_window setDocumentEdited:isUnsavedChanges];
-       
-       [pool drain];
-       return GHOST_Window::setModifiedState(isUnsavedChanges);
-}
-
-
-
-GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
-{
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")
-    if (order == GHOST_kWindowOrderTop) {
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")\r
+    if (order == GHOST_kWindowOrderTop) {\r
                [m_window makeKeyAndOrderFront:nil];
-    }
-    else {
+    }\r
+    else {\r
                NSArray *windowsList;
                
-               [m_window orderBack:nil];
+               [m_window orderBack:nil];\r
                
                //Check for other blender opened windows and make the frontmost key
                windowsList = [NSApp orderedWindows];
                if ([windowsList count]) {
                        [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
                }
-    }
+    }\r
        
        [pool drain];
-    return GHOST_kSuccess;
-}
-
-#pragma mark Drawing context
-
-/*#define  WAIT_FOR_VSYNC 1*/
-
-GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
-{
-    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
-        if (m_openGLContext != nil) {
-                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-                       [m_openGLContext flushBuffer];
-                       [pool drain];
-            return GHOST_kSuccess;
-        }
-    }
-    return GHOST_kFailure;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
-{
-       if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
-               if (m_openGLContext != nil) {
-                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-                       [m_openGLContext update];
-                       [pool drain];
-                       return GHOST_kSuccess;
-               }
-       }
-       return GHOST_kFailure;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
-{
-       if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
-               if (m_openGLContext != nil) {
-                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-                       [m_openGLContext makeCurrentContext];
+    return GHOST_kSuccess;\r
+}\r
+\r
+#pragma mark Drawing context\r
+\r
+/*#define  WAIT_FOR_VSYNC 1*/\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()\r
+{\r
+    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
+        if (m_openGLContext != nil) {\r
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+                       [m_openGLContext flushBuffer];\r
+                       [pool drain];\r
+            return GHOST_kSuccess;\r
+        }\r
+    }\r
+    return GHOST_kFailure;\r
+}\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()\r
+{\r
+       if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
+               if (m_openGLContext != nil) {\r
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+                       [m_openGLContext update];\r
+                       [pool drain];\r
+                       return GHOST_kSuccess;\r
+               }\r
+       }\r
+       return GHOST_kFailure;\r
+}\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()\r
+{\r
+       if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
+               if (m_openGLContext != nil) {\r
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+                       [m_openGLContext makeCurrentContext];\r
                        
                        // Disable AA by default
                        if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
-                       [pool drain];
-                       return GHOST_kSuccess;
-               }
-       }
-       return GHOST_kFailure;
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
-{
-       GHOST_TSuccess success = GHOST_kFailure;
-       
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       NSOpenGLPixelFormat *pixelFormat;
-       NSOpenGLContext *tmpOpenGLContext;
-       
+                       [pool drain];\r
+                       return GHOST_kSuccess;\r
+               }\r
+       }\r
+       return GHOST_kFailure;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)\r
+{\r
+       GHOST_TSuccess success = GHOST_kFailure;\r
+       \r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       NSOpenGLPixelFormat *pixelFormat;\r
+       NSOpenGLContext *tmpOpenGLContext;\r
+       \r
        /***** Multithreaded opengl code : uncomment for enabling
        CGLContextObj cglCtx;
        */
         
-       switch (type) {
-               case GHOST_kDrawingContextTypeOpenGL:
-                       if (!getValid()) break;
-                                       
-                       pixelFormat = [m_openGLView pixelFormat];
-                       tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
-                                                                                                                         shareContext:s_firstOpenGLcontext];
-                       if (tmpOpenGLContext == nil) {
-                               success = GHOST_kFailure;
-                               break;
-                       }
-                       
+       switch (type) {\r
+               case GHOST_kDrawingContextTypeOpenGL:\r
+                       if (!getValid()) break;\r
+                                       \r
+                       pixelFormat = [m_openGLView pixelFormat];\r
+                       tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat\r
+                                                                                                                         shareContext:s_firstOpenGLcontext];\r
+                       if (tmpOpenGLContext == nil) {\r
+                               success = GHOST_kFailure;\r
+                               break;\r
+                       }\r
+                       \r
                        //Switch openGL to multhreaded mode
                        /******* Multithreaded opengl code : uncomment for enabling
                        cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj];
@@ -955,165 +955,165 @@ GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextTyp
                                printf("\nSwitched openGL to multithreaded mode");
                         */
                        
-                       if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;
-#ifdef WAIT_FOR_VSYNC
+                       if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;\r
+#ifdef WAIT_FOR_VSYNC\r
                        {
                                GLint swapInt = 1;
-                               /* wait for vsync, to avoid tearing artifacts */
+                               /* wait for vsync, to avoid tearing artifacts */\r
                                [tmpOpenGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
                        }
-#endif
+#endif\r
                        [m_openGLView setOpenGLContext:tmpOpenGLContext];
                        [tmpOpenGLContext setView:m_openGLView];
                        
                        m_openGLContext = tmpOpenGLContext;
-                       break;
-       
-               case GHOST_kDrawingContextTypeNone:
-                       success = GHOST_kSuccess;
-                       break;
-               
-               default:
-                       break;
-       }
-       [pool drain];
-       return success;
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
-{
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       switch (m_drawingContextType) {
-               case GHOST_kDrawingContextTypeOpenGL:
-                       if (m_openGLContext)
-                       {
-                               [m_openGLView clearGLContext];
-                               if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
-                               m_openGLContext = nil;
-                       }
-                       [pool drain];
-                       return GHOST_kSuccess;
-               case GHOST_kDrawingContextTypeNone:
-                       [pool drain];
-                       return GHOST_kSuccess;
-                       break;
-               default:
-                       [pool drain];
-                       return GHOST_kFailure;
-       }
-}
-
-
-GHOST_TSuccess GHOST_WindowCocoa::invalidate()
-{
-       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid")
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       [m_openGLView setNeedsDisplay:YES];
-       [pool drain];
-       return GHOST_kSuccess;
-}
-
-#pragma mark Cursor handling
-
-void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
-{
-       static bool systemCursorVisible = true;
-       
-       NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
-
-       NSCursor *tmpCursor =nil;
-       
-       if (visible != systemCursorVisible) {
-               if (visible) {
-                       [NSCursor unhide];
-                       systemCursorVisible = true;
-               }
-               else {
-                       [NSCursor hide];
-                       systemCursorVisible = false;
-               }
-       }
-
-       if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {
-               tmpCursor = m_customCursor;
-       } else {
-               switch (cursor) {
-                       case GHOST_kStandardCursorDestroy:
-                               tmpCursor = [NSCursor disappearingItemCursor];
-                               break;
-                       case GHOST_kStandardCursorText:
-                               tmpCursor = [NSCursor IBeamCursor];
-                               break;
-                       case GHOST_kStandardCursorCrosshair:
-                               tmpCursor = [NSCursor crosshairCursor];
-                               break;
-                       case GHOST_kStandardCursorUpDown:
-                               tmpCursor = [NSCursor resizeUpDownCursor];
-                               break;
-                       case GHOST_kStandardCursorLeftRight:
-                               tmpCursor = [NSCursor resizeLeftRightCursor];
-                               break;
-                       case GHOST_kStandardCursorTopSide:
-                               tmpCursor = [NSCursor resizeUpCursor];
-                               break;
-                       case GHOST_kStandardCursorBottomSide:
-                               tmpCursor = [NSCursor resizeDownCursor];
-                               break;
-                       case GHOST_kStandardCursorLeftSide:
-                               tmpCursor = [NSCursor resizeLeftCursor];
-                               break;
-                       case GHOST_kStandardCursorRightSide:
-                               tmpCursor = [NSCursor resizeRightCursor];
-                               break;
-                       case GHOST_kStandardCursorRightArrow:
-                       case GHOST_kStandardCursorInfo:
-                       case GHOST_kStandardCursorLeftArrow:
-                       case GHOST_kStandardCursorHelp:
-                       case GHOST_kStandardCursorCycle:
-                       case GHOST_kStandardCursorSpray:
-                       case GHOST_kStandardCursorWait:
-                       case GHOST_kStandardCursorTopLeftCorner:
-                       case GHOST_kStandardCursorTopRightCorner:
-                       case GHOST_kStandardCursorBottomRightCorner:
-                       case GHOST_kStandardCursorBottomLeftCorner:
+                       break;\r
+       
+               case GHOST_kDrawingContextTypeNone:\r
+                       success = GHOST_kSuccess;\r
+                       break;\r
+               \r
+               default:\r
+                       break;\r
+       }\r
+       [pool drain];\r
+       return success;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()\r
+{\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       switch (m_drawingContextType) {\r
+               case GHOST_kDrawingContextTypeOpenGL:\r
+                       if (m_openGLContext)\r
+                       {\r
+                               [m_openGLView clearGLContext];\r
+                               if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;\r
+                               m_openGLContext = nil;\r
+                       }\r
+                       [pool drain];\r
+                       return GHOST_kSuccess;\r
+               case GHOST_kDrawingContextTypeNone:\r
+                       [pool drain];\r
+                       return GHOST_kSuccess;\r
+                       break;\r
+               default:\r
+                       [pool drain];\r
+                       return GHOST_kFailure;\r
+       }\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::invalidate()\r
+{\r
+       GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid")\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       [m_openGLView setNeedsDisplay:YES];\r
+       [pool drain];\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+#pragma mark Cursor handling\r
+\r
+void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const\r
+{\r
+       static bool systemCursorVisible = true;\r
+       \r
+       NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];\r
+\r
+       NSCursor *tmpCursor =nil;\r
+       \r
+       if (visible != systemCursorVisible) {\r
+               if (visible) {\r
+                       [NSCursor unhide];\r
+                       systemCursorVisible = true;\r
+               }\r
+               else {\r
+                       [NSCursor hide];\r
+                       systemCursorVisible = false;\r
+               }\r
+       }\r
+\r
+       if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {\r
+               tmpCursor = m_customCursor;\r
+       } else {\r
+               switch (cursor) {\r
+                       case GHOST_kStandardCursorDestroy:\r
+                               tmpCursor = [NSCursor disappearingItemCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorText:\r
+                               tmpCursor = [NSCursor IBeamCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorCrosshair:\r
+                               tmpCursor = [NSCursor crosshairCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorUpDown:\r
+                               tmpCursor = [NSCursor resizeUpDownCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorLeftRight:\r
+                               tmpCursor = [NSCursor resizeLeftRightCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorTopSide:\r
+                               tmpCursor = [NSCursor resizeUpCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorBottomSide:\r
+                               tmpCursor = [NSCursor resizeDownCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorLeftSide:\r
+                               tmpCursor = [NSCursor resizeLeftCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorRightSide:\r
+                               tmpCursor = [NSCursor resizeRightCursor];\r
+                               break;\r
+                       case GHOST_kStandardCursorRightArrow:\r
+                       case GHOST_kStandardCursorInfo:\r
+                       case GHOST_kStandardCursorLeftArrow:\r
+                       case GHOST_kStandardCursorHelp:\r
+                       case GHOST_kStandardCursorCycle:\r
+                       case GHOST_kStandardCursorSpray:\r
+                       case GHOST_kStandardCursorWait:\r
+                       case GHOST_kStandardCursorTopLeftCorner:\r
+                       case GHOST_kStandardCursorTopRightCorner:\r
+                       case GHOST_kStandardCursorBottomRightCorner:\r
+                       case GHOST_kStandardCursorBottomLeftCorner:\r
                        case GHOST_kStandardCursorCopy:
-                       case GHOST_kStandardCursorDefault:
-                       default:
-                               tmpCursor = [NSCursor arrowCursor];
-                               break;
-               };
-       }
-       [tmpCursor set];
-       [pool drain];
-}
-
-
-
-GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
-{
-       if ([m_window isVisible]) {
-               loadCursor(visible, getCursorShape());
-       }
-       
-       return GHOST_kSuccess;
-}
-
-
+                       case GHOST_kStandardCursorDefault:\r
+                       default:\r
+                               tmpCursor = [NSCursor arrowCursor];\r
+                               break;\r
+               };\r
+       }\r
+       [tmpCursor set];\r
+       [pool drain];\r
+}\r
+\r
+\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)\r
+{\r
+       if ([m_window isVisible]) {\r
+               loadCursor(visible, getCursorShape());\r
+       }\r
+       \r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
 GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
-{
+{\r
        GHOST_TSuccess err = GHOST_kSuccess;
-       
+       \r
        if (mode != GHOST_kGrabDisable)
-       {
-               //No need to perform grab without warp as it is always on in OS X
+       {\r
+               //No need to perform grab without warp as it is always on in OS X\r
                if(mode != GHOST_kGrabNormal) {
-                       GHOST_TInt32 x_old,y_old;
+                       GHOST_TInt32 x_old,y_old;\r
                        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-                       m_systemCocoa->getCursorPosition(x_old,y_old);
+\r
+                       m_systemCocoa->getCursorPosition(x_old,y_old);\r
                        screenToClient(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
-                       //Warp position is stored in client (window base) coordinates
+                       //Warp position is stored in client (window base) coordinates\r
                        setCursorGrabAccum(0, 0);
                        
                        if(mode == GHOST_kGrabHide) {
@@ -1127,128 +1127,128 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
                        err = CGAssociateMouseAndMouseCursorPosition(false) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
                        
                        [pool drain];
-               }
-       }
-       else {
+               }\r
+       }\r
+       else {\r
                if(m_cursorGrab==GHOST_kGrabHide)
                {
                        //No need to set again cursor position, as it has not changed for Cocoa
-                       setWindowCursorVisibility(true);
-               }
+                       setWindowCursorVisibility(true);\r
+               }\r
                
                err = CGAssociateMouseAndMouseCursorPosition(true) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
                /* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */
                setCursorGrabAccum(0, 0);
                m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; /* disable */
-       }
+       }\r
        return err;
-}
-       
-GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape)
-{
-       if (m_customCursor) {
-               [m_customCursor release];
-               m_customCursor = nil;
-       }
-
-       if ([m_window isVisible]) {
-               loadCursor(getCursorVisibility(), shape);
-       }
-       
-       return GHOST_kSuccess;
-}
-
-/** Reverse the bits in a GHOST_TUns8
-static GHOST_TUns8 uns8ReverseBits(GHOST_TUns8 ch)
-{
-       ch= ((ch>>1)&0x55) | ((ch<<1)&0xAA);
-       ch= ((ch>>2)&0x33) | ((ch<<2)&0xCC);
-       ch= ((ch>>4)&0x0F) | ((ch<<4)&0xF0);
-       return ch;
-}
-*/
-
-
-/** Reverse the bits in a GHOST_TUns16 */
-static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)
-{
-       shrt= ((shrt>>1)&0x5555) | ((shrt<<1)&0xAAAA);
-       shrt= ((shrt>>2)&0x3333) | ((shrt<<2)&0xCCCC);
-       shrt= ((shrt>>4)&0x0F0F) | ((shrt<<4)&0xF0F0);
-       shrt= ((shrt>>8)&0x00FF) | ((shrt<<8)&0xFF00);
-       return shrt;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
-                                       int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)
-{
-       int y,nbUns16;
-       NSPoint hotSpotPoint;
-       NSBitmapImageRep *cursorImageRep;
-       NSImage *cursorImage;
-       NSSize imSize;
-       GHOST_TUns16 *cursorBitmap;
-       
-       
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       if (m_customCursor) {
-               [m_customCursor release];
-               m_customCursor = nil;
-       }
-       
-
-       cursorImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
-                                                                                                                        pixelsWide:sizex
-                                                                                                                        pixelsHigh:sizey
-                                                                                                                 bitsPerSample:1 
-                                                                                                               samplesPerPixel:2
-                                                                                                                          hasAlpha:YES
-                                                                                                                          isPlanar:YES
+}\r
+       \r
+GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape)\r
+{\r
+       if (m_customCursor) {\r
+               [m_customCursor release];\r
+               m_customCursor = nil;\r
+       }\r
+\r
+       if ([m_window isVisible]) {\r
+               loadCursor(getCursorVisibility(), shape);\r
+       }\r
+       \r
+       return GHOST_kSuccess;\r
+}\r
+\r
+/** Reverse the bits in a GHOST_TUns8\r
+static GHOST_TUns8 uns8ReverseBits(GHOST_TUns8 ch)\r
+{\r
+       ch= ((ch>>1)&0x55) | ((ch<<1)&0xAA);\r
+       ch= ((ch>>2)&0x33) | ((ch<<2)&0xCC);\r
+       ch= ((ch>>4)&0x0F) | ((ch<<4)&0xF0);\r
+       return ch;\r
+}\r
+*/\r
+\r
+\r
+/** Reverse the bits in a GHOST_TUns16 */\r
+static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)\r
+{\r
+       shrt= ((shrt>>1)&0x5555) | ((shrt<<1)&0xAAAA);\r
+       shrt= ((shrt>>2)&0x3333) | ((shrt<<2)&0xCCCC);\r
+       shrt= ((shrt>>4)&0x0F0F) | ((shrt<<4)&0xF0F0);\r
+       shrt= ((shrt>>8)&0x00FF) | ((shrt<<8)&0xFF00);\r
+       return shrt;\r
+}\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,\r
+                                       int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)\r
+{\r
+       int y,nbUns16;\r
+       NSPoint hotSpotPoint;\r
+       NSBitmapImageRep *cursorImageRep;\r
+       NSImage *cursorImage;\r
+       NSSize imSize;\r
+       GHOST_TUns16 *cursorBitmap;\r
+       \r
+       \r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       if (m_customCursor) {\r
+               [m_customCursor release];\r
+               m_customCursor = nil;\r
+       }\r
+       \r
+\r
+       cursorImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil\r
+                                                                                                                        pixelsWide:sizex\r
+                                                                                                                        pixelsHigh:sizey\r
+                                                                                                                 bitsPerSample:1 \r
+                                                                                                               samplesPerPixel:2\r
+                                                                                                                          hasAlpha:YES\r
+                                                                                                                          isPlanar:YES\r
                                                                                                                 colorSpaceName:NSDeviceWhiteColorSpace
-                                                                                                                       bytesPerRow:(sizex/8 + (sizex%8 >0 ?1:0))
-                                                                                                                  bitsPerPixel:1];
-       
-       
-       cursorBitmap = (GHOST_TUns16*)[cursorImageRep bitmapData];
-       nbUns16 = [cursorImageRep bytesPerPlane]/2;
-       
-       for (y=0; y<nbUns16; y++) {
-#if !defined(__LITTLE_ENDIAN__)
+                                                                                                                       bytesPerRow:(sizex/8 + (sizex%8 >0 ?1:0))\r
+                                                                                                                  bitsPerPixel:1];\r
+       \r
+       \r
+       cursorBitmap = (GHOST_TUns16*)[cursorImageRep bitmapData];\r
+       nbUns16 = [cursorImageRep bytesPerPlane]/2;\r
+       \r
+       for (y=0; y<nbUns16; y++) {\r
+#if !defined(__LITTLE_ENDIAN__)\r
                cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y]<<0) | (bitmap[2*y+1]<<8));
-               cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y]<<0) | (mask[2*y+1]<<8));
-#else
+               cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y]<<0) | (mask[2*y+1]<<8));\r
+#else\r
                cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y+1]<<0) | (bitmap[2*y]<<8));
-               cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y+1]<<0) | (mask[2*y]<<8));
-#endif
-               
-       }
-       
-       
-       imSize.width = sizex;
-       imSize.height= sizey;
-       cursorImage = [[NSImage alloc] initWithSize:imSize];
-       [cursorImage addRepresentation:cursorImageRep];
-       
-       hotSpotPoint.x = hotX;
-       hotSpotPoint.y = hotY;
-       
-       //foreground and background color parameter is not handled for now (10.6)
-       m_customCursor = [[NSCursor alloc] initWithImage:cursorImage
-                                                                                        hotSpot:hotSpotPoint];
-       
-       [cursorImageRep release];
-       [cursorImage release];
-       
-       if ([m_window isVisible]) {
-               loadCursor(getCursorVisibility(), GHOST_kStandardCursorCustom);
-       }
-       [pool drain];
-       return GHOST_kSuccess;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], 
-                                                                                               GHOST_TUns8 mask[16][2], int hotX, int hotY)
-{
-       return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);
-}
+               cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y+1]<<0) | (mask[2*y]<<8));\r
+#endif\r
+               \r
+       }\r
+       \r
+       \r
+       imSize.width = sizex;\r
+       imSize.height= sizey;\r
+       cursorImage = [[NSImage alloc] initWithSize:imSize];\r
+       [cursorImage addRepresentation:cursorImageRep];\r
+       \r
+       hotSpotPoint.x = hotX;\r
+       hotSpotPoint.y = hotY;\r
+       \r
+       //foreground and background color parameter is not handled for now (10.6)\r
+       m_customCursor = [[NSCursor alloc] initWithImage:cursorImage\r
+                                                                                        hotSpot:hotSpotPoint];\r
+       \r
+       [cursorImageRep release];\r
+       [cursorImage release];\r
+       \r
+       if ([m_window isVisible]) {\r
+               loadCursor(getCursorVisibility(), GHOST_kStandardCursorCustom);\r
+       }\r
+       [pool drain];\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], \r
+                                                                                               GHOST_TUns8 mask[16][2], int hotX, int hotY)\r
+{\r
+       return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);\r
+}\r