summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fsdk_mgr.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-06-19 15:09:45 -0700
committerLei Zhang <thestig@chromium.org>2015-06-19 15:09:45 -0700
commite8d3691c82d1be805ffdce3329d00313af7ce0ab (patch)
tree39c6aeb956cc865e8f0b88ddcd80d1dd9e4285f7 /fpdfsdk/src/fsdk_mgr.cpp
parentcfac954abcab7caf47d3fa3d641c553cba998271 (diff)
downloadpdfium-e8d3691c82d1be805ffdce3329d00313af7ce0ab.tar.xz
Replace CFX_MapPtrTemplate with std::map.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1181593003.
Diffstat (limited to 'fpdfsdk/src/fsdk_mgr.cpp')
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp98
1 files changed, 35 insertions, 63 deletions
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 5d4680d978..003753223f 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -317,14 +317,9 @@ CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv
CPDFSDK_Document::~CPDFSDK_Document()
{
- FX_POSITION pos = m_pageMap.GetStartPosition();
- while (pos) {
- CPDF_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;
@@ -333,36 +328,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(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)
-{
- m_pageMap.SetAt(pPDFPage, pPageView);
-}
-
CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)
{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
- if(pPageView != NULL)
- return pPageView;
- if(ReNew)
- {
- pPageView = new CPDFSDK_PageView(this,pPDFPage);
- m_pageMap.SetAt(pPDFPage, pPageView);
- //Delay to load all the annotations, to avoid endless loop.
- pPageView->LoadFXAnnots();
- }
- return pPageView;
+ auto it = m_pageMap.find(pPDFPage);
+ if (it != m_pageMap.end())
+ return it->second;
+ if (!ReNew)
+ return nullptr;
+
+ CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFPage);
+ m_pageMap[pPDFPage] = pPageView;
+ // Delay to load all the annotations, to avoid endless loop.
+ pPageView->LoadFXAnnots();
+ return pPageView;
}
CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
@@ -373,16 +352,12 @@ CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
{
- CPDFSDK_PageView * pTempPageView = NULL;
- CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
- if(!pTempPage)
- return NULL;
-
- m_pageMap.Lookup(pTempPage, pTempPageView);
+ CPDF_Page* pTempPage = (CPDF_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()
@@ -440,12 +415,16 @@ CPDF_OCContext* CPDFSDK_Document::GetOCContext()
void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)
{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
- if(pPageView && !pPageView->IsLocked())
- {
- delete pPageView;
- m_pageMap.RemoveKey(pPDFPage);
- }
+ auto it = m_pageMap.find(pPDFPage);
+ if (it == m_pageMap.end())
+ return;
+
+ CPDFSDK_PageView* pPageView = it->second;
+ if (pPageView->IsLocked())
+ return;
+
+ delete pPageView;
+ m_pageMap.erase(it);
}
CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)
@@ -465,19 +444,12 @@ CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
{
-
- FX_POSITION pos = m_pageMap.GetStartPosition();
- CPDF_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()