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