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