improve window_base_on_event

This commit is contained in:
xianjimli 2019-12-26 17:52:24 +08:00
parent 1df646caa7
commit 934f17d757
3 changed files with 28 additions and 7 deletions

View File

@ -5,6 +5,7 @@
* 增加widget\_close\_window
* 修改了lcd的宽高被修改后脏矩形的宽高不修改导致裁剪去有问题感谢智明提供补丁
* 增加了把一个资源data加载到awtk的资源管理器的函数感谢智明提供补丁
* 完善window\_base\_on\_event感谢尧燊提供补丁
* 2019/12/25
* 完善 line number感谢大恒提供补丁

View File

@ -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);
}

View File

@ -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*/