Added baking for softbodies.
[blender.git] / source / blender / src / space.c
index ac21a92399017681ded145ef3a9e1df0c2886edb..dadfbf0f0b23bb3997434082b2ed84f4590926ca 100644 (file)
 #include <config.h>
 #endif
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #ifdef INTERNATIONAL
@@ -81,6 +77,8 @@
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
+#include "BIF_spacetypes.h"  // first, nasty dependency with typedef
+
 #include "BIF_butspace.h"
 #include "BIF_drawimage.h"
 #include "BIF_drawseq.h"
@@ -93,6 +91,7 @@
 #include "BIF_editlattice.h"
 #include "BIF_editmesh.h"
 #include "BIF_editmode_undo.h"
+#include "BIF_editnla.h"
 #include "BIF_editoops.h"
 #include "BIF_editseq.h"
 #include "BIF_editsima.h"
 #include "BIF_meshtools.h"
 #include "BIF_mywindow.h"
 #include "BIF_oops.h"
+#include "BIF_outliner.h"
 #include "BIF_resources.h"
 #include "BIF_screen.h"
 #include "BIF_space.h"
-#include "BIF_spacetypes.h"
 #include "BIF_toets.h"
 #include "BIF_toolbox.h"
 #include "BIF_usiblender.h"
 
 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
 
+#include "PIL_time.h"
+
 #include "BPY_extern.h"
 
 #include "mydevice.h"
 #include "blendef.h"
 #include "datatoc.h"
 
+#include "BIF_transform.h"
+
+#include "BKE_depsgraph.h"
+
 #include "TPT_DependKludge.h"
 #ifdef NAN_TPT
 #include "BSE_trans_types.h"
@@ -470,7 +475,7 @@ void start_game(void)
 
        /* Restart BPY - unload the game engine modules. */
        BPY_end_python();
-       BPY_start_python();
+       BPY_start_python(0, NULL); /* argc, argv stored there already */
        BPY_post_start_python(); /* userpref path and menus init */
 
        restore_all_scene_cfra(scene_cfra_store);
@@ -523,7 +528,7 @@ static void align_view_to_selected(View3D *v3d)
        }
 }
 
-void select_children(Object *ob, int recursive)
+static void select_children(Object *ob, int recursive)
 {
        Base *base;
 
@@ -535,7 +540,7 @@ void select_children(Object *ob, int recursive)
                }
 }
 
-void select_parent(void)       /* Makes parent active and de-selected OBACT */
+static void select_parent(void)        /* Makes parent active and de-selected OBACT */
 {
        Base *base, *startbase, *basact=NULL, *oldbasact;
        
@@ -548,16 +553,19 @@ void select_parent(void)  /* Makes parent active and de-selected OBACT */
        while(base) {
                if(base->object==BASACT->object->parent) { basact=base; break; }
                base=base->next;
-               if(base==0) base= FIRSTBASE;
+               if(base==NULL) base= FIRSTBASE;
                if(base==startbase) break;
        }
-       oldbasact = BASACT;
-       BASACT = basact;
-       basact->flag |= SELECT;         
-       
-       basact->object->flag= basact->flag;
-       
-       set_active_base(basact);
+       /* can be NULL if parent in other scene */
+       if(basact) {
+               oldbasact = BASACT;
+               BASACT = basact;
+               basact->flag |= SELECT;         
+               
+               basact->object->flag= basact->flag;
+               
+               set_active_base(basact);
+       }
 }
 
 
@@ -629,8 +637,12 @@ void BIF_undo_push(char *str)
                        undo_push_mesh(str);
                else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
                        undo_push_curve(str);
+               else if (G.obedit->type==OB_FONT)
+                       undo_push_font(str);
                else if (G.obedit->type==OB_MBALL)
                        undo_push_mball(str);
+               else if (G.obedit->type==OB_LATTICE)
+                       undo_push_lattice(str);
        }
        else {
                if(U.uiflag & USER_GLOBALUNDO) 
@@ -641,22 +653,16 @@ void BIF_undo_push(char *str)
 void BIF_undo(void)
 {      
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_step(1);
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_step(1);
-               else if (G.obedit->type==OB_MBALL)
-                       undo_editmode_step(1);
-                       
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
                else {
+                       /* now also in faceselect mode */
                        if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(1);
                }
        }
@@ -665,22 +671,16 @@ void BIF_undo(void)
 void BIF_redo(void)
 {
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_step(-1);
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_step(-1);
-               else if (G.obedit->type==OB_MBALL)
-                       undo_editmode_step(-1);
-       
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
                else {
+                       /* includes faceselect now */
                        if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(-1);
                }
        }
@@ -689,36 +689,36 @@ void BIF_redo(void)
 void BIF_undo_menu(void)
 {
        if(G.obedit) {
-               if(G.obedit->type==OB_MESH)
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
                        undo_editmode_menu();
-               else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                       undo_editmode_menu();
-               else if (G.obedit->type==OB_MBALL)
-                       undo_editmode_menu();
-               
                allqueue(REDRAWALL, 0);
        }
        else {
-               if (G.f & G_FACESELECT)
-                       ;
-               else if(G.f & G_WEIGHTPAINT)
+               if(G.f & G_WEIGHTPAINT)
                        ;
                else if(G.f & G_VERTEXPAINT)
                        ;
                else {
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_menu();
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               char *menu= BKE_undo_menu_string();
+                               if(menu) {
+                                       short event= pupmenu_col(menu, 20);
+                                       MEM_freeN(menu);
+                                       if(event>0) BKE_undo_number(event);
+                               }
+                       }
                }
        }
 }
 
 /* *************** */
 
-void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
        char ascii= evt->ascii;
-       View3D *v3d= curarea->spacedata.first;
+       View3D *v3d= sa->spacedata.first;
        Object *ob;
        float *curs;
        int doredraw= 0, pupval;
@@ -732,13 +732,13 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                
                if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
                
+               /* we consider manupilator a button, defaulting to leftmouse */
+               if(event==LEFTMOUSE) if(BIF_do_manipulator(sa)) return;
+               
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
-                               event = RIGHTMOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
-                               event = LEFTMOUSE;
-                       }
+                       if (event==LEFTMOUSE) event = RIGHTMOUSE;
+                       else if (event==RIGHTMOUSE) event = LEFTMOUSE;
                }
                
                /* TEXTEDITING?? */
@@ -1056,6 +1056,34 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                do_layer_buttons(11); break;
                        case ACCENTGRAVEKEY:
                                do_layer_buttons(-1); break;
+                       
+                       case SPACEKEY:
+                               if(G.qual == LR_CTRLKEY) {
+                                       val= pupmenu("Manipulator%t|Enable/Disable|Translate|Rotate|Scale|Combo");
+                                       if(val>0) {
+                                               if(val==1) v3d->twflag ^= V3D_USE_MANIPULATOR;
+                                               else {
+                                                       if(val==2) v3d->twtype= V3D_MANIP_TRANSLATE;
+                                                       else if(val==3) v3d->twtype= V3D_MANIP_ROTATE;
+                                                       else if(val==4) v3d->twtype= V3D_MANIP_SCALE;
+                                                       else if(val==5) v3d->twtype= V3D_MANIP_TRANSLATE|V3D_MANIP_ROTATE|V3D_MANIP_SCALE;
+                                                       v3d->twflag |= V3D_USE_MANIPULATOR;
+                                               }
+                                               doredraw= 1;
+                                       }
+                               }
+                               else if(G.qual == LR_ALTKEY) {
+                                       val= pupmenu("Manipulator Orientation%t|Global|Local|Normal");
+                                       if(val>0) {
+                                               if(val==1) v3d->twmode= V3D_MANIP_GLOBAL;
+                                               else if(val==2) v3d->twmode= V3D_MANIP_LOCAL;
+                                               else if(val==3) v3d->twmode= V3D_MANIP_NORMAL;
+                                               v3d->twflag |= V3D_USE_MANIPULATOR;
+                                               doredraw= 1;
+                                       }
+                               }
+
+                               break;
                                
                        case AKEY:
                                if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
@@ -1182,7 +1210,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
-                                               transform('e');
+                                               Transform(TFM_CREASE, CTX_EDGE);
                                        }
                                }
                                break;
@@ -1214,10 +1242,18 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
                                if((G.qual==LR_SHIFTKEY))
                                        select_group_menu();
-                               else if(G.qual==LR_ALTKEY)
-                                       clear_object('g');
-                               else if((G.qual==0))
-                                       transform('g');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear location")) {
+                                               clear_object('g');
+                                       }
+                               }
+                               else if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_TRANSLATE;
+                                       doredraw= 1;
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_TRANSLATION, CTX_NONE);
+                               }
                                break;
                        case HKEY:
                                if(G.obedit) {
@@ -1260,6 +1296,14 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if(G.obedit->type==OB_LATTICE) {
                                                if(G.qual==LR_CTRLKEY) add_hook();
                                        }
+                                       else if(G.obedit->type==OB_MBALL) {
+                                               if(G.qual==LR_ALTKEY)
+                                                       reveal_mball();
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       hide_mball(1);
+                                               else if((G.qual==0)) 
+                                                       hide_mball(0);
+                                       }
                                }
                                else if(G.f & G_FACESELECT)
                                        hide_tface();
@@ -1339,14 +1383,22 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                selectconnected_posearmature();
                                }
                                else {
-                                       if((G.qual==LR_SHIFTKEY))
-                                               selectlinks_menu();
-                                       else if(G.qual==LR_CTRLKEY)
-                                               make_links_menu();
-                                       else if(G.f & G_FACESELECT)
-                                               select_linked_tfaces();
-                                       else if((G.qual==0))
-                                               make_local();
+                                       if(G.f & G_FACESELECT) {
+                                               if((G.qual==0))
+                                                       select_linked_tfaces(0);
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       select_linked_tfaces(1);
+                                               else if(G.qual==LR_CTRLKEY)
+                                                       select_linked_tfaces(2);
+                                       }
+                                       else {
+                                               if((G.qual==0))
+                                                       make_local();
+                                               else if((G.qual==LR_SHIFTKEY))
+                                                       selectlinks_menu();
+                                               else if(G.qual==LR_CTRLKEY)
+                                                       make_links_menu();
+                                       }
                                }
                                break;
                        case MKEY:
@@ -1360,7 +1412,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
                                                mirrormenu();
                                        }
-                                       if(G.qual & (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY)) {
+                                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
                                                if(G.obedit->type==OB_MESH) select_non_manifold();
                                        }
                                }
@@ -1408,11 +1460,10 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case OKEY:
                                ob= OBACT;
-                               if(G.obedit) {
-                                       extern int prop_mode;
-
+                               if (G.obedit) {
                                        if (G.qual==LR_SHIFTKEY) {
-                                               prop_mode= !prop_mode;
+                                               extern int prop_mode;
+                                               prop_mode = (prop_mode+1)%6;
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                        else if((G.qual==0)) {
@@ -1425,11 +1476,14 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                flip_subdivison(ob, -1);
                                        }
                                }
-                               else if(G.qual==LR_ALTKEY) clear_object('o');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear origin")) {
+                                               clear_object('o');
+                                       }
+                               }
                                break;
 
                        case PKEY:
-                               
                                if(G.obedit) {
                                        if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                                make_parent();
@@ -1437,9 +1491,13 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                separatemenu();
                                        else if ((G.qual==0) && ELEM(G.obedit->type, OB_CURVE, OB_SURF))
                                                separate_nurb();
+                                       else if (G.qual==LR_SHIFTKEY)
+                                               Transform(TFM_PUSHPULL, CTX_NONE);
                                }
                                else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                        make_parent();
+                               else if(G.qual==LR_SHIFTKEY)
+                                       Transform(TFM_PUSHPULL, CTX_NONE);
                                else if(G.qual==LR_ALTKEY)
                                        clear_parent();
                                else if((G.qual==0)) {
@@ -1449,8 +1507,15 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case RKEY:
                                if((G.obedit==0) && (G.f & G_FACESELECT) && (G.qual==0))
                                        rotate_uv_tface();
-                               else if(G.qual==LR_ALTKEY)
-                                       clear_object('r');
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear rotation")) {
+                                               clear_object('r');
+                                       }
+                               } 
+                               else if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_ROTATE;
+                                       doredraw= 1;
+                               }
                                else if (G.obedit) {
                                        if((G.qual==LR_SHIFTKEY)) {
                                                if ELEM(G.obedit->type,  OB_CURVE, OB_SURF)                                     
@@ -1462,30 +1527,51 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                if (G.obedit->type==OB_MESH)
                                                        loopoperations(LOOP_CUT);
                                        }
-                                       else if((G.qual==0))
-                                               transform('r');
+                                       else if((G.qual==0)) {
+                                               Transform(TFM_ROTATION, CTX_NONE);
+                                       }
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_ROTATION, CTX_NONE);
                                }
-                               else if((G.qual==0))
-                                       transform('r');
                                break;
                        case SKEY:
-                               if(G.obedit) {
+                               if(G.qual== (LR_CTRLKEY|LR_ALTKEY)) {
+                                       v3d->twtype= V3D_MANIP_SCALE;
+                                       doredraw= 1;
+                               }
+                               else if(G.obedit) {
                                        if(G.qual==LR_ALTKEY)
-                                               transform('N'); /* scale along normal */
+                                               Transform(TFM_SHRINKFATTEN, CTX_NONE);
                                        else if(G.qual==LR_CTRLKEY)
-                                               transform('S');
+                                               Transform(TFM_SHEAR, CTX_NONE);
+                                       else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
+                                               Transform(TFM_SHEAR, CTX_NONE);
                                        else if(G.qual==LR_SHIFTKEY)
                                                snapmenu();
-                                       else if((G.qual==0))
-                                               transform('s');
+                                       else if(G.qual==0) {
+                                               Transform(TFM_RESIZE, CTX_NONE);
+                                       }
+                                       else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)){
+                                               Transform(TFM_TOSPHERE, CTX_NONE);
+                                       }
+                                       
                                }
                                else if(G.qual==LR_ALTKEY) {
-                                       clear_object('s');
+                                       if(okee("Clear size")) {
+                                               clear_object('s');
+                                       }
                                }
-                               else if((G.qual==LR_SHIFTKEY))
+                               else if(G.qual==LR_SHIFTKEY) {
                                        snapmenu();
-                               else if((G.qual==0))
-                                       transform('s');
+                               }
+                               else if((G.qual==0)) {
+                                       Transform(TFM_RESIZE, CTX_NONE);
+                               }
+                               else if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
+                                       Transform(TFM_TOSPHERE, CTX_NONE);
+                               else if(G.qual==(LR_CTRLKEY|LR_ALTKEY))
+                                       Transform(TFM_SHEAR, CTX_NONE);
                                break;
                        case TKEY:
                                if(G.obedit){
@@ -1495,10 +1581,14 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                countall();
                                                makeDispList(G.obedit);
                                        }
-                                       else if((G.qual==LR_ALTKEY) && G.obedit->type==OB_CURVE)
-                                               clear_tilt();
-                                       else if((G.qual==0))
-                                               transform('t');
+                                       if (G.obedit->type==OB_CURVE) {
+                                               if (G.qual==LR_ALTKEY) {
+                                                       clear_tilt();
+                                               }
+                                               else if (G.qual==0) {
+                                                       Transform(TFM_TILT, CTX_NONE);
+                                               }
+                                       }
                                }
                                else if(G.qual==LR_CTRLKEY) {
                                        make_track();
@@ -1518,13 +1608,11 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                        else if(G.obedit->type==OB_ARMATURE)
                                                remake_editArmature();
-                                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
+                                       else if ELEM4(G.obedit->type, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE) {
                                                if(G.qual==0) BIF_undo(); else BIF_redo();
                                        }
-                                       else if(G.obedit->type==OB_LATTICE)
-                                               remake_editLatt();
                                }
-                               else if((G.qual==0)){
+                               else if((G.qual==0)) {
                                        if (G.f & G_FACESELECT)
                                                uv_autocalc_tface();
                                        else if(G.f & G_WEIGHTPAINT)
@@ -1564,7 +1652,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case WKEY:
                                if((G.qual==LR_SHIFTKEY)) {
-                                       transform('w');
+                                       Transform(TFM_WARP, CTX_NONE);
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        /* if(G.obedit && G.obedit->type==OB_MESH) write_videoscape(); */
@@ -1609,6 +1697,8 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                } else if(G.qual==0) {
                                        G.vd->around= V3D_CENTRE;
                                }
+                               handle_view3d_around();
+                               
                                scrarea_queue_headredraw(curarea);
                                break;
                                
@@ -1618,6 +1708,8 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }       else if(G.qual==0) {
                                        G.vd->around= V3D_CURSOR;
                                }
+                               handle_view3d_around();
+                               
                                scrarea_queue_headredraw(curarea);
                                break;
                        
@@ -1638,7 +1730,18 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(G.qual==0) {
                                        ob= OBACT;
                                        if(ob) {
-                                               obmat_to_viewmat(ob);
+                                               if ((G.obedit) && (G.obedit->type == OB_MESH)) {
+                                                       editmesh_align_view_to_selected(G.vd, 2);
+                                               } 
+                                               else if (G.f & G_FACESELECT) {
+                                                       if(ob->type==OB_MESH) {
+                                                               Mesh *me= ob->data;
+                                                               faceselect_align_view_to_selected(G.vd, me, 2);
+                                                       }
+                                               }
+                                               else
+                                                       obmat_to_viewmat(ob);
+                                               
                                                if(G.vd->persp==2) G.vd->persp= 1;
                                                scrarea_queue_winredraw(curarea);
                                        }
@@ -1707,7 +1810,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        }
 }
 
-void initview3d(ScrArea *sa)
+static void initview3d(ScrArea *sa)
 {
        View3D *vd;
        
@@ -1750,7 +1853,7 @@ static void changeview2dspace(ScrArea *sa, void *spacedata)
        myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
 }
 
-void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        extern void do_ipobuts(unsigned short event);   // drawipo.c
        unsigned short event= evt->event;
@@ -1769,10 +1872,10 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
+                       if (event == LEFTMOUSE) {
                                event = RIGHTMOUSE;
                                mousebut = L_MOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
+                       } else if (event == RIGHTMOUSE) {
                                event = LEFTMOUSE;
                                mousebut = R_MOUSE;
                        }
@@ -1789,7 +1892,8 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        if( in_ipo_buttons() ) {
                                do_ipo_selectbuttons();
                                doredraw= 1;
-                       }                       
+                       }
+                       else if(view2dmove(LEFTMOUSE)); // only checks for sliders
                        else if(G.qual & LR_CTRLKEY) add_vert_ipo();
                        else {
                                do {
@@ -1802,8 +1906,9 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if( cfra!=CFRA ) {
                                                CFRA= cfra;
                                                update_for_newframe();
-                                               force_draw_all();/* To make constraint sliders redraw */
+                                               force_draw_all(0); /* To make constraint sliders redraw */
                                        }
+                                       else PIL_sleep_ms(30);
                                
                                } while(get_mbut() & mousebut);
                        }
@@ -1853,7 +1958,9 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(in_ipo_buttons()) {
                                        swap_visible_editipo();
                                }
-                               else swap_selectall_editipo();
+                               else {
+                                       swap_selectall_editipo();
+                               }
                                allspace (REMAKEIPO, 0);
                                allqueue (REDRAWNLA, 0);
                                allqueue (REDRAWACTION, 0);
@@ -1966,7 +2073,8 @@ void space_mipmap_button_function(int event) {
        allqueue(REDRAWVIEW3D, 0);
 }
 
-void space_sound_button_function(int event)
+#if 0
+static void space_sound_button_function(int event)
 {
        int a;
        SYS_SystemHandle syshandle;
@@ -1977,6 +2085,7 @@ void space_sound_button_function(int event)
                SYS_WriteCommandLineInt(syshandle, "noaudio", a);
        }
 }
+#endif
 
 #define B_ADD_THEME    3301
 #define B_DEL_THEME    3302
@@ -1994,7 +2103,7 @@ static short th_curcol= TH_BACK;
 static char *th_curcol_ptr= NULL;
 static char th_curcol_arr[4]={0, 0, 0, 255};
 
-void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
+static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
 {
        bTheme *btheme, *bt;
        int spacetype= 0;
@@ -2048,7 +2157,7 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        /* main choices pup */
        uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
                "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Audio Timeline %x8|Text Editor %x9|%l|User Preferences %x10|"
-               "OOPS Schematic %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
+               "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
                                                                                                        255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
        if(curmain==1) spacetype= 0;
        else if(curmain==2) spacetype= SPACE_VIEW3D;
@@ -2096,7 +2205,7 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        }
        else {
                uiBlockBeginAlign(block);
-               if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
+               if ELEM6(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
                        uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
                }
                uiDefButC(block, NUMSLI, B_UPDATE_THEME,"R ",   465,y3,200,20,  col, 0.0, 255.0, B_THEMECOL, 0, "");
@@ -2135,8 +2244,13 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
-       fac= ((float)curarea->winx)/1280.0f;
-       myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       if(curarea->winx<=1280.0) {
+               fac= ((float)curarea->winx)/1280.0f;
+               myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       }
+       else {
+               myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
+       }
        
        sprintf(naam, "infowin %d", curarea->win);
        block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->win);
@@ -2357,11 +2471,15 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
                                0, 0, 0, 0, 0, "");
                }
-
-               uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, 0, "Emulate 3 Button Mouse",
+               
+               /* illegal combo... */
+               if (U.flag & USER_LMOUSESELECT) 
+                       U.flag &= ~USER_TWOBUTTONMOUSE;
+               
+               uiDefButBitS(block, TOG, USER_TWOBUTTONMOUSE, B_DRAWINFO, "Emulate 3 Button Mouse",
                        (xpos+edgsp+(3*mpref)+(4*midsp)),y3,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Emulates a middle mouse button with Alt LeftMouse");
+                       "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
                
                        
                uiDefBut(block, LABEL,0,"Middle Mouse Button:",
@@ -2389,6 +2507,22 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        "The number of lines scrolled at a time with the mouse wheel"); 
 
 
+               uiDefBut(block, LABEL,0,"3D Transform Widget:",
+                                (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y6label,mpref,buth,
+                                0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
+               uiDefButS(block, NUM, B_REDRCURW3D, "Size:",
+                                        (xpos+edgsp+(5*mpref)+(6*midsp)),y5,(mpref/2),buth,
+                                        &(U.tw_size), 2, 40, 0, 0, "Size of widget as percentage of window size");
+               uiDefButS(block, NUM, B_REDRCURW3D, "Handle:",
+                                        (xpos+edgsp+(5*mpref)+(6*midsp)+(mpref/2)),y5,(mpref/2),buth,
+                                        &(U.tw_handlesize), 2, 40, 0, 0, "Size of widget handles as percentage of widget radius");
+               uiDefButS(block, NUM, B_REDRCURW3D, "Hotspot:",
+                                 (xpos+edgsp+(5*mpref)+(6*midsp)),y4,(mpref),buth,
+                                 &(U.tw_hotspot), 4, 40, 0, 0, "Hotspot in pixels for clicking widget handles");
+               
+               uiBlockEndAlign(block);
+               
        } else if (U.userpref == 1) { /* edit methods */
 
 
@@ -2470,25 +2604,29 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        } else if(U.userpref == 2) { /* language & colors */
 
 #ifdef INTERNATIONAL
-               char curfont[320];
-
-               sprintf(curfont, "Interface Font: ");
-               strcat(curfont,U.fontname);
-
                uiDefButBitS(block, TOG, USER_DOTRANSLATE, B_DOLANGUIFONT, "International Fonts",
                        xpos,y2,mpref,buth,
                        &(U.transopts), 0, 0, 0, 0, "Activate international interface");
 
                if(U.transopts & USER_DOTRANSLATE) {
+                       char curfont[320];
+                       
+                       sprintf(curfont, "Interface Font: ");
+                       if(U.fontname[0]) strcat(curfont, U.fontname);
+                       else strcat(curfont, "Built-in");
+                       
                        uiDefBut(block, LABEL,0,curfont,
-                               (xpos+edgsp+mpref+midsp),y2,mpref,buth,
+                               (xpos),y3,4*mpref,buth,
                                0, 0, 0, 0, 0, "");
 
                        uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
                                xpos,y1,mpref,buth,
                                0, 0, 0, 0, 0, "Select a new font for the interface");
 
-
+                       uiDefButI(block, BUT, B_RESTOREFONT, "Restore to default",
+                                         (xpos+edgsp+mpref+midsp),y2,mpref,buth,
+                                         &U.fontsize, 0, 0, 0, 0, "Restores to using the default included antialised font");
+                       
                        uiDefButI(block, MENU|INT, B_SETFONTSIZE, fontsize_pup(),
                                (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
@@ -2520,12 +2658,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
                                &U.language, 0, 0, 0, 0, "Select interface language");
                                
-                       /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
-                               (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
+                       uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
+                               (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
                                &(U.transopts), 0, 0, 0, 0,
-                               "Use FTF drawing for fileselect and textwindow "
-                               "(under construction)");
-                       */
+                               "Use Textured Fonts");
                }
 
 /* end of INTERNATIONAL */
@@ -2566,18 +2702,18 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                uiBlockSetCol(block, TH_BUT_SETTING1);
                uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
                        xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
-                       &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
+                       &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "Enable this OpenGL light in Solid draw mode");
                        
                uiBlockSetCol(block, TH_AUTO);
                uiDefButS(block, ROW, B_REDR, "Vec",
                        xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
-                       &cur_light_var, 123.0, 0.0, 0, 0, "");
+                       &cur_light_var, 123.0, 0.0, 0, 0, "Lamp vector for OpenGL light");
                uiDefButS(block, ROW, B_REDR, "Col",
                        xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
-                       &cur_light_var, 123.0, 1.0, 0, 0, "");
+                       &cur_light_var, 123.0, 1.0, 0, 0, "Diffuse Color for OpenGL light");
                uiDefButS(block, ROW, B_REDR, "Spec",
                        xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
-                       &cur_light_var, 123.0, 2.0, 0, 0, "");
+                       &cur_light_var, 123.0, 2.0, 0, 0, "Specular color for OpenGL light");
 
                if(cur_light_var==1) {
                        uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
@@ -2656,9 +2792,9 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Sound",
+               uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Game Sound",
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
-                       &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
+                       &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played in games");
 
                uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
@@ -2775,13 +2911,21 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        
        myortho2(-0.375, (float)(sa->winx)-0.375, -0.375, (float)(sa->winy)-0.375);
        draw_area_emboss(sa);
-       myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+
+       /* restore buttons transform */
+       if(curarea->winx<=1280.0) {
+               fac= ((float)curarea->winx)/1280.0f;
+               myortho2(0.0, 1280.0, 0.0, curarea->winy/fac);
+       }
+       else {
+               myortho2(0.0, (float)curarea->winx, 0.0, (float)curarea->winy);
+       }
        sa->win_swap= WIN_BACK_OK;
        
 }
 
 
-void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
@@ -2855,7 +2999,7 @@ void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        }
 }
 
-void init_infospace(ScrArea *sa)
+static void init_infospace(ScrArea *sa)
 {
        SpaceInfo *sinfo;
        
@@ -2877,7 +3021,7 @@ static void changebutspace(ScrArea *sa, void *spacedata)
        myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
 }
 
-void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
@@ -3000,7 +3144,7 @@ void test_butspace(void)
        G.buts->v2d.tot.ymin= MIN2(0.0, blocksmin-10.0);
 }
 
-void init_butspace(ScrArea *sa)
+static void init_butspace(ScrArea *sa)
 {
        SpaceButs *buts;
        
@@ -3020,7 +3164,7 @@ void extern_set_butspace(int fkey)
        ScrArea *sa;
        SpaceButs *sbuts;
        
-       /* when a f-key pressed: closest button window is initialized */
+       /* when a f-key pressed: 'closest' button window is initialized */
        if(curarea->spacetype==SPACE_BUTS) sa= curarea;
        else {
                /* find area */
@@ -3073,7 +3217,7 @@ void extern_set_butspace(int fkey)
 
 /*  extern void drawseqspace(ScrArea *sa, void *spacedata); BIF_drawseq.h */
 
-void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
@@ -3093,10 +3237,10 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
-                       if (evt->event == LEFTMOUSE) {
+                       if (event == LEFTMOUSE) {
                                event = RIGHTMOUSE;
                                mousebut = L_MOUSE;
-                       } else if (evt->event == RIGHTMOUSE) {
+                       } else if (event == RIGHTMOUSE) {
                                event = LEFTMOUSE;
                                mousebut = R_MOUSE;
                        }
@@ -3124,9 +3268,10 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                first= 0;
                                
                                                CFRA= cfra;
-                                               force_draw();
+                                               force_draw(0);
                                                update_for_newframe();  /* for audio scrubbing */                                               
                                        }
+                                       else PIL_sleep_ms(30);
                                
                                } while(get_mbut() & mousebut);
                                
@@ -3159,10 +3304,12 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if((G.qual==LR_SHIFTKEY)) {
                                        insert_gap(25, CFRA);
+                                       BIF_undo_push("Insert gaps Sequencer");
                                        allqueue(REDRAWSEQ, 0);
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        insert_gap(250, CFRA);
+                                       BIF_undo_push("Insert gaps Sequencer");
                                        allqueue(REDRAWSEQ, 0);
                                }
                        }
@@ -3239,7 +3386,7 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                case GKEY:
                        if(sseq->mainb) break;
                        if((G.qual==0))
-                               transform_seq('g');
+                               transform_seq('g', 0);
                        break;
                case MKEY:
                        if(G.qual==LR_ALTKEY)
@@ -3283,7 +3430,7 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 }
 
 
-void init_seqspace(ScrArea *sa)
+static void init_seqspace(ScrArea *sa)
 {
        SpaceSeq *sseq;
        
@@ -3334,7 +3481,7 @@ static void changeactionspace(ScrArea *sa, void *spacedata)
 }
 
 
-void init_actionspace(ScrArea *sa)
+static void init_actionspace(ScrArea *sa)
 {
        SpaceAction *saction;
        
@@ -3370,7 +3517,7 @@ void init_actionspace(ScrArea *sa)
        
 }
 
-void free_actionspace(SpaceAction *saction)
+static void free_actionspace(SpaceAction *saction)
 {
        /* don't free saction itself */
        
@@ -3385,7 +3532,7 @@ void free_actionspace(SpaceAction *saction)
 
 /* ******************** SPACE: FILE ********************** */
 
-void init_filespace(ScrArea *sa)
+static void init_filespace(ScrArea *sa)
 {
        SpaceFile *sfile;
        
@@ -3398,7 +3545,7 @@ void init_filespace(ScrArea *sa)
        sfile->spacetype= SPACE_FILE;
 }
 
-void init_textspace(ScrArea *sa)
+static void init_textspace(ScrArea *sa)
 {
        SpaceText *st;
        
@@ -3413,11 +3560,13 @@ void init_textspace(ScrArea *sa)
        st->font_id= 5;
        st->lheight= 12;
        st->showlinenrs= 0;
+       st->tabnumber = 4;
+       st->currtab_set = 0;
        
        st->top= 0;
 }
 
-void init_scriptspace(ScrArea *sa)
+static void init_scriptspace(ScrArea *sa)
 {
        SpaceScript *sc;
 
@@ -3430,7 +3579,7 @@ void init_scriptspace(ScrArea *sa)
        sc->flags = 0;
 }
 
-void init_imaselspace(ScrArea *sa)
+static void init_imaselspace(ScrArea *sa)
 {
        SpaceImaSel *simasel;
        
@@ -3469,7 +3618,7 @@ void init_imaselspace(ScrArea *sa)
 extern void drawsoundspace(ScrArea *sa, void *spacedata);
 extern void winqreadsoundspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 
-void init_soundspace(ScrArea *sa)
+static void init_soundspace(ScrArea *sa)
 {
        SpaceSound *ssound;
        
@@ -3517,7 +3666,7 @@ void free_soundspace(SpaceSound *ssound)
 
 /*  extern void drawimagespace(ScrArea *sa, void *spacedata); BIF_drawimage.h */
 
-void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
@@ -3539,10 +3688,10 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        
        /* swap mouse buttons based on user preference */
        if (U.flag & USER_LMOUSESELECT) {
-               if (evt->event == LEFTMOUSE) {
+               if (event == LEFTMOUSE) {
                        event = RIGHTMOUSE;
                        mousebut = R_MOUSE;
-               } else if (evt->event == RIGHTMOUSE) {
+               } else if (event == RIGHTMOUSE) {
                        event = LEFTMOUSE;
                        mousebut = L_MOUSE;
                }
@@ -3580,11 +3729,11 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        /* Make OpenGL aware of a changed texture */
                                                        free_realtime_image(sima->image);
                                                        /* Redraw this view and the 3D view */
-                                                       force_draw_plus(SPACE_VIEW3D);
+                                                       force_draw_plus(SPACE_VIEW3D, 0);
                                                }
                                                else {
                                                        /* Redraw only this view */
-                                                       force_draw();
+                                                       force_draw(0);
                                                }
                                                xy_prev[0] = xy_curr[0];
                                                xy_prev[1] = xy_curr[1];
@@ -3596,7 +3745,7 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        /* Make OpenGL aware of a changed texture */
                                        free_realtime_image(sima->image);
                                        /* Redraw this view and the 3D view */
-                                       force_draw_plus(SPACE_VIEW3D);
+                                       force_draw_plus(SPACE_VIEW3D, 1);
                                }
                                IMG_BrushDispose(brush);
                                IMG_CanvasDispose(canvas);
@@ -3616,9 +3765,6 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
                                else gesture();
                                break;
-                       case MIDDLEMOUSE:
-                               image_viewmove();
-                               break;
                        case RIGHTMOUSE:
                                if(G.f & G_FACESELECT)
                                        mouse_select_sima();
@@ -3644,12 +3790,12 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        toggle_uv_select('f');
                                break;
                        case EKEY :
-                               if (okee("LSCM unwrap"))
+                               if(okee("LSCM Unwrap"))
                                        unwrap_lscm();
                                break;
                        case GKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('g');
+                                       transform_tface_uv('g', 0);
                                break;
                        case HKEY:
                                if(G.qual==LR_ALTKEY)
@@ -3660,8 +3806,12 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        hide_tface_uv(0);
                                break;
                        case LKEY:
-                               if((G.qual==0))
-                                       select_linked_tface_uv();
+                               if(G.qual==0)
+                                       select_linked_tface_uv(0);
+                               else if(G.qual==LR_SHIFTKEY)
+                                       select_linked_tface_uv(1);
+                               else if(G.qual==LR_CTRLKEY)
+                                       select_linked_tface_uv(2);
                                else if(G.qual==LR_ALTKEY)
                                        unlink_selection();
                                break;
@@ -3693,11 +3843,11 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case RKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('r');
+                                       transform_tface_uv('r', 0);
                                break;
                        case SKEY:
                                if((G.qual==0))
-                                       transform_tface_uv('s');
+                                       transform_tface_uv('s', 0);
                                break;
                        case VKEY:
                                if((G.qual==0))
@@ -3706,7 +3856,11 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        stitch_uv_tface(1);
                                break;
                        case WKEY:
-                               transform_tface_uv('w');
+                               weld_align_menu_tface_uv();
+                               break;
+                       case PADPERIOD:
+                               if(G.qual==0)
+                                       image_viewcentre();
                                break;
                }
        }       
@@ -3723,13 +3877,13 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                do_imagebuts(val);      // drawimage.c
                break;
        case MIDDLEMOUSE:
-               image_viewmove();
+               if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                       image_viewmove(1);
+               else
+                       image_viewmove(0);
                break;
-       case WHEELUPMOUSE:
-       case WHEELDOWNMOUSE:
-       case PADPLUSKEY:
-       case PADMINUS:
-               image_viewzoom(event);
+       case WHEELUPMOUSE: case WHEELDOWNMOUSE: case PADPLUSKEY: case PADMINUS:
+               image_viewzoom(event, 0);
                scrarea_queue_winredraw(curarea);
                break;
        case HOMEKEY:
@@ -3746,7 +3900,7 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 }
 
 
-void init_imagespace(ScrArea *sa)
+static void init_imagespace(ScrArea *sa)
 {
        SpaceImage *sima;
        
@@ -3772,7 +3926,7 @@ extern void winqreadimaselspace(struct ScrArea *sa, void *spacedata, struct BWin
 
 extern void drawoopsspace(ScrArea *sa, void *spacedata);
 
-void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        unsigned short event= evt->event;
        short val= evt->val;
@@ -3782,161 +3936,236 @@ void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
        if(val==0) return;
 
-       if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
-
-       /* swap mouse buttons based on user preference */
-       if (U.flag & USER_LMOUSESELECT) {
-               if (evt->event == LEFTMOUSE) {
-                       event = RIGHTMOUSE;
-               } else if (evt->event == RIGHTMOUSE) {
-                       event = LEFTMOUSE;
-               }
-       }
+       if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
 
        if (U.flag & USER_NONUMPAD) {
                event= convert_for_nonumpad(event);
        }
-
-       switch(event) {
-       case LEFTMOUSE:
-               gesture();
-               break;
-       case MIDDLEMOUSE:
-       case WHEELUPMOUSE:
-       case WHEELDOWNMOUSE:
-               view2dmove(event);      /* in drawipo.c */
-               break;
-       case RIGHTMOUSE:
-               mouse_select_oops();
-               break;
-       case PADPLUSKEY:
        
-               dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
-               dy= 0.1154*(v2d->cur.ymax-v2d->cur.ymin);
-               v2d->cur.xmin+= dx;
-               v2d->cur.xmax-= dx;
-               v2d->cur.ymin+= dy;
-               v2d->cur.ymax-= dy;
-               test_view2d(G.v2d, curarea->winx, curarea->winy);
-               scrarea_queue_winredraw(curarea);
-               break;
-       
-       case PADMINUS:
-
-               dx= 0.15*(v2d->cur.xmax-v2d->cur.xmin);
-               dy= 0.15*(v2d->cur.ymax-v2d->cur.ymin);
-               v2d->cur.xmin-= dx;
-               v2d->cur.xmax+= dx;
-               v2d->cur.ymin-= dy;
-               v2d->cur.ymax+= dy;
-               test_view2d(G.v2d, curarea->winx, curarea->winy);
-               scrarea_queue_winredraw(curarea);
-               break;
+       /* keep leftmouse select for outliner, regardless of user pref */ 
+       if(soops->type==SO_OUTLINER) {
+               switch(event) {
+               case LEFTMOUSE:
+                       outliner_mouse_event(sa, event);                        
+                       break;
+               case MIDDLEMOUSE:
+               case WHEELUPMOUSE:
+               case WHEELDOWNMOUSE:
+                       view2dmove(event);      /* in drawipo.c */
+                       break;
+               case RIGHTMOUSE:
+                       // outliner_select(sa);
+                       break;
+                       
+               case AKEY:
+                       outliner_toggle_visible(sa);
+                       break;
+               case WKEY:
+                       // outliner_operation_menu(sa);
+                       break;
+                       
+               case HOMEKEY:
+                       outliner_show_hierarchy(sa);
+                       break;
+               case PAGEUPKEY:
+                       outliner_page_up_down(sa, 1);
+                       break;
+               case PAGEDOWNKEY:
+                       outliner_page_up_down(sa, -1);
+                       break;
+                       
+               case RETKEY:
+               case PADENTER:
+                       outliner_mouse_event(sa, event);
+                       break;
+               case PERIODKEY:
+               case PADPERIOD:
+                       outliner_show_active(sa);
+                       break;
+               case PADPLUSKEY:
+                       outliner_one_level(sa, 1);
+                       break;
+               case PADMINUS:
+                       outliner_one_level(sa, -1);
+                       break;
+               }
+       }
+       else {  
+               /* swap mouse buttons based on user preference */
+               if (U.flag & USER_LMOUSESELECT) {
+                       if (event==LEFTMOUSE) event = RIGHTMOUSE;
+                       else if (event==RIGHTMOUSE) event = LEFTMOUSE;
+               }
                
-       case HOMEKEY:   
-               if((G.qual==0))
-                       do_oops_buttons(B_OOPSHOME);
-               break;
+               switch(event) {
+               case LEFTMOUSE:
+                       gesture();
+                       break;
+               case MIDDLEMOUSE:
+               case WHEELUPMOUSE:
+               case WHEELDOWNMOUSE:
+                       view2dmove(event);      /* in drawipo.c */
+                       break;
+               case RIGHTMOUSE:
+                       mouse_select_oops();
+                       break;
+               case PADPLUSKEY:
                
-       case AKEY:
-               if((G.qual==0)) {
-                       swap_select_all_oops();
+                       dx= 0.1154*(v2d->cur.xmax-v2d->cur.xmin);
+                       dy= 0.1154*(v2d->cur.ymax-v2d->cur.ymin);
+                       v2d->cur.xmin+= dx;
+                       v2d->cur.xmax-= dx;
+                       v2d->cur.ymin+= dy;
+                       v2d->cur.ymax-= dy;
+                       test_view2d(G.v2d, curarea->winx, curarea->winy);
                        scrarea_queue_winredraw(curarea);
-               }
-               break;
-       case BKEY:
-               if((G.qual==0))
-                       borderselect_oops();
-               break;
-       case GKEY:
-               if((G.qual==0))
-                       transform_oops('g');
-               break;
-       case LKEY:
-               if((G.qual==LR_SHIFTKEY))
-                       select_backlinked_oops();
-               else if((G.qual==0))
-                       select_linked_oops();
-               break;
-       case SKEY:
-               if((G.qual==LR_ALTKEY)) {
-                       if (okee("Shrink blocks")) {
-                               shrink_oops();
+                       break;
+               
+               case PADMINUS:
+
+                       dx= 0.15*(v2d->cur.xmax-v2d->cur.xmin);
+                       dy= 0.15*(v2d->cur.ymax-v2d->cur.ymin);
+                       v2d->cur.xmin-= dx;
+                       v2d->cur.xmax+= dx;
+                       v2d->cur.ymin-= dy;
+                       v2d->cur.ymax+= dy;
+                       test_view2d(G.v2d, curarea->winx, curarea->winy);
+                       scrarea_queue_winredraw(curarea);
+                       break;
+                       
+               case HOMEKEY:   
+                       if((G.qual==0))
+                               do_oops_buttons(B_OOPSHOME);
+                       break;
+                       
+               case AKEY:
+                       if((G.qual==0)) {
+                               swap_select_all_oops();
+                               scrarea_queue_winredraw(curarea);
                        }
-               } else if((G.qual==LR_SHIFTKEY)) {
-                       if (okee("Shuffle blocks")) {
-                               shuffle_oops();
+                       break;
+               case BKEY:
+                       if((G.qual==0))
+                               borderselect_oops();
+                       break;
+               case GKEY:
+                       if((G.qual==0))
+                               transform_oops('g', 0);
+                       break;
+               case LKEY:
+                       if((G.qual==LR_SHIFTKEY))
+                               select_backlinked_oops();
+                       else if((G.qual==0))
+                               select_linked_oops();
+                       break;
+               case SKEY:
+                       if((G.qual==LR_ALTKEY)) {
+                               if (okee("Shrink blocks")) {
+                                       shrink_oops();
+                               }
+                       } else if((G.qual==LR_SHIFTKEY)) {
+                               if (okee("Shuffle blocks")) {
+                                       shuffle_oops();
+                               }
+                       } else if((G.qual==0)) {
+                               transform_oops('s', 0);
                        }
-               } else if((G.qual==0)) {
-                       transform_oops('s');
-               }
-               break;
-       case PKEY:
-               if((G.qual==LR_CTRLKEY)) {
-                       make_parent();
-               } else if((G.qual==LR_ALTKEY)) {
-                       clear_parent();
-               }
-               break;
+                       break;
+               case PKEY:
+                       if((G.qual==LR_CTRLKEY)) {
+                               make_parent();
+                       } else if((G.qual==LR_ALTKEY)) {
+                               clear_parent();
+                       }
+                       break;
 
 
-       case ONEKEY:
-               do_layer_buttons(0); break;
-       case TWOKEY:
-               do_layer_buttons(1); break;
-       case THREEKEY:
-               do_layer_buttons(2); break;
-       case FOURKEY:
-               do_layer_buttons(3); break;
-       case FIVEKEY:
-               do_layer_buttons(4); break;
-       case SIXKEY:
-               do_layer_buttons(5); break;
-       case SEVENKEY:
-               do_layer_buttons(6); break;
-       case EIGHTKEY:
-               do_layer_buttons(7); break;
-       case NINEKEY:
-               do_layer_buttons(8); break;
-       case ZEROKEY:
-               do_layer_buttons(9); break;
-       case MINUSKEY:
-               do_layer_buttons(10); break;
-       case EQUALKEY:
-               do_layer_buttons(11); break;
-       case ACCENTGRAVEKEY:
-               do_layer_buttons(-1); break;
-       
+               case ONEKEY:
+                       do_layer_buttons(0); break;
+               case TWOKEY:
+                       do_layer_buttons(1); break;
+               case THREEKEY:
+                       do_layer_buttons(2); break;
+               case FOURKEY:
+                       do_layer_buttons(3); break;
+               case FIVEKEY:
+                       do_layer_buttons(4); break;
+               case SIXKEY:
+                       do_layer_buttons(5); break;
+               case SEVENKEY:
+                       do_layer_buttons(6); break;
+               case EIGHTKEY:
+                       do_layer_buttons(7); break;
+               case NINEKEY:
+                       do_layer_buttons(8); break;
+               case ZEROKEY:
+                       do_layer_buttons(9); break;
+               case MINUSKEY:
+                       do_layer_buttons(10); break;
+               case EQUALKEY:
+                       do_layer_buttons(11); break;
+               case ACCENTGRAVEKEY:
+                       do_layer_buttons(-1); break;
+               
+               }
        }
 }
 
-void init_v2d_oops(View2D *v2d)
+void init_v2d_oops(ScrArea *sa, SpaceOops *soops)
 {
-       v2d->tot.xmin= -28.0;
-       v2d->tot.xmax= 28.0;
-       v2d->tot.ymin= -28.0;
-       v2d->tot.ymax= 28.0;
+       View2D *v2d= &soops->v2d;
        
-       v2d->cur= v2d->tot;
+       if(soops->type==SO_OUTLINER) {
+               /* outliner space is window size */
+               calc_scrollrcts(sa, v2d, sa->winx, sa->winy);
+               
+               v2d->tot.xmax= 0.0;
+               v2d->tot.ymax= 0.0;
+               v2d->tot.xmin= -(v2d->mask.xmax-v2d->mask.xmin);
+               v2d->tot.ymin= -(v2d->mask.ymax-v2d->mask.ymin);
+               
+               v2d->cur= v2d->tot;
+               
+               v2d->min[0]= v2d->tot.xmin;
+               v2d->min[1]= v2d->tot.ymin;
+               
+               v2d->max[0]= v2d->tot.xmax;
+               v2d->max[1]= v2d->tot.ymax;
+               
+               v2d->minzoom= 1.0;
+               v2d->maxzoom= 1.0;
+               
+               v2d->scroll= L_SCROLL;
+               v2d->keepaspect= 1;
+               v2d->keepzoom= 1;
+               v2d->keeptot= 1;
+       }
+       else {
+               v2d->tot.xmin= -28.0;
+               v2d->tot.xmax= 28.0;
+               v2d->tot.ymin= -28.0;
+               v2d->tot.ymax= 28.0;
+               
+               v2d->cur= v2d->tot;
 
-       v2d->min[0]= 10.0;
-       v2d->min[1]= 4.0;
+               v2d->min[0]= 10.0;
+               v2d->min[1]= 4.0;
 
-       v2d->max[0]= 320.0;
-       v2d->max[1]= 320.0;
-       
-       v2d->minzoom= 0.01f;
-       v2d->maxzoom= 2.0;
-       
-       /* v2d->scroll= L_SCROLL+B_SCROLL; */
-       v2d->scroll= 0;
-       v2d->keepaspect= 1;
-       v2d->keepzoom= 0;
-       v2d->keeptot= 0;
-       
+               v2d->max[0]= 320.0;
+               v2d->max[1]= 320.0;
+               
+               v2d->minzoom= 0.01f;
+               v2d->maxzoom= 2.0;
+               
+               /* v2d->scroll= L_SCROLL+B_SCROLL; */
+               v2d->scroll= 0;
+               v2d->keepaspect= 1;
+               v2d->keepzoom= 0;
+               v2d->keeptot= 0;
+       }
 }
 
-void init_oopsspace(ScrArea *sa)
+static void init_oopsspace(ScrArea *sa, int outliner)
 {
        SpaceOops *soops;
        
@@ -3944,13 +4173,53 @@ void init_oopsspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, soops);
 
        soops->visiflag= OOPS_OB+OOPS_MA+OOPS_ME+OOPS_TE+OOPS_CU+OOPS_IP;
+       if(outliner) soops->type= SO_OUTLINER;
        
        soops->spacetype= SPACE_OOPS;
+       soops->type= SO_OUTLINER;       // default starts new ones in outliner mode
        soops->blockscale= 0.7;
-       init_v2d_oops(&soops->v2d);
+       init_v2d_oops(sa, soops);
+}
+
+/* ******************** SPACE: NLA ********************** */
+
+static void init_nlaspace(ScrArea *sa)
+{
+       SpaceNla *snla;
+       
+       snla= MEM_callocN(sizeof(SpaceNla), "initnlaspace");
+       BLI_addhead(&sa->spacedata, snla);
+       
+       snla->spacetype= SPACE_NLA;
+       snla->blockscale= 0.7;
+       
+       snla->v2d.tot.xmin= 1.0;
+       snla->v2d.tot.ymin=     0.0;
+       snla->v2d.tot.xmax= 1000.0;
+       snla->v2d.tot.ymax= 1000.0;
+       
+       snla->v2d.cur.xmin= -5.0;
+       snla->v2d.cur.ymin= 0.0;
+       snla->v2d.cur.xmax= 65.0;
+       snla->v2d.cur.ymax= 1000.0;
+       
+       snla->v2d.min[0]= 0.0;
+       snla->v2d.min[1]= 0.0;
+       
+       snla->v2d.max[0]= 1000.0;
+       snla->v2d.max[1]= 1000.0;
+       
+       snla->v2d.minzoom= 0.1F;
+       snla->v2d.maxzoom= 50;
+       
+       snla->v2d.scroll= R_SCROLL+B_SCROLL;
+       snla->v2d.keepaspect= 0;
+       snla->v2d.keepzoom= V2D_LOCKZOOM_Y;
+       snla->v2d.keeptot= 0;
+       
+       snla->lock = 0;
 }
 
-/* ******************** SPACE: PAINT ********************** */
 
 
 /* ******************** SPACE: Text ********************** */
@@ -3967,6 +4236,10 @@ extern void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWin
 
 void newspace(ScrArea *sa, int type)
 {
+       int xtra= type & 256;   // hack to enforce outliner with hotkey from toets.c
+       
+       type &= ~256;
+       
        if(type>=0) {
                if(sa->spacetype != type) {
                        SpaceLink *sl;
@@ -4012,7 +4285,7 @@ void newspace(ScrArea *sa, int type)
                                else if(type==SPACE_IMASEL)
                                        init_imaselspace(sa);
                                else if(type==SPACE_OOPS)
-                                       init_oopsspace(sa);
+                                       init_oopsspace(sa, xtra);
                                else if(type==SPACE_ACTION)
                                        init_actionspace(sa);
                                else if(type==SPACE_TEXT)
@@ -4032,8 +4305,8 @@ void newspace(ScrArea *sa, int type)
 
                
        /* exception: filespace */
-       if(curarea->spacetype==SPACE_FILE) {
-               SpaceFile *sfile= curarea->spacedata.first;
+       if(sa->spacetype==SPACE_FILE) {
+               SpaceFile *sfile= sa->spacedata.first;
                
                if(sfile->type==FILE_MAIN) {
                        freefilelist(sfile);
@@ -4046,11 +4319,20 @@ void newspace(ScrArea *sa, int type)
                if(sfile->filelist) test_flags_file(sfile);
        }
        /* exception: imasel space */
-       else if(curarea->spacetype==SPACE_IMASEL) {
-               SpaceImaSel *simasel= curarea->spacedata.first;
+       else if(sa->spacetype==SPACE_IMASEL) {
+               SpaceImaSel *simasel= sa->spacedata.first;
                simasel->returnfunc= 0;
                simasel->title[0]= 0;
        }
+       else if(sa->spacetype==SPACE_OOPS) {
+               SpaceOops *so= sa->spacedata.first;
+               if(xtra && so->type!=SO_OUTLINER) {
+                       so->type= SO_OUTLINER;
+                       init_v2d_oops(sa, so);
+                       scrarea_queue_winredraw(sa);
+                       scrarea_queue_headredraw(sa);
+               }
+       }
 }
 
 void freespacelist(ListBase *lb)
@@ -4062,6 +4344,8 @@ void freespacelist(ListBase *lb)
                        SpaceFile *sfile= (SpaceFile*) sl;
                        if(sfile->libfiledata)  
                                BLO_blendhandle_close(sfile->libfiledata);
+                       if(sfile->filelist)
+                               freefilelist(sfile);
                }
                else if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs*) sl;
@@ -4127,7 +4411,9 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                }
                else if(sl->spacetype==SPACE_OOPS) {
                        SpaceOops *so= (SpaceOops *)sl;
-                       so->oops.first= so->oops.last= 0;
+                       so->oops.first= so->oops.last= NULL;
+                       so->tree.first= so->tree.last= NULL;
+                       so->treestore= NULL;
                }
                else if(sl->spacetype==SPACE_IMASEL) {
                        check_imasel_copy((SpaceImaSel *) sl);
@@ -4197,6 +4483,16 @@ void allqueue(unsigned short event, short val)
 
        sa= G.curscreen->areabase.first;
        while(sa) {
+//#ifdef NAN_DEP_GRAPH
+               /* dependency check.maybe not final pos */
+               if (sa->spacetype==SPACE_VIEW3D) {
+                       if (G.scene->dagisvalid == 0) {
+//                             fprintf(stderr,"building dag \n");
+                               G.scene->theDag = build_dag(G.scene, DAG_RL_ALL_BUT_DATA_MASK);
+                               G.scene->dagisvalid = 1;
+                       }
+               }
+//#endif
                if(event==REDRAWALL) {
                        scrarea_queue_winredraw(sa);
                        scrarea_queue_headredraw(sa);
@@ -4230,6 +4526,7 @@ void allqueue(unsigned short event, short val)
                                break;
                        case REDRAWINFO:
                                if(sa->spacetype==SPACE_INFO) {
+                                       scrarea_queue_winredraw(sa);
                                        scrarea_queue_headredraw(sa);
                                }
                                break;
@@ -4438,15 +4735,16 @@ void allspace(unsigned short event, short val)
        }
 }
 
-
-void force_draw()
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw(int header)
 {
        /* draws alle areas that something identical to curarea */
        extern int afterqtest(short win, unsigned short evt);   //editscreen.c
        ScrArea *tempsa, *sa;
 
        scrarea_do_windraw(curarea);
-       
+       if(header) scrarea_do_headdraw(curarea);
+               
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
        while(sa) {
@@ -4455,19 +4753,13 @@ void force_draw()
                                if( ((View3D *)sa->spacedata.first)->lay & ((View3D *)tempsa->spacedata.first)->lay) {
                                        areawinset(sa->win);
                                        scrarea_do_windraw(sa);
+                                       scrarea_do_headdraw(sa);
                                }
                        }
-                       else if(sa->spacetype==SPACE_IPO) {
-                               areawinset(sa->win);
-                               scrarea_do_windraw(sa);
-                       }
-                       else if(sa->spacetype==SPACE_SEQ) {
-                               areawinset(sa->win);
-                               scrarea_do_windraw(sa);
-                       }
-                       else if(sa->spacetype==SPACE_ACTION) {
+                       else {
                                areawinset(sa->win);
                                scrarea_do_windraw(sa);
+                               scrarea_do_headdraw(sa);
                        }
                }
                sa= sa->next;
@@ -4492,12 +4784,14 @@ void force_draw()
        
 }
 
-void force_draw_plus(int type)
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw_plus(int type, int header)
 {
        /* draws all areas that show something like curarea AND areas of 'type' */
        ScrArea *tempsa, *sa;
 
        scrarea_do_windraw(curarea); 
+       if(header) scrarea_do_headdraw(curarea);
 
        tempsa= curarea;
        sa= G.curscreen->areabase.first;
@@ -4506,6 +4800,7 @@ void force_draw_plus(int type)
                        if(ELEM5(sa->spacetype, SPACE_VIEW3D, SPACE_IPO, SPACE_SEQ, SPACE_BUTS, SPACE_ACTION)) {
                                areawinset(sa->win);
                                scrarea_do_windraw(sa);
+                               scrarea_do_headdraw(sa);
                        }
                }
                sa= sa->next;
@@ -4515,7 +4810,8 @@ void force_draw_plus(int type)
        screen_swapbuffers();
 }
 
-void force_draw_all(void)
+/* if header==1, then draw header for curarea too. Excepption for headerprint()... */
+void force_draw_all(int header)
 {
        /* redraws all */
        ScrArea *tempsa, *sa;
@@ -4527,7 +4823,7 @@ void force_draw_all(void)
        while(sa) {
                if(sa->headwin) {
                        scrarea_do_headdraw(sa);
-                       scrarea_do_headchange(sa);
+                       if(sa!=curarea || header) scrarea_do_headchange(sa);
                }
                if(sa->win) {
                        scrarea_do_windraw(sa);