merge with trunk/2.5 at r24378
[blender-staging.git] / intern / ghost / intern / GHOST_SystemCocoa.mm
index 73be363dff189756411e54f2dfcf81cbb2cb504e..46d8ecf6f9430f484b62d924ea5b0f6c0d8ad05d 100644 (file)
-/**
- * $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,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 09/2009
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#import <Cocoa/Cocoa.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
-#include "GHOST_SystemCocoa.h"
-
-#include "GHOST_DisplayManagerCocoa.h"
-#include "GHOST_EventKey.h"
-#include "GHOST_EventButton.h"
-#include "GHOST_EventCursor.h"
-#include "GHOST_EventWheel.h"
-#include "GHOST_EventNDOF.h"
-
-#include "GHOST_TimerManager.h"
-#include "GHOST_TimerTask.h"
-#include "GHOST_WindowManager.h"
-#include "GHOST_WindowCocoa.h"
-#include "GHOST_NDOFManager.h"
-#include "AssertMacros.h"
-
-#pragma mark KeyMap, mouse converters
-
-
-/* Keycodes from Carbon include file */
-/*  
- *  Summary:
- *    Virtual keycodes
- *  
- *  Discussion:
- *    These constants are the virtual keycodes defined originally in
- *    Inside Mac Volume V, pg. V-191. They identify physical keys on a
- *    keyboard. Those constants with "ANSI" in the name are labeled
- *    according to the key position on an ANSI-standard US keyboard.
- *    For example, kVK_ANSI_A indicates the virtual keycode for the key
- *    with the letter 'A' in the US keyboard layout. Other keyboard
- *    layouts may have the 'A' key label on a different physical key;
- *    in this case, pressing 'A' will generate a different virtual
- *    keycode.
- */
-enum {
-       kVK_ANSI_A                    = 0x00,
-       kVK_ANSI_S                    = 0x01,
-       kVK_ANSI_D                    = 0x02,
-       kVK_ANSI_F                    = 0x03,
-       kVK_ANSI_H                    = 0x04,
-       kVK_ANSI_G                    = 0x05,
-       kVK_ANSI_Z                    = 0x06,
-       kVK_ANSI_X                    = 0x07,
-       kVK_ANSI_C                    = 0x08,
-       kVK_ANSI_V                    = 0x09,
-       kVK_ANSI_B                    = 0x0B,
-       kVK_ANSI_Q                    = 0x0C,
-       kVK_ANSI_W                    = 0x0D,
-       kVK_ANSI_E                    = 0x0E,
-       kVK_ANSI_R                    = 0x0F,
-       kVK_ANSI_Y                    = 0x10,
-       kVK_ANSI_T                    = 0x11,
-       kVK_ANSI_1                    = 0x12,
-       kVK_ANSI_2                    = 0x13,
-       kVK_ANSI_3                    = 0x14,
-       kVK_ANSI_4                    = 0x15,
-       kVK_ANSI_6                    = 0x16,
-       kVK_ANSI_5                    = 0x17,
-       kVK_ANSI_Equal                = 0x18,
-       kVK_ANSI_9                    = 0x19,
-       kVK_ANSI_7                    = 0x1A,
-       kVK_ANSI_Minus                = 0x1B,
-       kVK_ANSI_8                    = 0x1C,
-       kVK_ANSI_0                    = 0x1D,
-       kVK_ANSI_RightBracket         = 0x1E,
-       kVK_ANSI_O                    = 0x1F,
-       kVK_ANSI_U                    = 0x20,
-       kVK_ANSI_LeftBracket          = 0x21,
-       kVK_ANSI_I                    = 0x22,
-       kVK_ANSI_P                    = 0x23,
-       kVK_ANSI_L                    = 0x25,
-       kVK_ANSI_J                    = 0x26,
-       kVK_ANSI_Quote                = 0x27,
-       kVK_ANSI_K                    = 0x28,
-       kVK_ANSI_Semicolon            = 0x29,
-       kVK_ANSI_Backslash            = 0x2A,
-       kVK_ANSI_Comma                = 0x2B,
-       kVK_ANSI_Slash                = 0x2C,
-       kVK_ANSI_N                    = 0x2D,
-       kVK_ANSI_M                    = 0x2E,
-       kVK_ANSI_Period               = 0x2F,
-       kVK_ANSI_Grave                = 0x32,
-       kVK_ANSI_KeypadDecimal        = 0x41,
-       kVK_ANSI_KeypadMultiply       = 0x43,
-       kVK_ANSI_KeypadPlus           = 0x45,
-       kVK_ANSI_KeypadClear          = 0x47,
-       kVK_ANSI_KeypadDivide         = 0x4B,
-       kVK_ANSI_KeypadEnter          = 0x4C,
-       kVK_ANSI_KeypadMinus          = 0x4E,
-       kVK_ANSI_KeypadEquals         = 0x51,
-       kVK_ANSI_Keypad0              = 0x52,
-       kVK_ANSI_Keypad1              = 0x53,
-       kVK_ANSI_Keypad2              = 0x54,
-       kVK_ANSI_Keypad3              = 0x55,
-       kVK_ANSI_Keypad4              = 0x56,
-       kVK_ANSI_Keypad5              = 0x57,
-       kVK_ANSI_Keypad6              = 0x58,
-       kVK_ANSI_Keypad7              = 0x59,
-       kVK_ANSI_Keypad8              = 0x5B,
-       kVK_ANSI_Keypad9              = 0x5C
-};
-
-/* keycodes for keys that are independent of keyboard layout*/
-enum {
-       kVK_Return                    = 0x24,
-       kVK_Tab                       = 0x30,
-       kVK_Space                     = 0x31,
-       kVK_Delete                    = 0x33,
-       kVK_Escape                    = 0x35,
-       kVK_Command                   = 0x37,
-       kVK_Shift                     = 0x38,
-       kVK_CapsLock                  = 0x39,
-       kVK_Option                    = 0x3A,
-       kVK_Control                   = 0x3B,
-       kVK_RightShift                = 0x3C,
-       kVK_RightOption               = 0x3D,
-       kVK_RightControl              = 0x3E,
-       kVK_Function                  = 0x3F,
-       kVK_F17                       = 0x40,
-       kVK_VolumeUp                  = 0x48,
-       kVK_VolumeDown                = 0x49,
-       kVK_Mute                      = 0x4A,
-       kVK_F18                       = 0x4F,
-       kVK_F19                       = 0x50,
-       kVK_F20                       = 0x5A,
-       kVK_F5                        = 0x60,
-       kVK_F6                        = 0x61,
-       kVK_F7                        = 0x62,
-       kVK_F3                        = 0x63,
-       kVK_F8                        = 0x64,
-       kVK_F9                        = 0x65,
-       kVK_F11                       = 0x67,
-       kVK_F13                       = 0x69,
-       kVK_F16                       = 0x6A,
-       kVK_F14                       = 0x6B,
-       kVK_F10                       = 0x6D,
-       kVK_F12                       = 0x6F,
-       kVK_F15                       = 0x71,
-       kVK_Help                      = 0x72,
-       kVK_Home                      = 0x73,
-       kVK_PageUp                    = 0x74,
-       kVK_ForwardDelete             = 0x75,
-       kVK_F4                        = 0x76,
-       kVK_End                       = 0x77,
-       kVK_F2                        = 0x78,
-       kVK_PageDown                  = 0x79,
-       kVK_F1                        = 0x7A,
-       kVK_LeftArrow                 = 0x7B,
-       kVK_RightArrow                = 0x7C,
-       kVK_DownArrow                 = 0x7D,
-       kVK_UpArrow                   = 0x7E
-};
-
-/* ISO keyboards only*/
-enum {
-       kVK_ISO_Section               = 0x0A
-};
-
-/* JIS keyboards only*/
-enum {
-       kVK_JIS_Yen                   = 0x5D,
-       kVK_JIS_Underscore            = 0x5E,
-       kVK_JIS_KeypadComma           = 0x5F,
-       kVK_JIS_Eisu                  = 0x66,
-       kVK_JIS_Kana                  = 0x68
-};
-
-
-static GHOST_TButtonMask convertButton(int button)
-{
-       switch (button) {
-               case 0:
-                       return GHOST_kButtonMaskLeft;
-               case 1:
-                       return GHOST_kButtonMaskRight;
-               case 2:
-                       return GHOST_kButtonMaskMiddle;
-               case 3:
-                       return GHOST_kButtonMaskButton4;
-               case 4:
-                       return GHOST_kButtonMaskButton5;
-               default:
-                       return GHOST_kButtonMaskLeft;
-       }
-}
-
-/**
- * Converts Mac rawkey codes (same for Cocoa & Carbon)
- * into GHOST key codes
- * @param rawCode The raw physical key code
- * @param recvChar the character ignoring modifiers (except for shift)
- * @return Ghost key code
- */
-static GHOST_TKey convertKey(int rawCode, unichar recvChar) 
-{      
-       
-       //printf("\nrecvchar %c 0x%x",recvChar,recvChar);
-       switch (rawCode) {
-               /*Physical keycodes not used due to map changes in int'l keyboards
-               case kVK_ANSI_A:        return GHOST_kKeyA;
-               case kVK_ANSI_B:        return GHOST_kKeyB;
-               case kVK_ANSI_C:        return GHOST_kKeyC;
-               case kVK_ANSI_D:        return GHOST_kKeyD;
-               case kVK_ANSI_E:        return GHOST_kKeyE;
-               case kVK_ANSI_F:        return GHOST_kKeyF;
-               case kVK_ANSI_G:        return GHOST_kKeyG;
-               case kVK_ANSI_H:        return GHOST_kKeyH;
-               case kVK_ANSI_I:        return GHOST_kKeyI;
-               case kVK_ANSI_J:        return GHOST_kKeyJ;
-               case kVK_ANSI_K:        return GHOST_kKeyK;
-               case kVK_ANSI_L:        return GHOST_kKeyL;
-               case kVK_ANSI_M:        return GHOST_kKeyM;
-               case kVK_ANSI_N:        return GHOST_kKeyN;
-               case kVK_ANSI_O:        return GHOST_kKeyO;
-               case kVK_ANSI_P:        return GHOST_kKeyP;
-               case kVK_ANSI_Q:        return GHOST_kKeyQ;
-               case kVK_ANSI_R:        return GHOST_kKeyR;
-               case kVK_ANSI_S:        return GHOST_kKeyS;
-               case kVK_ANSI_T:        return GHOST_kKeyT;
-               case kVK_ANSI_U:        return GHOST_kKeyU;
-               case kVK_ANSI_V:        return GHOST_kKeyV;
-               case kVK_ANSI_W:        return GHOST_kKeyW;
-               case kVK_ANSI_X:        return GHOST_kKeyX;
-               case kVK_ANSI_Y:        return GHOST_kKeyY;
-               case kVK_ANSI_Z:        return GHOST_kKeyZ;*/
-               
-               /* Numbers keys mapped to handle some int'l keyboard (e.g. French)*/
-               case kVK_ISO_Section: return    GHOST_kKeyUnknown;
-               case kVK_ANSI_1:        return GHOST_kKey1;
-               case kVK_ANSI_2:        return GHOST_kKey2;
-               case kVK_ANSI_3:        return GHOST_kKey3;
-               case kVK_ANSI_4:        return GHOST_kKey4;
-               case kVK_ANSI_5:        return GHOST_kKey5;
-               case kVK_ANSI_6:        return GHOST_kKey6;
-               case kVK_ANSI_7:        return GHOST_kKey7;
-               case kVK_ANSI_8:        return GHOST_kKey8;
-               case kVK_ANSI_9:        return GHOST_kKey9;
-               case kVK_ANSI_0:        return GHOST_kKey0;
-       
-               case kVK_ANSI_Keypad0:                  return GHOST_kKeyNumpad0;
-               case kVK_ANSI_Keypad1:                  return GHOST_kKeyNumpad1;
-               case kVK_ANSI_Keypad2:                  return GHOST_kKeyNumpad2;
-               case kVK_ANSI_Keypad3:                  return GHOST_kKeyNumpad3;
-               case kVK_ANSI_Keypad4:                  return GHOST_kKeyNumpad4;
-               case kVK_ANSI_Keypad5:                  return GHOST_kKeyNumpad5;
-               case kVK_ANSI_Keypad6:                  return GHOST_kKeyNumpad6;
-               case kVK_ANSI_Keypad7:                  return GHOST_kKeyNumpad7;
-               case kVK_ANSI_Keypad8:                  return GHOST_kKeyNumpad8;
-               case kVK_ANSI_Keypad9:                  return GHOST_kKeyNumpad9;
-               case kVK_ANSI_KeypadDecimal:    return GHOST_kKeyNumpadPeriod;
-               case kVK_ANSI_KeypadEnter:              return GHOST_kKeyNumpadEnter;
-               case kVK_ANSI_KeypadPlus:               return GHOST_kKeyNumpadPlus;
-               case kVK_ANSI_KeypadMinus:              return GHOST_kKeyNumpadMinus;
-               case kVK_ANSI_KeypadMultiply:   return GHOST_kKeyNumpadAsterisk;
-               case kVK_ANSI_KeypadDivide:     return GHOST_kKeyNumpadSlash;
-               case kVK_ANSI_KeypadClear:              return GHOST_kKeyUnknown;
-
-               case kVK_F1:                            return GHOST_kKeyF1;
-               case kVK_F2:                            return GHOST_kKeyF2;
-               case kVK_F3:                            return GHOST_kKeyF3;
-               case kVK_F4:                            return GHOST_kKeyF4;
-               case kVK_F5:                            return GHOST_kKeyF5;
-               case kVK_F6:                            return GHOST_kKeyF6;
-               case kVK_F7:                            return GHOST_kKeyF7;
-               case kVK_F8:                            return GHOST_kKeyF8;
-               case kVK_F9:                            return GHOST_kKeyF9;
-               case kVK_F10:                           return GHOST_kKeyF10;
-               case kVK_F11:                           return GHOST_kKeyF11;
-               case kVK_F12:                           return GHOST_kKeyF12;
-               case kVK_F13:                           return GHOST_kKeyF13;
-               case kVK_F14:                           return GHOST_kKeyF14;
-               case kVK_F15:                           return GHOST_kKeyF15;
-               case kVK_F16:                           return GHOST_kKeyF16;
-               case kVK_F17:                           return GHOST_kKeyF17;
-               case kVK_F18:                           return GHOST_kKeyF18;
-               case kVK_F19:                           return GHOST_kKeyF19;
-               case kVK_F20:                           return GHOST_kKeyF20;
-                       
-               case kVK_UpArrow:                       return GHOST_kKeyUpArrow;
-               case kVK_DownArrow:                     return GHOST_kKeyDownArrow;
-               case kVK_LeftArrow:                     return GHOST_kKeyLeftArrow;
-               case kVK_RightArrow:            return GHOST_kKeyRightArrow;
-                       
-               case kVK_Return:                        return GHOST_kKeyEnter;
-               case kVK_Delete:                        return GHOST_kKeyBackSpace;
-               case kVK_ForwardDelete:         return GHOST_kKeyDelete;
-               case kVK_Escape:                        return GHOST_kKeyEsc;
-               case kVK_Tab:                           return GHOST_kKeyTab;
-               case kVK_Space:                         return GHOST_kKeySpace;
-                       
-               case kVK_Home:                          return GHOST_kKeyHome;
-               case kVK_End:                           return GHOST_kKeyEnd;
-               case kVK_PageUp:                        return GHOST_kKeyUpPage;
-               case kVK_PageDown:                      return GHOST_kKeyDownPage;
-                       
-               /*case kVK_ANSI_Minus:          return GHOST_kKeyMinus;
-               case kVK_ANSI_Equal:            return GHOST_kKeyEqual;
-               case kVK_ANSI_Comma:            return GHOST_kKeyComma;
-               case kVK_ANSI_Period:           return GHOST_kKeyPeriod;
-               case kVK_ANSI_Slash:            return GHOST_kKeySlash;
-               case kVK_ANSI_Semicolon:        return GHOST_kKeySemicolon;
-               case kVK_ANSI_Quote:            return GHOST_kKeyQuote;
-               case kVK_ANSI_Backslash:        return GHOST_kKeyBackslash;
-               case kVK_ANSI_LeftBracket:      return GHOST_kKeyLeftBracket;
-               case kVK_ANSI_RightBracket:     return GHOST_kKeyRightBracket;
-               case kVK_ANSI_Grave:            return GHOST_kKeyAccentGrave;*/
-                       
-               case kVK_VolumeUp:
-               case kVK_VolumeDown:
-               case kVK_Mute:
-                       return GHOST_kKeyUnknown;
-                       
-               default:
-                       /*Then detect on character value for "remappable" keys in int'l keyboards*/
-                       if ((recvChar >= 'A') && (recvChar <= 'Z')) {
-                               return (GHOST_TKey) (recvChar - 'A' + GHOST_kKeyA);
-                       } else if ((recvChar >= 'a') && (recvChar <= 'z')) {
-                               return (GHOST_TKey) (recvChar - 'a' + GHOST_kKeyA);
-                       } else
-                       switch (recvChar) {
-                               case '-':       return GHOST_kKeyMinus;
-                               case '=':       return GHOST_kKeyEqual;
-                               case ',':       return GHOST_kKeyComma;
-                               case '.':       return GHOST_kKeyPeriod;
-                               case '/':       return GHOST_kKeySlash;
-                               case ';':       return GHOST_kKeySemicolon;
-                               case '\'':      return GHOST_kKeyQuote;
-                               case '\\':      return GHOST_kKeyBackslash;
-                               case '[':       return GHOST_kKeyLeftBracket;
-                               case ']':       return GHOST_kKeyRightBracket;
-                               case '`':       return GHOST_kKeyAccentGrave;
-                               default:
-                                       return GHOST_kKeyUnknown;
-                       }
-       }
-       return GHOST_kKeyUnknown;
-}
-
-
-#define FIRSTFILEBUFLG 512
-static bool g_hasFirstFile = false;
-static char g_firstFileBuf[512];
-
-//TODO:Need to investigate this. Function called too early in creator.c to have g_hasFirstFile == true
-extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { 
-       if (g_hasFirstFile) {
-               strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1);
-               buf[FIRSTFILEBUFLG - 1] = '\0';
-               return 1;
-       } else {
-               return 0; 
-       }
-}
-
-
-#pragma mark Cocoa objects
-
-/**
- * CocoaAppDelegate
- * ObjC object to capture applicationShouldTerminate, and send quit event
- **/
-@interface CocoaAppDelegate : NSObject {
-       GHOST_SystemCocoa *systemCocoa;
-}
+/**\r
+ * $Id: GHOST_SystemCocoa.mm 23854 2009-10-15 08:27:31Z 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+ *\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 09/2009\r
+ *\r
+ * ***** END GPL LICENSE BLOCK *****\r
+ */\r
+\r
+#import <Cocoa/Cocoa.h>\r
+\r
+#include <sys/time.h>\r
+#include <sys/types.h>\r
+#include <sys/sysctl.h>\r
+\r
+#include "GHOST_SystemCocoa.h"\r
+\r
+#include "GHOST_DisplayManagerCocoa.h"\r
+#include "GHOST_EventKey.h"\r
+#include "GHOST_EventButton.h"\r
+#include "GHOST_EventCursor.h"\r
+#include "GHOST_EventWheel.h"\r
+#include "GHOST_EventNDOF.h"\r
+\r
+#include "GHOST_TimerManager.h"\r
+#include "GHOST_TimerTask.h"\r
+#include "GHOST_WindowManager.h"\r
+#include "GHOST_WindowCocoa.h"\r
+#include "GHOST_NDOFManager.h"\r
+#include "AssertMacros.h"\r
+\r
+#pragma mark KeyMap, mouse converters\r
+\r
+\r
+/* Keycodes from Carbon include file */\r
+/*  \r
+ *  Summary:\r
+ *    Virtual keycodes\r
+ *  \r
+ *  Discussion:\r
+ *    These constants are the virtual keycodes defined originally in\r
+ *    Inside Mac Volume V, pg. V-191. They identify physical keys on a\r
+ *    keyboard. Those constants with "ANSI" in the name are labeled\r
+ *    according to the key position on an ANSI-standard US keyboard.\r
+ *    For example, kVK_ANSI_A indicates the virtual keycode for the key\r
+ *    with the letter 'A' in the US keyboard layout. Other keyboard\r
+ *    layouts may have the 'A' key label on a different physical key;\r
+ *    in this case, pressing 'A' will generate a different virtual\r
+ *    keycode.\r
+ */\r
+enum {\r
+       kVK_ANSI_A                    = 0x00,\r
+       kVK_ANSI_S                    = 0x01,\r
+       kVK_ANSI_D                    = 0x02,\r
+       kVK_ANSI_F                    = 0x03,\r
+       kVK_ANSI_H                    = 0x04,\r
+       kVK_ANSI_G                    = 0x05,\r
+       kVK_ANSI_Z                    = 0x06,\r
+       kVK_ANSI_X                    = 0x07,\r
+       kVK_ANSI_C                    = 0x08,\r
+       kVK_ANSI_V                    = 0x09,\r
+       kVK_ANSI_B                    = 0x0B,\r
+       kVK_ANSI_Q                    = 0x0C,\r
+       kVK_ANSI_W                    = 0x0D,\r
+       kVK_ANSI_E                    = 0x0E,\r
+       kVK_ANSI_R                    = 0x0F,\r
+       kVK_ANSI_Y                    = 0x10,\r
+       kVK_ANSI_T                    = 0x11,\r
+       kVK_ANSI_1                    = 0x12,\r
+       kVK_ANSI_2                    = 0x13,\r
+       kVK_ANSI_3                    = 0x14,\r
+       kVK_ANSI_4                    = 0x15,\r
+       kVK_ANSI_6                    = 0x16,\r
+       kVK_ANSI_5                    = 0x17,\r
+       kVK_ANSI_Equal                = 0x18,\r
+       kVK_ANSI_9                    = 0x19,\r
+       kVK_ANSI_7                    = 0x1A,\r
+       kVK_ANSI_Minus                = 0x1B,\r
+       kVK_ANSI_8                    = 0x1C,\r
+       kVK_ANSI_0                    = 0x1D,\r
+       kVK_ANSI_RightBracket         = 0x1E,\r
+       kVK_ANSI_O                    = 0x1F,\r
+       kVK_ANSI_U                    = 0x20,\r
+       kVK_ANSI_LeftBracket          = 0x21,\r
+       kVK_ANSI_I                    = 0x22,\r
+       kVK_ANSI_P                    = 0x23,\r
+       kVK_ANSI_L                    = 0x25,\r
+       kVK_ANSI_J                    = 0x26,\r
+       kVK_ANSI_Quote                = 0x27,\r
+       kVK_ANSI_K                    = 0x28,\r
+       kVK_ANSI_Semicolon            = 0x29,\r
+       kVK_ANSI_Backslash            = 0x2A,\r
+       kVK_ANSI_Comma                = 0x2B,\r
+       kVK_ANSI_Slash                = 0x2C,\r
+       kVK_ANSI_N                    = 0x2D,\r
+       kVK_ANSI_M                    = 0x2E,\r
+       kVK_ANSI_Period               = 0x2F,\r
+       kVK_ANSI_Grave                = 0x32,\r
+       kVK_ANSI_KeypadDecimal        = 0x41,\r
+       kVK_ANSI_KeypadMultiply       = 0x43,\r
+       kVK_ANSI_KeypadPlus           = 0x45,\r
+       kVK_ANSI_KeypadClear          = 0x47,\r
+       kVK_ANSI_KeypadDivide         = 0x4B,\r
+       kVK_ANSI_KeypadEnter          = 0x4C,\r
+       kVK_ANSI_KeypadMinus          = 0x4E,\r
+       kVK_ANSI_KeypadEquals         = 0x51,\r
+       kVK_ANSI_Keypad0              = 0x52,\r
+       kVK_ANSI_Keypad1              = 0x53,\r
+       kVK_ANSI_Keypad2              = 0x54,\r
+       kVK_ANSI_Keypad3              = 0x55,\r
+       kVK_ANSI_Keypad4              = 0x56,\r
+       kVK_ANSI_Keypad5              = 0x57,\r
+       kVK_ANSI_Keypad6              = 0x58,\r
+       kVK_ANSI_Keypad7              = 0x59,\r
+       kVK_ANSI_Keypad8              = 0x5B,\r
+       kVK_ANSI_Keypad9              = 0x5C\r
+};\r
+\r
+/* keycodes for keys that are independent of keyboard layout*/\r
+enum {\r
+       kVK_Return                    = 0x24,\r
+       kVK_Tab                       = 0x30,\r
+       kVK_Space                     = 0x31,\r
+       kVK_Delete                    = 0x33,\r
+       kVK_Escape                    = 0x35,\r
+       kVK_Command                   = 0x37,\r
+       kVK_Shift                     = 0x38,\r
+       kVK_CapsLock                  = 0x39,\r
+       kVK_Option                    = 0x3A,\r
+       kVK_Control                   = 0x3B,\r
+       kVK_RightShift                = 0x3C,\r
+       kVK_RightOption               = 0x3D,\r
+       kVK_RightControl              = 0x3E,\r
+       kVK_Function                  = 0x3F,\r
+       kVK_F17                       = 0x40,\r
+       kVK_VolumeUp                  = 0x48,\r
+       kVK_VolumeDown                = 0x49,\r
+       kVK_Mute                      = 0x4A,\r
+       kVK_F18                       = 0x4F,\r
+       kVK_F19                       = 0x50,\r
+       kVK_F20                       = 0x5A,\r
+       kVK_F5                        = 0x60,\r
+       kVK_F6                        = 0x61,\r
+       kVK_F7                        = 0x62,\r
+       kVK_F3                        = 0x63,\r
+       kVK_F8                        = 0x64,\r
+       kVK_F9                        = 0x65,\r
+       kVK_F11                       = 0x67,\r
+       kVK_F13                       = 0x69,\r
+       kVK_F16                       = 0x6A,\r
+       kVK_F14                       = 0x6B,\r
+       kVK_F10                       = 0x6D,\r
+       kVK_F12                       = 0x6F,\r
+       kVK_F15                       = 0x71,\r
+       kVK_Help                      = 0x72,\r
+       kVK_Home                      = 0x73,\r
+       kVK_PageUp                    = 0x74,\r
+       kVK_ForwardDelete             = 0x75,\r
+       kVK_F4                        = 0x76,\r
+       kVK_End                       = 0x77,\r
+       kVK_F2                        = 0x78,\r
+       kVK_PageDown                  = 0x79,\r
+       kVK_F1                        = 0x7A,\r
+       kVK_LeftArrow                 = 0x7B,\r
+       kVK_RightArrow                = 0x7C,\r
+       kVK_DownArrow                 = 0x7D,\r
+       kVK_UpArrow                   = 0x7E\r
+};\r
+\r
+/* ISO keyboards only*/\r
+enum {\r
+       kVK_ISO_Section               = 0x0A\r
+};\r
+\r
+/* JIS keyboards only*/\r
+enum {\r
+       kVK_JIS_Yen                   = 0x5D,\r
+       kVK_JIS_Underscore            = 0x5E,\r
+       kVK_JIS_KeypadComma           = 0x5F,\r
+       kVK_JIS_Eisu                  = 0x66,\r
+       kVK_JIS_Kana                  = 0x68\r
+};\r
+\r
+\r
+static GHOST_TButtonMask convertButton(int button)\r
+{\r
+       switch (button) {\r
+               case 0:\r
+                       return GHOST_kButtonMaskLeft;\r
+               case 1:\r
+                       return GHOST_kButtonMaskRight;\r
+               case 2:\r
+                       return GHOST_kButtonMaskMiddle;\r
+               case 3:\r
+                       return GHOST_kButtonMaskButton4;\r
+               case 4:\r
+                       return GHOST_kButtonMaskButton5;\r
+               default:\r
+                       return GHOST_kButtonMaskLeft;\r
+       }\r
+}\r
+\r
+/**\r
+ * Converts Mac rawkey codes (same for Cocoa & Carbon)\r
+ * into GHOST key codes\r
+ * @param rawCode The raw physical key code\r
+ * @param recvChar the character ignoring modifiers (except for shift)\r
+ * @return Ghost key code\r
+ */\r
+static GHOST_TKey convertKey(int rawCode, unichar recvChar) \r
+{      \r
+       \r
+       //printf("\nrecvchar %c 0x%x",recvChar,recvChar);\r
+       switch (rawCode) {\r
+               /*Physical keycodes not used due to map changes in int'l keyboards\r
+               case kVK_ANSI_A:        return GHOST_kKeyA;\r
+               case kVK_ANSI_B:        return GHOST_kKeyB;\r
+               case kVK_ANSI_C:        return GHOST_kKeyC;\r
+               case kVK_ANSI_D:        return GHOST_kKeyD;\r
+               case kVK_ANSI_E:        return GHOST_kKeyE;\r
+               case kVK_ANSI_F:        return GHOST_kKeyF;\r
+               case kVK_ANSI_G:        return GHOST_kKeyG;\r
+               case kVK_ANSI_H:        return GHOST_kKeyH;\r
+               case kVK_ANSI_I:        return GHOST_kKeyI;\r
+               case kVK_ANSI_J:        return GHOST_kKeyJ;\r
+               case kVK_ANSI_K:        return GHOST_kKeyK;\r
+               case kVK_ANSI_L:        return GHOST_kKeyL;\r
+               case kVK_ANSI_M:        return GHOST_kKeyM;\r
+               case kVK_ANSI_N:        return GHOST_kKeyN;\r
+               case kVK_ANSI_O:        return GHOST_kKeyO;\r
+               case kVK_ANSI_P:        return GHOST_kKeyP;\r
+               case kVK_ANSI_Q:        return GHOST_kKeyQ;\r
+               case kVK_ANSI_R:        return GHOST_kKeyR;\r
+               case kVK_ANSI_S:        return GHOST_kKeyS;\r
+               case kVK_ANSI_T:        return GHOST_kKeyT;\r
+               case kVK_ANSI_U:        return GHOST_kKeyU;\r
+               case kVK_ANSI_V:        return GHOST_kKeyV;\r
+               case kVK_ANSI_W:        return GHOST_kKeyW;\r
+               case kVK_ANSI_X:        return GHOST_kKeyX;\r
+               case kVK_ANSI_Y:        return GHOST_kKeyY;\r
+               case kVK_ANSI_Z:        return GHOST_kKeyZ;*/\r
+               \r
+               /* Numbers keys mapped to handle some int'l keyboard (e.g. French)*/\r
+               case kVK_ISO_Section: return    GHOST_kKeyUnknown;\r
+               case kVK_ANSI_1:        return GHOST_kKey1;\r
+               case kVK_ANSI_2:        return GHOST_kKey2;\r
+               case kVK_ANSI_3:        return GHOST_kKey3;\r
+               case kVK_ANSI_4:        return GHOST_kKey4;\r
+               case kVK_ANSI_5:        return GHOST_kKey5;\r
+               case kVK_ANSI_6:        return GHOST_kKey6;\r
+               case kVK_ANSI_7:        return GHOST_kKey7;\r
+               case kVK_ANSI_8:        return GHOST_kKey8;\r
+               case kVK_ANSI_9:        return GHOST_kKey9;\r
+               case kVK_ANSI_0:        return GHOST_kKey0;\r
+       \r
+               case kVK_ANSI_Keypad0:                  return GHOST_kKeyNumpad0;\r
+               case kVK_ANSI_Keypad1:                  return GHOST_kKeyNumpad1;\r
+               case kVK_ANSI_Keypad2:                  return GHOST_kKeyNumpad2;\r
+               case kVK_ANSI_Keypad3:                  return GHOST_kKeyNumpad3;\r
+               case kVK_ANSI_Keypad4:                  return GHOST_kKeyNumpad4;\r
+               case kVK_ANSI_Keypad5:                  return GHOST_kKeyNumpad5;\r
+               case kVK_ANSI_Keypad6:                  return GHOST_kKeyNumpad6;\r
+               case kVK_ANSI_Keypad7:                  return GHOST_kKeyNumpad7;\r
+               case kVK_ANSI_Keypad8:                  return GHOST_kKeyNumpad8;\r
+               case kVK_ANSI_Keypad9:                  return GHOST_kKeyNumpad9;\r
+               case kVK_ANSI_KeypadDecimal:    return GHOST_kKeyNumpadPeriod;\r
+               case kVK_ANSI_KeypadEnter:              return GHOST_kKeyNumpadEnter;\r
+               case kVK_ANSI_KeypadPlus:               return GHOST_kKeyNumpadPlus;\r
+               case kVK_ANSI_KeypadMinus:              return GHOST_kKeyNumpadMinus;\r
+               case kVK_ANSI_KeypadMultiply:   return GHOST_kKeyNumpadAsterisk;\r
+               case kVK_ANSI_KeypadDivide:     return GHOST_kKeyNumpadSlash;\r
+               case kVK_ANSI_KeypadClear:              return GHOST_kKeyUnknown;\r
+\r
+               case kVK_F1:                            return GHOST_kKeyF1;\r
+               case kVK_F2:                            return GHOST_kKeyF2;\r
+               case kVK_F3:                            return GHOST_kKeyF3;\r
+               case kVK_F4:                            return GHOST_kKeyF4;\r
+               case kVK_F5:                            return GHOST_kKeyF5;\r
+               case kVK_F6:                            return GHOST_kKeyF6;\r
+               case kVK_F7:                            return GHOST_kKeyF7;\r
+               case kVK_F8:                            return GHOST_kKeyF8;\r
+               case kVK_F9:                            return GHOST_kKeyF9;\r
+               case kVK_F10:                           return GHOST_kKeyF10;\r
+               case kVK_F11:                           return GHOST_kKeyF11;\r
+               case kVK_F12:                           return GHOST_kKeyF12;\r
+               case kVK_F13:                           return GHOST_kKeyF13;\r
+               case kVK_F14:                           return GHOST_kKeyF14;\r
+               case kVK_F15:                           return GHOST_kKeyF15;\r
+               case kVK_F16:                           return GHOST_kKeyF16;\r
+               case kVK_F17:                           return GHOST_kKeyF17;\r
+               case kVK_F18:                           return GHOST_kKeyF18;\r
+               case kVK_F19:                           return GHOST_kKeyF19;\r
+               case kVK_F20:                           return GHOST_kKeyF20;\r
+                       \r
+               case kVK_UpArrow:                       return GHOST_kKeyUpArrow;\r
+               case kVK_DownArrow:                     return GHOST_kKeyDownArrow;\r
+               case kVK_LeftArrow:                     return GHOST_kKeyLeftArrow;\r
+               case kVK_RightArrow:            return GHOST_kKeyRightArrow;\r
+                       \r
+               case kVK_Return:                        return GHOST_kKeyEnter;\r
+               case kVK_Delete:                        return GHOST_kKeyBackSpace;\r
+               case kVK_ForwardDelete:         return GHOST_kKeyDelete;\r
+               case kVK_Escape:                        return GHOST_kKeyEsc;\r
+               case kVK_Tab:                           return GHOST_kKeyTab;\r
+               case kVK_Space:                         return GHOST_kKeySpace;\r
+                       \r
+               case kVK_Home:                          return GHOST_kKeyHome;\r
+               case kVK_End:                           return GHOST_kKeyEnd;\r
+               case kVK_PageUp:                        return GHOST_kKeyUpPage;\r
+               case kVK_PageDown:                      return GHOST_kKeyDownPage;\r
+                       \r
+               /*case kVK_ANSI_Minus:          return GHOST_kKeyMinus;\r
+               case kVK_ANSI_Equal:            return GHOST_kKeyEqual;\r
+               case kVK_ANSI_Comma:            return GHOST_kKeyComma;\r
+               case kVK_ANSI_Period:           return GHOST_kKeyPeriod;\r
+               case kVK_ANSI_Slash:            return GHOST_kKeySlash;\r
+               case kVK_ANSI_Semicolon:        return GHOST_kKeySemicolon;\r
+               case kVK_ANSI_Quote:            return GHOST_kKeyQuote;\r
+               case kVK_ANSI_Backslash:        return GHOST_kKeyBackslash;\r
+               case kVK_ANSI_LeftBracket:      return GHOST_kKeyLeftBracket;\r
+               case kVK_ANSI_RightBracket:     return GHOST_kKeyRightBracket;\r
+               case kVK_ANSI_Grave:            return GHOST_kKeyAccentGrave;*/\r
+                       \r
+               case kVK_VolumeUp:\r
+               case kVK_VolumeDown:\r
+               case kVK_Mute:\r
+                       return GHOST_kKeyUnknown;\r
+                       \r
+               default:\r
+                       /*Then detect on character value for "remappable" keys in int'l keyboards*/\r
+                       if ((recvChar >= 'A') && (recvChar <= 'Z')) {\r
+                               return (GHOST_TKey) (recvChar - 'A' + GHOST_kKeyA);\r
+                       } else if ((recvChar >= 'a') && (recvChar <= 'z')) {\r
+                               return (GHOST_TKey) (recvChar - 'a' + GHOST_kKeyA);\r
+                       } else\r
+                       switch (recvChar) {\r
+                               case '-':       return GHOST_kKeyMinus;\r
+                               case '=':       return GHOST_kKeyEqual;\r
+                               case ',':       return GHOST_kKeyComma;\r
+                               case '.':       return GHOST_kKeyPeriod;\r
+                               case '/':       return GHOST_kKeySlash;\r
+                               case ';':       return GHOST_kKeySemicolon;\r
+                               case '\'':      return GHOST_kKeyQuote;\r
+                               case '\\':      return GHOST_kKeyBackslash;\r
+                               case '[':       return GHOST_kKeyLeftBracket;\r
+                               case ']':       return GHOST_kKeyRightBracket;\r
+                               case '`':       return GHOST_kKeyAccentGrave;\r
+                               default:\r
+                                       return GHOST_kKeyUnknown;\r
+                       }\r
+       }\r
+       return GHOST_kKeyUnknown;\r
+}\r
+\r
+\r
+#define FIRSTFILEBUFLG 512\r
+static bool g_hasFirstFile = false;\r
+static char g_firstFileBuf[512];\r
+\r
+//TODO:Need to investigate this. Function called too early in creator.c to have g_hasFirstFile == true\r
+extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { \r
+       if (g_hasFirstFile) {\r
+               strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1);\r
+               buf[FIRSTFILEBUFLG - 1] = '\0';\r
+               return 1;\r
+       } else {\r
+               return 0; \r
+       }\r
+}\r
+\r
+\r
+#pragma mark Cocoa objects\r
+\r
+/**\r
+ * CocoaAppDelegate\r
+ * ObjC object to capture applicationShouldTerminate, and send quit event\r
+ **/\r
+@interface CocoaAppDelegate : NSObject {\r
+       GHOST_SystemCocoa *systemCocoa;\r
+}\r
 - (void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa;
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
 - (void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa;
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
-- (void)applicationWillTerminate:(NSNotification *)aNotification;
-@end
-
-@implementation CocoaAppDelegate : NSObject
--(void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa
-{
-       systemCocoa = sysCocoa;
-}
-
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;\r
+- (void)applicationWillTerminate:(NSNotification *)aNotification;\r
+@end\r
+\r
+@implementation CocoaAppDelegate : NSObject\r
+-(void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa\r
+{\r
+       systemCocoa = sysCocoa;\r
+}\r
+\r
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
 {
        NSLog(@"\nGet open file event from cocoa : %@",filename);
        return YES;
 }
 
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
 {
        NSLog(@"\nGet open file event from cocoa : %@",filename);
        return YES;
 }
 
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
-{
-       //TODO: implement graceful termination through Cocoa mechanism to avoid session log off to be cancelled
-       //Note that Cmd+Q is already handled by keyhandler
-    if (systemCocoa->handleQuitRequest() == GHOST_kExitNow)
-               return NSTerminateCancel;//NSTerminateNow;
-       else
-               return NSTerminateCancel;
-}
-
-// To avoid cancelling a log off process, we must use Cocoa termination process
-// And this function is the only chance to perform clean up
-// So WM_exit needs to be called directly, as the event loop will never run before termination
-- (void)applicationWillTerminate:(NSNotification *)aNotification
-{
-       /*G.afbreek = 0; //Let Cocoa perform the termination at the end
-       WM_exit(C);*/
-}
-@end
-
-
-
-#pragma mark initialization/finalization
-
-
-GHOST_SystemCocoa::GHOST_SystemCocoa()
-{
-       m_modifierMask =0;
-       m_pressedMouseButtons =0;
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender\r
+{\r
+       //TODO: implement graceful termination through Cocoa mechanism to avoid session log off to be cancelled\r
+       //Note that Cmd+Q is already handled by keyhandler\r
+    if (systemCocoa->handleQuitRequest() == GHOST_kExitNow)\r
+               return NSTerminateCancel;//NSTerminateNow;\r
+       else\r
+               return NSTerminateCancel;\r
+}\r
+\r
+// To avoid cancelling a log off process, we must use Cocoa termination process\r
+// And this function is the only chance to perform clean up\r
+// So WM_exit needs to be called directly, as the event loop will never run before termination\r
+- (void)applicationWillTerminate:(NSNotification *)aNotification\r
+{\r
+       /*G.afbreek = 0; //Let Cocoa perform the termination at the end\r
+       WM_exit(C);*/\r
+}\r
+@end\r
+\r
+\r
+\r
+#pragma mark initialization/finalization\r
+\r
+\r
+GHOST_SystemCocoa::GHOST_SystemCocoa()\r
+{\r
+       m_modifierMask =0;\r
+       m_pressedMouseButtons =0;\r
        m_cursorDelta_x=0;
        m_cursorDelta_y=0;
        m_cursorDelta_x=0;
        m_cursorDelta_y=0;
-       m_displayManager = new GHOST_DisplayManagerCocoa ();
-       GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");
-       m_displayManager->initialize();
-
-       //NSEvent timeStamp is given in system uptime, state start date is boot time
-       //FIXME : replace by Cocoa equivalent
-       int mib[2];
-       struct timeval boottime;
-       size_t len;
-       
-       mib[0] = CTL_KERN;
-       mib[1] = KERN_BOOTTIME;
-       len = sizeof(struct timeval);
-       
-       sysctl(mib, 2, &boottime, &len, NULL, 0);
-       m_start_time = ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));
-       
-       m_ignoreWindowSizedMessages = false;
-}
-
-GHOST_SystemCocoa::~GHOST_SystemCocoa()
-{
-}
-
-
-GHOST_TSuccess GHOST_SystemCocoa::init()
-{
-       
-    GHOST_TSuccess success = GHOST_System::init();
-    if (success) {
-               //ProcessSerialNumber psn;
-               
-               //Carbon stuff to move window & menu to foreground
-               /*if (!GetCurrentProcess(&psn)) {
-                       TransformProcessType(&psn, kProcessTransformToForegroundApplication);
-                       SetFrontProcess(&psn);
-               }*/
-               
-               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-               if (NSApp == nil) {
-                       [NSApplication sharedApplication];
-                       
-                       if ([NSApp mainMenu] == nil) {
-                               NSMenu *mainMenubar = [[NSMenu alloc] init];
-                               NSMenuItem *menuItem;
-                               NSMenu *windowMenu;
-                               NSMenu *appMenu;
-                               
-                               //Create the application menu
-                               appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];
-                               
-                               [appMenu addItemWithTitle:@"About Blender" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
-                               [appMenu addItem:[NSMenuItem separatorItem]];
-                               
-                               menuItem = [appMenu addItemWithTitle:@"Hide Blender" action:@selector(hide:) keyEquivalent:@"h"];
-                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
-                                
-                               menuItem = [appMenu addItemWithTitle:@"Hide others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
-                               [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];
-                               
-                               [appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
-                               
-                               menuItem = [appMenu addItemWithTitle:@"Quit Blender" action:@selector(terminate:) keyEquivalent:@"q"];
-                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
-                               
-                               menuItem = [[NSMenuItem alloc] init];
-                               [menuItem setSubmenu:appMenu];
-                               
-                               [mainMenubar addItem:menuItem];
-                               [menuItem release];
-                               [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; //Needed for 10.5
-                               [appMenu release];
-                               
-                               //Create the window menu
-                               windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
-                               
-                               menuItem = [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
-                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
-                               
-                               [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
-                               
-                               menuItem = [[NSMenuItem alloc] init];
-                               [menuItem setSubmenu:windowMenu];
-                               
-                               [mainMenubar addItem:menuItem];
-                               [menuItem release];
-                               
-                               [NSApp setMainMenu:mainMenubar];
-                               [NSApp setWindowsMenu:windowMenu];
-                               [windowMenu release];
-                       }
-               }
-               if ([NSApp delegate] == nil) {
-                       CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init];
-                       [appDelegate setSystemCocoa:this];
-                       [NSApp setDelegate:appDelegate];
-               }
+       m_displayManager = new GHOST_DisplayManagerCocoa ();\r
+       GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");\r
+       m_displayManager->initialize();\r
+\r
+       //NSEvent timeStamp is given in system uptime, state start date is boot time\r
+       //FIXME : replace by Cocoa equivalent\r
+       int mib[2];\r
+       struct timeval boottime;\r
+       size_t len;\r
+       \r
+       mib[0] = CTL_KERN;\r
+       mib[1] = KERN_BOOTTIME;\r
+       len = sizeof(struct timeval);\r
+       \r
+       sysctl(mib, 2, &boottime, &len, NULL, 0);\r
+       m_start_time = ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));\r
+       \r
+       m_ignoreWindowSizedMessages = false;\r
+}\r
+\r
+GHOST_SystemCocoa::~GHOST_SystemCocoa()\r
+{\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::init()\r
+{\r
+       \r
+    GHOST_TSuccess success = GHOST_System::init();\r
+    if (success) {\r
+               //ProcessSerialNumber psn;\r
+               \r
+               //Carbon stuff to move window & menu to foreground\r
+               /*if (!GetCurrentProcess(&psn)) {\r
+                       TransformProcessType(&psn, kProcessTransformToForegroundApplication);\r
+                       SetFrontProcess(&psn);\r
+               }*/\r
+               \r
+               NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+               if (NSApp == nil) {\r
+                       [NSApplication sharedApplication];\r
+                       \r
+                       if ([NSApp mainMenu] == nil) {\r
+                               NSMenu *mainMenubar = [[NSMenu alloc] init];\r
+                               NSMenuItem *menuItem;\r
+                               NSMenu *windowMenu;\r
+                               NSMenu *appMenu;\r
+                               \r
+                               //Create the application menu\r
+                               appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];\r
+                               \r
+                               [appMenu addItemWithTitle:@"About Blender" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];\r
+                               [appMenu addItem:[NSMenuItem separatorItem]];\r
+                               \r
+                               menuItem = [appMenu addItemWithTitle:@"Hide Blender" action:@selector(hide:) keyEquivalent:@"h"];\r
+                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
+                                \r
+                               menuItem = [appMenu addItemWithTitle:@"Hide others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];\r
+                               [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];\r
+                               \r
+                               [appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];\r
+                               \r
+                               menuItem = [appMenu addItemWithTitle:@"Quit Blender" action:@selector(terminate:) keyEquivalent:@"q"];\r
+                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
+                               \r
+                               menuItem = [[NSMenuItem alloc] init];\r
+                               [menuItem setSubmenu:appMenu];\r
+                               \r
+                               [mainMenubar addItem:menuItem];\r
+                               [menuItem release];\r
+                               [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; //Needed for 10.5\r
+                               [appMenu release];\r
+                               \r
+                               //Create the window menu\r
+                               windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];\r
+                               \r
+                               menuItem = [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];\r
+                               [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
+                               \r
+                               [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];\r
+                               \r
+                               menuItem = [[NSMenuItem alloc] init];\r
+                               [menuItem setSubmenu:windowMenu];\r
+                               \r
+                               [mainMenubar addItem:menuItem];\r
+                               [menuItem release];\r
+                               \r
+                               [NSApp setMainMenu:mainMenubar];\r
+                               [NSApp setWindowsMenu:windowMenu];\r
+                               [windowMenu release];\r
+                       }\r
+               }\r
+               if ([NSApp delegate] == nil) {\r
+                       CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init];\r
+                       [appDelegate setSystemCocoa:this];\r
+                       [NSApp setDelegate:appDelegate];\r
+               }\r
                
                [NSApp finishLaunching];
                
                [NSApp finishLaunching];
-                               
-               [pool drain];
-    }
-    return success;
-}
-
-
-#pragma mark window management
-
-GHOST_TUns64 GHOST_SystemCocoa::getMilliSeconds() const
-{
-       //Cocoa equivalent exists in 10.6 ([[NSProcessInfo processInfo] systemUptime])
-       int mib[2];
-       struct timeval boottime;
-       size_t len;
-       
-       mib[0] = CTL_KERN;
-       mib[1] = KERN_BOOTTIME;
-       len = sizeof(struct timeval);
-       
-       sysctl(mib, 2, &boottime, &len, NULL, 0);
-
-       return ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));
-}
-
-
-GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const
-{
-       //Note that OS X supports monitor hot plug
-       // We do not support multiple monitors at the moment
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-       GHOST_TUns8 count = [[NSScreen screens] count];
-
-       [pool drain];
-       return count;
-}
-
-
-void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const
-{
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       //Get visible frame, that is frame excluding dock and top menu bar
-       NSRect frame = [[NSScreen mainScreen] visibleFrame];
-       
-       //Returns max window contents (excluding title bar...)
-       NSRect contentRect = [NSWindow contentRectForFrameRect:frame
-                                                                                                styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)];
-       
-       width = contentRect.size.width;
-       height = contentRect.size.height;
-
-       [pool drain];
-}
-
-
-GHOST_IWindow* GHOST_SystemCocoa::createWindow(
-       const STR_String& title, 
-       GHOST_TInt32 left,
-       GHOST_TInt32 top,
-       GHOST_TUns32 width,
-       GHOST_TUns32 height,
-       GHOST_TWindowState state,
-       GHOST_TDrawingContextType type,
-       bool stereoVisual,
-       const GHOST_TEmbedderWindowID parentWindow
-)
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       GHOST_IWindow* window = 0;
-       
-       //Get the available rect for including window contents
-       NSRect frame = [[NSScreen mainScreen] visibleFrame];
-       NSRect contentRect = [NSWindow contentRectForFrameRect:frame
-                                                                                                styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)];
-       
-       //Ensures window top left is inside this available rect
-       left = left > contentRect.origin.x ? left : contentRect.origin.x;
-       top = top > contentRect.origin.y ? top : contentRect.origin.y;
-       
-       window = new GHOST_WindowCocoa (this, title, left, top, width, height, state, type);
-
-    if (window) {
-        if (window->getValid()) {
-            // Store the pointer to the window 
-            GHOST_ASSERT(m_windowManager, "m_windowManager not initialized");
-            m_windowManager->addWindow(window);
-            m_windowManager->setActiveWindow(window);
-                       //Need to tell window manager the new window is the active one (Cocoa does not send the event activate upon window creation)
-            pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window));
-                       pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));
-
-        }
-        else {
-                       GHOST_PRINT("GHOST_SystemCocoa::createWindow(): window invalid\n");
-            delete window;
-            window = 0;
-        }
-    }
-       else {
-               GHOST_PRINT("GHOST_SystemCocoa::createWindow(): could not create window\n");
-       }
-       [pool drain];
-    return window;
-}
-
-GHOST_TSuccess GHOST_SystemCocoa::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window, const bool stereoVisual)
-{      
-       GHOST_IWindow* currentWindow = m_windowManager->getActiveWindow();
-
-       *window = currentWindow;
-       
-       return currentWindow->setState(GHOST_kWindowStateFullScreen);
-}
-
-GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void)
-{      
-       GHOST_IWindow* currentWindow = m_windowManager->getActiveWindow();
-       
-       return currentWindow->setState(GHOST_kWindowStateNormal);
-}
-
-
-       
+                               \r
+               [pool drain];\r
+    }\r
+    return success;\r
+}\r
+\r
+\r
+#pragma mark window management\r
+\r
+GHOST_TUns64 GHOST_SystemCocoa::getMilliSeconds() const\r
+{\r
+       //Cocoa equivalent exists in 10.6 ([[NSProcessInfo processInfo] systemUptime])\r
+       int mib[2];\r
+       struct timeval boottime;\r
+       size_t len;\r
+       \r
+       mib[0] = CTL_KERN;\r
+       mib[1] = KERN_BOOTTIME;\r
+       len = sizeof(struct timeval);\r
+       \r
+       sysctl(mib, 2, &boottime, &len, NULL, 0);\r
+\r
+       return ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));\r
+}\r
+\r
+\r
+GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const\r
+{\r
+       //Note that OS X supports monitor hot plug\r
+       // We do not support multiple monitors at the moment\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+\r
+       GHOST_TUns8 count = [[NSScreen screens] count];\r
+\r
+       [pool drain];\r
+       return count;\r
+}\r
+\r
+\r
+void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const\r
+{\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       //Get visible frame, that is frame excluding dock and top menu bar\r
+       NSRect frame = [[NSScreen mainScreen] visibleFrame];\r
+       \r
+       //Returns max window contents (excluding title bar...)\r
+       NSRect contentRect = [NSWindow contentRectForFrameRect:frame\r
+                                                                                                styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)];\r
+       \r
+       width = contentRect.size.width;\r
+       height = contentRect.size.height;\r
+\r
+       [pool drain];\r
+}\r
+\r
+\r
+GHOST_IWindow* GHOST_SystemCocoa::createWindow(\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
+       bool stereoVisual,\r
+       const GHOST_TEmbedderWindowID parentWindow\r
+)\r
+{\r
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       GHOST_IWindow* window = 0;\r
+       \r
+       //Get the available rect for including window contents\r
+       NSRect frame = [[NSScreen mainScreen] visibleFrame];\r
+       NSRect contentRect = [NSWindow contentRectForFrameRect:frame\r
+                                                                                                styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)];\r
+       \r
+       //Ensures window top left is inside this available rect\r
+       left = left > contentRect.origin.x ? left : contentRect.origin.x;\r
+       top = top > contentRect.origin.y ? top : contentRect.origin.y;\r
+       \r
+       window = new GHOST_WindowCocoa (this, title, left, top, width, height, state, type);\r
+\r
+    if (window) {\r
+        if (window->getValid()) {\r
+            // Store the pointer to the window \r
+            GHOST_ASSERT(m_windowManager, "m_windowManager not initialized");\r
+            m_windowManager->addWindow(window);\r
+            m_windowManager->setActiveWindow(window);\r
+                       //Need to tell window manager the new window is the active one (Cocoa does not send the event activate upon window creation)\r
+            pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window));\r
+                       pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));\r
+\r
+        }\r
+        else {\r
+                       GHOST_PRINT("GHOST_SystemCocoa::createWindow(): window invalid\n");\r
+            delete window;\r
+            window = 0;\r
+        }\r
+    }\r
+       else {\r
+               GHOST_PRINT("GHOST_SystemCocoa::createWindow(): could not create window\n");\r
+       }\r
+       [pool drain];\r
+    return window;\r
+}\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window, const bool stereoVisual)\r
+{      \r
+       GHOST_IWindow* currentWindow = m_windowManager->getActiveWindow();\r
+\r
+       *window = currentWindow;\r
+       \r
+       return currentWindow->setState(GHOST_kWindowStateFullScreen);\r
+}\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void)\r
+{      \r
+       GHOST_IWindow* currentWindow = m_windowManager->getActiveWindow();\r
+       \r
+       return currentWindow->setState(GHOST_kWindowStateNormal);\r
+}\r
+\r
+\r
+       \r
 /**
  * @note : returns coordinates in Cocoa screen coordinates
  */
 /**
  * @note : returns coordinates in Cocoa screen coordinates
  */
-GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const
-{
-    NSPoint mouseLoc = [NSEvent mouseLocation];
-       
-    // Returns the mouse location in screen coordinates
-    x = (GHOST_TInt32)mouseLoc.x;
-    y = (GHOST_TInt32)mouseLoc.y;
-    return GHOST_kSuccess;
-}
-
+GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const\r
+{\r
+    NSPoint mouseLoc = [NSEvent mouseLocation];\r
+       \r
+    // Returns the mouse location in screen coordinates\r
+    x = (GHOST_TInt32)mouseLoc.x;\r
+    y = (GHOST_TInt32)mouseLoc.y;\r
+    return GHOST_kSuccess;\r
+}\r
+\r
 /**
  * @note : expect Cocoa screen coordinates
  */
 /**
  * @note : expect Cocoa screen coordinates
  */
-GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const
-{
-       float xf=(float)x, yf=(float)y;
+GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const\r
+{\r
+       float xf=(float)x, yf=(float)y;\r
        GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow();
        NSScreen *windowScreen = window->getScreen();
        NSRect screenRect = [windowScreen frame];
        GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow();
        NSScreen *windowScreen = window->getScreen();
        NSRect screenRect = [windowScreen frame];
-       
+       \r
        //Set position relative to current screen
        xf -= screenRect.origin.x;
        yf -= screenRect.origin.y;
        
        //Set position relative to current screen
        xf -= screenRect.origin.x;
        yf -= screenRect.origin.y;
        
-       //Quartz Display Services uses the old coordinates (top left origin)
+       //Quartz Display Services uses the old coordinates (top left origin)\r
        yf = screenRect.size.height -yf;
        yf = screenRect.size.height -yf;
-
+\r
        CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
 
        CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
 
-    return GHOST_kSuccess;
-}
-
-
-GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
-{
-       unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
-       //Direct query to modifierFlags can be used in 10.6
-
-    keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
-    keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
-    keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
-    keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
-       
-    return GHOST_kSuccess;
-}
-
-GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons& buttons) const
-{
-       buttons.clear();
-    buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft);
-       buttons.set(GHOST_kButtonMaskRight, m_pressedMouseButtons & GHOST_kButtonMaskRight);
-       buttons.set(GHOST_kButtonMaskMiddle, m_pressedMouseButtons & GHOST_kButtonMaskMiddle);
-       buttons.set(GHOST_kButtonMaskButton4, m_pressedMouseButtons & GHOST_kButtonMaskButton4);
-       buttons.set(GHOST_kButtonMaskButton5, m_pressedMouseButtons & GHOST_kButtonMaskButton5);
-    return GHOST_kSuccess;
-}
-
-
-
-#pragma mark Event handlers
-
-/**
- * The event queue polling function
- */
-bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
-{
-       bool anyProcessed = false;
-       NSEvent *event;
-       
-       //      SetMouseCoalescingEnabled(false, NULL);
-       //TODO : implement timer ??
-       
-       /*do {
-               GHOST_TimerManager* timerMgr = getTimerManager();
-               
-                if (waitForEvent) {
-                GHOST_TUns64 next = timerMgr->nextFireTime();
-                double timeOut;
-                
-                if (next == GHOST_kFireTimeNever) {
-                timeOut = kEventDurationForever;
-                } else {
-                timeOut = (double)(next - getMilliSeconds())/1000.0;
-                if (timeOut < 0.0)
-                timeOut = 0.0;
-                }
-                
-                ::ReceiveNextEvent(0, NULL, timeOut, false, &event);
-                }
-                
-                if (timerMgr->fireTimers(getMilliSeconds())) {
-                anyProcessed = true;
-                }*/
-               
-               do {
-                       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-                       event = [NSApp nextEventMatchingMask:NSAnyEventMask
-                                                                          untilDate:[NSDate distantPast]
-                                                                                 inMode:NSDefaultRunLoopMode
-                                                                                dequeue:YES];
-                       if (event==nil) {
-                               [pool drain];
-                               break;
-                       }
-                       
-                       anyProcessed = true;
-                       
-                       switch ([event type]) {
-                               case NSKeyDown:
-                               case NSKeyUp:
-                               case NSFlagsChanged:
-                                       handleKeyEvent(event);
-                                       
+    return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const\r
+{\r
+       unsigned int modifiers = [[NSApp currentEvent] modifierFlags];\r
+       //Direct query to modifierFlags can be used in 10.6\r
+\r
+    keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);\r
+    keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);\r
+    keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);\r
+    keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);\r
+       \r
+    return GHOST_kSuccess;\r
+}\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons& buttons) const\r
+{\r
+       buttons.clear();\r
+    buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft);\r
+       buttons.set(GHOST_kButtonMaskRight, m_pressedMouseButtons & GHOST_kButtonMaskRight);\r
+       buttons.set(GHOST_kButtonMaskMiddle, m_pressedMouseButtons & GHOST_kButtonMaskMiddle);\r
+       buttons.set(GHOST_kButtonMaskButton4, m_pressedMouseButtons & GHOST_kButtonMaskButton4);\r
+       buttons.set(GHOST_kButtonMaskButton5, m_pressedMouseButtons & GHOST_kButtonMaskButton5);\r
+    return GHOST_kSuccess;\r
+}\r
+\r
+\r
+\r
+#pragma mark Event handlers\r
+\r
+/**\r
+ * The event queue polling function\r
+ */\r
+bool GHOST_SystemCocoa::processEvents(bool waitForEvent)\r
+{\r
+       bool anyProcessed = false;\r
+       NSEvent *event;\r
+       \r
+       //      SetMouseCoalescingEnabled(false, NULL);\r
+       //TODO : implement timer ??\r
+       \r
+       /*do {\r
+               GHOST_TimerManager* timerMgr = getTimerManager();\r
+               \r
+                if (waitForEvent) {\r
+                GHOST_TUns64 next = timerMgr->nextFireTime();\r
+                double timeOut;\r
+                \r
+                if (next == GHOST_kFireTimeNever) {\r
+                timeOut = kEventDurationForever;\r
+                } else {\r
+                timeOut = (double)(next - getMilliSeconds())/1000.0;\r
+                if (timeOut < 0.0)\r
+                timeOut = 0.0;\r
+                }\r
+                \r
+                ::ReceiveNextEvent(0, NULL, timeOut, false, &event);\r
+                }\r
+                \r
+                if (timerMgr->fireTimers(getMilliSeconds())) {\r
+                anyProcessed = true;\r
+                }*/\r
+               \r
+               do {\r
+                       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];\r
+                       event = [NSApp nextEventMatchingMask:NSAnyEventMask\r
+                                                                          untilDate:[NSDate distantPast]\r
+                                                                                 inMode:NSDefaultRunLoopMode\r
+                                                                                dequeue:YES];\r
+                       if (event==nil) {\r
+                               [pool drain];\r
+                               break;\r
+                       }\r
+                       \r
+                       anyProcessed = true;\r
+                       \r
+                       switch ([event type]) {\r
+                               case NSKeyDown:\r
+                               case NSKeyUp:\r
+                               case NSFlagsChanged:\r
+                                       handleKeyEvent(event);\r
+                                       \r
                                        /* Support system-wide keyboard shortcuts, like Expos√©, ...) =>included in always NSApp sendEvent */
                                        /* Support system-wide keyboard shortcuts, like Expos√©, ...) =>included in always NSApp sendEvent */
-                                       /*              if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) {
-                                        [NSApp sendEvent:event];
-                                        }*/
-                                       break;
-                                       
-                               case NSLeftMouseDown:
-                               case NSLeftMouseUp:
-                               case NSRightMouseDown:
-                               case NSRightMouseUp:
-                               case NSMouseMoved:
-                               case NSLeftMouseDragged:
-                               case NSRightMouseDragged:
-                               case NSScrollWheel:
-                               case NSOtherMouseDown:
-                               case NSOtherMouseUp:
-                               case NSOtherMouseDragged:                               
-                                       handleMouseEvent(event);
-                                       break;
-                                       
-                               case NSTabletPoint:
-                               case NSTabletProximity:
-                                       handleTabletEvent(event,[event type]);
-                                       break;
-                                       
-                                       /* Trackpad features, will need OS X 10.6 for implementation
-                                        case NSEventTypeGesture:
-                                        case NSEventTypeMagnify:
-                                        case NSEventTypeSwipe:
-                                        case NSEventTypeRotate:
-                                        case NSEventTypeBeginGesture:
-                                        case NSEventTypeEndGesture:
-                                        break; */
-                                       
-                                       /*Unused events
-                                        NSMouseEntered       = 8,
-                                        NSMouseExited        = 9,
-                                        NSAppKitDefined      = 13,
-                                        NSSystemDefined      = 14,
-                                        NSApplicationDefined = 15,
-                                        NSPeriodic           = 16,
-                                        NSCursorUpdate       = 17,*/
-                                       
-                               default:
-                                       break;
-                       }
-                       //Resend event to NSApp to ensure Mac wide events are handled
-                       [NSApp sendEvent:event];
-                       [pool drain];
-               } while (event!= nil);          
-       //} while (waitForEvent && !anyProcessed); Needed only for timer implementation
-       
-       
-       
-    return anyProcessed;
-}
-
-//Note: called from NSWindow delegate
-GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)
-{
-       if (!validWindow(window)) {
-               return GHOST_kFailure;
-       }
-               switch(eventType) 
-               {
-                       case GHOST_kEventWindowClose:
-                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window) );
-                               break;
-                       case GHOST_kEventWindowActivate:
-                               m_windowManager->setActiveWindow(window);
-                               window->loadCursor(window->getCursorVisibility(), window->getCursorShape());
-                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window) );
-                               break;
-                       case GHOST_kEventWindowDeactivate:
-                               m_windowManager->setWindowInactive(window);
-                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window) );
-                               break;
-                       case GHOST_kEventWindowUpdate:
-                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) );
-                               break;
-                       case GHOST_kEventWindowSize:
-                               if (!m_ignoreWindowSizedMessages)
-                               {
-                                       window->updateDrawingContext();
-                                       pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) );
-                               }
-                               break;
-                       default:
-                               return GHOST_kFailure;
-                               break;
-               }
-       return GHOST_kSuccess;
-}
-
-GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()
-{
+                                       /*              if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) {\r
+                                        [NSApp sendEvent:event];\r
+                                        }*/\r
+                                       break;\r
+                                       \r
+                               case NSLeftMouseDown:\r
+                               case NSLeftMouseUp:\r
+                               case NSRightMouseDown:\r
+                               case NSRightMouseUp:\r
+                               case NSMouseMoved:\r
+                               case NSLeftMouseDragged:\r
+                               case NSRightMouseDragged:\r
+                               case NSScrollWheel:\r
+                               case NSOtherMouseDown:\r
+                               case NSOtherMouseUp:\r
+                               case NSOtherMouseDragged:                               \r
+                                       handleMouseEvent(event);\r
+                                       break;\r
+                                       \r
+                               case NSTabletPoint:\r
+                               case NSTabletProximity:\r
+                                       handleTabletEvent(event,[event type]);\r
+                                       break;\r
+                                       \r
+                                       /* Trackpad features, will need OS X 10.6 for implementation\r
+                                        case NSEventTypeGesture:\r
+                                        case NSEventTypeMagnify:\r
+                                        case NSEventTypeSwipe:\r
+                                        case NSEventTypeRotate:\r
+                                        case NSEventTypeBeginGesture:\r
+                                        case NSEventTypeEndGesture:\r
+                                        break; */\r
+                                       \r
+                                       /*Unused events\r
+                                        NSMouseEntered       = 8,\r
+                                        NSMouseExited        = 9,\r
+                                        NSAppKitDefined      = 13,\r
+                                        NSSystemDefined      = 14,\r
+                                        NSApplicationDefined = 15,\r
+                                        NSPeriodic           = 16,\r
+                                        NSCursorUpdate       = 17,*/\r
+                                       \r
+                               default:\r
+                                       break;\r
+                       }\r
+                       //Resend event to NSApp to ensure Mac wide events are handled\r
+                       [NSApp sendEvent:event];\r
+                       [pool drain];\r
+               } while (event!= nil);          \r
+       //} while (waitForEvent && !anyProcessed); Needed only for timer implementation\r
+       \r
+       \r
+       \r
+    return anyProcessed;\r
+}\r
+\r
+//Note: called from NSWindow delegate\r
+GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)\r
+{\r
+       if (!validWindow(window)) {\r
+               return GHOST_kFailure;\r
+       }\r
+               switch(eventType) \r
+               {\r
+                       case GHOST_kEventWindowClose:\r
+                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window) );\r
+                               break;\r
+                       case GHOST_kEventWindowActivate:\r
+                               m_windowManager->setActiveWindow(window);\r
+                               window->loadCursor(window->getCursorVisibility(), window->getCursorShape());\r
+                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window) );\r
+                               break;\r
+                       case GHOST_kEventWindowDeactivate:\r
+                               m_windowManager->setWindowInactive(window);\r
+                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window) );\r
+                               break;\r
+                       case GHOST_kEventWindowUpdate:\r
+                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) );\r
+                               break;\r
+                       case GHOST_kEventWindowSize:\r
+                               if (!m_ignoreWindowSizedMessages)\r
+                               {\r
+                                       window->updateDrawingContext();\r
+                                       pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) );\r
+                               }\r
+                               break;\r
+                       default:\r
+                               return GHOST_kFailure;\r
+                               break;\r
+               }\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()\r
+{\r
        GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();
        
        //Discard quit event if we are in cursor grab sequence
        if (window && (window->getCursorGrabMode() != GHOST_kGrabDisable) && (window->getCursorGrabMode() != GHOST_kGrabNormal))
                return GHOST_kExitCancel;
        
        GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();
        
        //Discard quit event if we are in cursor grab sequence
        if (window && (window->getCursorGrabMode() != GHOST_kGrabDisable) && (window->getCursorGrabMode() != GHOST_kGrabNormal))
                return GHOST_kExitCancel;
        
-       //Check open windows if some changes are not saved
-       if (m_windowManager->getAnyModifiedState())
-       {
+       //Check open windows if some changes are not saved\r
+       if (m_windowManager->getAnyModifiedState())\r
+       {\r
                int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved.\nDo you really want to quit ?",
                                                                                 @"Cancel", @"Quit Anyway", nil);
                int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved.\nDo you really want to quit ?",
                                                                                 @"Cancel", @"Quit Anyway", nil);
-               if (shouldQuit == NSAlertAlternateReturn)
-               {
-                       pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );
-                       return GHOST_kExitNow;
+               if (shouldQuit == NSAlertAlternateReturn)\r
+               {\r
+                       pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );\r
+                       return GHOST_kExitNow;\r
                } else {
                        //Give back focus to the blender window if user selected cancel quit
                        NSArray *windowsList = [NSApp orderedWindows];
                        if ([windowsList count]) {
                                [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
                        }
                } else {
                        //Give back focus to the blender window if user selected cancel quit
                        NSArray *windowsList = [NSApp orderedWindows];
                        if ([windowsList count]) {
                                [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
                        }
-               }
-
-       }
-       else {
-               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );
-               return GHOST_kExitNow;
-       }
-       
-       return GHOST_kExitCancel;
-}
-
-
-GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)
-{
-       NSEvent *event = (NSEvent *)eventPtr;
-       GHOST_IWindow* window = m_windowManager->getActiveWindow();
+               }\r
+
+       }\r
+       else {\r
+               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );\r
+               return GHOST_kExitNow;\r
+       }\r
+       \r
+       return GHOST_kExitCancel;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)\r
+{\r
+       NSEvent *event = (NSEvent *)eventPtr;\r
+       GHOST_IWindow* window = m_windowManager->getActiveWindow();\r
        
        if (!window) return GHOST_kFailure;
        
        
        if (!window) return GHOST_kFailure;
        
-       GHOST_TabletData& ct=((GHOST_WindowCocoa*)window)->GetCocoaTabletData();
-       
-       switch (eventType) {
-               case NSTabletPoint:
+       GHOST_TabletData& ct=((GHOST_WindowCocoa*)window)->GetCocoaTabletData();\r
+       \r
+       switch (eventType) {\r
+               case NSTabletPoint:\r
                        ct.Pressure = [event pressure];
                        ct.Pressure = [event pressure];
-                       ct.Xtilt = [event tilt].x;
-                       ct.Ytilt = [event tilt].y;
-                       break;
-               
-               case NSTabletProximity:
-                       ct.Pressure = 0;
-                       ct.Xtilt = 0;
-                       ct.Ytilt = 0;
-                       if ([event isEnteringProximity])
-                       {
-                               //pointer is entering tablet area proximity
-                               switch ([event pointingDeviceType]) {
-                                       case NSPenPointingDevice:
-                                               ct.Active = GHOST_kTabletModeStylus;
-                                               break;
-                                       case NSEraserPointingDevice:
-                                               ct.Active = GHOST_kTabletModeEraser;
-                                               break;
-                                       case NSCursorPointingDevice:
-                                       case NSUnknownPointingDevice:
-                                       default:
-                                               ct.Active = GHOST_kTabletModeNone;
-                                               break;
-                               }
-                       } else {
-                               // pointer is leaving - return to mouse
-                               ct.Active = GHOST_kTabletModeNone;
-                       }
-                       break;
-               
-               default:
-                       GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received");
-                       return GHOST_kFailure;
-                       break;
-       }
-       return GHOST_kSuccess;
-}
-
-
-GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
-{
-       NSEvent *event = (NSEvent *)eventPtr;
-    GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();
-       
-       if (!window) {
-               return GHOST_kFailure;
-       }
-       
-       switch ([event type])
-    {
-               case NSLeftMouseDown:
-               case NSRightMouseDown:
-               case NSOtherMouseDown:
-                       pushEvent(new GHOST_EventButton([event timestamp], GHOST_kEventButtonDown, window, convertButton([event buttonNumber])));
-                       //Handle tablet events combined with mouse events
-                       switch ([event subtype]) {
-                               case NX_SUBTYPE_TABLET_POINT:
-                                       handleTabletEvent(eventPtr, NSTabletPoint);
-                                       break;
-                               case NX_SUBTYPE_TABLET_PROXIMITY:
-                                       handleTabletEvent(eventPtr, NSTabletProximity);
-                                       break;
-                               default:
-                                       //No tablet event included : do nothing
-                                       break;
-                       }
-                       break;
-                                               
-               case NSLeftMouseUp:
-               case NSRightMouseUp:
-               case NSOtherMouseUp:
-                       pushEvent(new GHOST_EventButton([event timestamp], GHOST_kEventButtonUp, window, convertButton([event buttonNumber])));
-                       //Handle tablet events combined with mouse events
-                       switch ([event subtype]) {
-                               case NX_SUBTYPE_TABLET_POINT:
-                                       handleTabletEvent(eventPtr, NSTabletPoint);
-                                       break;
-                               case NX_SUBTYPE_TABLET_PROXIMITY:
-                                       handleTabletEvent(eventPtr, NSTabletProximity);
-                                       break;
-                               default:
-                                       //No tablet event included : do nothing
-                                       break;
-                       }
-                       break;
-                       
-               case NSLeftMouseDragged:
-               case NSRightMouseDragged:
-               case NSOtherMouseDragged:                               
-                       //Handle tablet events combined with mouse events
-                       switch ([event subtype]) {
-                               case NX_SUBTYPE_TABLET_POINT:
-                                       handleTabletEvent(eventPtr, NSTabletPoint);
-                                       break;
-                               case NX_SUBTYPE_TABLET_PROXIMITY:
-                                       handleTabletEvent(eventPtr, NSTabletProximity);
-                                       break;
-                               default:
-                                       //No tablet event included : do nothing
-                                       break;
-                       }
+                       ct.Xtilt = [event tilt].x;\r
+                       ct.Ytilt = [event tilt].y;\r
+                       break;\r
+               \r
+               case NSTabletProximity:\r
+                       ct.Pressure = 0;\r
+                       ct.Xtilt = 0;\r
+                       ct.Ytilt = 0;\r
+                       if ([event isEnteringProximity])\r
+                       {\r
+                               //pointer is entering tablet area proximity\r
+                               switch ([event pointingDeviceType]) {\r
+                                       case NSPenPointingDevice:\r
+                                               ct.Active = GHOST_kTabletModeStylus;\r
+                                               break;\r
+                                       case NSEraserPointingDevice:\r
+                                               ct.Active = GHOST_kTabletModeEraser;\r
+                                               break;\r
+                                       case NSCursorPointingDevice:\r
+                                       case NSUnknownPointingDevice:\r
+                                       default:\r
+                                               ct.Active = GHOST_kTabletModeNone;\r
+                                               break;\r
+                               }\r
+                       } else {\r
+                               // pointer is leaving - return to mouse\r
+                               ct.Active = GHOST_kTabletModeNone;\r
+                       }\r
+                       break;\r
+               \r
+               default:\r
+                       GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received");\r
+                       return GHOST_kFailure;\r
+                       break;\r
+       }\r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)\r
+{\r
+       NSEvent *event = (NSEvent *)eventPtr;\r
+    GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();\r
+       \r
+       if (!window) {\r
+               return GHOST_kFailure;\r
+       }\r
+       \r
+       switch ([event type])\r
+    {\r
+               case NSLeftMouseDown:\r
+               case NSRightMouseDown:\r
+               case NSOtherMouseDown:\r
+                       pushEvent(new GHOST_EventButton([event timestamp], GHOST_kEventButtonDown, window, convertButton([event buttonNumber])));\r
+                       //Handle tablet events combined with mouse events\r
+                       switch ([event subtype]) {\r
+                               case NX_SUBTYPE_TABLET_POINT:\r
+                                       handleTabletEvent(eventPtr, NSTabletPoint);\r
+                                       break;\r
+                               case NX_SUBTYPE_TABLET_PROXIMITY:\r
+                                       handleTabletEvent(eventPtr, NSTabletProximity);\r
+                                       break;\r
+                               default:\r
+                                       //No tablet event included : do nothing\r
+                                       break;\r
+                       }\r
+                       break;\r
+                                               \r
+               case NSLeftMouseUp:\r
+               case NSRightMouseUp:\r
+               case NSOtherMouseUp:\r
+                       pushEvent(new GHOST_EventButton([event timestamp], GHOST_kEventButtonUp, window, convertButton([event buttonNumber])));\r
+                       //Handle tablet events combined with mouse events\r
+                       switch ([event subtype]) {\r
+                               case NX_SUBTYPE_TABLET_POINT:\r
+                                       handleTabletEvent(eventPtr, NSTabletPoint);\r
+                                       break;\r
+                               case NX_SUBTYPE_TABLET_PROXIMITY:\r
+                                       handleTabletEvent(eventPtr, NSTabletProximity);\r
+                                       break;\r
+                               default:\r
+                                       //No tablet event included : do nothing\r
+                                       break;\r
+                       }\r
+                       break;\r
+                       \r
+               case NSLeftMouseDragged:\r
+               case NSRightMouseDragged:\r
+               case NSOtherMouseDragged:                               \r
+                       //Handle tablet events combined with mouse events\r
+                       switch ([event subtype]) {\r
+                               case NX_SUBTYPE_TABLET_POINT:\r
+                                       handleTabletEvent(eventPtr, NSTabletPoint);\r
+                                       break;\r
+                               case NX_SUBTYPE_TABLET_PROXIMITY:\r
+                                       handleTabletEvent(eventPtr, NSTabletProximity);\r
+                                       break;\r
+                               default:\r
+                                       //No tablet event included : do nothing\r
+                                       break;\r
+                       }\r
                        
                        
-               case NSMouseMoved:
+               case NSMouseMoved:\r
                                switch (window->getCursorGrabMode()) {
                                        case GHOST_kGrabHide: //Cursor hidden grab operation : no cursor move
                                        {
                                switch (window->getCursorGrabMode()) {
                                        case GHOST_kGrabHide: //Cursor hidden grab operation : no cursor move
                                        {
@@ -1098,58 +1098,58 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
                                                m_cursorDelta_y=0; //Mouse motion occured between two cursor warps, so we can reset the delta counter
                                        }
                                                break;
                                                m_cursorDelta_y=0; //Mouse motion occured between two cursor warps, so we can reset the delta counter
                                        }
                                                break;
-                               }
-                               break;
-                       
-               case NSScrollWheel:
-                       {
-                               GHOST_TInt32 delta;
-                               
-                               double deltaF = [event deltaY];
-                               if (deltaF == 0.0) break; //discard trackpad delta=0 events
-                               
-                               delta = deltaF > 0.0 ? 1 : -1;
-                               pushEvent(new GHOST_EventWheel([event timestamp], window, delta));
-                       }
-                       break;
-                       
-               default:
-                       return GHOST_kFailure;
-                       break;
-               }
-       
-       return GHOST_kSuccess;
-}
-
-
-GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
-{
-       NSEvent *event = (NSEvent *)eventPtr;
-       GHOST_IWindow* window = m_windowManager->getActiveWindow();
-       unsigned int modifiers;
-       NSString *characters;
+                               }\r
+                               break;\r
+                       \r
+               case NSScrollWheel:\r
+                       {\r
+                               GHOST_TInt32 delta;\r
+                               \r
+                               double deltaF = [event deltaY];\r
+                               if (deltaF == 0.0) break; //discard trackpad delta=0 events\r
+                               \r
+                               delta = deltaF > 0.0 ? 1 : -1;\r
+                               pushEvent(new GHOST_EventWheel([event timestamp], window, delta));\r
+                       }\r
+                       break;\r
+                       \r
+               default:\r
+                       return GHOST_kFailure;\r
+                       break;\r
+               }\r
+       \r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)\r
+{\r
+       NSEvent *event = (NSEvent *)eventPtr;\r
+       GHOST_IWindow* window = m_windowManager->getActiveWindow();\r
+       unsigned int modifiers;\r
+       NSString *characters;\r
        NSData *convertedCharacters;
        NSData *convertedCharacters;
-       GHOST_TKey keyCode;
-       unsigned char ascii;
+       GHOST_TKey keyCode;\r
+       unsigned char ascii;\r
        NSString* charsIgnoringModifiers;
        NSString* charsIgnoringModifiers;
-
-       /* Can happen, very rarely - seems to only be when command-H makes
-        * the window go away and we still get an HKey up. 
-        */
-       if (!window) {
-               printf("\nW failure");
-               return GHOST_kFailure;
-       }
-       
-       switch ([event type]) {
-               case NSKeyDown:
-               case NSKeyUp:
+\r
+       /* Can happen, very rarely - seems to only be when command-H makes\r
+        * the window go away and we still get an HKey up. \r
+        */\r
+       if (!window) {\r
+               printf("\nW failure");\r
+               return GHOST_kFailure;\r
+       }\r
+       \r
+       switch ([event type]) {\r
+               case NSKeyDown:\r
+               case NSKeyUp:\r
                        charsIgnoringModifiers = [event charactersIgnoringModifiers];
                        if ([charsIgnoringModifiers length]>0)
                        charsIgnoringModifiers = [event charactersIgnoringModifiers];
                        if ([charsIgnoringModifiers length]>0)
-                               keyCode = convertKey([event keyCode],
+                               keyCode = convertKey([event keyCode],\r
                                                                         [charsIgnoringModifiers characterAtIndex:0]);
                        else
                                                                         [charsIgnoringModifiers characterAtIndex:0]);
                        else
-                               keyCode = convertKey([event keyCode],0);
+                               keyCode = convertKey([event keyCode],0);\r
 
                                
                        characters = [event characters];
 
                                
                        characters = [event characters];
@@ -1160,127 +1160,127 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
                                        ascii =((char*)[convertedCharacters bytes])[0];
                                else
                                        ascii = 0; //Character not available in iso latin 1 encoding
                                        ascii =((char*)[convertedCharacters bytes])[0];
                                else
                                        ascii = 0; //Character not available in iso latin 1 encoding
-                       }
+                       }\r
                        else
                                ascii= 0;
                        else
                                ascii= 0;
-                       
-                       if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))
-                               break; //Cmd-Q is directly handled by Cocoa
-
-                       if ([event type] == NSKeyDown) {
-                               pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyDown, window, keyCode, ascii) );
-                               //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);
-                       } else {
-                               pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyUp, window, keyCode, ascii) );
-                       }
-                       break;
-       
-               case NSFlagsChanged: 
-                       modifiers = [event modifierFlags];
-                       if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {
-                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );
-                       }
-                       if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {
-                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );
-                       }
-                       if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {
-                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );
-                       }
-                       if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {
-                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );
-                       }
-                       
-                       m_modifierMask = modifiers;
-                       break;
-                       
-               default:
-                       return GHOST_kFailure;
-                       break;
-       }
-       
-       return GHOST_kSuccess;
-}
-
-
-
-#pragma mark Clipboard get/set
-
-GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
-{
-       GHOST_TUns8 * temp_buff;
-       size_t pastedTextSize;  
-       
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       
-       NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
-       
-       if (pasteBoard == nil) {
-               [pool drain];
-               return NULL;
-       }
-       
-       NSArray *supportedTypes =
-               [NSArray arrayWithObjects: @"public.utf8-plain-text", nil];
-       
-       NSString *bestType = [[NSPasteboard generalPasteboard]
-                                                 availableTypeFromArray:supportedTypes];
-       
-       if (bestType == nil) {
-               [pool drain];
-               return NULL;
-       }
-       
-       NSString * textPasted = [pasteBoard stringForType:@"public.utf8-plain-text"];
-
-       if (textPasted == nil) {
-               [pool drain];
-               return NULL;
-       }
-       
-       pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
-       
-       temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
-
-       if (temp_buff == NULL) {
-               [pool drain];
-               return NULL;
-       }
-       
-       strncpy((char*)temp_buff, [textPasted UTF8String], pastedTextSize);
-       
-       temp_buff[pastedTextSize] = '\0';
-       
-       [pool drain];
-
-       if(temp_buff) {
-               return temp_buff;
-       } else {
-               return NULL;
-       }
-}
-
-void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
-{
-       NSString *textToCopy;
-       
-       if(selection) {return;} // for copying the selection, used on X11
-
-       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-               
-       NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
-       
-       if (pasteBoard == nil) {
-               [pool drain];
-               return;
-       }
-       
-       NSArray *supportedTypes = [NSArray arrayWithObject:@"public.utf8-plain-text"];
-       
-       [pasteBoard declareTypes:supportedTypes owner:nil];
-       
-       textToCopy = [NSString stringWithUTF8String:buffer];
-       
-       [pasteBoard setString:textToCopy forType:@"public.utf8-plain-text"];
-       
-       [pool drain];
-}
+                       \r
+                       if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))\r
+                               break; //Cmd-Q is directly handled by Cocoa\r
+\r
+                       if ([event type] == NSKeyDown) {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyDown, window, keyCode, ascii) );\r
+                               //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);\r
+                       } else {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyUp, window, keyCode, ascii) );\r
+                       }\r
+                       break;\r
+       \r
+               case NSFlagsChanged: \r
+                       modifiers = [event modifierFlags];\r
+                       if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );\r
+                       }\r
+                       if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );\r
+                       }\r
+                       if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );\r
+                       }\r
+                       if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {\r
+                               pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );\r
+                       }\r
+                       \r
+                       m_modifierMask = modifiers;\r
+                       break;\r
+                       \r
+               default:\r
+                       return GHOST_kFailure;\r
+                       break;\r
+       }\r
+       \r
+       return GHOST_kSuccess;\r
+}\r
+\r
+\r
+\r
+#pragma mark Clipboard get/set\r
+\r
+GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const\r
+{\r
+       GHOST_TUns8 * temp_buff;\r
+       size_t pastedTextSize;  \r
+       \r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+       \r
+       NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
+       \r
+       if (pasteBoard == nil) {\r
+               [pool drain];\r
+               return NULL;\r
+       }\r
+       \r
+       NSArray *supportedTypes =\r
+               [NSArray arrayWithObjects: @"public.utf8-plain-text", nil];\r
+       \r
+       NSString *bestType = [[NSPasteboard generalPasteboard]\r
+                                                 availableTypeFromArray:supportedTypes];\r
+       \r
+       if (bestType == nil) {\r
+               [pool drain];\r
+               return NULL;\r
+       }\r
+       \r
+       NSString * textPasted = [pasteBoard stringForType:@"public.utf8-plain-text"];\r
+\r
+       if (textPasted == nil) {\r
+               [pool drain];\r
+               return NULL;\r
+       }\r
+       \r
+       pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];\r
+       \r
+       temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); \r
+\r
+       if (temp_buff == NULL) {\r
+               [pool drain];\r
+               return NULL;\r
+       }\r
+       \r
+       strncpy((char*)temp_buff, [textPasted UTF8String], pastedTextSize);\r
+       \r
+       temp_buff[pastedTextSize] = '\0';\r
+       \r
+       [pool drain];\r
+\r
+       if(temp_buff) {\r
+               return temp_buff;\r
+       } else {\r
+               return NULL;\r
+       }\r
+}\r
+\r
+void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const\r
+{\r
+       NSString *textToCopy;\r
+       \r
+       if(selection) {return;} // for copying the selection, used on X11\r
+\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
+               \r
+       NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
+       \r
+       if (pasteBoard == nil) {\r
+               [pool drain];\r
+               return;\r
+       }\r
+       \r
+       NSArray *supportedTypes = [NSArray arrayWithObject:@"public.utf8-plain-text"];\r
+       \r
+       [pasteBoard declareTypes:supportedTypes owner:nil];\r
+       \r
+       textToCopy = [NSString stringWithUTF8String:buffer];\r
+       \r
+       [pasteBoard setString:textToCopy forType:@"public.utf8-plain-text"];\r
+       \r
+       [pool drain];\r
+}\r