summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-26 12:14:35 -0700
committerLei Zhang <thestig@chromium.org>2015-10-26 12:14:35 -0700
commitbf60b29fc07c668022fc06517782aeda25e8246c (patch)
treee96c1f8ffbe2ce381c3b45ed3da8ac8cf682dc03 /fpdfsdk
parent56a547dd81202c49d01232c358a28db886fd46ed (diff)
downloadpdfium-bf60b29fc07c668022fc06517782aeda25e8246c.tar.xz
Merge to XFA: Cleanup parts of CPDFSDK_AnnotIterator and CPDFSDK_PageView.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1411203007 . (cherry picked from commit 9b2741829b8a8c511ef0f2f313ff53d77ac96307) Review URL: https://codereview.chromium.org/1408263005 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/fsdk_annothandler.h47
-rw-r--r--fpdfsdk/include/fsdk_mgr.h17
-rw-r--r--fpdfsdk/src/fsdk_annothandler.cpp185
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp6
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp176
5 files changed, 131 insertions, 300 deletions
diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h
index c15681de96..6ce9e1229a 100644
--- a/fpdfsdk/include/fsdk_annothandler.h
+++ b/fpdfsdk/include/fsdk_annothandler.h
@@ -8,6 +8,7 @@
#define FPDFSDK_INCLUDE_FSDK_ANNOTHANDLER_H_
#include <map>
+#include <vector>
#include "../../core/include/fxcrt/fx_basic.h"
@@ -129,7 +130,7 @@ class IPDFSDK_AnnotHandler {
class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler {
public:
- CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
+ explicit CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
: m_pApp(pApp), m_pFormFiller(NULL) {}
~CPDFSDK_BFAnnotHandler() override {}
@@ -227,7 +228,7 @@ class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler {
class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler {
public:
- CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp);
+ explicit CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp);
~CPDFSDK_XFAAnnotHandler() {}
public:
@@ -433,38 +434,20 @@ class CPDFSDK_AnnotHandlerMgr {
CPDFDoc_Environment* m_pApp;
};
-typedef int (*AI_COMPARE)(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
-
class CPDFSDK_AnnotIterator {
public:
- CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
- FX_BOOL bReverse,
- FX_BOOL bIgnoreTopmost = FALSE,
- FX_BOOL bCircle = FALSE,
- CFX_PtrArray* pList = NULL);
- virtual ~CPDFSDK_AnnotIterator() {}
-
- virtual CPDFSDK_Annot* Next(const CPDFSDK_Annot* pCurrent);
- virtual CPDFSDK_Annot* Prev(const CPDFSDK_Annot* pCurrent);
- virtual CPDFSDK_Annot* Next(int& index);
- virtual CPDFSDK_Annot* Prev(int& index);
- virtual int Count() { return m_pIteratorAnnotList.GetSize(); }
-
- virtual FX_BOOL InitIteratorAnnotList(CPDFSDK_PageView* pPageView,
- CFX_PtrArray* pList = NULL);
-
- void InsertSort(CFX_PtrArray& arrayList, AI_COMPARE pCompare);
-
- protected:
- CPDFSDK_Annot* NextAnnot(const CPDFSDK_Annot* pCurrent);
- CPDFSDK_Annot* PrevAnnot(const CPDFSDK_Annot* pCurrent);
- CPDFSDK_Annot* NextAnnot(int& index);
- CPDFSDK_Annot* PrevAnnot(int& index);
-
- CFX_PtrArray m_pIteratorAnnotList;
- FX_BOOL m_bReverse;
- FX_BOOL m_bIgnoreTopmost;
- FX_BOOL m_bCircle;
+ CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, bool bReverse);
+ ~CPDFSDK_AnnotIterator();
+
+ CPDFSDK_Annot* Next();
+
+ private:
+ CPDFSDK_Annot* NextAnnot();
+ CPDFSDK_Annot* PrevAnnot();
+
+ std::vector<CPDFSDK_Annot*> m_iteratorAnnotList;
+ const bool m_bReverse;
+ size_t m_pos;
};
#endif // FPDFSDK_INCLUDE_FSDK_ANNOTHANDLER_H_
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 300ca2287e..d19c9233d7 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -12,6 +12,7 @@
#include "../../core/include/fpdftext/fpdf_text.h"
#include "../../public/fpdf_formfill.h"
#include "../../public/fpdf_fwlevent.h" // cross platform keycode and events define.
+#include "../../third_party/base/nonstd_unique_ptr.h"
#include "fsdk_common.h"
#include "fsdk_define.h"
#include "fx_systemhandler.h"
@@ -554,8 +555,8 @@ class CPDFSDK_PageView final {
CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
- int CountAnnots();
- CPDFSDK_Annot* GetAnnot(int nIndex);
+ int CountAnnots() const;
+ CPDFSDK_Annot* GetAnnot(size_t nIndex);
CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
@@ -575,11 +576,13 @@ class CPDFSDK_PageView final {
double deltaY,
const CPDF_Point& point,
int nFlag);
- FX_BOOL IsValidAnnot(void* p);
+ FX_BOOL IsValidAnnot(CPDF_Annot* p) const;
void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; }
void UpdateRects(CFX_RectArray& rects);
void UpdateView(CPDFSDK_Annot* pAnnot);
- CFX_PtrArray* GetAnnotList() { return &m_fxAnnotArray; }
+ const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
+ return m_fxAnnotArray;
+ }
int GetPageIndex();
void LoadFXAnnots();
@@ -591,11 +594,11 @@ class CPDFSDK_PageView final {
private:
void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
CPDFSDK_Widget* pWidget);
+
CPDF_Matrix m_curMatrix;
CPDFXFA_Page* m_page;
- CPDF_AnnotList* m_pAnnotList;
- // CPDFSDK_Annot* m_pFocusAnnot;
- CFX_PtrArray m_fxAnnotArray;
+ nonstd::unique_ptr<CPDF_AnnotList> m_pAnnotList;
+ std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
CPDFSDK_Document* m_pSDKDoc;
CPDFSDK_Annot* m_CaptureWidget;
FX_BOOL m_bEnterWidget;
diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp
index 11d2aef928..f17ebf1270 100644
--- a/fpdfsdk/src/fsdk_annothandler.cpp
+++ b/fpdfsdk/src/fsdk_annothandler.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "../include/fsdk_define.h"
#include "../include/fpdfxfa/fpdfxfa_doc.h"
#include "../include/fpdfxfa/fpdfxfa_util.h"
@@ -733,8 +735,6 @@ FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
return rect.Contains(point.x, point.y);
}
-// CPDFSDK_XFAAnnotHandler
-
#define FWL_WGTHITTEST_Unknown 0
#define FWL_WGTHITTEST_Client 1 // arrow
#define FWL_WGTHITTEST_Titlebar 11 // caption
@@ -1156,164 +1156,45 @@ FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) {
return dwFWLFlag;
}
-// 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);
-}
-
-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;
- }
- }
- }
- 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_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;
- }
- }
- }
- return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(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;
- }
- }
- }
- 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);
-}
-
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) {
- return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent);
-}
+ bool bReverse)
+ : m_bReverse(bReverse), m_pos(0) {
+ const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
+ annots.rend());
+ std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
+ return p1->GetLayoutOrder() < p2->GetLayoutOrder();
+ });
+
+ CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
+ if (!pTopMostAnnot)
+ return;
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) {
- return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index);
+ auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ pTopMostAnnot);
+ if (it != m_iteratorAnnotList.end()) {
+ CPDFSDK_Annot* pReaderAnnot = *it;
+ m_iteratorAnnotList.erase(it);
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
+ }
}
-CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) {
- return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index);
+CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {
}
-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) {
- int j = i - 1;
- CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
-
- do {
- arrayList[j + 1] = arrayList[j];
- } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
-
- arrayList[j + 1] = pTemp;
- }
- }
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_pos++];
+ return nullptr;
}
-int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
- if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
- return -1;
- if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
- return 1;
- return 0;
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
+ return nullptr;
}
-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();
-
- 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;
- }
- }
- }
-
- return TRUE;
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
+ return m_bReverse ? PrevAnnot() : NextAnnot();
}
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index bad8f3591a..112149370b 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -3120,7 +3120,7 @@ void CBA_AnnotIterator::GenerateResults() {
switch (m_nTabs) {
case BAI_STRUCTURE: {
- for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
+ for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
ASSERT(pAnnot != NULL);
@@ -3132,7 +3132,7 @@ void CBA_AnnotIterator::GenerateResults() {
CPDFSDK_SortAnnots sa;
{
- for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
+ for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
ASSERT(pAnnot != NULL);
@@ -3211,7 +3211,7 @@ void CBA_AnnotIterator::GenerateResults() {
CPDFSDK_SortAnnots sa;
{
- for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
+ for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
ASSERT(pAnnot != NULL);
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index a698453c04..c421673f15 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "../../public/fpdf_ext.h"
#include "../../third_party/base/nonstd_unique_ptr.h"
#include "../include/formfiller/FFL_FormFiller.h"
@@ -24,7 +26,8 @@
class CFX_SystemHandler : public IFX_SystemHandler {
public:
- CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv), m_nCharSet(-1) {}
+ explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv)
+ : m_pEnv(pEnv), m_nCharSet(-1) {}
~CFX_SystemHandler() override {}
public:
@@ -638,47 +641,38 @@ CFX_WideString CPDFSDK_Document::GetPath() {
CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,
CPDFXFA_Page* page)
- : m_page(page), m_pSDKDoc(pSDKDoc) {
+ : m_page(page),
+ m_pSDKDoc(pSDKDoc),
+ m_CaptureWidget(nullptr),
+ m_bEnterWidget(FALSE),
+ m_bExitWidget(FALSE),
+ m_bOnWidget(FALSE),
+ m_bValid(FALSE),
+ m_bLocked(FALSE) {
CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
if (pInterForm) {
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
if (page->GetPDFPage())
pPDFInterForm->FixPageFields(page->GetPDFPage());
}
- m_fxAnnotArray.RemoveAll();
-
- m_bEnterWidget = FALSE;
- m_bExitWidget = FALSE;
- m_bOnWidget = FALSE;
- m_CaptureWidget = NULL;
- m_bValid = FALSE;
- m_bLocked = FALSE;
- m_pAnnotList = NULL;
}
CPDFSDK_PageView::~CPDFSDK_PageView() {
// if there is a focused annot on the page, we should kill the focus first.
if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) {
- for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
- if (pAnnot == focusedAnnot) {
- KillFocusAnnot();
- break;
- }
- }
+ auto it =
+ std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), focusedAnnot);
+ if (it != m_fxAnnotArray.end())
+ KillFocusAnnot();
}
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr);
- for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray)
pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
- }
- m_fxAnnotArray.RemoveAll();
+ m_fxAnnotArray.clear();
- delete m_pAnnotList;
- m_pAnnotList = NULL;
+ m_pAnnotList.reset();
}
void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
@@ -719,9 +713,8 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
#endif // PDF_ENABLE_XFA
// for pdf/static xfa.
- CPDFSDK_AnnotIterator annotIterator(this, TRUE);
- int index = -1;
- while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next(index)) {
+ CPDFSDK_AnnotIterator annotIterator(this, true);
+ while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
}
@@ -729,7 +722,7 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
FX_FLOAT pageY) {
- int nCount = m_pAnnotList->Count();
+ int nCount = CountAnnots();
for (int i = 0; i < nCount; i++) {
CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
CFX_FloatRect annotRect;
@@ -737,13 +730,13 @@ CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
if (annotRect.Contains(pageX, pageY))
return pAnnot;
}
- return NULL;
+ return nullptr;
}
CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
FX_FLOAT pageY) {
- int nCount = m_pAnnotList->Count();
- for (int i = 0; i < nCount; i++) {
+ int nCount = CountAnnots();
+ for (int i = 0; i < nCount; ++i) {
CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
if (pAnnot->GetSubType() == "Widget") {
CFX_FloatRect annotRect;
@@ -752,34 +745,29 @@ CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
return pAnnot;
}
}
- return NULL;
+ return nullptr;
}
CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX,
FX_FLOAT pageY) {
- CPDFSDK_AnnotIterator annotIterator(this, FALSE);
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
- CPDFSDK_Annot* pSDKAnnot = NULL;
- int index = -1;
- pSDKAnnot = annotIterator.Next(index);
- while (pSDKAnnot) {
+ CPDFSDK_AnnotIterator annotIterator(this, false);
+ while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
if (rc.Contains(pageX, pageY))
return pSDKAnnot;
- pSDKAnnot = annotIterator.Next(index);
}
- return NULL;
+ return nullptr;
}
CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX,
FX_FLOAT pageY) {
- CPDFSDK_AnnotIterator annotIterator(this, FALSE);
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
- int index = -1;
- while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next(index)) {
+ CPDFSDK_AnnotIterator annotIterator(this, false);
+ while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
if (pSDKAnnot->GetType() == "Widget" ||
pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) {
pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
@@ -789,7 +777,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX,
}
}
- return NULL;
+ return nullptr;
}
FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) {
@@ -803,46 +791,35 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) {
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
ASSERT(pEnv);
CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
+ if (!pAnnotHandler)
+ return nullptr;
- CPDFSDK_Annot* pSDKAnnot = NULL;
-
- if (pAnnotHandler) {
- pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
- }
+ CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
if (!pSDKAnnot)
- return NULL;
-
- m_fxAnnotArray.Add(pSDKAnnot);
-
- if (pAnnotHandler) {
- pAnnotHandler->Annot_OnCreate(pSDKAnnot);
- }
+ return nullptr;
+ m_fxAnnotArray.push_back(pSDKAnnot);
+ pAnnotHandler->Annot_OnCreate(pSDKAnnot);
return pSDKAnnot;
}
CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) {
if (!pPDFAnnot)
- return NULL;
+ return nullptr;
CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
if (pSDKAnnot)
return pSDKAnnot;
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- ASSERT(pEnv);
CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
- pSDKAnnot = NULL;
-
- if (pAnnotHandler) {
+ if (pAnnotHandler)
pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
- }
if (!pSDKAnnot)
- return NULL;
-
- m_fxAnnotArray.Add(pSDKAnnot);
+ return nullptr;
+ m_fxAnnotArray.push_back(pSDKAnnot);
return pSDKAnnot;
}
@@ -863,10 +840,11 @@ FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) {
pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
return FALSE;
- int index = m_fxAnnotArray.Find(pAnnot);
- m_fxAnnotArray.RemoveAt(index);
+ auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot);
+ if (it != m_fxAnnotArray.end())
+ m_fxAnnotArray.erase(it);
if (m_CaptureWidget == pAnnot)
- m_CaptureWidget = NULL;
+ m_CaptureWidget = nullptr;
return TRUE;
}
@@ -886,39 +864,30 @@ CPDF_Page* CPDFSDK_PageView::GetPDFPage() {
return NULL;
}
-int CPDFSDK_PageView::CountAnnots() {
- return m_fxAnnotArray.GetSize();
+int CPDFSDK_PageView::CountAnnots() const {
+ return m_pAnnotList->Count();
}
-CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) {
- int nCount = m_fxAnnotArray.GetSize();
- if (nIndex < 0 || nIndex >= nCount) {
- return NULL;
- }
-
- return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) {
+ return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr;
}
CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) {
- int nCount = m_fxAnnotArray.GetSize();
- for (int i = 0; i < nCount; i++) {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
- if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
+ for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
+ if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict)
return pAnnot;
}
- return NULL;
+ return nullptr;
}
CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) {
- if (hWidget == NULL)
- return NULL;
- int annotCount = m_fxAnnotArray.GetSize();
+ if (!hWidget)
+ return nullptr;
- for (int i = 0; i < annotCount; i++) {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
if (pAnnot->GetXFAWidget() == hWidget)
return pAnnot;
}
- return NULL;
+ return nullptr;
}
FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point,
@@ -1092,18 +1061,13 @@ void CPDFSDK_PageView::LoadFXAnnots() {
return;
}
- IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
- while (pXFAAnnot) {
+ while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) {
CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
- if (!pAnnot) {
- pXFAAnnot = pWidgetHander->MoveToNext();
+ if (!pAnnot)
continue;
- }
- m_fxAnnotArray.Add(pAnnot);
+ m_fxAnnotArray.push_back(pAnnot);
pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
-
- pXFAAnnot = pWidgetHander->MoveToNext();
}
pWidgetHander->Release();
@@ -1114,7 +1078,7 @@ void CPDFSDK_PageView::LoadFXAnnots() {
FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
// Disable the default AP construction.
CPDF_InterForm::EnableUpdateAP(FALSE);
- m_pAnnotList = new CPDF_AnnotList(pPage);
+ m_pAnnotList.reset(new CPDF_AnnotList(pPage));
CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
int nCount = m_pAnnotList->Count();
@@ -1127,7 +1091,7 @@ void CPDFSDK_PageView::LoadFXAnnots() {
CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
if (!pAnnot)
continue;
- m_fxAnnotArray.Add(pAnnot);
+ m_fxAnnotArray.push_back(pAnnot);
pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
}
@@ -1162,11 +1126,12 @@ int CPDFSDK_PageView::GetPageIndex() {
return -1;
}
-FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) {
- if (p == NULL)
+FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const {
+ if (!p)
return FALSE;
- int iCount = m_pAnnotList->Count();
- for (int i = 0; i < iCount; i++) {
+
+ int nCount = CountAnnots();
+ for (int i = 0; i < nCount; ++i) {
if (m_pAnnotList->GetAt(i) == p)
return TRUE;
}
@@ -1176,12 +1141,11 @@ FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) {
CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
if (!pFocusAnnot)
- return NULL;
+ return nullptr;
- for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) {
- CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
if (pAnnot == pFocusAnnot)
return pAnnot;
}
- return NULL;
+ return nullptr;
}