5aa8a5b466bf9cd08a99f5bcdc48006627c30aa0
[blender.git] / source / blender / editors / screen / area.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "BLI_blenlib.h"
35 #include "BLI_arithb.h"
36 #include "BLI_rand.h"
37
38 #include "BKE_context.h"
39 #include "BKE_global.h"
40 #include "BKE_screen.h"
41 #include "BKE_utildefines.h"
42
43 #include "WM_api.h"
44 #include "WM_types.h"
45 #include "wm_subwindow.h"
46
47 #include "ED_screen.h"
48 #include "ED_screen_types.h"
49 #include "ED_types.h"
50
51 #include "BIF_gl.h"
52 #include "BIF_glutil.h"
53
54 #include "UI_interface.h"
55 #include "UI_resources.h"
56 #include "UI_view2d.h"
57
58 #include "BMF_Api.h"
59
60 #ifndef DISABLE_PYTHON
61 #include "BPY_extern.h"
62 #endif
63
64 #include "screen_intern.h"
65
66 /* general area and region code */
67
68 static void region_draw_emboss(ARegion *ar)
69 {
70         short winx, winy;
71         
72         winx= ar->winrct.xmax-ar->winrct.xmin;
73         winy= ar->winrct.ymax-ar->winrct.ymin;
74         
75         /* set transp line */
76         glEnable( GL_BLEND );
77         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
78         
79         /* right  */
80         glColor4ub(0,0,0, 50);
81         sdrawline(winx, 0, winx, winy);
82         
83         /* bottom  */
84         glColor4ub(0,0,0, 80);
85         sdrawline(0, 0, winx, 0);
86         
87         /* top  */
88         glColor4ub(255,255,255, 60);
89         sdrawline(0, winy, winx, winy);
90
91         /* left  */
92         glColor4ub(255,255,255, 50);
93         sdrawline(0, 0, 0, winy);
94         
95         glDisable( GL_BLEND );
96 }
97
98 void ED_region_pixelspace(ARegion *ar)
99 {
100         int width= ar->winrct.xmax-ar->winrct.xmin+1;
101         int height= ar->winrct.ymax-ar->winrct.ymin+1;
102         
103         wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
104         wmLoadIdentity();
105 }
106
107 /* only exported for WM */
108 void ED_region_do_listen(ARegion *ar, wmNotifier *note)
109 {
110         /* generic notes first */
111         switch(note->category) {
112                 case NC_WINDOW:
113                         ED_region_tag_redraw(ar);
114                         break;
115                 case NC_SCREEN:
116                         if(note->action==NA_EDITED)
117                                 ED_region_tag_redraw(ar);
118                         break;
119                 default:
120                         if(ar->type && ar->type->listener)
121                                 ar->type->listener(ar, note);
122         }
123 }
124
125 /* only exported for WM */
126 void ED_area_do_listen(ScrArea *sa, wmNotifier *note)
127 {
128         /* no generic notes? */
129         if(sa->type && sa->type->listener) {
130                 sa->type->listener(sa, note);
131         }
132 }
133
134 /* only exported for WM */
135 void ED_area_do_refresh(bContext *C, ScrArea *sa)
136 {
137         /* no generic notes? */
138         if(sa->type && sa->type->refresh) {
139                 sa->type->refresh(C, sa);
140         }
141         sa->do_refresh= 0;
142 }
143
144 /* based on screen region draw tags, set draw tags in azones, and future region tabs etc */
145 /* only exported for WM */
146 void ED_area_overdraw_flush(bContext *C)
147 {
148         ScrArea *sa;
149         
150         for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
151                 ARegion *ar;
152                 
153                 for(ar= sa->regionbase.first; ar; ar= ar->next) {
154                         if(ar->do_draw) {
155                                 AZone *az;
156                                 
157                                 for(az= sa->actionzones.first; az; az= az->next) {
158                                         int xs= (az->x1+az->x2)/2, ys= (az->y1+az->y2)/2;
159                 
160                                         /* test if inside */
161                                         if(BLI_in_rcti(&ar->winrct, xs, ys)) {
162                                                 az->do_draw= 1;
163                                         }
164                                 }
165                         }
166                 }
167         }       
168 }
169
170 /* only exported for WM */
171 void ED_area_overdraw(bContext *C)
172 {
173         wmWindow *win= CTX_wm_window(C);
174         bScreen *screen= CTX_wm_screen(C);
175         ScrArea *sa;
176         
177         /* Draw AZones, in screenspace */
178         wmSubWindowSet(win, screen->mainwin);
179
180         glEnable( GL_BLEND );
181         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
182         
183         for(sa= screen->areabase.first; sa; sa= sa->next) {
184                 AZone *az;
185                 for(az= sa->actionzones.first; az; az= az->next) {
186                         if(az->do_draw) {
187                                 if(az->type==AZONE_TRI) {
188                                         glColor4ub(0, 0, 0, 70);
189                                         sdrawtrifill(az->x1, az->y1, az->x2, az->y2);
190                                 }
191                                 az->do_draw= 0;
192                         }
193                 }
194         }       
195         glDisable( GL_BLEND );
196         
197 }
198
199 /* only exported for WM */
200 void ED_region_do_draw(bContext *C, ARegion *ar)
201 {
202         wmWindow *win= CTX_wm_window(C);
203         ScrArea *sa= CTX_wm_area(C);
204         ARegionType *at= ar->type;
205         
206         /* note; this sets state, so we can use wmOrtho and friends */
207         wmSubWindowSet(win, ar->swinid);
208         
209         /* optional header info instead? */
210         if(ar->headerstr) {
211                 float col[3];
212                 UI_SetTheme(sa);
213                 UI_GetThemeColor3fv(TH_HEADER, col);
214                 glClearColor(col[0], col[1], col[2], 0.0);
215                 glClear(GL_COLOR_BUFFER_BIT);
216                 
217                 UI_ThemeColor(TH_MENU_TEXT);
218                 glRasterPos2i(20, 6);
219                 BMF_DrawString(G.font, ar->headerstr);
220         }
221         else if(at->draw) {
222                 UI_SetTheme(sa);
223                 at->draw(C, ar);
224                 UI_SetTheme(NULL);
225         }
226         
227         if(sa)
228                 region_draw_emboss(ar);
229
230         uiFreeInactiveBlocks(C, &ar->uiblocks);
231         
232         /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
233         ED_region_pixelspace(ar);
234         
235         ar->do_draw= 0;
236 }
237
238 /* **********************************
239    maybe silly, but let's try for now
240    to keep these tags protected
241    ********************************** */
242
243 void ED_region_tag_redraw(ARegion *ar)
244 {
245         if(ar)
246                 ar->do_draw= 1;
247 }
248
249 void ED_area_tag_redraw(ScrArea *sa)
250 {
251         ARegion *ar;
252         
253         if(sa)
254                 for(ar= sa->regionbase.first; ar; ar= ar->next)
255                         ar->do_draw= 1;
256 }
257
258 void ED_area_tag_refresh(ScrArea *sa)
259 {
260         if(sa)
261                 sa->do_refresh= 1;
262 }
263
264 /* *************************************************************** */
265
266 /* use NULL to disable it */
267 void ED_area_headerprint(ScrArea *sa, const char *str)
268 {
269         ARegion *ar;
270         
271         for(ar= sa->regionbase.first; ar; ar= ar->next) {
272                 if(ar->regiontype==RGN_TYPE_HEADER) {
273                         if(str) {
274                                 if(ar->headerstr==NULL)
275                                         ar->headerstr= MEM_mallocN(256, "headerprint");
276                                 BLI_strncpy(ar->headerstr, str, 256);
277                         }
278                         else if(ar->headerstr) {
279                                 MEM_freeN(ar->headerstr);
280                                 ar->headerstr= NULL;
281                         }
282                         ED_region_tag_redraw(ar);
283                 }
284         }
285 }
286
287 /* *************************************************************** */
288
289 /* dir is direction to check, not the splitting edge direction! */
290 static int rct_fits(rcti *rect, char dir, int size)
291 {
292         if(dir=='h') {
293                 return rect->xmax-rect->xmin - size;
294         }
295         else { // 'v'
296                 return rect->ymax-rect->ymin - size;
297         }
298 }
299
300 static void region_rect_recursive(ARegion *ar, rcti *remainder)
301 {
302         int prefsizex, prefsizey;
303         
304         if(ar==NULL)
305                 return;
306         
307         /* clear state flags first */
308         ar->flag &= ~RGN_FLAG_TOO_SMALL;
309         if(ar->next==NULL)
310                 ar->alignment= RGN_ALIGN_NONE;
311         
312         prefsizex= ar->type->minsizex;
313         prefsizey= ar->type->minsizey;
314         
315         /* hidden is user flag */
316         if(ar->flag & RGN_FLAG_HIDDEN);
317         /* XXX floating area region, not handled yet here */
318         else if(ar->alignment == RGN_ALIGN_FLOAT);
319         /* remainder is too small for any usage */
320         else if( rct_fits(remainder, 'v', 1)<0 || rct_fits(remainder, 'h', 1) < 0 ) {
321                 ar->flag |= RGN_FLAG_TOO_SMALL;
322         }
323         else if(ar->alignment==RGN_ALIGN_NONE) {
324                 /* typically last region */
325                 ar->winrct= *remainder;
326                 BLI_init_rcti(remainder, 0, 0, 0, 0);
327         }
328         else if(ar->alignment==RGN_ALIGN_TOP || ar->alignment==RGN_ALIGN_BOTTOM) {
329                 
330                 if( rct_fits(remainder, 'v', prefsizey) < 0 ) {
331                         ar->flag |= RGN_FLAG_TOO_SMALL;
332                 }
333                 else {
334                         int fac= rct_fits(remainder, 'v', prefsizey);
335
336                         if(fac < 0 )
337                                 prefsizey += fac;
338                         
339                         ar->winrct= *remainder;
340                         
341                         if(ar->alignment==RGN_ALIGN_TOP) {
342                                 ar->winrct.ymin= ar->winrct.ymax - prefsizey + 1;
343                                 remainder->ymax= ar->winrct.ymin - 1;
344                         }
345                         else {
346                                 ar->winrct.ymax= ar->winrct.ymin + prefsizey - 1;
347                                 remainder->ymin= ar->winrct.ymax + 1;
348                         }
349                 }
350         }
351         else if(ar->alignment==RGN_ALIGN_LEFT || ar->alignment==RGN_ALIGN_RIGHT) {
352                 
353                 if( rct_fits(remainder, 'h', prefsizex) < 0 ) {
354                         ar->flag |= RGN_FLAG_TOO_SMALL;
355                 }
356                 else {
357                         int fac= rct_fits(remainder, 'h', prefsizex);
358                         
359                         if(fac < 0 )
360                                 prefsizex += fac;
361                         
362                         ar->winrct= *remainder;
363                         
364                         if(ar->alignment==RGN_ALIGN_RIGHT) {
365                                 ar->winrct.xmin= ar->winrct.xmax - prefsizex + 1;
366                                 remainder->xmax= ar->winrct.xmin - 1;
367                         }
368                         else {
369                                 ar->winrct.xmax= ar->winrct.xmin + prefsizex - 1;
370                                 remainder->xmin= ar->winrct.xmax + 1;
371                         }
372                 }
373         }
374         else {
375                 /* percentage subdiv*/
376                 ar->winrct= *remainder;
377                 
378                 if(ar->alignment==RGN_ALIGN_HSPLIT) {
379                         if( rct_fits(remainder, 'h', prefsizex) > 4) {
380                                 ar->winrct.xmax= (remainder->xmin+remainder->xmax)/2;
381                                 remainder->xmin= ar->winrct.xmax+1;
382                         }
383                         else {
384                                 BLI_init_rcti(remainder, 0, 0, 0, 0);
385                         }
386                 }
387                 else {
388                         if( rct_fits(remainder, 'v', prefsizey) > 4) {
389                                 ar->winrct.ymax= (remainder->ymin+remainder->ymax)/2;
390                                 remainder->ymin= ar->winrct.ymax+1;
391                         }
392                         else {
393                                 BLI_init_rcti(remainder, 0, 0, 0, 0);
394                         }
395                 }
396         }
397         /* for speedup */
398         ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
399         ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
400         
401         region_rect_recursive(ar->next, remainder);
402 }
403
404 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
405 {
406         
407         if(sa->v1->vec.x>0) sa->totrct.xmin= sa->v1->vec.x+1;
408         else sa->totrct.xmin= sa->v1->vec.x;
409         if(sa->v4->vec.x<sizex-1) sa->totrct.xmax= sa->v4->vec.x-1;
410         else sa->totrct.xmax= sa->v4->vec.x;
411         
412         if(sa->v1->vec.y>0) sa->totrct.ymin= sa->v1->vec.y+1;
413         else sa->totrct.ymin= sa->v1->vec.y;
414         if(sa->v2->vec.y<sizey-1) sa->totrct.ymax= sa->v2->vec.y-1;
415         else sa->totrct.ymax= sa->v2->vec.y;
416         
417         /* for speedup */
418         sa->winx= sa->totrct.xmax-sa->totrct.xmin+1;
419         sa->winy= sa->totrct.ymax-sa->totrct.ymin+1;
420 }
421
422
423 #define AZONESPOT               12
424 void area_azone_initialize(ScrArea *sa) 
425 {
426         AZone *az;
427         if(sa->actionzones.first==NULL) {
428                 /* set action zones - should these actually be ARegions? With these we can easier check area hotzones */
429                 /* (ton) for time being just area, ARegion split is not foreseen on user level */
430                 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
431                 BLI_addtail(&(sa->actionzones), az);
432                 az->type= AZONE_TRI;
433                 az->pos= AZONE_SW;
434                 
435                 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
436                 BLI_addtail(&(sa->actionzones), az);
437                 az->type= AZONE_TRI;
438                 az->pos= AZONE_NE;
439         }
440         
441         for(az= sa->actionzones.first; az; az= az->next) {
442                 if(az->pos==AZONE_SW) {
443                         az->x1= sa->v1->vec.x+1;
444                         az->y1= sa->v1->vec.y+1;
445                         az->x2= sa->v1->vec.x+AZONESPOT;
446                         az->y2= sa->v1->vec.y+AZONESPOT;
447                 } 
448                 else if (az->pos==AZONE_NE) {
449                         az->x1= sa->v3->vec.x;
450                         az->y1= sa->v3->vec.y;
451                         az->x2= sa->v3->vec.x-AZONESPOT;
452                         az->y2= sa->v3->vec.y-AZONESPOT;
453                 }
454         }
455 }
456
457 /* used for area initialize below */
458 static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
459 {
460         if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
461                 if(ar->swinid)
462                         wm_subwindow_close(win, ar->swinid);
463                 ar->swinid= 0;
464         }
465         else if(ar->swinid==0)
466                 ar->swinid= wm_subwindow_open(win, &ar->winrct);
467         else 
468                 wm_subwindow_position(win, ar->swinid, &ar->winrct);
469 }
470
471 static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int flag)
472 {
473         /* note, add-handler checks if it already exists */
474         
475         // XXX it would be good to have boundbox checks for some of these...
476         if(flag & ED_KEYMAP_UI) {
477                 UI_add_region_handlers(handlers);
478         }
479         if(flag & ED_KEYMAP_VIEW2D) {
480                 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
481                 WM_event_add_keymap_handler(handlers, keymap);
482         }
483         if(flag & ED_KEYMAP_MARKERS) {
484                 ListBase *keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
485                 WM_event_add_keymap_handler(handlers, keymap);
486                 // XXX need boundbox check urgently!!!
487         }
488         if(flag & ED_KEYMAP_ANIMATION) {
489                 ListBase *keymap= WM_keymap_listbase(wm, "Animation", 0, 0);
490                 WM_event_add_keymap_handler(handlers, keymap);
491         }
492 }
493
494
495 /* called in screen_refresh, or screens_init, also area size changes */
496 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
497 {
498         ARegion *ar;
499         rcti rect;
500         
501         /* set typedefinitions */
502         sa->type= BKE_spacetype_from_id(sa->spacetype);
503         
504         if(sa->type==NULL) {
505                 sa->butspacetype= sa->spacetype= SPACE_VIEW3D;
506                 sa->type= BKE_spacetype_from_id(sa->spacetype);
507         }
508         
509         for(ar= sa->regionbase.first; ar; ar= ar->next)
510                 ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
511         
512         /* area sizes */
513         area_calc_totrct(sa, win->sizex, win->sizey);
514         
515         /* region rect sizes */
516         rect= sa->totrct;
517         region_rect_recursive(sa->regionbase.first, &rect);
518         
519         /* default area handlers */
520         ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
521         /* checks spacedata, adds own handlers */
522         if(sa->type->init)
523                 sa->type->init(wm, sa);
524         
525         /* region windows, default and own handlers */
526         for(ar= sa->regionbase.first; ar; ar= ar->next) {
527                 region_subwindow(wm, win, ar);
528                 
529                 /* default region handlers */
530                 ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
531
532                 if(ar->type->init)
533                         ar->type->init(wm, ar);
534                 
535         }
536         area_azone_initialize(sa);
537 }
538
539 /* externally called for floating regions like menus */
540 void ED_region_init(bContext *C, ARegion *ar)
541 {
542 //      ARegionType *at= ar->type;
543         
544         /* refresh can be called before window opened */
545         region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
546         
547 }
548
549
550 /* sa2 to sa1, we swap spaces for fullscreen to keep all allocated data */
551 /* area vertices were set */
552 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
553 {
554         ARegion *ar;
555         
556         sa1->headertype= sa2->headertype;
557         sa1->spacetype= sa2->spacetype;
558         sa1->butspacetype= sa2->butspacetype;
559         
560         if(swap_space) {
561                 SWAP(ListBase, sa1->spacedata, sa2->spacedata);
562                 /* exception: ensure preview is reset */
563 //              if(sa1->spacetype==SPACE_VIEW3D)
564 // XXX                  BIF_view3d_previewrender_free(sa1->spacedata.first);
565         }
566         else {
567                 BKE_spacedata_freelist(&sa1->spacedata);
568                 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
569         }
570         
571         /* regions... XXX */
572         BLI_freelistN(&sa1->regionbase);
573         
574         for(ar= sa2->regionbase.first; ar; ar= ar->next) {
575                 ARegion *newar= BKE_area_region_copy(ar);
576                 BLI_addtail(&sa1->regionbase, newar);
577         }
578                 
579 #ifndef DISABLE_PYTHON
580         /* scripts */
581         BPY_free_scriptlink(&sa1->scriptlink);
582         sa1->scriptlink= sa2->scriptlink;
583         BPY_copy_scriptlink(&sa1->scriptlink);  /* copies internal pointers */
584 #endif
585 }
586
587 /* *********** Space switching code *********** */
588
589 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
590 {
591         if(sa->spacetype != type) {
592                 SpaceType *st;
593                 SpaceLink *slold;
594                 SpaceLink *sl;
595
596                 ED_area_exit(C, sa);
597
598                 st= BKE_spacetype_from_id(type);
599                 slold= sa->spacedata.first;
600
601                 sa->spacetype= type;
602                 sa->butspacetype= type;
603                 sa->type= st;
604                 
605                 /* check previously stored space */
606                 for (sl= sa->spacedata.first; sl; sl= sl->next)
607                         if(sl->spacetype==type)
608                                 break;
609                 
610                 /* old spacedata... happened during work on 2.50, remove */
611                 if(sl && sl->regionbase.first==NULL) {
612                         st->free(sl);
613                         BLI_freelinkN(&sa->spacedata, sl);
614                         sl= NULL;
615                 }
616                 
617                 if (sl) {
618                         
619                         /* swap regions */
620                         slold->regionbase= sa->regionbase;
621                         sa->regionbase= sl->regionbase;
622                         sl->regionbase.first= sl->regionbase.last= NULL;
623                         
624                         /* put in front of list */
625                         BLI_remlink(&sa->spacedata, sl);
626                         BLI_addhead(&sa->spacedata, sl);
627                 } 
628                 else {
629                         /* new space */
630                         if(st) {
631                                 sl= st->new(C);
632                                 BLI_addhead(&sa->spacedata, sl);
633                                 
634                                 /* swap regions */
635                                 if(slold)
636                                         slold->regionbase= sa->regionbase;
637                                 sa->regionbase= sl->regionbase;
638                                 sl->regionbase.first= sl->regionbase.last= NULL;
639                         }
640                 }
641                 
642                 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
643                 
644                 /* tell WM to refresh, cursor types etc */
645                 WM_event_add_mousemove(C);
646                 
647                 ED_area_tag_redraw(sa);
648         }
649 }
650
651 void ED_area_prevspace(bContext *C)
652 {
653         SpaceLink *sl= CTX_wm_space_data(C);
654         ScrArea *sa= CTX_wm_area(C);
655
656         /* cleanup */
657 #if 0 // XXX needs to be space type specific
658         if(sfile->spacetype==SPACE_FILE) {
659                 if(sfile->pupmenu) {
660                         MEM_freeN(sfile->pupmenu);
661                         sfile->pupmenu= NULL;
662                 }
663         }
664 #endif
665
666         if(sl->next) {
667
668 #if 0 // XXX check whether this is still needed
669                 if (sfile->spacetype == SPACE_SCRIPT) {
670                         SpaceScript *sc = (SpaceScript *)sfile;
671                         if (sc->script) sc->script->flags &=~SCRIPT_FILESEL;
672                 }
673 #endif
674
675                 ED_area_newspace(C, sa, sl->next->spacetype);
676         }
677         else {
678                 ED_area_newspace(C, sa, SPACE_INFO);
679         }
680         ED_area_tag_redraw(sa);
681 }
682
683 static char *windowtype_pup(void)
684 {
685         return(
686                    "Window type:%t" //14
687                    "|3D View %x1" //30
688                    
689                    "|%l" // 33
690                    
691                    "|Ipo Curve Editor %x2" //54
692                    "|Action Editor %x12" //73
693                    "|NLA Editor %x13" //94
694                    
695                    "|%l" //97
696                    
697                    "|UV/Image Editor %x6" //117
698                    
699                    "|Video Sequence Editor %x8" //143
700                    "|Timeline %x15" //163
701                    "|Audio Window %x11" //163
702                    "|Text Editor %x9" //179
703                    
704                    "|%l" //192
705                    
706                    
707                    "|User Preferences %x7" //213
708                    "|Outliner %x3" //232
709                    "|Buttons Window %x4" //251
710                    "|Node Editor %x16"
711                    "|%l" //254
712                    
713                    "|File Browser %x5" //290
714                    
715                    "|%l" //293
716                    
717                    "|Scripts Window %x14"//313
718                    );
719 }
720
721 static void spacefunc(struct bContext *C, void *arg1, void *arg2)
722 {
723         ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
724         ED_area_tag_redraw(CTX_wm_area(C));
725 }
726
727 /* returns offset for next button in header */
728 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
729 {
730         ScrArea *sa= CTX_wm_area(C);
731         uiBut *but;
732         int xco= 8;
733         
734         if(ED_screen_area_active(C)) uiBlockSetCol(block, TH_HEADER);
735         else uiBlockSetCol(block, TH_HEADERDESEL);
736         
737         but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
738                                                    windowtype_pup(), xco, yco, XIC+10, YIC, 
739                                                    &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
740                                                    "Displays Current Window Type. "
741                                                    "Click for menu of available types.");
742         uiButSetFunc(but, spacefunc, NULL, NULL);
743         
744         xco += XIC + 14;
745         
746         uiBlockSetEmboss(block, UI_EMBOSSN);
747         if (sa->flag & HEADER_NO_PULLDOWN) {
748                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
749                                                  ICON_DISCLOSURE_TRI_RIGHT,
750                                                  xco,yco,XIC,YIC-2,
751                                                  &(sa->flag), 0, 0, 0, 0, 
752                                                  "Show pulldown menus");
753         }
754         else {
755                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
756                                                  ICON_DISCLOSURE_TRI_DOWN,
757                                                  xco,yco,XIC,YIC-2,
758                                                  &(sa->flag), 0, 0, 0, 0, 
759                                                  "Hide pulldown menus");
760         }
761         xco+=XIC;
762         
763         return xco;
764 }
765