Merging r50470 through r50477 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index 420cae8..dcd652a 100644 (file)
@@ -50,6 +50,8 @@
 #include "BLI_utildefines.h"
 #include "BLI_string_cursor_utf8.h"
 
+#include "BLF_translation.h"
+
 #include "PIL_time.h"
 
 #include "BKE_colortools.h"
@@ -254,13 +256,42 @@ static uiBut *ui_but_last(uiBlock *block)
 
 static int ui_is_a_warp_but(uiBut *but)
 {
-       if (U.uiflag & USER_CONTINUOUS_MOUSE)
-               if (ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW))
+       if (U.uiflag & USER_CONTINUOUS_MOUSE) {
+               if (ELEM6(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW, HSVCUBE, BUT_CURVE)) {
                        return TRUE;
+               }
+       }
 
        return FALSE;
 }
 
+static float ui_mouse_scale_warp_factor(const short shift)
+{
+       if (U.uiflag & USER_CONTINUOUS_MOUSE) {
+               return shift ? 0.05f : 1.0f;
+       }
+       else {
+               return 1.0f;
+       }
+}
+
+static void ui_mouse_scale_warp(uiHandleButtonData *data,
+                                const float mx, const float my,
+                                float *r_mx, float *r_my,
+                                const short shift)
+{
+       if (U.uiflag & USER_CONTINUOUS_MOUSE) {
+               const float fac = ui_mouse_scale_warp_factor(shift);
+               /* slow down the mouse, this is fairly picky */
+               *r_mx = (data->dragstartx * (1.0f - fac) + mx * fac);
+               *r_my = (data->dragstarty * (1.0f - fac) + my * fac);
+       }
+       else {
+               *r_mx = mx;
+               *r_my = my;
+       }
+}
+
 /* file selectors are exempt from utf-8 checks */
 int ui_is_but_utf8(uiBut *but)
 {
@@ -286,7 +317,9 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
         * handling is done, i.e. menus are closed, in order to avoid conflicts
         * with these functions removing the buttons we are working with */
 
-       if (but->func || but->funcN || block->handle_func || but->rename_func || (but->type == BUTM && block->butm_func) || but->optype || but->rnaprop) {
+       if (but->func || but->funcN || block->handle_func || but->rename_func ||
+           (but->type == BUTM && block->butm_func) || but->optype || but->rnaprop)
+       {
                after = MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
 
                if (but->func && ELEM(but, but->func_arg1, but->func_arg2)) {
@@ -468,9 +501,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
        lvalue = (int)value;
        
        if (but->bit) {
-               w = BTST(lvalue, but->bitnr);
-               if (w) lvalue = BCLR(lvalue, but->bitnr);
-               else lvalue = BSET(lvalue, but->bitnr);
+               w = UI_BITBUT_TEST(lvalue, but->bitnr);
+               if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr);
+               else   lvalue = UI_BITBUT_SET(lvalue, but->bitnr);
                
                if (but->type == TOGR) {
                        if (!data->togonly) {
@@ -572,27 +605,27 @@ static void ui_apply_but_TOG3(bContext *C, uiBut *but, uiHandleButtonData *data)
        if (but->pointype == SHO) {
                short *sp = (short *)but->poin;
                
-               if (BTST(sp[1], but->bitnr)) {
-                       sp[1] = BCLR(sp[1], but->bitnr);
-                       sp[0] = BCLR(sp[0], but->bitnr);
+               if (UI_BITBUT_TEST(sp[1], but->bitnr)) {
+                       sp[1] = UI_BITBUT_CLR(sp[1], but->bitnr);
+                       sp[0] = UI_BITBUT_CLR(sp[0], but->bitnr);
                }
-               else if (BTST(sp[0], but->bitnr)) {
-                       sp[1] = BSET(sp[1], but->bitnr);
+               else if (UI_BITBUT_TEST(sp[0], but->bitnr)) {
+                       sp[1] = UI_BITBUT_SET(sp[1], but->bitnr);
                }
                else {
-                       sp[0] = BSET(sp[0], but->bitnr);
+                       sp[0] = UI_BITBUT_SET(sp[0], but->bitnr);
                }
        }
        else {
-               if (BTST(*(but->poin + 2), but->bitnr)) {
-                       *(but->poin + 2) = BCLR(*(but->poin + 2), but->bitnr);
-                       *(but->poin) = BCLR(*(but->poin), but->bitnr);
+               if (UI_BITBUT_TEST(*(but->poin + 2), but->bitnr)) {
+                       *(but->poin + 2) = UI_BITBUT_CLR(*(but->poin + 2), but->bitnr);
+                       *(but->poin)     = UI_BITBUT_CLR(*(but->poin),     but->bitnr);
                }
-               else if (BTST(*(but->poin), but->bitnr)) {
-                       *(but->poin + 2) = BSET(*(but->poin + 2), but->bitnr);
+               else if (UI_BITBUT_TEST(*(but->poin), but->bitnr)) {
+                       *(but->poin + 2) = UI_BITBUT_SET(*(but->poin + 2), but->bitnr);
                }
                else {
-                       *(but->poin) = BSET(*(but->poin), but->bitnr);
+                       *(but->poin) = UI_BITBUT_SET(*(but->poin), but->bitnr);
                }
        }
        
@@ -653,20 +686,19 @@ static int ui_but_mouse_inside_icon(uiBut *but, ARegion *ar, wmEvent *event)
        
        ui_window_to_block(ar, but->block, &x, &y);
        
-       rect.xmin = but->x1; rect.xmax = but->x2;
-       rect.ymin = but->y1; rect.ymax = but->y2;
+       BLI_rcti_rctf_copy(&rect, &but->rect);
        
        if (but->imb) ;  /* use button size itself */
        else if (but->flag & UI_ICON_LEFT) {
-               rect.xmax = rect.xmin + (rect.ymax - rect.ymin);
+               rect.xmax = rect.xmin + (BLI_RCT_SIZE_Y(&rect));
        }
        else {
-               int delta = (rect.xmax - rect.xmin) - (rect.ymax - rect.ymin);
+               int delta = BLI_RCT_SIZE_X(&rect) - BLI_RCT_SIZE_Y(&rect);
                rect.xmin += delta / 2;
                rect.xmax -= delta / 2;
        }
        
-       return BLI_in_rcti(&rect, x, y);
+       return BLI_rcti_isect_pt(&rect, x, y);
 }
 
 static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event)
@@ -682,7 +714,7 @@ static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data,
                
                drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but));
                if (but->imb)
-                       WM_event_drag_image(drag, but->imb, but->imb_scale, but->x2 - but->x1, but->y2 - but->y1);
+                       WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_RCT_SIZE_X(&but->rect), BLI_RCT_SIZE_Y(&but->rect));
                return 1;
        }
        
@@ -781,9 +813,9 @@ static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to)
        act_to = (bActuator *)(to->poin);
 
        /* (1) get the object */
-       CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) {
-               for (sens_iter = ob_iter->sensors.first; sens_iter; sens_iter = sens_iter->next)
-               {
+       CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects)
+       {
+               for (sens_iter = ob_iter->sensors.first; sens_iter; sens_iter = sens_iter->next) {
                        if (&(sens_iter->links) == sens_from_links) {
                                ob = ob_iter;
                                break;
@@ -800,12 +832,13 @@ static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to)
                        break;
        }
 
-       // only works if the sensor and the actuator are from the same object
+       /* only works if the sensor and the actuator are from the same object */
        if (!act_iter) return;
 
        /* (3) add a new controller */
        if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, NULL) & OPERATOR_FINISHED) {
                cont = (bController *)ob->controllers.last;
+               cont->type = CONT_LOGIC_AND; /* Quick fix to make sure we always have an AND controller. It might be nicer to make sure the operator gives us the right one though... */
 
                /* (4) link the sensor->controller->actuator */
                tmp_but = MEM_callocN(sizeof(uiBut), "uiBut");
@@ -1017,7 +1050,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                        ui_apply_but_BLOCK(C, but, data);
                        break;
                case COL:
-                       if(data->cancel)
+                       if (data->cancel)
                                ui_apply_but_VEC(C, but, data);
                        else
                                ui_apply_but_BLOCK(C, but, data);
@@ -1107,8 +1140,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
        static ColorBand but_copypaste_coba = {0};
        char buf[UI_MAX_DRAW_STR + 1] = {0};
 
-       if (mode == 'v' && but->lock)
+       if (mode == 'v' && but->lock  == TRUE) {
                return;
+       }
 
        if (mode == 'v') {
                /* extract first line from clipboard in case of multi-line copies */
@@ -1153,12 +1187,20 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                else if (mode == 'c') {
 
                        ui_get_but_vectorf(but, rgb);
+                       /* convert to linear color to do compatible copy between gamma and non-gamma */
+                       if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
+                               srgb_to_linearrgb_v3_v3(rgb, rgb);
+
                        BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
                        WM_clipboard_text_set(buf, 0);
                        
                }
                else {
                        if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) {
+                               /* assume linear colors in buffer */
+                               if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
+                                       linearrgb_to_srgb_v3_v3(rgb, rgb);
+
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
                                ui_set_but_vectorf(but, rgb);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -1207,7 +1249,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                                but->poin = MEM_callocN(sizeof(ColorBand), "colorband");
 
                        button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
-                       memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand) );
+                       memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand));
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
                }
        }
@@ -1249,7 +1291,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
 {
        uiStyle *style = UI_GetStyle();  // XXX pass on as arg
        uiFontStyle *fstyle = &style->widget;
-       int startx = but->x1;
+       int startx = but->rect.xmin;
        char *origstr;
 
        uiStyleFontSet(fstyle);
@@ -1263,7 +1305,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
        
        /* XXX solve generic */
        if (but->type == NUM || but->type == NUMSLI)
-               startx += (int)(0.5f * (but->y2 - but->y1));
+               startx += (int)(0.5f * (BLI_RCT_SIZE_Y(&but->rect)));
        else if (ELEM(but->type, TEX, SEARCH_MENU)) {
                startx += 5;
                if (but->flag & UI_HAS_ICON)
@@ -1305,7 +1347,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
 
                        /* check if position is found */
                        if (cdist < x) {
-                               /* check is previous location was infact closer */
+                               /* check is previous location was in fact closer */
                                if (((float)x - cdist) > (cdist_prev - (float)x)) {
                                        but->pos = pos_prev;
                                }
@@ -1564,8 +1606,7 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
                                len = strlen(str);
                        }
                        
-                       for (y = 0; y < strlen(buf); y++)
-                       {
+                       for (y = 0; y < strlen(buf); y++) {
                                /* add contents of buffer */
                                if (len + 1 < data->maxlen) {
                                        for (x = data->maxlen; x > but->pos; x--)
@@ -1750,8 +1791,8 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
                        retval = WM_UI_HANDLER_BREAK;
                        break;
-               case LEFTMOUSE: {
-                       
+               case LEFTMOUSE:
+               {
                        /* exit on LMB only on RELEASE for searchbox, to mimic other popups, and allow multiple menu levels */
                        if (data->searchbox)
                                inbox = ui_searchbox_inside(data->searchbox, event->x, event->y);
@@ -1917,7 +1958,8 @@ static void ui_do_but_textedit_select(bContext *C, uiBlock *block, uiBut *but, u
        int mx, my, retval = WM_UI_HANDLER_CONTINUE;
 
        switch (event->type) {
-               case MOUSEMOVE: {
+               case MOUSEMOVE:
+               {
                        mx = event->x;
                        my = event->y;
                        ui_window_to_block(data->region, block, &mx, &my);
@@ -2062,7 +2104,7 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data
        }
 
        /* this makes adjacent blocks auto open from now on */
-       //if(but->block->auto_open==0) but->block->auto_open= 1;
+       //if (but->block->auto_open ==0 ) but->block->auto_open = 1;
 }
 
 static void ui_blockopen_end(bContext *C, uiBut *but, uiHandleButtonData *data)
@@ -2294,7 +2336,7 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa
                
                if (ui_is_but_unit(but)) {
                        UnitSettings *unit = but->block->unit;
-                       int unit_type = uiButGetUnitType(but) >> 16;
+                       int unit_type = RNA_SUBTYPE_UNIT_VALUE(uiButGetUnitType(but));
 
                        if (bUnit_IsValid(unit->system, unit_type)) {
                                fac = (float)bUnit_BaseScalar(unit->system, unit_type);
@@ -2505,11 +2547,11 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                /* XXX hardcoded keymap check.... */
                if (event->type == WHEELDOWNMOUSE && event->alt) {
-                       mx = but->x1;
+                       mx = but->rect.xmin;
                        click = 1;
                }
                else if (event->type == WHEELUPMOUSE && event->alt) {
-                       mx = but->x2;
+                       mx = but->rect.xmax;
                        click = 1;
                }
                else if (event->val == KM_PRESS) {
@@ -2579,7 +2621,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                softmax = but->softmax;
 
                if (!ui_is_but_float(but)) {
-                       if (mx < (but->x1 + (but->x2 - but->x1) / 3 - 3)) {
+                       if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                temp = (int)data->value - 1;
@@ -2590,7 +2632,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
-                       else if (mx > (but->x1 + (2 * (but->x2 - but->x1) / 3) + 3)) {
+                       else if (mx > (but->rect.xmin + (2 * BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                temp = (int)data->value + 1;
@@ -2605,7 +2647,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                                button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
                }
                else {
-                       if (mx < (but->x1 + (but->x2 - but->x1) / 3 - 3)) {
+                       if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                tempf = (float)data->value - 0.01f * but->a1;
@@ -2614,7 +2656,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
-                       else if (mx > but->x1 + (2 * ((but->x2 - but->x1) / 3) + 3)) {
+                       else if (mx > but->rect.xmin + (2 * (BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                                tempf = (float)data->value + 0.01f * but->a1;
@@ -2633,7 +2675,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
        return retval;
 }
 
-static int ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, int shift, int ctrl, int mx)
+static int ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, const short shift, const short ctrl, int mx)
 {
        float deler, f, tempf, softmin, softmax, softrange;
        int temp, lvalue, changed = 0;
@@ -2642,14 +2684,14 @@ static int ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, int shift, i
        softmax = but->softmax;
        softrange = softmax - softmin;
 
-       if (but->type == NUMSLI) deler = ((but->x2 - but->x1) - 5.0f * but->aspect);
-       else if (but->type == HSVSLI) deler = ((but->x2 - but->x1) / 2.0f - 5.0f * but->aspect);
+       if (but->type == NUMSLI) deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
+       else if (but->type == HSVSLI) deler = (BLI_RCT_SIZE_X(&but->rect) / 2.0f - 5.0f * but->aspect);
        else if (but->type == SCROLL) {
-               int horizontal = (but->x2 - but->x1 > but->y2 - but->y1);
-               float size = (horizontal) ? (but->x2 - but->x1) : -(but->y2 - but->y1);
+               int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
+               float size = (horizontal) ? BLI_RCT_SIZE_X(&but->rect) : -BLI_RCT_SIZE_Y(&but->rect);
                deler = size * (but->softmax - but->softmin) / (but->softmax - but->softmin + but->a1);
        }
-       else deler = (but->x2 - but->x1 - 5.0f * but->aspect);
+       else deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
 
        f = (float)(mx - data->dragstartx) / deler + data->dragfstart;
        
@@ -2718,11 +2760,11 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                /* XXX hardcoded keymap check.... */
                if (event->type == WHEELDOWNMOUSE && event->alt) {
-                       mx = but->x1;
+                       mx = but->rect.xmin;
                        click = 2;
                }
                else if (event->type == WHEELUPMOUSE && event->alt) {
-                       mx = but->x2;
+                       mx = but->rect.xmax;
                        click = 2;
                }
                else if (event->val == KM_PRESS) {
@@ -2732,12 +2774,12 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                        }
                        /* alt-click on sides to get "arrows" like in NUM buttons, and match wheel usage above */
                        else if (event->type == LEFTMOUSE && event->alt) {
-                               int halfpos = (but->x1 + but->x2) / 2;
+                               int halfpos = BLI_RCT_CENTER_X(&but->rect);
                                click = 2;
                                if (mx < halfpos)
-                                       mx = but->x1;
+                                       mx = but->rect.xmin;
                                else
-                                       mx = but->x2;
+                                       mx = but->rect.xmax;
                        }
                        else if (event->type == LEFTMOUSE) {
                                data->dragstartx = mx;
@@ -2799,12 +2841,12 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
 #if 0
                        if (but->type == SLI) {
-                               f = (float)(mx - but->x1) / (but->x2 - but->x1); /* same as below */
+                               f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect)); /* same as below */
                        }
                        else
 #endif
                        {
-                               f = (float)(mx - but->x1) / (but->x2 - but->x1);
+                               f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect));
                        }
                        
                        f = softmin + f * softrange;
@@ -2845,7 +2887,7 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
 {
        int mx, my /*, click= 0 */;
        int retval = WM_UI_HANDLER_CONTINUE;
-       int horizontal = (but->x2 - but->x1 > but->y2 - but->y1);
+       int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
        
        mx = event->x;
        my = event->y;
@@ -2914,9 +2956,11 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                        return WM_UI_HANDLER_BREAK;
                }
                else if (ELEM3(but->type, MENU, ICONROW, ICONTEXTROW)) {
-                       
-                       if (event->type == WHEELDOWNMOUSE && event->alt) {
-                               data->value = ui_step_name_menu(but, -1);
+                       if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
+                               const int direction = (event->type == WHEELDOWNMOUSE) ? -1 : 1;
+
+                               data->value = ui_step_name_menu(but, direction);
+
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                                ui_apply_button(C, but->block, but, data, 1);
 
@@ -2930,16 +2974,15 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                                data->postbut = but;
                                data->posttype = BUTTON_ACTIVATE_OVER;
 
-                               return WM_UI_HANDLER_BREAK;
-                       }
-                       else if (event->type == WHEELUPMOUSE && event->alt) {
-                               data->value = ui_step_name_menu(but, 1);
-                               button_activate_state(C, but, BUTTON_STATE_EXIT);
-                               ui_apply_button(C, but->block, but, data, 1);
-
-                               /* why this is needed described above */
-                               data->postbut = but;
-                               data->posttype = BUTTON_ACTIVATE_OVER;
+                               /* without this, a new interface that draws as result of the menu change
+                                * won't register that the mouse is over it, eg:
+                                * Alt+MouseWheel over the render slots, without this,
+                                * the slot menu fails to switch a second time.
+                                *
+                                * The active state of the button could be maintained some other way
+                                * and remove this mousemove event.
+                                */
+                               WM_event_add_mousemove(C);
 
                                return WM_UI_HANDLER_BREAK;
                        }
@@ -2950,14 +2993,14 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
                                float col[3];
                                
                                ui_get_but_vectorf(but, col);
-                               rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv + 1, hsv + 2);
+                               rgb_to_hsv_compat_v(col, hsv);
 
                                if (event->type == WHEELDOWNMOUSE)
                                        hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
                                else
                                        hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
                                
-                               hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec + 1, data->vec + 2);
+                               hsv_to_rgb_v(hsv, data->vec);
                                ui_set_but_vectorf(but, data->vec);
                                
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -3002,7 +3045,7 @@ static int ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data, int mx, i
         * else we'll get a harmless but annoying jump when first clicking */
 
        fp = data->origvec;
-       rad = (but->x2 - but->x1);
+       rad = BLI_RCT_SIZE_X(&but->rect);
        radsq = rad * rad;
        
        if (fp[2] > 0.0f) {
@@ -3088,14 +3131,17 @@ static int ui_do_but_NORMAL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
        return WM_UI_HANDLER_CONTINUE;
 }
 
-static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx, int my)
+static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx, int my, const short shift)
 {
        float rgb[3];
        float *hsv = ui_block_hsv_get(but->block);
        float x, y;
+       float mx_fl, my_fl;
        int changed = 1;
        int color_profile = but->block->color_profile;
        
+       ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
+
        if (but->rnaprop) {
                if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
                        color_profile = BLI_PR_NONE;
@@ -3103,11 +3149,12 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
 
        ui_get_but_vectorf(but, rgb);
 
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
+
 
        /* relative position within box */
-       x = ((float)mx - but->x1) / (but->x2 - but->x1);
-       y = ((float)my - but->y1) / (but->y2 - but->y1);
+       x = ((float)mx_fl - but->rect.xmin) / BLI_RCT_SIZE_X(&but->rect);
+       y = ((float)my_fl - but->rect.ymin) / BLI_RCT_SIZE_Y(&but->rect);
        CLAMP(x, 0.0f, 1.0f);
        CLAMP(y, 0.0f, 1.0f);
 
@@ -3149,7 +3196,7 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
                        assert(!"invalid hsv type");
        }
 
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
        copy_v3_v3(data->vec, rgb);
 
        data->draglastx = mx;
@@ -3158,7 +3205,7 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
        return changed;
 }
 
-static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOFMotionData *ndof, int shift)
+static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOFMotionData *ndof, const short shift)
 {
        float *hsv = ui_block_hsv_get(but->block);
        float rgb[3];
@@ -3172,7 +3219,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOF
        }
 
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        switch ((int)but->a1) {
                case UI_GRAD_SV:
@@ -3210,7 +3257,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, wmNDOF
                        assert(!"invalid hsv type");
        }
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
        copy_v3_v3(data->vec, rgb);
        ui_set_but_vectorf(but, data->vec);
 }
@@ -3232,7 +3279,7 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
                        button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 
                        /* also do drag the first time */
-                       if (ui_numedit_but_HSVCUBE(but, data, mx, my))
+                       if (ui_numedit_but_HSVCUBE(but, data, mx, my, event->shift))
                                ui_numedit_apply(C, block, but, data);
                        
                        return WM_UI_HANDLER_BREAK;
@@ -3262,12 +3309,15 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
                                        def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
                                        
                                        RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
-                                       rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv + 1, def_hsv + 2);
+                                       rgb_to_hsv_v(def, def_hsv);
                                        
                                        ui_get_but_vectorf(but, rgb);
-                                       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+                                       rgb_to_hsv_compat_v(rgb, hsv);
+
+                                       def_hsv[0] = hsv[0];
+                                       def_hsv[1] = hsv[1];
                                        
-                                       hsv_to_rgb(hsv[0], hsv[1], def_hsv[2], rgb, rgb + 1, rgb + 2);
+                                       hsv_to_rgb_v(def_hsv, rgb);
                                        ui_set_but_vectorf(but, rgb);
                                        
                                        RNA_property_update(C, &but->rnapoin, but->rnaprop);
@@ -3286,7 +3336,7 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
                }
                else if (event->type == MOUSEMOVE) {
                        if (mx != data->draglastx || my != data->draglasty) {
-                               if (ui_numedit_but_HSVCUBE(but, data, mx, my))
+                               if (ui_numedit_but_HSVCUBE(but, data, mx, my, event->shift))
                                        ui_numedit_apply(C, block, but, data);
                        }
                }
@@ -3299,19 +3349,21 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
        return WM_UI_HANDLER_CONTINUE;
 }
 
-static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
+static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, float mx, float my, int shift)
 {
        rcti rect;
        int changed = 1;
+       float mx_fl, my_fl;
        float rgb[3];
        float hsv[3];
        
-       rect.xmin = but->x1; rect.xmax = but->x2;
-       rect.ymin = but->y1; rect.ymax = but->y2;
-       
+       ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
+
+       BLI_rcti_rctf_copy(&rect, &but->rect);
+
        ui_get_but_vectorf(but, rgb);
        copy_v3_v3(hsv, ui_block_hsv_get(but->block));
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
        /* exception, when using color wheel in 'locked' value state:
         * allow choosing a hue for black values, by giving a tiny increment */
@@ -3319,19 +3371,13 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
                if (hsv[2] == 0.f) hsv[2] = 0.0001f;
        }
 
-       if (U.uiflag & USER_CONTINUOUS_MOUSE) {
-               float fac = shift ? 0.05f : 1.0f;
-               /* slow down the mouse, this is fairly picky */
-               mx = (data->dragstartx * (1.0f - fac) + mx * fac);
-               my = (data->dragstarty * (1.0f - fac) + my * fac);
-       }
 
-       ui_hsvcircle_vals_from_pos(hsv, hsv + 1, &rect, (float)mx, (float)my);
+       ui_hsvcircle_vals_from_pos(hsv, hsv + 1, &rect, mx_fl, my_fl);
 
        if (but->flag & UI_BUT_COLOR_CUBIC)
                hsv[1] = 1.0f - sqrt3f(1.0f - hsv[1]);
 
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+       hsv_to_rgb_v(hsv, rgb);
 
        if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (rgb[0] || rgb[1] || rgb[2])) {
                normalize_v3(rgb);
@@ -3346,7 +3392,7 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
        return changed;
 }
 
-static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmNDOFMotionData *ndof, int shift)
+static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmNDOFMotionData *ndof, const short shift)
 {
        float *hsv = ui_block_hsv_get(but->block);
        float rgb[3];
@@ -3354,12 +3400,12 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmND
        float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
        
        ui_get_but_vectorf(but, rgb);
-       rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+       rgb_to_hsv_compat_v(rgb, hsv);
        
-       /* Convert current colour on hue/sat disc to circular coordinates phi, r */
+       /* Convert current color on hue/sat disc to circular coordinates phi, r */
        phi = fmodf(hsv[0] + 0.25f, 1.0f) * -2.0f * (float)M_PI;
        r = hsv[1];
-       /* sqr= r>0.f?sqrtf(r):1; */ /* UNUSED */
+       /* sqr = r > 0.0f ? sqrtf(r) : 1; */ /* UNUSED */
        
        /* Convert to 2d vectors */
        v[0] = r * cosf(phi);
@@ -3388,7 +3434,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, wmND
                if (hsv[2] == 0.0f) hsv[2] = 0.0001f;
        }
        
-       hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec + 1, data->vec + 2);
+       hsv_to_rgb_v(hsv, data->vec);
        
        if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (data->vec[0] || data->vec[1] || data->vec[2])) {
                normalize_v3(data->vec);
@@ -3444,12 +3490,15 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
                                def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
                                
                                RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
-                               rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv + 1, def_hsv + 2);
+                               rgb_to_hsv_v(def, def_hsv);
                                
                                ui_get_but_vectorf(but, rgb);
-                               rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
+                               rgb_to_hsv_compat_v(rgb, hsv);
                                
-                               hsv_to_rgb(hsv[0], def_hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
+                               def_hsv[0] = hsv[0];
+                               def_hsv[2] = hsv[2];
+
+                               hsv_to_rgb_v(def_hsv, rgb);
                                ui_set_but_vectorf(but, rgb);
                                
                                RNA_property_update(C, &but->rnapoin, but->rnaprop);
@@ -3469,13 +3518,13 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
                else if (event->type == WHEELDOWNMOUSE) {
                        float *hsv = ui_block_hsv_get(but->block);
                        hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
-                       ui_set_but_hsv(but);    // converts to rgb
+                       ui_set_but_hsv(but);    /* converts to rgb */
                        ui_numedit_apply(C, block, but, data);
                }
                else if (event->type == WHEELUPMOUSE) {
                        float *hsv = ui_block_hsv_get(but->block);
                        hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
-                       ui_set_but_hsv(but);    // converts to rgb
+                       ui_set_but_hsv(but);    /* converts to rgb */
                        ui_numedit_apply(C, block, but, data);
                }
                else if (event->type == MOUSEMOVE) {
@@ -3502,7 +3551,7 @@ static int ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx
        if (data->draglastx == mx)
                return changed;
 
-       dx = ((float)(mx - data->draglastx)) / (but->x2 - but->x1);
+       dx = ((float)(mx - data->draglastx)) / BLI_RCT_SIZE_X(&but->rect);
        data->dragcbd->pos += dx;
        CLAMP(data->dragcbd->pos, 0.0f, 1.0f);
        
@@ -3531,7 +3580,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
 
                        if (event->ctrl) {
                                /* insert new key on mouse location */
-                               float pos = ((float)(mx - but->x1)) / (but->x2 - but->x1);
+                               float pos = ((float)(mx - but->rect.xmin)) / BLI_RCT_SIZE_X(&but->rect);
                                colorband_element_add(coba, pos);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                        }
@@ -3543,7 +3592,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
 
                                /* activate new key when mouse is close */
                                for (a = 0, cbd = coba->data; a < coba->tot; a++, cbd++) {
-                                       xco = but->x1 + (cbd->pos * (but->x2 - but->x1));
+                                       xco = but->rect.xmin + (cbd->pos * BLI_RCT_SIZE_X(&but->rect));
                                        xco = ABS(xco - mx);
                                        if (a == coba->cur) xco += 5;  // selected one disadvantage
                                        if (xco < mindist) {
@@ -3575,7 +3624,8 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
        return WM_UI_HANDLER_CONTINUE;
 }
 
-static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap, int mx, int my)
+static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
+                                float mx, float my, const short shift)
 {
        CurveMapping *cumap = (CurveMapping *)but->poin;
        CurveMap *cuma = cumap->cm + cumap->cur;
@@ -3583,8 +3633,8 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
        float fx, fy, zoomx, zoomy /*, offsx, offsy */ /* UNUSED */;
        int a, changed = 0;
 
-       zoomx = (but->x2 - but->x1) / (cumap->curr.xmax - cumap->curr.xmin);
-       zoomy = (but->y2 - but->y1) / (cumap->curr.ymax - cumap->curr.ymin);
+       zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+       zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
        /* offsx= cumap->curr.xmin; */
        /* offsy= cumap->curr.ymin; */
 
@@ -3599,12 +3649,17 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
        }
 
        if (data->dragsel != -1) {
+               const float mval_factor = ui_mouse_scale_warp_factor(shift);
                int moved_point = 0;     /* for ctrl grid, can't use orig coords because of sorting */
                
                fx = (mx - data->draglastx) / zoomx;
                fy = (my - data->draglasty) / zoomy;
+
+               fx *= mval_factor;
+               fy *= mval_factor;
+
                for (a = 0; a < cuma->totpoint; a++) {
-                       if (cmp[a].flag & SELECT) {
+                       if (cmp[a].flag & CUMA_SELECT) {
                                float origx = cmp[a].x, origy = cmp[a].y;
                                cmp[a].x += fx;
                                cmp[a].y += fy;
@@ -3617,7 +3672,7 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
                        }
                }
 
-               curvemapping_changed(cumap, 0); /* no remove doubles */
+               curvemapping_changed(cumap, FALSE);
                
                if (moved_point) {
                        data->draglastx = mx;
@@ -3674,25 +3729,25 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                        float dist, mindist = 200.0f; // 14 pixels radius
                        int sel = -1;
 
-                       zoomx = (but->x2 - but->x1) / (cumap->curr.xmax - cumap->curr.xmin);
-                       zoomy = (but->y2 - but->y1) / (cumap->curr.ymax - cumap->curr.ymin);
+                       zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+                       zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
                        offsx = cumap->curr.xmin;
                        offsy = cumap->curr.ymin;
 
                        if (event->ctrl) {
-                               fx = ((float)my - but->x1) / zoomx + offsx;
-                               fy = ((float)my - but->y1) / zoomy + offsy;
+                               fx = ((float)mx - but->rect.xmin) / zoomx + offsx;
+                               fy = ((float)my - but->rect.ymin) / zoomy + offsy;
                                
                                curvemap_insert(cuma, fx, fy);
-                               curvemapping_changed(cumap, 0);
+                               curvemapping_changed(cumap, FALSE);
                                changed = 1;
                        }
 
                        /* check for selecting of a point */
                        cmp = cuma->curve;   /* ctrl adds point, new malloc */
                        for (a = 0; a < cuma->totpoint; a++) {
-                               fx = but->x1 + zoomx * (cmp[a].x - offsx);
-                               fy = but->y1 + zoomy * (cmp[a].y - offsy);
+                               fx = but->rect.xmin + zoomx * (cmp[a].x - offsx);
+                               fy = but->rect.ymin + zoomy * (cmp[a].y - offsy);
                                dist = (fx - mx) * (fx - mx) + (fy - my) * (fy - my);
                                if (dist < mindist) {
                                        sel = a;
@@ -3705,20 +3760,20 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
 
                                /* if the click didn't select anything, check if it's clicked on the 
                                 * curve itself, and if so, add a point */
-                               fx = ((float)mx - but->x1) / zoomx + offsx;
-                               fy = ((float)my - but->y1) / zoomy + offsy;
+                               fx = ((float)mx - but->rect.xmin) / zoomx + offsx;
+                               fy = ((float)my - but->rect.ymin) / zoomy + offsy;
                                
                                cmp = cuma->table;
 
                                /* loop through the curve segment table and find what's near the mouse.
                                 * 0.05 is kinda arbitrary, but seems to be what works nicely. */
                                for (i = 0; i <= CM_TABLE; i++) {
-                                       if ( (fabsf(fx - cmp[i].x) < 0.05f) &&
-                                            (fabsf(fy - cmp[i].y) < 0.05f))
+                                       if ((fabsf(fx - cmp[i].x) < 0.05f) &&
+                                           (fabsf(fy - cmp[i].y) < 0.05f))
                                        {
                                        
                                                curvemap_insert(cuma, fx, fy);
-                                               curvemapping_changed(cumap, 0);
+                                               curvemapping_changed(cumap, FALSE);
 
                                                changed = 1;
                                                
@@ -3740,11 +3795,11 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                /* deselect all if this one is deselect. except if we hold shift */
                                if (event->shift == FALSE) {
                                        for (a = 0; a < cuma->totpoint; a++)
-                                               cmp[a].flag &= ~SELECT;
-                                       cmp[sel].flag |= SELECT;
+                                               cmp[a].flag &= ~CUMA_SELECT;
+                                       cmp[sel].flag |= CUMA_SELECT;
                                }
                                else
-                                       cmp[sel].flag ^= SELECT;
+                                       cmp[sel].flag ^= CUMA_SELECT;
                        }
                        else {
                                /* move the view */
@@ -3765,7 +3820,7 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
        else if (data->state == BUTTON_STATE_NUM_EDITING) {
                if (event->type == MOUSEMOVE) {
                        if (mx != data->draglastx || my != data->draglasty) {
-                               if (ui_numedit_but_CURVE(but, data, event->ctrl, mx, my))
+                               if (ui_numedit_but_CURVE(but, data, event->ctrl, mx, my, event->shift))
                                        ui_numedit_apply(C, block, but, data);
                        }
                }
@@ -3779,12 +3834,13 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                        /* deselect all, select one */
                                        if (event->shift == FALSE) {
                                                for (a = 0; a < cuma->totpoint; a++)
-                                                       cmp[a].flag &= ~SELECT;
-                                               cmp[data->dragsel].flag |= SELECT;
+                                                       cmp[a].flag &= ~CUMA_SELECT;
+                                               cmp[data->dragsel].flag |= CUMA_SELECT;
                                        }
                                }
-                               else
-                                       curvemapping_changed(cumap, 1);  /* remove doubles */
+                               else {
+                                       curvemapping_changed(cumap, TRUE);  /* remove doubles */
+                               }
                        }
 
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -3801,8 +3857,8 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
 
 static int in_scope_resize_zone(uiBut *but, int UNUSED(x), int y)
 {
-       // bottom corner return (x > but->x2 - SCOPE_RESIZE_PAD) && (y < but->y1 + SCOPE_RESIZE_PAD);
-       return (y < but->y1 + SCOPE_RESIZE_PAD);
+       /* bottom corner return (x > but->rect.xmax - SCOPE_RESIZE_PAD) && (y < but->rect.ymin + SCOPE_RESIZE_PAD); */
+       return (y < but->rect.ymin + SCOPE_RESIZE_PAD);
 }
 
 static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx, int my)
@@ -3810,25 +3866,24 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
        Histogram *hist = (Histogram *)but->poin;
        /* rcti rect; */
        int changed = 1;
-       float /* dx, */ dy, yfac = 1.f; /* UNUSED */
+       float /* dx, */ dy; /* UNUSED */
        
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
        
        /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
-       
-       
+
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize histogram widget itself */
-               hist->height = (but->y2 - but->y1) + (data->dragstarty - my);
+               hist->height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
-               /* scale histogram values */
-               yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5f;
-               hist->ymax += dy * yfac;
+               /* scale histogram values (dy / 10 for better control) */
+               const float yfac = minf(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
+               hist->ymax += (dy * 0.1f) * yfac;
        
-               CLAMP(hist->ymax, 1.f, 100.f);
+               /* 0.1 allows us to see HDR colors up to 10 */
+               CLAMP(hist->ymax, 0.1f, 100.f);
        }
        
        data->draglastx = mx;
@@ -3896,8 +3951,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
        int changed = 1;
        float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */
 
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
 
        /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
@@ -3905,7 +3959,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize waveform widget itself */
-               scopes->wavefrm_height = (but->y2 - but->y1) + (data->dragstarty - my);
+               scopes->wavefrm_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
                /* scale waveform values */
@@ -3980,15 +4034,14 @@ static int ui_numedit_but_VECTORSCOPE(uiBut *but, uiHandleButtonData *data, int
        int changed = 1;
        /* float dx, dy; */
 
-       /* rect.xmin = but->x1; rect.xmax = but->x2; */
-       /* rect.ymin = but->y1; rect.ymax = but->y2; */
+       /* BLI_rcti_rctf_copy(&rect, &but->rect); */
 
        /* dx = mx - data->draglastx; */
        /* dy = my - data->draglasty; */
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize vectorscope widget itself */
-               scopes->vecscope_height = (but->y2 - but->y1) + (data->dragstarty - my);
+               scopes->vecscope_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
 
        data->draglastx = mx;
@@ -4058,17 +4111,17 @@ static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut
        if (data->state == BUTTON_STATE_HIGHLIGHT) {
                if (ELEM3(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) {
                        /* Calculate the size of the button */
-                       width = abs(but->x2 - but->x1);
-                       height = abs(but->y2 - but->y1);
+                       width  = abs(BLI_RCT_SIZE_X(&but->rect));
+                       height = abs(BLI_RCT_SIZE_Y(&but->rect));
 
                        butw = floor(width / 12);
                        buth = floor(height / 6);
 
                        /* Initialize variables */
-                       sx = but->x1;
-                       ex = but->x1 + butw;
-                       sy = but->y1 + height - buth;
-                       ey = but->y1 + height;
+                       sx = but->rect.xmin;
+                       ex = but->rect.xmin + butw;
+                       sy = but->rect.ymin + height - buth;
+                       ey = but->rect.ymin + height;
 
                        cs = G.charstart;
 
@@ -4174,7 +4227,8 @@ static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmE
        return WM_UI_HANDLER_CONTINUE;
 }
 
-static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
+static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data,
+                                       int mx, int my, const short shift)
 {
        MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
        int changed = 1;
@@ -4190,16 +4244,16 @@ static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDa
 
        if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
                /* resize preview widget itself */
-               scopes->track_preview_height = (but->y2 - but->y1) + (data->dragstarty - my);
+               scopes->track_preview_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
        }
        else {
-               if (scopes->marker) {
+               if (!scopes->track_locked) {
                        if (scopes->marker->framenr != scopes->framenr)
-                               scopes->marker = BKE_tracking_ensure_marker(scopes->track, scopes->framenr);
+                               scopes->marker = BKE_tracking_marker_ensure(scopes->track, scopes->framenr);
 
                        scopes->marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED);
-                       scopes->marker->pos[0] += -dx * scopes->slide_scale[0] / (but->block->maxx - but->block->minx);
-                       scopes->marker->pos[1] += -dy * scopes->slide_scale[1] / (but->block->maxy - but->block->miny);
+                       scopes->marker->pos[0] += -dx * scopes->slide_scale[0] / BLI_RCT_SIZE_X(&but->block->rect);
+                       scopes->marker->pos[1] += -dy * scopes->slide_scale[1] / BLI_RCT_SIZE_Y(&but->block->rect);
 
                        WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
                }
@@ -4391,23 +4445,32 @@ static int ui_but_menu(bContext *C, uiBut *but)
        uiPopupMenu *pup;
        uiLayout *layout;
        int length;
-       const char *name;
+       char *name;
+       uiStringInfo label = {BUT_GET_LABEL, NULL};
 
-       if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)
-               return 0;
+/*     if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/
+/*             return 0;*/
        
        button_timers_tooltip_remove(C, but);
 
+#if 0
        if (but->rnaprop)
                name = RNA_property_ui_name(but->rnaprop);
-       else if (but->optype)
-               name = but->optype->name;
+       else if (but->optype && but->optype->srna)
+               name = RNA_struct_ui_name(but->optype->srna);
        else
-               name = "<needs_name>";  // XXX - should never happen.
+               name = IFACE_("<needs_name>");  // XXX - should never happen.
+#else
+       uiButGetStrInfo(C, but, 1, &label);
+       name = label.strinfo;
+#endif
 
        pup = uiPupMenuBegin(C, name, ICON_NONE);
        layout = uiPupMenuLayout(pup);
-       
+
+       if (label.strinfo)
+               MEM_freeN(label.strinfo);
+
        uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
 
        if (but->rnapoin.data && but->rnaprop) {
@@ -4423,14 +4486,20 @@ static int ui_but_menu(bContext *C, uiBut *but)
                if (but->flag & UI_BUT_ANIMATED_KEY) {
                        /* replace/delete keyfraemes */
                        if (length) {
-                               uiItemBooleanO(layout, "Replace Keyframes", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
-                               uiItemBooleanO(layout, "Replace Single Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
-                               uiItemBooleanO(layout, "Delete Keyframes", ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 1);
-                               uiItemBooleanO(layout, "Delete Single Keyframe", ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Single Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0);
                        }
                        else {
-                               uiItemBooleanO(layout, "Replace Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
-                               uiItemBooleanO(layout, "Delete Keyframe", ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0);
                        }
                        
                        /* keyframe settings */
@@ -4441,56 +4510,86 @@ static int ui_but_menu(bContext *C, uiBut *but)
                else if (but->flag & UI_BUT_DRIVEN) ;
                else if (is_anim) {
                        if (length) {
-                               uiItemBooleanO(layout, "Insert Keyframes", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
-                               uiItemBooleanO(layout, "Insert Single Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Single Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
                        }
                        else
-                               uiItemBooleanO(layout, "Insert Keyframe", ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframe"),
+                                              ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0);
                }
                
+               if (but->flag & UI_BUT_ANIMATED) {
+                       if (length) {
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Single Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 0);
+                       }
+                       else {
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"),
+                                              ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 0);
+                       }
+               }
+
                /* Drivers */
                if (but->flag & UI_BUT_DRIVEN) {
                        uiItemS(layout);
 
                        if (length) {
-                               uiItemBooleanO(layout, "Delete Drivers", ICON_NONE, "ANIM_OT_driver_button_remove", "all", 1);
-                               uiItemBooleanO(layout, "Delete Single Driver", ICON_NONE, "ANIM_OT_driver_button_remove", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Drivers"),
+                                              ICON_NONE, "ANIM_OT_driver_button_remove", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Driver"),
+                                              ICON_NONE, "ANIM_OT_driver_button_remove", "all", 0);
                        }
                        else
-                               uiItemBooleanO(layout, "Delete Driver", ICON_NONE, "ANIM_OT_driver_button_remove", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Driver"),
+                                              ICON_NONE, "ANIM_OT_driver_button_remove", "all", 0);
 
-                       uiItemO(layout, "Copy Driver", ICON_NONE, "ANIM_OT_copy_driver_button");
+                       uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Driver"),
+                               ICON_NONE, "ANIM_OT_copy_driver_button");
                        if (ANIM_driver_can_paste())
-                               uiItemO(layout, "Paste Driver", ICON_NONE, "ANIM_OT_paste_driver_button");
+                               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Paste Driver"),
+                                       ICON_NONE, "ANIM_OT_paste_driver_button");
                }
                else if (but->flag & (UI_BUT_ANIMATED_KEY | UI_BUT_ANIMATED)) ;
                else if (is_anim) {
                        uiItemS(layout);
 
                        if (length) {
-                               uiItemBooleanO(layout, "Add Drivers", ICON_NONE, "ANIM_OT_driver_button_add", "all", 1);
-                               uiItemBooleanO(layout, "Add Single Driver", ICON_NONE, "ANIM_OT_driver_button_add", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Drivers"),
+                                              ICON_NONE, "ANIM_OT_driver_button_add", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single Driver"),
+                                              ICON_NONE, "ANIM_OT_driver_button_add", "all", 0);
                        }
                        else
-                               uiItemBooleanO(layout, "Add Driver", ICON_NONE, "ANIM_OT_driver_button_add", "all", 0);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Driver"),
+                                              ICON_NONE, "ANIM_OT_driver_button_add", "all", 0);
 
                        if (ANIM_driver_can_paste())
-                               uiItemO(layout, "Paste Driver", ICON_NONE, "ANIM_OT_paste_driver_button");
+                               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Paste Driver"),
+                                       ICON_NONE, "ANIM_OT_paste_driver_button");
                }
                
                /* Keying Sets */
-               // TODO: check on modifyability of Keying Set when doing this
+               /* TODO: check on modifyability of Keying Set when doing this */
                if (is_anim) {
                        uiItemS(layout);
 
                        if (length) {
-                               uiItemBooleanO(layout, "Add All to Keying Set", ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 1);
-                               uiItemBooleanO(layout, "Add Single to Keying Set", ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 0);
-                               uiItemO(layout, "Remove from Keying Set", ICON_NONE, "ANIM_OT_keyingset_button_remove");
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add All to Keying Set"),
+                                              ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 1);
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single to Keying Set"),
+                                              ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 0);
+                               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"),
+                                       ICON_NONE, "ANIM_OT_keyingset_button_remove");
                        }
                        else {
-                               uiItemBooleanO(layout, "Add to Keying Set", ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 0);
-                               uiItemO(layout, "Remove from Keying Set", ICON_NONE, "ANIM_OT_keyingset_button_remove");
+                               uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Keying Set"),
+                                              ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 0);
+                               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"),
+                                       ICON_NONE, "ANIM_OT_keyingset_button_remove");
                        }
                }
                
@@ -4498,18 +4597,23 @@ static int ui_but_menu(bContext *C, uiBut *but)
                
                /* Property Operators */
                
-               //Copy Property Value
-               //Paste Property Value
+               /*Copy Property Value
+                *Paste Property Value */
                
                if (length) {
-                       uiItemBooleanO(layout, "Reset All to Default Values", ICON_NONE, "UI_OT_reset_default_button", "all", 1);
-                       uiItemBooleanO(layout, "Reset Single to Default Value", ICON_NONE, "UI_OT_reset_default_button", "all", 0);
+                       uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset All to Default Values"),
+                                      ICON_NONE, "UI_OT_reset_default_button", "all", 1);
+                       uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset Single to Default Value"),
+                                      ICON_NONE, "UI_OT_reset_default_button", "all", 0);
                }
                else
-                       uiItemO(layout, "Reset to Default Value", ICON_NONE, "UI_OT_reset_default_button");
+                       uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset to Default Value"),
+                               ICON_NONE, "UI_OT_reset_default_button");
                
-               uiItemO(layout, "Copy Data Path", ICON_NONE, "UI_OT_copy_data_path_button");
-               uiItemO(layout, "Copy To Selected", ICON_NONE, "UI_OT_copy_to_selected_button");
+               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Data Path"),
+                       ICON_NONE, "UI_OT_copy_data_path_button");
+               uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy To Selected"),
+                       ICON_NONE, "UI_OT_copy_to_selected_button");
 
                uiItemS(layout);
        }
@@ -4530,18 +4634,21 @@ static int ui_but_menu(bContext *C, uiBut *but)
                /* keyboard shortcuts */
                if ((kmi) && ISKEYBOARD(kmi->type)) {
 
-                       // would rather use a block but, but gets weirdly positioned...
+                       /* would rather use a block but, but gets weirdly positioned... */
                        //uiDefBlockBut(block, menu_change_shortcut, but, "Change Shortcut", 0, 0, uiLayoutGetWidth(layout), UI_UNIT_Y, "");
                        
-                       but2 = uiDefIconTextBut(block, BUT, 0, 0, "Change Shortcut", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+                       but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut"),
+                                               0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
                        uiButSetFunc(but2, popup_change_shortcut_func, but, NULL);
 
-                       but2 = uiDefIconTextBut(block, BUT, 0, 0, "Remove Shortcut", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+                       but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Shortcut"),
+                                               0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
                        uiButSetFunc(but2, remove_shortcut_func, but, NULL);
                }
                /* only show 'add' if there's a suitable key map for it to go in */
                else if (WM_keymap_guess_opname(C, but->optype->idname)) {
-                       but2 = uiDefIconTextBut(block, BUT, 0, 0, "Add Shortcut", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+                       but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Shortcut"),
+                                               0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
                        uiButSetFunc(but2, popup_add_shortcut_func, but, NULL);
                }
                
@@ -4554,11 +4661,18 @@ static int ui_but_menu(bContext *C, uiBut *but)
                PointerRNA ptr_props;
 
                if (but->rnapoin.data && but->rnaprop) {
-                       BLI_snprintf(buf, sizeof(buf), "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+                       BLI_snprintf(buf, sizeof(buf), "%s.%s",
+                                    RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+
+                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
+                       RNA_string_set(&ptr_props, "doc_id", buf);
+                       uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
 
                        WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
                        RNA_string_set(&ptr_props, "doc_id", buf);
-                       uiItemFullO(layout, "WM_OT_doc_view", "View Docs", ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+                       uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
+                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
 
                        /* XXX inactive option, not for public! */
 #if 0
@@ -4572,21 +4686,32 @@ static int ui_but_menu(bContext *C, uiBut *but)
                else if (but->optype) {
                        WM_operator_py_idname(buf, but->optype->idname);
 
-                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
+
+                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
                        RNA_string_set(&ptr_props, "doc_id", buf);
-                       uiItemFullO(layout, "WM_OT_doc_view", "View Docs", ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+                       uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
 
+                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
+                       RNA_string_set(&ptr_props, "doc_id", buf);
+                       uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
+                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
 
+                       /* XXX inactive option, not for public! */
+#if 0
                        WM_operator_properties_create(&ptr_props, "WM_OT_doc_edit");
                        RNA_string_set(&ptr_props, "doc_id", buf);
                        RNA_string_set(&ptr_props, "doc_new", but->optype->description);
 
-                       uiItemFullO(layout, "WM_OT_doc_edit", "Submit Description", ICON_NONE, ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
+                       uiItemFullO(layout, "WM_OT_doc_edit", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Submit Description"),
+                                   ICON_NONE, ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
+#endif
                }
        }
 
-       /* perhaps we should move this into (G.f & G_DEBUG) - campbell */
-       uiItemFullO(layout, "UI_OT_editsource", "Edit Source", ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0);
+       /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */
+       uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0);
+       uiItemFullO(layout, "UI_OT_edittranslation_init", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0);
 
        uiPupMenuEnd(C, pup);
 
@@ -4595,7 +4720,6 @@ static int ui_but_menu(bContext *C, uiBut *but)
 
 static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
 {
-//     Scene *scene= CTX_data_scene(C);
        uiHandleButtonData *data;
        int retval;
 
@@ -4621,11 +4745,18 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
                        ui_but_drop(C, event, but, data);
                }
                /* handle keyframing */
-               else if (event->type == IKEY && !ELEM3(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && event->val == KM_PRESS) {
-                       if (event->alt)
-                               ui_but_anim_delete_keyframe(C);
-                       else
+               else if (event->type == IKEY && !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && event->val == KM_PRESS) {
+                       if (event->alt) {
+                               if (event->shift) {
+                                       ui_but_anim_clear_keyframe(C);
+                               }
+                               else {
+                                       ui_but_anim_delete_keyframe(C);
+                               }
+                       }
+                       else {
                                ui_but_anim_insert_keyframe(C);
+                       }
                        
                        ED_region_tag_redraw(CTX_wm_region(C));
                        
@@ -4672,7 +4803,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        /* verify if we can edit this button */
        if (ELEM(event->type, LEFTMOUSE, RETKEY)) {
                /* this should become disabled button .. */
-               if (but->lock) {
+               if (but->lock == TRUE) {
                        if (but->lockstr) {
                                BKE_report(NULL, RPT_WARNING, but->lockstr);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -4755,7 +4886,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
                        retval = ui_do_but_BUT(C, but, data, event);
                        break;
                case COL:
-                       if (but->a1 == UI_GRAD_V_ALT) // signal to prevent calling up color picker
+                       if (but->a1 == UI_GRAD_V_ALT)  /* signal to prevent calling up color picker */
                                retval = ui_do_but_EXIT(C, but, data, event);
                        else
                                retval = ui_do_but_BLOCK(C, but, data, event);
@@ -4797,7 +4928,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
 
 static int ui_but_contains_pt(uiBut *but, int mx, int my)
 {
-       return ((but->x1 < mx && but->x2 >= mx) && (but->y1 < my && but->y2 >= my));
+       return BLI_rctf_isect_pt(&but->rect, mx, my);
 }
 
 static uiBut *ui_but_find_activated(ARegion *ar)
@@ -4873,7 +5004,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
        uiBlock *block;
        
        /* check if the mouse is in the region */
-       if (!BLI_in_rcti(&ar->winrct, x, y)) {
+       if (!BLI_rcti_isect_pt(&ar->winrct, x, y)) {
                for (block = ar->uiblocks.first; block; block = block->next)
                        block->auto_open = FALSE;
                
@@ -4896,10 +5027,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
                ui_window_to_region(ar, &mx, &my);
                
                /* make a copy of the mask rect, and tweak accordingly for hidden scrollbars */
-               mask_rct.xmin = v2d->mask.xmin;
-               mask_rct.xmax = v2d->mask.xmax;
-               mask_rct.ymin = v2d->mask.ymin;
-               mask_rct.ymax = v2d->mask.ymax;
+               mask_rct = v2d->mask;
                
                if (v2d->scroll & (V2D_SCROLL_VERTICAL_HIDE | V2D_SCROLL_VERTICAL_FULLR)) {
                        if (v2d->scroll & V2D_SCROLL_LEFT)
@@ -4915,7 +5043,7 @@ static int ui_mouse_inside_region(ARegion *ar, int x, int y)
                }
                
                /* check if in the rect */
-               if (!BLI_in_rcti(&mask_rct, mx, my)) 
+               if (!BLI_rcti_isect_pt(&mask_rct, mx, my)) 
                        return 0;
        }
        
@@ -4952,7 +5080,7 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
                ui_window_to_block(ar, block, &mx, &my);
 
                for (but = block->buttons.first; but; but = but->next) {
-                       /* note, LABEL is included for hilights, this allows drags */
+                       /* note, LABEL is included for highlights, this allows drags */
                        if (but->type == LABEL && but->dragpoin == NULL)
                                continue;
                        if (ELEM3(but->type, ROUNDBOX, SEPR, LISTBOX))
@@ -4968,9 +5096,7 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
                /* CLIP_EVENTS prevents the event from reaching other blocks */
                if (block->flag & UI_BLOCK_CLIP_EVENTS) {
                        /* check if mouse is inside block */
-                       if (block->minx <= mx && block->maxx >= mx &&
-                           block->miny <= my && block->maxy >= my)
-                       {
+                       if (BLI_rctf_isect_pt(&block->rect, mx, my)) {
                                break;
                        }
                }
@@ -5098,13 +5224,13 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
        /* number editing */
        if (state == BUTTON_STATE_NUM_EDITING) {
                if (ui_is_a_warp_but(but))
-                       WM_cursor_grab(CTX_wm_window(C), TRUE, TRUE, NULL);
+                       WM_cursor_grab_enable(CTX_wm_window(C), TRUE, TRUE, NULL);
                ui_numedit_begin(but, data);
        }
        else if (data->state == BUTTON_STATE_NUM_EDITING) {
                ui_numedit_end(but, data);
                if (ui_is_a_warp_but(but))
-                       WM_cursor_ungrab(CTX_wm_window(C));
+                       WM_cursor_grab_disable(CTX_wm_window(C));
        }
        /* menu open */
        if (state == BUTTON_STATE_MENU_OPEN)
@@ -5129,8 +5255,10 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
                                WM_event_add_ui_handler(C, &data->window->modalhandlers, ui_handler_region_menu, NULL, data);
                }
                else {
-                       if (button_modal_state(data->state))
-                               WM_event_remove_ui_handler(&data->window->modalhandlers, ui_handler_region_menu, NULL, data, 1);  /* 1 = postpone free */
+                       if (button_modal_state(data->state)) {
+                               /* TRUE = postpone free */
+                               WM_event_remove_ui_handler(&data->window->modalhandlers, ui_handler_region_menu, NULL, data, TRUE);
+                       }
                }
        }
        
@@ -5164,8 +5292,13 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
        data->wm = CTX_wm_manager(C);
        data->window = CTX_wm_window(C);
        data->region = ar;
-       if (ELEM(but->type, BUT_CURVE, SEARCH_MENU) ) ;  // XXX curve is temp
-       else data->interactive = 1;
+
+       if (ELEM(but->type, BUT_CURVE, SEARCH_MENU)) {
+               /* XXX curve is temp */
+       }
+       else {
+               data->interactive = 1;
+       }
        
        data->state = BUTTON_STATE_INIT;
 
@@ -5181,7 +5314,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
                        but->block->auto_open = FALSE;
 
        if (type == BUTTON_ACTIVATE_OVER) {
-               data->used_mouse = 1;
+               data->used_mouse = TRUE;
        }
        button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT);
        
@@ -5572,7 +5705,8 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
                                }
 
                                break;
-                       case TIMER: {
+                       case TIMER:
+                       {
                                /* handle tooltip timer */
                                if (event->customdata == data->tooltiptimer) {
                                        WM_event_remove_timer(data->wm, data->window, data->tooltiptimer);
@@ -5649,9 +5783,11 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
        }
        else if (data->state == BUTTON_STATE_WAIT_FLASH) {
                switch (event->type) {
-                       case TIMER: {
-                               if (event->customdata == data->flashtimer)
+                       case TIMER:
+                       {
+                               if (event->customdata == data->flashtimer) {
                                        button_activate_state(C, but, BUTTON_STATE_EXIT);
+                               }
                        }
                }
 
@@ -5661,21 +5797,25 @@ static int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but)
                /* check for exit because of mouse-over another button */
                switch (event->type) {
                        case MOUSEMOVE:
-                               
-                               if (data->menu && data->menu->region)
-                                       if (ui_mouse_inside_region(data->menu->region, event->x, event->y))
+                       {
+                               uiBut *bt;
+
+                               if (data->menu && data->menu->region) {
+                                       if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) {
                                                break;
-                       
-                               {
-                                       uiBut *bt = ui_but_find_mouse_over(ar, event->x, event->y);
+                                       }
+                               }
 
-                                       if (bt && bt->active != data) {
-                                               if (but->type != COL) /* exception */
-                                                       data->cancel = 1;
-                                               button_activate_state(C, but, BUTTON_STATE_EXIT);
+                               bt = ui_but_find_mouse_over(ar, event->x, event->y);
+
+                               if (bt && bt->active != data) {
+                                       if (but->type != COL) {  /* exception */
+                                               data->cancel = 1;
                                        }
-                                       break;
+                                       button_activate_state(C, but, BUTTON_STATE_EXIT);
                                }
+                               break;
+                       }
                }
 
                ui_do_button(C, block, but, event);
@@ -5710,7 +5850,8 @@ static int ui_handle_list_event(bContext *C, wmEvent *event, ARegion *ar)
                Panel *pa = but->block->panel;
 
                if (ELEM(event->type, UPARROWKEY, DOWNARROWKEY) ||
-                   ((ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->alt))) {
+                   ((ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->alt)))
+               {
                        /* activate up/down the list */
                        value = RNA_property_int_get(&but->rnapoin, but->rnaprop);
 
@@ -5719,6 +5860,8 @@ static int ui_handle_list_event(bContext *C, wmEvent *event, ARegion *ar)
                        else
                                value++;
 
+                       CLAMP(value, 0, pa->list_last_len - 1);
+
                        if (value < pa->list_scroll)
                                pa->list_scroll = value;
                        else if (value >= pa->list_scroll + pa->list_size)
@@ -5804,7 +5947,7 @@ static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut *
                else {
                        if (ISKEYBOARD(event->type)) {
                                /* keyboard menu hierarchy navigation, going back to previous level */
-                               but->active->used_mouse = 0;
+                               but->active->used_mouse = FALSE;
                                button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT);
                        }
                        else {
@@ -5850,17 +5993,17 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men
        /* verify that we are moving towards one of the edges of the
         * menu block, in other words, in the triangle formed by the
         * initial mouse location and two edge points. */
-       p1[0] = block->minx - 20;
-       p1[1] = block->miny - 20;
+       p1[0] = block->rect.xmin - 20;
+       p1[1] = block->rect.ymin - 20;
 
-       p2[0] = block->maxx + 20;
-       p2[1] = block->miny - 20;
+       p2[0] = block->rect.xmax + 20;
+       p2[1] = block->rect.ymin - 20;
        
-       p3[0] = block->maxx + 20;
-       p3[1] = block->maxy + 20;
+       p3[0] = block->rect.xmax + 20;
+       p3[1] = block->rect.ymax + 20;
 
-       p4[0] = block->minx - 20;
-       p4[1] = block->maxy + 20;
+       p4[0] = block->rect.xmin - 20;
+       p4[1] = block->rect.ymax + 20;
 
        oldp[0] = menu->towardsx;
        oldp[1] = menu->towardsy;
@@ -5868,14 +6011,13 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men
        newp[0] = mx;
        newp[1] = my;
 
-       if (len_v2v2(oldp, newp) < 4.0f)
+       if (len_squared_v2v2(oldp, newp) < (4.0f * 4.0f))
                return menu->dotowards;
 
-       closer = 0;
-       closer |= isect_point_tri_v2(newp, oldp, p1, p2);
-       closer |= isect_point_tri_v2(newp, oldp, p2, p3);
-       closer |= isect_point_tri_v2(newp, oldp, p3, p4);
-       closer |= isect_point_tri_v2(newp, oldp, p4, p1);
+       closer = (isect_point_tri_v2(newp, oldp, p1, p2) ||
+                 isect_point_tri_v2(newp, oldp, p2, p3) ||
+                 isect_point_tri_v2(newp, oldp, p3, p4) ||
+                 isect_point_tri_v2(newp, oldp, p4, p1));
 
        if (!closer)
                menu->dotowards = 0;
@@ -5891,10 +6033,10 @@ static char ui_menu_scroll_test(uiBlock *block, int my)
 {
        if (block->flag & (UI_BLOCK_CLIPTOP | UI_BLOCK_CLIPBOTTOM)) {
                if (block->flag & UI_BLOCK_CLIPTOP) 
-                       if (my > block->maxy - 14)
+                       if (my > block->rect.ymax - 14)
                                return 't';
                if (block->flag & UI_BLOCK_CLIPBOTTOM)
-                       if (my < block->miny + 14)
+                       if (my < block->rect.ymin + 14)
                                return 'b';
        }
        return 0;
@@ -5925,25 +6067,25 @@ static int ui_menu_scroll(ARegion *ar, uiBlock *block, int my)
                
                if (test == 't') {
                        /* bottom button is first button */
-                       if (b1->y1 < b2->y1)
-                               dy = bnext->y1 - b1->y1;
+                       if (b1->rect.ymin < b2->rect.ymin)
+                               dy = bnext->rect.ymin - b1->rect.ymin;
                        /* bottom button is last button */
                        else 
-                               dy = bprev->y1 - b2->y1;
+                               dy = bprev->rect.ymin - b2->rect.ymin;
                }
                else if (test == 'b') {
                        /* bottom button is first button */
-                       if (b1->y1 < b2->y1)
-                               dy = b1->y1 - bnext->y1;
+                       if (b1->rect.ymin < b2->rect.ymin)
+                               dy = b1->rect.ymin - bnext->rect.ymin;
                        /* bottom button is last button */
                        else 
-                               dy = b2->y1 - bprev->y1;
+                               dy = b2->rect.ymin - bprev->rect.ymin;
                }
                if (dy) {
                        
                        for (b1 = block->buttons.first; b1; b1 = b1->next) {
-                               b1->y1 -= dy;
-                               b1->y2 -= dy;
+                               b1->rect.ymin -= dy;
+                               b1->rect.ymax -= dy;
                        }
                        /* set flags again */
                        ui_popup_block_scrolltest(block);
@@ -5975,10 +6117,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
        ui_window_to_block(ar, block, &mx, &my);
 
        /* check if mouse is inside block */
-       inside = 0;
-       if (block->minx <= mx && block->maxx >= mx)
-               if (block->miny <= my && block->maxy >= my)
-                       inside = 1;
+       inside = BLI_rctf_isect_pt(&block->rect, mx, my);
 
        /* if there's an active modal button, don't check events or outside, except for search menu */
        but = ui_but_find_activated(ar);
@@ -6184,9 +6323,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                case YKEY:
                                case ZKEY:
                                {
-                                       if ((event->val == KM_PRESS) &&
+                                       if ((event->val   == KM_PRESS) &&
                                            (event->shift == FALSE) &&
-                                           (event->ctrl ==  FALSE) &&
+                                           (event->ctrl  == FALSE) &&
                                            (event->oskey == FALSE))
                                        {
                                                for (but = block->buttons.first; but; but = but->next) {
@@ -6227,7 +6366,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                uiSafetyRct *saferct = block->saferct.first;
 
                                if (ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) && event->val == KM_PRESS) {
-                                       if (saferct && !BLI_in_rctf(&saferct->parent, event->x, event->y)) {
+                                       if (saferct && !BLI_rctf_isect_pt(&saferct->parent, event->x, event->y)) {
                                                if (block->flag & (UI_BLOCK_OUT_1))
                                                        menu->menuretval = UI_RETURN_OK;
                                                else
@@ -6260,9 +6399,9 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                                 * events we check all preceding block rects too to make
                                                 * arrow keys navigation work */
                                                if (event->type != MOUSEMOVE || saferct == block->saferct.first) {
-                                                       if (BLI_in_rctf(&saferct->parent, (float)event->x, (float)event->y))
+                                                       if (BLI_rctf_isect_pt(&saferct->parent, (float)event->x, (float)event->y))
                                                                break;
-                                                       if (BLI_in_rctf(&saferct->safety, (float)event->x, (float)event->y))
+                                                       if (BLI_rctf_isect_pt(&saferct->safety, (float)event->x, (float)event->y))
                                                                break;
                                                }
                                        }
@@ -6504,6 +6643,18 @@ static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
 {
        uiPopupBlockHandle *menu = userdata;
 
+       /* we block all events, this is modal interaction, except for drop events which is described below */
+       int retval = WM_UI_HANDLER_BREAK;
+
+       if (event->type == EVT_DROP) {
+               /* if we're handling drop event we'll want it to be handled by popup callee as well,
+                * so it'll be possible to perform such operations as opening .blend files by dropping
+                * them into blender even if there's opened popup like splash screen (sergey)
+                */
+
+               retval = WM_UI_HANDLER_CONTINUE;
+       }
+
        ui_handle_menus_recursive(C, event, menu);
 
        /* free if done, does not free handle itself */
@@ -6532,8 +6683,7 @@ static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
        /* delayed apply callbacks */
        ui_apply_but_funcs_after(C);
 
-       /* we block all events, this is modal interaction */
-       return WM_UI_HANDLER_BREAK;
+       return retval;
 }
 
 static void ui_handler_remove_popup(bContext *C, void *userdata)
@@ -6549,7 +6699,7 @@ static void ui_handler_remove_popup(bContext *C, void *userdata)
 
 void UI_add_region_handlers(ListBase *handlers)
 {
-       WM_event_remove_ui_handler(handlers, ui_handler_region, ui_handler_remove_region, NULL, 0);
+       WM_event_remove_ui_handler(handlers, ui_handler_region, ui_handler_remove_region, NULL, FALSE);
        WM_event_add_ui_handler(NULL, handlers, ui_handler_region, ui_handler_remove_region, NULL);
 }
 
@@ -6560,7 +6710,7 @@ void UI_add_popup_handlers(bContext *C, ListBase *handlers, uiPopupBlockHandle *
 
 void UI_remove_popup_handlers(ListBase *handlers, uiPopupBlockHandle *popup)
 {
-       WM_event_remove_ui_handler(handlers, ui_handler_popup, ui_handler_remove_popup, popup, 0);
+       WM_event_remove_ui_handler(handlers, ui_handler_popup, ui_handler_remove_popup, popup, FALSE);
 }