doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / screen / area.c
index 08a05f4..4ddb5d0 100644 (file)
@@ -1,5 +1,5 @@
-/**
- * $Id:
+/*
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008 Blender Foundation.
  * All rights reserved.
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_screen_types.h"
 #include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
-#include "BKE_utildefines.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -49,7 +48,9 @@
 
 #include "ED_screen.h"
 #include "ED_screen_types.h"
+#include "ED_space_api.h"
 #include "ED_types.h"
+#include "ED_fileselect.h" 
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
-#ifndef DISABLE_PYTHON
-#include "BPY_extern.h"
-#endif
-
 #include "screen_intern.h"
 
 /* general area and region code */
@@ -106,7 +103,7 @@ void ED_region_pixelspace(ARegion *ar)
        int height= ar->winrct.ymax-ar->winrct.ymin+1;
        
        wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
-       wmLoadIdentity();
+       glLoadIdentity();
 }
 
 /* only exported for WM */
@@ -121,14 +118,10 @@ void ED_region_do_listen(ARegion *ar, wmNotifier *note)
                case NC_WINDOW:
                        ED_region_tag_redraw(ar);
                        break;
-               case NC_SCREEN:
-                       if(note->action==NA_EDITED)
-                               ED_region_tag_redraw(ar);
-                       /* pass on */
-               default:
-                       if(ar->type && ar->type->listener)
-                               ar->type->listener(ar, note);
        }
+
+       if(ar->type && ar->type->listener)
+               ar->type->listener(ar, note);
 }
 
 /* only exported for WM */
@@ -152,7 +145,7 @@ void ED_area_do_refresh(bContext *C, ScrArea *sa)
 
 /* based on screen region draw tags, set draw tags in azones, and future region tabs etc */
 /* only exported for WM */
-void ED_area_overdraw_flush(bContext *C, ScrArea *sa, ARegion *ar)
+void ED_area_overdraw_flush(ScrArea *sa, ARegion *ar)
 {
        AZone *az;
        
@@ -171,27 +164,26 @@ void ED_area_overdraw_flush(bContext *C, ScrArea *sa, ARegion *ar)
 
 static void area_draw_azone(short x1, short y1, short x2, short y2)
 {
-       float xmin = x1;
-       float xmax = x2-2;
-       float ymin = y1-1;
-       float ymax = y2-3;
-       
-       float dx= 0.3f*(xmax-xmin);
-       float dy= 0.3f*(ymax-ymin);
+       int dx= floor(0.3f*(x2-x1));
+       int dy= floor(0.3f*(y2-y1));
        
+       glColor4ub(255, 255, 255, 180);
+       fdrawline(x1, y2, x2, y1);
+       glColor4ub(255, 255, 255, 130);
+       fdrawline(x1, y2-dy, x2-dx, y1);
        glColor4ub(255, 255, 255, 80);
-       fdrawline(xmin, ymax, xmax, ymin);
-       fdrawline(xmin, ymax-dy, xmax-dx, ymin);
-       fdrawline(xmin, ymax-2*dy, xmax-2*dx, ymin);
+       fdrawline(x1, y2-2*dy, x2-2*dx, y1);
        
+       glColor4ub(0, 0, 0, 210);
+       fdrawline(x1, y2+1, x2+1, y1);
+       glColor4ub(0, 0, 0, 180);
+       fdrawline(x1, y2-dy+1, x2-dx+1, y1);
        glColor4ub(0, 0, 0, 150);
-       fdrawline(xmin, ymax+1, xmax+1, ymin);
-       fdrawline(xmin, ymax-dy+1, xmax-dx+1, ymin);
-       fdrawline(xmin, ymax-2*dy+1, xmax-2*dx+1, ymin);
+       fdrawline(x1, y2-2*dy+1, x2-2*dx+1, y1);
 }
 
 
-static void region_draw_azone(ScrArea *sa, AZone *az)
+static void region_draw_azone(AZone *az)
 {
        GLUquadricObj *qobj = NULL; 
        short midx = az->x1 + (az->x2 - az->x1)/2;
@@ -251,7 +243,7 @@ void ED_area_overdraw(bContext *C)
                                if(az->type==AZONE_AREA) {
                                        area_draw_azone(az->x1, az->y1, az->x2, az->y2);
                                } else if(az->type==AZONE_REGION) {
-                                       region_draw_azone(sa, az);
+                                       region_draw_azone(az);
                                }
                                
                                az->do_draw= 0;
@@ -338,17 +330,17 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
        
        /* optional header info instead? */
        if(ar->headerstr) {
-               float col[3];
-               UI_GetThemeColor3fv(TH_HEADER, col);
-               glClearColor(col[0], col[1], col[2], 0.0);
+               UI_ThemeClearColor(TH_HEADER);
                glClear(GL_COLOR_BUFFER_BIT);
                
                UI_ThemeColor(TH_TEXT);
-               BLF_draw_default(20, 8, 0.0f, ar->headerstr);
+               BLF_draw_default(20, 8, 0.0f, ar->headerstr, 65535); /* XXX, use real length */
        }
        else if(at->draw) {
                at->draw(C, ar);
        }
+
+       ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
        
        uiFreeInactiveBlocks(C, &ar->uiblocks);
        
@@ -371,17 +363,23 @@ void ED_region_tag_redraw(ARegion *ar)
 {
        if(ar) {
                /* zero region means full region redraw */
-               ar->do_draw= 1;
+               ar->do_draw= RGN_DRAW;
                memset(&ar->drawrct, 0, sizeof(ar->drawrct));
        }
 }
 
+void ED_region_tag_redraw_overlay(ARegion *ar)
+{
+       if(ar)
+               ar->do_draw_overlay= RGN_DRAW;
+}
+
 void ED_region_tag_redraw_partial(ARegion *ar, rcti *rct)
 {
        if(ar) {
                if(!ar->do_draw) {
                        /* no redraw set yet, set partial region */
-                       ar->do_draw= 1;
+                       ar->do_draw= RGN_DRAW_PARTIAL;
                        ar->drawrct= *rct;
                }
                else if(ar->drawrct.xmin != ar->drawrct.xmax) {
@@ -403,6 +401,19 @@ void ED_area_tag_redraw(ScrArea *sa)
                        ED_region_tag_redraw(ar);
 }
 
+void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype)
+{
+       ARegion *ar;
+       
+       if(sa) {
+               for(ar= sa->regionbase.first; ar; ar= ar->next) {
+                       if(ar->regiontype == regiontype) {
+                               ED_region_tag_redraw(ar);
+                       }
+               }
+       }
+}
+
 void ED_area_tag_refresh(ScrArea *sa)
 {
        if(sa)
@@ -435,7 +446,6 @@ void ED_area_headerprint(ScrArea *sa, const char *str)
 /* ************************************************************ */
 
 
-#define AZONESPOT              12
 static void area_azone_initialize(ScrArea *sa) 
 {
        AZone *az;
@@ -449,8 +459,8 @@ static void area_azone_initialize(ScrArea *sa)
        az->type= AZONE_AREA;
        az->x1= sa->totrct.xmin;
        az->y1= sa->totrct.ymin;
-       az->x2= sa->totrct.xmin + AZONESPOT-1;
-       az->y2= sa->totrct.ymin + AZONESPOT-1;
+       az->x2= sa->totrct.xmin + AZONESPOT;
+       az->y2= sa->totrct.ymin + AZONESPOT;
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
        
        az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
@@ -458,38 +468,40 @@ static void area_azone_initialize(ScrArea *sa)
        az->type= AZONE_AREA;
        az->x1= sa->totrct.xmax+1;
        az->y1= sa->totrct.ymax+1;
-       az->x2= sa->totrct.xmax-AZONESPOT+1;
-       az->y2= sa->totrct.ymax-AZONESPOT+1;
+       az->x2= sa->totrct.xmax-AZONESPOT;
+       az->y2= sa->totrct.ymax-AZONESPOT;
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
 }
 
 #define AZONEPAD_EDGE  4
-#define AZONEPAD_ICON  8
+#define AZONEPAD_ICON  9
 static void region_azone_edge(AZone *az, ARegion *ar)
 {
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymax;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
-               az->x2= ar->winrct.xmax;
-               az->y2= ar->winrct.ymin;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax;
-               az->y1= ar->winrct.ymin;
-               az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
-               az->y2= ar->winrct.ymax;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymax - AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin + AZONEPAD_EDGE;
+                       az->x2= ar->winrct.xmax;
+                       az->y2= ar->winrct.ymin;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmin + AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax;
+                       az->y1= ar->winrct.ymin;
+                       az->x2= ar->winrct.xmax - AZONEPAD_EDGE;
+                       az->y2= ar->winrct.ymax;
+                       break;
        }
 
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
@@ -500,33 +512,38 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
        AZone *azt;
        int tot=0;
        
+       /* count how many actionzones with along same edge are available.
+          This allows for adding more action zones in the future without
+          having to worry about correct offset */
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
                if(azt->edge == az->edge) tot++;
        }
        
-       if(az->edge=='t') {
-               az->x1= ar->winrct.xmax - tot*2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax + AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax - tot*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax + 2*AZONEPAD_ICON;
-       }
-       else if(az->edge=='b') {
-               az->x1= ar->winrct.xmin + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymin - AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymin - 2*AZONEPAD_ICON;
-       }
-       else if(az->edge=='l') {
-               az->x1= ar->winrct.xmin - 2*AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmin - AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
-       }
-       else { // if(az->edge=='r') {
-               az->x1= ar->winrct.xmax + AZONEPAD_ICON;
-               az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
-               az->x2= ar->winrct.xmax + 2*AZONEPAD_ICON;
-               az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+       switch(az->edge) {
+               case AE_TOP_TO_BOTTOMRIGHT:
+                       az->x1= ar->winrct.xmax - tot*2*AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax + AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmax - tot*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax + 2*AZONEPAD_ICON;
+                       break;
+               case AE_BOTTOM_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmin + AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymin - 2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmin + 2*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymin - AZONEPAD_ICON;
+                       break;
+               case AE_LEFT_TO_TOPRIGHT:
+                       az->x1= ar->winrct.xmin - 2*AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmin - AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+                       break;
+               case AE_RIGHT_TO_TOPLEFT:
+                       az->x1= ar->winrct.xmax + AZONEPAD_ICON;
+                       az->y1= ar->winrct.ymax - tot*2*AZONEPAD_ICON;
+                       az->x2= ar->winrct.xmax + 2*AZONEPAD_ICON;
+                       az->y2= ar->winrct.ymax - tot*AZONEPAD_ICON;
+                       break;
        }
 
        BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
@@ -535,22 +552,21 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
        for(azt= sa->actionzones.first; azt; azt= azt->next) {
                if(az!=azt) {
                        if( ABS(az->x1-azt->x1) < 2 && ABS(az->y1-azt->y1) < 2) {
-                               if(az->edge=='t' || az->edge=='b') {
+                               if(az->edge==AE_TOP_TO_BOTTOMRIGHT || az->edge==AE_BOTTOM_TO_TOPLEFT) {
                                        az->x1+= AZONESPOT;
                                        az->x2+= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                                }
-                               else {
+                               else{
                                        az->y1-= AZONESPOT;
                                        az->y2-= AZONESPOT;
-                                       BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                                }
+                               BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2);
                        }
                }
        }
 }
 
-static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge) 
+static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge) 
 {
        AZone *az;
        
@@ -573,17 +589,16 @@ static void region_azone_initialize(ScrArea *sa, ARegion *ar, char edge)
 
 static void region_azone_add(ScrArea *sa, ARegion *ar, int alignment)
 {
-        /* edge code (t b l r) is where azone will be drawn */
+        /* edge code (t b l r) is along which area edge azone will be drawn */
        
        if(alignment==RGN_ALIGN_TOP)
-               region_azone_initialize(sa, ar, 'b');
+               region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT);
        else if(alignment==RGN_ALIGN_BOTTOM)
-               region_azone_initialize(sa, ar, 't');
+               region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_RIGHT, RGN_OVERLAP_RIGHT))
-               region_azone_initialize(sa, ar, 'l');
+               region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT);
        else if(ELEM(alignment, RGN_ALIGN_LEFT, RGN_OVERLAP_LEFT))
-               region_azone_initialize(sa, ar, 'r');
-                                                               
+               region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT);
 }
 
 /* dir is direction to check, not the splitting edge direction! */
@@ -622,8 +637,8 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int
        if(ar->next==NULL && alignment!=RGN_ALIGN_QSPLIT)
                alignment= RGN_ALIGN_NONE;
        
-       prefsizex= ar->type->minsizex;
-       prefsizey= ar->type->minsizey;
+       prefsizex= ar->sizex?ar->sizex:ar->type->prefsizex;
+       prefsizey= ar->sizey?ar->sizey:ar->type->prefsizey;
        
        /* hidden is user flag */
        if(ar->flag & RGN_FLAG_HIDDEN);
@@ -726,7 +741,8 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int
                        if(count!=4) {
                                /* let's stop adding regions */
                                BLI_init_rcti(remainder, 0, 0, 0, 0);
-                               printf("region quadsplit failed\n");
+                               if (G.f & G_DEBUG)
+                                       printf("region quadsplit failed\n");
                        }
                        else quad= 1;
                }
@@ -809,7 +825,7 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
 
 
 /* used for area initialize below */
-static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
+static void region_subwindow(wmWindow *win, ARegion *ar)
 {
        if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
                if(ar->swinid)
@@ -828,29 +844,40 @@ static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int fla
        
        // XXX it would be good to have boundbox checks for some of these...
        if(flag & ED_KEYMAP_UI) {
+               /* user interface widgets */
                UI_add_region_handlers(handlers);
        }
        if(flag & ED_KEYMAP_VIEW2D) {
+               /* 2d-viewport handling+manipulation */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "View2D", 0, 0);
                WM_event_add_keymap_handler(handlers, keymap);
        }
        if(flag & ED_KEYMAP_MARKERS) {
+               /* time-markers */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
                WM_event_add_keymap_handler(handlers, keymap);
                // XXX need boundbox check urgently!!!
        }
        if(flag & ED_KEYMAP_ANIMATION) {
+               /* frame changing and timeline operators (for time spaces) */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Animation", 0, 0);
                WM_event_add_keymap_handler(handlers, keymap);
        }
        if(flag & ED_KEYMAP_FRAMES) {
+               /* frame changing/jumping (for all spaces) */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
                WM_event_add_keymap_handler(handlers, keymap);
        }
        if(flag & ED_KEYMAP_GPENCIL) {
+               /* grease pencil */
                wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
                WM_event_add_keymap_handler(handlers, keymap);
        }
+       if(flag & ED_KEYMAP_HEADER) {
+               /* standard keymap for headers regions */
+               wmKeyMap *keymap= WM_keymap_find(wm->defaultconf, "Header", 0, 0);
+               WM_event_add_keymap_handler(handlers, keymap);
+       }
 }
 
 
@@ -889,12 +916,12 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        
        /* region windows, default and own handlers */
        for(ar= sa->regionbase.first; ar; ar= ar->next) {
-               region_subwindow(wm, win, ar);
+               region_subwindow(win, ar);
                
                if(ar->swinid) {
                        /* default region handlers */
                        ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
-
+                       /* own handlers */
                        if(ar->type->init)
                                ar->type->init(wm, ar);
                }
@@ -912,15 +939,14 @@ void ED_region_init(bContext *C, ARegion *ar)
 //     ARegionType *at= ar->type;
        
        /* refresh can be called before window opened */
-       region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
+       region_subwindow(CTX_wm_window(C), ar);
        
        ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
        ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
        
        /* UI convention */
-       wmLoadIdentity();
        wmOrtho2(-0.01f, ar->winx-0.01f, -0.01f, ar->winy-0.01f);
-       
+       glLoadIdentity();
 }
 
 void ED_region_toggle_hidden(bContext *C, ARegion *ar)
@@ -928,7 +954,6 @@ void ED_region_toggle_hidden(bContext *C, ARegion *ar)
        ScrArea *sa= CTX_wm_area(C);
 
        ar->flag ^= RGN_FLAG_HIDDEN;
-       ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
 
        if(ar->flag & RGN_FLAG_HIDDEN)
                WM_event_remove_handlers(C, &ar->handlers);
@@ -943,6 +968,7 @@ void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
 {
        SpaceType *st;
        ARegion *ar;
+       int spacetype= sa1->spacetype;
        
        sa1->headertype= sa2->headertype;
        sa1->spacetype= sa2->spacetype;
@@ -970,7 +996,7 @@ void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
        }
        else {
                if(swap_space<2) {
-                       st= BKE_spacetype_from_id(sa1->spacetype);
+                       st= BKE_spacetype_from_id(spacetype);
                        for(ar= sa1->regionbase.first; ar; ar= ar->next)
                                BKE_area_region_free(st, ar);
                        BLI_freelistN(&sa1->regionbase);
@@ -993,10 +1019,6 @@ void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
        ED_area_exit(C, sa1);
        ED_area_exit(C, sa2);
 
-       tmp->spacetype= sa1->spacetype;
-       tmp->butspacetype= sa1->butspacetype;
-       BKE_spacedata_copyfirst(&tmp->spacedata, &sa1->spacedata);
-
        area_copy_data(tmp, sa1, 2);
        area_copy_data(sa1, sa2, 0);
        area_copy_data(sa2, tmp, 0);
@@ -1072,36 +1094,22 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type)
                
                /* tell WM to refresh, cursor types etc */
                WM_event_add_mousemove(C);
+                               
+               /*send space change notifyer*/
+               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, sa);
                
-               ED_area_tag_redraw(sa);
                ED_area_tag_refresh(sa);
        }
+       
+       /* also redraw when re-used */
+       ED_area_tag_redraw(sa);
 }
 
-void ED_area_prevspace(bContext *C)
+void ED_area_prevspace(bContext *C, ScrArea *sa)
 {
-       SpaceLink *sl= CTX_wm_space_data(C);
-       ScrArea *sa= CTX_wm_area(C);
-
-       /* cleanup */
-#if 0 // XXX needs to be space type specific
-       if(sfile->spacetype==SPACE_FILE) {
-               if(sfile->pupmenu) {
-                       MEM_freeN(sfile->pupmenu);
-                       sfile->pupmenu= NULL;
-               }
-       }
-#endif
+       SpaceLink *sl = (sa) ? sa->spacedata.first : CTX_wm_space_data(C);
 
        if(sl->next) {
-
-#if 0 // XXX check whether this is still needed
-               if (sfile->spacetype == SPACE_SCRIPT) {
-                       SpaceScript *sc = (SpaceScript *)sfile;
-                       if (sc->script) sc->script->flags &=~SCRIPT_FILESEL;
-               }
-#endif
-
                /* workaround for case of double prevspace, render window
                   with a file browser on top of it */
                if(sl->next->spacetype == SPACE_FILE && sl->next->next)
@@ -1113,12 +1121,15 @@ void ED_area_prevspace(bContext *C)
                ED_area_newspace(C, sa, SPACE_INFO);
        }
        ED_area_tag_redraw(sa);
+
+       /*send space change notifyer*/
+       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, sa);
 }
 
-static char *windowtype_pup(void)
+static const char *editortype_pup(void)
 {
        return(
-                  "Window type:%t"
+                  "Editor type:%t"
                   "|3D View %x1"
 
                   "|%l"
@@ -1150,14 +1161,17 @@ static char *windowtype_pup(void)
                   
                   "|%l"
                   
-                  "|Console %x18"
+                  "|Python Console %x18"
                   );
 }
 
-static void spacefunc(struct bContext *C, void *arg1, void *arg2)
+static void spacefunc(struct bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
 {
        ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
        ED_area_tag_redraw(CTX_wm_area(C));
+
+       /*send space change notifyer*/
+       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CHANGED, CTX_wm_area(C));
 }
 
 /* returns offset for next button in header */
@@ -1168,10 +1182,10 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
        int xco= 8;
        
        but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
-                                                  windowtype_pup(), xco, yco, XIC+10, YIC, 
+                                                  editortype_pup(), xco, yco, XIC+10, YIC, 
                                                   &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
-                                                  "Displays Current Window Type. "
-                                                  "Click for menu of available types.");
+                                                  "Displays current editor type. "
+                                                  "Click for menu of available types");
        uiButSetFunc(but, spacefunc, NULL, NULL);
        
        return xco + XIC + 14;
@@ -1182,7 +1196,8 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
        ScrArea *sa= CTX_wm_area(C);
        int xco= 8;
        
-       xco= ED_area_header_switchbutton(C, block, yco);
+       if (!sa->full)
+               xco= ED_area_header_switchbutton(C, block, yco);
 
        uiBlockSetEmboss(block, UI_EMBOSSN);
 
@@ -1208,7 +1223,7 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
 
 /************************ standard UI regions ************************/
 
-void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *context, int contextnr)
+void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
 {
        ScrArea *sa= CTX_wm_area(C);
        uiStyle *style= U.uistyles.first;
@@ -1217,7 +1232,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
        Panel *panel;
        View2D *v2d= &ar->v2d;
        View2DScrollers *scrollers;
-       float col[3];
        int xco, yco, x, y, miny=0, w, em, header, triangle, open, newcontext= 0;
 
        if(contextnr >= 0)
@@ -1225,11 +1239,11 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
 
        if(vertical) {
                w= v2d->cur.xmax - v2d->cur.xmin;
-               em= (ar->type->minsizex)? 10: 20;
+               em= (ar->type->prefsizex)? 10: 20;
        }
        else {
                w= UI_PANEL_WIDTH;
-               em= (ar->type->minsizex)? 10: 20;
+               em= (ar->type->prefsizex)? 10: 20;
        }
 
        x= 0;
@@ -1239,7 +1253,7 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
        uiBeginPanels(C, ar);
 
        /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, v2d);
+       UI_view2d_view_ortho(v2d);
 
        for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
                /* verify context */
@@ -1270,6 +1284,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                                panel->labelofs= xco - triangle;
                                panel->layout= NULL;
                        }
+                       else {
+                               panel->labelofs= 0;
+                       }
 
                        if(open) {
                                short panelContext;
@@ -1323,15 +1340,16 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
        }
 
        /* clear */
-       UI_GetThemeColor3fv(TH_BACK, col);
-       glClearColor(col[0], col[1], col[2], 0.0);
+       UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW)?TH_PREVIEW_BACK:TH_BACK);
        glClear(GL_COLOR_BUFFER_BIT);
-
+       
        /* before setting the view */
        if(vertical) {
                /* only allow scrolling in vertical direction */
                v2d->keepofs |= V2D_LOCKOFS_X|V2D_KEEPOFS_Y;
                v2d->keepofs &= ~(V2D_LOCKOFS_Y|V2D_KEEPOFS_X);
+               v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
+               v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
                
                // don't jump back when panels close or hide
                if(!newcontext)
@@ -1346,6 +1364,8 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
                v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_LOCKOFS_Y|V2D_KEEPOFS_X|V2D_KEEPOFS_Y);
                //v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
                //v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
+               v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
+               v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_HIDE;
                
                // don't jump back when panels close or hide
                if(!newcontext)
@@ -1357,7 +1377,7 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
        UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
 
        /* set the view */
-       UI_view2d_view_ortho(C, v2d);
+       UI_view2d_view_ortho(v2d);
 
        /* this does the actual drawing! */
        uiEndPanels(C, ar);
@@ -1378,6 +1398,8 @@ void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
        // XXX quick hacks for files saved with 2.5 already (i.e. the builtin defaults file)
                // scrollbars for button regions
        ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); 
+       ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
+       ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
        ar->v2d.keepzoom |= V2D_KEEPZOOM;
 
                // correctly initialised User-Prefs?
@@ -1397,27 +1419,21 @@ void ED_region_header(const bContext *C, ARegion *ar)
        uiLayout *layout;
        HeaderType *ht;
        Header header = {0};
-       float col[3];
        int maxco, xco, yco;
 
-       /* clear */
-       if(ED_screen_area_active(C))
-               UI_GetThemeColor3fv(TH_HEADER, col);
-       else
-               UI_GetThemeColor3fv(TH_HEADERDESEL, col);
-       
-       glClearColor(col[0], col[1], col[2], 0.0);
+       /* clear */     
+       UI_ThemeClearColor((ED_screen_area_active(C))?TH_HEADER:TH_HEADERDESEL);
        glClear(GL_COLOR_BUFFER_BIT);
        
        /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, &ar->v2d);
+       UI_view2d_view_ortho(&ar->v2d);
 
        xco= maxco= 8;
        yco= HEADERY-3;
 
        /* draw all headers types */
        for(ht= ar->type->headertypes.first; ht; ht= ht->next) {
-               block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
+               block= uiBeginBlock(C, ar, ht->idname, UI_EMBOSS);
                layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, HEADERY-6, 1, style);
 
                if(ht->draw) {