From 5d7dcef619bd1f866684b57351dde2efbda6959c Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 21:15:31 +0800 Subject: ... --- include/cru/ui/host/WindowHost.h | 8 +++++--- src/ui/host/WindowHost.cpp | 10 ++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h index caa50397..8a8f1da5 100644 --- a/include/cru/ui/host/WindowHost.h +++ b/include/cru/ui/host/WindowHost.h @@ -29,7 +29,9 @@ class CRU_UI_API WindowHost : public Object { ~WindowHost() override; public: - platform::gui::INativeWindow* GetNativeWindow() { return native_window_; } + platform::gui::INativeWindow* GetNativeWindow() { + return native_window_.get(); + } // Mark the layout as invalid, and arrange a re-layout later. // This method could be called more than one times in a message cycle. But @@ -103,7 +105,7 @@ class CRU_UI_API WindowHost : public Object { void SetOverrideCursor(std::shared_ptr cursor); private: - gsl::not_null CreateNativeWindow(); + std::unique_ptr CreateNativeWindow(); //*************** region: native messages *************** void OnNativeDestroy(platform::gui::INativeWindow* window, std::nullptr_t); @@ -140,7 +142,7 @@ class CRU_UI_API WindowHost : public Object { controls::Control* root_control_ = nullptr; render::RenderObject* root_render_object_ = nullptr; - platform::gui::INativeWindow* native_window_ = nullptr; + std::unique_ptr native_window_; std::unique_ptr layout_paint_cycler_; diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 2d09a895..4373afe9 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -115,19 +115,17 @@ WindowHost::WindowHost(controls::Control* root_control) this->layout_paint_cycler_ = std::make_unique(this); - CreateNativeWindow(); + native_window_ = CreateNativeWindow(); } -WindowHost::~WindowHost() { delete native_window_; } +WindowHost::~WindowHost() {} -gsl::not_null WindowHost::CreateNativeWindow() { +std::unique_ptr WindowHost::CreateNativeWindow() { const auto ui_application = IUiApplication::GetInstance(); auto native_window = ui_application->CreateWindow(); Ensures(native_window); - native_window_ = native_window; - BindNativeEvent(this, native_window, native_window->DestroyEvent(), &WindowHost::OnNativeDestroy, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->PaintEvent(), @@ -153,7 +151,7 @@ gsl::not_null WindowHost::CreateNativeWindow() { native_window_change_event_.Raise(native_window); - return native_window_; + return std::unique_ptr(native_window); } void WindowHost::InvalidatePaint() { layout_paint_cycler_->InvalidatePaint(); } -- cgit v1.2.3