2.5
[blender-staging.git] / source / blender / editors / screen / screen_ops.c
index e973e776c21217411d9d87971220cf6c5069f4d3..c991a63e762c4786c91deb67b52079e6c009e99b 100644 (file)
@@ -24,6 +24,8 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <math.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_arithb.h"
@@ -45,6 +47,7 @@
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_mesh.h"
 #include "BKE_multires.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
@@ -55,6 +58,7 @@
 
 #include "ED_util.h"
 #include "ED_screen.h"
+#include "ED_mesh.h"
 #include "ED_screen_types.h"
 
 #include "RE_pipeline.h"
 
 /* ************** Exported Poll tests ********************** */
 
+int ED_operator_regionactive(bContext *C)
+{
+       if(CTX_wm_window(C)==NULL) return 0;
+       if(CTX_wm_screen(C)==NULL) return 0;
+       if(CTX_wm_region(C)==NULL) return 0;
+       return 1;
+}
+
 int ED_operator_areaactive(bContext *C)
 {
        if(CTX_wm_window(C)==NULL) return 0;
@@ -124,11 +136,7 @@ int ED_operator_timeline_active(bContext *C)
 
 int ED_operator_outliner_active(bContext *C)
 {
-       if(ed_spacetype_test(C, SPACE_OOPS)) {
-               SpaceOops *so= (SpaceOops *)CTX_wm_space_data(C);
-               return (so->type == SO_OUTLINER);
-       }
-       return 0;
+       return ed_spacetype_test(C, SPACE_OUTLINER);
 }
 
 int ED_operator_file_active(bContext *C)
@@ -210,11 +218,14 @@ int ED_operator_uvedit(bContext *C)
        EditMesh *em= NULL;
 
        if(obedit && obedit->type==OB_MESH)
-               em= ((Mesh *)obedit->data)->edit_mesh;
+               em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
-    if(em && (em->faces.first) && (CustomData_has_layer(&em->fdata, CD_MTFACE)))
+       if(em && (em->faces.first) && (CustomData_has_layer(&em->fdata, CD_MTFACE))) {
+               BKE_mesh_end_editmesh(obedit->data, em);
                return 1;
+       }
 
+       BKE_mesh_end_editmesh(obedit->data, em);
        return 0;
 }
 
@@ -224,11 +235,14 @@ int ED_operator_uvmap(bContext *C)
        EditMesh *em= NULL;
 
        if(obedit && obedit->type==OB_MESH)
-               em= ((Mesh *)obedit->data)->edit_mesh;
+               em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
-    if(em && (em->faces.first))
+       if(em && (em->faces.first)) {
+               BKE_mesh_end_editmesh(obedit->data, em);
                return 1;
+       }
 
+       BKE_mesh_end_editmesh(obedit->data, em);
        return 0;
 }
 
@@ -238,9 +252,6 @@ int ED_operator_editsurfcurve(bContext *C)
        if(obedit && ELEM(obedit->type, OB_CURVE, OB_SURF))
                return NULL != ((Curve *)obedit->data)->editnurb;
        return 0;
-
-       // XXX this test was in many tools, still needed?
-       // if(v3d==0 || (v3d->lay & obedit->lay)==0 ) return 0;
 }
 
 
@@ -260,6 +271,14 @@ int ED_operator_editsurf(bContext *C)
        return 0;
 }
 
+int ED_operator_editfont(bContext *C)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       if(obedit && obedit->type==OB_FONT)
+               return NULL != ((Curve *)obedit->data)->editfont;
+       return 0;
+}
+
 /* *************************** action zone operator ************************** */
 
 /* operator state vars used:  
@@ -288,7 +307,7 @@ callbacks:
 typedef struct sActionzoneData {
        ScrArea *sa1, *sa2;
        AZone *az;
-       int x, y, gesture_dir;
+       int x, y, gesture_dir, modifier;
 } sActionzoneData;
 
 /* used by other operators too */
@@ -357,6 +376,8 @@ static void actionzone_apply(bContext *C, wmOperator *op)
 {
        wmEvent event;
        wmWindow *win= CTX_wm_window(C);
+       sActionzoneData *sad= op->customdata;
+       sad->modifier= RNA_int_get(op->ptr, "modifier");
        
        event= *(win->eventstate);      /* XXX huh huh? make api call */
        event.type= EVT_ACTIONZONE;
@@ -418,29 +439,144 @@ void SCREEN_OT_actionzone(wmOperatorType *ot)
        ot->modal= actionzone_modal;
        
        ot->poll= ED_operator_areaactive;
+       RNA_def_int(ot->srna, "modifier", 0, 0, 2, "modifier", "modifier state", 0, 2);
 }
 
+/* ************** swap area operator *********************************** */
 
-/* *********** Rip area operator ****************** */
+/* operator state vars used:  
+                                       sa1             start area
+                                       sa2             area to swap with
+
+       functions:
+
+       init()   set custom data for operator, based on actionzone event custom data
+
+       cancel()        cancel the operator
+
+       exit()  cleanup, send notifier
+
+       callbacks:
 
+       invoke() gets called on shift+lmb drag in actionzone
+            call init(), add handler
+
+       modal()  accept modal events while doing it
+
+*/
+
+typedef struct sAreaSwapData {
+       ScrArea *sa1, *sa2;
+} sAreaSwapData;
+
+static int area_swap_init(bContext *C, wmOperator *op, wmEvent *event)
+{
+       sAreaSwapData *sd= NULL;
+       sActionzoneData *sad= event->customdata;
+
+       if(sad==NULL || sad->sa1==NULL)
+                                       return 0;
+       
+       sd= MEM_callocN(sizeof(sAreaSwapData), "sAreaSwapData");
+       sd->sa1= sad->sa1;
+       sd->sa2= sad->sa2;
+       op->customdata= sd;
+
+       return 1;
+}
+
+
+static void area_swap_exit(bContext *C, wmOperator *op)
+{
+       if(op->customdata)
+               MEM_freeN(op->customdata);
+       op->customdata= NULL;
+}
+
+static int area_swap_cancel(bContext *C, wmOperator *op)
+{
+       area_swap_exit(C, op);
+       return OPERATOR_CANCELLED;
+}
+
+static int area_swap_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+
+       if(!area_swap_init(C, op, event))
+               return OPERATOR_PASS_THROUGH;
+
+       /* add modal handler */
+       WM_cursor_modal(CTX_wm_window(C), BC_SWAPAREA_CURSOR);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+       
+       return OPERATOR_RUNNING_MODAL;
+
+}
+
+static int area_swap_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       sActionzoneData *sad= op->customdata;
+
+       switch(event->type) {
+               case MOUSEMOVE:
+                       /* second area, for join */
+                       sad->sa2= screen_areahascursor(CTX_wm_screen(C), event->x, event->y);
+                       break;
+               case LEFTMOUSE: /* release LMB */
+                       if(event->val==0) {
+                               if(sad->sa1 == sad->sa2) {
+
+                                       return area_swap_cancel(C, op);
+                               }
+                               ED_area_swapspace(C, sad->sa1, sad->sa2);
+
+                               area_swap_exit(C, op);
+
+                               WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+
+                               return OPERATOR_FINISHED;
+                       }
+                       break;
+
+               case ESCKEY:
+                       return area_swap_cancel(C, op);
+       }
+       return OPERATOR_RUNNING_MODAL;
+}
+
+void SCREEN_OT_area_swap(wmOperatorType *ot)
+{
+       ot->name= "Swap areas";
+       ot->idname= "SCREEN_OT_area_swap";
+
+       ot->invoke= area_swap_invoke;
+       ot->modal= area_swap_modal;
+       ot->poll= ED_operator_areaactive;
+}
+
+/* *********** Duplicate area as new window operator ****************** */
 
 /* operator callback */
-/* (ton) removed attempt to merge ripped area with another, don't think this is desired functionality.
-conventions: 'atomic' and 'dont think for user' :) */
-static int screen_area_rip_op(bContext *C, wmOperator *op)
+static int area_dupli_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        wmWindow *newwin, *win;
        bScreen *newsc, *sc;
        ScrArea *sa;
        rcti rect;
+       sActionzoneData *sad= event->customdata;
+
+       if(sad==NULL)
+               return OPERATOR_PASS_THROUGH;
        
        win= CTX_wm_window(C);
        sc= CTX_wm_screen(C);
-       sa= CTX_wm_area(C);
+       sa= sad->sa1;
 
        /*  poll() checks area context, but we don't accept full-area windows */
-       if(sc->full != SCREENNORMAL) 
+       if(sc->full != SCREENNORMAL) {
+               actionzone_exit(C, op);
                return OPERATOR_CANCELLED;
+       }
        
        /* adds window to WM */
        rect= sa->totrct;
@@ -456,17 +592,18 @@ static int screen_area_rip_op(bContext *C, wmOperator *op)
        
        /* screen, areas init */
        WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+
+       actionzone_exit(C, op);
        
        return OPERATOR_FINISHED;
 }
 
-void SCREEN_OT_area_rip(wmOperatorType *ot)
+void SCREEN_OT_area_dupli(wmOperatorType *ot)
 {
-       ot->name= "Rip Area into New Window";
-       ot->idname= "SCREEN_OT_area_rip";
+       ot->name= "Duplicate Area into New Window";
+       ot->idname= "SCREEN_OT_area_dupli";
        
-       ot->invoke= WM_operator_confirm;
-       ot->exec= screen_area_rip_op;
+       ot->invoke= area_dupli_invoke;
        ot->poll= ED_operator_areaactive;
 }
 
@@ -881,6 +1018,10 @@ static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event)
        if(event->type==EVT_ACTIONZONE) {
                sActionzoneData *sad= event->customdata;
                int dir;
+
+               if(sad->modifier>0) {
+                       return OPERATOR_PASS_THROUGH;
+               }
                
                /* verify *sad itself */
                if(sad==NULL || sad->sa1==NULL || sad->az==NULL)
@@ -1040,7 +1181,7 @@ void SCREEN_OT_frame_offset(wmOperatorType *ot)
        ot->exec= frame_offset_exec;
 
        ot->poll= ED_operator_screenactive;
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= 0;
 
        /* rna */
        RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
@@ -1118,7 +1259,7 @@ void SCREEN_OT_screen_full_area(wmOperatorType *ot)
        
        ot->exec= screen_full_area_exec;
        ot->poll= ED_operator_areaactive;
-       ot->flag= OPTYPE_REGISTER;
+       ot->flag= 0;
 
 }
 
@@ -1244,6 +1385,10 @@ static int area_join_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
        if(event->type==EVT_ACTIONZONE) {
                sActionzoneData *sad= event->customdata;
+
+               if(sad->modifier>0) {
+                       return OPERATOR_PASS_THROUGH;
+               }
                
                /* verify *sad itself */
                if(sad==NULL || sad->sa1==NULL || sad->sa2==NULL)
@@ -1428,19 +1573,21 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
        wmOperator *lastop;
-       uiMenuItem *head;
+       uiPopupMenu *pup;
+       uiLayout *layout;
        int items, i;
        
        items= BLI_countlist(&wm->operators);
        if(items==0)
                return OPERATOR_CANCELLED;
        
-       head= uiPupMenuBegin(op->type->name, 0);
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
 
        for (i=items-1, lastop= wm->operators.last; lastop; lastop= lastop->prev, i--)
-               uiMenuItemIntO(head, lastop->type->name, 0, op->type->idname, "index", i);
+               uiItemIntO(layout, lastop->type->name, 0, op->type->idname, "index", i);
 
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        return OPERATOR_CANCELLED;
 }
@@ -1478,71 +1625,18 @@ void SCREEN_OT_repeat_history(wmOperatorType *ot)
 
 /* ********************** redo operator ***************************** */
 
-static int redo_last_exec(bContext *C, wmOperator *op)
-{
-#if 0
-       /* XXX context is not correct after popup menu */
-       wmOperator *lastop= CTX_wm_manager(C)->operators.last;
-       
-       if(lastop) {
-               ED_undo_pop(C);
-               WM_operator_repeat(C, lastop);
-       }
-#endif
-       
-       return OPERATOR_CANCELLED;
-}
-
-static void redo_last_cb(bContext *C, void *arg1, void *arg2)
-{
-       wmOperator *lastop= CTX_wm_manager(C)->operators.last;
-       
-       if(lastop) {
-               ED_undo_pop(C);
-               WM_operator_repeat(C, lastop);
-       }
-       
-}
-
-static uiBlock *ui_block_create_redo_last(bContext *C, ARegion *ar, void *arg_op)
-{
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *op= arg_op;
-       PointerRNA ptr;
-       uiBlock *block;
-       int height;
-       
-       block= uiBeginBlock(C, ar, "redo_last_popup", UI_EMBOSS, UI_HELV);
-       uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
-       uiBlockSetFunc(block, redo_last_cb, NULL, NULL);
-
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       height= uiDefAutoButsRNA(block, &ptr);
-
-       uiPopupBoundsBlock(block, 4.0f, 0, 0);
-       uiEndBlock(C, block);
-
-       return block;
-}
-
 static int redo_last_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *lastop= wm->operators.last;
-
-       if(!lastop)
-               return OPERATOR_CANCELLED;
+       wmOperator *lastop;
 
        /* only for operators that are registered and did an undo push */
-       if(!(lastop->type->flag & OPTYPE_REGISTER) || !(lastop->type->flag & OPTYPE_UNDO))
-               return OPERATOR_CANCELLED;
-
-       uiPupBlockO(C, ui_block_create_redo_last, lastop, op->type->idname, WM_OP_EXEC_DEFAULT);
+       for(lastop= wm->operators.last; lastop; lastop= lastop->prev)
+               if((lastop->type->flag & OPTYPE_REGISTER) && (lastop->type->flag & OPTYPE_UNDO))
+                       break;
+       
+       if(lastop)
+               WM_operator_redo_popup(C, lastop);
 
        return OPERATOR_CANCELLED;
 }
@@ -1555,7 +1649,6 @@ void SCREEN_OT_redo_last(wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= redo_last_invoke;
-       ot->exec= redo_last_exec;
        
        ot->poll= ED_operator_screenactive;
 }
@@ -1625,6 +1718,7 @@ static int region_foursplit_exec(bContext *C, wmOperator *op)
                if(sa->spacetype==SPACE_VIEW3D) {
                        RegionView3D *rv3d= ar->regiondata;
                        rv3d->viewlock= 0;
+                       rv3d->rflag &= ~RV3D_CLIPPING;
                }
                
                for(ar= sa->regionbase.first; ar; ar= arn) {
@@ -1721,28 +1815,28 @@ static void testfunc(bContext *C, void *argv, int arg)
        printf("arg %d\n", arg);
 }
 
-static void newlevel1(bContext *C, uiMenuItem *head, void *arg)
+static void newlevel1(bContext *C, uiLayout *layout, void *arg)
 {
-       uiMenuFunc(head, testfunc, NULL);
+       uiLayoutFunc(layout, testfunc, NULL);
        
-       uiMenuItemVal(head, "First", ICON_PROP_ON, 1);
-       uiMenuItemVal(head, "Second", ICON_PROP_CON, 2);
-       uiMenuItemVal(head, "Third", ICON_SMOOTHCURVE, 3);
-       uiMenuItemVal(head, "Fourth", ICON_SHARPCURVE, 4);      
+       uiItemV(layout, "First", ICON_PROP_ON, 1);
+       uiItemV(layout, "Second", ICON_PROP_CON, 2);
+       uiItemV(layout, "Third", ICON_SMOOTHCURVE, 3);
+       uiItemV(layout, "Fourth", ICON_SHARPCURVE, 4);  
 }
 
 static int testing123(bContext *C, wmOperator *op, wmEvent *event)
 {
-       uiMenuItem *head= uiPupMenuBegin("Hello world", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Hello world", 0);
+       uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiMenuContext(head, WM_OP_EXEC_DEFAULT);
-       uiMenuItemO(head, ICON_PROP_ON, "SCREEN_OT_region_flip");
-       uiMenuItemO(head, ICON_PROP_CON, "SCREEN_OT_screen_full_area");
-       uiMenuItemO(head, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit");
-       uiMenuLevel(head, "Submenu", newlevel1);
-       uiMenuItemO(head, ICON_PROP_ON, "SCREEN_OT_area_rip");
+       uiLayoutContext(layout, WM_OP_EXEC_DEFAULT);
+       uiItemO(layout, NULL, ICON_PROP_ON, "SCREEN_OT_region_flip");
+       uiItemO(layout, NULL, ICON_PROP_CON, "SCREEN_OT_screen_full_area");
+       uiItemO(layout, NULL, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit");
+       uiItemMenuF(layout, "Submenu", 0, newlevel1);
        
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        /* this operator is only for a menu, not used further */
        return OPERATOR_CANCELLED;
@@ -1765,16 +1859,71 @@ void SCREEN_OT_region_flip(wmOperatorType *ot)
 
 }
 
-/* ****************** anim player, typically with timer ***************** */
+/* ****************** anim player, with timer ***************** */
 
-static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
+static int match_region_with_redraws(int spacetype, int regiontype, int redraws)
+{
+       if(regiontype==RGN_TYPE_WINDOW) {
+
+               switch (spacetype) {
+                       case SPACE_VIEW3D:
+                               if(redraws & TIME_ALL_3D_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_IPO:
+                       case SPACE_ACTION:
+                       case SPACE_NLA:
+                               if(redraws & TIME_ALL_ANIM_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_TIME:
+                               /* if only 1 window or 3d windows, we do timeline too */
+                               if(redraws & (TIME_ALL_ANIM_WIN|TIME_REGION|TIME_ALL_3D_WIN))
+                                       return 1;
+                               break;
+                       case SPACE_BUTS:
+                               if(redraws & TIME_ALL_BUTS_WIN)
+                                       return 1;
+                               break;
+                       case SPACE_SEQ:
+                               if(redraws & (TIME_SEQ|TIME_ALL_ANIM_WIN))
+                                       return 1;
+                               break;
+                       case SPACE_IMAGE:
+                               if(redraws & TIME_ALL_IMAGE_WIN)
+                                       return 1;
+                               break;
+                               
+               }
+       }
+       else if(regiontype==RGN_TYPE_UI) {
+               if(redraws & TIME_ALL_BUTS_WIN)
+                       return 1;
+       }
+       else if(regiontype==RGN_TYPE_HEADER) {
+               if(spacetype==SPACE_TIME)
+                       return 1;
+       }
+       return 0;
+}
+
+static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
 {
        bScreen *screen= CTX_wm_screen(C);
        
        if(screen->animtimer==event->customdata) {
                Scene *scene= CTX_data_scene(C);
+               wmTimer *wt= screen->animtimer;
+               ScreenAnimData *sad= wt->customdata;
+               ScrArea *sa;
                
-               scene->r.cfra++;
+               if(scene->audio.flag & AUDIO_SYNC) {
+                       int step = floor(wt->duration * FPS);
+                       scene->r.cfra += step;
+                       wt->duration -= ((float)step)/FPS;
+               }
+               else
+                       scene->r.cfra++;
                
                if (scene->r.psfra) {
                        if(scene->r.cfra > scene->r.pefra)
@@ -1785,13 +1934,65 @@ static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
                                scene->r.cfra= scene->r.sfra;
                }
 
-               WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+               /* since we follow drawflags, we can't send notifier but tag regions ourselves */
+               ED_update_for_newframe(C, 1);
+               
+               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                       ARegion *ar;
+                       for(ar= sa->regionbase.first; ar; ar= ar->next) {
+                               if(ar==sad->ar)
+                                       ED_region_tag_redraw(ar);
+                               else
+                                       if(match_region_with_redraws(sa->spacetype, ar->regiontype, sad->redraws))
+                                               ED_region_tag_redraw(ar);
+                       }
+               }
+               
+               //WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
                
                return OPERATOR_FINISHED;
        }
        return OPERATOR_PASS_THROUGH;
 }
 
+static void SCREEN_OT_animation_step(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Animation Step";
+       ot->idname= "SCREEN_OT_animation_step";
+       
+       /* api callbacks */
+       ot->invoke= screen_animation_step;
+       
+       ot->poll= ED_operator_screenactive;
+       
+}
+
+/* ****************** anim player, starts or ends timer ***************** */
+
+/* toggle operator */
+static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event)
+{
+       bScreen *screen= CTX_wm_screen(C);
+       
+       if(screen->animtimer) {
+               ED_screen_animation_timer(C, 0, 0);
+       }
+       else {
+               /* todo: RNA properties to define play types */
+               ED_screen_animation_timer(C, TIME_REGION|TIME_ALL_3D_WIN, 1);
+               
+               if(screen->animtimer) {
+                       wmTimer *wt= screen->animtimer;
+                       ScreenAnimData *sad= wt->customdata;
+                       
+                       sad->ar= CTX_wm_region(C);
+               }
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
 void SCREEN_OT_animation_play(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1803,6 +2004,7 @@ void SCREEN_OT_animation_play(wmOperatorType *ot)
        
        ot->poll= ED_operator_screenactive;
        
+       
 }
 
 /* ************** border select operator (template) ***************************** */
@@ -1878,7 +2080,7 @@ static ScrArea *biggest_non_image_area(bContext *C)
        short foundwin= 0;
        
        for(sa= sc->areabase.first; sa; sa= sa->next) {
-               if(sa->winx > 10 && sa->winy > 10) {
+               if(sa->winx > 30 && sa->winy > 30) {
                        size= sa->winx*sa->winy;
                        if(sa->spacetype == SPACE_BUTS) {
                                if(foundwin == 0 && size > bwmaxsize) {
@@ -2130,6 +2332,22 @@ static int render_breakjob(void *rjv)
        return 0;
 }
 
+/* catch esc */
+static int screen_render_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       /* no running blender, remove handler and pass through */
+       if(0==WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
+          return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH;
+       
+       /* running render */
+       switch (event->type) {
+               case ESCKEY:
+                       return OPERATOR_RUNNING_MODAL;
+                       break;
+       }
+       return OPERATOR_PASS_THROUGH;
+}
+
 /* using context, starts job */
 static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
@@ -2194,7 +2412,10 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
        WM_cursor_wait(0);
        WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, scene);
 
-       return OPERATOR_FINISHED;
+       /* add modal handler for ESC */
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+       
+       return OPERATOR_RUNNING_MODAL;
 }
 
 
@@ -2207,6 +2428,7 @@ void SCREEN_OT_render(wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= screen_render_invoke;
+       ot->modal= screen_render_modal;
        ot->exec= screen_render_exec;
        
        ot->poll= ED_operator_screenactive;
@@ -2224,12 +2446,18 @@ static int render_view_cancel_exec(bContext *C, wmOperator *unused)
        
        if(sima->flag & SI_PREVSPACE) {
                sima->flag &= ~SI_PREVSPACE;
-               ED_area_prevspace(C);
+               
+               if(sima->flag & SI_FULLWINDOW) {
+                       sima->flag &= ~SI_FULLWINDOW;
+                       ED_screen_full_prevspace(C);
+               }
+               else
+                       ED_area_prevspace(C);
        }
        else if(sima->flag & SI_FULLWINDOW) {
                sima->flag &= ~SI_FULLWINDOW;
-               ED_screen_full_prevspace(C);
-       }
+               ed_screen_fullarea(C, sa);
+       }               
        
        return OPERATOR_FINISHED;
 }
@@ -2261,7 +2489,8 @@ void ED_operatortypes_screen(void)
        WM_operatortype_append(SCREEN_OT_area_move);
        WM_operatortype_append(SCREEN_OT_area_split);
        WM_operatortype_append(SCREEN_OT_area_join);
-       WM_operatortype_append(SCREEN_OT_area_rip);
+       WM_operatortype_append(SCREEN_OT_area_dupli);
+       WM_operatortype_append(SCREEN_OT_area_swap);
        WM_operatortype_append(SCREEN_OT_region_split);
        WM_operatortype_append(SCREEN_OT_region_foursplit);
        WM_operatortype_append(SCREEN_OT_region_flip);
@@ -2272,6 +2501,7 @@ void ED_operatortypes_screen(void)
        
        /*frame changes*/
        WM_operatortype_append(SCREEN_OT_frame_offset);
+       WM_operatortype_append(SCREEN_OT_animation_step);
        WM_operatortype_append(SCREEN_OT_animation_play);
        
        /* render */
@@ -2290,15 +2520,18 @@ void ED_keymap_screen(wmWindowManager *wm)
        ListBase *keymap= WM_keymap_listbase(wm, "Screen", 0, 0);
        
        /* standard timers */
-       WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", TIMER0, KM_ANY, KM_ANY, 0);
+       WM_keymap_add_item(keymap, "SCREEN_OT_animation_step", TIMER0, KM_ANY, KM_ANY, 0);
        
-       WM_keymap_verify_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, 0, 0);
+       RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, 0, 0)->ptr, "modifier", 0);
+       RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "modifier", 1);
+       RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_actionzone", LEFTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "modifier", 2);
        
        /* screen tools */
        WM_keymap_verify_item(keymap, "SCREEN_OT_area_move", LEFTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "SCREEN_OT_area_split", EVT_ACTIONZONE, 0, 0, 0);
        WM_keymap_verify_item(keymap, "SCREEN_OT_area_join", EVT_ACTIONZONE, 0, 0, 0);
-       WM_keymap_verify_item(keymap, "SCREEN_OT_area_rip", RKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "SCREEN_OT_area_dupli", EVT_ACTIONZONE, 0, KM_SHIFT, 0);
+       WM_keymap_verify_item(keymap, "SCREEN_OT_area_swap", EVT_ACTIONZONE, 0, KM_ALT, 0);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_screen_set", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_screen_set", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1);
        WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", UPARROWKEY, KM_PRESS, KM_CTRL, 0);
@@ -2315,6 +2548,9 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "SCREEN_OT_region_flip", F5KEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0);
+       
+       RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", F7KEY, KM_PRESS, 0, 0)->ptr, "filename", "test.py");
+       WM_keymap_verify_item(keymap, "SCRIPT_OT_python_run_ui_scripts", F8KEY, KM_PRESS, 0, 0);
 
        /* files */
        WM_keymap_add_item(keymap, "FILE_OT_exec", RETKEY, KM_PRESS, 0, 0);
@@ -2330,12 +2566,13 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "SCREEN_OT_render_view_cancel", ESCKEY, KM_PRESS, 0, 0);
        
-       /* frame offsets */
+       /* frame offsets & play */
        keymap= WM_keymap_listbase(wm, "Frames", 0, 0);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 10);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -10);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -1);
        RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
+       WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT, 0);
        
 }