merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
authorJoseph Eagar <joeedh@gmail.com>
Tue, 9 Mar 2010 04:32:40 +0000 (04:32 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Tue, 9 Mar 2010 04:32:40 +0000 (04:32 +0000)
229 files changed:
1  2 
SConstruct
config/win32-vc-config.py
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_Mixer.h
intern/ghost/intern/GHOST_DisplayManagerCocoa.h
intern/ghost/intern/GHOST_DisplayManagerCocoa.mm
intern/ghost/intern/GHOST_SystemCocoa.h
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_WindowCocoa.h
intern/ghost/intern/GHOST_WindowCocoa.mm
intern/guardedalloc/MEM_guardedalloc.h
intern/guardedalloc/intern/mallocn.c
intern/guardedalloc/intern/mmap_win.c
projectfiles_vc9/blender/blender.vcproj
projectfiles_vc9/blender/makesrna/RNA_makesrna.vcproj
projectfiles_vc9/blender/makesrna/RNA_rna.vcproj
projectfiles_vc9/gameengine/gameplayer/common/GP_common.vcproj
source/blender/CMakeLists.txt
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/BKE_bmesh.h
source/blender/blenkernel/BKE_cdderivedmesh.h
source/blender/blenkernel/BKE_customdata.h
source/blender/blenkernel/BKE_key.h
source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/BKE_utildefines.h
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/BME_Customdata.c
source/blender/blenkernel/intern/BME_conversions.c
source/blender/blenkernel/intern/BME_mesh.c
source/blender/blenkernel/intern/BME_tools.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/booleanops.c
source/blender/blenkernel/intern/bvhutils.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/exotic.c
source/blender/blenkernel/intern/fluidsim.c
source/blender/blenkernel/intern/fmodifier.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/shrinkwrap.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenkernel/nla_private.h
source/blender/blenlib/BLI_cellalloc.h
source/blender/blenlib/BLI_edgehash.h
source/blender/blenlib/BLI_editVert.h
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/BLI_mempool.h
source/blender/blenlib/SConscript
source/blender/blenlib/intern/BLI_cellalloc.c
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/BLI_mempool.c
source/blender/blenlib/intern/edgehash.c
source/blender/blenlib/intern/math_vector_inline.c
source/blender/blenlib/intern/pbvh.c
source/blender/blenlib/intern/scanfill.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/intern/bmesh_mesh.c
source/blender/bmesh/intern/bmesh_operators.c
source/blender/bmesh/intern/bmesh_walkers.c
source/blender/bmesh/operators/createops.c
source/blender/editors/CMakeLists.txt
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/armature/poseobject.c
source/blender/editors/armature/reeb.c
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editfont.c
source/blender/editors/include/ED_mesh.h
source/blender/editors/include/ED_util.h
source/blender/editors/include/ED_uvedit.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/include/UI_resources.h
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/resources.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/bmeshutils.c
source/blender/editors/mesh/editbmesh_add.c
source/blender/editors/mesh/mesh_data.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/metaball/mball_edit.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_hook.c
source/blender/editors/object/object_lattice.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_transform.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/physics/particle_object.c
source/blender/editors/render/SConscript
source/blender/editors/render/render_shading.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_utils.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_header.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_info/info_stats.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.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_header.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_ops.c
source/blender/editors/transform/transform_orientations.c
source/blender/editors/transform/transform_snap.c
source/blender/editors/util/ed_util.c
source/blender/editors/util/editmode_undo.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/editors/uvedit/uvedit_intern.h
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_parametrizer.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/gpu/gpu_buffers.h
source/blender/gpu/intern/gpu_buffers.c
source/blender/ikplugin/intern/itasc_plugin.cpp
source/blender/makesdna/DNA_customdata_types.h
source/blender/makesdna/DNA_key_types.h
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_meshdata_types.h
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesdna/intern/SConscript
source/blender/makesrna/SConscript
source/blender/makesrna/intern/SConscript
source/blender/makesrna/intern/rna_animviz.c
source/blender/makesrna/intern/rna_image_api.c
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_mesh_api.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_nla.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_pose_api.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/makesrna/intern/rna_wm_api.c
source/blender/python/generic/Geometry.c
source/blender/python/generic/Geometry.h
source/blender/python/generic/Mathutils.c
source/blender/python/generic/Mathutils.h
source/blender/python/generic/bpy_internal_import.c
source/blender/python/generic/bpy_internal_import.h
source/blender/python/generic/euler.c
source/blender/python/generic/euler.h
source/blender/python/generic/matrix.c
source/blender/python/generic/matrix.h
source/blender/python/generic/quat.c
source/blender/python/generic/quat.h
source/blender/python/generic/vector.c
source/blender/python/generic/vector.h
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_operator.h
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_operator_wrap.h
source/blender/python/rna_dump.py
source/blender/python/simple_enum_gen.py
source/blender/readblenfile/intern/BLO_readblenfile.c
source/blender/render/intern/include/raycounter.h
source/blender/render/intern/include/rayobject.h
source/blender/render/intern/raytrace/reorganize.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pointdensity.c
source/blender/render/intern/source/rayobject_blibvh.c
source/blender/render/intern/source/rayobject_instance.c
source/blender/render/intern/source/rayobject_octree.c
source/blender/render/intern/source/rayobject_raycounter.c
source/blender/render/intern/source/shadeoutput.c
source/blender/render/intern/source/strand.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_operators.c
source/creator/CMakeLists.txt
source/creator/creator.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Converter/BL_ArmatureActuator.cpp
source/gameengine/Converter/BL_ArmatureActuator.h
source/gameengine/Converter/BL_ArmatureChannel.cpp
source/gameengine/Converter/BL_ArmatureChannel.h
source/gameengine/Converter/BL_ArmatureConstraint.cpp
source/gameengine/Converter/BL_ArmatureConstraint.h
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/GameLogic/SCA_BasicEventManager.cpp
source/gameengine/GameLogic/SCA_BasicEventManager.h
source/gameengine/Ketsji/KX_ArmatureSensor.cpp
source/gameengine/Ketsji/KX_ArmatureSensor.h
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
tools/Blender.py
tools/btools.py

diff --cc SConstruct
index ab20bb857aba4196036ec52dd0d9620bb37fc693,7e432bf7dfae1442d45caf58d47570f13e001dc4..bfb36ce7ceedfa20a3254a6b90bf94e0b5a73ef5
@@@ -591,8 -583,9 +583,9 @@@ if env['OURPLATFORM'] in ('win32-vc', '
                        pass # we link statically already to SDL on win64
                else:
                        dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
        if env['WITH_BF_PYTHON']:
 -              if env['BF_DEBUG']:
 +              if env['BF_DEBUG'] and not env["BF_NO_PYDEBUG"]:
                        dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
                else:
                        dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
Simple merge
Simple merge
Simple merge
index cd2362ab538dde35195e2da02bb8eda7f2ea506c,ab3abdd659fd158c99b339743bef233c078048a4..991188524df44e167bbff1e7c0b5dbd8ac577ef0
 -/**
 - * $Id$
 - * ***** BEGIN GPL LICENSE BLOCK *****
 - *
 - * This program is free software; you can redistribute it and/or
 - * modify it under the terms of the GNU General Public License
 - * as published by the Free Software Foundation; either version 2
 - * of the License, or (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software Foundation,
 +/**\r
 + * $Id: GHOST_DisplayManagerCocoa.mm 23603 2009-10-02 07:20:33Z 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
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 - *
 - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 - * All rights reserved.
 - *
 - * The Original Code is: all of this file.
 - *
 - * Contributor(s):    Maarten Gribnau 09/2001
 -                                      Damien Plisson  10/2009
 - *
 - * ***** END GPL LICENSE BLOCK *****
 - */
 -
 -#include <Cocoa/Cocoa.h>
 -
 -#include "GHOST_DisplayManagerCocoa.h"
 -#include "GHOST_Debug.h"
 -
 -// We do not support multiple monitors at the moment
 -
 -
 -GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void)
 -{
 -}
 -
 -
 -GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(GHOST_TUns8& numDisplays) const
 -{
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      numDisplays = (GHOST_TUns8) [[NSScreen screens] count];
 -      
 -      [pool drain];
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
 -{
 -      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getNumDisplaySettings(): only main display is supported");
 -      
 -      numSettings = (GHOST_TInt32)3; //Width, Height, BitsPerPixel
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
 -{
 -      //Note that only current display setting is available
 -      NSScreen *askedDisplay;
 -      
 -      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getDisplaySetting(): only main display is supported");
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      if (display == kMainDisplay) //Screen #0 may not be the main one
 -              askedDisplay = [NSScreen mainScreen];
 -      else
 -              askedDisplay = [[NSScreen screens] objectAtIndex:display];
 -      
 -      if(askedDisplay == nil) {
 -              [pool drain];
 -              return GHOST_kFailure;
 -      }
 -      
 -      NSRect frame = [askedDisplay visibleFrame];
 -      setting.xPixels = frame.size.width;
 -      setting.yPixels = frame.size.height;
 -      
 -      setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
 -      
 -      setting.frequency = 0; //No more CRT display...
 -                              
 -#ifdef GHOST_DEBUG
 -      printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
 -#endif // GHOST_DEBUG
 -
 -      [pool drain];
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
 -{
 -      NSScreen *askedDisplay;
 -      
 -      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");
 -    
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];     
 -
 -      if (display == kMainDisplay) //Screen #0 may not be the main one
 -              askedDisplay = [NSScreen mainScreen];
 -      else
 -              askedDisplay = [[NSScreen screens] objectAtIndex:display];
 -      
 -      if(askedDisplay == nil) {
 -              [pool drain];
 -              return GHOST_kFailure;
 -      }
 -      
 -      NSRect frame = [askedDisplay visibleFrame];
 -      setting.xPixels = frame.size.width;
 -      setting.yPixels = frame.size.height;
 -      
 -      setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
 -      
 -      setting.frequency = 0; //No more CRT display...
 -
 -#ifdef GHOST_DEBUG
 -      printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
 -#endif // GHOST_DEBUG
 -
 -      [pool drain];
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
 -{
 -      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");
 -
 -#ifdef GHOST_DEBUG
 -      printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");
 -      printf("  setting.xPixels=%d\n", setting.xPixels);
 -      printf("  setting.yPixels=%d\n", setting.yPixels);
 -      printf("  setting.bpp=%d\n", setting.bpp);
 -      printf("  setting.frequency=%d\n", setting.frequency);
 -#endif // GHOST_DEBUG
 -
 -      //Display configuration is no more available in 10.6
 -      
 -/*    CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
 -              m_displayIDs[display],
 -              (size_t)setting.bpp,
 -              (size_t)setting.xPixels,
 -              (size_t)setting.yPixels,
 -              (CGRefreshRate)setting.frequency,
 -              NULL);*/
 -
 -#ifdef GHOST_DEBUG
 + *\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 09/2001\r
 +                                      Damien Plisson  10/2009\r
 + *\r
 + * ***** END GPL LICENSE BLOCK *****\r
 + */\r
 +\r
 +#include <Cocoa/Cocoa.h>\r
 +\r
 +#include "GHOST_DisplayManagerCocoa.h"\r
 +#include "GHOST_Debug.h"\r
 +\r
 +// We do not support multiple monitors at the moment\r
 +\r
 +\r
 +GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void)\r
 +{\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(GHOST_TUns8& numDisplays) const\r
 +{\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      numDisplays = (GHOST_TUns8) [[NSScreen screens] count];\r
 +      \r
 +      [pool drain];\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const\r
 +{\r
 +      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getNumDisplaySettings(): only main display is supported");\r
 +      \r
 +      numSettings = (GHOST_TInt32)3; //Width, Height, BitsPerPixel\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const\r
 +{\r
 +      //Note that only current display setting is available\r
 +      NSScreen *askedDisplay;\r
 +      \r
 +      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getDisplaySetting(): only main display is supported");\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      if (display == kMainDisplay) //Screen #0 may not be the main one\r
 +              askedDisplay = [NSScreen mainScreen];\r
 +      else\r
 +              askedDisplay = [[NSScreen screens] objectAtIndex:display];\r
 +      \r
 +      if(askedDisplay == nil) {\r
 +              [pool drain];\r
 +              return GHOST_kFailure;\r
 +      }\r
 +      \r
 +      NSRect frame = [askedDisplay visibleFrame];\r
 +      setting.xPixels = frame.size.width;\r
 +      setting.yPixels = frame.size.height;\r
 +      \r
 +      setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);\r
 +      \r
 +      setting.frequency = 0; //No more CRT display...\r
 +                              \r
 +#ifdef GHOST_DEBUG\r
 +      printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);\r
 +#endif // GHOST_DEBUG\r
 +\r
 +      [pool drain];\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const\r
 +{\r
 +      NSScreen *askedDisplay;\r
 +      \r
 +      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");\r
 +    \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];     \r
 +\r
 +      if (display == kMainDisplay) //Screen #0 may not be the main one\r
 +              askedDisplay = [NSScreen mainScreen];\r
 +      else\r
 +              askedDisplay = [[NSScreen screens] objectAtIndex:display];\r
 +      \r
 +      if(askedDisplay == nil) {\r
 +              [pool drain];\r
 +              return GHOST_kFailure;\r
 +      }\r
 +      \r
 +      NSRect frame = [askedDisplay visibleFrame];\r
 +      setting.xPixels = frame.size.width;\r
 +      setting.yPixels = frame.size.height;\r
 +      \r
 +      setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);\r
 +      \r
 +      setting.frequency = 0; //No more CRT display...\r
 +\r
 +#ifdef GHOST_DEBUG\r
 +      printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);\r
 +#endif // GHOST_DEBUG\r
 +\r
 +      [pool drain];\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)\r
 +{\r
 +      GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");\r
 +\r
 +#ifdef GHOST_DEBUG\r
 +      printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");\r
 +      printf("  setting.xPixels=%d\n", setting.xPixels);\r
 +      printf("  setting.yPixels=%d\n", setting.yPixels);\r
 +      printf("  setting.bpp=%d\n", setting.bpp);\r
 +      printf("  setting.frequency=%d\n", setting.frequency);\r
 +#endif // GHOST_DEBUG\r
 +\r
 +      //Display configuration is no more available in 10.6\r
 +      \r
 +/*    CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(\r
 +              m_displayIDs[display],\r
 +              (size_t)setting.bpp,\r
 +              (size_t)setting.xPixels,\r
 +              (size_t)setting.yPixels,\r
 +              (CGRefreshRate)setting.frequency,\r
 +              NULL);*/\r
 +\r
 +#ifdef GHOST_DEBUG\r
  /*    printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): switching to:\n");
 -      printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
 -      printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
 -      printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
 +      printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));\r
 +      printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));\r
 +      printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));\r
        printf("  setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate)); */
 -#endif // GHOST_DEBUG
 -
 -      //CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
 -        
 -      return /*err == CGDisplayNoErr ? GHOST_kSuccess :*/ GHOST_kFailure;
 -}
 +#endif // GHOST_DEBUG\r
 +\r
 +      //CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);\r
 +        \r
 +      return /*err == CGDisplayNoErr ? GHOST_kSuccess :*/ GHOST_kFailure;\r
 +}\r
index c2d3b56ce59d6f5030c04587fd53d9e534a074bc,5289920cccb3d6f05013f52d0479cbe611ca267e..a5ee257bcd4646f4ded71bc58d3f77a3719a52b4
 -/**
 - * $Id$
 - * ***** BEGIN GPL LICENSE BLOCK *****
 - *
 - * This program is free software; you can redistribute it and/or
 - * modify it under the terms of the GNU General Public License
 - * as published by the Free Software Foundation; either version 2
 - * of the License, or (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software Foundation,
 +/**\r
 + * $Id: GHOST_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
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 - *
 - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 - * All rights reserved.
 - *
 - * The Original Code is: all of this file.
 - *
 - * Contributor(s):    Maarten Gribnau 05/2001
 - *                                    Damien Plisson 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
 + * 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_EventTrackpad.h"
  #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;
 -}
 -
 -
+ #include "GHOST_EventString.h"
 +\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
  #pragma mark defines for 10.6 api not documented in 10.5
  #ifndef MAC_OS_X_VERSION_10_6
  enum {
@@@ -500,100 -490,119 +490,119 @@@ int cocoa_request_qtcodec_settings(bCon
  {
        systemCocoa->handleApplicationBecomeActiveEvent();
  }
 -@end
 -
 -
 -
 -#pragma mark initialization/finalization
 -
 -
 -GHOST_SystemCocoa::GHOST_SystemCocoa()
 -{
 +@end\r
 +\r
 +\r
 +\r
 +#pragma mark initialization/finalization\r
 +\r
 +\r
 +GHOST_SystemCocoa::GHOST_SystemCocoa()\r
 +{\r
+       int mib[2];
+       struct timeval boottime;
+       size_t len;
+       char *rstring = NULL;
+       
 -      m_modifierMask =0;
 -      m_pressedMouseButtons =0;
 +      m_modifierMask =0;\r
 +      m_pressedMouseButtons =0;\r
+       m_isGestureInProgress = false;
        m_cursorDelta_x=0;
        m_cursorDelta_y=0;
        m_outsideLoopEventProcessed = false;
 -      m_displayManager = new GHOST_DisplayManagerCocoa ();
 -      GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");
 -      m_displayManager->initialize();
 -
 -      //NSEvent timeStamp is given in system uptime, state start date is boot time
 -      mib[0] = CTL_KERN;
 -      mib[1] = KERN_BOOTTIME;
 -      len = sizeof(struct timeval);
 -      
 -      sysctl(mib, 2, &boottime, &len, NULL, 0);
 -      m_start_time = ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));
 -      
+       m_needDelayedApplicationBecomeActiveEventProcessing = false;
-       int mib[2];\r
-       struct timeval boottime;\r
-       size_t len;\r
-       \r
 +      m_displayManager = new GHOST_DisplayManagerCocoa ();\r
 +      GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");\r
 +      m_displayManager->initialize();\r
 +\r
 +      //NSEvent timeStamp is given in system uptime, state start date is boot time\r
 -      m_ignoreWindowSizedMessages = false;
 -}
 -
 -GHOST_SystemCocoa::~GHOST_SystemCocoa()
 -{
 -}
 -
 -
 -GHOST_TSuccess GHOST_SystemCocoa::init()
 -{
 -      
 -    GHOST_TSuccess success = GHOST_System::init();
 -    if (success) {
 -              //ProcessSerialNumber psn;
 -              
 -              //Carbon stuff to move window & menu to foreground
 -              /*if (!GetCurrentProcess(&psn)) {
 -                      TransformProcessType(&psn, kProcessTransformToForegroundApplication);
 -                      SetFrontProcess(&psn);
 -              }*/
 -              
 -              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -              if (NSApp == nil) {
 -                      [NSApplication sharedApplication];
 -                      
 -                      if ([NSApp mainMenu] == nil) {
 -                              NSMenu *mainMenubar = [[NSMenu alloc] init];
 -                              NSMenuItem *menuItem;
 -                              NSMenu *windowMenu;
 -                              NSMenu *appMenu;
 -                              
 -                              //Create the application menu
 -                              appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];
 -                              
 -                              [appMenu addItemWithTitle:@"About Blender" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
 -                              [appMenu addItem:[NSMenuItem separatorItem]];
 -                              
 -                              menuItem = [appMenu addItemWithTitle:@"Hide Blender" action:@selector(hide:) keyEquivalent:@"h"];
 -                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
 -                               
 -                              menuItem = [appMenu addItemWithTitle:@"Hide others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
 -                              [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];
 -                              
 -                              [appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
 -                              
 -                              menuItem = [appMenu addItemWithTitle:@"Quit Blender" action:@selector(terminate:) keyEquivalent:@"q"];
 -                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
 -                              
 -                              menuItem = [[NSMenuItem alloc] init];
 -                              [menuItem setSubmenu:appMenu];
 -                              
 -                              [mainMenubar addItem:menuItem];
 -                              [menuItem release];
 -                              [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; //Needed for 10.5
 -                              [appMenu release];
 -                              
 -                              //Create the window menu
 -                              windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
 -                              
 -                              menuItem = [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
 -                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
 -                              
 -                              [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
 -                              
 +      mib[0] = CTL_KERN;\r
 +      mib[1] = KERN_BOOTTIME;\r
 +      len = sizeof(struct timeval);\r
 +      \r
 +      sysctl(mib, 2, &boottime, &len, NULL, 0);\r
 +      m_start_time = ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));\r
 +      \r
+       //Detect multitouch trackpad
+       mib[0] = CTL_HW;
+       mib[1] = HW_MODEL;
+       sysctl( mib, 2, NULL, &len, NULL, 0 );
+       rstring = (char*)malloc( len );
+       sysctl( mib, 2, rstring, &len, NULL, 0 );
+       
+       //Hack on MacBook revision, as multitouch avail. function missing
+       if (strstr(rstring,"MacBookAir") ||
+               (strstr(rstring,"MacBook") && (rstring[strlen(rstring)-3]>='5') && (rstring[strlen(rstring)-3]<='9')))
+               m_hasMultiTouchTrackpad = true;
+       else m_hasMultiTouchTrackpad = false;
+       
+       free( rstring );
+       rstring = NULL;
+       
 +      m_ignoreWindowSizedMessages = false;\r
 +}\r
 +\r
 +GHOST_SystemCocoa::~GHOST_SystemCocoa()\r
 +{\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::init()\r
 +{\r
 +      \r
 +    GHOST_TSuccess success = GHOST_System::init();\r
 +    if (success) {\r
 +              //ProcessSerialNumber psn;\r
 +              \r
 +              //Carbon stuff to move window & menu to foreground\r
 +              /*if (!GetCurrentProcess(&psn)) {\r
 +                      TransformProcessType(&psn, kProcessTransformToForegroundApplication);\r
 +                      SetFrontProcess(&psn);\r
 +              }*/\r
 +              \r
 +              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +              if (NSApp == nil) {\r
 +                      [NSApplication sharedApplication];\r
 +                      \r
 +                      if ([NSApp mainMenu] == nil) {\r
 +                              NSMenu *mainMenubar = [[NSMenu alloc] init];\r
 +                              NSMenuItem *menuItem;\r
 +                              NSMenu *windowMenu;\r
 +                              NSMenu *appMenu;\r
 +                              \r
 +                              //Create the application menu\r
 +                              appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];\r
 +                              \r
 +                              [appMenu addItemWithTitle:@"About Blender" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];\r
 +                              [appMenu addItem:[NSMenuItem separatorItem]];\r
 +                              \r
 +                              menuItem = [appMenu addItemWithTitle:@"Hide Blender" action:@selector(hide:) keyEquivalent:@"h"];\r
 +                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
 +                               \r
 +                              menuItem = [appMenu addItemWithTitle:@"Hide others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];\r
 +                              [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];\r
 +                              \r
 +                              [appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];\r
 +                              \r
 +                              menuItem = [appMenu addItemWithTitle:@"Quit Blender" action:@selector(terminate:) keyEquivalent:@"q"];\r
 +                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
 +                              \r
 +                              menuItem = [[NSMenuItem alloc] init];\r
 +                              [menuItem setSubmenu:appMenu];\r
 +                              \r
 +                              [mainMenubar addItem:menuItem];\r
 +                              [menuItem release];\r
 +                              [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; //Needed for 10.5\r
 +                              [appMenu release];\r
 +                              \r
 +                              //Create the window menu\r
 +                              windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];\r
 +                              \r
 +                              menuItem = [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];\r
 +                              [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];\r
 +                              \r
 +                              [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];\r
 +                              \r
                                menuItem = [windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
                                [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
                                
@@@ -868,39 -877,41 +877,41 @@@ bool GHOST_SystemCocoa::processEvents(b
                                case NSOtherMouseDragged:
                                case NSEventTypeMagnify:
                                case NSEventTypeRotate:
 -                                      handleMouseEvent(event);
 -                                      break;
 -                                      
 -                              case NSTabletPoint:
 -                              case NSTabletProximity:
 -                                      handleTabletEvent(event,[event type]);
 -                                      break;
 -                                      
+                               case NSEventTypeBeginGesture:
+                               case NSEventTypeEndGesture:
 +                                      handleMouseEvent(event);\r
 +                                      break;\r
 +                                      \r
 +                              case NSTabletPoint:\r
 +                              case NSTabletProximity:\r
 +                                      handleTabletEvent(event,[event type]);\r
 +                                      break;\r
 +                                      \r
                                        /* Trackpad features, fired only from OS X 10.5.2
 -                                       case NSEventTypeGesture:
 -                                       case NSEventTypeSwipe:
 -                                       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
 -      
 +                                       case NSEventTypeGesture:\r
 +                                       case NSEventTypeSwipe:\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
+       if (m_needDelayedApplicationBecomeActiveEventProcessing) handleApplicationBecomeActiveEvent();
+       
        if (m_outsideLoopEventProcessed) {
                m_outsideLoopEventProcessed = false;
                return true;
@@@ -916,20 -927,15 +927,15 @@@ GHOST_TSuccess GHOST_SystemCocoa::handl
        //(that is when update events are sent to another application)
        unsigned int modifiers;
        GHOST_IWindow* window = m_windowManager->getActiveWindow();
- #ifdef MAC_OS_X_VERSION_10_6
-       modifiers = [NSEvent modifierFlags];
- #else
-       //If build against an older SDK, check if running on 10.6 to use the correct function
-       if ([NSEvent respondsToSelector:@selector(modifierFlags)]) {
-               modifiers = [NSEvent modifierFlags];
-       }
-       else {
-               //TODO: need to find a better workaround for the missing cocoa "getModifierFlag" function in 10.4/10.5
-               modifiers = 0;
+       
+       if (!window) {
+               m_needDelayedApplicationBecomeActiveEventProcessing = true;
+               return GHOST_kFailure;
        }
- #endif
+       else m_needDelayedApplicationBecomeActiveEventProcessing = false;
+       modifiers = [[[NSApplication sharedApplication] currentEvent] modifierFlags];
 -      
 +      \r
        if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {
                pushEvent( new GHOST_EventKey(getMilliSeconds(), (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );
        }
        
        m_modifierMask = modifiers;
        
+       m_outsideLoopEventProcessed = true;
        return GHOST_kSuccess;
 -}
 -
 -//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;
 +}\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_kEventWindowMove:
+                               pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, window) );
+                               break;
 -                      case GHOST_kEventWindowSize:
 -                              if (!m_ignoreWindowSizedMessages)
 -                              {
 -                                      window->updateDrawingContext();
 -                                      pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) );
 -                              }
 -                              break;
 -                      default:
 -                              return GHOST_kFailure;
 -                              break;
 -              }
 +                      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
        
        m_outsideLoopEventProcessed = true;
 -      return GHOST_kSuccess;
 -}
 -
 +      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)
@@@ -1147,121 -1294,127 +1294,127 @@@ bool GHOST_SystemCocoa::handleOpenDocum
        else return NO;
  }
  
 -GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)
 -{
 -      NSEvent *event = (NSEvent *)eventPtr;
 +GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)\r
 +{\r
 +      NSEvent *event = (NSEvent *)eventPtr;\r
-       GHOST_IWindow* window = m_windowManager->getActiveWindow();\r
+       GHOST_IWindow* window;
        
-       if (!window) return GHOST_kFailure;
+       window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
+       if (!window) {
+               //printf("\nW failure for event 0x%x",[event type]);
+               return GHOST_kFailure;
+       }
        
 -      GHOST_TabletData& ct=((GHOST_WindowCocoa*)window)->GetCocoaTabletData();
 -      
 -      switch (eventType) {
 -              case NSTabletPoint:
 +      GHOST_TabletData& ct=((GHOST_WindowCocoa*)window)->GetCocoaTabletData();\r
 +      \r
 +      switch (eventType) {\r
 +              case NSTabletPoint:\r
                        ct.Pressure = [event pressure];
 -                      ct.Xtilt = [event tilt].x;
 -                      ct.Ytilt = [event tilt].y;
 -                      break;
 -              
 -              case NSTabletProximity:
 -                      ct.Pressure = 0;
 -                      ct.Xtilt = 0;
 -                      ct.Ytilt = 0;
 -                      if ([event isEnteringProximity])
 -                      {
 -                              //pointer is entering tablet area proximity
 -                              switch ([event pointingDeviceType]) {
 -                                      case NSPenPointingDevice:
 -                                              ct.Active = GHOST_kTabletModeStylus;
 -                                              break;
 -                                      case NSEraserPointingDevice:
 -                                              ct.Active = GHOST_kTabletModeEraser;
 -                                              break;
 -                                      case NSCursorPointingDevice:
 -                                      case NSUnknownPointingDevice:
 -                                      default:
 -                                              ct.Active = GHOST_kTabletModeNone;
 -                                              break;
 -                              }
 -                      } else {
 -                              // pointer is leaving - return to mouse
 -                              ct.Active = GHOST_kTabletModeNone;
 -                      }
 -                      break;
 -              
 -              default:
 -                      GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received");
 -                      return GHOST_kFailure;
 -                      break;
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
 -{
 -      NSEvent *event = (NSEvent *)eventPtr;
 +                      ct.Xtilt = [event tilt].x;\r
 +                      ct.Ytilt = [event tilt].y;\r
 +                      break;\r
 +              \r
 +              case NSTabletProximity:\r
 +                      ct.Pressure = 0;\r
 +                      ct.Xtilt = 0;\r
 +                      ct.Ytilt = 0;\r
 +                      if ([event isEnteringProximity])\r
 +                      {\r
 +                              //pointer is entering tablet area proximity\r
 +                              switch ([event pointingDeviceType]) {\r
 +                                      case NSPenPointingDevice:\r
 +                                              ct.Active = GHOST_kTabletModeStylus;\r
 +                                              break;\r
 +                                      case NSEraserPointingDevice:\r
 +                                              ct.Active = GHOST_kTabletModeEraser;\r
 +                                              break;\r
 +                                      case NSCursorPointingDevice:\r
 +                                      case NSUnknownPointingDevice:\r
 +                                      default:\r
 +                                              ct.Active = GHOST_kTabletModeNone;\r
 +                                              break;\r
 +                              }\r
 +                      } else {\r
 +                              // pointer is leaving - return to mouse\r
 +                              ct.Active = GHOST_kTabletModeNone;\r
 +                      }\r
 +                      break;\r
 +              \r
 +              default:\r
 +                      GHOST_ASSERT(FALSE,"GHOST_SystemCocoa::handleTabletEvent : unknown event received");\r
 +                      return GHOST_kFailure;\r
 +                      break;\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)\r
 +{\r
 +      NSEvent *event = (NSEvent *)eventPtr;\r
-     GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();\r
+     GHOST_Window* window;
 -      
 +      \r
+       window = (GHOST_Window*)m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
 -      if (!window) {
 +      if (!window) {\r
+               //printf("\nW failure for event 0x%x",[event type]);
 -              return GHOST_kFailure;
 -      }
 -      
 -      switch ([event type])
 -    {
 -              case NSLeftMouseDown:
 -              case NSRightMouseDown:
 -              case NSOtherMouseDown:
 +              return GHOST_kFailure;\r
 +      }\r
 +      \r
 +      switch ([event type])\r
 +    {\r
 +              case NSLeftMouseDown:\r
 +              case NSRightMouseDown:\r
 +              case NSOtherMouseDown:\r
                        pushEvent(new GHOST_EventButton([event timestamp]*1000, GHOST_kEventButtonDown, window, convertButton([event buttonNumber])));
 -                      //Handle tablet events combined with mouse events
 -                      switch ([event subtype]) {
 -                              case NX_SUBTYPE_TABLET_POINT:
 -                                      handleTabletEvent(eventPtr, NSTabletPoint);
 -                                      break;
 -                              case NX_SUBTYPE_TABLET_PROXIMITY:
 -                                      handleTabletEvent(eventPtr, NSTabletProximity);
 -                                      break;
 -                              default:
 -                                      //No tablet event included : do nothing
 -                                      break;
 -                      }
 -                      break;
 -                                              
 -              case NSLeftMouseUp:
 -              case NSRightMouseUp:
 -              case NSOtherMouseUp:
 +                      //Handle tablet events combined with mouse events\r
 +                      switch ([event subtype]) {\r
 +                              case NX_SUBTYPE_TABLET_POINT:\r
 +                                      handleTabletEvent(eventPtr, NSTabletPoint);\r
 +                                      break;\r
 +                              case NX_SUBTYPE_TABLET_PROXIMITY:\r
 +                                      handleTabletEvent(eventPtr, NSTabletProximity);\r
 +                                      break;\r
 +                              default:\r
 +                                      //No tablet event included : do nothing\r
 +                                      break;\r
 +                      }\r
 +                      break;\r
 +                                              \r
 +              case NSLeftMouseUp:\r
 +              case NSRightMouseUp:\r
 +              case NSOtherMouseUp:\r
                        pushEvent(new GHOST_EventButton([event timestamp]*1000, GHOST_kEventButtonUp, window, convertButton([event buttonNumber])));
 -                      //Handle tablet events combined with mouse events
 -                      switch ([event subtype]) {
 -                              case NX_SUBTYPE_TABLET_POINT:
 -                                      handleTabletEvent(eventPtr, NSTabletPoint);
 -                                      break;
 -                              case NX_SUBTYPE_TABLET_PROXIMITY:
 -                                      handleTabletEvent(eventPtr, NSTabletProximity);
 -                                      break;
 -                              default:
 -                                      //No tablet event included : do nothing
 -                                      break;
 -                      }
 -                      break;
 +                      //Handle tablet events combined with mouse events\r
 +                      switch ([event subtype]) {\r
 +                              case NX_SUBTYPE_TABLET_POINT:\r
 +                                      handleTabletEvent(eventPtr, NSTabletPoint);\r
 +                                      break;\r
 +                              case NX_SUBTYPE_TABLET_PROXIMITY:\r
 +                                      handleTabletEvent(eventPtr, NSTabletProximity);\r
 +                                      break;\r
 +                              default:\r
 +                                      //No tablet event included : do nothing\r
 +                                      break;\r
 +                      }\r
 +                      break;\r
 +                      \r
 +              case NSLeftMouseDragged:\r
 +              case NSRightMouseDragged:\r
 +              case NSOtherMouseDragged:                               \r
 +                      //Handle tablet events combined with mouse events\r
 +                      switch ([event subtype]) {\r
 +                              case NX_SUBTYPE_TABLET_POINT:\r
 +                                      handleTabletEvent(eventPtr, NSTabletPoint);\r
 +                                      break;\r
 +                              case NX_SUBTYPE_TABLET_PROXIMITY:\r
 +                                      handleTabletEvent(eventPtr, NSTabletProximity);\r
 +                                      break;\r
 +                              default:\r
 +                                      //No tablet event included : do nothing\r
 +                                      break;\r
 +                      }\r
                        
 -              case NSLeftMouseDragged:
 -              case NSRightMouseDragged:
 -              case NSOtherMouseDragged:                               
 -                      //Handle tablet events combined with mouse events
 -                      switch ([event subtype]) {
 -                              case NX_SUBTYPE_TABLET_POINT:
 -                                      handleTabletEvent(eventPtr, NSTabletPoint);
 -                                      break;
 -                              case NX_SUBTYPE_TABLET_PROXIMITY:
 -                                      handleTabletEvent(eventPtr, NSTabletProximity);
 -                                      break;
 -                              default:
 -                                      //No tablet event included : do nothing
 -                                      break;
 -                      }
 -                      
 -              case NSMouseMoved:
 +              case NSMouseMoved:\r
                                switch (window->getCursorGrabMode()) {
                                        case GHOST_kGrabHide: //Cursor hidden grab operation : no cursor move
                                        {
                                                m_cursorDelta_y=0; //Mouse motion occured between two cursor warps, so we can reset the delta counter
                                        }
                                                break;
 -                              }
 -                              break;
 -                      
 -              case NSScrollWheel:
 -                      {
 +                              }\r
 +                              break;\r
 +                      \r
 +              case NSScrollWheel:\r
 +                      {\r
-                               /* Send Wheel event if sent from the mouse, trackpad event otherwise */
-                               if ([event subtype] == NSMouseEventSubtype) {
+                               /* Send trackpad event if inside a trackpad gesture, send wheel event otherwise */
+                               if (!m_hasMultiTouchTrackpad || !m_isGestureInProgress) {
                                        GHOST_TInt32 delta;
                                        
                                        double deltaF = [event deltaY];
                                pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventRotate, mousePos.x, mousePos.y,
                                                                                                  -[event rotation] * 5.0, 0));
                        }
 -              default:
 -                      return GHOST_kFailure;
 -                      break;
 -              }
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
 -{
 -      NSEvent *event = (NSEvent *)eventPtr;
+               case NSEventTypeBeginGesture:
+                       m_isGestureInProgress = true;
+                       break;
+               case NSEventTypeEndGesture:
+                       m_isGestureInProgress = false;
+                       break;
-       GHOST_IWindow* window = m_windowManager->getActiveWindow();\r
 +              default:\r
 +                      return GHOST_kFailure;\r
 +                      break;\r
 +              }\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)\r
 +{\r
 +      NSEvent *event = (NSEvent *)eventPtr;\r
 -      unsigned int modifiers;
 -      NSString *characters;
+       GHOST_IWindow* window;
 +      unsigned int modifiers;\r
 +      NSString *characters;\r
        NSData *convertedCharacters;
 -      GHOST_TKey keyCode;
 -      unsigned char ascii;
 +      GHOST_TKey keyCode;\r
 +      unsigned char ascii;\r
        NSString* charsIgnoringModifiers;
 -
 +\r
-       /* Can happen, very rarely - seems to only be when command-H makes\r
-        * the window go away and we still get an HKey up. \r
-        */\r
+       window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
 -      if (!window) {
 +      if (!window) {\r
-               printf("\nW failure");\r
+               //printf("\nW failure for event 0x%x",[event type]);
 -              return GHOST_kFailure;
 -      }
 -      
 -      switch ([event type]) {
 -              case NSKeyDown:
 -              case NSKeyUp:
 +              return GHOST_kFailure;\r
 +      }\r
 +      \r
 +      switch ([event type]) {\r
 +              case NSKeyDown:\r
 +              case NSKeyUp:\r
                        charsIgnoringModifiers = [event charactersIgnoringModifiers];
                        if ([charsIgnoringModifiers length]>0)
 -                              keyCode = convertKey([event keyCode],
 +                              keyCode = convertKey([event keyCode],\r
                                                                         [charsIgnoringModifiers characterAtIndex:0]);
                        else
 -                              keyCode = convertKey([event keyCode],0);
 +                              keyCode = convertKey([event keyCode],0);\r
  
                                
                        characters = [event characters];
                                        ascii =((char*)[convertedCharacters bytes])[0];
                                else
                                        ascii = 0; //Character not available in iso latin 1 encoding
 -                      }
 +                      }\r
                        else
                                ascii= 0;
 -                      
 -                      if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))
 -                              break; //Cmd-Q is directly handled by Cocoa
 -
 -                      if ([event type] == NSKeyDown) {
 +                      \r
 +                      if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))\r
 +                              break; //Cmd-Q is directly handled by Cocoa\r
 +\r
 +                      if ([event type] == NSKeyDown) {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, GHOST_kEventKeyDown, window, keyCode, ascii) );
 -                              //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);
 -                      } else {
 +                              //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);\r
 +                      } else {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, GHOST_kEventKeyUp, window, keyCode, ascii) );
 -                      }
 -                      break;
 -      
 -              case NSFlagsChanged: 
 -                      modifiers = [event modifierFlags];
 +                      }\r
 +                      break;\r
 +      \r
 +              case NSFlagsChanged: \r
 +                      modifiers = [event modifierFlags];\r
+                       
 -                      if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {
 +                      if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );
 -                      }
 -                      if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {
 +                      }\r
 +                      if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );
 -                      }
 -                      if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {
 +                      }\r
 +                      if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );
 -                      }
 -                      if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {
 +                      }\r
 +                      if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {\r
                                pushEvent( new GHOST_EventKey([event timestamp]*1000, (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );
 -                      }
 -                      
 -                      m_modifierMask = modifiers;
 -                      break;
 -                      
 -              default:
 -                      return GHOST_kFailure;
 -                      break;
 -      }
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 -
 -#pragma mark Clipboard get/set
 -
 -GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
 -{
 -      GHOST_TUns8 * temp_buff;
 -      size_t pastedTextSize;  
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
 -      
 -      if (pasteBoard == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 -      NSArray *supportedTypes =
 +                      }\r
 +                      \r
 +                      m_modifierMask = modifiers;\r
 +                      break;\r
 +                      \r
 +              default:\r
 +                      return GHOST_kFailure;\r
 +                      break;\r
 +      }\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +\r
 +#pragma mark Clipboard get/set\r
 +\r
 +GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const\r
 +{\r
 +      GHOST_TUns8 * temp_buff;\r
 +      size_t pastedTextSize;  \r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
 +      \r
 +      if (pasteBoard == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
 +      NSArray *supportedTypes =\r
                [NSArray arrayWithObjects: NSStringPboardType, nil];
 -      
 -      NSString *bestType = [[NSPasteboard generalPasteboard]
 -                                                availableTypeFromArray:supportedTypes];
 -      
 -      if (bestType == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 +      \r
 +      NSString *bestType = [[NSPasteboard generalPasteboard]\r
 +                                                availableTypeFromArray:supportedTypes];\r
 +      \r
 +      if (bestType == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
        NSString * textPasted = [pasteBoard stringForType:NSStringPboardType];
 -
 -      if (textPasted == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 +\r
 +      if (textPasted == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
        pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding];
 -      
 -      temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
 -
 -      if (temp_buff == NULL) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 +      \r
 +      temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); \r
 +\r
 +      if (temp_buff == NULL) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
        strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSISOLatin1StringEncoding], pastedTextSize);
 -      
 -      temp_buff[pastedTextSize] = '\0';
 -      
 -      [pool drain];
 -
 -      if(temp_buff) {
 -              return temp_buff;
 -      } else {
 -              return NULL;
 -      }
 -}
 -
 -void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
 -{
 -      NSString *textToCopy;
 -      
 -      if(selection) {return;} // for copying the selection, used on X11
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -              
 -      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
 -      
 -      if (pasteBoard == nil) {
 -              [pool drain];
 -              return;
 -      }
 -      
 +      \r
 +      temp_buff[pastedTextSize] = '\0';\r
 +      \r
 +      [pool drain];\r
 +\r
 +      if(temp_buff) {\r
 +              return temp_buff;\r
 +      } else {\r
 +              return NULL;\r
 +      }\r
 +}\r
 +\r
 +void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const\r
 +{\r
 +      NSString *textToCopy;\r
 +      \r
 +      if(selection) {return;} // for copying the selection, used on X11\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +              \r
 +      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
 +      \r
 +      if (pasteBoard == nil) {\r
 +              [pool drain];\r
 +              return;\r
 +      }\r
 +      \r
        NSArray *supportedTypes = [NSArray arrayWithObject:NSStringPboardType];
 -      
 -      [pasteBoard declareTypes:supportedTypes owner:nil];
 -      
 +      \r
 +      [pasteBoard declareTypes:supportedTypes owner:nil];\r
 +      \r
        textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding];
 -      
 +      \r
        [pasteBoard setString:textToCopy forType:NSStringPboardType];
 -      
 -      [pool drain];
 -}
 +      \r
 +      [pool drain];\r
 +}\r
+ #pragma mark Base directories retrieval
+ const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
+ {
+       static GHOST_TUns8 tempPath[512] = "";
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       NSFileManager *fileManager;
+       NSString *basePath;
+       NSArray *paths;
+       
+       paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
+       
+       if ([paths count] > 0)
+               basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
+       else { //Fall back to standard unix path in case of issue
+               basePath = @"/usr/share/blender";
+       }
+       
+       /* Ensure path exists, creates it if needed */
+       fileManager = [NSFileManager defaultManager];
+       if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
+               [fileManager createDirectoryAtPath:basePath attributes:nil];
+       }
+       
+       strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+       
+       [pool drain];
+       return tempPath;
+ }
+ const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
+ {
+       static GHOST_TUns8 tempPath[512] = "";
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       NSFileManager *fileManager;
+       NSString *basePath;
+       NSArray *paths;
+       paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+       if ([paths count] > 0)
+               basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
+       else { //Fall back to HOME in case of issue
+               basePath = [NSHomeDirectory() stringByAppendingPathComponent:@".blender"];
+       }
+       
+       /* Ensure path exists, creates it if needed */
+       fileManager = [NSFileManager defaultManager];
+       if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
+               [fileManager createDirectoryAtPath:basePath attributes:nil];
+       }
+       
+       strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+       
+       [pool drain];
+       return tempPath;
+ }
index 873a59251026b6f853c24bcbf6cce2274bf4c8a9,0b10a02849f2e2afad3b4f7838f7a66428ad1c32..6206388fdaab1496fa865648668d8bb7cc5d047a
@@@ -1,39 -1,39 +1,39 @@@
 -/**
 - * $Id$
 - * ***** BEGIN GPL LICENSE BLOCK *****
 - *
 - * This program is free software; you can redistribute it and/or
 - * modify it under the terms of the GNU General Public License
 - * as published by the Free Software Foundation; either version 2
 - * of the License, or (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software Foundation,
 +/**\r
 + * $Id: GHOST_WindowCocoa.mm 23873 2009-10-15 20:09:50Z damien78 $\r
 + * ***** BEGIN GPL LICENSE BLOCK *****\r
 + *\r
 + * This program is free software; you can redistribute it and/or\r
 + * modify it under the terms of the GNU General Public License\r
 + * as published by the Free Software Foundation; either version 2\r
 + * of the License, or (at your option) any later version.\r
 + *\r
 + * This program is distributed in the hope that it will be useful,\r
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
 + * GNU General Public License for more details.\r
 + *\r
 + * You should have received a copy of the GNU General Public License\r
 + * along with this program; if not, write to the Free Software Foundation,\r
-  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 - *
 - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 - * All rights reserved.
 - *
 - * The Original Code is: all of this file.
 - *
 - * Contributor(s):    Maarten Gribnau 05/2001
 -                                      Damien Plisson 10/2009
 - *
 - * ***** END GPL LICENSE BLOCK *****
 - */
 -
 -#include <Cocoa/Cocoa.h>
 -
 -#ifndef MAC_OS_X_VERSION_10_6
 -//Use of the SetSystemUIMode function (64bit compatible)
 -#include <Carbon/Carbon.h>
 -#endif
 -
 + *\r
 + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.\r
 + * All rights reserved.\r
 + *\r
 + * The Original Code is: all of this file.\r
 + *\r
 + * Contributor(s):    Maarten Gribnau 05/2001\r
 +                                      Damien Plisson 10/2009\r
 + *\r
 + * ***** END GPL LICENSE BLOCK *****\r
 + */\r
 +\r
 +#include <Cocoa/Cocoa.h>\r
 +\r
 +#ifndef MAC_OS_X_VERSION_10_6\r
 +//Use of the SetSystemUIMode function (64bit compatible)\r
 +#include <Carbon/Carbon.h>\r
 +#endif\r
 +\r
  #include <OpenGL/gl.h>
  /***** Multithreaded opengl code : uncomment for enabling
  #include <OpenGL/OpenGL.h>
@@@ -61,48 -61,60 +61,60 @@@ extern "C" 
  #ifdef MAC_OS_X_VERSION_10_6
  <NSWindowDelegate>
  #endif
 -{
 -      GHOST_SystemCocoa *systemCocoa;
 -      GHOST_WindowCocoa *associatedWindow;
 -}
 -
 +{\r
 +      GHOST_SystemCocoa *systemCocoa;\r
 +      GHOST_WindowCocoa *associatedWindow;\r
 +}\r
 +\r
  - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
 -- (void)windowWillClose:(NSNotification *)notification;
 -- (void)windowDidBecomeKey:(NSNotification *)notification;
 -- (void)windowDidResignKey:(NSNotification *)notification;
 +- (void)windowWillClose:(NSNotification *)notification;\r
 +- (void)windowDidBecomeKey:(NSNotification *)notification;\r
 +- (void)windowDidResignKey:(NSNotification *)notification;\r
  - (void)windowDidExpose:(NSNotification *)notification;
 -- (void)windowDidResize:(NSNotification *)notification;
 +- (void)windowDidResize:(NSNotification *)notification;\r
+ - (void)windowDidMove:(NSNotification *)notification;
+ - (void)windowWillMove:(NSNotification *)notification;
 -@end
 -
 -@implementation CocoaWindowDelegate : NSObject
 -- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
 -{
 -      systemCocoa = sysCocoa;
 -      associatedWindow = winCocoa;
 -}
 -
 -- (void)windowWillClose:(NSNotification *)notification
 -{
 -      systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);
 -}
 -
 -- (void)windowDidBecomeKey:(NSNotification *)notification
 -{
 -      systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);
 -}
 -
 -- (void)windowDidResignKey:(NSNotification *)notification
 -{
 -      systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);
 -}
 -
 +@end\r
 +\r
 +@implementation CocoaWindowDelegate : NSObject\r
 +- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa\r
 +{\r
 +      systemCocoa = sysCocoa;\r
 +      associatedWindow = winCocoa;\r
 +}\r
 +\r
 +- (void)windowWillClose:(NSNotification *)notification\r
 +{\r
 +      systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);\r
 +}\r
 +\r
 +- (void)windowDidBecomeKey:(NSNotification *)notification\r
 +{\r
 +      systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);\r
 +}\r
 +\r
 +- (void)windowDidResignKey:(NSNotification *)notification\r
 +{\r
 +              systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);\r
 +}\r
 +\r
  - (void)windowDidExpose:(NSNotification *)notification
 -{
 -      systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
 -}
 -
 +{\r
 +      systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);\r
 +}\r
 +\r
+ - (void)windowDidMove:(NSNotification *)notification
+ {
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
+ }
+ - (void)windowWillMove:(NSNotification *)notification
+ {
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
+ }
 -- (void)windowDidResize:(NSNotification *)notification
 -{
 +- (void)windowDidResize:(NSNotification *)notification\r
 +{\r
  #ifdef MAC_OS_X_VERSION_10_6
        //if (![[notification object] inLiveResize]) {
                //Send event only once, at end of resize operation (when user has released mouse button)
@@@ -407,259 -434,263 +434,263 @@@ GHOST_WindowCocoa::GHOST_WindowCocoa
        [m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
                                                                                  NSStringPboardType, NSTIFFPboardType, nil]];
                                                                                  
 -      if (state == GHOST_kWindowStateFullScreen)
 -              setState(GHOST_kWindowStateFullScreen);
 -              
 -      [pool drain];
 -}
 -
 -
 -GHOST_WindowCocoa::~GHOST_WindowCocoa()
 -{
 -      if (m_customCursor) delete m_customCursor;
 -
 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      [m_openGLView release];
 -      
 -      if (m_window) {
 -              [m_window close];
 -              [[m_window delegate] release];
 -              [m_window release];
 -              m_window = nil;
 -      }
 -      
 -      //Check for other blender opened windows and make the frontmost key
 -      NSArray *windowsList = [NSApp orderedWindows];
 -      if ([windowsList count]) {
 -              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
 -      }
 -      [pool drain];
 -}
 -
 -#pragma mark accessors
 -
 -bool GHOST_WindowCocoa::getValid() const
 -{
 +      if (state == GHOST_kWindowStateFullScreen)\r
 +              setState(GHOST_kWindowStateFullScreen);\r
 +              \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_WindowCocoa::~GHOST_WindowCocoa()\r
 +{\r
 +      if (m_customCursor) delete m_customCursor;\r
 +\r
 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      [m_openGLView release];\r
 +      \r
 +      if (m_window) {\r
 +              [m_window close];\r
 +              [[m_window delegate] release];\r
 +              [m_window release];\r
 +              m_window = nil;\r
 +      }\r
 +      \r
 +      //Check for other blender opened windows and make the frontmost key\r
 +      NSArray *windowsList = [NSApp orderedWindows];\r
 +      if ([windowsList count]) {\r
 +              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +#pragma mark accessors\r
 +\r
 +bool GHOST_WindowCocoa::getValid() const\r
 +{\r
        return (m_window != 0);
 -}
 -
 +}\r
 +\r
+ void* GHOST_WindowCocoa::getOSWindow() const
+ {
+       return (void*)m_window;
+ }
 -
 -void GHOST_WindowCocoa::setTitle(const STR_String& title)
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];
 -      
 -      //Set associated file if applicable
 -      if ([windowTitle hasPrefix:@"Blender"])
 -      {
 -              NSRange fileStrRange;
 -              NSString *associatedFileName;
 -              int len;
 -              
 -              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;
 -              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
 -      
 -              if (len >0)
 -              {
 -                      fileStrRange.length = len;
 -                      associatedFileName = [windowTitle substringWithRange:fileStrRange];
 -                      @try {
 -                              [m_window setRepresentedFilename:associatedFileName];
 -                      }
 -                      @catch (NSException * e) {
 -                              printf("\nInvalid file path given in window title");
 -                      }
 -                      [m_window setTitle:[associatedFileName lastPathComponent]];
 -              }
 -              else {
 -                      [m_window setTitle:windowTitle];
 -                      [m_window setRepresentedFilename:@""];
 -              }
 -
 -      } else {
 -              [m_window setTitle:windowTitle];
 -              [m_window setRepresentedFilename:@""];
 -      }
 -
 -      
 -      [windowTitle release];
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getTitle(STR_String& title) const
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [m_window title];
 -
 -      if (windowTitle != nil) {
 -              title = [windowTitle UTF8String];               
 -      }
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -      rect = [m_window frame];
 -
 -      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);
 -      bounds.m_l = rect.origin.x -screenSize.origin.x;
 -      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;
 -      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      if (!m_fullScreen)
 -      {
 -              NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -              //Max window contents as screen size (excluding title bar...)
 -              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
 -                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -
 -              rect = [m_window contentRectForFrameRect:[m_window frame]];
 -              
 -              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);
 -              bounds.m_l = rect.origin.x -contentRect.origin.x;
 -              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;
 -              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);
 -      }
 -      else {
 -              NSRect screenSize = [[m_window screen] frame];
 -              
 -              bounds.m_b = screenSize.origin.y + screenSize.size.height;
 -              bounds.m_l = screenSize.origin.x;
 -              bounds.m_r = screenSize.origin.x + screenSize.size.width;
 -              bounds.m_t = screenSize.origin.y;
 -      }
 -      [pool drain];
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getWidth()) != width) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=cBnds.getHeight();
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getHeight()) != height) {
 -              NSSize size;
 -              size.width=cBnds.getWidth();
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
 -          (((GHOST_TUns32)cBnds.getHeight()) != height)) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TWindowState GHOST_WindowCocoa::getState() const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      GHOST_TWindowState state;
 -      if (m_fullScreen) {
 -              state = GHOST_kWindowStateFullScreen;
 -      } 
 -      else if ([m_window isMiniaturized]) {
 -              state = GHOST_kWindowStateMinimized;
 -      }
 -      else if ([m_window isZoomed]) {
 -              state = GHOST_kWindowStateMaximized;
 -      }
 -      else {
 -              state = GHOST_kWindowStateNormal;
 -      }
 -      [pool drain];
 -      return state;
 -}
 -
 -
 -void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      screenCoord.x = inX;
 -      screenCoord.y = inY;
 -      
 -      baseCoord = [m_window convertScreenToBase:screenCoord];
 -      
 -      outX = baseCoord.x;
 -      outY = baseCoord.y;
 -}
 -
 -
 -void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      baseCoord.x = inX;
 -      baseCoord.y = inY;
 -      
 -      screenCoord = [m_window convertBaseToScreen:baseCoord];
 -      
 -      outX = screenCoord.x;
 -      outY = screenCoord.y;
 -}
 -
 +\r
 +void GHOST_WindowCocoa::setTitle(const STR_String& title)\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];\r
 +      \r
 +      //Set associated file if applicable\r
 +      if ([windowTitle hasPrefix:@"Blender"])\r
 +      {\r
 +              NSRange fileStrRange;\r
 +              NSString *associatedFileName;\r
 +              int len;\r
 +              \r
 +              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;\r
 +              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;\r
 +      \r
 +              if (len >0)\r
 +              {\r
 +                      fileStrRange.length = len;\r
 +                      associatedFileName = [windowTitle substringWithRange:fileStrRange];\r
 +                      @try {\r
 +                              [m_window setRepresentedFilename:associatedFileName];\r
 +                      }\r
 +                      @catch (NSException * e) {\r
 +                              printf("\nInvalid file path given in window title");\r
 +                      }\r
 +                      [m_window setTitle:[associatedFileName lastPathComponent]];\r
 +              }\r
 +              else {\r
 +                      [m_window setTitle:windowTitle];\r
 +                      [m_window setRepresentedFilename:@""];\r
 +              }\r
 +\r
 +      } else {\r
 +              [m_window setTitle:windowTitle];\r
 +              [m_window setRepresentedFilename:@""];\r
 +      }\r
 +\r
 +      \r
 +      [windowTitle release];\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getTitle(STR_String& title) const\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [m_window title];\r
 +\r
 +      if (windowTitle != nil) {\r
 +              title = [windowTitle UTF8String];               \r
 +      }\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +      rect = [m_window frame];\r
 +\r
 +      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);\r
 +      bounds.m_l = rect.origin.x -screenSize.origin.x;\r
 +      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;\r
 +      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      if (!m_fullScreen)\r
 +      {\r
 +              NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +              //Max window contents as screen size (excluding title bar...)\r
 +              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize\r
 +                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +\r
 +              rect = [m_window contentRectForFrameRect:[m_window frame]];\r
 +              \r
 +              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);\r
 +              bounds.m_l = rect.origin.x -contentRect.origin.x;\r
 +              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;\r
 +              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);\r
 +      }\r
 +      else {\r
 +              NSRect screenSize = [[m_window screen] frame];\r
 +              \r
 +              bounds.m_b = screenSize.origin.y + screenSize.size.height;\r
 +              bounds.m_l = screenSize.origin.x;\r
 +              bounds.m_r = screenSize.origin.x + screenSize.size.width;\r
 +              bounds.m_t = screenSize.origin.y;\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getWidth()) != width) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=cBnds.getHeight();\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getHeight()) != height) {\r
 +              NSSize size;\r
 +              size.width=cBnds.getWidth();\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||\r
 +          (((GHOST_TUns32)cBnds.getHeight()) != height)) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TWindowState GHOST_WindowCocoa::getState() const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      GHOST_TWindowState state;\r
 +      if (m_fullScreen) {\r
 +              state = GHOST_kWindowStateFullScreen;\r
 +      } \r
 +      else if ([m_window isMiniaturized]) {\r
 +              state = GHOST_kWindowStateMinimized;\r
 +      }\r
 +      else if ([m_window isZoomed]) {\r
 +              state = GHOST_kWindowStateMaximized;\r
 +      }\r
 +      else {\r
 +              state = GHOST_kWindowStateNormal;\r
 +      }\r
 +      [pool drain];\r
 +      return state;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      screenCoord.x = inX;\r
 +      screenCoord.y = inY;\r
 +      \r
 +      baseCoord = [m_window convertScreenToBase:screenCoord];\r
 +      \r
 +      outX = baseCoord.x;\r
 +      outY = baseCoord.y;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      baseCoord.x = inX;\r
 +      baseCoord.y = inY;\r
 +      \r
 +      screenCoord = [m_window convertBaseToScreen:baseCoord];\r
 +      \r
 +      outX = screenCoord.x;\r
 +      outY = screenCoord.y;\r
 +}\r
 +\r
  
  NSScreen* GHOST_WindowCocoa::getScreen()
  {
  }
  
  
 -/**
 - * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.
 - * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.
 - * Thus, process switch, exposé, spaces, ... still work in fullscreen mode
 - */
 -GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")
 -    switch (state) {
 -              case GHOST_kWindowStateMinimized:
 -            [m_window miniaturize:nil];
 -            break;
 -              case GHOST_kWindowStateMaximized:
 -                      [m_window zoom:nil];
 -                      break;
 -              
 -              case GHOST_kWindowStateFullScreen:
 -                      if (!m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      
 -                              //This status change needs to be done before Cocoa call to enter fullscreen mode
 -                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference
 -                              m_fullScreen = true;
 -
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];
 -                              }
 -                              //Make window borderless and enlarge it
 -                              [m_window setStyleMask:NSBorderlessWindowMask];
 -                              [m_window setFrame:[[m_window screen] frame] display:YES];
 +/**\r
 + * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.\r
 + * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.\r
 + * Thus, process switch, exposé, spaces, ... still work in fullscreen mode\r
 + */\r
 +GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")\r
 +    switch (state) {\r
 +              case GHOST_kWindowStateMinimized:\r
 +            [m_window miniaturize:nil];\r
 +            break;\r
 +              case GHOST_kWindowStateMaximized:\r
 +                      [m_window zoom:nil];\r
 +                      break;\r
 +              \r
 +              case GHOST_kWindowStateFullScreen:\r
 +                      if (!m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      \r
 +                              //This status change needs to be done before Cocoa call to enter fullscreen mode\r
 +                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference\r
 +                              m_fullScreen = true;\r
 +\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];\r
 +                              }\r
 +                              //Make window borderless and enlarge it\r
 +                              [m_window setStyleMask:NSBorderlessWindowMask];\r
 +                              [m_window setFrame:[[m_window screen] frame] display:YES];\r
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];
 -                                      //One of the very few 64bit compatible Carbon function
 -                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                styleMask:NSBorderlessWindowMask
 -                                                                                backing:NSBackingStoreBuffered
 -                                                                                defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                              }
 -                      break;
 -              case GHOST_kWindowStateNormal:
 -        default:
 -                      if (m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                              m_fullScreen = false;
 -
 -                              //Exit fullscreen
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //Show again menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];
 -                              }
 -                              //Make window normal and resize it
 -                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];\r
 +                                      //One of the very few 64bit compatible Carbon function\r
 +                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                styleMask:NSBorderlessWindowMask\r
 +                                                                                backing:NSBackingStoreBuffered\r
 +                                                                                defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                              }\r
 +                      break;\r
 +              case GHOST_kWindowStateNormal:\r
 +        default:\r
 +                      if (m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                              m_fullScreen = false;\r
 +\r
 +                              //Exit fullscreen\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //Show again menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];\r
 +                              }\r
 +                              //Make window normal and resize it\r
 +                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];\r
                                //TODO for 10.6 only : window title is forgotten after the style change
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Show menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];
 -                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
 -                                                                                                        backing:NSBackingStoreBuffered
 -                                                                                                              defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                      }
 -            else if ([m_window isMiniaturized])
 -                              [m_window deminiaturize:nil];
 -                      else if ([m_window isZoomed])
 -                              [m_window zoom:nil];
 -            break;
 -    }
 -    return GHOST_kSuccess;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
 -{
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Show menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];\r
 +                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)\r
 +                                                                                                        backing:NSBackingStoreBuffered\r
 +                                                                                                              defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                      }\r
 +            else if ([m_window isMiniaturized])\r
 +                              [m_window deminiaturize:nil];\r
 +                      else if ([m_window isZoomed])\r
 +                              [m_window zoom:nil];\r
 +            break;\r
 +    }\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)\r
 +{\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      [m_window setDocumentEdited:isUnsavedChanges];\r
 +      \r
 +      [pool drain];\r
 +      return GHOST_Window::setModifiedState(isUnsavedChanges);\r
 +}\r
 +\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)\r
 +{\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       
 -      [m_window setDocumentEdited:isUnsavedChanges];
 -      
 -      [pool drain];
 -      return GHOST_Window::setModifiedState(isUnsavedChanges);
 -}
 -
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
 -{
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")
 -    if (order == GHOST_kWindowOrderTop) {
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")\r
 +    if (order == GHOST_kWindowOrderTop) {\r
                [m_window makeKeyAndOrderFront:nil];
 -    }
 -    else {
 +    }\r
 +    else {\r
                NSArray *windowsList;
                
 -              [m_window orderBack:nil];
 +              [m_window orderBack:nil];\r
                
                //Check for other blender opened windows and make the frontmost key
                windowsList = [NSApp orderedWindows];
                if ([windowsList count]) {
                        [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
                }
 -    }
 +    }\r
+       
+       [pool drain];
 -    return GHOST_kSuccess;
 -}
 -
 -#pragma mark Drawing context
 -
 -/*#define  WAIT_FOR_VSYNC 1*/
 -
 -GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
 -{
 -    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -        if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext flushBuffer];
 -                      [pool drain];
 -            return GHOST_kSuccess;
 -        }
 -    }
 -    return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext update];
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              }
 -      }
 -      return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext makeCurrentContext];
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +#pragma mark Drawing context\r
 +\r
 +/*#define  WAIT_FOR_VSYNC 1*/\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()\r
 +{\r
 +    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +        if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext flushBuffer];\r
 +                      [pool drain];\r
 +            return GHOST_kSuccess;\r
 +        }\r
 +    }\r
 +    return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext update];\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              }\r
 +      }\r
 +      return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext makeCurrentContext];\r
                        
                        // Disable AA by default
                        if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
@@@ -932,162 -967,169 +967,169 @@@ GHOST_TSuccess GHOST_WindowCocoa::insta
                        [tmpOpenGLContext setView:m_openGLView];
                        
                        m_openGLContext = tmpOpenGLContext;
 -                      break;
 -      
 -              case GHOST_kDrawingContextTypeNone:
 -                      success = GHOST_kSuccess;
 -                      break;
 -              
 -              default:
 -                      break;
 -      }
 -      [pool drain];
 -      return success;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
 -{
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      switch (m_drawingContextType) {
 -              case GHOST_kDrawingContextTypeOpenGL:
 -                      if (m_openGLContext)
 -                      {
 -                              [m_openGLView clearGLContext];
 -                              if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
 -                              m_openGLContext = nil;
 -                      }
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              case GHOST_kDrawingContextTypeNone:
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -                      break;
 -              default:
 -                      [pool drain];
 -                      return GHOST_kFailure;
 -      }
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::invalidate()
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      [m_openGLView setNeedsDisplay:YES];
 -      [pool drain];
 -      return GHOST_kSuccess;
 -}
 -
 -#pragma mark Cursor handling
 -
 -void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
 -{
 -      static bool systemCursorVisible = true;
 -      
 -      NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
 -
 -      NSCursor *tmpCursor =nil;
 -      
 -      if (visible != systemCursorVisible) {
 -              if (visible) {
 -                      [NSCursor unhide];
 -                      systemCursorVisible = true;
 -              }
 -              else {
 -                      [NSCursor hide];
 -                      systemCursorVisible = false;
 -              }
 -      }
 -
 -      if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {
 -              tmpCursor = m_customCursor;
 -      } else {
 -              switch (cursor) {
 -                      case GHOST_kStandardCursorDestroy:
 -                              tmpCursor = [NSCursor disappearingItemCursor];
 -                              break;
 -                      case GHOST_kStandardCursorText:
 -                              tmpCursor = [NSCursor IBeamCursor];
 -                              break;
 -                      case GHOST_kStandardCursorCrosshair:
 -                              tmpCursor = [NSCursor crosshairCursor];
 -                              break;
 -                      case GHOST_kStandardCursorUpDown:
 -                              tmpCursor = [NSCursor resizeUpDownCursor];
 -                              break;
 -                      case GHOST_kStandardCursorLeftRight:
 -                              tmpCursor = [NSCursor resizeLeftRightCursor];
 -                              break;
 -                      case GHOST_kStandardCursorTopSide:
 -                              tmpCursor = [NSCursor resizeUpCursor];
 -                              break;
 -                      case GHOST_kStandardCursorBottomSide:
 -                              tmpCursor = [NSCursor resizeDownCursor];
 -                              break;
 -                      case GHOST_kStandardCursorLeftSide:
 -                              tmpCursor = [NSCursor resizeLeftCursor];
 -                              break;
 -                      case GHOST_kStandardCursorRightSide:
 -                              tmpCursor = [NSCursor resizeRightCursor];
 -                              break;
 -                      case GHOST_kStandardCursorRightArrow:
 -                      case GHOST_kStandardCursorInfo:
 -                      case GHOST_kStandardCursorLeftArrow:
 -                      case GHOST_kStandardCursorHelp:
 -                      case GHOST_kStandardCursorCycle:
 -                      case GHOST_kStandardCursorSpray:
 -                      case GHOST_kStandardCursorWait:
 -                      case GHOST_kStandardCursorTopLeftCorner:
 -                      case GHOST_kStandardCursorTopRightCorner:
 -                      case GHOST_kStandardCursorBottomRightCorner:
 -                      case GHOST_kStandardCursorBottomLeftCorner:
 +                      break;\r
 +      
 +              case GHOST_kDrawingContextTypeNone:\r
 +                      success = GHOST_kSuccess;\r
 +                      break;\r
 +              \r
 +              default:\r
 +                      break;\r
 +      }\r
 +      [pool drain];\r
 +      return success;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()\r
 +{\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      switch (m_drawingContextType) {\r
 +              case GHOST_kDrawingContextTypeOpenGL:\r
 +                      if (m_openGLContext)\r
 +                      {\r
 +                              [m_openGLView clearGLContext];\r
 +                              if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;\r
 +                              m_openGLContext = nil;\r
 +                      }\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              case GHOST_kDrawingContextTypeNone:\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +                      break;\r
 +              default:\r
 +                      [pool drain];\r
 +                      return GHOST_kFailure;\r
 +      }\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::invalidate()\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      [m_openGLView setNeedsDisplay:YES];\r
 +      [pool drain];\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +#pragma mark Cursor handling\r
 +\r
 +void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const\r
 +{\r
 +      static bool systemCursorVisible = true;\r
 +      \r
 +      NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSCursor *tmpCursor =nil;\r
 +      \r
 +      if (visible != systemCursorVisible) {\r
 +              if (visible) {\r
 +                      [NSCursor unhide];\r
 +                      systemCursorVisible = true;\r
 +              }\r
 +              else {\r
 +                      [NSCursor hide];\r
 +                      systemCursorVisible = false;\r
 +              }\r
 +      }\r
 +\r
 +      if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {\r
 +              tmpCursor = m_customCursor;\r
 +      } else {\r
 +              switch (cursor) {\r
 +                      case GHOST_kStandardCursorDestroy:\r
 +                              tmpCursor = [NSCursor disappearingItemCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorText:\r
 +                              tmpCursor = [NSCursor IBeamCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorCrosshair:\r
 +                              tmpCursor = [NSCursor crosshairCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorUpDown:\r
 +                              tmpCursor = [NSCursor resizeUpDownCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorLeftRight:\r
 +                              tmpCursor = [NSCursor resizeLeftRightCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorTopSide:\r
 +                              tmpCursor = [NSCursor resizeUpCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorBottomSide:\r
 +                              tmpCursor = [NSCursor resizeDownCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorLeftSide:\r
 +                              tmpCursor = [NSCursor resizeLeftCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorRightSide:\r
 +                              tmpCursor = [NSCursor resizeRightCursor];\r
 +                              break;\r
 +                      case GHOST_kStandardCursorRightArrow:\r
 +                      case GHOST_kStandardCursorInfo:\r
 +                      case GHOST_kStandardCursorLeftArrow:\r
 +                      case GHOST_kStandardCursorHelp:\r
 +                      case GHOST_kStandardCursorCycle:\r
 +                      case GHOST_kStandardCursorSpray:\r
 +                      case GHOST_kStandardCursorWait:\r
 +                      case GHOST_kStandardCursorTopLeftCorner:\r
 +                      case GHOST_kStandardCursorTopRightCorner:\r
 +                      case GHOST_kStandardCursorBottomRightCorner:\r
 +                      case GHOST_kStandardCursorBottomLeftCorner:\r
+                       case GHOST_kStandardCursorCopy:
 -                      case GHOST_kStandardCursorDefault:
 -                      default:
 -                              tmpCursor = [NSCursor arrowCursor];
 -                              break;
 -              };
 -      }
 -      [tmpCursor set];
 -      [pool drain];
 -}
 -
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
 -{
 -      if ([m_window isVisible]) {
 -              loadCursor(visible, getCursorShape());
 -      }
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 +                      case GHOST_kStandardCursorDefault:\r
 +                      default:\r
 +                              tmpCursor = [NSCursor arrowCursor];\r
 +                              break;\r
 +              };\r
 +      }\r
 +      [tmpCursor set];\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)\r
 +{\r
 +      if ([m_window isVisible]) {\r
 +              loadCursor(visible, getCursorShape());\r
 +      }\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
  GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
 -{
 +{\r
        GHOST_TSuccess err = GHOST_kSuccess;
 -      
 +      \r
        if (mode != GHOST_kGrabDisable)
 -      {
 -              //No need to perform grab without warp as it is always on in OS X
 +      {\r
 +              //No need to perform grab without warp as it is always on in OS X\r
                if(mode != GHOST_kGrabNormal) {
 -                      GHOST_TInt32 x_old,y_old;
 +                      GHOST_TInt32 x_old,y_old;\r
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -                      m_systemCocoa->getCursorPosition(x_old,y_old);
 +\r
 +                      m_systemCocoa->getCursorPosition(x_old,y_old);\r
                        screenToClient(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
 -                      //Warp position is stored in client (window base) coordinates
 +                      //Warp position is stored in client (window base) coordinates\r
                        setCursorGrabAccum(0, 0);
                        
                        if(mode == GHOST_kGrabHide) {
                                setWindowCursorVisibility(false);
                        }
                        
+                       //Make window key if it wasn't to get the mouse move events
+                       [m_window makeKeyWindow];
+                       
                        //Dissociate cursor position even for warp mode, to allow mouse acceleration to work even when warping the cursor
                        err = CGAssociateMouseAndMouseCursorPosition(false) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
 -              }
 -      }
 -      else {
+                       
+                       [pool drain];
 +              }\r
 +      }\r
 +      else {\r
                if(m_cursorGrab==GHOST_kGrabHide)
                {
                        //No need to set again cursor position, as it has not changed for Cocoa
index ef1f827071f574cda50977346914303bd189bfae,806f8d183ba8354872c493328465f46079be79d1..d89983bc938e3a9dfb9d3d418f05fccc47763c45
@@@ -174,7 -224,28 +174,29 @@@ int MEM_allocN_len(void *vmemh
                return 0;
  }
  
 -void *MEM_dupallocN(void *vmemh)
++void *MEM_reallocN(void *vmemh, unsigned int len)
+ {
+       void *newp= NULL;
+       
+       if (vmemh) {
+               MemHead *memh= vmemh;
+               memh--;
 -              
 -              if(memh->mmap)
 -                      newp= MEM_mapallocN(memh->len, "dupli_mapalloc");
 -              else
 -                      newp= MEM_mallocN(memh->len, "dupli_alloc");
 -              if (newp == NULL) return NULL;
++              newp= MEM_mallocN(len, memh->name);
++              if(newp) {
++                      if(len < memh->len)
++                              memcpy(newp, vmemh, len);
++                      else
++                              memcpy(newp, vmemh, memh->len);
++              }
 -              memcpy(newp, vmemh, memh->len);
++              MEM_freeN(vmemh);
+       }
+       return newp;
+ }
 -void *MEM_reallocN(void *vmemh, unsigned int len)
 +void *MEM_dupallocN(void *vmemh)
  {
        void *newp= NULL;
        
Simple merge
index 8ff0a6a854b30739682834632e0a97ac0bbba480,9b2613de86156c223b2e38ef8fde0c2ff2307b74..60824daaa618ab1fb006c8012098397a9c6f849d
 -<?xml version="1.0" encoding="Windows-1252"?>\r
 -<VisualStudioProject\r
 -      ProjectType="Visual C++"\r
 -      Version="9,00"\r
 -      Name="blender"\r
 -      ProjectGUID="{F78B7FC9-DE32-465E-9F26-BB0B6B7A2EAF}"\r
 -      RootNamespace="blender"\r
 -      TargetFrameworkVersion="131072"\r
 -      >\r
 -      <Platforms>\r
 -              <Platform\r
 -                      Name="Win32"\r
 -              />\r
 -      </Platforms>\r
 -      <ToolFiles>\r
 -      </ToolFiles>\r
 -      <Configurations>\r
 -              <Configuration\r
 -                      Name="Blender Release|Win32"\r
 -                      OutputDirectory="..\..\bin"\r
 -                      IntermediateDirectory="..\..\..\build\msvc_9\source\blender"\r
 -                      ConfigurationType="1"\r
 -                      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
 -                      UseOfMFC="0"\r
 -                      ATLMinimizesCRunTimeLibraryUsage="false"\r
 -                      CharacterSet="2"\r
 -                      >\r
 -                      <Tool\r
 -                              Name="VCPreBuildEventTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCCustomBuildTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCXMLDataGeneratorTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCWebServiceProxyGeneratorTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCMIDLTool"\r
 -                              TypeLibraryName=".\..\..\obj\windows\blender/blender.tlb"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCCLCompilerTool"\r
 -                              Optimization="2"\r
 -                              InlineFunctionExpansion="1"\r
 -                              AdditionalIncludeDirectories="..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\source\blender;..\..\source\blender\imbuf;..\..\source\blender\misc;..\..\source\blender\blenlib;..\..\source\blender\editors\include;..\..\source\blender\python;..\..\source\blender\windowmanager;..\..\source\blender\renderui;..\..\source\blender\makesdna;..\..\source\blender\makesrna;..\..\source\blender\blenkernel;..\..\source\blender\blenloader;..\..\source\blender\renderconverter;..\..\source\blender\render\extern\include;..\..\source\blender\radiosity\extern\include;..\..\source\kernel\gen_system;..\..\source\kernel\gen_messaging;..\..\..\build\msvc_9\extern\glew\include;..\..\source\blender\gpu"\r
 -                              PreprocessorDefinitions="NDEBUG;WIN32;_CONSOLE;WITH_QUICKTIME;GAMEBLENDER=1;USE_SUMO_SOLID;FTGL_LIBRARY_STATIC"\r
 -                              StringPooling="true"\r
 -                              RuntimeLibrary="0"\r
 -                              EnableFunctionLevelLinking="true"\r
 -                              DefaultCharIsUnsigned="true"\r
 -                              UsePrecompiledHeader="0"\r
 -                              PrecompiledHeaderFile="..\..\..\build\msvc_9\source\blender\blender.pch"\r
 -                              AssemblerListingLocation="..\..\..\build\msvc_9\source\blender\"\r
 -                              ObjectFile="..\..\..\build\msvc_9\source\blender\"\r
 -                              ProgramDataBaseFileName="..\..\..\build\msvc_9\source\blender\"\r
 -                              WarningLevel="2"\r
 -                              SuppressStartupBanner="true"\r
 -                              CompileAs="0"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCManagedResourceCompilerTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCResourceCompilerTool"\r
 -                              PreprocessorDefinitions="NDEBUG"\r
 -                              Culture="0"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCPreLinkEventTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCLinkerTool"\r
 -                              AdditionalOptions="/MACHINE:I386"\r
 -                              AdditionalDependencies="libsamplerate.lib SDL.lib freetype2ST.lib gnu_gettext.lib qtmlClient.lib wrap_oal.lib ws2_32.lib dxguid.lib opengl32.lib libjpeg.lib glu32.lib vfw32.lib winmm.lib libpng_st.lib zlib.lib python31.lib pthreadVSE2.lib pthreadVC2.lib libtiff.lib Half.lib Iex.lib IlmImf.lib Imath.lib IlmThread.lib avcodec-52.lib avformat-52.lib avutil-50.lib swscale-0.lib avdevice-52.lib libsndfile-1.lib OpenCOLLADABaseUtils.lib OpenCOLLADAFramework.lib OpenCOLLADAStreamWriter.lib OpenCOLLADASaxFrameworkLoader.lib pcre.lib UTF.lib GeneratedSaxParser.lib MathMLSolver.lib xml2.lib buffer.lib ftoa.lib"\r
 -                              ShowProgress="0"\r
 -                              OutputFile="..\..\..\install\msvc_9\blender.exe"\r
 -                              LinkIncremental="1"\r
 -                              SuppressStartupBanner="true"\r
 -                              AdditionalLibraryDirectories="..\..\..\lib\windows\sdl\lib;..\..\..\lib\windows\ode\lib;..\..\..\lib\windows\zlib\lib;..\..\..\lib\windows\png\lib;..\..\..\lib\windows\jpeg\lib;..\..\..\lib\windows\gettext\lib;..\..\..\lib\windows\python\lib;..\..\..\lib\windows\freetype\lib;..\..\..\lib\windows\tiff\lib;..\..\..\lib\windows\pthreads\lib;..\..\..\lib\windows\openal\lib;..\..\..\lib\windows\openexr\lib_vs2008;..\..\..\lib\windows\QTDevWin\Libraries;..\..\..\build\msvc_9\libs\intern;..\..\..\build\msvc_9\libs\extern;..\..\..\lib\windows\ffmpeg\lib;..\..\..\lib\windows\samplerate\lib;..\..\..\lib\windows\sndfile\lib;..\..\..\lib\windows\opencollada\lib;..\..\..\lib\windows\jack\lib"\r
 -                              IgnoreAllDefaultLibraries="false"\r
 -                              IgnoreDefaultLibraryNames="msvcprt.lib;glut32.lib;libc.lib;libcd.lib;libcpd.lib;libcp.lib;libcmtd.lib;odbc32.lib;odbccp32.lib"\r
 -                              GenerateDebugInformation="true"\r
 -                              ProgramDatabaseFile="..\..\..\build\msvc_9\libs\blender.pdb"\r
 -                              SubSystem="1"\r
 -                              RandomizedBaseAddress="1"\r
 -                              DataExecutionPrevention="0"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCALinkTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCManifestTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCXDCMakeTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCBscMakeTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCFxCopTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCAppVerifierTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCPostBuildEventTool"\r
 -                              CommandLine="ECHO Moving libraries and export definitions...&#x0D;&#x0A;MOVE /Y ..\..\bin\blender.lib ..\..\..\build\msvc_9\libs&#x0D;&#x0A;MOVE /Y ..\..\bin\blender.exp ..\..\..\build\msvc_9\libs&#x0D;&#x0A;ECHO Copying required 3rd party dlls...&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\python\lib\python31.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\release\python31.zip ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\zlib\lib\zlib.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\openal\lib\wrap_oal.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\openal\lib\OpenAL32.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\jack\lib\libjack.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\gettext\lib\*.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\sdl\lib\*.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\tiff\lib\*.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\pthreads\lib\pthreadVSE2.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\ffmpeg\lib\*.dll ..\..\..\install\msvc_9&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\sndfile\lib\*.dll ..\..\..\install\msvc_9&#x0D;&#x0A;ECHO Copying language folder&#x0D;&#x0A;IF NOT EXIST ..\..\..\install\msvc_9\.blender MKDIR ..\..\..\install\msvc_9\.blender&#x0D;&#x0A;XCOPY /Y ..\..\bin\.blender ..\..\..\install\msvc_9\.blender /E&#x0D;&#x0A;ECHO Copying python scripts&#x0D;&#x0A;IF NOT EXIST ..\..\..\install\msvc_9\.blender\scripts MKDIR ..\..\..\install\msvc_9\.blender\scripts&#x0D;&#x0A;XCOPY /Y ..\..\release\scripts ..\..\..\install\msvc_9\.blender\scripts /E&#x0D;&#x0A;ECHO Copying python ui scripts&#x0D;&#x0A;IF NOT EXIST ..\..\bin\.blender\ui MKDIR ..\..\..\install\msvc_9\.blender\ui&#x0D;&#x0A;XCOPY /Y ..\..\release\ui ..\..\..\install\msvc_9\.blender\ui /E&#x0D;&#x0A;ECHO Copying manuals/text&#x0D;&#x0A;XCOPY/Y ..\..\release\text ..\..\..\install\msvc_9 /E&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"\r
 -                      />\r
 -              </Configuration>\r
 -              <Configuration\r
 -                      Name="Blender Debug|Win32"\r
 -                      OutputDirectory="..\..\bin\debug"\r
 -                      IntermediateDirectory="..\..\..\build\msvc_9\source\blender\debug"\r
 -                      ConfigurationType="1"\r
 -                      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
 -                      UseOfMFC="0"\r
 -                      ATLMinimizesCRunTimeLibraryUsage="false"\r
 -                      CharacterSet="2"\r
 -                      DeleteExtensionsOnClean="*.obj;*.pdb;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.bat;$(TargetPath)"\r
 -                      >\r
 -                      <Tool\r
 -                              Name="VCPreBuildEventTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCCustomBuildTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCXMLDataGeneratorTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCWebServiceProxyGeneratorTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCMIDLTool"\r
 -                              TypeLibraryName=".\..\..\obj\windows\blender\debug/blender.tlb"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCCLCompilerTool"\r
 -                              Optimization="0"\r
 -                              AdditionalIncludeDirectories="..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\source\blender;..\..\source\blender\imbuf;..\..\source\blender\misc;..\..\source\blender\blenlib;..\..\source\blender\editors\include;..\..\source\blender\python;..\..\source\blender\windowmanager;..\..\source\blender\renderui;..\..\source\blender\makesdna;..\..\source\blender\makesrna;..\..\source\blender\blenkernel;..\..\source\blender\blenloader;..\..\source\blender\renderconverter;..\..\source\blender\render\extern\include;..\..\source\blender\radiosity\extern\include;..\..\source\kernel\gen_system;..\..\source\kernel\gen_messaging;..\..\..\build\msvc_9\extern\glew\include;..\..\source\blender\gpu"\r
 -                              PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;WITH_QUICKTIME"\r
 -                              BasicRuntimeChecks="3"\r
 -                              RuntimeLibrary="1"\r
 -                              UsePrecompiledHeader="0"\r
 -                              PrecompiledHeaderFile="..\..\..\build\msvc_9\source\blender\debug\blender.pch"\r
 -                              AssemblerListingLocation="..\..\..\build\msvc_9\source\blender\debug\"\r
 -                              ObjectFile="..\..\..\build\msvc_9\source\blender\debug\"\r
 -                              ProgramDataBaseFileName="..\..\..\build\msvc_9\source\blender\debug\"\r
 -                              WarningLevel="3"\r
 -                              SuppressStartupBanner="true"\r
 -                              DebugInformationFormat="3"\r
 -                              CompileAs="0"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCManagedResourceCompilerTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCResourceCompilerTool"\r
 -                              PreprocessorDefinitions="_DEBUG"\r
 -                              Culture="1033"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCPreLinkEventTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCLinkerTool"\r
 -                              AdditionalOptions="/MACHINE:I386&#x0D;&#x0A;"\r
 -                              AdditionalDependencies="SDL.lib freetype2ST.lib gnu_gettext.lib qtmlClient.lib wrap_oal.lib ws2_32.lib dxguid.lib opengl32.lib libjpeg.lib glu32.lib vfw32.lib winmm.lib libpng_st.lib zlib.lib python31_d.lib pthreadVSE2.lib pthreadVC2.lib libtiff.lib Half_d.lib Iex_d.lib Imath_d.lib IlmImf_d.lib IlmThread_d.lib avcodec-52.lib avformat-52.lib avdevice-52.lib avutil-50.lib swscale-0.lib libsndfile-1.lib libsamplerate.lib libjack.lib OpenCOLLADABaseUtils_d.lib OpenCOLLADAFramework_d.lib OpenCOLLADAStreamWriter_d.lib OpenCOLLADASaxFrameworkLoader_d.lib pcre_d.lib UTF_d.lib GeneratedSaxParser_d.lib MathMLSolver_d.lib xml2_d.lib buffer_d.lib ftoa_d.lib"\r
 -                              ShowProgress="0"\r
 -                              OutputFile="..\..\..\install\msvc_9d\blender.exe"\r
 -                              LinkIncremental="2"\r
 -                              SuppressStartupBanner="true"\r
 -                              AdditionalLibraryDirectories="..\..\..\lib\windows\sdl\lib;..\..\..\lib\windows\ode\lib;..\..\..\lib\windows\zlib\lib;..\..\..\lib\windows\png\lib;..\..\..\lib\windows\jpeg\lib;..\..\..\lib\windows\pthreads\lib;..\..\..\lib\windows\tiff\lib;..\..\..\lib\windows\gettext\lib;..\..\..\lib\windows\freetype\lib;..\..\..\lib\windows\python\lib;..\..\..\lib\windows\openal\lib;..\..\..\lib\windows\openexr\lib_vs2008;..\..\..\lib\windows\QTDevWin\Libraries;..\..\..\lib\windows\ffmpeg\lib;..\..\..\build\msvc_9\libs\intern\debug;..\..\..\build\msvc_9\libs\extern\debug;..\..\..\lib\windows\samplerate\lib;..\..\..\lib\windows\sndfile\lib;..\..\..\lib\windows\opencollada\lib;..\..\..\lib\windows\jack\lib"\r
 -                              IgnoreDefaultLibraryNames="libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, odbc32.lib, odbccp32.lib"\r
 -                              GenerateDebugInformation="true"\r
 -                              ProgramDatabaseFile="..\..\..\build\msvc_9\libs\debug\blender.pdb"\r
 -                              SubSystem="1"\r
 -                              RandomizedBaseAddress="1"\r
 -                              DataExecutionPrevention="0"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCALinkTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCManifestTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCXDCMakeTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCBscMakeTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCFxCopTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCAppVerifierTool"\r
 -                      />\r
 -                      <Tool\r
 -                              Name="VCPostBuildEventTool"\r
 -                              CommandLine="ECHO Copying required 3rd party dlls...&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\gettext\lib\*.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\sdl\lib\*.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\python\lib\python31_d.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;COPY /Y ..\..\..\lib\windows\release\python31.zip ..\..\..\install\msvc_9d\python31_d.zip&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\zlib\lib\zlib.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\openal\lib\wrap_oal.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\openal\lib\OpenAL32.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\jack\lib\libjack.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\CRTL\lib\msvcrtd.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\tiff\lib\*.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\pthreads\lib\pthreadVSE2.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\ffmpeg\lib\*.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;XCOPY /Y ..\..\..\lib\windows\sndfile\lib\*.dll ..\..\..\install\msvc_9d&#x0D;&#x0A;ECHO Copying language folder&#x0D;&#x0A;IF NOT EXIST ..\..\..\install\msvc_9d\.blender MKDIR ..\..\..\install\msvc_9d\.blender&#x0D;&#x0A;XCOPY /Y ..\..\bin\.blender ..\..\..\install\msvc_9d\.blender /E&#x0D;&#x0A;ECHO Copying python scripts&#x0D;&#x0A;IF NOT EXIST ..\..\..\install\msvc_9d\.blender\scripts MKDIR ..\..\..\install\msvc_9d\.blender\scripts&#x0D;&#x0A;XCOPY /Y ..\..\release\scripts ..\..\..\install\msvc_9d\.blender\scripts /E&#x0D;&#x0A;ECHO Copying python ui scripts&#x0D;&#x0A;IF NOT EXIST ..\..\..\install\msvc_9d\.blender\ui MKDIR ..\..\..\install\msvc_9d\.blender\ui&#x0D;&#x0A;XCOPY /Y ..\..\release\ui ..\..\..\install\msvc_9d\.blender\ui /E&#x0D;&#x0A;ECHO Copying manuals/text&#x0D;&#x0A;XCOPY/Y ..\..\release\text ..\..\..\install\msvc_9d /E&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"\r
 -                      />\r
 -              </Configuration>\r
 -      </Configurations>\r
 -      <References>\r
 -      </References>\r
 -      <Files>\r
 -              <Filter\r
 -                      Name="Resource Files"\r
 -                      Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
 -                      >\r
 -                      <File\r
 -                              RelativePath="..\..\source\icons\winblender.ico"\r
 -                              >\r
 -                      </File>\r
 -                      <File\r
 -                              RelativePath="..\..\source\icons\winblenderfile.ico"\r
 -                              >\r
 -                      </File>\r
 -              </Filter>\r
 -              <Filter\r
 -                      Name="Header Files"\r
 -                      Filter="h;hpp;hxx;hm;inl"\r
 -                      >\r
 -              </Filter>\r
 -              <Filter\r
 -                      Name="Source Files"\r
 -                      Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
 -                      >\r
 -                      <File\r
 -                              RelativePath="..\..\source\creator\buildinfo.c"\r
 -                              >\r
 -                      </File>\r
 -                      <File\r
 -                              RelativePath="..\..\source\creator\creator.c"\r
 -                              >\r
 -                      </File>\r
 -                      <File\r
 -                              RelativePath="..\..\source\icons\winblender.rc"\r
 -                              >\r
 -                              <FileConfiguration\r
 -                                      Name="Blender Release|Win32"\r
 -                                      >\r
 -                                      <Tool\r
 -                                              Name="VCResourceCompilerTool"\r
 -                                              AdditionalIncludeDirectories="\blenderdev\blender.test2\source\icons;$(NoInherit)"\r
 -                                      />\r
 -                              </FileConfiguration>\r
 -                              <FileConfiguration\r
 -                                      Name="Blender Debug|Win32"\r
 -                                      >\r
 -                                      <Tool\r
 -                                              Name="VCResourceCompilerTool"\r
 -                                              AdditionalIncludeDirectories="\blenderdev\blender.test2\source\icons;$(NoInherit)"\r
 -                                      />\r
 -                              </FileConfiguration>\r
 -                      </File>\r
 -              </Filter>\r
 -      </Files>\r
 -      <Globals>\r
 -      </Globals>\r
 -</VisualStudioProject>\r
 +<?xml version="1.0" encoding="Windows-1252"?>
 +<VisualStudioProject
 +      ProjectType="Visual C++"
 +      Version="9.00"
 +      Name="blender"
 +      ProjectGUID="{F78B7FC9-DE32-465E-9F26-BB0B6B7A2EAF}"
 +      RootNamespace="blender"
 +      TargetFrameworkVersion="131072"
 +      >
 +      <Platforms>
 +              <Platform
 +                      Name="Win32"
 +              />
 +      </Platforms>
 +      <ToolFiles>
 +      </ToolFiles>
 +      <Configurations>
 +              <Configuration
 +                      Name="Blender Release|Win32"
 +                      OutputDirectory="..\..\bin"
 +                      IntermediateDirectory="..\..\..\build\msvc_9\source\blender"
 +                      ConfigurationType="1"
 +                      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
 +                      UseOfMFC="0"
 +                      ATLMinimizesCRunTimeLibraryUsage="false"
 +                      CharacterSet="2"
 +                      >
 +                      <Tool
 +                              Name="VCPreBuildEventTool"
 +                      />
 +                      <Tool
 +                              Name="VCCustomBuildTool"
 +                      />
 +                      <Tool
 +                              Name="VCXMLDataGeneratorTool"
 +                      />
 +                      <Tool
 +                              Name="VCWebServiceProxyGeneratorTool"
 +                      />
 +                      <Tool
 +                              Name="VCMIDLTool"
 +                              TypeLibraryName=".\..\..\obj\windows\blender/blender.tlb"
 +                      />
 +                      <Tool
 +                              Name="VCCLCompilerTool"
 +                              Optimization="2"
 +                              InlineFunctionExpansion="1"
 +                              AdditionalIncludeDirectories="..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\source\blender;..\..\source\blender\imbuf;..\..\source\blender\misc;..\..\source\blender\blenlib;..\..\source\blender\editors\include;..\..\source\blender\python;..\..\source\blender\windowmanager;..\..\source\blender\renderui;..\..\source\blender\makesdna;..\..\source\blender\makesrna;..\..\source\blender\blenkernel;..\..\source\blender\blenloader;..\..\source\blender\renderconverter;..\..\source\blender\render\extern\include;..\..\source\blender\radiosity\extern\include;..\..\source\kernel\gen_system;..\..\source\kernel\gen_messaging;..\..\..\build\msvc_9\extern\glew\include;..\..\source\blender\gpu;..\..\source\blender\bmesh"
 +                              PreprocessorDefinitions="NDEBUG;WIN32;_CONSOLE;WITH_QUICKTIME;GAMEBLENDER=1;USE_SUMO_SOLID;FTGL_LIBRARY_STATIC"
 +                              StringPooling="true"
 +                              RuntimeLibrary="0"
 +                              EnableFunctionLevelLinking="true"
 +                              DefaultCharIsUnsigned="true"
 +                              UsePrecompiledHeader="0"
 +                              PrecompiledHeaderFile="..\..\..\build\msvc_9\source\blender\blender.pch"
 +                              AssemblerListingLocation="..\..\..\build\msvc_9\source\blender\"
 +                              ObjectFile="..\..\..\build\msvc_9\source\blender\"
 +                              ProgramDataBaseFileName="..\..\..\build\msvc_9\source\blender\"
 +                              WarningLevel="2"
 +                              SuppressStartupBanner="true"
 +                              CompileAs="0"
 +                      />
 +                      <Tool
 +                              Name="VCManagedResourceCompilerTool"
 +                      />
 +                      <Tool
 +                              Name="VCResourceCompilerTool"
 +                              PreprocessorDefinitions="NDEBUG"
 +                              Culture="0"
 +                      />
 +                      <Tool
 +                              Name="VCPreLinkEventTool"
 +                      />
 +                      <Tool
 +                              Name="VCLinkerTool"
 +                              AdditionalOptions="/MACHINE:I386"
 +                              AdditionalDependencies="libsamplerate.lib SDL.lib freetype2ST.lib gnu_gettext.lib qtmlClient.lib OpenAL32.lib wrap_oal.lib ws2_32.lib dxguid.lib opengl32.lib libjpeg.lib glu32.lib vfw32.lib winmm.lib libpng_st.lib zlib.lib python31.lib pthreadVSE2.lib pthreadVC2.lib libtiff.lib Half.lib Iex.lib IlmImf.lib Imath.lib IlmThread.lib avcodec-52.lib avformat-52.lib avutil-50.lib swscale-0.lib avdevice-52.lib libsndfile-1.lib OpenCOLLADABaseUtils.lib OpenCOLLADAFramework.lib OpenCOLLADAStreamWriter.lib OpenCOLLADASaxFrameworkLoader.lib pcre.lib UTF.lib GeneratedSaxParser.lib MathMLSolver.lib xml2.lib"
 +                              ShowProgress="0"
 +                              OutputFile="..\..\..\install\msvc_9\blender.exe"
 +                              LinkIncremental="1"
 +                              SuppressStartupBanner="true"
 +                              AdditionalLibraryDirectori