Cleaning i18n code.
[blender.git] / source / blender / editors / interface / interface_regions.c
index 624f06db3c131622899a110c3dad269b8a9d306e..bc4e3cf9f131050b8ad2dac305cfbcb80eb09186 100644 (file)
 #include "UI_view2d.h"
 
 #include "BLF_api.h"
 #include "UI_view2d.h"
 
 #include "BLF_api.h"
+#include "BLF_translation.h"
 
 #include "ED_screen.h"
 
 #include "interface_intern.h"
 
 
 #include "ED_screen.h"
 
 #include "interface_intern.h"
 
-#define MENU_BUTTON_HEIGHT     20
 #define MENU_SEPR_HEIGHT       6
 #define B_NOP                  -1
 #define MENU_SHADOW_SIDE       8
 #define MENU_SEPR_HEIGHT       6
 #define B_NOP                  -1
 #define MENU_SHADOW_SIDE       8
@@ -84,7 +84,7 @@ typedef struct MenuEntry {
 } MenuEntry;
 
 typedef struct MenuData {
 } MenuEntry;
 
 typedef struct MenuData {
-       char *instr;
+       const char *instr;
        const char *title;
        int titleicon;
        
        const char *title;
        int titleicon;
        
@@ -92,7 +92,7 @@ typedef struct MenuData {
        int nitems, itemssize;
 } MenuData;
 
        int nitems, itemssize;
 } MenuData;
 
-static MenuData *menudata_new(char *instr)
+static MenuData *menudata_new(const char *instr)
 {
        MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
 
 {
        MenuData *md= MEM_mallocN(sizeof(*md), "MenuData");
 
@@ -137,7 +137,7 @@ static void menudata_add_item(MenuData *md, const char *str, int retval, int ico
 
 static void menudata_free(MenuData *md)
 {
 
 static void menudata_free(MenuData *md)
 {
-       MEM_freeN(md->instr);
+       MEM_freeN((void *)md->instr);
        if (md->items)
                MEM_freeN(md->items);
        MEM_freeN(md);
        if (md->items)
                MEM_freeN(md->items);
        MEM_freeN(md);
@@ -156,7 +156,7 @@ static void menudata_free(MenuData *md)
         * @param str String to be parsed.
         * @retval new menudata structure, free with menudata_free()
         */
         * @param str String to be parsed.
         * @retval new menudata structure, free with menudata_free()
         */
-static MenuData *decompose_menu_string(char *str) 
+static MenuData *decompose_menu_string(const char *str)
 {
        char *instr= BLI_strdup(str);
        MenuData *md= menudata_new(instr);
 {
        char *instr= BLI_strdup(str);
        MenuData *md= menudata_new(instr);
@@ -174,7 +174,7 @@ static MenuData *decompose_menu_string(char *str)
                                *s= '\0';
                                s++;
                        } else if (s[1]=='t') {
                                *s= '\0';
                                s++;
                        } else if (s[1]=='t') {
-                               nitem_is_title= 1;
+                               nitem_is_title= (s != instr); /* check for empty title */
 
                                *s= '\0';
                                s++;
 
                                *s= '\0';
                                s++;
@@ -213,11 +213,13 @@ static MenuData *decompose_menu_string(char *str)
                                nicon= 0;
                        }
                        
                                nicon= 0;
                        }
                        
-                       if (c=='\0')
+                       if (c=='\0') {
                                break;
                                break;
-               } else if (!nitem)
+                       }
+               } else if (!nitem) {
                        nitem= s;
                        nitem= s;
-               
+               }
+
                s++;
        }
        
                s++;
        }
        
@@ -230,9 +232,12 @@ void ui_set_name_menu(uiBut *but, int value)
        int i;
        
        md= decompose_menu_string(but->str);
        int i;
        
        md= decompose_menu_string(but->str);
-       for (i=0; i<md->nitems; i++)
-               if (md->items[i].retval==value)
-                       strcpy(but->drawstr, md->items[i].str);
+       for (i=0; i<md->nitems; i++) {
+               if (md->items[i].retval==value) {
+                       BLI_strncpy(but->drawstr, md->items[i].str, sizeof(but->drawstr));
+                       break;
+               }
+       }
        
        menudata_free(md);
 }
        
        menudata_free(md);
 }
@@ -319,7 +324,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
        rcti bbox= data->bbox;
        int a;
        
        rcti bbox= data->bbox;
        int a;
        
-       ui_draw_menu_back(U.uistyles.first, NULL, &data->bbox);
+       ui_draw_menu_back(UI_GetStyle(), NULL, &data->bbox);
        
        /* draw text */
        uiStyleFontSet(&data->fstyle);
        
        /* draw text */
        uiStyleFontSet(&data->fstyle);
@@ -346,7 +351,7 @@ static void ui_tooltip_region_free_cb(ARegion *ar)
 
 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 {
 
 ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 {
-       uiStyle *style= U.uistyles.first;       // XXX pass on as arg
+       uiStyle *style= UI_GetStyle();
        static ARegionType type;
        ARegion *ar;
        uiTooltipData *data;
        static ARegionType type;
        ARegion *ar;
        uiTooltipData *data;
@@ -362,7 +367,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
        /* create tooltip data */
        data= MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
 
        /* create tooltip data */
        data= MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
 
-       /* special case, enum rna buttons only have enum item description, use general enum description too before the spesific one */
+       /* special case, enum rna buttons only have enum item description, use general enum description too before the specific one */
        if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM) {
                const char *descr= RNA_property_description(but->rnaprop);
                if(descr && descr[0]) {
        if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM) {
                const char *descr= RNA_property_description(but->rnaprop);
                if(descr && descr[0]) {
@@ -370,6 +375,27 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                        data->color[data->totline]= 0xFFFFFF;
                        data->totline++;
                }
                        data->color[data->totline]= 0xFFFFFF;
                        data->totline++;
                }
+
+               if(but->type == ROW) {
+                       EnumPropertyItem *item;
+                       int i, totitem, free;
+
+                       RNA_property_enum_items_gettexted(C, &but->rnapoin, but->rnaprop, &item, &totitem, &free);
+
+                       for(i=0; i<totitem; i++) {
+                               if(item[i].identifier[0] && item[i].value == (int)but->hardmax) {
+                                       if(item[i].description[0]) {
+                                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "%s: %s", item[i].name, item[i].description);
+                                               data->color[data->totline]= 0xFFFFFF;
+                                               data->totline++;
+                                       }
+                                       break;
+                               }
+                       }
+
+                       if(free)
+                               MEM_freeN(item);
+               }
        }
        
        if(but->tip && strlen(but->tip)) {
        }
        
        if(but->tip && strlen(but->tip)) {
@@ -383,7 +409,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                prop= (but->opptr)? but->opptr->data: NULL;
 
                if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
                prop= (but->opptr)? but->opptr->data: NULL;
 
                if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
-                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Shortcut: %s", buf);
+                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Shortcut: %s"), buf);
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
@@ -393,7 +419,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                /* full string */
                ui_get_but_string(but, buf, sizeof(buf));
                if(buf[0]) {
                /* full string */
                ui_get_but_string(but, buf, sizeof(buf));
                if(buf[0]) {
-                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Value: %s", buf);
+                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Value: %s"), buf);
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
@@ -404,7 +430,8 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                
                if (unit_type == PROP_UNIT_ROTATION) {
                        if (RNA_property_type(but->rnaprop) == PROP_FLOAT) {
                
                if (unit_type == PROP_UNIT_ROTATION) {
                        if (RNA_property_type(but->rnaprop) == PROP_FLOAT) {
-                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Radians: %f", RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex));
+                               float value= RNA_property_array_check(but->rnaprop) ? RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex) : RNA_property_float_get(&but->rnapoin, but->rnaprop);
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Radians: %f"), value);
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
@@ -413,7 +440,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                if(but->flag & UI_BUT_DRIVEN) {
                        if(ui_but_anim_expression_get(but, buf, sizeof(buf))) {
                                /* expression */
                if(but->flag & UI_BUT_DRIVEN) {
                        if(ui_but_anim_expression_get(but, buf, sizeof(buf))) {
                                /* expression */
-                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Expression: %s", buf);
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Expression: %s"), buf);
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
@@ -421,7 +448,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
                /* rna info */
                if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
 
                /* rna info */
                if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
-                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Python: %s.%s"), RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
@@ -429,7 +456,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                if(but->rnapoin.id.data) {
                        ID *id= but->rnapoin.id.data;
                        if(id->lib && id->lib->name) {
                if(but->rnapoin.id.data) {
                        ID *id= but->rnapoin.id.data;
                        if(id->lib && id->lib->name) {
-                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Library: %s", id->lib->name);
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Library: %s"), id->lib->name);
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                                data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
@@ -444,7 +471,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
                /* operator info */
                if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
 
                /* operator info */
                if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
-                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s", str);
+                       BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Python: %s"), str);
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
                        data->color[data->totline]= 0x888888;
                        data->totline++;
                }
@@ -458,12 +485,23 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                        WM_operator_poll_context(C, but->optype, but->opcontext);
                        poll_msg= CTX_wm_operator_poll_msg_get(C);
                        if(poll_msg) {
                        WM_operator_poll_context(C, but->optype, but->opcontext);
                        poll_msg= CTX_wm_operator_poll_msg_get(C);
                        if(poll_msg) {
-                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Disabled: %s", poll_msg);
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Disabled: %s"), poll_msg);
                                data->color[data->totline]= 0x6666ff; /* alert */
                                data->totline++;                        
                        }
                }
        }
                                data->color[data->totline]= 0x6666ff; /* alert */
                                data->totline++;                        
                        }
                }
        }
+       else if (ELEM(but->type, MENU, PULLDOWN)) {
+               if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
+                       if(but->menu_create_func && WM_menutype_contains((MenuType *)but->poin)) {
+                               MenuType *mt= (MenuType *)but->poin;
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Python: %s"), mt->idname);
+                               data->color[data->totline]= 0x888888;
+                               data->totline++;
+                       }
+               }
+
+       }
 
        assert(data->totline < MAX_TOOLTIP_LINES);
        
 
        assert(data->totline < MAX_TOOLTIP_LINES);
        
@@ -654,7 +692,7 @@ int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int icon
 
 int uiSearchBoxhHeight(void)
 {
 
 int uiSearchBoxhHeight(void)
 {
-       return SEARCH_ITEMS*MENU_BUTTON_HEIGHT + 2*MENU_TOP;
+       return SEARCH_ITEMS*UI_UNIT_Y + 2*MENU_TOP;
 }
 
 /* ar is the search box itself */
 }
 
 /* ar is the search box itself */
@@ -951,11 +989,9 @@ static void ui_searchbox_region_free_cb(ARegion *ar)
        ar->regiondata= NULL;
 }
 
        ar->regiondata= NULL;
 }
 
-static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block);
-
 ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but)
 {
 ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but)
 {
-       uiStyle *style= U.uistyles.first;       // XXX pass on as arg
+       uiStyle *style= UI_GetStyle();
        static ARegionType type;
        ARegion *ar;
        uiSearchboxData *data;
        static ARegionType type;
        ARegion *ar;
        uiSearchboxData *data;
@@ -1159,7 +1195,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
        uiBut *bt;
        uiSafetyRct *saferct;
        rctf butrct;
        uiBut *bt;
        uiSafetyRct *saferct;
        rctf butrct;
-       float aspect;
+       /*float aspect;*/ /*UNUSED*/
        int xsize, ysize, xof=0, yof=0, center;
        short dir1= 0, dir2=0;
        
        int xsize, ysize, xof=0, yof=0, center;
        short dir1= 0, dir2=0;
        
@@ -1194,7 +1230,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
                }
        }
        
                }
        }
        
-       aspect= (float)(block->maxx - block->minx + 4);
+       /*aspect= (float)(block->maxx - block->minx + 4);*/ /*UNUSED*/
        ui_block_to_window_fl(butregion, but->block, &block->minx, &block->miny);
        ui_block_to_window_fl(butregion, but->block, &block->maxx, &block->maxy);
 
        ui_block_to_window_fl(butregion, but->block, &block->minx, &block->miny);
        ui_block_to_window_fl(butregion, but->block, &block->maxx, &block->maxy);
 
@@ -1203,23 +1239,31 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
        
        xsize= block->maxx - block->minx+4; // 4 for shadow
        ysize= block->maxy - block->miny+4;
        
        xsize= block->maxx - block->minx+4; // 4 for shadow
        ysize= block->maxy - block->miny+4;
-       aspect/= (float)xsize;
+       /*aspect/= (float)xsize;*/ /*UNUSED*/
 
 
-       if(but) {
+       {
                int left=0, right=0, top=0, down=0;
                int winx, winy;
                int left=0, right=0, top=0, down=0;
                int winx, winy;
-               int offscreen;
+               // int offscreen;
 
                wm_window_get_size(window, &winx, &winy);
 
                if(block->direction & UI_CENTER) center= ysize/2;
                else center= 0;
 
                wm_window_get_size(window, &winx, &winy);
 
                if(block->direction & UI_CENTER) center= ysize/2;
                else center= 0;
-
+               
+               /* check if there's space at all */
                if( butrct.xmin-xsize > 0.0f) left= 1;
                if( butrct.xmax+xsize < winx) right= 1;
                if( butrct.ymin-ysize+center > 0.0f) down= 1;
                if( butrct.ymax+ysize-center < winy) top= 1;
                
                if( butrct.xmin-xsize > 0.0f) left= 1;
                if( butrct.xmax+xsize < winx) right= 1;
                if( butrct.ymin-ysize+center > 0.0f) down= 1;
                if( butrct.ymax+ysize-center < winy) top= 1;
                
+               if(top==0 && down==0) {
+                       if (butrct.ymin-ysize < winy-butrct.ymax-ysize)
+                               top= 1;
+                       else
+                               down= 1;
+               }
+               
                dir1= block->direction & UI_DIRECTION;
 
                /* secundary directions */
                dir1= block->direction & UI_DIRECTION;
 
                /* secundary directions */
@@ -1284,7 +1328,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
                if(top==0 && down==0) {
                        if(dir1==UI_LEFT || dir1==UI_RIGHT) {
                                // align with bottom of screen 
                if(top==0 && down==0) {
                        if(dir1==UI_LEFT || dir1==UI_RIGHT) {
                                // align with bottom of screen 
-                               yof= ysize;
+                               // yof= ysize; (not with menu scrolls)
                        }
                }
                
                        }
                }
                
@@ -1299,15 +1343,16 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
                // apply requested offset in the block
                xof += block->xofs/block->aspect;
                yof += block->yofs/block->aspect;
                // apply requested offset in the block
                xof += block->xofs/block->aspect;
                yof += block->yofs/block->aspect;
-
+#if 0
                /* clamp to window bounds, could be made into an option if its ever annoying */
                if(     (offscreen= (block->miny+yof)) < 0)      yof -= offscreen; /* bottom */
                else if((offscreen= (block->maxy+yof)-winy) > 0) yof -= offscreen; /* top */
                if(     (offscreen= (block->minx+xof)) < 0)      xof -= offscreen; /* left */
                else if((offscreen= (block->maxx+xof)-winx) > 0) xof -= offscreen; /* right */
                /* clamp to window bounds, could be made into an option if its ever annoying */
                if(     (offscreen= (block->miny+yof)) < 0)      yof -= offscreen; /* bottom */
                else if((offscreen= (block->maxy+yof)-winy) > 0) yof -= offscreen; /* top */
                if(     (offscreen= (block->minx+xof)) < 0)      xof -= offscreen; /* left */
                else if((offscreen= (block->maxx+xof)-winx) > 0) xof -= offscreen; /* right */
+#endif
        }
        
        }
        
-       /* apply */
+       /* apply offset, buttons in window coords */
        
        for(bt= block->buttons.first; bt; bt= bt->next) {
                ui_block_to_window_fl(butregion, but->block, &bt->x1, &bt->y1);
        
        for(bt= block->buttons.first; bt; bt= bt->next) {
                ui_block_to_window_fl(butregion, but->block, &bt->x1, &bt->y1);
@@ -1381,6 +1426,62 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
                uiDrawBlock(C, block);
 }
 
                uiDrawBlock(C, block);
 }
 
+static void ui_popup_block_clip(wmWindow *window, uiBlock *block)
+{
+       int winx, winy;
+       
+       wm_window_get_size(window, &winx, &winy);
+       
+       if(block->minx < MENU_SHADOW_SIDE)
+               block->minx= MENU_SHADOW_SIDE;
+       if(block->maxx > winx-MENU_SHADOW_SIDE)
+               block->maxx= winx-MENU_SHADOW_SIDE;
+       
+       if(block->miny < MENU_SHADOW_BOTTOM)
+               block->miny= MENU_SHADOW_BOTTOM;
+       if(block->maxy > winy-MENU_TOP)
+               block->maxy= winy-MENU_TOP;
+}
+
+void ui_popup_block_scrolltest(uiBlock *block)
+{
+       uiBut *bt;
+       
+       block->flag &= ~(UI_BLOCK_CLIPBOTTOM|UI_BLOCK_CLIPTOP);
+       
+       for(bt= block->buttons.first; bt; bt= bt->next)
+               bt->flag &= ~UI_SCROLLED;
+       
+       if(block->buttons.first==block->buttons.last)
+               return;
+       
+       /* mark buttons that are outside boundary and the ones next to it for arrow(s) */
+       for(bt= block->buttons.first; bt; bt= bt->next) {
+               if(bt->y1 < block->miny) {
+                       bt->flag |= UI_SCROLLED;
+                       block->flag |= UI_BLOCK_CLIPBOTTOM;
+                       /* make space for arrow */
+                       if(bt->y2 < block->miny +10) {
+                               if(bt->next && bt->next->y1 > bt->y1)
+                                       bt->next->flag |= UI_SCROLLED;
+                               if(bt->prev && bt->prev->y1 > bt->y1)
+                                       bt->prev->flag |= UI_SCROLLED;
+                       }
+               }
+               if(bt->y2 > block->maxy) {
+                       bt->flag |= UI_SCROLLED;
+                       block->flag |= UI_BLOCK_CLIPTOP;
+                       /* make space for arrow */
+                       if(bt->y1 > block->maxy -10) {
+                               if(bt->next && bt->next->y2 < bt->y2)
+                                       bt->next->flag |= UI_SCROLLED;
+                               if(bt->prev && bt->prev->y2 < bt->y2)
+                                       bt->prev->flag |= UI_SCROLLED;
+                       }
+               }
+       }
+}
+
 uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, void *arg)
 {
        wmWindow *window= CTX_wm_window(C);
 uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, void *arg)
 {
        wmWindow *window= CTX_wm_window(C);
@@ -1451,6 +1552,9 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut
                block->flag |= UI_BLOCK_POPUP|UI_BLOCK_NUMSELECT;
        }
 
                block->flag |= UI_BLOCK_POPUP|UI_BLOCK_NUMSELECT;
        }
 
+       /* clip block with window boundary */
+       ui_popup_block_clip(window, block);
+       
        /* the block and buttons were positioned in window space as in 2.4x, now
         * these menu blocks are regions so we bring it back to region space.
         * additionally we add some padding for the menu shadow or rounded menus */
        /* the block and buttons were positioned in window space as in 2.4x, now
         * these menu blocks are regions so we bring it back to region space.
         * additionally we add some padding for the menu shadow or rounded menus */
@@ -1458,7 +1562,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut
        ar->winrct.xmax= block->maxx + MENU_SHADOW_SIDE;
        ar->winrct.ymin= block->miny - MENU_SHADOW_BOTTOM;
        ar->winrct.ymax= block->maxy + MENU_TOP;
        ar->winrct.xmax= block->maxx + MENU_SHADOW_SIDE;
        ar->winrct.ymin= block->miny - MENU_SHADOW_BOTTOM;
        ar->winrct.ymax= block->maxy + MENU_TOP;
-
+       
        block->minx -= ar->winrct.xmin;
        block->maxx -= ar->winrct.xmin;
        block->miny -= ar->winrct.ymin;
        block->minx -= ar->winrct.xmin;
        block->maxx -= ar->winrct.xmin;
        block->miny -= ar->winrct.ymin;
@@ -1470,12 +1574,15 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut
                bt->y1 -= ar->winrct.ymin;
                bt->y2 -= ar->winrct.ymin;
        }
                bt->y1 -= ar->winrct.ymin;
                bt->y2 -= ar->winrct.ymin;
        }
-
+       
        block->flag |= UI_BLOCK_LOOP;
 
        /* adds subwindow */
        ED_region_init(C, ar);
 
        block->flag |= UI_BLOCK_LOOP;
 
        /* adds subwindow */
        ED_region_init(C, ar);
 
+       /* checks which buttons are visible, sets flags to prevent draw (do after region init) */
+       ui_popup_block_scrolltest(block);
+       
        /* get winmat now that we actually have the subwindow */
        wmSubWindowSet(window, ar->swinid);
        
        /* get winmat now that we actually have the subwindow */
        wmSubWindowSet(window, ar->swinid);
        
@@ -1490,6 +1597,10 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut
 void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle)
 {
        ui_remove_temporary_region(C, CTX_wm_screen(C), handle->region);
 void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle)
 {
        ui_remove_temporary_region(C, CTX_wm_screen(C), handle->region);
+       
+       if(handle->scrolltimer)
+               WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), handle->scrolltimer);
+       
        MEM_freeN(handle);
 }
 
        MEM_freeN(handle);
 }
 
@@ -1503,7 +1614,7 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
        uiBut *bt;
        MenuData *md;
        MenuEntry *entry;
        uiBut *bt;
        MenuData *md;
        MenuEntry *entry;
-       char *instr= arg_str;
+       const char *instr= arg_str;
        int columns, rows, a, b;
 
        uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
        int columns, rows, a, b;
 
        uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
@@ -1537,11 +1648,12 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
        }
 
        /* inconsistent, but menus with labels do not look good flipped */
        }
 
        /* inconsistent, but menus with labels do not look good flipped */
-       for(a=0, b=0; a<md->nitems; a++, b++) {
-               entry= &md->items[a];
-
-               if(entry->sepr && entry->str[0])
+       entry= md->items;
+       for(a=0; a<md->nitems; a++, entry++) {
+               if(entry->sepr && entry->str[0]) {
                        block->flag |= UI_BLOCK_NO_FLIP;
                        block->flag |= UI_BLOCK_NO_FLIP;
+                       break;
+               }
        }
 
        /* create items */
        }
 
        /* create items */
@@ -1690,7 +1802,7 @@ static void ui_update_block_buts_rgb(uiBlock *block, float *rgb)
                        if (rgb_gamma[1] > 1.0f) rgb_gamma[1] = modf(rgb_gamma[1], &intpart);
                        if (rgb_gamma[2] > 1.0f) rgb_gamma[2] = modf(rgb_gamma[2], &intpart);
 
                        if (rgb_gamma[1] > 1.0f) rgb_gamma[1] = modf(rgb_gamma[1], &intpart);
                        if (rgb_gamma[2] > 1.0f) rgb_gamma[2] = modf(rgb_gamma[2], &intpart);
 
-                       sprintf(col, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
+                       BLI_snprintf(col, sizeof(col), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
                        
                        strcpy(bt->poin, col);
                }
                        
                        strcpy(bt->poin, col);
                }
@@ -1830,31 +1942,31 @@ static void do_picker_new_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(a
 
 #define PICKER_TOTAL_W (PICKER_W+PICKER_SPACE+PICKER_BAR)
 
 
 #define PICKER_TOTAL_W (PICKER_W+PICKER_SPACE+PICKER_BAR)
 
-static void circle_picker(uiBlock *block, PointerRNA *ptr, const char *propname)
+static void circle_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop)
 {
        uiBut *bt;
        
        /* HS circle */
 {
        uiBut *bt;
        
        /* HS circle */
-       bt= uiDefButR(block, HSVCIRCLE, 0, "",  0, 0, PICKER_H, PICKER_W, ptr, propname, 0, 0.0, 0.0, 0, 0, "Color");
+       bt= uiDefButR_prop(block, HSVCIRCLE, 0, "",     0, 0, PICKER_H, PICKER_W, ptr, prop, 0, 0.0, 0.0, 0, 0, "Color");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        
        /* value */
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        
        /* value */
-       bt= uiDefButR(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, propname, 0, 0.0, 0.0, UI_GRAD_V_ALT, 0, "Value");
+       bt= uiDefButR_prop(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, prop, 0, 0.0, 0.0, UI_GRAD_V_ALT, 0, "Value");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 }
 
 
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 }
 
 
-static void square_picker(uiBlock *block, PointerRNA *ptr, const char *propname, int type)
+static void square_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type)
 {
        uiBut *bt;
        int bartype = type + 3;
        
        /* HS square */
 {
        uiBut *bt;
        int bartype = type + 3;
        
        /* HS square */
-       bt= uiDefButR(block, HSVCUBE, 0, "",    0, PICKER_BAR+PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, propname, 0, 0.0, 0.0, type, 0, "Color");
+       bt= uiDefButR_prop(block, HSVCUBE, 0, "",       0, PICKER_BAR+PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, prop, 0, 0.0, 0.0, type, 0, "Color");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        
        /* value */
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        
        /* value */
-       bt= uiDefButR(block, HSVCUBE, 0, "",            0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, propname, 0, 0.0, 0.0, bartype, 0, "Value");
+       bt= uiDefButR_prop(block, HSVCUBE, 0, "",               0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, prop, 0, 0.0, 0.0, bartype, 0, "Value");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 }
 
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 }
 
@@ -1869,7 +1981,6 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
        static char hexcol[128];
        float rgb_gamma[3];
        float min, max, step, precision;
        static char hexcol[128];
        float rgb_gamma[3];
        float min, max, step, precision;
-       const char *propname = RNA_property_identifier(prop);
        float *hsv= ui_block_hsv_get(block);
        
        ui_block_hsv_get(block);
        float *hsv= ui_block_hsv_get(block);
        
        ui_block_hsv_get(block);
@@ -1879,10 +1990,10 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
        
        /* existence of profile means storage is in linear color space, with display correction */
        if (block->color_profile == BLI_PR_NONE) {
        
        /* existence of profile means storage is in linear color space, with display correction */
        if (block->color_profile == BLI_PR_NONE) {
-               sprintf(tip, "Value in Display Color Space");
+               BLI_strncpy(tip, "Value in Display Color Space", sizeof(tip));
                copy_v3_v3(rgb_gamma, rgb);
        } else {
                copy_v3_v3(rgb_gamma, rgb);
        } else {
-               sprintf(tip, "Value in Linear RGB Color Space");
+               BLI_strncpy(tip, "Value in Linear RGB Color Space", sizeof(tip));
                /* make an sRGB version, for Hex code */
                linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
        }
                /* make an sRGB version, for Hex code */
                linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
        }
@@ -1895,16 +2006,16 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
 
        switch (U.color_picker_type) {
                case USER_CP_CIRCLE:
 
        switch (U.color_picker_type) {
                case USER_CP_CIRCLE:
-                       circle_picker(block, ptr, propname);
+                       circle_picker(block, ptr, prop);
                        break;
                case USER_CP_SQUARE_SV:
                        break;
                case USER_CP_SQUARE_SV:
-                       square_picker(block, ptr, propname, UI_GRAD_SV);
+                       square_picker(block, ptr, prop, UI_GRAD_SV);
                        break;
                case USER_CP_SQUARE_HS:
                        break;
                case USER_CP_SQUARE_HS:
-                       square_picker(block, ptr, propname, UI_GRAD_HS);
+                       square_picker(block, ptr, prop, UI_GRAD_HS);
                        break;
                case USER_CP_SQUARE_HV:
                        break;
                case USER_CP_SQUARE_HV:
-                       square_picker(block, ptr, propname, UI_GRAD_HV);
+                       square_picker(block, ptr, prop, UI_GRAD_HV);
                        break;
        }
        
                        break;
        }
        
@@ -1923,11 +2034,11 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
        
        /* RGB values */
        uiBlockBeginAlign(block);
        
        /* RGB values */
        uiBlockBeginAlign(block);
-       bt= uiDefButR(block, NUMSLI, 0, "R ",   0, -60, butwidth, UI_UNIT_Y, ptr, propname, 0, 0.0, 0.0, 0, 3, "Red");
+       bt= uiDefButR_prop(block, NUMSLI, 0, "R ",      0, -60, butwidth, UI_UNIT_Y, ptr, prop, 0, 0.0, 0.0, 0, 3, "Red");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
-       bt= uiDefButR(block, NUMSLI, 0, "G ",   0, -80, butwidth, UI_UNIT_Y, ptr, propname, 1, 0.0, 0.0, 0, 3, "Green");
+       bt= uiDefButR_prop(block, NUMSLI, 0, "G ",      0, -80, butwidth, UI_UNIT_Y, ptr, prop, 1, 0.0, 0.0, 0, 3, "Green");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
-       bt= uiDefButR(block, NUMSLI, 0, "B ",   0, -100, butwidth, UI_UNIT_Y, ptr, propname, 2, 0.0, 0.0, 0, 3, "Blue");
+       bt= uiDefButR_prop(block, NUMSLI, 0, "B ",      0, -100, butwidth, UI_UNIT_Y, ptr, prop, 2, 0.0, 0.0, 0, 3, "Blue");
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 
        // could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE);
        uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
 
        // could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE);
@@ -1944,14 +2055,14 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
        uiBlockEndAlign(block);
 
        if(rgb[3] != FLT_MAX) {
        uiBlockEndAlign(block);
 
        if(rgb[3] != FLT_MAX) {
-               bt= uiDefButR(block, NUMSLI, 0, "A ",   0, -120, butwidth, UI_UNIT_Y, ptr, propname, 3, 0.0, 0.0, 0, 0, "Alpha");
+               bt= uiDefButR_prop(block, NUMSLI, 0, "A ",      0, -120, butwidth, UI_UNIT_Y, ptr, prop, 3, 0.0, 0.0, 0, 0, "Alpha");
                uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        }
        else {
                rgb[3]= 1.0f;
        }
 
                uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
        }
        else {
                rgb[3]= 1.0f;
        }
 
-       sprintf(hexcol, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
+       BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
 
        bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
        uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
 
        bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
        uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
@@ -2045,7 +2156,7 @@ static int ui_popup_string_hash(char *str)
        return hash;
 }
 
        return hash;
 }
 
-static int ui_popup_menu_hash(char *str)
+static int ui_popup_menu_hash(const char *str)
 {
        return BLI_ghashutil_strhash(str);
 }
 {
        return BLI_ghashutil_strhash(str);
 }
@@ -2095,8 +2206,6 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
 {
        uiBlock *block;
        uiBut *bt;
 {
        uiBlock *block;
        uiBut *bt;
-       ScrArea *sa;
-       ARegion *ar;
        uiPopupMenu *pup= arg_pup;
        int offset[2], direction, minwidth, width, height, flip;
 
        uiPopupMenu *pup= arg_pup;
        int offset[2], direction, minwidth, width, height, flip;
 
@@ -2150,7 +2259,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
                           the offset is negative because we are inverse moving the
                           block to be under the mouse */
                        offset[0]= -(bt->x1 + 0.8f*(bt->x2 - bt->x1));
                           the offset is negative because we are inverse moving the
                           block to be under the mouse */
                        offset[0]= -(bt->x1 + 0.8f*(bt->x2 - bt->x1));
-                       offset[1]= -(bt->y1 + 0.5f*MENU_BUTTON_HEIGHT);
+                       offset[1]= -(bt->y1 + 0.5f*UI_UNIT_Y);
                }
                else {
                        /* position mouse at 0.8*width of the button and below the tile
                }
                else {
                        /* position mouse at 0.8*width of the button and below the tile
@@ -2159,7 +2268,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
                        for(bt=block->buttons.first; bt; bt=bt->next)
                                offset[0]= MIN2(offset[0], -(bt->x1 + 0.8f*(bt->x2 - bt->x1)));
 
                        for(bt=block->buttons.first; bt; bt=bt->next)
                                offset[0]= MIN2(offset[0], -(bt->x1 + 0.8f*(bt->x2 - bt->x1)));
 
-                       offset[1]= 1.5*MENU_BUTTON_HEIGHT;
+                       offset[1]= 1.5*UI_UNIT_Y;
                }
 
                block->minbounds= minwidth;
                }
 
                block->minbounds= minwidth;
@@ -2168,10 +2277,9 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
        else {
                /* for a header menu we set the direction automatic */
                if(!pup->slideout && flip) {
        else {
                /* for a header menu we set the direction automatic */
                if(!pup->slideout && flip) {
-                       sa= CTX_wm_area(C);
-                       ar= CTX_wm_region(C);
-
+                       ScrArea *sa= CTX_wm_area(C);
                        if(sa && sa->headertype==HEADERDOWN) {
                        if(sa && sa->headertype==HEADERDOWN) {
+                               ARegion *ar= CTX_wm_region(C);
                                if(ar && ar->regiontype == RGN_TYPE_HEADER) {
                                        uiBlockSetDirection(block, UI_TOP);
                                        uiBlockFlipOrder(block);
                                if(ar && ar->regiontype == RGN_TYPE_HEADER) {
                                        uiBlockSetDirection(block, UI_TOP);
                                        uiBlockFlipOrder(block);
@@ -2195,10 +2303,9 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
 uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg, char *str)
 {
        wmWindow *window= CTX_wm_window(C);
 uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg, char *str)
 {
        wmWindow *window= CTX_wm_window(C);
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        uiPopupBlockHandle *handle;
        uiPopupMenu *pup;
        uiPopupBlockHandle *handle;
        uiPopupMenu *pup;
-       
        pup= MEM_callocN(sizeof(uiPopupMenu), "menu dummy");
        pup->block= uiBeginBlock(C, NULL, "ui_button_menu_create", UI_EMBOSSP);
        pup->layout= uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style);
        pup= MEM_callocN(sizeof(uiPopupMenu), "menu dummy");
        pup->block= uiBeginBlock(C, NULL, "ui_button_menu_create", UI_EMBOSSP);
        pup->layout= uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style);
@@ -2213,6 +2320,19 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut
                pup->popup= 1;
                pup->block->flag |= UI_BLOCK_NO_FLIP;
        }
                pup->popup= 1;
                pup->block->flag |= UI_BLOCK_NO_FLIP;
        }
+       /* some enums reversing is strange, currently we have no good way to
+        * reverse some enum's but not others, so reverse all so the first menu
+        * items are always close to the mouse cursor */
+#if 0
+       else {
+               /* if this is an rna button then we can assume its an enum
+                * flipping enums is generally not good since the order can be
+                * important [#28786] */
+               if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM) {
+                       pup->block->flag |= UI_BLOCK_NO_FLIP;
+               }
+       }
+#endif
 
        if(str) {
                /* menu is created from a string */
 
        if(str) {
                /* menu is created from a string */
@@ -2244,7 +2364,7 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut
 /* only return handler, and set optional title */
 uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon)
 {
 /* only return handler, and set optional title */
 uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon)
 {
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        uiPopupMenu *pup= MEM_callocN(sizeof(uiPopupMenu), "popup menu");
        uiBut *but;
        
        uiPopupMenu *pup= MEM_callocN(sizeof(uiPopupMenu), "popup menu");
        uiBut *but;
        
@@ -2262,11 +2382,11 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon)
                char titlestr[256];
                
                if(icon) {
                char titlestr[256];
                
                if(icon) {
-                       sprintf(titlestr, " %s", title);
-                       uiDefIconTextBut(pup->block, LABEL, 0, icon, titlestr, 0, 0, 200, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
+                       BLI_snprintf(titlestr, sizeof(titlestr), " %s", title);
+                       uiDefIconTextBut(pup->block, LABEL, 0, icon, titlestr, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
                }
                else {
                }
                else {
-                       but= uiDefBut(pup->block, LABEL, 0, title, 0, 0, 200, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
+                       but= uiDefBut(pup->block, LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
                        but->flag= UI_TEXT_LEFT;
                }
        }
                        but->flag= UI_TEXT_LEFT;
                }
        }
@@ -2360,7 +2480,7 @@ void uiPupMenuOkee(bContext *C, const char *opname, const char *str, ...)
        va_list ap;
        char titlestr[256];
 
        va_list ap;
        char titlestr[256];
 
-       sprintf(titlestr, "OK? %%i%d", ICON_QUESTION);
+       BLI_snprintf(titlestr, sizeof(titlestr), "OK? %%i%d", ICON_QUESTION);
 
        va_start(ap, str);
        vconfirm_opname(C, opname, titlestr, str, ap);
 
        va_start(ap, str);
        vconfirm_opname(C, opname, titlestr, str, ap);
@@ -2400,9 +2520,9 @@ void uiPupMenuError(bContext *C, const char *str, ...)
        char nfmt[256];
        char titlestr[256];
 
        char nfmt[256];
        char titlestr[256];
 
-       sprintf(titlestr, "Error %%i%d", ICON_ERROR);
+       BLI_snprintf(titlestr, sizeof(titlestr), "Error %%i%d", ICON_ERROR);
 
 
-       sprintf(nfmt, "%s", str);
+       BLI_strncpy(nfmt, str, sizeof(nfmt));
 
        va_start(ap, str);
        vconfirm_opname(C, NULL, titlestr, nfmt, ap);
 
        va_start(ap, str);
        vconfirm_opname(C, NULL, titlestr, nfmt, ap);
@@ -2449,7 +2569,7 @@ void uiPupMenuInvoke(bContext *C, const char *idname)
        MenuType *mt= WM_menutype_find(idname, TRUE);
 
        if(mt==NULL) {
        MenuType *mt= WM_menutype_find(idname, TRUE);
 
        if(mt==NULL) {
-               printf("uiPupMenuInvoke: named menu \"%s\" not found\n", idname);
+               printf("%s: named menu \"%s\" not found\n", __func__, idname);
                return;
        }
 
                return;
        }
 
@@ -2489,6 +2609,25 @@ void uiPupBlock(bContext *C, uiBlockCreateFunc func, void *arg)
        uiPupBlockO(C, func, arg, NULL, 0);
 }
 
        uiPupBlockO(C, func, arg, NULL, 0);
 }
 
+void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockCancelFunc cancel_func, void *arg)
+{
+       wmWindow *window= CTX_wm_window(C);
+       uiPopupBlockHandle *handle;
+       
+       handle= ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
+       handle->popup= 1;
+       handle->retvalue= 1;
+
+       handle->popup_arg= arg;
+       // handle->popup_func= operator_cb;
+       handle->cancel_func= cancel_func;
+       // handle->opcontext= opcontext;
+       
+       UI_add_popup_handlers(C, &window->modalhandlers, handle);
+       WM_event_add_mousemove(C);
+}
+
+#if 0 /* UNUSED */
 void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int opcontext)
 {
        wmWindow *window= CTX_wm_window(C);
 void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int opcontext)
 {
        wmWindow *window= CTX_wm_window(C);
@@ -2506,6 +2645,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int
        UI_add_popup_handlers(C, &window->modalhandlers, handle);
        WM_event_add_mousemove(C);
 }
        UI_add_popup_handlers(C, &window->modalhandlers, handle);
        WM_event_add_mousemove(C);
 }
+#endif
 
 void uiPupBlockClose(bContext *C, uiBlock *block)
 {
 
 void uiPupBlockClose(bContext *C, uiBlock *block)
 {