Fix #22621 Alt-A toggles panel expand collapse
[blender-staging.git] / source / blender / editors / interface / interface_panel.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation, 2003-2009 full recode.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /* a full doc with API notes can be found in bf-blender/blender/doc/interface_API.txt */
29  
30 #include <math.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "PIL_time.h"
38
39 #include "BLI_blenlib.h"
40 #include "BLI_math.h"
41
42 #include "DNA_userdef_types.h"
43
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
46 #include "BKE_utildefines.h"
47
48 #include "BIF_gl.h"
49 #include "BIF_glutil.h"
50
51 #include "WM_api.h"
52 #include "WM_types.h"
53
54 #include "ED_screen.h"
55
56 #include "UI_interface.h"
57
58 #include "interface_intern.h"
59
60 /*********************** defines and structs ************************/
61
62 #define ANIMATION_TIME          0.30
63 #define ANIMATION_INTERVAL      0.02
64
65 #define PNL_LAST_ADDED          1
66 #define PNL_ACTIVE                      2
67 #define PNL_WAS_ACTIVE          4
68 #define PNL_ANIM_ALIGN          8
69 #define PNL_NEW_ADDED           16
70 #define PNL_FIRST                       32
71
72 typedef enum uiHandlePanelState {
73         PANEL_STATE_DRAG,
74         PANEL_STATE_DRAG_SCALE,
75         PANEL_STATE_WAIT_UNTAB,
76         PANEL_STATE_ANIMATION,
77         PANEL_STATE_EXIT
78 } uiHandlePanelState;
79
80 typedef struct uiHandlePanelData {
81         uiHandlePanelState state;
82
83         /* animation */
84         wmTimer *animtimer;
85         double starttime;
86
87         /* dragging */
88         int startx, starty;
89         int startofsx, startofsy;
90         int startsizex, startsizey;
91 } uiHandlePanelData;
92
93 static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelState state);
94
95 /*********************** space specific code ************************/
96 /* temporary code to remove all sbuts stuff from panel code         */
97
98 static int panel_aligned(ScrArea *sa, ARegion *ar)
99 {
100         if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
101                 SpaceButs *sbuts= sa->spacedata.first;
102                 return sbuts->align;
103         }
104         else if(sa->spacetype==SPACE_USERPREF && ar->regiontype == RGN_TYPE_WINDOW)
105                 return BUT_VERTICAL;
106         else if(sa->spacetype==SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS)
107                 return BUT_VERTICAL;
108         else if(sa->spacetype==SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW)
109                 return BUT_VERTICAL; 
110         else if(ELEM3(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS))
111                 return BUT_VERTICAL;
112         
113         return 0;
114 }
115
116 static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa)
117 {
118         Panel *pa;
119         int active= 0;
120
121         *r_pa= NULL;
122
123         if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
124                 SpaceButs *sbuts= sa->spacedata.first;
125
126                 if(sbuts->align)
127                         if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb)
128                                 return 1;
129         }
130         else if(ar->regiontype==RGN_TYPE_UI)
131                 return 1;
132         else if(sa->spacetype==SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW)
133                 return 1;
134         else if(sa->spacetype==SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS)
135                 return 1;
136
137         /* in case panel is added or disappears */
138         for(pa=ar->panels.first; pa; pa=pa->next) {
139                 if((pa->runtime_flag & PNL_WAS_ACTIVE) && !(pa->runtime_flag & PNL_ACTIVE))
140                         return 1;
141                 if(!(pa->runtime_flag & PNL_WAS_ACTIVE) && (pa->runtime_flag & PNL_ACTIVE))
142                         return 1;
143                 if(pa->activedata)
144                         active= 1;
145         }
146
147         /* in case we need to do an animation (size changes) */
148         for(pa=ar->panels.first; pa; pa=pa->next) {
149                 if(pa->runtime_flag & PNL_ANIM_ALIGN) {
150                         if(!active)
151                                 *r_pa= pa;
152                         return 1;
153                 }
154         }
155         
156         return 0;
157 }
158
159 /****************************** panels ******************************/
160
161 static void ui_panel_copy_offset(Panel *pa, Panel *papar)
162 {
163         /* with respect to sizes... papar is parent */
164
165         pa->ofsx= papar->ofsx;
166         pa->ofsy= papar->ofsy + papar->sizey-pa->sizey;
167 }
168
169 Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, int *open)
170 {
171         uiStyle *style= U.uistyles.first;
172         Panel *pa, *patab, *palast, *panext;
173         char *drawname= pt->label;
174         char *idname= pt->idname;
175         char *tabname= pt->idname;
176         char *hookname= NULL;
177         int newpanel;
178         int align= panel_aligned(sa, ar);
179         
180         /* check if Panel exists, then use that one */
181         for(pa=ar->panels.first; pa; pa=pa->next)
182                 if(strncmp(pa->panelname, idname, UI_MAX_NAME_STR)==0)
183                         if(strncmp(pa->tabname, tabname, UI_MAX_NAME_STR)==0)
184                                 break;
185         
186         newpanel= (pa == NULL);
187
188         if(!newpanel) {
189                 pa->type= pt;
190         }
191         else {
192                 /* new panel */
193                 pa= MEM_callocN(sizeof(Panel), "new panel");
194                 pa->type= pt;
195                 BLI_strncpy(pa->panelname, idname, UI_MAX_NAME_STR);
196                 BLI_strncpy(pa->tabname, tabname, UI_MAX_NAME_STR);
197
198                 if(pt->flag & PNL_DEFAULT_CLOSED) {
199                         if(align == BUT_VERTICAL)
200                                 pa->flag |= PNL_CLOSEDY;
201                         else
202                                 pa->flag |= PNL_CLOSEDX;
203                 }
204         
205                 pa->ofsx= 0;
206                 pa->ofsy= style->panelouter;
207                 pa->sizex= 0;
208                 pa->sizey= 0;
209                 pa->runtime_flag |= PNL_NEW_ADDED;
210
211                 BLI_addtail(&ar->panels, pa);
212                 
213                 /* make new Panel tabbed? */
214                 if(hookname) {
215                         for(patab= ar->panels.first; patab; patab= patab->next) {
216                                 if((patab->runtime_flag & PNL_ACTIVE) && patab->paneltab==NULL) {
217                                         if(strncmp(hookname, patab->panelname, UI_MAX_NAME_STR)==0) {
218                                                 if(strncmp(tabname, patab->tabname, UI_MAX_NAME_STR)==0) {
219                                                         pa->paneltab= patab;
220                                                         ui_panel_copy_offset(pa, patab);
221                                                         break;
222                                                 }
223                                         }
224                                 }
225                         } 
226                 }
227         }
228
229         BLI_strncpy(pa->drawname, drawname, UI_MAX_NAME_STR);
230
231         /* if a new panel is added, we insert it right after the panel
232          * that was last added. this way new panels are inserted in the
233          * right place between versions */
234         for(palast=ar->panels.first; palast; palast=palast->next)
235                 if(palast->runtime_flag & PNL_LAST_ADDED)
236                         break;
237         
238         if(newpanel) {
239                 pa->sortorder= (palast)? palast->sortorder+1: 0;
240
241                 for(panext=ar->panels.first; panext; panext=panext->next)
242                         if(panext != pa && panext->sortorder >= pa->sortorder)
243                                 panext->sortorder++;
244         }
245
246         if(palast)
247                 palast->runtime_flag &= ~PNL_LAST_ADDED;
248
249         /* assign to block */
250         block->panel= pa;
251         pa->runtime_flag |= PNL_ACTIVE|PNL_LAST_ADDED;
252
253         *open= 0;
254
255         if(pa->paneltab) return pa;
256         if(pa->flag & PNL_CLOSED) return pa;
257
258         *open= 1;
259         
260         return pa;
261 }
262
263 void uiEndPanel(uiBlock *block, int width, int height)
264 {
265         Panel *pa= block->panel;
266
267         if(pa->runtime_flag & PNL_NEW_ADDED) {
268                 pa->runtime_flag &= ~PNL_NEW_ADDED;
269                 pa->sizex= width;
270                 pa->sizey= height;
271         }
272         else {
273                 /* check if we need to do an animation */
274                 if(!ELEM(width, 0, pa->sizex) || !ELEM(height, 0, pa->sizey)) {
275                         pa->runtime_flag |= PNL_ANIM_ALIGN;
276                         if(height != 0)
277                                 pa->ofsy += pa->sizey-height;
278                 }
279
280                 /* update width/height if non-zero */
281                 if(width != 0)
282                         pa->sizex= width;
283                 if(height != 0)
284                         pa->sizey= height;
285         }
286 }
287
288 #if 0
289 void uiPanelToMouse(const bContext *C, Panel *pa)
290 {
291         /* global control over this feature; UI_PNL_TO_MOUSE only called for hotkey panels */
292         if(U.uiflag & USER_PANELPINNED);
293         else if(pa->control & UI_PNL_TO_MOUSE) {
294                 int mx, my;
295
296                 mx= CTX_wm_window(C)->eventstate->x;
297                 my= CTX_wm_window(C)->eventstate->y;
298                 
299                 pa->ofsx= mx-pa->sizex/2;
300                 pa->ofsy= my-pa->sizey/2;
301                 
302                 if(pa->flag & PNL_CLOSED) pa->flag &= ~PNL_CLOSED;
303         }
304         
305         if(pa->control & UI_PNL_UNSTOW) {
306                 if(pa->flag & PNL_CLOSEDY) {
307                         pa->flag &= ~PNL_CLOSED;
308                 }
309         }
310 }
311 #endif
312
313
314 static void ui_offset_panel_block(uiBlock *block)
315 {
316         uiStyle *style= U.uistyles.first;
317         uiBut *but;
318         int ofsy;
319
320         /* compute bounds and offset */
321         ui_bounds_block(block);
322
323         ofsy= block->panel->sizey - style->panelspace;
324
325         for(but= block->buttons.first; but; but=but->next) {
326                 but->y1 += ofsy;
327                 but->y2 += ofsy;
328         }
329
330         block->maxx= block->panel->sizex;
331         block->maxy= block->panel->sizey;
332         block->minx= block->miny= 0.0;
333 }
334
335 /**************************** drawing *******************************/
336
337 /* extern used by previewrender */
338 void uiPanelPush(uiBlock *block)
339 {
340         glPushMatrix(); 
341
342         if(block->panel)
343                 glTranslatef((float)block->panel->ofsx, (float)block->panel->ofsy, 0.0);
344 }
345
346 void uiPanelPop(uiBlock *block)
347 {
348         glPopMatrix();
349 }
350
351 /* triangle 'icon' for panel header */
352 void ui_draw_tria_icon(float x, float y, char dir)
353 {
354         if(dir=='h') {
355                 ui_draw_anti_tria(x-1, y, x-1, y+11.0, x+9, y+6.25);
356         }
357         else {
358                 ui_draw_anti_tria(x-3, y+10,  x+8-1, y+10, x+4.25-2, y);        
359         }
360 }
361
362 /* triangle 'icon' inside rect */
363 void ui_draw_tria_rect(rctf *rect, char dir)
364 {
365         if(dir=='h') {
366                 float half= 0.5f*(rect->ymax - rect->ymin);
367                 ui_draw_anti_tria(rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin+half);
368         }
369         else {
370                 float half= 0.5f*(rect->xmax - rect->xmin);
371                 ui_draw_anti_tria(rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin+half, rect->ymin);
372         }
373 }
374
375 void ui_draw_anti_x(float x1, float y1, float x2, float y2)
376 {
377
378         /* set antialias line */
379         glEnable(GL_LINE_SMOOTH);
380         glEnable(GL_BLEND);
381
382         glLineWidth(2.0);
383         
384         fdrawline(x1, y1, x2, y2);
385         fdrawline(x1, y2, x2, y1);
386         
387         glLineWidth(1.0);
388         
389         glDisable(GL_LINE_SMOOTH);
390         glDisable(GL_BLEND);
391         
392 }
393
394 /* x 'icon' for panel header */
395 static void ui_draw_x_icon(float x, float y)
396 {
397
398         ui_draw_anti_x(x, y, x+9.375, y+9.375);
399
400 }
401
402 #define PNL_ICON        20
403
404 static void ui_draw_panel_scalewidget(rcti *rect)
405 {
406         float xmin, xmax, dx;
407         float ymin, ymax, dy;
408         
409         xmin= rect->xmax-PNL_HEADER+2;
410         xmax= rect->xmax-3;
411         ymin= rect->ymin+3;
412         ymax= rect->ymin+PNL_HEADER-2;
413                 
414         dx= 0.5f*(xmax-xmin);
415         dy= 0.5f*(ymax-ymin);
416         
417         glEnable(GL_BLEND);
418         glColor4ub(255, 255, 255, 50);
419         fdrawline(xmin, ymin, xmax, ymax);
420         fdrawline(xmin+dx, ymin, xmax, ymax-dy);
421         
422         glColor4ub(0, 0, 0, 50);
423         fdrawline(xmin, ymin+1, xmax, ymax+1);
424         fdrawline(xmin+dx, ymin+1, xmax, ymax-dy+1);
425         glDisable(GL_BLEND);
426 }
427
428 static void ui_draw_panel_dragwidget(rctf *rect)
429 {
430         float xmin, xmax, dx;
431         float ymin, ymax, dy;
432         
433         xmin= rect->xmin;
434         xmax= rect->xmax;
435         ymin= rect->ymin;
436         ymax= rect->ymax;
437         
438         dx= 0.333f*(xmax-xmin);
439         dy= 0.333f*(ymax-ymin);
440         
441         glEnable(GL_BLEND);
442         glColor4ub(255, 255, 255, 50);
443         fdrawline(xmin, ymax, xmax, ymin);
444         fdrawline(xmin+dx, ymax, xmax, ymin+dy);
445         fdrawline(xmin+2*dx, ymax, xmax, ymin+2*dy);
446         
447         glColor4ub(0, 0, 0, 50);
448         fdrawline(xmin, ymax+1, xmax, ymin+1);
449         fdrawline(xmin+dx, ymax+1, xmax, ymin+dy+1);
450         fdrawline(xmin+2*dx, ymax+1, xmax, ymin+2*dy+1);
451         glDisable(GL_BLEND);
452 }
453
454
455 static void ui_draw_aligned_panel_header(ARegion *ar, uiStyle *style, uiBlock *block, rcti *rect, char dir)
456 {
457         Panel *panel= block->panel;
458         rcti hrect;
459         int  pnl_icons;
460         char *activename= panel->drawname[0]?panel->drawname:panel->panelname;
461         
462         /* + 0.001f to avoid flirting with float inaccuracy */
463         if(panel->control & UI_PNL_CLOSE) pnl_icons=(panel->labelofs+2*PNL_ICON+5)/block->aspect + 0.001f;
464         else pnl_icons= (panel->labelofs+PNL_ICON+5)/block->aspect + 0.001f;
465         
466         /* active tab */
467         /* draw text label */
468         UI_ThemeColor(TH_TITLE);
469         
470         hrect= *rect;
471         if(dir == 'h') {
472                 hrect.xmin= rect->xmin+pnl_icons;
473                 uiStyleFontDraw(&style->paneltitle, &hrect, activename);
474         }
475         else {
476                 /* ignore 'pnl_icons', otherwise the text gets offset horizontally 
477                  * + 0.001f to avoid flirting with float inaccuracy
478                  */
479                 hrect.xmin= rect->xmin + (PNL_ICON+5)/block->aspect + 0.001f;
480                 uiStyleFontDrawRotated(&style->paneltitle, &hrect, activename);
481         }
482 }
483
484 static void rectf_scale(rctf *rect, float scale)
485 {
486         float centx= 0.5f*(rect->xmin+rect->xmax);
487         float centy= 0.5f*(rect->ymin+rect->ymax);
488         float sizex= 0.5f*scale*(rect->xmax - rect->xmin);
489         float sizey= 0.5f*scale*(rect->ymax - rect->ymin);
490         
491         rect->xmin= centx - sizex;
492         rect->xmax= centx + sizex;
493         rect->ymin= centy - sizey;
494         rect->ymax= centy + sizey;
495 }
496
497 /* panel integrated in buttonswindow, tool/property lists etc */
498 void ui_draw_aligned_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *rect)
499 {
500         Panel *panel= block->panel;
501         rcti headrect;
502         rctf itemrect;
503         int ofsx;
504         
505         if(panel->paneltab) return;
506         if(panel->type && (panel->type->flag & PNL_NO_HEADER)) return;
507
508         /* calculate header rect */
509         /* + 0.001f to prevent flicker due to float inaccuracy */
510         headrect= *rect;
511         headrect.ymin= headrect.ymax;
512         headrect.ymax= headrect.ymin + floor(PNL_HEADER/block->aspect + 0.001f);
513         
514         if(!(panel->runtime_flag & PNL_FIRST)) {
515                 float minx= rect->xmin+5.0f/block->aspect;
516                 float maxx= rect->xmax-5.0f/block->aspect;
517                 float y= headrect.ymax;
518                 
519                 glEnable(GL_BLEND);
520                 glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
521                 fdrawline(minx, y+1, maxx, y+1);
522                 glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
523                 fdrawline(minx, y, maxx, y);
524                 glDisable(GL_BLEND);
525         }
526         
527         /* horizontal title */
528         if(!(panel->flag & PNL_CLOSEDX)) {
529                 ui_draw_aligned_panel_header(ar, style, block, &headrect, 'h');
530                 
531                 /* itemrect smaller */  
532                 itemrect.xmax= headrect.xmax - 5.0f/block->aspect;
533                 itemrect.xmin= itemrect.xmax - (headrect.ymax-headrect.ymin);
534                 itemrect.ymin= headrect.ymin;
535                 itemrect.ymax= headrect.ymax;
536                 rectf_scale(&itemrect, 0.8f);
537                 ui_draw_panel_dragwidget(&itemrect);
538         }
539         
540         /* if the panel is minimized vertically:
541                 * (------)
542                 */
543         if(panel->flag & PNL_CLOSEDY) {
544                 
545         }
546         else if(panel->flag & PNL_CLOSEDX) {
547                 /* draw vertical title */
548                 ui_draw_aligned_panel_header(ar, style, block, &headrect, 'v');
549         }
550         /* an open panel */
551         else {
552                 
553                 /* in some occasions, draw a border */
554                 if(panel->flag & PNL_SELECT) {
555                         if(panel->control & UI_PNL_SOLID) uiSetRoundBox(15);
556                         else uiSetRoundBox(3);
557                         
558                         UI_ThemeColorShade(TH_BACK, -120);
559                         uiRoundRect(0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax+1, 8);
560                 }
561                 
562                 if(panel->control & UI_PNL_SCALE)
563                         ui_draw_panel_scalewidget(rect);
564         }
565         
566         /* draw optional close icon */
567         
568         ofsx= 6;
569         if(panel->control & UI_PNL_CLOSE) {
570                 
571                 UI_ThemeColor(TH_TEXT);
572                 ui_draw_x_icon(rect->xmin+2+ofsx, rect->ymax+2);
573                 ofsx= 22;
574         }
575         
576         /* draw collapse icon */
577         UI_ThemeColor(TH_TEXT);
578         
579         /* itemrect smaller */  
580         itemrect.xmin= headrect.xmin + 5.0f/block->aspect;
581         itemrect.xmax= itemrect.xmin + (headrect.ymax-headrect.ymin);
582         itemrect.ymin= headrect.ymin;
583         itemrect.ymax= headrect.ymax;
584         
585         rectf_scale(&itemrect, 0.5f);
586         
587         if(panel->flag & PNL_CLOSEDY)
588                 ui_draw_tria_rect(&itemrect, 'h');
589         else if(panel->flag & PNL_CLOSEDX)
590                 ui_draw_tria_rect(&itemrect, 'h');
591         else
592                 ui_draw_tria_rect(&itemrect, 'v');
593         
594         
595 }
596
597 /************************** panel alignment *************************/
598
599 static int get_panel_header(Panel *pa)
600 {
601         if(pa->type && (pa->type->flag & PNL_NO_HEADER))
602                 return 0;
603
604         return PNL_HEADER;
605 }
606
607 static int get_panel_size_y(uiStyle *style, Panel *pa)
608 {
609         if(pa->type && (pa->type->flag & PNL_NO_HEADER))
610                 return pa->sizey;
611
612         return PNL_HEADER + pa->sizey + style->panelouter;
613 }
614
615 /* this function is needed because uiBlock and Panel itself dont
616 change sizey or location when closed */
617 static int get_panel_real_ofsy(Panel *pa)
618 {
619         if(pa->flag & PNL_CLOSEDY) return pa->ofsy+pa->sizey;
620         else if(pa->paneltab && (pa->paneltab->flag & PNL_CLOSEDY)) return pa->ofsy+pa->sizey;
621         else if(pa->paneltab) return pa->paneltab->ofsy;
622         else return pa->ofsy;
623 }
624
625 static int get_panel_real_ofsx(Panel *pa)
626 {
627         if(pa->flag & PNL_CLOSEDX) return pa->ofsx+get_panel_header(pa);
628         else if(pa->paneltab && (pa->paneltab->flag & PNL_CLOSEDX)) return pa->ofsx+get_panel_header(pa);
629         else return pa->ofsx+pa->sizex;
630 }
631
632 typedef struct PanelSort {
633         Panel *pa, *orig;
634 } PanelSort;
635
636 /* note about sorting;
637    the sortorder has a lower value for new panels being added.
638    however, that only works to insert a single panel, when more new panels get
639    added the coordinates of existing panels and the previously stored to-be-insterted
640    panels do not match for sorting */
641
642 static int find_leftmost_panel(const void *a1, const void *a2)
643 {
644         const PanelSort *ps1=a1, *ps2=a2;
645         
646         if(ps1->pa->ofsx > ps2->pa->ofsx) return 1;
647         else if(ps1->pa->ofsx < ps2->pa->ofsx) return -1;
648         else if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
649         else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
650
651         return 0;
652 }
653
654
655 static int find_highest_panel(const void *a1, const void *a2)
656 {
657         const PanelSort *ps1=a1, *ps2=a2;
658         
659         /* stick uppermost header-less panels to the top of the region -
660          * prevent them from being sorted */
661         if (ps1->pa->sortorder < ps2->pa->sortorder && ps1->pa->type->flag & PNL_NO_HEADER) return -1;
662         
663         if(ps1->pa->ofsy+ps1->pa->sizey < ps2->pa->ofsy+ps2->pa->sizey) return 1;
664         else if(ps1->pa->ofsy+ps1->pa->sizey > ps2->pa->ofsy+ps2->pa->sizey) return -1;
665         else if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
666         else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
667         
668         return 0;
669 }
670
671 static int compare_panel(const void *a1, const void *a2)
672 {
673         const PanelSort *ps1=a1, *ps2=a2;
674         
675         if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
676         else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
677         
678         return 0;
679 }
680
681 /* this doesnt draw */
682 /* returns 1 when it did something */
683 int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag)
684 {
685         uiStyle *style= U.uistyles.first;
686         Panel *pa;
687         PanelSort *ps, *panelsort, *psnext;
688         int a, tot=0, done;
689         int align= panel_aligned(sa, ar);
690         
691         /* count active, not tabbed panels */
692         for(pa= ar->panels.first; pa; pa= pa->next)
693                 if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL)
694                         tot++;
695
696         if(tot==0) return 0;
697
698         /* extra; change close direction? */
699         for(pa= ar->panels.first; pa; pa= pa->next) {
700                 if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) {
701                         if((pa->flag & PNL_CLOSEDX) && (align==BUT_VERTICAL))
702                                 pa->flag ^= PNL_CLOSED;
703                         else if((pa->flag & PNL_CLOSEDY) && (align==BUT_HORIZONTAL))
704                                 pa->flag ^= PNL_CLOSED;
705                 }
706         }
707
708         /* sort panels */
709         panelsort= MEM_callocN(tot*sizeof(PanelSort), "panelsort");
710         
711         ps= panelsort;
712         for(pa= ar->panels.first; pa; pa= pa->next) {
713                 if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) {
714                         ps->pa= MEM_dupallocN(pa);
715                         ps->orig= pa;
716                         ps++;
717                 }
718         }
719         
720         if(drag) {
721                 /* while we are dragging, we sort on location and update sortorder */
722                 if(align==BUT_VERTICAL) 
723                         qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel);
724                 else
725                         qsort(panelsort, tot, sizeof(PanelSort), find_leftmost_panel);
726
727                 for(ps=panelsort, a=0; a<tot; a++, ps++)
728                         ps->orig->sortorder= a;
729         }
730         else
731                 /* otherwise use sortorder */
732                 qsort(panelsort, tot, sizeof(PanelSort), compare_panel);
733         
734         /* no smart other default start loc! this keeps switching f5/f6/etc compatible */
735         ps= panelsort;
736         ps->pa->ofsx= 0;
737         ps->pa->ofsy= -get_panel_size_y(style, ps->pa);
738
739         for(a=0; a<tot-1; a++, ps++) {
740                 psnext= ps+1;
741         
742                 if(align==BUT_VERTICAL) {
743                         psnext->pa->ofsx= ps->pa->ofsx;
744                         psnext->pa->ofsy= get_panel_real_ofsy(ps->pa) - get_panel_size_y(style, psnext->pa);
745                 }
746                 else {
747                         psnext->pa->ofsx= get_panel_real_ofsx(ps->pa);
748                         psnext->pa->ofsy= ps->pa->ofsy + get_panel_size_y(style, ps->pa) - get_panel_size_y(style, psnext->pa);
749                 }
750         }
751         
752         /* we interpolate */
753         done= 0;
754         ps= panelsort;
755         for(a=0; a<tot; a++, ps++) {
756                 if((ps->pa->flag & PNL_SELECT)==0) {
757                         if((ps->orig->ofsx != ps->pa->ofsx) || (ps->orig->ofsy != ps->pa->ofsy)) {
758                                 ps->orig->ofsx= floor(0.5 + fac*ps->pa->ofsx + (1.0-fac)*ps->orig->ofsx);
759                                 ps->orig->ofsy= floor(0.5 + fac*ps->pa->ofsy + (1.0-fac)*ps->orig->ofsy);
760                                 done= 1;
761                         }
762                 }
763         }
764
765         /* copy locations to tabs */
766         for(pa= ar->panels.first; pa; pa= pa->next)
767                 if(pa->paneltab && (pa->runtime_flag & PNL_ACTIVE))
768                         ui_panel_copy_offset(pa, pa->paneltab);
769
770         /* free panelsort array */
771         for(ps= panelsort, a=0; a<tot; a++, ps++)
772                 MEM_freeN(ps->pa);
773         MEM_freeN(panelsort);
774         
775         return done;
776 }
777
778
779 static void ui_do_animate(const bContext *C, Panel *panel)
780 {
781         uiHandlePanelData *data= panel->activedata;
782         ScrArea *sa= CTX_wm_area(C);
783         ARegion *ar= CTX_wm_region(C);
784         float fac;
785
786         fac= (PIL_check_seconds_timer()-data->starttime)/ANIMATION_TIME;
787         fac= sqrt(fac);
788         fac= MIN2(fac, 1.0f);
789
790         /* for max 1 second, interpolate positions */
791         if(uiAlignPanelStep(sa, ar, fac, 0))
792                 ED_region_tag_redraw(ar);
793         else
794                 fac= 1.0f;
795
796         if(fac >= 1.0f) {
797                 panel_activate_state(C, panel, PANEL_STATE_EXIT);
798                 return;
799         }
800 }
801
802 void uiBeginPanels(const bContext *C, ARegion *ar)
803 {
804         Panel *pa;
805   
806           /* set all panels as inactive, so that at the end we know
807          * which ones were used */
808         for(pa=ar->panels.first; pa; pa=pa->next) {
809                 if(pa->runtime_flag & PNL_ACTIVE)
810                         pa->runtime_flag= PNL_WAS_ACTIVE;
811                 else
812                         pa->runtime_flag= 0;
813         }
814 }
815
816 /* only draws blocks with panels */
817 void uiEndPanels(const bContext *C, ARegion *ar)
818 {
819         ScrArea *sa= CTX_wm_area(C);
820         uiBlock *block;
821         Panel *panot, *panew, *patest, *pa, *firstpa;
822         
823         /* offset contents */
824         for(block= ar->uiblocks.first; block; block= block->next)
825                 if(block->active && block->panel)
826                         ui_offset_panel_block(block);
827
828         /* consistancy; are panels not made, whilst they have tabs */
829         for(panot= ar->panels.first; panot; panot= panot->next) {
830                 if((panot->runtime_flag & PNL_ACTIVE)==0) { // not made
831
832                         for(panew= ar->panels.first; panew; panew= panew->next) {
833                                 if((panew->runtime_flag & PNL_ACTIVE)) {
834                                         if(panew->paneltab==panot) { // panew is tab in notmade pa
835                                                 break;
836                                         }
837                                 }
838                         }
839                         /* now panew can become the new parent, check all other tabs */
840                         if(panew) {
841                                 for(patest= ar->panels.first; patest; patest= patest->next) {
842                                         if(patest->paneltab == panot) {
843                                                 patest->paneltab= panew;
844                                         }
845                                 }
846                                 panot->paneltab= panew;
847                                 panew->paneltab= NULL;
848                                 ED_region_tag_redraw(ar); // the buttons panew were not made
849                         }
850                 }       
851         }
852
853         /* re-align, possibly with animation */
854         if(panels_re_align(sa, ar, &pa)) {
855                 if(pa)
856                         panel_activate_state(C, pa, PANEL_STATE_ANIMATION);
857                 else
858                         uiAlignPanelStep(sa, ar, 1.0, 0);
859         }
860
861         /* tag first panel */
862         firstpa= NULL;
863         for(block= ar->uiblocks.first; block; block=block->next)
864                 if(block->active && block->panel)
865                         if(!firstpa || block->panel->sortorder < firstpa->sortorder)
866                                 firstpa= block->panel;
867         
868         if(firstpa)
869                 firstpa->runtime_flag |= PNL_FIRST;
870
871         UI_ThemeClearColor(TH_BACK);
872         
873         /* draw panels, selected on top */
874         for(block= ar->uiblocks.first; block; block=block->next) {
875                 if(block->active && block->panel && !(block->panel->flag & PNL_SELECT)) {
876                         uiDrawBlock(C, block);
877                 }
878         }
879
880         for(block= ar->uiblocks.first; block; block=block->next) {
881                 if(block->active && block->panel && (block->panel->flag & PNL_SELECT)) {
882                         uiDrawBlock(C, block);
883                 }
884         }
885 }
886
887 /* ------------ panel merging ---------------- */
888
889 static void check_panel_overlap(ARegion *ar, Panel *panel)
890 {
891         Panel *pa;
892
893         /* also called with panel==NULL for clear */
894         
895         for(pa=ar->panels.first; pa; pa=pa->next) {
896                 pa->flag &= ~PNL_OVERLAP;
897                 if(panel && (pa != panel)) {
898                         if(pa->paneltab==NULL && (pa->runtime_flag & PNL_ACTIVE)) {
899                                 float safex= 0.2, safey= 0.2;
900                                 
901                                 if(pa->flag & PNL_CLOSEDX) safex= 0.05;
902                                 else if(pa->flag & PNL_CLOSEDY) safey= 0.05;
903                                 else if(panel->flag & PNL_CLOSEDX) safex= 0.05;
904                                 else if(panel->flag & PNL_CLOSEDY) safey= 0.05;
905                                 
906                                 if(pa->ofsx > panel->ofsx- safex*panel->sizex)
907                                 if(pa->ofsx+pa->sizex < panel->ofsx+ (1.0+safex)*panel->sizex)
908                                 if(pa->ofsy > panel->ofsy- safey*panel->sizey)
909                                 if(pa->ofsy+pa->sizey < panel->ofsy+ (1.0+safey)*panel->sizey)
910                                         pa->flag |= PNL_OVERLAP;
911                         }
912                 }
913         }
914 }
915
916 /************************ panel dragging ****************************/
917
918 static void ui_do_drag(const bContext *C, wmEvent *event, Panel *panel)
919 {
920         uiHandlePanelData *data= panel->activedata;
921         ScrArea *sa= CTX_wm_area(C);
922         ARegion *ar= CTX_wm_region(C);
923         short align= panel_aligned(sa, ar), dx=0, dy=0;
924         
925         /* first clip for window, no dragging outside */
926         if(!BLI_in_rcti(&ar->winrct, event->x, event->y))
927                 return;
928
929         dx= (event->x-data->startx) & ~(PNL_GRID-1);
930         dy= (event->y-data->starty) & ~(PNL_GRID-1);
931
932         dx *= (float)(ar->v2d.cur.xmax - ar->v2d.cur.xmin)/(float)(ar->winrct.xmax - ar->winrct.xmin);
933         dy *= (float)(ar->v2d.cur.ymax - ar->v2d.cur.ymin)/(float)(ar->winrct.ymax - ar->winrct.ymin);
934         
935         if(data->state == PANEL_STATE_DRAG_SCALE) {
936                 panel->sizex = MAX2(data->startsizex+dx, UI_PANEL_MINX);
937                 
938                 if(data->startsizey-dy < UI_PANEL_MINY)
939                         dy= -UI_PANEL_MINY+data->startsizey;
940
941                 panel->sizey= data->startsizey-dy;
942                 panel->ofsy= data->startofsy+dy;
943         }
944         else {
945                 /* reset the panel snapping, to allow dragging away from snapped edges */
946                 panel->snap = PNL_SNAP_NONE;
947                 
948                 panel->ofsx = data->startofsx+dx;
949                 panel->ofsy = data->startofsy+dy;
950                 check_panel_overlap(ar, panel);
951                 
952                 if(align) uiAlignPanelStep(sa, ar, 0.2, 1);
953         }
954
955         ED_region_tag_redraw(ar);
956 }
957
958 /******************* region level panel interaction *****************/
959
960
961 /* this function is supposed to call general window drawing too */
962 /* also it supposes a block has panel, and isnt a menu */
963 static void ui_handle_panel_header(const bContext *C, uiBlock *block, int mx, int my, int event)
964 {
965         ScrArea *sa= CTX_wm_area(C);
966         ARegion *ar= CTX_wm_region(C);
967         Panel *pa;
968         int align= panel_aligned(sa, ar), button= 0;
969
970         /* mouse coordinates in panel space! */
971         
972         /* XXX weak code, currently it assumes layout style for location of widgets */
973         
974         /* check open/collapsed button */
975         if(event==RETKEY)
976                 button= 1;
977         else if(event==AKEY)
978                 button= 1;
979         else if(block->panel->flag & PNL_CLOSEDX) {
980                 if(my >= block->maxy) button= 1;
981         }
982         else if(block->panel->control & UI_PNL_CLOSE) {
983                 if(mx <= block->minx+10+PNL_ICON-2) button= 2;
984                 else if(mx <= block->minx+10+2*PNL_ICON+2) button= 1;
985         }
986         else if(mx <= block->minx+10+PNL_ICON+2) {
987                 button= 1;
988         }
989         
990         if(button) {
991                 if(button==2) { // close
992                         ED_region_tag_redraw(ar);
993                 }
994                 else {  // collapse
995                         if(block->panel->flag & PNL_CLOSED) {
996                                 block->panel->flag &= ~PNL_CLOSED;
997                                 /* snap back up so full panel aligns with screen edge */
998                                 if (block->panel->snap & PNL_SNAP_BOTTOM) 
999                                         block->panel->ofsy= 0;
1000                         }
1001                         else if(align==BUT_HORIZONTAL) {
1002                                 block->panel->flag |= PNL_CLOSEDX;
1003                         }
1004                         else {
1005                                 /* snap down to bottom screen edge*/
1006                                 block->panel->flag |= PNL_CLOSEDY;
1007                                 if (block->panel->snap & PNL_SNAP_BOTTOM) 
1008                                         block->panel->ofsy= -block->panel->sizey;
1009                         }
1010                         
1011                         for(pa= ar->panels.first; pa; pa= pa->next) {
1012                                 if(pa->paneltab==block->panel) {
1013                                         if(block->panel->flag & PNL_CLOSED) pa->flag |= PNL_CLOSED;
1014                                         else pa->flag &= ~PNL_CLOSED;
1015                                 }
1016                         }
1017                 }
1018
1019                 if(align)
1020                         panel_activate_state(C, block->panel, PANEL_STATE_ANIMATION);
1021                 else
1022                         ED_region_tag_redraw(ar);
1023         }
1024         else if(block->panel->flag & PNL_CLOSED) {
1025                 panel_activate_state(C, block->panel, PANEL_STATE_DRAG);
1026         }
1027         else {
1028                 panel_activate_state(C, block->panel, PANEL_STATE_DRAG);
1029         }
1030 }
1031
1032 /* XXX should become modal keymap */
1033 /* AKey is opening/closing panels, independent of button state now */
1034
1035 int ui_handler_panel_region(bContext *C, wmEvent *event)
1036 {
1037         ARegion *ar= CTX_wm_region(C);
1038         uiBlock *block;
1039         Panel *pa;
1040         int retval, mx, my, inside_header= 0, inside_scale= 0, inside;
1041
1042         retval= WM_UI_HANDLER_CONTINUE;
1043         for(block=ar->uiblocks.last; block; block=block->prev) {
1044                 mx= event->x;
1045                 my= event->y;
1046                 ui_window_to_block(ar, block, &mx, &my);
1047
1048                 /* check if inside boundbox */
1049                 inside= 0;
1050                 pa= block->panel;
1051
1052                 if(!pa || pa->paneltab!=NULL)
1053                         continue;
1054                 if(pa->type && pa->type->flag & PNL_NO_HEADER) // XXX - accessed freed panels when scripts reload, need to fix.
1055                         continue;
1056
1057                 if(block->minx <= mx && block->maxx >= mx)
1058                         if(block->miny <= my && block->maxy+PNL_HEADER >= my)
1059                                 inside= 1;
1060                 
1061                 if(inside && event->val==KM_PRESS) {
1062                         if(event->type == AKEY && !ELEM4(1, event->ctrl, event->oskey, event->shift, event->alt)) {
1063                                 
1064                                 if(pa->flag & PNL_CLOSEDY) {
1065                                         if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my))
1066                                                 ui_handle_panel_header(C, block, mx, my, event->type);
1067                                 }
1068                                 else
1069                                         ui_handle_panel_header(C, block, mx, my, event->type);
1070                                 
1071                                 continue;
1072                         }
1073                 }
1074                 
1075                 /* on active button, do not handle panels */
1076                 if(ui_button_is_active(ar))
1077                         continue;
1078                 
1079                 if(inside) {
1080                         /* clicked at panel header? */
1081                         if(pa->flag & PNL_CLOSEDX) {
1082                                 if(block->minx <= mx && block->minx+PNL_HEADER >= mx) 
1083                                         inside_header= 1;
1084                         }
1085                         else if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my)) {
1086                                 inside_header= 1;
1087                         }
1088                         else if(pa->control & UI_PNL_SCALE) {
1089                                 if(block->maxx-PNL_HEADER <= mx)
1090                                         if(block->miny+PNL_HEADER >= my)
1091                                                 inside_scale= 1;
1092                         }
1093
1094                         if(event->val==KM_PRESS) {
1095                                 /* open close on header */
1096                                 if(ELEM(event->type, RETKEY, PADENTER)) {
1097                                         if(inside_header) {
1098                                                 ui_handle_panel_header(C, block, mx, my, RETKEY);
1099                                                 break;
1100                                         }
1101                                 }
1102                                 else if(event->type == LEFTMOUSE) {
1103                                         if(inside_header) {
1104                                                 ui_handle_panel_header(C, block, mx, my, 0);
1105                                                 break;
1106                                         }
1107                                         else if(inside_scale && !(pa->flag & PNL_CLOSED)) {
1108                                                 panel_activate_state(C, pa, PANEL_STATE_DRAG_SCALE);
1109                                                 break;
1110                                         }
1111                                 }
1112                                 else if(event->type == ESCKEY) {
1113                                         /*XXX 2.50 if(block->handler) {
1114                                                 rem_blockhandler(sa, block->handler);
1115                                                 ED_region_tag_redraw(ar);
1116                                                 retval= WM_UI_HANDLER_BREAK;
1117                                         }*/
1118                                 }
1119                                 else if(event->type==PADPLUSKEY || event->type==PADMINUS) {
1120                                         int zoom=0;
1121                                 
1122                                         /* if panel is closed, only zoom if mouse is over the header */
1123                                         if (pa->flag & (PNL_CLOSEDX|PNL_CLOSEDY)) {
1124                                                 if (inside_header)
1125                                                         zoom=1;
1126                                         }
1127                                         else
1128                                                 zoom=1;
1129
1130 #if 0 // XXX make float panel exception?
1131                                         if(zoom) {
1132                                                 ScrArea *sa= CTX_wm_area(C);
1133                                                 SpaceLink *sl= sa->spacedata.first;
1134
1135                                                 if(sa->spacetype!=SPACE_BUTS) {
1136                                                         if(!(pa->control & UI_PNL_SCALE)) {
1137                                                                 if(event->type==PADPLUSKEY) sl->blockscale+= 0.1;
1138                                                                 else sl->blockscale-= 0.1;
1139                                                                 CLAMP(sl->blockscale, 0.6, 1.0);
1140
1141                                                                 ED_region_tag_redraw(ar);
1142                                                                 retval= WM_UI_HANDLER_BREAK;
1143                                                         }                                               
1144                                                 }
1145                                         }
1146 #endif
1147                                 }
1148                         }
1149                 }
1150         }
1151
1152         return retval;
1153 }
1154
1155 /**************** window level modal panel interaction **************/
1156
1157 /* note, this is modal handler and should not swallow events for animation */
1158 static int ui_handler_panel(bContext *C, wmEvent *event, void *userdata)
1159 {
1160         Panel *panel= userdata;
1161         uiHandlePanelData *data= panel->activedata;
1162
1163         /* verify if we can stop */
1164         if(event->type == LEFTMOUSE && event->val!=KM_PRESS) {
1165                 ScrArea *sa= CTX_wm_area(C);
1166                 ARegion *ar= CTX_wm_region(C);
1167                 int align= panel_aligned(sa, ar);
1168
1169                 if(align)
1170                         panel_activate_state(C, panel, PANEL_STATE_ANIMATION);
1171                 else
1172                         panel_activate_state(C, panel, PANEL_STATE_EXIT);
1173         }
1174         else if(event->type == MOUSEMOVE) {
1175                 if(data->state == PANEL_STATE_DRAG)
1176                         ui_do_drag(C, event, panel);
1177         }
1178         else if(event->type == TIMER && event->customdata == data->animtimer) {
1179                 if(data->state == PANEL_STATE_ANIMATION)
1180                         ui_do_animate(C, panel);
1181                 else if(data->state == PANEL_STATE_DRAG)
1182                         ui_do_drag(C, event, panel);
1183         }
1184
1185         data= panel->activedata;
1186
1187         if(data && data->state == PANEL_STATE_ANIMATION)
1188                 return WM_UI_HANDLER_CONTINUE;
1189         else
1190                 return WM_UI_HANDLER_BREAK;
1191 }
1192
1193 static void ui_handler_remove_panel(bContext *C, void *userdata)
1194 {
1195         Panel *pa= userdata;
1196
1197         panel_activate_state(C, pa, PANEL_STATE_EXIT);
1198 }
1199
1200 static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelState state)
1201 {
1202         uiHandlePanelData *data= pa->activedata;
1203         wmWindow *win= CTX_wm_window(C);
1204         ARegion *ar= CTX_wm_region(C);
1205         
1206         if(data && data->state == state)
1207                 return;
1208
1209         if(state == PANEL_STATE_EXIT || state == PANEL_STATE_ANIMATION) {
1210                 if(data && data->state != PANEL_STATE_ANIMATION) {
1211                         /* XXX:
1212                          *      - the panel tabbing function call below (test_add_new_tabs()) has been commented out
1213                          *        "It is too easy to do by accident when reordering panels, is very hard to control and use, and has no real benefit." - BillRey
1214                          * Aligorith, 2009Sep
1215                          */
1216                         //test_add_new_tabs(ar);   // also copies locations of tabs in dragged panel
1217                         check_panel_overlap(ar, NULL);  // clears
1218                 }
1219
1220                 pa->flag &= ~PNL_SELECT;
1221         }
1222         else
1223                 pa->flag |= PNL_SELECT;
1224
1225         if(data && data->animtimer) {
1226                 WM_event_remove_timer(CTX_wm_manager(C), win, data->animtimer);
1227                 data->animtimer= NULL;
1228         }
1229
1230         if(state == PANEL_STATE_EXIT) {
1231                 MEM_freeN(data);
1232                 pa->activedata= NULL;
1233
1234                 WM_event_remove_ui_handler(&win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, pa);
1235         }
1236         else {
1237                 if(!data) {
1238                         data= MEM_callocN(sizeof(uiHandlePanelData), "uiHandlePanelData");
1239                         pa->activedata= data;
1240
1241                         WM_event_add_ui_handler(C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, pa);
1242                 }
1243
1244                 if(ELEM(state, PANEL_STATE_ANIMATION, PANEL_STATE_DRAG))
1245                         data->animtimer= WM_event_add_timer(CTX_wm_manager(C), win, TIMER, ANIMATION_INTERVAL);
1246
1247                 data->state= state;
1248                 data->startx= win->eventstate->x;
1249                 data->starty= win->eventstate->y;
1250                 data->startofsx= pa->ofsx;
1251                 data->startofsy= pa->ofsy;
1252                 data->startsizex= pa->sizex;
1253                 data->startsizey= pa->sizey;
1254                 data->starttime= PIL_check_seconds_timer();
1255         }
1256
1257         ED_region_tag_redraw(ar);
1258
1259         /* XXX exception handling, 3d window preview panel */
1260         /* if(block->drawextra==BIF_view3d_previewdraw)
1261                 BIF_view3d_previewrender_clear(curarea);*/
1262         
1263         /* XXX exception handling, 3d window preview panel */
1264         /* if(block->drawextra==BIF_view3d_previewdraw)
1265                 BIF_view3d_previewrender_signal(curarea, PR_DISPRECT);
1266         else if(strcmp(block->name, "image_panel_preview")==0)
1267                 image_preview_event(2); */
1268 }
1269