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