merge with trunk/2.5 at r24463
authorJoseph Eagar <joeedh@gmail.com>
Sun, 22 Nov 2009 14:06:30 +0000 (14:06 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Sun, 22 Nov 2009 14:06:30 +0000 (14:06 +0000)
37 files changed:
1  2 
intern/ghost/intern/GHOST_SystemCocoa.h
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_WindowCocoa.h
intern/ghost/intern/GHOST_WindowCocoa.mm
release/datafiles/datatoc.py
release/scripts/modules/bpy_ext/Object.py
release/scripts/modules/bpy_ops.py
release/scripts/ui/space_console.py
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/node.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/animation/drivers.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/mesh/mesh_data.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_orientations.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_rna.c
source/blender/windowmanager/intern/wm_operators.c
source/creator/creator.c
source/gameengine/Converter/BL_ArmatureChannel.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp

index 46d8ecf6f9430f484b62d924ea5b0f6c0d8ad05d,c7127e26a4abcce3fc45429450daea975fb34f7a..ccd7157c6e32d6ce6d86bffab98264784267406b
 -/**
 - * $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"
 +/**\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
+ #include "GHOST_EventDragnDrop.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
 +#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;
 -- (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);
@@@ -697,191 -699,287 +699,287 @@@ GHOST_TSuccess GHOST_SystemCocoa::setCu
        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;
 -
 +\r
        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 */
 -                                      /*              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;
 -}
 -
 +                                      /*              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
+ //Note: called from NSWindow subclass
+ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
+                                                                  GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data)
+ {
+       if (!validWindow(window)) {
+               return GHOST_kFailure;
+       }
+       switch(eventType) 
+       {
+               case GHOST_kEventDraggingEntered:
+                       setAcceptDragOperation(FALSE); //Drag operation needs to be accepted explicitely by the event manager
+               case GHOST_kEventDraggingUpdated:
+               case GHOST_kEventDraggingExited:
+                       pushEvent(new GHOST_EventDragnDrop(getMilliSeconds(),GHOST_kEventDraggingEntered,draggedObjectType,window,mouseX,mouseY,NULL));
+                       break;
+                       
+               case GHOST_kEventDraggingDropDone:
+               case GHOST_kEventDraggingDropOnIcon:
+               {
+                       GHOST_TUns8 * temp_buff;
+                       GHOST_TStringArray *strArray;
+                       NSArray *droppedArray;
+                       size_t pastedTextSize;  
+                       NSString *droppedStr;
+                       GHOST_TEventDataPtr eventData;
+                       int i;
+                       if (!data) return GHOST_kFailure;
+                       
+                       switch (draggedObjectType) {
+                               case GHOST_kDragnDropTypeBitmap:
+                                       //TODO: implement bitmap conversion to a blender friendly format
+                                       break;
+                               case GHOST_kDragnDropTypeFilenames:
+                                       droppedArray = (NSArray*)data;
+                                       
+                                       strArray = (GHOST_TStringArray*)malloc(sizeof(GHOST_TStringArray));
+                                       if (!strArray) return GHOST_kFailure;
+                                       
+                                       strArray->count = [droppedArray count];
+                                       if (strArray->count == 0) return GHOST_kFailure;
+                                       
+                                       strArray->strings = (GHOST_TUns8**) malloc(strArray->count*sizeof(GHOST_TUns8*));
+                                       
+                                       for (i=0;i<strArray->count;i++)
+                                       {
+                                               droppedStr = [droppedArray objectAtIndex:i];
+                                               
+                                               pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+                                               temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
+                                       
+                                               if (!temp_buff) {
+                                                       strArray->count = i;
+                                                       break;
+                                               }
+                                       
+                                               strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize);
+                                               temp_buff[pastedTextSize] = '\0';
+                                               
+                                               strArray->strings[i] = temp_buff;
+                                       }
+                                       eventData = (GHOST_TEventDataPtr) strArray;     
+                                       break;
+                                       
+                               case GHOST_kDragnDropTypeString:
+                                       droppedStr = (NSString*)data;
+                                       pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+                                       
+                                       temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
+                                       
+                                       if (temp_buff == NULL) {
+                                               return GHOST_kFailure;
+                                       }
+                                       
+                                       strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize);
+                                       
+                                       temp_buff[pastedTextSize] = '\0';
+                                       
+                                       eventData = (GHOST_TEventDataPtr) temp_buff;
+                                       break;
+                                       
+                               default:
+                                       return GHOST_kFailure;
+                                       break;
+                       }
+                       pushEvent(new GHOST_EventDragnDrop(getMilliSeconds(),GHOST_kEventDraggingEntered,draggedObjectType,window,mouseX,mouseY,eventData));
+               }
+                       break;
+               default:
+                       return GHOST_kFailure;
+       }
+       return GHOST_kSuccess;
+ }
 -GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()
 -{
 +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
index 9613ee64ef4eda5ca7394a76f52d5832bc814a9e,459a4a54ee31fe536d2fa32e65be1a22e59f6bbf..dffb9b7772fe5e2b1466d4db3e51158e2e4ee698
@@@ -117,96 -117,168 +117,168 @@@ extern "C" 
                wm_event_do_notifiers(ghostC);
                wm_draw_update(ghostC);
        }*/
 -}
 -@end
 -
 -#pragma mark NSWindow subclass
 -//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)
 -@interface CocoaWindow: NSWindow
 -{
 +}\r
 +@end\r
 +\r
 +#pragma mark NSWindow subclass\r
 +//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)\r
 +@interface CocoaWindow: NSWindow\r
 +{\r
\r
+       GHOST_SystemCocoa *systemCocoa;
+       GHOST_WindowCocoa *associatedWindow;
+       GHOST_TDragnDropTypes m_draggedObjectType;
 -}
 +}\r
+ - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
 -@end
 -@implementation CocoaWindow
 +@end\r
 +@implementation CocoaWindow\r
+ - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
+ {
+       systemCocoa = sysCocoa;
+       associatedWindow = winCocoa;
+ }
 -
 --(BOOL)canBecomeKeyWindow
 -{
 -      return YES;
 -}
 -
 +\r
 +-(BOOL)canBecomeKeyWindow\r
 +{\r
 +      return YES;\r
 +}\r
 +\r
+ //The drag'n'drop dragging destination methods
+ - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
+ {
+       NSPoint mouseLocation = [sender draggingLocation];
+       NSPasteboard *draggingPBoard = [sender draggingPasteboard];
+       
+       if ([[draggingPBoard types] containsObject:NSTIFFPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeBitmap;
+       else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeFilenames;
+       else if ([[draggingPBoard types] containsObject:NSStringPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeString;
+       else return NSDragOperationNone;
+       
+       systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
+       return NSDragOperationCopy;
+ }
+ - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
+ {
+       NSPoint mouseLocation = [sender draggingLocation];
+       
+       systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
+       return NSDragOperationCopy;
+ }
+ - (void)draggingExited:(id < NSDraggingInfo >)sender
+ {
+       systemCocoa->handleDraggingEvent(GHOST_kEventDraggingExited, m_draggedObjectType, associatedWindow, 0, 0, nil);
+       m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
+ }
+ - (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
+ {
+       if (systemCocoa->canAcceptDragOperation())
+               return YES;
+       else
+               return NO;
+ }
+ - (BOOL)performDragOperation:(id < NSDraggingInfo >)sender
+ {
+       NSPoint mouseLocation = [sender draggingLocation];
+       NSPasteboard *draggingPBoard = [sender draggingPasteboard];
+       id data;
+       
+       switch (m_draggedObjectType) {
+               case GHOST_kDragnDropTypeBitmap:
+                       data = [draggingPBoard dataForType:NSTIFFPboardType];
+                       break;
+               case GHOST_kDragnDropTypeFilenames:
+                       data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
+                       break;
+               case GHOST_kDragnDropTypeString:
+                       data = [draggingPBoard stringForType:@"public.utf8-plain-text"];
+                       break;
+               default:
+                       return NO;
+                       break;
+       }
+       systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, (void*)data);
+       return YES;
+ }
 -@end
 -
 -
 -
 -#pragma mark NSOpenGLView subclass
 -//We need to subclass it in order to give Cocoa the feeling key events are trapped
 -@interface CocoaOpenGLView : NSOpenGLView
 -{
 -}
 -@end
 -@implementation CocoaOpenGLView
 -
 -- (BOOL)acceptsFirstResponder
 -{
 -    return YES;
 -}
 -
 -//The trick to prevent Cocoa from complaining (beeping)
 -- (void)keyDown:(NSEvent *)theEvent
 -{}
 -
 -- (BOOL)isOpaque
 -{
 -    return YES;
 -}
 -
 -@end
 -
 -
 -#pragma mark initialization / finalization
 -
 -NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
 -
 -GHOST_WindowCocoa::GHOST_WindowCocoa(
 -      GHOST_SystemCocoa *systemCocoa,
 -      const STR_String& title,
 -      GHOST_TInt32 left,
 -      GHOST_TInt32 top,
 -      GHOST_TUns32 width,
 -      GHOST_TUns32 height,
 -      GHOST_TWindowState state,
 -      GHOST_TDrawingContextType type,
 -      const bool stereoVisual
 -) :
 +@end\r
 +\r
 +\r
 +\r
 +#pragma mark NSOpenGLView subclass\r
 +//We need to subclass it in order to give Cocoa the feeling key events are trapped\r
 +@interface CocoaOpenGLView : NSOpenGLView\r
 +{\r
 +}\r
 +@end\r
 +@implementation CocoaOpenGLView\r
 +\r
 +- (BOOL)acceptsFirstResponder\r
 +{\r
 +    return YES;\r
 +}\r
 +\r
 +//The trick to prevent Cocoa from complaining (beeping)\r
 +- (void)keyDown:(NSEvent *)theEvent\r
 +{}\r
 +\r
 +- (BOOL)isOpaque\r
 +{\r
 +    return YES;\r
 +}\r
 +\r
 +@end\r
 +\r
 +\r
 +#pragma mark initialization / finalization\r
 +\r
 +NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;\r
 +\r
 +GHOST_WindowCocoa::GHOST_WindowCocoa(\r
 +      GHOST_SystemCocoa *systemCocoa,\r
 +      const STR_String& title,\r
 +      GHOST_TInt32 left,\r
 +      GHOST_TInt32 top,\r
 +      GHOST_TUns32 width,\r
 +      GHOST_TUns32 height,\r
 +      GHOST_TWindowState state,\r
 +      GHOST_TDrawingContextType type,\r
 +      const bool stereoVisual\r
 +) :\r
        GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual),
 -      m_customCursor(0)
 -{
 +      m_customCursor(0)\r
 +{\r
        NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
        int i;
        
 -      m_systemCocoa = systemCocoa;
 -      m_fullScreen = false;
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -
 -      //Creates the window
 -      NSRect rect;
 +      m_systemCocoa = systemCocoa;\r
 +      m_fullScreen = false;\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +\r
 +      //Creates the window\r
 +      NSRect rect;\r
        NSSize  minSize;
 -      
 -      rect.origin.x = left;
 -      rect.origin.y = top;
 -      rect.size.width = width;
 -      rect.size.height = height;
 -      
 -      m_window = [[CocoaWindow alloc] initWithContentRect:rect
 -                                                                                 styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
 -                                                                                       backing:NSBackingStoreBuffered defer:NO];
 -      if (m_window == nil) {
 -              [pool drain];
 -              return;
 -      }
 -      
 +      \r
 +      rect.origin.x = left;\r
 +      rect.origin.y = top;\r
 +      rect.size.width = width;\r
 +      rect.size.height = height;\r
 +      \r
 +      m_window = [[CocoaWindow alloc] initWithContentRect:rect\r
 +                                                                                 styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask\r
 +                                                                                       backing:NSBackingStoreBuffered defer:NO];\r
 +      if (m_window == nil) {\r
 +              [pool drain];\r
 +              return;\r
 +      }\r
 +      \r
+       [m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
+       
        //Forbid to resize the window below the blender defined minimum one
        minSize.width = 320;
        minSize.height = 240;
        pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
        
  
 -      //Creates the OpenGL View inside the window
 -      NSOpenGLPixelFormat *pixelFormat =
 -      [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
 -      
 -      m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
 -                                                                                               pixelFormat:pixelFormat];
 -      
 -      [pixelFormat release];
 -      
 -      m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
 -      
 -      [m_window setContentView:m_openGLView];
 -      [m_window setInitialFirstResponder:m_openGLView];
 -      
 -      [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window
 -      
 -      [m_window makeKeyAndOrderFront:nil];
 -      
 -      setDrawingContextType(type);
 -      updateDrawingContext();
 -      activateDrawingContext();
 -      
 -      m_tablet.Active = GHOST_kTabletModeNone;
 -      
 -      CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
 -      [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
 -      [m_window setDelegate:windowDelegate];
 -      
 -      [m_window setAcceptsMouseMovedEvents:YES];
 -      
 +      //Creates the OpenGL View inside the window\r
 +      NSOpenGLPixelFormat *pixelFormat =\r
 +      [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];\r
 +      \r
 +      m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect\r
 +                                                                                               pixelFormat:pixelFormat];\r
 +      \r
 +      [pixelFormat release];\r
 +      \r
 +      m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after\r
 +      \r
 +      [m_window setContentView:m_openGLView];\r
 +      [m_window setInitialFirstResponder:m_openGLView];\r
 +      \r
 +      [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window\r
 +      \r
 +      [m_window makeKeyAndOrderFront:nil];\r
 +      \r
 +      setDrawingContextType(type);\r
 +      updateDrawingContext();\r
 +      activateDrawingContext();\r
 +      \r
 +      m_tablet.Active = GHOST_kTabletModeNone;\r
 +      \r
 +      CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];\r
 +      [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];\r
 +      [m_window setDelegate:windowDelegate];\r
 +      \r
 +      [m_window setAcceptsMouseMovedEvents:YES];\r
 +      \r
+       [m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
+                                                                                 NSStringPboardType, NSTIFFPboardType, nil]];
+                                                                                 
 -      if (state == GHOST_kWindowStateFullScreen)
 -              setState(GHOST_kWindowStateFullScreen);
 -              
 -      [pool drain];
 -}
 -
 -
 -GHOST_WindowCocoa::~GHOST_WindowCocoa()
 -{
 -      if (m_customCursor) delete m_customCursor;
 -
 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      [m_openGLView release];
 -      
 -      if (m_window) {
 -              [m_window close];
 -              [[m_window delegate] release];
 -              [m_window release];
 -              m_window = nil;
 -      }
 -      
 -      //Check for other blender opened windows and make the frontmost key
 -      NSArray *windowsList = [NSApp orderedWindows];
 -      if ([windowsList count]) {
 -              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
 -      }
 -      [pool drain];
 -}
 -
 -#pragma mark accessors
 -
 -bool GHOST_WindowCocoa::getValid() const
 -{
 -    bool valid;
 -    if (!m_fullScreen) {
 -        valid = (m_window != 0); //&& ::IsValidWindowPtr(m_windowRef);
 -    }
 -    else {
 -        valid = true;
 -    }
 -    return valid;
 -}
 -
 -
 -void GHOST_WindowCocoa::setTitle(const STR_String& title)
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];
 -      
 -      //Set associated file if applicable
 -      if ([windowTitle hasPrefix:@"Blender"])
 -      {
 -              NSRange fileStrRange;
 -              NSString *associatedFileName;
 -              int len;
 -              
 -              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;
 -              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
 -      
 -              if (len >0)
 -              {
 -                      fileStrRange.length = len;
 -                      associatedFileName = [windowTitle substringWithRange:fileStrRange];
 -                      @try {
 -                              [m_window setRepresentedFilename:associatedFileName];
 -                      }
 -                      @catch (NSException * e) {
 -                              printf("\nInvalid file path given in window title");
 -                      }
 -                      [m_window setTitle:[associatedFileName lastPathComponent]];
 -              }
 -              else {
 -                      [m_window setTitle:windowTitle];
 -                      [m_window setRepresentedFilename:@""];
 -              }
 -
 -      } else {
 -              [m_window setTitle:windowTitle];
 -              [m_window setRepresentedFilename:@""];
 -      }
 -
 -      
 -      [windowTitle release];
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getTitle(STR_String& title) const
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [m_window title];
 -
 -      if (windowTitle != nil) {
 -              title = [windowTitle UTF8String];               
 -      }
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -      rect = [m_window frame];
 -
 -      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);
 -      bounds.m_l = rect.origin.x -screenSize.origin.x;
 -      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;
 -      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      if (!m_fullScreen)
 -      {
 -              NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -              //Max window contents as screen size (excluding title bar...)
 -              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
 -                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -
 -              rect = [m_window contentRectForFrameRect:[m_window frame]];
 -              
 -              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);
 -              bounds.m_l = rect.origin.x -contentRect.origin.x;
 -              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;
 -              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);
 -      }
 -      else {
 -              NSRect screenSize = [[m_window screen] frame];
 -              
 -              bounds.m_b = screenSize.origin.y + screenSize.size.height;
 -              bounds.m_l = screenSize.origin.x;
 -              bounds.m_r = screenSize.origin.x + screenSize.size.width;
 -              bounds.m_t = screenSize.origin.y;
 -      }
 -      [pool drain];
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getWidth()) != width) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=cBnds.getHeight();
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getHeight()) != height) {
 -              NSSize size;
 -              size.width=cBnds.getWidth();
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
 -          (((GHOST_TUns32)cBnds.getHeight()) != height)) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TWindowState GHOST_WindowCocoa::getState() const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      GHOST_TWindowState state;
 -      if (m_fullScreen) {
 -              state = GHOST_kWindowStateFullScreen;
 -      } 
 -      else if ([m_window isMiniaturized]) {
 -              state = GHOST_kWindowStateMinimized;
 -      }
 -      else if ([m_window isZoomed]) {
 -              state = GHOST_kWindowStateMaximized;
 -      }
 -      else {
 -              state = GHOST_kWindowStateNormal;
 -      }
 -      [pool drain];
 -      return state;
 -}
 -
 -
 -void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      screenCoord.x = inX;
 -      screenCoord.y = inY;
 -      
 -      baseCoord = [m_window convertScreenToBase:screenCoord];
 -      
 -      outX = baseCoord.x;
 -      outY = baseCoord.y;
 -}
 -
 -
 -void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      baseCoord.x = inX;
 -      baseCoord.y = inY;
 -      
 -      screenCoord = [m_window convertBaseToScreen:baseCoord];
 -      
 -      outX = screenCoord.x;
 -      outY = screenCoord.y;
 -}
 -
 +      if (state == GHOST_kWindowStateFullScreen)\r
 +              setState(GHOST_kWindowStateFullScreen);\r
 +              \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_WindowCocoa::~GHOST_WindowCocoa()\r
 +{\r
 +      if (m_customCursor) delete m_customCursor;\r
 +\r
 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      [m_openGLView release];\r
 +      \r
 +      if (m_window) {\r
 +              [m_window close];\r
 +              [[m_window delegate] release];\r
 +              [m_window release];\r
 +              m_window = nil;\r
 +      }\r
 +      \r
 +      //Check for other blender opened windows and make the frontmost key\r
 +      NSArray *windowsList = [NSApp orderedWindows];\r
 +      if ([windowsList count]) {\r
 +              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +#pragma mark accessors\r
 +\r
 +bool GHOST_WindowCocoa::getValid() const\r
 +{\r
 +    bool valid;\r
 +    if (!m_fullScreen) {\r
 +        valid = (m_window != 0); //&& ::IsValidWindowPtr(m_windowRef);\r
 +    }\r
 +    else {\r
 +        valid = true;\r
 +    }\r
 +    return valid;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::setTitle(const STR_String& title)\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];\r
 +      \r
 +      //Set associated file if applicable\r
 +      if ([windowTitle hasPrefix:@"Blender"])\r
 +      {\r
 +              NSRange fileStrRange;\r
 +              NSString *associatedFileName;\r
 +              int len;\r
 +              \r
 +              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;\r
 +              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;\r
 +      \r
 +              if (len >0)\r
 +              {\r
 +                      fileStrRange.length = len;\r
 +                      associatedFileName = [windowTitle substringWithRange:fileStrRange];\r
 +                      @try {\r
 +                              [m_window setRepresentedFilename:associatedFileName];\r
 +                      }\r
 +                      @catch (NSException * e) {\r
 +                              printf("\nInvalid file path given in window title");\r
 +                      }\r
 +                      [m_window setTitle:[associatedFileName lastPathComponent]];\r
 +              }\r
 +              else {\r
 +                      [m_window setTitle:windowTitle];\r
 +                      [m_window setRepresentedFilename:@""];\r
 +              }\r
 +\r
 +      } else {\r
 +              [m_window setTitle:windowTitle];\r
 +              [m_window setRepresentedFilename:@""];\r
 +      }\r
 +\r
 +      \r
 +      [windowTitle release];\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getTitle(STR_String& title) const\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [m_window title];\r
 +\r
 +      if (windowTitle != nil) {\r
 +              title = [windowTitle UTF8String];               \r
 +      }\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +      rect = [m_window frame];\r
 +\r
 +      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);\r
 +      bounds.m_l = rect.origin.x -screenSize.origin.x;\r
 +      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;\r
 +      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      if (!m_fullScreen)\r
 +      {\r
 +              NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +              //Max window contents as screen size (excluding title bar...)\r
 +              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize\r
 +                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +\r
 +              rect = [m_window contentRectForFrameRect:[m_window frame]];\r
 +              \r
 +              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);\r
 +              bounds.m_l = rect.origin.x -contentRect.origin.x;\r
 +              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;\r
 +              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);\r
 +      }\r
 +      else {\r
 +              NSRect screenSize = [[m_window screen] frame];\r
 +              \r
 +              bounds.m_b = screenSize.origin.y + screenSize.size.height;\r
 +              bounds.m_l = screenSize.origin.x;\r
 +              bounds.m_r = screenSize.origin.x + screenSize.size.width;\r
 +              bounds.m_t = screenSize.origin.y;\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getWidth()) != width) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=cBnds.getHeight();\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getHeight()) != height) {\r
 +              NSSize size;\r
 +              size.width=cBnds.getWidth();\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||\r
 +          (((GHOST_TUns32)cBnds.getHeight()) != height)) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TWindowState GHOST_WindowCocoa::getState() const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      GHOST_TWindowState state;\r
 +      if (m_fullScreen) {\r
 +              state = GHOST_kWindowStateFullScreen;\r
 +      } \r
 +      else if ([m_window isMiniaturized]) {\r
 +              state = GHOST_kWindowStateMinimized;\r
 +      }\r
 +      else if ([m_window isZoomed]) {\r
 +              state = GHOST_kWindowStateMaximized;\r
 +      }\r
 +      else {\r
 +              state = GHOST_kWindowStateNormal;\r
 +      }\r
 +      [pool drain];\r
 +      return state;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      screenCoord.x = inX;\r
 +      screenCoord.y = inY;\r
 +      \r
 +      baseCoord = [m_window convertScreenToBase:screenCoord];\r
 +      \r
 +      outX = baseCoord.x;\r
 +      outY = baseCoord.y;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      baseCoord.x = inX;\r
 +      baseCoord.y = inY;\r
 +      \r
 +      screenCoord = [m_window convertBaseToScreen:baseCoord];\r
 +      \r
 +      outX = screenCoord.x;\r
 +      outY = screenCoord.y;\r
 +}\r
 +\r
  
  NSScreen* GHOST_WindowCocoa::getScreen()
  {
  }
  
  
 -/**
 - * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.
 - * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.
 - * Thus, process switch, exposé, spaces, ... still work in fullscreen mode
 - */
 -GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")
 -    switch (state) {
 -              case GHOST_kWindowStateMinimized:
 -            [m_window miniaturize:nil];
 -            break;
 -              case GHOST_kWindowStateMaximized:
 -                      [m_window zoom:nil];
 -                      break;
 -              
 -              case GHOST_kWindowStateFullScreen:
 -                      if (!m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      
 -                              //This status change needs to be done before Cocoa call to enter fullscreen mode
 -                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference
 -                              m_fullScreen = true;
 -
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];
 -                              }
 -                              //Make window borderless and enlarge it
 -                              [m_window setStyleMask:NSBorderlessWindowMask];
 -                              [m_window setFrame:[[m_window screen] frame] display:YES];
 +/**\r
 + * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.\r
 + * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.\r
 + * Thus, process switch, exposé, spaces, ... still work in fullscreen mode\r
 + */\r
 +GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")\r
 +    switch (state) {\r
 +              case GHOST_kWindowStateMinimized:\r
 +            [m_window miniaturize:nil];\r
 +            break;\r
 +              case GHOST_kWindowStateMaximized:\r
 +                      [m_window zoom:nil];\r
 +                      break;\r
 +              \r
 +              case GHOST_kWindowStateFullScreen:\r
 +                      if (!m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      \r
 +                              //This status change needs to be done before Cocoa call to enter fullscreen mode\r
 +                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference\r
 +                              m_fullScreen = true;\r
 +\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];\r
 +                              }\r
 +                              //Make window borderless and enlarge it\r
 +                              [m_window setStyleMask:NSBorderlessWindowMask];\r
 +                              [m_window setFrame:[[m_window screen] frame] display:YES];\r
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];
 -                                      //One of the very few 64bit compatible Carbon function
 -                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                styleMask:NSBorderlessWindowMask
 -                                                                                backing:NSBackingStoreBuffered
 -                                                                                defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                              }
 -                      break;
 -              case GHOST_kWindowStateNormal:
 -        default:
 -                      if (m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                              m_fullScreen = false;
 -
 -                              //Exit fullscreen
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //Show again menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];
 -                              }
 -                              //Make window normal and resize it
 -                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];\r
 +                                      //One of the very few 64bit compatible Carbon function\r
 +                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                styleMask:NSBorderlessWindowMask\r
 +                                                                                backing:NSBackingStoreBuffered\r
 +                                                                                defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                              }\r
 +                      break;\r
 +              case GHOST_kWindowStateNormal:\r
 +        default:\r
 +                      if (m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                              m_fullScreen = false;\r
 +\r
 +                              //Exit fullscreen\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //Show again menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];\r
 +                              }\r
 +                              //Make window normal and resize it\r
 +                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];\r
                                //TODO for 10.6 only : window title is forgotten after the style change
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Show menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];
 -                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
 -                                                                                                        backing:NSBackingStoreBuffered
 -                                                                                                              defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                      }
 -            else if ([m_window isMiniaturized])
 -                              [m_window deminiaturize:nil];
 -                      else if ([m_window isZoomed])
 -                              [m_window zoom:nil];
 -            break;
 -    }
 -    return GHOST_kSuccess;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
 -{
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      [m_window setDocumentEdited:isUnsavedChanges];
 -      
 -      [pool drain];
 -      return GHOST_Window::setModifiedState(isUnsavedChanges);
 -}
 -
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")
 -    if (order == GHOST_kWindowOrderTop) {
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Show menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];\r
 +                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)\r
 +                                                                                                        backing:NSBackingStoreBuffered\r
 +                                                                                                              defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                      }\r
 +            else if ([m_window isMiniaturized])\r
 +                              [m_window deminiaturize:nil];\r
 +                      else if ([m_window isZoomed])\r
 +                              [m_window zoom:nil];\r
 +            break;\r
 +    }\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)\r
 +{\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      [m_window setDocumentEdited:isUnsavedChanges];\r
 +      \r
 +      [pool drain];\r
 +      return GHOST_Window::setModifiedState(isUnsavedChanges);\r
 +}\r
 +\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")\r
 +    if (order == GHOST_kWindowOrderTop) {\r
-               [m_window orderFront:nil];\r
+               [m_window makeKeyAndOrderFront:nil];
 -    }
 -    else {
 +    }\r
 +    else {\r
+               NSArray *windowsList;
+               
 -              [m_window orderBack:nil];
 +              [m_window orderBack:nil];\r
+               
+               //Check for other blender opened windows and make the frontmost key
+               windowsList = [NSApp orderedWindows];
+               if ([windowsList count]) {
+                       [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
+               }
 -    }
 -    return GHOST_kSuccess;
 -}
 -
 -#pragma mark Drawing context
 -
 -/*#define  WAIT_FOR_VSYNC 1*/
 -
 -GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
 -{
 -    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -        if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext flushBuffer];
 -                      [pool drain];
 -            return GHOST_kSuccess;
 -        }
 -    }
 -    return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext update];
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              }
 -      }
 -      return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext makeCurrentContext];
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              }
 -      }
 -      return GHOST_kFailure;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
 -{
 -      GHOST_TSuccess success = GHOST_kFailure;
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSOpenGLPixelFormat *pixelFormat;
 -      NSOpenGLContext *tmpOpenGLContext;
 -      
 +    }\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +#pragma mark Drawing context\r
 +\r
 +/*#define  WAIT_FOR_VSYNC 1*/\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()\r
 +{\r
 +    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +        if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext flushBuffer];\r
 +                      [pool drain];\r
 +            return GHOST_kSuccess;\r
 +        }\r
 +    }\r
 +    return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext update];\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              }\r
 +      }\r
 +      return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext makeCurrentContext];\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              }\r
 +      }\r
 +      return GHOST_kFailure;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)\r
 +{\r
 +      GHOST_TSuccess success = GHOST_kFailure;\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSOpenGLPixelFormat *pixelFormat;\r
 +      NSOpenGLContext *tmpOpenGLContext;\r
 +      \r
        /***** Multithreaded opengl code : uncomment for enabling
        CGLContextObj cglCtx;
        */
Simple merge
index 59c2ca3ebda1ff01f7e727b21331a9b2f5931798,e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ccd9da414d872259025d40c5d185f4ee14d5323e
@@@ -1,22 -1,0 +1,25 @@@
++<<<<<<< .working
 +# ##### 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.
 +#
 +# ##### END GPL LICENSE BLOCK #####
 +
 +import bpy
 +class_obj = bpy.types.Object
 +
 +class_obj.getChildren = lambda self: [child for child in bpy.data.objects if child.parent == self]
++=======
++>>>>>>> .merge-right.r24463
index 8078816f982fed373ebac7a03a50ff6bac23aafb,35d986fe09db78e386e78127f56f53acf779be4b..9551429e4c47ae979c5734bc905796a7a66c3e52
@@@ -127,13 -127,13 +127,19 @@@ class bpy_ops_submodule_op(object)
      '''
  
      __keys__ = ('module', 'func')
 +    
 +    
 +    def _get_doc(self):
 +        return op_as_string(self.idname())
 +    
 +    __doc__ = property(_get_doc)
  
+     def _get_doc(self):
+         return op_as_string(self.idname())
+     __doc__ = property(_get_doc)
      def __init__(self, module, func):
          self.module = module
          self.func = func
index 06754ea81cb13790a0395c2cdd4227fa78fd7041,d5392645387c8edd0d64a17b5e2e4e097056b3b3..401d445a53bbe576b8e1239597e1922f95b383df
@@@ -86,22 -86,22 +86,41 @@@ class CONSOLE_MT_report(bpy.types.Menu)
  class CONSOLE_MT_language(bpy.types.Menu):
      bl_label = "Languages..."
  
++<<<<<<< .working
 +    def draw(self, context):
 +        layout = self.layout
 +        layout.column()
 +        
 +        mod = bpy.ops.console
 +        languages = []
 +        for opname in dir(mod):
 +            # execute_python, execute_shell etc.
 +            if opname.startswith("execute_"):
 +                languages.append(opname.split('_', 1)[-1])
 +        
 +        languages.sort()
 +        
 +        for language in languages:
 +            layout.item_stringO("console.language", "language", language, text=language[0].upper() + language[1:])
 +
++=======
+     def draw(self, context):
+         layout = self.layout
+         layout.column()
+         mod = bpy.ops.console
+         languages = []
+         for opname in dir(mod):
+             # execute_python, execute_shell etc.
+             if opname.startswith("execute_"):
+                 languages.append(opname.split('_', 1)[-1])
+         languages.sort()
+         for language in languages:
+             layout.item_stringO("console.language", "language", language, text=language[0].upper() + language[1:])
++>>>>>>> .merge-right.r24463
  def add_scrollback(text, text_type):
      for l in text.split('\n'):
          bpy.ops.console.scrollback_append(text=l.replace('\t', '    '),
@@@ -147,6 -147,6 +166,8 @@@ class ConsoleAutocomplete(bpy.types.Ope
          else:
              print("Error: bpy.ops.console.autocomplete_" + sc.language + " - not found")
  
++<<<<<<< .working
++=======
          return ('FINISHED',)
  
  
@@@ -155,39 -155,39 +176,82 @@@ class ConsoleBanner(bpy.types.Operator)
  
      def execute(self, context):
          sc = context.space_data
++>>>>>>> .merge-right.r24463
+         # default to python
+         if not sc.language:
+             sc.language = 'python'
+         banner = getattr(bpy.ops.console, "banner_" + sc.language, None)
+         if banner:
+             banner()
+         else:
+             print("Error: bpy.ops.console.banner_" + sc.language + " - not found")
+         return ('FINISHED',)
+ class ConsoleLanguage(bpy.types.Operator):
+     '''Set the current language for this console'''
+     bl_idname = "console.language"
+     language = StringProperty(name="Language", maxlen= 32, default= "")
+     def execute(self, context):
+         sc = context.space_data
++<<<<<<< .working
 +        
 +        # default to python
 +        if not sc.language:
 +            sc.language = 'python'
++=======
++>>>>>>> .merge-right.r24463
  
++<<<<<<< .working
 +        banner = getattr(bpy.ops.console, "banner_" + sc.language, None)
 +        
 +        if banner:
 +            banner()
 +        else:
 +            print("Error: bpy.ops.console.banner_" + sc.language + " - not found")
++=======
+         # defailt to python
+         sc.language = self.language
++>>>>>>> .merge-right.r24463
  
++<<<<<<< .working
 +        return ('FINISHED',)
++=======
+         bpy.ops.console.banner()
++>>>>>>> .merge-right.r24463
 +
++<<<<<<< .working
 +
 +
 +class ConsoleLanguage(bpy.types.Operator):
 +    '''Set the current language for this console'''
 +    bl_idname = "console.language"
 +    language = StringProperty(name="Language", maxlen= 32, default= "")
 +
 +    def execute(self, context):
 +        sc = context.space_data
 +        
 +        # defailt to python
 +        sc.language = self.language
 +        
 +        bpy.ops.console.banner()
 +        
 +        # insert a new blank line
 +        bpy.ops.console.history_append(text="", current_character=0,
 +            remove_duplicates=True)
  
++=======
+         # insert a new blank line
+         bpy.ops.console.history_append(text="", current_character=0,
+             remove_duplicates=True)
++>>>>>>> .merge-right.r24463
          return ('FINISHED',)
  
  
index 87760d2da5eb16ca719432d9de02aa77ced8ab94,13f38dae6ea50012fc273895c9c3e34e835d4d7e..7d01557aa83bb9a0847f2df66c89d6091d5b9aa8
@@@ -164,44 -165,47 +165,47 @@@ short ANIM_add_driver (ID *id, const ch
        
        /* will only loop once unless the array index was -1 */
        for (; array_index < array_index_max; array_index++) {
 -              /* create F-Curve with Driver */
 -              fcu= verify_driver_fcurve(id, rna_path, array_index, 1);
 +      /* create F-Curve with Driver */
 +      fcu= verify_driver_fcurve(id, rna_path, array_index, 1);
                
 -              if (fcu && fcu->driver) {
 -                      fcu->driver->type= type;
 +      if (fcu && fcu->driver) {
 +              fcu->driver->type= type;
 +              
 +              /* fill in current value for python */
 +              if (type == DRIVER_TYPE_PYTHON) {
 +                      PropertyType proptype= RNA_property_type(prop);
 +                      int array= RNA_property_array_length(&ptr, prop);
 +                      char *expression= fcu->driver->expression;
 +                      int val, maxlen= sizeof(fcu->driver->expression);
 +                      float fval;
                        
 -                      /* fill in current value for python */
 -                      if (type == DRIVER_TYPE_PYTHON) {
 -                              PropertyType proptype= RNA_property_type(prop);
 -                              int array= RNA_property_array_length(&ptr, prop);
 -                              char *expression= fcu->driver->expression;
 -                              int val, maxlen= sizeof(fcu->driver->expression);
 -                              float fval;
 +                      if (proptype == PROP_BOOLEAN) {
 +                              if (!array) val= RNA_property_boolean_get(&ptr, prop);
 +                              else val= RNA_property_boolean_get_index(&ptr, prop, array_index);
                                
 -                              if (proptype == PROP_BOOLEAN) {
 -                                      if (!array) val= RNA_property_boolean_get(&ptr, prop);
 -                                      else val= RNA_property_boolean_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_strncpy(expression, (val)? "True": "False", maxlen);
 -                              }
 -                              else if (proptype == PROP_INT) {
 -                                      if (!array) val= RNA_property_int_get(&ptr, prop);
 -                                      else val= RNA_property_int_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_snprintf(expression, maxlen, "%d", val);
 -                              }
 -                              else if (proptype == PROP_FLOAT) {
 -                                      if (!array) fval= RNA_property_float_get(&ptr, prop);
 -                                      else fval= RNA_property_float_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_snprintf(expression, maxlen, "%.3f", fval);
 -                              }
 +                              BLI_strncpy(expression, (val)? "True": "False", maxlen);
 +                      }
 +                      else if (proptype == PROP_INT) {
 +                              if (!array) val= RNA_property_int_get(&ptr, prop);
 +                              else val= RNA_property_int_get_index(&ptr, prop, array_index);
 +                              
 +                              BLI_snprintf(expression, maxlen, "%d", val);
 +                      }
 +                      else if (proptype == PROP_FLOAT) {
 +                              if (!array) fval= RNA_property_float_get(&ptr, prop);
 +                              else fval= RNA_property_float_get_index(&ptr, prop, array_index);
 +                              
 +                              BLI_snprintf(expression, maxlen, "%.3f", fval);
                        }
                }
+               
+               /* set the done status */
+               done += (fcu != NULL);
        }
 +      }
        
        /* done */
-       return (fcu != NULL);
+       return done;
  }
  
  /* Main Driver Management API calls:
index 28272722e3cc7a3667415a80db72876f05640d05,6dad0b6e90f165d54341fd369bda830deab9cc22..a02a81bbeac2e3a6a84fa20fa1d29350809c48f9
@@@ -2103,23 -2141,34 +2141,34 @@@ void ARMATURE_OT_calculate_roll(wmOpera
  
  /* **************** undo for armatures ************** */
  
- static void undoBones_to_editBones(void *lbuv, void *lbev, void *data)
+ typedef struct UndoArmature {
+       EditBone *act_edbone;
+       ListBase lb;
+ } UndoArmature;
 -static void undoBones_to_editBones(void *uarmv, void *armv)
++static void undoBones_to_editBones(void *uarmv, void *armv, void *data)
  {
-       ListBase *lbu= lbuv;
-       ListBase *edbo= lbev;
+       UndoArmature *uarm= uarmv;
+       bArmature *arm= armv;
        EditBone *ebo, *newebo;
        
-       BLI_freelistN(edbo);
+       BLI_freelistN(arm->edbo);
        
        /* copy  */
-       for(ebo= lbu->first; ebo; ebo= ebo->next) {
+       for(ebo= uarm->lb.first; ebo; ebo= ebo->next) {
                newebo= MEM_dupallocN(ebo);
                ebo->temp= newebo;
-               BLI_addtail(edbo, newebo);
+               BLI_addtail(arm->edbo, newebo);
        }
        
+       /* active bone */
+       if(uarm->act_edbone) {
+               ebo= uarm->act_edbone;
+               arm->act_edbone= ebo->temp;
+       }
        /* set pointers */
-       for(newebo= edbo->first; newebo; newebo= newebo->next) {
+       for(newebo= arm->edbo->first; newebo; newebo= newebo->next) {
                if(newebo->parent) newebo->parent= newebo->parent->temp;
        }
        /* be sure they dont hang ever */
        }
  }
  
- static void *editBones_to_undoBones(void *lbev, void *obdata)
 -static void *editBones_to_undoBones(void *armv)
++static void *editBones_to_undoBones(void *armv, void *obdata)
  {
-       ListBase *edbo= lbev;
-       ListBase *lb;
+       bArmature *arm= armv;
+       UndoArmature *uarm;
        EditBone *ebo, *newebo;
        
-       lb= MEM_callocN(sizeof(ListBase), "listbase undo");
+       uarm= MEM_callocN(sizeof(UndoArmature), "listbase undo");
        
        /* copy */
-       for(ebo= edbo->first; ebo; ebo= ebo->next) {
+       for(ebo= arm->edbo->first; ebo; ebo= ebo->next) {
                newebo= MEM_dupallocN(ebo);
                ebo->temp= newebo;
-               BLI_addtail(lb, newebo);
+               BLI_addtail(&uarm->lb, newebo);
        }
        
+       /* active bone */
+       if(arm->act_edbone) {
+               ebo= arm->act_edbone;
+               uarm->act_edbone= ebo->temp;
+       }
        /* set pointers */
-       for(newebo= lb->first; newebo; newebo= newebo->next) {
+       for(newebo= uarm->lb.first; newebo; newebo= newebo->next) {
                if(newebo->parent) newebo->parent= newebo->parent->temp;
        }
        
index 06ea163eb8dce0cf10cbe06d2bac04a664ed9f48,18125207eca4b21018ed04a326be3218ec96b58b..94fb7f5a638f729f41972bd85575def536fb10b7
@@@ -126,11 -123,11 +126,11 @@@ int join_mesh_exec(bContext *C, wmOpera
        KeyBlock *kb, *okb, *kbn;
        float imat[4][4], cmat[4][4], *fp1, *fp2, curpos;
        int a, b, totcol, totmat=0, totedge=0, totvert=0, totface=0, ok=0;
-       int totloop=0, totpoly=0, vertofs, *matmap;
-       int     i, j, index, haskey=0, edgeofs, faceofs, loopofs, polyofs;
 -      int vertofs, *matmap=NULL;
 -      int     i, j, index, haskey=0, edgeofs, faceofs;
++      int totloop=0, totpoly=0, vertofs, *matmap=NULL;
++      int i, j, index, haskey=0, edgeofs, faceofs, loopofs, polyofs;
        bDeformGroup *dg, *odg;
        MDeformVert *dvert;
 -      CustomData vdata, edata, fdata;
 +      CustomData vdata, edata, fdata, ldata, pdata;
  
        if(scene->obedit)
                return OPERATOR_CANCELLED;
index e4eaa7671a4d9c17b2340bd1cfabcfa106ae2973,2505110d766a401493c90a7291f8900e2581ad7a..f277633811a5b3a5a53343ea7bf3f0016106255e
@@@ -1413,8 -1406,8 +1422,8 @@@ static int view3d_borderselect_exec(bCo
        if(obedit) {
                if(obedit->type==OB_MESH) {
                        Mesh *me= obedit->data;
 -                      vc.em= me->edit_mesh;
 +                      vc.em= me->edit_btmesh;
-                       do_mesh_box_select(&vc, &rect, (val==LEFTMOUSE));
+                       do_mesh_box_select(&vc, &rect, selecting);
  //                    if (EM_texFaceCheck())
                        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
                        
                                }
                        }
                        
 -                      ED_armature_sync_selection(arm->edbo);
                }
                else if(obedit->type==OB_LATTICE) {
-                       do_lattice_box_select(&vc, &rect, val==LEFTMOUSE);
+                       do_lattice_box_select(&vc, &rect, selecting);
                }
        }
        else {  /* no editmode, unified for bones and objects */
index 3a871500ae77561f86459509d6930672df2a0d0f,86e83715da428cd52f910b072f5c47420cddf937..8c6e73800a994d4c8bff0ea7471bb52c9c5bf290
@@@ -495,13 -484,15 +487,15 @@@ int calc_manipulator_stats(const bConte
                        Mat3One(mat);
                        gimbal_axis(ob, mat);
                        Mat4CpyMat3(rv3d->twmat, mat);
 -                      break;
 -              }
 +                                              break;
 +                                              }
                case V3D_MANIP_NORMAL:
                        if(obedit || ob->mode & OB_MODE_POSE) {
-                               getTransformOrientationMatrix(C, rv3d->twmat, (v3d->around == V3D_ACTIVE));
+                               float mat[3][3];
+                               ED_getTransformOrientationMatrix(C, mat, (v3d->around == V3D_ACTIVE));
+                               Mat4CpyMat3(rv3d->twmat, mat);
 -                              break;
 -                      }
 +                                              break;
 +                                              }
                        /* no break we define 'normal' as 'local' in Object mode */
                case V3D_MANIP_LOCAL:
                        Mat4CpyMat4(rv3d->twmat, ob->obmat);
index 509dd16cd46d05b78d5066c51d24a334a12ee411,0cb2515828d2159373b66f6c54a9292f2cdd6493..f75ff24878cd5d06c63d908626a1e592031104ef
@@@ -533,9 -529,9 +530,9 @@@ void initTransformOrientation(bContext 
        case V3D_MANIP_NORMAL:
                if(obedit || (ob && ob->mode & OB_MODE_POSE)) {
                        strcpy(t->spacename, "normal");
-                       getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
+                       ED_getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
 -                      break;
 -              }
 +                                      break;
 +                                      }
                /* no break we define 'normal' as 'local' in Object mode */
        case V3D_MANIP_LOCAL:
                strcpy(t->spacename, "local");
index c29eafc8b74d8f46920e60d03f385c8b2439be5e,c06931feedb7156ef4e65db7ec93db4b1060409f..af23b766985485eaa79976275d39eb42f587fc9e
@@@ -1412,10 -1416,11 +1416,11 @@@ static PyObject *pyrna_struct_getattro
                if(self->ptr.id.data) {
                        PointerRNA id_ptr;
                        RNA_id_pointer_create((ID *)self->ptr.id.data, &id_ptr);
-                       return pyrna_struct_CreatePyObject(&id_ptr);
+                       ret = pyrna_struct_CreatePyObject(&id_ptr);
                }
 -              else {
 +      else {
-                       Py_RETURN_NONE;
+                       ret = Py_None;
+                       Py_INCREF(ret);
                }
        }
        else {
Simple merge