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_EVENT_H_ | 7 #ifndef XFA_FWL_CORE_CFWL_EVENT_H_ |
8 #define XFA_FWL_CORE_CFWL_EVENT_H_ | 8 #define XFA_FWL_CORE_CFWL_EVENT_H_ |
9 | 9 |
10 #include "core/fxcrt/include/fx_coordinates.h" | 10 #include "core/fxcrt/include/fx_coordinates.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 FWL_EVENT_IDLE_MASK = 1 << 7, | 59 FWL_EVENT_IDLE_MASK = 1 << 7, |
60 FWL_EVENT_CONTROL_MASK = 1 << 8, | 60 FWL_EVENT_CONTROL_MASK = 1 << 8, |
61 FWL_EVENT_ALL_MASK = 0xFF | 61 FWL_EVENT_ALL_MASK = 0xFF |
62 }; | 62 }; |
63 | 63 |
64 class CFX_Graphics; | 64 class CFX_Graphics; |
65 class IFWL_Widget; | 65 class IFWL_Widget; |
66 | 66 |
67 class CFWL_Event { | 67 class CFWL_Event { |
68 public: | 68 public: |
69 CFWL_Event() | 69 CFWL_Event(); |
70 : m_pSrcTarget(nullptr), m_pDstTarget(nullptr), m_dwRefCount(1) {} | 70 virtual ~CFWL_Event(); |
71 virtual ~CFWL_Event() {} | |
72 | 71 |
73 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const { | 72 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const; |
74 return FWL_Error::Succeeded; | 73 virtual CFWL_EventType GetClassID() const; |
75 } | |
76 virtual CFWL_EventType GetClassID() const { return CFWL_EventType::None; } | |
77 | 74 |
78 uint32_t Release() { | 75 uint32_t Release(); |
79 m_dwRefCount--; | |
80 uint32_t dwRefCount = m_dwRefCount; | |
81 if (!m_dwRefCount) | |
82 delete this; | |
83 return dwRefCount; | |
84 } | |
85 | 76 |
86 IFWL_Widget* m_pSrcTarget; | 77 IFWL_Widget* m_pSrcTarget; |
87 IFWL_Widget* m_pDstTarget; | 78 IFWL_Widget* m_pDstTarget; |
88 | 79 |
89 private: | 80 private: |
90 uint32_t m_dwRefCount; | 81 uint32_t m_dwRefCount; |
91 }; | 82 }; |
92 | 83 |
93 #define BEGIN_FWL_EVENT_DEF(classname, eventType) \ | 84 inline CFWL_Event::CFWL_Event() |
85 : m_pSrcTarget(nullptr), m_pDstTarget(nullptr), m_dwRefCount(1) {} | |
86 | |
87 inline CFWL_Event::~CFWL_Event() {} | |
88 | |
89 inline FWL_Error CFWL_Event::GetClassName(CFX_WideString& wsClass) const { | |
90 return FWL_Error::Succeeded; | |
91 } | |
92 | |
93 inline CFWL_EventType CFWL_Event::GetClassID() const { | |
94 return CFWL_EventType::None; | |
95 } | |
96 | |
97 inline uint32_t CFWL_Event::Release() { | |
98 m_dwRefCount--; | |
99 uint32_t dwRefCount = m_dwRefCount; | |
100 if (!m_dwRefCount) | |
101 delete this; | |
102 return dwRefCount; | |
103 } | |
104 | |
105 #define FWL_EVENT_DEF(classname, eventType, ...) \ | |
94 class classname : public CFWL_Event { \ | 106 class classname : public CFWL_Event { \ |
95 public: \ | 107 public: \ |
96 classname() : CFWL_Event() {} \ | 108 classname(); \ |
97 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const { \ | 109 ~classname() override; \ |
98 wsClass = L## #classname; \ | 110 FWL_Error GetClassName(CFX_WideString& wsClass) const override; \ |
99 return FWL_Error::Succeeded; \ | 111 CFWL_EventType GetClassID() const override; \ |
100 } \ | 112 __VA_ARGS__ \ |
dsinclair
2016/06/16 17:35:19
That's frighteningly awesome.
Wei Li
2016/06/16 18:16:33
thanks :)
| |
101 virtual CFWL_EventType GetClassID() const { return eventType; } | 113 }; // NOLINT |
dsinclair
2016/06/16 17:35:20
Does this need a nolint? It was there before becau
Wei Li
2016/06/16 18:16:33
Done.
| |
102 | 114 |
103 #define END_FWL_EVENT_DEF \ | 115 #define FWL_EVENT_FUNCTION_DEF(classname, eventType) \ |
dsinclair
2016/06/16 17:35:19
Do we ever doe the above without doing this macro?
Wei Li
2016/06/16 18:16:33
This is the price we have to pay for using clang_u
dsinclair
2016/06/16 18:21:13
Right, but could the macro be:
#define FWL_EVENT_
Wei Li
2016/06/17 18:11:18
oh, since customized function implementation is no
| |
104 } \ | 116 inline classname::classname() {} \ |
105 ; // NOLINT | 117 inline classname::~classname() {} \ |
118 inline FWL_Error classname::GetClassName(CFX_WideString& wsClass) const { \ | |
119 wsClass = L## #classname; \ | |
120 return FWL_Error::Succeeded; \ | |
121 } \ | |
122 inline CFWL_EventType classname::GetClassID() const { return eventType; } | |
106 | 123 |
107 BEGIN_FWL_EVENT_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse) | 124 FWL_EVENT_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse, FX_FLOAT m_fx; |
108 FX_FLOAT m_fx; | 125 FX_FLOAT m_fy; |
109 FX_FLOAT m_fy; | 126 uint32_t m_dwFlags; |
110 uint32_t m_dwFlags; | 127 FWL_MouseCommand m_dwCmd;) |
111 FWL_MouseCommand m_dwCmd; | 128 FWL_EVENT_FUNCTION_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse) |
112 END_FWL_EVENT_DEF | |
113 | 129 |
114 BEGIN_FWL_EVENT_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel) | 130 FWL_EVENT_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel, FX_FLOAT m_fx; |
115 FX_FLOAT m_fx; | 131 FX_FLOAT m_fy; |
116 FX_FLOAT m_fy; | 132 FX_FLOAT m_fDeltaX; |
117 FX_FLOAT m_fDeltaX; | 133 FX_FLOAT m_fDeltaY; |
118 FX_FLOAT m_fDeltaY; | 134 uint32_t m_dwFlags;) |
119 uint32_t m_dwFlags; | 135 FWL_EVENT_FUNCTION_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel) |
120 END_FWL_EVENT_DEF | |
121 | 136 |
122 BEGIN_FWL_EVENT_DEF(CFWL_EvtKey, CFWL_EventType::Key) | 137 FWL_EVENT_DEF(CFWL_EvtKey, CFWL_EventType::Key, uint32_t m_dwKeyCode; |
123 uint32_t m_dwKeyCode; | 138 uint32_t m_dwFlags; |
124 uint32_t m_dwFlags; | 139 FWL_KeyCommand m_dwCmd;) |
125 FWL_KeyCommand m_dwCmd; | 140 FWL_EVENT_FUNCTION_DEF(CFWL_EvtKey, CFWL_EventType::Key) |
126 END_FWL_EVENT_DEF | |
127 | 141 |
128 BEGIN_FWL_EVENT_DEF(CFWL_EvtSetFocus, CFWL_EventType::SetFocus) | 142 FWL_EVENT_DEF(CFWL_EvtSetFocus, |
129 IFWL_Widget* m_pSetFocus; | 143 CFWL_EventType::SetFocus, |
130 END_FWL_EVENT_DEF | 144 IFWL_Widget* m_pSetFocus;) |
145 FWL_EVENT_FUNCTION_DEF(CFWL_EvtSetFocus, CFWL_EventType::SetFocus) | |
131 | 146 |
132 BEGIN_FWL_EVENT_DEF(CFWL_EvtKillFocus, CFWL_EventType::KillFocus) | 147 FWL_EVENT_DEF(CFWL_EvtKillFocus, |
133 IFWL_Widget* m_pKillFocus; | 148 CFWL_EventType::KillFocus, |
134 END_FWL_EVENT_DEF | 149 IFWL_Widget* m_pKillFocus;) |
150 FWL_EVENT_FUNCTION_DEF(CFWL_EvtKillFocus, CFWL_EventType::KillFocus) | |
135 | 151 |
136 BEGIN_FWL_EVENT_DEF(CFWL_EvtDraw, CFWL_EventType::Draw) | 152 FWL_EVENT_DEF(CFWL_EvtDraw, CFWL_EventType::Draw, CFX_Graphics* m_pGraphics; |
137 CFX_Graphics* m_pGraphics; | 153 IFWL_Widget * m_pWidget;) |
138 IFWL_Widget* m_pWidget; | 154 FWL_EVENT_FUNCTION_DEF(CFWL_EvtDraw, CFWL_EventType::Draw) |
139 END_FWL_EVENT_DEF | |
140 | 155 |
141 BEGIN_FWL_EVENT_DEF(CFWL_EvtClick, CFWL_EventType::Click) | 156 FWL_EVENT_DEF(CFWL_EvtClick, CFWL_EventType::Click) |
142 END_FWL_EVENT_DEF | 157 FWL_EVENT_FUNCTION_DEF(CFWL_EvtClick, CFWL_EventType::Click) |
143 | 158 |
144 BEGIN_FWL_EVENT_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll) | 159 FWL_EVENT_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll, uint32_t m_iScrollCode; |
145 uint32_t m_iScrollCode; | 160 FX_FLOAT m_fPos; |
146 FX_FLOAT m_fPos; | 161 FX_BOOL * m_pRet;) |
147 FX_BOOL* m_pRet; | 162 FWL_EVENT_FUNCTION_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll) |
148 END_FWL_EVENT_DEF | |
149 | 163 |
150 BEGIN_FWL_EVENT_DEF(CFWL_EvtClose, CFWL_EventType::Close) | 164 FWL_EVENT_DEF(CFWL_EvtClose, CFWL_EventType::Close) |
151 END_FWL_EVENT_DEF | 165 FWL_EVENT_FUNCTION_DEF(CFWL_EvtClose, CFWL_EventType::Close) |
152 | 166 |
153 BEGIN_FWL_EVENT_DEF(CFWL_EvtContextMenu, CFWL_EventType::ContextMenu) | 167 FWL_EVENT_DEF(CFWL_EvtContextMenu, |
154 FX_FLOAT m_fPosX; | 168 CFWL_EventType::ContextMenu, |
155 FX_FLOAT m_fPosY; | 169 FX_FLOAT m_fPosX; |
156 IFWL_Widget* m_pOwner; | 170 FX_FLOAT m_fPosY; |
157 END_FWL_EVENT_DEF | 171 IFWL_Widget * m_pOwner;) |
172 FWL_EVENT_FUNCTION_DEF(CFWL_EvtContextMenu, CFWL_EventType::ContextMenu) | |
158 | 173 |
159 BEGIN_FWL_EVENT_DEF(CFWL_EvtMenuCommand, CFWL_EventType::MenuCommand) | 174 FWL_EVENT_DEF(CFWL_EvtMenuCommand, |
160 int32_t m_iCommand; | 175 CFWL_EventType::MenuCommand, |
161 void* m_pData; | 176 int32_t m_iCommand; |
162 END_FWL_EVENT_DEF | 177 void* m_pData;) |
178 FWL_EVENT_FUNCTION_DEF(CFWL_EvtMenuCommand, CFWL_EventType::MenuCommand) | |
163 | 179 |
164 BEGIN_FWL_EVENT_DEF(CFWL_EvtSizeChanged, CFWL_EventType::SizeChanged) | 180 FWL_EVENT_DEF(CFWL_EvtSizeChanged, |
165 IFWL_Widget* m_pWidget; | 181 CFWL_EventType::SizeChanged, |
166 CFX_RectF m_rtOld; | 182 IFWL_Widget* m_pWidget; |
167 CFX_RectF m_rtNew; | 183 CFX_RectF m_rtOld; |
168 END_FWL_EVENT_DEF | 184 CFX_RectF m_rtNew;) |
185 FWL_EVENT_FUNCTION_DEF(CFWL_EvtSizeChanged, CFWL_EventType::SizeChanged) | |
169 | 186 |
170 BEGIN_FWL_EVENT_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) | 187 FWL_EVENT_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) |
171 END_FWL_EVENT_DEF | 188 FWL_EVENT_FUNCTION_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) |
172 | 189 |
173 #endif // XFA_FWL_CORE_CFWL_EVENT_H_ | 190 #endif // XFA_FWL_CORE_CFWL_EVENT_H_ |
OLD | NEW |