Long waited feature: Render Baking
[blender.git] / source / blender / src / space.c
index c95c8403208e143c0d46d9a06e12c3020c34a24f..078c6f6a8864d67f0ed338607cf05a99e04c6f0b 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
+#include "BLI_gsqueue.h"
 #include "BLI_linklist.h"
 
 #include "DNA_action_types.h"
@@ -61,6 +62,8 @@
 #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_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 "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. */
 
@@ -182,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;
@@ -219,7 +225,7 @@ 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;
@@ -428,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);
        }
@@ -609,13 +615,34 @@ static void select_same_group(Object *ob) /* Select objects in the same group as
        if (!group || !ob)
                return;
        
-       for (base= FIRSTBASE; base; base= base->next)
-               if (object_in_group(base->object, group)) {
+       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 */
 {
@@ -663,6 +690,7 @@ void select_object_grouped(short nr)
        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);
        
        
        
@@ -681,13 +709,14 @@ static void select_object_grouped_menu(void)
 
        /* make menu string */
        
-       str= MEM_mallocN(180, "groupmenu");
+       str= MEM_mallocN(512, "groupmenu");
        strcpy(str, "Select Grouped%t|Children%x1|"
                    "Immediate Children%x2|Parent%x3|"
                    "Siblings (Shared Parent)%x4|"
                    "Objects of Same Type%x5|"
                                "Objects on Shared Layers%x6|"
-                "Objects in Same Group%x7|");
+                "Objects in Same Group%x7|"
+                "Object Hooks%x8|");
 
        /* here we go */
        
@@ -753,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);
@@ -770,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();
                        }
@@ -793,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) {
@@ -815,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();
@@ -833,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;
        
@@ -845,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;
@@ -858,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))
@@ -1002,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:
@@ -1047,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 */
@@ -1119,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) )
@@ -1153,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) )
@@ -1212,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();
                                }
@@ -1227,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);
@@ -1248,16 +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...
+                                               /* 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;
@@ -1288,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)) {
@@ -1310,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;
+                                               }
                                        }
                                }
                                
@@ -1465,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();
@@ -1627,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)) {
@@ -1640,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")) {
@@ -1660,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))
@@ -1685,6 +1775,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                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)) {
                        start_game();
                                }
@@ -1732,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) {
@@ -1774,7 +1871,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                }
                                        }
                                        
-                                       if(okee("Clear size")) {
+                                       if(okee("Clear scale")) {
                                                clear_object('s');
                                        }
                                }
@@ -1835,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();
                                        }
@@ -1895,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:
@@ -1979,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:
@@ -2002,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;
@@ -2012,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;
@@ -2066,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;
 }
 
 
@@ -2081,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;
@@ -2119,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 {
@@ -2131,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);
@@ -2217,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:
@@ -2228,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();
@@ -2312,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};
@@ -2325,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++;
@@ -2389,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);
        
@@ -2413,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, "");
@@ -2704,7 +2845,11 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                        &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,
@@ -2833,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:",
@@ -2971,6 +3116,18 @@ 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, "");
@@ -3094,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, "");
@@ -3268,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) {
@@ -3282,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) {
@@ -3422,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);
                                
@@ -3486,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;
@@ -3503,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;
@@ -3530,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) 
@@ -3566,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) {
@@ -3600,7 +3758,7 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        View2D *v2d= &sseq->v2d;
        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;
@@ -3652,7 +3810,8 @@ 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:
@@ -3802,6 +3961,9 @@ 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();
@@ -3881,7 +4043,7 @@ static void changeactionspace(ScrArea *sa, void *spacedata)
        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); */
 }
 
 
@@ -3975,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");
@@ -4041,13 +4203,13 @@ static void changeimagepace(ScrArea *sa, void *spacedata)
 
 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) {
@@ -4057,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:
-                               toggle_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW);
-                               scrarea_queue_winredraw(curarea);
+                       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);
@@ -4149,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)) {
@@ -4167,8 +4329,8 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else {
                                        if(G.qual==LR_SHIFTKEY) {
-                                               toggle_blockhandler(curarea, IMAGE_HANDLER_PREVIEW, 0);
-                                               scrarea_queue_winredraw(curarea);
+                                               toggle_blockhandler(sa, IMAGE_HANDLER_PREVIEW, 0);
+                                               scrarea_queue_winredraw(sa);
                                        }
                                }
                                break;
@@ -4183,8 +4345,6 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        initTransform(TFM_RESIZE, CTX_NONE);
                                        Transform();
                                }
-                               else if((G.qual==LR_SHIFTKEY) && is_uv_tface_editing_allowed())
-                                       smooth_area_tface_uv();
                                break;
                        case VKEY:
                                if((G.qual==0))
@@ -4213,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))))
@@ -4222,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();
+               }
        }
 }
 
@@ -4294,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:
@@ -4303,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;
@@ -4513,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;
        
@@ -4521,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);
 }
@@ -4703,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;
        
@@ -4752,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)
@@ -4841,13 +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(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);
@@ -4871,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; */
@@ -4897,6 +5127,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                }
                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;
@@ -4942,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;
        }
@@ -5227,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);