diff options
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 184 |
1 files changed, 66 insertions, 118 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 8a744a1edbe..d720b52a59e 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -439,11 +439,11 @@ typedef struct uiHandleButtonData { float ungrab_mval[2]; #endif - /* menu open (watch UI_screen_free_active_but) */ + /* Menu open, see: #UI_screen_free_active_but_highlight. */ uiPopupBlockHandle *menu; int menuretval; - /* search box (watch UI_screen_free_active_but) */ + /* Search box see: #UI_screen_free_active_but_highlight. */ ARegion *searchbox; #ifdef USE_KEYNAV_LIMIT struct uiKeyNavLock searchbox_keynav_state; @@ -555,7 +555,6 @@ bool ui_but_is_editing(const uiBut *but) return (data && ELEM(data->state, BUTTON_STATE_TEXT_EDITING, BUTTON_STATE_NUM_EDITING)); } -/* assumes event type is MOUSEPAN */ void ui_pan_to_scroll(const wmEvent *event, int *type, int *val) { static int lastdy = 0; @@ -594,11 +593,6 @@ static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut *but (but_a->rnaprop == but_b->rnaprop)); } -/** - * Finds the pressed button in an aligned row (typically an expanded enum). - * - * \param direction: Use when there may be multiple buttons pressed. - */ uiBut *ui_but_find_select_in_enum(uiBut *but, int direction) { uiBut *but_iter = but; @@ -1266,12 +1260,22 @@ static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data) static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) { if (data->str) { + /* This is intended to avoid unnecessary updates when the value stays the same, however there + * are issues with the current implementation. It does not work with multi-button editing + * (T89996) or operator popups where a number button requires an update even if the value is + * unchanged (T89996). + * + * Trying to detect changes at this level is not reliable. Instead it could be done at the + * level of RNA update/set, skipping RNA update if RNA set did not change anything, instead + * of skipping all button updates. */ +#if 0 double value; /* Check if the string value is a number and cancel if it's equal to the startvalue. */ if (ui_but_string_eval_number(C, but, data->str, &value) && (value == data->startvalue)) { data->cancel = true; return; } +#endif if (ui_but_string_set(C, but, data->str)) { data->value = ui_but_value_get(but); @@ -1783,7 +1787,7 @@ static bool ui_but_is_drag_toggle(const uiBut *but) static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore *selctx_data) { - PointerRNA lptr, idptr; + PointerRNA lptr; PropertyRNA *lprop; bool success = false; @@ -1817,68 +1821,48 @@ static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore if (i >= selctx_data->elems_len) { break; } + + if (!UI_context_copy_to_selected_check( + &ptr, &link->ptr, prop, path, use_path_from_id, &lptr, &lprop)) { + selctx_data->elems_len -= 1; + i -= 1; + continue; + } + uiSelectContextElem *other = &selctx_data->elems[i]; - /* TODO: de-duplicate copy_to_selected_button. */ - if (link->ptr.data != ptr.data) { - if (use_path_from_id) { - /* Path relative to ID. */ - lprop = NULL; - RNA_id_pointer_create(link->ptr.owner_id, &idptr); - RNA_path_resolve_property(&idptr, path, &lptr, &lprop); - } - else if (path) { - /* Path relative to elements from list. */ - lprop = NULL; - RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop); + other->ptr = lptr; + if (is_array) { + if (rna_type == PROP_FLOAT) { + other->val_f = RNA_property_float_get_index(&lptr, lprop, index); } - else { - lptr = link->ptr; - lprop = prop; + else if (rna_type == PROP_INT) { + other->val_i = RNA_property_int_get_index(&lptr, lprop, index); } - - /* lptr might not be the same as link->ptr! */ - if ((lptr.data != ptr.data) && (lprop == prop) && RNA_property_editable(&lptr, lprop)) { - other->ptr = lptr; - if (is_array) { - if (rna_type == PROP_FLOAT) { - other->val_f = RNA_property_float_get_index(&lptr, lprop, index); - } - else if (rna_type == PROP_INT) { - other->val_i = RNA_property_int_get_index(&lptr, lprop, index); - } - /* ignored for now */ + /* ignored for now */ # if 0 - else if (rna_type == PROP_BOOLEAN) { - other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index); - } -# endif + else if (rna_type == PROP_BOOLEAN) { + other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index); } - else { - if (rna_type == PROP_FLOAT) { - other->val_f = RNA_property_float_get(&lptr, lprop); - } - else if (rna_type == PROP_INT) { - other->val_i = RNA_property_int_get(&lptr, lprop); - } - /* ignored for now */ -# if 0 - else if (rna_type == PROP_BOOLEAN) { - other->val_b = RNA_property_boolean_get(&lptr, lprop); - } - else if (rna_type == PROP_ENUM) { - other->val_i = RNA_property_enum_get(&lptr, lprop); - } # endif - } - - continue; + } + else { + if (rna_type == PROP_FLOAT) { + other->val_f = RNA_property_float_get(&lptr, lprop); + } + else if (rna_type == PROP_INT) { + other->val_i = RNA_property_int_get(&lptr, lprop); } + /* ignored for now */ +# if 0 + else if (rna_type == PROP_BOOLEAN) { + other->val_b = RNA_property_boolean_get(&lptr, lprop); + } + else if (rna_type == PROP_ENUM) { + other->val_i = RNA_property_enum_get(&lptr, lprop); + } +# endif } - - selctx_data->elems_len -= 1; - i -= 1; } - success = (selctx_data->elems_len != 0); } } @@ -2334,9 +2318,6 @@ static void ui_apply_but( case UI_BTYPE_LISTROW: ui_apply_but_LISTROW(C, block, but, data); break; - case UI_BTYPE_DATASETROW: - ui_apply_but_ROW(C, block, but, data); - break; case UI_BTYPE_TAB: ui_apply_but_TAB(C, but, data); break; @@ -2985,11 +2966,6 @@ void ui_but_text_password_hide(char password_str[UI_MAX_PASSWORD_STR], /** \name Button Text Selection/Editing * \{ */ -/** - * Use handling code to set a string for the button. Handles the case where the string is set for a - * search button while the search menu is open, so the results are updated accordingly. - * This is basically the same as pasting the string into the button. - */ void ui_but_set_string_interactive(bContext *C, uiBut *but, const char *value) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); @@ -3555,6 +3531,12 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) if ((ui_searchbox_apply(but, data->searchbox) == false) && (ui_searchbox_find_index(data->searchbox, but->editstr) == -1) && !but_search->results_are_suggestions) { + + if (but->flag & UI_BUT_VALUE_CLEAR) { + /* It is valid for _VALUE_CLEAR flavor to have no active element + * (it's a valid way to unlink). */ + but->editstr[0] = '\0'; + } data->cancel = true; /* ensure menu (popup) too is closed! */ @@ -8012,7 +7994,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * case UI_BTYPE_CHECKBOX: case UI_BTYPE_CHECKBOX_N: case UI_BTYPE_ROW: - case UI_BTYPE_DATASETROW: retval = ui_do_but_TOG(C, but, data, event); break; case UI_BTYPE_TREEROW: @@ -8185,9 +8166,6 @@ static void ui_blocks_set_tooltips(ARegion *region, const bool enable) } } -/** - * Recreate tool-tip (use to update dynamic tips) - */ void UI_but_tooltip_refresh(bContext *C, uiBut *but) { uiHandleButtonData *data = but->active; @@ -8199,10 +8177,6 @@ void UI_but_tooltip_refresh(bContext *C, uiBut *but) } } -/** - * Removes tool-tip timer from active but - * (meaning tool-tip is disabled until it's re-enabled again). - */ void UI_but_tooltip_timer_remove(bContext *C, uiBut *but) { uiHandleButtonData *data = but->active; @@ -8770,11 +8744,6 @@ uiBut *UI_context_active_but_get(const bContext *C) return ui_context_button_active(CTX_wm_region(C), NULL); } -/* - * Version of #UI_context_active_get() that uses the result of #CTX_wm_menu() - * if set. Does not traverse into parent menus, which may be wanted in some - * cases. - */ uiBut *UI_context_active_but_get_respect_menu(const bContext *C) { ARegion *region_menu = CTX_wm_menu(C); @@ -8798,12 +8767,6 @@ uiBlock *UI_region_block_find_mouse_over(const struct ARegion *region, return ui_block_find_mouse_over_ex(region, xy, only_clip); } -/** - * Version of #UI_context_active_but_get that also returns RNA property info. - * Helper function for insert keyframe, reset to default, etc operators. - * - * \return active button, NULL if none found or if it doesn't contain valid RNA data. - */ uiBut *UI_context_active_but_prop_get(const bContext *C, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, @@ -8879,16 +8842,12 @@ wmOperator *UI_context_active_operator_get(const struct bContext *C) return NULL; } -/** - * Try to find a search-box region opened from a button in \a button_region. - */ ARegion *UI_region_searchbox_region_get(const ARegion *button_region) { uiBut *but = UI_region_active_but_get(button_region); return (but != NULL) ? but->active->searchbox : NULL; } -/* helper function for insert keyframe, reset to default, etc operators */ void UI_context_update_anim_flag(const bContext *C) { Scene *scene = CTX_data_scene(C); @@ -8937,10 +8896,6 @@ void UI_context_update_anim_flag(const bContext *C) } } -/** - * In some cases we may want to update the view (#View2D) in-between layout definition and drawing. - * E.g. to make sure a button is visible while editing. - */ void ui_but_update_view_for_active(const bContext *C, const uiBlock *block) { uiBut *active_but = ui_block_active_but_get(block); @@ -9000,11 +8955,6 @@ static int ui_handle_button_over(bContext *C, const wmEvent *event, ARegion *reg return WM_UI_HANDLER_CONTINUE; } -/** - * Exported to interface.c: #UI_but_active_only() - * \note The region is only for the button. - * The context needs to be set by the caller. - */ void ui_but_activate_event(bContext *C, ARegion *region, uiBut *but) { wmWindow *win = CTX_wm_window(C); @@ -9022,12 +8972,6 @@ void ui_but_activate_event(bContext *C, ARegion *region, uiBut *but) ui_do_button(C, but->block, but, &event); } -/** - * Simulate moving the mouse over a button (or navigating to it with arrow keys). - * - * exported so menus can start with a highlighted button, - * even if the mouse isn't over it - */ void ui_but_activate_over(bContext *C, ARegion *region, uiBut *but) { button_activate_init(C, region, but, BUTTON_ACTIVATE_OVER); @@ -11267,10 +11211,6 @@ static int ui_handle_menus_recursive(bContext *C, return retval; } -/** - * Allow setting menu return value from externals. - * E.g. WM might need to do this for exiting files correctly. - */ void UI_popup_menu_retval_set(const uiBlock *block, const int retval, const bool enable) { uiPopupBlockHandle *menu = block->handle; @@ -11344,8 +11284,7 @@ static void ui_region_handler_remove(bContext *C, void *UNUSED(userdata)) return; } - UI_blocklist_free(C, ®ion->uiblocks); - + UI_blocklist_free(C, region); bScreen *screen = CTX_wm_screen(C); if (screen == NULL) { return; @@ -11669,8 +11608,19 @@ bool UI_textbutton_activate_but(const bContext *C, uiBut *actbut) /** \name Public Utilities * \{ */ -/* is called by notifier */ -void UI_screen_free_active_but(const bContext *C, bScreen *screen) +void UI_region_free_active_but_all(bContext *C, ARegion *region) +{ + LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { + LISTBASE_FOREACH (uiBut *, but, &block->buttons) { + if (but->active == NULL) { + continue; + } + ui_but_active_free(C, but); + } + } +} + +void UI_screen_free_active_but_highlight(const bContext *C, bScreen *screen) { wmWindow *win = CTX_wm_window(C); @@ -11704,8 +11654,6 @@ uiBut *UI_but_active_drop_name_button(const bContext *C) return NULL; } -/* returns true if highlighted button allows drop of names */ -/* called in region context */ bool UI_but_active_drop_name(const bContext *C) { return UI_but_active_drop_name_button(C) != NULL; |