Long waited feature: Render Baking
[blender.git] / source / blender / src / space.c
index 86fbacb567ec607e1b79870edf5925788c9583a1..078c6f6a8864d67f0ed338607cf05a99e04c6f0b 100644 (file)
@@ -41,6 +41,7 @@
 #endif
 
 #include "MEM_guardedalloc.h"
+#include "MEM_CacheLimiterC-Api.h"
 
 #ifdef INTERNATIONAL
 #include "BIF_language.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
+#include "BLI_gsqueue.h"
 #include "BLI_linklist.h"
 
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_group_types.h" /* used for select_same_group */
 #include "DNA_image_types.h"
 #include "DNA_ipo_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h" /* used for select grouped hooks */
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_group.h"
 #include "BKE_ipo.h"
 #include "BKE_main.h"
+#include "BKE_mesh.h"
 #include "BKE_node.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
-#include "BIF_spacetypes.h"  // first, nasty dependency with typedef
+#include "BIF_spacetypes.h"  /* first, nasty dependency with typedef */
 
 #include "BIF_butspace.h"
 #include "BIF_drawimage.h"
 #include "BIF_poseobject.h"
 #include "BIF_outliner.h"
 #include "BIF_resources.h"
+#include "BIF_retopo.h"
 #include "BIF_screen.h"
 #include "BIF_space.h"
 #include "BIF_toets.h"
 #include "BDR_drawmesh.h"
 #include "BDR_drawobject.h"
 #include "BDR_imagepaint.h"
+#include "BDR_sculptmode.h"
 #include "BDR_unwrapper.h"
 
 #include "BLO_readfile.h" /* for BLO_blendhandle_close */
 
 #include "BPY_extern.h"
 
+#include "butspace.h"
 #include "mydevice.h"
 #include "blendef.h"
 #include "datatoc.h"
+#include "multires.h"
 
 #include "BIF_transform.h"
 
 #include "BKE_depsgraph.h"
 
 #include "BSE_trans_types.h"
-#include "IMG_Api.h"
 
 #include "SYS_System.h" /* for the user def menu ... should move elsewhere. */
 
@@ -178,7 +188,7 @@ void add_blockhandler(ScrArea *sa, short eventcode, short val)
        SpaceLink *sl= sa->spacedata.first;
        short a;
        
-       // find empty spot
+       /* find empty spot */
        for(a=0; a<SPACE_MAXHANDLER; a+=2) {
                if( sl->blockhandler[a]==eventcode ) {
                        sl->blockhandler[a+1]= val;
@@ -201,6 +211,10 @@ void rem_blockhandler(ScrArea *sa, short eventcode)
        for(a=0; a<SPACE_MAXHANDLER; a+=2) {
                if( sl->blockhandler[a]==eventcode) {
                        sl->blockhandler[a]= 0;
+                       
+                       /* specific free calls */
+                       if(eventcode==IMAGE_HANDLER_PREVIEW)
+                               image_preview_event(0);
                        break;
                }
        }
@@ -211,14 +225,16 @@ void toggle_blockhandler(ScrArea *sa, short eventcode, short val)
        SpaceLink *sl= sa->spacedata.first;
        short a, addnew=1;
        
-       // find if it exists
+       /* find if it exists */
        for(a=0; a<SPACE_MAXHANDLER; a+=2) {
                if( sl->blockhandler[a]==eventcode ) {
                        sl->blockhandler[a]= 0;
                        
                        /* specific free calls */
                        if(eventcode==VIEW3D_HANDLER_PREVIEW)
-                               BIF_view3d_previewrender_free(sa);
+                               BIF_view3d_previewrender_free(sa->spacedata.first);
+                       else if(eventcode==IMAGE_HANDLER_PREVIEW)
+                               image_preview_event(0);
                        
                        addnew= 0;
                }
@@ -372,6 +388,8 @@ void space_set_commmandline_options(void) {
 
                a=(G.fileflags & G_FILE_GAME_MAT);
                SYS_WriteCommandLineInt(syshandle, "blender_material", a);
+               a=(G.fileflags & G_FILE_DIAPLAY_LISTS);
+               SYS_WriteCommandLineInt(syshandle, "displaylists", a);
 
 
        }
@@ -416,8 +434,8 @@ static LinkNode *save_and_reset_all_scene_cfra(void)
        for (sc= G.main->scene.first; sc; sc= sc->id.next) {
                BLI_linklist_prepend(&storelist, (void*) (long) sc->r.cfra);
 
-               //why is this reset to 1 ?
-               //sc->r.cfra= 1;
+               /* why is this reset to 1 ?*/
+               /* sc->r.cfra= 1;*/
 
                set_scene_bg(sc);
        }
@@ -459,6 +477,7 @@ void start_game(void)
                 * Better would be to make a better routine
                 * in the game engine for finding the camera.
                 *  - zr
+                * Note: yes, this is all very badly hacked! (ton)
                 */
        for (sc= G.main->scene.first; sc; sc= sc->id.next) {
                if (!sc->camera) {
@@ -500,7 +519,8 @@ void start_game(void)
 
        restore_all_scene_cfra(scene_cfra_store);
        set_scene_bg(startscene);
-       
+       scene_update_for_newframe(G.scene, G.scene->lay);
+
        if (G.flags & G_FILE_AUTOPLAY)
                exit_usiblender();
 
@@ -588,11 +608,73 @@ static void select_parent(void)   /* Makes parent active and de-selected OBACT */
        }
 }
 
-void select_grouped(short nr)
+static void select_same_group(Object *ob)      /* Select objects in the same group as the active */
+{
+       Base *base;
+       Group *group= find_group(ob);
+       if (!group || !ob)
+               return;
+       
+       for (base= FIRSTBASE; base; base= base->next) {
+               if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
+                       base->flag |= SELECT;
+                       base->object->flag |= SELECT;
+               }
+       }
+}
+
+static void select_object_hooks(Object *ob)    /* Select objects in the same group as the active */
+{
+       Base *base;
+       ModifierData *md;
+       HookModifierData *hmd;
+       
+       if (!ob)
+               return;
+       
+       for (md = ob->modifiers.first; md; md=md->next) {
+               if (md->type==eModifierType_Hook) {
+                       hmd= (HookModifierData*) md;
+                       if (hmd->object && !(hmd->object->flag & SELECT)) {
+                               base= object_in_scene(hmd->object, G.scene);
+                               base->flag |= SELECT;
+                               base->object->flag |= SELECT;
+                       }
+               }
+       }
+}
+
+static void select_same_parent(Object *ob)     /* Select objects woth the same parent as the active (siblings), parent can be NULL also */
+{
+       Base *base;
+       if (!ob)
+               return;
+       
+       for (base= FIRSTBASE; base; base= base->next)
+               if (base->object->parent==ob->parent) {
+                       base->flag |= SELECT;
+                       base->object->flag |= SELECT;
+               }
+}
+
+static void select_same_type(Object *ob)       /* Select objects woth the same parent as the active (siblings), parent can be NULL also */
+{
+       Base *base;
+       if (!ob)
+               return;
+       
+       for (base= FIRSTBASE; base; base= base->next)
+               if (base->object->type==ob->type) {
+                       base->flag |= SELECT;
+                       base->object->flag |= SELECT;
+               }
+}
+
+void select_object_grouped(short nr)
 {
        Base *base;
        
-       if(nr==4) {
+       if(nr==6) {
                base= FIRSTBASE;
                while(base) {
                        if (base->lay & OBACT->lay) {
@@ -600,11 +682,18 @@ void select_grouped(short nr)
                                base->object->flag |= SELECT;
                        }
                        base= base->next;
-               }               
+               }
        }
-       else if(nr==2) select_children(OBACT, 0);
        else if(nr==1) select_children(OBACT, 1);
+       else if(nr==2) select_children(OBACT, 0);
        else if(nr==3) select_parent();
+       else if(nr==4) select_same_parent(OBACT);       
+       else if(nr==5) select_same_type(OBACT); 
+       else if(nr==7) select_same_group(OBACT);
+       else if(nr==8) select_object_hooks(OBACT);
+       
+       
+       
        
        countall();
        allqueue(REDRAWVIEW3D, 0);
@@ -613,24 +702,28 @@ void select_grouped(short nr)
        allqueue(REDRAWIPO, 0);
 }
 
-static void select_grouped_menu(void)
+static void select_object_grouped_menu(void)
 {
        char *str;
        short nr;
 
        /* make menu string */
        
-       str= MEM_mallocN(160, "groupmenu");
+       str= MEM_mallocN(512, "groupmenu");
        strcpy(str, "Select Grouped%t|Children%x1|"
                    "Immediate Children%x2|Parent%x3|"
-                   "Objects on Shared Layers%x4");
+                   "Siblings (Shared Parent)%x4|"
+                   "Objects of Same Type%x5|"
+                               "Objects on Shared Layers%x6|"
+                "Objects in Same Group%x7|"
+                "Object Hooks%x8|");
 
        /* here we go */
        
        nr= pupmenu(str);
        MEM_freeN(str);
        
-       select_grouped(nr);
+       select_object_grouped(nr);
 }
 
 void join_menu(void)
@@ -689,6 +782,8 @@ void BIF_undo_push(char *str)
                else if (G.obedit->type==OB_ARMATURE)
                        undo_push_armature(str);
        }
+       else if(G.f & G_SCULPTMODE) {
+       }
        else {
                if(U.uiflag & USER_GLOBALUNDO) 
                        BKE_write_undo(str);
@@ -706,11 +801,18 @@ void BIF_undo(void)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
-               else if(G.f & G_TEXTUREPAINT); /* no texture paint undo yet */
-               else if(curarea->spacetype==SPACE_IMAGE && (G.sima->flag & SI_DRAWTOOL));
+               else if(G.f & G_TEXTUREPAINT)
+                       imagepaint_undo();
+               else if(G.f & G_SCULPTMODE)
+                       sculptmode_undo();
+               else if(curarea->spacetype==SPACE_IMAGE && (G.sima->flag & SI_DRAWTOOL))
+                       imagepaint_undo();
                else {
                        /* now also in faceselect mode */
                        if(U.uiflag & USER_GLOBALUNDO) {
+                               if(G.f & G_SCULPTMODE)
+                                       set_sculpt_object(NULL);
+
                                BKE_undo_step(1);
                                sound_initialize_sounds();
                        }
@@ -729,6 +831,12 @@ void BIF_redo(void)
                        wpaint_undo();
                else if(G.f & G_VERTEXPAINT)
                        vpaint_undo();
+               else if(G.f & G_TEXTUREPAINT)
+                       imagepaint_undo();
+               else if(G.f & G_SCULPTMODE)
+                       sculptmode_redo();
+               else if(curarea->spacetype==SPACE_IMAGE && (G.sima->flag & SI_DRAWTOOL))
+                       imagepaint_undo();
                else {
                        /* includes faceselect now */
                        if(U.uiflag & USER_GLOBALUNDO) {
@@ -751,6 +859,8 @@ void BIF_undo_menu(void)
                        ;
                else if(G.f & G_VERTEXPAINT)
                        ;
+               else if(G.f & G_SCULPTMODE)
+                       sculptmode_undo_menu();
                else {
                        if(U.uiflag & USER_GLOBALUNDO) {
                                char *menu= BKE_undo_menu_string();
@@ -769,10 +879,10 @@ void BIF_undo_menu(void)
 static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        View3D *v3d= sa->spacedata.first;
-       Object *ob= OBACT;      // do not change!
+       Object *ob= OBACT;      /* do not change! */
        float *curs;
        int doredraw= 0, pupval;
-       unsigned short event= evt->event;
+       unsigned short event= evt->event, origevent= evt->event;
        short val= evt->val;
        char ascii= evt->ascii;
        
@@ -781,9 +891,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        if(val) {
 
                if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
-               if(event==MOUSEY || event==MOUSEX) return;
+
+               //if(event==MOUSEY || event==MOUSEX) return;
                
-               if(event==UI_BUT_EVENT) do_butspace(val); // temporal, view3d deserves own queue?
+               if(event==UI_BUT_EVENT) do_butspace(val); /* temporal, view3d deserves own queue? */
                
                /* we consider manipulator a button, defaulting to leftmouse */
                if(event==LEFTMOUSE) if(BIF_do_manipulator(sa)) return;
@@ -794,6 +905,23 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        else if (event==RIGHTMOUSE) event = LEFTMOUSE;
                }
 
+               if(!G.obedit && (G.f & G_SCULPTMODE)) {
+                       if(G.scene->sculptdata.propset) {
+                               sculptmode_propset(event);
+                               return;
+                       }
+                       else if(event!=LEFTMOUSE && event!=MIDDLEMOUSE && (event==MOUSEY || event==MOUSEX)) {
+                               if(!bwin_qtest(sa->win))
+                                       allqueue(REDRAWVIEW3D, 0);
+                       }
+               }
+
+               /* Handle retopo painting */
+               if(retopo_mesh_paint_check()) {
+                       if(!retopo_paint(event))
+                               return;
+               }
+
                /* run any view3d event handler script links */
                if (event && sa->scriptlink.totscript)
                        if (BPY_do_spacehandlers(sa, event, SPACEHANDLER_VIEW3D_EVENT))
@@ -938,16 +1066,23 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                         * based on user preference USER_LMOUSESELECT
                         */
                        case LEFTMOUSE: 
-                               if ((G.obedit) || !(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
+                               if ((G.obedit) || !(G.f&(G_SCULPTMODE|G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
                                        mouse_cursor();
-                               } else if (G.f & G_VERTEXPAINT) {
-                                       vertex_paint();
                                }
-                               else if (G.f & G_WEIGHTPAINT){
+                               else if (G.f & G_SCULPTMODE) {
+                                       if(G.qual==LR_SHIFTKEY+LR_CTRLKEY)
+                                               sculptmode_pmv(0);
+                                       else if(!G.scene->sculptdata.propset)
+                                               sculpt();
+                               }
+                               else if (G.f & G_WEIGHTPAINT) {
                                        weight_paint();
                                }
+                               else if (G.f & G_VERTEXPAINT) {
+                                       vertex_paint();
+                               }
                                else if (G.f & G_TEXTUREPAINT) {
-                                       face_draw();
+                                       imagepaint_paint(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE, 1);
                                }
                                break;
                        case MIDDLEMOUSE:
@@ -983,17 +1118,19 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                mouse_armature();
                                }
                                else if((G.obedit && G.obedit->type==OB_MESH) && (G.qual == (LR_CTRLKEY|LR_ALTKEY)))
-                                       mouse_mesh();   // loop select for 1 mousebutton dudes
+                                       mouse_mesh();   /* loop select for 1 mousebutton dudes */
                                else if((G.obedit && G.obedit->type==OB_MESH) && (G.qual == (LR_CTRLKEY|LR_ALTKEY|LR_SHIFTKEY)))
-                                       mouse_mesh();   // loop select for 1 mousebutton dudes
+                                       mouse_mesh();   /* loop select for 1 mousebutton dudes */
                                else if(G.qual==LR_CTRLKEY)
-                                       mouse_select(); // also allow in editmode, for vertex parenting
+                                       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))
                                        sample_vpaint();
+                               else if((G.f & G_SCULPTMODE) && G.qual==LR_SHIFTKEY+LR_CTRLKEY)
+                                       sculptmode_pmv(1);
                                else
-                                       mouse_select(); // does poses too
+                                       mouse_select(); /* does poses too */
                                break;
                        case WHEELUPMOUSE:
                                /* Regular:   Zoom in */
@@ -1055,30 +1192,24 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                doredraw= 1;
                                break;
-                       
+
                        case ONEKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, 1);
-                                       }
+                                       flip_subdivison(1);
                                }
                                else do_layer_buttons(0); 
                                break;
                                
                        case TWOKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, 2);
-                                       }
+                                       flip_subdivison(2);
                                }
                                else do_layer_buttons(1); 
                                break;
                                
                        case THREEKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, 3);
-                                       }
+                                       flip_subdivison(3);
                                }
                                else if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
                                        if ( (G.obedit) && (G.obedit->type==OB_MESH) )
@@ -1089,9 +1220,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                        case FOURKEY:
                                if(G.qual==LR_CTRLKEY) {
-                                       if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, 4);
-                                       }
+                                       flip_subdivison(4);
                                }
                                else if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
                                        if ( (G.obedit) && (G.obedit->type==OB_MESH) )
@@ -1148,7 +1277,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                                
                        case AKEY:
-                               if(G.qual & LR_CTRLKEY) apply_object(); // also with shift!
+                               if(G.qual & LR_CTRLKEY) apply_object(); /* also with shift! */
                                else if((G.qual==LR_SHIFTKEY)) {
                                        toolbox_n_add();
                                }
@@ -1163,7 +1292,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else if(G.obedit->type==OB_LATTICE)
                                                        deselectall_Latt();
                                                else if(G.obedit->type==OB_ARMATURE)
-                                                       deselectall_armature(1);        // 1 == toggle
+                                                       deselectall_armature(1);        /* 1 == toggle */
                                        }
                                        else if (ob && (ob->flag & OB_POSEMODE)){
                                                deselectall_posearmature(ob, 1);
@@ -1184,7 +1313,23 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if(G.qual==LR_ALTKEY)
                                        view3d_edit_clipping(v3d);
                                else if(G.qual==LR_SHIFTKEY)
-                                       set_render_border();
+                               {
+                                       if(G.vd->persp==2)
+                                               set_render_border();
+                                       else
+                                               view3d_border_zoom();
+                               }
+                               else if(G.qual==LR_CTRLKEY) {
+                                       if(okee("Bake all selected")) {
+                                               extern void softbody_bake(Object *ob);
+                                               extern void fluidsimBake(Object *ob);
+                                               softbody_bake(NULL);
+                                               /* also bake first domain of selected objects... */
+                                               fluidsimBake(NULL);
+                                       }
+                               }
+                               else if(G.qual== (LR_ALTKEY|LR_CTRLKEY))
+                                       objects_bake_render();
                                else if(G.qual==0)
                                        borderselect();
                                break;
@@ -1215,13 +1360,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        allqueue(REDRAWVIEW3D, 0);
                                }
                                else if((G.qual==0)){
-                                       curs= give_cursor();
-                                       G.vd->ofs[0]= -curs[0];
-                                       G.vd->ofs[1]= -curs[1];
-                                       G.vd->ofs[2]= -curs[2];
+                                       if (G.vd->persp==2)
+                                               /* center the camera offset */
+                                               G.vd->camdx= G.vd->camdy= 0.0;
+                                       else {
+                                               /*non camera center*/
+                                               curs= give_cursor();
+                                               G.vd->ofs[0]= -curs[0];
+                                               G.vd->ofs[1]= -curs[1];
+                                               G.vd->ofs[2]= -curs[2];
+                                       }
                                        scrarea_queue_winredraw(curarea);
                                }
-                       
                                break;
                        case DKEY:
                                if((G.qual==LR_SHIFTKEY)) {
@@ -1237,11 +1387,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        imagestodisplist();
                                }
                                else if((G.qual==0)){
-                                       pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
-                                       if(pupval>0) {
-                                               G.vd->drawtype= pupval;
-                                               doredraw= 1;
-                                       
+                                       if(G.f & G_SCULPTMODE)
+                                               sculptmode_propset_init(DKEY);
+                                       else {
+                                               pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
+                                               if(pupval>0) {
+                                                       G.vd->drawtype= pupval;
+                                                       doredraw= 1;
+                                               }
                                        }
                                }
                                
@@ -1262,6 +1415,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if (G.qual==LR_CTRLKEY) {
                                        if(G.obedit && G.obedit->type==OB_MESH)
                                                Edge_Menu();
+                                       else if (G.f & G_FACESELECT)
+                                               seam_mark_clear_tface(0);
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
@@ -1308,9 +1463,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                break;
                        case GKEY:
-                               if(G.qual & LR_CTRLKEY) group_operation_with_menu();
+                               if(G.qual == LR_CTRLKEY) 
+                                       group_operation_with_menu();
                                else if((G.qual==LR_SHIFTKEY))
-                                       select_grouped_menu();
+                                       if(G.obedit) {
+                                               if(G.obedit->type==OB_MESH)
+                                                       select_mesh_group_menu();
+                                       } else
+                                               select_object_grouped_menu();
                                else if(G.qual==LR_ALTKEY) {
                                        if(okee("Clear location")) {
                                                clear_object('g');
@@ -1385,6 +1545,15 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if(G.f & G_FACESELECT)
                                        hide_tface();
+                               else if(G.f & G_SCULPTMODE) {
+                                       if(G.qual==LR_ALTKEY) {
+                                               waitcursor(1);
+                                               sculptmode_pmv_off(get_mesh(ob));
+                                               BIF_undo_push("Partial mesh hide");
+                                               allqueue(REDRAWVIEW3D,0);
+                                               waitcursor(0);
+                                       }
+                               }
                                else if(ob && (ob->flag & OB_POSEMODE)) {
                                        if (G.qual==0)
                                                hide_selected_pose_bones();
@@ -1437,7 +1606,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else {
                                        if((G.qual==LR_SHIFTKEY)) {
                                                if(G.f & G_FACESELECT)
-                                                       clear_vpaint_selectedfaces();
+                                                       if (G.f & G_WEIGHTPAINT)
+                                                               clear_wpaint_selectedfaces();
+                                                       else
+                                                               clear_vpaint_selectedfaces();
                                                else if(G.f & G_VERTEXPAINT)
                                                        clear_vpaint();
                                                else
@@ -1471,7 +1643,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                        else {
                                                if((G.qual==0))
-                                                       make_local();
+                                                       make_local_menu();
                                                else if((G.qual==LR_SHIFTKEY))
                                                        selectlinks_menu();
                                                else if(G.qual==LR_CTRLKEY)
@@ -1544,7 +1716,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        case OKEY:
                                if (G.obedit) {
                                        if (G.qual==LR_SHIFTKEY) {
-                                               G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                                               G.scene->prop_mode = (G.scene->prop_mode+1)%7;
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                        else if((G.qual==LR_ALTKEY)) {
@@ -1557,10 +1729,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                allqueue(REDRAWHEADERS, 0);
                                        }
                                }
-                               else if((G.qual==LR_SHIFTKEY)) {
-                                       if(ob && ob->type == OB_MESH) {
-                                               flip_subdivison(ob, -1);
-                                       }
+                               else if((G.qual==LR_SHIFTKEY || G.qual==(LR_ALTKEY|LR_SHIFTKEY))) {
+                                       flip_subdivison(-1);
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        if(okee("Clear origin")) {
@@ -1577,8 +1747,11 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                else
                                                        make_parent();
                                        }
+                                       
                                        else if(G.qual==LR_ALTKEY && G.obedit->type==OB_ARMATURE)
                                                clear_bone_parent();
+                                       else if((G.qual==0) && (G.obedit->type==OB_ARMATURE)) 
+                                               select_bone_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))
@@ -1591,18 +1764,22 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(G.qual==LR_CTRLKEY || G.qual==(LR_SHIFTKEY|LR_CTRLKEY))
                                        make_parent();
                                else if(G.qual==LR_SHIFTKEY) {
-                                       //initTransform(TFM_PUSHPULL, CTX_NONE);
-                                       //Transform();
-                                       
-                                       //Ton: is this where is should go?
-                                       toggle_blockhandler(curarea, VIEW3D_HANDLER_PREVIEW, 0);
-                                       doredraw= 1;
+                                       if(G.obedit) {
+                                               initTransform(TFM_PUSHPULL, CTX_NONE);
+                                               Transform();
+                                       }
+                                       else {
+                                               toggle_blockhandler(curarea, VIEW3D_HANDLER_PREVIEW, 0);
+                                               doredraw= 1;
+                                       }
                                }
                                else if(G.qual==LR_ALTKEY)
                                        clear_parent();
+                               else if(G.qual==(LR_ALTKEY|LR_CTRLKEY))
+                                       make_proxy();
+                               else if((G.qual==0) && (OBACT) && (OBACT->type==OB_ARMATURE) && (OBACT->flag & OB_POSEMODE))
+                                       select_bone_parent();
                                else if((G.qual==0)) {
-                                       //toggle_blockhandler(curarea, VIEW3D_HANDLER_PREVIEW, 0);
-                                       //doredraw= 1;
                        start_game();
                                }
                                break;                          
@@ -1649,8 +1826,11 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                if(G.obedit->type==OB_ARMATURE) {
                                                        initTransform(TFM_BONESIZE, CTX_NONE);
                                                }
-                                               else
+                                               else if (G.obedit->type==OB_CURVE) {
+                                                       initTransform(TFM_CURVE_SHRINKFATTEN, CTX_NONE);
+                                               } else {
                                                        initTransform(TFM_SHRINKFATTEN, CTX_NONE);
+                                               }
                                                Transform();
                                        }
                                        else if(G.qual==LR_CTRLKEY) {
@@ -1691,7 +1871,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                }
                                        }
                                        
-                                       if(okee("Clear size")) {
+                                       if(okee("Clear scale")) {
                                                clear_object('s');
                                        }
                                }
@@ -1752,12 +1932,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        }
                                }
                                else if((G.qual==0)) {
-                                       if (G.f & G_FACESELECT)
-                                               uv_autocalc_tface();
-                                       else if(G.f & G_WEIGHTPAINT)
+                                       if(G.f & G_WEIGHTPAINT)
                                                wpaint_undo();
                                        else if(G.f & G_VERTEXPAINT)
                                                vpaint_undo();
+                                       else if(G.f & G_TEXTUREPAINT)
+                                               imagepaint_undo();
+                                       else if (G.f & G_FACESELECT)
+                                               uv_autocalc_tface();
                                        else {
                                                single_user();
                                        }
@@ -1812,7 +1994,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case XKEY:
                        case DELKEY:
-                               if(G.qual==0)
+                               if(G.qual==0 || G.qual==LR_SHIFTKEY)
                                        delete_context_selected();
                                break;
                        case YKEY:
@@ -1896,19 +2078,33 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        
                        case PAGEUPKEY:
-                               if(G.qual==LR_CTRLKEY)
-                                       movekey_obipo(1);
-                               else if((G.qual==0))
-                                       nextkey_obipo(1);       /* in editipo.c */
+                               if(G.f & G_SCULPTMODE) {
+                                       if(ob && ob->type == OB_MESH && ((Mesh*)ob->data)->mr) {
+                                               ((Mesh*)ob->data)->mr->newlvl= ((Mesh*)ob->data)->mr->current+1;
+                                               multires_set_level(ob,ob->data);
+                                       }
+                               } else {
+                                       if(G.qual==LR_CTRLKEY)
+                                               movekey_obipo(1);
+                                       else if((G.qual==0))
+                                               nextkey_obipo(1);       /* in editipo.c */
+                               }
                                break;
 
                        case PAGEDOWNKEY:
-                               if(G.qual==LR_CTRLKEY)
-                                       movekey_obipo(-1);
-                               else if((G.qual==0))
-                                       nextkey_obipo(-1);
+                               if(G.f & G_SCULPTMODE) {
+                                       if(ob && ob->type == OB_MESH && ((Mesh*)ob->data)->mr) {
+                                               ((Mesh*)ob->data)->mr->newlvl= ((Mesh*)ob->data)->mr->current-1;
+                                               multires_set_level(ob,ob->data);
+                                       }
+                               } else {
+                                       if(G.qual==LR_CTRLKEY)
+                                               movekey_obipo(-1);
+                                       else if((G.qual==0))
+                                               nextkey_obipo(-1);
+                               }
                                break;
-                               
+
                        case PAD0: case PAD1: case PAD2: case PAD3: case PAD4:
                        case PAD5: case PAD6: case PAD7: case PAD8: case PAD9:
                        case PADENTER:
@@ -1919,6 +2115,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if ( (G.qual==LR_CTRLKEY)
                                         && (G.obedit) && (G.obedit->type==OB_MESH) )
                                        select_less();
+                               else if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_CURVE) )
+                                       select_less_nurb();
+                               /*
+                               else if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_SURF) )
+                                       select_less_nurb(); 
+                               */
                                else {
                                        persptoetsen(event);
                                        doredraw= 1;
@@ -1929,6 +2133,14 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                if ( (G.qual==LR_CTRLKEY)
                                         && (G.obedit) && (G.obedit->type==OB_MESH) )
                                        select_more();
+                               else if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_CURVE) )
+                                       select_more_nurb();
+                               /*
+                               else if ( (G.qual==LR_CTRLKEY)
+                                        && (G.obedit) && (G.obedit->type==OB_SURF) )
+                                       select_more_nurb();
+                               */
                                else {
                                        persptoetsen(event);
                                        doredraw= 1;
@@ -1983,6 +2195,8 @@ static void initview3d(ScrArea *sa)
        vd->gridflag |= V3D_SHOW_Y;
        vd->gridflag |= V3D_SHOW_FLOOR;
        vd->gridflag &= ~V3D_SHOW_Z;
+
+       vd->depths= NULL;
 }
 
 
@@ -1998,7 +2212,7 @@ static void changeview2dspace(ScrArea *sa, void *spacedata)
 
 static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
-       extern void do_ipobuts(unsigned short event);   // drawipo.c
+       extern void do_ipobuts(unsigned short event);   /* drawipo.c */
        unsigned short event= evt->event;
        short val= evt->val;
        SpaceIpo *sipo= curarea->spacedata.first;
@@ -2027,7 +2241,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                switch(event) {
                case UI_BUT_EVENT:
                        /* note: bad bad code, will be cleaned! is because event queues are all shattered */
-                       if(val>0 && val < 65) do_ipowin_buts(val-1);
+                       if(val>0 && val < 256) do_ipowin_buts(val-1);
                        else do_ipobuts(val);
                        break;
                        
@@ -2036,7 +2250,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                do_ipo_selectbuttons();
                                doredraw= 1;
                        }
-                       else if(view2dmove(LEFTMOUSE)); // only checks for sliders
+                       else if(view2dmove(LEFTMOUSE)); /* only checks for sliders */
                        else if(G.qual & LR_CTRLKEY) add_vert_ipo();
                        else {
                                do {
@@ -2048,7 +2262,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        
                                        if( cfra!=CFRA ) {
                                                CFRA= cfra;
-                                               update_for_newframe_nodraw(1);  /* 1 = nosound */
+                                               update_for_newframe_nodraw(0);  /* 1 = nosound */
                                                force_draw_all(0); /* To make constraint sliders redraw */
                                        }
                                        else PIL_sleep_ms(30);
@@ -2134,7 +2348,7 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                sethandles_ipo(HD_ALIGN);
                        break;
                case JKEY:
-                       if((G.qual==0))
+                       if((G.qual==LR_CTRLKEY))
                                join_ipo_menu();
                        break;
                case KKEY:
@@ -2145,10 +2359,20 @@ static void winqreadipospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                doredraw= 1;
                        }
                        break;
+               case MKEY:
+                       if((G.qual==0))
+                               ipo_mirror_menu();
+                       break;
                case NKEY:
                        toggle_blockhandler(sa, IPO_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
                        doredraw= 1;
                        break;
+               case OKEY: 
+                       if(G.qual==LR_SHIFTKEY) 
+                               smooth_ipo();
+                       else
+                               clean_ipo(sipo->ipo, 1);
+                       break;
                case RKEY:
                        if((G.qual==0))
                                ipo_record();
@@ -2229,7 +2453,7 @@ static void space_sound_button_function(int event)
 }
 #endif
 
-// needed for event; choose new 'curmain' resets it...
+/* needed for event; choose new 'curmain' resets it... */
 static short th_curcol= TH_BACK;
 static char *th_curcol_ptr= NULL;
 static char th_curcol_arr[4]={0, 0, 0, 255};
@@ -2242,7 +2466,7 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        short a, tot=0, isbuiltin= 0;
        char string[21*32], *strp, *col;
        
-       y3= y2+23;      // exception!
+       y3= y2+23;      /* exception! */
        
        /* count total, max 16! */
        for(bt= U.themes.first; bt; bt= bt->next) tot++;
@@ -2306,12 +2530,12 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        else if(curmain==14) spacetype= SPACE_IMASEL;
        else if(curmain==15) spacetype= SPACE_TIME;
        else if(curmain==16) spacetype= SPACE_NODE;
-       else return; // only needed while coding... when adding themes for more windows
+       else return; /* only needed while coding... when adding themes for more windows */
        
        /* color choices pup */
        if(curmain==1) {
                strp= BIF_ThemeColorsPup(0);
-               if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  // switching main choices...
+               if(th_curcol==TH_BACK) th_curcol= TH_BUT_OUTLINE;  /* switching main choices... */
        }
        else strp= BIF_ThemeColorsPup(spacetype);
        
@@ -2330,15 +2554,15 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        }
        else if(th_curcol==TH_BUT_DRAWTYPE) {
                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, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Minimal", 465,y3,100,20,  col, 2.0, (float) TH_MINIMAL, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Shaded", 565,y3,100,20,  col, 2.0, (float) TH_SHADED, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "Rounded", 465,y2,100,20,  col, 2.0, (float) TH_ROUNDED, 0, 0, "");
+               uiDefButC(block, ROW, B_UPDATE_THEME, "OldSkool", 565,y2,100,20,  col, 2.0, (float) TH_OLDSKOOL, 0, 0, "");
                uiBlockEndAlign(block);
        }
        else {
                uiBlockBeginAlign(block);
-               if ELEM7(th_curcol, TH_PANEL, TH_LAMP, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM) {
+               if ELEM8(th_curcol, TH_PANEL, TH_LAMP, TH_FACE, TH_FACE_SELECT, TH_MENU_BACK, TH_MENU_HILITE, TH_MENU_ITEM, TH_NODE) {
                        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, "");
@@ -2471,7 +2695,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        xpos,y6label,spref,buth,
                        0, 0, 0, 0, 0, "");     
                uiBlockBeginAlign(block);
-               uiDefButBitI(block, TOG, USER_TOOLTIPS, 0, "ToolTips",
+               uiDefButBitI(block, TOG, USER_TOOLTIPS, 0, "Tool Tips",
                        (xpos+edgsp),y5,spref,buth,
                        &(U.flag), 0, 0, 0, 0,
                        "Display tooltips (help tags) over buttons");
@@ -2491,10 +2715,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
 #else 
                U.curssize=0; /*Small Cursor always for OS X for now */
 #endif
-               uiDefButBitI(block, TOG, USER_PLAINMENUS, B_PLAINMENUS, "Plain menus",
+               uiDefButBitI(block, TOG, USER_SHOW_VIEWPORTNAME, B_DRAWINFO, "View Name",
                        (xpos+edgsp),y1,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
-                       "Use column layout for toolbox and do not flip contents in any menu");
+                       "Show the name of the view's direction in each 3D View");
                uiBlockEndAlign(block);
 
                uiDefBut(block, LABEL,0,"Menus:",
@@ -2533,11 +2757,11 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+spref+midsp),y1,(mpref/2),buth,
                        &(U.uiflag), 0, 0, 0, 0,
                        "Make floating panels invoked by a hotkey (eg. N Key) open at the previous location");
-               
-               uiDefButBitI(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
-                       (xpos+edgsp+spref+midsp+(mpref/2)),y1,(mpref/2),buth,
+               uiDefButBitI(block, TOG, USER_PLAINMENUS, B_PLAINMENUS, "Plain Menus",
+                       (xpos+edgsp+(2*spref)+(2*midsp)),y1,spref,buth,
                        &(U.uiflag), 0, 0, 0, 0,
-                       "Lock the same rotation/scaling pivot in all 3D Views");        
+                       "Use a column layout for toolbox and do not flip the contents of any menu");
+               uiBlockEndAlign(block);
                
                uiDefBut(block, LABEL,0,"Snap to grid:",
                        (xpos+(2*edgsp)+spref+midsp+mpref),y6label,mpref,buth,
@@ -2557,6 +2781,11 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        "Snap objects and sub-objects to grid units when scaling");
                uiBlockEndAlign(block);
                
+               uiDefButBitI(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, "");
@@ -2600,6 +2829,27 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        &(U.uiflag), 0, 0, 0, 0,
                        "Keep the active object in place when orbiting the views (Object Mode)");
                uiBlockEndAlign(block);
+               
+
+               uiBlockBeginAlign(block);
+               uiDefButBitI(block, TOG, USER_SHOW_ROTVIEWICON, B_DRAWINFO, "Mini Axis",
+                        (xpos+edgsp+(2*mpref)+(2*midsp)),y1,(mpref/3),buth,
+                        &(U.uiflag), 0, 0, 0, 0,
+                        "Show a small rotating 3D axis in the bottom left corner of the 3D View");
+               uiDefButS(block, NUM, B_DRAWINFO, "Size:",
+                       (xpos+edgsp+(2*mpref)+(2*midsp)+(mpref/3)),y1,(mpref/3),buth,
+                       &U.rvisize, 10, 64, 0, 0,
+                       "The axis icon's size");
+               uiDefButS(block, NUM, B_DRAWINFO, "Bright:",
+                       (xpos+edgsp+(2*mpref)+(2*midsp)+2*(mpref/3)),y1,(mpref/3),buth,
+                       &U.rvibright, 0, 10, 0, 0,
+                       "The brightness of the icon");
+               uiBlockEndAlign(block);
+
+        uiDefButS(block, NUM, B_DRAWINFO, "Rotation Angle:",
+                       (xpos+edgsp+(3*mpref)+(4*midsp)),y1,(mpref),buth,
+                       &U.pad_rot_angle, 0, 90, 0, 0,
+                       "The rotation step for numerical pad keys (2 4 6 8)");
 
                uiDefBut(block, LABEL,0,"Select with:",
                        (xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
@@ -2680,15 +2930,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                  &(U.tw_hotspot), 4, 40, 0, 0, "Hotspot in pixels for clicking widget handles");
                uiBlockEndAlign(block);
                
-               
-               uiDefBut(block, LABEL,0,"Object center diameter",
-                                (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y3label,mpref,buth,
-                                0, 0, 0, 0, 0, "");
-               uiBlockBeginAlign(block);
-               uiDefButS(block, NUM, B_REDRCURW3D, "Size",
-                                 (xpos+(2*edgsp)+(5*mpref)+(5*midsp)),y2,mpref,buth,
+               uiDefButS(block, NUM, B_REDRCURW3D, "Object Center Size: ",
+                                  (xpos+edgsp+(5*mpref)+(6*midsp)),y3,mpref,buth,
                                  &(U.obcenter_dia), 4, 10, 0, 0,
-                                 "Diameter in Pixels for Object/Lamp center drawing");
+                                 "Diameter in Pixels for Object/Lamp center display");
                
                
        } else if (U.userpref == 1) { /* edit methods */
@@ -2711,11 +2956,11 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+(2*edgsp)+mpref),y3label, mpref,buth,
                        0, 0, 0, 0, 0, "");
                uiBlockBeginAlign(block);
-               uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps:",
+               uiDefButS(block, NUMSLI, B_DRAWINFO, "Steps: ",
                        (xpos+edgsp+mpref+midsp),y2,mpref,buth,
                        &(U.undosteps), 0, 64, 0, 0, "Number of undo steps available (smaller values conserve memory)");
 
-               uiDefButBitI(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global undo",
+               uiDefButBitI(block, TOG, USER_GLOBALUNDO, B_DRAWINFO, "Global Undo",
                        (xpos+edgsp+mpref+midsp),y1,mpref,buth,
                        &(U.uiflag), 2, 64, 0, 0, "Global undo works by keeping a full copy of the file itself in memory, so takes extra memory");
                uiBlockEndAlign(block);
@@ -2733,12 +2978,12 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(2*mpref)+(2*midsp)),y1,mpref, buth,
                        &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in available curves");
 
-//             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");
+/*             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:",
@@ -2871,17 +3116,30 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                }
 
        } else if (U.userpref == 4) { /* system & opengl */
+
+#ifdef WITH_VERSE
+               uiDefBut(block, TEX, 0, "Verse Master: ",
+                       (xpos+edgsp),y3label+buth+5,mpref*2,buth,
+                       U.versemaster, 1.0, 63.0, 0, 0,
+                       "The Verse Master-server IP");
+               uiDefBut(block, TEX, 0, "Verse Username: ",
+                       (xpos+edgsp)+mpref*2+10,y3label+buth+5,mpref*2,buth,
+                       U.verseuser, 1.0, 63.0, 0, 0,
+                       "The Verse user name");
+#endif
+
                uiDefBut(block, LABEL,0,"Solid OpenGL light:",
                        xpos+edgsp, y3label, mpref, buth,
                        0, 0, 0, 0, 0, "");
                
+               uiBlockBeginAlign(block);
                uiDefButS(block, MENU, B_REDR, "Light1 %x0|Light2 %x1|Light3 %x2",
                        xpos+edgsp, y2, 2*mpref/6, buth, &cur_light, 0.0, 0.0, 0, 0, "");
                uiBlockSetCol(block, TH_BUT_SETTING1);
                uiDefButBitI(block, TOG, 1, B_RECALCLIGHT, "On",
                        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+edgsp+3*mpref/6, y2, mpref/6, buth, 
@@ -2892,7 +3150,9 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                uiDefButS(block, ROW, B_REDR, "Spec",
                        xpos+edgsp+5*mpref/6, y2, mpref/6, buth, 
                        &cur_light_var, 123.0, 2.0, 0, 0, "Specular color for OpenGL light");
-
+               uiBlockEndAlign(block);
+               
+               uiBlockBeginAlign(block);
                if(cur_light_var==1) {
                        uiDefButF(block, NUM, B_RECALCLIGHT, "R ",
                                xpos+edgsp, y1, mpref/3, buth, 
@@ -2926,6 +3186,7 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                xpos+edgsp+2*mpref/3, y1, mpref/3, buth, 
                                U.light[cur_light].vec+2, -1.0, 1.0, 100, 2, "");
                }
+               uiBlockEndAlign(block);
 
 /*
                uiDefButBitS(block, TOG, USER_EVTTOCONSOLE, 0, "Log Events to Console",
@@ -2967,8 +3228,16 @@ void drawinfospace(ScrArea *sa, void *spacedata)
 
 
                uiDefBut(block, LABEL,0,"System:",
-                       (xpos+edgsp+(4*midsp)+(4*mpref)),y4label,mpref,buth,
+                       (xpos+edgsp+(4*midsp)+(4*mpref)),y6label,mpref,buth,
                        0, 0, 0, 0, 0, "");
+               uiDefButI(block, NUM, B_MEMCACHELIMIT, "MEM Cache Limit ",
+                         (xpos+edgsp+(4*mpref)+(4*midsp)), y5, mpref, buth, 
+                         &U.memcachelimit, 0.0, 1024.0, 30, 2, 
+                         "Memory cache limit in sequencer");
+               uiDefButS(block, NUM, B_REDR, "Frameserver Port ",
+                         (xpos+edgsp+(4*mpref)+(4*midsp)), y4, mpref, buth, 
+                         &U.frameserverport, 0.0, 32727.0, 30, 2, 
+                         "Frameserver Port for Framserver-Rendering");
 
                uiDefButBitI(block, TOG, USER_DISABLE_SOUND, B_SOUNDTOGGLE, "Disable Game Sound",
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y3,mpref,buth,
@@ -2982,7 +3251,6 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
                        &(U.uiflag), 0, 0, 0, 0, "Hide files/datablocks that start with a dot(.*)");
 
-
                uiDefBut(block, LABEL,0,"OpenGL:",
                        (xpos+edgsp+(5*midsp)+(5*mpref)),y5label,mpref,buth,
                        0, 0, 0, 0, 0, "");
@@ -3156,7 +3424,7 @@ static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                bTheme *btheme= U.themes.first;
                                BLI_remlink(&U.themes, btheme);
                                MEM_freeN(btheme);
-                               BIF_SetTheme(sa); // 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) {
@@ -3170,7 +3438,7 @@ static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                allqueue(REDRAWALL, 0);
                        }
                        else if(val==B_CHANGE_THEME) {
-                               th_curcol= TH_BACK;     // backdrop color is always there...
+                               th_curcol= TH_BACK;     /* backdrop color is always there... */
                                addqueue(sa->win, REDRAW, 1);
                        }
                        else if(val==B_THEME_COPY) {
@@ -3198,6 +3466,12 @@ static void winqreadinfospace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                default_gl_light();
                                addqueue(sa->win, REDRAW, 1);
                                allqueue(REDRAWVIEW3D, 0);
+                       } 
+                       else if (val==B_MEMCACHELIMIT) {
+                               printf("Setting memcache limit to %d\n",
+                                      U.memcachelimit);
+                               MEM_CacheLimiter_set_maximum(
+                                       U.memcachelimit * 1024 * 1024);
                        }
                        else do_global_buttons(val);
                        
@@ -3304,7 +3578,7 @@ static void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                sa= curarea;
                                areawinset(sa3d->win);
                                
-                               if(event==PKEY) start_game();
+                               if(event==PKEY && G.qual==0) start_game();
                                else if(event==ZKEY) toggle_shading();
                                else persptoetsen(event);
                                
@@ -3368,7 +3642,7 @@ static void init_butspace(ScrArea *sa)
        buts->ri = NULL;
 }
 
-void extern_set_butspace(int fkey)
+void extern_set_butspace(int fkey, int do_cycle)
 {
        ScrArea *sa;
        SpaceButs *sbuts;
@@ -3385,11 +3659,12 @@ void extern_set_butspace(int fkey)
                }
        }
        
-       if(sa==0) return;
+       if(sa==NULL) return;
        
        if(sa!=curarea) areawinset(sa->win);
        
        sbuts= sa->spacedata.first;
+       if(!do_cycle) sbuts->oldkeypress= 0;
        
        if(fkey==F4KEY) {
                sbuts->mainb= CONTEXT_LOGIC;
@@ -3412,7 +3687,7 @@ void extern_set_butspace(int fkey)
                }
                /* if we're coming in from texture buttons, 
                or from outside the shading context, just go to the 'default' */
-               else if (ob && ((sbuts->mainb!= CONTEXT_SHADING) || (sbuts->oldkeypress == F6KEY)) ) {
+               else if (ob) {
                        sbuts->mainb= CONTEXT_SHADING;
                        
                        if(ob->type==OB_CAMERA) 
@@ -3448,6 +3723,7 @@ void extern_set_butspace(int fkey)
        else if(fkey==F8KEY) {
                sbuts->mainb= CONTEXT_SHADING;
                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_WORLD;
+               BIF_preview_changed(ID_TE);
        }
        else if(fkey==F9KEY) sbuts->mainb= CONTEXT_EDITING;
        else if(fkey==F10KEY) {
@@ -3480,16 +3756,16 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        short val= evt->val;
        SpaceSeq *sseq= curarea->spacedata.first;
        View2D *v2d= &sseq->v2d;
-       extern Sequence *last_seq;
+       Sequence *last_seq = get_last_seq();
        float dx, dy;
-       int doredraw= 0, cfra, first;
+       int doredraw= 0, cfra=0, first;
        short mval[2];
+       short nr;
        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 */
@@ -3534,20 +3810,20 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                set_special_seq_update(0);
                                
-                               update_for_newframe();
+                               if (cfra == 0)
+                                       update_for_newframe();
                        }
                        break;
                case MIDDLEMOUSE:
-               case WHEELUPMOUSE:
-               case WHEELDOWNMOUSE:
-                       if(sseq->mainb) break;
-                       view2dmove(event);      /* in drawipo.c */
+                       if(sseq->mainb) seq_viewmove(sseq);
+                       else view2dmove(event); /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
                        if(sseq->mainb) break;
                        mouse_select_seq();
                        break;
                case PADPLUSKEY:
+               case WHEELUPMOUSE:
                        if(sseq->mainb) {
                                sseq->zoom++;
                                if(sseq->zoom==-1) sseq->zoom= 1;
@@ -3558,7 +3834,8 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        dx= 0.1154f*(v2d->cur.xmax-v2d->cur.xmin);
                                        v2d->cur.xmin+= dx;
                                        v2d->cur.xmax-= dx;
-                                       test_view2d(G.v2d, curarea->winx, curarea->winy);
+                                       test_view2d(G.v2d, sa->winx, sa->winy);
+                                       view2d_do_locks(sa, V2D_LOCK_COPY);
                                }
                                else if((G.qual==LR_SHIFTKEY)) {
                                        insert_gap(25, CFRA);
@@ -3574,6 +3851,7 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        doredraw= 1;
                        break;
                case PADMINUS:
+               case WHEELDOWNMOUSE:
                        if(sseq->mainb) {
                                sseq->zoom--;
                                if(sseq->zoom==0) sseq->zoom= -2;
@@ -3586,7 +3864,8 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        dx= 0.15f*(v2d->cur.xmax-v2d->cur.xmin);
                                        v2d->cur.xmin-= dx;
                                        v2d->cur.xmax+= dx;
-                                       test_view2d(G.v2d, curarea->winx, curarea->winy);
+                                       test_view2d(G.v2d, sa->winx, sa->winy);
+                                       view2d_do_locks(sa, V2D_LOCK_COPY);
                                }
                        }
                        doredraw= 1;
@@ -3612,6 +3891,15 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        else if((G.qual==0))
                                swap_select_seq();
                        break;
+               case SPACEKEY:
+                       if (G.qual==0) {
+                               if (sseq->mainb) {
+                                       play_anim(1);
+                               } else {
+                                       add_sequence(-1);
+                               }
+                       }
+                       break;
                case BKEY:
                        if(sseq->mainb) break;
                        if((G.qual==0))
@@ -3656,7 +3944,9 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        if(G.qual==LR_ALTKEY)
                                un_meta();
                        else if((G.qual==0)){
-                               if ((last_seq) && (last_seq->type == SEQ_SOUND)) 
+                               if ((last_seq) && 
+                                   (last_seq->type == SEQ_RAM_SOUND
+                                    || last_seq->type == SEQ_HD_SOUND)) 
                                {
                                        last_seq->flag ^= SEQ_MUTE;
                                        doredraw = 1;
@@ -3671,14 +3961,25 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                scrarea_queue_winredraw(curarea);
                        }
                        break;
+               case RKEY:
+                       reassign_inputs_seq_effect();
+                       break;
                case SKEY:
                        if((G.qual==LR_SHIFTKEY))
                                seq_snap_menu();
                        break;
-               case TKEY:
+               case PKEY:
                        if((G.qual==0))
                                touch_seq_files();
                        break;
+               case TKEY: /* popup menu */
+                       nr= pupmenu("Time value%t|Frames %x1|Seconds%x2");
+                       if (nr>0) {
+                               if(nr==1) sseq->flag |= SEQ_DRAWFRAMES;
+                               else sseq->flag &= ~SEQ_DRAWFRAMES;
+                               doredraw= 1;
+                       }
+                       break;
                case XKEY:
                case DELKEY:
                        if(G.qual==0) {
@@ -3702,8 +4003,9 @@ static void init_seqspace(ScrArea *sa)
        BLI_addhead(&sa->spacedata, sseq);
 
        sseq->spacetype= SPACE_SEQ;
-       sseq->zoom= 1;
+       sseq->zoom= 4;
        sseq->blockscale= 0.7;
+       sseq->chanshown = 0;
        
        /* seq space goes from (0,8) to (250, 0) */
 
@@ -3738,10 +4040,10 @@ static void changeactionspace(ScrArea *sa, void *spacedata)
        if(G.v2d==0) return;
 
        /* this sets the sub-areas correct, for scrollbars */
-       test_view2d(G.v2d, curarea->winx, curarea->winy);
+       test_view2d(G.v2d, sa->winx, sa->winy);
        
        /* action space uses weird matrices... local calculated in a function */
-       // myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
+       /* myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); */
 }
 
 
@@ -3835,7 +4137,7 @@ static void init_imaselspace(ScrArea *sa)
        
        clear_ima_dir(simasel);
        
-       // simasel->cmap= IMB_loadiffmem((int*)datatoc_cmap_tga, IB_rect|IB_cmap);
+       /* simasel->cmap= IMB_loadiffmem((int*)datatoc_cmap_tga, IB_rect|IB_cmap); */
        simasel->cmap= IMB_ibImageFromMemory((int *)datatoc_cmap_tga, datatoc_cmap_tga_size, IB_rect|IB_cmap);
        if (!simasel->cmap) {
                error("in console");
@@ -3894,17 +4196,20 @@ void free_soundspace(SpaceSound *ssound)
 
 /* ******************** SPACE: IMAGE ********************** */
 
-/*  extern void drawimagespace(ScrArea *sa, void *spacedata); BIF_drawimage.h */
+static void changeimagepace(ScrArea *sa, void *spacedata)
+{
+       image_preview_event(2);
+}
 
 static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
+       SpaceImage *sima= spacedata;
        unsigned short event= evt->event, origevent= evt->event;
        short val= evt->val;
-       SpaceImage *sima= curarea->spacedata.first;
        
        if(val==0) return;
 
-       if(uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+       if(uiDoBlocks(&sa->uiblocks, event)!=UI_NOTHING ) event= 0;
        
        if (U.flag & USER_LMOUSESELECT) {
                if (event == LEFTMOUSE) {
@@ -3914,14 +4219,14 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                }
        }
 
-       if (sima->flag & SI_DRAWTOOL) {
+       if (sima->image && (sima->flag & SI_DRAWTOOL)) {
                switch(event) {
-                       case CKEY: 
-                               add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
-                               scrarea_queue_winredraw(curarea);
+                       case CKEY:
+                       toggle_blockhandler(sa, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
+                               scrarea_queue_winredraw(sa);
                                break;
                        case LEFTMOUSE:
-                               imagepaint_paint(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE);
+                               imagepaint_paint(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE, 0);
                                break;
                        case RIGHTMOUSE:
                                imagepaint_pick(origevent==LEFTMOUSE? L_MOUSE: R_MOUSE);
@@ -3969,8 +4274,8 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        toggle_uv_select('f');
                                break;
                        case EKEY :
-                               if(okee("LSCM Unwrap"))
-                                       unwrap_lscm();
+                               if(okee("Unwrap"))
+                                       unwrap_lscm(0);
                                break;
                        case GKEY:
                                if((G.qual==0) && is_uv_tface_editing_allowed()) {
@@ -4006,7 +4311,7 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
                        case OKEY:
                                if (G.qual==LR_SHIFTKEY) {
-                                       G.scene->prop_mode = (G.scene->prop_mode+1)%6;
+                                       G.scene->prop_mode = (G.scene->prop_mode+1)%7;
                                        allqueue(REDRAWHEADERS, 0);
                                }
                                else if((G.qual==0)) {
@@ -4014,12 +4319,20 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                break;
                        case PKEY:
-                               if(G.qual==LR_SHIFTKEY)
-                                       select_pinned_tface_uv();
-                               else if(G.qual==LR_ALTKEY)
-                                       pin_tface_uv(0);
-                               else
-                                       pin_tface_uv(1);
+                               if(G.f & G_FACESELECT) {
+                                       if(G.qual==LR_SHIFTKEY)
+                                               select_pinned_tface_uv();
+                                       else if(G.qual==LR_ALTKEY)
+                                               pin_tface_uv(0);
+                                       else
+                                               pin_tface_uv(1);
+                               }
+                               else {
+                                       if(G.qual==LR_SHIFTKEY) {
+                                               toggle_blockhandler(sa, IMAGE_HANDLER_PREVIEW, 0);
+                                               scrarea_queue_winredraw(sa);
+                                       }
+                               }
                                break;
                        case RKEY:
                                if((G.qual==0) && is_uv_tface_editing_allowed()) {
@@ -4060,7 +4373,7 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        /* Events handled always (whether the draw tool is active or not) */
        switch (event) {
        case UI_BUT_EVENT:
-               do_imagebuts(val);      // drawimage.c
+               do_imagebuts(val);      /* drawimage.c */
                break;
        case MIDDLEMOUSE:
                if((G.qual==LR_CTRLKEY) || ((U.flag & USER_TWOBUTTONMOUSE) && (G.qual==(LR_ALTKEY|LR_CTRLKEY))))
@@ -4069,19 +4382,58 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        image_viewmove(0);
                break;
        case WHEELUPMOUSE: case WHEELDOWNMOUSE: case PADPLUSKEY: case PADMINUS:
-               image_viewzoom(event, 0);
-               scrarea_queue_winredraw(curarea);
+       case PAD1: case PAD2: case PAD4: case PAD8:
+               image_viewzoom(event, (G.qual & LR_SHIFTKEY)==0);
+               scrarea_queue_winredraw(sa);
                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);
+               if(G.qual==LR_ALTKEY) {
+                       new_image_sima();
+               }
+               else if(G.qual==0) {
+                       toggle_blockhandler(sa, IMAGE_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
+                       scrarea_queue_winredraw(sa);
                }
                break;
+       case OKEY:
+               if (G.qual & LR_ALTKEY)
+                       open_image_sima(G.qual & LR_CTRLKEY);
+               break;
+       case RKEY:
+               if(G.qual==LR_ALTKEY)
+                       reload_image_sima();
+               break;
+       case SKEY:
+               if(G.qual & LR_ALTKEY)
+                       save_image_sima();
+               break;
+       case ESCKEY:
+               if(sima->flag & SI_PREVSPACE) {
+                       /* only allow ESC once */
+                       sima->flag &= ~SI_PREVSPACE;
+                       
+                       sima= sa->spacedata.first;
+                       if(sima->next) {
+                               SpaceLink *sl;
+                               
+                               BLI_remlink(&sa->spacedata, sima);
+                               BLI_addtail(&sa->spacedata, sima);
+                               
+                               sl= sa->spacedata.first;
+                               
+                               newspace(sa, sl->spacetype);
+                       }
+               }
+               if(sima->flag & SI_FULLWINDOW) {
+                       sima->flag &= ~SI_FULLWINDOW;
+                       if(sa->full)
+                               area_fullscreen();
+               }
        }
 }
 
@@ -4096,6 +4448,7 @@ static void init_imagespace(ScrArea *sa)
        sima->spacetype= SPACE_IMAGE;
        sima->zoom= 1;
        sima->blockscale= 0.7;
+       sima->flag = SI_LOCALSTICKY;
 }
 
 
@@ -4140,7 +4493,12 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
+#ifdef WITH_VERSE
+                       /* evil hack due to verse */
+                       outliner_mouse_event(sa, event);
+#else
                        outliner_operation_menu(sa);
+#endif
                        break;
                        
                case AKEY:
@@ -4149,6 +4507,23 @@ static void winqreadoopsspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        else
                                outliner_toggle_visible(sa);
                        break;
+               case FKEY: 
+                       {
+                               /* search */
+                               int search_flags=0, again=0;
+                               
+                               /* CTRL=case sensitive, SHIFT=find again, ALT=complete */
+                               if (G.qual & LR_CTRLKEY) search_flags |= 1;
+                               if (G.qual & LR_ALTKEY) search_flags |= 8;
+                               if (G.qual & LR_SHIFTKEY) again = 1;
+                               
+                               outliner_find_panel(sa, again, search_flags);                           
+                       }
+                       break;
+               case XKEY:
+               case DELKEY:
+                       outliner_del(sa);
+                       break;
                case WKEY:
                        outliner_operation_menu(sa);
                        break;
@@ -4359,7 +4734,7 @@ void init_v2d_oops(ScrArea *sa, SpaceOops *soops)
        }
 }
 
-static void init_oopsspace(ScrArea *sa, int outliner)
+static void init_oopsspace(ScrArea *sa)
 {
        SpaceOops *soops;
        
@@ -4367,10 +4742,10 @@ static void init_oopsspace(ScrArea *sa, int outliner)
        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;
-       
+       /* new oops is default an outliner */
+       soops->type= SO_OUTLINER;
+               
        soops->spacetype= SPACE_OOPS;
-       soops->type= SO_OUTLINER;       // default starts new ones in outliner mode
        soops->blockscale= 0.7;
        init_v2d_oops(sa, soops);
 }
@@ -4549,7 +4924,7 @@ static void init_nodespace(ScrArea *sa)
 
 void newspace(ScrArea *sa, int type)
 {
-       int xtra= type & 256;   // hack to enforce outliner with hotkey from toets.c
+       int xtra= type & 256;   /* hack to enforce outliner with hotkey from toets.c */
        
        type &= ~256;
        
@@ -4598,7 +4973,7 @@ void newspace(ScrArea *sa, int type)
                                else if(type==SPACE_IMASEL)
                                        init_imaselspace(sa);
                                else if(type==SPACE_OOPS)
-                                       init_oopsspace(sa, xtra);
+                                       init_oopsspace(sa);
                                else if(type==SPACE_ACTION)
                                        init_actionspace(sa);
                                else if(type==SPACE_TEXT)
@@ -4687,15 +5062,20 @@ void freespacelist(ScrArea *sa)
                        }
                        if(vd->localvd) MEM_freeN(vd->localvd);
                        if(vd->clipbb) MEM_freeN(vd->clipbb);
+                       if(vd->depths) {
+                               if(vd->depths->depths) MEM_freeN(vd->depths->depths);
+                               MEM_freeN(vd->depths);
+                               vd->depths= NULL;
+                       }
+                       retopo_free_view_data(vd);
                        if(G.vd==vd) G.vd= NULL;
                        if(vd->ri) { 
-                               BIF_view3d_previewrender_free(sa);
-                               if (vd->ri->rect) MEM_freeN(vd->ri->rect);
-                               MEM_freeN(vd->ri);
+                               BIF_view3d_previewrender_free(vd);
                        }
                }
                else if(sl->spacetype==SPACE_OOPS) {
-                       free_oopspace((SpaceOops *)sl);
+                       SpaceOops *so= (SpaceOops *) sl;
+                       free_oopspace(so);
                }
                else if(sl->spacetype==SPACE_IMASEL) {
                        free_imasel((SpaceImaSel *)sl);
@@ -4719,6 +5099,8 @@ void freespacelist(ScrArea *sa)
                        SpaceImage *sima= (SpaceImage *)sl;
                        if(sima->cumap)
                                curvemapping_free(sima->cumap);
+                       if(sima->info_str)
+                               MEM_freeN(sima->info_str);
                }
                else if(sl->spacetype==SPACE_NODE) {
 /*                     SpaceNode *snode= (SpaceNode *)sl; */
@@ -4734,7 +5116,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
 
        duplicatelist(lb1, lb2);
        
-       /* lb1 is copy from lb2, from lb2 we free the file list */
+       /* lb1 is copy from lb2, from lb2 we free stuff, rely on event system to properly re-alloc */
        
        sl= lb2->first;
        while(sl) {
@@ -4743,6 +5125,10 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                        sfile->libfiledata= 0;
                        sfile->filelist= 0;
                }
+               else if(sl->spacetype==SPACE_VIEW3D) {
+                       BIF_view3d_previewrender_free((View3D *)sl);
+                       ((View3D*)sl)->depths= NULL;
+               }
                else if(sl->spacetype==SPACE_OOPS) {
                        SpaceOops *so= (SpaceOops *)sl;
                        so->oops.first= so->oops.last= NULL;
@@ -4756,15 +5142,6 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                        SpaceNode *snode= (SpaceNode *)sl;
                        snode->nodetree= NULL;
                }
-               /* __PINFAKE */
-/*             else if(sfile->spacetype==SPACE_ACTION) {
-                       SpaceAction *sa= (SpaceAction *)sfile;
-                       if (sa->flag & SACTION_PIN)
-                               if (sa->action)
-                                       sa->action->id.us++;
-
-               }
-*/             /* end PINFAKE */
 
                sl= sl->next;
        }
@@ -4796,6 +5173,8 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                        SpaceImage *sima= (SpaceImage *)sl;
                        if(sima->cumap)
                                sima->cumap= curvemapping_copy(sima->cumap);
+                       if(sima->info_str)
+                               sima->info_str= MEM_dupallocN(sima->info_str);
                }
                sl= sl->next;
        }
@@ -5023,6 +5402,11 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_winredraw(sa);
                                }
                                break;
+                       case RECALC_COMPOSITE:
+                               if(sa->spacetype==SPACE_NODE) {
+                                       addqueue(sa->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
+                               }
+                               break;
                        case REDRAWANIM:
                                if ELEM6(sa->spacetype, SPACE_IPO, SPACE_SOUND, SPACE_TIME, SPACE_NLA, SPACE_ACTION, SPACE_SEQ) {
                                        scrarea_queue_winredraw(sa);
@@ -5076,7 +5460,7 @@ void allspace(unsigned short event, short val)
 void force_draw(int header)
 {
        /* draws all areas that show something identical to curarea */
-       extern int afterqtest(short win, unsigned short evt);   //editscreen.c
+       extern int afterqtest(short win, unsigned short evt);   /*editscreen.c*/
        ScrArea *tempsa, *sa;
 
        scrarea_do_windraw(curarea);
@@ -5204,7 +5588,7 @@ SpaceType *spaceimage_get_type(void)
        
        if (!st) {
                st= spacetype_new("Image");
-               spacetype_set_winfuncs(st, drawimagespace, NULL, winqreadimagespace);
+               spacetype_set_winfuncs(st, drawimagespace, changeimagepace, winqreadimagespace);
        }
 
        return st;