From db663ebb463dc00416038d068e538ab410558503 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 12 Apr 2020 20:30:49 +0800 Subject: ... --- src/ui/ui_host.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ui/ui_host.cpp') diff --git a/src/ui/ui_host.cpp b/src/ui/ui_host.cpp index c82709dd..8b85ad30 100644 --- a/src/ui/ui_host.cpp +++ b/src/ui/ui_host.cpp @@ -101,7 +101,7 @@ UiHost::UiHost(Window* window) IUiApplication::GetInstance()->CreateWindow(nullptr); const auto native_window = native_window_resolver_->Resolve(); - window->_SetDescendantUiHost(this); + window->ui_host_ = this; root_render_object_ = std::make_unique(this); root_render_object_->SetAttachedControl(window); @@ -130,8 +130,15 @@ UiHost::UiHost(Window* window) } UiHost::~UiHost() { + deleting_ = true; window_control_->TraverseDescendants( [this](Control* control) { control->OnDetachFromHost(this); }); + if (!native_window_destroyed_) { + const auto native_window = native_window_resolver_->Resolve(); + if (native_window) { + native_window->Close(); + } + } } void UiHost::InvalidatePaint() { @@ -216,7 +223,8 @@ Control* UiHost::GetMouseCaptureControl() { return mouse_captured_control_; } void UiHost::OnNativeDestroy(INativeWindow* window, std::nullptr_t) { CRU_UNUSED(window) - delete this; // TODO: Develop this. + native_window_destroyed_ = true; + if (!deleting_ && !retain_after_destroy_) delete window_control_; } void UiHost::OnNativePaint(INativeWindow* window, std::nullptr_t) { -- cgit v1.2.3