diff options
author | crupest <crupest@outlook.com> | 2020-04-12 20:30:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-04-12 20:30:49 +0800 |
commit | db663ebb463dc00416038d068e538ab410558503 (patch) | |
tree | 5c20cac738e2a7111ba61754479a774c2e9e0c0a /src/ui/ui_host.cpp | |
parent | 23ef59b6aa14874e3b68c8716c137eb65583cd63 (diff) | |
download | cru-db663ebb463dc00416038d068e538ab410558503.tar.gz cru-db663ebb463dc00416038d068e538ab410558503.tar.bz2 cru-db663ebb463dc00416038d068e538ab410558503.zip |
...
Diffstat (limited to 'src/ui/ui_host.cpp')
-rw-r--r-- | src/ui/ui_host.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
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<render::WindowRenderObject>(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) { |