diff options
Diffstat (limited to 'fpdfsdk/src/fsdk_mgr.cpp')
-rw-r--r-- | fpdfsdk/src/fsdk_mgr.cpp | 100 |
1 files changed, 36 insertions, 64 deletions
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index 0f71e6eaa0..1169d79a22 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -315,15 +315,9 @@ CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* p CPDFSDK_Document::~CPDFSDK_Document() { - FX_POSITION pos = m_pageMap.GetStartPosition(); - while(pos) - { - CPDFXFA_Page* pPage = NULL; - CPDFSDK_PageView* pPageView = NULL; - m_pageMap.GetNextAssoc(pos, pPage, pPageView); - delete pPageView; - } - m_pageMap.RemoveAll(); + for (auto& it : m_pageMap) + delete it.second; + m_pageMap.clear(); delete m_pInterForm; m_pInterForm = nullptr; @@ -332,36 +326,20 @@ CPDFSDK_Document::~CPDFSDK_Document() m_pOccontent = nullptr; } -void CPDFSDK_Document::InitPageView() -{ - int nCount = m_pDoc->GetPageCount(); - for(int i=0; i<nCount; i++) - { - // To do -// CPDF_Dictionary* pDic = m_pDoc->GetPage(i); -// m_pageMap.SetAt(pDic, pPageView); - } -} - -void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView) -{ - m_pageMap.SetAt(pPDFXFAPage, pPageView); -} - CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew) { - CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage); - if(pPageView != NULL) - return pPageView; - if(ReNew) - { - pPageView = new CPDFSDK_PageView(this,pPDFXFAPage); - m_pageMap.SetAt(pPDFXFAPage, pPageView); - //Delay to load all the annotations, to avoid endless loop. - pPageView->LoadFXAnnots(); - } - return pPageView; + auto it = m_pageMap.find(pPDFXFAPage); + if (it != m_pageMap.end()) + return it->second; + if (!ReNew) + return nullptr; + + CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFXFAPage); + m_pageMap[pPDFXFAPage] = pPageView; + // Delay to load all the annotations, to avoid endless loop. + pPageView->LoadFXAnnots(); + return pPageView; } CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() @@ -372,16 +350,13 @@ CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { - CPDFSDK_PageView * pTempPageView = NULL; - CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex); - if(!pTempPage) - return NULL; - - m_pageMap.Lookup(pTempPage, pTempPageView); + CPDFXFA_Page* pTempPage = + (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); + if (!pTempPage) + return nullptr; - ASSERT(pTempPageView != NULL); - - return pTempPageView; + auto it = m_pageMap.find(pTempPage); + return it->second; } void CPDFSDK_Document:: ProcJavascriptFun() @@ -439,12 +414,16 @@ CPDF_OCContext* CPDFSDK_Document::GetOCContext() void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) { - CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage); - if(pPageView && !pPageView->IsLocked()) - { - delete pPageView; - m_pageMap.RemoveKey(pPDFXFAPage); - } + auto it = m_pageMap.find(pPDFXFAPage); + if (it == m_pageMap.end()) + return; + + CPDFSDK_PageView* pPageView = it->second; + if (pPageView->IsLocked()) + return; + + delete pPageView; + m_pageMap.erase(it); } CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex) @@ -464,19 +443,12 @@ CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) { - - FX_POSITION pos = m_pageMap.GetStartPosition(); - CPDFXFA_Page * pPage = NULL; - CPDFSDK_PageView * pPageView = NULL; - while(pos) - { - m_pageMap.GetNextAssoc(pos, pPage, pPageView); - - if(pPageView != pSender) - { - pPageView->UpdateView(pAnnot); - } - } + for (const auto& it : m_pageMap) { + CPDFSDK_PageView* pPageView = it.second; + if (pPageView != pSender) { + pPageView->UpdateView(pAnnot); + } + } } CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() |