Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / interface / interface_handlers.c
index 47de598c028b3e3f4f4866f46865e8794db3fea1..3af64c8c5a6645539c48a98b4cf5cd23a1f2f5ec 100644 (file)
@@ -185,7 +185,6 @@ typedef struct uiSelectContextStore {
        uiSelectContextElem *elems;
        int elems_len;
        bool do_free;
-       bool is_enabled;
        /* When set, simply copy values (don't apply difference).
         * Rules are:
         * - dragging numbers uses delta.
@@ -201,7 +200,9 @@ static void ui_selectcontext_apply(
         bContext *C, uiBut *but, struct uiSelectContextStore *selctx_data,
         const double value, const double value_orig);
 
+#if 0
 #define IS_ALLSELECT_EVENT(event) ((event)->alt != 0)
+#endif
 
 /** just show a tinted color so users know its activated */
 #define UI_BUT_IS_SELECT_CONTEXT UI_BUT_NODE_ACTIVE
@@ -1179,14 +1180,11 @@ static void ui_multibut_states_apply(bContext *C, uiHandleButtonData *data, uiBl
                                ui_but_execute_begin(C, ar, but, &active_back);
 
 #ifdef USE_ALLSELECT
-                               if (data->select_others.is_enabled) {
-                                       /* init once! */
-                                       if (mbut_state->select_others.elems_len == 0) {
-                                               ui_selectcontext_begin(C, but, &mbut_state->select_others);
-                                       }
-                                       if (mbut_state->select_others.elems_len == 0) {
-                                               mbut_state->select_others.elems_len = -1;
-                                       }
+                               if (mbut_state->select_others.elems_len == 0) {
+                                       ui_selectcontext_begin(C, but, &mbut_state->select_others);
+                               }
+                               if (mbut_state->select_others.elems_len == 0) {
+                                       mbut_state->select_others.elems_len = -1;
                                }
 
                                /* needed so we apply the right deltas */
@@ -2069,12 +2067,7 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                else
 #  endif
                if (data->select_others.elems_len == 0) {
-                       wmWindow *win = CTX_wm_window(C);
-                       /* may have been enabled before activating */
-                       if (data->select_others.is_enabled || IS_ALLSELECT_EVENT(win->eventstate)) {
-                               ui_selectcontext_begin(C, but, &data->select_others);
-                               data->select_others.is_enabled = true;
-                       }
+                       ui_selectcontext_begin(C, but, &data->select_others);
                }
                if (data->select_others.elems_len == 0) {
                        /* dont check again */
@@ -2115,6 +2108,7 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
                        break;
                case UI_BTYPE_ROW:
                case UI_BTYPE_LISTROW:
+               case UI_BTYPE_TAB:
                        ui_apply_but_ROW(C, block, but, data);
                        break;
                case UI_BTYPE_SCROLL:
@@ -3076,11 +3070,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
 
 #ifdef USE_ALLSELECT
        if (is_num_but) {
-               if (IS_ALLSELECT_EVENT(win->eventstate)) {
-                       data->select_others.is_enabled = true;
-                       data->select_others.is_copy = true;
-
-               }
+               data->select_others.is_copy = true;
        }
 #endif
 
@@ -3167,6 +3157,9 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
 
                        ui_searchbox_free(C, data->searchbox);
                        data->searchbox = NULL;
+                       if (but->free_search_arg) {
+                               MEM_SAFE_FREE(but->search_arg);
+                       }
                }
                
                but->editstr = NULL;
@@ -3682,15 +3675,6 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
                        data->menu->popup = but->block->handle->popup;
        }
 
-#ifdef USE_ALLSELECT
-       {
-               wmWindow *win = CTX_wm_window(C);
-               if (IS_ALLSELECT_EVENT(win->eventstate)) {
-                       data->select_others.is_enabled = true;
-               }
-       }
-#endif
-
        /* this makes adjacent blocks auto open from now on */
        //if (but->block->auto_open == 0) but->block->auto_open = 1;
 }
@@ -3872,6 +3856,18 @@ static int ui_do_but_KEYEVT(
        return WM_UI_HANDLER_CONTINUE;
 }
 
+static int ui_do_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
+{
+       if (data->state == BUTTON_STATE_HIGHLIGHT) {
+               if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_RELEASE) {
+                       button_activate_state(C, but, BUTTON_STATE_EXIT);
+                       return WM_UI_HANDLER_CONTINUE;
+               }
+       }
+
+       return WM_UI_HANDLER_CONTINUE;
+}
+
 static bool ui_but_is_mouse_over_icon_extra(const ARegion *region, uiBut *but, const int mouse_xy[2])
 {
        int x = mouse_xy[0], y = mouse_xy[1];
@@ -5216,7 +5212,8 @@ static int ui_do_but_COLOR(
                                if (!event->ctrl) {
                                        float color[3];
                                        Scene *scene = CTX_data_scene(C);
-                                       Paint *paint = BKE_paint_get_active(scene);
+                                       ViewLayer *view_layer = CTX_data_view_layer(C);
+                                       Paint *paint = BKE_paint_get_active(scene, view_layer);
                                        Brush *brush = BKE_paint_brush(paint);
 
                                        if (brush->flag & BRUSH_USE_GRADIENT) {
@@ -6133,6 +6130,7 @@ static int ui_do_but_CURVE(
        int mx, my, a;
        bool changed = false;
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        mx = event->x;
        my = event->y;
@@ -6261,7 +6259,7 @@ static int ui_do_but_CURVE(
                                }
                                else {
                                        curvemapping_changed(cumap, true);  /* remove doubles */
-                                       BKE_paint_invalidate_cursor_overlay(scene, cumap);
+                                       BKE_paint_invalidate_cursor_overlay(scene, view_layer, cumap);
                                }
                        }
 
@@ -6767,6 +6765,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
        MenuType *mt = WM_menutype_find("WM_MT_button_context", true);
        bool is_array, is_array_component;
        uiStringInfo label = {BUT_GET_LABEL, NULL};
+       wmOperatorType *ot;
+       PointerRNA op_ptr;
 
 /*     if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/
 /*             return 0;*/
@@ -6793,11 +6793,11 @@ static bool ui_but_menu(bContext *C, uiBut *but)
                const PropertySubType subtype = RNA_property_subtype(prop);
                bool is_anim = RNA_property_animateable(ptr, prop);
                bool is_editable = RNA_property_editable(ptr, prop);
+               bool is_overridable;
                /*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */
                bool is_set = RNA_property_is_set(ptr, prop);
 
-               /* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */
-               uiLayoutSetContextFromBut(layout, but);
+               RNA_property_override_status(ptr, prop, -1, &is_overridable, NULL, NULL, NULL);
 
                /* second slower test, saved people finding keyframe items in menus when its not possible */
                if (is_anim)
@@ -6926,11 +6926,57 @@ static bool ui_but_menu(bContext *C, uiBut *but)
                                        ICON_NONE, "ANIM_OT_keyingset_button_remove");
                        }
                }
-               
+
+               if (is_overridable) {
+                       /* Override Operators */
+                       uiItemS(layout);
+
+                       if (but->flag & UI_BUT_OVERRIDEN) {
+                               if (is_array_component) {
+                                       ot = WM_operatortype_find("UI_OT_override_type_set_button", false);
+                                       uiItemFullO_ptr(layout, ot, "Overrides Type", ICON_NONE,
+                                                       NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", true);
+                                       uiItemFullO_ptr(layout, ot, "Single Override Type", ICON_NONE,
+                                                       NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", false);
+
+                                       uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Overrides"),
+                                                      ICON_X, "UI_OT_override_remove_button", "all", true);
+                                       uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Single Override"),
+                                                      ICON_X, "UI_OT_override_remove_button", "all", false);
+                               }
+                               else {
+                                       uiItemFullO(layout, "UI_OT_override_type_set_button", "Override Type", ICON_NONE,
+                                                   NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", false);
+
+                                       uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Override"),
+                                                      ICON_X, "UI_OT_override_remove_button", "all", true);
+                               }
+                       }
+                       else {
+                               if (is_array_component) {
+                                       ot = WM_operatortype_find("UI_OT_override_type_set_button", false);
+                                       uiItemFullO_ptr(layout, ot, "Define Overrides", ICON_NONE,
+                                                       NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", true);
+                                       uiItemFullO_ptr(layout, ot, "Define Single Override", ICON_NONE,
+                                                       NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", false);
+                               }
+                               else {
+                                       uiItemFullO(layout, "UI_OT_override_type_set_button", "Define Override", ICON_NONE,
+                                                   NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+                                       RNA_boolean_set(&op_ptr, "all", false);
+                               }
+                       }
+               }
+
                uiItemS(layout);
-               
+
                /* Property Operators */
-               
+
                /* Copy Property Value
                 * Paste Property Value */
                
@@ -7135,6 +7181,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
                case UI_BTYPE_HOTKEY_EVENT:
                        retval = ui_do_but_HOTKEYEVT(C, but, data, event);
                        break;
+               case UI_BTYPE_TAB:
+                       retval = ui_do_but_TAB(C, but, data, event);
+                       break;
                case UI_BTYPE_BUT_TOGGLE:
                case UI_BTYPE_TOGGLE:
                case UI_BTYPE_ICON_TOGGLE:
@@ -7652,7 +7701,7 @@ void UI_but_tooltip_refresh(bContext *C, uiBut *but)
 {
        uiHandleButtonData *data = but->active;
        if (data) {
-               bScreen *sc = data->window->screen;
+               bScreen *sc = WM_window_get_active_screen(data->window);
                if (sc->tool_tip && sc->tool_tip->region) {
                        WM_tooltip_refresh(C, data->window);
                }
@@ -8208,6 +8257,7 @@ void UI_context_update_anim_flag(const bContext *C)
                for (block = ar->uiblocks.first; block; block = block->next) {
                        for (but = block->buttons.first; but; but = but->next) {
                                ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f);
+                               ui_but_override_flag(but);
                                ED_region_tag_redraw(ar);
                                
                                if (but->active) {