aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-08 21:15:31 +0800
committercrupest <crupest@outlook.com>2022-02-08 21:15:31 +0800
commit5d7dcef619bd1f866684b57351dde2efbda6959c (patch)
treeab63bd149854ce0cf4cad338dd962e5ea613010b
parentfa1764d7cb77aa683c6049f915a46b981f9161f7 (diff)
downloadcru-5d7dcef619bd1f866684b57351dde2efbda6959c.tar.gz
cru-5d7dcef619bd1f866684b57351dde2efbda6959c.tar.bz2
cru-5d7dcef619bd1f866684b57351dde2efbda6959c.zip
...
-rw-r--r--include/cru/ui/host/WindowHost.h8
-rw-r--r--src/ui/host/WindowHost.cpp10
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<platform::gui::ICursor> cursor);
private:
- gsl::not_null<platform::gui::INativeWindow*> CreateNativeWindow();
+ std::unique_ptr<platform::gui::INativeWindow> 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<platform::gui::INativeWindow> native_window_;
std::unique_ptr<LayoutPaintCycler> 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<LayoutPaintCycler>(this);
- CreateNativeWindow();
+ native_window_ = CreateNativeWindow();
}
-WindowHost::~WindowHost() { delete native_window_; }
+WindowHost::~WindowHost() {}
-gsl::not_null<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow() {
+std::unique_ptr<platform::gui::INativeWindow> 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<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow() {
native_window_change_event_.Raise(native_window);
- return native_window_;
+ return std::unique_ptr<INativeWindow>(native_window);
}
void WindowHost::InvalidatePaint() { layout_paint_cycler_->InvalidatePaint(); }