misc edits
[blender.git] / source / blender / editors / space_file / file_draw.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) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_file/file_draw.c
30  *  \ingroup spfile
31  */
32
33
34 #include <math.h>
35 #include <string.h>
36
37 #include "BLI_blenlib.h"
38 #include "BLI_utildefines.h"
39 #include "BLI_dynstr.h"
40 #include "BLI_storage_types.h"
41 #ifdef WIN32
42 #include "BLI_winstuff.h"
43 #endif
44
45 #include "BIF_gl.h"
46 #include "BIF_glutil.h"
47
48 #include "BKE_context.h"
49 #include "BKE_global.h"
50 #include "BKE_main.h"
51
52 #include "BLF_api.h"
53 #include "BLF_translation.h"
54
55 #include "IMB_imbuf_types.h"
56  
57 #include "MEM_guardedalloc.h"
58
59 #include "DNA_userdef_types.h"
60
61 #include "RNA_access.h"
62
63 #include "ED_fileselect.h"
64 #include "ED_screen.h"
65
66 #include "UI_interface.h"
67 #include "UI_interface_icons.h"
68 #include "UI_resources.h"
69 #include "UI_view2d.h"
70
71 #include "WM_types.h"
72
73 #include "fsmenu.h"
74 #include "filelist.h"
75
76 #include "file_intern.h"        // own include
77
78 /* button events */
79 enum {
80         B_FS_DIRNAME,
81         B_FS_FILENAME
82 } /*eFile_ButEvents*/;
83
84
85 static void do_file_buttons(bContext *C, void *UNUSED(arg), int event)
86 {
87         switch(event) {
88                 case B_FS_FILENAME:
89                         file_filename_exec(C, NULL);
90                         break;
91                 case B_FS_DIRNAME:
92                         file_directory_exec(C, NULL);
93                         break;
94         }
95 }
96
97 /* Note: This function uses pixelspace (0, 0, winx, winy), not view2d. 
98  * The controls are laid out as follows:
99  *
100  * -------------------------------------------
101  * | Directory input               | execute |
102  * -------------------------------------------
103  * | Filename input        | + | - | cancel  |
104  * -------------------------------------------
105  *
106  * The input widgets will stretch to fill any excess space.
107  * When there isn't enough space for all controls to be shown, they are
108  * hidden in this order: x/-, execute/cancel, input widgets.
109  */
110 void file_draw_buttons(const bContext *C, ARegion *ar)
111 {
112         /* Button layout. */
113         const int max_x      = ar->winx - 10;
114         const int line1_y    = ar->winy - (IMASEL_BUTTONS_HEIGHT/2 + IMASEL_BUTTONS_MARGIN);
115         const int line2_y    = line1_y - (IMASEL_BUTTONS_HEIGHT/2 + IMASEL_BUTTONS_MARGIN);
116         const int input_minw = 20;
117         const int btn_h      = UI_UNIT_Y;
118         const int btn_fn_w   = UI_UNIT_X;
119         const int btn_minw   = 80;
120         const int btn_margin = 20;
121         const int separator  = 4;
122
123         /* Additional locals. */
124         char  name[32];
125         int loadbutton;
126         int fnumbuttons;
127         int min_x       = 10;
128         int chan_offs   = 0;
129         int available_w = max_x - min_x;
130         int line1_w     = available_w;
131         int line2_w     = available_w;
132         
133         uiBut*            but;
134         uiBlock*          block;
135         SpaceFile*        sfile  = CTX_wm_space_file(C);
136         FileSelectParams* params = ED_fileselect_get_params(sfile);
137         ARegion*                  artmp;
138         
139         /* Initialize UI block. */
140         sprintf(name, "win %p", (void *)ar);
141         block = uiBeginBlock(C, ar, name, UI_EMBOSS);
142         uiBlockSetHandleFunc(block, do_file_buttons, NULL);
143
144         /* exception to make space for collapsed region icon */
145         for (artmp=CTX_wm_area(C)->regionbase.first; artmp; artmp=artmp->next) {
146                 if (artmp->regiontype == RGN_TYPE_CHANNELS && artmp->flag & RGN_FLAG_HIDDEN) {
147                         chan_offs = 16;
148                         min_x += chan_offs;
149                         available_w -= chan_offs;
150                 }
151         }
152         
153         /* Is there enough space for the execute / cancel buttons? */
154         loadbutton = UI_GetStringWidth(sfile->params->title) + btn_margin;
155         if (loadbutton < btn_minw) {
156                 loadbutton = MAX2(btn_minw, 
157                                                   btn_margin + UI_GetStringWidth(params->title));
158         }
159         
160         if (available_w <= loadbutton + separator + input_minw 
161          || params->title[0] == 0) {
162                 loadbutton = 0;
163         } else {
164                 line1_w -= (loadbutton + separator);
165                 line2_w  = line1_w;
166         }
167
168         /* Is there enough space for file number increment/decrement buttons? */
169         fnumbuttons = 2 * btn_fn_w;
170         if (!loadbutton || line2_w <= fnumbuttons + separator + input_minw) {
171                 fnumbuttons = 0;
172         } else {
173                 line2_w -= (fnumbuttons + separator);
174         }
175         
176         /* Text input fields for directory and file. */
177         if (available_w > 0) {
178                 int overwrite_alert= file_draw_check_exists(sfile);
179                 /* callbacks for operator check functions */
180                 uiBlockSetFunc(block, file_draw_check_cb, NULL, NULL);
181
182                 but = uiDefButTextO(block, TEX, "FILE_OT_directory", 0, "",
183                                  min_x, line1_y, line1_w-chan_offs, btn_h, 
184                                  params->dir, 0.0, (float)FILE_MAX, 0, 0,
185                                  UI_translate_do_tooltip(N_("File path")));
186                 uiButSetCompleteFunc(but, autocomplete_directory, NULL);
187                 uiButSetFlag(but, UI_BUT_NO_UTF8);
188
189                 if((params->flag & FILE_DIRSEL_ONLY) == 0) {
190                         but = uiDefBut(block, TEX, B_FS_FILENAME, "",
191                                          min_x, line2_y, line2_w-chan_offs, btn_h,
192                                          params->file, 0.0, (float)FILE_MAXFILE, 0, 0,
193                                          UI_translate_do_tooltip(overwrite_alert ?N_("File name, overwrite existing") : N_("File name")));
194                         uiButSetCompleteFunc(but, autocomplete_file, NULL);
195                         uiButSetFlag(but, UI_BUT_NO_UTF8);
196
197                         /* check if this overrides a file and if the operator option is used */
198                         if(overwrite_alert) {
199                                 uiButSetFlag(but, UI_BUT_REDALERT);
200                         }
201                 }
202                 
203                 /* clear func */
204                 uiBlockSetFunc(block, NULL, NULL, NULL);
205         }
206         
207         /* Filename number increment / decrement buttons. */
208         if (fnumbuttons && (params->flag & FILE_DIRSEL_ONLY) == 0) {
209                 uiBlockBeginAlign(block);
210                 but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMOUT,
211                                 min_x + line2_w + separator - chan_offs, line2_y, 
212                                 btn_fn_w, btn_h, 
213                                 UI_translate_do_tooltip(N_("Decrement the filename number")));    
214                 RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", -1); 
215         
216                 but = uiDefIconButO(block, BUT, "FILE_OT_filenum", 0, ICON_ZOOMIN, 
217                                 min_x + line2_w + separator + btn_fn_w - chan_offs, line2_y, 
218                                 btn_fn_w, btn_h, 
219                                 UI_translate_do_tooltip(N_("Increment the filename number")));    
220                 RNA_int_set(uiButGetOperatorPtrRNA(but), "increment", 1); 
221                 uiBlockEndAlign(block);
222         }
223         
224         /* Execute / cancel buttons. */
225         if(loadbutton) {
226                 
227                 uiDefButO(block, BUT, "FILE_OT_execute", WM_OP_EXEC_REGION_WIN, params->title,
228                         max_x - loadbutton, line1_y, loadbutton, btn_h, 
229                         params->title);
230                 uiDefButO(block, BUT, "FILE_OT_cancel", WM_OP_EXEC_REGION_WIN, UI_translate_do_iface(N_("Cancel")),
231                         max_x - loadbutton, line2_y, loadbutton, btn_h, 
232                         UI_translate_do_tooltip(N_("Cancel")));
233         }
234         
235         uiEndBlock(C, block);
236         uiDrawBlock(C, block);
237 }
238
239
240 static void draw_tile(int sx, int sy, int width, int height, int colorid, int shade)
241 {       
242         UI_ThemeColorShade(colorid, shade);
243         uiSetRoundBox(UI_CNR_ALL);
244         uiRoundBox((float)sx, (float)(sy - height), (float)(sx + width), (float)sy, 5.0f);
245 }
246
247
248 static int get_file_icon(struct direntry *file)
249 {
250         if (file->type & S_IFDIR) {
251                 if ( strcmp(file->relname, "..") == 0) {
252                                 return  ICON_FILE_PARENT;
253                 }
254                 if(file->flags & BLENDERFILE) {
255                         return ICON_FILE_BLEND;
256                 }
257                 return ICON_FILE_FOLDER;
258         }
259         else if (file->flags & BLENDERFILE)
260                 return ICON_FILE_BLEND;
261         else if (file->flags & BLENDERFILE_BACKUP)
262                 return ICON_FILE_BLEND;
263         else if (file->flags & IMAGEFILE)
264                 return ICON_FILE_IMAGE;
265         else if (file->flags & MOVIEFILE)
266                 return ICON_FILE_MOVIE;
267         else if (file->flags & PYSCRIPTFILE)
268                 return ICON_FILE_SCRIPT;
269         else if (file->flags & SOUNDFILE) 
270                 return ICON_FILE_SOUND;
271         else if (file->flags & FTFONTFILE) 
272                 return ICON_FILE_FONT;
273         else if (file->flags & BTXFILE) 
274                 return ICON_FILE_BLANK;
275         else if (file->flags & COLLADAFILE) 
276                 return ICON_FILE_BLANK;
277         else
278                 return ICON_FILE_BLANK;
279 }
280
281 static void file_draw_icon(uiBlock *block, char *path, int sx, int sy, int icon, int width, int height)
282 {
283         uiBut *but;
284         int x,y;
285         /*float alpha=1.0f;*/
286         
287         x = sx;
288         y = sy-height;
289         
290         /*if (icon == ICON_FILE_BLANK) alpha = 0.375f;*/
291
292         but= uiDefIconBut(block, LABEL, 0, icon, x, y, width, height, NULL, 0.0f, 0.0f, 0.0f, 0.0f, "");
293         uiButSetDragPath(but, path);
294 }
295
296
297 static void file_draw_string(int sx, int sy, const char* string, float width, int height, short align)
298 {
299         uiStyle *style= UI_GetStyle();
300         uiFontStyle fs = style->widgetlabel;
301         rcti rect;
302         char fname[FILE_MAXFILE];
303
304         fs.align = align;
305
306         BLI_strncpy(fname,string, FILE_MAXFILE);
307         file_shorten_string(fname, width + 1.0f, 0);
308
309         /* no text clipping needed, uiStyleFontDraw does it but is a bit too strict (for buttons it works) */
310         rect.xmin = sx;
311         rect.xmax = (int)(sx + ceil(width+4.0f));
312         rect.ymin = sy - height;
313         rect.ymax = sy;
314         
315         uiStyleFontDraw(&fs, &rect, fname);
316 }
317
318 void file_calc_previews(const bContext *C, ARegion *ar)
319 {
320         SpaceFile *sfile= CTX_wm_space_file(C);
321         View2D *v2d= &ar->v2d;
322         
323         ED_fileselect_init_layout(sfile, ar);
324         /* +SCROLL_HEIGHT is bad hack to work around issue in UI_view2d_totRect_set */
325         UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height+V2D_SCROLL_HEIGHT);
326 }
327
328 static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int sy, ImBuf *imb, FileLayout *layout, short dropshadow)
329 {
330         if (imb) {
331                 uiBut *but;
332                 float fx, fy;
333                 float dx, dy;
334                 int xco, yco;
335                 float scaledx, scaledy;
336                 float scale;
337                 int ex, ey;
338                 
339                 if ( (imb->x > layout->prv_w) || (imb->y > layout->prv_h) ) {
340                         if (imb->x > imb->y) {
341                                 scaledx = (float)layout->prv_w;
342                                 scaledy =  ( (float)imb->y/(float)imb->x )*layout->prv_w;
343                                 scale = scaledx/imb->x;
344                         }
345                         else {
346                                 scaledy = (float)layout->prv_h;
347                                 scaledx =  ( (float)imb->x/(float)imb->y )*layout->prv_h;
348                                 scale = scaledy/imb->y;
349                         }
350                 } else {
351                         scaledx = (float)imb->x;
352                         scaledy = (float)imb->y;
353                         scale = 1.0;
354                 }
355                 ex = (int)scaledx;
356                 ey = (int)scaledy;
357                 fx = ((float)layout->prv_w - (float)ex)/2.0f;
358                 fy = ((float)layout->prv_h - (float)ey)/2.0f;
359                 dx = (fx + 0.5f + layout->prv_border_x);
360                 dy = (fy + 0.5f - layout->prv_border_y);
361                 xco = sx + (int)dx;
362                 yco = sy - layout->prv_h + (int)dy;
363                 
364                 glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA);
365                 
366                 /* shadow */
367                 if (dropshadow)
368                         uiDrawBoxShadow(220, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
369
370                 glEnable(GL_BLEND);
371                 
372                 /* the image */
373                 glColor4f(1.0, 1.0, 1.0, 1.0);
374                 glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
375                 
376                 /* border */
377                 if (dropshadow) {
378                         glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
379                         fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
380                 }
381                 
382                 /* dragregion */
383                 but= uiDefBut(block, LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, "");
384                 uiButSetDragImage(but, file->path, get_file_icon(file), imb, scale);
385                 
386                 glDisable(GL_BLEND);
387                 imb = NULL;
388         }
389 }
390
391 static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
392 {
393         char newname[FILE_MAX+12];
394         char orgname[FILE_MAX+12];
395         char filename[FILE_MAX+12];
396         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
397         ARegion* ar = CTX_wm_region(C);
398
399         BLI_make_file_string(G.main->name, orgname, sfile->params->dir, oldname);
400         BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename));
401         BLI_make_file_string(G.main->name, newname, sfile->params->dir, filename);
402
403         if( strcmp(orgname, newname) != 0 ) {
404                 if (!BLI_exists(newname)) {
405                         BLI_rename(orgname, newname);
406                         /* to make sure we show what is on disk */
407                         ED_fileselect_clear(C, sfile);
408                 }
409
410                 ED_region_tag_redraw(ar);
411         }
412 }
413
414
415 static void draw_background(FileLayout *layout, View2D *v2d)
416 {
417         int i;
418         int sy;
419
420         /* alternating flat shade background */
421         for (i=0; (i <= layout->rows); i+=2)
422         {
423                 sy = (int)v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y;
424
425                 UI_ThemeColorShade(TH_BACK, -7);
426                 glRectf(v2d->cur.xmin, (float)sy, v2d->cur.xmax, (float)(sy+layout->tile_h+2*layout->tile_border_y));
427                 
428         }
429 }
430
431 static void draw_dividers(FileLayout *layout, View2D *v2d)
432 {
433         int sx;
434
435         /* vertical column dividers */
436         sx = (int)v2d->tot.xmin;
437         while (sx < v2d->cur.xmax) {
438                 sx += (layout->tile_w+2*layout->tile_border_x);
439                 
440                 UI_ThemeColorShade(TH_BACK, 30);
441                 sdrawline(sx+1, (short)(v2d->cur.ymax - layout->tile_border_y),  sx+1,  (short)v2d->cur.ymin); 
442                 UI_ThemeColorShade(TH_BACK, -30);
443                 sdrawline(sx, (short)(v2d->cur.ymax - layout->tile_border_y),  sx,  (short)v2d->cur.ymin); 
444         }
445 }
446
447 void file_draw_list(const bContext *C, ARegion *ar)
448 {
449         SpaceFile *sfile= CTX_wm_space_file(C);
450         FileSelectParams* params = ED_fileselect_get_params(sfile);
451         FileLayout* layout= ED_fileselect_get_layout(sfile, ar);
452         View2D *v2d= &ar->v2d;
453         struct FileList* files = sfile->files;
454         struct direntry *file;
455         ImBuf *imb;
456         uiBlock *block = uiBeginBlock(C, ar, "FileNames", UI_EMBOSS);
457         int numfiles;
458         int numfiles_layout;
459         int sx, sy;
460         int offset;
461         int textwidth, textheight;
462         int i;
463         short is_icon;
464         short align;
465
466
467         numfiles = filelist_numfiles(files);
468         
469         if (params->display != FILE_IMGDISPLAY) {
470
471                 draw_background(layout, v2d);
472         
473                 draw_dividers(layout, v2d);
474         }
475
476         offset = ED_fileselect_layout_offset(layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax);
477         if (offset<0) offset=0;
478
479         numfiles_layout = ED_fileselect_layout_numfiles(layout, ar);
480
481         /* adjust, so the next row is already drawn when scrolling */
482         if (layout->flag & FILE_LAYOUT_HOR) {
483                 numfiles_layout += layout->rows;
484         } else {
485                 numfiles_layout += layout->columns;
486         }
487
488         textwidth =( FILE_IMGDISPLAY == params->display) ? layout->tile_w : (int)layout->column_widths[COLUMN_NAME];
489         textheight = (int)(layout->textheight*3.0/2.0 + 0.5);
490
491         align = ( FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT;
492
493         for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++i)
494         {
495                 ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
496                 sx += (int)(v2d->tot.xmin+2.0f);
497                 sy = (int)(v2d->tot.ymax - sy);
498
499                 file = filelist_file(files, i); 
500                 
501                 UI_ThemeColor4(TH_TEXT);
502
503
504                 if (!(file->selflag & EDITING_FILE)) {
505                         if  ((params->active_file == i) || (file->selflag & HILITED_FILE) || (file->selflag & SELECTED_FILE) ) {
506                                 int colorid = (file->selflag & SELECTED_FILE) ? TH_HILITE : TH_BACK;
507                                 int shade = (params->active_file == i) || (file->selflag & HILITED_FILE) ? 20 : 0;
508                                 draw_tile(sx, sy-1, layout->tile_w+4, sfile->layout->tile_h+layout->tile_border_y, colorid, shade);
509                         }
510                 }
511                 uiSetRoundBox(UI_CNR_NONE);
512
513                 if ( FILE_IMGDISPLAY == params->display ) {
514                         is_icon = 0;
515                         imb = filelist_getimage(files, i);
516                         if (!imb) {
517                                 imb = filelist_geticon(files,i);
518                                 is_icon = 1;
519                         }
520                         
521                         file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE));
522                 } else {
523                         file_draw_icon(block, file->path, sx, sy-(UI_UNIT_Y / 6), get_file_icon(file), ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE);
524                         sx += ICON_DEFAULT_WIDTH_SCALE + 4;
525                 }
526
527                 UI_ThemeColor4(TH_TEXT);
528
529                 if (file->selflag & EDITING_FILE) {
530                         uiBut *but = uiDefBut(block, TEX, 1, "", sx , sy-layout->tile_h-3, 
531                                 textwidth, textheight, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,"");
532                         uiButSetRenameFunc(but, renamebutton_cb, file);
533                         uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
534                         if ( 0 == uiButActiveOnly(C, block, but)) {
535                                 file->selflag &= ~EDITING_FILE;
536                         }
537                 }
538
539                 if (!(file->selflag & EDITING_FILE))  {
540                         int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy;
541                         file_draw_string(sx+1, tpos, file->relname, (float)textwidth, textheight, align);
542                 }
543
544                 if (params->display == FILE_SHORTDISPLAY) {
545                         sx += (int)layout->column_widths[COLUMN_NAME] + 12;
546                         if (!(file->type & S_IFDIR)) {
547                                 file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);        
548                                 sx += (int)layout->column_widths[COLUMN_SIZE] + 12;
549                         }
550                 } else if (params->display == FILE_LONGDISPLAY) {
551                         sx += (int)layout->column_widths[COLUMN_NAME] + 12;
552
553 #ifndef WIN32
554                         /* rwx rwx rwx */
555                         file_draw_string(sx, sy, file->mode1, layout->column_widths[COLUMN_MODE1], layout->tile_h, align); 
556                         sx += layout->column_widths[COLUMN_MODE1] + 12;
557
558                         file_draw_string(sx, sy, file->mode2, layout->column_widths[COLUMN_MODE2], layout->tile_h, align);
559                         sx += layout->column_widths[COLUMN_MODE2] + 12;
560
561                         file_draw_string(sx, sy, file->mode3, layout->column_widths[COLUMN_MODE3], layout->tile_h, align);
562                         sx += layout->column_widths[COLUMN_MODE3] + 12;
563
564                         file_draw_string(sx, sy, file->owner, layout->column_widths[COLUMN_OWNER] , layout->tile_h, align);
565                         sx += layout->column_widths[COLUMN_OWNER] + 12;
566 #endif
567
568                         file_draw_string(sx, sy, file->date, layout->column_widths[COLUMN_DATE], layout->tile_h, align);
569                         sx += (int)layout->column_widths[COLUMN_DATE] + 12;
570
571                         file_draw_string(sx, sy, file->time, layout->column_widths[COLUMN_TIME] , layout->tile_h, align); 
572                         sx += (int)layout->column_widths[COLUMN_TIME] + 12;
573
574                         if (!(file->type & S_IFDIR)) {
575                                 file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
576                                 sx += (int)layout->column_widths[COLUMN_SIZE] + 12;
577                         }
578                 }
579         }
580
581         uiEndBlock(C, block);
582         uiDrawBlock(C, block);
583
584 }