blob: 00e15084bd2957e0460517b28840934d0b039ff1 (
plain)
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
|
#pragma once
#include "cru/platform/gui/osx/Window.h"
#include "cru/common/Event.h"
#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/Window.h"
#include "cru/platform/gui/osx/Cursor.h"
#import <AppKit/AppKit.h>
@interface CruWindowDelegate : NSObject <NSWindowDelegate>
- (id)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p;
@end
@interface CruWindow : NSWindow
- (instancetype)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p
contentRect:(NSRect)contentRect
style:(NSWindowStyleMask)style;
@end
@interface CruView : NSView <NSTextInputClient>
- (instancetype)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p
input_context_p:
(cru::platform::gui::osx::details::OsxInputMethodContextPrivate*)input_context_p
frame:(cru::platform::Rect)frame;
@end
namespace cru::platform::gui::osx {
namespace details {
class OsxInputMethodContextPrivate;
class OsxWindowPrivate {
friend OsxWindow;
friend OsxInputMethodContextPrivate;
public:
explicit OsxWindowPrivate(OsxWindow* osx_window);
CRU_DELETE_COPY(OsxWindowPrivate)
CRU_DELETE_MOVE(OsxWindowPrivate)
~OsxWindowPrivate();
public:
void OnMouseEnterLeave(MouseEnterLeaveType type);
void OnMouseMove(Point p);
void OnMouseDown(MouseButton button, Point p, KeyModifier key_modifier);
void OnMouseUp(MouseButton button, Point p, KeyModifier key_modifier);
void OnMouseWheel(float delta, Point p, KeyModifier key_modifier, bool horizontal);
void OnKeyDown(KeyCode key, KeyModifier key_modifier);
void OnKeyUp(KeyCode key, KeyModifier key_modifier);
void OnWindowWillClose();
void OnWindowDidExpose();
void OnWindowDidUpdate();
void OnWindowDidMove();
void OnWindowDidResize();
void OnBecomeKeyWindow();
void OnResignKeyWindow();
CGLayerRef GetDrawLayer() { return draw_layer_; }
OsxWindow* GetWindow() { return osx_window_; }
NSWindow* GetNSWindow() { return window_; }
Size GetScreenSize();
private:
void CreateWindow();
void UpdateCursor();
Point TransformMousePoint(const Point& point);
CGLayerRef CreateLayer(const CGSize& size);
Rect RetrieveContentRect();
private:
OsxWindow* osx_window_;
INativeWindow* parent_ = nullptr;
WindowStyleFlag style_flag_ = WindowStyleFlag{};
String title_;
Rect content_rect_;
NSWindow* window_ = nil;
CruWindowDelegate* window_delegate_ = nil;
CGLayerRef draw_layer_ = nullptr;
bool mouse_in_ = false;
std::shared_ptr<OsxCursor> cursor_ = nullptr;
std::unique_ptr<OsxInputMethodContext> input_method_context_;
TimerAutoCanceler draw_timer_;
Event<std::nullptr_t> create_event_;
Event<std::nullptr_t> destroy_event_;
Event<std::nullptr_t> paint_event_;
Event<WindowVisibilityType> visibility_change_event_;
Event<Size> resize_event_;
Event<FocusChangeType> focus_event_;
Event<MouseEnterLeaveType> mouse_enter_leave_event_;
Event<Point> mouse_move_event_;
Event<NativeMouseButtonEventArgs> mouse_down_event_;
Event<NativeMouseButtonEventArgs> mouse_up_event_;
Event<NativeMouseWheelEventArgs> mouse_wheel_event_;
Event<NativeKeyEventArgs> key_down_event_;
Event<NativeKeyEventArgs> key_up_event_;
};
} // namespace details
} // namespace cru::platform::gui::osx
|