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