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