Added baking for softbodies.
[blender.git] / source / blender / src / space.c
index 7e73f924f8124930111f9c83acfe4e400eb89222..dadfbf0f0b23bb3997434082b2ed84f4590926ca 100644 (file)
 #include <config.h>
 #endif
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #ifdef INTERNATIONAL
@@ -55,7 +51,6 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
-#include "BLI_editVert.h"
 #include "BLI_linklist.h"
 
 #include "DNA_action_types.h"
 #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"
 #include "BIF_drawtext.h"
+#include "BIF_drawscript.h"
 #include "BIF_editarmature.h"
 #include "BIF_editfont.h"
 #include "BIF_editika.h"
 #include "BIF_editkey.h"
 #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_gl.h"
 #include "BIF_imasel.h"
 #include "BIF_interface.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 "BDR_editface.h"
 #include "BDR_drawmesh.h"
 #include "BDR_drawobject.h"
+#include "BDR_unwrapper.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 "BPY_extern.h" // Blender Python library
+#include "BIF_transform.h"
+
+#include "BKE_depsgraph.h"
 
 #include "TPT_DependKludge.h"
 #ifdef NAN_TPT
@@ -153,7 +161,6 @@ extern void StartKetsjiShell(ScrArea *area, char* startscenename, struct Main* m
  */
 void space_mipmap_button_function(int event);
 
-unsigned short convert_for_nonumpad(unsigned short event);
 void free_soundspace(SpaceSound *ssound);
 
 /* *************************************** */
@@ -194,6 +201,20 @@ void rem_blockhandler(ScrArea *sa, short eventcode)
        }
 }
 
+void toggle_blockhandler(ScrArea *sa, short eventcode, short val)
+{
+       SpaceLink *sl= sa->spacedata.first;
+       short a, addnew=1;
+       
+       // find if it exists
+       for(a=0; a<SPACE_MAXHANDLER; a+=2) {
+               if( sl->blockhandler[a]==eventcode ) {
+                       sl->blockhandler[a]= 0;
+                       addnew= 0;
+               }
+       }
+       if(addnew) add_blockhandler(sa, eventcode, val);
+}
 
 
 
@@ -252,6 +273,42 @@ void copy_view3d_lock(short val)
        }
 }
 
+void handle_view3d_around()
+{
+       bScreen *sc;
+       
+       if ((U.uiflag & USER_LOCKAROUND)==0) return;
+       
+       /* copies from G.vd->around to other view3ds */
+       
+       sc= G.main->screen.first;
+       
+       while(sc) {
+               if(sc->scene==G.scene) {
+                       ScrArea *sa= sc->areabase.first;
+                       while(sa) {
+                               SpaceLink *sl= sa->spacedata.first;
+                               while(sl) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *vd= (View3D*) sl;
+                                               if (vd != G.vd) {
+                                                       vd->around= G.vd->around;
+                                                       if (G.vd->flag & V3D_ALIGN)
+                                                               vd->flag |= V3D_ALIGN;
+                                                       else
+                                                               vd->flag &= ~V3D_ALIGN;
+                                                       scrarea_queue_headredraw(sa);
+                                               }
+                                       }
+                                       sl= sl->next;
+                               }
+                               sa= sa->next;
+                       }
+               }
+               sc= sc->id.next;
+       }
+}
+
 void handle_view3d_lock()
 {
        if (G.vd != NULL) {
@@ -272,13 +329,13 @@ void space_set_commmandline_options(void) {
                
        if ( (syshandle = SYS_GetSystem()) ) {
                /* User defined settings */
-               a= (U.gameflags & USERDEF_VERTEX_ARRAYS);
+               a= (U.gameflags & USER_VERTEX_ARRAYS);
                SYS_WriteCommandLineInt(syshandle, "vertexarrays", a);
 
-               a= (U.gameflags & USERDEF_DISABLE_SOUND);
+               a= (U.gameflags & USER_DISABLE_SOUND);
                SYS_WriteCommandLineInt(syshandle, "noaudio", a);
 
-               a= (U.gameflags & USERDEF_DISABLE_MIPMAP);
+               a= (U.gameflags & USER_DISABLE_MIPMAP);
                set_mipmap(!a);
                SYS_WriteCommandLineInt(syshandle, "nomipmap", a);
 
@@ -325,7 +382,7 @@ static void RestoreState(void)
 {
        curarea->win_swap = 0;
        curarea->head_swap=0;
-       allqueue(REDRAWVIEW3D, 0);
+       allqueue(REDRAWVIEW3D, 1);
        allqueue(REDRAWBUTSALL, 0);
        reset_slowparents();
        waitcursor(0);
@@ -370,6 +427,7 @@ static void restore_all_scene_cfra(LinkNode *storelist) {
 void start_game(void)
 {
 #if GAMEBLENDER == 1
+#ifndef NO_KETSJI
        Scene *sc, *startscene = G.scene;
        LinkNode *scene_cfra_store;
 
@@ -403,10 +461,11 @@ void start_game(void)
     
        scene_cfra_store= save_and_reset_all_scene_cfra();
        
-       BPY_end_python();
 
+       /* game engine will do its own sounds. */
        sound_stop_all_sounds();
-
+       sound_exit_audio();
+       
        /* Before jumping into Ketsji, we configure some settings. */
        space_set_commmandline_options();
 
@@ -414,7 +473,10 @@ void start_game(void)
        StartKetsjiShell(curarea, startscene->id.name+2, G.main, 1);
        RestoreState();
 
-       BPY_start_python();
+       /* Restart BPY - unload the game engine modules. */
+       BPY_end_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);
        set_scene_bg(startscene);
@@ -427,6 +489,7 @@ void start_game(void)
        allqueue(REDRAWACTION, 0);
        allspace(REMAKEIPO, 0);
        allqueue(REDRAWIPO, 0);
+#endif
 #else
        notice("Game engine is disabled in this release!");
 #endif
@@ -443,7 +506,7 @@ static void changeview3dspace(ScrArea *sa, void *spacedata)
         */
 static void align_view_to_selected(View3D *v3d)
 {
-       int nr= pupmenu("Align view%t|To selection (top)%x2|To selection (front)%x1|To selection (side)%x0");
+       int nr= pupmenu("Align View%t|To Selected (top)%x2|To Selected (front)%x1|To Selected (side)%x0");
 
        if (nr!=-1) {
                int axis= nr;
@@ -465,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;
 
@@ -477,11 +540,11 @@ 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;
-
-       if (!(OBACT->parent)) return;
+       
+       if (!(OBACT) || !(OBACT->parent)) return;
        BASACT->flag &= (~SELECT);
        BASACT->object->flag &= (~SELECT);
        startbase=  FIRSTBASE;
@@ -490,35 +553,45 @@ 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;         
-       if(oldbasact) if(oldbasact != basact) draw_object_ext(oldbasact);
-       basact->object->flag= basact->flag;
-       draw_object_ext(basact);
-       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);
+       }
 }
 
-void group_menu(void)
+
+void select_group_menu(void)
 {
-       Base *base;
-       short nr;
        char *str;
+       short nr;
 
        /* make menu string */
        
        str= MEM_mallocN(160, "groupmenu");
-       strcpy(str, "Group selection%t|Children%x1|"
-                   "Immediate children%x2|Parent%x3|"
-                   "Objects on shared layers%x4");
+       strcpy(str, "Select Grouped%t|Children%x1|"
+                   "Immediate Children%x2|Parent%x3|"
+                   "Objects on Shared Layers%x4");
 
        /* here we go */
        
        nr= pupmenu(str);
        MEM_freeN(str);
+       
+       select_group(nr);
+}
+
+void select_group(short nr)
+{
+       Base *base;
 
        if(nr==4) {
                base= FIRSTBASE;
@@ -540,26 +613,133 @@ void group_menu(void)
        allqueue(REDRAWIPO, 0);
 }
 
-void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
+static unsigned short convert_for_nonumpad(unsigned short event)
+{
+       if (event>=ZEROKEY && event<=NINEKEY) {
+               return event - ZEROKEY + PAD0;
+       } else if (event==MINUSKEY) {
+               return PADMINUS;
+       } else if (event==EQUALKEY) {
+               return PADPLUSKEY;
+       } else if (event==BACKSLASHKEY) {
+               return PADSLASHKEY;
+       } else {
+               return event;
+       }
+}
+
+/* *************** */
+
+void BIF_undo_push(char *str)
+{
+       if(G.obedit) {
+               if(G.obedit->type==OB_MESH)
+                       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) 
+                       BKE_write_undo(str);
+       }
+}
+
+void BIF_undo(void)
+{      
+       if(G.obedit) {
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+                       undo_editmode_step(1);
+       }
+       else {
+               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);
+               }
+       }
+}
+
+void BIF_redo(void)
+{
+       if(G.obedit) {
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+                       undo_editmode_step(-1);
+       }
+       else {
+               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);
+               }
+       }
+}
+
+void BIF_undo_menu(void)
+{
+       if(G.obedit) {
+               if ELEM6(G.obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE)
+                       undo_editmode_menu();
+               allqueue(REDRAWALL, 0);
+       }
+       else {
+               if(G.f & G_WEIGHTPAINT)
+                       ;
+               else if(G.f & G_VERTEXPAINT)
+                       ;
+               else {
+                       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);
+                               }
+                       }
+               }
+       }
+}
+
+/* *************** */
+
+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;
        
        if(curarea->win==0) return;     /* when it comes from sa->headqread() */
        
-       
        if(val) {
 
                if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
-               if(event==MOUSEY) return;
+               if(event==MOUSEY || event==MOUSEX) return;
                
                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 (event==LEFTMOUSE) event = RIGHTMOUSE;
+                       else if (event==RIGHTMOUSE) event = LEFTMOUSE;
+               }
                
                /* TEXTEDITING?? */
                if((G.obedit) && G.obedit->type==OB_FONT) {
@@ -570,18 +750,18 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case MIDDLEMOUSE:
                                /* use '&' here, because of alt+leftmouse which emulates middlemouse */
-                               if(U.flag & VIEWMOVE) {
-                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
+                               if(U.flag & USER_VIEWMOVE) {
+                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
                                                viewmove(0);
-                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
                                                viewmove(2);
-                                       else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
+                                       else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
                                                viewmove(1);
                                }
                                else {
-                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
+                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
                                                viewmove(1);
-                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
                                                viewmove(2);
                                        else
                                                viewmove(0);
@@ -611,7 +791,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        } else {
                                                persptoetsen(PAD4);
                                        }
-                               } else if(U.uiflag & WHEELZOOMDIR) 
+                               } else if(U.uiflag & USER_WHEELZOOMDIR) 
                                        persptoetsen(PADMINUS);
                                else
                                        persptoetsen(PADPLUSKEY);
@@ -642,7 +822,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        } else {
                                                persptoetsen(PAD6);
                                        }
-                               } else if(U.uiflag & WHEELZOOMDIR) 
+                               } else if(U.uiflag & USER_WHEELZOOMDIR) 
                                        persptoetsen(PADPLUSKEY);
                                else
                                        persptoetsen(PADMINUS);
@@ -681,17 +861,24 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                }
                else {
+
+                       if (U.flag & USER_NONUMPAD) {
+                               event= convert_for_nonumpad(event);
+                       }
+
                        switch(event) {
                        
                        case BACKBUFDRAW:
                                backdrawview3d(1);
                                break;
-                               
-                       case LEFTMOUSE:
+                                               
+                       /* LEFTMOUSE and RIGHTMOUSE event codes can be swapped above,
+                        * based on user preference USER_LMOUSESELECT
+                        */
+                       case LEFTMOUSE: 
                                if ((G.obedit) || !(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
                                        mouse_cursor();
-                               }
-                               else if (G.f & G_VERTEXPAINT) {
+                               } else if (G.f & G_VERTEXPAINT) {
                                        vertex_paint();
                                }
                                else if (G.f & G_WEIGHTPAINT){
@@ -703,20 +890,20 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case MIDDLEMOUSE:
                                /* use '&' here, because of alt+leftmouse which emulates middlemouse */
-                               if(U.flag & VIEWMOVE) {
-                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
+                               if(U.flag & USER_VIEWMOVE) {
+                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
                                                viewmove(0);
-                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
                                                viewmove(2);
-                                       else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
+                                       else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
                                                viewmove(1);
                                }
                                else {
-                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
+                                       if((G.qual==LR_SHIFTKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_SHIFTKEY))))
                                                viewmove(1);
-                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
+                                       else if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
                                                viewmove(2);
-                                       else if((G.qual==0) || ((U.flag & TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
+                                       else if((G.qual==0) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==LR_ALTKEY)))
                                                viewmove(0);
                                }
                                break;
@@ -733,14 +920,16 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        else if(G.obedit->type==OB_ARMATURE)
                                                mouse_armature();
                                }
-                               else if((G.obedit) && (G.qual==(LR_CTRLKEY|LR_ALTKEY)))
-                                       mouse_mesh();   // edge select
+                               else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY)))
+                                       mouse_mesh();   // loop select for 1 mousebutton dudes
+                               else if((G.obedit) && (G.qual == (LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)))
+                                       mouse_mesh();   // loop select for 1 mousebutton dudes
                                else if(G.obpose) { 
                                        if (G.obpose->type==OB_ARMATURE)
                                                mousepose_armature();
                                }
                                else if(G.qual==LR_CTRLKEY)
-                                       mouse_select();
+                                       mouse_select(); // also allow in editmode, for vertex parenting
                                else if(G.f & G_FACESELECT)
                                        face_select();
                                else if( G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
@@ -748,7 +937,6 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else
                                        mouse_select();
                                break;
-
                        case WHEELUPMOUSE:
                                /* Regular:   Zoom in */
                                /* Shift:     Scroll up */
@@ -772,7 +960,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        } else {
                                                persptoetsen(PAD4);
                                        }
-                               } else if(U.uiflag & WHEELZOOMDIR) 
+                               } else if(U.uiflag & USER_WHEELZOOMDIR) 
                                        persptoetsen(PADMINUS);
                                else
                                        persptoetsen(PADPLUSKEY);
@@ -802,7 +990,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        } else {
                                                persptoetsen(PAD6);
                                        }
-                               } else if(U.uiflag & WHEELZOOMDIR) 
+                               } else if(U.uiflag & USER_WHEELZOOMDIR) 
                                        persptoetsen(PADPLUSKEY);
                                else
                                        persptoetsen(PADMINUS);
@@ -813,52 +1001,43 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case ONEKEY:
                                ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
-                                       if(G.obedit) {
-                                                       flip_subdivison(G.obedit, 1);
-                                       }
-                                       else if(ob->type == OB_MESH) {
+                                       if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 1);
                                        }
                                }
-                               else
-                                       do_layer_buttons(0); break;
+                               else do_layer_buttons(0); 
+                               break;
+                               
                        case TWOKEY:
                                ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
-                                       if(G.obedit) {
-                                                       flip_subdivison(G.obedit, 2);
-                                       }
-                                       else if(ob->type == OB_MESH) {
+                                       if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 2);
                                        }
                                }
-                               else
-                                       do_layer_buttons(1); 
+                               else do_layer_buttons(1); 
                                break;
+                               
                        case THREEKEY:
                                ob= OBACT;
                                if(G.qual==LR_CTRLKEY) {
-                                       if(G.obedit) {
-                                                       flip_subdivison(G.obedit, 3);
-                                       }
-                                       else if(ob->type == OB_MESH) {
+                                       if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 3);
                                        }
                                }
-                               else
-                                       do_layer_buttons(2); break;
+                               else do_layer_buttons(2); 
+                               break;
+                               
                        case FOURKEY:
                                ob= OBACT;
-                               if(G.qual & LR_CTRLKEY) {
-                                       if(G.obedit) {
-                                                       flip_subdivison(G.obedit, 4);
-                                       }
-                                       else if(ob->type == OB_MESH) {
+                               if(G.qual==LR_CTRLKEY) {
+                                       if(ob && ob->type == OB_MESH) {
                                                flip_subdivison(ob, 4);
                                        }
                                }
-                               else
-                               do_layer_buttons(3); break;
+                               else do_layer_buttons(3); 
+                               break;
+                               
                        case FIVEKEY:
                                do_layer_buttons(4); break;
                        case SIXKEY:
@@ -877,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!
@@ -918,12 +1125,20 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case BKEY:
                                if((G.qual==LR_SHIFTKEY))
                                        set_render_border();
+                               else if((G.qual==LR_ALTKEY)){
+                                       if(G.obedit && G.obedit->type==OB_MESH) {
+                                               /* Loop Select Operations */
+                                               /*   Vertexloop */
+                                               /*   Faceloop   */                                              
+                                               vertex_loop_select(); 
+                                       }
+                               }
                                else if((G.qual==0))
                                        borderselect();
                                break;
                        case CKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       copymenu();
+                                       copy_attr_menu();
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        convertmenu();  /* editobject.c */
@@ -989,6 +1204,15 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        extrude_ika(ob, 1);
                                        }
                                }
+                               else if (G.qual==LR_CTRLKEY) {
+                                       if(G.obedit && G.obedit->type==OB_MESH)
+                                               Edge_Menu();
+                               }
+                               else if (G.qual==LR_SHIFTKEY) {
+                                       if (G.obedit && G.obedit->type==OB_MESH) {
+                                               Transform(TFM_CREASE, CTX_EDGE);
+                                       }
+                               }
                                break;
                        case FKEY:
                                if(G.obedit) {
@@ -1000,7 +1224,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if(G.qual==LR_CTRLKEY)
                                                        edge_flip();
                                                else if (G.qual==0)
-                                                       addedgevlak_mesh();
+                                                       addedgeface_mesh();
                                        }
                                        else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
                                }
@@ -1016,18 +1240,27 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case GKEY:
                                /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
                                else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
-                               
                                if((G.qual==LR_SHIFTKEY))
-                                       group_menu();
-                               else if(G.qual==LR_ALTKEY)
-                                       clear_object('g');
-                               else if((G.qual==0))
-                                       transform('g');
+                                       select_group_menu();
+                               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) {
                                        if(G.obedit->type==OB_MESH) {
-                                               if(G.qual==LR_ALTKEY)
+                                               if(G.qual==LR_CTRLKEY)
+                                                       add_hook();
+                                               else if(G.qual==LR_ALTKEY)
                                                        reveal_mesh();
                                                else if((G.qual==LR_SHIFTKEY))
                                                        hide_mesh(1);
@@ -1035,7 +1268,9 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        hide_mesh(0);
                                        }
                                        else if(G.obedit->type== OB_SURF) {
-                                               if(G.qual==LR_ALTKEY)
+                                               if(G.qual==LR_CTRLKEY)
+                                                       add_hook();
+                                               else if(G.qual==LR_ALTKEY)
                                                        revealNurb();
                                                else if((G.qual==LR_SHIFTKEY))
                                                        hideNurb(1);
@@ -1044,20 +1279,42 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                        else if(G.obedit->type==OB_CURVE) {
                                                if(G.qual==LR_CTRLKEY)
-                                                       autocalchandlesNurb_all(1);     /* flag=1, selected */
+                                                       add_hook();
+                                               else {
+                                                       if(G.qual==LR_CTRLKEY)
+                                                               autocalchandlesNurb_all(1);     /* flag=1, selected */
+                                                       else if((G.qual==LR_SHIFTKEY))
+                                                               sethandlesNurb(1);
+                                                       else if((G.qual==0))
+                                                               sethandlesNurb(3);
+                                                       
+                                                       makeDispList(G.obedit);
+                                                       BIF_undo_push("Handle change");
+                                                       allqueue(REDRAWVIEW3D, 0);
+                                               }
+                                       }
+                                       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))
-                                                       sethandlesNurb(1);
-                                               else if((G.qual==0))
-                                                       sethandlesNurb(3);
-                                               
-                                               makeDispList(G.obedit);
-                                               
-                                               allqueue(REDRAWVIEW3D, 0);
+                                                       hide_mball(1);
+                                               else if((G.qual==0)) 
+                                                       hide_mball(0);
                                        }
                                }
                                else if(G.f & G_FACESELECT)
                                        hide_tface();
-                               
+                               else if(G.obpose) {
+                                       if (G.qual==0)
+                                               hide_selected_pose_bones();
+                                       else if (G.qual==LR_SHIFTKEY)
+                                               hide_unselected_pose_bones();
+                                       else if (G.qual==LR_ALTKEY)
+                                               show_all_pose_bones();
+                               }
                                break;
                        case IKEY:
                                break;
@@ -1126,39 +1383,56 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                selectconnected_posearmature();
                                }
                                else {
-                                       if((G.qual==LR_SHIFTKEY))
-                                               selectlinks();
-                                       else if(G.qual==LR_CTRLKEY)
-                                               linkmenu();
-                                       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:
                                if(G.obedit){
                                        if(G.qual==LR_ALTKEY) {
-                                               if(G.obedit->type==OB_MESH)
+                                               if(G.obedit->type==OB_MESH) {
                                                        mergemenu();
+                                                       makeDispList(G.obedit);
+                                               }
                                        }
-                                       else if((G.qual==0))
+                                       else if((G.qual==0) || (G.qual==LR_CTRLKEY)) {
                                                mirrormenu();
+                                       }
+                                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                               if(G.obedit->type==OB_MESH) select_non_manifold();
+                                       }
                                }
-                               else if((G.qual==0)){
+                               else if(G.qual & LR_CTRLKEY) {
+                                       mirrormenu();
+                               }
+                               else if(G.qual==0) {
                                     movetolayer();
                                }
                                break;
                        case NKEY:
                                if((G.qual==0)) {
-                                       add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
+                                       toggle_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_TO_MOUSE);
                                        allqueue(REDRAWVIEW3D, 0);
                                }
                                else if(G.obedit) {
                                        switch (G.obedit->type){
                                        case OB_ARMATURE:
                                                if(G.qual==LR_CTRLKEY){
-                                                       if (okee("Recalc bone roll angles")) {
+                                                       if (okee("Recalculate bone roll angles")) {
                                                                auto_align_armature();
                                                                allqueue(REDRAWVIEW3D, 0);
                                                        }
@@ -1166,17 +1440,17 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                break;
                                        case OB_MESH: 
                                                if(G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
-                                                       if(okee("Recalc normals inside")) {
-                                                               undo_push_mesh("Recalc normals inside");
+                                                       if(okee("Recalculate normals inside")) {
                                                                righthandfaces(2);
                                                                allqueue(REDRAWVIEW3D, 0);
+                                                               BIF_undo_push("Recalculate normals inside");
                                                        }
                                                }
                                                else if(G.qual==LR_CTRLKEY){
-                                                       if(okee("Recalc normals outside")) {
-                                                               undo_push_mesh("Recalc normals outside");
+                                                       if(okee("Recalculate normals outside")) {
                                                                righthandfaces(1);
                                                                allqueue(REDRAWVIEW3D, 0);
+                                                               BIF_undo_push("Recalculate normals outside");
                                                        }
                                                }
                                                break;
@@ -1186,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)) {
@@ -1200,24 +1473,31 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if((G.qual==LR_SHIFTKEY)) {
                                        if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, 0);
+                                               flip_subdivison(ob, -1);
+                                       }
+                               }
+                               else if(G.qual==LR_ALTKEY) {
+                                       if(okee("Clear origin")) {
+                                               clear_object('o');
                                        }
                                }
-                               else if(G.qual==LR_ALTKEY) clear_object('o');
                                break;
 
                        case PKEY:
-                               
                                if(G.obedit) {
-                                       if(G.qual==LR_CTRLKEY)
+                                       if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                                make_parent();
                                        else if((G.qual==0) && G.obedit->type==OB_MESH)
                                                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)
+                               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)) {
@@ -1227,43 +1507,71 @@ 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)                                     
                                                        selectrow_nurb();
                                                else if (G.obedit->type==OB_MESH)
-                                                       loop('s');
+                                                       loopoperations(LOOP_SELECT);
                                        }
                                        else if(G.qual==LR_CTRLKEY) {
                                                if (G.obedit->type==OB_MESH)
-                                                       loop('c');
+                                                       loopoperations(LOOP_CUT);
+                                       }
+                                       else if((G.qual==0)) {
+                                               Transform(TFM_ROTATION, CTX_NONE);
                                        }
-                                       else if((G.qual==0))
-                                               transform('r');
                                }
-                               else if((G.qual==0))
-                                       transform('r');
+                               else if((G.qual==0)) {
+                                       Transform(TFM_ROTATION, CTX_NONE);
+                               }
                                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){
@@ -1273,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();
@@ -1291,32 +1603,27 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case UKEY:
                                if(G.obedit) {
-                                       if(G.obedit->type==OB_MESH){
-                                               if (G.qual==LR_ALTKEY)
-                                                       undo_menu_mesh();
-                                               else if (G.qual==LR_SHIFTKEY)
-                                                       undo_redo_mesh();
-                                               else if((G.qual==0))
-                                                       undo_pop_mesh(1);
+                                       if(G.obedit->type==OB_MESH) {
+                                               if(G.qual==0) BIF_undo(); else BIF_redo();
                                        }
                                        else if(G.obedit->type==OB_ARMATURE)
                                                remake_editArmature();
-                                       else if ELEM(G.obedit->type, OB_CURVE, OB_SURF)
-                                               remake_editNurb();
-                                       else if(G.obedit->type==OB_LATTICE)
-                                               remake_editLatt();
+                                       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.qual==0)){
+                               else if((G.qual==0)) {
                                        if (G.f & G_FACESELECT)
                                                uv_autocalc_tface();
                                        else if(G.f & G_WEIGHTPAINT)
                                                wpaint_undo();
                                        else if(G.f & G_VERTEXPAINT)
                                                vpaint_undo();
-                                       else
+                                       else {
                                                single_user();
+                                       }
                                }
-                               
+                                       
                                break;
                        case VKEY:
                                ob= OBACT;
@@ -1336,6 +1643,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        sethandlesNurb(2);
                                                        makeDispList(G.obedit);
                                                        allqueue(REDRAWVIEW3D, 0);
+                                                       BIF_undo_push("Handle change");
                                                }
                                        }
                                        else if(ob && ob->type == OB_MESH) 
@@ -1344,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(); */
@@ -1376,24 +1684,33 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                scrarea_queue_headredraw(curarea);
                                scrarea_queue_winredraw(curarea);
                                break;
-                               
                        
                        case HOMEKEY:
                                if(G.qual==0)
                                        view3d_home(0);
                                break;
                        case COMMAKEY:
-                               if(G.qual==0) {
+                               if(G.qual==LR_CTRLKEY) {
+                                       G.vd->around= V3D_CENTROID;
+                               } else if(G.qual==LR_SHIFTKEY) {
+                                       G.vd->around= V3D_CENTROID;
+                               } else if(G.qual==0) {
                                        G.vd->around= V3D_CENTRE;
-                                       scrarea_queue_headredraw(curarea);
                                }
+                               handle_view3d_around();
+                               
+                               scrarea_queue_headredraw(curarea);
                                break;
                                
                        case PERIODKEY:
-                               if(G.qual==0) {
+                               if(G.qual==LR_CTRLKEY) {
+                                       G.vd->around= V3D_LOCAL;
+                               }       else if(G.qual==0) {
                                        G.vd->around= V3D_CURSOR;
-                                       scrarea_queue_headredraw(curarea);
                                }
+                               handle_view3d_around();
+                               
+                               scrarea_queue_headredraw(curarea);
                                break;
                        
                        case PADSLASHKEY:
@@ -1413,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);
                                        }
@@ -1440,11 +1768,30 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                        case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
                        case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
-                       case PADMINUS: case PADPLUSKEY: case PADENTER:
+                       case PADENTER:
                                persptoetsen(event);
                                doredraw= 1;
                                break;
-                       
+                       case PADMINUS:
+                               if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_MESH) )
+                                       select_less();
+                               else {
+                                       persptoetsen(event);
+                                       doredraw= 1;
+                               }
+                               break;
+
+                       case PADPLUSKEY:
+                               if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_MESH) )
+                                       select_more();
+                               else {
+                                       persptoetsen(event);
+                                       doredraw= 1;
+                               }
+                               break;
+
                        case ESCKEY:
                                if(G.qual==0) {
                                        if (G.vd->flag & V3D_DISPIMAGE) {
@@ -1463,7 +1810,7 @@ void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        }
 }
 
-void initview3d(ScrArea *sa)
+static void initview3d(ScrArea *sa)
 {
        View3D *vd;
        
@@ -1471,6 +1818,7 @@ void initview3d(ScrArea *sa)
        BLI_addhead(&sa->spacedata, vd);        /* addhead! not addtail */
 
        vd->spacetype= SPACE_VIEW3D;
+       vd->blockscale= 0.7;
        vd->viewquat[0]= 1.0;
        vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0;
        vd->persp= 1;
@@ -1488,6 +1836,10 @@ void initview3d(ScrArea *sa)
                vd->camera= G.scene->camera;
        }
        vd->scenelock= 1;
+       vd->gridflag |= V3D_SHOW_X;
+       vd->gridflag |= V3D_SHOW_Y;
+       vd->gridflag |= V3D_SHOW_FLOOR;
+       vd->gridflag &= ~V3D_SHOW_Z;
 }
 
 
@@ -1501,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;
@@ -1511,17 +1863,28 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        float dx, dy;
        int cfra, doredraw= 0;
        short mval[2];
+       short mousebut = L_MOUSE;
        
-
        if(sa->win==0) return;
 
        if(val) {
                if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
 
+               /* swap mouse buttons based on user preference */
+               if (U.flag & USER_LMOUSESELECT) {
+                       if (event == LEFTMOUSE) {
+                               event = RIGHTMOUSE;
+                               mousebut = L_MOUSE;
+                       } else if (event == RIGHTMOUSE) {
+                               event = LEFTMOUSE;
+                               mousebut = R_MOUSE;
+                       }
+               }
+
                switch(event) {
                case UI_BUT_EVENT:
                        /* note: bad bad code, will be cleaned! is because event queues are all shattered */
-                       if(val>0 && val < 32) do_ipowin_buts(val-1);
+                       if(val>0 && val < 65) do_ipowin_buts(val-1);
                        else do_ipobuts(val);
                        break;
                        
@@ -1529,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 {
@@ -1542,14 +1906,17 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if( cfra!=CFRA ) {
                                                CFRA= cfra;
                                                update_for_newframe();
-                                               force_draw_plus(SPACE_VIEW3D);
-                                               force_draw_plus(SPACE_ACTION);
-                                               force_draw_plus(SPACE_BUTS);    /* To make constraint sliders redraw */
+                                               force_draw_all(0); /* To make constraint sliders redraw */
                                        }
+                                       else PIL_sleep_ms(30);
                                
-                               } while(get_mbut()&L_MOUSE);
+                               } while(get_mbut() & mousebut);
                        }
-                       
+                       break;
+               case RIGHTMOUSE:
+                       mouse_select_ipo();
+                       allqueue (REDRAWACTION, 0);
+                       allqueue(REDRAWNLA, 0);
                        break;
                case MIDDLEMOUSE:
                        if(in_ipo_buttons()) {
@@ -1557,17 +1924,10 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                        else view2dmove(event); /* in drawipo.c */
                        break;
-
                case WHEELUPMOUSE:
                case WHEELDOWNMOUSE:
                        view2dmove(event);      /* in drawipo.c */
                        break;
-
-               case RIGHTMOUSE:
-                       mouse_select_ipo();
-                       allqueue (REDRAWACTION, 0);
-                       allqueue(REDRAWNLA, 0);
-                       break;
                case PADPLUSKEY:
                        view2d_zoom(v2d, 0.1154, sa->winx, sa->winy);
                        doredraw= 1;
@@ -1598,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);
@@ -1628,7 +1990,7 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        break;
                case JKEY:
                        if((G.qual==0))
-                               join_ipo();
+                               join_ipo_menu();
                        break;
                case KKEY:
                        if((G.qual==0)) {
@@ -1639,7 +2001,7 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                        break;
                case NKEY:
-                       add_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
+                       toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
                        doredraw= 1;
                        break;
                case RKEY:
@@ -1647,9 +2009,9 @@ void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                ipo_record();
                        break;
                case SKEY:
-                       if((G.qual==LR_SHIFTKEY))
-                               ipo_snapmenu();
-                       else if((G.qual==0))
+                       if((G.qual==LR_SHIFTKEY)) {             
+                               ipo_snap_menu();
+                       else if((G.qual==0))
                                transform_ipo('s');
                        break;
                case TKEY:
@@ -1681,6 +2043,8 @@ void initipo(ScrArea *sa)
        BLI_addhead(&sa->spacedata, sipo);
 
        sipo->spacetype= SPACE_IPO;
+       sipo->blockscale= 0.7;
+       
        /* sipo space loopt van (0,-?) tot (??,?) */
        sipo->v2d.tot.xmin= 0.0;
        sipo->v2d.tot.ymin= -10.0;
@@ -1704,22 +2068,24 @@ void initipo(ScrArea *sa)
 /* ******************** SPACE: INFO ********************** */
 
 void space_mipmap_button_function(int event) {
-       set_mipmap(!(U.gameflags & USERDEF_DISABLE_MIPMAP));
+       set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
 
        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;
 
        if ((syshandle = SYS_GetSystem()))
        {
-               a = (U.gameflags & USERDEF_DISABLE_SOUND);
+               a = (U.gameflags & USER_DISABLE_SOUND);
                SYS_WriteCommandLineInt(syshandle, "noaudio", a);
        }
 }
+#endif
 
 #define B_ADD_THEME    3301
 #define B_DEL_THEME    3302
@@ -1737,13 +2103,13 @@ 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;
        static short cur=1, curmain=2;
        short a, tot=0, isbuiltin= 0;
-       char string[20*32], *strp, *col;
+       char string[21*32], *strp, *col;
        
        y3= y2+23;      // exception!
        
@@ -1757,6 +2123,7 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
                        if(a==cur) {
                                BLI_remlink(&U.themes, bt);
                                BLI_addhead(&U.themes, bt);
+                               allqueue(REDRAWALL, 0);
                                cur= 1;
                                break;
                        }
@@ -1788,9 +2155,9 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        uiDefBut(block, TEX, B_NAME_THEME, "",                  255,y3,200,20, btheme->name, 1.0, 30.0, 0, 0, "Rename theme");
 
        /* main choices pup */
-       uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|3D View %x2|Ipo Curve Editor %x3|Action Editor %x4|"
-               "NLA Editor %x5|UV/Image Editor %x6|Sequence Editor %x7|Sound Editor %x8|Text Editor %x9|User Preferences %x10|"
-               "OOPS Schematic %x11|Buttons Window %x12|File Window %x13|Image Browser %x14",
+       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|"
+               "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;
@@ -1811,7 +2178,7 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        /* color choices pup */
        if(curmain==1) {
                strp= BIF_ThemeColorsPup(0);
-               if(th_curcol==TH_BACK) th_curcol= TH_BUT_NEUTRAL;  // switching main choices...
+               if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
        }
        else strp= BIF_ThemeColorsPup(spacetype);
        
@@ -1825,25 +2192,35 @@ void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        if(th_curcol==TH_VERTEX_SIZE) {
                uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Vertex size ", 465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
        }
+       else if(th_curcol==TH_FACEDOT_SIZE) {
+               uiDefButC(block, NUMSLI, B_UPDATE_THEME,"Face dot size ",       465,y3,200,20,  col, 1.0, 10.0, 0, 0, "");
+       }
        else if(th_curcol==TH_BUT_DRAWTYPE) {
-               uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,200,20,  col, 2.0, 0.0, 0, 0, "");
-               uiDefButC(block, ROW, B_UPDATE_THEME, "Default",        465,y2,200,20,  col, 2.0, 1.0, 0, 0, "");
-       
+               uiBlockBeginAlign(block);
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal",        465,y3,100,20,  col, 2.0, 0.0, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, 1.0, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded",        465,y2,100,20,  col, 2.0, 2.0, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool",       565,y2,100,20,  col, 2.0, 3.0, 0, 0, "");
+               uiBlockEndAlign(block);
        }
        else {
+               uiBlockBeginAlign(block);
+               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, "");
                uiDefButC(block, NUMSLI, B_UPDATE_THEME,"G ",   465,y2,200,20,  col+1, 0.0, 255.0, B_THEMECOL, 0, "");
                uiDefButC(block, NUMSLI, B_UPDATE_THEME,"B ",   465,y1,200,20,  col+2, 0.0, 255.0, B_THEMECOL, 0, "");
+               uiBlockEndAlign(block);
 
-               uiDefButC(block, COL, B_THEMECOL, "",           675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
-               if ELEM3(th_curcol, TH_PANEL, TH_FACE, TH_FACE_SELECT) {
-                       uiDefButC(block, NUMSLI, B_UPDATE_THEME,"A ",   465,y3+25,200,20,  col+3, 0.0, 255.0, B_THEMECOL, 0, "");
-               }
-               
+               uiDefButC(block, COL, B_UPDATE_THEME, "",               675,y1,50,y3-y1+20, col, 0, 0, 0, 0, "");
+                               
                /* copy paste */
+               uiBlockBeginAlign(block);
                uiDefBut(block, BUT, B_THEME_COPY, "Copy Color",        755,y2,120,20, NULL, 0, 0, 0, 0, "Stores current color in buffer");
                uiDefBut(block, BUT, B_THEME_PASTE, "Paste Color",      755,y1,120,20, NULL, 0, 0, 0, 0, "Pastes buffer color");
-
+               uiBlockEndAlign(block);
+               
                uiDefButC(block, COL, 0, "",                            885,y1,50,y2-y1+20, th_curcol_arr, 0, 0, 0, 0, "");
                
        }
@@ -1855,9 +2232,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        uiBlock *block;
        static short cur_light=0, cur_light_var=0;
        float fac, col[3];
-       short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y2label, y3label, y4label;
-       short smallprefbut, medprefbut, largeprefbut, smfileselbut;
-       short edgespace, midspace;
+       short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
+       short y2label, y3label, y4label, y5label, y6label;
+       short spref, mpref, lpref, smfileselbut;
+       short edgsp, midsp;
        char naam[32];
 
        if(curarea->win==0) return;
@@ -1866,76 +2244,87 @@ 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);
 
 
+       /* Vars for nice grid alignment */ 
        dx= (1280-90)/7;        /* spacing for use in equally dividing 'tab' row */
 
        xpos = 45;              /* left padding */
        ypos = 50;              /* bottom padding for buttons */
        ypostab = 10;           /* bottom padding for 'tab' row */
 
-
        buth = 20;              /* standard button height */
 
-       smallprefbut = 94;      /* standard size for small preferences button */
-       medprefbut = 193;       /* standard size for medium preferences button */
-       largeprefbut = 292;     /* standard size for large preferences button */
+       spref = 90;     /* standard size for small preferences button */
+       mpref = 189;    /* standard size for medium preferences button */
+       lpref = 288;    /* standard size for large preferences button */
        smfileselbut = buth;    /* standard size for fileselect button (square) */
-       
-       edgespace = 3;          /* space from edge of end 'tab' to edge of end button */
-       midspace = 5;           /* horizontal space between buttons */
+
+       edgsp = 3;              /* space from edge of end 'tab' to edge of end button */
+       midsp = 9;              /* horizontal space between buttons */
 
        rspace = 3;             /* default space between rows */
 
-       y1 = ypos;              /* bottom padding of 1st (bottom) button row */
-       y2 = ypos+buth+rspace;  /* bottom padding of 2nd button row */
-       y3 = ypos+2*(buth+rspace)+(3*rspace);   /* bottom padding of 3rd button row */
-       y4 = ypos+3*(buth+rspace)+(3*rspace);   /* bottom padding of 4th button row */
+       y1 = ypos;              /* grid alignment for each row of buttons */
+       y2 = ypos+buth+rspace;
+       y3 = ypos+2*(buth+rspace);
+       y4 = ypos+3*(buth+rspace);
+       y5 = ypos+4*(buth+rspace);
+       y6 = ypos+5*(buth+rspace);
+
 
        y2label = y2-2;         /* adjustments to offset the labels down to align better */
-       y3label = y3-(3*rspace)-2;      /* again for 3rd row */
-       y4label = y4-2;         /* again for 4th row */
+       y3label = y3-2;
+       y4label = y4-2;
+       y5label = y5-2;
+       y6label = y6-2;
 
 
        /* set the colour to blue and draw the main 'tab' controls */
 
        uiBlockSetCol(block, TH_BUT_SETTING1);
-
-       uiDefButI(block, ROW,B_USERPREF,"View & Controls",
+       uiBlockBeginAlign(block);
+       
+       uiDefButS(block, ROW,B_USERPREF,"View & Controls",
                xpos,ypostab,(short)dx,buth,
                &U.userpref,1.0,0.0, 0, 0,"");
                
-       uiDefButI(block, ROW,B_USERPREF,"Edit Methods",
+       uiDefButS(block, ROW,B_USERPREF,"Edit Methods",
                (short)(xpos+dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,1.0, 0, 0,"");
 
-       uiDefButI(block, ROW,B_USERPREF,"Language & Font",
+       uiDefButS(block, ROW,B_USERPREF,"Language & Font",
                (short)(xpos+2*dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,2.0, 0, 0,"");
 
-       uiDefButI(block, ROW,B_USERPREF,"Themes",
+       uiDefButS(block, ROW,B_USERPREF,"Themes",
                (short)(xpos+3*dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,6.0, 0, 0,"");
 
-       uiDefButI(block, ROW,B_USERPREF,"Auto Save",
+       uiDefButS(block, ROW,B_USERPREF,"Auto Save",
                (short)(xpos+4*dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,3.0, 0, 0,"");
 
-       uiDefButI(block, ROW,B_USERPREF,"System & OpenGL",
+       uiDefButS(block, ROW,B_USERPREF,"System & OpenGL",
                (short)(xpos+5*dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,4.0, 0, 0,"");
                
-       uiDefButI(block, ROW,B_USERPREF,"File Paths",
+       uiDefButS(block, ROW,B_USERPREF,"File Paths",
                (short)(xpos+6*dx),ypostab,(short)dx,buth,
                &U.userpref,1.0,5.0, 0, 0,"");
 
        uiBlockSetCol(block, TH_AUTO);
-
+       uiBlockEndAlign(block);
        /* end 'tab' controls */
 
         /* line 2: left x co-ord, top y co-ord, width, height */
@@ -1946,269 +2335,333 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        else if (U.userpref == 0) { /* view & controls */
 
                uiDefBut(block, LABEL,0,"Display:",
-                       xpos,y3label,medprefbut,buth,
-                       0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOG|BIT|11, 0, "ToolTips",
-                       (xpos+edgespace),y2,smallprefbut,buth,
+                       xpos,y6label,spref,buth,
+                       0, 0, 0, 0, 0, "");     
+               uiDefButBitS(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
+                       (xpos+edgsp),y5,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Displays tooltips (help tags) over buttons");
-
-               uiDefButS(block, TOG|BIT|4, B_DRAWINFO, "Object Info",
-                       (xpos+edgespace+midspace+smallprefbut),y2,smallprefbut,buth,
+                       "Display tooltips (help tags) over buttons");
+               uiDefButBitS(block, TOG, USER_DRAWVIEWINFO, B_DRAWINFO, "Object Info",
+                       (xpos+edgsp),y4,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
-                       "Displays current object name and frame number in the 3D viewport");
-
-               uiDefButS(block, TOG|BIT|4, 0, "Global Scene",
-                       (xpos+edgespace),y1,medprefbut,buth,
+                       "Display active object name and frame number in the 3D View");
+               uiDefButBitS(block, TOG, USER_SCENEGLOBAL, 0, "Global Scene",
+                       (xpos+edgsp),y3,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Forces the current Scene to be displayed in all Screens");
+#ifndef __APPLE__      
+               uiDefButS(block, TOG|BIT|0, 0, "Large Cursors",
+                       (xpos+edgsp),y2,spref,buth,
+                       &(U.curssize), 0, 0, 0, 0,
+                       "Use large mouse cursors when available");
+#else 
+               U.curssize=0; /*Small Cursor always for OS X for now */
+#endif
 
-
-               uiDefBut(block, LABEL,0,"Snap to grid:",
-                       (xpos+edgespace+medprefbut),y3label,medprefbut,buth,
-                       0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOG|BIT|1, 0, "Grab",
-                       (xpos+edgespace+medprefbut+midspace),y2,smallprefbut,buth,
-                       &(U.flag), 0, 0, 0, 0,
-                       "Move objects to grid units");
-
-               uiDefButS(block, TOG|BIT|3, 0, "Size",
-                       (xpos+edgespace+medprefbut+midspace),y1,smallprefbut,buth,
-                       &(U.flag), 0, 0, 0, 0,
-                       "Scale objects to grid units");
-
-               uiDefButS(block, TOG|BIT|2, 0, "Rotate",
-                       (xpos+edgespace+medprefbut+(2*midspace)+smallprefbut),y2,smallprefbut,buth,
-                       &(U.flag), 0, 0, 0, 0,
-                       "Rotate objects to grid units");
-
-
-
-               uiDefBut(block, LABEL,0,"Menu Buttons:",
-                       (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y3label,medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Menus:",
+                       (xpos+(2*edgsp)+spref),y6label,spref,buth,
                        0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOG|BIT|9, 0, "Auto Open",
-                       (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_MENUOPENAUTO, 0, "Open on Mouse Over",
+                       (xpos+edgsp+spref+midsp),y5,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
-                       "Automatic opening of menu buttons");
-
-               uiDefButS(block, NUM, 0, "ThresA:",
-                       (xpos+edgespace+medprefbut+(3*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
+                       "Open menu buttons and pulldowns automatically when the mouse is hovering");
+               uiDefButS(block, NUM, 0, "Top Level:",
+                       (xpos+edgsp+spref+midsp),y4,spref+edgsp,buth,
                        &(U.menuthreshold1), 1, 40, 0, 0,
-                       "Time in 1/10 seconds for auto open");
-
-               uiDefButS(block, NUM, 0, "ThresB:",
-                       (xpos+edgespace+medprefbut+(4*midspace)+(3*smallprefbut)),y1,smallprefbut,buth,
+                       "Time delay in 1/10 seconds before automatically opening top level menus");
+               uiDefButS(block, NUM, 0, "Sublevels:",
+                       (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y4,spref+edgsp,buth,
                        &(U.menuthreshold2), 1, 40, 0, 0,
-                       "Time in 1/10 seconds for auto open sublevels");
+                       "Time delay in 1/10 seconds before automatically opening menu sublevels");
 
-
-               uiDefBut(block, LABEL,0,"Toolbox Thresh.:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Toolbox click-hold delay:",
+                       (xpos+(2*edgsp)+spref),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
                uiDefButS(block, NUM, 0, "LMB:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,smallprefbut,buth,
+                       (xpos+edgsp+spref+midsp),y2,spref+edgsp,buth,
                        &(U.tb_leftmouse), 2, 40, 0, 0,
-                       "Time in 1/10 seconds leftmouse hold to open toolbox");
-
+                       "Time in 1/10 seconds to hold the Left Mouse Button before opening the toolbox");
                uiDefButS(block, NUM, 0, "RMB:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,smallprefbut,buth,
+                       (xpos+edgsp+(2*spref)+(2*midsp)-edgsp),y2,spref+edgsp,buth,
                        &(U.tb_rightmouse), 2, 40, 0, 0,
-                       "Time in 1/10 seconds for rightmouse to open toolbox");
-
-                       
+                       "Time in 1/10 seconds to hold the Right Mouse Button before opening the toolbox");      
+               uiDefButBitS(block, TOG, USER_PANELPINNED, 0, "Pin Floating Panels",
+                       (xpos+edgsp+spref+midsp),y1,mpref,buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
+               
+               
+               uiDefBut(block, LABEL,0,"Snap to grid:",
+                       (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
+                       0, 0, 0, 0, 0, "");
+               uiDefButBitS(block, TOG, USER_AUTOGRABGRID, 0, "Grab/Move",
+                       (xpos+edgsp+mpref+spref+(2*midsp)),y5,spref,buth,
+                       &(U.flag), 0, 0, 0, 0,
+                       "Snap objects and sub-objects to grid units when moving");
+               uiDefButBitS(block, TOG, USER_AUTOROTGRID, 0, "Rotate",
+                       (xpos+edgsp+mpref+spref+(2*midsp)),y4,spref,buth,
+                       &(U.flag), 0, 0, 0, 0,
+                       "Snap objects and sub-objects to grid units when rotating");
+               uiDefButBitS(block, TOG, USER_AUTOSIZEGRID, 0, "Scale",
+                       (xpos+edgsp+mpref+spref+(2*midsp)),y3,spref,buth,
+                       &(U.flag), 0, 0, 0, 0,
+                       "Snap objects and sub-objects to grid units when scaling");
+               
+               uiDefButBitS(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
+                       (xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Lock the same rotation/scaling pivot in all 3D Views");        
+               
+               uiDefBut(block, LABEL,0,"View zoom:",
+                       (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y6label,mpref,buth,
+                       0, 0, 0, 0, 0, "");
+               uiBlockBeginAlign(block);
+               uiDefButS(block, ROW, 0, "Continue",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y5,(mpref/3),buth,
+                       &(U.viewzoom), 40, USER_ZOOM_CONT, 0, 0,
+                       "Old style zoom, continues while moving mouse up or down");
+               uiDefButS(block, ROW, 0, "Dolly",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/3)),y5,(mpref/3),buth,
+                       &(U.viewzoom), 40, USER_ZOOM_DOLLY, 0, 0,
+                       "Zooms in and out based on vertical mouse movement.");
+               uiDefButS(block, ROW, 0, "Scale",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(2*mpref/3)),y5,(mpref/3),buth,
+                       &(U.viewzoom), 40, USER_ZOOM_SCALE, 0, 0,
+                       "Zooms in and out like scaling the view, mouse movements relative to center.");
+               uiBlockEndAlign(block);
+               
                uiDefBut(block, LABEL,0,"View rotation:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y3label,medprefbut,buth,
+                       (xpos+(2*edgsp)+mpref+(2*spref)+(2*midsp)),y4label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOG|BIT|5, B_DRAWINFO, "Trackball",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
+               uiBlockBeginAlign(block);
+               uiDefButBitS(block, TOG, USER_TRACKBALL, B_DRAWINFO, "Trackball",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y3,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Use trackball style rotation with middle mouse button");
-
-               uiDefButS(block, TOGN|BIT|5, B_DRAWINFO, "Turntable",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut+2),y1,(smallprefbut+2),buth,
+                       "Allow the view to tumble freely when orbiting with the Middle Mouse Button");
+               uiDefButBitS(block, TOGN, USER_TRACKBALL, B_DRAWINFO, "Turntable",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y3,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0,
-                       "Use turntable style rotation with middle mouse button");
-
-
-
-               uiDefButS(block, TOGN|BIT|10, B_DRAWINFO, "Rotate View",
-                       (xpos+edgespace+(4*midspace)+(4*medprefbut)),y2,(smallprefbut+2),buth,
-                       &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
-
-               uiDefButS(block, TOG|BIT|10, B_DRAWINFO, "Pan View",
-                       (xpos+edgespace+(4*midspace)+(4*medprefbut)+smallprefbut+2),y2,(smallprefbut+2),buth,
-                       &(U.flag), 0, 0, 0, 0, "Default action for the middle mouse button");
+                       "Keep the Global Z axis pointing upwards when orbiting the view with the Middle Mouse Button");
+               uiBlockEndAlign(block);
+               
+               uiDefButBitS(block, TOG, USER_AUTOPERSP, B_DRAWINFO, "Auto Perspective",
+                       (xpos+edgsp+mpref+(2*spref)+(3*midsp)),y1,spref,buth,
+                       &(U.uiflag), 0, 0, 0, 0,
+                       "Automatically switch between orthographic and perspective when changing from top/front/side views");
 
-               uiDefBut(block, LABEL,0,"Middle mouse button:",
-                       (xpos+edgespace+(3*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Select with:",
+                       (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButS(block, TOG|BIT|12, 0, "Emulate 3 Buttons",
-                       (xpos+edgespace+(4*midspace)+(4*medprefbut)),y1,medprefbut,buth,
+               uiBlockBeginAlign(block);
+               uiDefButBitS(block, TOG, USER_LMOUSESELECT, B_DRAWINFO, "Left Mouse",
+                       (xpos+edgsp+(3*mpref)+(4*midsp)),y5,(mpref/2),buth,
+                       &(U.flag), 0, 0, 0, 0, "Use the Left Mouse Button for selection");
+               uiDefButBitS(block, TOGN, USER_LMOUSESELECT, B_DRAWINFO, "Right Mouse",
+                       (xpos+edgsp+(3*mpref)+(4*midsp)+(mpref/2)),y5,(mpref/2),buth,
+                       &(U.flag), 0, 0, 0, 0, "Use the Right Mouse Button for selection");
+               uiBlockEndAlign(block);
+               
+               
+               if(U.flag & USER_LMOUSESELECT) {
+                       uiDefBut(block, LABEL,0,"Cursor with: Right Mouse",
+                               (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
+                               0, 0, 0, 0, 0, "");
+               } else {
+                       uiDefBut(block, LABEL,0,"Cursor with: Left Mouse",
+                               (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y4label+5,mpref,buth,
+                               0, 0, 0, 0, 0, "");
+               }
+               
+               /* 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");
-
-
-
-
-               uiDefBut(block, LABEL,0,"Mousewheel:",
-                       (xpos+edgespace+(4*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
+                       "Emulates Middle Mouse with Alt+LeftMouse (doesnt work with Left Mouse Select option)");
+               
+                       
+               uiDefBut(block, LABEL,0,"Middle Mouse Button:",
+                       (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-               uiDefButS(block, TOG|BIT|2, 0, "Invert Wheel Zoom",
-                       (xpos+edgespace+(5*midspace)+(5*medprefbut)),y1,medprefbut,buth,
+               uiBlockBeginAlign(block);
+               uiDefButBitS(block, TOGN, USER_VIEWMOVE, B_DRAWINFO, "Rotate View",
+                       (xpos+edgsp+(4*mpref)+(5*midsp)),y5,(mpref/2),buth,
+                       &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
+               uiDefButBitS(block, TOG, USER_VIEWMOVE, B_DRAWINFO, "Pan View",
+                       (xpos+edgsp+(4*mpref)+(5*midsp)+(mpref/2)),y5,(mpref/2),buth,
+                       &(U.flag), 0, 0, 0, 0, "Default action for the Middle Mouse Button");
+               uiBlockEndAlign(block);
+                       
+               uiDefBut(block, LABEL,0,"Mouse Wheel:",
+                       (xpos+(2*edgsp)+(4*mpref)+(4*midsp)),y4label,mpref,buth,
+                       0, 0, 0, 0, 0, "");
+               uiDefButBitS(block, TOG, USER_WHEELZOOMDIR, 0, "Invert Zoom",
+                       (xpos+edgsp+(4*mpref)+(5*midsp)),y3,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
-                       "Swaps mouse wheel zoom direction");
-
-
+                       "Swap the Mouse Wheel zoom direction");
                uiDefButI(block, NUM, 0, "Scroll Lines:",
-                       (xpos+edgespace+(5*midspace)+(5*medprefbut)),y2,medprefbut,buth,
+                       (xpos+edgsp+(4*mpref)+(6*midsp)+spref-edgsp),y3,spref+edgsp,buth,
                        &U.wheellinescroll, 0.0, 32.0, 0, 0,
-                       "The number of lines scrolled at a time with the mouse wheel");
-
-
+                       "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 */
 
 
                uiDefBut(block, LABEL,0,"Material linked to:",
-                       xpos,y3label,medprefbut,buth,
+                       xpos,y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOGN|BIT|8, B_DRAWINFO, "ObData",
-                       (xpos+edgespace),y2,(smallprefbut),buth,
+               uiBlockBeginAlign(block);
+               uiDefButBitS(block, TOGN, USER_MAT_ON_OB, B_DRAWINFO, "ObData",
+                       (xpos+edgsp),y2,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Link new objects' material to the obData block");
-
-               uiDefButS(block, TOG|BIT|8, B_DRAWINFO, "Object",
-                       (xpos+edgespace+midspace+smallprefbut),y2,(smallprefbut),buth,
+               uiDefButBitS(block, TOG, USER_MAT_ON_OB, B_DRAWINFO, "Object",
+                       (xpos+edgsp+(mpref/2)),y2,(mpref/2),buth,
                        &(U.flag), 0, 0, 0, 0, "Link new objects' material to the object block");
+               uiBlockEndAlign(block);
 
 
-
-               uiDefBut(block, LABEL,0,"Mesh Undo",
-                       (xpos+edgespace+medprefbut),y3label, medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Editmode undo:",
+                       (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
                        0, 0, 0, 0, 0, "");
-
                uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
-                       (xpos+edgespace+medprefbut+midspace),y2,(medprefbut),buth,
-                               &(U.undosteps), 1, 64, 0, 0, "Number of undo steps avail. in Editmode.  Smaller conserves memory.");
+                       (xpos+edgsp+mpref+midsp),y2,mpref,buth,
+                       &(U.undosteps), 2, 64, 0, 0, "Number of undo steps available in Edit Mode (smaller values conserve memory)");
+
+               uiDefButBitS(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
+                       (xpos+edgsp+mpref+midsp),y1,mpref,buth,
+                       &(U.uiflag), 2, 64, 0, 0, "");
 
 
                uiDefBut(block, LABEL,0,"Auto keyframe on:",
-                       (xpos+edgespace+(2*medprefbut)+midspace),y3label,medprefbut,buth,
+                       (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
-               uiDefButS(block, TOG|BIT|0, 0, "Action",
-                       (xpos+edgespace+(2*medprefbut)+(2*midspace)),y2,smallprefbut,buth,
-                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in action ipo curve");
-
-               uiDefButS(block, TOG|BIT|1, 0, "Object",
-                       (xpos+edgespace+(2*medprefbut)+(3*midspace)+smallprefbut),y2,smallprefbut,buth,
-                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in object ipo curve");
-
+               uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
+                       (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
+                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
+               uiDefButBitS(block, TOG, USER_KEYINSERTOBJ, 0, "Object",
+                       (xpos+edgsp+(2*mpref)+(3*midsp)+spref-edgsp),y2,(spref+edgsp),buth,
+                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Object Ipo curve");
 
 
-                uiDefBut(block, LABEL,0,"Duplicate with object:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)+smallprefbut),y3label,medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Duplicate with object:",
+                       (xpos+(2*edgsp)+(3*midsp)+(3*mpref)+spref),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButS(block, TOG|BIT|0, 0, "Mesh",
-                       (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_MESH, 0, "Mesh",
+                       (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes mesh data to be duplicated with Shift+D");
-               uiDefButS(block, TOG|BIT|9, 0, "Armature",
-                       (xpos+edgespace+(4*midspace)+(3*medprefbut)+smallprefbut),y1,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_ARM, 0, "Armature",
+                       (xpos+edgsp+(4*midsp)+(3*mpref)+spref),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes armature data to be duplicated with Shift+D");
 
-               uiDefButS(block, TOG|BIT|2, 0, "Surface",
-                       (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_SURF, 0, "Surface",
+                       (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes surface data to be duplicated with Shift+D");
-               uiDefButS(block, TOG|BIT|5, 0, "Lamp",
-                       (xpos+edgespace+(5*midspace)+(3*medprefbut)+(2*smallprefbut)),y1,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_LAMP, 0, "Lamp",
+                       (xpos+edgsp+(5*midsp)+(3*mpref)+(2*spref)),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes lamp data to be duplicated with Shift+D");
 
-                uiDefButS(block, TOG|BIT|1, 0, "Curve",
-                       (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_CURVE, 0, "Curve",
+                       (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes curve data to be duplicated with Shift+D");
-               uiDefButS(block, TOG|BIT|7, 0, "Material",
-                       (xpos+edgespace+(6*midspace)+(3*medprefbut)+(3*smallprefbut)),y1,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_MAT, 0, "Material",
+                       (xpos+edgsp+(6*midsp)+(3*mpref)+(3*spref)),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes material data to be duplicated with Shift+D");
 
-               uiDefButS(block, TOG|BIT|3, 0, "Text",
-                       (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_FONT, 0, "Text",
+                       (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes text data to be duplicated with Shift+D");
-               uiDefButS(block, TOG|BIT|8, 0, "Texture",
-                       (xpos+edgespace+(7*midspace)+(3*medprefbut)+(4*smallprefbut)),y1,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_TEX, 0, "Texture",
+                       (xpos+edgsp+(7*midsp)+(3*mpref)+(4*spref)),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes texture data to be duplicated with Shift+D");
 
-               uiDefButS(block, TOG|BIT|4, 0, "Metaball",
-                       (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y2,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_MBALL, 0, "Metaball",
+                       (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y2,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes metaball data to be duplicated with Shift+D");
-               uiDefButS(block, TOG|BIT|6, 0, "Ipo",
-                       (xpos+edgespace+(8*midspace)+(3*medprefbut)+(5*smallprefbut)),y1,smallprefbut,buth,
+               uiDefButBitS(block, TOG, USER_DUP_IPO, 0, "Ipo",
+                       (xpos+edgsp+(8*midsp)+(3*mpref)+(5*spref)),y1,(spref+edgsp),buth,
                        &(U.dupflag), 0, 0, 0, 0, "Causes ipo data to be duplicated with Shift+D");
        
        } else if(U.userpref == 2) { /* language & colors */
 
 #ifdef INTERNATIONAL
-               char curfont[64];
-
-               sprintf(curfont, "Interface Font: ");
-               strcat(curfont,U.fontname);
-
-               uiDefButS(block, TOG|BIT|5, B_DOLANGUIFONT, "International Fonts",
-                       xpos,y2,medprefbut,buth,
+               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 & TR_ALL) {
+               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+edgespace+medprefbut+midspace),y2,medprefbut,buth,
+                               (xpos),y3,4*mpref,buth,
                                0, 0, 0, 0, 0, "");
 
                        uiDefBut(block, BUT, B_LOADUIFONT, "Select Font",
-                               xpos,y1,medprefbut,buth,
+                               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+edgespace+medprefbut+midspace),y1,medprefbut,buth,
+                               (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.fontsize, 0, 0, 0, 0, "Current interface font size (points)");
 
 /*
                        uiDefButS(block, MENU|SHO, B_SETENCODING, encoding_pup(),
-                               (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
+                               (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                                &U.encoding, 0, 0, 0, 0, "Current interface font encoding");
 
 
                        uiDefBut(block, LABEL,0,"Translate:",
-                               (xpos+edgespace+(2.1*medprefbut)+(2*midspace)),y3label,medprefbut,buth,
+                               (xpos+edgsp+(2.1*mpref)+(2*midsp)),y3label,mpref,buth,
                                0, 0, 0, 0, 0, "");
 */
 
-                       uiDefButS(block, TOG|BIT|0, B_SETTRANSBUTS, "Tooltips",
-                               (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y1,smallprefbut,buth,
+                       uiDefButBitS(block, TOG, USER_TR_TOOLTIPS, B_SETTRANSBUTS, "Tooltips",
+                               (xpos+edgsp+(2.2*mpref)+(3*midsp)),y1,spref,buth,
                                &(U.transopts), 0, 0, 0, 0, "Translate tooltips");
 
-                       uiDefButS(block, TOG|BIT|1, B_SETTRANSBUTS, "Buttons",
-                               (xpos+edgespace+(2.2*medprefbut)+(4*midspace)+smallprefbut),y1,smallprefbut,buth,
+                       uiDefButBitS(block, TOG, USER_TR_BUTTONS, B_SETTRANSBUTS, "Buttons",
+                               (xpos+edgsp+(2.2*mpref)+(4*midsp)+spref),y1,spref,buth,
                                &(U.transopts), 0, 0, 0, 0, "Translate button labels");
 
-                       uiDefButS(block, TOG|BIT|2, B_SETTRANSBUTS, "Toolbox",
-                               (xpos+edgespace+(2.2*medprefbut)+(5*midspace)+(2*smallprefbut)),y1,smallprefbut,buth,
+                       uiDefButBitS(block, TOG, USER_TR_MENUS, B_SETTRANSBUTS, "Toolbox",
+                               (xpos+edgsp+(2.2*mpref)+(5*midsp)+(2*spref)),y1,spref,buth,
                                &(U.transopts), 0, 0, 0, 0, "Translate toolbox menu");
 
                        uiDefButS(block, MENU|SHO, B_SETLANGUAGE, language_pup(),
-                               (xpos+edgespace+(2.2*medprefbut)+(3*midspace)),y2,medprefbut+(0.5*medprefbut)+3,buth,
+                               (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
                                &U.language, 0, 0, 0, 0, "Select interface language");
                                
-                       /* uiDefButS(block, TOG|BIT|3, B_SETTRANSBUTS, "FTF All windows",
-                               (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,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 */
@@ -2217,234 +2670,262 @@ void drawinfospace(ScrArea *sa, void *spacedata)
        } else if(U.userpref == 3) { /* auto save */
 
 
-               uiDefButS(block, TOG|BIT|0, B_RESETAUTOSAVE, "Auto Save Temp Files",
-                       (xpos+edgespace),y2,medprefbut,buth,
+               uiDefButS(block, NUM, 0, "Save Versions:",
+                       (xpos+edgsp),y3,mpref,buth,
+                       &U.versions, 0.0, 32.0, 0, 0,
+                       "The number of old versions to maintain in the current directory, when manually saving");
+
+               uiDefButBitS(block, TOG, USER_AUTOSAVE, B_RESETAUTOSAVE, "Auto Save Temp Files",
+                       (xpos+edgsp+mpref+midsp),y3,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Enables automatic saving of temporary files");
 
-               if(U.flag & AUTOSAVE) {
-
-                       uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
-                               (xpos+edgespace),y1,medprefbut,buth,
-                               0, 0, 0, 0, 0,"Opens the most recently saved temporary file");
+               if(U.flag & USER_AUTOSAVE) {
 
                        uiDefButI(block, NUM, B_RESETAUTOSAVE, "Minutes:",
-                               (xpos+edgespace+medprefbut+midspace),y2,medprefbut,buth,
+                               (xpos+edgsp+mpref+midsp),y2,mpref,buth,
                                &(U.savetime), 1.0, 60.0, 0, 0,
                                "The time (in minutes) to wait between automatic temporary saves");
 
-                       uiDefButS(block, NUM, 0, "Versions:",
-                               (xpos+edgespace+medprefbut+midspace),y1,medprefbut,buth,
-                               &U.versions, 0.0, 32.0, 0, 0,
-                               "The number of old versions to maintain when saving");
+                       uiDefBut(block, BUT, B_LOADTEMP, "Open Recent",
+                               (xpos+edgsp+mpref+midsp),y1,mpref,buth,
+                               0, 0, 0, 0, 0,"Open the most recently saved temporary file");
                }
 
        } else if (U.userpref == 4) { /* system & opengl */
                uiDefBut(block, LABEL,0,"Solid OpenGL light:",
-                       xpos+edgespace, y3label, medprefbut, buth,
+                       xpos+edgsp, y3label, mpref, buth,
                        0, 0, 0, 0, 0, "");
                
                uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
-                       xpos+edgespace, y2, 2*medprefbut/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
+                       xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
                uiBlockSetCol(block, TH_BUT_SETTING1);
                uiDefButI(block, TOG|BIT|0, B_RECALCLIGHT, "On",
-                       xpos+edgespace+2*medprefbut/6, y2, medprefbut/6, buth, 
-                       &U.light[cur_light].flag, 0.0, 0.0, 0, 0, "");
+                       xpos+edgsp+2*mpref/6, y2, mpref/6, buth, 
+                       &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+edgespace+3*medprefbut/6, y2, medprefbut/6, buth, 
-                       &cur_light_var, 123.0, 0.0, 0, 0, "");
+                       xpos+edgsp+3*mpref/6, y2, mpref/6, buth, 
+                       &cur_light_var, 123.0, 0.0, 0, 0, "Lamp vector for OpenGL light");
                uiDefButS(block, ROW, B_REDR, "Col",
-                       xpos+edgespace+4*medprefbut/6, y2, medprefbut/6, buth, 
-                       &cur_light_var, 123.0, 1.0, 0, 0, "");
+                       xpos+edgsp+4*mpref/6, y2, mpref/6, buth, 
+                       &cur_light_var, 123.0, 1.0, 0, 0, "Diffuse Color for OpenGL light");
                uiDefButS(block, ROW, B_REDR, "Spec",
-                       xpos+edgespace+5*medprefbut/6, y2, medprefbut/6, buth, 
-                       &cur_light_var, 123.0, 2.0, 0, 0, "");
+                       xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
+                       &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 ",
-                               xpos+edgespace, y1, medprefbut/3, buth, 
+                               xpos+edgsp, y1, mpref/3, buth, 
                                U.light[cur_light].col, 0.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "G ",
-                               xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].col+1, 0.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "B ",
-                               xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].col+2, 0.0, 1.0, 100, 2, "");
                }
                else if(cur_light_var==2) {
                        uiDefButF(block, NUM, B_RECALCLIGHT, "sR ",
-                               xpos+edgespace, y1, medprefbut/3, buth, 
+                               xpos+edgsp, y1, mpref/3, buth, 
                                U.light[cur_light].spec, 0.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "sG ",
-                               xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].spec+1, 0.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "sB ",
-                               xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].spec+2, 0.0, 1.0, 100, 2, "");
                }
                else if(cur_light_var==0) {
                        uiDefButF(block, NUM, B_RECALCLIGHT, "X ",
-                               xpos+edgespace, y1, medprefbut/3, buth, 
+                               xpos+edgsp, y1, mpref/3, buth, 
                                U.light[cur_light].vec, -1.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "Y ",
-                               xpos+edgespace+medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].vec+1, -1.0, 1.0, 100, 2, "");
                        uiDefButF(block, NUM, B_RECALCLIGHT, "Z ",
-                               xpos+edgespace+2*medprefbut/3, y1, medprefbut/3, buth, 
+                               xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
                }
 
 /*
                uiDefButS(block, TOG|BIT|5, 0, "Log Events to Console",
-                       (xpos+edgespace),y2,largeprefbut,buth,
+                       (xpos+edgsp),y2,lpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Display a list of input events in the console");
 
                uiDefButS(block, MENU|SHO, B_CONSOLEOUT, consolemethod_pup(),
-                       (xpos+edgespace), y1, largeprefbut,buth,
+                       (xpos+edgsp), y1, lpref,buth,
                        &U.console_out, 0, 0, 0, 0, "Select console output method");
 
                uiDefButS(block, NUM, B_CONSOLENUMLINES, "Lines:",
-                       (xpos+edgespace+largeprefbut+midspace),y1,smallprefbut,buth,
+                       (xpos+edgsp+lpref+midsp),y1,spref,buth,
                        &U.console_buffer, 1.0, 4000.0, 0, 0, "Maximum number of internal console lines");
 */
 
 #ifdef _WIN32
                uiDefBut(block, LABEL,0,"Win Codecs:",
-                       (xpos+edgespace+(1*midspace)+(1*medprefbut)),y3label,medprefbut,buth,
+                       (xpos+edgsp+(1*midsp)+(1*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButS(block, TOG|BIT|8, 0, "Enable all codecs",
-                       (xpos+edgespace+(1*medprefbut)+(1*midspace)),y2,medprefbut,buth,
+               uiDefButBitS(block, TOG, USER_ALLWINCODECS, 0, "Enable all codecs",
+                       (xpos+edgsp+(1*mpref)+(1*midsp)),y2,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Allows all codecs for rendering (not guaranteed)");
 #endif
 
                uiDefBut(block, LABEL,0,"Keyboard:",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y3label,medprefbut,buth,
+                       (xpos+edgsp+(3*midsp)+(3*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButS(block, TOG|BIT|9, B_U_CAPSLOCK, "Disable Caps Lock",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y1,medprefbut,buth,
+               uiDefButBitS(block, TOG, USER_NO_CAPSLOCK, B_U_CAPSLOCK, "Disable Caps Lock",
+                       (xpos+edgsp+(3*midsp)+(3*mpref)),y1,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Disables the Caps Lock key when entering text");
 
-               uiDefButS(block, TOG|BIT|13, 0, "Emulate Numpad",
-                       (xpos+edgespace+(3*midspace)+(3*medprefbut)),y2,medprefbut,buth,
+               uiDefButBitS(block, TOG, USER_NONUMPAD, 0, "Emulate Numpad",
+                       (xpos+edgsp+(3*midsp)+(3*mpref)),y2,mpref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Causes the 1 to 0 keys to act as the numpad (useful for laptops)");
 
 
                uiDefBut(block, LABEL,0,"System:",
-                       (xpos+edgespace+(4*midspace)+(4*medprefbut)),y3label,medprefbut,buth,
+                       (xpos+edgsp+(4*midsp)+(4*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButI(block, TOG|BIT|USERDEF_DISABLE_SOUND_BIT, B_SOUNDTOGGLE, "Disable Sound",
-                       (xpos+edgespace+(4*medprefbut)+(4*midspace)),y2,medprefbut,buth,
-                       &(U.gameflags), 0, 0, 0, 0, "Disables sounds from being played");
+               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 in games");
 
-               uiDefButS(block, TOG|BIT|3, 0, "Filter File Extensions",
-                       (xpos+edgespace+(4*medprefbut)+(4*midspace)),y1,medprefbut,buth,
+               uiDefButBitS(block, TOG, USER_FILTERFILEEXTS, 0, "Filter File Extensions",
+                       (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Display only files with extensions in the image select window");
 
 
                uiDefBut(block, LABEL,0,"OpenGL:",
-                       (xpos+edgespace+(5*midspace)+(5*medprefbut)),y3label,medprefbut,buth,
+                       (xpos+edgsp+(5*midsp)+(5*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
 
-               uiDefButI(block, TOGN|BIT|USERDEF_DISABLE_MIPMAP_BIT, B_MIPMAPCHANGED, "Mipmaps",
-                       (xpos+edgespace+(5*medprefbut)+(5*midspace)),y2,medprefbut,buth,
+               uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
+                       (xpos+edgsp+(5*mpref)+(5*midsp)),y2,mpref,buth,
                        &(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
 
-               uiDefButI(block, TOG|BIT|USERDEF_VERTEX_ARRAYS_BIT, 0, "Vertex Arrays",
-                       (xpos+edgespace+(5*medprefbut)+(5*midspace)),y1,medprefbut,buth,
+               uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
+                       (xpos+edgsp+(5*mpref)+(5*midsp)),y1,mpref,buth,
                        &(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
 
-               uiDefBut(block, LABEL,0,"Audio:",
-                       (xpos+edgespace+(2*midspace)+(2*medprefbut)),y3label,medprefbut,buth,
+               uiDefBut(block, LABEL,0,"Audio mixing buffer:",
+                       (xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
-
-               uiDefButI(block, ROW, 0, "Mixing buffer 256", (xpos+edgespace+(2*midspace)+(2*medprefbut)),y2,medprefbut,buth, &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio buffer size to 256 samples");
-               uiDefButI(block, ROW, 0, "512", (xpos+edgespace+(2*midspace)+(2*medprefbut)),y1,61,buth, &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio buffer size to 512 samples");      
-               uiDefButI(block, ROW, 0, "1024", (xpos+edgespace+(2*midspace)+(2*medprefbut))+61+midspace,y1,61,buth, &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio buffer size to 1024 samples");               
-               uiDefButI(block, ROW, 0, "2048", (xpos+edgespace+(2*midspace)+(2*medprefbut))+2*(61+midspace),y1,61,buth, &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio buffer size to 2048 samples");                   
+               uiBlockBeginAlign(block);
+               uiDefButI(block, ROW, 0, "256",
+                       (xpos+edgsp+(2*midsp)+(2*mpref)),y2,(mpref/4),buth,
+                       &U.mixbufsize, 2.0, 256.0, 0, 0, "Set audio mixing buffer size to 256 samples");
+               uiDefButI(block, ROW, 0, "512",
+                       (xpos+edgsp+(2*midsp)+(2*mpref)+(mpref/4)),y2,(mpref/4),buth,
+                       &U.mixbufsize, 2.0, 512.0, 0, 0, "Set audio mixing buffer size to 512 samples");        
+               uiDefButI(block, ROW, 0, "1024",
+                       (xpos+edgsp+(2*midsp)+(2*mpref)+(2*mpref/4)),y2,(mpref/4),buth,
+                       &U.mixbufsize, 2.0, 1024.0, 0, 0, "Set audio mixing buffer size to 1024 samples");              
+               uiDefButI(block, ROW, 0, "2048",
+                       (xpos+edgsp+(2*midsp)+(2*mpref)+(3*mpref/4)),y2,(mpref/4),buth,
+                       &U.mixbufsize, 2.0, 2048.0, 0, 0, "Set audio mixing buffer size to 2048 samples");                      
+               uiBlockEndAlign(block);
 
        } else if(U.userpref == 5) { /* file paths */
 
+               /* yafray: (temporary) path button for yafray xml export, now with fileselect */
+               uiDefBut(block, TEX, 0, "YFexport: ",
+                       (xpos+edgsp), y2+buth+rspace, lpref-smfileselbut, buth,
+                       U.yfexportdir, 1.0, 63.0, 0, 0,
+                       "The default directory for yafray xml export (must exist!)");
+               uiDefIconBut(block, BUT, B_YAFRAYDIRFILESEL, ICON_FILESEL,
+                       (xpos+edgsp+lpref-smfileselbut), y2+buth+rspace, smfileselbut, buth,
+                       0, 0, 0, 0, 0, "Select the default yafray export directory");
 
                uiDefBut(block, TEX, 0, "Fonts: ",
-                       (xpos+edgespace),y2,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp),y2,(lpref-smfileselbut),buth,
                        U.fontdir, 1.0, 63.0, 0, 0,
                        "The default directory to search for loading fonts");
                uiDefIconBut(block, BUT, B_FONTDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+largeprefbut-smfileselbut),y2,smfileselbut,buth,
+                       (xpos+edgsp+lpref-smfileselbut),y2,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default font directory");
 
                uiDefBut(block, TEX, 0, "Textures: ",
-                       (xpos+edgespace+largeprefbut+midspace),y2,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp+lpref+midsp),y2,(lpref-smfileselbut),buth,
                        U.textudir, 1.0, 63.0, 0, 0, "The default directory to search for textures");
                uiDefIconBut(block, BUT, B_TEXTUDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y2,smfileselbut,buth,
+                       (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y2,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default texture location");
 
 
                uiDefBut(block, TEX, 0, "Tex Plugins: ",
-                       (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y2,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp+(2*lpref)+(2*midsp)),y2,(lpref-smfileselbut),buth,
                        U.plugtexdir, 1.0, 63.0, 0, 0, "The default directory to search for texture plugins");
                uiDefIconBut(block, BUT, B_PLUGTEXDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y2,smfileselbut,buth,
+                       (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y2,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default texture plugin location");
 
                uiDefBut(block, TEX, 0, "Seq Plugins: ",
-                       (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y2,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp+(3*lpref)+(3*midsp)),y2,(lpref-smfileselbut),buth,
                        U.plugseqdir, 1.0, 63.0, 0, 0, "The default directory to search for sequence plugins");
                uiDefIconBut(block, BUT, B_PLUGSEQDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y2,smfileselbut,buth,
+                       (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y2,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default sequence plugin location");
 
 
                uiDefBut(block, TEX, 0, "Render: ",
-                       (xpos+edgespace),y1,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp),y1,(lpref-smfileselbut),buth,
                        U.renderdir, 1.0, 63.0, 0, 0, "The default directory for rendering output");
                uiDefIconBut(block, BUT, B_RENDERDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+largeprefbut-smfileselbut),y1,smfileselbut,buth,
+                       (xpos+edgsp+lpref-smfileselbut),y1,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default render output location");
 
                uiDefBut(block, TEX, 0, "Python: ",
-                       (xpos+edgespace+largeprefbut+midspace),y1,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp+lpref+midsp),y1,(lpref-2*smfileselbut),buth,
                        U.pythondir, 1.0, 63.0, 0, 0, "The default directory to search for Python scripts");
+               uiDefIconBut(block, BUT, B_PYMENUEVAL, ICON_SCRIPT,
+                       (xpos+edgsp+(2*lpref)+midsp-2*smfileselbut),y1,smfileselbut,buth,
+                       0, 0, 0, 0, 0, "Re-evaluate scripts registration in menus");
                uiDefIconBut(block, BUT, B_PYTHONDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(2*largeprefbut)+midspace-smfileselbut),y1,smfileselbut,buth,
+                       (xpos+edgsp+(2*lpref)+midsp-smfileselbut),y1,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default Python script location");
 
 
                uiDefBut(block, TEX, 0, "Sounds: ",
-                       (xpos+edgespace+(2*largeprefbut)+(2*midspace)),y1,(largeprefbut-smfileselbut),buth,
+                       (xpos+edgsp+(2*lpref)+(2*midsp)),y1,(lpref-smfileselbut),buth,
                        U.sounddir, 1.0, 63.0, 0, 0, "The default directory to search for sounds");
                uiDefIconBut(block, BUT, B_SOUNDDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(3*largeprefbut)+(2*midspace)-smfileselbut),y1,smfileselbut,buth,
+                       (xpos+edgsp+(3*lpref)+(2*midsp)-smfileselbut),y1,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default sound location");
 
                uiDefBut(block, TEX, 0, "Temp: ",
-                        (xpos+edgespace+(3*largeprefbut)+(3*midspace)),y1,(largeprefbut-smfileselbut),buth,
+                        (xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
                         U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
                uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
-                       (xpos+edgespace+(4*largeprefbut)+(3*midspace)-smfileselbut),y1,smfileselbut,buth,
+                       (xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
                        0, 0, 0, 0, 0, "Select the default temporary save file location");
 
        }
 
        uiDrawBlock(block);
        
-       myortho2(-0.5, (float)(sa->winx)-0.5, -0.5, (float)(sa->winy)-0.5);
+       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;
@@ -2468,7 +2949,7 @@ void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                bTheme *btheme= U.themes.first;
                                BLI_remlink(&U.themes, btheme);
                                MEM_freeN(btheme);
-                               BIF_SetTheme(curarea); // prevent usage of old theme in calls   
+                               BIF_SetTheme(sa); // prevent usage of old theme in calls        
                                addqueue(sa->win, REDRAW, 1);
                        }
                        else if(val==B_NAME_THEME) {
@@ -2518,7 +2999,7 @@ void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        }
 }
 
-void init_infospace(ScrArea *sa)
+static void init_infospace(ScrArea *sa)
 {
        SpaceInfo *sinfo;
        
@@ -2540,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;
@@ -2572,7 +3053,7 @@ void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        break;
                        
                case RIGHTMOUSE:
-                       nr= pupmenu("Align buttons%t|Free %x0|Horizontal%x1|Vertical%x2");
+                       nr= pupmenu("Panel Alignment%t|Horizontal%x1|Vertical%x2|Free %x0");
                        if (nr>=0) {
                                sbuts->align= nr;
                                if(nr) {
@@ -2663,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;
        
@@ -2683,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 */
@@ -2736,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;
@@ -2746,14 +3227,29 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        float dx, dy;
        int doredraw= 0, cfra, first;
        short mval[2];
+       short mousebut = L_MOUSE;
        
        if(curarea->win==0) return;
 
        if(val) {
                
                if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
-
+               
+               /* swap mouse buttons based on user preference */
+               if (U.flag & USER_LMOUSESELECT) {
+                       if (event == LEFTMOUSE) {
+                               event = RIGHTMOUSE;
+                               mousebut = L_MOUSE;
+                       } else if (event == RIGHTMOUSE) {
+                               event = LEFTMOUSE;
+                               mousebut = R_MOUSE;
+                       }
+               }
+               
                switch(event) {
+               case UI_BUT_EVENT:
+                       do_seqbuttons(val);                     
+                       break;
                case LEFTMOUSE:
                        if(sseq->mainb || view2dmove(event)==0) {
                                
@@ -2772,11 +3268,12 @@ 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()&L_MOUSE);
+                               } while(get_mbut() & mousebut);
                                
                                set_special_seq_update(0);
                                
@@ -2807,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);
                                }
                        }
@@ -2887,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)
@@ -2902,9 +3401,15 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        make_meta();
                        }
                        break;
+               case NKEY:
+                       if(G.qual==0) {
+                               toggle_blockhandler(curarea, SEQ_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
+                               scrarea_queue_winredraw(curarea);
+                       }
+                       break;
                case SKEY:
                        if((G.qual==LR_SHIFTKEY))
-                               seq_snapmenu();
+                               seq_snap_menu();
                        break;
                case TKEY:
                        if((G.qual==0))
@@ -2925,7 +3430,7 @@ void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 }
 
 
-void init_seqspace(ScrArea *sa)
+static void init_seqspace(ScrArea *sa)
 {
        SpaceSeq *sseq;
        
@@ -2934,6 +3439,7 @@ void init_seqspace(ScrArea *sa)
 
        sseq->spacetype= SPACE_SEQ;
        sseq->zoom= 1;
+       sseq->blockscale= 0.7;
        
        /* seq space goes from (0,8) to (250, 0) */
 
@@ -2975,7 +3481,7 @@ static void changeactionspace(ScrArea *sa, void *spacedata)
 }
 
 
-void init_actionspace(ScrArea *sa)
+static void init_actionspace(ScrArea *sa)
 {
        SpaceAction *saction;
        
@@ -2983,6 +3489,7 @@ void init_actionspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, saction);
 
        saction->spacetype= SPACE_ACTION;
+       saction->blockscale= 0.7;
 
        saction->v2d.tot.xmin= 1.0;
        saction->v2d.tot.ymin=  0.0;
@@ -3010,7 +3517,7 @@ void init_actionspace(ScrArea *sa)
        
 }
 
-void free_actionspace(SpaceAction *saction)
+static void free_actionspace(SpaceAction *saction)
 {
        /* don't free saction itself */
        
@@ -3025,7 +3532,7 @@ void free_actionspace(SpaceAction *saction)
 
 /* ******************** SPACE: FILE ********************** */
 
-void init_filespace(ScrArea *sa)
+static void init_filespace(ScrArea *sa)
 {
        SpaceFile *sfile;
        
@@ -3034,11 +3541,11 @@ void init_filespace(ScrArea *sa)
 
        sfile->dir[0]= '/';
        sfile->type= FILE_UNIX;
-
+       sfile->blockscale= 0.7;
        sfile->spacetype= SPACE_FILE;
 }
 
-void init_textspace(ScrArea *sa)
+static void init_textspace(ScrArea *sa)
 {
        SpaceText *st;
        
@@ -3046,18 +3553,33 @@ void init_textspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, st);
 
        st->spacetype= SPACE_TEXT;      
-       
+       st->blockscale= 0.7;
        st->text= NULL;
        st->flags= 0;
        
        st->font_id= 5;
        st->lheight= 12;
        st->showlinenrs= 0;
+       st->tabnumber = 4;
+       st->currtab_set = 0;
        
        st->top= 0;
 }
 
-void init_imaselspace(ScrArea *sa)
+static void init_scriptspace(ScrArea *sa)
+{
+       SpaceScript *sc;
+
+       sc = MEM_callocN(sizeof(SpaceScript), "initscriptspace");
+       BLI_addhead(&sa->spacedata, sc);
+
+       sc->spacetype = SPACE_SCRIPT;
+       sc->blockscale= 0.7;
+       sc->script = NULL;
+       sc->flags = 0;
+}
+
+static void init_imaselspace(ScrArea *sa)
 {
        SpaceImaSel *simasel;
        
@@ -3065,7 +3587,7 @@ void init_imaselspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, simasel);
 
        simasel->spacetype= SPACE_IMASEL;
-       
+       simasel->blockscale= 0.7;
        simasel->mode = 7;
        strcpy (simasel->dir,  U.textudir);     /* TON */
        strcpy (simasel->file, "");
@@ -3096,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;
        
@@ -3104,7 +3626,7 @@ void init_soundspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, ssound);
 
        ssound->spacetype= SPACE_SOUND;
-       
+       ssound->blockscale= 0.7;
        /* sound space goes from (0,8) to (250, 0) */
 
        ssound->v2d.tot.xmin= -4.0;
@@ -3144,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;
@@ -3157,10 +3679,23 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        short xy_prev[2], xy_curr[2];
        float uv_prev[2], uv_curr[2];
        extern VPaint Gvp;
-#endif /* NAN_TPT */   
+#endif /* NAN_TPT */
+       short mousebut = L_MOUSE;
+       
        if(val==0) return;
 
-       if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+       if(uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+       
+       /* swap mouse buttons based on user preference */
+       if (U.flag & USER_LMOUSESELECT) {
+               if (event == LEFTMOUSE) {
+                       event = RIGHTMOUSE;
+                       mousebut = R_MOUSE;
+               } else if (event == RIGHTMOUSE) {
+                       event = LEFTMOUSE;
+                       mousebut = L_MOUSE;
+               }
+       }
        
        if (sima->flag & SI_DRAWTOOL) {
 #ifdef NAN_TPT
@@ -3182,7 +3717,7 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                canvas = IMG_CanvasCreateFromPtr(sima->image->ibuf->rect, sima->image->ibuf->x, sima->image->ibuf->y, rowBytes);
 
                                getmouseco_areawin(xy_prev);
-                               while (get_mbut() & L_MOUSE) {
+                               while (get_mbut() & mousebut) {
                                        getmouseco_areawin(xy_curr);
                                        /* Check if mouse position changed */
                                        if ((xy_prev[0] != xy_curr[0]) || (xy_prev[1] != xy_curr[1])) {
@@ -3194,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];
@@ -3210,27 +3745,31 @@ 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);
                                allqueue(REDRAWHEADERS, 0);
                                break;
+                       case RIGHTMOUSE:
+                               sample_vpaint();
+                               break;
                }
 #endif /* NAN_TPT */
        }
        else {
                /* Draw tool is inactive */
+
                switch(event) {
                        case LEFTMOUSE:
                                if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
                                else gesture();
                                break;
-                       case MIDDLEMOUSE:
-                               image_viewmove();
-                               break;
                        case RIGHTMOUSE:
-                               mouse_select_sima();
+                               if(G.f & G_FACESELECT)
+                                       mouse_select_sima();
+                               else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
+                                       sample_vpaint();
                                break;
                        case AKEY:
                                if((G.qual==0))
@@ -3240,46 +3779,128 @@ void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if((G.qual==0))
                                        borderselect_sima();
                                break;
+                       case CKEY:
+                               if(G.qual==LR_CTRLKEY)
+                                       toggle_uv_select('s');
+                               else if(G.qual==LR_SHIFTKEY)
+                                       toggle_uv_select('l');
+                               else if(G.qual==LR_ALTKEY)
+                                       toggle_uv_select('o');
+                               else
+                                       toggle_uv_select('f');
+                               break;
+                       case EKEY :
+                               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)
+                                       reveal_tface_uv();
+                               else if((G.qual==LR_SHIFTKEY))
+                                       hide_tface_uv(1);
+                               else if((G.qual==0))
+                                       hide_tface_uv(0);
+                               break;
+                       case LKEY:
+                               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;
+                       case MKEY:
+                               if((G.qual==0))
+                                       mirrormenu_tface_uv();
                                break;
                        case NKEY:
                                if(G.qual==LR_CTRLKEY)
                                        replace_names_but();
                                break;
+                       case OKEY:
+                               if (G.qual==LR_SHIFTKEY) {
+                                       extern int prop_mode;
+                                       prop_mode= !prop_mode;
+                               }
+                               else if((G.qual==0)) {
+                                       if(G.f & G_PROPORTIONAL)
+                                               G.f &= ~G_PROPORTIONAL;
+                                       else
+                                               G.f |= G_PROPORTIONAL;
+                               }
+                               break;
+                       case PKEY:
+                               if(G.qual==LR_ALTKEY)
+                                       pin_tface_uv(0);
+                               else
+                                       pin_tface_uv(1);
+                               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))
+                                       stitch_uv_tface(0);
+                               else if(G.qual==LR_SHIFTKEY)
+                                       stitch_uv_tface(1);
+                               break;
+                       case WKEY:
+                               weld_align_menu_tface_uv();
+                               break;
+                       case PADPERIOD:
+                               if(G.qual==0)
+                                       image_viewcentre();
                                break;
                }
+       }       
+
+
+       /* least intrusive nonumpad hack, only for plus/minus */
+       if (U.flag & USER_NONUMPAD) {
+               event= convert_for_nonumpad(event);
        }
 
        /* Events handled always (whether the draw tool is active or not) */
        switch (event) {
-               case MIDDLEMOUSE:
-                       image_viewmove();
-                       break;
-               case WHEELUPMOUSE:
-               case WHEELDOWNMOUSE:
-               case PADPLUSKEY:
-               case PADMINUS:
-                       image_viewzoom(event);
+       case UI_BUT_EVENT:
+               do_imagebuts(val);      // drawimage.c
+               break;
+       case MIDDLEMOUSE:
+               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, 0);
+               scrarea_queue_winredraw(curarea);
+               break;
+       case HOMEKEY:
+               if((G.qual==0))
+                       image_home();
+               break;
+       case NKEY:
+               if(G.qual==0) {
+                       toggle_blockhandler(curarea, IMAGE_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
                        scrarea_queue_winredraw(curarea);
-                       break;
-               case HOMEKEY:
-                       if((G.qual==0))
-                               image_home();
-                       break;
+               }
+               break;
        }
 }
 
 
-void init_imagespace(ScrArea *sa)
+static void init_imagespace(ScrArea *sa)
 {
        SpaceImage *sima;
        
@@ -3288,6 +3909,7 @@ void init_imagespace(ScrArea *sa)
 
        sima->spacetype= SPACE_IMAGE;
        sima->zoom= 1;
+       sima->blockscale= 0.7;
 }
 
 
@@ -3304,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;
@@ -3314,136 +3936,236 @@ void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
        if(val==0) return;
 
-       if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+       if( uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
 
-       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;
+       if (U.flag & USER_NONUMPAD) {
+               event= convert_for_nonumpad(event);
+       }
        
-       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:
+                       break;
                
-               if(G.qual==LR_ALTKEY)
-                       shrink_oops();
-               else if((G.qual==LR_SHIFTKEY))
-                       shuffle_oops();
-               else if((G.qual==0))
-                       transform_oops('s');
-               break;
+               case PADMINUS:
 
-       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;
-       
+                       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);
+                       }
+                       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);
+                       }
+                       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;
+               
+               }
        }
 }
 
-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;
        
@@ -3451,12 +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;
-       init_v2d_oops(&soops->v2d);
+       soops->type= SO_OUTLINER;       // default starts new ones in outliner mode
+       soops->blockscale= 0.7;
+       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 ********************** */
@@ -3464,10 +4227,19 @@ void init_oopsspace(ScrArea *sa)
 extern void drawtextspace(ScrArea *sa, void *spacedata);
 extern void winqreadtextspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 
+/* ******************** SPACE: Script ********************** */
+
+extern void drawscriptspace(ScrArea *sa, void *spacedata);
+extern void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
+
 /* ******************** SPACE: ALGEMEEN ********************** */
 
 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;
@@ -3513,11 +4285,13 @@ 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)
                                        init_textspace(sa);
+                               else if(type==SPACE_SCRIPT)
+                                       init_scriptspace(sa);
                                else if(type==SPACE_SOUND)
                                        init_soundspace(sa);
                                else if(type==SPACE_NLA)
@@ -3531,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);
@@ -3545,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)
@@ -3561,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;
@@ -3598,6 +4383,9 @@ void freespacelist(ListBase *lb)
                else if(sl->spacetype==SPACE_TEXT) {
                        free_textspace((SpaceText *)sl);
                }
+               else if(sl->spacetype==SPACE_SCRIPT) {
+                       free_scriptspace((SpaceScript *)sl);
+               }
                else if(sl->spacetype==SPACE_SOUND) {
                        free_soundspace((SpaceSound *)sl);
                }
@@ -3623,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);
@@ -3693,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);
@@ -3726,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;
@@ -3742,7 +4543,7 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_headredraw(sa);
                                        if(val) {
                                                si= sa->spacedata.first;
-                                               if (!G.sipo->pin)                                                       
+                                               if (si->pin==0)                                                 
                                                        si->blocktype= val;
                                        }
                                }
@@ -3865,6 +4666,11 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_winredraw(sa);
                                }
                                break;
+                       case REDRAWSCRIPT:
+                               if (sa->spacetype==SPACE_SCRIPT) {
+                                       scrarea_queue_winredraw(sa);
+                               }
+                               break;
                        case REDRAWSOUND:
                                if(sa->spacetype==SPACE_SOUND) {
                                        scrarea_queue_headredraw(sa);
@@ -3929,14 +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) {
@@ -3945,35 +4753,45 @@ 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) {
+                       else {
                                areawinset(sa->win);
                                scrarea_do_windraw(sa);
+                               scrarea_do_headdraw(sa);
                        }
-                       else if(sa->spacetype==SPACE_ACTION) {
+               }
+               sa= sa->next;
+       }
+       
+       screen_swapbuffers();
+
+#ifndef __APPLE__
+       /* de the afterqueuetest for backbuf draw */
+       sa= G.curscreen->areabase.first;
+       while(sa) {
+               if(sa->spacetype==SPACE_VIEW3D) {
+                       if(afterqtest(sa->win, BACKBUFDRAW)) {
                                areawinset(sa->win);
-                               scrarea_do_windraw(sa);
+                               backdrawview3d(0);
                        }
                }
                sa= sa->next;
        }
+#endif
        if(curarea!=tempsa) areawinset(tempsa->win);
        
-       screen_swapbuffers();
-
 }
 
-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;
@@ -3982,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;
@@ -3991,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;
@@ -4003,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);
@@ -4149,6 +4969,17 @@ SpaceType *spacetext_get_type(void)
 
        return st;
 }
+SpaceType *spacescript_get_type(void)
+{
+       static SpaceType *st = NULL;
+
+       if (!st) {
+               st = spacetype_new("Script");
+               spacetype_set_winfuncs(st, drawscriptspace, NULL, winqreadscriptspace);
+       }
+
+       return st;
+}
 SpaceType *spaceview3d_get_type(void)
 {
        static SpaceType *st= NULL;