diff --git a/components/rtgui/include/rtgui/widgets/workbench.h b/components/rtgui/include/rtgui/widgets/workbench.h index 1038c92e09382f1b4faa8fcacb855e077be9e9b8..7ada3553cac2076add0f8f18b9d45b7f97ed5477 100644 --- a/components/rtgui/include/rtgui/widgets/workbench.h +++ b/components/rtgui/include/rtgui/widgets/workbench.h @@ -64,6 +64,7 @@ rtgui_type_t* rtgui_workbench_type_get(void); rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title); void rtgui_workbench_destroy(rtgui_workbench_t* workbench); +void rtgui_workbench_close(rtgui_workbench_t* workbench); rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event); diff --git a/components/rtgui/widgets/workbench.c b/components/rtgui/widgets/workbench.c index fd203f91e0739790190464d72e2f3ec215b9e319..1ccc1774534e6f3123ea85acc4cd5defbc7d59a6 100644 --- a/components/rtgui/widgets/workbench.c +++ b/components/rtgui/widgets/workbench.c @@ -135,6 +135,20 @@ void rtgui_workbench_destroy(rtgui_workbench_t* workbench) { RT_ASSERT(workbench != RT_NULL); + if (workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED) + { + rtgui_widget_destroy(RTGUI_WIDGET(workbench)); + } + else + { + /* just close workbench */ + rtgui_workbench_close(workbench); + } +} + +void rtgui_workbench_close(rtgui_workbench_t* workbench) +{ + /* detach workbench in server */ if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL) { struct rtgui_event_panel_detach edetach; @@ -148,10 +162,11 @@ void rtgui_workbench_destroy(rtgui_workbench_t* workbench) RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK) return; - RTGUI_TOPLEVEL(workbench)->server = RT_NULL; + RTGUI_TOPLEVEL(workbench)->server = RT_NULL; } - rtgui_widget_destroy(RTGUI_WIDGET(workbench)); + /* set status to close */ + workbench->flag |= RTGUI_WORKBENCH_FLAG_CLOSED; } void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag)