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