From 8c54182aba447f7fbd6e763a559bec99ab996613 Mon Sep 17 00:00:00 2001 From: jaepark Date: Tue, 30 Aug 2016 13:43:05 -0700 Subject: Rename CPDFSDK_BFAnnotHandler and CPDFSDK_XFAAnnotHandler. CPDFSDK_BFAnnotHandler handles CPDFSDK_Widget, so rename it to CPDFSDK_WidgetHandler. Similarly, CPDFSDK_XFAAnnotHandler handles CPDFSDK_XFAWidget, so rename it to CPDFSDK_XFAWidgetHandler. Review-Url: https://codereview.chromium.org/2298443002 --- BUILD.gn | 8 +- fpdfsdk/cpdfsdk_annothandlermgr.cpp | 14 +- fpdfsdk/cpdfsdk_bfannothandler.cpp | 311 ----------------------- fpdfsdk/cpdfsdk_widgethandler.cpp | 311 +++++++++++++++++++++++ fpdfsdk/cpdfsdk_xfaannothandler.cpp | 386 ----------------------------- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 386 +++++++++++++++++++++++++++++ fpdfsdk/include/cpdfsdk_annothandlermgr.h | 8 +- fpdfsdk/include/cpdfsdk_bfannothandler.h | 121 --------- fpdfsdk/include/cpdfsdk_widgethandler.h | 121 +++++++++ fpdfsdk/include/cpdfsdk_xfaannothandler.h | 113 --------- fpdfsdk/include/cpdfsdk_xfawidgethandler.h | 113 +++++++++ 11 files changed, 946 insertions(+), 946 deletions(-) delete mode 100644 fpdfsdk/cpdfsdk_bfannothandler.cpp create mode 100644 fpdfsdk/cpdfsdk_widgethandler.cpp delete mode 100644 fpdfsdk/cpdfsdk_xfaannothandler.cpp create mode 100644 fpdfsdk/cpdfsdk_xfawidgethandler.cpp delete mode 100644 fpdfsdk/include/cpdfsdk_bfannothandler.h create mode 100644 fpdfsdk/include/cpdfsdk_widgethandler.h delete mode 100644 fpdfsdk/include/cpdfsdk_xfaannothandler.h create mode 100644 fpdfsdk/include/cpdfsdk_xfawidgethandler.h diff --git a/BUILD.gn b/BUILD.gn index 68c09502e7..ad7b5d1b1c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -70,10 +70,10 @@ static_library("pdfium") { "fpdfsdk/cpdfsdk_annotiterator.cpp", "fpdfsdk/cpdfsdk_baannot.cpp", "fpdfsdk/cpdfsdk_baannothandler.cpp", - "fpdfsdk/cpdfsdk_bfannothandler.cpp", "fpdfsdk/cpdfsdk_datetime.cpp", "fpdfsdk/cpdfsdk_interform.cpp", "fpdfsdk/cpdfsdk_widget.cpp", + "fpdfsdk/cpdfsdk_widgethandler.cpp", "fpdfsdk/fpdf_dataavail.cpp", "fpdfsdk/fpdf_ext.cpp", "fpdfsdk/fpdf_flatten.cpp", @@ -98,10 +98,10 @@ static_library("pdfium") { "fpdfsdk/include/cpdfsdk_annotiterator.h", "fpdfsdk/include/cpdfsdk_baannot.h", "fpdfsdk/include/cpdfsdk_baannothandler.h", - "fpdfsdk/include/cpdfsdk_bfannothandler.h", "fpdfsdk/include/cpdfsdk_datetime.h", "fpdfsdk/include/cpdfsdk_interform.h", "fpdfsdk/include/cpdfsdk_widget.h", + "fpdfsdk/include/cpdfsdk_widgethandler.h", "fpdfsdk/include/fsdk_actionhandler.h", "fpdfsdk/include/fsdk_pauseadapter.h", "fpdfsdk/include/pdfsdk_fieldaction.h", @@ -144,10 +144,10 @@ static_library("pdfium") { if (pdf_enable_xfa) { sources += [ - "fpdfsdk/cpdfsdk_xfaannothandler.cpp", "fpdfsdk/cpdfsdk_xfawidget.cpp", - "fpdfsdk/include/cpdfsdk_xfaannothandler.h", + "fpdfsdk/cpdfsdk_xfawidgethandler.cpp", "fpdfsdk/include/cpdfsdk_xfawidget.h", + "fpdfsdk/include/cpdfsdk_xfawidgethandler.h", ] deps += [ ":fpdfxfa" ] diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp index 33c1ca95a9..9f5a545d65 100644 --- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -11,12 +11,12 @@ #include "fpdfsdk/include/cpdfsdk_annot.h" #include "fpdfsdk/include/cpdfsdk_baannot.h" #include "fpdfsdk/include/cpdfsdk_baannothandler.h" -#include "fpdfsdk/include/cpdfsdk_bfannothandler.h" #include "fpdfsdk/include/cpdfsdk_datetime.h" +#include "fpdfsdk/include/cpdfsdk_widgethandler.h" #include "fpdfsdk/include/fsdk_mgr.h" #ifdef PDF_ENABLE_XFA -#include "fpdfsdk/include/cpdfsdk_xfaannothandler.h" +#include "fpdfsdk/include/cpdfsdk_xfawidgethandler.h" #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" #include "xfa/fxfa/include/xfa_ffpageview.h" #include "xfa/fxfa/include/xfa_ffwidget.h" @@ -24,12 +24,12 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) : m_pBAAnnotHandler(new CPDFSDK_BAAnnotHandler()), - m_pBFAnnotHandler(new CPDFSDK_BFAnnotHandler(pApp)), + m_pWidgetHandler(new CPDFSDK_WidgetHandler(pApp)), #ifdef PDF_ENABLE_XFA - m_pXFAAnnotHandler(new CPDFSDK_XFAAnnotHandler(pApp)), + m_pXFAWidgetHandler(new CPDFSDK_XFAWidgetHandler(pApp)), #endif // PDF_ENABLE_XFA m_pApp(pApp) { - m_pBFAnnotHandler->SetFormFiller(m_pApp->GetIFormFiller()); + m_pWidgetHandler->SetFormFiller(m_pApp->GetIFormFiller()); } CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} @@ -79,11 +79,11 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( const CFX_ByteString& sType) const { if (sType == "Widget") - return m_pBFAnnotHandler.get(); + return m_pWidgetHandler.get(); #ifdef PDF_ENABLE_XFA if (sType == FSDK_XFAWIDGET_TYPENAME) - return m_pXFAAnnotHandler.get(); + return m_pXFAWidgetHandler.get(); #endif // PDF_ENABLE_XFA return m_pBAAnnotHandler.get(); diff --git a/fpdfsdk/cpdfsdk_bfannothandler.cpp b/fpdfsdk/cpdfsdk_bfannothandler.cpp deleted file mode 100644 index ff0c26404c..0000000000 --- a/fpdfsdk/cpdfsdk_bfannothandler.cpp +++ /dev/null @@ -1,311 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/include/cpdfsdk_bfannothandler.h" - -#include -#include - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfdoc/include/cpdf_interform.h" -#include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/include/cpdfsdk_annot.h" -#include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/include/fsdk_mgr.h" - -#ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" -#endif // PDF_ENABLE_XFA - -CPDFSDK_BFAnnotHandler::CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp) - : m_pApp(pApp), m_pFormFiller(nullptr) {} - -CPDFSDK_BFAnnotHandler::~CPDFSDK_BFAnnotHandler() {} - -CFX_ByteString CPDFSDK_BFAnnotHandler::GetType() { - return CFX_ByteString("Widget"); -} - -FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot->GetAnnotSubtype() == "Widget"); - if (pAnnot->IsSignatureWidget()) - return FALSE; - - CPDFSDK_Widget* pWidget = static_cast(pAnnot); - if (!pWidget->IsVisible()) - return FALSE; - - int nFieldFlags = pWidget->GetFieldFlags(); - if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) - return FALSE; - - if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) - return TRUE; - - CPDF_Page* pPage = pWidget->GetPDFPage(); - CPDF_Document* pDocument = pPage->m_pDocument; - uint32_t dwPermissions = pDocument->GetUserPermissions(); - return (dwPermissions & FPDFPERM_FILL_FORM) || - (dwPermissions & FPDFPERM_ANNOT_FORM); -} - -CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, - CPDFSDK_PageView* pPage) { - CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); - CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( - pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); - if (!pCtrl) - return nullptr; - - CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); - pInterForm->AddMap(pCtrl, pWidget); - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) - pWidget->ResetAppearance(nullptr, FALSE); - - return pWidget; -} - -#ifdef PDF_ENABLE_XFA -CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget, - CPDFSDK_PageView* pPage) { - return nullptr; -} -#endif // PDF_ENABLE_XFA - -void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot); - - if (m_pFormFiller) - m_pFormFiller->OnDelete(pAnnot); - - std::unique_ptr pWidget(static_cast(pAnnot)); - CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - CPDF_FormControl* pControl = pWidget->GetFormControl(); - pInterForm->RemoveMap(pControl); -} - -void CPDFSDK_BFAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - uint32_t dwFlags) { - if (pAnnot->IsSignatureWidget()) { - static_cast(pAnnot)->DrawAppearance( - pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); - } else { - if (m_pFormFiller) - m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); - } -} - -void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rcWindow, - uint32_t dwFlags) {} - -void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); -} - -void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, - point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, - int nKeyCode, - int nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); - - return FALSE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, - int nKeyCode, - int nFlag) { - return FALSE; -} - -void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - m_pFormFiller->OnCreate(pAnnot); -} - -void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { - if (pAnnot->IsSignatureWidget()) - return; - - CPDFSDK_Widget* pWidget = static_cast(pAnnot); - if (!pWidget->IsAppearanceValid()) - pWidget->ResetAppearance(nullptr, FALSE); - - int nFieldType = pWidget->GetFieldType(); - if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) - pWidget->ResetAppearance(sValue.c_str(), FALSE); - } - -#ifdef PDF_ENABLE_XFA - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { - if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) - pWidget->ResetAppearance(FALSE); - } -#endif // PDF_ENABLE_XFA - if (m_pFormFiller) - m_pFormFiller->OnLoad(pAnnot); -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnSetFocus(pAnnot, nFlag); - - return TRUE; -} - -FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnKillFocus(pAnnot, nFlag); - - return TRUE; -} - -#ifdef PDF_ENABLE_XFA -FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, - CPDFSDK_Annot* pNewAnnot) { - return TRUE; -} -#endif // PDF_ENABLE_XFA - -CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); - - return CFX_FloatRect(0, 0, 0, 0); -} - -FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - const CFX_FloatPoint& point) { - ASSERT(pPageView); - ASSERT(pAnnot); - - CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); - return rect.Contains(point.x, point.y); -} diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp new file mode 100644 index 0000000000..0fb64dfaec --- /dev/null +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -0,0 +1,311 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/include/cpdfsdk_widgethandler.h" + +#include +#include + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfdoc/include/cpdf_interform.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_widget.h" +#include "fpdfsdk/include/fsdk_mgr.h" + +#ifdef PDF_ENABLE_XFA +#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" +#endif // PDF_ENABLE_XFA + +CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler(CPDFDoc_Environment* pApp) + : m_pApp(pApp), m_pFormFiller(nullptr) {} + +CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {} + +CFX_ByteString CPDFSDK_WidgetHandler::GetType() { + return CFX_ByteString("Widget"); +} + +FX_BOOL CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { + ASSERT(pAnnot->GetAnnotSubtype() == "Widget"); + if (pAnnot->IsSignatureWidget()) + return FALSE; + + CPDFSDK_Widget* pWidget = static_cast(pAnnot); + if (!pWidget->IsVisible()) + return FALSE; + + int nFieldFlags = pWidget->GetFieldFlags(); + if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) + return FALSE; + + if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) + return TRUE; + + CPDF_Page* pPage = pWidget->GetPDFPage(); + CPDF_Document* pDocument = pPage->m_pDocument; + uint32_t dwPermissions = pDocument->GetUserPermissions(); + return (dwPermissions & FPDFPERM_FILL_FORM) || + (dwPermissions & FPDFPERM_ANNOT_FORM); +} + +CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, + CPDFSDK_PageView* pPage) { + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); + CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( + pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); + if (!pCtrl) + return nullptr; + + CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); + pInterForm->AddMap(pCtrl, pWidget); + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) + pWidget->ResetAppearance(nullptr, FALSE); + + return pWidget; +} + +#ifdef PDF_ENABLE_XFA +CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CXFA_FFWidget* hWidget, + CPDFSDK_PageView* pPage) { + return nullptr; +} +#endif // PDF_ENABLE_XFA + +void CPDFSDK_WidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { + ASSERT(pAnnot); + + if (m_pFormFiller) + m_pFormFiller->OnDelete(pAnnot); + + std::unique_ptr pWidget(static_cast(pAnnot)); + CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); + CPDF_FormControl* pControl = pWidget->GetFormControl(); + pInterForm->RemoveMap(pControl); +} + +void CPDFSDK_WidgetHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + uint32_t dwFlags) { + if (pAnnot->IsSignatureWidget()) { + static_cast(pAnnot)->DrawAppearance( + pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + } else { + if (m_pFormFiller) + m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); + } +} + +void CPDFSDK_WidgetHandler::OnDrawSleep(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rcWindow, + uint32_t dwFlags) {} + +void CPDFSDK_WidgetHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_WidgetHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); +} + +void CPDFSDK_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); +} + +FX_BOOL CPDFSDK_WidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, + point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, + int nKeyCode, + int nFlag) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); + + return FALSE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, + int nKeyCode, + int nFlag) { + return FALSE; +} + +void CPDFSDK_WidgetHandler::OnCreate(CPDFSDK_Annot* pAnnot) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + m_pFormFiller->OnCreate(pAnnot); +} + +void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { + if (pAnnot->IsSignatureWidget()) + return; + + CPDFSDK_Widget* pWidget = static_cast(pAnnot); + if (!pWidget->IsAppearanceValid()) + pWidget->ResetAppearance(nullptr, FALSE); + + int nFieldType = pWidget->GetFieldType(); + if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormated); + if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) + pWidget->ResetAppearance(sValue.c_str(), FALSE); + } + +#ifdef PDF_ENABLE_XFA + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { + if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) + pWidget->ResetAppearance(FALSE); + } +#endif // PDF_ENABLE_XFA + if (m_pFormFiller) + m_pFormFiller->OnLoad(pAnnot); +} + +FX_BOOL CPDFSDK_WidgetHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnSetFocus(pAnnot, nFlag); + + return TRUE; +} + +FX_BOOL CPDFSDK_WidgetHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->OnKillFocus(pAnnot, nFlag); + + return TRUE; +} + +#ifdef PDF_ENABLE_XFA +FX_BOOL CPDFSDK_WidgetHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, + CPDFSDK_Annot* pNewAnnot) { + return TRUE; +} +#endif // PDF_ENABLE_XFA + +CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); + + return CFX_FloatRect(0, 0, 0, 0); +} + +FX_BOOL CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + const CFX_FloatPoint& point) { + ASSERT(pPageView); + ASSERT(pAnnot); + + CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); + return rect.Contains(point.x, point.y); +} diff --git a/fpdfsdk/cpdfsdk_xfaannothandler.cpp b/fpdfsdk/cpdfsdk_xfaannothandler.cpp deleted file mode 100644 index 2f4599da5d..0000000000 --- a/fpdfsdk/cpdfsdk_xfaannothandler.cpp +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/include/cpdfsdk_xfaannothandler.h" - -#include "core/fpdfdoc/include/cpdf_interform.h" -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" -#include "fpdfsdk/include/cpdfsdk_annot.h" -#include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/cpdfsdk_xfawidget.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "xfa/fxfa/include/fxfa_basic.h" -#include "xfa/fxfa/include/xfa_ffdocview.h" -#include "xfa/fxfa/include/xfa_ffpageview.h" -#include "xfa/fxfa/include/xfa_ffwidget.h" -#include "xfa/fxfa/include/xfa_ffwidgethandler.h" -#include "xfa/fxgraphics/include/cfx_graphics.h" -#include "xfa/fwl/core/include/fwl_widgethit.h" - -CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) - : m_pApp(pApp) {} - -CPDFSDK_XFAAnnotHandler::~CPDFSDK_XFAAnnotHandler() {} - -CFX_ByteString CPDFSDK_XFAAnnotHandler::GetType() { - return FSDK_XFAWIDGET_TYPENAME; -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { - return !!pAnnot->GetXFAWidget(); -} - -CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, - CPDFSDK_PageView* pPage) { - return nullptr; -} - -CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CXFA_FFWidget* pAnnot, - CPDFSDK_PageView* pPage) { - CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); - CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); - pInterForm->AddXFAMap(pAnnot, pWidget); - return pWidget; -} - -void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - uint32_t dwFlags) { - ASSERT(pPageView); - ASSERT(pAnnot); - - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - - CFX_Graphics gs; - gs.Create(pDevice); - - CFX_Matrix mt; - mt = *pUser2Device; - - FX_BOOL bIsHighlight = FALSE; - if (pSDKDoc->GetFocusAnnot() != pAnnot) - bIsHighlight = TRUE; - - pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); - - // to do highlight and shadow -} - -void CPDFSDK_XFAAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rcWindow, - uint32_t dwFlags) {} - -void CPDFSDK_XFAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_XFAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_XFAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_XFAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { - CPDFSDK_XFAWidget* pWidget = reinterpret_cast(pAnnot); - CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); - - delete pWidget; -} - -void CPDFSDK_XFAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} - -CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot); - - CFX_RectF rcBBox; - XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType(); - if (eType == XFA_Element::Signature) - pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, TRUE); - else - pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None); - - CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, - rcBBox.top + rcBBox.height); - rcWidget.left -= 1.0f; - rcWidget.right += 1.0f; - rcWidget.bottom -= 1.0f; - rcWidget.top += 1.0f; - - return rcWidget; -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - if (!pSDKDoc) - return FALSE; - - CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); - if (!pDoc) - return FALSE; - - CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); - if (!pDocView) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); - if (!pWidgetHandler) - return FALSE; - - FWL_WidgetHit dwHitTest = - pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); - return dwHitTest != FWL_WidgetHit::Unknown; -} - -void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pPageView || !pAnnot) - return; - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); -} - -void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - if (!pPageView || !pAnnot) - return; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnMouseWheel( - pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - if (!pPageView || !pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), - GetFWLFlags(nFlags), point.x, point.y); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags) { - if (!pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, - GetFWLFlags(nFlags)); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, - int nKeyCode, - int nFlag) { - if (!pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, - GetFWLFlags(nFlag)); -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, - int nKeyCode, - int nFlag) { - if (!pAnnot) - return FALSE; - - CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, - GetFWLFlags(nFlag)); -} - -void CPDFSDK_XFAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {} - -void CPDFSDK_XFAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - return TRUE; -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - return TRUE; -} - -FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, - CPDFSDK_Annot* pNewAnnot) { - CXFA_FFWidgetHandler* pWidgetHandler = nullptr; - - if (pOldAnnot) - pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); - else if (pNewAnnot) - pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); - - if (pWidgetHandler) { - FX_BOOL bRet = TRUE; - CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : nullptr; - if (hWidget) { - CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); - if (pXFAPageView) { - bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); - if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) - bRet = TRUE; - } - } - return bRet; - } - - return TRUE; -} - -CXFA_FFWidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( - CPDFSDK_Annot* pAnnot) { - if (!pAnnot) - return nullptr; - - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - if (!pPageView) - return nullptr; - - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - if (!pSDKDoc) - return nullptr; - - CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); - if (!pDoc) - return nullptr; - - CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); - if (!pDocView) - return nullptr; - - return pDocView->GetWidgetHandler(); -} - -const uint32_t FWL_KEYFLAG_Ctrl = (1 << 0); -const uint32_t FWL_KEYFLAG_Alt = (1 << 1); -const uint32_t FWL_KEYFLAG_Shift = (1 << 2); -const uint32_t FWL_KEYFLAG_LButton = (1 << 3); -const uint32_t FWL_KEYFLAG_RButton = (1 << 4); -const uint32_t FWL_KEYFLAG_MButton = (1 << 5); - -uint32_t CPDFSDK_XFAAnnotHandler::GetFWLFlags(uint32_t dwFlag) { - uint32_t dwFWLFlag = 0; - - if (dwFlag & FWL_EVENTFLAG_ControlKey) - dwFWLFlag |= FWL_KEYFLAG_Ctrl; - if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) - dwFWLFlag |= FWL_KEYFLAG_LButton; - if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) - dwFWLFlag |= FWL_KEYFLAG_MButton; - if (dwFlag & FWL_EVENTFLAG_RightButtonDown) - dwFWLFlag |= FWL_KEYFLAG_RButton; - if (dwFlag & FWL_EVENTFLAG_ShiftKey) - dwFWLFlag |= FWL_KEYFLAG_Shift; - if (dwFlag & FWL_EVENTFLAG_AltKey) - dwFWLFlag |= FWL_KEYFLAG_Alt; - - return dwFWLFlag; -} diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp new file mode 100644 index 0000000000..9a9a7a8a4a --- /dev/null +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -0,0 +1,386 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/include/cpdfsdk_xfawidgethandler.h" + +#include "core/fpdfdoc/include/cpdf_interform.h" +#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" +#include "fpdfsdk/include/cpdfsdk_annot.h" +#include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_xfawidget.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "xfa/fxfa/include/fxfa_basic.h" +#include "xfa/fxfa/include/xfa_ffdocview.h" +#include "xfa/fxfa/include/xfa_ffpageview.h" +#include "xfa/fxfa/include/xfa_ffwidget.h" +#include "xfa/fxfa/include/xfa_ffwidgethandler.h" +#include "xfa/fxgraphics/include/cfx_graphics.h" +#include "xfa/fwl/core/include/fwl_widgethit.h" + +CPDFSDK_XFAWidgetHandler::CPDFSDK_XFAWidgetHandler(CPDFDoc_Environment* pApp) + : m_pApp(pApp) {} + +CPDFSDK_XFAWidgetHandler::~CPDFSDK_XFAWidgetHandler() {} + +CFX_ByteString CPDFSDK_XFAWidgetHandler::GetType() { + return FSDK_XFAWIDGET_TYPENAME; +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { + return !!pAnnot->GetXFAWidget(); +} + +CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CPDF_Annot* pAnnot, + CPDFSDK_PageView* pPage) { + return nullptr; +} + +CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CXFA_FFWidget* pAnnot, + CPDFSDK_PageView* pPage) { + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); + CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); + pInterForm->AddXFAMap(pAnnot, pWidget); + return pWidget; +} + +void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + uint32_t dwFlags) { + ASSERT(pPageView); + ASSERT(pAnnot); + + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + + CFX_Graphics gs; + gs.Create(pDevice); + + CFX_Matrix mt; + mt = *pUser2Device; + + FX_BOOL bIsHighlight = FALSE; + if (pSDKDoc->GetFocusAnnot() != pAnnot) + bIsHighlight = TRUE; + + pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); + + // to do highlight and shadow +} + +void CPDFSDK_XFAWidgetHandler::OnDrawSleep(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rcWindow, + uint32_t dwFlags) {} + +void CPDFSDK_XFAWidgetHandler::OnCreate(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_XFAWidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_XFAWidgetHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_XFAWidgetHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_XFAWidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { + CPDFSDK_XFAWidget* pWidget = reinterpret_cast(pAnnot); + CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); + pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); + + delete pWidget; +} + +void CPDFSDK_XFAWidgetHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} + +CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + ASSERT(pAnnot); + + CFX_RectF rcBBox; + XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType(); + if (eType == XFA_Element::Signature) + pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, TRUE); + else + pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None); + + CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, + rcBBox.top + rcBBox.height); + rcWidget.left -= 1.0f; + rcWidget.right += 1.0f; + rcWidget.bottom -= 1.0f; + rcWidget.top += 1.0f; + + return rcWidget; +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + if (!pSDKDoc) + return FALSE; + + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); + if (!pDoc) + return FALSE; + + CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); + if (!pDocView) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); + if (!pWidgetHandler) + return FALSE; + + FWL_WidgetHit dwHitTest = + pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); + return dwHitTest != FWL_WidgetHit::Unknown; +} + +void CPDFSDK_XFAWidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pPageView || !pAnnot) + return; + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); +} + +void CPDFSDK_XFAWidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pPageView || !pAnnot) + return; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnMouseWheel( + pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + if (!pPageView || !pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), + GetFWLFlags(nFlags), point.x, point.y); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags) { + if (!pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, + GetFWLFlags(nFlags)); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, + int nKeyCode, + int nFlag) { + if (!pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, + GetFWLFlags(nFlag)); +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, + int nKeyCode, + int nFlag) { + if (!pAnnot) + return FALSE; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, + GetFWLFlags(nFlag)); +} + +void CPDFSDK_XFAWidgetHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {} + +void CPDFSDK_XFAWidgetHandler::OnSelected(CPDFSDK_Annot* pAnnot) {} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + return TRUE; +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + return TRUE; +} + +FX_BOOL CPDFSDK_XFAWidgetHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, + CPDFSDK_Annot* pNewAnnot) { + CXFA_FFWidgetHandler* pWidgetHandler = nullptr; + + if (pOldAnnot) + pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); + else if (pNewAnnot) + pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); + + if (pWidgetHandler) { + FX_BOOL bRet = TRUE; + CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : nullptr; + if (hWidget) { + CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); + if (pXFAPageView) { + bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); + if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) + bRet = TRUE; + } + } + return bRet; + } + + return TRUE; +} + +CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler( + CPDFSDK_Annot* pAnnot) { + if (!pAnnot) + return nullptr; + + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + if (!pPageView) + return nullptr; + + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + if (!pSDKDoc) + return nullptr; + + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); + if (!pDoc) + return nullptr; + + CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); + if (!pDocView) + return nullptr; + + return pDocView->GetWidgetHandler(); +} + +const uint32_t FWL_KEYFLAG_Ctrl = (1 << 0); +const uint32_t FWL_KEYFLAG_Alt = (1 << 1); +const uint32_t FWL_KEYFLAG_Shift = (1 << 2); +const uint32_t FWL_KEYFLAG_LButton = (1 << 3); +const uint32_t FWL_KEYFLAG_RButton = (1 << 4); +const uint32_t FWL_KEYFLAG_MButton = (1 << 5); + +uint32_t CPDFSDK_XFAWidgetHandler::GetFWLFlags(uint32_t dwFlag) { + uint32_t dwFWLFlag = 0; + + if (dwFlag & FWL_EVENTFLAG_ControlKey) + dwFWLFlag |= FWL_KEYFLAG_Ctrl; + if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) + dwFWLFlag |= FWL_KEYFLAG_LButton; + if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) + dwFWLFlag |= FWL_KEYFLAG_MButton; + if (dwFlag & FWL_EVENTFLAG_RightButtonDown) + dwFWLFlag |= FWL_KEYFLAG_RButton; + if (dwFlag & FWL_EVENTFLAG_ShiftKey) + dwFWLFlag |= FWL_KEYFLAG_Shift; + if (dwFlag & FWL_EVENTFLAG_AltKey) + dwFWLFlag |= FWL_KEYFLAG_Alt; + + return dwFWLFlag; +} diff --git a/fpdfsdk/include/cpdfsdk_annothandlermgr.h b/fpdfsdk/include/cpdfsdk_annothandlermgr.h index 2ff35f83be..016135c0d0 100644 --- a/fpdfsdk/include/cpdfsdk_annothandlermgr.h +++ b/fpdfsdk/include/cpdfsdk_annothandlermgr.h @@ -19,12 +19,12 @@ class CPDF_Annot; class CPDFDoc_Environment; class CPDFSDK_Annot; class CPDFSDK_BAAnnotHandler; -class CPDFSDK_BFAnnotHandler; +class CPDFSDK_WidgetHandler; class CPDFSDK_PageView; class IPDFSDK_AnnotHandler; #ifdef PDF_ENABLE_XFA -class CPDFSDK_XFAAnnotHandler; +class CPDFSDK_XFAWidgetHandler; class CXFA_FFWidget; #endif // PDF_ENABLE_XFA @@ -113,9 +113,9 @@ class CPDFSDK_AnnotHandlerMgr { CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext); std::unique_ptr m_pBAAnnotHandler; - std::unique_ptr m_pBFAnnotHandler; + std::unique_ptr m_pWidgetHandler; #ifdef PDF_ENABLE_XFA - std::unique_ptr m_pXFAAnnotHandler; + std::unique_ptr m_pXFAWidgetHandler; #endif // PDF_ENABLE_XFA CPDFDoc_Environment* m_pApp; diff --git a/fpdfsdk/include/cpdfsdk_bfannothandler.h b/fpdfsdk/include/cpdfsdk_bfannothandler.h deleted file mode 100644 index be7e79279d..0000000000 --- a/fpdfsdk/include/cpdfsdk_bfannothandler.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_INCLUDE_CPDFSDK_BFANNOTHANDLER_H_ -#define FPDFSDK_INCLUDE_CPDFSDK_BFANNOTHANDLER_H_ - -#include "core/fxcrt/include/fx_basic.h" -#include "core/fxcrt/include/fx_coordinates.h" -#include "fpdfsdk/include/ipdfsdk_annothandler.h" - -class CFFL_IFormFiller; -class CFX_Matrix; -class CFX_RenderDevice; -class CPDF_Annot; -class CPDFDoc_Environment; -class CPDFSDK_Annot; -class CPDFSDK_PageView; - -#ifdef PDF_ENABLE_XFA -class CXFA_FFWidget; -#endif // PDF_ENABLE_XFA - -class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler { - public: - explicit CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp); - ~CPDFSDK_BFAnnotHandler() override; - - CFX_ByteString GetType() override; - FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override; - CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override; -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot* NewAnnot(CXFA_FFWidget* hWidget, - CPDFSDK_PageView* pPage) override; -#endif // PDF_ENABLE_XFA - void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; - void DeleteAnnot(CPDFSDK_Annot* pAnnot) override; - CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) override; - FX_BOOL HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - const CFX_FloatPoint& point) override; - void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - uint32_t dwFlags) override; - void OnDrawSleep(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rcWindow, - uint32_t dwFlags) override; - void OnCreate(CPDFSDK_Annot* pAnnot) override; - void OnLoad(CPDFSDK_Annot* pAnnot) override; - void OnDelete(CPDFSDK_Annot* pAnnot) override; - void OnRelease(CPDFSDK_Annot* pAnnot) override; - void OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) override; - void OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) override; - FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags) override; - FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; - FX_BOOL OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; - void OnDeSelected(CPDFSDK_Annot* pAnnot) override {} - void OnSelected(CPDFSDK_Annot* pAnnot) override {} - FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; - FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; -#ifdef PDF_ENABLE_XFA - FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, - CPDFSDK_Annot* pNewAnnot) override; -#endif // PDF_ENABLE_XFA - - void SetFormFiller(CFFL_IFormFiller* pFiller) { m_pFormFiller = pFiller; } - CFFL_IFormFiller* GetFormFiller() { return m_pFormFiller; } - - private: - CPDFDoc_Environment* m_pApp; - CFFL_IFormFiller* m_pFormFiller; -}; - -#endif // FPDFSDK_INCLUDE_CPDFSDK_BFANNOTHANDLER_H_ diff --git a/fpdfsdk/include/cpdfsdk_widgethandler.h b/fpdfsdk/include/cpdfsdk_widgethandler.h new file mode 100644 index 0000000000..0155967f3a --- /dev/null +++ b/fpdfsdk/include/cpdfsdk_widgethandler.h @@ -0,0 +1,121 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_INCLUDE_CPDFSDK_WIDGETHANDLER_H_ +#define FPDFSDK_INCLUDE_CPDFSDK_WIDGETHANDLER_H_ + +#include "core/fxcrt/include/fx_basic.h" +#include "core/fxcrt/include/fx_coordinates.h" +#include "fpdfsdk/include/ipdfsdk_annothandler.h" + +class CFFL_IFormFiller; +class CFX_Matrix; +class CFX_RenderDevice; +class CPDF_Annot; +class CPDFDoc_Environment; +class CPDFSDK_Annot; +class CPDFSDK_PageView; + +#ifdef PDF_ENABLE_XFA +class CXFA_FFWidget; +#endif // PDF_ENABLE_XFA + +class CPDFSDK_WidgetHandler : public IPDFSDK_AnnotHandler { + public: + explicit CPDFSDK_WidgetHandler(CPDFDoc_Environment* pApp); + ~CPDFSDK_WidgetHandler() override; + + CFX_ByteString GetType() override; + FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override; + CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override; +#ifdef PDF_ENABLE_XFA + CPDFSDK_Annot* NewAnnot(CXFA_FFWidget* hWidget, + CPDFSDK_PageView* pPage) override; +#endif // PDF_ENABLE_XFA + void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; + void DeleteAnnot(CPDFSDK_Annot* pAnnot) override; + CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) override; + FX_BOOL HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + const CFX_FloatPoint& point) override; + void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + uint32_t dwFlags) override; + void OnDrawSleep(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rcWindow, + uint32_t dwFlags) override; + void OnCreate(CPDFSDK_Annot* pAnnot) override; + void OnLoad(CPDFSDK_Annot* pAnnot) override; + void OnDelete(CPDFSDK_Annot* pAnnot) override; + void OnRelease(CPDFSDK_Annot* pAnnot) override; + void OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) override; + void OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) override; + FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags) override; + FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; + FX_BOOL OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; + void OnDeSelected(CPDFSDK_Annot* pAnnot) override {} + void OnSelected(CPDFSDK_Annot* pAnnot) override {} + FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; + FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; +#ifdef PDF_ENABLE_XFA + FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, + CPDFSDK_Annot* pNewAnnot) override; +#endif // PDF_ENABLE_XFA + + void SetFormFiller(CFFL_IFormFiller* pFiller) { m_pFormFiller = pFiller; } + CFFL_IFormFiller* GetFormFiller() { return m_pFormFiller; } + + private: + CPDFDoc_Environment* m_pApp; + CFFL_IFormFiller* m_pFormFiller; +}; + +#endif // FPDFSDK_INCLUDE_CPDFSDK_WIDGETHANDLER_H_ diff --git a/fpdfsdk/include/cpdfsdk_xfaannothandler.h b/fpdfsdk/include/cpdfsdk_xfaannothandler.h deleted file mode 100644 index 2dd6f297a7..0000000000 --- a/fpdfsdk/include/cpdfsdk_xfaannothandler.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_INCLUDE_CPDFSDK_XFAANNOTHANDLER_H_ -#define FPDFSDK_INCLUDE_CPDFSDK_XFAANNOTHANDLER_H_ - -#include "core/fxcrt/include/fx_basic.h" -#include "core/fxcrt/include/fx_coordinates.h" -#include "fpdfsdk/include/ipdfsdk_annothandler.h" - -class CFX_Matrix; -class CFX_RenderDevice; -class CPDF_Annot; -class CPDFDoc_Environment; -class CPDFSDK_Annot; -class CPDFSDK_PageView; -class CXFA_FFWidget; -class CXFA_FFWidgetHandler; - -class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler { - public: - explicit CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp); - ~CPDFSDK_XFAAnnotHandler() override; - - CFX_ByteString GetType() override; - FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override; - CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override; - CPDFSDK_Annot* NewAnnot(CXFA_FFWidget* pAnnot, - CPDFSDK_PageView* pPage) override; - void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; - void DeleteAnnot(CPDFSDK_Annot* pAnnot) override; - CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) override; - FX_BOOL HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - const CFX_FloatPoint& point) override; - void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - uint32_t dwFlags) override; - void OnDrawSleep(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rcWindow, - uint32_t dwFlags) override; - void OnCreate(CPDFSDK_Annot* pAnnot) override; - void OnLoad(CPDFSDK_Annot* pAnnot) override; - void OnDelete(CPDFSDK_Annot* pAnnot) override; - void OnRelease(CPDFSDK_Annot* pAnnot) override; - void OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) override; - void OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) override; - FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnRButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags) override; - FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; - FX_BOOL OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; - void OnDeSelected(CPDFSDK_Annot* pAnnot) override; - void OnSelected(CPDFSDK_Annot* pAnnot) override; - FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; - FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; - FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, - CPDFSDK_Annot* pNewAnnot) override; - - private: - CXFA_FFWidgetHandler* GetXFAWidgetHandler(CPDFSDK_Annot* pAnnot); - uint32_t GetFWLFlags(uint32_t dwFlag); - - CPDFDoc_Environment* m_pApp; -}; - -#endif // FPDFSDK_INCLUDE_CPDFSDK_XFAANNOTHANDLER_H_ diff --git a/fpdfsdk/include/cpdfsdk_xfawidgethandler.h b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h new file mode 100644 index 0000000000..84e74b4a73 --- /dev/null +++ b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h @@ -0,0 +1,113 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_INCLUDE_CPDFSDK_XFAWIDGETHANDLER_H_ +#define FPDFSDK_INCLUDE_CPDFSDK_XFAWIDGETHANDLER_H_ + +#include "core/fxcrt/include/fx_basic.h" +#include "core/fxcrt/include/fx_coordinates.h" +#include "fpdfsdk/include/ipdfsdk_annothandler.h" + +class CFX_Matrix; +class CFX_RenderDevice; +class CPDF_Annot; +class CPDFDoc_Environment; +class CPDFSDK_Annot; +class CPDFSDK_PageView; +class CXFA_FFWidget; +class CXFA_FFWidgetHandler; + +class CPDFSDK_XFAWidgetHandler : public IPDFSDK_AnnotHandler { + public: + explicit CPDFSDK_XFAWidgetHandler(CPDFDoc_Environment* pApp); + ~CPDFSDK_XFAWidgetHandler() override; + + CFX_ByteString GetType() override; + FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override; + CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override; + CPDFSDK_Annot* NewAnnot(CXFA_FFWidget* pAnnot, + CPDFSDK_PageView* pPage) override; + void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; + void DeleteAnnot(CPDFSDK_Annot* pAnnot) override; + CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) override; + FX_BOOL HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + const CFX_FloatPoint& point) override; + void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + uint32_t dwFlags) override; + void OnDrawSleep(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + const CFX_FloatRect& rcWindow, + uint32_t dwFlags) override; + void OnCreate(CPDFSDK_Annot* pAnnot) override; + void OnLoad(CPDFSDK_Annot* pAnnot) override; + void OnDelete(CPDFSDK_Annot* pAnnot) override; + void OnRelease(CPDFSDK_Annot* pAnnot) override; + void OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) override; + void OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) override; + FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnRButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags) override; + FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; + FX_BOOL OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override; + void OnDeSelected(CPDFSDK_Annot* pAnnot) override; + void OnSelected(CPDFSDK_Annot* pAnnot) override; + FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; + FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override; + FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, + CPDFSDK_Annot* pNewAnnot) override; + + private: + CXFA_FFWidgetHandler* GetXFAWidgetHandler(CPDFSDK_Annot* pAnnot); + uint32_t GetFWLFlags(uint32_t dwFlag); + + CPDFDoc_Environment* m_pApp; +}; + +#endif // FPDFSDK_INCLUDE_CPDFSDK_XFAWIDGETHANDLER_H_ -- cgit v1.2.3