6f2b71b04575ce0f83853c11afa9035220e292d1
[pdfium.git] / fpdfsdk / include / fsdk_annothandler.h
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 #define FSDK_XFAWIDGET_TYPENAME "XFAWidget"
11
12 class CPDFDoc_Environment;
13 class CFFL_IFormFiller;
14 class CPDFSDK_PageView;
15 class IPDFSDK_AnnotHandler
16 {
17
18 public:
19         virtual ~IPDFSDK_AnnotHandler() {};
20
21         virtual CFX_ByteString          GetType() = 0;
22
23         virtual CFX_ByteString          GetName() = 0;
24
25         virtual FX_BOOL                         CanAnswer(CPDFSDK_Annot* pAnnot) = 0;
26         
27
28         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) = 0;
29
30         virtual CPDFSDK_Annot*          NewAnnot(XFA_HWIDGET hWidget, CPDFSDK_PageView* pPage) = 0;
31
32         virtual void                            ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0;
33
34         virtual void                            DeleteAnnot(CPDFSDK_Annot* pAnnot) = 0;
35         
36
37         virtual CPDF_Rect                               GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) = 0;
38         
39         virtual FX_BOOL                         HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) = 0;
40         
41
42         virtual void                            OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
43                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
44                 FX_DWORD dwFlags) = 0;
45         
46         virtual void                            OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
47                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
48                 const CPDF_Rect& rcWindow, FX_DWORD dwFlags) = 0;
49         
50
51         
52
53         virtual void                            OnCreate(CPDFSDK_Annot* pAnnot) = 0;
54
55         virtual void                            OnLoad(CPDFSDK_Annot* pAnnot) = 0;
56
57         virtual void                            OnDelete(CPDFSDK_Annot* pAnnot) = 0;
58
59         virtual void                            OnRelease(CPDFSDK_Annot* pAnnot) = 0;
60         
61
62         virtual void                            OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
63         virtual void                            OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
64         
65
66         virtual FX_BOOL                         OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
67         virtual FX_BOOL                         OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
68         virtual FX_BOOL                         OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
69         virtual FX_BOOL                         OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
70         virtual FX_BOOL                         OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) = 0;
71         virtual FX_BOOL                         OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
72         virtual FX_BOOL                         OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
73         virtual FX_BOOL                         OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;
74 //by wjm.
75         virtual FX_BOOL                         OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) = 0;
76         virtual FX_BOOL                         OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) = 0;
77         virtual FX_BOOL                         OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) =0 ;
78
79         virtual void                            OnDeSelected(CPDFSDK_Annot* pAnnot) = 0;
80         virtual void                            OnSelected(CPDFSDK_Annot* pAnnot) = 0;
81
82         virtual FX_BOOL                         OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
83         virtual FX_BOOL                         OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
84         virtual FX_BOOL                         OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot) = 0;
85
86 };
87
88
89 class CPDFSDK_BFAnnotHandler:public IPDFSDK_AnnotHandler
90 {
91 public:
92         CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pFormFiller(NULL) {}
93         virtual ~CPDFSDK_BFAnnotHandler() {}
94 public:
95
96         virtual CFX_ByteString          GetType()  {return CFX_ByteString("Widget");}
97
98         virtual CFX_ByteString          GetName()  {return CFX_ByteString("WidgetHandler");}
99         
100         virtual FX_BOOL                         CanAnswer(CPDFSDK_Annot* pAnnot);
101
102         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage);
103
104         virtual CPDFSDK_Annot*          NewAnnot(XFA_HWIDGET hWidget, CPDFSDK_PageView* pPage);
105
106         virtual void                            ReleaseAnnot(CPDFSDK_Annot* pAnnot)  ;
107
108         virtual void                            DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
109         
110
111         virtual CPDF_Rect                               GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) ;
112         
113         virtual FX_BOOL                         HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);
114         
115
116         virtual void                            OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
117                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
118                  FX_DWORD dwFlags) ;
119         
120         virtual void                            OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
121                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
122                 const CPDF_Rect& rcWindow, FX_DWORD dwFlags) {}
123         
124
125         virtual void                            OnCreate(CPDFSDK_Annot* pAnnot) ;
126
127         virtual void                            OnLoad(CPDFSDK_Annot* pAnnot) ;
128
129         virtual void                            OnDelete(CPDFSDK_Annot* pAnnot) {}
130
131         virtual void                            OnRelease(CPDFSDK_Annot* pAnnot) {}
132         
133
134         virtual void                            OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;
135         virtual void                            OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;
136         
137
138         virtual FX_BOOL                         OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
139         virtual FX_BOOL                         OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
140         virtual FX_BOOL                         OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
141         virtual FX_BOOL                         OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
142         virtual FX_BOOL                         OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) ;
143         virtual FX_BOOL                         OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
144         virtual FX_BOOL                         OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
145         virtual FX_BOOL                         OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) {return FALSE;}
146         
147 //by wjm.
148         virtual FX_BOOL                         OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);
149         virtual FX_BOOL                         OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
150         virtual FX_BOOL                         OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
151
152         virtual void                            OnDeSelected(CPDFSDK_Annot* pAnnot) {}
153         virtual void                            OnSelected(CPDFSDK_Annot* pAnnot) {}
154
155         virtual FX_BOOL                         OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
156         virtual FX_BOOL                         OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
157         virtual FX_BOOL                         OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot){ return TRUE; }
158
159         void                                            SetFormFiller(CFFL_IFormFiller* pFiller){m_pFormFiller = pFiller;}
160         CFFL_IFormFiller*                       GetFormFiller() {return m_pFormFiller;}
161 private:
162
163         CPDFDoc_Environment*            m_pApp;
164         CFFL_IFormFiller*                       m_pFormFiller;
165 };
166
167 class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler
168 {
169 public:
170         CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp);
171         ~CPDFSDK_XFAAnnotHandler(){}
172
173 public:
174         virtual CFX_ByteString          GetType() { return FSDK_XFAWIDGET_TYPENAME; }
175
176         virtual CFX_ByteString          GetName() { return "XFAWidgetHandler"; }
177
178         virtual FX_BOOL                         CanAnswer(CPDFSDK_Annot* pAnnot);
179
180
181         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) { return NULL; }
182
183         virtual CPDFSDK_Annot*          NewAnnot(XFA_HWIDGET pAnnot, CPDFSDK_PageView* pPage);
184
185         virtual void                            ReleaseAnnot(CPDFSDK_Annot* pAnnot);
186
187         virtual void                            DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
188
189
190         virtual CPDF_Rect                               GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot);
191
192         virtual FX_BOOL                         HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);
193
194
195         virtual void                            OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
196                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
197                 FX_DWORD dwFlags);
198
199         virtual void                            OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, 
200                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
201                 const CPDF_Rect& rcWindow, FX_DWORD dwFlags) {}
202
203
204
205
206         virtual void                            OnCreate(CPDFSDK_Annot* pAnnot) {}
207
208         virtual void                            OnLoad(CPDFSDK_Annot* pAnnot) {}
209
210         virtual void                            OnDelete(CPDFSDK_Annot* pAnnot) {}
211
212         virtual void                            OnRelease(CPDFSDK_Annot* pAnnot) {}
213
214
215         virtual void                            OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
216         virtual void                            OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
217
218
219         virtual FX_BOOL                         OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
220         virtual FX_BOOL                         OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
221         virtual FX_BOOL                         OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
222         virtual FX_BOOL                         OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
223         virtual FX_BOOL                         OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) ;
224         virtual FX_BOOL                         OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
225         virtual FX_BOOL                         OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
226         virtual FX_BOOL                         OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;
227         //by wjm.
228         virtual FX_BOOL                         OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);
229         virtual FX_BOOL                         OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
230         virtual FX_BOOL                         OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
231
232         virtual void                            OnDeSelected(CPDFSDK_Annot* pAnnot) {}
233         virtual void                            OnSelected(CPDFSDK_Annot* pAnnot) {}
234
235         virtual FX_BOOL                         OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
236         virtual FX_BOOL                         OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;
237         virtual FX_BOOL                         OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot);
238
239 private:
240         IXFA_WidgetHandler*                     GetXFAWidgetHandler(CPDFSDK_Annot* pAnnot);
241         FX_DWORD                                        GetFWLFlags(FX_DWORD dwFlag);
242
243 private:
244         CPDFDoc_Environment*            m_pApp;
245 };
246
247 #define CBA_AnnotHandlerArray CFX_ArrayTemplate<IPDFSDK_AnnotHandler*>
248 class CPDFSDK_AnnotHandlerMgr
249 {
250 public:
251         // Destroy the handler
252         CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp);
253         virtual ~CPDFSDK_AnnotHandlerMgr() ;
254
255 public:
256         void                                            RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
257         void                                            UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
258
259         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView);
260         virtual CPDFSDK_Annot*          NewAnnot(XFA_HWIDGET pAnnot, CPDFSDK_PageView* pPageView);
261         virtual void                            ReleaseAnnot(CPDFSDK_Annot * pAnnot);
262         
263         virtual void                            Annot_OnCreate(CPDFSDK_Annot* pAnnot);
264         virtual void                            Annot_OnLoad(CPDFSDK_Annot* pAnnot);
265 public:
266         IPDFSDK_AnnotHandler*           GetAnnotHandler(CPDFSDK_Annot* pAnnot) const;
267         virtual void                            Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot,
268                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags);
269
270         virtual void                            Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);
271         virtual void                            Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);
272
273         virtual FX_BOOL                         Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
274         virtual FX_BOOL                         Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
275         virtual FX_BOOL                         Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
276         
277         virtual FX_BOOL                         Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
278         virtual FX_BOOL                         Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point);
279         virtual FX_BOOL                         Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
280         virtual FX_BOOL                         Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);
281
282
283         virtual FX_BOOL                         Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);
284         virtual FX_BOOL                         Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
285         virtual FX_BOOL                         Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);
286
287         virtual FX_BOOL                         Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
288         virtual FX_BOOL                         Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
289         virtual FX_BOOL                         Annot_OnChangeFocus(CPDFSDK_Annot* pSetAnnot,CPDFSDK_Annot* pKillAnnot);
290
291         virtual CPDF_Rect                       Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot);
292         virtual FX_BOOL                         Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);
293
294 private:
295         IPDFSDK_AnnotHandler*                   GetAnnotHandler(const CFX_ByteString& sType) const;
296         CPDFSDK_Annot*                          GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext);
297 private:
298         CBA_AnnotHandlerArray           m_Handlers;
299         CFX_MapByteStringToPtr          m_mapType2Handler;
300         CPDFDoc_Environment*            m_pApp;
301 };
302
303 //#define CBF_Page2Accessible    CFX_MapPtrTemplate<CPDFSDK_PageView*, IAccessible*>
304
305 typedef int (*AI_COMPARE) (CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
306
307 class CPDFSDK_AnnotIterator
308 {
309 public:
310     CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView, FX_BOOL bReverse,
311                 FX_BOOL bIgnoreTopmost=FALSE,FX_BOOL bCircle=FALSE,CFX_PtrArray* pList=NULL);
312     virtual ~CPDFSDK_AnnotIterator() { }
313
314         virtual CPDFSDK_Annot*  Next (const CPDFSDK_Annot* pCurrent) ;
315         virtual CPDFSDK_Annot*  Prev (const CPDFSDK_Annot* pCurrent) ;  
316         virtual CPDFSDK_Annot*  Next(int& index ) ;
317         virtual CPDFSDK_Annot*  Prev(int& index ) ;
318         virtual int             Count(){return m_pIteratorAnnotList.GetSize();}
319
320         virtual FX_BOOL         InitIteratorAnnotList(CPDFSDK_PageView * pPageView,CFX_PtrArray* pList=NULL);
321
322         void                                    InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare);
323
324 protected:
325         CPDFSDK_Annot*  NextAnnot (const CPDFSDK_Annot* pCurrent) ;
326         CPDFSDK_Annot*  PrevAnnot (const CPDFSDK_Annot* pCurrent) ;
327         CPDFSDK_Annot*  NextAnnot(int& index ) ;
328         CPDFSDK_Annot*  PrevAnnot(int& index ) ;
329
330         CFX_PtrArray         m_pIteratorAnnotList;
331         FX_BOOL                      m_bReverse;
332         FX_BOOL              m_bIgnoreTopmost;
333         FX_BOOL              m_bCircle;
334 };
335
336
337
338 #endif
339