2.5 audio cleanup:
[blender.git] / source / blender / editors / screen / screen_edit.c
index 4c255b8362c0eed7a171a71f51b91d863146c2fb..5519b2609a1494dda08edc354fee7278d5fcafa9 100644 (file)
 #include "MEM_guardedalloc.h"
 
 #include "DNA_vec_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 #include "BKE_screen.h"
+#include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "ED_area.h"
 #include "ED_screen.h"
 #include "ED_screen_types.h"
 
+/* XXX actually should be not here... solve later */
 #include "wm_subwindow.h"
 
 #include "screen_intern.h"     /* own module include */
 
-/* ******************* gesture manager ******************* */
-void ed_gesture_draw_rect(wmWindow *win, wmGesture *gt)
-{
-       wmGestureRect *rect= (wmGestureRect *)gt;
-       sdrawbox(rect->x1, rect->y1, rect->x2, rect->y2);
-}
-
-void ed_gesture_update(wmWindow *win)
-{
-       wmGesture *gt= (wmGesture *)win->gesture.first;
-
-       while(gt) {
-               if(gt->type==GESTURE_RECT)
-                       ed_gesture_draw_rect(win, gt);
-               gt= gt->next;
-       }
-}
 
 /* ******************* screen vert, edge, area managing *********************** */
 
@@ -107,7 +96,7 @@ static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
 }
 
 
-static ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
+ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
 {
        ScrEdge *se;
        
@@ -119,170 +108,7 @@ static ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
        return NULL;
 }
 
-static ScrArea *screen_areahascursor(bScreen *scr, int x, int y)
-{
-       ScrArea *sa= NULL;
-       sa= scr->areabase.first;
-       while(sa) {
-               if(BLI_in_rcti(&sa->totrct, x, y)) break;
-               sa= sa->next;
-       }
-
-       return sa;
-}
-
-/* *************************** action zone operator ************************** */
-
-/* operator state vars used:  
-               none
-
-functions:
-
-       apply() set actionzone event
-
-       exit()  free customdata
-
-callbacks:
-
-       exec()  never used
-
-       invoke() check if in zone  
-                       add customdata, put mouseco and area in it
-                       add modal handler
-
-       modal() accept modal events while doing it
-                       call apply() with gesture info, active window, nonactive window
-                       call exit() and remove handler when LMB confirm
-
-*/
-
-typedef struct sActionzoneData {
-       ScrArea *sa1, *sa2;
-       AZone *az;
-       int x, y, gesture_dir;
-} sActionzoneData;
-
-
-static AZone *is_in_area_actionzone(ScrArea *sa, int x, int y)
-{
-       AZone *az= NULL;
-       int i= 0;
-       
-       for(az= sa->actionzones.first, i= 0; az; az= az->next, i++) {
-               if(az && az->type == AZONE_TRI) {
-                       if(IsPointInTri2DInts(az->x1, az->y1, az->x2, az->y2, x, y)) 
-                               break;
-               }
-               if(az->type == AZONE_QUAD) {
-                       if(az->x1 < x && x < az->x2 && az->y1 < y && y < az->y2) 
-                               break;
-               }
-       }
-       
-       return az;
-}
-
-static int actionzone_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       AZone *az= is_in_area_actionzone(C->area, event->x, event->y);
-       sActionzoneData *sad;
-       
-       /* quick escape */
-       if(az==NULL)
-               return OPERATOR_PASS_THROUGH;
-       
-       /* ok we do the actionzone */
-       sad= op->customdata= MEM_callocN(sizeof(sActionzoneData), "sActionzoneData");
-       sad->sa1= C->area;
-       sad->az= az;
-       sad->x= event->x; sad->y= event->y;
-       
-       /* add modal handler */
-       WM_event_add_modal_handler(&C->window->handlers, op);
-       
-       return OPERATOR_RUNNING_MODAL;
-}
-
-static void actionzone_exit(bContext *C, wmOperator *op)
-{
-       if(op->customdata)
-               MEM_freeN(op->customdata);
-       op->customdata= NULL;
-}
-
-/* send EVT_ACTIONZONE event */
-static void actionzone_apply(bContext *C, wmOperator *op)
-{
-       wmEvent event;
-       
-       event= *(C->window->eventstate);        /* XXX huh huh? make api call */
-       event.type= EVT_ACTIONZONE;
-       event.customdata= op->customdata;
-       event.customdatafree= TRUE;
-       op->customdata= NULL;
-       
-       wm_event_add(C->window, &event);
-}
-
-static int actionzone_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
-       sActionzoneData *sad= op->customdata;
-       int deltax, deltay;
-
-       switch(event->type) {
-               case MOUSEMOVE:
-                       /* calculate gesture direction */
-                       deltax= (event->x - sad->x);
-                       deltay= (event->y - sad->y);
-                       
-                       if(deltay > ABS(deltax))
-                               sad->gesture_dir= AZONE_N;
-                       else if(deltax > ABS(deltay))
-                               sad->gesture_dir= AZONE_E;
-                       else if(deltay < -ABS(deltax))
-                               sad->gesture_dir= AZONE_S;
-                       else
-                               sad->gesture_dir= AZONE_W;
-                       
-                       /* gesture is large enough? */
-                       if(ABS(deltax) > 12 || ABS(deltay) > 12) {
-                               
-                               /* second area, for join */
-                               sad->sa2= screen_areahascursor(C->screen, event->x, event->y);
-                               /* apply sends event */
-                               actionzone_apply(C, op);
-                               actionzone_exit(C, op);
-                               
-                               WM_event_remove_modal_handler(&C->window->handlers, op);
-                               
-                               return OPERATOR_FINISHED;
-                       }
-                       break;
-               case ESCKEY:
-               case LEFTMOUSE:
-                       actionzone_exit(C, op);
-                       WM_event_remove_modal_handler(&C->window->handlers, op);
-                       return OPERATOR_CANCELLED;
-       }
-       
-       return OPERATOR_RUNNING_MODAL;
-}
-
-void ED_SCR_OT_actionzone(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Handle area action zones";
-       ot->idname= "ED_SCR_OT_actionzone";
-       
-       ot->invoke= actionzone_invoke;
-       ot->modal= actionzone_modal;
-       
-       ot->poll= ED_operator_areaactive;
-}
-
-/* ************************************** */
-
-static void removedouble_scrverts(bScreen *sc)
+void removedouble_scrverts(bScreen *sc)
 {
        ScrVert *v1, *verg;
        ScrEdge *se;
@@ -336,7 +162,7 @@ static void removedouble_scrverts(bScreen *sc)
 
 }
 
-static void removenotused_scrverts(bScreen *sc)
+void removenotused_scrverts(bScreen *sc)
 {
        ScrVert *sv, *svn;
        ScrEdge *se;
@@ -362,7 +188,7 @@ static void removenotused_scrverts(bScreen *sc)
        }
 }
 
-static void removedouble_scredges(bScreen *sc)
+void removedouble_scredges(bScreen *sc)
 {
        ScrEdge *verg, *se, *sn;
        
@@ -382,7 +208,7 @@ static void removedouble_scredges(bScreen *sc)
        }
 }
 
-static void removenotused_scredges(bScreen *sc)
+void removenotused_scredges(bScreen *sc)
 {
        ScrEdge *se, *sen;
        ScrArea *sa;
@@ -418,12 +244,12 @@ static void removenotused_scredges(bScreen *sc)
        }
 }
 
-static int scredge_is_horizontal(ScrEdge *se)
+int scredge_is_horizontal(ScrEdge *se)
 {
        return (se->v1->vec.y == se->v2->vec.y);
 }
 
-static ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
+ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
 {
        ScrEdge *se;
        
@@ -449,48 +275,7 @@ static ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
        return NULL;
 }
 
-/* danger: is used while areamove! */
-static void select_connected_scredge(bScreen *sc, ScrEdge *edge)
-{
-       ScrEdge *se;
-       ScrVert *sv;
-       int oneselected;
-       char dir;
-       
-       /* select connected, only in the right direction */
-       /* 'dir' is the direction of EDGE */
-       
-       if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
-       else dir= 'h';
-       
-       sv= sc->vertbase.first;
-       while(sv) {
-               sv->flag = 0;
-               sv= sv->next;
-       }
-       
-       edge->v1->flag= 1;
-       edge->v2->flag= 1;
-       
-       oneselected= 1;
-       while(oneselected) {
-               se= sc->edgebase.first;
-               oneselected= 0;
-               while(se) {
-                       if(se->v1->flag + se->v2->flag==1) {
-                               if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
-                                       se->v1->flag= se->v2->flag= 1;
-                                       oneselected= 1;
-                               }
-                               if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
-                                       se->v1->flag= se->v2->flag= 1;
-                                       oneselected= 1;
-                               }
-                       }
-                       se= se->next;
-               }
-       }
-}
+
 
 /* adds no space data */
 static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
@@ -501,38 +286,134 @@ static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v
        sa->v3= v3;
        sa->v4= v4;
        sa->headertype= headertype;
-       sa->spacetype= spacetype;
+       sa->spacetype= sa->butspacetype= spacetype;
        
        BLI_addtail(&sc->areabase, sa);
        
        return sa;
 }
 
-static void screen_delarea(bScreen *sc, ScrArea *sa)
+static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
 {
-       /* XXX need context to cancel operators ED_area_exit(C, sa); */
+       
+       ED_area_exit(C, sa);
+       
        BKE_screen_area_free(sa);
+       
        BLI_remlink(&sc->areabase, sa);
        MEM_freeN(sa);
 }
 
-/* Helper function to join 2 areas, it has a return value, 0=failed 1=success
- *     used by the split, join and rip operators
- */
-int screen_join_areas(bScreen *scr, ScrArea *sa1, ScrArea *sa2);
+/* return 0: no split possible */
+/* else return (integer) screencoordinate split point */
+static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
+{
+       short x, y;
+       
+       // area big enough?
+       if(dir=='v' && (sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX)) return 0;
+       if(dir=='h' && (sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY)) return 0;
+       
+       // to be sure
+       if(fac<0.0) fac= 0.0;
+       if(fac>1.0) fac= 1.0;
+       
+       if(dir=='h') {
+               y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
+               
+               if(y- sa->v1->vec.y < AREAMINY) 
+                       y= sa->v1->vec.y+ AREAMINY;
+               else if(sa->v2->vec.y- y < AREAMINY) 
+                       y= sa->v2->vec.y- AREAMINY;
+               else y-= (y % AREAGRID);
+               
+               return y;
+       }
+       else {
+               x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
+               
+               if(x- sa->v1->vec.x < AREAMINX) 
+                       x= sa->v1->vec.x+ AREAMINX;
+               else if(sa->v4->vec.x- x < AREAMINX) 
+                       x= sa->v4->vec.x- AREAMINX;
+               else x-= (x % AREAGRID);
+               
+               return x;
+       }
+}
+
+ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
+{
+       ScrArea *newa=NULL;
+       ScrVert *sv1, *sv2;
+       short split;
+       
+       if(sa==NULL) return NULL;
+       
+       split= testsplitpoint(win, sa, dir, fac);
+       if(split==0) return NULL;
+       
+       if(dir=='h') {
+               /* new vertices */
+               sv1= screen_addvert(sc, sa->v1->vec.x, split);
+               sv2= screen_addvert(sc, sa->v4->vec.x, split);
+               
+               /* new edges */
+               screen_addedge(sc, sa->v1, sv1);
+               screen_addedge(sc, sv1, sa->v2);
+               screen_addedge(sc, sa->v3, sv2);
+               screen_addedge(sc, sv2, sa->v4);
+               screen_addedge(sc, sv1, sv2);
+               
+               /* new areas: top */
+               newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
+               area_copy_data(newa, sa, 0);
+               
+               /* area below */
+               sa->v2= sv1;
+               sa->v3= sv2;
+               
+       }
+       else {
+               /* new vertices */
+               sv1= screen_addvert(sc, split, sa->v1->vec.y);
+               sv2= screen_addvert(sc, split, sa->v2->vec.y);
+               
+               /* new edges */
+               screen_addedge(sc, sa->v1, sv1);
+               screen_addedge(sc, sv1, sa->v4);
+               screen_addedge(sc, sa->v2, sv2);
+               screen_addedge(sc, sv2, sa->v3);
+               screen_addedge(sc, sv1, sv2);
+               
+               /* new areas: left */
+               newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
+               area_copy_data(newa, sa, 0);
+               
+               /* area right */
+               sa->v1= sv1;
+               sa->v2= sv2;
+       }
+       
+       /* remove double vertices en edges */
+       removedouble_scrverts(sc);
+       removedouble_scredges(sc);
+       removenotused_scredges(sc);
+       
+       return newa;
+}
 
 /* empty screen, with 1 dummy area without spacedata */
 /* uses window size */
-static bScreen *screen_add(wmWindow *win, char *name)
+bScreen *ED_screen_add(wmWindow *win, Scene *scene, char *name)
 {
        bScreen *sc;
        ScrVert *sv1, *sv2, *sv3, *sv4;
        
        sc= alloc_libblock(&G.main->screen, ID_SCR, name);
-       sc->scene= G.scene;
+       sc->scene= scene;
        sc->do_refresh= 1;
-       
-       win->screen= sc;
+       sc->winid= win->winid;
        
        sv1= screen_addvert(sc, 0, 0);
        sv2= screen_addvert(sc, 0, win->sizey-1);
@@ -545,7 +426,7 @@ static bScreen *screen_add(wmWindow *win, char *name)
        screen_addedge(sc, sv4, sv1);
        
        /* dummy type, no spacedata */
-       screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_INFO);
+       screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
                
        return sc;
 }
@@ -583,11 +464,8 @@ static void screen_copy(bScreen *to, bScreen *from)
                sa->v4= sa->v4->newv;
                
                sa->spacedata.first= sa->spacedata.last= NULL;
-               sa->uiblocks.first= sa->uiblocks.last= NULL;
-               sa->panels.first= sa->panels.last= NULL;
                sa->regionbase.first= sa->regionbase.last= NULL;
                sa->actionzones.first= sa->actionzones.last= NULL;
-               sa->scriptlink.totscript= 0;
                
                area_copy_data(sa, saf, 0);
        }
@@ -598,100 +476,11 @@ static void screen_copy(bScreen *to, bScreen *from)
 
 }
 
-/* *********** Rip area 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)
-{
-       wmWindow *win;
-       bScreen *newsc;
-       rcti rect;
-       
-       /*  poll() checks area context, but we don't accept full-area windows */
-       if(C->screen->full != SCREENNORMAL) 
-               return OPERATOR_CANCELLED;
-       
-       /* adds window to WM */
-       rect= C->area->totrct;
-       BLI_translate_rcti(&rect, C->window->posx, C->window->posy);
-       win= WM_window_open(C, &rect);
-       
-       /* allocs new screen and adds to newly created window, using window size */
-       newsc= screen_add(win, C->screen->id.name+2);
-       
-       /* copy area to new screen */
-       area_copy_data((ScrArea *)newsc->areabase.first, C->area, 0);
-       
-       /* screen, areas init */
-       WM_event_add_notifier(C->wm, win, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-
-
-void ED_SCR_OT_area_rip(wmOperatorType *ot)
-{
-       ot->name= "Rip Area into New Window";
-       ot->idname= "ED_SCR_OT_area_rip";
-       
-       ot->invoke= NULL; //WM_operator_confirm;
-       ot->exec= screen_area_rip_op;
-       ot->poll= ED_operator_areaactive;
-}
-
-/* ********************************************* */
-
-bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
-{
-       bScreen *newsc;
-       
-       if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
-       
-       /* make new empty screen: */
-       newsc= screen_add(win, sc->id.name+2);
-       /* copy all data */
-       screen_copy(newsc, sc);
-       
-       return newsc;
-}
-
-/* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
-/* used with split operator */
-static ScrEdge *area_findsharededge(bScreen *screen, ScrArea *sa, ScrArea *sb)
-{
-       ScrVert *sav1= sa->v1;
-       ScrVert *sav2= sa->v2;
-       ScrVert *sav3= sa->v3;
-       ScrVert *sav4= sa->v4;
-       ScrVert *sbv1= sb->v1;
-       ScrVert *sbv2= sb->v2;
-       ScrVert *sbv3= sb->v3;
-       ScrVert *sbv4= sb->v4;
-       
-       if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
-               return screen_findedge(screen, sav1, sav2);
-       }
-       else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
-               return screen_findedge(screen, sav2, sav3);
-       }
-       else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
-               return screen_findedge(screen, sav3, sav4);
-       }
-       else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
-               return screen_findedge(screen, sav1, sav4);
-       }
-       
-       return NULL;
-}
 
 /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
 /* -1 = not valid check */
 /* used with join operator */
-static int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
+int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
 {
        ScrVert *sav1, *sav2, *sav3, *sav4;
        ScrVert *sbv1, *sbv2, *sbv3, *sbv4;
@@ -723,115 +512,10 @@ static int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
        return -1;
 }
 
-/* return 0: no split possible */
-/* else return (integer) screencoordinate split point */
-static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
-{
-       short x, y;
-       
-       // area big enough?
-       if(sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX) return 0;
-       if(sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY) return 0;
-
-       // to be sure
-       if(fac<0.0) fac= 0.0;
-       if(fac>1.0) fac= 1.0;
-       
-       if(dir=='h') {
-               y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
-               
-               if(sa->v2->vec.y==win->sizey-1 && sa->v2->vec.y- y < HEADERY) 
-                       y= sa->v2->vec.y- HEADERY;
-
-               else if(sa->v1->vec.y==0 && y- sa->v1->vec.y < HEADERY)
-                       y= sa->v1->vec.y+ HEADERY;
-
-               else if(y- sa->v1->vec.y < AREAMINY) y= sa->v1->vec.y+ AREAMINY;
-               else if(sa->v2->vec.y- y < AREAMINY) y= sa->v2->vec.y- AREAMINY;
-               else y-= (y % AREAGRID);
-
-               return y;
-       }
-       else {
-               x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
-               if(x- sa->v1->vec.x < AREAMINX) x= sa->v1->vec.x+ AREAMINX;
-               else if(sa->v4->vec.x- x < AREAMINX) x= sa->v4->vec.x- AREAMINX;
-               else x-= (x % AREAGRID);
-
-               return x;
-       }
-}
-
-static ScrArea *splitarea(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
-{
-       ScrArea *newa=NULL;
-       ScrVert *sv1, *sv2;
-       short split;
-       
-       if(sa==0) return NULL;
-       
-       split= testsplitpoint(win, sa, dir, fac);
-       if(split==0) return NULL;
-       
-       //sc= G.curscreen;
-       
-       //areawinset(sa->win);
-       
-       if(dir=='h') {
-               /* new vertices */
-               sv1= screen_addvert(sc, sa->v1->vec.x, split);
-               sv2= screen_addvert(sc, sa->v4->vec.x, split);
-               
-               /* new edges */
-               screen_addedge(sc, sa->v1, sv1);
-               screen_addedge(sc, sv1, sa->v2);
-               screen_addedge(sc, sa->v3, sv2);
-               screen_addedge(sc, sv2, sa->v4);
-               screen_addedge(sc, sv1, sv2);
-               
-               /* new areas: top */
-               newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
-               area_copy_data(newa, sa, 0);
-
-               /* area below */
-               sa->v2= sv1;
-               sa->v3= sv2;
-               
-       }
-       else {
-               /* new vertices */
-               sv1= screen_addvert(sc, split, sa->v1->vec.y);
-               sv2= screen_addvert(sc, split, sa->v2->vec.y);
-               
-               /* new edges */
-               screen_addedge(sc, sa->v1, sv1);
-               screen_addedge(sc, sv1, sa->v4);
-               screen_addedge(sc, sa->v2, sv2);
-               screen_addedge(sc, sv2, sa->v3);
-               screen_addedge(sc, sv1, sv2);
-               
-               /* new areas: left */
-               newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
-               area_copy_data(newa, sa, 0);
-
-               /* area right */
-               sa->v1= sv1;
-               sa->v2= sv2;
-       }
-       
-       /* remove double vertices en edges */
-       removedouble_scrverts(sc);
-       removedouble_scredges(sc);
-       removenotused_scredges(sc);
-       
-       return newa;
-}
-
-
-/* Helper function to join 2 areas, it has a return value, 0=failed 1=success
- *     used by the split, join and rip operators
- */
-int screen_join_areas(bScreen* scr, ScrArea *sa1, ScrArea *sa2) 
+/* Helper function to join 2 areas, it has a return value, 0=failed 1=success
+*      used by the split, join operators
+*/
+int screen_area_join(bContext *C, bScreen* scr, ScrArea *sa1, ScrArea *sa2) 
 {
        int dir;
        
@@ -870,20 +554,60 @@ int screen_join_areas(bScreen* scr, ScrArea *sa1, ScrArea *sa2)
                screen_addedge(scr, sa1->v3, sa1->v4);
        }
        
-       screen_delarea(scr, sa2);
+       screen_delarea(C, scr, sa2);
        removedouble_scrverts(scr);
        sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
        
        return 1;
 }
 
-/* *************************************************************** */
+void select_connected_scredge(bScreen *sc, ScrEdge *edge)
+{
+       ScrEdge *se;
+       ScrVert *sv;
+       int oneselected;
+       char dir;
+       
+       /* select connected, only in the right direction */
+       /* 'dir' is the direction of EDGE */
+       
+       if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
+       else dir= 'h';
+       
+       sv= sc->vertbase.first;
+       while(sv) {
+               sv->flag = 0;
+               sv= sv->next;
+       }
+       
+       edge->v1->flag= 1;
+       edge->v2->flag= 1;
+       
+       oneselected= 1;
+       while(oneselected) {
+               se= sc->edgebase.first;
+               oneselected= 0;
+               while(se) {
+                       if(se->v1->flag + se->v2->flag==1) {
+                               if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
+                                       se->v1->flag= se->v2->flag= 1;
+                                       oneselected= 1;
+                               }
+                                       if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
+                                               se->v1->flag= se->v2->flag= 1;
+                                               oneselected= 1;
+                                       }
+                       }
+                               se= se->next;
+               }
+       }
+}
 
 /* test if screen vertices should be scaled */
-void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
+static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
 {
        ScrVert *sv=NULL;
-       ScrArea *sa, *san;
+       ScrArea *sa;
        int sizex, sizey;
        float facx, facy, tempf, min[2], max[2];
        
@@ -932,13 +656,37 @@ void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
        }
        
        /* test for collapsed areas. This could happen in some blender version... */
-       for(sa= sc->areabase.first; sa; sa= san) {
-               san= sa->next;
-               if(sa->v1==sa->v2 || sa->v3==sa->v4 || sa->v2==sa->v3)
-                       screen_delarea(sc, sa);
+       /* ton: removed option now, it needs Context... */
+       
+       /* make each window at least HEADERY high */
+       for(sa= sc->areabase.first; sa; sa= sa->next) {
+               int headery= HEADERY+1;
+               
+               if(sa->v1->vec.y+headery > sa->v2->vec.y) {
+                       /* lower edge */
+                       ScrEdge *se= screen_findedge(sc, sa->v4, sa->v1);
+                       if(se && sa->v1!=sa->v2 ) {
+                               int yval;
+                               
+                               select_connected_scredge(sc, se);
+                               
+                               /* all selected vertices get the right offset */
+                               yval= sa->v2->vec.y-headery;
+                               sv= sc->vertbase.first;
+                               while(sv) {
+                                       /* if is a collapsed area */
+                                       if(sv!=sa->v2 && sv!=sa->v3) {
+                                               if(sv->flag) sv->vec.y= yval;
+                                       }
+                                       sv= sv->next;
+                               }
+                       }
+               }
        }
+       
 }
 
+/* *********************** DRAWING **************************************** */
 
 
 #define SCR_BACK 0.55
@@ -1120,35 +868,87 @@ static void scrarea_draw_shape_light(ScrArea *sa, char dir)
        glDisable(GL_BLEND);
 }
 
+static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2, short a) 
+{
+       /* right border area */
+       if(x2<sizex-1)
+               sdrawline(x2+a, y1, x2+a, y2);
+       
+       /* left border area */
+       if(x1>0)  /* otherwise it draws the emboss of window over */
+               sdrawline(x1+a, y1, x1+a, y2);
+       
+       /* top border area */
+       if(y2<sizey-1)
+               sdrawline(x1, y2+a, x2, y2+a);
+       
+       /* bottom border area */
+       if(y1>0)
+               sdrawline(x1, y1+a, x2, y1+a);
+       
+}
+
 /** screen edges drawing **/
-static void drawscredge_area(ScrArea *sa)
+static void drawscredge_area(ScrArea *sa, int sizex, int sizey, int center)
 {
-       AZone *az;
        short x1= sa->v1->vec.x;
        short y1= sa->v1->vec.y;
        short x2= sa->v3->vec.x;
        short y2= sa->v3->vec.y;
+       short a, rt;
        
-       cpack(0x0);
+       rt= CLAMPIS(G.rt, 0, 16);
        
-       /* right border area */
-       sdrawline(x2, y1, x2, y2);
-       
-       /* left border area */
-       if(x1>0) { /* otherwise it draws the emboss of window over */
-               sdrawline(x1, y1, x1, y2);
+       if(center==0) {
+               cpack(0x505050);
+               for(a=-rt; a<=rt; a++)
+                       if(a!=0)
+                               drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, a);
+       }
+       else {
+               cpack(0x0);
+               drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, 0);
        }
+}
+
+/* ****************** EXPORTED API TO OTHER MODULES *************************** */
+
+bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
+{
+       bScreen *newsc;
        
-       /* top border area */
-       sdrawline(x1, y2, x2, y2);
+       if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
        
-       /* bottom border area */
-       sdrawline(x1, y1, x2, y1);
+       /* make new empty screen: */
+       newsc= ED_screen_add(win, sc->scene, sc->id.name+2);
+       /* copy all data */
+       screen_copy(newsc, sc);
+       /* set in window */
+       win->screen= newsc;
+       
+       /* store identifier */
+       win->screen->winid= win->winid;
+       BLI_strncpy(win->screenname, win->screen->id.name+2, 21);
+
+       return newsc;
+}
+
+/* screen sets cursor based on swinid */
+static void region_cursor_set(wmWindow *win, int swinid)
+{
+       ScrArea *sa= win->screen->areabase.first;
        
-       /* temporary viz for 'action corner' */
-       for(az= sa->actionzones.first; az; az= az->next) {
-               if(az->type==AZONE_TRI) sdrawtrifill(az->x1, az->y1, az->x2, az->y2, .2, .2, .2);
-               //if(az->type==AZONE_TRI) sdrawtri(az->x1, az->y1, az->x2, az->y2);
+       for(;sa; sa= sa->next) {
+               ARegion *ar= sa->regionbase.first;
+               for(;ar; ar= ar->next) {
+                       if(ar->swinid == swinid) {
+                               if(ar->type && ar->type->cursor)
+                                       ar->type->cursor(win, sa, ar);
+                               else
+                                       WM_cursor_set(win, CURSOR_STD);
+                               return;
+                       }
+               }
        }
 }
 
@@ -1156,27 +956,25 @@ void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
 {
        
        /* generic notes */
-       switch(note->type) {
-               case WM_NOTE_WINDOW_REDRAW:
-                       win->screen->do_draw= 1;
-                       break;
-               case WM_NOTE_SCREEN_CHANGED:
-                       win->screen->do_draw= win->screen->do_refresh= 1;
+       switch(note->category) {
+               case NC_WM:
+                       if(note->data==ND_FILEREAD)
+                               win->screen->do_draw= 1;
                        break;
-               case WM_NOTE_AREA_SPLIT:
-                       printf("WM_NOTE_AREA_SPLIT\n");
-                       break;
-               case WM_NOTE_AREA_DRAG:
-                       printf("WM_NOTE_AREA_DRAG\n");
+               case NC_WINDOW:
+                       win->screen->do_draw= 1;
                        break;
-               case WM_NOTE_GESTURE_CHANGED:
-                       printf("WM_NOTE_GESTURE_CHANGED\n");
-                       win->screen->do_gesture= 1;
+               case NC_SCREEN:
+                       if(note->action==NA_EDITED)
+                               win->screen->do_draw= win->screen->do_refresh= 1;
+               case NC_SCENE:
+                       if(note->data==ND_MODE)
+                               region_cursor_set(win, note->swinid);                           
                        break;
        }
 }
 
-
+/* only for edge lines between areas, and the blended join arrows */
 void ED_screen_draw(wmWindow *win)
 {
        ScrArea *sa;
@@ -1185,14 +983,17 @@ void ED_screen_draw(wmWindow *win)
        int dir = -1;
        int dira = -1;
 
-       wm_subwindow_set(win, win->screen->mainwin);
+       wmSubWindowSet(win, win->screen->mainwin);
        
        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
                if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
-               drawscredge_area(sa);
+               drawscredge_area(sa, win->sizex, win->sizey, 0);
        }
-
+       for(sa= win->screen->areabase.first; sa; sa= sa->next)
+               drawscredge_area(sa, win->sizex, win->sizey, 1);
+       
+       /* blended join arrow */
        if (sa1 && sa2) {
                dir = area_getorientation(win->screen, sa1, sa2);
                if (dir >= 0) {
@@ -1218,27 +1019,17 @@ void ED_screen_draw(wmWindow *win)
                scrarea_draw_shape_dark(sa2, dir);
                scrarea_draw_shape_light(sa1, dira);
        }
-       if(G.f & G_DEBUG) printf("draw screen\n");
+       
+//     if(G.f & G_DEBUG) printf("draw screen\n");
        win->screen->do_draw= 0;
 }
 
-void ED_screen_gesture(wmWindow *win)
-{
-       if(G.f & G_DEBUG) printf("gesture draw screen\n");
-
-       if(win->gesture.first) {
-               ed_gesture_update(win);
-       }
-       win->screen->do_gesture= 0;
-}
-
 /* make this screen usable */
 /* for file read and first use, for scaling window, area moves */
 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
 {
        ScrArea *sa;
-       ARegion *ar;
-       rcti winrct= {0, win->sizex, 0, win->sizey};
+       rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
        
        screen_test_scale(win->screen, win->sizex, win->sizey);
        
@@ -1248,19 +1039,19 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
                wm_subwindow_position(win, win->screen->mainwin, &winrct);
        
        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
-               /* set spacetype and region callbacks */
-               /* sets subwindow */
+               /* set spacetype and region callbacks, calls init() */
+               /* sets subwindows for regions, adds handlers */
                ED_area_initialize(wm, win, sa);
        }
 
-       for(ar= win->screen->regionbase.first; ar; ar= ar->next) {
-               /* set subwindow */
-               ED_region_initialize(wm, win, ar);
-       }
+       /* wake up animtimer */
+       if(win->screen->animtimer)
+               WM_event_window_timer_sleep(win, win->screen->animtimer, 0);
        
        if(G.f & G_DEBUG) printf("set screen\n");
        win->screen->do_refresh= 0;
 
+       win->screen->context= ed_screen_context;
 }
 
 /* file read, set all screens, ... */
@@ -1277,850 +1068,473 @@ void ED_screens_initialize(wmWindowManager *wm)
        }
 }
 
+
+/* *********** exit calls are for closing running stuff ******** */
+
 void ED_region_exit(bContext *C, ARegion *ar)
 {
-       WM_operator_cancel(C, &ar->modalops, NULL);
-       WM_event_remove_handlers(&ar->handlers);
+       ARegion *prevar= CTX_wm_region(C);
+
+       CTX_wm_region_set(C, ar);
+       WM_event_remove_handlers(C, &ar->handlers);
+       if(ar->swinid)
+               wm_subwindow_close(CTX_wm_window(C), ar->swinid);
+       ar->swinid= 0;
+       
+       if(ar->headerstr)
+               MEM_freeN(ar->headerstr);
+       ar->headerstr= NULL;
+       
+       CTX_wm_region_set(C, prevar);
 }
 
 void ED_area_exit(bContext *C, ScrArea *sa)
 {
+       ScrArea *prevsa= CTX_wm_area(C);
        ARegion *ar;
 
+       CTX_wm_area_set(C, sa);
        for(ar= sa->regionbase.first; ar; ar= ar->next)
                ED_region_exit(C, ar);
 
-       WM_operator_cancel(C, &sa->modalops, NULL);
-       WM_event_remove_handlers(&sa->handlers);
+       WM_event_remove_handlers(C, &sa->handlers);
+       CTX_wm_area_set(C, prevsa);
 }
 
 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 {
+       wmWindow *prevwin= CTX_wm_window(C);
        ScrArea *sa;
        ARegion *ar;
 
+       CTX_wm_window_set(C, window);
+       
+       if(screen->animtimer)
+               WM_event_remove_window_timer(window, screen->animtimer);
+       screen->animtimer= NULL;
+       
+       if(screen->mainwin)
+               wm_subwindow_close(window, screen->mainwin);
+       screen->mainwin= 0;
+       screen->subwinactive= 0;
+       
        for(ar= screen->regionbase.first; ar; ar= ar->next)
                ED_region_exit(C, ar);
 
        for(sa= screen->areabase.first; sa; sa= sa->next)
                ED_area_exit(C, sa);
 
-       WM_operator_cancel(C, &window->modalops, NULL);
-       WM_event_remove_handlers(&window->handlers);
+       /* mark it available for use for other windows */
+       screen->winid= 0;
+       
+       CTX_wm_window_set(C, prevwin);
 }
 
-void placeholder()
+/* *********************************** */
+
+/* case when on area-edge or in azones, or outside window */
+static void screen_cursor_set(wmWindow *win, wmEvent *event)
 {
-       removenotused_scrverts(NULL);
-       removenotused_scredges(NULL);
+       AZone *az= NULL;
+       ScrArea *sa;
+       
+       for(sa= win->screen->areabase.first; sa; sa= sa->next)
+               if((az=is_in_area_actionzone(sa, event->x, event->y)))
+                       break;
+       
+       if(sa) {
+               if(az->type==AZONE_AREA)
+                       WM_cursor_set(win, CURSOR_EDIT);
+               else if(az->type==AZONE_REGION) {
+                       if(az->x1==az->x2)
+                               WM_cursor_set(win, CURSOR_X_MOVE);
+                       else
+                               WM_cursor_set(win, CURSOR_Y_MOVE);
+               }
+       }
+       else {
+               ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
+               
+               if (actedge) {
+                       if(scredge_is_horizontal(actedge))
+                               WM_cursor_set(win, CURSOR_Y_MOVE);
+                       else
+                               WM_cursor_set(win, CURSOR_X_MOVE);
+               }
+               else
+                       WM_cursor_set(win, CURSOR_STD);
+       } 
 }
 
-/* called in wm_event_system.c. sets state var in screen */
-void ED_screen_set_subwinactive(wmWindow *win)
+
+/* called in wm_event_system.c. sets state vars in screen, cursors */
+/* event type is mouse move */
+void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
 {
        if(win->screen) {
-               wmEvent *event= win->eventstate;
+               bScreen *scr= win->screen;
                ScrArea *sa;
-               
-               for(sa= win->screen->areabase.first; sa; sa= sa->next) {
+               ARegion *ar;
+               int oldswin= scr->subwinactive;
+
+               for(sa= scr->areabase.first; sa; sa= sa->next) {
                        if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
                                if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
-                                       break;
+                                       if(NULL==is_in_area_actionzone(sa, event->x, event->y))
+                                               break;
                }
                if(sa) {
-                       ARegion *ar;
                        for(ar= sa->regionbase.first; ar; ar= ar->next) {
                                if(BLI_in_rcti(&ar->winrct, event->x, event->y))
-                                       win->screen->subwinactive= ar->swinid;
+                                       scr->subwinactive= ar->swinid;
                        }
                }
                else
-                       win->screen->subwinactive= win->screen->mainwin;
+                       scr->subwinactive= scr->mainwin;
                
-       }
-}
-
-/* ****************** cursor near edge operator ********************************* */
+               /* check for redraw headers */
+               if(oldswin!=scr->subwinactive) {
 
-/* operator cb */
-int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event)
-{
-       if (C->screen->subwinactive==C->screen->mainwin) {
-               ScrEdge *actedge= screen_find_active_scredge(C->screen, event->x, event->y);
-               
-               if (actedge && scredge_is_horizontal(actedge)) {
-                       WM_set_cursor(C, CURSOR_Y_MOVE);
-               } else {
-                       WM_set_cursor(C, CURSOR_X_MOVE);
-               }
-       } else {
-               ScrArea *sa= NULL;
-               AZone *az= NULL;
-               for(sa= C->screen->areabase.first; sa; sa= sa->next) {
-                       az= is_in_area_actionzone(sa, event->x, event->y);
-                       if(az!=NULL) break;
+                       for(sa= scr->areabase.first; sa; sa= sa->next) {
+                               int do_draw= 0;
+                               
+                               for(ar= sa->regionbase.first; ar; ar= ar->next)
+                                       if(ar->swinid==oldswin || ar->swinid==scr->subwinactive)
+                                               do_draw= 1;
+                               
+                               if(do_draw) {
+                                       for(ar= sa->regionbase.first; ar; ar= ar->next)
+                                               if(ar->regiontype==RGN_TYPE_HEADER)
+                                                       ED_region_tag_redraw(ar);
+                               }
+                       }
                }
-               if(az!=NULL) WM_set_cursor(C, CURSOR_EDIT);
-               else WM_set_cursor(C, CURSOR_STD);
-       }
-       
-       return OPERATOR_PASS_THROUGH;
-}
-
-/* ************** move area edge operator *********************************** */
-
-/* operator state vars used:  
-           x, y                        mouse coord near edge
-           delta            movement of edge
-
-       functions:
-
-       init()   set default property values, find edge based on mouse coords, test
-            if the edge can be moved, select edges, calculate min and max movement
-
-       apply() apply delta on selection
-
-       exit()  cleanup, send notifier
-
-       cancel() cancel moving
-
-       callbacks:
-
-       exec()   execute without any user interaction, based on properties
-            call init(), apply(), exit()
-
-       invoke() gets called on mouse click near edge
-            call init(), add handler
-
-       modal()  accept modal events while doing it
-                       call apply() with delta motion
-            call exit() and remove handler
-
-*/
-
-typedef struct sAreaMoveData {
-       int bigger, smaller, origval;
-       char dir;
-} sAreaMoveData;
-
-/* helper call to move area-edge, sets limits */
-static void move_areas_set_limits(bScreen *sc, int dir, int *bigger, int *smaller)
-{
-       ScrArea *sa;
-       
-       /* we check all areas and test for free space with MINSIZE */
-       *bigger= *smaller= 100000;
-       
-       for(sa= sc->areabase.first; sa; sa= sa->next) {
-               if(dir=='h') {
-                       int y1= sa->v2->vec.y - sa->v1->vec.y-AREAMINY;
-                       
-                       /* if top or down edge selected, test height */
-                       if(sa->v1->flag && sa->v4->flag)
-                               *bigger= MIN2(*bigger, y1);
-                       else if(sa->v2->flag && sa->v3->flag)
-                               *smaller= MIN2(*smaller, y1);
+               
+               /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
+               if(scr->subwinactive==scr->mainwin) {
+                       screen_cursor_set(win, event);
                }
-               else {
-                       int x1= sa->v4->vec.x - sa->v1->vec.x-AREAMINX;
-                       
-                       /* if left or right edge selected, test width */
-                       if(sa->v1->flag && sa->v2->flag)
-                               *bigger= MIN2(*bigger, x1);
-                       else if(sa->v3->flag && sa->v4->flag)
-                               *smaller= MIN2(*smaller, x1);
+               else if(oldswin!=scr->subwinactive) {
+                       region_cursor_set(win, scr->subwinactive);
                }
        }
 }
 
-/* validate selection inside screen, set variables OK */
-/* return 0: init failed */
-static int move_areas_init (bContext *C, wmOperator *op)
+int ED_screen_area_active(const bContext *C)
 {
-       ScrEdge *actedge;
-       sAreaMoveData *md;
-       int x, y;
-
-       /* required properties */
-       if(!(OP_get_int(op, "x", &x) && OP_get_int(op, "y", &y)))
-               return 0;
-
-       /* default properties */
-       OP_verify_int(op, "delta", 0, NULL);
-
-       /* setup */
-       actedge= screen_find_active_scredge(C->screen, x, y);
-       if(actedge==NULL) return 0;
-
-       md= MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData");
-       op->customdata= md;
-
-       md->dir= scredge_is_horizontal(actedge)?'h':'v';
-       if(md->dir=='h') md->origval= actedge->v1->vec.y;
-       else md->origval= actedge->v1->vec.x;
-       
-       select_connected_scredge(C->screen, actedge);
-       /* now all vertices with 'flag==1' are the ones that can be moved. */
+       bScreen *sc= CTX_wm_screen(C);
+       ScrArea *sa= CTX_wm_area(C);
 
-       move_areas_set_limits(C->screen, md->dir, &md->bigger, &md->smaller);
-       
-       return 1;
+       if(sc && sa) {
+               ARegion *ar;
+               for(ar= sa->regionbase.first; ar; ar= ar->next)
+                       if(ar->swinid == sc->subwinactive)
+                               return 1;
+       }       
+       return 0;
 }
 
-/* moves selected screen edge amount of delta, used by split & move */
-static void move_areas_apply_do(bContext *C, int origval, int delta, int dir, int bigger, int smaller)
+/* operator call, WM + Window + screen already existed before */
+/* Do NOT call in area/region queues! */
+void ED_screen_set(bContext *C, bScreen *sc)
 {
-       ScrVert *v1;
+       wmWindow *win= CTX_wm_window(C);
+       bScreen *oldscreen= CTX_wm_screen(C);
+       ID *id;
        
-       delta= CLAMPIS(delta, -smaller, bigger);
-       
-       for (v1= C->screen->vertbase.first; v1; v1= v1->next) {
-               if (v1->flag) {
-                       /* that way a nice AREAGRID  */
-                       if((dir=='v') && v1->vec.x>0 && v1->vec.x<C->window->sizex-1) {
-                               v1->vec.x= origval + delta;
-                               if(delta != bigger && delta != -smaller) v1->vec.x-= (v1->vec.x % AREAGRID);
-                       }
-                       if((dir=='h') && v1->vec.y>0 && v1->vec.y<C->window->sizey-1) {
-                               v1->vec.y= origval + delta;
-
-                               v1->vec.y+= AREAGRID-1;
-                               v1->vec.y-= (v1->vec.y % AREAGRID);
-                               
-                               /* prevent too small top header */
-                               if(v1->vec.y > C->window->sizey-HEADERY)
-                                       v1->vec.y= C->window->sizey-HEADERY;
+       /* validate screen, it's called with notifier reference */
+       for(id= CTX_data_main(C)->screen.first; id; id= id->next)
+               if(sc == (bScreen *)id)
+                       break;
+       if(id==NULL) 
+               return;
+       
+       /* check for valid winid */
+       if(sc->winid!=0 && sc->winid!=win->winid)
+               return;
+       
+       if(sc->full) {                          /* find associated full */
+               bScreen *sc1;
+               for(sc1= CTX_data_main(C)->screen.first; sc1; sc1= sc1->id.next) {
+                       ScrArea *sa= sc1->areabase.first;
+                       if(sa->full==sc) {
+                               sc= sc1;
+                               break;
                        }
                }
        }
-
-       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-}
-
-static void move_areas_apply(bContext *C, wmOperator *op)
-{
-       sAreaMoveData *md= op->customdata;
-       int delta;
        
-       OP_get_int(op, "delta", &delta);
-       move_areas_apply_do(C, md->origval, delta, md->dir, md->bigger, md->smaller);
-}
-
-static void move_areas_exit(bContext *C, wmOperator *op)
-{
-       if(op->customdata)
-               MEM_freeN(op->customdata);
-       op->customdata= NULL;
-       
-       /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scrverts(C->screen);
-       removedouble_scredges(C->screen);
-}
-
-static int move_areas_exec(bContext *C, wmOperator *op)
-{
-       if(!move_areas_init(C, op))
-               return OPERATOR_CANCELLED;
-       
-       move_areas_apply(C, op);
-       move_areas_exit(C, op);
-       
-       return OPERATOR_FINISHED;
+       if (oldscreen != sc) {
+               wmTimer *wt= oldscreen->animtimer;
+               
+               /* we put timer to sleep, so screen_exit has to think there's no timer */
+               oldscreen->animtimer= NULL;
+               if(wt)
+                       WM_event_window_timer_sleep(win, wt, 1);
+               
+               ED_screen_exit(C, win, oldscreen);
+               oldscreen->animtimer= wt;
+               
+               win->screen= sc;
+               CTX_wm_window_set(C, win);      // stores C->wm.screen... hrmf
+               
+               /* prevent multiwin errors */
+               sc->winid= win->winid;
+               
+               ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
+               WM_event_add_notifier(C, NC_WINDOW, NULL);
+               
+               /* makes button hilites work */
+               WM_event_add_mousemove(C);
+       }
 }
 
-/* interaction callback */
-static int move_areas_invoke(bContext *C, wmOperator *op, wmEvent *event)
+/* only call outside of area/region loops */
+void ED_screen_set_scene(bContext *C, Scene *scene)
 {
-       OP_verify_int(op, "x", event->x, NULL);
-       OP_verify_int(op, "y", event->y, NULL);
-
-       if(!move_areas_init(C, op)) 
-               return OPERATOR_PASS_THROUGH;
-       
-       /* add temp handler */
-       WM_event_add_modal_handler(&C->window->handlers, op);
+       bScreen *sc;
+       bScreen *curscreen= CTX_wm_screen(C);
        
-       return OPERATOR_RUNNING_MODAL;
-}
-
-static int move_areas_cancel(bContext *C, wmOperator *op)
-{
-       WM_event_remove_modal_handler(&C->window->handlers, op);                                
-
-       OP_set_int(op, "delta", 0);
-       move_areas_apply(C, op);
-       move_areas_exit(C, op);
-
-       return OPERATOR_CANCELLED;
-}
-
-/* modal callback for while moving edges */
-static int move_areas_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
-       sAreaMoveData *md;
-       int delta, x, y;
-
-       md= op->customdata;
-
-       OP_get_int(op, "x", &x);
-       OP_get_int(op, "y", &y);
-
-       /* execute the events */
-       switch(event->type) {
-               case MOUSEMOVE:
-                       delta= (md->dir == 'v')? event->x - x: event->y - y;
-                       OP_set_int(op, "delta", delta);
-
-                       move_areas_apply(C, op);
-                       break;
+       for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
+               if((U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
                        
-               case LEFTMOUSE:
-                       if(event->val==0) {
-                               move_areas_exit(C, op);
-                               WM_event_remove_modal_handler(&C->window->handlers, op);                                
-                               return OPERATOR_FINISHED;
+                       if(scene != sc->scene) {
+                               /* all areas endlocalview */
+                       // XXX  ScrArea *sa= sc->areabase.first;
+                       //      while(sa) {
+                       //              endlocalview(sa);
+                       //              sa= sa->next;
+                       //      }               
+                               sc->scene= scene;
                        }
-                       break;
                        
-               case ESCKEY:
-                       return move_areas_cancel(C, op);
+               }
        }
        
-       return OPERATOR_RUNNING_MODAL;
-}
-
-void ED_SCR_OT_move_areas(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Move area edges";
-       ot->idname= "ED_SCR_OT_move_areas";
-
-       ot->exec= move_areas_exec;
-       ot->invoke= move_areas_invoke;
-       ot->cancel= move_areas_cancel;
-       ot->modal= move_areas_modal;
-
-       ot->poll= ED_operator_screen_mainwinactive; /* when mouse is over area-edge */
-}
-
-/* ************** split area operator *********************************** */
-
-/* 
-operator state vars:  
-       fac              spit point
-       dir              direction 'v' or 'h'
-
-operator customdata:
-       area                    pointer to (active) area
-       x, y                    last used mouse pos
-       (more, see below)
-
-functions:
-
-       init()   set default property values, find area based on context
-
-       apply() split area based on state vars
-
-       exit()  cleanup, send notifier
-
-       cancel() remove duplicated area
-
-callbacks:
-
-       exec()   execute without any user interaction, based on state vars
-            call init(), apply(), exit()
-
-       invoke() gets called on mouse click in action-widget
-            call init(), add modal handler
-                       call apply() with initial motion
-
-       modal()  accept modal events while doing it
-            call move-areas code with delta motion
-            call exit() or cancel() and remove handler
-
-*/
-
-#define SPLIT_STARTED  1
-#define SPLIT_PROGRESS 2
-
-typedef struct sAreaSplitData
-{
-       int x, y;       /* last used mouse position */
-       
-       int origval;                    /* for move areas */
-       int bigger, smaller;    /* constraints for moving new edge */
-       int delta;                              /* delta move edge */
-       
-       ScrEdge *nedge;                 /* new edge */
-       ScrArea *sarea;                 /* start area */
-       ScrArea *narea;                 /* new area */
-} sAreaSplitData;
-
-/* generic init, no UI stuff here */
-static int split_area_init(bContext *C, wmOperator *op)
-{
-       sAreaSplitData *sd;
-       int dir;
-       
-       /* required context */
-       if(C->area==NULL) return 0;
+       //  copy_view3d_lock(0);        /* space.c */
+       
+       /* are there cameras in the views that are not in the scene? */
+       for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
+               if( (U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
+                       ScrArea *sa= sc->areabase.first;
+                       while(sa) {
+                               SpaceLink *sl= sa->spacedata.first;
+                               while(sl) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *v3d= (View3D*) sl;
+                                               if (!v3d->camera || !object_in_scene(v3d->camera, scene)) {
+                                                       v3d->camera= scene_find_camera(sc->scene);
+                                                       // XXX if (sc==curscreen) handle_view3d_lock();
+                                                       if (!v3d->camera && v3d->persp==V3D_CAMOB) 
+                                                               v3d->persp= V3D_PERSP;
+                                               }
+                                       }
+                                       sl= sl->next;
+                               }
+                               sa= sa->next;
+                       }
+               }
+       }
        
-       /* required properties */
-       OP_verify_float(op, "fac", 0.5f, NULL);
-       OP_verify_int(op, "dir", 'h', &dir);
+       CTX_data_scene_set(C, scene);
+       set_scene_bg(scene);
        
-       /* minimal size */
-       if(dir=='v' && C->area->winx < 2*AREAMINX) return 0;
-       if(dir=='h' && C->area->winy < 2*AREAMINY) return 0;
-          
-       /* custom data */
-       sd= (sAreaSplitData*)MEM_callocN(sizeof (sAreaSplitData), "op_split_area");
-       op->customdata= sd;
+       ED_update_for_newframe(C, 1);
        
-       sd->sarea= C->area;
+       /* complete redraw */
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
        
-       return 1;
 }
 
-/* do the split */
-static void split_area_apply(bContext *C, wmOperator *op)
+/* this function toggles: if area is full then the parent will be restored */
+void ed_screen_fullarea(bContext *C, ScrArea *sa)
 {
-       sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
-       float fac;
-       int dir;
-       
-       OP_get_float(op, "fac", &fac);
-       OP_get_int(op, "dir", &dir);
-
-       sd->narea= splitarea(C->window, C->screen, sd->sarea, dir, fac);
-       
-       if(sd->narea) {
-               ScrVert *sv;
-               
-               sd->nedge= area_findsharededge(C->screen, sd->sarea, sd->narea);
-       
-               /* select newly created edge, prepare for moving edge */
-               for(sv= C->screen->vertbase.first; sv; sv= sv->next)
-                       sv->flag = 0;
-               
-               sd->nedge->v1->flag= 1;
-               sd->nedge->v2->flag= 1;
-
-               if(dir=='h') sd->origval= sd->nedge->v1->vec.y;
-               else sd->origval= sd->nedge->v1->vec.x;
-
-       }               
+       bScreen *sc, *oldscreen;
        
-       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-       
-}
-
-static void split_area_exit(bContext *C, wmOperator *op)
-{
-       if (op->customdata) {
-               MEM_freeN(op->customdata);
-               op->customdata = NULL;
+       if(sa==NULL) {
+               return;
        }
-       
-       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-
-       /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scrverts(C->screen);
-       removedouble_scredges(C->screen);
-}
-
-
-/* UI callback, adds new handler */
-static int split_area_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       sAreaSplitData *sd;
-       
-       if(event->type==EVT_ACTIONZONE) {
-               sActionzoneData *sad= event->customdata;
-               int dir;
+       else if(sa->full) {
+               short fulltype;
                
-               /* verify *sad itself */
-               if(sad==NULL || sad->sa1==NULL || sad->az==NULL)
-                       return OPERATOR_PASS_THROUGH;
+               sc= sa->full;           /* the old screen to restore */
+               oldscreen= CTX_wm_screen(C);    /* the one disappearing */
                
-               /* is this our *sad? if areas not equal it should be passed on */
-               if(C->area!=sad->sa1 || sad->sa1!=sad->sa2)
-                       return OPERATOR_PASS_THROUGH;
+               fulltype = sc->full;
                
-               /* prepare operator state vars */
-               if(sad->gesture_dir==AZONE_N || sad->gesture_dir==AZONE_S) {
-                       dir= 'h';
-                       OP_set_float(op, "fac", ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx);
-               }
-               else {
-                       dir= 'v';
-                       OP_set_float(op, "fac", ((float)(event->y - sad->sa1->v1->vec.y)) / (float)sad->sa1->winy);
-               }
-               OP_set_int(op, "dir", dir);
-
-               /* general init, also non-UI case, adds customdata, sets area and defaults */
-               if(!split_area_init(C, op))
-                       return OPERATOR_PASS_THROUGH;
+               /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
+                  is set */
                
-               sd= (sAreaSplitData *)op->customdata;
+               if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
+                       ScrArea *old;
+                       
+                       sc->full= 0;
+                       
+                       /* find old area */
+                       for(old= sc->areabase.first; old; old= old->next) 
+                               if(old->full) break;
+                       if(old==NULL) {
+                               printf("something wrong in areafullscreen\n"); 
+                               return;
+                       }
+                           // old feature described below (ton)
+                               // in autoplay screens the headers are disabled by 
+                               // default. So use the old headertype instead
+                       
+                       area_copy_data(old, sa, 1);     /*  1 = swap spacelist */
+                       
+                       old->full= NULL;
+                       
+                       /* animtimer back */
+                       sc->animtimer= oldscreen->animtimer;
+                       oldscreen->animtimer= NULL;
+                       
+                       ED_screen_set(C, sc);
+                       
+                       free_screen(oldscreen);
+                       free_libblock(&CTX_data_main(C)->screen, oldscreen);
+               }
+       }
+       else {
+               ScrArea *newa;
                
-               sd->x= event->x;
-               sd->y= event->y;
+               oldscreen= CTX_wm_screen(C);
+
+               /* is there only 1 area? */
+               if(oldscreen->areabase.first==oldscreen->areabase.last) return;
                
-               /* do the split */
-               split_area_apply(C, op);
-               move_areas_set_limits(C->screen, dir, &sd->bigger, &sd->smaller);
+               oldscreen->full = SCREENFULL;
                
-               /* add temp handler for edge move or cancel */
-               WM_event_add_modal_handler(&C->window->handlers, op);
+               sc= ED_screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
+               sc->full = SCREENFULL; // XXX
                
-               return OPERATOR_RUNNING_MODAL;
+               /* timer */
+               sc->animtimer= oldscreen->animtimer;
+               oldscreen->animtimer= NULL;
                
-       }
-       return OPERATOR_PASS_THROUGH;
-}
+               /* returns the top small area */
+               newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
+               ED_area_newspace(C, newa, SPACE_INFO);
 
-/* function to be called outside UI context, or for redo */
-static int split_area_exec(bContext *C, wmOperator *op)
-{
-       
-       if(!split_area_init(C, op))
-               return OPERATOR_CANCELLED;
-       
-       split_area_apply(C, op);
-       split_area_exit(C, op);
-       
-       return OPERATOR_FINISHED;
-}
+               /* copy area */
+               newa= newa->prev;
+               area_copy_data(newa, sa, 1);    /* 1 = swap spacelist */
 
-static int split_area_cancel(bContext *C, wmOperator *op)
-{
-       sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
+               sa->full= oldscreen;
+               newa->full= oldscreen;
+               newa->next->full= oldscreen; // XXX
 
-       WM_event_remove_modal_handler(&C->window->handlers, op);
-
-       if (screen_join_areas(C->screen,sd->sarea, sd->narea)) {
-               if (C->area == sd->narea) {
-                       C->area = NULL;
-               }
-               sd->narea = NULL;
+               ED_screen_set(C, sc);
        }
-       split_area_exit(C, op);
 
-       return OPERATOR_CANCELLED;
-}
+       /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
+       CTX_wm_area_set(C, sc->areabase.first);
 
-static int split_area_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
-       sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
-       int dir;
+       /* XXX retopo_force_update(); */
 
-       /* execute the events */
-       switch(event->type) {
-               case MOUSEMOVE:
-                       
-                       OP_get_int(op, "dir", &dir);
-                       
-                       sd->delta= (dir == 'v')? event->x - sd->origval: event->y - sd->origval;
-                       move_areas_apply_do(C, sd->origval, sd->delta, dir, sd->bigger, sd->smaller);
-                       
-                       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-                       break;
-                       
-               case LEFTMOUSE:
-                       if(event->val==0) { /* mouse up */
-                               split_area_exit(C, op);
-                               WM_event_remove_modal_handler(&C->window->handlers, op);
-                               return OPERATOR_FINISHED;
-                       }
-                       break;
-               case RIGHTMOUSE: /* cancel operation */
-               case ESCKEY:
-                       return split_area_cancel(C, op);
-       }
-       
-       return OPERATOR_RUNNING_MODAL;
 }
 
-void ED_SCR_OT_split_area(wmOperatorType *ot)
+int ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
 {
-       ot->name = "Split area";
-       ot->idname = "ED_SCR_OT_split_area";
+       if(sa==NULL)
+               return 0;
        
-       ot->exec= split_area_exec;
-       ot->invoke= split_area_invoke;
-       ot->modal= split_area_modal;
+       if(sa->full==0)
+               ed_screen_fullarea(C, sa);
+
+       /* CTX_wm_area(C) is new area */
+       ED_area_newspace(C, CTX_wm_area(C), type);
        
-       ot->poll= ED_operator_screenactive; /* XXX should be area active */
+       return 1;
 }
 
-/* ************** join area operator ********************************************** */
-
-/* operator state vars used:  
-                       x1, y1     mouse coord in first area, which will disappear
-                       x2, y2     mouse coord in 2nd area, which will become joined
-
-functions:
-
-   init()   find edge based on state vars 
-                       test if the edge divides two areas, 
-                       store active and nonactive area,
-            
-   apply()  do the actual join
-
-   exit()      cleanup, send notifier
-
-callbacks:
-
-   exec()      calls init, apply, exit 
-   
-   invoke() sets mouse coords in x,y
-            call init()
-            add modal handler
-
-   modal()     accept modal events while doing it
-                       call apply() with active window and nonactive window
-            call exit() and remove handler when LMB confirm
-
-*/
-
-typedef struct sAreaJoinData
-{
-       ScrArea *sa1;   /* first area to be considered */
-       ScrArea *sa2;   /* second area to be considered */
-       ScrArea *scr;   /* designed for removal */
-
-} sAreaJoinData;
-
-
-/* validate selection inside screen, set variables OK */
-/* return 0: init failed */
-/* XXX todo: find edge based on (x,y) and set other area? */
-static int join_areas_init(bContext *C, wmOperator *op)
+void ED_screen_full_prevspace(bContext *C)
 {
-       ScrArea *sa1, *sa2;
-       sAreaJoinData* jd= NULL;
-       int x1, y1;
-       int x2, y2;
-
-       /* required properties, make negative to get return 0 if not set by caller */
-       OP_verify_int(op, "x1", -100, &x1);
-       OP_verify_int(op, "y1", -100, &y1);
-       OP_verify_int(op, "x2", -100, &x2);
-       OP_verify_int(op, "y2", -100, &y2);
-       
-       sa1 = screen_areahascursor(C->screen, x1, y1);
-       sa2 = screen_areahascursor(C->screen, x2, y2);
-       if(sa1==NULL || sa2==NULL || sa1==sa2)
-               return 0;
-
-       jd = (sAreaJoinData*)MEM_callocN(sizeof (sAreaJoinData), "op_join_areas");
-               
-       jd->sa1 = sa1;
-       jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
-       jd->sa2 = sa2;
-       jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
+       ScrArea *sa= CTX_wm_area(C);
        
-       op->customdata= jd;
+       ED_area_prevspace(C);
        
-       return 1;
+       if(sa->full)
+               ed_screen_fullarea(C, sa);
 }
 
-/* apply the join of the areas (space types) */
-static int join_areas_apply(bContext *C, wmOperator *op)
+/* redraws: uses defines from stime->redraws 
+ * enable: 1 - forward on, -1 - backwards on, 0 - off
+ */
+void ED_screen_animation_timer(bContext *C, int redraws, int enable)
 {
-       sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
-       if (!jd) return 0;
-
-       if(!screen_join_areas(C->screen,jd->sa1,jd->sa2)){
-               return 0;
-       }
-       if (C->area == jd->sa2) {
-               C->area = NULL;
+       bScreen *screen= CTX_wm_screen(C);
+       wmWindow *win= CTX_wm_window(C);
+       Scene *scene= CTX_data_scene(C);
+       
+       if(screen->animtimer)
+               WM_event_remove_window_timer(win, screen->animtimer);
+       screen->animtimer= NULL;
+       
+       if(enable) {
+               struct ScreenAnimData *sad= MEM_mallocN(sizeof(ScreenAnimData), "ScreenAnimData");
+               
+               screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));
+               sad->ar= CTX_wm_region(C);
+               sad->redraws= redraws;
+               sad->flag= (enable < 0) ? ANIMPLAY_FLAG_REVERSE : 0;
+               screen->animtimer->customdata= sad;
+               
        }
-
-       return 1;
+       /* notifier catched by top header, for button */
+       WM_event_add_notifier(C, NC_SCREEN|ND_ANIMPLAY, screen);
 }
 
-/* finish operation */
-static void join_areas_exit(bContext *C, wmOperator *op)
+unsigned int ED_screen_view3d_layers(bScreen *screen)
 {
-       if (op->customdata) {
-               MEM_freeN(op->customdata);
-               op->customdata = NULL;
+       if(screen) {
+               unsigned int layer= screen->scene->lay; /* as minimum this */
+               ScrArea *sa;
+               
+               /* get all used view3d layers */
+               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                       if(sa->spacetype==SPACE_VIEW3D)
+                               layer |= ((View3D *)sa->spacedata.first)->lay;
+               }
+               return layer;
        }
-
-       /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scredges(C->screen);
-       removenotused_scredges(C->screen);
-       removenotused_scrverts(C->screen);
+       return 0;
 }
 
-static int join_areas_exec(bContext *C, wmOperator *op)
-{
-       if(!join_areas_init(C, op)) 
-               return OPERATOR_CANCELLED;
-       
-       join_areas_apply(C, op);
-       join_areas_exit(C, op);
 
-       return OPERATOR_FINISHED;
-}
-
-/* interaction callback */
-static int join_areas_invoke(bContext *C, wmOperator *op, wmEvent *event)
+/* results in fully updated anim system */
+void ED_update_for_newframe(const bContext *C, int mute)
 {
-
-       if(event->type==EVT_ACTIONZONE) {
-               sActionzoneData *sad= event->customdata;
-               
-               /* verify *sad itself */
-               if(sad==NULL || sad->sa1==NULL || sad->sa2==NULL)
-                       return OPERATOR_PASS_THROUGH;
-               
-               /* is this our *sad? if areas equal it should be passed on */
-               if(sad->sa1==sad->sa2)
-                       return OPERATOR_PASS_THROUGH;
-               
-               /* prepare operator state vars */
-               OP_set_int(op, "x1", sad->x);
-               OP_set_int(op, "y1", sad->y);
-               OP_set_int(op, "x2", event->x);
-               OP_set_int(op, "y2", event->y);
-
-               if(!join_areas_init(C, op)) 
-                       return OPERATOR_PASS_THROUGH;
+       bScreen *screen= CTX_wm_screen(C);
+       Scene *scene= screen->scene;
        
-               /* add temp handler */
-               WM_event_add_modal_handler(&C->window->handlers, op);
+       //extern void audiostream_scrub(unsigned int frame);    /* seqaudio.c */
        
-               return OPERATOR_RUNNING_MODAL;
-       }
+       /* this function applies the changes too */
+       /* XXX future: do all windows */
+       scene_update_for_newframe(scene, ED_screen_view3d_layers(screen)); /* BKE_scene.h */
        
-       return OPERATOR_PASS_THROUGH;
-}
-
-static int join_areas_cancel(bContext *C, wmOperator *op)
-{
-       sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
-
-       if (jd->sa1) {
-               jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
-               jd->sa1->flag &= ~AREA_FLAG_DRAWJOINTO;
-       }
-       if (jd->sa2) {
-               jd->sa2->flag &= ~AREA_FLAG_DRAWJOINFROM;
-               jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-       }
-
-       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
-       WM_event_remove_modal_handler(&C->window->handlers, op);                        
+       //if ( (CFRA>1) && (!mute) && (scene->audio.flag & AUDIO_SCRUB)) 
+       //      audiostream_scrub( CFRA );
        
-       join_areas_exit(C, op);
-
-       return OPERATOR_CANCELLED;
-}
-
-/* modal callback while selecting area (space) that will be removed */
-static int join_areas_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
-       sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
+       /* 3d window, preview */
+       //BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
        
-       /* execute the events */
-       switch(event->type) {
-                       
-               case MOUSEMOVE: 
-                       {
-                               ScrArea *sa = screen_areahascursor(C->screen, event->x, event->y);
-                               int dir;
-                               
-                               if (sa) {                                       
-                                       if (jd->sa1 != sa) {
-                                               dir = area_getorientation(C->screen, jd->sa1, sa);
-                                               if (dir >= 0) {
-                                                       if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-                                                       jd->sa2 = sa;
-                                                       jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
-                                               } 
-                                               else {
-                                                       /* we are not bordering on the previously selected area 
-                                                          we check if area has common border with the one marked for removal
-                                                          in this case we can swap areas.
-                                                       */
-                                                       dir = area_getorientation(C->screen, sa, jd->sa2);
-                                                       if (dir >= 0) {
-                                                               if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
-                                                               if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-                                                               jd->sa1 = jd->sa2;
-                                                               jd->sa2 = sa;
-                                                               if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
-                                                               if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
-                                                       } 
-                                                       else {
-                                                               if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-                                                               jd->sa2 = NULL;
-                                                       }
-                                               }
-                                               WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
-                                       } 
-                                       else {
-                                               /* we are back in the area previously selected for keeping 
-                                                * we swap the areas if possible to allow user to choose */
-                                               if (jd->sa2 != NULL) {
-                                                       if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
-                                                       if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-                                                       jd->sa1 = jd->sa2;
-                                                       jd->sa2 = sa;
-                                                       if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
-                                                       if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
-                                                       dir = area_getorientation(C->screen, jd->sa1, jd->sa2);
-                                                       if (dir < 0) {
-                                                               printf("oops, didn't expect that!\n");
-                                                       }
-                                               } 
-                                               else {
-                                                       dir = area_getorientation(C->screen, jd->sa1, sa);
-                                                       if (dir >= 0) {
-                                                               if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
-                                                               jd->sa2 = sa;
-                                                               jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
-                                                       }
-                                               }
-                                               WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_WINDOW_REDRAW, 0, NULL);
-                                       }
-                               }
-                       }
-                       break;
-               case LEFTMOUSE:
-                       if(event->val==0) {
-                               join_areas_apply(C, op);
-                               WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
-                               join_areas_exit(C, op);
-                               WM_event_remove_modal_handler(&C->window->handlers, op);
-                               return OPERATOR_FINISHED;
+       /* all movie/sequence images */
+       //BIF_image_update_frame();
+       
+       /* composite */
+       if(scene->use_nodes && scene->nodetree)
+               ntreeCompositTagAnimated(scene->nodetree);
+       
+       /* update animated texture nodes */
+       {
+               Tex *tex;
+               for(tex= CTX_data_main(C)->tex.first; tex; tex= tex->id.next)
+                       if( tex->use_nodes && tex->nodetree ) {
+                               ntreeTexTagAnimated( tex->nodetree );
                        }
-                       break;
-                       
-               case ESCKEY:
-                       return join_areas_cancel(C, op);
        }
-
-       return OPERATOR_RUNNING_MODAL;
 }
 
-/* Operator for joining two areas (space types) */
-void ED_SCR_OT_join_areas(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Join area";
-       ot->idname= "ED_SCR_OT_join_areas";
-       
-       /* api callbacks */
-       ot->exec= join_areas_exec;
-       ot->invoke= join_areas_invoke;
-       ot->cancel= join_areas_cancel;
-       ot->modal= join_areas_modal;
-
-       ot->poll= ED_operator_screenactive;
-}