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"
12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
16 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
17 RegisterAnnotHandler(pHandler);
20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
21 for (int i = 0; i < m_Handlers.GetSize(); i++) {
22 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
25 m_Handlers.RemoveAll();
26 m_mapType2Handler.RemoveAll();
29 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
30 IPDFSDK_AnnotHandler* pAnnotHandler) {
31 ASSERT(pAnnotHandler != NULL);
33 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);
35 m_Handlers.Add(pAnnotHandler);
36 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);
39 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
40 IPDFSDK_AnnotHandler* pAnnotHandler) {
41 ASSERT(pAnnotHandler != NULL);
43 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());
45 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
46 if (m_Handlers.GetAt(i) == pAnnotHandler) {
47 m_Handlers.RemoveAt(i);
53 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
54 CPDFSDK_PageView* pPageView) {
55 ASSERT(pAnnot != NULL);
56 ASSERT(pPageView != NULL);
58 if (IPDFSDK_AnnotHandler* pAnnotHandler =
59 GetAnnotHandler(pAnnot->GetSubType())) {
60 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
63 return new CPDFSDK_Annot(pAnnot, pPageView);
66 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
67 ASSERT(pAnnot != NULL);
71 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
72 pAnnotHandler->OnRelease(pAnnot);
73 pAnnotHandler->ReleaseAnnot(pAnnot);
75 delete (CPDFSDK_Annot*)pAnnot;
79 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
80 ASSERT(pAnnot != NULL);
82 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
84 CPDFSDK_DateTime curTime;
85 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
86 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
88 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
89 pAnnotHandler->OnCreate(pAnnot);
93 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
94 ASSERT(pAnnot != NULL);
96 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
97 pAnnotHandler->OnLoad(pAnnot);
101 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
102 CPDFSDK_Annot* pAnnot) const {
103 ASSERT(pAnnot != NULL);
105 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
106 ASSERT(pPDFAnnot != NULL);
108 return GetAnnotHandler(pPDFAnnot->GetSubType());
111 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
112 const CFX_ByteString& sType) const {
114 m_mapType2Handler.Lookup(sType, pRet);
115 return (IPDFSDK_AnnotHandler*)pRet;
118 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
119 CPDFSDK_Annot* pAnnot,
120 CFX_RenderDevice* pDevice,
121 CPDF_Matrix* pUser2Device,
123 ASSERT(pAnnot != NULL);
125 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
126 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
128 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
132 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
133 CPDFSDK_PageView* pPageView,
134 CPDFSDK_Annot* pAnnot,
136 const CPDF_Point& point) {
137 ASSERT(pAnnot != NULL);
139 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
140 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
144 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView* pPageView,
145 CPDFSDK_Annot* pAnnot,
147 const CPDF_Point& point) {
148 ASSERT(pAnnot != NULL);
150 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
151 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
155 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
156 CPDFSDK_PageView* pPageView,
157 CPDFSDK_Annot* pAnnot,
159 const CPDF_Point& point) {
160 ASSERT(pAnnot != NULL);
162 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
163 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
167 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView* pPageView,
168 CPDFSDK_Annot* pAnnot,
170 const CPDF_Point& point) {
171 ASSERT(pAnnot != NULL);
173 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
174 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
178 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView* pPageView,
179 CPDFSDK_Annot* pAnnot,
182 const CPDF_Point& point) {
183 ASSERT(pAnnot != NULL);
185 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
186 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
191 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
192 CPDFSDK_PageView* pPageView,
193 CPDFSDK_Annot* pAnnot,
195 const CPDF_Point& point) {
196 ASSERT(pAnnot != NULL);
198 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
199 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
203 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView* pPageView,
204 CPDFSDK_Annot* pAnnot,
206 const CPDF_Point& point) {
207 ASSERT(pAnnot != NULL);
209 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
210 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
215 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
216 CPDFSDK_Annot* pAnnot,
218 ASSERT(pAnnot != NULL);
220 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
221 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
226 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
227 CPDFSDK_Annot* pAnnot,
229 ASSERT(pAnnot != NULL);
231 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
232 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
237 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
240 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
241 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
246 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
249 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
250 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
251 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
252 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
253 CPDFSDK_Annot* pNext =
254 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
256 if (pNext && pNext != pFocusAnnot) {
257 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
258 pDocument->SetFocusAnnot(pNext);
264 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
265 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
269 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
275 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
277 ASSERT(pAnnot != NULL);
279 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
280 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
281 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
282 pPage->GetSDKDocument();
289 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
292 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
293 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
298 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
299 CPDFSDK_PageView* pPageView,
300 CPDFSDK_Annot* pAnnot) {
302 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
303 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
305 return pAnnot->GetRect();
308 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
309 CPDFSDK_Annot* pAnnot,
310 const CPDF_Point& point) {
312 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
313 if (pAnnotHandler->CanAnswer(pAnnot))
314 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
319 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
321 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
322 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
325 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
326 ASSERT(pAnnot->GetType() == "Widget");
327 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
330 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
331 if (!pWidget->IsVisible())
334 int nFieldFlags = pWidget->GetFieldFlags();
335 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
338 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
341 CPDF_Page* pPage = pWidget->GetPDFPage();
342 CPDF_Document* pDocument = pPage->m_pDocument;
343 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
344 return (dwPermissions & FPDFPERM_FILL_FORM) ||
345 (dwPermissions & FPDFPERM_ANNOT_FORM);
348 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
349 CPDFSDK_PageView* pPage) {
350 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
351 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
352 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
353 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
357 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
358 pInterForm->AddMap(pCtrl, pWidget);
359 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
360 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
361 pWidget->ResetAppearance(nullptr, FALSE);
366 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
367 ASSERT(pAnnot != NULL);
370 m_pFormFiller->OnDelete(pAnnot);
372 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
373 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
374 ASSERT(pInterForm != NULL);
376 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
377 pInterForm->RemoveMap(pCtrol);
382 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
383 CPDFSDK_Annot* pAnnot,
384 CFX_RenderDevice* pDevice,
385 CPDF_Matrix* pUser2Device,
387 ASSERT(pAnnot != NULL);
388 CFX_ByteString sSubType = pAnnot->GetSubType();
390 if (sSubType == BFFT_SIGNATURE) {
391 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
394 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
399 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
400 CPDFSDK_Annot* pAnnot,
402 ASSERT(pAnnot != NULL);
403 CFX_ByteString sSubType = pAnnot->GetSubType();
405 if (sSubType == BFFT_SIGNATURE) {
408 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
411 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
412 CPDFSDK_Annot* pAnnot,
414 ASSERT(pAnnot != NULL);
415 CFX_ByteString sSubType = pAnnot->GetSubType();
417 if (sSubType == BFFT_SIGNATURE) {
420 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
423 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
424 CPDFSDK_Annot* pAnnot,
426 const CPDF_Point& point) {
427 ASSERT(pAnnot != NULL);
428 CFX_ByteString sSubType = pAnnot->GetSubType();
430 if (sSubType == BFFT_SIGNATURE) {
433 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
439 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
440 CPDFSDK_Annot* pAnnot,
442 const CPDF_Point& point) {
443 ASSERT(pAnnot != NULL);
444 CFX_ByteString sSubType = pAnnot->GetSubType();
446 if (sSubType == BFFT_SIGNATURE) {
449 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
455 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
456 CPDFSDK_Annot* pAnnot,
458 const CPDF_Point& point) {
459 ASSERT(pAnnot != NULL);
460 CFX_ByteString sSubType = pAnnot->GetSubType();
462 if (sSubType == BFFT_SIGNATURE) {
465 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
471 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
472 CPDFSDK_Annot* pAnnot,
474 const CPDF_Point& point) {
475 ASSERT(pAnnot != NULL);
476 CFX_ByteString sSubType = pAnnot->GetSubType();
478 if (sSubType == BFFT_SIGNATURE) {
481 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
487 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
488 CPDFSDK_Annot* pAnnot,
491 const CPDF_Point& point) {
492 ASSERT(pAnnot != NULL);
493 CFX_ByteString sSubType = pAnnot->GetSubType();
495 if (sSubType == BFFT_SIGNATURE) {
498 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
505 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
506 CPDFSDK_Annot* pAnnot,
508 const CPDF_Point& point) {
509 ASSERT(pAnnot != NULL);
510 CFX_ByteString sSubType = pAnnot->GetSubType();
512 if (sSubType == BFFT_SIGNATURE) {
515 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
520 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
521 CPDFSDK_Annot* pAnnot,
523 const CPDF_Point& point) {
524 ASSERT(pAnnot != NULL);
525 CFX_ByteString sSubType = pAnnot->GetSubType();
527 if (sSubType == BFFT_SIGNATURE) {
530 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
536 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
539 ASSERT(pAnnot != NULL);
540 CFX_ByteString sSubType = pAnnot->GetSubType();
542 if (sSubType == BFFT_SIGNATURE) {
545 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
551 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
554 ASSERT(pAnnot != NULL);
555 CFX_ByteString sSubType = pAnnot->GetSubType();
557 if (sSubType == BFFT_SIGNATURE) {
560 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
566 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
571 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
572 ASSERT(pAnnot != NULL);
573 CFX_ByteString sSubType = pAnnot->GetSubType();
575 if (sSubType == BFFT_SIGNATURE) {
578 m_pFormFiller->OnCreate(pAnnot);
582 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
583 ASSERT(pAnnot != NULL);
585 CFX_ByteString sSubType = pAnnot->GetSubType();
587 if (sSubType == BFFT_SIGNATURE) {
589 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
590 if (!pWidget->IsAppearanceValid())
591 pWidget->ResetAppearance(NULL, FALSE);
593 int nFieldType = pWidget->GetFieldType();
594 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
595 FX_BOOL bFormated = FALSE;
596 CFX_WideString sValue = pWidget->OnFormat(bFormated);
597 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
598 pWidget->ResetAppearance(sValue.c_str(), FALSE);
603 m_pFormFiller->OnLoad(pAnnot);
607 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
609 ASSERT(pAnnot != NULL);
610 CFX_ByteString sSubType = pAnnot->GetSubType();
612 if (sSubType == BFFT_SIGNATURE) {
615 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
620 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
622 ASSERT(pAnnot != NULL);
623 CFX_ByteString sSubType = pAnnot->GetSubType();
625 if (sSubType == BFFT_SIGNATURE) {
628 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
634 CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
635 CPDFSDK_Annot* pAnnot) {
636 ASSERT(pAnnot != NULL);
637 CFX_ByteString sSubType = pAnnot->GetSubType();
639 if (sSubType == BFFT_SIGNATURE) {
642 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
645 return CPDF_Rect(0, 0, 0, 0);
648 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
649 CPDFSDK_Annot* pAnnot,
650 const CPDF_Point& point) {
654 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
655 return rect.Contains(point.x, point.y);
658 // CReader_AnnotIteratorEx
660 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
662 FX_BOOL bIgnoreTopmost /*=FALSE*/,
663 FX_BOOL bCircle /*=FALSE*/,
664 CFX_PtrArray* pList /*=NULL*/) {
666 m_bReverse = bReverse;
667 m_bIgnoreTopmost = bIgnoreTopmost;
669 m_pIteratorAnnotList.RemoveAll();
670 InitIteratorAnnotList(pPageView, pList);
673 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) {
675 int nCount = m_pIteratorAnnotList.GetSize();
677 for (int i = 0; i < nCount; i++) {
678 CPDFSDK_Annot* pReaderAnnot =
679 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
680 if (pReaderAnnot == pCurrent) {
686 return NextAnnot(index);
688 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(const CPDFSDK_Annot* pCurrent) {
690 int nCount = m_pIteratorAnnotList.GetSize();
692 for (int i = 0; i < nCount; i++) {
693 CPDFSDK_Annot* pReaderAnnot =
694 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
695 if (pReaderAnnot == pCurrent) {
701 return PrevAnnot(index);
703 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int& index) {
704 int nCount = m_pIteratorAnnotList.GetSize();
712 index = (index < nCount - 1) ? (index + 1) : 0;
714 index = (index < nCount - 1) ? (index + 1) : -1;
718 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
721 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) {
722 int nCount = m_pIteratorAnnotList.GetSize();
730 index = (index > 0) ? (index - 1) : nCount - 1;
732 index = (index > 0) ? (index - 1) : -1;
736 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
739 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) {
740 return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent);
743 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) {
744 return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent);
747 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) {
748 return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index);
751 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) {
752 return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index);
755 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray& arrayList,
756 AI_COMPARE pCompare) {
757 for (int i = 1; i < arrayList.GetSize(); i++) {
758 if (pCompare((CPDFSDK_Annot*)(arrayList[i]),
759 (CPDFSDK_Annot*)(arrayList[i - 1])) < 0) {
761 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
764 arrayList[j + 1] = arrayList[j];
765 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
767 arrayList[j + 1] = pTemp;
772 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
773 if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
775 if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
780 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(
781 CPDFSDK_PageView* pPageView,
782 CFX_PtrArray* pAnnotList) {
785 if (pAnnotList == NULL) {
786 pAnnotList = pPageView->GetAnnotList();
789 m_pIteratorAnnotList.RemoveAll();
793 CPDFSDK_Annot* pTopMostAnnot =
794 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
796 int nCount = pAnnotList->GetSize();
798 for (int i = nCount - 1; i >= 0; i--) {
799 CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i);
800 m_pIteratorAnnotList.Add(pReaderAnnot);
803 InsertSort(m_pIteratorAnnotList, &LyOrderCompare);
806 for (int i = 0; i < nCount; i++) {
807 CPDFSDK_Annot* pReaderAnnot =
808 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
809 if (pReaderAnnot == pTopMostAnnot) {
810 m_pIteratorAnnotList.RemoveAt(i);
811 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);