From b94d7c9216160269d43a722b8e216790ba4b5d3b Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 21 Sep 2016 12:07:00 -0700 Subject: Make the I in IFormFiller explicit Typically the I prefix means Interface, except for CFFL_IFormFiller where it means Interactive. Rename CFFL_IFormFiller to CFFL_InteractiveFormFiller to make the meaning explicit. Review-Url: https://codereview.chromium.org/2357203003 --- BUILD.gn | 4 +- fpdfsdk/cpdfsdk_annothandlermgr.cpp | 2 +- fpdfsdk/cpdfsdk_environment.cpp | 10 +- fpdfsdk/cpdfsdk_interform.cpp | 4 +- fpdfsdk/formfiller/cffl_checkbox.cpp | 8 +- fpdfsdk/formfiller/cffl_combobox.cpp | 4 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 13 +- fpdfsdk/formfiller/cffl_formfiller.h | 2 +- fpdfsdk/formfiller/cffl_iformfiller.cpp | 1007 -------------------- fpdfsdk/formfiller/cffl_iformfiller.h | 189 ---- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 1013 +++++++++++++++++++++ fpdfsdk/formfiller/cffl_interactiveformfiller.h | 189 ++++ fpdfsdk/formfiller/cffl_listbox.cpp | 6 +- fpdfsdk/formfiller/cffl_radiobutton.cpp | 6 +- fpdfsdk/formfiller/cffl_textfield.cpp | 4 +- fpdfsdk/include/cpdfsdk_baannothandler.h | 2 +- fpdfsdk/include/cpdfsdk_environment.h | 7 +- fpdfsdk/include/cpdfsdk_widgethandler.h | 10 +- xfa/fxfa/parser/cxfa_document.cpp | 6 +- 19 files changed, 1243 insertions(+), 1243 deletions(-) delete mode 100644 fpdfsdk/formfiller/cffl_iformfiller.cpp delete mode 100644 fpdfsdk/formfiller/cffl_iformfiller.h create mode 100644 fpdfsdk/formfiller/cffl_interactiveformfiller.cpp create mode 100644 fpdfsdk/formfiller/cffl_interactiveformfiller.h diff --git a/BUILD.gn b/BUILD.gn index df8cdbaaad..22f018eadd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -990,8 +990,8 @@ static_library("formfiller") { "fpdfsdk/formfiller/cffl_combobox.h", "fpdfsdk/formfiller/cffl_formfiller.cpp", "fpdfsdk/formfiller/cffl_formfiller.h", - "fpdfsdk/formfiller/cffl_iformfiller.cpp", - "fpdfsdk/formfiller/cffl_iformfiller.h", + "fpdfsdk/formfiller/cffl_interactiveformfiller.cpp", + "fpdfsdk/formfiller/cffl_interactiveformfiller.h", "fpdfsdk/formfiller/cffl_listbox.cpp", "fpdfsdk/formfiller/cffl_listbox.h", "fpdfsdk/formfiller/cffl_pushbutton.cpp", diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp index f808b8412b..5092dc731f 100644 --- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -31,7 +31,7 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFSDK_Environment* pApp) m_pXFAWidgetHandler(new CPDFSDK_XFAWidgetHandler(pApp)), #endif // PDF_ENABLE_XFA m_pApp(pApp) { - m_pWidgetHandler->SetFormFiller(m_pApp->GetIFormFiller()); + m_pWidgetHandler->SetFormFiller(m_pApp->GetInteractiveFormFiller()); } CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} diff --git a/fpdfsdk/cpdfsdk_environment.cpp b/fpdfsdk/cpdfsdk_environment.cpp index 12ef66997b..21549bc1ab 100644 --- a/fpdfsdk/cpdfsdk_environment.cpp +++ b/fpdfsdk/cpdfsdk_environment.cpp @@ -6,7 +6,7 @@ #include "fpdfsdk/include/cpdfsdk_environment.h" -#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/include/cpdfsdk_annothandlermgr.h" #include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/javascript/ijs_runtime.h" @@ -207,8 +207,8 @@ CPDFSDK_ActionHandler* CPDFSDK_Environment::GetActionHander() { return m_pActionHandler.get(); } -CFFL_IFormFiller* CPDFSDK_Environment::GetIFormFiller() { - if (!m_pIFormFiller) - m_pIFormFiller.reset(new CFFL_IFormFiller(this)); - return m_pIFormFiller.get(); +CFFL_InteractiveFormFiller* CPDFSDK_Environment::GetInteractiveFormFiller() { + if (!m_pFormFiller) + m_pFormFiller.reset(new CFFL_InteractiveFormFiller(this)); + return m_pFormFiller.get(); } diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index e9fb5b4de0..ce6206a3f7 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -342,10 +342,10 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); - CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); - FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); + FX_RECT rcBBox = + pEnv->GetInteractiveFormFiller()->GetViewBBox(pPageView, pWidget); pEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom); diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp index ef1bf18ea6..01f1a2a08c 100644 --- a/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -42,17 +42,13 @@ FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, switch (nChar) { case FWL_VKEY_Return: case FWL_VKEY_Space: { - CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); - ASSERT(pIFormFiller); - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); ASSERT(pPageView); FX_BOOL bReset = FALSE; FX_BOOL bExit = FALSE; - - pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit, nFlags); - + m_pEnv->GetInteractiveFormFiller()->OnButtonUp(m_pWidget, pPageView, + bReset, bExit, nFlags); if (bReset) return TRUE; if (bExit) diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index 84e242ab5c..aaddcf5fbc 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -8,7 +8,7 @@ #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/include/cpdfsdk_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" @@ -54,7 +54,7 @@ CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, pWnd->AttachFFLData(this); pWnd->Create(cp); - CFFL_IFormFiller* pFormFiller = m_pEnv->GetIFormFiller(); + CFFL_InteractiveFormFiller* pFormFiller = m_pEnv->GetInteractiveFormFiller(); pWnd->SetFillerNotify(pFormFiller); int32_t nCurSel = m_pWidget->GetSelectedIndex(0); diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 889f3b46a1..7aeda57c2e 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -94,7 +94,7 @@ void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, pWnd->DrawAppearance(pDevice, &mt); } else { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (CFFL_IFormFiller::IsVisible(pWidget)) + if (CFFL_InteractiveFormFiller::IsVisible(pWidget)) pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); } @@ -525,8 +525,9 @@ FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, if (IsDataChanged(pPageView)) { FX_BOOL bRC = TRUE; FX_BOOL bExit = FALSE; - CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); - pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); + CFFL_InteractiveFormFiller* pFormFiller = + m_pEnv->GetInteractiveFormFiller(); + pFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); if (bExit) return TRUE; if (!bRC) { @@ -534,7 +535,7 @@ FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, return TRUE; } - pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); + pFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); if (bExit) return TRUE; if (!bRC) { @@ -543,11 +544,11 @@ FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, } SaveData(pPageView); - pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); + pFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); if (bExit) return TRUE; - pIFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); + pFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); } return TRUE; } diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h index d2f2fe6230..1d679df536 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.h +++ b/fpdfsdk/formfiller/cffl_formfiller.h @@ -10,7 +10,7 @@ #include #include "fpdfsdk/formfiller/cba_fontmap.h" -#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/include/pdfsdk_fieldaction.h" class CPDFSDK_Annot; diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp deleted file mode 100644 index 83e91982cc..0000000000 --- a/fpdfsdk/formfiller/cffl_iformfiller.cpp +++ /dev/null @@ -1,1007 +0,0 @@ -// Copyright 2014 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/formfiller/cffl_iformfiller.h" - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fxge/include/cfx_graphstatedata.h" -#include "core/fxge/include/cfx_pathdata.h" -#include "core/fxge/include/cfx_renderdevice.h" -#include "fpdfsdk/formfiller/cffl_checkbox.h" -#include "fpdfsdk/formfiller/cffl_combobox.h" -#include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/formfiller/cffl_listbox.h" -#include "fpdfsdk/formfiller/cffl_pushbutton.h" -#include "fpdfsdk/formfiller/cffl_radiobutton.h" -#include "fpdfsdk/formfiller/cffl_textfield.h" -#include "fpdfsdk/include/cpdfsdk_document.h" -#include "fpdfsdk/include/cpdfsdk_environment.h" -#include "fpdfsdk/include/cpdfsdk_interform.h" -#include "fpdfsdk/include/cpdfsdk_pageview.h" -#include "fpdfsdk/include/cpdfsdk_widget.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" - -#define FFL_MAXLISTBOXHEIGHT 140.0f - -CFFL_IFormFiller::CFFL_IFormFiller(CPDFSDK_Environment* pEnv) - : m_pEnv(pEnv), m_bNotifying(FALSE) {} - -CFFL_IFormFiller::~CFFL_IFormFiller() {} - -FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_FloatPoint point) { - CFX_FloatRect rc = pAnnot->GetRect(); - return rc.Contains(point.x, point.y); -} - -FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) - return pFormFiller->GetViewBBox(pPageView, pAnnot); - - ASSERT(pPageView); - - CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - CFX_FloatRect rcWin = CPWL_Utils::InflateRect(pPDFAnnot->GetRect(), 1); - return rcWin.GetOuterRect(); -} - -void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - ASSERT(pPageView); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - if (!IsVisible(pWidget)) - return; - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - if (pFormFiller->IsValid()) { - pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); - pAnnot->GetPDFPage(); - - CPDFSDK_Document* pDocument = m_pEnv->GetSDKDocument(); - if (pDocument->GetFocusAnnot() == pAnnot) { - CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); - if (!rcFocus.IsEmpty()) { - CFX_PathData path; - path.SetPointCount(5); - path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO); - path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO); - path.SetPoint(2, rcFocus.right, rcFocus.bottom, FXPT_LINETO); - path.SetPoint(3, rcFocus.right, rcFocus.top, FXPT_LINETO); - path.SetPoint(4, rcFocus.left, rcFocus.top, FXPT_LINETO); - - CFX_GraphStateData gsd; - gsd.SetDashCount(1); - gsd.m_DashArray[0] = 1.0f; - gsd.m_DashPhase = 0; - gsd.m_LineWidth = 1.0f; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE); - } - } - return; - } - } - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device); - } else { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); - } - - if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) - pWidget->DrawShadow(pDevice, pPageView); -} - -void CFFL_IFormFiller::OnCreate(CPDFSDK_Annot* pAnnot) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->OnCreate(pAnnot); - } -} - -void CFFL_IFormFiller::OnLoad(CPDFSDK_Annot* pAnnot) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->OnLoad(pAnnot); - } -} - -void CFFL_IFormFiller::OnDelete(CPDFSDK_Annot* pAnnot) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->OnDelete(pAnnot); - } - - UnRegisterFormFiller(pAnnot); -} - -void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) { - m_bNotifying = TRUE; - - int nValueAge = pWidget->GetValueAge(); - - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView); - m_bNotifying = FALSE; - - if (pWidget->IsAppModified()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - pWidget->GetValueAge() == nValueAge); - } - } - } - } - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) { - pFormFiller->OnMouseEnter(pPageView, pAnnot); - } -} - -void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) { - m_bNotifying = TRUE; - pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView); - m_bNotifying = FALSE; - - if (pWidget->IsAppModified()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - } - } - } - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->OnMouseExit(pPageView, pAnnot); - } -} - -FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (Annot_HitTest(pPageView, pAnnot, point) && - pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) { - m_bNotifying = TRUE; - pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlags); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlags); - pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pAnnot)) - return TRUE; - - if (pWidget->IsAppModified()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - } - } - } - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - CPDFSDK_Document* pDocument = m_pEnv->GetSDKDocument(); - - switch (pWidget->GetFieldType()) { - case FIELDTYPE_PUSHBUTTON: - case FIELDTYPE_CHECKBOX: - case FIELDTYPE_RADIOBUTTON: - if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y)) - pDocument->SetFocusAnnot(pAnnot); - break; - default: - pDocument->SetFocusAnnot(pAnnot); - break; - } - - FX_BOOL bRet = FALSE; - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); - } - - if (pDocument->GetFocusAnnot() == pAnnot) { - FX_BOOL bExit = FALSE; - FX_BOOL bReset = FALSE; - OnButtonUp(pWidget, pPageView, bReset, bExit, nFlags); - if (bExit) - return TRUE; -#ifdef PDF_ENABLE_XFA - OnClick(pWidget, pPageView, bReset, bExit, nFlags); - if (bExit) - return TRUE; -#endif // PDF_ENABLE_XFA - } - return bRet; -} - -void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag) { - ASSERT(pWidget); - - if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) { - m_bNotifying = TRUE; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = TRUE; - return; - } - - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - - bReset = TRUE; - } - } - } -} - -FX_BOOL CFFL_IFormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - // change cursor - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) { - return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, - uint32_t nKeyCode, - uint32_t nFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - if (nChar == FWL_VKEY_Tab) - return TRUE; - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) - return pFormFiller->OnChar(pAnnot, nChar, nFlags); - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { - if (!pAnnot) - return FALSE; - - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) { - m_bNotifying = TRUE; - pWidget->GetAppearanceAge(); - - int nValueAge = pWidget->GetValueAge(); - pWidget->ClearAppModified(); - - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE); - if (!pFormFiller) - return FALSE; - pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa); - pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView); - m_bNotifying = FALSE; - - if (pWidget->IsAppModified()) { - if (CFFL_FormFiller* pFiller = GetFormFiller(pWidget, FALSE)) { - pFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - } - } - } - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) - pFormFiller->SetFocusForAnnot(pAnnot, nFlag); - - return TRUE; -} - -FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { - if (!pAnnot) - return FALSE; - ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - pFormFiller->KillFocusForAnnot(pAnnot, nFlag); - - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) { - m_bNotifying = TRUE; - pWidget->ClearAppModified(); - - CPDFSDK_PageView* pPageView = pWidget->GetPageView(); - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa); - - pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView); - m_bNotifying = FALSE; - } - } - } - - return TRUE; -} - -FX_BOOL CFFL_IFormFiller::IsVisible(CPDFSDK_Widget* pWidget) { - return pWidget->IsVisible(); -} - -FX_BOOL CFFL_IFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget) { - int nFieldFlags = pWidget->GetFieldFlags(); - return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY; -} - -FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget) { - 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) || - (dwPermissions & FPDFPERM_MODIFY); -} - -CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, - FX_BOOL bRegister) { - auto it = m_Maps.find(pAnnot); - if (it != m_Maps.end()) - return it->second.get(); - - if (!bRegister) - return nullptr; - - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - int nFieldType = pWidget->GetFieldType(); - CFFL_FormFiller* pFormFiller; - switch (nFieldType) { - case FIELDTYPE_PUSHBUTTON: - pFormFiller = new CFFL_PushButton(m_pEnv, pWidget); - break; - case FIELDTYPE_CHECKBOX: - pFormFiller = new CFFL_CheckBox(m_pEnv, pWidget); - break; - case FIELDTYPE_RADIOBUTTON: - pFormFiller = new CFFL_RadioButton(m_pEnv, pWidget); - break; - case FIELDTYPE_TEXTFIELD: - pFormFiller = new CFFL_TextField(m_pEnv, pWidget); - break; - case FIELDTYPE_LISTBOX: - pFormFiller = new CFFL_ListBox(m_pEnv, pWidget); - break; - case FIELDTYPE_COMBOBOX: - pFormFiller = new CFFL_ComboBox(m_pEnv, pWidget); - break; - case FIELDTYPE_UNKNOWN: - default: - pFormFiller = nullptr; - break; - } - - if (!pFormFiller) - return nullptr; - - m_Maps[pAnnot].reset(pFormFiller); - return pFormFiller; -} - -void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) { - if (pAnnot) { - UnRegisterFormFiller(pAnnot); - } -} - -void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { - auto it = m_Maps.find(pAnnot); - if (it == m_Maps.end()) - return; - - m_Maps.erase(it); -} - -void CFFL_IFormFiller::QueryWherePopup(void* pPrivateData, - FX_FLOAT fPopupMin, - FX_FLOAT fPopupMax, - int32_t& nRet, - FX_FLOAT& fPopupRet) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; - - CFX_FloatRect rcPageView(0, 0, 0, 0); - rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth(); - rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight(); - rcPageView.Normalize(); - - CFX_FloatRect rcAnnot = pData->pWidget->GetRect(); - - FX_FLOAT fTop = 0.0f; - FX_FLOAT fBottom = 0.0f; - - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pData->pWidget; - switch (pWidget->GetRotate() / 90) { - default: - case 0: - fTop = rcPageView.top - rcAnnot.top; - fBottom = rcAnnot.bottom - rcPageView.bottom; - break; - case 1: - fTop = rcAnnot.left - rcPageView.left; - fBottom = rcPageView.right - rcAnnot.right; - break; - case 2: - fTop = rcAnnot.bottom - rcPageView.bottom; - fBottom = rcPageView.top - rcAnnot.top; - break; - case 3: - fTop = rcPageView.right - rcAnnot.right; - fBottom = rcAnnot.left - rcPageView.left; - break; - } - - FX_FLOAT fFactHeight = 0; - FX_BOOL bBottom = TRUE; - FX_FLOAT fMaxListBoxHeight = 0; - if (fPopupMax > FFL_MAXLISTBOXHEIGHT) { - if (fPopupMin > FFL_MAXLISTBOXHEIGHT) { - fMaxListBoxHeight = fPopupMin; - } else { - fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT; - } - } else { - fMaxListBoxHeight = fPopupMax; - } - - if (fBottom > fMaxListBoxHeight) { - fFactHeight = fMaxListBoxHeight; - bBottom = TRUE; - } else { - if (fTop > fMaxListBoxHeight) { - fFactHeight = fMaxListBoxHeight; - bBottom = FALSE; - } else { - if (fTop > fBottom) { - fFactHeight = fTop; - bBottom = FALSE; - } else { - fFactHeight = fBottom; - bBottom = TRUE; - } - } - } - - nRet = bBottom ? 0 : 1; - fPopupRet = fFactHeight; -} - -void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { - m_bNotifying = TRUE; - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - fa.bWillCommit = TRUE; - fa.bKeyDown = TRUE; - fa.bRC = TRUE; - - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); - pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa); - pFormFiller->SaveState(pPageView); - - pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView); - - bRC = fa.bRC; - m_bNotifying = FALSE; - } - } -} - -void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { - m_bNotifying = TRUE; - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - fa.bKeyDown = TRUE; - fa.bRC = TRUE; - - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); - pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); - pFormFiller->SaveState(pPageView); - - pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView); - - bRC = fa.bRC; - m_bNotifying = FALSE; - } - } -} - -void CFFL_IFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); - pInterForm->OnCalculate(pWidget->GetFormField()); - m_bNotifying = FALSE; - } -} - -void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); - - FX_BOOL bFormatted = FALSE; - CFX_WideString sValue = - pInterForm->OnFormat(pWidget->GetFormField(), bFormatted); - - if (bExit) - return; - - if (bFormatted) { - pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, TRUE); - pInterForm->UpdateField(pWidget->GetFormField()); - } - - m_bNotifying = FALSE; - } -} - -#ifdef PDF_ENABLE_XFA -void CFFL_IFormFiller::OnClick(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_Click)) { - m_bNotifying = TRUE; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = TRUE; - return; - } - - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - - bReset = TRUE; - } - } - } -} - -void CFFL_IFormFiller::OnFull(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_Full)) { - m_bNotifying = TRUE; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = TRUE; - return; - } - - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - - bReset = TRUE; - } - } - } -} - -void CFFL_IFormFiller::OnPopupPreOpen(void* pPrivateData, - FX_BOOL& bExit, - uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; - ASSERT(pData); - ASSERT(pData->pWidget); - - FX_BOOL bTempReset = FALSE; - FX_BOOL bTempExit = FALSE; - OnPreOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); - - if (bTempReset || bTempExit) { - bExit = TRUE; - } -} - -void CFFL_IFormFiller::OnPopupPostOpen(void* pPrivateData, - FX_BOOL& bExit, - uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; - ASSERT(pData); - ASSERT(pData->pWidget); - - FX_BOOL bTempReset = FALSE; - FX_BOOL bTempExit = FALSE; - OnPostOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); - - if (bTempReset || bTempExit) { - bExit = TRUE; - } -} - -void CFFL_IFormFiller::OnPreOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) { - m_bNotifying = TRUE; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = TRUE; - return; - } - - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - - bReset = TRUE; - } - } - } -} - -void CFFL_IFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) { - m_bNotifying = TRUE; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - - pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView); - m_bNotifying = FALSE; - - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = TRUE; - return; - } - - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - - bReset = TRUE; - } - } - } -} -#endif // PDF_ENABLE_XFA - -FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - if (pPageView) - return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot()); - - return FALSE; -} - -void CFFL_IFormFiller::OnBeforeKeyStroke(void* pPrivateData, - CFX_WideString& strChange, - const CFX_WideString& strChangeEx, - int nSelStart, - int nSelEnd, - FX_BOOL bKeyDown, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; - ASSERT(pData->pWidget); - - CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE); - -#ifdef PDF_ENABLE_XFA - if (pFormFiller->IsFieldFull(pData->pPageView)) { - FX_BOOL bFullExit = FALSE; - FX_BOOL bFullReset = FALSE; - OnFull(pData->pWidget, pData->pPageView, bFullReset, bFullExit, nFlag); - - if (bFullReset || bFullExit) { - bExit = TRUE; - return; - } - } -#endif // PDF_ENABLE_XFA - - if (!m_bNotifying) { - if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { - m_bNotifying = TRUE; - int nAge = pData->pWidget->GetAppearanceAge(); - int nValueAge = pData->pWidget->GetValueAge(); - - CPDFSDK_Document* pDocument = pData->pPageView->GetSDKDocument(); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); - fa.sChange = strChange; - fa.sChangeEx = strChangeEx; - fa.bKeyDown = bKeyDown; - fa.bWillCommit = FALSE; - fa.bRC = TRUE; - fa.nSelStart = nSelStart; - fa.nSelEnd = nSelEnd; - - pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa); - pFormFiller->SaveState(pData->pPageView); - - if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, - pData->pPageView)) { - if (!IsValidAnnot(pData->pPageView, pData->pWidget)) { - bExit = TRUE; - m_bNotifying = FALSE; - return; - } - - if (nAge != pData->pWidget->GetAppearanceAge()) { - CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow( - pData->pPageView, nValueAge == pData->pWidget->GetValueAge()); - pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - bExit = TRUE; - } - - if (fa.bRC) { - pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, - fa); - bRC = FALSE; - } else { - pFormFiller->RestoreState(pData->pPageView); - bRC = FALSE; - } - - if (pDocument->GetFocusAnnot() != pData->pWidget) { - pFormFiller->CommitData(pData->pPageView, nFlag); - bExit = TRUE; - } - } else { - if (!IsValidAnnot(pData->pPageView, pData->pWidget)) { - bExit = TRUE; - m_bNotifying = FALSE; - return; - } - } - - m_bNotifying = FALSE; - } - } -} diff --git a/fpdfsdk/formfiller/cffl_iformfiller.h b/fpdfsdk/formfiller/cffl_iformfiller.h deleted file mode 100644 index f326123a47..0000000000 --- a/fpdfsdk/formfiller/cffl_iformfiller.h +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2014 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_FORMFILLER_CFFL_IFORMFILLER_H_ -#define FPDFSDK_FORMFILLER_CFFL_IFORMFILLER_H_ - -#include -#include - -#include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" - -class CFFL_FormFiller; -class CPDFSDK_Environment; -class CPDFSDK_Annot; -class CPDFSDK_PageView; -class CPDFSDK_Widget; - -class CFFL_IFormFiller : public IPWL_Filler_Notify { - public: - explicit CFFL_IFormFiller(CPDFSDK_Environment* pEnv); - ~CFFL_IFormFiller() override; - - virtual FX_BOOL Annot_HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_FloatPoint point); - virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot); - virtual void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device); - - virtual void OnCreate(CPDFSDK_Annot* pAnnot); - virtual void OnLoad(CPDFSDK_Annot* pAnnot); - virtual void OnDelete(CPDFSDK_Annot* pAnnot); - - virtual void OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag); - virtual void OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlag); - - virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - short zDelta, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_FloatPoint& point); - - virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, - uint32_t nKeyCode, - uint32_t nFlags); - virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, - uint32_t nChar, - uint32_t nFlags); - - virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag); - virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag); - - CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister); - void RemoveFormFiller(CPDFSDK_Annot* pAnnot); - - static FX_BOOL IsVisible(CPDFSDK_Widget* pWidget); - static FX_BOOL IsReadOnly(CPDFSDK_Widget* pWidget); - static FX_BOOL IsFillingAllowed(CPDFSDK_Widget* pWidget); - static FX_BOOL IsValidAnnot(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot); - - void OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag); - void OnValidate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag); - - void OnCalculate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - uint32_t nFlag); - void OnFormat(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - uint32_t nFlag); - void OnButtonUp(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag); -#ifdef PDF_ENABLE_XFA - void OnClick(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag); - void OnFull(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag); - void OnPreOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag); - void OnPostOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - uint32_t nFlag); -#endif // PDF_ENABLE_XFA - - private: - using CFFL_Widget2Filler = - std::map>; - - // IPWL_Filler_Notify: - void QueryWherePopup(void* pPrivateData, - FX_FLOAT fPopupMin, - FX_FLOAT fPopupMax, - int32_t& nRet, - FX_FLOAT& fPopupRet) override; - void OnBeforeKeyStroke(void* pPrivateData, - CFX_WideString& strChange, - const CFX_WideString& strChangeEx, - int nSelStart, - int nSelEnd, - FX_BOOL bKeyDown, - FX_BOOL& bRC, - FX_BOOL& bExit, - uint32_t nFlag) override; -#ifdef PDF_ENABLE_XFA - void OnPopupPreOpen(void* pPrivateData, - FX_BOOL& bExit, - uint32_t nFlag) override; - void OnPopupPostOpen(void* pPrivateData, - FX_BOOL& bExit, - uint32_t nFlag) override; - void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, - FX_BOOL bSameField, - FX_BOOL bNext); -#endif // PDF_ENABLE_XFA - void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); - - CPDFSDK_Environment* const m_pEnv; - CFFL_Widget2Filler m_Maps; - FX_BOOL m_bNotifying; -}; - -class CFFL_PrivateData { - public: - CPDFSDK_Widget* pWidget; - CPDFSDK_PageView* pPageView; - int nWidgetAge; - int nValueAge; -}; - -#endif // FPDFSDK_FORMFILLER_CFFL_IFORMFILLER_H_ diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp new file mode 100644 index 0000000000..3d1a716580 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -0,0 +1,1013 @@ +// Copyright 2014 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/formfiller/cffl_interactiveformfiller.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fxge/include/cfx_graphstatedata.h" +#include "core/fxge/include/cfx_pathdata.h" +#include "core/fxge/include/cfx_renderdevice.h" +#include "fpdfsdk/formfiller/cffl_checkbox.h" +#include "fpdfsdk/formfiller/cffl_combobox.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_listbox.h" +#include "fpdfsdk/formfiller/cffl_pushbutton.h" +#include "fpdfsdk/formfiller/cffl_radiobutton.h" +#include "fpdfsdk/formfiller/cffl_textfield.h" +#include "fpdfsdk/include/cpdfsdk_document.h" +#include "fpdfsdk/include/cpdfsdk_environment.h" +#include "fpdfsdk/include/cpdfsdk_interform.h" +#include "fpdfsdk/include/cpdfsdk_pageview.h" +#include "fpdfsdk/include/cpdfsdk_widget.h" +#include "fpdfsdk/pdfwindow/PWL_Utils.h" + +#define FFL_MAXLISTBOXHEIGHT 140.0f + +CFFL_InteractiveFormFiller::CFFL_InteractiveFormFiller( + CPDFSDK_Environment* pEnv) + : m_pEnv(pEnv), m_bNotifying(FALSE) {} + +CFFL_InteractiveFormFiller::~CFFL_InteractiveFormFiller() {} + +FX_BOOL CFFL_InteractiveFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_FloatPoint point) { + CFX_FloatRect rc = pAnnot->GetRect(); + return rc.Contains(point.x, point.y); +} + +FX_RECT CFFL_InteractiveFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) + return pFormFiller->GetViewBBox(pPageView, pAnnot); + + ASSERT(pPageView); + + CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); + CFX_FloatRect rcWin = CPWL_Utils::InflateRect(pPDFAnnot->GetRect(), 1); + return rcWin.GetOuterRect(); +} + +void CFFL_InteractiveFormFiller::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + ASSERT(pPageView); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + + if (!IsVisible(pWidget)) + return; + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + if (pFormFiller->IsValid()) { + pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); + pAnnot->GetPDFPage(); + + CPDFSDK_Document* pDocument = m_pEnv->GetSDKDocument(); + if (pDocument->GetFocusAnnot() == pAnnot) { + CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); + if (!rcFocus.IsEmpty()) { + CFX_PathData path; + path.SetPointCount(5); + path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO); + path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO); + path.SetPoint(2, rcFocus.right, rcFocus.bottom, FXPT_LINETO); + path.SetPoint(3, rcFocus.right, rcFocus.top, FXPT_LINETO); + path.SetPoint(4, rcFocus.left, rcFocus.top, FXPT_LINETO); + + CFX_GraphStateData gsd; + gsd.SetDashCount(1); + gsd.m_DashArray[0] = 1.0f; + gsd.m_DashPhase = 0; + gsd.m_LineWidth = 1.0f; + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, + ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE); + } + } + return; + } + } + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device); + } else { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + } + + if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) + pWidget->DrawShadow(pDevice, pPageView); +} + +void CFFL_InteractiveFormFiller::OnCreate(CPDFSDK_Annot* pAnnot) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->OnCreate(pAnnot); + } +} + +void CFFL_InteractiveFormFiller::OnLoad(CPDFSDK_Annot* pAnnot) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->OnLoad(pAnnot); + } +} + +void CFFL_InteractiveFormFiller::OnDelete(CPDFSDK_Annot* pAnnot) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->OnDelete(pAnnot); + } + + UnRegisterFormFiller(pAnnot); +} + +void CFFL_InteractiveFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (!m_bNotifying) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) { + m_bNotifying = TRUE; + + int nValueAge = pWidget->GetValueAge(); + + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView); + m_bNotifying = FALSE; + + if (pWidget->IsAppModified()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + pWidget->GetValueAge() == nValueAge); + } + } + } + } + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) { + pFormFiller->OnMouseEnter(pPageView, pAnnot); + } +} + +void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (!m_bNotifying) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) { + m_bNotifying = TRUE; + pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView); + m_bNotifying = FALSE; + + if (pWidget->IsAppModified()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + } + } + } + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->OnMouseExit(pPageView, pAnnot); + } +} + +FX_BOOL CFFL_InteractiveFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (!m_bNotifying) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (Annot_HitTest(pPageView, pAnnot, point) && + pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) { + m_bNotifying = TRUE; + pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlags); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlags); + pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pAnnot)) + return TRUE; + + if (pWidget->IsAppModified()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + } + } + } + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDFSDK_Document* pDocument = m_pEnv->GetSDKDocument(); + + switch (pWidget->GetFieldType()) { + case FIELDTYPE_PUSHBUTTON: + case FIELDTYPE_CHECKBOX: + case FIELDTYPE_RADIOBUTTON: + if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y)) + pDocument->SetFocusAnnot(pAnnot); + break; + default: + pDocument->SetFocusAnnot(pAnnot); + break; + } + + FX_BOOL bRet = FALSE; + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); + } + + if (pDocument->GetFocusAnnot() == pAnnot) { + FX_BOOL bExit = FALSE; + FX_BOOL bReset = FALSE; + OnButtonUp(pWidget, pPageView, bReset, bExit, nFlags); + if (bExit) + return TRUE; +#ifdef PDF_ENABLE_XFA + OnClick(pWidget, pPageView, bReset, bExit, nFlags); + if (bExit) + return TRUE; +#endif // PDF_ENABLE_XFA + } + return bRet; +} + +void CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag) { + ASSERT(pWidget); + + if (!m_bNotifying) { + if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) { + m_bNotifying = TRUE; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pWidget)) { + bExit = TRUE; + return; + } + + if (nAge != pWidget->GetAppearanceAge()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + + bReset = TRUE; + } + } + } +} + +FX_BOOL CFFL_InteractiveFormFiller::OnLButtonDblClk( + CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + // change cursor + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) { + return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, + uint32_t nKeyCode, + uint32_t nFlags) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); + } + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + if (nChar == FWL_VKEY_Tab) + return TRUE; + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) + return pFormFiller->OnChar(pAnnot, nChar, nFlags); + + return FALSE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot) + return FALSE; + + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (!m_bNotifying) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) { + m_bNotifying = TRUE; + pWidget->GetAppearanceAge(); + + int nValueAge = pWidget->GetValueAge(); + pWidget->ClearAppModified(); + + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE); + if (!pFormFiller) + return FALSE; + pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa); + pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView); + m_bNotifying = FALSE; + + if (pWidget->IsAppModified()) { + if (CFFL_FormFiller* pFiller = GetFormFiller(pWidget, FALSE)) { + pFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + } + } + } + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) + pFormFiller->SetFocusForAnnot(pAnnot, nFlag); + + return TRUE; +} + +FX_BOOL CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, + uint32_t nFlag) { + if (!pAnnot) + return FALSE; + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + pFormFiller->KillFocusForAnnot(pAnnot, nFlag); + + if (!m_bNotifying) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) { + m_bNotifying = TRUE; + pWidget->ClearAppModified(); + + CPDFSDK_PageView* pPageView = pWidget->GetPageView(); + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa); + + pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView); + m_bNotifying = FALSE; + } + } + } + + return TRUE; +} + +FX_BOOL CFFL_InteractiveFormFiller::IsVisible(CPDFSDK_Widget* pWidget) { + return pWidget->IsVisible(); +} + +FX_BOOL CFFL_InteractiveFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget) { + int nFieldFlags = pWidget->GetFieldFlags(); + return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY; +} + +FX_BOOL CFFL_InteractiveFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget) { + 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) || + (dwPermissions & FPDFPERM_MODIFY); +} + +CFFL_FormFiller* CFFL_InteractiveFormFiller::GetFormFiller( + CPDFSDK_Annot* pAnnot, + FX_BOOL bRegister) { + auto it = m_Maps.find(pAnnot); + if (it != m_Maps.end()) + return it->second.get(); + + if (!bRegister) + return nullptr; + + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + int nFieldType = pWidget->GetFieldType(); + CFFL_FormFiller* pFormFiller; + switch (nFieldType) { + case FIELDTYPE_PUSHBUTTON: + pFormFiller = new CFFL_PushButton(m_pEnv, pWidget); + break; + case FIELDTYPE_CHECKBOX: + pFormFiller = new CFFL_CheckBox(m_pEnv, pWidget); + break; + case FIELDTYPE_RADIOBUTTON: + pFormFiller = new CFFL_RadioButton(m_pEnv, pWidget); + break; + case FIELDTYPE_TEXTFIELD: + pFormFiller = new CFFL_TextField(m_pEnv, pWidget); + break; + case FIELDTYPE_LISTBOX: + pFormFiller = new CFFL_ListBox(m_pEnv, pWidget); + break; + case FIELDTYPE_COMBOBOX: + pFormFiller = new CFFL_ComboBox(m_pEnv, pWidget); + break; + case FIELDTYPE_UNKNOWN: + default: + pFormFiller = nullptr; + break; + } + + if (!pFormFiller) + return nullptr; + + m_Maps[pAnnot].reset(pFormFiller); + return pFormFiller; +} + +void CFFL_InteractiveFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) { + if (pAnnot) { + UnRegisterFormFiller(pAnnot); + } +} + +void CFFL_InteractiveFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { + auto it = m_Maps.find(pAnnot); + if (it == m_Maps.end()) + return; + + m_Maps.erase(it); +} + +void CFFL_InteractiveFormFiller::QueryWherePopup(void* pPrivateData, + FX_FLOAT fPopupMin, + FX_FLOAT fPopupMax, + int32_t& nRet, + FX_FLOAT& fPopupRet) { + CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + + CFX_FloatRect rcPageView(0, 0, 0, 0); + rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth(); + rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight(); + rcPageView.Normalize(); + + CFX_FloatRect rcAnnot = pData->pWidget->GetRect(); + + FX_FLOAT fTop = 0.0f; + FX_FLOAT fBottom = 0.0f; + + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pData->pWidget; + switch (pWidget->GetRotate() / 90) { + default: + case 0: + fTop = rcPageView.top - rcAnnot.top; + fBottom = rcAnnot.bottom - rcPageView.bottom; + break; + case 1: + fTop = rcAnnot.left - rcPageView.left; + fBottom = rcPageView.right - rcAnnot.right; + break; + case 2: + fTop = rcAnnot.bottom - rcPageView.bottom; + fBottom = rcPageView.top - rcAnnot.top; + break; + case 3: + fTop = rcPageView.right - rcAnnot.right; + fBottom = rcAnnot.left - rcPageView.left; + break; + } + + FX_FLOAT fFactHeight = 0; + FX_BOOL bBottom = TRUE; + FX_FLOAT fMaxListBoxHeight = 0; + if (fPopupMax > FFL_MAXLISTBOXHEIGHT) { + if (fPopupMin > FFL_MAXLISTBOXHEIGHT) { + fMaxListBoxHeight = fPopupMin; + } else { + fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT; + } + } else { + fMaxListBoxHeight = fPopupMax; + } + + if (fBottom > fMaxListBoxHeight) { + fFactHeight = fMaxListBoxHeight; + bBottom = TRUE; + } else { + if (fTop > fMaxListBoxHeight) { + fFactHeight = fMaxListBoxHeight; + bBottom = FALSE; + } else { + if (fTop > fBottom) { + fFactHeight = fTop; + bBottom = FALSE; + } else { + fFactHeight = fBottom; + bBottom = TRUE; + } + } + } + + nRet = bBottom ? 0 : 1; + fPopupRet = fFactHeight; +} + +void CFFL_InteractiveFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { + m_bNotifying = TRUE; + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + fa.bWillCommit = TRUE; + fa.bKeyDown = TRUE; + fa.bRC = TRUE; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); + pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa); + pFormFiller->SaveState(pPageView); + + pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView); + + bRC = fa.bRC; + m_bNotifying = FALSE; + } + } +} + +void CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { + m_bNotifying = TRUE; + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + fa.bKeyDown = TRUE; + fa.bRC = TRUE; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); + pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); + pFormFiller->SaveState(pPageView); + + pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView); + + bRC = fa.bRC; + m_bNotifying = FALSE; + } + } +} + +void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + ASSERT(pWidget); + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); + pInterForm->OnCalculate(pWidget->GetFormField()); + m_bNotifying = FALSE; + } +} + +void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + ASSERT(pWidget); + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); + + FX_BOOL bFormatted = FALSE; + CFX_WideString sValue = + pInterForm->OnFormat(pWidget->GetFormField(), bFormatted); + + if (bExit) + return; + + if (bFormatted) { + pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, TRUE); + pInterForm->UpdateField(pWidget->GetFormField()); + } + + m_bNotifying = FALSE; + } +} + +#ifdef PDF_ENABLE_XFA +void CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->HasXFAAAction(PDFSDK_XFA_Click)) { + m_bNotifying = TRUE; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pWidget)) { + bExit = TRUE; + return; + } + + if (nAge != pWidget->GetAppearanceAge()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + + bReset = TRUE; + } + } + } +} + +void CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->HasXFAAAction(PDFSDK_XFA_Full)) { + m_bNotifying = TRUE; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pWidget)) { + bExit = TRUE; + return; + } + + if (nAge != pWidget->GetAppearanceAge()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + + bReset = TRUE; + } + } + } +} + +void CFFL_InteractiveFormFiller::OnPopupPreOpen(void* pPrivateData, + FX_BOOL& bExit, + uint32_t nFlag) { + CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + ASSERT(pData); + ASSERT(pData->pWidget); + + FX_BOOL bTempReset = FALSE; + FX_BOOL bTempExit = FALSE; + OnPreOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); + + if (bTempReset || bTempExit) { + bExit = TRUE; + } +} + +void CFFL_InteractiveFormFiller::OnPopupPostOpen(void* pPrivateData, + FX_BOOL& bExit, + uint32_t nFlag) { + CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + ASSERT(pData); + ASSERT(pData->pWidget); + + FX_BOOL bTempReset = FALSE; + FX_BOOL bTempExit = FALSE; + OnPostOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); + + if (bTempReset || bTempExit) { + bExit = TRUE; + } +} + +void CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) { + m_bNotifying = TRUE; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pWidget)) { + bExit = TRUE; + return; + } + + if (nAge != pWidget->GetAppearanceAge()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + + bReset = TRUE; + } + } + } +} + +void CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag) { + if (!m_bNotifying) { + if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) { + m_bNotifying = TRUE; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + + pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView); + m_bNotifying = FALSE; + + if (!IsValidAnnot(pPageView, pWidget)) { + bExit = TRUE; + return; + } + + if (nAge != pWidget->GetAppearanceAge()) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->ResetPDFWindow(pPageView, + nValueAge == pWidget->GetValueAge()); + } + + bReset = TRUE; + } + } + } +} +#endif // PDF_ENABLE_XFA + +FX_BOOL CFFL_InteractiveFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + if (pPageView) + return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot()); + + return FALSE; +} + +void CFFL_InteractiveFormFiller::OnBeforeKeyStroke( + void* pPrivateData, + CFX_WideString& strChange, + const CFX_WideString& strChangeEx, + int nSelStart, + int nSelEnd, + FX_BOOL bKeyDown, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag) { + CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + ASSERT(pData->pWidget); + + CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE); + +#ifdef PDF_ENABLE_XFA + if (pFormFiller->IsFieldFull(pData->pPageView)) { + FX_BOOL bFullExit = FALSE; + FX_BOOL bFullReset = FALSE; + OnFull(pData->pWidget, pData->pPageView, bFullReset, bFullExit, nFlag); + + if (bFullReset || bFullExit) { + bExit = TRUE; + return; + } + } +#endif // PDF_ENABLE_XFA + + if (!m_bNotifying) { + if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { + m_bNotifying = TRUE; + int nAge = pData->pWidget->GetAppearanceAge(); + int nValueAge = pData->pWidget->GetValueAge(); + + CPDFSDK_Document* pDocument = pData->pPageView->GetSDKDocument(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pEnv->IsSHIFTKeyDown(nFlag); + fa.sChange = strChange; + fa.sChangeEx = strChangeEx; + fa.bKeyDown = bKeyDown; + fa.bWillCommit = FALSE; + fa.bRC = TRUE; + fa.nSelStart = nSelStart; + fa.nSelEnd = nSelEnd; + + pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa); + pFormFiller->SaveState(pData->pPageView); + + if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, + pData->pPageView)) { + if (!IsValidAnnot(pData->pPageView, pData->pWidget)) { + bExit = TRUE; + m_bNotifying = FALSE; + return; + } + + if (nAge != pData->pWidget->GetAppearanceAge()) { + CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow( + pData->pPageView, nValueAge == pData->pWidget->GetValueAge()); + pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + bExit = TRUE; + } + + if (fa.bRC) { + pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, + fa); + bRC = FALSE; + } else { + pFormFiller->RestoreState(pData->pPageView); + bRC = FALSE; + } + + if (pDocument->GetFocusAnnot() != pData->pWidget) { + pFormFiller->CommitData(pData->pPageView, nFlag); + bExit = TRUE; + } + } else { + if (!IsValidAnnot(pData->pPageView, pData->pWidget)) { + bExit = TRUE; + m_bNotifying = FALSE; + return; + } + } + + m_bNotifying = FALSE; + } + } +} diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h new file mode 100644 index 0000000000..1594cfda17 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -0,0 +1,189 @@ +// Copyright 2014 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_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ +#define FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ + +#include +#include + +#include "fpdfsdk/include/fsdk_define.h" +#include "fpdfsdk/pdfwindow/PWL_Edit.h" + +class CFFL_FormFiller; +class CPDFSDK_Environment; +class CPDFSDK_Annot; +class CPDFSDK_PageView; +class CPDFSDK_Widget; + +class CFFL_InteractiveFormFiller : public IPWL_Filler_Notify { + public: + explicit CFFL_InteractiveFormFiller(CPDFSDK_Environment* pEnv); + ~CFFL_InteractiveFormFiller() override; + + virtual FX_BOOL Annot_HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_FloatPoint point); + virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot); + virtual void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device); + + virtual void OnCreate(CPDFSDK_Annot* pAnnot); + virtual void OnLoad(CPDFSDK_Annot* pAnnot); + virtual void OnDelete(CPDFSDK_Annot* pAnnot); + + virtual void OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag); + virtual void OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlag); + + virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + short zDelta, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_FloatPoint& point); + + virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, + uint32_t nKeyCode, + uint32_t nFlags); + virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, + uint32_t nChar, + uint32_t nFlags); + + virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag); + virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag); + + CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister); + void RemoveFormFiller(CPDFSDK_Annot* pAnnot); + + static FX_BOOL IsVisible(CPDFSDK_Widget* pWidget); + static FX_BOOL IsReadOnly(CPDFSDK_Widget* pWidget); + static FX_BOOL IsFillingAllowed(CPDFSDK_Widget* pWidget); + static FX_BOOL IsValidAnnot(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot); + + void OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag); + void OnValidate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag); + + void OnCalculate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + uint32_t nFlag); + void OnFormat(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + uint32_t nFlag); + void OnButtonUp(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag); +#ifdef PDF_ENABLE_XFA + void OnClick(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag); + void OnFull(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag); + void OnPreOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag); + void OnPostOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + uint32_t nFlag); +#endif // PDF_ENABLE_XFA + + private: + using CFFL_Widget2Filler = + std::map>; + + // IPWL_Filler_Notify: + void QueryWherePopup(void* pPrivateData, + FX_FLOAT fPopupMin, + FX_FLOAT fPopupMax, + int32_t& nRet, + FX_FLOAT& fPopupRet) override; + void OnBeforeKeyStroke(void* pPrivateData, + CFX_WideString& strChange, + const CFX_WideString& strChangeEx, + int nSelStart, + int nSelEnd, + FX_BOOL bKeyDown, + FX_BOOL& bRC, + FX_BOOL& bExit, + uint32_t nFlag) override; +#ifdef PDF_ENABLE_XFA + void OnPopupPreOpen(void* pPrivateData, + FX_BOOL& bExit, + uint32_t nFlag) override; + void OnPopupPostOpen(void* pPrivateData, + FX_BOOL& bExit, + uint32_t nFlag) override; + void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, + FX_BOOL bSameField, + FX_BOOL bNext); +#endif // PDF_ENABLE_XFA + void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); + + CPDFSDK_Environment* const m_pEnv; + CFFL_Widget2Filler m_Maps; + FX_BOOL m_bNotifying; +}; + +class CFFL_PrivateData { + public: + CPDFSDK_Widget* pWidget; + CPDFSDK_PageView* pPageView; + int nWidgetAge; + int nValueAge; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 0f253ec380..7a6976e440 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -8,7 +8,7 @@ #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/include/cpdfsdk_environment.h" #include "fpdfsdk/include/cpdfsdk_widget.h" #include "fpdfsdk/include/fsdk_common.h" @@ -47,9 +47,7 @@ CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPWL_ListBox* pWnd = new CPWL_ListBox(); pWnd->AttachFFLData(this); pWnd->Create(cp); - - CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); - pWnd->SetFillerNotify(pIFormFiller); + pWnd->SetFillerNotify(m_pEnv->GetInteractiveFormFiller()); for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) pWnd->AddString(m_pWidget->GetOptionLabel(i)); diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index 8e782d0eb9..17573fd625 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -46,15 +46,13 @@ FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, switch (nChar) { case FWL_VKEY_Return: case FWL_VKEY_Space: { - CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); ASSERT(pPageView); FX_BOOL bReset = FALSE; FX_BOOL bExit = FALSE; - - pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit, nFlags); - + m_pEnv->GetInteractiveFormFiller()->OnButtonUp(m_pWidget, pPageView, + bReset, bExit, nFlags); if (bReset) return TRUE; if (bExit) diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index aa3b87a09a..b80bbe4e17 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -83,9 +83,7 @@ CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, CPWL_Edit* pWnd = new CPWL_Edit(); pWnd->AttachFFLData(this); pWnd->Create(cp); - - CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); - pWnd->SetFillerNotify(pIFormFiller); + pWnd->SetFillerNotify(m_pEnv->GetInteractiveFormFiller()); int32_t nMaxLen = m_pWidget->GetMaxLen(); CFX_WideString swValue = m_pWidget->GetValue(); diff --git a/fpdfsdk/include/cpdfsdk_baannothandler.h b/fpdfsdk/include/cpdfsdk_baannothandler.h index 1e04bc15c2..112f8125f1 100644 --- a/fpdfsdk/include/cpdfsdk_baannothandler.h +++ b/fpdfsdk/include/cpdfsdk_baannothandler.h @@ -11,7 +11,7 @@ #include "core/fxcrt/include/fx_coordinates.h" #include "fpdfsdk/include/ipdfsdk_annothandler.h" -class CFFL_IFormFiller; +class CFFL_InteractiveFormFiller; class CFX_Matrix; class CFX_RenderDevice; class CPDF_Annot; diff --git a/fpdfsdk/include/cpdfsdk_environment.h b/fpdfsdk/include/cpdfsdk_environment.h index 59b260859a..338d70f33b 100644 --- a/fpdfsdk/include/cpdfsdk_environment.h +++ b/fpdfsdk/include/cpdfsdk_environment.h @@ -18,7 +18,7 @@ #include "public/fpdf_formfill.h" #include "public/fpdf_fwlevent.h" -class CFFL_IFormFiller; +class CFFL_InteractiveFormFiller; class CFX_SystemHandler; class CPDFSDK_ActionHandler; class CPDFSDK_AnnotHandlerMgr; @@ -400,7 +400,8 @@ class CPDFSDK_Environment final { CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } - CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. + // Creates if not present. + CFFL_InteractiveFormFiller* GetInteractiveFormFiller(); CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. IJS_Runtime* GetJSRuntime(); // Creates if not present. CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. @@ -412,7 +413,7 @@ class CPDFSDK_Environment final { FPDF_FORMFILLINFO* const m_pInfo; CPDFSDK_Document* m_pSDKDoc; UnderlyingDocumentType* const m_pUnderlyingDoc; - std::unique_ptr m_pIFormFiller; + std::unique_ptr m_pFormFiller; std::unique_ptr m_pSysHandler; }; diff --git a/fpdfsdk/include/cpdfsdk_widgethandler.h b/fpdfsdk/include/cpdfsdk_widgethandler.h index 432a90bc24..c5efd21e84 100644 --- a/fpdfsdk/include/cpdfsdk_widgethandler.h +++ b/fpdfsdk/include/cpdfsdk_widgethandler.h @@ -11,7 +11,7 @@ #include "core/fxcrt/include/fx_coordinates.h" #include "fpdfsdk/include/ipdfsdk_annothandler.h" -class CFFL_IFormFiller; +class CFFL_InteractiveFormFiller; class CFX_Matrix; class CFX_RenderDevice; class CPDF_Annot; @@ -103,12 +103,14 @@ class CPDFSDK_WidgetHandler : public IPDFSDK_AnnotHandler { CPDFSDK_Annot* pNewAnnot) override; #endif // PDF_ENABLE_XFA - void SetFormFiller(CFFL_IFormFiller* pFiller) { m_pFormFiller = pFiller; } - CFFL_IFormFiller* GetFormFiller() { return m_pFormFiller; } + void SetFormFiller(CFFL_InteractiveFormFiller* pFiller) { + m_pFormFiller = pFiller; + } + CFFL_InteractiveFormFiller* GetFormFiller() { return m_pFormFiller; } private: CPDFSDK_Environment* m_pApp; - CFFL_IFormFiller* m_pFormFiller; + CFFL_InteractiveFormFiller* m_pFormFiller; }; #endif // FPDFSDK_INCLUDE_CPDFSDK_WIDGETHANDLER_H_ diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index 346690b484..a80d842325 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -269,10 +269,10 @@ FX_BOOL CXFA_Document::IsInteractive() { if (!pPDF) return FALSE; - CXFA_Node* pInteractive = pPDF->GetChild(0, XFA_Element::Interactive); - if (pInteractive) { + CXFA_Node* pFormFiller = pPDF->GetChild(0, XFA_Element::Interactive); + if (pFormFiller) { m_dwDocFlags |= XFA_DOCFLAG_HasInteractive; - if (pInteractive->TryContent(wsInteractive) && + if (pFormFiller->TryContent(wsInteractive) && wsInteractive == FX_WSTRC(L"1")) { m_dwDocFlags |= XFA_DOCFLAG_Interactive; return TRUE; -- cgit v1.2.3