diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_formfillenvironment.cpp | 25 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_formfillenvironment.h | 60 |
2 files changed, 33 insertions, 52 deletions
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index b4624548e9..71b83b2655 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -40,16 +40,13 @@ CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( : m_pInfo(pFFinfo), m_pUnderlyingDoc(pDoc), m_pSysHandler(new CFX_SystemHandler(this)), - m_bChangeMask(FALSE), - m_bBeingDestroyed(FALSE) {} + m_bChangeMask(false), + m_bBeingDestroyed(false) {} CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { - m_bBeingDestroyed = TRUE; + m_bBeingDestroyed = true; ClearAllFocusedAnnots(); - for (auto& it : m_pageMap) - delete it.second; - m_pageMap.clear(); // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| // when it cleans up. So, we must make sure it is cleaned up before @@ -584,16 +581,16 @@ void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( UnderlyingPageType* pUnderlyingPage, - bool ReNew) { + bool renew) { auto it = m_pageMap.find(pUnderlyingPage); if (it != m_pageMap.end()) - return it->second; + return it->second.get(); - if (!ReNew) + if (!renew) return nullptr; CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); - m_pageMap[pUnderlyingPage] = pPageView; + m_pageMap[pUnderlyingPage].reset(pPageView); // Delay to load all the annotations, to avoid endless loop. pPageView->LoadFXAnnots(); return pPageView; @@ -612,7 +609,7 @@ CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { return nullptr; auto it = m_pageMap.find(pTempPage); - return it != m_pageMap.end() ? it->second : nullptr; + return it != m_pageMap.end() ? it->second.get() : nullptr; } void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { @@ -664,7 +661,7 @@ void CPDFSDK_FormFillEnvironment::RemovePageView( if (it == m_pageMap.end()) return; - CPDFSDK_PageView* pPageView = it->second; + CPDFSDK_PageView* pPageView = it->second.get(); if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) return; @@ -683,8 +680,6 @@ void CPDFSDK_FormFillEnvironment::RemovePageView( // Remove the page from the map to make sure we don't accidentally attempt // to use the |pPageView| while we're cleaning it up. m_pageMap.erase(it); - - delete pPageView; } UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { @@ -700,7 +695,7 @@ CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) { for (const auto& it : m_pageMap) { - CPDFSDK_PageView* pPageView = it.second; + CPDFSDK_PageView* pPageView = it.second.get(); if (pPageView != pSender) pPageView->UpdateView(pAnnot); } diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index dd0e6bffe1..f59999f9ce 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -34,37 +34,7 @@ class CPDFSDK_FormFillEnvironment FPDF_FORMFILLINFO* pFFinfo); ~CPDFSDK_FormFillEnvironment(); - CPDFSDK_InterForm* GetInterForm(); - - // Gets the document object for the next layer down; for master this is - // a CPDF_Document, but for XFA it is a CPDFXFA_Document. - UnderlyingDocumentType* GetUnderlyingDocument() const { -#ifdef PDF_ENABLE_XFA - return GetXFADocument(); -#else // PDF_ENABLE_XFA - return GetPDFDocument(); -#endif // PDF_ENABLE_XFA - } - - // Gets the CPDF_Document, either directly in master, or from the - // CPDFXFA_Document for XFA. - CPDF_Document* GetPDFDocument() const { -#ifdef PDF_ENABLE_XFA - return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr; -#else // PDF_ENABLE_XFA - return m_pUnderlyingDoc; -#endif // PDF_ENABLE_XFA - } - -#ifdef PDF_ENABLE_XFA - // Gets the XFA document directly (XFA-only). - CPDFXFA_Document* GetXFADocument() const { return m_pUnderlyingDoc; } - void ResetXFADocument() { m_pUnderlyingDoc = nullptr; } - - int GetPageViewCount() const { return m_pageMap.size(); } -#endif // PDF_ENABLE_XFA - - CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool ReNew); + CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool renew); CPDFSDK_PageView* GetPageView(int nIndex); CPDFSDK_PageView* GetCurrentView(); void RemovePageView(UnderlyingPageType* pPage); @@ -87,9 +57,9 @@ class CPDFSDK_FormFillEnvironment int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); } FX_BOOL GetPermissions(int nFlag); - FX_BOOL GetChangeMark() { return m_bChangeMask; } - void SetChangeMark() { m_bChangeMask = TRUE; } - void ClearChangeMark() { m_bChangeMask = FALSE; } + bool GetChangeMark() const { return m_bChangeMask; } + void SetChangeMark() { m_bChangeMask = true; } + void ClearChangeMark() { m_bChangeMask = false; } UnderlyingPageType* GetPage(int nIndex); @@ -130,7 +100,20 @@ class CPDFSDK_FormFillEnvironment float* fPosArray, int sizeOfArray); + UnderlyingDocumentType* GetUnderlyingDocument() const { + return m_pUnderlyingDoc; + } + #ifdef PDF_ENABLE_XFA + CPDF_Document* GetPDFDocument() const { + return m_pUnderlyingDoc ? m_pUnderlyingDoc->GetPDFDoc() : nullptr; + } + + CPDFXFA_Document* GetXFADocument() const { return m_pUnderlyingDoc; } + void ResetXFADocument() { m_pUnderlyingDoc = nullptr; } + + int GetPageViewCount() const { return m_pageMap.size(); } + void DisplayCaret(FPDF_PAGE page, FPDF_BOOL bVisible, double left, @@ -176,6 +159,8 @@ class CPDFSDK_FormFillEnvironment CFX_WideString GetLanguage(); void PageEvent(int iPageCount, uint32_t dwEventType) const; +#else // PDF_ENABLE_XFA + CPDF_Document* GetPDFDocument() const { return m_pUnderlyingDoc; } #endif // PDF_ENABLE_XFA int JS_appAlert(const FX_WCHAR* Msg, @@ -221,20 +206,21 @@ class CPDFSDK_FormFillEnvironment CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. IJS_Runtime* GetJSRuntime(); // Creates if not present. CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. + CPDFSDK_InterForm* GetInterForm(); // Creates if not present. private: std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr; std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; std::unique_ptr<IJS_Runtime> m_pJSRuntime; FPDF_FORMFILLINFO* const m_pInfo; - std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap; + std::map<UnderlyingPageType*, std::unique_ptr<CPDFSDK_PageView>> m_pageMap; std::unique_ptr<CPDFSDK_InterForm> m_pInterForm; CPDFSDK_Annot::ObservedPtr m_pFocusAnnot; UnderlyingDocumentType* m_pUnderlyingDoc; std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller; std::unique_ptr<CFX_SystemHandler> m_pSysHandler; - FX_BOOL m_bChangeMask; - FX_BOOL m_bBeingDestroyed; + bool m_bChangeMask; + bool m_bBeingDestroyed; }; #endif // FPDFSDK_CPDFSDK_FORMFILLENVIRONMENT_H_ |