1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#pragma once
#include "../win_pre_config.hpp"
#include "cru/platform/native/native_window.hpp"
#include "window_native_message_event_args.hpp"
#include <memory>
namespace cru::win::native {
class WinApplication;
class WindowClass;
class WindowManager;
class WindowRenderTarget;
class WinNativeWindow : public Object,
public virtual platform::native::NativeWindow {
public:
WinNativeWindow(WinApplication* application,
std::shared_ptr<WindowClass> window_class, DWORD window_style,
WinNativeWindow* parent);
WinNativeWindow(const WinNativeWindow& other) = delete;
WinNativeWindow(WinNativeWindow&& other) = delete;
WinNativeWindow& operator=(const WinNativeWindow& other) = delete;
WinNativeWindow& operator=(WinNativeWindow&& other) = delete;
~WinNativeWindow() override;
bool IsValid() override;
void SetDeleteThisOnDestroy(bool value) override;
void Close() override;
NativeWindow* GetParent() override { return parent_window_; }
bool IsVisible() override;
void SetVisible(bool is_visible) override;
ui::Size GetClientSize() override;
void SetClientSize(const ui::Size& size) override;
// Get the rect of the window containing frame.
// The lefttop of the rect is relative to screen lefttop.
ui::Rect GetWindowRect() override;
// Set the rect of the window containing frame.
// The lefttop of the rect is relative to screen lefttop.
void SetWindowRect(const ui::Rect& rect) override;
platform::graph::Painter* BeginPaint() override;
Event<>* DestroyEvent() override { return &destroy_event_; }
Event<const ui::Size&>* ResizeEvent() override { return &resize_event_; }
Event<>* PaintEvent() override { return &paint_event_; }
Event<bool>* FocusEvent() override { return &focus_event_; }
Event<bool>* MouseEnterLeaveEvent() override {
return &mouse_enter_leave_event_;
}
Event<const ui::Point&>* MouseMoveEvent() override {
return &mouse_move_event_;
}
Event<platform::native::MouseButton, const ui::Point&>* MouseDownEvent()
override {
return &mouse_down_event_;
}
Event<platform::native::MouseButton, const ui::Point&>* MouseUpEvent()
override {
return &mouse_up_event_;
}
Event<int>* KeyDownEvent() override { return &key_down_event_; }
Event<int>* KeyUpEvent() override { return &key_up_event_; }
Event<WindowNativeMessageEventArgs&>* NativeMessageEvent() {
return &native_message_event_;
}
// Get the handle of the window. Return null if window is invalid.
HWND GetWindowHandle() const { return hwnd_; }
bool HandleNativeWindowMessage(HWND hwnd, UINT msg, WPARAM w_param,
LPARAM l_param, LRESULT* result);
WindowRenderTarget* GetWindowRenderTarget() const {
return window_render_target_.get();
}
private:
// Get the client rect in pixel.
RECT GetClientRectPixel();
//*************** region: native messages ***************
void OnDestroyInternal();
void OnPaintInternal();
void OnResizeInternal(int new_width, int new_height);
void OnSetFocusInternal();
void OnKillFocusInternal();
void OnMouseMoveInternal(POINT point);
void OnMouseLeaveInternal();
void OnMouseDownInternal(platform::native::MouseButton button, POINT point);
void OnMouseUpInternal(platform::native::MouseButton button, POINT point);
void OnMouseWheelInternal(short delta, POINT point);
void OnKeyDownInternal(int virtual_code);
void OnKeyUpInternal(int virtual_code);
void OnCharInternal(wchar_t c);
void OnActivatedInternal();
void OnDeactivatedInternal();
private:
WinApplication* application_;
bool delete_this_on_destroy_ = true;
HWND hwnd_;
WinNativeWindow* parent_window_;
bool has_focus_ = false;
bool is_mouse_in_ = false;
std::shared_ptr<WindowRenderTarget> window_render_target_;
Event<> destroy_event_;
Event<const ui::Size&> resize_event_;
Event<> paint_event_;
Event<bool> focus_event_;
Event<bool> mouse_enter_leave_event_;
Event<const ui::Point&> mouse_move_event_;
Event<platform::native::MouseButton, const ui::Point&> mouse_down_event_;
Event<platform::native::MouseButton, const ui::Point&> mouse_up_event_;
Event<int> key_down_event_;
Event<int> key_up_event_;
Event<WindowNativeMessageEventArgs&> native_message_event_;
};
} // namespace cru::win::native
|