| Index: fpdfsdk/src/fsdk_annothandler.cpp
|
| diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp
|
| index bb999e1f08c420f768f0b7fa9935eac71794dd2c..8f3fa2337180cdc906620b66df1d70afca6cb9db 100644
|
| --- a/fpdfsdk/src/fsdk_annothandler.cpp
|
| +++ b/fpdfsdk/src/fsdk_annothandler.cpp
|
| @@ -9,6 +9,18 @@
|
| #include "../include/formfiller/FFL_FormFiller.h"
|
| #include "../include/fsdk_annothandler.h"
|
|
|
| +namespace {
|
| +
|
| +typedef int (*AI_COMPARE)(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
|
| +
|
| +int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
|
| + if (p1->GetLayoutOrder() == p2->GetLayoutOrder())
|
| + return 0;
|
| + return (p1->GetLayoutOrder() < p2->GetLayoutOrder()) ? -1 : 1;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
|
| m_pApp = pApp;
|
|
|
| @@ -649,164 +661,93 @@ FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
|
| return rect.Contains(point.x, point.y);
|
| }
|
|
|
| -// CReader_AnnotIteratorEx
|
| -
|
| CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
|
| - FX_BOOL bReverse,
|
| - FX_BOOL bIgnoreTopmost /*=FALSE*/,
|
| - FX_BOOL bCircle /*=FALSE*/,
|
| - CFX_PtrArray* pList /*=NULL*/) {
|
| - ASSERT(pPageView);
|
| - m_bReverse = bReverse;
|
| - m_bIgnoreTopmost = bIgnoreTopmost;
|
| - m_bCircle = bCircle;
|
| - m_pIteratorAnnotList.RemoveAll();
|
| - InitIteratorAnnotList(pPageView, pList);
|
| -}
|
| + bool bReverse)
|
| + : m_bReverse(bReverse) {
|
| + CFX_PtrArray* pAnnotList = pPageView->GetAnnotList();
|
| + if (!pAnnotList)
|
| + return;
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) {
|
| - int index = -1;
|
| - int nCount = m_pIteratorAnnotList.GetSize();
|
| - if (pCurrent) {
|
| - for (int i = 0; i < nCount; i++) {
|
| - CPDFSDK_Annot* pReaderAnnot =
|
| - (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
|
| - if (pReaderAnnot == pCurrent) {
|
| - index = i;
|
| - break;
|
| - }
|
| + CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
|
| +
|
| + const int nCount = pAnnotList->GetSize();
|
| + for (int i = nCount - 1; i >= 0; --i)
|
| + m_pIteratorAnnotList.Add(static_cast<CPDFSDK_Annot*>(pAnnotList->GetAt(i)));
|
| + InsertSort();
|
| +
|
| + if (!pTopMostAnnot)
|
| + return;
|
| +
|
| + for (int i = 0; i < nCount; ++i) {
|
| + CPDFSDK_Annot* pReaderAnnot =
|
| + static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(i));
|
| + if (pReaderAnnot == pTopMostAnnot) {
|
| + m_pIteratorAnnotList.RemoveAt(i);
|
| + m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
|
| + break;
|
| }
|
| }
|
| - return NextAnnot(index);
|
| }
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(const CPDFSDK_Annot* pCurrent) {
|
| - int index = -1;
|
| - int nCount = m_pIteratorAnnotList.GetSize();
|
| - if (pCurrent) {
|
| - for (int i = 0; i < nCount; i++) {
|
| - CPDFSDK_Annot* pReaderAnnot =
|
| - (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
|
| - if (pReaderAnnot == pCurrent) {
|
| - index = i;
|
| - break;
|
| - }
|
| - }
|
| - }
|
| - return PrevAnnot(index);
|
| +
|
| +CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {
|
| }
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int& index) {
|
| +
|
| +CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int* index) {
|
| int nCount = m_pIteratorAnnotList.GetSize();
|
| - if (nCount <= 0)
|
| - index = -1;
|
| - else {
|
| - if (index < 0) {
|
| - index = 0;
|
| - } else {
|
| - if (m_bCircle) {
|
| - index = (index < nCount - 1) ? (index + 1) : 0;
|
| - } else {
|
| - index = (index < nCount - 1) ? (index + 1) : -1;
|
| - }
|
| - }
|
| + if (nCount <= 0) {
|
| + *index = -1;
|
| + return nullptr;
|
| }
|
| - return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
|
| +
|
| + if (*index < 0)
|
| + *index = 0;
|
| + else
|
| + *index = (*index < nCount - 1) ? (*index + 1) : -1;
|
| +
|
| + if (*index < 0)
|
| + return nullptr;
|
| + return static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(*index));
|
| }
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) {
|
| +CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int* index) {
|
| int nCount = m_pIteratorAnnotList.GetSize();
|
| - if (nCount <= 0)
|
| - index = -1;
|
| - else {
|
| - if (index < 0) {
|
| - index = nCount - 1;
|
| - } else {
|
| - if (m_bCircle) {
|
| - index = (index > 0) ? (index - 1) : nCount - 1;
|
| - } else {
|
| - index = (index > 0) ? (index - 1) : -1;
|
| - }
|
| - }
|
| + if (nCount <= 0) {
|
| + *index = -1;
|
| + return nullptr;
|
| }
|
| - return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
|
| -}
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) {
|
| - return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent);
|
| -}
|
| + if (*index < 0)
|
| + *index = nCount - 1;
|
| + else
|
| + *index = (*index > 0) ? (*index - 1) : -1;
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) {
|
| - return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent);
|
| + if (*index < 0)
|
| + return nullptr;
|
| + return static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(*index));
|
| }
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) {
|
| - return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index);
|
| +CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int* index) {
|
| + return m_bReverse ? PrevAnnot(index) : NextAnnot(index);
|
| }
|
|
|
| -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) {
|
| - return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index);
|
| +CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int* index) {
|
| + return m_bReverse ? NextAnnot(index) : PrevAnnot(index);
|
| }
|
|
|
| -void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray& arrayList,
|
| - AI_COMPARE pCompare) {
|
| - for (int i = 1; i < arrayList.GetSize(); i++) {
|
| - if (pCompare((CPDFSDK_Annot*)(arrayList[i]),
|
| - (CPDFSDK_Annot*)(arrayList[i - 1])) < 0) {
|
| +void CPDFSDK_AnnotIterator::InsertSort() {
|
| + for (int i = 1; i < m_pIteratorAnnotList.GetSize(); ++i) {
|
| + if (LyOrderCompare((CPDFSDK_Annot*)(m_pIteratorAnnotList[i]),
|
| + (CPDFSDK_Annot*)(m_pIteratorAnnotList[i - 1])) < 0) {
|
| int j = i - 1;
|
| - CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
|
| + CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)m_pIteratorAnnotList[i];
|
|
|
| do {
|
| - arrayList[j + 1] = arrayList[j];
|
| - } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
|
| -
|
| - arrayList[j + 1] = pTemp;
|
| - }
|
| - }
|
| -}
|
| -
|
| -int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
|
| - if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
|
| - return -1;
|
| - if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
|
| - return 1;
|
| - return 0;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(
|
| - CPDFSDK_PageView* pPageView,
|
| - CFX_PtrArray* pAnnotList) {
|
| - ASSERT(pPageView);
|
| -
|
| - if (pAnnotList == NULL) {
|
| - pAnnotList = pPageView->GetAnnotList();
|
| - }
|
| -
|
| - m_pIteratorAnnotList.RemoveAll();
|
| - if (!pAnnotList)
|
| - return FALSE;
|
| -
|
| - CPDFSDK_Annot* pTopMostAnnot =
|
| - (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
|
| + m_pIteratorAnnotList[j + 1] = m_pIteratorAnnotList[j];
|
| + } while (--j >= 0 &&
|
| + LyOrderCompare(pTemp, (CPDFSDK_Annot*)m_pIteratorAnnotList[j]) <
|
| + 0);
|
|
|
| - int nCount = pAnnotList->GetSize();
|
| -
|
| - for (int i = nCount - 1; i >= 0; i--) {
|
| - CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i);
|
| - m_pIteratorAnnotList.Add(pReaderAnnot);
|
| - }
|
| -
|
| - InsertSort(m_pIteratorAnnotList, &LyOrderCompare);
|
| -
|
| - if (pTopMostAnnot) {
|
| - for (int i = 0; i < nCount; i++) {
|
| - CPDFSDK_Annot* pReaderAnnot =
|
| - (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
|
| - if (pReaderAnnot == pTopMostAnnot) {
|
| - m_pIteratorAnnotList.RemoveAt(i);
|
| - m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
|
| - break;
|
| - }
|
| + m_pIteratorAnnotList[j + 1] = pTemp;
|
| }
|
| }
|
| -
|
| - return TRUE;
|
| }
|
|
|