diff options
Diffstat (limited to 'fpdfsdk/src/fsdk_mgr.cpp')
-rw-r--r-- | fpdfsdk/src/fsdk_mgr.cpp | 139 |
1 files changed, 58 insertions, 81 deletions
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index f43a45b1f7..53a774edcd 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" @@ -19,7 +21,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: @@ -606,47 +609,39 @@ CFX_WideString CPDFSDK_Document::GetPath() { } CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, CPDF_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), + m_bTakeOverPage(FALSE) { CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); if (pInterForm) { CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); pPDFInterForm->FixPageFields(page); } - m_page->SetPrivateData((void*)m_page, (void*)this, NULL); - m_fxAnnotArray.RemoveAll(); - - m_bEnterWidget = FALSE; - m_bExitWidget = FALSE; - m_bOnWidget = FALSE; - m_CaptureWidget = NULL; - m_bValid = FALSE; - m_bLocked = FALSE; - m_bTakeOverPage = FALSE; + m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); } 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(); m_page->RemovePrivateData((void*)m_page); if (m_bTakeOverPage) { @@ -660,9 +655,8 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, m_curMatrix = *pUser2Device; CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - 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); } @@ -670,7 +664,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; @@ -678,13 +672,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; @@ -693,33 +687,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; - while ((pSDKAnnot = annotIterator.Next(index))) { + 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; } - 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(); - CPDFSDK_Annot* pSDKAnnot = NULL; - int index = -1; - while ((pSDKAnnot = annotIterator.Next(index))) { + CPDFSDK_AnnotIterator annotIterator(this, false); + while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { if (pSDKAnnot->GetType() == "Widget") { pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); CPDF_Point point(pageX, pageY); @@ -728,7 +718,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, } } - return NULL; + return nullptr; } FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) { @@ -742,21 +732,15 @@ 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; } @@ -780,27 +764,20 @@ CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { return NULL; } -int CPDFSDK_PageView::CountAnnots() { +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; } FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, @@ -920,11 +897,11 @@ void CPDFSDK_PageView::LoadFXAnnots() { FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); // Disable the default AP construction. CPDF_InterForm::EnableUpdateAP(FALSE); - m_pAnnotList = new CPDF_AnnotList(m_page); + m_pAnnotList.reset(new CPDF_AnnotList(m_page)); CPDF_InterForm::EnableUpdateAP(enableAPUpdate); - int nCount = m_pAnnotList->Count(); + int nCount = CountAnnots(); SetLock(TRUE); - for (int i = 0; i < nCount; i++) { + for (int i = 0; i < nCount; ++i) { CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); CPDF_Document* pDoc = GetPDFDocument(); @@ -937,7 +914,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); } @@ -971,11 +948,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; } @@ -985,12 +963,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; } |