1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef _FWL_NOTE_H
8 #define _FWL_NOTE_H
9 class IFWL_Target;
10 class IFWL_Widget;
11 class IFWL_NoteThread;
12 class IFWL_ThemeProvider;
13 class CFWL_Note;
14 class CFWL_Message;
15 class CFWL_MsgActivate;
16 class CFWL_MsgDeactivate;
17 class CFWL_MsgMouse;
18 class CFWL_MsgMouseWheel;
19 class CFWL_MsgKey;
20 class CFWL_MsgSetFocus;
21 class CFWL_MsgKillFocus;
22 class CFWL_MsgCursor;
23 class CFWL_MsgSize;
24 class CFWL_MsgWindowMove;
25 class CFWL_MsgDropFiles;
26 class CFWL_MsgTaskClicked;
27 class CFWL_MsgClose;
28 class CFWL_MsgWindowWillMove;
29 class CFWL_Event;
30 class CFWL_EvtMouse;
31 class CFWL_EvtMouseWheel;
32 class CFWL_EvtKey;
33 class CFWL_EvtSetFocus;
34 class CFWL_EvtKillFocus;
35 class CFWL_EvtDraw;
36 class CFWL_EvtClick;
37 class CFWL_EvtScroll;
38 class CFWL_EvtClose;
39 class CFWL_EvtContextMenu;
40 class CFWL_EvtMenuCommand;
41 class CFWL_EvtSizeChanged;
42 class CFWL_EvtIdle;
43 class IFWL_NoteDriver;
44 class IFWL_NoteLoop;
45 #define FWL_MSG_Activate L"FWL_MESSAGE_Activate"
46 #define FWL_MSG_Deactivate L"FWL_MESSAGE_Deactivate"
47 #define FWL_MSG_SetFocus L"FWL_MESSAGE_SetFocus"
48 #define FWL_MSG_KillFocus L"FWL_MESSAGE_KillFocus"
49 #define FWL_MSG_Mouse L"FWL_MESSAGE_Mouse"
50 #define FWL_MSG_MouseWheel L"FWL_MESSAGE_MouseWheel"
51 #define FWL_MSG_Key L"FWL_MESSAGE_Key"
52 #define FWL_MSG_Cursor L"FWL_MESSAGE_Cursor"
53 #define FWL_MSG_Size L"FWL_MESSAGE_Size"
54 #define FWL_MSG_WindowMove L"FWL_MESSAGE_WindowMove"
55 #define FWL_MSG_DropFiles L"FWL_MESSAGE_DropFiles"
56 #define FWL_MSG_TaskClicked L"FWL_MESSAGE_TaskClicked"
57 #define FWL_MSG_Close L"FWL_MESSAGE_Close"
58 #define FWL_MSG_Post L"FWL_MESSAGE_Post"
59 #define FWL_MSG_WindowWillMove L"FWL_MESSAGE_WindowWillMove"
60 #define FWL_MSGHASH_Activate 2410369469
61 #define FWL_MSGHASH_Deactivate 1184214790
62 #define FWL_MSGHASH_SetFocus 4174512504
63 #define FWL_MSGHASH_KillFocus 1557903832
64 #define FWL_MSGHASH_Mouse 706128309
65 #define FWL_MSGHASH_MouseWheel 893703466
66 #define FWL_MSGHASH_Key 3751372405
67 #define FWL_MSGHASH_Cursor 3182626218
68 #define FWL_MSGHASH_Size 160077735
69 #define FWL_MSGHASH_WindowMove 1032269377
70 #define FWL_MSGHASH_DropFiles 2004165236
71 #define FWL_MSGHASH_TaskClicked 3128231086
72 #define FWL_MSGHASH_Close 2977563906
73 #define FWL_MSGHASH_Post 1969633074
74 #define FWL_MSGHASH_WindowWillMove 2229175763
75 #define FWL_EVT_Mouse L"FWL_EVENT_Mouse"
76 #define FWL_EVT_MouseWheel L"FWL_EVENT_MouseWheel"
77 #define FWL_EVT_Key L"FWL_EVENT_Key"
78 #define FWL_EVT_SetFocus L"FWL_EVENT_SetFocus"
79 #define FWL_EVT_KillFocus L"FWL_EVENT_KillFocus"
80 #define FWL_EVT_Click L"FWL_EVENT_Click"
81 #define FWL_EVT_Draw L"FWL_EVENT_Draw"
82 #define FWL_EVT_Scroll L"FWL_EVENT_Scroll"
83 #define FWL_EVT_Close L"FWL_EVENT_Close"
84 #define FWL_EVT_ContextMenu L"FWL_EVENT_ContextMenu"
85 #define FWL_EVT_MenuCommand L"FWL_EVENT_MenuCommand"
86 #define FWL_EVT_SizeChanged L"FWL_EVENT_SizeChanged"
87 #define FWL_EVTHASH_Mouse 1765258002
88 #define FWL_EVTHASH_MouseWheel 3907114407
89 #define FWL_EVTHASH_Key 2408354450
90 #define FWL_EVTHASH_SetFocus 3909721269
91 #define FWL_EVTHASH_KillFocus 1779363253
92 #define FWL_EVTHASH_Draw 2430713303
93 #define FWL_EVTHASH_Click 4026328783
94 #define FWL_EVTHASH_Scroll 2965158968
95 #define FWL_EVTHASH_Close 4036693599
96 #define FWL_EVTHASH_ContextMenu 2717307715
97 #define FWL_EVTHASH_MenuCommand 497763741
98 #define FWL_EVTHASH_SizeChanged 3083958510
99 #define FWL_EVTHASH_Idle 839546759
100 #define FWL_MSGMOUSECMD_LButtonDown 1
101 #define FWL_MSGMOUSECMD_LButtonUp 2
102 #define FWL_MSGMOUSECMD_LButtonDblClk 3
103 #define FWL_MSGMOUSECMD_RButtonDown 4
104 #define FWL_MSGMOUSECMD_RButtonUp 5
105 #define FWL_MSGMOUSECMD_RButtonDblClk 6
106 #define FWL_MSGMOUSECMD_MButtonDown 7
107 #define FWL_MSGMOUSECMD_MButtonUp 8
108 #define FWL_MSGMOUSECMD_MButtonDblClk 9
109 #define FWL_MSGMOUSECMD_MouseMove 10
110 #define FWL_MSGMOUSECMD_MouseEnter 11
111 #define FWL_MSGMOUSECMD_MouseLeave 12
112 #define FWL_MSGMOUSECMD_MouseHover 13
113 #define FWL_MSGKEYCMD_KeyDown 1
114 #define FWL_MSGKEYCMD_KeyUp 2
115 #define FWL_MSGKEYCMD_Char 3
116 #define FWL_KEYFLAG_Ctrl (1 << 0)
117 #define FWL_KEYFLAG_Alt (1 << 1)
118 #define FWL_KEYFLAG_Shift (1 << 2)
119 #define FWL_KEYFLAG_Command (1 << 3)
120 #define FWL_KEYFLAG_LButton (1 << 4)
121 #define FWL_KEYFLAG_RButton (1 << 5)
122 #define FWL_KEYFLAG_MButton (1 << 6)
123
124 // Separate hierarchy not related to IFWL_* hierarchy. These should not
125 // get cast to IFWL_* types.
126 class CFWL_Note {
127 public:
Release()128 virtual FX_DWORD Release() {
129 m_dwRefCount--;
130 FX_DWORD dwRefCount = m_dwRefCount;
131 if (!m_dwRefCount) {
132 delete this;
133 }
134 return dwRefCount;
135 }
Retain()136 virtual CFWL_Note* Retain() {
137 m_dwRefCount++;
138 return this;
139 }
GetClassName(CFX_WideString & wsClass)140 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const {
141 wsClass = L"CFWL_Note";
142 return FWL_ERR_Succeeded;
143 }
GetClassID()144 virtual FX_DWORD GetClassID() const { return 0; }
IsInstance(const CFX_WideStringC & wsClass)145 virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const {
146 return TRUE;
147 }
Clone()148 virtual CFWL_Note* Clone() { return NULL; }
IsEvent()149 FX_BOOL IsEvent() const { return m_bIsEvent; }
150 IFWL_Widget* m_pSrcTarget;
151 IFWL_Widget* m_pDstTarget;
152
153 protected:
CFWL_Note(FX_BOOL bIsEvent)154 CFWL_Note(FX_BOOL bIsEvent)
155 : m_pSrcTarget(NULL),
156 m_pDstTarget(NULL),
157 m_dwRefCount(1),
158 m_bIsEvent(bIsEvent),
159 m_dwExtend(0) {}
~CFWL_Note()160 virtual ~CFWL_Note() {}
Initialize()161 virtual FX_BOOL Initialize() { return TRUE; }
Finalize()162 virtual int32_t Finalize() { return 0; }
163 FX_DWORD m_dwRefCount;
164 FX_BOOL m_bIsEvent;
165
166 public:
167 FX_DWORD m_dwExtend;
168 };
169 class CFWL_Message : public CFWL_Note {
170 public:
CFWL_Message()171 CFWL_Message() : CFWL_Note(FALSE) {}
~CFWL_Message()172 virtual ~CFWL_Message() {}
173 };
174 #define BEGIN_FWL_MESSAGE_DEF(classname, msghashcode) \
175 class classname : public CFWL_Message { \
176 public: \
177 classname() : CFWL_Message() {} \
178 virtual CFWL_Note* Clone() { return new classname(*this); } \
179 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const { \
180 wsClass = L## #classname; \
181 return FWL_ERR_Succeeded; \
182 } \
183 virtual FX_DWORD GetClassID() const { return msghashcode; }
184 #define END_FWL_MESSAGE_DEF \
185 } \
186 ;
187 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgActivate, FWL_MSGHASH_Activate)
188 END_FWL_MESSAGE_DEF
189 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgDeactivate, FWL_MSGHASH_Deactivate)
190 END_FWL_MESSAGE_DEF
191 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgMouse, FWL_MSGHASH_Mouse)
192 FX_FLOAT m_fx;
193 FX_FLOAT m_fy;
194 FX_DWORD m_dwFlags;
195 FX_DWORD m_dwCmd;
196 END_FWL_MESSAGE_DEF
197 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgMouseWheel, FWL_MSGHASH_MouseWheel)
198 FX_FLOAT m_fx;
199 FX_FLOAT m_fy;
200 FX_FLOAT m_fDeltaX;
201 FX_FLOAT m_fDeltaY;
202 FX_DWORD m_dwFlags;
203 END_FWL_MESSAGE_DEF
204 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgSetFocus, FWL_MSGHASH_SetFocus)
205 IFWL_Widget* m_pKillFocus;
206 END_FWL_MESSAGE_DEF
207 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgKillFocus, FWL_MSGHASH_KillFocus)
208 IFWL_Widget* m_pSetFocus;
209 END_FWL_MESSAGE_DEF
210 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgKey, FWL_MSGHASH_Key)
211 FX_DWORD m_dwKeyCode;
212 FX_DWORD m_dwFlags;
213 FX_DWORD m_dwCmd;
214 END_FWL_MESSAGE_DEF
215 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgCursor, FWL_MSGHASH_Cursor)
216 END_FWL_MESSAGE_DEF
217 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgSize, FWL_MSGHASH_Size)
218 int32_t m_iWidth;
219 int32_t m_iHeight;
220 END_FWL_MESSAGE_DEF
BEGIN_FWL_MESSAGE_DEF(CFWL_MsgWindowMove,FWL_MSGHASH_WindowMove)221 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgWindowMove, FWL_MSGHASH_WindowMove)
222 FX_FLOAT m_fx;
223 FX_FLOAT m_fy;
224 END_FWL_MESSAGE_DEF
225 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgDropFiles, FWL_MSGHASH_DropFiles)
226 CFWL_MsgDropFiles(const CFWL_MsgDropFiles& copy) {
227 m_pDstTarget = copy.m_pDstTarget;
228 m_pSrcTarget = copy.m_pSrcTarget;
229 m_fx = copy.m_fx;
230 m_fy = copy.m_fy;
231 m_files.Append(copy.m_files);
232 }
233 FX_FLOAT m_fx;
234 FX_FLOAT m_fy;
235 CFX_WideStringArray m_files;
236 END_FWL_MESSAGE_DEF
BEGIN_FWL_MESSAGE_DEF(CFWL_MsgTaskClicked,FWL_MSGHASH_TaskClicked)237 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgTaskClicked, FWL_MSGHASH_TaskClicked)
238 FX_FLOAT m_fx;
239 FX_FLOAT m_fy;
240 END_FWL_MESSAGE_DEF
241 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgClose, FWL_MSGHASH_Close)
242 END_FWL_MESSAGE_DEF
243 BEGIN_FWL_MESSAGE_DEF(CFWL_MsgWindowWillMove, FWL_MSGHASH_WindowWillMove)
244 END_FWL_MESSAGE_DEF
245 class CFWL_Event : public CFWL_Note {
246 public:
247 CFWL_Event() : CFWL_Note(TRUE) {}
248 virtual ~CFWL_Event() {}
249 };
250 #define BEGIN_FWL_EVENT_DEF(classname, eventhashcode) \
251 class classname : public CFWL_Event { \
252 public: \
253 classname() : CFWL_Event() {} \
254 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const { \
255 wsClass = L## #classname; \
256 return FWL_ERR_Succeeded; \
257 } \
258 virtual FX_DWORD GetClassID() const { return eventhashcode; }
259 #define END_FWL_EVENT_DEF \
260 } \
261 ;
262 BEGIN_FWL_EVENT_DEF(CFWL_EvtMouse, FWL_EVTHASH_Mouse)
263 FX_FLOAT m_fx;
264 FX_FLOAT m_fy;
265 FX_DWORD m_dwFlags;
266 FX_DWORD m_dwCmd;
267 END_FWL_EVENT_DEF
268 BEGIN_FWL_EVENT_DEF(CFWL_EvtMouseWheel, FWL_EVTHASH_MouseWheel)
269 FX_FLOAT m_fx;
270 FX_FLOAT m_fy;
271 FX_FLOAT m_fDeltaX;
272 FX_FLOAT m_fDeltaY;
273 FX_DWORD m_dwFlags;
274 END_FWL_EVENT_DEF
275 BEGIN_FWL_EVENT_DEF(CFWL_EvtKey, FWL_EVTHASH_Key)
276 FX_DWORD m_dwKeyCode;
277 FX_DWORD m_dwFlags;
278 FX_DWORD m_dwCmd;
279 END_FWL_EVENT_DEF
280 BEGIN_FWL_EVENT_DEF(CFWL_EvtSetFocus, FWL_EVTHASH_SetFocus)
281 IFWL_Widget* m_pSetFocus;
282 END_FWL_EVENT_DEF
283 BEGIN_FWL_EVENT_DEF(CFWL_EvtKillFocus, FWL_EVTHASH_KillFocus)
284 IFWL_Widget* m_pKillFocus;
285 END_FWL_EVENT_DEF
286 BEGIN_FWL_EVENT_DEF(CFWL_EvtDraw, FWL_EVTHASH_Draw)
287 CFX_Graphics* m_pGraphics;
288 IFWL_Widget* m_pWidget;
289 END_FWL_EVENT_DEF
290 BEGIN_FWL_EVENT_DEF(CFWL_EvtClick, FWL_EVTHASH_Click)
291 END_FWL_EVENT_DEF
292 BEGIN_FWL_EVENT_DEF(CFWL_EvtScroll, FWL_EVTHASH_Scroll)
293 FX_DWORD m_iScrollCode;
294 FX_FLOAT m_fPos;
295 FX_BOOL* m_pRet;
296 END_FWL_EVENT_DEF
297 BEGIN_FWL_EVENT_DEF(CFWL_EvtClose, FWL_EVTHASH_Close)
298 END_FWL_EVENT_DEF
299 BEGIN_FWL_EVENT_DEF(CFWL_EvtContextMenu, FWL_EVTHASH_ContextMenu)
300 FX_FLOAT m_fPosX;
301 FX_FLOAT m_fPosY;
302 IFWL_Widget* m_pOwner;
303 END_FWL_EVENT_DEF
304 BEGIN_FWL_EVENT_DEF(CFWL_EvtMenuCommand, FWL_EVTHASH_MenuCommand)
305 int32_t m_iCommand;
306 void* m_pData;
307 END_FWL_EVENT_DEF
308 BEGIN_FWL_EVENT_DEF(CFWL_EvtSizeChanged, FWL_EVTHASH_SizeChanged)
309 IFWL_Widget* m_pWidget;
310 CFX_RectF m_rtOld;
311 CFX_RectF m_rtNew;
312 END_FWL_MESSAGE_DEF
313 BEGIN_FWL_EVENT_DEF(CFWL_EvtIdle, FWL_EVTHASH_Idle)
314 END_FWL_EVENT_DEF
315 typedef enum {
316 FWL_EVENT_MOUSE_MASK = 1 << 0,
317 FWL_EVENT_MOUSEWHEEL_MASK = 1 << 1,
318 FWL_EVENT_KEY_MASK = 1 << 2,
319 FWL_EVENT_FOCUSCHANGED_MASK = 1 << 3,
320 FWL_EVENT_DRAW_MASK = 1 << 4,
321 FWL_EVENT_CLOSE_MASK = 1 << 5,
322 FWL_EVENT_SIZECHANGED_MASK = 1 << 6,
323 FWL_EVENT_IDLE_MASK = 1 << 7,
324 FWL_EVENT_CONTROL_MASK = 1 << 8,
325 FWL_EVENT_ALL_MASK = 0xFF
326 } FWLEventMask;
327 class IFWL_NoteDriver {
328 public:
~IFWL_NoteDriver()329 virtual ~IFWL_NoteDriver() {}
330 virtual FX_BOOL SendNote(CFWL_Note* pNote) = 0;
331 virtual FX_BOOL PostMessage(CFWL_Message* pMessage) = 0;
332 virtual FWL_ERR RegisterEventTarget(
333 IFWL_Widget* pListener,
334 IFWL_Widget* pEventSource = NULL,
335 FX_DWORD dwFilter = FWL_EVENT_ALL_MASK) = 0;
336 virtual FWL_ERR UnregisterEventTarget(IFWL_Widget* pListener) = 0;
337 virtual void ClearEventTargets(FX_BOOL bRemoveAll) = 0;
338 virtual int32_t GetQueueMaxSize() const = 0;
339 virtual FWL_ERR SetQueueMaxSize(const int32_t size) = 0;
340 virtual IFWL_NoteThread* GetOwnerThread() const = 0;
341 virtual FWL_ERR PushNoteLoop(IFWL_NoteLoop* pNoteLoop) = 0;
342 virtual IFWL_NoteLoop* PopNoteLoop() = 0;
343 virtual IFWL_Widget* GetFocus() = 0;
344 virtual FX_BOOL SetFocus(IFWL_Widget* pFocus, FX_BOOL bNotify = FALSE) = 0;
345 virtual void SetGrab(IFWL_Widget* pGrab, FX_BOOL bSet) = 0;
346 virtual FWL_ERR Run() = 0;
347 };
348 IFWL_Widget* FWL_GetCurrentThreadModalWidget(IFWL_NoteThread* pNoteThread);
349 class IFWL_NoteLoop {
350 public:
~IFWL_NoteLoop()351 virtual ~IFWL_NoteLoop() {}
352 virtual FX_BOOL PreProcessMessage(CFWL_Message* pMessage) = 0;
353 virtual FWL_ERR Idle(int32_t count) = 0;
354 };
355 class IFWL_ToolTipTarget {
356 public:
~IFWL_ToolTipTarget()357 virtual ~IFWL_ToolTipTarget() {}
358 virtual IFWL_Widget* GetWidget() = 0;
359 virtual FX_BOOL IsShowed() = 0;
360 virtual FWL_ERR DrawToolTip(CFX_Graphics* pGraphics,
361 const CFX_Matrix* pMatrix,
362 IFWL_Widget* pToolTip) = 0;
363 virtual FX_BOOL UseDefaultTheme() = 0;
364 virtual FWL_ERR GetCaption(CFX_WideString& wsCaption) = 0;
365 virtual FWL_ERR GetToolTipSize(CFX_SizeF& sz) = 0;
GetToolTipPos(CFX_PointF & pt)366 virtual FWL_ERR GetToolTipPos(CFX_PointF& pt) { return FWL_ERR_Indefinite; }
367 };
368 FWL_ERR FWL_AddToolTipTarget(IFWL_ToolTipTarget* pTarget);
369 FWL_ERR FWL_RemoveToolTipTarget(IFWL_ToolTipTarget* pTarget);
370 FWL_ERR FWL_SetToolTipInitialDelay(int32_t iDelayTime);
371 FWL_ERR FWL_SetToolTipAutoPopDelay(int32_t iDelayTime);
372 typedef FX_BOOL (*FWLMessageHookCallback)(CFWL_Message* msg, void* info);
373 FWL_ERR FWL_SetHook(IFWL_NoteDriver* driver,
374 FWLMessageHookCallback callback,
375 void* info);
376 #endif
377