2.5
[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         ar->swap= WIN_BACK_OK;
237 }
238
239 /* **********************************
240    maybe silly, but let's try for now
241    to keep these tags protected
242    ********************************** */
243
244 void ED_region_tag_redraw(ARegion *ar)
245 {
246         if(ar)
247                 ar->do_draw= 1;
248 }
249
250 void ED_area_tag_redraw(ScrArea *sa)
251 {
252         ARegion *ar;
253         
254         if(sa)
255                 for(ar= sa->regionbase.first; ar; ar= ar->next)
256                         ar->do_draw= 1;
257 }
258
259 void ED_area_tag_refresh(ScrArea *sa)
260 {
261         if(sa)
262                 sa->do_refresh= 1;
263 }
264
265 /* *************************************************************** */
266
267 /* use NULL to disable it */
268 void ED_area_headerprint(ScrArea *sa, const char *str)
269 {
270         ARegion *ar;
271         
272         for(ar= sa->regionbase.first; ar; ar= ar->next) {
273                 if(ar->regiontype==RGN_TYPE_HEADER) {
274                         if(str) {
275                                 if(ar->headerstr==NULL)
276                                         ar->headerstr= MEM_mallocN(256, "headerprint");
277                                 BLI_strncpy(ar->headerstr, str, 256);
278                         }
279                         else if(ar->headerstr) {
280                                 MEM_freeN(ar->headerstr);
281                                 ar->headerstr= NULL;
282                         }
283                         ED_region_tag_redraw(ar);
284                 }
285         }
286 }
287
288 /* *************************************************************** */
289
290 /* dir is direction to check, not the splitting edge direction! */
291 static int rct_fits(rcti *rect, char dir, int size)
292 {
293         if(dir=='h') {
294                 return rect->xmax-rect->xmin - size;
295         }
296         else { // 'v'
297                 return rect->ymax-rect->ymin - size;
298         }
299 }
300
301 static void region_rect_recursive(ARegion *ar, rcti *remainder)
302 {
303         int prefsizex, prefsizey;
304         
305         if(ar==NULL)
306                 return;
307         
308         /* clear state flags first */
309         ar->flag &= ~RGN_FLAG_TOO_SMALL;
310         if(ar->next==NULL)
311                 ar->alignment= RGN_ALIGN_NONE;
312         
313         prefsizex= ar->type->minsizex;
314         prefsizey= ar->type->minsizey;
315         
316         /* hidden is user flag */
317         if(ar->flag & RGN_FLAG_HIDDEN);
318         /* XXX floating area region, not handled yet here */
319         else if(ar->alignment == RGN_ALIGN_FLOAT);
320         /* remainder is too small for any usage */
321         else if( rct_fits(remainder, 'v', 1)<0 || rct_fits(remainder, 'h', 1) < 0 ) {
322                 ar->flag |= RGN_FLAG_TOO_SMALL;
323         }
324         else if(ar->alignment==RGN_ALIGN_NONE) {
325                 /* typically last region */
326                 ar->winrct= *remainder;
327                 BLI_init_rcti(remainder, 0, 0, 0, 0);
328         }
329         else if(ar->alignment==RGN_ALIGN_TOP || ar->alignment==RGN_ALIGN_BOTTOM) {
330                 
331                 if( rct_fits(remainder, 'v', prefsizey) < 0 ) {
332                         ar->flag |= RGN_FLAG_TOO_SMALL;
333                 }
334                 else {
335                         int fac= rct_fits(remainder, 'v', prefsizey);
336
337                         if(fac < 0 )
338                                 prefsizey += fac;
339                         
340                         ar->winrct= *remainder;
341                         
342                         if(ar->alignment==RGN_ALIGN_TOP) {
343                                 ar->winrct.ymin= ar->winrct.ymax - prefsizey + 1;
344                                 remainder->ymax= ar->winrct.ymin - 1;
345                         }
346                         else {
347                                 ar->winrct.ymax= ar->winrct.ymin + prefsizey - 1;
348                                 remainder->ymin= ar->winrct.ymax + 1;
349                         }
350                 }
351         }
352         else if(ar->alignment==RGN_ALIGN_LEFT || ar->alignment==RGN_ALIGN_RIGHT) {
353                 
354                 if( rct_fits(remainder, 'h', prefsizex) < 0 ) {
355                         ar->flag |= RGN_FLAG_TOO_SMALL;
356                 }
357                 else {
358                         int fac= rct_fits(remainder, 'h', prefsizex);
359                         
360                         if(fac < 0 )
361                                 prefsizex += fac;
362                         
363                         ar->winrct= *remainder;
364                         
365                         if(ar->alignment==RGN_ALIGN_RIGHT) {
366                                 ar->winrct.xmin= ar->winrct.xmax - prefsizex + 1;
367                                 remainder->xmax= ar->winrct.xmin - 1;
368                         }
369                         else {
370                                 ar->winrct.xmax= ar->winrct.xmin + prefsizex - 1;
371                                 remainder->xmin= ar->winrct.xmax + 1;
372                         }
373                 }
374         }
375         else {
376                 /* percentage subdiv*/
377                 ar->winrct= *remainder;
378                 
379                 if(ar->alignment==RGN_ALIGN_HSPLIT) {
380                         if( rct_fits(remainder, 'h', prefsizex) > 4) {
381                                 ar->winrct.xmax= (remainder->xmin+remainder->xmax)/2;
382                                 remainder->xmin= ar->winrct.xmax+1;
383                         }
384                         else {
385                                 BLI_init_rcti(remainder, 0, 0, 0, 0);
386                         }
387                 }
388                 else {
389                         if( rct_fits(remainder, 'v', prefsizey) > 4) {
390                                 ar->winrct.ymax= (remainder->ymin+remainder->ymax)/2;
391                                 remainder->ymin= ar->winrct.ymax+1;
392                         }
393                         else {
394                                 BLI_init_rcti(remainder, 0, 0, 0, 0);
395                         }
396                 }
397         }
398         /* for speedup */
399         ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
400         ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
401         
402         region_rect_recursive(ar->next, remainder);
403 }
404
405 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
406 {
407         
408         if(sa->v1->vec.x>0) sa->totrct.xmin= sa->v1->vec.x+1;
409         else sa->totrct.xmin= sa->v1->vec.x;
410         if(sa->v4->vec.x<sizex-1) sa->totrct.xmax= sa->v4->vec.x-1;
411         else sa->totrct.xmax= sa->v4->vec.x;
412         
413         if(sa->v1->vec.y>0) sa->totrct.ymin= sa->v1->vec.y+1;
414         else sa->totrct.ymin= sa->v1->vec.y;
415         if(sa->v2->vec.y<sizey-1) sa->totrct.ymax= sa->v2->vec.y-1;
416         else sa->totrct.ymax= sa->v2->vec.y;
417         
418         /* for speedup */
419         sa->winx= sa->totrct.xmax-sa->totrct.xmin+1;
420         sa->winy= sa->totrct.ymax-sa->totrct.ymin+1;
421 }
422
423
424 #define AZONESPOT               12
425 void area_azone_initialize(ScrArea *sa) 
426 {
427         AZone *az;
428         if(sa->actionzones.first==NULL) {
429                 /* set action zones - should these actually be ARegions? With these we can easier check area hotzones */
430                 /* (ton) for time being just area, ARegion split is not foreseen on user level */
431                 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
432                 BLI_addtail(&(sa->actionzones), az);
433                 az->type= AZONE_TRI;
434                 az->pos= AZONE_SW;
435                 
436                 az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
437                 BLI_addtail(&(sa->actionzones), az);
438                 az->type= AZONE_TRI;
439                 az->pos= AZONE_NE;
440         }
441         
442         for(az= sa->actionzones.first; az; az= az->next) {
443                 if(az->pos==AZONE_SW) {
444                         az->x1= sa->v1->vec.x+1;
445                         az->y1= sa->v1->vec.y+1;
446                         az->x2= sa->v1->vec.x+AZONESPOT;
447                         az->y2= sa->v1->vec.y+AZONESPOT;
448                 } 
449                 else if (az->pos==AZONE_NE) {
450                         az->x1= sa->v3->vec.x;
451                         az->y1= sa->v3->vec.y;
452                         az->x2= sa->v3->vec.x-AZONESPOT;
453                         az->y2= sa->v3->vec.y-AZONESPOT;
454                 }
455         }
456 }
457
458 /* used for area initialize below */
459 static void region_subwindow(wmWindowManager *wm, wmWindow *win, ARegion *ar)
460 {
461         if(ar->flag & (RGN_FLAG_HIDDEN|RGN_FLAG_TOO_SMALL)) {
462                 if(ar->swinid)
463                         wm_subwindow_close(win, ar->swinid);
464                 ar->swinid= 0;
465         }
466         else if(ar->swinid==0)
467                 ar->swinid= wm_subwindow_open(win, &ar->winrct);
468         else 
469                 wm_subwindow_position(win, ar->swinid, &ar->winrct);
470 }
471
472 static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int flag)
473 {
474         /* note, add-handler checks if it already exists */
475         
476         // XXX it would be good to have boundbox checks for some of these...
477         if(flag & ED_KEYMAP_UI) {
478                 UI_add_region_handlers(handlers);
479         }
480         if(flag & ED_KEYMAP_VIEW2D) {
481                 ListBase *keymap= WM_keymap_listbase(wm, "View2D", 0, 0);
482                 WM_event_add_keymap_handler(handlers, keymap);
483         }
484         if(flag & ED_KEYMAP_MARKERS) {
485                 ListBase *keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
486                 WM_event_add_keymap_handler(handlers, keymap);
487                 // XXX need boundbox check urgently!!!
488         }
489         if(flag & ED_KEYMAP_ANIMATION) {
490                 ListBase *keymap= WM_keymap_listbase(wm, "Animation", 0, 0);
491                 WM_event_add_keymap_handler(handlers, keymap);
492         }
493 }
494
495
496 /* called in screen_refresh, or screens_init, also area size changes */
497 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
498 {
499         ARegion *ar;
500         rcti rect;
501         
502         /* set typedefinitions */
503         sa->type= BKE_spacetype_from_id(sa->spacetype);
504         
505         if(sa->type==NULL) {
506                 sa->butspacetype= sa->spacetype= SPACE_VIEW3D;
507                 sa->type= BKE_spacetype_from_id(sa->spacetype);
508         }
509         
510         for(ar= sa->regionbase.first; ar; ar= ar->next)
511                 ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
512         
513         /* area sizes */
514         area_calc_totrct(sa, win->sizex, win->sizey);
515         
516         /* region rect sizes */
517         rect= sa->totrct;
518         region_rect_recursive(sa->regionbase.first, &rect);
519         
520         /* default area handlers */
521         ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
522         /* checks spacedata, adds own handlers */
523         if(sa->type->init)
524                 sa->type->init(wm, sa);
525         
526         /* region windows, default and own handlers */
527         for(ar= sa->regionbase.first; ar; ar= ar->next) {
528                 region_subwindow(wm, win, ar);
529                 
530                 /* default region handlers */
531                 ed_default_handlers(wm, &ar->handlers, ar->type->keymapflag);
532
533                 if(ar->type->init)
534                         ar->type->init(wm, ar);
535                 
536         }
537         area_azone_initialize(sa);
538 }
539
540 /* externally called for floating regions like menus */
541 void ED_region_init(bContext *C, ARegion *ar)
542 {
543 //      ARegionType *at= ar->type;
544         
545         /* refresh can be called before window opened */
546         region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
547         
548 }
549
550
551 /* sa2 to sa1, we swap spaces for fullscreen to keep all allocated data */
552 /* area vertices were set */
553 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
554 {
555         ARegion *ar;
556         
557         sa1->headertype= sa2->headertype;
558         sa1->spacetype= sa2->spacetype;
559         sa1->butspacetype= sa2->butspacetype;
560         
561         if(swap_space) {
562                 SWAP(ListBase, sa1->spacedata, sa2->spacedata);
563                 /* exception: ensure preview is reset */
564 //              if(sa1->spacetype==SPACE_VIEW3D)
565 // XXX                  BIF_view3d_previewrender_free(sa1->spacedata.first);
566         }
567         else {
568                 BKE_spacedata_freelist(&sa1->spacedata);
569                 BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
570         }
571         
572         /* regions... XXX */
573         BLI_freelistN(&sa1->regionbase);
574         
575         for(ar= sa2->regionbase.first; ar; ar= ar->next) {
576                 ARegion *newar= BKE_area_region_copy(ar);
577                 BLI_addtail(&sa1->regionbase, newar);
578         }
579                 
580 #ifndef DISABLE_PYTHON
581         /* scripts */
582         BPY_free_scriptlink(&sa1->scriptlink);
583         sa1->scriptlink= sa2->scriptlink;
584         BPY_copy_scriptlink(&sa1->scriptlink);  /* copies internal pointers */
585 #endif
586 }
587
588 /* *********** Space switching code *********** */
589
590 void ED_area_newspace(bContext *C, ScrArea *sa, int type)
591 {
592         if(sa->spacetype != type) {
593                 SpaceType *st;
594                 SpaceLink *slold;
595                 SpaceLink *sl;
596
597                 ED_area_exit(C, sa);
598
599                 st= BKE_spacetype_from_id(type);
600                 slold= sa->spacedata.first;
601
602                 sa->spacetype= type;
603                 sa->butspacetype= type;
604                 sa->type= st;
605                 
606                 /* check previously stored space */
607                 for (sl= sa->spacedata.first; sl; sl= sl->next)
608                         if(sl->spacetype==type)
609                                 break;
610                 
611                 /* old spacedata... happened during work on 2.50, remove */
612                 if(sl && sl->regionbase.first==NULL) {
613                         st->free(sl);
614                         BLI_freelinkN(&sa->spacedata, sl);
615                         sl= NULL;
616                 }
617                 
618                 if (sl) {
619                         
620                         /* swap regions */
621                         slold->regionbase= sa->regionbase;
622                         sa->regionbase= sl->regionbase;
623                         sl->regionbase.first= sl->regionbase.last= NULL;
624                         
625                         /* put in front of list */
626                         BLI_remlink(&sa->spacedata, sl);
627                         BLI_addhead(&sa->spacedata, sl);
628                 } 
629                 else {
630                         /* new space */
631                         if(st) {
632                                 sl= st->new(C);
633                                 BLI_addhead(&sa->spacedata, sl);
634                                 
635                                 /* swap regions */
636                                 if(slold)
637                                         slold->regionbase= sa->regionbase;
638                                 sa->regionbase= sl->regionbase;
639                                 sl->regionbase.first= sl->regionbase.last= NULL;
640                         }
641                 }
642                 
643                 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
644                 
645                 /* tell WM to refresh, cursor types etc */
646                 WM_event_add_mousemove(C);
647                 
648                 ED_area_tag_redraw(sa);
649         }
650 }
651
652 void ED_area_prevspace(bContext *C)
653 {
654         SpaceLink *sl= CTX_wm_space_data(C);
655         ScrArea *sa= CTX_wm_area(C);
656
657         /* cleanup */
658 #if 0 // XXX needs to be space type specific
659         if(sfile->spacetype==SPACE_FILE) {
660                 if(sfile->pupmenu) {
661                         MEM_freeN(sfile->pupmenu);
662                         sfile->pupmenu= NULL;
663                 }
664         }
665 #endif
666
667         if(sl->next) {
668
669 #if 0 // XXX check whether this is still needed
670                 if (sfile->spacetype == SPACE_SCRIPT) {
671                         SpaceScript *sc = (SpaceScript *)sfile;
672                         if (sc->script) sc->script->flags &=~SCRIPT_FILESEL;
673                 }
674 #endif
675
676                 ED_area_newspace(C, sa, sl->next->spacetype);
677         }
678         else {
679                 ED_area_newspace(C, sa, SPACE_INFO);
680         }
681         ED_area_tag_redraw(sa);
682 }
683
684 static char *windowtype_pup(void)
685 {
686         return(
687                    "Window type:%t" //14
688                    "|3D View %x1" //30
689                    
690                    "|%l" // 33
691                    
692                    "|Ipo Curve Editor %x2" //54
693                    "|Action Editor %x12" //73
694                    "|NLA Editor %x13" //94
695                    
696                    "|%l" //97
697                    
698                    "|UV/Image Editor %x6" //117
699                    
700                    "|Video Sequence Editor %x8" //143
701                    "|Timeline %x15" //163
702                    "|Audio Window %x11" //163
703                    "|Text Editor %x9" //179
704                    
705                    "|%l" //192
706                    
707                    
708                    "|User Preferences %x7" //213
709                    "|Outliner %x3" //232
710                    "|Buttons Window %x4" //251
711                    "|Node Editor %x16"
712                    "|%l" //254
713                    
714                    "|File Browser %x5" //290
715                    
716                    "|%l" //293
717                    
718                    "|Scripts Window %x14"//313
719                    );
720 }
721
722 static void spacefunc(struct bContext *C, void *arg1, void *arg2)
723 {
724         ED_area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
725         ED_area_tag_redraw(CTX_wm_area(C));
726 }
727
728 /* returns offset for next button in header */
729 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
730 {
731         ScrArea *sa= CTX_wm_area(C);
732         uiBut *but;
733         int xco= 8;
734         
735         if(ED_screen_area_active(C)) uiBlockSetCol(block, TH_HEADER);
736         else uiBlockSetCol(block, TH_HEADERDESEL);
737         
738         but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
739                                                    windowtype_pup(), xco, yco, XIC+10, YIC, 
740                                                    &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
741                                                    "Displays Current Window Type. "
742                                                    "Click for menu of available types.");
743         uiButSetFunc(but, spacefunc, NULL, NULL);
744         
745         xco += XIC + 14;
746         
747         uiBlockSetEmboss(block, UI_EMBOSSN);
748         if (sa->flag & HEADER_NO_PULLDOWN) {
749                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
750                                                  ICON_DISCLOSURE_TRI_RIGHT,
751                                                  xco,yco,XIC,YIC-2,
752                                                  &(sa->flag), 0, 0, 0, 0, 
753                                                  "Show pulldown menus");
754         }
755         else {
756                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
757                                                  ICON_DISCLOSURE_TRI_DOWN,
758                                                  xco,yco,XIC,YIC-2,
759                                                  &(sa->flag), 0, 0, 0, 0, 
760                                                  "Hide pulldown menus");
761         }
762         xco+=XIC;
763         
764         return xco;
765 }
766