OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
8 #include "../include/fsdk_mgr.h" | 10 #include "../include/fsdk_mgr.h" |
9 #include "../include/formfiller/FFL_FormFiller.h" | 11 #include "../include/formfiller/FFL_FormFiller.h" |
10 #include "../include/fsdk_annothandler.h" | 12 #include "../include/fsdk_annothandler.h" |
11 | 13 |
12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { | 14 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { |
13 m_pApp = pApp; | 15 m_pApp = pApp; |
14 | 16 |
15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | 17 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | 18 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | 644 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
643 CPDFSDK_Annot* pAnnot, | 645 CPDFSDK_Annot* pAnnot, |
644 const CPDF_Point& point) { | 646 const CPDF_Point& point) { |
645 ASSERT(pPageView); | 647 ASSERT(pPageView); |
646 ASSERT(pAnnot); | 648 ASSERT(pAnnot); |
647 | 649 |
648 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); | 650 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); |
649 return rect.Contains(point.x, point.y); | 651 return rect.Contains(point.x, point.y); |
650 } | 652 } |
651 | 653 |
652 // CReader_AnnotIteratorEx | 654 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, |
| 655 bool bReverse) |
| 656 : m_bReverse(bReverse), m_pos(0) { |
| 657 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); |
| 658 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(), |
| 659 annots.rend()); |
| 660 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), |
| 661 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { |
| 662 return p1->GetLayoutOrder() < p2->GetLayoutOrder(); |
| 663 }); |
653 | 664 |
654 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, | 665 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); |
655 FX_BOOL bReverse, | 666 if (!pTopMostAnnot) |
656 FX_BOOL bIgnoreTopmost /*=FALSE*/, | 667 return; |
657 FX_BOOL bCircle /*=FALSE*/, | |
658 CFX_PtrArray* pList /*=NULL*/) { | |
659 ASSERT(pPageView); | |
660 m_bReverse = bReverse; | |
661 m_bIgnoreTopmost = bIgnoreTopmost; | |
662 m_bCircle = bCircle; | |
663 m_pIteratorAnnotList.RemoveAll(); | |
664 InitIteratorAnnotList(pPageView, pList); | |
665 } | |
666 | 668 |
667 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) { | 669 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), |
668 int index = -1; | 670 pTopMostAnnot); |
669 int nCount = m_pIteratorAnnotList.GetSize(); | 671 if (it != m_iteratorAnnotList.end()) { |
670 if (pCurrent) { | 672 CPDFSDK_Annot* pReaderAnnot = *it; |
671 for (int i = 0; i < nCount; i++) { | 673 m_iteratorAnnotList.erase(it); |
672 CPDFSDK_Annot* pReaderAnnot = | 674 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot); |
673 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); | |
674 if (pReaderAnnot == pCurrent) { | |
675 index = i; | |
676 break; | |
677 } | |
678 } | |
679 } | |
680 return NextAnnot(index); | |
681 } | |
682 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(const CPDFSDK_Annot* pCurrent) { | |
683 int index = -1; | |
684 int nCount = m_pIteratorAnnotList.GetSize(); | |
685 if (pCurrent) { | |
686 for (int i = 0; i < nCount; i++) { | |
687 CPDFSDK_Annot* pReaderAnnot = | |
688 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); | |
689 if (pReaderAnnot == pCurrent) { | |
690 index = i; | |
691 break; | |
692 } | |
693 } | |
694 } | |
695 return PrevAnnot(index); | |
696 } | |
697 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int& index) { | |
698 int nCount = m_pIteratorAnnotList.GetSize(); | |
699 if (nCount <= 0) | |
700 index = -1; | |
701 else { | |
702 if (index < 0) { | |
703 index = 0; | |
704 } else { | |
705 if (m_bCircle) { | |
706 index = (index < nCount - 1) ? (index + 1) : 0; | |
707 } else { | |
708 index = (index < nCount - 1) ? (index + 1) : -1; | |
709 } | |
710 } | |
711 } | |
712 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); | |
713 } | |
714 | |
715 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) { | |
716 int nCount = m_pIteratorAnnotList.GetSize(); | |
717 if (nCount <= 0) | |
718 index = -1; | |
719 else { | |
720 if (index < 0) { | |
721 index = nCount - 1; | |
722 } else { | |
723 if (m_bCircle) { | |
724 index = (index > 0) ? (index - 1) : nCount - 1; | |
725 } else { | |
726 index = (index > 0) ? (index - 1) : -1; | |
727 } | |
728 } | |
729 } | |
730 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); | |
731 } | |
732 | |
733 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) { | |
734 return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent); | |
735 } | |
736 | |
737 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) { | |
738 return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent); | |
739 } | |
740 | |
741 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) { | |
742 return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index); | |
743 } | |
744 | |
745 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) { | |
746 return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index); | |
747 } | |
748 | |
749 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray& arrayList, | |
750 AI_COMPARE pCompare) { | |
751 for (int i = 1; i < arrayList.GetSize(); i++) { | |
752 if (pCompare((CPDFSDK_Annot*)(arrayList[i]), | |
753 (CPDFSDK_Annot*)(arrayList[i - 1])) < 0) { | |
754 int j = i - 1; | |
755 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i]; | |
756 | |
757 do { | |
758 arrayList[j + 1] = arrayList[j]; | |
759 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0); | |
760 | |
761 arrayList[j + 1] = pTemp; | |
762 } | |
763 } | 675 } |
764 } | 676 } |
765 | 677 |
766 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | 678 CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() { |
767 if (p1->GetLayoutOrder() < p2->GetLayoutOrder()) | |
768 return -1; | |
769 if (p1->GetLayoutOrder() > p2->GetLayoutOrder()) | |
770 return 1; | |
771 return 0; | |
772 } | 679 } |
773 | 680 |
774 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList( | 681 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() { |
775 CPDFSDK_PageView* pPageView, | 682 if (m_pos < m_iteratorAnnotList.size()) |
776 CFX_PtrArray* pAnnotList) { | 683 return m_iteratorAnnotList[m_pos++]; |
777 ASSERT(pPageView); | 684 return nullptr; |
| 685 } |
778 | 686 |
779 if (pAnnotList == NULL) { | 687 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { |
780 pAnnotList = pPageView->GetAnnotList(); | 688 if (m_pos < m_iteratorAnnotList.size()) |
781 } | 689 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; |
| 690 return nullptr; |
| 691 } |
782 | 692 |
783 m_pIteratorAnnotList.RemoveAll(); | 693 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { |
784 if (!pAnnotList) | 694 return m_bReverse ? PrevAnnot() : NextAnnot(); |
785 return FALSE; | |
786 | |
787 CPDFSDK_Annot* pTopMostAnnot = | |
788 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); | |
789 | |
790 int nCount = pAnnotList->GetSize(); | |
791 | |
792 for (int i = nCount - 1; i >= 0; i--) { | |
793 CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i); | |
794 m_pIteratorAnnotList.Add(pReaderAnnot); | |
795 } | |
796 | |
797 InsertSort(m_pIteratorAnnotList, &LyOrderCompare); | |
798 | |
799 if (pTopMostAnnot) { | |
800 for (int i = 0; i < nCount; i++) { | |
801 CPDFSDK_Annot* pReaderAnnot = | |
802 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); | |
803 if (pReaderAnnot == pTopMostAnnot) { | |
804 m_pIteratorAnnotList.RemoveAt(i); | |
805 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); | |
806 break; | |
807 } | |
808 } | |
809 } | |
810 | |
811 return TRUE; | |
812 } | 695 } |
OLD | NEW |