OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef XFA_FWL_CORE_CFWL_MESSAGE_H_ | 7 #ifndef XFA_FWL_CORE_CFWL_MESSAGE_H_ |
8 #define XFA_FWL_CORE_CFWL_MESSAGE_H_ | 8 #define XFA_FWL_CORE_CFWL_MESSAGE_H_ |
9 | 9 |
10 #include "core/fxcrt/include/fx_string.h" | 10 #include "core/fxcrt/include/fx_string.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 Leave, | 46 Leave, |
47 Hover | 47 Hover |
48 }; | 48 }; |
49 | 49 |
50 enum class FWL_KeyCommand { KeyDown, KeyUp, Char }; | 50 enum class FWL_KeyCommand { KeyDown, KeyUp, Char }; |
51 | 51 |
52 class IFWL_Widget; | 52 class IFWL_Widget; |
53 | 53 |
54 class CFWL_Message { | 54 class CFWL_Message { |
55 public: | 55 public: |
56 CFWL_Message() | 56 CFWL_Message(); |
57 : m_pSrcTarget(nullptr), | 57 virtual ~CFWL_Message(); |
58 m_pDstTarget(nullptr), | |
59 m_dwExtend(0), | |
60 m_dwRefCount(1) {} | |
61 virtual ~CFWL_Message() {} | |
62 | 58 |
63 virtual CFWL_Message* Clone() { return nullptr; } | 59 virtual CFWL_Message* Clone(); |
64 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const { | 60 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const; |
65 return FWL_Error::Succeeded; | 61 virtual CFWL_MessageType GetClassID() const; |
66 } | |
67 virtual CFWL_MessageType GetClassID() const { return CFWL_MessageType::None; } | |
68 | 62 |
69 uint32_t Release() { | 63 uint32_t Release(); |
70 m_dwRefCount--; | 64 CFWL_Message* Retain(); |
71 uint32_t dwRefCount = m_dwRefCount; | |
72 if (!m_dwRefCount) | |
73 delete this; | |
74 return dwRefCount; | |
75 } | |
76 | |
77 CFWL_Message* Retain() { | |
78 m_dwRefCount++; | |
79 return this; | |
80 } | |
81 | 65 |
82 IFWL_Widget* m_pSrcTarget; | 66 IFWL_Widget* m_pSrcTarget; |
83 IFWL_Widget* m_pDstTarget; | 67 IFWL_Widget* m_pDstTarget; |
84 uint32_t m_dwExtend; | 68 uint32_t m_dwExtend; |
85 | 69 |
86 private: | 70 private: |
87 uint32_t m_dwRefCount; | 71 uint32_t m_dwRefCount; |
88 }; | 72 }; |
89 | 73 |
90 #define BEGIN_FWL_MESSAGE_DEF(classname, msgType) \ | 74 inline CFWL_Message::CFWL_Message() |
91 class classname : public CFWL_Message { \ | 75 : m_pSrcTarget(nullptr), |
92 public: \ | 76 m_pDstTarget(nullptr), |
93 classname() : CFWL_Message() {} \ | 77 m_dwExtend(0), |
94 CFWL_Message* Clone() override { return new classname(*this); } \ | 78 m_dwRefCount(1) {} |
95 FWL_Error GetClassName(CFX_WideString& wsClass) const override { \ | |
96 wsClass = L## #classname; \ | |
97 return FWL_Error::Succeeded; \ | |
98 } \ | |
99 CFWL_MessageType GetClassID() const override { return msgType; } | |
100 | 79 |
101 #define END_FWL_MESSAGE_DEF \ | 80 inline CFWL_Message::~CFWL_Message() {} |
102 } \ | |
103 ; // NOLINT | |
104 | 81 |
105 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgActivate, CFWL_MessageType::Activate) | 82 inline CFWL_Message* CFWL_Message::Clone() { |
106 END_FWL_MESSAGE_DEF | 83 return nullptr; |
84 } | |
107 | 85 |
108 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgDeactivate, CFWL_MessageType::Deactivate) | 86 inline FWL_Error CFWL_Message::GetClassName(CFX_WideString& wsClass) const { |
109 END_FWL_MESSAGE_DEF | 87 return FWL_Error::Succeeded; |
88 } | |
110 | 89 |
111 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgMouse, CFWL_MessageType::Mouse) | 90 inline CFWL_MessageType CFWL_Message::GetClassID() const { |
112 FX_FLOAT m_fx; | 91 return CFWL_MessageType::None; |
113 FX_FLOAT m_fy; | 92 } |
114 uint32_t m_dwFlags; | |
115 FWL_MouseCommand m_dwCmd; | |
116 END_FWL_MESSAGE_DEF | |
117 | 93 |
118 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgMouseWheel, CFWL_MessageType::MouseWheel) | 94 inline uint32_t CFWL_Message::Release() { |
119 FX_FLOAT m_fx; | 95 m_dwRefCount--; |
120 FX_FLOAT m_fy; | 96 uint32_t dwRefCount = m_dwRefCount; |
121 FX_FLOAT m_fDeltaX; | 97 if (!m_dwRefCount) |
122 FX_FLOAT m_fDeltaY; | 98 delete this; |
123 uint32_t m_dwFlags; | 99 return dwRefCount; |
124 END_FWL_MESSAGE_DEF | 100 } |
125 | 101 |
126 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgSetFocus, CFWL_MessageType::SetFocus) | 102 inline CFWL_Message* CFWL_Message::Retain() { |
127 IFWL_Widget* m_pKillFocus; | 103 m_dwRefCount++; |
128 END_FWL_MESSAGE_DEF | 104 return this; |
105 } | |
129 | 106 |
130 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgKillFocus, CFWL_MessageType::KillFocus) | 107 #define FWL_MESSAGE_DEF(classname, msgType, ...) \ |
131 IFWL_Widget* m_pSetFocus; | 108 class classname : public CFWL_Message { \ |
132 END_FWL_MESSAGE_DEF | 109 public: \ |
110 classname(); \ | |
111 ~classname() override; \ | |
112 CFWL_Message* Clone() override; \ | |
113 FWL_Error GetClassName(CFX_WideString& wsClass) const override; \ | |
114 CFWL_MessageType GetClassID() const override; \ | |
115 __VA_ARGS__ \ | |
116 }; // NOLINT | |
133 | 117 |
134 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgKey, CFWL_MessageType::Key) | 118 #define FWL_MESSAGE_FUNCTION_DEF(classname, msgType, ...) \ |
dsinclair
2016/06/16 17:35:20
ditto, can they be combined?
Wei Li
2016/06/16 18:16:33
Maybe not, this is to give Macro user the flexibil
dsinclair
2016/06/16 18:21:13
Doh, missed the VA_ARGS used in both macros.
Wei Li
2016/06/17 18:11:18
Found a way to make this better. :) thanks.
| |
135 uint32_t m_dwKeyCode; | 119 inline classname::classname() {} \ |
136 uint32_t m_dwFlags; | 120 inline classname::~classname() {} \ |
137 FWL_KeyCommand m_dwCmd; | 121 inline CFWL_Message* classname::Clone() { return new classname(*this); } \ |
138 END_FWL_MESSAGE_DEF | 122 inline FWL_Error classname::GetClassName(CFX_WideString& wsClass) const { \ |
123 wsClass = L## #classname; \ | |
124 return FWL_Error::Succeeded; \ | |
125 } \ | |
126 inline CFWL_MessageType classname::GetClassID() const { return msgType; } \ | |
127 __VA_ARGS__ | |
139 | 128 |
140 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgCursor, CFWL_MessageType::Cursor) | 129 FWL_MESSAGE_DEF(CFWL_MsgActivate, CFWL_MessageType::Activate) |
141 END_FWL_MESSAGE_DEF | 130 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgActivate, CFWL_MessageType::Activate) |
142 | 131 |
143 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgSize, CFWL_MessageType::Size) | 132 FWL_MESSAGE_DEF(CFWL_MsgDeactivate, CFWL_MessageType::Deactivate) |
144 int32_t m_iWidth; | 133 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgDeactivate, CFWL_MessageType::Deactivate) |
145 int32_t m_iHeight; | |
146 END_FWL_MESSAGE_DEF | |
147 | 134 |
148 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgWindowMove, CFWL_MessageType::WindowMove) | 135 FWL_MESSAGE_DEF(CFWL_MsgMouse, CFWL_MessageType::Mouse, FX_FLOAT m_fx; |
149 FX_FLOAT m_fx; | 136 FX_FLOAT m_fy; |
150 FX_FLOAT m_fy; | 137 uint32_t m_dwFlags; |
151 END_FWL_MESSAGE_DEF | 138 FWL_MouseCommand m_dwCmd;) |
139 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgMouse, CFWL_MessageType::Mouse) | |
152 | 140 |
153 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgDropFiles, CFWL_MessageType::DropFiles) | 141 FWL_MESSAGE_DEF(CFWL_MsgMouseWheel, CFWL_MessageType::MouseWheel, FX_FLOAT m_fx; |
154 CFWL_MsgDropFiles(const CFWL_MsgDropFiles& copy) { | 142 FX_FLOAT m_fy; |
155 m_pDstTarget = copy.m_pDstTarget; | 143 FX_FLOAT m_fDeltaX; |
156 m_pSrcTarget = copy.m_pSrcTarget; | 144 FX_FLOAT m_fDeltaY; |
157 m_fx = copy.m_fx; | 145 uint32_t m_dwFlags;) |
158 m_fy = copy.m_fy; | 146 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgMouseWheel, CFWL_MessageType::MouseWheel) |
159 m_files.Append(copy.m_files); | |
160 } | |
161 FX_FLOAT m_fx; | |
162 FX_FLOAT m_fy; | |
163 CFX_WideStringArray m_files; | |
164 END_FWL_MESSAGE_DEF | |
165 | 147 |
166 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgTaskClicked, CFWL_MessageType::TaskClicked) | 148 FWL_MESSAGE_DEF(CFWL_MsgSetFocus, |
167 FX_FLOAT m_fx; | 149 CFWL_MessageType::SetFocus, |
168 FX_FLOAT m_fy; | 150 IFWL_Widget* m_pKillFocus;) |
169 END_FWL_MESSAGE_DEF | 151 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgSetFocus, CFWL_MessageType::SetFocus) |
170 | 152 |
171 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgClose, CFWL_MessageType::Close) | 153 FWL_MESSAGE_DEF(CFWL_MsgKillFocus, |
172 END_FWL_MESSAGE_DEF | 154 CFWL_MessageType::KillFocus, |
155 IFWL_Widget* m_pSetFocus;) | |
156 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgKillFocus, CFWL_MessageType::KillFocus) | |
173 | 157 |
174 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgWindowWillMove, CFWL_MessageType::WindowWillMove) | 158 FWL_MESSAGE_DEF(CFWL_MsgKey, CFWL_MessageType::Key, uint32_t m_dwKeyCode; |
175 END_FWL_MESSAGE_DEF | 159 uint32_t m_dwFlags; |
160 FWL_KeyCommand m_dwCmd;) | |
161 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgKey, CFWL_MessageType::Key) | |
162 | |
163 FWL_MESSAGE_DEF(CFWL_MsgCursor, CFWL_MessageType::Cursor) | |
164 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgCursor, CFWL_MessageType::Cursor) | |
165 | |
166 FWL_MESSAGE_DEF(CFWL_MsgSize, CFWL_MessageType::Size, int32_t m_iWidth; | |
167 int32_t m_iHeight;) | |
168 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgSize, CFWL_MessageType::Size) | |
169 | |
170 FWL_MESSAGE_DEF(CFWL_MsgWindowMove, CFWL_MessageType::WindowMove, FX_FLOAT m_fx; | |
171 FX_FLOAT m_fy;) | |
172 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgWindowMove, CFWL_MessageType::WindowMove) | |
173 | |
174 FWL_MESSAGE_DEF(CFWL_MsgDropFiles, | |
175 CFWL_MessageType::DropFiles, | |
176 CFWL_MsgDropFiles(const CFWL_MsgDropFiles& copy); | |
177 FX_FLOAT m_fx; | |
178 FX_FLOAT m_fy; | |
179 CFX_WideStringArray m_files;) | |
180 FWL_MESSAGE_FUNCTION_DEF( | |
181 CFWL_MsgDropFiles, | |
182 CFWL_MessageType::DropFiles, | |
183 inline CFWL_MsgDropFiles::CFWL_MsgDropFiles(const CFWL_MsgDropFiles& copy) { | |
184 m_pDstTarget = copy.m_pDstTarget; | |
185 m_pSrcTarget = copy.m_pSrcTarget; | |
186 m_fx = copy.m_fx; | |
187 m_fy = copy.m_fy; | |
188 m_files.Append(copy.m_files); | |
189 }) | |
190 | |
191 FWL_MESSAGE_DEF(CFWL_MsgTaskClicked, | |
192 CFWL_MessageType::TaskClicked, | |
193 FX_FLOAT m_fx; | |
194 FX_FLOAT m_fy;) | |
195 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgTaskClicked, CFWL_MessageType::TaskClicked) | |
196 | |
197 FWL_MESSAGE_DEF(CFWL_MsgClose, CFWL_MessageType::Close) | |
198 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgClose, CFWL_MessageType::Close) | |
199 | |
200 FWL_MESSAGE_DEF(CFWL_MsgWindowWillMove, CFWL_MessageType::WindowWillMove) | |
201 FWL_MESSAGE_FUNCTION_DEF(CFWL_MsgWindowWillMove, | |
202 CFWL_MessageType::WindowWillMove) | |
176 | 203 |
177 #endif // XFA_FWL_CORE_CFWL_MESSAGE_H_ | 204 #endif // XFA_FWL_CORE_CFWL_MESSAGE_H_ |
OLD | NEW |