• 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 _FSDK_ANNOTHANDLER_H_
8 #define _FSDK_ANNOTHANDLER_H_
9 
10 
11 class CPDFDoc_Environment;
12 class CFFL_IFormFiller;
13 class CPDFSDK_PageView;
14 class IPDFSDK_AnnotHandler
15 {
16 
17 public:
~IPDFSDK_AnnotHandler()18 	virtual ~IPDFSDK_AnnotHandler() {};
19 
20 	virtual CFX_ByteString		GetType() = 0;
21 
22 	virtual CFX_ByteString		GetName() = 0;
23 
24 	virtual FX_BOOL				CanAnswer(CPDFSDK_Annot* pAnnot) = 0;
25 
26 
27 	virtual CPDFSDK_Annot*		NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) = 0;
28 
29 	virtual void				ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0;
30 
31 	virtual void				DeleteAnnot(CPDFSDK_Annot* pAnnot) = 0;
32 
33 
34 	virtual CPDF_Rect				GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) = 0;
35 
36 	virtual FX_BOOL				HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) = 0;
37 
38 
39 	virtual void				OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
40 		CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
41 		FX_DWORD dwFlags) = 0;
42 
43 	virtual void				OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
44 		CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
45 		const CPDF_Rect& rcWindow, FX_DWORD dwFlags) = 0;
46 
47 
48 
49 
50 	virtual void				OnCreate(CPDFSDK_Annot* pAnnot) = 0;
51 
52 	virtual void				OnLoad(CPDFSDK_Annot* pAnnot) = 0;
53 
54 	virtual void				OnDelete(CPDFSDK_Annot* pAnnot) = 0;
55 
56 	virtual void				OnRelease(CPDFSDK_Annot* pAnnot) = 0;
57 
58 
59 	virtual void				OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
60 	virtual void				OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
61 
62 
63 	virtual FX_BOOL				OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
64 	virtual FX_BOOL				OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
65 	virtual FX_BOOL				OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
66 	virtual FX_BOOL				OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
67 	virtual FX_BOOL				OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) = 0;
68 	virtual FX_BOOL				OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
69 	virtual FX_BOOL				OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
70 	virtual FX_BOOL				OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
71 //by wjm.
72 	virtual FX_BOOL				OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) = 0;
73 	virtual FX_BOOL				OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) = 0;
74 	virtual FX_BOOL				OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) =0 ;
75 
76 	virtual	void				OnDeSelected(CPDFSDK_Annot* pAnnot) = 0;
77 	virtual	void				OnSelected(CPDFSDK_Annot* pAnnot) = 0;
78 
79 	virtual FX_BOOL				OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
80 	virtual FX_BOOL				OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
81 
82 };
83 
84 
85 class CPDFSDK_BFAnnotHandler:public IPDFSDK_AnnotHandler
86 {
87 public:
CPDFSDK_BFAnnotHandler(CPDFDoc_Environment * pApp)88 	CPDFSDK_BFAnnotHandler(CPDFDoc_Environment*	pApp):m_pFormFiller(NULL),m_pApp(pApp) {}
~CPDFSDK_BFAnnotHandler()89 	virtual	~CPDFSDK_BFAnnotHandler() {}
90 public:
91 
GetType()92 	virtual CFX_ByteString		GetType()  {return CFX_ByteString("Widget");}
93 
GetName()94 	virtual CFX_ByteString		GetName()  {return CFX_ByteString("WidgetHandler");}
95 
96 	virtual FX_BOOL				CanAnswer(CPDFSDK_Annot* pAnnot);
97 
98 	virtual CPDFSDK_Annot*		NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage);
99 
100 	virtual void				ReleaseAnnot(CPDFSDK_Annot* pAnnot)  ;
101 
DeleteAnnot(CPDFSDK_Annot * pAnnot)102 	virtual void				DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
103 
104 
105 	virtual CPDF_Rect				GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) ;
106 
107 	virtual FX_BOOL				HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);
108 
109 
110 	virtual void				OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
111 		CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
112 		 FX_DWORD dwFlags) ;
113 
OnDrawSleep(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,CFX_RenderDevice * pDevice,CPDF_Matrix * pUser2Device,const CPDF_Rect & rcWindow,FX_DWORD dwFlags)114 	virtual void				OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot,
115 		CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
116 		const CPDF_Rect& rcWindow, FX_DWORD dwFlags) {}
117 
118 
119 	virtual void				OnCreate(CPDFSDK_Annot* pAnnot) ;
120 
121 	virtual void				OnLoad(CPDFSDK_Annot* pAnnot) ;
122 
OnDelete(CPDFSDK_Annot * pAnnot)123 	virtual void				OnDelete(CPDFSDK_Annot* pAnnot) {}
124 
OnRelease(CPDFSDK_Annot * pAnnot)125 	virtual void				OnRelease(CPDFSDK_Annot* pAnnot) {}
126 
127 
128 	virtual void				OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;
129 	virtual void				OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;
130 
131 
132 	virtual FX_BOOL				OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
133 	virtual FX_BOOL				OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
134 	virtual FX_BOOL				OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
135 	virtual FX_BOOL				OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
136 	virtual FX_BOOL				OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) ;
137 	virtual FX_BOOL				OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
138 	virtual FX_BOOL				OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
OnRButtonDblClk(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,FX_DWORD nFlags,const CPDF_Point & point)139 	virtual FX_BOOL				OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) {return FALSE;}
140 
141 //by wjm.
142 	virtual FX_BOOL				OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);
143 	virtual FX_BOOL				OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
144 	virtual FX_BOOL				OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
145 
OnDeSelected(CPDFSDK_Annot * pAnnot)146 	virtual	void				OnDeSelected(CPDFSDK_Annot* pAnnot) {}
OnSelected(CPDFSDK_Annot * pAnnot)147 	virtual	void				OnSelected(CPDFSDK_Annot* pAnnot) {}
148 
149 	virtual FX_BOOL				OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
150 	virtual FX_BOOL				OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
151 
SetFormFiller(CFFL_IFormFiller * pFiller)152 	void						SetFormFiller(CFFL_IFormFiller* pFiller){m_pFormFiller = pFiller;}
GetFormFiller()153 	CFFL_IFormFiller*			GetFormFiller() {return m_pFormFiller;}
154 private:
155 
156 	CPDFDoc_Environment*		m_pApp;
157 	CFFL_IFormFiller*			m_pFormFiller;
158 };
159 
160 #define CBA_AnnotHandlerArray CFX_ArrayTemplate<IPDFSDK_AnnotHandler*>
161 class CPDFSDK_AnnotHandlerMgr
162 {
163 public:
164 	// Destroy the handler
165 	CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp);
166 	virtual ~CPDFSDK_AnnotHandlerMgr() ;
167 
168 public:
169 	void						RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
170 	void						UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
171 
172 	virtual CPDFSDK_Annot*		NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView);
173 	virtual void				ReleaseAnnot(CPDFSDK_Annot * pAnnot);
174 
175 	virtual void				Annot_OnCreate(CPDFSDK_Annot* pAnnot);
176 	virtual void				Annot_OnLoad(CPDFSDK_Annot* pAnnot);
177 public:
178 	IPDFSDK_AnnotHandler*		GetAnnotHandler(CPDFSDK_Annot* pAnnot) const;
179 	virtual void				Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot,
180 		CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags);
181 
182 	virtual void				Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);
183 	virtual void				Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);
184 
185 	virtual FX_BOOL				Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
186 	virtual FX_BOOL				Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
187 	virtual FX_BOOL				Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
188 
189 	virtual FX_BOOL				Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
190 	virtual FX_BOOL				Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point);
191 	virtual FX_BOOL				Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
192 	virtual FX_BOOL				Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
193 
194 
195 	virtual FX_BOOL				Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);
196 	virtual FX_BOOL				Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
197 	virtual FX_BOOL				Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
198 
199 	virtual FX_BOOL				Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
200 	virtual FX_BOOL				Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
201 
202 	virtual CPDF_Rect			Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot);
203 	virtual FX_BOOL				Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);
204 
205 private:
206 	IPDFSDK_AnnotHandler*			GetAnnotHandler(const CFX_ByteString& sType) const;
207 	CPDFSDK_Annot*				GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext);
208 private:
209 	CBA_AnnotHandlerArray		m_Handlers;
210 	CFX_MapByteStringToPtr		m_mapType2Handler;
211 	CPDFDoc_Environment*		m_pApp;
212 };
213 
214 //#define CBF_Page2Accessible	 CFX_MapPtrTemplate<CPDFSDK_PageView*, IAccessible*>
215 
216 typedef int (*AI_COMPARE) (CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
217 
218 class CPDFSDK_AnnotIterator
219 {
220 protected:
221 	CPDFSDK_Annot*	NextAnnot (const CPDFSDK_Annot* pCurrent) ;
222 	CPDFSDK_Annot*	PrevAnnot (const CPDFSDK_Annot* pCurrent) ;
223 	CPDFSDK_Annot*	NextAnnot(int& index ) ;
224 	CPDFSDK_Annot*	PrevAnnot(int& index ) ;
225 public:
226     CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView, FX_BOOL bReverse,
227 		FX_BOOL bIgnoreTopmost=FALSE,FX_BOOL bCircle=FALSE,CFX_PtrArray* pList=NULL);
228 	virtual CPDFSDK_Annot*	Next (const CPDFSDK_Annot* pCurrent) ;
229 	virtual CPDFSDK_Annot*	Prev (const CPDFSDK_Annot* pCurrent) ;
230 	virtual CPDFSDK_Annot*	Next(int& index ) ;
231 	virtual CPDFSDK_Annot*	Prev(int& index ) ;
Count()232 	virtual int             Count(){return m_pIteratorAnnotList.GetSize();}
233 
234 	virtual FX_BOOL         InitIteratorAnnotList(CPDFSDK_PageView * pPageView,CFX_PtrArray* pList=NULL);
235 
236 	void					InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare);
237 protected:
238 	//	CFX_PtrList			 m_pIteratorAnnotList;
239 	CFX_PtrArray	     m_pIteratorAnnotList;
240 	FX_BOOL			     m_bReverse;
241 	FX_BOOL              m_bIgnoreTopmost;
242 	FX_BOOL              m_bCircle;
243 };
244 
245 
246 
247 #endif
248 
249