merge with trunk/2.5 at r24378
authorJoseph Eagar <joeedh@gmail.com>
Sat, 7 Nov 2009 23:10:18 +0000 (23:10 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Sat, 7 Nov 2009 23:10:18 +0000 (23:10 +0000)
100 files changed:
1  2 
SConstruct
config/win32-vc-config.py
intern/ghost/SConscript
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_WindowCocoa.mm
projectfiles_vc9/blender/blender.sln
projectfiles_vc9/blender/blender.vcproj
release/datafiles/datatoc.py
release/scripts/modules/bpy_ext/Object.py
release/scripts/modules/bpy_ops.py
release/scripts/ui/space_console.py
release/scripts/ui/space_view3d.py
source/blender/CMakeLists.txt
source/blender/SConscript
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/constraint.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/fmodifier.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/animation/drivers.c
source/blender/editors/animation/keyframing.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/armature/poseobject.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_view3d.h
source/blender/editors/interface/interface_handlers.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/editmesh.c
source/blender/editors/mesh/editmesh_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/metaball/mball_edit.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_shapekey.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/screen/Makefile
source/blender/editors/screen/SConscript
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_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_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_orientations.c
source/blender/editors/util/editmode_undo.c
source/blender/editors/uvedit/uvedit_intern.h
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/makesrna/intern/rna_wm_api.c
source/blender/python/epy_doc_gen.py
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_operator.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_rna.c
source/blender/python/rna_dump.py
source/blender/python/simple_enum_gen.py
source/blender/render/intern/source/pointdensity.c
source/blender/render/intern/source/shadeoutput.c
source/blender/windowmanager/intern/wm_operators.c
source/creator/CMakeLists.txt
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
tools/Blender.py
tools/btools.py

diff --cc SConstruct
Simple merge
Simple merge
index 48009152699488fb57ec51c5ca6460d739f69031,09da6f94ddcb1272e9f9a9d2e6f00d829b843c10..490b45afc1f506a75d34954e0995f3a8121fb03c
@@@ -7,26 -7,38 +7,38 @@@ Import ('env'
  window_system = env['OURPLATFORM']
  
  sources = env.Glob('intern/*.cpp')
 -      sources += env.Glob('intern/*.mm')
+ if window_system == 'darwin':
++    sources += env.Glob('intern/*.mm')
  
  pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_Window']
  
  if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd6', 'irix6'):
 -      for f in pf:
 -              sources.remove('intern' + os.sep + f + 'Win32.cpp')
 -              sources.remove('intern' + os.sep + f + 'Carbon.cpp')
 +    for f in pf:
 +        sources.remove('intern' + os.sep + f + 'Win32.cpp')
 +        sources.remove('intern' + os.sep + f + 'Carbon.cpp')
  elif window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'):
 -      for f in pf:
 -              sources.remove('intern' + os.sep + f + 'X11.cpp')
 -              sources.remove('intern' + os.sep + f + 'Carbon.cpp')
 +    for f in pf:
 +        sources.remove('intern' + os.sep + f + 'X11.cpp')
 +        sources.remove('intern' + os.sep + f + 'Carbon.cpp')
  elif window_system == 'darwin':
-     for f in pf:
-         sources.remove('intern' + os.sep + f + 'Win32.cpp')
-         sources.remove('intern' + os.sep + f + 'X11.cpp')
 -      if env['WITH_GHOST_COCOA']:
 -              for f in pf:
 -                      sources.remove('intern' + os.sep + f + 'Win32.cpp')
 -                      sources.remove('intern' + os.sep + f + 'X11.cpp')
 -                      sources.remove('intern' + os.sep + f + 'Carbon.cpp')
 -      else:
 -              for f in pf:
 -                      sources.remove('intern' + os.sep + f + 'Win32.cpp')
 -                      sources.remove('intern' + os.sep + f + 'X11.cpp')
 -                      sources.remove('intern' + os.sep + f + 'Cocoa.mm')
++    if env['WITH_GHOST_COCOA']:
++        for f in pf:
++            sources.remove('intern' + os.sep + f + 'Win32.cpp')
++            sources.remove('intern' + os.sep + f + 'X11.cpp')
++            sources.remove('intern' + os.sep + f + 'Carbon.cpp')
++    else:
++        for f in pf:
++            sources.remove('intern' + os.sep + f + 'Win32.cpp')
++            sources.remove('intern' + os.sep + f + 'X11.cpp')
++            sources.remove('intern' + os.sep + f + 'Cocoa.mm')
  else:
 -      print "Unknown window system specified."
 -      Exit()
 +    print "Unknown window system specified."
 +    Exit()
  
  incs = '. ../string ' + env['BF_OPENGL_INC']
  if window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'):
 -      incs = env['BF_WINTAB_INC'] + ' ' + incs
 +    incs = env['BF_WINTAB_INC'] + ' ' + incs
  env.BlenderLib ('bf_ghost', sources, Split(incs), defines=['_USE_MATH_DEFINES'], libtype=['intern','player'], priority = [40,15] ) 
index b476ee8f0f2bc175509800af45796e8c8f744a78,73be363dff189756411e54f2dfcf81cbb2cb504e..46d8ecf6f9430f484b62d924ea5b0f6c0d8ad05d
 -/**
 - * $Id$
 - * ***** BEGIN GPL LICENSE BLOCK *****
 - *
 - * This program is free software; you can redistribute it and/or
 - * modify it under the terms of the GNU General Public License
 - * as published by the Free Software Foundation; either version 2
 - * of the License, or (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software Foundation,
 - * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 - *
 - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 - * All rights reserved.
 - *
 - * The Original Code is: all of this file.
 - *
 - * Contributor(s):    Maarten Gribnau 05/2001
 - *                                    Damien Plisson 09/2009
 - *
 - * ***** END GPL LICENSE BLOCK *****
 - */
 -
 -#import <Cocoa/Cocoa.h>
 -
 -#include <sys/time.h>
 -#include <sys/types.h>
 -#include <sys/sysctl.h>
 -
 -#include "GHOST_SystemCocoa.h"
 -
 -#include "GHOST_DisplayManagerCocoa.h"
 -#include "GHOST_EventKey.h"
 -#include "GHOST_EventButton.h"
 -#include "GHOST_EventCursor.h"
 -#include "GHOST_EventWheel.h"
 -#include "GHOST_EventNDOF.h"
 -
 -#include "GHOST_TimerManager.h"
 -#include "GHOST_TimerTask.h"
 -#include "GHOST_WindowManager.h"
 -#include "GHOST_WindowCocoa.h"
 -#include "GHOST_NDOFManager.h"
 -#include "AssertMacros.h"
 -
 -#pragma mark KeyMap, mouse converters
 -
 -
 -/* Keycodes from Carbon include file */
 -/*  
 - *  Summary:
 - *    Virtual keycodes
 - *  
 - *  Discussion:
 - *    These constants are the virtual keycodes defined originally in
 - *    Inside Mac Volume V, pg. V-191. They identify physical keys on a
 - *    keyboard. Those constants with "ANSI" in the name are labeled
 - *    according to the key position on an ANSI-standard US keyboard.
 - *    For example, kVK_ANSI_A indicates the virtual keycode for the key
 - *    with the letter 'A' in the US keyboard layout. Other keyboard
 - *    layouts may have the 'A' key label on a different physical key;
 - *    in this case, pressing 'A' will generate a different virtual
 - *    keycode.
 - */
 -enum {
 -      kVK_ANSI_A                    = 0x00,
 -      kVK_ANSI_S                    = 0x01,
 -      kVK_ANSI_D                    = 0x02,
 -      kVK_ANSI_F                    = 0x03,
 -      kVK_ANSI_H                    = 0x04,
 -      kVK_ANSI_G                    = 0x05,
 -      kVK_ANSI_Z                    = 0x06,
 -      kVK_ANSI_X                    = 0x07,
 -      kVK_ANSI_C                    = 0x08,
 -      kVK_ANSI_V                    = 0x09,
 -      kVK_ANSI_B                    = 0x0B,
 -      kVK_ANSI_Q                    = 0x0C,
 -      kVK_ANSI_W                    = 0x0D,
 -      kVK_ANSI_E                    = 0x0E,
 -      kVK_ANSI_R                    = 0x0F,
 -      kVK_ANSI_Y                    = 0x10,
 -      kVK_ANSI_T                    = 0x11,
 -      kVK_ANSI_1                    = 0x12,
 -      kVK_ANSI_2                    = 0x13,
 -      kVK_ANSI_3                    = 0x14,
 -      kVK_ANSI_4                    = 0x15,
 -      kVK_ANSI_6                    = 0x16,
 -      kVK_ANSI_5                    = 0x17,
 -      kVK_ANSI_Equal                = 0x18,
 -      kVK_ANSI_9                    = 0x19,
 -      kVK_ANSI_7                    = 0x1A,
 -      kVK_ANSI_Minus                = 0x1B,
 -      kVK_ANSI_8                    = 0x1C,
 -      kVK_ANSI_0                    = 0x1D,
 -      kVK_ANSI_RightBracket         = 0x1E,
 -      kVK_ANSI_O                    = 0x1F,
 -      kVK_ANSI_U                    = 0x20,
 -      kVK_ANSI_LeftBracket          = 0x21,
 -      kVK_ANSI_I                    = 0x22,
 -      kVK_ANSI_P                    = 0x23,
 -      kVK_ANSI_L                    = 0x25,
 -      kVK_ANSI_J                    = 0x26,
 -      kVK_ANSI_Quote                = 0x27,
 -      kVK_ANSI_K                    = 0x28,
 -      kVK_ANSI_Semicolon            = 0x29,
 -      kVK_ANSI_Backslash            = 0x2A,
 -      kVK_ANSI_Comma                = 0x2B,
 -      kVK_ANSI_Slash                = 0x2C,
 -      kVK_ANSI_N                    = 0x2D,
 -      kVK_ANSI_M                    = 0x2E,
 -      kVK_ANSI_Period               = 0x2F,
 -      kVK_ANSI_Grave                = 0x32,
 -      kVK_ANSI_KeypadDecimal        = 0x41,
 -      kVK_ANSI_KeypadMultiply       = 0x43,
 -      kVK_ANSI_KeypadPlus           = 0x45,
 -      kVK_ANSI_KeypadClear          = 0x47,
 -      kVK_ANSI_KeypadDivide         = 0x4B,
 -      kVK_ANSI_KeypadEnter          = 0x4C,
 -      kVK_ANSI_KeypadMinus          = 0x4E,
 -      kVK_ANSI_KeypadEquals         = 0x51,
 -      kVK_ANSI_Keypad0              = 0x52,
 -      kVK_ANSI_Keypad1              = 0x53,
 -      kVK_ANSI_Keypad2              = 0x54,
 -      kVK_ANSI_Keypad3              = 0x55,
 -      kVK_ANSI_Keypad4              = 0x56,
 -      kVK_ANSI_Keypad5              = 0x57,
 -      kVK_ANSI_Keypad6              = 0x58,
 -      kVK_ANSI_Keypad7              = 0x59,
 -      kVK_ANSI_Keypad8              = 0x5B,
 -      kVK_ANSI_Keypad9              = 0x5C
 -};
 -
 -/* keycodes for keys that are independent of keyboard layout*/
 -enum {
 -      kVK_Return                    = 0x24,
 -      kVK_Tab                       = 0x30,
 -      kVK_Space                     = 0x31,
 -      kVK_Delete                    = 0x33,
 -      kVK_Escape                    = 0x35,
 -      kVK_Command                   = 0x37,
 -      kVK_Shift                     = 0x38,
 -      kVK_CapsLock                  = 0x39,
 -      kVK_Option                    = 0x3A,
 -      kVK_Control                   = 0x3B,
 -      kVK_RightShift                = 0x3C,
 -      kVK_RightOption               = 0x3D,
 -      kVK_RightControl              = 0x3E,
 -      kVK_Function                  = 0x3F,
 -      kVK_F17                       = 0x40,
 -      kVK_VolumeUp                  = 0x48,
 -      kVK_VolumeDown                = 0x49,
 -      kVK_Mute                      = 0x4A,
 -      kVK_F18                       = 0x4F,
 -      kVK_F19                       = 0x50,
 -      kVK_F20                       = 0x5A,
 -      kVK_F5                        = 0x60,
 -      kVK_F6                        = 0x61,
 -      kVK_F7                        = 0x62,
 -      kVK_F3                        = 0x63,
 -      kVK_F8                        = 0x64,
 -      kVK_F9                        = 0x65,
 -      kVK_F11                       = 0x67,
 -      kVK_F13                       = 0x69,
 -      kVK_F16                       = 0x6A,
 -      kVK_F14                       = 0x6B,
 -      kVK_F10                       = 0x6D,
 -      kVK_F12                       = 0x6F,
 -      kVK_F15                       = 0x71,
 -      kVK_Help                      = 0x72,
 -      kVK_Home                      = 0x73,
 -      kVK_PageUp                    = 0x74,
 -      kVK_ForwardDelete             = 0x75,
 -      kVK_F4                        = 0x76,
 -      kVK_End                       = 0x77,
 -      kVK_F2                        = 0x78,
 -      kVK_PageDown                  = 0x79,
 -      kVK_F1                        = 0x7A,
 -      kVK_LeftArrow                 = 0x7B,
 -      kVK_RightArrow                = 0x7C,
 -      kVK_DownArrow                 = 0x7D,
 -      kVK_UpArrow                   = 0x7E
 -};
 -
 -/* ISO keyboards only*/
 -enum {
 -      kVK_ISO_Section               = 0x0A
 -};
 -
 -/* JIS keyboards only*/
 -enum {
 -      kVK_JIS_Yen                   = 0x5D,
 -      kVK_JIS_Underscore            = 0x5E,
 -      kVK_JIS_KeypadComma           = 0x5F,
 -      kVK_JIS_Eisu                  = 0x66,
 -      kVK_JIS_Kana                  = 0x68
 -};
 -
 -
 -static GHOST_TButtonMask convertButton(int button)
 -{
 -      switch (button) {
 -              case 0:
 -                      return GHOST_kButtonMaskLeft;
 -              case 1:
 -                      return GHOST_kButtonMaskRight;
 -              case 2:
 -                      return GHOST_kButtonMaskMiddle;
 -              case 3:
 -                      return GHOST_kButtonMaskButton4;
 -              case 4:
 -                      return GHOST_kButtonMaskButton5;
 -              default:
 -                      return GHOST_kButtonMaskLeft;
 -      }
 -}
 -
 -/**
 - * Converts Mac rawkey codes (same for Cocoa & Carbon)
 - * into GHOST key codes
 - * @param rawCode The raw physical key code
 - * @param recvChar the character ignoring modifiers (except for shift)
 - * @return Ghost key code
 - */
 -static GHOST_TKey convertKey(int rawCode, unichar recvChar) 
 -{     
 -      
 -      //printf("\nrecvchar %c 0x%x",recvChar,recvChar);
 -      switch (rawCode) {
 -              /*Physical keycodes not used due to map changes in int'l keyboards
 -              case kVK_ANSI_A:        return GHOST_kKeyA;
 -              case kVK_ANSI_B:        return GHOST_kKeyB;
 -              case kVK_ANSI_C:        return GHOST_kKeyC;
 -              case kVK_ANSI_D:        return GHOST_kKeyD;
 -              case kVK_ANSI_E:        return GHOST_kKeyE;
 -              case kVK_ANSI_F:        return GHOST_kKeyF;
 -              case kVK_ANSI_G:        return GHOST_kKeyG;
 -              case kVK_ANSI_H:        return GHOST_kKeyH;
 -              case kVK_ANSI_I:        return GHOST_kKeyI;
 -              case kVK_ANSI_J:        return GHOST_kKeyJ;
 -              case kVK_ANSI_K:        return GHOST_kKeyK;
 -              case kVK_ANSI_L:        return GHOST_kKeyL;
 -              case kVK_ANSI_M:        return GHOST_kKeyM;
 -              case kVK_ANSI_N:        return GHOST_kKeyN;
 -              case kVK_ANSI_O:        return GHOST_kKeyO;
 -              case kVK_ANSI_P:        return GHOST_kKeyP;
 -              case kVK_ANSI_Q:        return GHOST_kKeyQ;
 -              case kVK_ANSI_R:        return GHOST_kKeyR;
 -              case kVK_ANSI_S:        return GHOST_kKeyS;
 -              case kVK_ANSI_T:        return GHOST_kKeyT;
 -              case kVK_ANSI_U:        return GHOST_kKeyU;
 -              case kVK_ANSI_V:        return GHOST_kKeyV;
 -              case kVK_ANSI_W:        return GHOST_kKeyW;
 -              case kVK_ANSI_X:        return GHOST_kKeyX;
 -              case kVK_ANSI_Y:        return GHOST_kKeyY;
 -              case kVK_ANSI_Z:        return GHOST_kKeyZ;*/
 -              
 -              /* Numbers keys mapped to handle some int'l keyboard (e.g. French)*/
 -              case kVK_ISO_Section: return    GHOST_kKeyUnknown;
 -              case kVK_ANSI_1:        return GHOST_kKey1;
 -              case kVK_ANSI_2:        return GHOST_kKey2;
 -              case kVK_ANSI_3:        return GHOST_kKey3;
 -              case kVK_ANSI_4:        return GHOST_kKey4;
 -              case kVK_ANSI_5:        return GHOST_kKey5;
 -              case kVK_ANSI_6:        return GHOST_kKey6;
 -              case kVK_ANSI_7:        return GHOST_kKey7;
 -              case kVK_ANSI_8:        return GHOST_kKey8;
 -              case kVK_ANSI_9:        return GHOST_kKey9;
 -              case kVK_ANSI_0:        return GHOST_kKey0;
 -      
 -              case kVK_ANSI_Keypad0:                  return GHOST_kKeyNumpad0;
 -              case kVK_ANSI_Keypad1:                  return GHOST_kKeyNumpad1;
 -              case kVK_ANSI_Keypad2:                  return GHOST_kKeyNumpad2;
 -              case kVK_ANSI_Keypad3:                  return GHOST_kKeyNumpad3;
 -              case kVK_ANSI_Keypad4:                  return GHOST_kKeyNumpad4;
 -              case kVK_ANSI_Keypad5:                  return GHOST_kKeyNumpad5;
 -              case kVK_ANSI_Keypad6:                  return GHOST_kKeyNumpad6;
 -              case kVK_ANSI_Keypad7:                  return GHOST_kKeyNumpad7;
 -              case kVK_ANSI_Keypad8:                  return GHOST_kKeyNumpad8;
 -              case kVK_ANSI_Keypad9:                  return GHOST_kKeyNumpad9;
 -              case kVK_ANSI_KeypadDecimal:    return GHOST_kKeyNumpadPeriod;
 -              case kVK_ANSI_KeypadEnter:              return GHOST_kKeyNumpadEnter;
 -              case kVK_ANSI_KeypadPlus:               return GHOST_kKeyNumpadPlus;
 -              case kVK_ANSI_KeypadMinus:              return GHOST_kKeyNumpadMinus;
 -              case kVK_ANSI_KeypadMultiply:   return GHOST_kKeyNumpadAsterisk;
 -              case kVK_ANSI_KeypadDivide:     return GHOST_kKeyNumpadSlash;
 -              case kVK_ANSI_KeypadClear:              return GHOST_kKeyUnknown;
 -
 -              case kVK_F1:                            return GHOST_kKeyF1;
 -              case kVK_F2:                            return GHOST_kKeyF2;
 -              case kVK_F3:                            return GHOST_kKeyF3;
 -              case kVK_F4:                            return GHOST_kKeyF4;
 -              case kVK_F5:                            return GHOST_kKeyF5;
 -              case kVK_F6:                            return GHOST_kKeyF6;
 -              case kVK_F7:                            return GHOST_kKeyF7;
 -              case kVK_F8:                            return GHOST_kKeyF8;
 -              case kVK_F9:                            return GHOST_kKeyF9;
 -              case kVK_F10:                           return GHOST_kKeyF10;
 -              case kVK_F11:                           return GHOST_kKeyF11;
 -              case kVK_F12:                           return GHOST_kKeyF12;
 -              case kVK_F13:                           return GHOST_kKeyF13;
 -              case kVK_F14:                           return GHOST_kKeyF14;
 -              case kVK_F15:                           return GHOST_kKeyF15;
 -              case kVK_F16:                           return GHOST_kKeyF16;
 -              case kVK_F17:                           return GHOST_kKeyF17;
 -              case kVK_F18:                           return GHOST_kKeyF18;
 -              case kVK_F19:                           return GHOST_kKeyF19;
 -              case kVK_F20:                           return GHOST_kKeyF20;
 -                      
 -              case kVK_UpArrow:                       return GHOST_kKeyUpArrow;
 -              case kVK_DownArrow:                     return GHOST_kKeyDownArrow;
 -              case kVK_LeftArrow:                     return GHOST_kKeyLeftArrow;
 -              case kVK_RightArrow:            return GHOST_kKeyRightArrow;
 -                      
 -              case kVK_Return:                        return GHOST_kKeyEnter;
 -              case kVK_Delete:                        return GHOST_kKeyBackSpace;
 -              case kVK_ForwardDelete:         return GHOST_kKeyDelete;
 -              case kVK_Escape:                        return GHOST_kKeyEsc;
 -              case kVK_Tab:                           return GHOST_kKeyTab;
 -              case kVK_Space:                         return GHOST_kKeySpace;
 -                      
 -              case kVK_Home:                          return GHOST_kKeyHome;
 -              case kVK_End:                           return GHOST_kKeyEnd;
 -              case kVK_PageUp:                        return GHOST_kKeyUpPage;
 -              case kVK_PageDown:                      return GHOST_kKeyDownPage;
 -                      
 -              /*case kVK_ANSI_Minus:          return GHOST_kKeyMinus;
 -              case kVK_ANSI_Equal:            return GHOST_kKeyEqual;
 -              case kVK_ANSI_Comma:            return GHOST_kKeyComma;
 -              case kVK_ANSI_Period:           return GHOST_kKeyPeriod;
 -              case kVK_ANSI_Slash:            return GHOST_kKeySlash;
 -              case kVK_ANSI_Semicolon:        return GHOST_kKeySemicolon;
 -              case kVK_ANSI_Quote:            return GHOST_kKeyQuote;
 -              case kVK_ANSI_Backslash:        return GHOST_kKeyBackslash;
 -              case kVK_ANSI_LeftBracket:      return GHOST_kKeyLeftBracket;
 -              case kVK_ANSI_RightBracket:     return GHOST_kKeyRightBracket;
 -              case kVK_ANSI_Grave:            return GHOST_kKeyAccentGrave;*/
 -                      
 -              case kVK_VolumeUp:
 -              case kVK_VolumeDown:
 -              case kVK_Mute:
 -                      return GHOST_kKeyUnknown;
 -                      
 -              default:
 -                      /*Then detect on character value for "remappable" keys in int'l keyboards*/
 -                      if ((recvChar >= 'A') && (recvChar <= 'Z')) {
 -                              return (GHOST_TKey) (recvChar - 'A' + GHOST_kKeyA);
 -                      } else if ((recvChar >= 'a') && (recvChar <= 'z')) {
 -                              return (GHOST_TKey) (recvChar - 'a' + GHOST_kKeyA);
 -                      } else
 -                      switch (recvChar) {
 -                              case '-':       return GHOST_kKeyMinus;
 -                              case '=':       return GHOST_kKeyEqual;
 -                              case ',':       return GHOST_kKeyComma;
 -                              case '.':       return GHOST_kKeyPeriod;
 -                              case '/':       return GHOST_kKeySlash;
 -                              case ';':       return GHOST_kKeySemicolon;
 -                              case '\'':      return GHOST_kKeyQuote;
 -                              case '\\':      return GHOST_kKeyBackslash;
 -                              case '[':       return GHOST_kKeyLeftBracket;
 -                              case ']':       return GHOST_kKeyRightBracket;
 -                              case '`':       return GHOST_kKeyAccentGrave;
 -                              default:
 -                                      return GHOST_kKeyUnknown;
 -                      }
 -      }
 -      return GHOST_kKeyUnknown;
 -}
 -
 -
 -#define FIRSTFILEBUFLG 512
 -static bool g_hasFirstFile = false;
 -static char g_firstFileBuf[512];
 -
 -//TODO:Need to investigate this. Function called too early in creator.c to have g_hasFirstFile == true
 -extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { 
 -      if (g_hasFirstFile) {
 -              strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1);
 -              buf[FIRSTFILEBUFLG - 1] = '\0';
 -              return 1;
 -      } else {
 -              return 0; 
 -      }
 -}
 -
 -
 -#pragma mark Cocoa objects
 -
 -/**
 - * CocoaAppDelegate
 - * ObjC object to capture applicationShouldTerminate, and send quit event
 - **/
 -@interface CocoaAppDelegate : NSObject {
 -      GHOST_SystemCocoa *systemCocoa;
 -}
 +/**\r
 + * $Id: GHOST_SystemCocoa.mm 23854 2009-10-15 08:27:31Z damien78 $\r
 + * ***** BEGIN GPL LICENSE BLOCK *****\r
 + *\r
 + * This program is free software; you can redistribute it and/or\r
 + * modify it under the terms of the GNU General Public License\r
 + * as published by the Free Software Foundation; either version 2\r
 + * of the License, or (at your option) any later version.\r
 + *\r
 + * This program is distributed in the hope that it will be useful,\r
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
 + * GNU General Public License for more details.\r
 + *\r
 + * You should have received a copy of the GNU General Public License\r
 + * along with this program; if not, write to the Free Software Foundation,\r
 + * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
 + *\r
 + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.\r
 + * All rights reserved.\r
 + *\r
 + * The Original Code is: all of this file.\r
 + *\r
 + * Contributor(s):    Maarten Gribnau 05/2001\r
 + *                                    Damien Plisson 09/2009\r
 + *\r
 + * ***** END GPL LICENSE BLOCK *****\r
 + */\r
 +\r
 +#import <Cocoa/Cocoa.h>\r
 +\r
 +#include <sys/time.h>\r
 +#include <sys/types.h>\r
 +#include <sys/sysctl.h>\r
 +\r
 +#include "GHOST_SystemCocoa.h"\r
 +\r
 +#include "GHOST_DisplayManagerCocoa.h"\r
 +#include "GHOST_EventKey.h"\r
 +#include "GHOST_EventButton.h"\r
 +#include "GHOST_EventCursor.h"\r
 +#include "GHOST_EventWheel.h"\r
 +#include "GHOST_EventNDOF.h"\r
 +\r
 +#include "GHOST_TimerManager.h"\r
 +#include "GHOST_TimerTask.h"\r
 +#include "GHOST_WindowManager.h"\r
 +#include "GHOST_WindowCocoa.h"\r
 +#include "GHOST_NDOFManager.h"\r
 +#include "AssertMacros.h"\r
 +\r
 +#pragma mark KeyMap, mouse converters\r
 +\r
 +\r
 +/* Keycodes from Carbon include file */\r
 +/*  \r
 + *  Summary:\r
 + *    Virtual keycodes\r
 + *  \r
 + *  Discussion:\r
 + *    These constants are the virtual keycodes defined originally in\r
 + *    Inside Mac Volume V, pg. V-191. They identify physical keys on a\r
 + *    keyboard. Those constants with "ANSI" in the name are labeled\r
 + *    according to the key position on an ANSI-standard US keyboard.\r
 + *    For example, kVK_ANSI_A indicates the virtual keycode for the key\r
 + *    with the letter 'A' in the US keyboard layout. Other keyboard\r
 + *    layouts may have the 'A' key label on a different physical key;\r
 + *    in this case, pressing 'A' will generate a different virtual\r
 + *    keycode.\r
 + */\r
 +enum {\r
 +      kVK_ANSI_A                    = 0x00,\r
 +      kVK_ANSI_S                    = 0x01,\r
 +      kVK_ANSI_D                    = 0x02,\r
 +      kVK_ANSI_F                    = 0x03,\r
 +      kVK_ANSI_H                    = 0x04,\r
 +      kVK_ANSI_G                    = 0x05,\r
 +      kVK_ANSI_Z                    = 0x06,\r
 +      kVK_ANSI_X                    = 0x07,\r
 +      kVK_ANSI_C                    = 0x08,\r
 +      kVK_ANSI_V                    = 0x09,\r
 +      kVK_ANSI_B                    = 0x0B,\r
 +      kVK_ANSI_Q                    = 0x0C,\r
 +      kVK_ANSI_W                    = 0x0D,\r
 +      kVK_ANSI_E                    = 0x0E,\r
 +      kVK_ANSI_R                    = 0x0F,\r
 +      kVK_ANSI_Y                    = 0x10,\r
 +      kVK_ANSI_T                    = 0x11,\r
 +      kVK_ANSI_1                    = 0x12,\r
 +      kVK_ANSI_2                    = 0x13,\r
 +      kVK_ANSI_3                    = 0x14,\r
 +      kVK_ANSI_4                    = 0x15,\r
 +      kVK_ANSI_6                    = 0x16,\r
 +      kVK_ANSI_5                    = 0x17,\r
 +      kVK_ANSI_Equal                = 0x18,\r
 +      kVK_ANSI_9                    = 0x19,\r
 +      kVK_ANSI_7                    = 0x1A,\r
 +      kVK_ANSI_Minus                = 0x1B,\r
 +      kVK_ANSI_8                    = 0x1C,\r
 +      kVK_ANSI_0                    = 0x1D,\r
 +      kVK_ANSI_RightBracket         = 0x1E,\r
 +      kVK_ANSI_O                    = 0x1F,\r
 +      kVK_ANSI_U                    = 0x20,\r
 +      kVK_ANSI_LeftBracket          = 0x21,\r
 +      kVK_ANSI_I                    = 0x22,\r
 +      kVK_ANSI_P                    = 0x23,\r
 +      kVK_ANSI_L                    = 0x25,\r
 +      kVK_ANSI_J                    = 0x26,\r
 +      kVK_ANSI_Quote                = 0x27,\r
 +      kVK_ANSI_K                    = 0x28,\r
 +      kVK_ANSI_Semicolon            = 0x29,\r
 +      kVK_ANSI_Backslash            = 0x2A,\r
 +      kVK_ANSI_Comma                = 0x2B,\r
 +      kVK_ANSI_Slash                = 0x2C,\r
 +      kVK_ANSI_N                    = 0x2D,\r
 +      kVK_ANSI_M                    = 0x2E,\r
 +      kVK_ANSI_Period               = 0x2F,\r
 +      kVK_ANSI_Grave                = 0x32,\r
 +      kVK_ANSI_KeypadDecimal        = 0x41,\r
 +      kVK_ANSI_KeypadMultiply       = 0x43,\r
 +      kVK_ANSI_KeypadPlus           = 0x45,\r
 +      kVK_ANSI_KeypadClear          = 0x47,\r
 +      kVK_ANSI_KeypadDivide         = 0x4B,\r
 +      kVK_ANSI_KeypadEnter          = 0x4C,\r
 +      kVK_ANSI_KeypadMinus          = 0x4E,\r
 +      kVK_ANSI_KeypadEquals         = 0x51,\r
 +      kVK_ANSI_Keypad0              = 0x52,\r
 +      kVK_ANSI_Keypad1              = 0x53,\r
 +      kVK_ANSI_Keypad2              = 0x54,\r
 +      kVK_ANSI_Keypad3              = 0x55,\r
 +      kVK_ANSI_Keypad4              = 0x56,\r
 +      kVK_ANSI_Keypad5              = 0x57,\r
 +      kVK_ANSI_Keypad6              = 0x58,\r
 +      kVK_ANSI_Keypad7              = 0x59,\r
 +      kVK_ANSI_Keypad8              = 0x5B,\r
 +      kVK_ANSI_Keypad9              = 0x5C\r
 +};\r
 +\r
 +/* keycodes for keys that are independent of keyboard layout*/\r
 +enum {\r
 +      kVK_Return                    = 0x24,\r
 +      kVK_Tab                       = 0x30,\r
 +      kVK_Space                     = 0x31,\r
 +      kVK_Delete                    = 0x33,\r
 +      kVK_Escape                    = 0x35,\r
 +      kVK_Command                   = 0x37,\r
 +      kVK_Shift                     = 0x38,\r
 +      kVK_CapsLock                  = 0x39,\r
 +      kVK_Option                    = 0x3A,\r
 +      kVK_Control                   = 0x3B,\r
 +      kVK_RightShift                = 0x3C,\r
 +      kVK_RightOption               = 0x3D,\r
 +      kVK_RightControl              = 0x3E,\r
 +      kVK_Function                  = 0x3F,\r
 +      kVK_F17                       = 0x40,\r
 +      kVK_VolumeUp                  = 0x48,\r
 +      kVK_VolumeDown                = 0x49,\r
 +      kVK_Mute                      = 0x4A,\r
 +      kVK_F18                       = 0x4F,\r
 +      kVK_F19                       = 0x50,\r
 +      kVK_F20                       = 0x5A,\r
 +      kVK_F5                        = 0x60,\r
 +      kVK_F6                        = 0x61,\r
 +      kVK_F7                        = 0x62,\r
 +      kVK_F3                        = 0x63,\r
 +      kVK_F8                        = 0x64,\r
 +      kVK_F9                        = 0x65,\r
 +      kVK_F11                       = 0x67,\r
 +      kVK_F13                       = 0x69,\r
 +      kVK_F16                       = 0x6A,\r
 +      kVK_F14                       = 0x6B,\r
 +      kVK_F10                       = 0x6D,\r
 +      kVK_F12                       = 0x6F,\r
 +      kVK_F15                       = 0x71,\r
 +      kVK_Help                      = 0x72,\r
 +      kVK_Home                      = 0x73,\r
 +      kVK_PageUp                    = 0x74,\r
 +      kVK_ForwardDelete             = 0x75,\r
 +      kVK_F4                        = 0x76,\r
 +      kVK_End                       = 0x77,\r
 +      kVK_F2                        = 0x78,\r
 +      kVK_PageDown                  = 0x79,\r
 +      kVK_F1                        = 0x7A,\r
 +      kVK_LeftArrow                 = 0x7B,\r
 +      kVK_RightArrow                = 0x7C,\r
 +      kVK_DownArrow                 = 0x7D,\r
 +      kVK_UpArrow                   = 0x7E\r
 +};\r
 +\r
 +/* ISO keyboards only*/\r
 +enum {\r
 +      kVK_ISO_Section               = 0x0A\r
 +};\r
 +\r
 +/* JIS keyboards only*/\r
 +enum {\r
 +      kVK_JIS_Yen                   = 0x5D,\r
 +      kVK_JIS_Underscore            = 0x5E,\r
 +      kVK_JIS_KeypadComma           = 0x5F,\r
 +      kVK_JIS_Eisu                  = 0x66,\r
 +      kVK_JIS_Kana                  = 0x68\r
 +};\r
 +\r
 +\r
 +static GHOST_TButtonMask convertButton(int button)\r
 +{\r
 +      switch (button) {\r
 +              case 0:\r
 +                      return GHOST_kButtonMaskLeft;\r
 +              case 1:\r
 +                      return GHOST_kButtonMaskRight;\r
 +              case 2:\r
 +                      return GHOST_kButtonMaskMiddle;\r
 +              case 3:\r
 +                      return GHOST_kButtonMaskButton4;\r
 +              case 4:\r
 +                      return GHOST_kButtonMaskButton5;\r
 +              default:\r
 +                      return GHOST_kButtonMaskLeft;\r
 +      }\r
 +}\r
 +\r
 +/**\r
 + * Converts Mac rawkey codes (same for Cocoa & Carbon)\r
 + * into GHOST key codes\r
 + * @param rawCode The raw physical key code\r
 + * @param recvChar the character ignoring modifiers (except for shift)\r
 + * @return Ghost key code\r
 + */\r
 +static GHOST_TKey convertKey(int rawCode, unichar recvChar) \r
 +{     \r
 +      \r
 +      //printf("\nrecvchar %c 0x%x",recvChar,recvChar);\r
 +      switch (rawCode) {\r
 +              /*Physical keycodes not used due to map changes in int'l keyboards\r
 +              case kVK_ANSI_A:        return GHOST_kKeyA;\r
 +              case kVK_ANSI_B:        return GHOST_kKeyB;\r
 +              case kVK_ANSI_C:        return GHOST_kKeyC;\r
 +              case kVK_ANSI_D:        return GHOST_kKeyD;\r
 +              case kVK_ANSI_E:        return GHOST_kKeyE;\r
 +              case kVK_ANSI_F:        return GHOST_kKeyF;\r
 +              case kVK_ANSI_G:        return GHOST_kKeyG;\r
 +              case kVK_ANSI_H:        return GHOST_kKeyH;\r
 +              case kVK_ANSI_I:        return GHOST_kKeyI;\r
 +              case kVK_ANSI_J:        return GHOST_kKeyJ;\r
 +              case kVK_ANSI_K:        return GHOST_kKeyK;\r
 +              case kVK_ANSI_L:        return GHOST_kKeyL;\r
 +              case kVK_ANSI_M:        return GHOST_kKeyM;\r
 +              case kVK_ANSI_N:        return GHOST_kKeyN;\r
 +              case kVK_ANSI_O:        return GHOST_kKeyO;\r
 +              case kVK_ANSI_P:        return GHOST_kKeyP;\r
 +              case kVK_ANSI_Q:        return GHOST_kKeyQ;\r
 +              case kVK_ANSI_R:        return GHOST_kKeyR;\r
 +              case kVK_ANSI_S:        return GHOST_kKeyS;\r
 +              case kVK_ANSI_T:        return GHOST_kKeyT;\r
 +              case kVK_ANSI_U:        return GHOST_kKeyU;\r
 +              case kVK_ANSI_V:        return GHOST_kKeyV;\r
 +              case kVK_ANSI_W:        return GHOST_kKeyW;\r
 +              case kVK_ANSI_X:        return GHOST_kKeyX;\r
 +              case kVK_ANSI_Y:        return GHOST_kKeyY;\r
 +              case kVK_ANSI_Z:        return GHOST_kKeyZ;*/\r
 +              \r
 +              /* Numbers keys mapped to handle some int'l keyboard (e.g. French)*/\r
 +              case kVK_ISO_Section: return    GHOST_kKeyUnknown;\r
 +              case kVK_ANSI_1:        return GHOST_kKey1;\r
 +              case kVK_ANSI_2:        return GHOST_kKey2;\r
 +              case kVK_ANSI_3:        return GHOST_kKey3;\r
 +              case kVK_ANSI_4:        return GHOST_kKey4;\r
 +              case kVK_ANSI_5:        return GHOST_kKey5;\r
 +              case kVK_ANSI_6:        return GHOST_kKey6;\r
 +              case kVK_ANSI_7:        return GHOST_kKey7;\r
 +              case kVK_ANSI_8:        return GHOST_kKey8;\r
 +              case kVK_ANSI_9:        return GHOST_kKey9;\r
 +              case kVK_ANSI_0:        return GHOST_kKey0;\r
 +      \r
 +              case kVK_ANSI_Keypad0:                  return GHOST_kKeyNumpad0;\r
 +              case kVK_ANSI_Keypad1:                  return GHOST_kKeyNumpad1;\r
 +              case kVK_ANSI_Keypad2:                  return GHOST_kKeyNumpad2;\r
 +              case kVK_ANSI_Keypad3:                  return GHOST_kKeyNumpad3;\r
 +              case kVK_ANSI_Keypad4:                  return GHOST_kKeyNumpad4;\r
 +              case kVK_ANSI_Keypad5:                  return GHOST_kKeyNumpad5;\r
 +              case kVK_ANSI_Keypad6:                  return GHOST_kKeyNumpad6;\r
 +              case kVK_ANSI_Keypad7:                  return GHOST_kKeyNumpad7;\r
 +              case kVK_ANSI_Keypad8:                  return GHOST_kKeyNumpad8;\r
 +              case kVK_ANSI_Keypad9:                  return GHOST_kKeyNumpad9;\r
 +              case kVK_ANSI_KeypadDecimal:    return GHOST_kKeyNumpadPeriod;\r
 +              case kVK_ANSI_KeypadEnter:              return GHOST_kKeyNumpadEnter;\r
 +              case kVK_ANSI_KeypadPlus:               return GHOST_kKeyNumpadPlus;\r
 +              case kVK_ANSI_KeypadMinus:              return GHOST_kKeyNumpadMinus;\r
 +              case kVK_ANSI_KeypadMultiply:   return GHOST_kKeyNumpadAsterisk;\r
 +              case kVK_ANSI_KeypadDivide:     return GHOST_kKeyNumpadSlash;\r
 +              case kVK_ANSI_KeypadClear:              return GHOST_kKeyUnknown;\r
 +\r
 +              case kVK_F1:                            return GHOST_kKeyF1;\r
 +              case kVK_F2:                            return GHOST_kKeyF2;\r
 +              case kVK_F3:                            return GHOST_kKeyF3;\r
 +              case kVK_F4:                            return GHOST_kKeyF4;\r
 +              case kVK_F5:                            return GHOST_kKeyF5;\r
 +              case kVK_F6:                            return GHOST_kKeyF6;\r
 +              case kVK_F7:                            return GHOST_kKeyF7;\r
 +              case kVK_F8:                            return GHOST_kKeyF8;\r
 +              case kVK_F9:                            return GHOST_kKeyF9;\r
 +              case kVK_F10:                           return GHOST_kKeyF10;\r
 +              case kVK_F11:                           return GHOST_kKeyF11;\r
 +              case kVK_F12:                           return GHOST_kKeyF12;\r
 +              case kVK_F13:                           return GHOST_kKeyF13;\r
 +              case kVK_F14:                           return GHOST_kKeyF14;\r
 +              case kVK_F15:                           return GHOST_kKeyF15;\r
 +              case kVK_F16:                           return GHOST_kKeyF16;\r
 +              case kVK_F17:                           return GHOST_kKeyF17;\r
 +              case kVK_F18:                           return GHOST_kKeyF18;\r
 +              case kVK_F19:                           return GHOST_kKeyF19;\r
 +              case kVK_F20:                           return GHOST_kKeyF20;\r
 +                      \r
 +              case kVK_UpArrow:                       return GHOST_kKeyUpArrow;\r
 +              case kVK_DownArrow:                     return GHOST_kKeyDownArrow;\r
 +              case kVK_LeftArrow:                     return GHOST_kKeyLeftArrow;\r
 +              case kVK_RightArrow:            return GHOST_kKeyRightArrow;\r
 +                      \r
 +              case kVK_Return:                        return GHOST_kKeyEnter;\r
 +              case kVK_Delete:                        return GHOST_kKeyBackSpace;\r
 +              case kVK_ForwardDelete:         return GHOST_kKeyDelete;\r
 +              case kVK_Escape:                        return GHOST_kKeyEsc;\r
 +              case kVK_Tab:                           return GHOST_kKeyTab;\r
 +              case kVK_Space:                         return GHOST_kKeySpace;\r
 +                      \r
 +              case kVK_Home:                          return GHOST_kKeyHome;\r
 +              case kVK_End:                           return GHOST_kKeyEnd;\r
 +              case kVK_PageUp:                        return GHOST_kKeyUpPage;\r
 +              case kVK_PageDown:                      return GHOST_kKeyDownPage;\r
 +                      \r
 +              /*case kVK_ANSI_Minus:          return GHOST_kKeyMinus;\r
 +              case kVK_ANSI_Equal:            return GHOST_kKeyEqual;\r
 +              case kVK_ANSI_Comma:            return GHOST_kKeyComma;\r
 +              case kVK_ANSI_Period:           return GHOST_kKeyPeriod;\r
 +              case kVK_ANSI_Slash:            return GHOST_kKeySlash;\r
 +              case kVK_ANSI_Semicolon:        return GHOST_kKeySemicolon;\r
 +              case kVK_ANSI_Quote:            return GHOST_kKeyQuote;\r
 +              case kVK_ANSI_Backslash:        return GHOST_kKeyBackslash;\r
 +              case kVK_ANSI_LeftBracket:      return GHOST_kKeyLeftBracket;\r
 +              case kVK_ANSI_RightBracket:     return GHOST_kKeyRightBracket;\r
 +              case kVK_ANSI_Grave:            return GHOST_kKeyAccentGrave;*/\r
 +                      \r
 +              case kVK_VolumeUp:\r
 +              case kVK_VolumeDown:\r
 +              case kVK_Mute:\r
 +                      return GHOST_kKeyUnknown;\r
 +                      \r
 +              default:\r
 +                      /*Then detect on character value for "remappable" keys in int'l keyboards*/\r
 +                      if ((recvChar >= 'A') && (recvChar <= 'Z')) {\r
 +                              return (GHOST_TKey) (recvChar - 'A' + GHOST_kKeyA);\r
 +                      } else if ((recvChar >= 'a') && (recvChar <= 'z')) {\r
 +                              return (GHOST_TKey) (recvChar - 'a' + GHOST_kKeyA);\r
 +                      } else\r
 +                      switch (recvChar) {\r
 +                              case '-':       return GHOST_kKeyMinus;\r
 +                              case '=':       return GHOST_kKeyEqual;\r
 +                              case ',':       return GHOST_kKeyComma;\r
 +                              case '.':       return GHOST_kKeyPeriod;\r
 +                              case '/':       return GHOST_kKeySlash;\r
 +                              case ';':       return GHOST_kKeySemicolon;\r
 +                              case '\'':      return GHOST_kKeyQuote;\r
 +                              case '\\':      return GHOST_kKeyBackslash;\r
 +                              case '[':       return GHOST_kKeyLeftBracket;\r
 +                              case ']':       return GHOST_kKeyRightBracket;\r
 +                              case '`':       return GHOST_kKeyAccentGrave;\r
 +                              default:\r
 +                                      return GHOST_kKeyUnknown;\r
 +                      }\r
 +      }\r
 +      return GHOST_kKeyUnknown;\r
 +}\r
 +\r
- /* MacOSX returns a Roman charset with kEventParamKeyMacCharCodes\r
-  * as defined here: http://developer.apple.com/documentation/mac/Text/Text-516.html\r
-  * I am not sure how international this works...\r
-  * For cross-platform convention, we'll use the Latin ascii set instead.\r
-  * As defined at: http://www.ramsch.org/martin/uni/fmi-hp/iso8859-1.html\r
-  * \r
-  */\r
- static unsigned char convertRomanToLatin(unsigned char ascii)\r
- {\r
\r
-       if(ascii<128) return ascii;\r
-       \r
-       switch(ascii) {\r
-       case 128:       return 142;\r
-       case 129:       return 143;\r
-       case 130:       return 128;\r
-       case 131:       return 201;\r
-       case 132:       return 209;\r
-       case 133:       return 214;\r
-       case 134:       return 220;\r
-       case 135:       return 225;\r
-       case 136:       return 224;\r
-       case 137:       return 226;\r
-       case 138:       return 228;\r
-       case 139:       return 227;\r
-       case 140:       return 229;\r
-       case 141:       return 231;\r
-       case 142:       return 233;\r
-       case 143:       return 232;\r
-       case 144:       return 234;\r
-       case 145:       return 235;\r
-       case 146:       return 237;\r
-       case 147:       return 236;\r
-       case 148:       return 238;\r
-       case 149:       return 239;\r
-       case 150:       return 241;\r
-       case 151:       return 243;\r
-       case 152:       return 242;\r
-       case 153:       return 244;\r
-       case 154:       return 246;\r
-       case 155:       return 245;\r
-       case 156:       return 250;\r
-       case 157:       return 249;\r
-       case 158:       return 251;\r
-       case 159:       return 252;\r
-       case 160:       return 0;\r
-       case 161:       return 176;\r
-       case 162:       return 162;\r
-       case 163:       return 163;\r
-       case 164:       return 167;\r
-       case 165:       return 183;\r
-       case 166:       return 182;\r
-       case 167:       return 223;\r
-       case 168:       return 174;\r
-       case 169:       return 169;\r
-       case 170:       return 174;\r
-       case 171:       return 180;\r
-       case 172:       return 168;\r
-       case 173:       return 0;\r
-       case 174:       return 198;\r
-       case 175:       return 216;\r
-       case 176:       return 0;\r
-       case 177:       return 177;\r
-       case 178:       return 0;\r
-       case 179:       return 0;\r
-       case 180:       return 165;\r
-       case 181:       return 181;\r
-       case 182:       return 0;\r
-       case 183:       return 0;\r
-       case 184:       return 215;\r
-       case 185:       return 0;\r
-       case 186:       return 0;\r
-       case 187:       return 170;\r
-       case 188:       return 186;\r
-       case 189:       return 0;\r
-       case 190:       return 230;\r
-       case 191:       return 248;\r
-       case 192:       return 191;\r
-       case 193:       return 161;\r
-       case 194:       return 172;\r
-       case 195:       return 0;\r
-       case 196:       return 0;\r
-       case 197:       return 0;\r
-       case 198:       return 0;\r
-       case 199:       return 171;\r
-       case 200:       return 187;\r
-       case 201:       return 201;\r
-       case 202:       return 0;\r
-       case 203:       return 192;\r
-       case 204:       return 195;\r
-       case 205:       return 213;\r
-       case 206:       return 0;\r
-       case 207:       return 0;\r
-       case 208:       return 0;\r
-       case 209:       return 0;\r
-       case 210:       return 0;\r
-       \r
-       case 214:       return 247;\r
\r
-       case 229:       return 194;\r
-       case 230:       return 202;\r
-       case 231:       return 193;\r
-       case 232:       return 203;\r
-       case 233:       return 200;\r
-       case 234:       return 205;\r
-       case 235:       return 206;\r
-       case 236:       return 207;\r
-       case 237:       return 204;\r
-       case 238:       return 211;\r
-       case 239:       return 212;\r
-       case 240:       return 0;\r
-       case 241:       return 210;\r
-       case 242:       return 218;\r
-       case 243:       return 219;\r
-       case 244:       return 217;\r
-       case 245:       return 0;\r
-       case 246:       return 0;\r
-       case 247:       return 0;\r
-       case 248:       return 0;\r
-       case 249:       return 0;\r
-       case 250:       return 0;\r
\r
-       \r
-               default: return 0;\r
-       }\r
\r
- }\r
 +\r
 +#define FIRSTFILEBUFLG 512\r
 +static bool g_hasFirstFile = false;\r
 +static char g_firstFileBuf[512];\r
 +\r
 +//TODO:Need to investigate this. Function called too early in creator.c to have g_hasFirstFile == true\r
 +extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { \r
 +      if (g_hasFirstFile) {\r
 +              strncpy(buf, g_firstFileBuf, FIRSTFILEBUFLG - 1);\r
 +              buf[FIRSTFILEBUFLG - 1] = '\0';\r
 +              return 1;\r
 +      } else {\r
 +              return 0; \r
 +      }\r
 +}\r
 +\r
 +\r
 +#pragma mark Cocoa objects\r
 +\r
 +/**\r
 + * CocoaAppDelegate\r
 + * ObjC object to capture applicationShouldTerminate, and send quit event\r
 + **/\r
 +@interface CocoaAppDelegate : NSObject {\r
 +      GHOST_SystemCocoa *systemCocoa;\r
 +}\r
  - (void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa;
  - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
 -- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
 -- (void)applicationWillTerminate:(NSNotification *)aNotification;
 -@end
 -
 -@implementation CocoaAppDelegate : NSObject
 --(void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa
 -{
 -      systemCocoa = sysCocoa;
 -}
 -
 +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;\r
 +- (void)applicationWillTerminate:(NSNotification *)aNotification;\r
 +@end\r
 +\r
 +@implementation CocoaAppDelegate : NSObject\r
 +-(void)setSystemCocoa:(GHOST_SystemCocoa *)sysCocoa\r
 +{\r
 +      systemCocoa = sysCocoa;\r
 +}\r
 +\r
  - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
  {
        NSLog(@"\nGet open file event from cocoa : %@",filename);
@@@ -824,206 -697,206 +697,206 @@@ GHOST_TSuccess GHOST_SystemCocoa::setCu
        xf -= screenRect.origin.x;
        yf -= screenRect.origin.y;
        
 -      //Quartz Display Services uses the old coordinates (top left origin)
 +      //Quartz Display Services uses the old coordinates (top left origin)\r
        yf = screenRect.size.height -yf;
 -
 +\r
-       CGDisplayMoveCursorToPoint([[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
+       CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
  
 -    return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
 -{
 -      unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
 -      //Direct query to modifierFlags can be used in 10.6
 -
 -    keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
 -    keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
 -    keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
 -    keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
 -      
 -    return GHOST_kSuccess;
 -}
 -
 -GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons& buttons) const
 -{
 -      buttons.clear();
 -    buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft);
 -      buttons.set(GHOST_kButtonMaskRight, m_pressedMouseButtons & GHOST_kButtonMaskRight);
 -      buttons.set(GHOST_kButtonMaskMiddle, m_pressedMouseButtons & GHOST_kButtonMaskMiddle);
 -      buttons.set(GHOST_kButtonMaskButton4, m_pressedMouseButtons & GHOST_kButtonMaskButton4);
 -      buttons.set(GHOST_kButtonMaskButton5, m_pressedMouseButtons & GHOST_kButtonMaskButton5);
 -    return GHOST_kSuccess;
 -}
 -
 -
 -
 -#pragma mark Event handlers
 -
 -/**
 - * The event queue polling function
 - */
 -bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
 -{
 -      bool anyProcessed = false;
 -      NSEvent *event;
 -      
 -      //      SetMouseCoalescingEnabled(false, NULL);
 -      //TODO : implement timer ??
 -      
 -      /*do {
 -              GHOST_TimerManager* timerMgr = getTimerManager();
 -              
 -               if (waitForEvent) {
 -               GHOST_TUns64 next = timerMgr->nextFireTime();
 -               double timeOut;
 -               
 -               if (next == GHOST_kFireTimeNever) {
 -               timeOut = kEventDurationForever;
 -               } else {
 -               timeOut = (double)(next - getMilliSeconds())/1000.0;
 -               if (timeOut < 0.0)
 -               timeOut = 0.0;
 -               }
 -               
 -               ::ReceiveNextEvent(0, NULL, timeOut, false, &event);
 -               }
 -               
 -               if (timerMgr->fireTimers(getMilliSeconds())) {
 -               anyProcessed = true;
 -               }*/
 -              
 -              do {
 -                      NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
 -                      event = [NSApp nextEventMatchingMask:NSAnyEventMask
 -                                                                         untilDate:[NSDate distantPast]
 -                                                                                inMode:NSDefaultRunLoopMode
 -                                                                               dequeue:YES];
 -                      if (event==nil) {
 -                              [pool drain];
 -                              break;
 -                      }
 -                      
 -                      anyProcessed = true;
 -                      
 -                      switch ([event type]) {
 -                              case NSKeyDown:
 -                              case NSKeyUp:
 -                              case NSFlagsChanged:
 -                                      handleKeyEvent(event);
 -                                      
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const\r
 +{\r
 +      unsigned int modifiers = [[NSApp currentEvent] modifierFlags];\r
 +      //Direct query to modifierFlags can be used in 10.6\r
 +\r
 +    keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);\r
 +    keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);\r
 +    keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);\r
 +    keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);\r
 +      \r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons& buttons) const\r
 +{\r
 +      buttons.clear();\r
 +    buttons.set(GHOST_kButtonMaskLeft, m_pressedMouseButtons & GHOST_kButtonMaskLeft);\r
 +      buttons.set(GHOST_kButtonMaskRight, m_pressedMouseButtons & GHOST_kButtonMaskRight);\r
 +      buttons.set(GHOST_kButtonMaskMiddle, m_pressedMouseButtons & GHOST_kButtonMaskMiddle);\r
 +      buttons.set(GHOST_kButtonMaskButton4, m_pressedMouseButtons & GHOST_kButtonMaskButton4);\r
 +      buttons.set(GHOST_kButtonMaskButton5, m_pressedMouseButtons & GHOST_kButtonMaskButton5);\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +\r
 +#pragma mark Event handlers\r
 +\r
 +/**\r
 + * The event queue polling function\r
 + */\r
 +bool GHOST_SystemCocoa::processEvents(bool waitForEvent)\r
 +{\r
 +      bool anyProcessed = false;\r
 +      NSEvent *event;\r
 +      \r
 +      //      SetMouseCoalescingEnabled(false, NULL);\r
 +      //TODO : implement timer ??\r
 +      \r
 +      /*do {\r
 +              GHOST_TimerManager* timerMgr = getTimerManager();\r
 +              \r
 +               if (waitForEvent) {\r
 +               GHOST_TUns64 next = timerMgr->nextFireTime();\r
 +               double timeOut;\r
 +               \r
 +               if (next == GHOST_kFireTimeNever) {\r
 +               timeOut = kEventDurationForever;\r
 +               } else {\r
 +               timeOut = (double)(next - getMilliSeconds())/1000.0;\r
 +               if (timeOut < 0.0)\r
 +               timeOut = 0.0;\r
 +               }\r
 +               \r
 +               ::ReceiveNextEvent(0, NULL, timeOut, false, &event);\r
 +               }\r
 +               \r
 +               if (timerMgr->fireTimers(getMilliSeconds())) {\r
 +               anyProcessed = true;\r
 +               }*/\r
 +              \r
 +              do {\r
 +                      NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];\r
 +                      event = [NSApp nextEventMatchingMask:NSAnyEventMask\r
 +                                                                         untilDate:[NSDate distantPast]\r
 +                                                                                inMode:NSDefaultRunLoopMode\r
 +                                                                               dequeue:YES];\r
 +                      if (event==nil) {\r
 +                              [pool drain];\r
 +                              break;\r
 +                      }\r
 +                      \r
 +                      anyProcessed = true;\r
 +                      \r
 +                      switch ([event type]) {\r
 +                              case NSKeyDown:\r
 +                              case NSKeyUp:\r
 +                              case NSFlagsChanged:\r
 +                                      handleKeyEvent(event);\r
 +                                      \r
-                                       /* Support system-wide keyboard shortcuts, like Exposé, ...) =>included in always NSApp sendEvent */\r
+                                       /* Support system-wide keyboard shortcuts, like Expos√©, ...) =>included in always NSApp sendEvent */
 -                                      /*              if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) {
 -                                       [NSApp sendEvent:event];
 -                                       }*/
 -                                      break;
 -                                      
 -                              case NSLeftMouseDown:
 -                              case NSLeftMouseUp:
 -                              case NSRightMouseDown:
 -                              case NSRightMouseUp:
 -                              case NSMouseMoved:
 -                              case NSLeftMouseDragged:
 -                              case NSRightMouseDragged:
 -                              case NSScrollWheel:
 -                              case NSOtherMouseDown:
 -                              case NSOtherMouseUp:
 -                              case NSOtherMouseDragged:                               
 -                                      handleMouseEvent(event);
 -                                      break;
 -                                      
 -                              case NSTabletPoint:
 -                              case NSTabletProximity:
 -                                      handleTabletEvent(event,[event type]);
 -                                      break;
 -                                      
 -                                      /* Trackpad features, will need OS X 10.6 for implementation
 -                                       case NSEventTypeGesture:
 -                                       case NSEventTypeMagnify:
 -                                       case NSEventTypeSwipe:
 -                                       case NSEventTypeRotate:
 -                                       case NSEventTypeBeginGesture:
 -                                       case NSEventTypeEndGesture:
 -                                       break; */
 -                                      
 -                                      /*Unused events
 -                                       NSMouseEntered       = 8,
 -                                       NSMouseExited        = 9,
 -                                       NSAppKitDefined      = 13,
 -                                       NSSystemDefined      = 14,
 -                                       NSApplicationDefined = 15,
 -                                       NSPeriodic           = 16,
 -                                       NSCursorUpdate       = 17,*/
 -                                      
 -                              default:
 -                                      break;
 -                      }
 -                      //Resend event to NSApp to ensure Mac wide events are handled
 -                      [NSApp sendEvent:event];
 -                      [pool drain];
 -              } while (event!= nil);          
 -      //} while (waitForEvent && !anyProcessed); Needed only for timer implementation
 -      
 -      
 -      
 -    return anyProcessed;
 -}
 -
 -//Note: called from NSWindow delegate
 -GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)
 -{
 -      if (!validWindow(window)) {
 -              return GHOST_kFailure;
 -      }
 -              switch(eventType) 
 -              {
 -                      case GHOST_kEventWindowClose:
 -                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window) );
 -                              break;
 -                      case GHOST_kEventWindowActivate:
 -                              m_windowManager->setActiveWindow(window);
 -                              window->loadCursor(window->getCursorVisibility(), window->getCursorShape());
 -                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window) );
 -                              break;
 -                      case GHOST_kEventWindowDeactivate:
 -                              m_windowManager->setWindowInactive(window);
 -                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window) );
 -                              break;
 -                      case GHOST_kEventWindowUpdate:
 -                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) );
 -                              break;
 -                      case GHOST_kEventWindowSize:
 -                              if (!m_ignoreWindowSizedMessages)
 -                              {
 -                                      window->updateDrawingContext();
 -                                      pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) );
 -                              }
 -                              break;
 -                      default:
 -                              return GHOST_kFailure;
 -                              break;
 -              }
 -      return GHOST_kSuccess;
 -}
 -
 -GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()
 -{
 +                                      /*              if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) {\r
 +                                       [NSApp sendEvent:event];\r
 +                                       }*/\r
 +                                      break;\r
 +                                      \r
 +                              case NSLeftMouseDown:\r
 +                              case NSLeftMouseUp:\r
 +                              case NSRightMouseDown:\r
 +                              case NSRightMouseUp:\r
 +                              case NSMouseMoved:\r
 +                              case NSLeftMouseDragged:\r
 +                              case NSRightMouseDragged:\r
 +                              case NSScrollWheel:\r
 +                              case NSOtherMouseDown:\r
 +                              case NSOtherMouseUp:\r
 +                              case NSOtherMouseDragged:                               \r
 +                                      handleMouseEvent(event);\r
 +                                      break;\r
 +                                      \r
 +                              case NSTabletPoint:\r
 +                              case NSTabletProximity:\r
 +                                      handleTabletEvent(event,[event type]);\r
 +                                      break;\r
 +                                      \r
 +                                      /* Trackpad features, will need OS X 10.6 for implementation\r
 +                                       case NSEventTypeGesture:\r
 +                                       case NSEventTypeMagnify:\r
 +                                       case NSEventTypeSwipe:\r
 +                                       case NSEventTypeRotate:\r
 +                                       case NSEventTypeBeginGesture:\r
 +                                       case NSEventTypeEndGesture:\r
 +                                       break; */\r
 +                                      \r
 +                                      /*Unused events\r
 +                                       NSMouseEntered       = 8,\r
 +                                       NSMouseExited        = 9,\r
 +                                       NSAppKitDefined      = 13,\r
 +                                       NSSystemDefined      = 14,\r
 +                                       NSApplicationDefined = 15,\r
 +                                       NSPeriodic           = 16,\r
 +                                       NSCursorUpdate       = 17,*/\r
 +                                      \r
 +                              default:\r
 +                                      break;\r
 +                      }\r
 +                      //Resend event to NSApp to ensure Mac wide events are handled\r
 +                      [NSApp sendEvent:event];\r
 +                      [pool drain];\r
 +              } while (event!= nil);          \r
 +      //} while (waitForEvent && !anyProcessed); Needed only for timer implementation\r
 +      \r
 +      \r
 +      \r
 +    return anyProcessed;\r
 +}\r
 +\r
 +//Note: called from NSWindow delegate\r
 +GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)\r
 +{\r
 +      if (!validWindow(window)) {\r
 +              return GHOST_kFailure;\r
 +      }\r
 +              switch(eventType) \r
 +              {\r
 +                      case GHOST_kEventWindowClose:\r
 +                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window) );\r
 +                              break;\r
 +                      case GHOST_kEventWindowActivate:\r
 +                              m_windowManager->setActiveWindow(window);\r
 +                              window->loadCursor(window->getCursorVisibility(), window->getCursorShape());\r
 +                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window) );\r
 +                              break;\r
 +                      case GHOST_kEventWindowDeactivate:\r
 +                              m_windowManager->setWindowInactive(window);\r
 +                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window) );\r
 +                              break;\r
 +                      case GHOST_kEventWindowUpdate:\r
 +                              pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) );\r
 +                              break;\r
 +                      case GHOST_kEventWindowSize:\r
 +                              if (!m_ignoreWindowSizedMessages)\r
 +                              {\r
 +                                      window->updateDrawingContext();\r
 +                                      pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) );\r
 +                              }\r
 +                              break;\r
 +                      default:\r
 +                              return GHOST_kFailure;\r
 +                              break;\r
 +              }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()\r
 +{\r
        GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();
        
        //Discard quit event if we are in cursor grab sequence
        if (window && (window->getCursorGrabMode() != GHOST_kGrabDisable) && (window->getCursorGrabMode() != GHOST_kGrabNormal))
                return GHOST_kExitCancel;
        
 -      //Check open windows if some changes are not saved
 -      if (m_windowManager->getAnyModifiedState())
 -      {
 +      //Check open windows if some changes are not saved\r
 +      if (m_windowManager->getAnyModifiedState())\r
 +      {\r
-               int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved. Do you really want to quit ?",\r
-                                                                                @"Cancel", @"Quit anyway", nil);\r
+               int shouldQuit = NSRunAlertPanel(@"Exit Blender", @"Some changes have not been saved.\nDo you really want to quit ?",
+                                                                                @"Cancel", @"Quit Anyway", nil);
 -              if (shouldQuit == NSAlertAlternateReturn)
 -              {
 -                      pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );
 -                      return GHOST_kExitNow;
 +              if (shouldQuit == NSAlertAlternateReturn)\r
 +              {\r
 +                      pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL) );\r
 +                      return GHOST_kExitNow;\r
                } else {
                        //Give back focus to the blender window if user selected cancel quit
                        NSArray *windowsList = [NSApp orderedWindows];
@@@ -1225,178 -1098,189 +1098,189 @@@ GHOST_TSuccess GHOST_SystemCocoa::handl
                                                m_cursorDelta_y=0; //Mouse motion occured between two cursor warps, so we can reset the delta counter
                                        }
                                                break;
 -                              }
 -                              break;
 -                      
 -              case NSScrollWheel:
 -                      {
 -                              GHOST_TInt32 delta;
 -                              
 -                              double deltaF = [event deltaY];
 -                              if (deltaF == 0.0) break; //discard trackpad delta=0 events
 -                              
 -                              delta = deltaF > 0.0 ? 1 : -1;
 -                              pushEvent(new GHOST_EventWheel([event timestamp], window, delta));
 -                      }
 -                      break;
 -                      
 -              default:
 -                      return GHOST_kFailure;
 -                      break;
 -              }
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
 -{
 -      NSEvent *event = (NSEvent *)eventPtr;
 -      GHOST_IWindow* window = m_windowManager->getActiveWindow();
 -      unsigned int modifiers;
 -      NSString *characters;
 +                              }\r
 +                              break;\r
 +                      \r
 +              case NSScrollWheel:\r
 +                      {\r
 +                              GHOST_TInt32 delta;\r
 +                              \r
 +                              double deltaF = [event deltaY];\r
 +                              if (deltaF == 0.0) break; //discard trackpad delta=0 events\r
 +                              \r
 +                              delta = deltaF > 0.0 ? 1 : -1;\r
 +                              pushEvent(new GHOST_EventWheel([event timestamp], window, delta));\r
 +                      }\r
 +                      break;\r
 +                      \r
 +              default:\r
 +                      return GHOST_kFailure;\r
 +                      break;\r
 +              }\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)\r
 +{\r
 +      NSEvent *event = (NSEvent *)eventPtr;\r
 +      GHOST_IWindow* window = m_windowManager->getActiveWindow();\r
 +      unsigned int modifiers;\r
 +      NSString *characters;\r
+       NSData *convertedCharacters;
 -      GHOST_TKey keyCode;
 -      unsigned char ascii;
 +      GHOST_TKey keyCode;\r
 +      unsigned char ascii;\r
+       NSString* charsIgnoringModifiers;
 -
 -      /* Can happen, very rarely - seems to only be when command-H makes
 -       * the window go away and we still get an HKey up. 
 -       */
 -      if (!window) {
 -              printf("\nW failure");
 -              return GHOST_kFailure;
 -      }
 -      
 -      switch ([event type]) {
 -              case NSKeyDown:
 -              case NSKeyUp:
 +\r
 +      /* Can happen, very rarely - seems to only be when command-H makes\r
 +       * the window go away and we still get an HKey up. \r
 +       */\r
 +      if (!window) {\r
 +              printf("\nW failure");\r
 +              return GHOST_kFailure;\r
 +      }\r
 +      \r
 +      switch ([event type]) {\r
 +              case NSKeyDown:\r
 +              case NSKeyUp:\r
-                       characters = [event characters];\r
-                       if ([characters length]) { //Check for dead keys\r
+                       charsIgnoringModifiers = [event charactersIgnoringModifiers];
+                       if ([charsIgnoringModifiers length]>0)
 -                              keyCode = convertKey([event keyCode],
 +                              keyCode = convertKey([event keyCode],\r
-                                                                        [[event charactersIgnoringModifiers] characterAtIndex:0]);\r
-                               ascii= convertRomanToLatin((char)[characters characterAtIndex:0]);\r
-                       } else {\r
+                                                                        [charsIgnoringModifiers characterAtIndex:0]);
+                       else
 -                              keyCode = convertKey([event keyCode],0);
 +                              keyCode = convertKey([event keyCode],0);\r
-                               ascii= 0;\r
+                               
+                       characters = [event characters];
+                       if ([characters length]>0) { //Check for dead keys
+                               //Convert characters to iso latin 1 encoding
+                               convertedCharacters = [characters dataUsingEncoding:NSISOLatin1StringEncoding];
+                               if ([convertedCharacters length]>0)
+                                       ascii =((char*)[convertedCharacters bytes])[0];
+                               else
+                                       ascii = 0; //Character not available in iso latin 1 encoding
 -                      }
 +                      }\r
-                       \r
+                       else
+                               ascii= 0;
 -                      
 -                      if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))
 -                              break; //Cmd-Q is directly handled by Cocoa
 -
 -                      if ([event type] == NSKeyDown) {
 -                              pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyDown, window, keyCode, ascii) );
 -                              //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);
 -                      } else {
 -                              pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyUp, window, keyCode, ascii) );
 -                      }
 -                      break;
 -      
 -              case NSFlagsChanged: 
 -                      modifiers = [event modifierFlags];
 -                      if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {
 -                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );
 -                      }
 -                      if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {
 -                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );
 -                      }
 -                      if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {
 -                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );
 -                      }
 -                      if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {
 -                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );
 -                      }
 -                      
 -                      m_modifierMask = modifiers;
 -                      break;
 -                      
 -              default:
 -                      return GHOST_kFailure;
 -                      break;
 -      }
 -      
 -      return GHOST_kSuccess;
 -}
 -
 -
 -
 -#pragma mark Clipboard get/set
 -
 -GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
 -{
 -      GHOST_TUns8 * temp_buff;
 -      size_t pastedTextSize;  
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
 -      
 -      if (pasteBoard == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 -      NSArray *supportedTypes =
 -              [NSArray arrayWithObjects: @"public.utf8-plain-text", nil];
 -      
 -      NSString *bestType = [[NSPasteboard generalPasteboard]
 -                                                availableTypeFromArray:supportedTypes];
 -      
 -      if (bestType == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 -      NSString * textPasted = [pasteBoard stringForType:@"public.utf8-plain-text"];
 -
 -      if (textPasted == nil) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 -      pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
 -      
 -      temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
 -
 -      if (temp_buff == NULL) {
 -              [pool drain];
 -              return NULL;
 -      }
 -      
 -      strncpy((char*)temp_buff, [textPasted UTF8String], pastedTextSize);
 -      
 -      temp_buff[pastedTextSize] = '\0';
 -      
 -      [pool drain];
 -
 -      if(temp_buff) {
 -              return temp_buff;
 -      } else {
 -              return NULL;
 -      }
 -}
 -
 -void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
 -{
 -      NSString *textToCopy;
 -      
 -      if(selection) {return;} // for copying the selection, used on X11
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -              
 -      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
 -      
 -      if (pasteBoard == nil) {
 -              [pool drain];
 -              return;
 -      }
 -      
 -      NSArray *supportedTypes = [NSArray arrayWithObject:@"public.utf8-plain-text"];
 -      
 -      [pasteBoard declareTypes:supportedTypes owner:nil];
 -      
 -      textToCopy = [NSString stringWithUTF8String:buffer];
 -      
 -      [pasteBoard setString:textToCopy forType:@"public.utf8-plain-text"];
 -      
 -      [pool drain];
 -}
 +                      \r
 +                      if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSCommandKeyMask))\r
 +                              break; //Cmd-Q is directly handled by Cocoa\r
 +\r
 +                      if ([event type] == NSKeyDown) {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyDown, window, keyCode, ascii) );\r
 +                              //printf("\nKey pressed keyCode=%u ascii=%i %c",keyCode,ascii,ascii);\r
 +                      } else {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], GHOST_kEventKeyUp, window, keyCode, ascii) );\r
 +                      }\r
 +                      break;\r
 +      \r
 +              case NSFlagsChanged: \r
 +                      modifiers = [event modifierFlags];\r
 +                      if ((modifiers & NSShiftKeyMask) != (m_modifierMask & NSShiftKeyMask)) {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSShiftKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) );\r
 +                      }\r
 +                      if ((modifiers & NSControlKeyMask) != (m_modifierMask & NSControlKeyMask)) {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSControlKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) );\r
 +                      }\r
 +                      if ((modifiers & NSAlternateKeyMask) != (m_modifierMask & NSAlternateKeyMask)) {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSAlternateKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) );\r
 +                      }\r
 +                      if ((modifiers & NSCommandKeyMask) != (m_modifierMask & NSCommandKeyMask)) {\r
 +                              pushEvent( new GHOST_EventKey([event timestamp], (modifiers & NSCommandKeyMask)?GHOST_kEventKeyDown:GHOST_kEventKeyUp, window, GHOST_kKeyCommand) );\r
 +                      }\r
 +                      \r
 +                      m_modifierMask = modifiers;\r
 +                      break;\r
 +                      \r
 +              default:\r
 +                      return GHOST_kFailure;\r
 +                      break;\r
 +      }\r
 +      \r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +\r
 +#pragma mark Clipboard get/set\r
 +\r
 +GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const\r
 +{\r
 +      GHOST_TUns8 * temp_buff;\r
 +      size_t pastedTextSize;  \r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
 +      \r
 +      if (pasteBoard == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
 +      NSArray *supportedTypes =\r
 +              [NSArray arrayWithObjects: @"public.utf8-plain-text", nil];\r
 +      \r
 +      NSString *bestType = [[NSPasteboard generalPasteboard]\r
 +                                                availableTypeFromArray:supportedTypes];\r
 +      \r
 +      if (bestType == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
 +      NSString * textPasted = [pasteBoard stringForType:@"public.utf8-plain-text"];\r
 +\r
 +      if (textPasted == nil) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
 +      pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];\r
 +      \r
 +      temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); \r
 +\r
 +      if (temp_buff == NULL) {\r
 +              [pool drain];\r
 +              return NULL;\r
 +      }\r
 +      \r
 +      strncpy((char*)temp_buff, [textPasted UTF8String], pastedTextSize);\r
 +      \r
 +      temp_buff[pastedTextSize] = '\0';\r
 +      \r
 +      [pool drain];\r
 +\r
 +      if(temp_buff) {\r
 +              return temp_buff;\r
 +      } else {\r
 +              return NULL;\r
 +      }\r
 +}\r
 +\r
 +void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const\r
 +{\r
 +      NSString *textToCopy;\r
 +      \r
 +      if(selection) {return;} // for copying the selection, used on X11\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +              \r
 +      NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];\r
 +      \r
 +      if (pasteBoard == nil) {\r
 +              [pool drain];\r
 +              return;\r
 +      }\r
 +      \r
 +      NSArray *supportedTypes = [NSArray arrayWithObject:@"public.utf8-plain-text"];\r
 +      \r
 +      [pasteBoard declareTypes:supportedTypes owner:nil];\r
 +      \r
 +      textToCopy = [NSString stringWithUTF8String:buffer];\r
 +      \r
 +      [pasteBoard setString:textToCopy forType:@"public.utf8-plain-text"];\r
 +      \r
 +      [pool drain];\r
 +}\r
index aac12e80893c0c97bade3d86d10e5d29724dfb8c,f0bc8dd4d0f8de6b41ba2808520313eff7ff92b2..9613ee64ef4eda5ca7394a76f52d5832bc814a9e
  #include <OpenGL/OpenGL.h>
  */
   
 -#include "GHOST_WindowCocoa.h"
 -#include "GHOST_SystemCocoa.h"
 -#include "GHOST_Debug.h"
 -
 -
 -#pragma mark Cocoa window delegate object
 +#include "GHOST_WindowCocoa.h"\r
 +#include "GHOST_SystemCocoa.h"\r
 +#include "GHOST_Debug.h"\r
 +\r
 +\r
- // Pixel Format Attributes for the windowed NSOpenGLContext\r
- static NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[] =\r
- {\r
-       NSOpenGLPFADoubleBuffer,\r
-       NSOpenGLPFAAccelerated,\r
-       //NSOpenGLPFAAllowOfflineRenderers,   // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway\r
-       NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) 32,\r
-       (NSOpenGLPixelFormatAttribute) 0\r
- };\r
\r
 +#pragma mark Cocoa window delegate object\r
  /* live resize ugly patch
  extern "C" {
        struct bContext;
  #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)windowDidUpdate:(NSNotification *)notification;\r
+ - (void)windowDidExpose:(NSNotification *)notification;
 -- (void)windowDidResize:(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);
 -}
 -
 +- (void)windowDidResize:(NSNotification *)notification;\r
 +@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
-       //The window is no more key when its own view becomes fullscreen\r
-       //but ghost doesn't know the view/window difference, so hide this fact\r
-       if (associatedWindow->getState() != GHOST_kWindowStateFullScreen)\r
 +              systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);\r
 +}\r
 +\r
- - (void)windowDidUpdate:(NSNotification *)notification\r
+ - (void)windowDidExpose:(NSNotification *)notification
 -{
 -      systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
 -}
 -
 -- (void)windowDidResize:(NSNotification *)notification
 -{
 +{\r
 +      systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);\r
 +}\r
 +\r
 +- (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)
                wm_event_do_notifiers(ghostC);
                wm_draw_update(ghostC);
        }*/
 -}
 -@end
 -
 -#pragma mark NSWindow subclass
 -//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)
 -@interface CocoaWindow: NSWindow
 -{
 -
 -}
 -@end
 -@implementation CocoaWindow
 -
 --(BOOL)canBecomeKeyWindow
 -{
 -      return YES;
 -}
 -
 -@end
 -
 -
 -
 -#pragma mark NSOpenGLView subclass
 -//We need to subclass it in order to give Cocoa the feeling key events are trapped
 -@interface CocoaOpenGLView : NSOpenGLView
 -{
 -}
 -@end
 -@implementation CocoaOpenGLView
 -
 -- (BOOL)acceptsFirstResponder
 -{
 -    return YES;
 -}
 -
 -//The trick to prevent Cocoa from complaining (beeping)
 -- (void)keyDown:(NSEvent *)theEvent
 -{}
 -
 -- (BOOL)isOpaque
 -{
 -    return YES;
 -}
 -
 -@end
 -
 -
 -#pragma mark initialization / finalization
 -
 -NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
 -
 -GHOST_WindowCocoa::GHOST_WindowCocoa(
 -      GHOST_SystemCocoa *systemCocoa,
 -      const STR_String& title,
 -      GHOST_TInt32 left,
 -      GHOST_TInt32 top,
 -      GHOST_TUns32 width,
 -      GHOST_TUns32 height,
 -      GHOST_TWindowState state,
 -      GHOST_TDrawingContextType type,
 -      const bool stereoVisual
 -) :
 +}\r
 +@end\r
 +\r
 +#pragma mark NSWindow subclass\r
 +//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)\r
 +@interface CocoaWindow: NSWindow\r
 +{\r
 +\r
 +}\r
 +@end\r
 +@implementation CocoaWindow\r
 +\r
 +-(BOOL)canBecomeKeyWindow\r
 +{\r
 +      return YES;\r
 +}\r
 +\r
 +@end\r
 +\r
 +\r
 +\r
 +#pragma mark NSOpenGLView subclass\r
 +//We need to subclass it in order to give Cocoa the feeling key events are trapped\r
 +@interface CocoaOpenGLView : NSOpenGLView\r
 +{\r
 +}\r
 +@end\r
 +@implementation CocoaOpenGLView\r
 +\r
 +- (BOOL)acceptsFirstResponder\r
 +{\r
 +    return YES;\r
 +}\r
 +\r
 +//The trick to prevent Cocoa from complaining (beeping)\r
 +- (void)keyDown:(NSEvent *)theEvent\r
 +{}\r
 +\r
 +- (BOOL)isOpaque\r
 +{\r
 +    return YES;\r
 +}\r
 +\r
 +@end\r
 +\r
 +\r
 +#pragma mark initialization / finalization\r
 +\r
 +NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;\r
 +\r
 +GHOST_WindowCocoa::GHOST_WindowCocoa(\r
 +      GHOST_SystemCocoa *systemCocoa,\r
 +      const STR_String& title,\r
 +      GHOST_TInt32 left,\r
 +      GHOST_TInt32 top,\r
 +      GHOST_TUns32 width,\r
 +      GHOST_TUns32 height,\r
 +      GHOST_TWindowState state,\r
 +      GHOST_TDrawingContextType type,\r
 +      const bool stereoVisual\r
 +) :\r
-       GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone),\r
+       GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual),
 -      m_customCursor(0)
 -{
 +      m_customCursor(0)\r
 +{\r
+       NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
+       int i;
+       
 -      m_systemCocoa = systemCocoa;
 -      m_fullScreen = false;
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -
 -      //Creates the window
 -      NSRect rect;
 +      m_systemCocoa = systemCocoa;\r
 +      m_fullScreen = false;\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +\r
 +      //Creates the window\r
 +      NSRect rect;\r
        NSSize  minSize;
 -      
 -      rect.origin.x = left;
 -      rect.origin.y = top;
 -      rect.size.width = width;
 -      rect.size.height = height;
 -      
 -      m_window = [[CocoaWindow alloc] initWithContentRect:rect
 -                                                                                 styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
 -                                                                                       backing:NSBackingStoreBuffered defer:NO];
 -      if (m_window == nil) {
 -              [pool drain];
 -              return;
 -      }
 -      
 +      \r
 +      rect.origin.x = left;\r
 +      rect.origin.y = top;\r
 +      rect.size.width = width;\r
 +      rect.size.height = height;\r
 +      \r
 +      m_window = [[CocoaWindow alloc] initWithContentRect:rect\r
 +                                                                                 styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask\r
 +                                                                                       backing:NSBackingStoreBuffered defer:NO];\r
 +      if (m_window == nil) {\r
 +              [pool drain];\r
 +              return;\r
 +      }\r
 +      \r
        //Forbid to resize the window below the blender defined minimum one
        minSize.width = 320;
        minSize.height = 240;
        [m_window setContentMinSize:minSize];
        
 -      setTitle(title);
 -      
 -      
 +      setTitle(title);\r
 +      \r
 +                      \r
+       // Pixel Format Attributes for the windowed NSOpenGLContext
+       i=0;
+       pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
+       pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
+       //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,;   // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
+       
+       pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
+       pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
+       
+       if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
+       
+       pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
+       
 -      //Creates the OpenGL View inside the window
 -      NSOpenGLPixelFormat *pixelFormat =
 -      [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
 -      
 -      m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
 -                                                                                               pixelFormat:pixelFormat];
 -      
 -      [pixelFormat release];
 -      
 -      m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
 -      
 -      [m_window setContentView:m_openGLView];
 -      [m_window setInitialFirstResponder:m_openGLView];
 -      
 -      [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window
 -      
 -      [m_window makeKeyAndOrderFront:nil];
 -      
 -      setDrawingContextType(type);
 -      updateDrawingContext();
 -      activateDrawingContext();
 -      
 -      m_tablet.Active = GHOST_kTabletModeNone;
 -      
 -      CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
 -      [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
 -      [m_window setDelegate:windowDelegate];
 -      
 -      [m_window setAcceptsMouseMovedEvents:YES];
 -      
 -      if (state == GHOST_kWindowStateFullScreen)
 -              setState(GHOST_kWindowStateFullScreen);
 -              
 -      [pool drain];
 -}
 -
 -
 -GHOST_WindowCocoa::~GHOST_WindowCocoa()
 -{
 -      if (m_customCursor) delete m_customCursor;
 -
 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      [m_openGLView release];
 -      
 -      if (m_window) {
 -              [m_window close];
 -              [[m_window delegate] release];
 -              [m_window release];
 -              m_window = nil;
 -      }
 -      
 -      //Check for other blender opened windows and make the frontmost key
 -      NSArray *windowsList = [NSApp orderedWindows];
 -      if ([windowsList count]) {
 -              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
 -      }
 -      [pool drain];
 -}
 -
 -#pragma mark accessors
 -
 -bool GHOST_WindowCocoa::getValid() const
 -{
 -    bool valid;
 -    if (!m_fullScreen) {
 -        valid = (m_window != 0); //&& ::IsValidWindowPtr(m_windowRef);
 -    }
 -    else {
 -        valid = true;
 -    }
 -    return valid;
 -}
 -
 -
 -void GHOST_WindowCocoa::setTitle(const STR_String& title)
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];
 -      
 -      //Set associated file if applicable
 -      if ([windowTitle hasPrefix:@"Blender"])
 -      {
 -              NSRange fileStrRange;
 -              NSString *associatedFileName;
 -              int len;
 -              
 -              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;
 -              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
 -      
 -              if (len >0)
 -              {
 -                      fileStrRange.length = len;
 -                      associatedFileName = [windowTitle substringWithRange:fileStrRange];
 -                      @try {
 -                              [m_window setRepresentedFilename:associatedFileName];
 -                      }
 -                      @catch (NSException * e) {
 -                              printf("\nInvalid file path given in window title");
 -                      }
 -                      [m_window setTitle:[associatedFileName lastPathComponent]];
 -              }
 -              else {
 -                      [m_window setTitle:windowTitle];
 -                      [m_window setRepresentedFilename:@""];
 -              }
 -
 -      } else {
 -              [m_window setTitle:windowTitle];
 -              [m_window setRepresentedFilename:@""];
 -      }
 -
 -      
 -      [windowTitle release];
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getTitle(STR_String& title) const
 -{
 -    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -
 -      NSString *windowTitle = [m_window title];
 -
 -      if (windowTitle != nil) {
 -              title = [windowTitle UTF8String];               
 -      }
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")
 -
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -      rect = [m_window frame];
 -
 -      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);
 -      bounds.m_l = rect.origin.x -screenSize.origin.x;
 -      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;
 -      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);
 -      
 -      [pool drain];
 -}
 -
 -
 -void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
 -{
 -      NSRect rect;
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      if (!m_fullScreen)
 -      {
 -              NSRect screenSize = [[m_window screen] visibleFrame];
 -
 -              //Max window contents as screen size (excluding title bar...)
 -              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
 -                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -
 -              rect = [m_window contentRectForFrameRect:[m_window frame]];
 -              
 -              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);
 -              bounds.m_l = rect.origin.x -contentRect.origin.x;
 -              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;
 -              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);
 -      }
 -      else {
 -              NSRect screenSize = [[m_window screen] frame];
 -              
 -              bounds.m_b = screenSize.origin.y + screenSize.size.height;
 -              bounds.m_l = screenSize.origin.x;
 -              bounds.m_r = screenSize.origin.x + screenSize.size.width;
 -              bounds.m_t = screenSize.origin.y;
 -      }
 -      [pool drain];
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getWidth()) != width) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=cBnds.getHeight();
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if (((GHOST_TUns32)cBnds.getHeight()) != height) {
 -              NSSize size;
 -              size.width=cBnds.getWidth();
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")
 -      GHOST_Rect cBnds, wBnds;
 -      getClientBounds(cBnds);
 -      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
 -          (((GHOST_TUns32)cBnds.getHeight()) != height)) {
 -              NSSize size;
 -              size.width=width;
 -              size.height=height;
 -              [m_window setContentSize:size];
 -      }
 -      return GHOST_kSuccess;
 -}
 -
 -
 -GHOST_TWindowState GHOST_WindowCocoa::getState() const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      GHOST_TWindowState state;
 -      if (m_fullScreen) {
 -              state = GHOST_kWindowStateFullScreen;
 -      } 
 -      else if ([m_window isMiniaturized]) {
 -              state = GHOST_kWindowStateMinimized;
 -      }
 -      else if ([m_window isZoomed]) {
 -              state = GHOST_kWindowStateMaximized;
 -      }
 -      else {
 -              state = GHOST_kWindowStateNormal;
 -      }
 -      [pool drain];
 -      return state;
 -}
 -
 -
 -void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      screenCoord.x = inX;
 -      screenCoord.y = inY;
 -      
 -      baseCoord = [m_window convertScreenToBase:screenCoord];
 -      
 -      outX = baseCoord.x;
 -      outY = baseCoord.y;
 -}
 -
 -
 -void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")
 -      
 -      NSPoint screenCoord;
 -      NSPoint baseCoord;
 -      
 -      baseCoord.x = inX;
 -      baseCoord.y = inY;
 -      
 -      screenCoord = [m_window convertBaseToScreen:baseCoord];
 -      
 -      outX = screenCoord.x;
 -      outY = screenCoord.y;
 -}
 -
 +      //Creates the OpenGL View inside the window\r
 +      NSOpenGLPixelFormat *pixelFormat =\r
 +      [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];\r
 +      \r
 +      m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect\r
 +                                                                                               pixelFormat:pixelFormat];\r
 +      \r
 +      [pixelFormat release];\r
 +      \r
 +      m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after\r
 +      \r
 +      [m_window setContentView:m_openGLView];\r
 +      [m_window setInitialFirstResponder:m_openGLView];\r
 +      \r
 +      [m_window setReleasedWhenClosed:NO]; //To avoid bad pointer exception in case of user closing the window\r
 +      \r
 +      [m_window makeKeyAndOrderFront:nil];\r
 +      \r
 +      setDrawingContextType(type);\r
 +      updateDrawingContext();\r
 +      activateDrawingContext();\r
 +      \r
 +      m_tablet.Active = GHOST_kTabletModeNone;\r
 +      \r
 +      CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];\r
 +      [windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];\r
 +      [m_window setDelegate:windowDelegate];\r
 +      \r
 +      [m_window setAcceptsMouseMovedEvents:YES];\r
 +      \r
 +      if (state == GHOST_kWindowStateFullScreen)\r
 +              setState(GHOST_kWindowStateFullScreen);\r
 +              \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_WindowCocoa::~GHOST_WindowCocoa()\r
 +{\r
 +      if (m_customCursor) delete m_customCursor;\r
 +\r
 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      [m_openGLView release];\r
 +      \r
 +      if (m_window) {\r
 +              [m_window close];\r
 +              [[m_window delegate] release];\r
 +              [m_window release];\r
 +              m_window = nil;\r
 +      }\r
 +      \r
 +      //Check for other blender opened windows and make the frontmost key\r
 +      NSArray *windowsList = [NSApp orderedWindows];\r
 +      if ([windowsList count]) {\r
 +              [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +#pragma mark accessors\r
 +\r
 +bool GHOST_WindowCocoa::getValid() const\r
 +{\r
 +    bool valid;\r
 +    if (!m_fullScreen) {\r
 +        valid = (m_window != 0); //&& ::IsValidWindowPtr(m_windowRef);\r
 +    }\r
 +    else {\r
 +        valid = true;\r
 +    }\r
 +    return valid;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::setTitle(const STR_String& title)\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];\r
 +      \r
 +      //Set associated file if applicable\r
 +      if ([windowTitle hasPrefix:@"Blender"])\r
 +      {\r
 +              NSRange fileStrRange;\r
 +              NSString *associatedFileName;\r
 +              int len;\r
 +              \r
 +              fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;\r
 +              len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;\r
 +      \r
 +              if (len >0)\r
 +              {\r
 +                      fileStrRange.length = len;\r
 +                      associatedFileName = [windowTitle substringWithRange:fileStrRange];\r
 +                      @try {\r
 +                              [m_window setRepresentedFilename:associatedFileName];\r
 +                      }\r
 +                      @catch (NSException * e) {\r
 +                              printf("\nInvalid file path given in window title");\r
 +                      }\r
 +                      [m_window setTitle:[associatedFileName lastPathComponent]];\r
 +              }\r
 +              else {\r
 +                      [m_window setTitle:windowTitle];\r
 +                      [m_window setRepresentedFilename:@""];\r
 +              }\r
 +\r
 +      } else {\r
 +              [m_window setTitle:windowTitle];\r
 +              [m_window setRepresentedFilename:@""];\r
 +      }\r
 +\r
 +      \r
 +      [windowTitle release];\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getTitle(STR_String& title) const\r
 +{\r
 +    GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +\r
 +      NSString *windowTitle = [m_window title];\r
 +\r
 +      if (windowTitle != nil) {\r
 +              title = [windowTitle UTF8String];               \r
 +      }\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")\r
 +\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +      rect = [m_window frame];\r
 +\r
 +      bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);\r
 +      bounds.m_l = rect.origin.x -screenSize.origin.x;\r
 +      bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;\r
 +      bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);\r
 +      \r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const\r
 +{\r
 +      NSRect rect;\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      if (!m_fullScreen)\r
 +      {\r
 +              NSRect screenSize = [[m_window screen] visibleFrame];\r
 +\r
 +              //Max window contents as screen size (excluding title bar...)\r
 +              NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize\r
 +                                                                                                       styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +\r
 +              rect = [m_window contentRectForFrameRect:[m_window frame]];\r
 +              \r
 +              bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);\r
 +              bounds.m_l = rect.origin.x -contentRect.origin.x;\r
 +              bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;\r
 +              bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);\r
 +      }\r
 +      else {\r
 +              NSRect screenSize = [[m_window screen] frame];\r
 +              \r
 +              bounds.m_b = screenSize.origin.y + screenSize.size.height;\r
 +              bounds.m_l = screenSize.origin.x;\r
 +              bounds.m_r = screenSize.origin.x + screenSize.size.width;\r
 +              bounds.m_t = screenSize.origin.y;\r
 +      }\r
 +      [pool drain];\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getWidth()) != width) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=cBnds.getHeight();\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if (((GHOST_TUns32)cBnds.getHeight()) != height) {\r
 +              NSSize size;\r
 +              size.width=cBnds.getWidth();\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")\r
 +      GHOST_Rect cBnds, wBnds;\r
 +      getClientBounds(cBnds);\r
 +      if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||\r
 +          (((GHOST_TUns32)cBnds.getHeight()) != height)) {\r
 +              NSSize size;\r
 +              size.width=width;\r
 +              size.height=height;\r
 +              [m_window setContentSize:size];\r
 +      }\r
 +      return GHOST_kSuccess;\r
 +}\r
 +\r
 +\r
 +GHOST_TWindowState GHOST_WindowCocoa::getState() const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid")\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      GHOST_TWindowState state;\r
 +      if (m_fullScreen) {\r
 +              state = GHOST_kWindowStateFullScreen;\r
 +      } \r
 +      else if ([m_window isMiniaturized]) {\r
 +              state = GHOST_kWindowStateMinimized;\r
 +      }\r
 +      else if ([m_window isZoomed]) {\r
 +              state = GHOST_kWindowStateMaximized;\r
 +      }\r
 +      else {\r
 +              state = GHOST_kWindowStateNormal;\r
 +      }\r
 +      [pool drain];\r
 +      return state;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      screenCoord.x = inX;\r
 +      screenCoord.y = inY;\r
 +      \r
 +      baseCoord = [m_window convertScreenToBase:screenCoord];\r
 +      \r
 +      outX = baseCoord.x;\r
 +      outY = baseCoord.y;\r
 +}\r
 +\r
 +\r
 +void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")\r
 +      \r
 +      NSPoint screenCoord;\r
 +      NSPoint baseCoord;\r
 +      \r
 +      baseCoord.x = inX;\r
 +      baseCoord.y = inY;\r
 +      \r
 +      screenCoord = [m_window convertBaseToScreen:baseCoord];\r
 +      \r
 +      outX = screenCoord.x;\r
 +      outY = screenCoord.y;\r
 +}\r
 +\r
  
  NSScreen* GHOST_WindowCocoa::getScreen()
  {
  }
  
  
 -/**
 - * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.
 - * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.
 - * Thus, process switch, exposé, spaces, ... still work in fullscreen mode
 - */
 -GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")
 -    switch (state) {
 -              case GHOST_kWindowStateMinimized:
 -            [m_window miniaturize:nil];
 -            break;
 -              case GHOST_kWindowStateMaximized:
 -                      [m_window zoom:nil];
 -                      break;
 -              
 -              case GHOST_kWindowStateFullScreen:
 -                      if (!m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      
 -                              //This status change needs to be done before Cocoa call to enter fullscreen mode
 -                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference
 -                              m_fullScreen = true;
 -
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];
 -                              }
 -                              //Make window borderless and enlarge it
 -                              [m_window setStyleMask:NSBorderlessWindowMask];
 -                              [m_window setFrame:[[m_window screen] frame] display:YES];
 +/**\r
 + * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.\r
 + * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.\r
 + * Thus, process switch, exposé, spaces, ... still work in fullscreen mode\r
 + */\r
 +GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")\r
 +    switch (state) {\r
 +              case GHOST_kWindowStateMinimized:\r
 +            [m_window miniaturize:nil];\r
 +            break;\r
 +              case GHOST_kWindowStateMaximized:\r
 +                      [m_window zoom:nil];\r
 +                      break;\r
 +              \r
 +              case GHOST_kWindowStateFullScreen:\r
 +                      if (!m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      \r
 +                              //This status change needs to be done before Cocoa call to enter fullscreen mode\r
 +                              //to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference\r
 +                              m_fullScreen = true;\r
 +\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //10.6 provides Cocoa functions to autoshow menu bar, and to change a window style\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar)];\r
 +                              }\r
 +                              //Make window borderless and enlarge it\r
 +                              [m_window setStyleMask:NSBorderlessWindowMask];\r
 +                              [m_window setFrame:[[m_window screen] frame] display:YES];\r
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Hide menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];
 -                                      //One of the very few 64bit compatible Carbon function
 -                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                styleMask:NSBorderlessWindowMask
 -                                                                                backing:NSBackingStoreBuffered
 -                                                                                defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                              }
 -                      break;
 -              case GHOST_kWindowStateNormal:
 -        default:
 -                      if (m_fullScreen)
 -                      {
 -                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                              m_fullScreen = false;
 -
 -                              //Exit fullscreen
 -#ifdef MAC_OS_X_VERSION_10_6
 -                              //Show again menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];
 -                              }
 -                              //Make window normal and resize it
 -                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
 -                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Hide menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];\r
 +                                      //One of the very few 64bit compatible Carbon function\r
 +                                      SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                styleMask:NSBorderlessWindowMask\r
 +                                                                                backing:NSBackingStoreBuffered\r
 +                                                                                defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                              }\r
 +                      break;\r
 +              case GHOST_kWindowStateNormal:\r
 +        default:\r
 +                      if (m_fullScreen)\r
 +                      {\r
 +                              NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                              m_fullScreen = false;\r
 +\r
 +                              //Exit fullscreen\r
 +#ifdef MAC_OS_X_VERSION_10_6\r
 +                              //Show again menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      [NSApp setPresentationOptions:NSApplicationPresentationDefault];\r
 +                              }\r
 +                              //Make window normal and resize it\r
 +                              [m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];\r
 +                              [m_window setFrame:[[m_window screen] visibleFrame] display:YES];\r
+                               //TODO for 10.6 only : window title is forgotten after the style change
                                [m_window makeFirstResponder:m_openGLView];
 -#else
 -                              //With 10.5, we need to create a new window to change its style to borderless
 -                              //Show menu & dock if needed
 -                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])
 -                              {
 -                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];
 -                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function
 -                              }
 -                              //Create a fullscreen borderless window
 -                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]
 -                                                                                initWithContentRect:[[m_window screen] frame]
 -                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
 -                                                                                                        backing:NSBackingStoreBuffered
 -                                                                                                              defer:YES];
 -                              //Copy current window parameters
 -                              [tmpWindow setTitle:[m_window title]];
 -                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];
 -                              [tmpWindow setReleasedWhenClosed:NO];
 -                              [tmpWindow setAcceptsMouseMovedEvents:YES];
 -                              [tmpWindow setDelegate:[m_window delegate]];
 -                              
 -                              //Assign the openGL view to the new window
 -                              [tmpWindow setContentView:m_openGLView];
 -                              
 -                              //Show the new window
 -                              [tmpWindow makeKeyAndOrderFront:nil];
 -                              //Close and release old window
 -                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event
 -                              [m_window close];
 -                              [m_window release];
 -                              m_window = tmpWindow;
 -#endif
 -                      
 -                              //Tell WM of view new size
 -                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
 -                              
 -                              [pool drain];
 -                      }
 -            else if ([m_window isMiniaturized])
 -                              [m_window deminiaturize:nil];
 -                      else if ([m_window isZoomed])
 -                              [m_window zoom:nil];
 -            break;
 -    }
 -    return GHOST_kSuccess;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
 -{
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      [m_window setDocumentEdited:isUnsavedChanges];
 -      
 -      [pool drain];
 -      return GHOST_Window::setModifiedState(isUnsavedChanges);
 -}
 -
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
 -{
 -      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")
 -    if (order == GHOST_kWindowOrderTop) {
 -              [m_window orderFront:nil];
 -    }
 -    else {
 -              [m_window orderBack:nil];
 -    }
 -    return GHOST_kSuccess;
 -}
 -
 -#pragma mark Drawing context
 -
 -/*#define  WAIT_FOR_VSYNC 1*/
 -
 -GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
 -{
 -    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -        if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext flushBuffer];
 -                      [pool drain];
 -            return GHOST_kSuccess;
 -        }
 -    }
 -    return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext update];
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              }
 -      }
 -      return GHOST_kFailure;
 -}
 -
 -GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
 -{
 -      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 -              if (m_openGLContext != nil) {
 -                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -                      [m_openGLContext makeCurrentContext];
 -                      [pool drain];
 -                      return GHOST_kSuccess;
 -              }
 -      }
 -      return GHOST_kFailure;
 -}
 -
 -
 -GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
 -{
 -      GHOST_TSuccess success = GHOST_kFailure;
 -      
 -      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 -      
 -      NSOpenGLPixelFormat *pixelFormat;
 -      NSOpenGLContext *tmpOpenGLContext;
 -      
 +#else\r
 +                              //With 10.5, we need to create a new window to change its style to borderless\r
 +                              //Show menu & dock if needed\r
 +                              if ([[m_window screen] isEqual:[NSScreen mainScreen]])\r
 +                              {\r
 +                                      //Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];\r
 +                                      SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function\r
 +                              }\r
 +                              //Create a fullscreen borderless window\r
 +                              CocoaWindow *tmpWindow = [[CocoaWindow alloc]\r
 +                                                                                initWithContentRect:[[m_window screen] frame]\r
 +                                                                                                      styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)\r
 +                                                                                                        backing:NSBackingStoreBuffered\r
 +                                                                                                              defer:YES];\r
 +                              //Copy current window parameters\r
 +                              [tmpWindow setTitle:[m_window title]];\r
 +                              [tmpWindow setRepresentedFilename:[m_window representedFilename]];\r
 +                              [tmpWindow setReleasedWhenClosed:NO];\r
 +                              [tmpWindow setAcceptsMouseMovedEvents:YES];\r
 +                              [tmpWindow setDelegate:[m_window delegate]];\r
 +                              \r
 +                              //Assign the openGL view to the new window\r
 +                              [tmpWindow setContentView:m_openGLView];\r
 +                              \r
 +                              //Show the new window\r
 +                              [tmpWindow makeKeyAndOrderFront:nil];\r
 +                              //Close and release old window\r
 +                              [m_window setDelegate:nil]; // To avoid the notification of "window closed" event\r
 +                              [m_window close];\r
 +                              [m_window release];\r
 +                              m_window = tmpWindow;\r
 +#endif\r
 +                      \r
 +                              //Tell WM of view new size\r
 +                              m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);\r
 +                              \r
 +                              [pool drain];\r
 +                      }\r
 +            else if ([m_window isMiniaturized])\r
 +                              [m_window deminiaturize:nil];\r
 +                      else if ([m_window isZoomed])\r
 +                              [m_window zoom:nil];\r
 +            break;\r
 +    }\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)\r
 +{\r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      [m_window setDocumentEdited:isUnsavedChanges];\r
 +      \r
 +      [pool drain];\r
 +      return GHOST_Window::setModifiedState(isUnsavedChanges);\r
 +}\r
 +\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)\r
 +{\r
 +      GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")\r
 +    if (order == GHOST_kWindowOrderTop) {\r
 +              [m_window orderFront:nil];\r
 +    }\r
 +    else {\r
 +              [m_window orderBack:nil];\r
 +    }\r
 +    return GHOST_kSuccess;\r
 +}\r
 +\r
 +#pragma mark Drawing context\r
 +\r
 +/*#define  WAIT_FOR_VSYNC 1*/\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()\r
 +{\r
 +    if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +        if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext flushBuffer];\r
 +                      [pool drain];\r
 +            return GHOST_kSuccess;\r
 +        }\r
 +    }\r
 +    return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext update];\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              }\r
 +      }\r
 +      return GHOST_kFailure;\r
 +}\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()\r
 +{\r
 +      if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {\r
 +              if (m_openGLContext != nil) {\r
 +                      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +                      [m_openGLContext makeCurrentContext];\r
 +                      [pool drain];\r
 +                      return GHOST_kSuccess;\r
 +              }\r
 +      }\r
 +      return GHOST_kFailure;\r
 +}\r
 +\r
 +\r
 +GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)\r
 +{\r
 +      GHOST_TSuccess success = GHOST_kFailure;\r
 +      \r
 +      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\r
 +      \r
 +      NSOpenGLPixelFormat *pixelFormat;\r
 +      NSOpenGLContext *tmpOpenGLContext;\r
 +      \r
        /***** Multithreaded opengl code : uncomment for enabling
        CGLContextObj cglCtx;
        */
index c85103c62ce0db7a58d172b223eabcd4217b0191,deb9d216bf6c6fd5f5d1901c6d6e433a68b2567b..46dff6c41cab965ca2ee7e6ee798ad5459fd45c6
@@@ -7,8 -7,10 +7,9 @@@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C
                {6E24BF09-9653-4166-A871-F65CC9E98A9B} = {6E24BF09-9653-4166-A871-F65CC9E98A9B}\r
                {A90C4918-4B21-4277-93BD-AF65F30951D9} = {A90C4918-4B21-4277-93BD-AF65F30951D9}\r
                {FB88301F-F725-401B-ACD7-D2ABBF333B71} = {FB88301F-F725-401B-ACD7-D2ABBF333B71}\r
+               {76D3102B-7DD2-8BA1-034A-8B19FE2897C2} = {76D3102B-7DD2-8BA1-034A-8B19FE2897C2}\r
                {BAAE3F2B-BCF8-4E84-B8BA-CFB2D64945FE} = {BAAE3F2B-BCF8-4E84-B8BA-CFB2D64945FE}\r
                {C66F722C-46BE-40C9-ABAE-2EAC7A697EB8} = {C66F722C-46BE-40C9-ABAE-2EAC7A697EB8}\r
 -              {D1A9312F-4557-4982-A0F4-4D08508235F4} = {D1A9312F-4557-4982-A0F4-4D08508235F4}\r
                {884D8731-654C-4C7F-9A75-8F37A305BE1E} = {884D8731-654C-4C7F-9A75-8F37A305BE1E}\r
                {79D0B232-208C-F208-DA71-79B4AC088602} = {79D0B232-208C-F208-DA71-79B4AC088602}\r
                {E645CC32-4823-463E-82F0-46ADDE664018} = {E645CC32-4823-463E-82F0-46ADDE664018}\r
index 362d4ddc126db91953a3e04e158aa9898d57041e,70bb348ad02efe4c61a1216593a1e3f5fabecbd5..246040ab3302f0c4fe91cd51322ff582f9c2c4f6
@@@ -63,11 -63,11 +63,11 @@@ fpout.write("int datatoc_%s_size= %d;\n
  fpout.write("char datatoc_%s[]= {\n" % filename)
  
  while size > 0:
 -    size -= 1
 -    if size % 32 == 31:
 -        fpout.write("\n")
 +      size -= 1
 +      if size % 32 == 31:
 +              fpout.write("\n")
-       
 -    fpout.write("%3d," % ord(fpin.read(1)))
 +      fpout.write("%3d," % ord(fpin.read(1)))
  
  fpout.write("\n  0};\n\n")
  
index 0000000000000000000000000000000000000000,203e50bdef74434a1f2ea05f329f761e67a00da3..59c2ca3ebda1ff01f7e727b21331a9b2f5931798
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,22 +1,22 @@@
 -class_obj.getChildren = lambda ob: [child for child in bpy.data.objects if child.parent == ob]
+ # ##### BEGIN GPL LICENSE BLOCK #####
+ #
+ #  This program is free software; you can redistribute it and/or
+ #  modify it under the terms of the GNU General Public License
+ #  as published by the Free Software Foundation; either version 2
+ #  of the License, or (at your option) any later version.
+ # 
+ #  This program is distributed in the hope that it will be useful,
+ #  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #  GNU General Public License for more details.
+ # 
+ #  You should have received a copy of the GNU General Public License
+ #  along with this program; if not, write to the Free Software Foundation,
+ #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ #
+ # ##### END GPL LICENSE BLOCK #####
+ import bpy
+ class_obj = bpy.types.Object
++class_obj.getChildren = lambda self: [child for child in bpy.data.objects if child.parent == self]
index 639b9836b0c65cc78f82edefec715297ec27997d,55df062ac83be1df9c075c109ed6507755bdecc5..8078816f982fed373ebac7a03a50ff6bac23aafb
@@@ -60,267 -84,105 +84,111 @@@ class bpy_ops(object)
  
  
  class bpy_ops_submodule(object):
-       '''
-       Utility class to fake submodules.
-       
-       eg. bpy.ops.object
-       '''
-       __keys__ = ('module',)
-       
-       def __init__(self, module):
-               self.module = module
-               
-       def __getattr__(self, func):
-               '''
-               gets a bpy.ops.submodule function
-               '''
-               return bpy_ops_submodule_op(self.module, func)
-               
-       def __dir__(self):
-               
-               functions = set()
-               
-               module_upper = self.module.upper()
-               
-               for id_name in op_dir():
-                       id_split = id_name.split('_OT_', 1)
-                       if len(id_split) == 2 and module_upper == id_split[0]:
-                               functions.add(id_split[1])
-               
-               return list(functions)
-       
-       def __repr__(self):
-               return "<module like class 'bpy.ops.%s'>" % self.module
+     '''
+     Utility class to fake submodules.
+     eg. bpy.ops.object
+     '''
+     __keys__ = ('module',)
+     def __init__(self, module):
+         self.module = module
+     def __getattr__(self, func):
+         '''
+         gets a bpy.ops.submodule function
+         '''
+         if func.startswith('__'):
+             raise AttributeError(func)
+         return bpy_ops_submodule_op(self.module, func)
+     def __dir__(self):
+         functions = set()
+         module_upper = self.module.upper()
+         for id_name in op_dir():
+             id_split = id_name.split('_OT_', 1)
+             if len(id_split) == 2 and module_upper == id_split[0]:
+                 functions.add(id_split[1])
+         return list(functions)
+     def __repr__(self):
+         return "<module like class 'bpy.ops.%s'>" % self.module
  
  class bpy_ops_submodule_op(object):
-       '''
-       Utility class to fake submodule operators.
-       
-       eg. bpy.ops.object.somefunc
-       '''
-       __keys__ = ('module', 'func')
-       def __init__(self, module, func):
-               self.module = module
-               self.func = func
-       
-       def idname(self):
-               # submod.foo -> SUBMOD_OT_foo
-               return self.module.upper() + '_OT_' + self.func
-       
-       def __call__(self, *args, **kw):
-               
-               # Get the operator from blender
-               if len(args) > 1:
-                       raise ValueError("only one argument for the execution context is supported ")
-               
-               if args:
-                       try:
-                               context = context_dict[args[0]]
-                       except:
-                               raise ValueError("Expected a single context argument in: " + str(list(context_dict.keys())))
-                       
-                       return op_call(self.idname(), kw, context)
-               
-               else:
-                       return op_call(self.idname(), kw)
-       
-       def get_rna(self):
-               '''
-               currently only used for '__rna__'
-               '''
-               return op_get_rna(self.idname())
-                       
-       
-       def __repr__(self): # useful display, repr(op)
-               return op_as_string(self.idname())
-       
-       def __str__(self): # used for print(...)
-               return "<function bpy.ops.%s.%s at 0x%x'>" % (self.module, self.func, id(self))
+     '''
+     Utility class to fake submodule operators.
  
- import bpy
- bpy.ops = bpy_ops()
+     eg. bpy.ops.object.somefunc
+     '''
+     __keys__ = ('module', 'func')
++    
++    
++    def _get_doc(self):
++        return op_as_string(self.idname())
++    
++    __doc__ = property(_get_doc)
+     def __init__(self, module, func):
+         self.module = module
+         self.func = func
+     def idname(self):
+         # submod.foo -> SUBMOD_OT_foo
+         return self.module.upper() + '_OT_' + self.func
+     def __call__(self, *args, **kw):
+         # Get the operator from blender
+         if len(args) > 2:
+             raise ValueError("1 or 2 args execution context is supported")
+         C_dict = None
+         if args:
  
- # TODO, C macro's cant define settings :|
- class MESH_OT_delete_edgeloop(bpy.types.Operator):
-       '''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
-       __idname__ = "mesh.delete_edgeloop"
-       __label__ = "Delete Edge Loop"
-       
-       def execute(self, context):
-               bpy.ops.tfm.edge_slide(value=1.0)
-               bpy.ops.mesh.select_more()
-               bpy.ops.mesh.remove_doubles()
-               return ('FINISHED',)
- rna_path_prop = bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= "")
- rna_reverse_prop = bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)
- class NullPathMember:
-       pass
- def context_path_validate(context, path):
-       import sys
-       try:
-               value = eval("context.%s" % path)
-       except AttributeError:
-               if "'NoneType'" in str(sys.exc_info()[1]):
-                       # One of the items in the rna path is None, just ignore this
-                       value = NullPathMember
-               else:
-                       # We have a real error in the rna path, dont ignore that
-                       raise
-       
-       return value
-               
-       
- def execute_context_assign(self, context):
-       if context_path_validate(context, self.path) == NullPathMember:
-               return ('PASS_THROUGH',)
-       
-       exec("context.%s=self.value" % self.path)
-       return ('FINISHED',)
- class WM_OT_context_set_boolean(bpy.types.Operator):
-       '''Set a context value.'''
-       __idname__ = "wm.context_set_boolean"
-       __label__ = "Context Set"
-       __props__ = [rna_path_prop, bpy.props.BoolProperty(attr="value", name="Value", description="Assignment value", default= True)]
-       execute = execute_context_assign
- class WM_OT_context_set_int(bpy.types.Operator): # same as enum
-       '''Set a context value.'''
-       __idname__ = "wm.context_set_int"
-       __label__ = "Context Set"
-       __props__ = [rna_path_prop, bpy.props.IntProperty(attr="value", name="Value", description="Assignment value", default= 0)]
-       execute = execute_context_assign
-               
- class WM_OT_context_set_float(bpy.types.Operator): # same as enum
-       '''Set a context value.'''
-       __idname__ = "wm.context_set_int"
-       __label__ = "Context Set"
-       __props__ = [rna_path_prop, bpy.props.FloatProperty(attr="value", name="Value", description="Assignment value", default= 0.0)]
-       execute = execute_context_assign
- class WM_OT_context_set_string(bpy.types.Operator): # same as enum
-       '''Set a context value.'''
-       __idname__ = "wm.context_set_string"
-       __label__ = "Context Set"
-       __props__ = [rna_path_prop, bpy.props.StringProperty(attr="value", name="Value", description="Assignment value", maxlen= 1024, default= "")]
-       execute = execute_context_assign
- class WM_OT_context_set_enum(bpy.types.Operator):
-       '''Set a context value.'''
-       __idname__ = "wm.context_set_enum"
-       __label__ = "Context Set"
-       __props__ = [rna_path_prop, bpy.props.StringProperty(attr="value", name="Value", description="Assignment value (as a string)", maxlen= 1024, default= "")]
-       execute = execute_context_assign
- class WM_OT_context_toggle(bpy.types.Operator):
-       '''Toggle a context value.'''
-       __idname__ = "wm.context_toggle"
-       __label__ = "Context Toggle"
-       __props__ = [rna_path_prop]
-       def execute(self, context):
-               
-               if context_path_validate(context, self.path) == NullPathMember:
-                       return ('PASS_THROUGH',)
-               
-               exec("context.%s=not (context.%s)" % (self.path, self.path)) # security nuts will complain.
-               return ('FINISHED',)
- class WM_OT_context_toggle_enum(bpy.types.Operator):
-       '''Toggle a context value.'''
-       __idname__ = "wm.context_toggle_enum"
-       __label__ = "Context Toggle Values"
-       __props__ = [
-               rna_path_prop,
-               bpy.props.StringProperty(attr="value_1", name="Value", description="Toggle enum", maxlen= 1024, default= ""),
-               bpy.props.StringProperty(attr="value_2", name="Value", description="Toggle enum", maxlen= 1024, default= "")
-       ]
-       def execute(self, context):
-               
-               if context_path_validate(context, self.path) == NullPathMember:
-                       return ('PASS_THROUGH',)
-               
-               exec("context.%s = ['%s', '%s'][context.%s!='%s']" % (self.path, self.value_1, self.value_2, self.path, self.value_2)) # security nuts will complain.
-               return ('FINISHED',)
- class WM_OT_context_cycle_int(bpy.types.Operator):
-       '''Set a context value. Useful for cycling active material, vertex keys, groups' etc.'''
-       __idname__ = "wm.context_cycle_int"
-       __label__ = "Context Int Cycle"
-       __props__ = [rna_path_prop, rna_reverse_prop]
-       def execute(self, context):
-               
-               value = context_path_validate(context, self.path)
-               if value == NullPathMember:
-                       return ('PASS_THROUGH',)
-               
-               self.value = value
-               if self.reverse:        self.value -= 1
-               else:           self.value += 1
-               execute_context_assign(self, context)
-               
-               if self.value != eval("context.%s" % self.path):
-                       # relies on rna clamping int's out of the range
-                       if self.reverse:        self.value =  (1<<32)
-                       else:           self.value = -(1<<32)
-                       execute_context_assign(self, context)
-                       
-               return ('FINISHED',)
- class WM_OT_context_cycle_enum(bpy.types.Operator):
-       '''Toggle a context value.'''
-       __idname__ = "wm.context_cycle_enum"
-       __label__ = "Context Enum Cycle"
-       __props__ = [rna_path_prop, rna_reverse_prop]
-       def execute(self, context):
-               
-               value = context_path_validate(context, self.path)
-               if value == NullPathMember:
-                       return ('PASS_THROUGH',)
-               
-               orig_value = value
-               
-               # Have to get rna enum values
-               rna_struct_str, rna_prop_str =  self.path.rsplit('.', 1)
-               i = rna_prop_str.find('[')
-               if i != -1: rna_prop_str = rna_prop_str[0:i] # just incse we get "context.foo.bar[0]"
-               
-               rna_struct = eval("context.%s.rna_type" % rna_struct_str)
-               
-               rna_prop = rna_struct.properties[rna_prop_str]
-               
-               if type(rna_prop) != bpy.types.EnumProperty:
-                       raise Exception("expected an enum property")
-               
-               enums = rna_struct.properties[rna_prop_str].items.keys()
-               orig_index = enums.index(orig_value)
-               
-               # Have the info we need, advance to the next item
-               if self.reverse:
-                       if orig_index==0:                       advance_enum = enums[-1]
-                       else:                                   advance_enum = enums[orig_index-1]
-               else:
-                       if orig_index==len(enums)-1:    advance_enum = enums[0]
-                       else:                                   advance_enum = enums[orig_index+1]
-               
-               # set the new value
-               exec("context.%s=advance_enum" % self.path)
-               return ('FINISHED',)
- bpy.ops.add(MESH_OT_delete_edgeloop)
- bpy.ops.add(WM_OT_context_set_boolean)
- bpy.ops.add(WM_OT_context_set_int)
- bpy.ops.add(WM_OT_context_set_float)
- bpy.ops.add(WM_OT_context_set_string)
- bpy.ops.add(WM_OT_context_set_enum)
- bpy.ops.add(WM_OT_context_toggle)
- bpy.ops.add(WM_OT_context_toggle_enum)
- bpy.ops.add(WM_OT_context_cycle_enum)
- bpy.ops.add(WM_OT_context_cycle_int)
+             C_exec = 'EXEC_DEFAULT'
  
+             if len(args) == 2:
+                 C_exec = args[0]
+                 C_dict = args[1]
+             else:
+                 if type(args[0]) != str:
+                     C_dict = args[0]
+                 else:
+                     C_exec = args[0]
+             try:
+                 context = context_dict[C_exec]
+             except:
+                 raise ValueError("Expected a single context argument in: " + \
+                  str(list(context_dict.keys())))
+             if len(args) == 2:
+                 C_dict = args[1]
+             return op_call(self.idname(), C_dict, kw, context)
+         else:
+             return op_call(self.idname(), C_dict, kw)
+     def get_rna(self):
+         '''
+         currently only used for 'bl_rna'
+         '''
+         return op_get_rna(self.idname())
+     def __repr__(self): # useful display, repr(op)
+         return op_as_string(self.idname())
+     def __str__(self): # used for print(...)
+         return "<function bpy.ops.%s.%s at 0x%x'>" % \
+                 (self.module, self.func, id(self))
+ import bpy
+ bpy.ops = bpy_ops()
index 5bb211f7d9820b2efc18a22e210a0f0678817eb5,abf7b23e27a68f7f20a46f73c0febd19876a7c4d..06754ea81cb13790a0395c2cdd4227fa78fd7041
+ # ##### BEGIN GPL LICENSE BLOCK #####
+ #
+ #  This program is free software; you can redistribute it and/or
+ #  modify it under the terms of the GNU General Public License
+ #  as published by the Free Software Foundation; either version 2
+ #  of the License, or (at your option) any later version.
+ #
+ #  This program is distributed in the hope that it will be useful,
+ #  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #  GNU General Public License for more details.
+ #
+ #  You should have received a copy of the GNU General Public License
+ #  along with this program; if not, write to the Free Software Foundation,
+ #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ #
+ # ##### END GPL LICENSE BLOCK #####
+ # <pep8 compliant>
+ import sys
  import bpy
++from bpy.props import *
  
  class CONSOLE_HT_header(bpy.types.Header):
-       __space_type__ = 'CONSOLE'
-       def draw(self, context):
-               sc = context.space_data
-               # text = sc.text
-               layout = self.layout
-               row= layout.row(align=True)
-               row.template_header()
-               if context.area.show_menus:
-                       sub = row.row(align=True)
-                       if sc.console_type == 'REPORT':
-                               sub.itemM("CONSOLE_MT_report")
-                       else:
-                               sub.itemM("CONSOLE_MT_console")
-               layout.itemS()
-               layout.itemR(sc, "console_type", expand=True)
-               if sc.console_type == 'REPORT':
-                       row = layout.row(align=True)
-                       row.itemR(sc, "show_report_debug", text="Debug")
-                       row.itemR(sc, "show_report_info", text="Info")
-                       row.itemR(sc, "show_report_operator", text="Operators")
-                       row.itemR(sc, "show_report_warn", text="Warnings")
-                       row.itemR(sc, "show_report_error", text="Errors")
-                       
-                       row = layout.row()
-                       row.enabled = sc.show_report_operator
-                       row.itemO("console.report_replay")
-               else:
-                       row = layout.row(align=True)
-                       row.itemO("console.autocomplete", text="Autocomplete")
+     bl_space_type = 'CONSOLE'
+     def draw(self, context):
+         sc = context.space_data
+         # text = sc.text
+         layout = self.layout
+         row = layout.row(align=True)
+         row.template_header()
+         if context.area.show_menus:
+             sub = row.row(align=True)
+             if sc.console_type == 'REPORT':
+                 sub.itemM("CONSOLE_MT_report")
+             else:
+                 sub.itemM("CONSOLE_MT_console")
+         layout.itemS()
+         layout.itemR(sc, "console_type", expand=True)
+         if sc.console_type == 'REPORT':
+             row = layout.row(align=True)
+             row.itemR(sc, "show_report_debug", text="Debug")
+             row.itemR(sc, "show_report_info", text="Info")
+             row.itemR(sc, "show_report_operator", text="Operators")
+             row.itemR(sc, "show_report_warn", text="Warnings")
+             row.itemR(sc, "show_report_error", text="Errors")
+             row = layout.row()
+             row.enabled = sc.show_report_operator
+             row.itemO("console.report_replay")
+         else:
+             row = layout.row(align=True)
+             row.itemO("console.autocomplete", text="Autocomplete")
  
  class CONSOLE_MT_console(bpy.types.Menu):
-       __label__ = "Console"
+     bl_label = "Console"
  
-       def draw(self, context):
-               layout = self.layout
-               sc = context.space_data
+     def draw(self, context):
+         layout = self.layout
+         layout.column()
+         layout.itemO("console.clear")
+         layout.itemO("console.copy")
+         layout.itemO("console.paste")
++        layout.itemM("CONSOLE_MT_language")
  
-               layout.column()
-               layout.itemO("console.clear")
-               layout.itemO("console.copy")
-               layout.itemO("console.paste")
  
  class CONSOLE_MT_report(bpy.types.Menu):
-       __label__ = "Report"
+     bl_label = "Report"
+     def draw(self, context):
+         layout = self.layout
+         layout.column()
+         layout.itemO("console.select_all_toggle")
+         layout.itemO("console.select_border")
+         layout.itemO("console.report_delete")
+         layout.itemO("console.report_copy")
++class CONSOLE_MT_language(bpy.types.Menu):
++    bl_label = "Languages..."
++
++    def draw(self, context):
++        layout = self.layout
++        layout.column()
++        
++        mod = bpy.ops.console
++        languages = []
++        for opname in dir(mod):
++            # execute_python, execute_shell etc.
++            if opname.startswith("execute_"):
++                languages.append(opname.split('_', 1)[-1])
++        
++        languages.sort()
++        
++        for language in languages:
++            layout.item_stringO("console.language", "language", language, text=language[0].upper() + language[1:])
+ def add_scrollback(text, text_type):
+     for l in text.split('\n'):
+         bpy.ops.console.scrollback_append(text=l.replace('\t', '    '),
+             type=text_type)
  
-       def draw(self, context):
-               layout = self.layout
-               sc = context.space_data
  
-               layout.column()
-               layout.itemO("console.select_all_toggle")
-               layout.itemO("console.select_border")
-               layout.itemO("console.report_delete")
-               layout.itemO("console.report_copy")
 -def get_console(console_id):
 -    '''
 -    helper function for console operators
 -    currently each text datablock gets its own
 -    console - bpython_code.InteractiveConsole()
 -    ...which is stored in this function.
 -
 -    console_id can be any hashable type
 -    '''
 -    from code import InteractiveConsole
 -
 -    try:
 -        consoles = get_console.consoles
 -    except:
 -        consoles = get_console.consoles = {}
 -
 -    # clear all dead consoles, use text names as IDs
 -    # TODO, find a way to clear IDs
 -    '''
 -    for console_id in list(consoles.keys()):
 -        if console_id not in bpy.data.texts:
 -            del consoles[id]
 -    '''
 -
 -    try:
 -        console, stdout, stderr = consoles[console_id]
 -    except:
 -        namespace = {'__builtins__': __builtins__, 'bpy': bpy}
 -        console = InteractiveConsole(namespace)
 -
 -        import io
 -        stdout = io.StringIO()
 -        stderr = io.StringIO()
 -
 -        consoles[console_id] = console, stdout, stderr
 -
 -    return console, stdout, stderr
 -
 -
+ class ConsoleExec(bpy.types.Operator):
+     '''Execute the current console line as a python expression.'''
+     bl_idname = "console.execute"
+     bl_label = "Console Execute"
+     bl_register = False
  
- def add_scrollback(text, text_type):
-       for l in text.split('\n'):
-               bpy.ops.console.scrollback_append(text=l.replace('\t', '    '), type=text_type)
- def get_console(console_id):
-       '''
-       helper function for console operators
-       currently each text datablock gets its own console - code.InteractiveConsole()
-       ...which is stored in this function.
-       
-       console_id can be any hashable type
-       '''
-       import sys, code
-       
-       try:    consoles = get_console.consoles
-       except:consoles = get_console.consoles = {}
-       
-       # clear all dead consoles, use text names as IDs
-       # TODO, find a way to clear IDs
-       '''
-       for console_id in list(consoles.keys()):
-               if console_id not in bpy.data.texts:
-                       del consoles[id]
-       '''
-       
-       try:
-               namespace, console, stdout, stderr = consoles[console_id]
-       except:
-               namespace = {'__builtins__':__builtins__} # locals()
-               namespace['bpy'] = bpy
-               
-               console = code.InteractiveConsole(namespace)
-               
-               import io
-               stdout = io.StringIO()
-               stderr = io.StringIO()
-       
-               consoles[console_id]= namespace, console, stdout, stderr
-               
-       return namespace, console, stdout, stderr
- class CONSOLE_OT_exec(bpy.types.Operator):
-       '''Execute the current console line as a python expression.'''
-       __idname__ = "console.execute"
-       __label__ = "Console Execute"
-       __register__ = False
-       
-       # Both prompts must be the same length
-       PROMPT = '>>> ' 
-       PROMPT_MULTI = '... '
-       
-       # is this working???
-       '''
-       def poll(self, context):
-               return (context.space_data.type == 'PYTHON')
-       ''' # its not :|
-       
-       def execute(self, context):
-               import sys
-               
-               sc = context.space_data
-               
-               try:
-                       line = sc.history[-1].line
-               except:
-                       return ('CANCELLED',)
-               
-               if sc.console_type != 'PYTHON':
-                       return ('CANCELLED',)
-               
-               namespace, console, stdout, stderr = get_console(hash(context.region))
-               
-               # redirect output
-               sys.stdout = stdout
-               sys.stderr = stderr
-               
-               # run the console
-               if not line.strip():
-                       line_exec = '\n' # executes a multiline statement
-               else:
-                       line_exec = line
-               
-               is_multiline = console.push(line_exec)
-               
-               stdout.seek(0)
-               stderr.seek(0)
-               
-               output = stdout.read()
-               output_err = stderr.read()
-       
-               # cleanup
-               sys.stdout = sys.__stdout__
-               sys.stderr = sys.__stderr__
-               sys.last_traceback = None
-               
-               # So we can reuse, clear all data
-               stdout.truncate(0)
-               stderr.truncate(0)
-               
-               bpy.ops.console.scrollback_append(text = sc.prompt+line, type='INPUT')
-               
-               if is_multiline:        sc.prompt = self.PROMPT_MULTI
-               else:                           sc.prompt = self.PROMPT
-               
-               # insert a new blank line
-               bpy.ops.console.history_append(text="", current_character=0, remove_duplicates= True)
-               
-               # Insert the output into the editor
-               # not quite correct because the order might have changed, but ok 99% of the time.
-               if output:                      add_scrollback(output, 'OUTPUT')
-               if output_err:          add_scrollback(output_err, 'ERROR')
-               
-               
-               return ('FINISHED',)
 -    # Both prompts must be the same length
 -    PROMPT = '>>> '
 -    PROMPT_MULTI = '... '
--
 -    # is this working???
 -    '''
 -    def poll(self, context):
 -        return (context.space_data.type == 'PYTHON')
 -    '''
 -    # its not :|
--
- class CONSOLE_OT_autocomplete(bpy.types.Operator):
-       '''Evaluate the namespace up until the cursor and give a list of options or complete the name if there is only one.'''
-       __idname__ = "console.autocomplete"
-       __label__ = "Console Autocomplete"
-       __register__ = False
-       
-       def poll(self, context):
-               return context.space_data.console_type == 'PYTHON'
-       
-       def execute(self, context):
-               
-               sc = context.space_data
-               
-               namespace, console, stdout, stderr = get_console(hash(context.region))
-               
-               current_line = sc.history[-1]
-               line = current_line.line
-               
-               if not console:
-                       return ('CANCELLED',)
-               
-               if sc.console_type != 'PYTHON':
-                       return ('CANCELLED',)
-               
-               # fake cursor, use for autocomp func.
-               bcon = {}
-               bcon['cursor'] = current_line.current_character
-               bcon['console'] = console
-               bcon['edit_text'] = line
-               bcon['namespace'] = namespace
-               bcon['scrollback'] = '' # nor from the BGE console
-               
-               
-               # This function isnt aware of the text editor or being an operator
-               # just does the autocomp then copy its results back
-               import autocomplete
-               autocomplete.execute(bcon)
-               
-               # Now we need to copy back the line from blender back into the text editor.
-               # This will change when we dont use the text editor anymore
-               if bcon['scrollback']:
-                       add_scrollback(bcon['scrollback'], 'INFO')
-               
-               # copy back
-               current_line.line = bcon['edit_text']
-               current_line.current_character = bcon['cursor']
-               
-               context.area.tag_redraw()
-               
-               return ('FINISHED',)
+     def execute(self, context):
+         sc = context.space_data
 -        try:
 -            line = sc.history[-1].line
 -        except:
 -            return ('CANCELLED',)
 -
 -        if sc.console_type != 'PYTHON':
 -            return ('CANCELLED',)
 -
 -        console, stdout, stderr = get_console(hash(context.region))
 -
 -        # Hack, useful but must add some other way to access
 -        #if "C" not in console.locals:
 -        console.locals["C"] = context
 -
 -        # redirect output
 -        sys.stdout = stdout
 -        sys.stderr = stderr
 -
 -        # run the console
 -        if not line.strip():
 -            line_exec = '\n'  # executes a multiline statement
 -        else:
 -            line_exec = line
 -
 -        is_multiline = console.push(line_exec)
 -
 -        stdout.seek(0)
 -        stderr.seek(0)
 -
 -        output = stdout.read()
 -        output_err = stderr.read()
 -
 -        # cleanup
 -        sys.stdout = sys.__stdout__
 -        sys.stderr = sys.__stderr__
 -        sys.last_traceback = None
++        execute = getattr(bpy.ops.console, "execute_" + sc.language, None)
 -        # So we can reuse, clear all data
 -        stdout.truncate(0)
 -        stderr.truncate(0)
 -
 -        bpy.ops.console.scrollback_append(text=sc.prompt + line, type='INPUT')
 -
 -        if is_multiline:
 -            sc.prompt = self.PROMPT_MULTI
++        if execute:
++            execute()
+         else:
 -            sc.prompt = self.PROMPT
 -
 -        # insert a new blank line
 -        bpy.ops.console.history_append(text="", current_character=0,
 -            remove_duplicates=True)
 -
 -        # Insert the output into the editor
 -        # not quite correct because the order might have changed,
 -        # but ok 99% of the time.
 -        if output:
 -            add_scrollback(output, 'OUTPUT')
 -        if output_err:
 -            add_scrollback(output_err, 'ERROR')
++            print("Error: bpy.ops.console.execute_" + sc.language + " - not found")
+         return ('FINISHED',)
+ class ConsoleAutocomplete(bpy.types.Operator):
+     '''Evaluate the namespace up until the cursor and give a list of
+     options or complete the name if there is only one.'''
+     bl_idname = "console.autocomplete"
+     bl_label = "Console Autocomplete"
+     bl_register = False
+     def poll(self, context):
 -        return context.space_data.console_type == 'PYTHON'
++        return context.space_data.console_type != 'REPORT'
+     def execute(self, context):
 -        from console import intellisense
 -
+         sc = context.space_data
 -        console = get_console(hash(context.region))[0]
 -        
 -        current_line = sc.history[-1]
 -        line = current_line.line
++        autocomplete = getattr(bpy.ops.console, "autocomplete_" + sc.language, None)
 -        if not console:
 -            return ('CANCELLED',)
++        if autocomplete:
++            autocomplete()
++        else:
++            print("Error: bpy.ops.console.autocomplete_" + sc.language + " - not found")
 -        if sc.console_type != 'PYTHON':
 -            return ('CANCELLED',)
++        return ('FINISHED',)
 -        # This function isnt aware of the text editor or being an operator
 -        # just does the autocomp then copy its results back
 -        current_line.line, current_line.current_character, scrollback = \
 -            intellisense.expand(
 -                line=current_line.line,
 -                cursor=current_line.current_character,
 -                namespace=console.locals,
 -                private='-d' in sys.argv)
 -        # Now we need to copy back the line from blender back into the
 -        # text editor. This will change when we dont use the text editor
 -        # anymore
 -        if scrollback:
 -            add_scrollback(scrollback, 'INFO')
++class ConsoleBanner(bpy.types.Operator):
++    bl_idname = "console.banner"
 -        context.area.tag_redraw()
++    def execute(self, context):
++        sc = context.space_data
++        
++        # default to python
++        if not sc.language:
++            sc.language = 'python'
++
++        banner = getattr(bpy.ops.console, "banner_" + sc.language, None)
++        
++        if banner:
++            banner()
++        else:
++            print("Error: bpy.ops.console.banner_" + sc.language + " - not found")
+         return ('FINISHED',)
 -class ConsoleBanner(bpy.types.Operator):
 -    bl_idname = "console.banner"
++
++class ConsoleLanguage(bpy.types.Operator):
++    '''Set the current language for this console'''
++    bl_idname = "console.language"
++    language = StringProperty(name="Language", maxlen= 32, default= "")
+     def execute(self, context):
+         sc = context.space_data
 -        version_string = sys.version.strip().replace('\n', ' ')
 -
 -        add_scrollback(" * Python Interactive Console %s *" % version_string, 'OUTPUT')
 -        add_scrollback("Command History:  Up/Down Arrow", 'OUTPUT')
 -        add_scrollback("Cursor:           Left/Right Home/End", 'OUTPUT')
 -        add_scrollback("Remove:           Backspace/Delete", 'OUTPUT')
 -        add_scrollback("Execute:          Enter", 'OUTPUT')
 -        add_scrollback("Autocomplete:     Ctrl+Space", 'OUTPUT')
 -        add_scrollback("Ctrl +/-  Wheel:  Zoom", 'OUTPUT')
 -        add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, Mathutils, Geometry, BGL", 'OUTPUT')
 -        add_scrollback("", 'OUTPUT')
 -        add_scrollback("", 'OUTPUT')
 -        sc.prompt = ConsoleExec.PROMPT
 -
 -        # Add context into the namespace for quick access
 -        console = get_console(hash(context.region))[0]
 -        console.locals["C"] = bpy.context
++        
++        # defailt to python
++        sc.language = self.language
++        
++        bpy.ops.console.banner()
++        
++        # insert a new blank line
++        bpy.ops.console.history_append(text="", current_character=0,
++            remove_duplicates=True)
  
+         return ('FINISHED',)
  
  
  bpy.types.register(CONSOLE_HT_header)
  bpy.types.register(CONSOLE_MT_console)
  bpy.types.register(CONSOLE_MT_report)
++bpy.types.register(CONSOLE_MT_language)
  
- bpy.ops.add(CONSOLE_OT_exec)
- bpy.ops.add(CONSOLE_OT_autocomplete)
++# Stubs that call the language operators
+ bpy.ops.add(ConsoleExec)
+ bpy.ops.add(ConsoleAutocomplete)
+ bpy.ops.add(ConsoleBanner)
 +
++# Set the language and call the banner
++bpy.ops.add(ConsoleLanguage)
index ad2597d6c243d2d9a716d04d48e7cee45baf87c6,483031837cf17cc03199279b2cca953968dcabc3..863bab35f131d51e7f5ccbf15acdbb00cfc76f28
@@@ -74,87 -108,102 +108,132 @@@ class VIEW3D_MT_uv_map(dynamic_menu.Dyn
  
  # ********** View menus **********
  
  class VIEW3D_MT_view(bpy.types.Menu):
-       __label__ = "View"
-       def draw(self, context):
-               layout = self.layout
-               layout.itemO("view3d.properties", icon='ICON_MENU_PANEL')
-               layout.itemO("view3d.toolbar", icon='ICON_MENU_PANEL')
-               
-               layout.itemS()
-               
-               layout.item_enumO("view3d.viewnumpad", "type", 'CAMERA')
-               layout.item_enumO("view3d.viewnumpad", "type", 'TOP')
-               layout.item_enumO("view3d.viewnumpad", "type", 'FRONT')
-               layout.item_enumO("view3d.viewnumpad", "type", 'RIGHT')
-               
-               layout.itemM("VIEW3D_MT_view_cameras", text="Cameras")
-               
-               layout.itemS()
-               
-               layout.itemO("view3d.view_persportho")
-               
-               layout.itemS()
-               
-               layout.itemM("VIEW3D_MT_view_navigation")
-               layout.itemM("VIEW3D_MT_view_align")
-               
-               layout.itemS()
-               layout.operator_context = "INVOKE_REGION_WIN"
-               
-               layout.itemO("view3d.clip_border", text="Clipping Border...")
-               layout.itemO("view3d.zoom_border", text="Zoom Border...")
-               
-               layout.itemS()
-               
-               layout.itemO("view3d.localview", text="View Global/Local")
-               layout.itemO("view3d.view_center")
-               layout.itemO("view3d.view_all")
-               
-               layout.itemS()
-               
-               layout.itemO("screen.region_foursplit", text="Toggle Quad View")
-               layout.itemO("screen.screen_full_area", text="Toggle Full Screen")
+     bl_label = "View"
+     def draw(self, context):
+         layout = self.layout
+         layout.itemO("view3d.properties", icon='ICON_MENU_PANEL')
+         layout.itemO("view3d.toolbar", icon='ICON_MENU_PANEL')
+         layout.itemS()
+         layout.item_enumO("view3d.viewnumpad", "type", 'CAMERA')
+         layout.item_enumO("view3d.viewnumpad", "type", 'TOP')
+         layout.item_enumO("view3d.viewnumpad", "type", 'FRONT')
+         layout.item_enumO("view3d.viewnumpad", "type", 'RIGHT')
+         layout.itemM("VIEW3D_MT_view_cameras", text="Cameras")
+         layout.itemS()
+         layout.itemO("view3d.view_persportho")
+         layout.itemS()
+         layout.itemM("VIEW3D_MT_view_navigation")
+         layout.itemM("VIEW3D_MT_view_align")
+         layout.itemS()
+         layout.operator_context = "INVOKE_REGION_WIN"
+         layout.itemO("view3d.clip_border", text="Clipping Border...")
+         layout.itemO("view3d.zoom_border", text="Zoom Border...")
+         layout.itemS()
+         layout.item_intO("view3d.layers", "nr", 0, text="Show All Layers")
+         layout.itemS()
+         layout.itemO("view3d.localview", text="View Global/Local")
+         layout.itemO("view3d.view_center")
+         layout.itemO("view3d.view_all")
+         layout.itemS()
+         layout.itemO("screen.region_foursplit", text="Toggle Quad View")
+         layout.itemO("screen.screen_full_area", text="Toggle Full Screen")
+         layout.itemS()
+         layout.itemO("screen.animation_play", text="Playback Animation", icon='ICON_PLAY')
  
  class VIEW3D_MT_view_navigation(bpy.types.Menu):
-       __label__ = "Navigation"
-       def draw(self, context):
-               layout = self.layout
-               layout.items_enumO("view3d.view_orbit", "type")
-               
-               layout.itemS()
-               
-               layout.items_enumO("view3d.view_pan", "type")
-               
-               layout.itemS()
-               
-               layout.item_floatO("view3d.zoom", "delta", 1.0, text="Zoom In")
-               layout.item_floatO("view3d.zoom", "delta", -1.0, text="Zoom Out")
-               
-               layout.itemS()
-               
-               layout.itemO("view3d.fly")
+     bl_label = "Navigation"
+     def draw(self, context):
+         layout = self.layout
+         layout.items_enumO("view3d.view_orbit", "type")
+         layout.itemS()
+         layout.items_enumO("view3d.view_pan", "type")
+         layout.itemS()
+         layout.item_floatO("view3d.zoom", "delta", 1.0, text="Zoom In")
+         layout.item_floatO("view3d.zoom", "delta", -1.0, text="Zoom Out")
+         layout.itemS()
+         layout.itemO("view3d.fly")
  
  class VIEW3D_MT_view_align(bpy.types.Menu):
-       __label__ = "Align View"
+     bl_label = "Align View"
+     def draw(self, context):
+         layout = self.layout
++        layout.itemM("VIEW3D_MT_view_align_selected")
++
++        layout.itemS()
++
+         layout.item_booleanO("view3d.view_all", "center", True, text="Center Cursor and View All")
+         layout.itemO("view3d.camera_to_view", text="Align Active Camera to View")
+         layout.itemO("view3d.view_center")
++class VIEW3D_MT_view_align_selected(bpy.types.Menu):
++    bl_label = "Align View to Selected"
++
++    def draw(self, context):
++        layout = self.layout
++
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Top")
++        props.align_active = True
++        props.type = 'TOP'
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Bottom")
++        props.align_active = True
++        props.type = 'BOTTOM'
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Front")
++        props.align_active = True
++        props.type = 'FRONT'
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Back")
++        props.align_active = True
++        props.type = 'BACK'
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Right")
++        props.align_active = True
++        props.type = 'RIGHT'
++        props = layout.itemO("view3d.viewnumpad", properties=True, text="Left")
++        props.align_active = True
++        props.type = 'LEFT'
++
 +
-       def draw(self, context):
-               layout = self.layout
-               
-               layout.itemO("view3d.view_center")
-               
  class VIEW3D_MT_view_cameras(bpy.types.Menu):
-       __label__ = "Cameras"
+     bl_label = "Cameras"
  
-       def draw(self, context):
-               layout = self.layout
-               
-               layout.itemO("view3d.object_as_camera")
+     def draw(self, context):
+         layout = self.layout
+         layout.itemO("view3d.object_as_camera")
+         layout.item_enumO("view3d.viewnumpad", "type", 'CAMERA', text="Active Camera")
  
  # ********** Select menus, suffix from context.mode **********
  
@@@ -1470,6 -1621,6 +1651,7 @@@ bpy.types.register(VIEW3D_HT_header) # 
  bpy.types.register(VIEW3D_MT_view) #View Menus
  bpy.types.register(VIEW3D_MT_view_navigation)
  bpy.types.register(VIEW3D_MT_view_align)
++bpy.types.register(VIEW3D_MT_view_align_selected)
  bpy.types.register(VIEW3D_MT_view_cameras)
  
  bpy.types.register(VIEW3D_MT_select_object) # Select Menus
Simple merge
Simple merge
index fa0db751c00142ffd1c906646abe7ba9697380a6,f178553d796c20372e6b11bce063a88a74985c6f..1c85a5e3a9a48161d24d5f65cef6fcdaf780bda7
  
  #include "MEM_guardedalloc.h"
  
- //XXX #include "nla.h"
  #include "BLI_arithb.h"
  #include "BLI_blenlib.h"
 +#include "BLI_cellalloc.h"
  
  #include "DNA_armature_types.h"
  #include "DNA_action_types.h"
index aff056ffebcfc64e7a9d702bba8c06fa20556737,1f4f69bd376ffd09ff6efc751d13cba67a97b0a7..8e3a6174c55948720f2a215a08111244795a2209
@@@ -3402,11 -4202,11 +3395,11 @@@ static DerivedMesh *decimateModifier_ap
                        }
  
                        if(lod.vertex_num>2) {
--                              result = CDDM_new(lod.vertex_num, 0, lod.face_num);
++                              result = CDDM_new(lod.vertex_num, 0, lod.face_num, 0, 0);
                                dmd->faceCount = lod.face_num;
                        }
                        else
--                              result = CDDM_new(lod.vertex_num, 0, 0);
++                              result = CDDM_new(lod.vertex_num, 0, 0, 0, 0);
  
                        mvert = CDDM_get_verts(result);
                        for(a=0; a<lod.vertex_num; a++) {
  
                        CDDM_calc_edges(result);
                        CDDM_calc_normals(result);
++                      CDDM_tessfaces_to_faces(result);
                }
                else
                        modifier_setError(md, "Out of memory.");
@@@ -7061,8 -7848,8 +7045,9 @@@ static void meshdeformModifier_do
        float (*vertexCos)[3], int numVerts)
  {
        MeshDeformModifierData *mmd = (MeshDeformModifierData*) md;
-       Mesh *me= ob->data;
+       Mesh *me= (mmd->object)? mmd->object->data: NULL;
+       EditMesh *em = (me)? BKE_mesh_get_editmesh(me): NULL;
 +      BMEditMesh *bem = me->edit_btmesh;
        DerivedMesh *tmpdm, *cagedm;
        MDeformVert *dvert = NULL;
        MDeformWeight *dw;
index be68ebbdaedfb281ab5d8c111ff3a82225774839,6e986325f551b70efce0858375e5b7ff3b400236..94b9cfcdf537e5efeb3ef477b5e66b472d023346
@@@ -2075,10 -2071,24 +2072,24 @@@ static void sb_spring_force(Object *ob,
                forcefactor = iks/bs->len;
        else
                forcefactor = iks;
 -      kw = (bp1->springweight+bp2->springweight)/2.0f;
 -      kw = kw * kw;
 -      kw = kw * kw;
 +          kw = (bp1->springweight+bp2->springweight)/2.0f;
 +              kw = kw * kw;
 +              kw = kw * kw;
-       forcefactor *= bs->strength * kw; 
+       switch (bs->springtype){
+               case SB_EDGE:
+                       forcefactor *=  kw; 
+                       break;
+               case SB_BEND:
+                       forcefactor *=sb->secondspring*kw; 
+                       break;
+               case SB_STIFFQUAD:
+                       forcefactor *=sb->shearstiff*sb->shearstiff* kw; 
+                       break;
+               default:
+                       break;
+       }
        Vec3PlusStVec(bp1->force,(bs->len - distance)*forcefactor,dir);
  
        /* do bp1 <--> bp2 viscous */
@@@ -3770,7 -3768,15 +3769,15 @@@ static void softbody_step(Scene *scene
  {
        /* the simulator */
        float forcetime;
-       double sct,sst=PIL_check_seconds_timer();
+       double sct,sst;
 -              
++      
+               
+       sst=PIL_check_seconds_timer();
+       /* Integration back in time is possible in theory, but pretty useless here. 
+       So we refuse to do so. Since we do not know anything about 'outside' canges
+       especially colliders we refuse to go more than 10 frames.
+       */
+       if(dtime < 0 || dtime > 10.5f) return; 
        
        ccd_update_deflector_hash(scene, ob, sb->scratch->colliderhash);
  
index 46d31ed47aaee66824009d04cfb46831603b18e4,16da7d25721e1fb732bdb507f9b519101aee9b03..2658bcbd14f1561a023b9d5fa72d8cc4826f02fc
@@@ -320,6 -320,10 +320,7 @@@ void Mat3Clr(float *m)
  void Mat3One(float m[][3]);
  void Mat4One(float m[][4]);
  
 -void Mat3Scale(float m[][3], float scale);
 -void Mat4Scale(float m[][4], float scale);
 -
+ /* NOTE: These only normalise the matrix, they don't make it orthogonal */
  void Mat3Ortho(float mat[][3]);
  void Mat4Ortho(float mat[][4]);
  
index a5c4a03cdd62e8ca90608ba497bd8c7e065ba181,874756135e59ac3279f68f5f9a3dfd577ffb63ff..c98f4a14fea6eabb6782fd5e3db53419c7be269a
@@@ -131,26 -131,7 +131,27 @@@ float Normalize(float *n
        return d;
  }
  
 +/*original function from shadeoutput.c*/
 +double Normalize_d(double *n)
 +{
 +      double d;
 +      
 +      d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
 +
 +      if(d>0.00000000000000001) {
 +              d= sqrt(d);
 +
 +              n[0]/=d; 
 +              n[1]/=d; 
 +              n[2]/=d;
 +      } else {
 +              n[0]=n[1]=n[2]= 0.0;
 +              d= 0.0;
 +      }
 +      return d;
 +}
 +
+ /* Crossf stores the cross product c = a x b */
  void Crossf(float *c, float *a, float *b)
  {
        c[0] = a[1] * b[2] - a[2] * b[1];
index d6cc785b146d053ccc69b6484a94f0f02ac7673b,00f7cbd9eebfbe99c99e4b345b294ed6f49aed10..7ca07fc13cef6f47adc7395d2d2ffc1aca1bd807
@@@ -2289,6 -2302,11 +2303,11 @@@ static void direct_link_constraints(Fil
                        if (data->prop)
                                IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                }
 -              }
+               else if (cons->type == CONSTRAINT_TYPE_SPLINEIK) {
+                       bSplineIKConstraint *data= cons->data;
+                       
+                       data->points= newdataadr(fd, data->points);
++      }
        }
  }
  
index 14b99dd7ae5c944eb3f401a4ca9bbeae53e084d3,8ec12496e5928fcf3c413068de961bb6a8dc64de..dcbdb3884ec99fa7966e3d66a642c406b01b809e
@@@ -1077,8 -1077,16 +1077,16 @@@ static void write_constraints(WriteDat
                                         of library blocks that implement this.*/
                                        IDP_WriteProperty(data->prop, wd);
                                }
 -                                      break;
 +                              break;
+                               case CONSTRAINT_TYPE_SPLINEIK: 
+                               {
+                                       bSplineIKConstraint *data= (bSplineIKConstraint*)con->data;
+                                       
+                                       /* write points array */
+                                       writedata(wd, DATA, sizeof(float)*(data->numpoints), data->points);
 -                              }
 -                                      break;
                        }
++                                      break;
++              }
                }
                
                /* Write the constraint */
index bf3fd0f4cf1bcf17977b5af0b59112519a79ae12,5c2cbce4c5d55949da4255023ecd0b6f36f5d4bd..87760d2da5eb16ca719432d9de02aa77ced8ab94
@@@ -155,40 -156,49 +156,49 @@@ short ANIM_add_driver (ID *id, const ch
                return 0;
        }
        
 -              /* create F-Curve with Driver */
 -              fcu= verify_driver_fcurve(id, rna_path, array_index, 1);
+       /* key entire array convenience method */
+       if (array_index == -1) {
+               array_index= 0;
+               array_index_max= RNA_property_array_length(&ptr, prop) + 1;
+       }
+       
+       /* will only loop once unless the array index was -1 */
+       for (; array_index < array_index_max; array_index++) {
 +      /* create F-Curve with Driver */
 +      fcu= verify_driver_fcurve(id, rna_path, array_index, 1);
 -              if (fcu && fcu->driver) {
 -                      fcu->driver->type= type;
+               
 +      if (fcu && fcu->driver) {
 +              fcu->driver->type= type;
 +              
 +              /* fill in current value for python */
 +              if (type == DRIVER_TYPE_PYTHON) {
 +                      PropertyType proptype= RNA_property_type(prop);
 +                      int array= RNA_property_array_length(&ptr, prop);
 +                      char *expression= fcu->driver->expression;
 +                      int val, maxlen= sizeof(fcu->driver->expression);
 +                      float fval;
                        
 -                      /* fill in current value for python */
 -                      if (type == DRIVER_TYPE_PYTHON) {
 -                              PropertyType proptype= RNA_property_type(prop);
 -                              int array= RNA_property_array_length(&ptr, prop);
 -                              char *expression= fcu->driver->expression;
 -                              int val, maxlen= sizeof(fcu->driver->expression);
 -                              float fval;
 +                      if (proptype == PROP_BOOLEAN) {
 +                              if (!array) val= RNA_property_boolean_get(&ptr, prop);
 +                              else val= RNA_property_boolean_get_index(&ptr, prop, array_index);
                                
 -                              if (proptype == PROP_BOOLEAN) {
 -                                      if (!array) val= RNA_property_boolean_get(&ptr, prop);
 -                                      else val= RNA_property_boolean_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_strncpy(expression, (val)? "True": "False", maxlen);
 -                              }
 -                              else if (proptype == PROP_INT) {
 -                                      if (!array) val= RNA_property_int_get(&ptr, prop);
 -                                      else val= RNA_property_int_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_snprintf(expression, maxlen, "%d", val);
 -                              }
 -                              else if (proptype == PROP_FLOAT) {
 -                                      if (!array) fval= RNA_property_float_get(&ptr, prop);
 -                                      else fval= RNA_property_float_get_index(&ptr, prop, array_index);
 -                                      
 -                                      BLI_snprintf(expression, maxlen, "%.3f", fval);
 -                              }
 +                              BLI_strncpy(expression, (val)? "True": "False", maxlen);
 +                      }
 +                      else if (proptype == PROP_INT) {
 +                              if (!array) val= RNA_property_int_get(&ptr, prop);
 +                              else val= RNA_property_int_get_index(&ptr, prop, array_index);
 +                              
 +                              BLI_snprintf(expression, maxlen, "%d", val);
 +                      }
 +                      else if (proptype == PROP_FLOAT) {
 +                              if (!array) fval= RNA_property_float_get(&ptr, prop);
 +                              else fval= RNA_property_float_get_index(&ptr, prop, array_index);
 +                              
 +                              BLI_snprintf(expression, maxlen, "%.3f", fval);
                        }
                }
        }
++      }
        
        /* done */
        return (fcu != NULL);
@@@ -366,19 -379,9 +379,9 @@@ static int add_driver_button_exec (bCon
        if (ptr.data && prop && RNA_property_animateable(ptr.data, prop)) {
                path= RNA_path_from_ID_to_property(&ptr, prop);
                
-               if (path) {
-                       if (all) {
-                               length= RNA_property_array_length(&ptr, prop);
+               if (path) {                     
+                       success+= ANIM_add_driver(ptr.id.data, path, index, 0, DRIVER_TYPE_PYTHON);
 -                      
 +                              
-                               if (length) index= 0;
-                               else length= 1;
-                       }
-                       else
-                               length= 1;
-                       
-                       for (a=0; a<length; a++)
-                               success+= ANIM_add_driver(ptr.id.data, path, index+a, 0, DRIVER_TYPE_PYTHON);
-                       
                        MEM_freeN(path);
                }
        }
index 6a16d6d0ee1f306aa8f5fbbc64f53b4b1d4b81f8,0412ee89e517135ede0feccb2e6d2ba3b6b5ead8..42f6d881037eb1d3262723d92720e2a445396ed3
@@@ -827,9 -831,23 +831,23 @@@ short insert_keyframe (ID *id, bAction 
                //      cfra-= give_timeoffset(ob)*scene->r.framelen;
                //}
        }
+ #endif
+       
+       /* key entire array convenience method */
+       if (array_index == -1) { 
+               array_index= 0;
+               array_index_max= RNA_property_array_length(&ptr, prop) + 1;
+       }
        
 -              /* insert keyframe */
+       /* will only loop once unless the array index was -1 */
+       for (; array_index < array_index_max; array_index++) {
+               fcu= verify_fcurve(act, group, rna_path, array_index, 1);
+               
-       return insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
 +      /* insert keyframe */
+               ret += insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
+       }
+       
+       return ret;
  }
  
  /* ************************************************** */
index 331bd6fa28f7b867ba2f96b5e896aa2302f1aa43,696fa65b33a006e372aced1d2d61a709bcdcacbe..993f1e49e711478165b34de1e6599aef934ab237
@@@ -1334,18 -1333,12 +1333,12 @@@ static int pose_group_assign_exec (bCon
        
        /* add selected bones to group then */
        // NOTE: unfortunately, we cannot use the context-iterators here, since they might not be defined...
-       // CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) 
-       for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
-               /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
-               // NOTE: sync this view3d_context() in space_view3d.c
-               if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
-                       if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) {
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
 -              pchan->agrp_index= pose->active_group;
 -              done= 1;
 -      }
 +                              pchan->agrp_index= pose->active_group;
 +                              done= 1;
 +                      }
-               }
-       }
-       
+       CTX_DATA_END;
        /* notifiers for updates */
        WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
        
index e5f703e714e600e9c22aa141b0f0b84bca30acec,fa47426c70ac718218292ae099b2eac5c0123ba2..1cd685b5f32530f12d14f3633d0a60cd5c5edab5
@@@ -50,30 -51,21 +50,30 @@@ struct MCol
  struct UvVertMap;
  struct UvMapVert;
  struct CustomData;
 +struct BMEditSelection;
 +struct BMesh;
 +struct BMVert;
 +struct BMEdge;
 +struct BMFace;
 +struct UvVertMap;
 +struct UvMapVert;
  struct Material;
  struct Object;
- struct recti;
+ struct rcti;
  
 -#define EM_FGON_DRAW  1 // face flag
 -#define EM_FGON                       2 // edge and face flag both
 +// edge and face flag both
 +#define EM_FGON               2
 +// face flag
 +#define EM_FGON_DRAW  1
  
  /* editbutflag */
 -#define B_CLOCKWISE                   1
 -#define B_KEEPORIG                    2
 -#define B_BEAUTY                      4
 -#define B_SMOOTH                      8
 -#define B_BEAUTY_SHORT        0x10
 -#define B_AUTOFGON                    0x20
 -#define B_KNIFE                               0x80
 +#define B_CLOCKWISE           1
 +#define B_KEEPORIG            2
 +#define B_BEAUTY              4
 +#define B_SMOOTH              8
 +#define B_BEAUTY_SHORT        16
 +#define B_AUTOFGON            32
 +#define B_KNIFE                       0x80
  #define B_PERCENTSUBD         0x40
  //#define B_MESH_X_MIRROR             0x100 // deprecated, use mesh
  #define B_JOINTRIA_UV         0x200
index c963848b9234f9aa72c7b7801694eed0c2bbc344,f085e7054a3ff0aae9a91c944a4751ad7de4a18b..c689b5a73c7a872f961a63a71da173750ea6b735
@@@ -3446,8 -3582,11 +3582,11 @@@ static int ui_do_button(bContext *C, ui
  
                                }
                        }
 -                      }
+                       else if (ui_but_menu(C, but)) {
+                               return WM_UI_HANDLER_BREAK;
                }
        }
++      }
  
        /* verify if we can edit this button */
        if(ELEM(event->type, LEFTMOUSE, RETKEY)) {
index 9c4829a9d7a3768e3d9435ff14215cb98edf7074,0000000000000000000000000000000000000000..354c638817cc7797ad2cf7dd2db1a0c754bcbd75
mode 100644,000000..100644
--- /dev/null
@@@ -1,3372 -1,0 +1,3610 @@@
-       int i, types[3] = {BM_VERTS_OF_MESH, BM_EDGES_OF_MESH, BM_FACES_OF_MESH};
 + /* $Id: bmesh_tools.c
 + *
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 + *
 + * The Original Code is Copyright (C) 2004 by Blender Foundation.
 + * All rights reserved.
 + *
 + * The Original Code is: all of this file.
 + *
 + * Contributor(s): Joseph Eagar
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +#include <stdlib.h>
 +#include <stdarg.h>
 +#include <string.h>
 +#include <math.h>
 +#include <float.h>
 +
 +#include "MEM_guardedalloc.h"
 +#include "PIL_time.h"
 +
 +#include "BLO_sys_types.h" // for intptr_t support
 +
 +#include "DNA_mesh_types.h"
 +#include "DNA_material_types.h"
 +#include "DNA_meshdata_types.h"
 +#include "DNA_modifier_types.h"
 +#include "DNA_object_types.h"
 +#include "DNA_scene_types.h"
 +#include "DNA_screen_types.h"
 +#include "DNA_view3d_types.h"
 +#include "DNA_key_types.h"
 +#include "DNA_windowmanager_types.h"
 +
 +#include "RNA_types.h"
 +#include "RNA_define.h"
 +#include "RNA_access.h"
 +
 +#include "BLI_blenlib.h"
 +#include "BLI_arithb.h"
 +#include "BLI_editVert.h"
 +#include "BLI_rand.h"
 +#include "BLI_ghash.h"
 +#include "BLI_linklist.h"
 +#include "BLI_heap.h"
 +#include "BLI_array.h"
 +
 +#include "BKE_context.h"
 +#include "BKE_customdata.h"
 +#include "BKE_depsgraph.h"
 +#include "BKE_global.h"
 +#include "BKE_library.h"
 +#include "BKE_mesh.h"
 +#include "BKE_object.h"
 +#include "BKE_utildefines.h"
 +#include "BKE_bmesh.h"
 +#include "BKE_report.h"
 +#include "BKE_tessmesh.h"
 +
 +#include "BIF_gl.h"
 +#include "BIF_glutil.h"
 +
 +#include "WM_api.h"
 +#include "WM_types.h"
 +
 +#include "ED_mesh.h"
 +#include "ED_view3d.h"
 +#include "ED_util.h"
 +#include "ED_screen.h"
 +#include "ED_transform.h"
 +
 +#include "UI_interface.h"
 +
 +#include "mesh_intern.h"
 +#include "bmesh.h"
 +
 +#include "editbmesh_bvh.h"
 +
 +static void add_normal_aligned(float *nor, float *add)
 +{
 +      if( INPR(nor, add) < -0.9999f)
 +              VecSubf(nor, nor, add);
 +      else
 +              VecAddf(nor, nor, add);
 +}
 +
 +
 +static int subdivide_exec(bContext *C, wmOperator *op)
 +{
 +      ToolSettings *ts = CTX_data_tool_settings(C);
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
 +      int cuts= RNA_int_get(op->ptr,"number_cuts");
 +      float smooth= 0.292f*RNA_float_get(op->ptr, "smoothness");
 +      float fractal= RNA_float_get(op->ptr, "fractal")/100;
 +      int flag= 0;
 +
 +      if(smooth != 0.0f)
 +              flag |= B_SMOOTH;
 +      if(fractal != 0.0f)
 +              flag |= B_FRACTAL;
 +
 +      BM_esubdivideflag(obedit, em->bm, BM_SELECT, 
 +                        smooth, fractal, 
 +                        ts->editbutflag|flag, 
 +                        cuts, 0, RNA_enum_get(op->ptr, "quadcorner"), 
 +                        RNA_boolean_get(op->ptr, "tess_single_edge"),
 +                        RNA_boolean_get(op->ptr, "gridfill"));
 +
 +      DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +/* Note, these values must match delete_mesh() event values */
 +static EnumPropertyItem prop_mesh_cornervert_types[] = {
 +      {SUBD_INNERVERT,     "INNERVERT", 0,      "Inner Vert", ""},
 +      {SUBD_PATH,          "PATH", 0,           "Path", ""},
 +      {SUBD_STRAIGHT_CUT,  "STRAIGHT_CUT", 0,   "Straight Cut", ""},
 +      {SUBD_FAN,           "FAN", 0,            "Fan", ""},
 +      {0, NULL, 0, NULL, NULL}
 +};
 +
 +void MESH_OT_subdivide(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Subdivide";
 +      ot->description= "Subdivide selected edges.";
 +      ot->idname= "MESH_OT_subdivide";
 +
 +      /* api callbacks */
 +      ot->exec= subdivide_exec;
 +      ot->poll= ED_operator_editmesh;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* properties */
 +      RNA_def_int(ot->srna, "number_cuts", 1, 1, 20, "Number of Cuts", "", 1, INT_MAX);
 +      RNA_def_float(ot->srna, "fractal", 0.0, 0.0f, FLT_MAX, "Fractal", "Fractal randomness factor.", 0.0f, 1000.0f);
 +      RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, 1000.0f, "Smoothness", "Smoothness factor.", 0.0f, FLT_MAX);
 +
 +      /*props */
 +      RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_STRAIGHT_CUT, "Quad Corner Type", "Method used for subdividing two adjacent edges in a quad");
 +      RNA_def_boolean(ot->srna, "tess_single_edge", 0, "Tesselate Single Edge", "Adds triangles to single edges belonging to triangles or quads");
 +      RNA_def_boolean(ot->srna, "gridfill", 1, "Grid Fill", "Fill Fully Selected Triangles and Quads With A Grid");
 +}
 +
 +/* individual face extrude */
 +/* will use vertex normals for extrusion directions, so *nor is unaffected */
 +short EDBM_Extrude_face_indiv(BMEditMesh *em, wmOperator *op, short flag, float *nor) 
 +{
 +      BMOIter siter;
 +      BMIter liter;
 +      BMFace *f;
 +      BMLoop *l;
 +      BMOperator bmop;
 +
 +      EDBM_InitOpf(em, &bmop, op, "extrude_face_indiv faces=%hf", flag);
 +
 +      /*deselect original verts*/
 +      EDBM_clear_flag_all(em, BM_SELECT);
 +
 +      BMO_Exec_Op(em->bm, &bmop);
 +      
 +      BMO_ITER(f, &siter, em->bm, &bmop, "faceout", BM_FACE) {
 +              BM_Select(em->bm, f, 1);
 +
 +              /*set face vertex normals to face normal*/
 +              BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) {
 +                      VECCOPY(l->v->no, f->no);
 +              }
 +      }
 +
 +      if (!EDBM_FinishOp(em, &bmop, op, 1)) return 0;
 +
 +      return 's'; // s is shrink/fatten
 +}
 +
 +#if 0
 +short EDBM_Extrude_face_indiv(BMEditMesh *em, wmOperator *op, short flag, float *nor) 
 +      EditVert *eve, *v1, *v2, *v3, *v4;
 +      EditEdge *eed;
 +      EditFace *efa, *nextfa;
 +      
 +      if(em==NULL) return 0;
 +      
 +      /* selected edges with 1 or more selected face become faces */
 +      /* selected faces each makes new faces */
 +      /* always remove old faces, keeps volumes manifold */
 +      /* select the new extrusion, deselect old */
 +      
 +      /* step 1; init, count faces in edges */
 +      recalc_editnormals(em);
 +      
 +      for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;      // new select flag
 +
 +      for(eed= em->edges.first; eed; eed= eed->next) {
 +              eed->f2= 0; // amount of unselected faces
 +      }
 +      for(efa= em->faces.first; efa; efa= efa->next) {
 +              if(efa->f & SELECT);
 +              else {
 +                      efa->e1->f2++;
 +                      efa->e2->f2++;
 +                      efa->e3->f2++;
 +                      if(efa->e4) efa->e4->f2++;
 +              }
 +      }
 +
 +      /* step 2: make new faces from faces */
 +      for(efa= em->faces.last; efa; efa= efa->prev) {
 +              if(efa->f & SELECT) {
 +                      v1= addvertlist(em, efa->v1->co, efa->v1);
 +                      v2= addvertlist(em, efa->v2->co, efa->v2);
 +                      v3= addvertlist(em, efa->v3->co, efa->v3);
 +                      
 +                      v1->f1= v2->f1= v3->f1= 1;
 +                      VECCOPY(v1->no, efa->n);
 +                      VECCOPY(v2->no, efa->n);
 +                      VECCOPY(v3->no, efa->n);
 +                      if(efa->v4) {
 +                              v4= addvertlist(em, efa->v4->co, efa->v4); 
 +                              v4->f1= 1;
 +                              VECCOPY(v4->no, efa->n);
 +                      }
 +                      else v4= NULL;
 +                      
 +                      /* side faces, clockwise */
 +                      addfacelist(em, efa->v2, v2, v1, efa->v1, efa, NULL);
 +                      addfacelist(em, efa->v3, v3, v2, efa->v2, efa, NULL);
 +                      if(efa->v4) {
 +                              addfacelist(em, efa->v4, v4, v3, efa->v3, efa, NULL);
 +                              addfacelist(em, efa->v1, v1, v4, efa->v4, efa, NULL);
 +                      }
 +                      else {
 +                              addfacelist(em, efa->v1, v1, v3, efa->v3, efa, NULL);
 +                      }
 +                      /* top face */
 +                      addfacelist(em, v1, v2, v3, v4, efa, NULL);
 +              }
 +      }
 +      
 +      /* step 3: remove old faces */
 +      efa= em->faces.first;
 +      while(efa) {
 +              nextfa= efa->next;
 +              if(efa->f & SELECT) {
 +                      BLI_remlink(&em->faces, efa);
 +                      free_editface(em, efa);
 +              }
 +              efa= nextfa;
 +      }
 +
 +      /* step 4: redo selection */
 +      EM_clear_flag_all(em, SELECT);
 +      
 +      for(eve= em->verts.first; eve; eve= eve->next) {
 +              if(eve->f1)  eve->f |= SELECT;
 +      }
 +      
 +      EM_select_flush(em);
 +      
 +      return 'n';
 +}
 +#endif
 +
 +/* extrudes individual edges */
 +short EDBM_Extrude_edges_indiv(BMEditMesh *em, wmOperator *op, short flag, float *nor) 
 +{
 +      BMOperator bmop;
 +
 +      EDBM_InitOpf(em, &bmop, op, "extrude_edge_only edges=%he", flag);
 +
 +      /*deselect original verts*/
 +      EDBM_clear_flag_all(em, BM_SELECT);
 +
 +      BMO_Exec_Op(em->bm, &bmop);
 +      BMO_HeaderFlag_Buffer(em->bm, &bmop, "geomout", BM_SELECT, BM_VERT|BM_EDGE);
 +
 +      if (!EDBM_FinishOp(em, &bmop, op, 1)) return 0;
 +
 +      return 'n'; // n is normal grab
 +}
 +
 +#if 0
 +/* nor is filled with constraint vector */
 +short EDBM_Extrude_edges_indiv(BMEditMesh *em, short flag, float *nor) 
 +{
 +      EditVert *eve;
 +      EditEdge *eed;
 +      EditFace *efa;
 +      
 +      for(eve= em->verts.first; eve; eve= eve->next) eve->tmp.v = NULL;
 +      for(eed= em->edges.first; eed; eed= eed->next) {
 +              eed->tmp.f = NULL;
 +              eed->f2= ((eed->f & flag)!=0);
 +      }
 +      
 +      set_edge_directions_f2(em, 2);
 +
 +      /* sample for next loop */
 +      for(efa= em->faces.first; efa; efa= efa->next) {
 +              efa->e1->tmp.f = efa;
 +              efa->e2->tmp.f = efa;
 +              efa->e3->tmp.f = efa;
 +              if(efa->e4) efa->e4->tmp.f = efa;
 +      }
 +      /* make the faces */
 +      for(eed= em->edges.first; eed; eed= eed->next) {
 +              if(eed->f & flag) {
 +                      if(eed->v1->tmp.v == NULL)
 +                              eed->v1->tmp.v = addvertlist(em, eed->v1->co, eed->v1);
 +                      if(eed->v2->tmp.v == NULL)
 +                              eed->v2->tmp.v = addvertlist(em, eed->v2->co, eed->v2);
 +
 +                      if(eed->dir==1) 
 +                              addfacelist(em, eed->v1, eed->v2, 
 +                                                      eed->v2->tmp.v, eed->v1->tmp.v, 
 +                                                      eed->tmp.f, NULL);
 +                      else 
 +                              addfacelist(em, eed->v2, eed->v1, 
 +                                                      eed->v1->tmp.v, eed->v2->tmp.v, 
 +                                                      eed->tmp.f, NULL);
 +
 +                      /* for transform */
 +                      if(eed->tmp.f) {
 +                              efa = eed->tmp.f;
 +                              if (efa->f & SELECT) add_normal_aligned(nor, efa->n);
 +                      }
 +              }
 +      }
 +      Normalize(nor);
 +      
 +      /* set correct selection */
 +      EM_clear_flag_all(em, SELECT);
 +      for(eve= em->verts.last; eve; eve= eve->prev) {
 +              if(eve->tmp.v) {
 +                      eve->tmp.v->f |= flag;
 +              }
 +      }
 +
 +      for(eed= em->edges.first; eed; eed= eed->next) {
 +              if(eed->v1->f & eed->v2->f & flag) eed->f |= flag;
 +      }
 +      
 +      if(nor[0]==0.0 && nor[1]==0.0 && nor[2]==0.0) return 'g'; // g is grab
 +      return 'n';  // n is for normal constraint
 +}
 +#endif
 +
 +/* extrudes individual vertices */
 +short EDBM_Extrude_verts_indiv(BMEditMesh *em, wmOperator *op, short flag, float *nor) 
 +{
 +      BMOperator bmop;
 +
 +      EDBM_InitOpf(em, &bmop, op, "extrude_vert_indiv verts=%hv", flag);
 +
 +      /*deselect original verts*/
 +      BMO_UnHeaderFlag_Buffer(em->bm, &bmop, "verts", BM_SELECT, BM_VERT);
 +
 +      BMO_Exec_Op(em->bm, &bmop);
 +      BMO_HeaderFlag_Buffer(em->bm, &bmop, "vertout", BM_SELECT, BM_VERT);
 +
 +      if (!EDBM_FinishOp(em, &bmop, op, 1)) return 0;
 +
 +      return 'g'; // g is grab
 +}
 +
 +short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, int flag, float *nor)
 +{
 +      BMesh *bm = em->bm;
 +      BMIter iter;
 +      BMOIter siter;
 +      BMOperator extop;
 +      BMVert *vert;
 +      BMEdge *edge;
 +      BMFace *f;
 +      ModifierData *md;
 +      BMHeader *el;
 +      
 +      BMO_Init_Op(&extop, "extrudefaceregion");
 +      BMO_HeaderFlag_To_Slot(bm, &extop, "edgefacein",
 +                             flag, BM_VERT|BM_EDGE|BM_FACE);
 +
 +      /* If a mirror modifier with clipping is on, we need to adjust some 
 +       * of the cases above to handle edges on the line of symmetry.
 +       */
 +      md = obedit->modifiers.first;
 +      for (; md; md=md->next) {
 +              if (md->type==eModifierType_Mirror) {
 +                      MirrorModifierData *mmd = (MirrorModifierData*) md;     
 +              
 +                      if(mmd->flag & MOD_MIR_CLIPPING) {
 +                              float mtx[4][4];
 +                              if (mmd->mirror_ob) {
 +                                      float imtx[4][4];
 +                                      Mat4Invert(imtx, mmd->mirror_ob->obmat);
 +                                      Mat4MulMat4(mtx, obedit->obmat, imtx);
 +                              }
 +
 +                              for (edge=BMIter_New(&iter,bm,BM_EDGES_OF_MESH,NULL);
 +                                   edge; edge=BMIter_Step(&iter))
 +                              {
 +                                      if(edge->head.flag & flag) {
 +                                              float co1[3], co2[3];
 +
 +                                              VecCopyf(co1, edge->v1->co);
 +                                              VecCopyf(co2, edge->v2->co);
 +
 +                                              if (mmd->mirror_ob) {
 +                                                      VecMat4MulVecfl(co1, mtx, co1);
 +                                                      VecMat4MulVecfl(co2, mtx, co2);
 +                                              }
 +
 +                                              if (mmd->flag & MOD_MIR_AXIS_X)
 +                                                      if ( (fabs(co1[0]) < mmd->tolerance) &&
 +                                                               (fabs(co2[0]) < mmd->tolerance) )
 +                                                              BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL);
 +
 +                                              if (mmd->flag & MOD_MIR_AXIS_Y)
 +                                                      if ( (fabs(co1[1]) < mmd->tolerance) &&
 +                                                               (fabs(co2[1]) < mmd->tolerance) )
 +                                                              BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL);
 +
 +                                              if (mmd->flag & MOD_MIR_AXIS_Z)
 +                                                      if ( (fabs(co1[2]) < mmd->tolerance) &&
 +                                                               (fabs(co2[2]) < mmd->tolerance) )
 +                                                              BMO_Insert_MapPointer(bm, &extop, "exclude", edge, NULL);
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      BM_ITER(vert, &iter, bm, BM_VERTS_OF_MESH, NULL) {
 +              BM_Select(bm, vert, 0);
 +      }
 +
 +      BM_ITER(edge, &iter, bm, BM_EDGES_OF_MESH, NULL) {
 +              BM_Select(bm, edge, 0);
 +      }
 +
 +      BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
 +              BM_Select(bm, f, 0);
 +      }
 +
 +      BMO_Exec_Op(bm, &extop);
 +
 +      nor[0] = nor[1] = nor[2] = 0.0f;
 +      
 +      BMO_ITER(el, &siter, bm, &extop, "geomout", BM_ALL) {
 +              BM_Select(bm, el, 1);
 +
 +              if (el->type == BM_FACE) {
 +                      f = (BMFace*)el;
 +                      add_normal_aligned(nor, f->no);
 +              };
 +      }
 +
 +      Normalize(nor);
 +
 +      BMO_Finish_Op(bm, &extop);
 +
 +      if(nor[0]==0.0 && nor[1]==0.0 && nor[2]==0.0) return 'g'; // grab
 +      return 'n'; // normal constraint 
 +
 +}
 +short EDBM_Extrude_vert(Object *obedit, BMEditMesh *em, short flag, float *nor)
 +{
 +              BMIter iter;
 +              BMEdge *eed;
 +              
 +              /*ensure vert flags are consistent for edge selections*/
 +              eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL);
 +              for ( ; eed; eed=BMIter_Step(&iter)) {
 +                      if (BM_TestHFlag(eed, flag)) {
 +                              if (flag != BM_SELECT) {
 +                                      BM_SetHFlag(eed->v1, flag);
 +                                      BM_SetHFlag(eed->v2, flag);
 +                              } else {
 +                                      BM_Select(em->bm, eed->v1, 1);
 +                                      BM_Select(em->bm, eed->v2, 1);
 +                              }
 +                      } else {
 +                              if (BM_TestHFlag(eed->v1, flag) && BM_TestHFlag(eed->v2, flag)) {
 +                                      if (flag != BM_SELECT)
 +                                              BM_SetHFlag(eed, flag);
 +                                      else BM_Select(em->bm, eed, 1);
 +                              }
 +                      }
 +              }
 +
 +              return EDBM_Extrude_edge(obedit, em, flag, nor);
 +
 +}
 +
 +static int extrude_repeat_mesh(bContext *C, wmOperator *op)
 +{
 +      Object *obedit= CTX_data_edit_object(C);
 +      Scene *scene = CTX_data_scene(C);
 +      BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
 +      RegionView3D *rv3d = CTX_wm_region_view3d(C);           
 +              
 +      int steps = RNA_int_get(op->ptr,"steps");
 +      
 +      float offs = RNA_float_get(op->ptr,"offset");
 +      float dvec[3], tmat[3][3], bmat[3][3], nor[3]= {0.0, 0.0, 0.0};
 +      short a;
 +
 +      /* dvec */
 +      dvec[0]= rv3d->persinv[2][0];
 +      dvec[1]= rv3d->persinv[2][1];
 +      dvec[2]= rv3d->persinv[2][2];
 +      Normalize(dvec);
 +      dvec[0]*= offs;
 +      dvec[1]*= offs;
 +      dvec[2]*= offs;
 +
 +      /* base correction */
 +      Mat3CpyMat4(bmat, obedit->obmat);
 +      Mat3Inv(tmat, bmat);
 +      Mat3MulVecfl(tmat, dvec);
 +
 +      for(a=0; a<steps; a++) {
 +              EDBM_Extrude_edge(obedit, em, BM_SELECT, nor);
 +              //BMO_CallOpf(em->bm, "extrudefaceregion edgefacein=%hef", BM_SELECT);
 +              BMO_CallOpf(em->bm, "translate vec=%v verts=%hv", (float*)dvec, BM_SELECT);
 +              //extrudeflag(obedit, em, SELECT, nor);
 +              //translateflag(em, SELECT, dvec);
 +      }
 +      
 +      EDBM_RecalcNormals(em);
 +
 +      DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_extrude_repeat(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Extrude Repeat Mesh";
 +      ot->description= "Extrude selected vertices, edges or faces repeatedly.";
 +      ot->idname= "MESH_OT_extrude_repeat";
 +      
 +      /* api callbacks */
 +      ot->exec= extrude_repeat_mesh;
 +      ot->poll= ED_operator_editmesh;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +      
 +      /* props */
 +      RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, 100.0f, "Offset", "", 0.0f, FLT_MAX);
 +      RNA_def_int(ot->srna, "steps", 10, 0, 180, "Steps", "", 0, INT_MAX);
 +}
 +
 +/* generic extern called extruder */
 +int EDBM_Extrude_Mesh(Object *obedit, BMEditMesh *em, wmOperator *op, float *norin)
 +{
 +      Scene *scene= NULL;             // XXX CTX!
 +      short nr, transmode= 0;
 +      float stacknor[3] = {0.0f, 0.0f, 0.0f};
 +      float *nor = norin ? norin : stacknor;
 +
 +      nor[0] = nor[1] = nor[2] = 0.0f;
 +
 +      if(em->selectmode & SCE_SELECT_VERTEX) {
 +              if(em->bm->totvertsel==0) nr= 0;
 +              else if(em->bm->totvertsel==1) nr= 4;
 +              else if(em->bm->totedgesel==0) nr= 4;
 +              else if(em->bm->totfacesel==0) 
 +                      nr= 3; // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4");
 +              else if(em->bm->totfacesel==1)
 +                      nr= 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4");
 +              else 
 +                      nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4");
 +      }
 +      else if(em->selectmode & SCE_SELECT_EDGE) {
 +              if (em->bm->totedgesel==0) nr = 0;
 +              
 +              nr = 1;
 +              /*else if (em->totedgesel==1) nr = 3;
 +              else if(em->totfacesel==0) nr = 3;
 +              else if(em->totfacesel==1)
 +                      nr= 1; // pupmenu("Extrude %t|Region %x1|Only Edges%x3");
 +              else
 +                      nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3");
 +              */
 +      }
 +      else {
 +              if (em->bm->totfacesel == 0) nr = 0;
 +              else if (em->bm->totfacesel == 1) nr = 1;
 +              else
 +                      nr= 1; // pupmenu("Extrude %t|Region %x1||Individual Faces %x2");
 +      }
 +
 +      if(nr<1) return 'g';
 +
 +      if(nr==1 && em->selectmode & SCE_SELECT_VERTEX) 
 +              transmode= EDBM_Extrude_vert(obedit, em, SELECT, nor);
 +      else if (nr == 1) transmode= EDBM_Extrude_edge(obedit, em, SELECT, nor);
 +      else if(nr==4) transmode= EDBM_Extrude_verts_indiv(em, op, SELECT, nor);
 +      else if(nr==3) transmode= EDBM_Extrude_edges_indiv(em, op, SELECT, nor);
 +      else transmode= EDBM_Extrude_face_indiv(em, op, SELECT, nor);
 +      
 +      if(transmode==0) {
 +              BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude");
 +      }
 +      else {
 +              
 +                      /* We need to force immediate calculation here because 
 +                      * transform may use derived objects (which are now stale).
 +                      *
 +                      * This shouldn't be necessary, derived queries should be
 +                      * automatically building this data if invalid. Or something.
 +                      */
 +//            DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); 
 +              object_handle_update(scene, obedit);
 +
 +              /* individual faces? */
 +//            BIF_TransformSetUndo("Extrude");
 +              if(nr==2) {
 +//                    initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_MIRROR);
 +//                    Transform();
 +              }
 +              else {
 +//                    initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR);
 +                      if(transmode=='n') {
 +                              Mat4MulVecfl(obedit->obmat, nor);
 +                              VecSubf(nor, nor, obedit->obmat[3]);
 +//                            BIF_setSingleAxisConstraint(nor, "along normal");
 +                      }
 +//                    Transform();
 +              }
 +      }
 +      
 +      return transmode;
 +}
 +
 +/* extrude without transform */
 +static int mesh_extrude_region_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      
 +      EDBM_Extrude_Mesh(obedit, em, op, NULL);
 +      
 +      WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit);
 +      
 +      return OPERATOR_FINISHED;       
 +}
 +
 +static int mesh_extrude_region_invoke(bContext *C, wmOperator *op, wmEvent *event)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      float nor[3];
 +      int constraint_axis[3] = {0, 0, 1};
 +      int tmode;
 +
 +      tmode = EDBM_Extrude_edge(obedit, em, BM_SELECT, nor);
 +
 +      DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      RNA_enum_set(op->ptr, "proportional", 0);
 +      RNA_boolean_set(op->ptr, "mirror", 0);
 +
 +      if (tmode == 'n') {
 +              RNA_enum_set(op->ptr, "constraint_orientation", V3D_MANIP_NORMAL);
 +              RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
 +      }
 +      WM_operator_name_call(C, "TFM_OT_translate", WM_OP_INVOKE_REGION_WIN, op->ptr);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_extrude_region(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Extrude Region";
 +      ot->idname= "MESH_OT_extrude_region";
 +      
 +      /* api callbacks */
 +      ot->invoke= mesh_extrude_region_invoke;
 +      ot->exec= mesh_extrude_region_exec;
 +      ot->poll= ED_operator_editmesh;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* to give to transform */
 +      Properties_Proportional(ot);
 +      Properties_Constraints(ot);
 +      RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 +}
 +
 +static int mesh_extrude_verts_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      float nor[3];
 +
 +      EDBM_Extrude_verts_indiv(em, op, BM_SELECT, nor);
 +      
 +      WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit);
 +      
 +      return OPERATOR_FINISHED;       
 +}
 +
 +static int mesh_extrude_verts_invoke(bContext *C, wmOperator *op, wmEvent *event)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      float nor[3];
 +      int constraint_axis[3] = {0, 0, 1};
 +      int tmode;
 +
 +      tmode = EDBM_Extrude_verts_indiv(em, op, BM_SELECT, nor);
 +
 +      DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      RNA_enum_set(op->ptr, "proportional", 0);
 +      RNA_boolean_set(op->ptr, "mirror", 0);
 +
 +      if (tmode == 'n') {
 +              RNA_enum_set(op->ptr, "constraint_orientation", V3D_MANIP_NORMAL);
 +              RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
 +      }
 +      WM_operator_name_call(C, "TFM_OT_translate", WM_OP_INVOKE_REGION_WIN, op->ptr);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_extrude_verts_indiv(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Extrude Only Vertices";
 +      ot->idname= "MESH_OT_extrude_verts_indiv";
 +      
 +      /* api callbacks */
 +      ot->invoke= mesh_extrude_verts_invoke;
 +      ot->exec= mesh_extrude_verts_exec;
 +      ot->poll= ED_operator_editmesh;
 +      
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      /* to give to transform */
 +      Properties_Proportional(ot);
 +      Properties_Constraints(ot);
 +      RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 +}
 +
 +static int mesh_extrude_edges_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      float nor[3];
 +
 +      EDBM_Extrude_edges_indiv(em, op, BM_SELECT, nor);
 +      
 +      WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit);
 +      
 +      return OPERATOR_FINISHED;       
 +}
 +
 +static int mesh_extrude_edges_invoke(bContext *C, wmOperator *op, wmEvent *event)
 +{
 +      Scene *scene= CTX_data_scene(C);
 +      Object *obedit= CTX_data_edit_object(C);
 +      BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
 +      float nor[3];
 +      int