diff --git a/docs/changes.md b/docs/changes.md index 6453f9259..c52fa7a54 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -5,6 +5,7 @@ * 增加widget\_close\_window * 修改了lcd的宽高被修改后脏矩形的宽高不修改导致裁剪去有问题(感谢智明提供补丁) * 增加了把一个资源data加载到awtk的资源管理器的函数(感谢智明提供补丁) + * 完善window\_base\_on\_event(感谢尧燊提供补丁) * 2019/12/25 * 完善 line number(感谢大恒提供补丁)。 diff --git a/src/base/window_base.c b/src/base/window_base.c index 8d753a481..0e8114432 100644 --- a/src/base/window_base.c +++ b/src/base/window_base.c @@ -221,6 +221,11 @@ ret_t window_base_on_destroy(widget_t* widget) { window_base_t* window_base = WINDOW_BASE(widget); return_value_if_fail(widget != NULL && window_base != NULL, RET_BAD_PARAMS); + if (window_base->save_focus_widget) { + widget_unref(window_base->save_focus_widget); + window_base->save_focus_widget = NULL; + } + TKMEM_FREE(window_base->theme); TKMEM_FREE(window_base->open_anim_hint); TKMEM_FREE(window_base->close_anim_hint); @@ -284,18 +289,33 @@ ret_t window_base_on_event(widget_t* widget, event_t* e) { window_close(widget); } } else if (e->type == EVT_WINDOW_TO_FOREGROUND) { - if (win->should_grab_when_to_foreground) { - widget_grab(widget->parent, widget); + widget->parent->grab_widget_count = + widget->grab_widget_count + win->grab_count_when_to_foreground; + if (widget->parent->grab_widget_count) { + widget->parent->grab_widget = widget; + } + if (win->save_focus_widget) { + widget_set_focused_internal(win->save_focus_widget, TRUE); + widget_unref(win->save_focus_widget); + win->save_focus_widget = NULL; } - widget_set_focused_internal(win->save_focus_widget, TRUE); } else if (e->type == EVT_WINDOW_TO_BACKGROUND) { if (widget->parent->grab_widget == widget) { - widget_ungrab(widget->parent, widget); - win->should_grab_when_to_foreground = TRUE; + win->grab_count_when_to_foreground = + widget->parent->grab_widget_count - widget->grab_widget_count; + widget->parent->grab_widget_count = 0; + widget->parent->grab_widget = NULL; } else { - win->should_grab_when_to_foreground = FALSE; + win->grab_count_when_to_foreground = 0; + } + if (win->save_focus_widget) { + widget_unref(win->save_focus_widget); + win->save_focus_widget = NULL; } win->save_focus_widget = window_base_get_key_target_leaf(widget); + if (win->save_focus_widget) { + widget_ref(win->save_focus_widget); + } widget_set_focused(widget, FALSE); } diff --git a/src/base/window_base.h b/src/base/window_base.h index 60dd90dab..8d31597c8 100644 --- a/src/base/window_base.h +++ b/src/base/window_base.h @@ -194,7 +194,7 @@ typedef struct _window_base_t { font_manager_t* font_manager; native_window_t* native_window; widget_t* save_focus_widget; - bool_t should_grab_when_to_foreground; + uint32_t grab_count_when_to_foreground; } window_base_t; /*for sub class*/