Merging r40615 through r40652 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_handlers.c
index e9ec4ccc66d5bc74f5b95afb06681bc8fd9d123d..9106453eb545095bb3ef35df64d3324830fa5ee3 100644 (file)
@@ -56,6 +56,7 @@
 #include "BKE_idprop.h"
 #include "BKE_report.h"
 #include "BKE_texture.h"
+#include "BKE_tracking.h"
 #include "BKE_unit.h"
 
 #include "ED_screen.h"
@@ -253,7 +254,7 @@ static uiBut *ui_but_last(uiBlock *block)
 static int ui_is_a_warp_but(uiBut *but)
 {
        if(U.uiflag & USER_CONTINUOUS_MOUSE)
-               if(ELEM3(but->type, NUM, NUMABS, HSVCIRCLE))
+               if(ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW))
                        return TRUE;
 
        return FALSE;
@@ -631,7 +632,7 @@ static void ui_apply_but_IDPOIN(bContext *C, uiBut *but, uiHandleButtonData *dat
        data->applied= 1;
 }
 
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
 static void ui_apply_but_CHARTAB(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
        ui_apply_but_func(C, but);
@@ -800,8 +801,7 @@ static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to)
        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)
-       {
+       if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, NULL) & OPERATOR_FINISHED) {
                cont = (bController *)ob->controllers.last;
 
                /* (4) link the sensor->controller->actuator */
@@ -917,6 +917,13 @@ static void ui_apply_but_WAVEFORM(bContext *C, uiBut *but, uiHandleButtonData *d
        data->applied= 1;
 }
 
+static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+       ui_apply_but_func(C, but);
+       data->retval= but->retval;
+       data->applied= 1;
+}
+
 
 static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
 {
@@ -1024,7 +1031,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                case IDPOIN:
                        ui_apply_but_IDPOIN(C, but, data);
                        break;
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
                case CHARTAB:
                        ui_apply_but_CHARTAB(C, but, data);
                        break;
@@ -1046,6 +1053,9 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                case WAVEFORM:
                        ui_apply_but_WAVEFORM(C, but, data);
                        break;
+               case TRACKPREVIEW:
+                       ui_apply_but_TRACKPREVIEW(C, but, data);
+                       break;
                default:
                        break;
        }
@@ -1114,9 +1124,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                if(but->poin==NULL && but->rnapoin.data==NULL);
                else if(mode=='c') {
                        if(ui_is_but_float(but))
-                               sprintf(buf, "%f", ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but));
                        else
-                               sprintf(buf, "%d", (int)ui_get_but_val(but));
+                               BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but));
 
                        WM_clipboard_text_set(buf, 0);
                }
@@ -1137,7 +1147,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
                else if(mode=='c') {
 
                        ui_get_but_vectorf(but, rgb);
-                       sprintf(buf, "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
+                       BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]);
                        WM_clipboard_text_set(buf, 0);
                        
                }
@@ -1236,7 +1246,7 @@ static short test_special_char(char ch)
                case ':':
                case ';':
                case '\'':
-               case '\"':
+               case '\"': // " - an extra closing one for Aligorith's text editor
                case '<':
                case '>':
                case ',':
@@ -1270,7 +1280,7 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data)
 /* note, but->block->aspect is used here, when drawing button style is getting scaled too */
 static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, short x)
 {
-       uiStyle *style= U.uistyles.first;       // XXX pass on as arg
+       uiStyle *style= UI_GetStyle();  // XXX pass on as arg
        uiFontStyle *fstyle = &style->widget;
        int startx= but->x1;
        char *origstr;
@@ -1290,7 +1300,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
        else if(ELEM(but->type, TEX, SEARCH_MENU)) {
                startx += 5;
                if (but->flag & UI_HAS_ICON)
-                       startx += 16;
+                       startx += UI_DPI_ICON_SIZE;
        }
        
        /* mouse dragged outside the widget to the left */
@@ -1685,7 +1695,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
                        /* not a file?, strip non utf-8 chars */
                        if(strip) {
                                /* wont happen often so isnt that annoying to keep it here for a while */
-                               printf("invalid utf8 - stripped chars %d\n", strip);
+                               printf("%s: invalid utf8 - stripped chars %d\n", __func__, strip);
                        }
                }
                
@@ -1879,7 +1889,6 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
                                if(but->autocomplete_func || data->searchbox) {
                                        changed= ui_textedit_autocomplete(C, but, data);
                                        update= 1; /* do live update for tab key */
-                                       retval= WM_UI_HANDLER_BREAK;
                                }
                                /* the hotkey here is not well defined, was G.qual so we check all */
                                else if(event->shift || event->ctrl || event->alt || event->oskey) {
@@ -2311,13 +2320,13 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa
                float fac= 1.0f;
                
                if(ui_is_but_unit(but)) {
-                       Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+                       UnitSettings *unit= but->block->unit;
                        int unit_type= uiButGetUnitType(but)>>16;
 
-                       if(bUnit_IsValid(scene->unit.system, unit_type)) {
-                               fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type);
+                       if(bUnit_IsValid(unit->system, unit_type)) {
+                               fac= (float)bUnit_BaseScalar(unit->system, unit_type);
                                if(ELEM3(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) {
-                                       fac /= scene->unit.scale_length;
+                                       fac /= unit->scale_length;
                                }
                        }
                }
@@ -2325,8 +2334,8 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa
                if(fac != 1.0f) {
                        /* snap in unit-space */
                        tempf /= fac;
-                       softmin /= fac;
-                       softmax /= fac;
+                       /* softmin /= fac; */ /* UNUSED */
+                       /* softmax /= fac; */ /* UNUSED */
                        softrange /= fac;
                }
 
@@ -2857,7 +2866,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
 
 static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
 {
-       int mx, my, click= 0;
+       int mx, my /*, click= 0 */;
        int retval= WM_UI_HANDLER_CONTINUE;
        int horizontal= (but->x2 - but->x1 > but->y2 - but->y1);
        
@@ -2879,8 +2888,10 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
                                button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
                                retval= WM_UI_HANDLER_BREAK;
                        }
-                       else if(ELEM(event->type, PADENTER, RETKEY) && event->val==KM_PRESS)
+                       /* UNUSED - otherwise code is ok, add back if needed */
+                       /* else if(ELEM(event->type, PADENTER, RETKEY) && event->val==KM_PRESS)
                                click= 1;
+                       */
                }
        }
        else if(data->state == BUTTON_STATE_NUM_EDITING) {
@@ -3469,13 +3480,13 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
        CurveMapping *cumap= (CurveMapping*)but->poin;
        CurveMap *cuma= cumap->cm+cumap->cur;
        CurveMapPoint *cmp= cuma->curve;
-       float fx, fy, zoomx, zoomy, offsx, offsy;
+       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);
-       offsx= cumap->curr.xmin;
-       offsy= cumap->curr.ymin;
+       /* offsx= cumap->curr.xmin; */
+       /* offsy= cumap->curr.ymin; */
 
        if(snap) {
                float d[2];
@@ -3678,6 +3689,9 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                return WM_UI_HANDLER_BREAK;
        }
 
+       /* UNUSED but keep for now */
+       (void)changed;
+
        return WM_UI_HANDLER_CONTINUE;
 }
 
@@ -3692,12 +3706,12 @@ 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;
+       float /* dx, */ dy, yfac=1.f; /* UNUSED */
        
        /* rect.xmin= but->x1; rect.xmax= but->x2; */
        /* rect.ymin= but->y1; rect.ymax= but->y2; */
        
-       dx = mx - data->draglastx;
+       /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
        
        
@@ -3775,12 +3789,12 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
        Scopes *scopes = (Scopes *)but->poin;
        /* rcti rect; */
        int changed= 1;
-       float dx, dy, yfac=1.f;
+       float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */
 
        /* rect.xmin= but->x1; rect.xmax= but->x2; */
        /* rect.ymin= but->y1; rect.ymax= but->y2; */
 
-       dx = mx - data->draglastx;
+       /* dx = mx - data->draglastx; */ /* UNUSED */
        dy = my - data->draglasty;
 
 
@@ -3789,7 +3803,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
                scopes->wavefrm_height = (but->y2 - but->y1) + (data->dragstarty - my);
        } else {
                /* scale waveform values */
-               yfac = scopes->wavefrm_yfac;
+               /* yfac = scopes->wavefrm_yfac; */ /* UNUSED */
                scopes->wavefrm_yfac += dy/200.0f;
 
                CLAMP(scopes->wavefrm_yfac, 0.5f, 2.f);
@@ -3921,7 +3935,7 @@ static int ui_do_but_VECTORSCOPE(bContext *C, uiBlock *block, uiBut *but, uiHand
        return WM_UI_HANDLER_CONTINUE;
 }
 
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
 static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut *UNUSED(but), uiHandleButtonData *UNUSED(data), wmEvent *UNUSED(event))
 {
        /* XXX 2.50 bad global and state access */
@@ -4057,6 +4071,88 @@ 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)
+{
+       MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
+       int changed= 1;
+       float dx, dy;
+
+       dx = mx - data->draglastx;
+       dy = my - data->draglasty;
+
+       if(shift) {
+               dx /= 5.0f;
+               dy /= 5.0f;
+       }
+
+       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);
+       } else {
+               if(scopes->marker) {
+                       if(scopes->marker->framenr!=scopes->framenr)
+                               scopes->marker= BKE_tracking_ensure_marker(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);
+
+                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
+               }
+
+               scopes->ok= 0;
+       }
+
+       data->draglastx= mx;
+       data->draglasty= my;
+
+       return changed;
+}
+
+static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
+{
+       int mx, my;
+
+       mx= event->x;
+       my= event->y;
+       ui_window_to_block(data->region, block, &mx, &my);
+
+       if(data->state == BUTTON_STATE_HIGHLIGHT) {
+               if(event->type==LEFTMOUSE && event->val==KM_PRESS) {
+                       data->dragstartx= mx;
+                       data->dragstarty= my;
+                       data->draglastx= mx;
+                       data->draglasty= my;
+                       button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
+
+                       /* also do drag the first time */
+                       if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
+                               ui_numedit_apply(C, block, but, data);
+
+                       return WM_UI_HANDLER_BREAK;
+               }
+       }
+       else if(data->state == BUTTON_STATE_NUM_EDITING) {
+               if(event->type == ESCKEY) {
+                       data->cancel= 1;
+                       data->escapecancel= 1;
+                       button_activate_state(C, but, BUTTON_STATE_EXIT);
+               }
+               else if(event->type == MOUSEMOVE) {
+                       if(mx!=data->draglastx || my!=data->draglasty) {
+                               if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
+                                       ui_numedit_apply(C, block, but, data);
+                       }
+               }
+               else if(event->type==LEFTMOUSE && event->val!=KM_PRESS) {
+                       button_activate_state(C, but, BUTTON_STATE_EXIT);
+               }
+               return WM_UI_HANDLER_BREAK;
+       }
+
+       return WM_UI_HANDLER_CONTINUE;
+}
+
 static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
 {
        uiBut *but = (uiBut *)arg1;
@@ -4068,7 +4164,6 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
                
                /* complex code to change name of button */
                if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
-                       wmKeyMap *km= NULL;
                        char *butstr_orig;
 
                        // XXX but->str changed... should not, remove the hotkey from it
@@ -4081,10 +4176,6 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
                        but->str= but->strdata;
 
                        ui_check_but(but);
-
-                       /* set the keymap editable else the key wont save */
-                       WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
-                       WM_keymap_copy_to_user(km);
                }
                else {
                        /* shortcut was removed */
@@ -4096,19 +4187,20 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
 
 static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        uiBlock *block;
        uiBut *but = (uiBut *)arg;
        wmKeyMap *km;
        wmKeyMapItem *kmi;
        PointerRNA ptr;
        uiLayout *layout;
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
        int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
 
        kmi = WM_keymap_item_find_id(km, kmi_id);
        
-       RNA_pointer_create(NULL, &RNA_KeyMapItem, kmi, &ptr);
+       RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr);
        
        block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
        uiBlockSetHandleFunc(block, but_shortcut_name_func, but);
@@ -4127,27 +4219,34 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg)
 
 static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        uiBlock *block;
        uiBut *but = (uiBut *)arg;
        wmKeyMap *km;
        wmKeyMapItem *kmi;
        PointerRNA ptr;
        uiLayout *layout;
-       uiStyle *style= U.uistyles.first;
+       uiStyle *style= UI_GetStyle();
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
+       int kmi_id;
        
        /* XXX this guess_opname can potentially return a different keymap than being found on adding later... */
        km = WM_keymap_guess_opname(C, but->optype->idname);            
        kmi = WM_keymap_add_item(km, but->optype->idname, AKEY, KM_PRESS, 0, 0);
+       kmi_id = kmi->id;
 
-       if (prop) {
+       /* copy properties, prop can be NULL for reset */       
+       if(prop)
                prop= IDP_CopyProperty(prop);
-       }
-
-       /* prop can be NULL */  
        WM_keymap_properties_reset(kmi, prop);
 
-       RNA_pointer_create(NULL, &RNA_KeyMapItem, kmi, &ptr);
+       /* update and get pointers again */
+       WM_keyconfig_update(wm);
+
+       km = WM_keymap_guess_opname(C, but->optype->idname);            
+       kmi = WM_keymap_item_find_id(km, kmi_id);
+
+       RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr);
 
        block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
        uiBlockSetHandleFunc(block, but_shortcut_name_func, but);
@@ -4228,6 +4327,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                
                /* Keyframes */
                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);
@@ -4238,6 +4338,11 @@ static int ui_but_menu(bContext *C, uiBut *but)
                                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);
                        }
+                       
+                       /* keyframe settings */
+                       uiItemS(layout);
+                       
+                       
                }
                else if(but->flag & UI_BUT_DRIVEN);
                else if(is_anim) {
@@ -4280,6 +4385,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                }
                
                /* Keying Sets */
+               // TODO: check on modifyability of Keying Set when doing this
                if(is_anim) {
                        uiItemS(layout);
 
@@ -4354,7 +4460,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
                PointerRNA ptr_props;
 
                if(but->rnapoin.data && but->rnaprop) {
-                       sprintf(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");
                        RNA_string_set(&ptr_props, "doc_id", buf);
@@ -4571,7 +4677,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        case HSVCIRCLE:
                retval= ui_do_but_HSVCIRCLE(C, block, but, data, event);
                break;
-#ifdef INTERNATIONAL
+#ifdef WITH_INTERNATIONAL
        case CHARTAB:
                retval= ui_do_but_CHARTAB(C, block, but, data, event);
                break;
@@ -4581,6 +4687,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        case INLINK:
                retval= ui_do_but_LINK(C, but, data, event);
                break;
+       case TRACKPREVIEW:
+               retval= ui_do_but_TRACKPREVIEW(C, block, but, data, event);
+               break;
        }
        
        return retval;
@@ -5901,7 +6010,7 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle
                                                                        ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE);
                                                                }
                                                                else {
-                                                                       printf("Error, but->menu_key type: %d\n", but->type);
+                                                                       printf("%s: error, but->menu_key type: %d\n", __func__, but->type);
                                                                }
 
                                                                break;