Initial commit.
[pdfium.git] / fpdfsdk / include / fsdk_annothandler.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FSDK_ANNOTHANDLER_H_\r
8 #define _FSDK_ANNOTHANDLER_H_\r
9 \r
10 \r
11 class CPDFDoc_Environment;\r
12 class CFFL_IFormFiller;\r
13 class CPDFSDK_PageView;\r
14 class IPDFSDK_AnnotHandler\r
15 {\r
16 \r
17 public:\r
18         virtual ~IPDFSDK_AnnotHandler() {};\r
19 \r
20         virtual CFX_ByteString          GetType() = 0;\r
21 \r
22         virtual CFX_ByteString          GetName() = 0;\r
23 \r
24         virtual FX_BOOL                         CanAnswer(CPDFSDK_Annot* pAnnot) = 0;\r
25         \r
26 \r
27         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) = 0;\r
28 \r
29         virtual void                            ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0;\r
30 \r
31         virtual void                            DeleteAnnot(CPDFSDK_Annot* pAnnot) = 0;\r
32         \r
33 \r
34         virtual CPDF_Rect                               GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) = 0;\r
35         \r
36         virtual FX_BOOL                         HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) = 0;\r
37         \r
38 \r
39         virtual void                            OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, \r
40                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,\r
41                 FX_DWORD dwFlags) = 0;\r
42         \r
43         virtual void                            OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, \r
44                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,\r
45                 const CPDF_Rect& rcWindow, FX_DWORD dwFlags) = 0;\r
46         \r
47 \r
48         \r
49 \r
50         virtual void                            OnCreate(CPDFSDK_Annot* pAnnot) = 0;\r
51 \r
52         virtual void                            OnLoad(CPDFSDK_Annot* pAnnot) = 0;\r
53 \r
54         virtual void                            OnDelete(CPDFSDK_Annot* pAnnot) = 0;\r
55 \r
56         virtual void                            OnRelease(CPDFSDK_Annot* pAnnot) = 0;\r
57         \r
58 \r
59         virtual void                            OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;\r
60         virtual void                            OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;\r
61         \r
62 \r
63         virtual FX_BOOL                         OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
64         virtual FX_BOOL                         OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
65         virtual FX_BOOL                         OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
66         virtual FX_BOOL                         OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
67         virtual FX_BOOL                         OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) = 0;\r
68         virtual FX_BOOL                         OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
69         virtual FX_BOOL                         OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
70         virtual FX_BOOL                         OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) = 0;\r
71 //by wjm.\r
72         virtual FX_BOOL                         OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) = 0;\r
73         virtual FX_BOOL                         OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) = 0;\r
74         virtual FX_BOOL                         OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) =0 ;\r
75 \r
76         virtual void                            OnDeSelected(CPDFSDK_Annot* pAnnot) = 0;\r
77         virtual void                            OnSelected(CPDFSDK_Annot* pAnnot) = 0;\r
78 \r
79         virtual FX_BOOL                         OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;\r
80         virtual FX_BOOL                         OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;\r
81 \r
82 };\r
83 \r
84 \r
85 class CPDFSDK_BFAnnotHandler:public IPDFSDK_AnnotHandler\r
86 {\r
87 public:\r
88         CPDFSDK_BFAnnotHandler(CPDFDoc_Environment*     pApp):m_pFormFiller(NULL),m_pApp(pApp) {}\r
89         virtual ~CPDFSDK_BFAnnotHandler() {}\r
90 public:\r
91 \r
92         virtual CFX_ByteString          GetType()  {return CFX_ByteString("Widget");}\r
93 \r
94         virtual CFX_ByteString          GetName()  {return CFX_ByteString("WidgetHandler");}\r
95         \r
96         virtual FX_BOOL                         CanAnswer(CPDFSDK_Annot* pAnnot);\r
97 \r
98         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage);\r
99 \r
100         virtual void                            ReleaseAnnot(CPDFSDK_Annot* pAnnot)  ;\r
101 \r
102         virtual void                            DeleteAnnot(CPDFSDK_Annot* pAnnot) {}\r
103         \r
104 \r
105         virtual CPDF_Rect                               GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) ;\r
106         \r
107         virtual FX_BOOL                         HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);\r
108         \r
109 \r
110         virtual void                            OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, \r
111                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,\r
112                  FX_DWORD dwFlags) ;\r
113         \r
114         virtual void                            OnDrawSleep(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, \r
115                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,\r
116                 const CPDF_Rect& rcWindow, FX_DWORD dwFlags) {}\r
117         \r
118 \r
119         virtual void                            OnCreate(CPDFSDK_Annot* pAnnot) ;\r
120 \r
121         virtual void                            OnLoad(CPDFSDK_Annot* pAnnot) ;\r
122 \r
123         virtual void                            OnDelete(CPDFSDK_Annot* pAnnot) {}\r
124 \r
125         virtual void                            OnRelease(CPDFSDK_Annot* pAnnot) {}\r
126         \r
127 \r
128         virtual void                            OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;\r
129         virtual void                            OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) ;\r
130         \r
131 \r
132         virtual FX_BOOL                         OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
133         virtual FX_BOOL                         OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
134         virtual FX_BOOL                         OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
135         virtual FX_BOOL                         OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
136         virtual FX_BOOL                         OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) ;\r
137         virtual FX_BOOL                         OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
138         virtual FX_BOOL                         OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) ;\r
139         virtual FX_BOOL                         OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) {return FALSE;}\r
140         \r
141 //by wjm.\r
142         virtual FX_BOOL                         OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);\r
143         virtual FX_BOOL                         OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);\r
144         virtual FX_BOOL                         OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);\r
145 \r
146         virtual void                            OnDeSelected(CPDFSDK_Annot* pAnnot) {}\r
147         virtual void                            OnSelected(CPDFSDK_Annot* pAnnot) {}\r
148 \r
149         virtual FX_BOOL                         OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);\r
150         virtual FX_BOOL                         OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);\r
151 \r
152         void                                            SetFormFiller(CFFL_IFormFiller* pFiller){m_pFormFiller = pFiller;}\r
153         CFFL_IFormFiller*                       GetFormFiller() {return m_pFormFiller;}\r
154 private:\r
155 \r
156         CPDFDoc_Environment*            m_pApp;\r
157         CFFL_IFormFiller*                       m_pFormFiller;\r
158 };\r
159 \r
160 #define CBA_AnnotHandlerArray CFX_ArrayTemplate<IPDFSDK_AnnotHandler*>\r
161 class CPDFSDK_AnnotHandlerMgr\r
162 {\r
163 public:\r
164         // Destroy the handler\r
165         CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp);\r
166         virtual ~CPDFSDK_AnnotHandlerMgr() ;\r
167 \r
168 public:\r
169         void                                            RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);\r
170         void                                            UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);\r
171 \r
172         virtual CPDFSDK_Annot*          NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView);\r
173         virtual void                            ReleaseAnnot(CPDFSDK_Annot * pAnnot);\r
174         \r
175         virtual void                            Annot_OnCreate(CPDFSDK_Annot* pAnnot);\r
176         virtual void                            Annot_OnLoad(CPDFSDK_Annot* pAnnot);\r
177 public:\r
178         IPDFSDK_AnnotHandler*           GetAnnotHandler(CPDFSDK_Annot* pAnnot) const;\r
179         virtual void                            Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot,\r
180                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags);\r
181 \r
182         virtual void                            Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);\r
183         virtual void                            Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags);\r
184 \r
185         virtual FX_BOOL                         Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
186         virtual FX_BOOL                         Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
187         virtual FX_BOOL                         Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
188         \r
189         virtual FX_BOOL                         Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
190         virtual FX_BOOL                         Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point);\r
191         virtual FX_BOOL                         Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
192         virtual FX_BOOL                         Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point);\r
193 \r
194 \r
195         virtual FX_BOOL                         Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags);\r
196         virtual FX_BOOL                         Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);\r
197         virtual FX_BOOL                         Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag);\r
198 \r
199         virtual FX_BOOL                         Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);\r
200         virtual FX_BOOL                         Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);\r
201 \r
202         virtual CPDF_Rect                       Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot);\r
203         virtual FX_BOOL                         Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point);\r
204 \r
205 private:\r
206         IPDFSDK_AnnotHandler*                   GetAnnotHandler(const CFX_ByteString& sType) const;\r
207         CPDFSDK_Annot*                          GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext);\r
208 private:\r
209         CBA_AnnotHandlerArray           m_Handlers;\r
210         CFX_MapByteStringToPtr          m_mapType2Handler;\r
211         CPDFDoc_Environment*            m_pApp;\r
212 };\r
213 \r
214 //#define CBF_Page2Accessible    CFX_MapPtrTemplate<CPDFSDK_PageView*, IAccessible*>\r
215 \r
216 typedef int (*AI_COMPARE) (CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);\r
217 \r
218 class CPDFSDK_AnnotIterator\r
219 {\r
220 protected:\r
221         CPDFSDK_Annot*  NextAnnot (const CPDFSDK_Annot* pCurrent) ;\r
222         CPDFSDK_Annot*  PrevAnnot (const CPDFSDK_Annot* pCurrent) ;     \r
223         CPDFSDK_Annot*  NextAnnot(int& index ) ;\r
224         CPDFSDK_Annot*  PrevAnnot(int& index ) ;\r
225 public:\r
226     CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView, FX_BOOL bReverse,\r
227                 FX_BOOL bIgnoreTopmost=FALSE,FX_BOOL bCircle=FALSE,CFX_PtrArray* pList=NULL);   \r
228         virtual CPDFSDK_Annot*  Next (const CPDFSDK_Annot* pCurrent) ;\r
229         virtual CPDFSDK_Annot*  Prev (const CPDFSDK_Annot* pCurrent) ;  \r
230         virtual CPDFSDK_Annot*  Next(int& index ) ;\r
231         virtual CPDFSDK_Annot*  Prev(int& index ) ;\r
232         virtual int             Count(){return m_pIteratorAnnotList.GetSize();}\r
233         \r
234         virtual FX_BOOL         InitIteratorAnnotList(CPDFSDK_PageView * pPageView,CFX_PtrArray* pList=NULL);\r
235         \r
236         void                                    InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare);\r
237 protected:\r
238         //      CFX_PtrList                      m_pIteratorAnnotList; \r
239         CFX_PtrArray         m_pIteratorAnnotList;      \r
240         FX_BOOL                      m_bReverse;\r
241         FX_BOOL              m_bIgnoreTopmost;\r
242         FX_BOOL              m_bCircle;\r
243 };\r
244 \r
245 \r
246 \r
247 #endif\r
248 \r