diff --git a/docs/changes.md b/docs/changes.md index add576682..066ea4e3e 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2021/05/08 + * 重构popup和相关测试。 + 2021/05/07 * 完善mledit(感谢兆坤提供补丁) * 重构button和相关测试。 diff --git a/src/widgets/popup.c b/src/widgets/popup.c index 8cc829764..0e4f63719 100644 --- a/src/widgets/popup.c +++ b/src/widgets/popup.c @@ -67,40 +67,6 @@ static ret_t popup_set_prop(widget_t* widget, const char* name, const value_t* v return window_base_set_prop(widget, name, v); } -static ret_t popup_idle_check_if_need_set_background_state(const idle_info_t* idle) { - xy_t x = 0; - xy_t y = 0; - wh_t right = 0; - wh_t bottom = 0; - bool_t is_background = FALSE; - widget_t* widget = WIDGET(idle->ctx); - widget_t* win = widget->parent; - event_t e = event_init(EVT_WINDOW_TO_BACKGROUND, widget); - - if (win != NULL) { - WIDGET_FOR_EACH_CHILD_BEGIN_R(win, iter, i) - if (iter == widget) { - break; - } - x = tk_min(x, iter->x); - y = tk_min(y, iter->y); - right = tk_max(right, (iter->x + iter->w)); - bottom = tk_max(bottom, (iter->y + iter->h)); - - WIDGET_FOR_EACH_CHILD_END(); - - if (x < widget->x && y < widget->y && right > (widget->x + widget->w) && - bottom > (widget->y + widget->h)) { - is_background = TRUE; - } - } - - if (is_background) { - widget_dispatch(widget, &e); - } - return RET_REMOVE; -} - static ret_t popup_idle_window_close(const idle_info_t* idle) { widget_t* widget = WIDGET(idle->ctx); widget_t* win = widget->parent; @@ -150,8 +116,6 @@ static ret_t popup_on_event(widget_t* widget, event_t* e) { if (!rect_contains(&r, evt->x, evt->y)) { close_window = TRUE; } - } else if (!popup->close_when_click) { - widget_add_idle(widget, popup_idle_check_if_need_set_background_state); } if (close_window) { diff --git a/src/window_manager/window_manager_default.c b/src/window_manager/window_manager_default.c index b05c53779..ae5f551f1 100644 --- a/src/window_manager/window_manager_default.c +++ b/src/window_manager/window_manager_default.c @@ -102,7 +102,7 @@ static widget_t* window_manager_find_prev_window(widget_t* widget) { return NULL; } -static widget_t* window_manager_find_prev_any_window(widget_t* widget) { +static widget_t* window_manager_find_prev_normal_window(widget_t* widget) { return_value_if_fail(widget != NULL, NULL); if (widget->children != NULL && widget->children->size >= 2) { @@ -305,7 +305,7 @@ static ret_t window_manager_prepare_dialog_highlighter(widget_t* widget, widget_ } static ret_t window_manager_create_highlighter(widget_t* widget, widget_t* curr_win) { - widget_t* prev_win = window_manager_find_prev_any_window(widget); + widget_t* prev_win = window_manager_find_prev_normal_window(widget); window_manager_prepare_dialog_highlighter(widget, prev_win, curr_win); return RET_OK; } @@ -314,7 +314,7 @@ static ret_t window_manager_create_animator(window_manager_default_t* wm, widget bool_t open) { value_t v; const char* anim_hint = NULL; - widget_t* prev_win = window_manager_find_prev_any_window(WIDGET(wm)); + widget_t* prev_win = window_manager_find_prev_normal_window(WIDGET(wm)); const char* key = open ? WIDGET_PROP_OPEN_ANIM_HINT : WIDGET_PROP_CLOSE_ANIM_HINT; if (prev_win == curr_win || prev_win == NULL) { @@ -773,6 +773,8 @@ static ret_t window_manager_animate_done(widget_t* widget) { wm->ignore_user_input = FALSE; if (is_open) { + /*此时前一个窗口并非是真正的前一个窗口,而是前一个normal窗口,所以这里重新找真正的前一个窗口*/ + prev_win = window_manager_find_prev_window(WIDGET(wm)); /* 结束打开窗口动画后 */ if (!curr_win_is_keyboard) { window_manager_dispatch_window_event(prev_win, EVT_WINDOW_TO_BACKGROUND);