Initial commit.
[pdfium.git] / fpdfsdk / src / fsdk_annothandler.cpp
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 #include "../include/fsdk_define.h"\r
8 #include "../include/fsdk_mgr.h"\r
9 #include "../include/formfiller/FFL_FormFiller.h"\r
10 #include "../include/fsdk_annothandler.h"\r
11 \r
12 \r
13 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)\r
14 {\r
15         m_pApp = pApp;\r
16 \r
17         CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);\r
18         pHandler->SetFormFiller(m_pApp->GetIFormFiller());\r
19         RegisterAnnotHandler(pHandler);\r
20 }\r
21 \r
22 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr()\r
23 {\r
24         for(int i=0; i<m_Handlers.GetSize(); i++)\r
25         {\r
26                 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);\r
27                 delete pHandler;\r
28         }\r
29         m_Handlers.RemoveAll();\r
30         m_mapType2Handler.RemoveAll();\r
31 }\r
32 \r
33 void    CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)\r
34 {\r
35         ASSERT(pAnnotHandler != NULL);\r
36         \r
37         ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);\r
38         \r
39         m_Handlers.Add(pAnnotHandler);\r
40         m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);\r
41 }\r
42 \r
43 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)\r
44 {\r
45         ASSERT(pAnnotHandler != NULL);\r
46         \r
47         m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());\r
48         \r
49         for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++)\r
50         {\r
51                 if (m_Handlers.GetAt(i) == pAnnotHandler)\r
52                 {\r
53                         m_Handlers.RemoveAt(i);\r
54                         break;\r
55                 }\r
56         }\r
57 }\r
58 \r
59 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView)\r
60 {\r
61         ASSERT(pAnnot != NULL);\r
62         ASSERT(pPageView != NULL);\r
63         \r
64         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType()))\r
65         {\r
66                 return pAnnotHandler->NewAnnot(pAnnot, pPageView);\r
67         }\r
68         \r
69         return new CPDFSDK_Annot(pAnnot, pPageView);\r
70 }\r
71 \r
72 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot)\r
73 {\r
74         ASSERT(pAnnot != NULL);\r
75         \r
76         pAnnot->GetPDFPage();\r
77         \r
78         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
79         {\r
80                 pAnnotHandler->OnRelease(pAnnot);\r
81                 pAnnotHandler->ReleaseAnnot(pAnnot);\r
82         }\r
83         else\r
84         {\r
85                 delete (CPDFSDK_Annot*)pAnnot;\r
86         }\r
87 }\r
88 \r
89 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot)\r
90 {\r
91         ASSERT(pAnnot != NULL);\r
92         \r
93         CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();\r
94         ASSERT(pPDFAnnot != NULL);\r
95         ASSERT(pPDFAnnot->m_pAnnotDict != NULL);\r
96         \r
97         CPDFSDK_DateTime curTime;\r
98         pPDFAnnot->m_pAnnotDict->SetAtString("M", curTime.ToPDFDateTimeString());\r
99         pPDFAnnot->m_pAnnotDict->SetAtNumber("F", (int)0);      \r
100         \r
101         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
102         {\r
103                 pAnnotHandler->OnCreate(pAnnot);\r
104         }\r
105 }\r
106 \r
107 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot)\r
108 {\r
109         ASSERT(pAnnot != NULL);\r
110         \r
111         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
112         {\r
113                 pAnnotHandler->OnLoad(pAnnot);\r
114         }\r
115 }\r
116 \r
117 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pAnnot) const\r
118 {\r
119         ASSERT(pAnnot != NULL);\r
120         \r
121         CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();\r
122         ASSERT(pPDFAnnot != NULL);\r
123         \r
124         return GetAnnotHandler(pPDFAnnot->GetSubType());\r
125 }\r
126 \r
127 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const\r
128 {\r
129         void* pRet = NULL;\r
130         m_mapType2Handler.Lookup(sType, pRet);  \r
131         return (IPDFSDK_AnnotHandler*)pRet;\r
132 }\r
133 \r
134 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags)\r
135 {\r
136         ASSERT(pAnnot != NULL);\r
137         \r
138         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
139         {\r
140                 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);\r
141         }\r
142         else\r
143         {\r
144                 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);\r
145         }\r
146 }\r
147 \r
148 \r
149 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
150 {\r
151         ASSERT(pAnnot != NULL);\r
152         \r
153         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
154         {\r
155                 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);\r
156         }\r
157         return FALSE;\r
158 }\r
159 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
160  {\r
161         ASSERT(pAnnot != NULL);\r
162 \r
163         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
164         {\r
165                 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);\r
166         }\r
167         return FALSE;\r
168  }\r
169 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
170 {\r
171         ASSERT(pAnnot != NULL);\r
172         \r
173         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
174         {\r
175                 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);\r
176         }\r
177         return FALSE;\r
178 }\r
179 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
180 {\r
181         ASSERT(pAnnot != NULL);\r
182         \r
183         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
184         {\r
185                 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);\r
186         }\r
187         return FALSE;\r
188 }\r
189 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)\r
190 {\r
191         ASSERT(pAnnot != NULL);\r
192         \r
193         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
194         {\r
195                 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point);\r
196         }\r
197         return FALSE;\r
198 }\r
199 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
200 {\r
201         ASSERT(pAnnot != NULL);\r
202         \r
203         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
204         {\r
205                 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);\r
206         }\r
207         return FALSE;\r
208 }\r
209 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
210 {\r
211         ASSERT(pAnnot != NULL);\r
212         \r
213         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
214         {\r
215                 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);\r
216         }\r
217         return FALSE;\r
218 }\r
219 \r
220 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
221 {\r
222         ASSERT(pAnnot != NULL);\r
223         \r
224         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
225         {\r
226                 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);\r
227         }\r
228         return ;\r
229 }\r
230 \r
231 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
232 {\r
233         ASSERT(pAnnot != NULL);\r
234         \r
235         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
236         {\r
237                 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);\r
238         }\r
239         return;\r
240 }\r
241 \r
242 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)\r
243 {\r
244 \r
245         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
246         {\r
247                 return pAnnotHandler->OnChar(pAnnot,nChar, nFlags);\r
248         }\r
249         return FALSE;\r
250 \r
251 }\r
252 \r
253 FX_BOOL                 CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)\r
254 {\r
255 \r
256         if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag))\r
257         {\r
258                 CPDFSDK_PageView* pPage = pAnnot->GetPageView();\r
259                 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();\r
260                 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab))\r
261                 {\r
262                         CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));\r
263 \r
264                         if(pNext && pNext != pFocusAnnot)\r
265                         {\r
266                                 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();\r
267                                 pDocument->SetFocusAnnot(pNext);\r
268                                 return TRUE;\r
269                         }\r
270                 }\r
271         }\r
272 \r
273         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
274         {\r
275                 return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag);\r
276         }\r
277         return FALSE;\r
278 }\r
279 FX_BOOL                 CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)\r
280 {\r
281         return FALSE;\r
282 }\r
283 \r
284 FX_BOOL                 CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
285 {\r
286         ASSERT(pAnnot != NULL);\r
287 \r
288         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
289         {\r
290                 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag))\r
291                 {\r
292                         CPDFSDK_PageView* pPage = pAnnot->GetPageView();\r
293                         ASSERT(pPage != NULL);\r
294 \r
295                         pPage->GetSDKDocument();\r
296         //              pDocument->SetTopmostAnnot(pAnnot);\r
297 \r
298                         return TRUE;\r
299                 }\r
300                 else\r
301                 {\r
302                         return FALSE;\r
303                 }\r
304         }\r
305         \r
306         return FALSE;\r
307 }\r
308 \r
309 FX_BOOL                 CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
310 {\r
311         ASSERT(pAnnot != NULL);\r
312         \r
313         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
314         {\r
315                 if (pAnnotHandler->OnKillFocus(pAnnot, nFlag))\r
316                 {       \r
317                         return TRUE;\r
318                 }\r
319                 else\r
320                         return FALSE;\r
321         }\r
322         \r
323         return FALSE;\r
324 }\r
325 \r
326 CPDF_Rect       CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)\r
327 {\r
328         ASSERT(pAnnot);\r
329         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
330         {\r
331                 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);\r
332         }\r
333         return pAnnot->GetRect();\r
334 }\r
335 \r
336 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)\r
337 {\r
338         ASSERT(pAnnot);\r
339         if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))\r
340         {\r
341                 if(pAnnotHandler->CanAnswer(pAnnot))\r
342                         return pAnnotHandler->HitTest(pPageView, pAnnot, point);\r
343         }\r
344         return FALSE;\r
345 }\r
346 \r
347 CPDFSDK_Annot*  CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext)\r
348 {\r
349          CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");\r
350 \r
351          CPDFSDK_Annot* pNext = bNext ? \r
352                  ai.GetNextAnnot(pSDKAnnot) : \r
353                 ai.GetPrevAnnot(pSDKAnnot);\r
354         \r
355                 return pNext;\r
356 }\r
357 \r
358 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)\r
359 {\r
360         ASSERT(pAnnot);\r
361         ASSERT(pAnnot->GetType() == "Widget");\r
362         CFX_ByteString sSubType = pAnnot->GetSubType();\r
363         \r
364         if (sSubType == BFFT_SIGNATURE)\r
365         {\r
366         }\r
367         else\r
368         {\r
369                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
370                 if (!pWidget->IsVisible()) return FALSE;\r
371 \r
372                 int nFieldFlags = pWidget->GetFieldFlags();\r
373                 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) return FALSE;\r
374                 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)\r
375                         return TRUE;\r
376                 else\r
377                 {\r
378                         CPDF_Page* pPage = pWidget->GetPDFPage();\r
379                         ASSERT(pPage != NULL);\r
380                         \r
381                         CPDF_Document* pDocument = pPage->m_pDocument;\r
382                         ASSERT(pDocument != NULL);\r
383                         \r
384                         FX_DWORD dwPermissions = pDocument->GetUserPermissions();\r
385                         return (dwPermissions&FPDFPERM_FILL_FORM) || \r
386                                 (dwPermissions&FPDFPERM_ANNOT_FORM) || \r
387                         (dwPermissions&FPDFPERM_ANNOT_FORM);\r
388                 }\r
389         }\r
390 \r
391         return FALSE;\r
392 }\r
393 \r
394 CPDFSDK_Annot*          CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage)\r
395 {\r
396         ASSERT(pPage != NULL);\r
397         pPage->GetPDFDocument();\r
398         \r
399         CPDFSDK_Document* pSDKDoc  = m_pApp->GetCurrentDoc();\r
400         ASSERT(pSDKDoc);\r
401         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();\r
402         ASSERT(pInterForm != NULL);\r
403         \r
404         CPDFSDK_Widget* pWidget = NULL;\r
405         if (CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->m_pAnnotDict))\r
406         {\r
407                 pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);\r
408                 pInterForm->AddMap(pCtrl, pWidget);\r
409                 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();\r
410                 if(pPDFInterForm && pPDFInterForm->NeedConstructAP())\r
411                         pWidget->ResetAppearance(NULL,FALSE);\r
412         }\r
413         \r
414         return pWidget;\r
415 }\r
416 \r
417 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)\r
418 {\r
419         ASSERT(pAnnot != NULL);\r
420 \r
421         if (m_pFormFiller)\r
422                 m_pFormFiller->OnDelete(pAnnot);\r
423         \r
424         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
425         CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();\r
426         ASSERT(pInterForm != NULL);\r
427         \r
428         CPDF_FormControl* pCtrol = pWidget->GetFormControl();\r
429         pInterForm->RemoveMap(pCtrol);\r
430         \r
431 \r
432         delete pWidget;\r
433 }\r
434 \r
435 \r
436 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,  FX_DWORD dwFlags)\r
437 {\r
438         ASSERT(pAnnot != NULL);\r
439         CFX_ByteString sSubType = pAnnot->GetSubType();\r
440         \r
441         if (sSubType == BFFT_SIGNATURE)\r
442         {\r
443                 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);\r
444         }\r
445         else\r
446         {\r
447                 if (m_pFormFiller)\r
448                 {\r
449                         m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);\r
450                 }\r
451         }\r
452 }\r
453 \r
454 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) \r
455 {\r
456         ASSERT(pAnnot != NULL);\r
457         CFX_ByteString sSubType = pAnnot->GetSubType();\r
458         \r
459         if (sSubType == BFFT_SIGNATURE)\r
460         {\r
461         }\r
462         else\r
463         {\r
464                 if (m_pFormFiller)\r
465                          m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);\r
466         }\r
467         \r
468 \r
469 }\r
470 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) \r
471 {\r
472         ASSERT(pAnnot != NULL);\r
473         CFX_ByteString sSubType = pAnnot->GetSubType();\r
474         \r
475         if (sSubType == BFFT_SIGNATURE)\r
476         {\r
477         }\r
478         else\r
479         {\r
480                 if (m_pFormFiller)\r
481                          m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);\r
482         }\r
483         \r
484 }\r
485 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
486 {\r
487         ASSERT(pAnnot != NULL);\r
488         CFX_ByteString sSubType = pAnnot->GetSubType();\r
489         \r
490         if (sSubType == BFFT_SIGNATURE)\r
491         {\r
492         }\r
493         else\r
494         {\r
495                 if (m_pFormFiller)\r
496                         return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);\r
497         }\r
498         \r
499         return FALSE;\r
500 }\r
501 \r
502 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
503 {\r
504         ASSERT(pAnnot != NULL);\r
505         CFX_ByteString sSubType = pAnnot->GetSubType();\r
506         \r
507         if (sSubType == BFFT_SIGNATURE)\r
508         {\r
509         }\r
510         else\r
511         {\r
512                 if (m_pFormFiller)\r
513                         return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);\r
514         }\r
515         \r
516         return FALSE;\r
517 }\r
518 \r
519 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
520 {\r
521         ASSERT(pAnnot != NULL);\r
522         CFX_ByteString sSubType = pAnnot->GetSubType();\r
523         \r
524         if (sSubType == BFFT_SIGNATURE)\r
525         {\r
526         }\r
527         else\r
528         {\r
529                 if (m_pFormFiller)\r
530                         return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);\r
531         }\r
532         \r
533         return FALSE;\r
534 }\r
535 \r
536 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
537 {       \r
538         ASSERT(pAnnot != NULL);\r
539         CFX_ByteString sSubType = pAnnot->GetSubType();\r
540 \r
541         if (sSubType == BFFT_SIGNATURE)\r
542         {\r
543         }\r
544         else\r
545         {\r
546                 if (m_pFormFiller)\r
547                         return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);\r
548         }\r
549 \r
550         return FALSE;\r
551 \r
552 }\r
553 \r
554 \r
555 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)\r
556 {\r
557         ASSERT(pAnnot != NULL);\r
558         CFX_ByteString sSubType = pAnnot->GetSubType();\r
559         \r
560         if (sSubType == BFFT_SIGNATURE)\r
561         {\r
562         }\r
563         else\r
564         {\r
565                 if (m_pFormFiller)\r
566                         return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point);\r
567         }\r
568         \r
569         return FALSE;\r
570 }\r
571 \r
572 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
573 {\r
574         ASSERT(pAnnot != NULL);\r
575         CFX_ByteString sSubType = pAnnot->GetSubType();\r
576         \r
577         if (sSubType == BFFT_SIGNATURE)\r
578         {\r
579         }\r
580         else\r
581         {\r
582                 if (m_pFormFiller)\r
583                         return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);\r
584         }\r
585         \r
586         return FALSE;\r
587 }\r
588 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)\r
589 {\r
590         ASSERT(pAnnot != NULL);\r
591         CFX_ByteString sSubType = pAnnot->GetSubType();\r
592         \r
593         if (sSubType == BFFT_SIGNATURE)\r
594         {\r
595         }\r
596         else\r
597         {\r
598                 if (m_pFormFiller)\r
599                         return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);\r
600         }\r
601         \r
602         return FALSE;\r
603 }\r
604 \r
605 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)\r
606 {\r
607         ASSERT(pAnnot != NULL);\r
608         CFX_ByteString sSubType = pAnnot->GetSubType();\r
609         \r
610         if (sSubType == BFFT_SIGNATURE)\r
611         {\r
612         }\r
613         else\r
614         {\r
615                 if (m_pFormFiller)\r
616                         return m_pFormFiller->OnChar(pAnnot,nChar, nFlags);\r
617         }\r
618         \r
619         return FALSE;\r
620 }\r
621 \r
622 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)\r
623 {\r
624         ASSERT(pAnnot != NULL);\r
625         CFX_ByteString sSubType = pAnnot->GetSubType();\r
626         \r
627         if (sSubType == BFFT_SIGNATURE)\r
628         {\r
629         }\r
630         else\r
631         {\r
632                 if (m_pFormFiller)\r
633                         return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag);\r
634         }\r
635         \r
636         return FALSE;\r
637 }\r
638 \r
639 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)\r
640 {\r
641 \r
642         return FALSE;\r
643 }\r
644 void    CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) \r
645 {\r
646         ASSERT(pAnnot != NULL);\r
647         CFX_ByteString sSubType = pAnnot->GetSubType();\r
648         \r
649         if (sSubType == BFFT_SIGNATURE)\r
650         {\r
651         }\r
652         else\r
653         {\r
654                 if (m_pFormFiller)\r
655                         m_pFormFiller->OnCreate(pAnnot);\r
656         }\r
657 }\r
658 \r
659 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)\r
660 {\r
661         ASSERT(pAnnot != NULL);\r
662         \r
663         CFX_ByteString sSubType = pAnnot->GetSubType();\r
664         \r
665         if (sSubType == BFFT_SIGNATURE)\r
666         {\r
667         }\r
668         else\r
669         {\r
670                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
671                 \r
672         if (!pWidget->IsAppearanceValid())\r
673                         pWidget->ResetAppearance(NULL, FALSE);\r
674                 \r
675                 int nFieldType = pWidget->GetFieldType();\r
676                 \r
677                 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX)\r
678                 {\r
679                         FX_BOOL bFormated = FALSE;\r
680                         CFX_WideString sValue = pWidget->OnFormat(0, bFormated);\r
681                         \r
682                         if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)\r
683                         {\r
684                                 pWidget->ResetAppearance(sValue, FALSE);\r
685                         }\r
686                 }\r
687                 \r
688 \r
689                 if (m_pFormFiller)\r
690                         m_pFormFiller->OnLoad(pAnnot);\r
691 \r
692         }\r
693 }\r
694 \r
695 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
696 {\r
697         ASSERT(pAnnot != NULL);\r
698         CFX_ByteString sSubType = pAnnot->GetSubType();\r
699         \r
700         if (sSubType == BFFT_SIGNATURE)\r
701         {\r
702         }\r
703         else\r
704         {\r
705                 if (m_pFormFiller)\r
706                         return m_pFormFiller->OnSetFocus(pAnnot,nFlag);\r
707         }\r
708         \r
709         return TRUE;\r
710 }\r
711 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)\r
712 {\r
713         ASSERT(pAnnot != NULL);\r
714         CFX_ByteString sSubType = pAnnot->GetSubType();\r
715         \r
716         if (sSubType == BFFT_SIGNATURE)\r
717         {\r
718         }\r
719         else\r
720         {\r
721                 if (m_pFormFiller)\r
722                         return m_pFormFiller->OnKillFocus(pAnnot,nFlag);\r
723         }\r
724         \r
725         return TRUE;\r
726 }\r
727 \r
728 CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)\r
729 {\r
730         ASSERT(pAnnot != NULL);\r
731         CFX_ByteString sSubType = pAnnot->GetSubType();\r
732         \r
733         if (sSubType == BFFT_SIGNATURE)\r
734         {\r
735         }\r
736         else\r
737         {\r
738                 if (m_pFormFiller)\r
739                         return m_pFormFiller->GetViewBBox(pPageView, pAnnot);\r
740 \r
741         }\r
742         \r
743         return CPDF_Rect(0,0,0,0);\r
744 }\r
745 \r
746 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)\r
747 {\r
748         ASSERT(pPageView);\r
749         ASSERT(pAnnot);\r
750 \r
751         CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);\r
752         return rect.Contains(point.x, point.y);\r
753 }\r
754 \r
755 //CReader_AnnotIteratorEx\r
756 \r
757 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse,\r
758                                                                                                  FX_BOOL bIgnoreTopmost/*=FALSE*/,\r
759                                                                                                  FX_BOOL bCircle/*=FALSE*/,\r
760                                                                                                  CFX_PtrArray *pList/*=NULL*/)\r
761 {\r
762         ASSERT(pPageView);\r
763         m_bReverse=bReverse;\r
764         m_bIgnoreTopmost= bIgnoreTopmost;\r
765         m_bCircle=bCircle;\r
766         m_pIteratorAnnotList.RemoveAll();\r
767         InitIteratorAnnotList(pPageView,pList);\r
768 }\r
769 \r
770 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent) \r
771 {\r
772         \r
773         int index=-1;\r
774         int nCount=this->m_pIteratorAnnotList.GetSize();\r
775         if(pCurrent){\r
776                 for(int i=0;i<nCount;i++){\r
777                         CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i);\r
778                         if(pReaderAnnot ==pCurrent){                    \r
779                                 index=i;\r
780                                 break;\r
781                         }                       \r
782                 }\r
783         }       \r
784         return NextAnnot(index);\r
785 }\r
786 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent)\r
787 {\r
788         \r
789         int index=-1;\r
790         int nCount=this->m_pIteratorAnnotList.GetSize();\r
791         if(pCurrent){\r
792                 for(int i=0;i<nCount;i++){\r
793                         CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);\r
794                         if(pReaderAnnot ==pCurrent){                    \r
795                                 index=i;\r
796                                 break;\r
797                         }                       \r
798                 }       \r
799         }\r
800         return PrevAnnot(index);        \r
801 }\r
802 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::NextAnnot (int& index) \r
803 {       \r
804         \r
805         int nCount=m_pIteratorAnnotList.GetSize();\r
806     if(nCount<=0) index=-1;\r
807     else{\r
808                 if(index<0){\r
809                         index=0;                \r
810                 }\r
811                 else{           \r
812                         if(m_bCircle){                  \r
813                                 index=( index <nCount-1) ? (index+1) :0;                \r
814                         }\r
815                         else{\r
816                                 index=( index <nCount-1) ? (index+1) :-1;               \r
817                         }\r
818                         \r
819                 }       \r
820         }\r
821         return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);           \r
822 }\r
823 \r
824 \r
825 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::PrevAnnot (int& index)\r
826 {\r
827         \r
828         int nCount=m_pIteratorAnnotList.GetSize();\r
829     if(nCount<=0) index=-1;\r
830         else{   \r
831                 if(index<0){\r
832                         index=nCount-1;          \r
833                 }\r
834                 else{   \r
835                         if(m_bCircle){                  \r
836                                 index = ( index >0) ? (index-1) :nCount-1;              \r
837                         }\r
838                         else{\r
839                                 index = ( index >0) ? (index-1) :-1;    \r
840                         }                               \r
841                 }\r
842         }\r
843         return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);           \r
844 }\r
845 \r
846 \r
847 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) \r
848 {\r
849 \r
850         return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent);           \r
851 \r
852 }\r
853 \r
854 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) \r
855 {\r
856 \r
857         return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent);           \r
858 }\r
859 \r
860 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index )\r
861 {\r
862         \r
863         return (m_bReverse) ? PrevAnnot(index):NextAnnot(index);                 \r
864         \r
865 }\r
866 \r
867 CPDFSDK_Annot*  CPDFSDK_AnnotIterator::Prev(int& index )\r
868 {\r
869         \r
870         return (m_bReverse) ? NextAnnot(index):PrevAnnot(index);                 \r
871 }\r
872 \r
873 \r
874 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare)\r
875 {\r
876         for (int i = 1; i < arrayList.GetSize(); i++)\r
877         {\r
878                 if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0)\r
879                 {\r
880                         int j = i-1;\r
881                         CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];\r
882                         \r
883                         do\r
884                         {\r
885                                 arrayList[j + 1] = arrayList[j];\r
886                         } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);\r
887 \r
888                         arrayList[j+1] = pTemp;\r
889                 }\r
890         }\r
891 }\r
892 \r
893 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)\r
894 {\r
895         if(p1->GetLayoutOrder() < p2->GetLayoutOrder())\r
896                 return -1;\r
897         else if (p1->GetLayoutOrder() == p2->GetLayoutOrder())\r
898                 return 0;\r
899         else\r
900                 return 1;\r
901 }\r
902 \r
903 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView,CFX_PtrArray * pAnnotList)\r
904 {\r
905         ASSERT(pPageView);\r
906         \r
907         \r
908 \r
909         if(pAnnotList==NULL){   \r
910                 pAnnotList=pPageView->GetAnnotList();\r
911         }\r
912 \r
913         this->m_pIteratorAnnotList.RemoveAll();\r
914         if(!pAnnotList) return FALSE;\r
915 \r
916         CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();\r
917 \r
918 \r
919         int nCount =pAnnotList->GetSize();\r
920 \r
921         for(int i = nCount- 1 ;i >= 0;i--)\r
922         {\r
923                 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i);\r
924                 m_pIteratorAnnotList.Add(pReaderAnnot); \r
925         }\r
926 \r
927         InsertSort(m_pIteratorAnnotList,&LyOrderCompare);\r
928 \r
929         if(pTopMostAnnot)\r
930         {\r
931                 for(int i=0 ;i<nCount;i++)\r
932                 {\r
933                         CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);\r
934                         if(pReaderAnnot == pTopMostAnnot)\r
935                         {\r
936                                 m_pIteratorAnnotList.RemoveAt(i);\r
937                                 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);\r
938                                 break;\r
939                         }       \r
940                 }\r
941         }\r
942 \r
943         return TRUE;\r
944 }\r
945 \r