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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
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"
13 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)
17 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
18 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
19 RegisterAnnotHandler(pHandler);
22 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr()
24 for(int i=0; i<m_Handlers.GetSize(); i++)
26 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
29 m_Handlers.RemoveAll();
30 m_mapType2Handler.RemoveAll();
33 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
35 ASSERT(pAnnotHandler != NULL);
37 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);
39 m_Handlers.Add(pAnnotHandler);
40 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);
43 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler)
45 ASSERT(pAnnotHandler != NULL);
47 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());
49 for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++)
51 if (m_Handlers.GetAt(i) == pAnnotHandler)
53 m_Handlers.RemoveAt(i);
59 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView)
61 ASSERT(pAnnot != NULL);
62 ASSERT(pPageView != NULL);
64 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType()))
66 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
69 return new CPDFSDK_Annot(pAnnot, pPageView);
72 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
74 ASSERT(pAnnot != NULL);
78 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
80 pAnnotHandler->OnRelease(pAnnot);
81 pAnnotHandler->ReleaseAnnot(pAnnot);
85 delete (CPDFSDK_Annot*)pAnnot;
89 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot)
91 ASSERT(pAnnot != NULL);
93 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
95 CPDFSDK_DateTime curTime;
96 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
97 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
99 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
101 pAnnotHandler->OnCreate(pAnnot);
105 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot)
107 ASSERT(pAnnot != NULL);
109 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
111 pAnnotHandler->OnLoad(pAnnot);
115 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pAnnot) const
117 ASSERT(pAnnot != NULL);
119 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
120 ASSERT(pPDFAnnot != NULL);
122 return GetAnnotHandler(pPDFAnnot->GetSubType());
125 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const
128 m_mapType2Handler.Lookup(sType, pRet);
129 return (IPDFSDK_AnnotHandler*)pRet;
132 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags)
134 ASSERT(pAnnot != NULL);
136 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
138 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
142 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
147 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
149 ASSERT(pAnnot != NULL);
151 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
153 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
157 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
159 ASSERT(pAnnot != NULL);
161 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
163 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
167 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
169 ASSERT(pAnnot != NULL);
171 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
173 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
177 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
179 ASSERT(pAnnot != NULL);
181 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
183 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
187 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
189 ASSERT(pAnnot != NULL);
191 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
193 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point);
197 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
199 ASSERT(pAnnot != NULL);
201 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
203 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
207 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
209 ASSERT(pAnnot != NULL);
211 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
213 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
218 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
220 ASSERT(pAnnot != NULL);
222 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
224 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
229 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
231 ASSERT(pAnnot != NULL);
233 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
235 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
240 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
243 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
245 return pAnnotHandler->OnChar(pAnnot,nChar, nFlags);
251 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
254 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag))
256 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
257 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
258 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab))
260 CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
262 if(pNext && pNext != pFocusAnnot)
264 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
265 pDocument->SetFocusAnnot(pNext);
271 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
273 return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag);
277 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
282 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
284 ASSERT(pAnnot != NULL);
286 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
288 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag))
290 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
291 pPage->GetSDKDocument();
298 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
301 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
302 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
307 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
310 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
311 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
313 return pAnnot->GetRect();
316 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
319 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
321 if (pAnnotHandler->CanAnswer(pAnnot))
322 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
327 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext)
329 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
330 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
333 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
335 ASSERT(pAnnot->GetType() == "Widget");
336 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
339 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
340 if (!pWidget->IsVisible())
343 int nFieldFlags = pWidget->GetFieldFlags();
344 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
347 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
350 CPDF_Page* pPage = pWidget->GetPDFPage();
351 CPDF_Document* pDocument = pPage->m_pDocument;
352 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
353 return (dwPermissions & FPDFPERM_FILL_FORM) ||
354 (dwPermissions & FPDFPERM_ANNOT_FORM);
357 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage)
359 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
360 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
361 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
365 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
366 pInterForm->AddMap(pCtrl, pWidget);
367 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
368 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
369 pWidget->ResetAppearance(nullptr, FALSE);
374 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
376 ASSERT(pAnnot != NULL);
379 m_pFormFiller->OnDelete(pAnnot);
381 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
382 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
383 ASSERT(pInterForm != NULL);
385 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
386 pInterForm->RemoveMap(pCtrol);
393 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags)
395 ASSERT(pAnnot != NULL);
396 CFX_ByteString sSubType = pAnnot->GetSubType();
398 if (sSubType == BFFT_SIGNATURE)
400 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
406 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
411 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
413 ASSERT(pAnnot != NULL);
414 CFX_ByteString sSubType = pAnnot->GetSubType();
416 if (sSubType == BFFT_SIGNATURE)
422 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
427 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
429 ASSERT(pAnnot != NULL);
430 CFX_ByteString sSubType = pAnnot->GetSubType();
432 if (sSubType == BFFT_SIGNATURE)
438 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
442 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
444 ASSERT(pAnnot != NULL);
445 CFX_ByteString sSubType = pAnnot->GetSubType();
447 if (sSubType == BFFT_SIGNATURE)
453 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
459 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
461 ASSERT(pAnnot != NULL);
462 CFX_ByteString sSubType = pAnnot->GetSubType();
464 if (sSubType == BFFT_SIGNATURE)
470 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
476 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
478 ASSERT(pAnnot != NULL);
479 CFX_ByteString sSubType = pAnnot->GetSubType();
481 if (sSubType == BFFT_SIGNATURE)
487 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
493 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
495 ASSERT(pAnnot != NULL);
496 CFX_ByteString sSubType = pAnnot->GetSubType();
498 if (sSubType == BFFT_SIGNATURE)
504 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
512 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
514 ASSERT(pAnnot != NULL);
515 CFX_ByteString sSubType = pAnnot->GetSubType();
517 if (sSubType == BFFT_SIGNATURE)
523 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point);
529 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
531 ASSERT(pAnnot != NULL);
532 CFX_ByteString sSubType = pAnnot->GetSubType();
534 if (sSubType == BFFT_SIGNATURE)
540 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
545 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
547 ASSERT(pAnnot != NULL);
548 CFX_ByteString sSubType = pAnnot->GetSubType();
550 if (sSubType == BFFT_SIGNATURE)
556 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
562 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
564 ASSERT(pAnnot != NULL);
565 CFX_ByteString sSubType = pAnnot->GetSubType();
567 if (sSubType == BFFT_SIGNATURE)
573 return m_pFormFiller->OnChar(pAnnot,nChar, nFlags);
579 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
581 ASSERT(pAnnot != NULL);
582 CFX_ByteString sSubType = pAnnot->GetSubType();
584 if (sSubType == BFFT_SIGNATURE)
590 return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag);
596 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
601 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot)
603 ASSERT(pAnnot != NULL);
604 CFX_ByteString sSubType = pAnnot->GetSubType();
606 if (sSubType == BFFT_SIGNATURE)
612 m_pFormFiller->OnCreate(pAnnot);
616 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
618 ASSERT(pAnnot != NULL);
620 CFX_ByteString sSubType = pAnnot->GetSubType();
622 if (sSubType == BFFT_SIGNATURE)
627 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
628 if (!pWidget->IsAppearanceValid())
629 pWidget->ResetAppearance(NULL, FALSE);
631 int nFieldType = pWidget->GetFieldType();
632 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX)
634 FX_BOOL bFormated = FALSE;
635 CFX_WideString sValue = pWidget->OnFormat(bFormated);
636 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
638 pWidget->ResetAppearance(sValue.c_str(), FALSE);
643 m_pFormFiller->OnLoad(pAnnot);
647 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
649 ASSERT(pAnnot != NULL);
650 CFX_ByteString sSubType = pAnnot->GetSubType();
652 if (sSubType == BFFT_SIGNATURE)
658 return m_pFormFiller->OnSetFocus(pAnnot,nFlag);
663 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
665 ASSERT(pAnnot != NULL);
666 CFX_ByteString sSubType = pAnnot->GetSubType();
668 if (sSubType == BFFT_SIGNATURE)
674 return m_pFormFiller->OnKillFocus(pAnnot,nFlag);
680 CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
682 ASSERT(pAnnot != NULL);
683 CFX_ByteString sSubType = pAnnot->GetSubType();
685 if (sSubType == BFFT_SIGNATURE)
691 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
695 return CPDF_Rect(0,0,0,0);
698 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
703 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
704 return rect.Contains(point.x, point.y);
707 //CReader_AnnotIteratorEx
709 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse,
710 FX_BOOL bIgnoreTopmost/*=FALSE*/,
711 FX_BOOL bCircle/*=FALSE*/,
712 CFX_PtrArray *pList/*=NULL*/)
716 m_bIgnoreTopmost= bIgnoreTopmost;
718 m_pIteratorAnnotList.RemoveAll();
719 InitIteratorAnnotList(pPageView,pList);
722 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent)
726 int nCount = m_pIteratorAnnotList.GetSize();
728 for(int i=0;i<nCount;i++){
729 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i);
730 if(pReaderAnnot ==pCurrent){
736 return NextAnnot(index);
738 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent)
741 int nCount = m_pIteratorAnnotList.GetSize();
743 for(int i=0;i<nCount;i++){
744 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
745 if(pReaderAnnot ==pCurrent){
751 return PrevAnnot(index);
753 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index)
756 int nCount=m_pIteratorAnnotList.GetSize();
757 if(nCount<=0) index=-1;
764 index=( index <nCount-1) ? (index+1) :0;
767 index=( index <nCount-1) ? (index+1) :-1;
772 return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
776 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index)
779 int nCount=m_pIteratorAnnotList.GetSize();
780 if(nCount<=0) index=-1;
787 index = ( index >0) ? (index-1) :nCount-1;
790 index = ( index >0) ? (index-1) :-1;
794 return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
798 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent)
801 return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent);
805 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent)
808 return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent);
811 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index )
814 return (m_bReverse) ? PrevAnnot(index):NextAnnot(index);
818 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index )
821 return (m_bReverse) ? NextAnnot(index):PrevAnnot(index);
825 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare)
827 for (int i = 1; i < arrayList.GetSize(); i++)
829 if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0)
832 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
836 arrayList[j + 1] = arrayList[j];
837 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
839 arrayList[j+1] = pTemp;
844 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
846 if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
848 if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
853 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView,CFX_PtrArray * pAnnotList)
857 if(pAnnotList==NULL){
858 pAnnotList=pPageView->GetAnnotList();
861 m_pIteratorAnnotList.RemoveAll();
862 if(!pAnnotList) return FALSE;
864 CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
867 int nCount =pAnnotList->GetSize();
869 for(int i = nCount- 1 ;i >= 0;i--)
871 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i);
872 m_pIteratorAnnotList.Add(pReaderAnnot);
875 InsertSort(m_pIteratorAnnotList,&LyOrderCompare);
879 for(int i=0 ;i<nCount;i++)
881 CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
882 if(pReaderAnnot == pTopMostAnnot)
884 m_pIteratorAnnotList.RemoveAt(i);
885 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);