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