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