aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/gui/Window.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/win/gui/Window.hpp')
-rw-r--r--include/cru/win/gui/Window.hpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/include/cru/win/gui/Window.hpp b/include/cru/win/gui/Window.hpp
index 9f241b0a..5ce3ed25 100644
--- a/include/cru/win/gui/Window.hpp
+++ b/include/cru/win/gui/Window.hpp
@@ -13,8 +13,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::gui::win::WinNativeWindow")
public:
- WinNativeWindow(WinUiApplication* application, WindowClass* window_class,
- DWORD window_style, WinNativeWindow* parent);
+ explicit WinNativeWindow(WinUiApplication* application);
CRU_DELETE_COPY(WinNativeWindow)
CRU_DELETE_MOVE(WinNativeWindow)
@@ -25,19 +24,31 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
void Close() override;
WinNativeWindow* GetParent() override { return parent_window_; }
+ void SetParent(INativeWindow* parent) override;
+ WindowStyleFlag GetStyleFlag() override { return style_flag_; }
+ void SetStyleFlag(WindowStyleFlag flag) override;
+
+ WindowVisibilityType GetVisibility() override { return visibility_; }
+ void SetVisibility(WindowVisibilityType visibility) override;
Size GetClientSize() override;
void SetClientSize(const Size& size) override;
+ Rect GetClientRect() override;
+ void SetClientRect(const Rect& rect) override;
+
// Get the rect of the window containing frame.
// The lefttop of the rect is relative to screen lefttop.
Rect GetWindowRect() override;
// Set the rect of the window containing frame.
// The lefttop of the rect is relative to screen lefttop.
+ // TODO: Known limitation: can't calc client rect and save.
void SetWindowRect(const Rect& rect) override;
+ bool RequestFocus() override;
+
Point GetMousePosition() override;
bool CaptureMouse() override;
@@ -48,8 +59,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
void SetCursor(std::shared_ptr<ICursor> cursor) override;
+ IEvent<std::nullptr_t>* CreateEvent() override { return &create_event_; }
IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; }
IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; }
+ IEvent<WindowVisibilityType>* VisibilityChangeEvent() override {
+ return &visibility_change_event_;
+ }
IEvent<Size>* ResizeEvent() override { return &resize_event_; }
IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; }
IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override {
@@ -103,6 +118,15 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
return result;
}
+ inline RECT DipToPixel(const Rect& dip_rect) {
+ RECT result;
+ result.left = DipToPixel(dip_rect.left);
+ result.top = DipToPixel(dip_rect.top);
+ result.right = DipToPixel(dip_rect.GetRight());
+ result.bottom = DipToPixel(dip_rect.GetBottom());
+ return result;
+ }
+
inline float PixelToDip(const int pixel) {
return static_cast<float>(pixel) * 96.0f / GetDpi();
}
@@ -111,10 +135,18 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
return Point(PixelToDip(pi_point.x), PixelToDip(pi_point.y));
}
+ inline Rect PixelToDip(const RECT& pi_rect) {
+ return Rect::FromVertices(PixelToDip(pi_rect.left), PixelToDip(pi_rect.top),
+ PixelToDip(pi_rect.right),
+ PixelToDip(pi_rect.bottom));
+ }
+
private:
// Get the client rect in pixel.
RECT GetClientRectPixel();
+ void RecreateWindow();
+
//*************** region: native messages ***************
void OnDestroyInternal();
@@ -139,15 +171,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
private:
WinUiApplication* application_;
- // when delete is called first, it set this to true to indicate
- // destroy message handler not to double delete this instance;
- // when destroy handler is called first (by user action or method
- // Close), it set this to true to indicate delete not call Close
- // again.
- bool sync_flag_ = false;
+ WindowStyleFlag style_flag_{};
+ WindowVisibilityType visibility_{};
+ Rect client_rect_;
- HWND hwnd_;
- WinNativeWindow* parent_window_;
+ HWND hwnd_ = nullptr;
+ WinNativeWindow* parent_window_ = nullptr;
float dpi_;
@@ -161,9 +190,11 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
std::unique_ptr<WinInputMethodContext> input_method_context_;
+ Event<std::nullptr_t> create_event_;
Event<std::nullptr_t> destroy_event_;
Event<std::nullptr_t> paint_event_;
Event<Size> resize_event_;
+ Event<WindowVisibilityType> visibility_change_event_;
Event<FocusChangeType> focus_event_;
Event<MouseEnterLeaveType> mouse_enter_leave_event_;
Event<Point> mouse_move_event_;