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 |
14 namespace { | |
15 | |
16 bool LayoutOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | |
Tom Sepez
2015/10/23 15:54:48
nit: This is actually LayoutOrderLessThan(), xxxCo
Lei Zhang
2015/10/24 01:01:23
Done.
| |
17 return p1->GetLayoutOrder() < p2->GetLayoutOrder(); | |
18 } | |
19 | |
20 } // namespace | |
21 | |
12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { | 22 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { |
13 m_pApp = pApp; | 23 m_pApp = pApp; |
14 | 24 |
15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | 25 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | 26 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
17 RegisterAnnotHandler(pHandler); | 27 RegisterAnnotHandler(pHandler); |
18 } | 28 } |
19 | 29 |
20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | 30 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { |
21 for (int i = 0; i < m_Handlers.GetSize(); i++) { | 31 for (int i = 0; i < m_Handlers.GetSize(); i++) { |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | 652 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
643 CPDFSDK_Annot* pAnnot, | 653 CPDFSDK_Annot* pAnnot, |
644 const CPDF_Point& point) { | 654 const CPDF_Point& point) { |
645 ASSERT(pPageView); | 655 ASSERT(pPageView); |
646 ASSERT(pAnnot); | 656 ASSERT(pAnnot); |
647 | 657 |
648 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); | 658 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); |
649 return rect.Contains(point.x, point.y); | 659 return rect.Contains(point.x, point.y); |
650 } | 660 } |
651 | 661 |
652 // CReader_AnnotIteratorEx | 662 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, |
663 bool bReverse) | |
664 : m_bReverse(bReverse), m_pos(0) { | |
665 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); | |
666 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(), | |
667 annots.rend()); | |
668 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), | |
669 LayoutOrderCompare); | |
653 | 670 |
654 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, | 671 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); |
655 FX_BOOL bReverse, | 672 if (!pTopMostAnnot) |
656 FX_BOOL bIgnoreTopmost /*=FALSE*/, | 673 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 | 674 |
667 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) { | 675 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), |
668 int index = -1; | 676 pTopMostAnnot); |
669 int nCount = m_pIteratorAnnotList.GetSize(); | 677 if (it != m_iteratorAnnotList.end()) { |
670 if (pCurrent) { | 678 CPDFSDK_Annot* pReaderAnnot = *it; |
671 for (int i = 0; i < nCount; i++) { | 679 m_iteratorAnnotList.erase(it); |
672 CPDFSDK_Annot* pReaderAnnot = | 680 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 } | 681 } |
764 } | 682 } |
765 | 683 |
766 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | 684 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 } | 685 } |
773 | 686 |
774 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList( | 687 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() { |
775 CPDFSDK_PageView* pPageView, | 688 if (m_pos >= m_iteratorAnnotList.size()) |
Tom Sepez
2015/10/23 15:54:48
nit: could you flip this around? My small brain u
Lei Zhang
2015/10/24 01:01:23
Done.
| |
776 CFX_PtrArray* pAnnotList) { | 689 return nullptr; |
777 ASSERT(pPageView); | |
778 | 690 |
779 if (pAnnotList == NULL) { | 691 return m_iteratorAnnotList[m_pos++]; |
780 pAnnotList = pPageView->GetAnnotList(); | 692 } |
781 } | |
782 | 693 |
783 m_pIteratorAnnotList.RemoveAll(); | 694 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { |
784 if (!pAnnotList) | 695 if (m_pos >= m_iteratorAnnotList.size()) |
785 return FALSE; | 696 return nullptr; |
786 | 697 |
787 CPDFSDK_Annot* pTopMostAnnot = | 698 const size_t oldIndex = m_iteratorAnnotList.size() - m_pos - 1; |
788 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); | 699 ++m_pos; |
Tom Sepez
2015/10/23 15:54:48
nit: maybe combine with previous line as - m_pos++
Tom Sepez
2015/10/23 16:05:04
And isn't x - m_pos++ - 1 == x - ++m_pos ? So mayb
Lei Zhang
2015/10/24 01:01:23
Done.
Lei Zhang
2015/10/24 01:01:23
Acknowledged.
| |
700 return m_iteratorAnnotList[oldIndex]; | |
701 } | |
789 | 702 |
790 int nCount = pAnnotList->GetSize(); | 703 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { |
791 | 704 return m_bReverse ? PrevAnnot() : NextAnnot(); |
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 } | 705 } |
OLD | NEW |