diff options
Diffstat (limited to 'fpdfsdk/src/fsdk_mgr.cpp')
-rw-r--r-- | fpdfsdk/src/fsdk_mgr.cpp | 273 |
1 files changed, 264 insertions, 9 deletions
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index 980ffb4534..65dc926fb3 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -15,6 +15,13 @@ #include "public/fpdf_ext.h" #include "third_party/base/stl_util.h" +#ifdef PDF_ENABLE_XFA +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" +#endif // PDF_ENABLE_XFA + #if _FX_OS_ == _FX_ANDROID_ #include "time.h" #else @@ -218,6 +225,11 @@ CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, } CPDFDoc_Environment::~CPDFDoc_Environment() { +#ifdef PDF_ENABLE_XFA + CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); + if (pProvider->m_pEnvList.GetSize() == 0) + pProvider->SetJavaScriptInitialized(FALSE); +#endif // PDF_ENABLE_XFA } int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, @@ -551,10 +563,17 @@ FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { if (!pAnnot) return FALSE; +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; +#endif // PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); if (pPageView && pPageView->IsValid()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); if (!m_pFocusAnnot) { +#ifdef PDF_ENABLE_XFA + if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) + return FALSE; +#endif // PDF_ENABLE_XFA if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) return FALSE; if (!m_pFocusAnnot) { @@ -571,6 +590,12 @@ FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; m_pFocusAnnot = nullptr; + +#ifdef PDF_ENABLE_XFA + if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) + return FALSE; +#endif // PDF_ENABLE_XFA + if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { if (pFocusAnnot->GetType() == "Widget") { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; @@ -611,18 +636,27 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, : m_page(page), m_pSDKDoc(pSDKDoc), m_CaptureWidget(nullptr), +#ifndef PDF_ENABLE_XFA + m_bTakeOverPage(FALSE), +#endif // PDF_ENABLE_XFA m_bEnterWidget(FALSE), m_bExitWidget(FALSE), m_bOnWidget(FALSE), m_bValid(FALSE), - m_bLocked(FALSE), - m_bTakeOverPage(FALSE) { + m_bLocked(FALSE) { CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); if (pInterForm) { CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); +#ifdef PDF_ENABLE_XFA + if (page->GetPDFPage()) + pPDFInterForm->FixPageFields(page->GetPDFPage()); +#else // PDF_ENABLE_XFA pPDFInterForm->FixPageFields(page); +#endif // PDF_ENABLE_XFA } +#ifndef PDF_ENABLE_XFA m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); +#endif // PDF_ENABLE_XFA } CPDFSDK_PageView::~CPDFSDK_PageView() { @@ -630,21 +664,66 @@ CPDFSDK_PageView::~CPDFSDK_PageView() { CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) pAnnotHandlerMgr->ReleaseAnnot(pAnnot); - m_fxAnnotArray.clear(); + m_fxAnnotArray.clear(); m_pAnnotList.reset(); - +#ifndef PDF_ENABLE_XFA m_page->RemovePrivateData((void*)m_page); if (m_bTakeOverPage) { delete m_page; } +#endif // PDF_ENABLE_XFA } void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device, +#ifdef PDF_ENABLE_XFA + CPDF_RenderOptions* pOptions, + const FX_RECT& pClip) { +#else CPDF_RenderOptions* pOptions) { +#endif // PDF_ENABLE_XFA m_curMatrix = *pUser2Device; CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + +#ifdef PDF_ENABLE_XFA + CPDFXFA_Page* pPage = GetPDFXFAPage(); + if (!pPage) + return; + + if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + CFX_Graphics gs; + gs.Create(pDevice); + CFX_RectF rectClip; + rectClip.Set(static_cast<FX_FLOAT>(pClip.left), + static_cast<FX_FLOAT>(pClip.top), + static_cast<FX_FLOAT>(pClip.Width()), + static_cast<FX_FLOAT>(pClip.Height())); + gs.SetClipRect(rectClip); + IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); + if (!pRenderContext) + return; + CXFA_RenderOptions renderOptions; + renderOptions.m_bHighlight = TRUE; + IXFA_PageView* xfaView = pPage->GetXFAPageView(); + pRenderContext->StartRender(xfaView, &gs, *pUser2Device, renderOptions); + pRenderContext->DoRender(); + pRenderContext->StopRender(); + pRenderContext->Release(); + IXFA_DocView* docView = xfaView->GetDocView(); + if (!docView) + return; + CPDFSDK_Annot* annot = GetFocusAnnot(); + if (!annot) + return; + // Render the focus widget + docView->GetWidgetHandler()->RenderWidget(annot->GetXFAWidget(), &gs, + pUser2Device, FALSE); + return; + } +#endif // PDF_ENABLE_XFA + + // for pdf/static xfa. CPDFSDK_AnnotIterator annotIterator(this, true); while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); @@ -696,7 +775,11 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); CPDFSDK_AnnotIterator annotIterator(this, false); while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { - if (pSDKAnnot->GetType() == "Widget") { + bool bHitTest = pSDKAnnot->GetType() == "Widget"; +#ifdef PDF_ENABLE_XFA + bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME; +#endif // PDF_ENABLE_XFA + if (bHitTest) { pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); CPDF_Point point(pageX, pageY); if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) @@ -735,6 +818,26 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { return pSDKAnnot; } +#ifdef PDF_ENABLE_XFA +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { + if (!pPDFAnnot) + return nullptr; + + CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); + if (pSDKAnnot) + return pSDKAnnot; + + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); + pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); + if (!pSDKAnnot) + return nullptr; + + m_fxAnnotArray.push_back(pSDKAnnot); + return pSDKAnnot; +} +#endif // PDF_ENABLE_XFA + CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { return pDict ? AddAnnot(pDict->GetStringBy("Subtype"), pDict) : nullptr; } @@ -745,16 +848,46 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, } FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { +#ifdef PDF_ENABLE_XFA + if (!pAnnot) + return FALSE; + CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); + if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && + pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) + return FALSE; + + 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 = nullptr; + + return TRUE; +#else // PDF_ENABLE_XFA return FALSE; +#endif // PDF_ENABLE_XFA } CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { if (m_page) { +#ifdef PDF_ENABLE_XFA + return m_page->GetDocument()->GetPDFDoc(); +#else // PDF_ENABLE_XFA return m_page->m_pDocument; +#endif // PDF_ENABLE_XFA } return NULL; } +#ifdef PDF_ENABLE_XFA +CPDF_Page* CPDFSDK_PageView::GetPDFPage() { + if (m_page) { + return m_page->GetPDFPage(); + } + return NULL; +} +#endif // PDF_ENABLE_XFA + size_t CPDFSDK_PageView::CountAnnots() const { return m_fxAnnotArray.size(); } @@ -771,6 +904,19 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { return nullptr; } +#ifdef PDF_ENABLE_XFA +CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { + if (!hWidget) + return nullptr; + + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { + if (pAnnot->GetXFAWidget() == hWidget) + return pAnnot; + } + return nullptr; +} +#endif // PDF_ENABLE_XFA + FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag) { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); @@ -789,6 +935,46 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, return bRet; } +#ifdef PDF_ENABLE_XFA +FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, + FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + + if (pFXAnnot == NULL) + return FALSE; + + FX_BOOL bRet = + pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); + if (bRet) { + SetFocusAnnot(pFXAnnot); + } + return TRUE; +} + +FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + + if (pFXAnnot == NULL) + return FALSE; + + FX_BOOL bRet = + pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); + if (bRet) { + SetFocusAnnot(pFXAnnot); + } + return TRUE; +} +#endif // PDF_ENABLE_XFA + FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); ASSERT(pEnv); @@ -874,28 +1060,93 @@ FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { void CPDFSDK_PageView::LoadFXAnnots() { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - +#ifdef PDF_ENABLE_XFA + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); +#else FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); // Disable the default AP construction. CPDF_InterForm::EnableUpdateAP(FALSE); m_pAnnotList.reset(new CPDF_AnnotList(m_page)); CPDF_InterForm::EnableUpdateAP(enableAPUpdate); const size_t nCount = m_pAnnotList->Count(); +#endif // PDF_ENABLE_XFA + SetLock(TRUE); + +#ifdef PDF_ENABLE_XFA + m_page->AddRef(); + if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { + IXFA_PageView* pageView = NULL; + pageView = m_page->GetXFAPageView(); + ASSERT(pageView != NULL); + + IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( + XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | + XFA_WIDGETFILTER_Viewable | + XFA_WIDGETFILTER_AllType); + if (!pWidgetHander) { + m_page->Release(); + SetLock(FALSE); + return; + } + + while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) { + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); + if (!pAnnot) + continue; + + m_fxAnnotArray.push_back(pAnnot); + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + } + pWidgetHander->Release(); + } else { + CPDF_Page* pPage = m_page->GetPDFPage(); + ASSERT(pPage != NULL); + FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); + // Disable the default AP construction. + CPDF_InterForm::EnableUpdateAP(FALSE); + m_pAnnotList.reset(new CPDF_AnnotList(pPage)); + CPDF_InterForm::EnableUpdateAP(enableAPUpdate); + + const size_t nCount = m_pAnnotList->Count(); + for (size_t i = 0; i < nCount; ++i) { + CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); + CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); + + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); + if (!pAnnot) + continue; + m_fxAnnotArray.push_back(pAnnot); + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + } + } + m_page->Release(); +#else // PDF_ENABLE_XFA for (size_t i = 0; i < nCount; ++i) { CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); CPDF_Document* pDoc = GetPDFDocument(); - CheckUnSupportAnnot(pDoc, pPDFAnnot); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); if (!pAnnot) continue; m_fxAnnotArray.push_back(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); } +#endif // PDF_ENABLE_XFA + + SetLock(FALSE); +} + +void CPDFSDK_PageView::ClearFXAnnots() { + SetLock(TRUE); + if (m_pSDKDoc && GetFocusAnnot()) + m_pSDKDoc->SetFocusAnnot(nullptr); + m_CaptureWidget = nullptr; + for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) + m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); + m_fxAnnotArray.clear(); + m_pAnnotList.reset(); SetLock(FALSE); } @@ -916,7 +1167,11 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { int CPDFSDK_PageView::GetPageIndex() { if (m_page) { +#ifdef PDF_ENABLE_XFA + CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; +#else // PDF_ENABLE_XFA CPDF_Dictionary* pDic = m_page->m_pFormDict; +#endif // PDF_ENABLE_XFA CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); if (pDoc && pDic) { return pDoc->GetPageIndex(pDic->GetObjNum()); |