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