OLD | NEW |
| (Empty) |
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 FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ | |
8 #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ | |
9 | |
10 #include <vector> | |
11 | |
12 #include "core/fxcrt/include/fx_basic.h" | |
13 #include "core/include/fpdfdoc/fpdf_doc.h" | |
14 #include "fpdfsdk/include/fx_systemhandler.h" | |
15 | |
16 class CPWL_MsgControl; | |
17 class CPWL_ScrollBar; | |
18 class CPWL_Timer; | |
19 class CPWL_TimerHandler; | |
20 class CPWL_Wnd; | |
21 class IFX_Edit_FontMap; | |
22 class IFX_SystemHandler; | |
23 class IPWL_Provider; | |
24 class IPWL_SpellCheck; | |
25 | |
26 // window styles | |
27 #define PWS_CHILD 0x80000000L | |
28 #define PWS_BORDER 0x40000000L | |
29 #define PWS_BACKGROUND 0x20000000L | |
30 #define PWS_HSCROLL 0x10000000L | |
31 #define PWS_VSCROLL 0x08000000L | |
32 #define PWS_VISIBLE 0x04000000L | |
33 #define PWS_DISABLE 0x02000000L | |
34 #define PWS_READONLY 0x01000000L | |
35 #define PWS_AUTOFONTSIZE 0x00800000L | |
36 #define PWS_AUTOTRANSPARENT 0x00400000L | |
37 #define PWS_NOREFRESHCLIP 0x00200000L | |
38 | |
39 // edit and label styles | |
40 #define PES_MULTILINE 0x0001L | |
41 #define PES_PASSWORD 0x0002L | |
42 #define PES_LEFT 0x0004L | |
43 #define PES_RIGHT 0x0008L | |
44 #define PES_MIDDLE 0x0010L | |
45 #define PES_TOP 0x0020L | |
46 #define PES_BOTTOM 0x0040L | |
47 #define PES_CENTER 0x0080L | |
48 #define PES_CHARARRAY 0x0100L | |
49 #define PES_AUTOSCROLL 0x0200L | |
50 #define PES_AUTORETURN 0x0400L | |
51 #define PES_UNDO 0x0800L | |
52 #define PES_RICH 0x1000L | |
53 #define PES_SPELLCHECK 0x2000L | |
54 #define PES_TEXTOVERFLOW 0x4000L | |
55 #define PES_NOREAD 0x8000L | |
56 | |
57 // listbox styles | |
58 #define PLBS_MULTIPLESEL 0x0001L | |
59 #define PLBS_HOVERSEL 0x0008L | |
60 | |
61 // combobox styles | |
62 #define PCBS_ALLOWCUSTOMTEXT 0x0001L | |
63 | |
64 // richedit styles | |
65 #define PRES_MULTILINE 0x0001L | |
66 #define PRES_AUTORETURN 0x0002L | |
67 #define PRES_AUTOSCROLL 0x0004L | |
68 #define PRES_SPELLCHECK 0x0008L | |
69 #define PRES_UNDO 0x0100L | |
70 #define PRES_MULTIPAGES 0x0200L | |
71 #define PRES_TEXTOVERFLOW 0x0400L | |
72 | |
73 // border style | |
74 #define PBS_SOLID 0 | |
75 #define PBS_DASH 1 | |
76 #define PBS_BEVELED 2 | |
77 #define PBS_INSET 3 | |
78 #define PBS_UNDERLINED 4 | |
79 #define PBS_SHADOW 5 | |
80 | |
81 // notification messages | |
82 #define PNM_ADDCHILD 0x00000000L | |
83 #define PNM_REMOVECHILD 0x00000001L | |
84 #define PNM_SETSCROLLINFO 0x00000002L | |
85 #define PNM_SETSCROLLPOS 0x00000003L | |
86 #define PNM_SCROLLWINDOW 0x00000004L | |
87 #define PNM_LBUTTONDOWN 0x00000005L | |
88 #define PNM_LBUTTONUP 0x00000006L | |
89 #define PNM_MOUSEMOVE 0x00000007L | |
90 #define PNM_NOTERESET 0x00000008L | |
91 #define PNM_SETCARETINFO 0x00000009L | |
92 #define PNM_SELCHANGED 0x0000000AL | |
93 #define PNM_NOTEEDITCHANGED 0x0000000BL | |
94 | |
95 #define PWL_CLASSNAME_EDIT "CPWL_Edit" | |
96 | |
97 struct CPWL_Dash { | |
98 CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) | |
99 : nDash(dash), nGap(gap), nPhase(phase) {} | |
100 | |
101 int32_t nDash; | |
102 int32_t nGap; | |
103 int32_t nPhase; | |
104 }; | |
105 | |
106 struct CPWL_Color { | |
107 CPWL_Color(int32_t type = COLORTYPE_TRANSPARENT, | |
108 FX_FLOAT color1 = 0.0f, | |
109 FX_FLOAT color2 = 0.0f, | |
110 FX_FLOAT color3 = 0.0f, | |
111 FX_FLOAT color4 = 0.0f) | |
112 : nColorType(type), | |
113 fColor1(color1), | |
114 fColor2(color2), | |
115 fColor3(color3), | |
116 fColor4(color4) {} | |
117 | |
118 CPWL_Color(int32_t r, int32_t g, int32_t b) | |
119 : nColorType(COLORTYPE_RGB), | |
120 fColor1(r / 255.0f), | |
121 fColor2(g / 255.0f), | |
122 fColor3(b / 255.0f), | |
123 fColor4(0) {} | |
124 | |
125 void ConvertColorType(int32_t other_nColorType); | |
126 | |
127 /* | |
128 COLORTYPE_TRANSPARENT | |
129 COLORTYPE_RGB | |
130 COLORTYPE_CMYK | |
131 COLORTYPE_GRAY | |
132 */ | |
133 int32_t nColorType; | |
134 FX_FLOAT fColor1, fColor2, fColor3, fColor4; | |
135 }; | |
136 | |
137 inline bool operator==(const CPWL_Color& c1, const CPWL_Color& c2) { | |
138 return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 && | |
139 c1.fColor1 - c2.fColor1 > -0.0001 && | |
140 c1.fColor2 - c2.fColor2 < 0.0001 && | |
141 c1.fColor2 - c2.fColor2 > -0.0001 && | |
142 c1.fColor3 - c2.fColor3 < 0.0001 && | |
143 c1.fColor3 - c2.fColor3 > -0.0001 && | |
144 c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001; | |
145 } | |
146 | |
147 inline bool operator!=(const CPWL_Color& c1, const CPWL_Color& c2) { | |
148 return !(c1 == c2); | |
149 } | |
150 | |
151 #define PWL_SCROLLBAR_WIDTH 12.0f | |
152 #define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f | |
153 #define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f | |
154 #define PWL_SCROLLBAR_TRANSPARANCY 150 | |
155 #define PWL_SCROLLBAR_BKCOLOR \ | |
156 CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f) | |
157 #define PWL_DEFAULT_SELTEXTCOLOR CPWL_Color(COLORTYPE_RGB, 1, 1, 1) | |
158 #define PWL_DEFAULT_SELBACKCOLOR \ | |
159 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) | |
160 #define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR | |
161 #define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB, 0, 0, 0) | |
162 #define PWL_DEFAULT_FONTSIZE 9.0f | |
163 #define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY, 0) | |
164 #define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY, 1) | |
165 #define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.50) | |
166 #define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.75) | |
167 #define PWL_TRIANGLE_HALFLEN 2.0f | |
168 #define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f | |
169 #define PWL_INVALIDATE_INFLATE 2 | |
170 | |
171 class IPWL_SpellCheck { | |
172 public: | |
173 virtual ~IPWL_SpellCheck() {} | |
174 virtual FX_BOOL CheckWord(const FX_CHAR* sWord) = 0; | |
175 virtual void SuggestWords(const FX_CHAR* sWord, | |
176 std::vector<CFX_ByteString>& sSuggest) = 0; | |
177 }; | |
178 | |
179 class IPWL_Provider { | |
180 public: | |
181 virtual ~IPWL_Provider() {} | |
182 | |
183 // get a matrix which map user space to CWnd client space | |
184 virtual CFX_Matrix GetWindowMatrix(void* pAttachedData) = 0; | |
185 | |
186 /* | |
187 0 L"&Undo\tCtrl+Z" | |
188 1 L"&Redo\tCtrl+Shift+Z" | |
189 2 L"Cu&t\tCtrl+X" | |
190 3 L"&Copy\tCtrl+C" | |
191 4 L"&Paste\tCtrl+V" | |
192 5 L"&Delete" | |
193 6 L"&Select All\tCtrl+A" | |
194 */ | |
195 virtual CFX_WideString LoadPopupMenuString(int32_t nIndex) = 0; | |
196 }; | |
197 | |
198 class IPWL_FocusHandler { | |
199 public: | |
200 virtual ~IPWL_FocusHandler() {} | |
201 virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; | |
202 virtual void OnKillFocus(CPWL_Wnd* pWnd) = 0; | |
203 }; | |
204 | |
205 struct PWL_CREATEPARAM { | |
206 public: | |
207 PWL_CREATEPARAM() | |
208 : rcRectWnd(0, 0, 0, 0), | |
209 pSystemHandler(NULL), | |
210 pFontMap(NULL), | |
211 pProvider(NULL), | |
212 pFocusHandler(NULL), | |
213 dwFlags(0), | |
214 sBackgroundColor(), | |
215 hAttachedWnd(NULL), | |
216 pSpellCheck(NULL), | |
217 nBorderStyle(PBS_SOLID), | |
218 dwBorderWidth(1), | |
219 sBorderColor(), | |
220 sTextColor(), | |
221 sTextStrokeColor(), | |
222 nTransparency(255), | |
223 fFontSize(PWL_DEFAULT_FONTSIZE), | |
224 sDash(3, 0, 0), | |
225 pAttachedData(NULL), | |
226 pParentWnd(NULL), | |
227 pMsgControl(NULL), | |
228 eCursorType(FXCT_ARROW), | |
229 mtChild(1, 0, 0, 1, 0, 0) {} | |
230 | |
231 CFX_FloatRect rcRectWnd; // required | |
232 IFX_SystemHandler* pSystemHandler; // required | |
233 IFX_Edit_FontMap* pFontMap; // required for text window | |
234 IPWL_Provider* pProvider; // required for self coordinate | |
235 IPWL_FocusHandler* pFocusHandler; // optional | |
236 FX_DWORD dwFlags; // optional | |
237 CPWL_Color sBackgroundColor; // optional | |
238 FX_HWND hAttachedWnd; // required for no-reader framework | |
239 IPWL_SpellCheck* pSpellCheck; // required for spellchecking | |
240 int32_t nBorderStyle; // optional | |
241 int32_t dwBorderWidth; // optional | |
242 CPWL_Color sBorderColor; // optional | |
243 CPWL_Color sTextColor; // optional | |
244 CPWL_Color sTextStrokeColor; // optional | |
245 int32_t nTransparency; // optional | |
246 FX_FLOAT fFontSize; // optional | |
247 CPWL_Dash sDash; // optional | |
248 void* pAttachedData; // optional | |
249 CPWL_Wnd* pParentWnd; // ignore | |
250 CPWL_MsgControl* pMsgControl; // ignore | |
251 int32_t eCursorType; // ignore | |
252 CFX_Matrix mtChild; // ignore | |
253 }; | |
254 | |
255 class CPWL_Timer { | |
256 public: | |
257 CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler); | |
258 virtual ~CPWL_Timer(); | |
259 | |
260 int32_t SetPWLTimer(int32_t nElapse); | |
261 void KillPWLTimer(); | |
262 static void TimerProc(int32_t idEvent); | |
263 | |
264 private: | |
265 int32_t m_nTimerID; | |
266 CPWL_TimerHandler* m_pAttached; | |
267 IFX_SystemHandler* m_pSystemHandler; | |
268 }; | |
269 | |
270 class CPWL_TimerHandler { | |
271 public: | |
272 CPWL_TimerHandler(); | |
273 virtual ~CPWL_TimerHandler(); | |
274 | |
275 void BeginTimer(int32_t nElapse); | |
276 void EndTimer(); | |
277 virtual void TimerProc(); | |
278 virtual IFX_SystemHandler* GetSystemHandler() const = 0; | |
279 | |
280 private: | |
281 CPWL_Timer* m_pTimer; | |
282 }; | |
283 | |
284 class CPWL_Wnd : public CPWL_TimerHandler { | |
285 friend class CPWL_MsgControl; | |
286 | |
287 public: | |
288 CPWL_Wnd(); | |
289 ~CPWL_Wnd() override; | |
290 | |
291 void Create(const PWL_CREATEPARAM& cp); | |
292 virtual CFX_ByteString GetClassName() const; | |
293 void InvalidateFocusHandler(IPWL_FocusHandler* handler); | |
294 void InvalidateProvider(IPWL_Provider* provider); | |
295 void Destroy(); | |
296 void Move(const CFX_FloatRect& rcNew, FX_BOOL bReset, FX_BOOL bRefresh); | |
297 virtual void InvalidateRect(CFX_FloatRect* pRect = NULL); | |
298 | |
299 void DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); | |
300 | |
301 virtual FX_BOOL OnKeyDown(uint16_t nChar, FX_DWORD nFlag); | |
302 virtual FX_BOOL OnKeyUp(uint16_t nChar, FX_DWORD nFlag); | |
303 virtual FX_BOOL OnChar(uint16_t nChar, FX_DWORD nFlag); | |
304 virtual FX_BOOL OnLButtonDblClk(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
305 virtual FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
306 virtual FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
307 virtual FX_BOOL OnMButtonDblClk(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
308 virtual FX_BOOL OnMButtonDown(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
309 virtual FX_BOOL OnMButtonUp(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
310 virtual FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
311 virtual FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
312 virtual FX_BOOL OnMouseMove(const CFX_FloatPoint& point, FX_DWORD nFlag); | |
313 virtual FX_BOOL OnMouseWheel(short zDelta, | |
314 const CFX_FloatPoint& point, | |
315 FX_DWORD nFlag); | |
316 | |
317 virtual void SetFocus(); | |
318 virtual void KillFocus(); | |
319 void SetCapture(); | |
320 void ReleaseCapture(); | |
321 | |
322 virtual void OnNotify(CPWL_Wnd* pWnd, | |
323 FX_DWORD msg, | |
324 intptr_t wParam = 0, | |
325 intptr_t lParam = 0); | |
326 virtual void SetTextColor(const CPWL_Color& color); | |
327 virtual void SetTextStrokeColor(const CPWL_Color& color); | |
328 virtual void SetVisible(FX_BOOL bVisible); | |
329 | |
330 virtual CFX_FloatRect GetFocusRect() const; | |
331 virtual CPWL_Color GetBackgroundColor() const; | |
332 virtual CPWL_Color GetBorderColor() const; | |
333 virtual CPWL_Color GetTextColor() const; | |
334 virtual CPWL_Color GetTextStrokeColor() const; | |
335 virtual FX_FLOAT GetFontSize() const; | |
336 virtual int32_t GetInnerBorderWidth() const; | |
337 virtual CPWL_Color GetBorderLeftTopColor(int32_t nBorderStyle) const; | |
338 virtual CPWL_Color GetBorderRightBottomColor(int32_t nBorderStyle) const; | |
339 | |
340 virtual void SetFontSize(FX_FLOAT fFontSize); | |
341 | |
342 void SetBackgroundColor(const CPWL_Color& color); | |
343 void SetClipRect(const CFX_FloatRect& rect); | |
344 void SetBorderStyle(int32_t eBorderStyle); | |
345 | |
346 virtual CFX_FloatRect GetWindowRect() const; | |
347 virtual CFX_FloatRect GetClientRect() const; | |
348 CFX_FloatPoint GetCenterPoint() const; | |
349 int32_t GetBorderWidth() const; | |
350 FX_BOOL IsVisible() const { return m_bVisible; } | |
351 FX_BOOL HasFlag(FX_DWORD dwFlags) const; | |
352 void AddFlag(FX_DWORD dwFlags); | |
353 void RemoveFlag(FX_DWORD dwFlags); | |
354 const CFX_FloatRect& GetClipRect() const; | |
355 CPWL_Wnd* GetParentWindow() const; | |
356 int32_t GetBorderStyle() const; | |
357 const CPWL_Dash& GetBorderDash() const; | |
358 void* GetAttachedData() const; | |
359 | |
360 FX_BOOL WndHitTest(const CFX_FloatPoint& point) const; | |
361 FX_BOOL ClientHitTest(const CFX_FloatPoint& point) const; | |
362 FX_BOOL IsCaptureMouse() const; | |
363 | |
364 const CPWL_Wnd* GetFocused() const; | |
365 FX_BOOL IsFocused() const; | |
366 FX_BOOL IsReadOnly() const; | |
367 CPWL_ScrollBar* GetVScrollBar() const; | |
368 | |
369 IFX_Edit_FontMap* GetFontMap() const; | |
370 IPWL_Provider* GetProvider() const; | |
371 IPWL_FocusHandler* GetFocusHandler() const; | |
372 | |
373 int32_t GetTransparency(); | |
374 void SetTransparency(int32_t nTransparency); | |
375 | |
376 CFX_Matrix GetChildToRoot() const; | |
377 CFX_Matrix GetChildMatrix() const; | |
378 void SetChildMatrix(const CFX_Matrix& mt); | |
379 CFX_Matrix GetWindowMatrix() const; | |
380 | |
381 virtual CFX_FloatPoint ChildToParent(const CFX_FloatPoint& point) const; | |
382 virtual CFX_FloatRect ChildToParent(const CFX_FloatRect& rect) const; | |
383 virtual CFX_FloatPoint ParentToChild(const CFX_FloatPoint& point) const; | |
384 virtual CFX_FloatRect ParentToChild(const CFX_FloatRect& rect) const; | |
385 | |
386 // those methods only implemented by listctrl item | |
387 virtual FX_FLOAT GetItemHeight(FX_FLOAT fLimitWidth) { return 0; } | |
388 virtual FX_FLOAT GetItemLeftMargin() { return 0; } | |
389 virtual FX_FLOAT GetItemRightMargin() { return 0; } | |
390 | |
391 void EnableWindow(FX_BOOL bEnable); | |
392 FX_BOOL IsEnabled(); | |
393 virtual void SetCursor(); | |
394 | |
395 protected: | |
396 // CPWL_TimerHandler | |
397 IFX_SystemHandler* GetSystemHandler() const override; | |
398 | |
399 virtual void CreateChildWnd(const PWL_CREATEPARAM& cp); | |
400 virtual void RePosChildWnd(); | |
401 void GetAppearanceStream(CFX_ByteTextBuf& sAppStream); | |
402 virtual void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream); | |
403 virtual void GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream); | |
404 | |
405 virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, | |
406 CFX_Matrix* pUser2Device); | |
407 virtual void DrawChildAppearance(CFX_RenderDevice* pDevice, | |
408 CFX_Matrix* pUser2Device); | |
409 | |
410 virtual void OnCreate(PWL_CREATEPARAM& cp); | |
411 virtual void OnCreated(); | |
412 virtual void OnDestroy(); | |
413 | |
414 virtual void OnSetFocus(); | |
415 virtual void OnKillFocus(); | |
416 | |
417 virtual void OnEnabled(); | |
418 virtual void OnDisabled(); | |
419 | |
420 void SetNotifyFlag(FX_BOOL bNotifying = TRUE) { m_bNotifying = bNotifying; } | |
421 | |
422 FX_BOOL IsValid() const; | |
423 const PWL_CREATEPARAM& GetCreationParam() const; | |
424 FX_BOOL IsNotifying() const { return m_bNotifying; } | |
425 | |
426 void InvalidateRectMove(const CFX_FloatRect& rcOld, | |
427 const CFX_FloatRect& rcNew); | |
428 | |
429 void PWLtoWnd(const CFX_FloatPoint& point, int32_t& x, int32_t& y) const; | |
430 FX_RECT PWLtoWnd(const CFX_FloatRect& rect) const; | |
431 FX_HWND GetAttachedHWnd() const; | |
432 | |
433 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const; | |
434 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const; | |
435 const CPWL_Wnd* GetRootWnd() const; | |
436 | |
437 FX_BOOL IsCTRLpressed(FX_DWORD nFlag) const; | |
438 FX_BOOL IsSHIFTpressed(FX_DWORD nFlag) const; | |
439 FX_BOOL IsALTpressed(FX_DWORD nFlag) const; | |
440 FX_BOOL IsINSERTpressed(FX_DWORD nFlag) const; | |
441 | |
442 private: | |
443 void AddChild(CPWL_Wnd* pWnd); | |
444 void RemoveChild(CPWL_Wnd* pWnd); | |
445 | |
446 void CreateScrollBar(const PWL_CREATEPARAM& cp); | |
447 void CreateVScrollBar(const PWL_CREATEPARAM& cp); | |
448 | |
449 void AdjustStyle(); | |
450 void CreateMsgControl(); | |
451 void DestroyMsgControl(); | |
452 | |
453 CPWL_MsgControl* GetMsgControl() const; | |
454 | |
455 protected: | |
456 CFX_ArrayTemplate<CPWL_Wnd*> m_aChildren; | |
457 | |
458 private: | |
459 PWL_CREATEPARAM m_sPrivateParam; | |
460 | |
461 CPWL_ScrollBar* m_pVScrollBar; | |
462 | |
463 CFX_FloatRect m_rcWindow; | |
464 CFX_FloatRect m_rcClip; | |
465 | |
466 FX_BOOL m_bCreated; | |
467 FX_BOOL m_bVisible; | |
468 FX_BOOL m_bNotifying; | |
469 FX_BOOL m_bEnabled; | |
470 }; | |
471 | |
472 #endif // FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_ | |
OLD | NEW |