From 26c97590171ab4c190bb9cb041e6234ce617ed13 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Sat, 21 Apr 2018 07:42:22 +0800 Subject: [PATCH] add window_close --- src/base/window.c | 7 +++++++ src/base/window.h | 10 ++++++++++ src/base/window_animator.h | 12 +++++++++--- src/base/window_manager.c | 12 ++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/base/window.c b/src/base/window.c index e1df29295..38f12d6a8 100644 --- a/src/base/window.c +++ b/src/base/window.c @@ -81,3 +81,10 @@ widget_t* window_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) { return widget; } + +ret_t window_close(widget_t* widget) { + return_value_if_fail(widget != NULL, RET_BAD_PARAMS); + + return window_manager_remove_child(widget->parent, widget); +} + diff --git a/src/base/window.h b/src/base/window.h index fb6f2f233..a52364c63 100644 --- a/src/base/window.h +++ b/src/base/window.h @@ -61,6 +61,16 @@ widget_t* window_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h); * @return {widget_t*} 对象。 */ +/** + * @method window_close + * @deconstructor + * 关闭窗口。 + * @param {widget_t*} parent window对象。 + * + * @return {ret_t} 返回RET_OK表示成功,否则表示失败。 + */ +ret_t window_close(widget_t* parent); + #define WINDOW(widget) ((window_t*)(widget)) END_C_DECLS diff --git a/src/base/window_animator.h b/src/base/window_animator.h index a30cbea0a..fb346c76e 100644 --- a/src/base/window_animator.h +++ b/src/base/window_animator.h @@ -52,10 +52,15 @@ typedef enum _window_animator_type_t { */ WINDOW_ANIMATOR_CENTER_SCALE, /** - * @const WINDOW_ANIMATOR_BOTTOM_POPUP - * 底部弹出。适用于底部的对话框。 + * @const WINDOW_ANIMATOR_TOP_TOP_BOTTOM + * 顶部部弹出。适用于对话框。 */ - WINDOW_ANIMATOR_BOTTOM_POPUP, + WINDOW_ANIMATOR_TOP_TOP_BOTTOM, + /** + * @const WINDOW_ANIMATOR_BOTTOM_TO_TOP + * 底部弹出。适用于对话框。 + */ + WINDOW_ANIMATOR_BOTTOM_TO_TOP, /** * @const WINDOW_ANIMATOR_HTRANSLATE * 水平平移。适用于窗口。 @@ -66,6 +71,7 @@ typedef enum _window_animator_type_t { * 垂直平移。适用于窗口。 */ WINDOW_ANIMATOR_VTRANSLATE, + WINDOW_ANIMATOR_NR } window_animator_type_t; diff --git a/src/base/window_manager.c b/src/base/window_manager.c index 0474dff45..bc7fd23da 100644 --- a/src/base/window_manager.c +++ b/src/base/window_manager.c @@ -44,7 +44,7 @@ static widget_t* window_manager_find_prev_window(widget_t* widget) { return NULL; } -static ret_t window_manager_check_if_need_open_animation(idle_info_t* info) { +static ret_t window_manager_check_if_need_open_animation(const idle_info_t* info) { value_t anim_hint; widget_t* prev_win = NULL; widget_t* curr_win = WIDGETP(info->ctx); @@ -140,12 +140,20 @@ ret_t window_manager_add_child(widget_t* wm, widget_t* window) { return widget_add_child(wm, window); } +static ret_t window_manager_idle_destroy_window(const idle_info_t* info) { + widget_t* win = WIDGETP(info->ctx); + widget_destroy(win); + + return RET_OK; +} + ret_t window_manager_remove_child(widget_t* wm, widget_t* window) { ret_t ret = RET_OK; return_value_if_fail(wm != NULL && window != NULL, RET_BAD_PARAMS); if (window_manager_check_if_need_close_animation(WINDOW_MANAGER(wm), window) != RET_OK) { - widget_destroy(window); + window_manager_remove_child_real(wm, window); + idle_add(window_manager_idle_destroy_window, window); } return ret;