From edbb319d3143692befdbb0603089b7e265cf89aa Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 21 Mar 2016 09:08:24 -0400 Subject: Move fpdfsdk/include/formfiller to fpdfsdk/formfiller. This CL moves the .h files and renames the .cpp files to match. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1809193002 . --- BUILD.gn | 36 +- fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp | 259 ------- fpdfsdk/formfiller/FFL_CheckBox.cpp | 116 --- fpdfsdk/formfiller/FFL_ComboBox.cpp | 302 -------- fpdfsdk/formfiller/FFL_FormFiller.cpp | 728 ------------------ fpdfsdk/formfiller/FFL_IFormFiller.cpp | 1016 -------------------------- fpdfsdk/formfiller/FFL_ListBox.cpp | 223 ------ fpdfsdk/formfiller/FFL_PushButton.cpp | 38 - fpdfsdk/formfiller/FFL_RadioButton.cpp | 121 --- fpdfsdk/formfiller/FFL_TextField.cpp | 292 -------- fpdfsdk/formfiller/cba_fontmap.cpp | 259 +++++++ fpdfsdk/formfiller/cba_fontmap.h | 46 ++ fpdfsdk/formfiller/cffl_checkbox.cpp | 116 +++ fpdfsdk/formfiller/cffl_checkbox.h | 32 + fpdfsdk/formfiller/cffl_combobox.cpp | 302 ++++++++ fpdfsdk/formfiller/cffl_combobox.h | 69 ++ fpdfsdk/formfiller/cffl_formfiller.cpp | 728 ++++++++++++++++++ fpdfsdk/formfiller/cffl_formfiller.h | 203 +++++ fpdfsdk/formfiller/cffl_iformfiller.cpp | 1016 ++++++++++++++++++++++++++ fpdfsdk/formfiller/cffl_iformfiller.h | 186 +++++ fpdfsdk/formfiller/cffl_listbox.cpp | 223 ++++++ fpdfsdk/formfiller/cffl_listbox.h | 45 ++ fpdfsdk/formfiller/cffl_pushbutton.cpp | 38 + fpdfsdk/formfiller/cffl_pushbutton.h | 28 + fpdfsdk/formfiller/cffl_radiobutton.cpp | 121 +++ fpdfsdk/formfiller/cffl_radiobutton.h | 32 + fpdfsdk/formfiller/cffl_textfield.cpp | 292 ++++++++ fpdfsdk/formfiller/cffl_textfield.h | 69 ++ fpdfsdk/fsdk_annothandler.cpp | 2 +- fpdfsdk/fsdk_baseform.cpp | 2 +- fpdfsdk/fsdk_mgr.cpp | 2 +- fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h | 46 -- fpdfsdk/include/formfiller/FFL_CheckBox.h | 32 - fpdfsdk/include/formfiller/FFL_ComboBox.h | 69 -- fpdfsdk/include/formfiller/FFL_FormFiller.h | 203 ----- fpdfsdk/include/formfiller/FFL_IFormFiller.h | 186 ----- fpdfsdk/include/formfiller/FFL_ListBox.h | 45 -- fpdfsdk/include/formfiller/FFL_PushButton.h | 28 - fpdfsdk/include/formfiller/FFL_RadioButton.h | 32 - fpdfsdk/include/formfiller/FFL_TextField.h | 69 -- pdfium.gyp | 36 +- 41 files changed, 3844 insertions(+), 3844 deletions(-) delete mode 100644 fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp delete mode 100644 fpdfsdk/formfiller/FFL_CheckBox.cpp delete mode 100644 fpdfsdk/formfiller/FFL_ComboBox.cpp delete mode 100644 fpdfsdk/formfiller/FFL_FormFiller.cpp delete mode 100644 fpdfsdk/formfiller/FFL_IFormFiller.cpp delete mode 100644 fpdfsdk/formfiller/FFL_ListBox.cpp delete mode 100644 fpdfsdk/formfiller/FFL_PushButton.cpp delete mode 100644 fpdfsdk/formfiller/FFL_RadioButton.cpp delete mode 100644 fpdfsdk/formfiller/FFL_TextField.cpp create mode 100644 fpdfsdk/formfiller/cba_fontmap.cpp create mode 100644 fpdfsdk/formfiller/cba_fontmap.h create mode 100644 fpdfsdk/formfiller/cffl_checkbox.cpp create mode 100644 fpdfsdk/formfiller/cffl_checkbox.h create mode 100644 fpdfsdk/formfiller/cffl_combobox.cpp create mode 100644 fpdfsdk/formfiller/cffl_combobox.h create mode 100644 fpdfsdk/formfiller/cffl_formfiller.cpp create mode 100644 fpdfsdk/formfiller/cffl_formfiller.h create mode 100644 fpdfsdk/formfiller/cffl_iformfiller.cpp create mode 100644 fpdfsdk/formfiller/cffl_iformfiller.h create mode 100644 fpdfsdk/formfiller/cffl_listbox.cpp create mode 100644 fpdfsdk/formfiller/cffl_listbox.h create mode 100644 fpdfsdk/formfiller/cffl_pushbutton.cpp create mode 100644 fpdfsdk/formfiller/cffl_pushbutton.h create mode 100644 fpdfsdk/formfiller/cffl_radiobutton.cpp create mode 100644 fpdfsdk/formfiller/cffl_radiobutton.h create mode 100644 fpdfsdk/formfiller/cffl_textfield.cpp create mode 100644 fpdfsdk/formfiller/cffl_textfield.h delete mode 100644 fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h delete mode 100644 fpdfsdk/include/formfiller/FFL_CheckBox.h delete mode 100644 fpdfsdk/include/formfiller/FFL_ComboBox.h delete mode 100644 fpdfsdk/include/formfiller/FFL_FormFiller.h delete mode 100644 fpdfsdk/include/formfiller/FFL_IFormFiller.h delete mode 100644 fpdfsdk/include/formfiller/FFL_ListBox.h delete mode 100644 fpdfsdk/include/formfiller/FFL_PushButton.h delete mode 100644 fpdfsdk/include/formfiller/FFL_RadioButton.h delete mode 100644 fpdfsdk/include/formfiller/FFL_TextField.h diff --git a/BUILD.gn b/BUILD.gn index 9f3b27e9bc..85b65c7c3e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -778,24 +778,24 @@ static_library("javascript") { static_library("formfiller") { sources = [ - "fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp", - "fpdfsdk/formfiller/FFL_CheckBox.cpp", - "fpdfsdk/formfiller/FFL_ComboBox.cpp", - "fpdfsdk/formfiller/FFL_FormFiller.cpp", - "fpdfsdk/formfiller/FFL_IFormFiller.cpp", - "fpdfsdk/formfiller/FFL_ListBox.cpp", - "fpdfsdk/formfiller/FFL_PushButton.cpp", - "fpdfsdk/formfiller/FFL_RadioButton.cpp", - "fpdfsdk/formfiller/FFL_TextField.cpp", - "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h", - "fpdfsdk/include/formfiller/FFL_CheckBox.h", - "fpdfsdk/include/formfiller/FFL_ComboBox.h", - "fpdfsdk/include/formfiller/FFL_FormFiller.h", - "fpdfsdk/include/formfiller/FFL_IFormFiller.h", - "fpdfsdk/include/formfiller/FFL_ListBox.h", - "fpdfsdk/include/formfiller/FFL_PushButton.h", - "fpdfsdk/include/formfiller/FFL_RadioButton.h", - "fpdfsdk/include/formfiller/FFL_TextField.h", + "fpdfsdk/formfiller/cba_fontmap.cpp", + "fpdfsdk/formfiller/cba_fontmap.h", + "fpdfsdk/formfiller/cffl_checkbox.cpp", + "fpdfsdk/formfiller/cffl_checkbox.h", + "fpdfsdk/formfiller/cffl_combobox.cpp", + "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_listbox.cpp", + "fpdfsdk/formfiller/cffl_listbox.h", + "fpdfsdk/formfiller/cffl_pushbutton.cpp", + "fpdfsdk/formfiller/cffl_pushbutton.h", + "fpdfsdk/formfiller/cffl_radiobutton.cpp", + "fpdfsdk/formfiller/cffl_radiobutton.h", + "fpdfsdk/formfiller/cffl_textfield.cpp", + "fpdfsdk/formfiller/cffl_textfield.h", ] configs += [ ":pdfium_config" ] } diff --git a/fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp deleted file mode 100644 index d7488d1592..0000000000 --- a/fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp +++ /dev/null @@ -1,259 +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/include/formfiller/FFL_CBA_Fontmap.h" - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" -#include "fpdfsdk/include/fsdk_baseannot.h" - -CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, - IFX_SystemHandler* pSystemHandler) - : CPWL_FontMap(pSystemHandler), - m_pDocument(NULL), - m_pAnnotDict(NULL), - m_pDefaultFont(NULL), - m_sAPType("N") { - CPDF_Page* pPage = pAnnot->GetPDFPage(); - - m_pDocument = pPage->m_pDocument; - m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); - Initialize(); -} - -CBA_FontMap::~CBA_FontMap() {} - -void CBA_FontMap::Reset() { - Empty(); - m_pDefaultFont = NULL; - m_sDefaultFontName = ""; -} - -void CBA_FontMap::Initialize() { - int32_t nCharset = DEFAULT_CHARSET; - - if (!m_pDefaultFont) { - m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); - if (m_pDefaultFont) { - if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { - nCharset = pSubstFont->m_Charset; - } else { - if (m_sDefaultFontName == "Wingdings" || - m_sDefaultFontName == "Wingdings2" || - m_sDefaultFontName == "Wingdings3" || - m_sDefaultFontName == "Webdings") - nCharset = SYMBOL_CHARSET; - else - nCharset = ANSI_CHARSET; - } - AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); - AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName); - } - } - - if (nCharset != ANSI_CHARSET) - CPWL_FontMap::Initialize(); -} - -void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, - const CFX_ByteString& sFontName) { - ASSERT(pFont); - - if (m_pDefaultFont) - return; - - m_pDefaultFont = pFont; - m_sDefaultFontName = sFontName; - - int32_t nCharset = DEFAULT_CHARSET; - if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) - nCharset = pSubstFont->m_Charset; - AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); -} - -CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, - int32_t nCharset) { - if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { - CPDF_Document* pDocument = GetDocument(); - CPDF_Dictionary* pRootDict = pDocument->GetRoot(); - if (!pRootDict) - return NULL; - - CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); - if (!pAcroFormDict) - return NULL; - - CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); - if (!pDRDict) - return NULL; - - return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); - } - - return NULL; -} - -CPDF_Document* CBA_FontMap::GetDocument() { - return m_pDocument; -} - -CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, - CFX_ByteString& sFontAlias, - int32_t nCharset) { - if (!pResDict) - return NULL; - - CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); - if (!pFonts) - return NULL; - - CPDF_Document* pDocument = GetDocument(); - CPDF_Font* pFind = NULL; - for (const auto& it : *pFonts) { - const CFX_ByteString& csKey = it.first; - CPDF_Object* pObj = it.second; - if (!pObj) - continue; - - CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); - if (!pElement) - continue; - if (pElement->GetStringBy("Type") != "Font") - continue; - - CPDF_Font* pFont = pDocument->LoadFont(pElement); - if (!pFont) - continue; - const CFX_SubstFont* pSubst = pFont->GetSubstFont(); - if (!pSubst) - continue; - if (pSubst->m_Charset == nCharset) { - sFontAlias = csKey; - pFind = pFont; - } - } - return pFind; -} - -void CBA_FontMap::AddedFont(CPDF_Font* pFont, - const CFX_ByteString& sFontAlias) { - AddFontToAnnotDict(pFont, sFontAlias); -} - -void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, - const CFX_ByteString& sAlias) { - if (!pFont) - return; - - CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); - - if (!pAPDict) { - pAPDict = new CPDF_Dictionary; - m_pAnnotDict->SetAt("AP", pAPDict); - } - - // to avoid checkbox and radiobutton - CPDF_Object* pObject = pAPDict->GetElement(m_sAPType); - if (ToDictionary(pObject)) - return; - - CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); - if (!pStream) { - pStream = new CPDF_Stream(NULL, 0, NULL); - int32_t objnum = m_pDocument->AddIndirectObject(pStream); - pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); - } - - CPDF_Dictionary* pStreamDict = pStream->GetDict(); - - if (!pStreamDict) { - pStreamDict = new CPDF_Dictionary; - pStream->InitStream(NULL, 0, pStreamDict); - } - - if (pStreamDict) { - CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); - if (!pStreamResList) { - pStreamResList = new CPDF_Dictionary(); - pStreamDict->SetAt("Resources", pStreamResList); - } - - if (pStreamResList) { - CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); - if (!pStreamResFontList) { - pStreamResFontList = new CPDF_Dictionary; - int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); - pStreamResList->SetAtReference("Font", m_pDocument, objnum); - } - if (!pStreamResFontList->KeyExist(sAlias)) - pStreamResFontList->SetAtReference(sAlias, m_pDocument, - pFont->GetFontDict()); - } - } -} - -CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { - CPDF_Dictionary* pAcroFormDict = NULL; - const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); - if (bWidget) { - if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) - pAcroFormDict = pRootDict->GetDictBy("AcroForm"); - } - - CFX_ByteString sDA; - CPDF_Object* pObj; - if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"))) - sDA = pObj->GetString(); - - if (bWidget) { - if (sDA.IsEmpty()) { - pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); - sDA = pObj ? pObj->GetString() : CFX_ByteString(); - } - } - - CPDF_Dictionary* pFontDict = NULL; - - if (!sDA.IsEmpty()) { - CPDF_SimpleParser syntax(sDA); - syntax.FindTagParamFromStart("Tf", 2); - CFX_ByteString sFontName = syntax.GetWord(); - sAlias = PDF_NameDecode(sFontName).Mid(1); - - if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) - if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) - pFontDict = pDRFontDict->GetDictBy(sAlias); - - if (!pFontDict) - if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP")) - if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N")) - if (CPDF_Dictionary* pNormalResDict = - pNormalDict->GetDictBy("Resources")) - if (CPDF_Dictionary* pResFontDict = - pNormalResDict->GetDictBy("Font")) - pFontDict = pResFontDict->GetDictBy(sAlias); - - if (bWidget) { - if (!pFontDict) { - if (pAcroFormDict) { - if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR")) - if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) - pFontDict = pDRFontDict->GetDictBy(sAlias); - } - } - } - } - - return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; -} - -void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { - m_sAPType = sAPType; - - Reset(); - Initialize(); -} diff --git a/fpdfsdk/formfiller/FFL_CheckBox.cpp b/fpdfsdk/formfiller/FFL_CheckBox.cpp deleted file mode 100644 index 485f86ba75..0000000000 --- a/fpdfsdk/formfiller/FFL_CheckBox.cpp +++ /dev/null @@ -1,116 +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/include/formfiller/FFL_CheckBox.h" - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" -#include "public/fpdf_fwlevent.h" - -CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget) - : CFFL_Button(pApp, pWidget) {} - -CFFL_CheckBox::~CFFL_CheckBox() {} - -CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_CheckBox* pWnd = new CPWL_CheckBox(); - pWnd->Create(cp); - pWnd->SetCheck(m_pWidget->IsChecked()); - return pWnd; -} - -FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags) { - switch (nKeyCode) { - case FWL_VKEY_Return: - case FWL_VKEY_Space: - return TRUE; - default: - return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); - } -} -FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - switch (nChar) { - case FWL_VKEY_Return: - case FWL_VKEY_Space: { - CFFL_IFormFiller* pIFormFiller = m_pApp->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); - - if (bReset) - return TRUE; - if (bExit) - return TRUE; - - CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) - pWnd->SetCheck(!pWnd->IsChecked()); - - CommitData(pPageView, nFlags); - return TRUE; - } - default: - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - } -} - -FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); - - if (IsValid()) { - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - pWnd->SetCheck(!pWidget->IsChecked()); - } - - if (!CommitData(pPageView, nFlags)) - return FALSE; - } - - return TRUE; -} - -FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { - CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE); - return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); -} - -void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { - bool bNewChecked = pWnd->IsChecked(); - - if (bNewChecked) { - CPDF_FormField* pField = m_pWidget->GetFormField(); - for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { - if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { - if (pCtrl->IsChecked()) { - break; - } - } - } - } - - m_pWidget->SetCheck(bNewChecked, false); - m_pWidget->UpdateField(); - SetChangeMark(); - } -} diff --git a/fpdfsdk/formfiller/FFL_ComboBox.cpp b/fpdfsdk/formfiller/FFL_ComboBox.cpp deleted file mode 100644 index 5e88a5d133..0000000000 --- a/fpdfsdk/formfiller/FFL_ComboBox.cpp +++ /dev/null @@ -1,302 +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/include/formfiller/FFL_ComboBox.h" - -#include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" -#include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_ComboBox.h" - -CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) - : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { - m_State.nIndex = 0; - m_State.nStart = 0; - m_State.nEnd = 0; -} - -CFFL_ComboBox::~CFFL_ComboBox() { - for (const auto& it : m_Maps) - it.second->InvalidateFocusHandler(this); - delete m_pFontMap; -} - -PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { - PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); - - int nFlags = m_pWidget->GetFieldFlags(); - if (nFlags & FIELDFLAG_EDIT) { - cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; - } - - if (!m_pFontMap) - m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler()); - cp.pFontMap = m_pFontMap; - cp.pFocusHandler = this; - - return cp; -} - -CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_ComboBox* pWnd = new CPWL_ComboBox(); - pWnd->AttachFFLData(this); - pWnd->Create(cp); - - CFFL_IFormFiller* pFormFiller = m_pApp->GetIFormFiller(); - pWnd->SetFillerNotify(pFormFiller); - - int32_t nCurSel = m_pWidget->GetSelectedIndex(0); - CFX_WideString swText; - if (nCurSel < 0) - swText = m_pWidget->GetValue(); - else - swText = m_pWidget->GetOptionLabel(nCurSel); - - for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { - pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); - } - - pWnd->SetSelect(nCurSel); - pWnd->SetText(swText.c_str()); - return pWnd; -} - -FX_BOOL CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); -} - -FX_BOOL CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) { - CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE); - if (!pWnd) - return FALSE; - - int32_t nCurSel = pWnd->GetSelect(); - if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) - return nCurSel != m_pWidget->GetSelectedIndex(0); - - if (nCurSel >= 0) - return nCurSel != m_pWidget->GetSelectedIndex(0); - - return pWnd->GetText() != m_pWidget->GetValue(); -} - -void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { - CPWL_ComboBox* pWnd = - static_cast(GetPDFWindow(pPageView, FALSE)); - if (!pWnd) - return; - - CFX_WideString swText = pWnd->GetText(); - int32_t nCurSel = pWnd->GetSelect(); - - bool bSetValue = false; - - if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) - bSetValue = (nCurSel < 0) || (swText != m_pWidget->GetOptionLabel(nCurSel)); - - if (bSetValue) { - m_pWidget->SetValue(swText, FALSE); - } else { - m_pWidget->GetSelectedIndex(0); - m_pWidget->SetOptionSelection(nCurSel, TRUE, FALSE); - } - - m_pWidget->ResetFieldAppearance(TRUE); - m_pWidget->UpdateField(); - SetChangeMark(); - - m_pWidget->GetPDFPage(); -} - -void CFFL_ComboBox::GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { - switch (type) { - case CPDF_AAction::KeyStroke: - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, FALSE))) { - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { - fa.bFieldFull = pEdit->IsTextFull(); - int nSelStart = 0; - int nSelEnd = 0; - pEdit->GetSel(nSelStart, nSelEnd); - fa.nSelEnd = nSelEnd; - fa.nSelStart = nSelStart; - fa.sValue = pEdit->GetText(); - fa.sChangeEx = GetSelectExportText(); - - if (fa.bFieldFull) { - fa.sChange = L""; - fa.sChangeEx = L""; - } - } - } - break; - case CPDF_AAction::Validate: - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, FALSE))) { - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { - fa.sValue = pEdit->GetText(); - } - } - break; - case CPDF_AAction::LoseFocus: - case CPDF_AAction::GetFocus: - fa.sValue = m_pWidget->GetValue(); - break; - default: - break; - } -} - -void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) { - switch (type) { - case CPDF_AAction::KeyStroke: - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, FALSE))) { - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { - pEdit->SetSel(fa.nSelStart, fa.nSelEnd); - pEdit->ReplaceSel(fa.sChange.c_str()); - } - } - break; - default: - break; - } -} - -FX_BOOL CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { - switch (type) { - case CPDF_AAction::KeyStroke: - return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || - faOld.nSelStart != faNew.nSelStart || - faOld.sChange != faNew.sChange; - default: - break; - } - - return FALSE; -} - -void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { - ASSERT(pPageView); - - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, FALSE))) { - m_State.nIndex = pComboBox->GetSelect(); - - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { - pEdit->GetSel(m_State.nStart, m_State.nEnd); - m_State.sValue = pEdit->GetText(); - } - } -} - -void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { - ASSERT(pPageView); - - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, TRUE))) { - if (m_State.nIndex >= 0) { - pComboBox->SetSelect(m_State.nIndex); - } else { - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { - pEdit->SetText(m_State.sValue.c_str()); - pEdit->SetSel(m_State.nStart, m_State.nEnd); - } - } - } -} - -CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) { - if (bRestoreValue) - SaveState(pPageView); - - DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = NULL; - - if (bRestoreValue) { - RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, FALSE); - } else { - pRet = GetPDFWindow(pPageView, TRUE); - } - - m_pWidget->UpdateField(); - - return pRet; -} - -#ifdef PDF_ENABLE_XFA -FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { - if (CPWL_ComboBox* pComboBox = - static_cast(GetPDFWindow(pPageView, FALSE))) { - if (CPWL_Edit* pEdit = pComboBox->GetEdit()) - return pEdit->IsTextFull(); - } - return FALSE; -} -#endif // PDF_ENABLE_XFA - -void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { - ASSERT(m_pApp); - - if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { - CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); - pEdit->SetCodePage(936); - - pEdit->SetReadyToInput(); - CFX_WideString wsText = pEdit->GetText(); - int nCharacters = wsText.GetLength(); - CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); - unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); - m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, - nCharacters, TRUE); - - pEdit->SetEditNotify(this); - } -} - -void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) { - ASSERT(m_pApp); -} - -void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) { - ASSERT(pEdit); -} - -CFX_WideString CFFL_ComboBox::GetSelectExportText() { - CFX_WideString swRet; - - int nExport = -1; - CPDFSDK_PageView* pPageView = GetCurPageView(); - if (CPWL_ComboBox* pComboBox = - (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { - nExport = pComboBox->GetSelect(); - } - - if (nExport >= 0) { - if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { - swRet = pFormField->GetOptionValue(nExport); - if (swRet.IsEmpty()) - swRet = pFormField->GetOptionLabel(nExport); - } - } - - return swRet; -} diff --git a/fpdfsdk/formfiller/FFL_FormFiller.cpp b/fpdfsdk/formfiller/FFL_FormFiller.cpp deleted file mode 100644 index e764c19270..0000000000 --- a/fpdfsdk/formfiller/FFL_FormFiller.cpp +++ /dev/null @@ -1,728 +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/include/formfiller/FFL_FormFiller.h" - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" -#include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_Utils.h" - -#define GetRed(rgb) ((uint8_t)(rgb)) -#define GetGreen(rgb) ((uint8_t)(((FX_WORD)(rgb)) >> 8)) -#define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) - -#define FFL_HINT_ELAPSE 800 - -CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, - CPDFSDK_Annot* pAnnot) - : m_pApp(pApp), m_pAnnot(pAnnot), m_bValid(FALSE), m_ptOldPos(0, 0) { - m_pWidget = (CPDFSDK_Widget*)pAnnot; -} - -CFFL_FormFiller::~CFFL_FormFiller() { - for (const auto& it : m_Maps) { - CPWL_Wnd* pWnd = it.second; - CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - pWnd->InvalidateProvider(this); - pWnd->Destroy(); - delete pWnd; - delete pData; - } - m_Maps.clear(); -} - -void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, - const CFX_FloatRect& rcWindow) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - pWnd->Move(CFX_FloatRect(rcWindow), TRUE, FALSE); - } -} - -CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - return pWnd->GetWindowRect(); - } - - return CFX_FloatRect(0, 0, 0, 0); -} - -FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - ASSERT(pPageView); - ASSERT(pAnnot); - - CFX_FloatRect rcAnnot = m_pWidget->GetRect(); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - CFX_FloatRect rcWindow = pWnd->GetWindowRect(); - rcAnnot = PWLtoFFL(rcWindow); - } - - CFX_FloatRect rcWin = rcAnnot; - - CFX_FloatRect rcFocus = GetFocusBox(pPageView); - if (!rcFocus.IsEmpty()) - rcWin.Union(rcFocus); - - CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); - - return rect.GetOutterRect(); -} - -void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - CFX_Matrix mt = GetCurMatrix(); - mt.Concat(*pUser2Device); - pWnd->DrawAppearance(pDevice, &mt); - } else { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (CFFL_IFormFiller::IsVisible(pWidget)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } -} - -void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); -} - -void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot) {} - -void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot) {} - -void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot) {} - -void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) {} - -void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - EndTimer(); - ASSERT(m_pWidget); -} - -FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { - m_bValid = TRUE; - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - - if (!rect.Contains((int)point.x, (int)point.y)) - return FALSE; - - return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); - pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); - return TRUE; - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); - return TRUE; - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) { - m_ptOldPos = point; - } - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); - return TRUE; - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - short zDelta, - const CFX_FloatPoint& point) { - if (!IsValid()) - return FALSE; - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { - return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { - pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); - return TRUE; - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); - return TRUE; - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags) { - if (IsValid()) { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - return pWnd->OnKeyDown(nKeyCode, nFlags); - } - } - - return FALSE; -} - -FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - if (IsValid()) { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - return pWnd->OnChar(nChar, nFlags); - } - } - - return FALSE; -} - -void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); - CPDFSDK_Document* pDoc = m_pApp->GetSDKDocument(); - CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) - pWnd->SetFocus(); - - m_bValid = TRUE; - FX_RECT rcRect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); -} - -void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { - if (!IsValid()) - return; - - CPDFSDK_PageView* pPageView = GetCurPageView(); - if (!pPageView) - return; - - CommitData(pPageView, nFlag); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) - pWnd->KillFocus(); - - FX_BOOL bDestroyPDFWindow; - switch (m_pWidget->GetFieldType()) { - case FIELDTYPE_PUSHBUTTON: - case FIELDTYPE_CHECKBOX: - case FIELDTYPE_RADIOBUTTON: - bDestroyPDFWindow = TRUE; - break; - default: - bDestroyPDFWindow = FALSE; - break; - } - EscapeFiller(pPageView, bDestroyPDFWindow); -} - -FX_BOOL CFFL_FormFiller::IsValid() const { - return m_bValid; -} - -PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { - ASSERT(m_pApp); - - PWL_CREATEPARAM cp; - cp.pParentWnd = NULL; - cp.pProvider = this; - cp.rcRectWnd = GetPDFWindowRect(); - - FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; - FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); - if (dwFieldFlag & FIELDFLAG_READONLY) { - dwCreateFlags |= PWS_READONLY; - } - - FX_COLORREF color; - if (m_pWidget->GetFillColor(color)) { - cp.sBackgroundColor = - CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } - - if (m_pWidget->GetBorderColor(color)) { - cp.sBorderColor = - CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } - - cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); - - if (m_pWidget->GetTextColor(color)) { - cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } - - cp.fFontSize = m_pWidget->GetFontSize(); - cp.dwBorderWidth = m_pWidget->GetBorderWidth(); - - int nBorderStyle = m_pWidget->GetBorderStyle(); - - switch (nBorderStyle) { - case BBS_SOLID: - cp.nBorderStyle = PBS_SOLID; - break; - case BBS_DASH: - cp.nBorderStyle = PBS_DASH; - cp.sDash = CPWL_Dash(3, 3, 0); - break; - case BBS_BEVELED: - cp.nBorderStyle = PBS_BEVELED; - cp.dwBorderWidth *= 2; - break; - case BBS_INSET: - cp.nBorderStyle = PBS_INSET; - cp.dwBorderWidth *= 2; - break; - case BBS_UNDERLINE: - cp.nBorderStyle = PBS_UNDERLINED; - break; - } - - if (cp.fFontSize <= 0) { - dwCreateFlags |= PWS_AUTOFONTSIZE; - } - - cp.dwFlags = dwCreateFlags; - cp.pSystemHandler = m_pApp->GetSysHandler(); - return cp; -} - -CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bNew) { - ASSERT(pPageView); - - auto it = m_Maps.find(pPageView); - const bool found = it != m_Maps.end(); - CPWL_Wnd* pWnd = found ? it->second : nullptr; - if (!bNew) - return pWnd; - - if (found) { - CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) { - return ResetPDFWindow( - pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); - } - } else { - PWL_CREATEPARAM cp = GetCreateParam(); - cp.hAttachedWnd = (FX_HWND)m_pWidget; - - CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; - pPrivateData->pWidget = m_pWidget; - pPrivateData->pPageView = pPageView; - pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); - pPrivateData->nValueAge = 0; - - cp.pAttachedData = pPrivateData; - - pWnd = NewPDFWindow(cp, pPageView); - m_Maps[pPageView] = pWnd; - } - - return pWnd; -} - -void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { - auto it = m_Maps.find(pPageView); - if (it == m_Maps.end()) - return; - - CPWL_Wnd* pWnd = it->second; - CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - pWnd->Destroy(); - delete pWnd; - delete pData; - - m_Maps.erase(it); -} - -CFX_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) { - if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) { - if (pPrivateData->pPageView) { - CFX_Matrix mtPageView; - pPrivateData->pPageView->GetCurrentMatrix(mtPageView); - CFX_Matrix mt = GetCurMatrix(); - mt.Concat(mtPageView); - - return mt; - } - } - return CFX_Matrix(1, 0, 0, 1, 0, 0); -} - -CFX_Matrix CFFL_FormFiller::GetCurMatrix() { - CFX_Matrix mt; - - CFX_FloatRect rcDA; - m_pWidget->GetPDFAnnot()->GetRect(rcDA); - - switch (m_pWidget->GetRotate()) { - default: - case 0: - mt = CFX_Matrix(1, 0, 0, 1, 0, 0); - break; - case 90: - mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); - break; - case 180: - mt = CFX_Matrix(-1, 0, 0, -1, rcDA.right - rcDA.left, - rcDA.top - rcDA.bottom); - break; - case 270: - mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); - break; - } - mt.e += rcDA.left; - mt.f += rcDA.bottom; - - return mt; -} - -CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) { - ASSERT(m_pApp); - - return L""; -} - -CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { - CFX_FloatRect rectAnnot; - m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); - - FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; - FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; - if ((m_pWidget->GetRotate() / 90) & 0x01) - return CFX_FloatRect(0, 0, fHeight, fWidth); - - return CFX_FloatRect(0, 0, fWidth, fHeight); -} - -CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView() { - UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); - CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); - return pSDKDoc ? pSDKDoc->GetPageView(pPage) : nullptr; -} - -CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { - CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); - CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); - if (rcPage.Contains(rcFocus)) - return rcFocus; - } - return CFX_FloatRect(0, 0, 0, 0); -} - -CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { - CFX_Matrix mt; - mt.SetReverse(GetCurMatrix()); - - CFX_FloatRect temp = rect; - mt.TransformRect(temp); - - return temp; -} - -CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { - CFX_Matrix mt = GetCurMatrix(); - - CFX_FloatRect temp = rect; - mt.TransformRect(temp); - - return temp; -} - -CFX_FloatPoint CFFL_FormFiller::FFLtoPWL(const CFX_FloatPoint& point) { - CFX_Matrix mt; - mt.SetReverse(GetCurMatrix()); - - CFX_FloatPoint pt = point; - mt.Transform(pt.x, pt.y); - - return pt; -} - -CFX_FloatPoint CFFL_FormFiller::PWLtoFFL(const CFX_FloatPoint& point) { - CFX_Matrix mt = GetCurMatrix(); - - CFX_FloatPoint pt = point; - mt.Transform(pt.x, pt.y); - - return pt; -} - -CFX_FloatPoint CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, - const CFX_FloatPoint& pt) { - return FFLtoPWL(pt); -} - -CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, - const CFX_FloatRect& rect) { - return rect; -} - -FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, - FX_UINT nFlag) { - if (IsDataChanged(pPageView)) { - FX_BOOL bRC = TRUE; - FX_BOOL bExit = FALSE; - CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); - pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); - if (bExit) - return TRUE; - if (!bRC) { - ResetPDFWindow(pPageView, FALSE); - return TRUE; - } - - pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); - if (bExit) - return TRUE; - if (!bRC) { - ResetPDFWindow(pPageView, FALSE); - return TRUE; - } - - SaveData(pPageView); - pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); - if (bExit) - return TRUE; - - pIFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); - } - return TRUE; -} - -FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { - return FALSE; -} - -void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} - -#ifdef PDF_ENABLE_XFA -FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { - return FALSE; -} -#endif // PDF_ENABLE_XFA - -void CFFL_FormFiller::SetChangeMark() { - m_pApp->FFI_OnChange(); -} - -void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { - fa.sValue = m_pWidget->GetValue(); -} - -void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) {} - -FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { - return FALSE; -} - -void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} - -void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} - -CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) { - return GetPDFWindow(pPageView, FALSE); -} - -void CFFL_FormFiller::TimerProc() {} - -IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { - return m_pApp->GetSysHandler(); -} - -void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, - FX_BOOL bDestroyPDFWindow) { - m_bValid = FALSE; - - FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); - InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); - - if (bDestroyPDFWindow) - DestroyPDFWindow(pPageView); -} - -void CFFL_FormFiller::InvalidateRect(double left, - double top, - double right, - double bottom) { - UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); - m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); -} - -CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) - : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(FALSE), m_bMouseDown(FALSE) {} - -CFFL_Button::~CFFL_Button() {} - -void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - m_bMouseIn = TRUE; - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); -} - -void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - m_bMouseIn = FALSE; - - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - EndTimer(); - ASSERT(m_pWidget); -} - -FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - CFX_FloatRect rcAnnot = pAnnot->GetRect(); - if (!rcAnnot.Contains(point.x, point.y)) - return FALSE; - - m_bMouseDown = TRUE; - m_bValid = TRUE; - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - return TRUE; -} - -FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - CFX_FloatRect rcAnnot = pAnnot->GetRect(); - if (!rcAnnot.Contains(point.x, point.y)) - return FALSE; - - m_bMouseDown = FALSE; - m_pWidget->GetPDFPage(); - - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - return TRUE; -} - -FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(m_pApp); - - return TRUE; -} - -void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - ASSERT(pPageView); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - CPDF_FormControl* pCtrl = pWidget->GetFormControl(); - CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); - - if (eHM != CPDF_FormControl::Push) { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - return; - } - - if (m_bMouseDown) { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } else if (m_bMouseIn) { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, - NULL); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } else { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } -} - -void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); -} diff --git a/fpdfsdk/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/formfiller/FFL_IFormFiller.cpp deleted file mode 100644 index 8cc7b40c9f..0000000000 --- a/fpdfsdk/formfiller/FFL_IFormFiller.cpp +++ /dev/null @@ -1,1016 +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/include/formfiller/FFL_IFormFiller.h" - -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "fpdfsdk/include/formfiller/FFL_CheckBox.h" -#include "fpdfsdk/include/formfiller/FFL_ComboBox.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/formfiller/FFL_ListBox.h" -#include "fpdfsdk/include/formfiller/FFL_PushButton.h" -#include "fpdfsdk/include/formfiller/FFL_RadioButton.h" -#include "fpdfsdk/include/formfiller/FFL_TextField.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_Utils.h" - -#define FFL_MAXLISTBOXHEIGHT 140.0f - -CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) - : m_pApp(pApp), m_bNotifying(FALSE) {} - -CFFL_IFormFiller::~CFFL_IFormFiller() { - for (auto& it : m_Maps) - delete it.second; - m_Maps.clear(); -} - -FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_FloatPoint point) { - CFX_FloatRect rc = pAnnot->GetRect(); - if (rc.Contains(point.x, point.y)) - return TRUE; - return FALSE; -} - -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 rcAnnot; - pPDFAnnot->GetRect(rcAnnot); - - CFX_FloatRect rcWin = CPWL_Utils::InflateRect(rcAnnot, 1); - return rcWin.GetOutterRect(); -} - -void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - ASSERT(pPageView); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - if (IsVisible(pWidget)) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - if (pFormFiller->IsValid()) { - pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); - pAnnot->GetPDFPage(); - - CPDFSDK_Document* pDocument = m_pApp->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, - dwFlags); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - - 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, - FX_UINT nFlag) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_UINT nFlag) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlags); - fa.bShift = m_pApp->FFI_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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - CPDFSDK_Document* pDocument = m_pApp->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, - FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, - FX_UINT nFlags, - short zDelta, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, - FX_UINT nKeyCode, - FX_UINT nFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { - return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); - } - - return FALSE; -} - -FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, FX_UINT nFlag) { - if (!pAnnot) - return FALSE; - - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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* pFormFiller = GetFormFiller(pWidget, FALSE)) { - pFormFiller->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, FX_UINT nFlag) { - if (!pAnnot) - return FALSE; - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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; - FX_DWORD 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; - - 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_pApp, pWidget); - break; - case FIELDTYPE_CHECKBOX: - pFormFiller = new CFFL_CheckBox(m_pApp, pWidget); - break; - case FIELDTYPE_RADIOBUTTON: - pFormFiller = new CFFL_RadioButton(m_pApp, pWidget); - break; - case FIELDTYPE_TEXTFIELD: - pFormFiller = new CFFL_TextField(m_pApp, pWidget); - break; - case FIELDTYPE_LISTBOX: - pFormFiller = new CFFL_ListBox(m_pApp, pWidget); - break; - case FIELDTYPE_COMBOBOX: - pFormFiller = new CFFL_ComboBox(m_pApp, pWidget); - break; - case FIELDTYPE_UNKNOWN: - default: - pFormFiller = nullptr; - break; - } - - if (!pFormFiller) - return nullptr; - - m_Maps[pAnnot] = 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; - - delete it->second; - 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, - FX_DWORD nFlag) { - if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { - m_bNotifying = TRUE; - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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); - - PDFSDK_FieldAction faOld = fa; - 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, - FX_DWORD nFlag) { - if (!m_bNotifying) { - if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { - m_bNotifying = TRUE; - pWidget->ClearAppModified(); - - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag); - fa.bKeyDown = TRUE; - fa.bRC = TRUE; - - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); - pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); - pFormFiller->SaveState(pPageView); - - PDFSDK_FieldAction faOld = fa; - 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, - FX_DWORD nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = - (CPDFSDK_InterForm*)pDocument->GetInterForm(); - pInterForm->OnCalculate(pWidget->GetFormField()); - - m_bNotifying = FALSE; - } -} - -void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - FX_DWORD nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFSDK_InterForm* pInterForm = - (CPDFSDK_InterForm*)pDocument->GetInterForm(); - - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = - pInterForm->OnFormat(pWidget->GetFormField(), bFormated); - - if (bExit) - return; - - if (bFormated) { - pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue.c_str(), - 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, - FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_DWORD 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, - FX_DWORD 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, - FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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, - FX_DWORD 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_pApp->FFI_IsCTRLKeyDown(nFlag); - fa.bShift = m_pApp->FFI_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/FFL_ListBox.cpp b/fpdfsdk/formfiller/FFL_ListBox.cpp deleted file mode 100644 index 638618f784..0000000000 --- a/fpdfsdk/formfiller/FFL_ListBox.cpp +++ /dev/null @@ -1,223 +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/include/formfiller/FFL_ListBox.h" - -#include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" -#include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_ListBox.h" - -#define FFL_DEFAULTLISTBOXFONTSIZE 12.0f - -CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) - : CFFL_FormFiller(pApp, pWidget), m_pFontMap(NULL) {} - -CFFL_ListBox::~CFFL_ListBox() { - delete m_pFontMap; -} - -PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { - PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); - - FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); - - if (dwFieldFlag & FIELDFLAG_MULTISELECT) { - cp.dwFlags |= PLBS_MULTIPLESEL; - } - - cp.dwFlags |= PWS_VSCROLL; - - if (cp.dwFlags & PWS_AUTOFONTSIZE) - cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE; - - if (!m_pFontMap) - m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); - cp.pFontMap = m_pFontMap; - - return cp; -} - -CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_ListBox* pWnd = new CPWL_ListBox(); - pWnd->AttachFFLData(this); - pWnd->Create(cp); - - CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); - pWnd->SetFillerNotify(pIFormFiller); - - for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) - pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); - - if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { - m_OriginSelections.clear(); - - FX_BOOL bSetCaret = FALSE; - for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { - if (m_pWidget->IsOptionSelected(i)) { - if (!bSetCaret) { - pWnd->SetCaret(i); - bSetCaret = TRUE; - } - pWnd->Select(i); - m_OriginSelections.insert(i); - } - } - } else { - for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { - if (m_pWidget->IsOptionSelected(i)) { - pWnd->Select(i); - break; - } - } - } - - pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex()); - - return pWnd; -} - -FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); -} - -FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) { - CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE); - if (!pListBox) - return FALSE; - - if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { - size_t nSelCount = 0; - for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) { - if (pListBox->IsItemSelected(i)) { - if (m_OriginSelections.count(i) == 0) - return TRUE; - - ++nSelCount; - } - } - - return nSelCount != m_OriginSelections.size(); - } - return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); -} - -void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { - ASSERT(m_pWidget); - - if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { - CFX_IntArray aOldSelect, aNewSelect; - - { - for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { - if (m_pWidget->IsOptionSelected(i)) { - aOldSelect.Add(i); - } - } - } - - int32_t nNewTopIndex = pListBox->GetTopVisibleIndex(); - - m_pWidget->ClearSelection(FALSE); - - if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { - for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { - if (pListBox->IsItemSelected(i)) { - m_pWidget->SetOptionSelection(i, TRUE, FALSE); - aNewSelect.Add(i); - } - } - } else { - m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE); - aNewSelect.Add(pListBox->GetCurSel()); - } - - m_pWidget->SetTopVisibleIndex(nNewTopIndex); - m_pWidget->ResetFieldAppearance(TRUE); - m_pWidget->UpdateField(); - SetChangeMark(); - } -} - -void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { - switch (type) { - case CPDF_AAction::Validate: - if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { - fa.sValue = L""; - } else { - if (CPWL_ListBox* pListBox = - (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { - int32_t nCurSel = pListBox->GetCurSel(); - if (nCurSel >= 0) - fa.sValue = m_pWidget->GetOptionLabel(nCurSel); - } - } - break; - case CPDF_AAction::LoseFocus: - case CPDF_AAction::GetFocus: - if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { - fa.sValue = L""; - } else { - int32_t nCurSel = m_pWidget->GetSelectedIndex(0); - if (nCurSel >= 0) - fa.sValue = m_pWidget->GetOptionLabel(nCurSel); - } - break; - default: - break; - } -} - -void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) {} - -void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) { - ASSERT(pPageView); - - if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { - for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { - if (pListBox->IsItemSelected(i)) { - m_State.Add(i); - } - } - } -} - -void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView) { - if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { - for (int i = 0, sz = m_State.GetSize(); i < sz; i++) - pListBox->Select(m_State[i]); - } -} - -CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) { - if (bRestoreValue) - SaveState(pPageView); - - DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = NULL; - - if (bRestoreValue) { - RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, FALSE); - } else { - pRet = GetPDFWindow(pPageView, TRUE); - } - - m_pWidget->UpdateField(); - - return pRet; -} diff --git a/fpdfsdk/formfiller/FFL_PushButton.cpp b/fpdfsdk/formfiller/FFL_PushButton.cpp deleted file mode 100644 index d5bd509718..0000000000 --- a/fpdfsdk/formfiller/FFL_PushButton.cpp +++ /dev/null @@ -1,38 +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/include/formfiller/FFL_PushButton.h" - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" - -CFFL_PushButton::CFFL_PushButton(CPDFDoc_Environment* pApp, - CPDFSDK_Annot* pAnnot) - : CFFL_Button(pApp, pAnnot) {} - -CFFL_PushButton::~CFFL_PushButton() {} - -CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_PushButton* pWnd = new CPWL_PushButton(); - pWnd->Create(cp); - - return pWnd; -} - -FX_BOOL CFFL_PushButton::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); -} - -void CFFL_PushButton::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) { - CFFL_Button::OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); -} diff --git a/fpdfsdk/formfiller/FFL_RadioButton.cpp b/fpdfsdk/formfiller/FFL_RadioButton.cpp deleted file mode 100644 index 029bcf1a17..0000000000 --- a/fpdfsdk/formfiller/FFL_RadioButton.cpp +++ /dev/null @@ -1,121 +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/include/formfiller/FFL_RadioButton.h" - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" -#include "fpdfsdk/include/fsdk_mgr.h" -#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" - -CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, - CPDFSDK_Annot* pWidget) - : CFFL_Button(pApp, pWidget) {} - -CFFL_RadioButton::~CFFL_RadioButton() {} - -CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_RadioButton* pWnd = new CPWL_RadioButton(); - pWnd->Create(cp); - - pWnd->SetCheck(m_pWidget->IsChecked()); - - return pWnd; -} - -FX_BOOL CFFL_RadioButton::OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags) { - switch (nKeyCode) { - case FWL_VKEY_Return: - case FWL_VKEY_Space: - return TRUE; - default: - return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); - } -} - -FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - switch (nChar) { - case FWL_VKEY_Return: - case FWL_VKEY_Space: { - CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - ASSERT(pPageView); - - FX_BOOL bReset = FALSE; - FX_BOOL bExit = FALSE; - - pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit, nFlags); - - if (bReset) - return TRUE; - if (bExit) - return TRUE; - - CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE)) - pWnd->SetCheck(TRUE); - CommitData(pPageView, nFlags); - return TRUE; - } - default: - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - } -} - -FX_BOOL CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) { - CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); - - if (IsValid()) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE)) - pWnd->SetCheck(TRUE); - - if (!CommitData(pPageView, nFlags)) - return FALSE; - } - - return TRUE; -} - -FX_BOOL CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE)) { - return pWnd->IsChecked() != m_pWidget->IsChecked(); - } - - return FALSE; -} - -void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE)) { - bool bNewChecked = pWnd->IsChecked(); - - if (bNewChecked) { - CPDF_FormField* pField = m_pWidget->GetFormField(); - for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { - if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { - if (pCtrl->IsChecked()) { - break; - } - } - } - } - - m_pWidget->SetCheck(bNewChecked, false); - m_pWidget->UpdateField(); - SetChangeMark(); - } -} diff --git a/fpdfsdk/formfiller/FFL_TextField.cpp b/fpdfsdk/formfiller/FFL_TextField.cpp deleted file mode 100644 index 42f2aad48f..0000000000 --- a/fpdfsdk/formfiller/FFL_TextField.cpp +++ /dev/null @@ -1,292 +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/include/formfiller/FFL_TextField.h" - -#include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" -#include "fpdfsdk/include/fsdk_common.h" -#include "fpdfsdk/include/fsdk_mgr.h" - -CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) - : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { - m_State.nStart = m_State.nEnd = 0; -} - -CFFL_TextField::~CFFL_TextField() { - for (const auto& it : m_Maps) - it.second->InvalidateFocusHandler(this); - delete m_pFontMap; -} - -PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { - PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); - - int nFlags = m_pWidget->GetFieldFlags(); - - if (nFlags & FIELDFLAG_PASSWORD) { - cp.dwFlags |= PES_PASSWORD; - } - - if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) { - } - - if (nFlags & FIELDFLAG_MULTILINE) { - cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP; - - if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { - cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL; - } - } else { - cp.dwFlags |= PES_CENTER; - - if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { - cp.dwFlags |= PES_AUTOSCROLL; - } - } - - if (nFlags & FIELDFLAG_COMB) { - cp.dwFlags |= PES_CHARARRAY; - } - - if (nFlags & FIELDFLAG_RICHTEXT) { - cp.dwFlags |= PES_RICH; - } - - cp.dwFlags |= PES_UNDO; - - switch (m_pWidget->GetAlignment()) { - default: - case BF_ALIGN_LEFT: - cp.dwFlags |= PES_LEFT; - break; - case BF_ALIGN_MIDDLE: - cp.dwFlags |= PES_MIDDLE; - break; - case BF_ALIGN_RIGHT: - cp.dwFlags |= PES_RIGHT; - break; - } - - if (!m_pFontMap) - m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); - cp.pFontMap = m_pFontMap; - cp.pFocusHandler = this; - - return cp; -} - -CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { - CPWL_Edit* pWnd = new CPWL_Edit(); - pWnd->AttachFFLData(this); - pWnd->Create(cp); - - CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); - pWnd->SetFillerNotify(pIFormFiller); - - int32_t nMaxLen = m_pWidget->GetMaxLen(); - CFX_WideString swValue = m_pWidget->GetValue(); - - if (nMaxLen > 0) { - if (pWnd->HasFlag(PES_CHARARRAY)) { - pWnd->SetCharArray(nMaxLen); - pWnd->SetAlignFormatV(PEAV_CENTER); - } else { - pWnd->SetLimitChar(nMaxLen); - } - } - - pWnd->SetText(swValue.c_str()); - return pWnd; -} - -FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, - FX_UINT nChar, - FX_UINT nFlags) { - switch (nChar) { - case FWL_VKEY_Return: - if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView); - m_bValid = !m_bValid; - CFX_FloatRect rcAnnot = pAnnot->GetRect(); - m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, - rcAnnot.top, rcAnnot.right, rcAnnot.bottom); - - if (m_bValid) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) - pWnd->SetFocus(); - } else { - if (CommitData(pPageView, nFlags)) { - DestroyPDFWindow(pPageView); - return TRUE; - } - return FALSE; - } - } - break; - case FWL_VKEY_Escape: { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView); - EscapeFiller(pPageView, TRUE); - return TRUE; - } - } - - return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); -} - -FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) - return pEdit->GetText() != m_pWidget->GetValue(); - - return FALSE; -} - -void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - CFX_WideString sOldValue = m_pWidget->GetValue(); - CFX_WideString sNewValue = pWnd->GetText(); - - m_pWidget->SetValue(sNewValue, FALSE); - m_pWidget->ResetFieldAppearance(TRUE); - m_pWidget->UpdateField(); - SetChangeMark(); - } -} - -void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { - switch (type) { - case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - fa.bFieldFull = pWnd->IsTextFull(); - - fa.sValue = pWnd->GetText(); - - if (fa.bFieldFull) { - fa.sChange = L""; - fa.sChangeEx = L""; - } - } - break; - case CPDF_AAction::Validate: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - fa.sValue = pWnd->GetText(); - } - break; - case CPDF_AAction::LoseFocus: - case CPDF_AAction::GetFocus: - fa.sValue = m_pWidget->GetValue(); - break; - default: - break; - } -} - -void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) { - switch (type) { - case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - pEdit->SetFocus(); - pEdit->SetSel(fa.nSelStart, fa.nSelEnd); - pEdit->ReplaceSel(fa.sChange.c_str()); - } - break; - default: - break; - } -} - -FX_BOOL CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { - switch (type) { - case CPDF_AAction::KeyStroke: - return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || - faOld.nSelStart != faNew.nSelStart || - faOld.sChange != faNew.sChange; - default: - break; - } - - return FALSE; -} - -void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { - ASSERT(pPageView); - - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - pWnd->GetSel(m_State.nStart, m_State.nEnd); - m_State.sValue = pWnd->GetText(); - } -} - -void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { - ASSERT(pPageView); - - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) { - pWnd->SetText(m_State.sValue.c_str()); - pWnd->SetSel(m_State.nStart, m_State.nEnd); - } -} - -CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) { - if (bRestoreValue) - SaveState(pPageView); - - DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = NULL; - - if (bRestoreValue) { - RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, FALSE); - } else { - pRet = GetPDFWindow(pPageView, TRUE); - } - - m_pWidget->UpdateField(); - - return pRet; -} - -#ifdef PDF_ENABLE_XFA -FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { - return pWnd->IsTextFull(); - } - - return FALSE; -} -#endif // PDF_ENABLE_XFA - -void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { - ASSERT(m_pApp); - if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { - CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); - pEdit->SetCodePage(936); - - pEdit->SetReadyToInput(); - CFX_WideString wsText = pEdit->GetText(); - int nCharacters = wsText.GetLength(); - CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); - unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); - m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, - nCharacters, TRUE); - - pEdit->SetEditNotify(this); - } -} - -void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {} - -void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {} diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp new file mode 100644 index 0000000000..0923c4d1ca --- /dev/null +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -0,0 +1,259 @@ +// 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/cba_fontmap.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" +#include "fpdfsdk/include/fsdk_baseannot.h" + +CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, + IFX_SystemHandler* pSystemHandler) + : CPWL_FontMap(pSystemHandler), + m_pDocument(NULL), + m_pAnnotDict(NULL), + m_pDefaultFont(NULL), + m_sAPType("N") { + CPDF_Page* pPage = pAnnot->GetPDFPage(); + + m_pDocument = pPage->m_pDocument; + m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); + Initialize(); +} + +CBA_FontMap::~CBA_FontMap() {} + +void CBA_FontMap::Reset() { + Empty(); + m_pDefaultFont = NULL; + m_sDefaultFontName = ""; +} + +void CBA_FontMap::Initialize() { + int32_t nCharset = DEFAULT_CHARSET; + + if (!m_pDefaultFont) { + m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); + if (m_pDefaultFont) { + if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { + nCharset = pSubstFont->m_Charset; + } else { + if (m_sDefaultFontName == "Wingdings" || + m_sDefaultFontName == "Wingdings2" || + m_sDefaultFontName == "Wingdings3" || + m_sDefaultFontName == "Webdings") + nCharset = SYMBOL_CHARSET; + else + nCharset = ANSI_CHARSET; + } + AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); + AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName); + } + } + + if (nCharset != ANSI_CHARSET) + CPWL_FontMap::Initialize(); +} + +void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, + const CFX_ByteString& sFontName) { + ASSERT(pFont); + + if (m_pDefaultFont) + return; + + m_pDefaultFont = pFont; + m_sDefaultFontName = sFontName; + + int32_t nCharset = DEFAULT_CHARSET; + if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) + nCharset = pSubstFont->m_Charset; + AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); +} + +CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, + int32_t nCharset) { + if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { + CPDF_Document* pDocument = GetDocument(); + CPDF_Dictionary* pRootDict = pDocument->GetRoot(); + if (!pRootDict) + return NULL; + + CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); + if (!pAcroFormDict) + return NULL; + + CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); + if (!pDRDict) + return NULL; + + return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); + } + + return NULL; +} + +CPDF_Document* CBA_FontMap::GetDocument() { + return m_pDocument; +} + +CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, + CFX_ByteString& sFontAlias, + int32_t nCharset) { + if (!pResDict) + return NULL; + + CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); + if (!pFonts) + return NULL; + + CPDF_Document* pDocument = GetDocument(); + CPDF_Font* pFind = NULL; + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; + if (!pObj) + continue; + + CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); + if (!pElement) + continue; + if (pElement->GetStringBy("Type") != "Font") + continue; + + CPDF_Font* pFont = pDocument->LoadFont(pElement); + if (!pFont) + continue; + const CFX_SubstFont* pSubst = pFont->GetSubstFont(); + if (!pSubst) + continue; + if (pSubst->m_Charset == nCharset) { + sFontAlias = csKey; + pFind = pFont; + } + } + return pFind; +} + +void CBA_FontMap::AddedFont(CPDF_Font* pFont, + const CFX_ByteString& sFontAlias) { + AddFontToAnnotDict(pFont, sFontAlias); +} + +void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, + const CFX_ByteString& sAlias) { + if (!pFont) + return; + + CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); + + if (!pAPDict) { + pAPDict = new CPDF_Dictionary; + m_pAnnotDict->SetAt("AP", pAPDict); + } + + // to avoid checkbox and radiobutton + CPDF_Object* pObject = pAPDict->GetElement(m_sAPType); + if (ToDictionary(pObject)) + return; + + CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); + if (!pStream) { + pStream = new CPDF_Stream(NULL, 0, NULL); + int32_t objnum = m_pDocument->AddIndirectObject(pStream); + pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); + } + + CPDF_Dictionary* pStreamDict = pStream->GetDict(); + + if (!pStreamDict) { + pStreamDict = new CPDF_Dictionary; + pStream->InitStream(NULL, 0, pStreamDict); + } + + if (pStreamDict) { + CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); + if (!pStreamResList) { + pStreamResList = new CPDF_Dictionary(); + pStreamDict->SetAt("Resources", pStreamResList); + } + + if (pStreamResList) { + CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); + if (!pStreamResFontList) { + pStreamResFontList = new CPDF_Dictionary; + int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); + pStreamResList->SetAtReference("Font", m_pDocument, objnum); + } + if (!pStreamResFontList->KeyExist(sAlias)) + pStreamResFontList->SetAtReference(sAlias, m_pDocument, + pFont->GetFontDict()); + } + } +} + +CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { + CPDF_Dictionary* pAcroFormDict = NULL; + const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); + if (bWidget) { + if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) + pAcroFormDict = pRootDict->GetDictBy("AcroForm"); + } + + CFX_ByteString sDA; + CPDF_Object* pObj; + if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"))) + sDA = pObj->GetString(); + + if (bWidget) { + if (sDA.IsEmpty()) { + pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); + sDA = pObj ? pObj->GetString() : CFX_ByteString(); + } + } + + CPDF_Dictionary* pFontDict = NULL; + + if (!sDA.IsEmpty()) { + CPDF_SimpleParser syntax(sDA); + syntax.FindTagParamFromStart("Tf", 2); + CFX_ByteString sFontName = syntax.GetWord(); + sAlias = PDF_NameDecode(sFontName).Mid(1); + + if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) + if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) + pFontDict = pDRFontDict->GetDictBy(sAlias); + + if (!pFontDict) + if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP")) + if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N")) + if (CPDF_Dictionary* pNormalResDict = + pNormalDict->GetDictBy("Resources")) + if (CPDF_Dictionary* pResFontDict = + pNormalResDict->GetDictBy("Font")) + pFontDict = pResFontDict->GetDictBy(sAlias); + + if (bWidget) { + if (!pFontDict) { + if (pAcroFormDict) { + if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR")) + if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) + pFontDict = pDRFontDict->GetDictBy(sAlias); + } + } + } + } + + return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; +} + +void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { + m_sAPType = sAPType; + + Reset(); + Initialize(); +} diff --git a/fpdfsdk/formfiller/cba_fontmap.h b/fpdfsdk/formfiller/cba_fontmap.h new file mode 100644 index 0000000000..b576d01fc2 --- /dev/null +++ b/fpdfsdk/formfiller/cba_fontmap.h @@ -0,0 +1,46 @@ +// 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_CBA_FONTMAP_H_ +#define FPDFSDK_FORMFILLER_CBA_FONTMAP_H_ + +#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h" + +class CPDF_Dictionary; +class CPDFSDK_Annot; + +class CBA_FontMap : public CPWL_FontMap { + public: + CBA_FontMap(CPDFSDK_Annot* pAnnot, IFX_SystemHandler* pSystemHandler); + ~CBA_FontMap() override; + + void SetDefaultFont(CPDF_Font* pFont, const CFX_ByteString& sFontName); + + void Reset(); + void SetAPType(const CFX_ByteString& sAPType); + + private: + // CPWL_FontMap: + void Initialize() override; + CPDF_Document* GetDocument() override; + CPDF_Font* FindFontSameCharset(CFX_ByteString& sFontAlias, + int32_t nCharset) override; + void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) override; + + CPDF_Font* FindResFontSameCharset(CPDF_Dictionary* pResDict, + CFX_ByteString& sFontAlias, + int32_t nCharset); + CPDF_Font* GetAnnotDefaultFont(CFX_ByteString& csNameTag); + void AddFontToAnnotDict(CPDF_Font* pFont, const CFX_ByteString& sAlias); + + CPDF_Document* m_pDocument; + CPDF_Dictionary* m_pAnnotDict; + CPDF_Font* m_pDefaultFont; + CFX_ByteString m_sDefaultFontName; + CFX_ByteString m_sAPType; +}; + +#endif // FPDFSDK_FORMFILLER_CBA_FONTMAP_H_ diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp new file mode 100644 index 0000000000..c0e3008508 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -0,0 +1,116 @@ +// 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_checkbox.h" + +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" +#include "public/fpdf_fwlevent.h" + +CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget) + : CFFL_Button(pApp, pWidget) {} + +CFFL_CheckBox::~CFFL_CheckBox() {} + +CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_CheckBox* pWnd = new CPWL_CheckBox(); + pWnd->Create(cp); + pWnd->SetCheck(m_pWidget->IsChecked()); + return pWnd; +} + +FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags) { + switch (nKeyCode) { + case FWL_VKEY_Return: + case FWL_VKEY_Space: + return TRUE; + default: + return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); + } +} +FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + switch (nChar) { + case FWL_VKEY_Return: + case FWL_VKEY_Space: { + CFFL_IFormFiller* pIFormFiller = m_pApp->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); + + if (bReset) + return TRUE; + if (bExit) + return TRUE; + + CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); + + if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) + pWnd->SetCheck(!pWnd->IsChecked()); + + CommitData(pPageView, nFlags); + return TRUE; + } + default: + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); + } +} + +FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); + + if (IsValid()) { + if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + pWnd->SetCheck(!pWidget->IsChecked()); + } + + if (!CommitData(pPageView, nFlags)) + return FALSE; + } + + return TRUE; +} + +FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { + CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE); + return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); +} + +void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { + if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { + bool bNewChecked = pWnd->IsChecked(); + + if (bNewChecked) { + CPDF_FormField* pField = m_pWidget->GetFormField(); + for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { + if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { + if (pCtrl->IsChecked()) { + break; + } + } + } + } + + m_pWidget->SetCheck(bNewChecked, false); + m_pWidget->UpdateField(); + SetChangeMark(); + } +} diff --git a/fpdfsdk/formfiller/cffl_checkbox.h b/fpdfsdk/formfiller/cffl_checkbox.h new file mode 100644 index 0000000000..01f6e3bee4 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_checkbox.h @@ -0,0 +1,32 @@ +// 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_CHECKBOX_H_ +#define FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_ + +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CFFL_CheckBox : public CFFL_Button { + public: + CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget); + ~CFFL_CheckBox() override; + + // CFFL_Button + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; + void SaveData(CPDFSDK_PageView* pPageView) override; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_ diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp new file mode 100644 index 0000000000..6a24df0dd9 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -0,0 +1,302 @@ +// 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_combobox.h" + +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/fsdk_common.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_ComboBox.h" + +CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) + : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { + m_State.nIndex = 0; + m_State.nStart = 0; + m_State.nEnd = 0; +} + +CFFL_ComboBox::~CFFL_ComboBox() { + for (const auto& it : m_Maps) + it.second->InvalidateFocusHandler(this); + delete m_pFontMap; +} + +PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { + PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); + + int nFlags = m_pWidget->GetFieldFlags(); + if (nFlags & FIELDFLAG_EDIT) { + cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; + } + + if (!m_pFontMap) + m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler()); + cp.pFontMap = m_pFontMap; + cp.pFocusHandler = this; + + return cp; +} + +CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_ComboBox* pWnd = new CPWL_ComboBox(); + pWnd->AttachFFLData(this); + pWnd->Create(cp); + + CFFL_IFormFiller* pFormFiller = m_pApp->GetIFormFiller(); + pWnd->SetFillerNotify(pFormFiller); + + int32_t nCurSel = m_pWidget->GetSelectedIndex(0); + CFX_WideString swText; + if (nCurSel < 0) + swText = m_pWidget->GetValue(); + else + swText = m_pWidget->GetOptionLabel(nCurSel); + + for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { + pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); + } + + pWnd->SetSelect(nCurSel); + pWnd->SetText(swText.c_str()); + return pWnd; +} + +FX_BOOL CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); +} + +FX_BOOL CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) { + CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE); + if (!pWnd) + return FALSE; + + int32_t nCurSel = pWnd->GetSelect(); + if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) + return nCurSel != m_pWidget->GetSelectedIndex(0); + + if (nCurSel >= 0) + return nCurSel != m_pWidget->GetSelectedIndex(0); + + return pWnd->GetText() != m_pWidget->GetValue(); +} + +void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { + CPWL_ComboBox* pWnd = + static_cast(GetPDFWindow(pPageView, FALSE)); + if (!pWnd) + return; + + CFX_WideString swText = pWnd->GetText(); + int32_t nCurSel = pWnd->GetSelect(); + + bool bSetValue = false; + + if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) + bSetValue = (nCurSel < 0) || (swText != m_pWidget->GetOptionLabel(nCurSel)); + + if (bSetValue) { + m_pWidget->SetValue(swText, FALSE); + } else { + m_pWidget->GetSelectedIndex(0); + m_pWidget->SetOptionSelection(nCurSel, TRUE, FALSE); + } + + m_pWidget->ResetFieldAppearance(TRUE); + m_pWidget->UpdateField(); + SetChangeMark(); + + m_pWidget->GetPDFPage(); +} + +void CFFL_ComboBox::GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) { + switch (type) { + case CPDF_AAction::KeyStroke: + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, FALSE))) { + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { + fa.bFieldFull = pEdit->IsTextFull(); + int nSelStart = 0; + int nSelEnd = 0; + pEdit->GetSel(nSelStart, nSelEnd); + fa.nSelEnd = nSelEnd; + fa.nSelStart = nSelStart; + fa.sValue = pEdit->GetText(); + fa.sChangeEx = GetSelectExportText(); + + if (fa.bFieldFull) { + fa.sChange = L""; + fa.sChangeEx = L""; + } + } + } + break; + case CPDF_AAction::Validate: + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, FALSE))) { + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { + fa.sValue = pEdit->GetText(); + } + } + break; + case CPDF_AAction::LoseFocus: + case CPDF_AAction::GetFocus: + fa.sValue = m_pWidget->GetValue(); + break; + default: + break; + } +} + +void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) { + switch (type) { + case CPDF_AAction::KeyStroke: + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, FALSE))) { + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { + pEdit->SetSel(fa.nSelStart, fa.nSelEnd); + pEdit->ReplaceSel(fa.sChange.c_str()); + } + } + break; + default: + break; + } +} + +FX_BOOL CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) { + switch (type) { + case CPDF_AAction::KeyStroke: + return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || + faOld.nSelStart != faNew.nSelStart || + faOld.sChange != faNew.sChange; + default: + break; + } + + return FALSE; +} + +void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { + ASSERT(pPageView); + + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, FALSE))) { + m_State.nIndex = pComboBox->GetSelect(); + + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { + pEdit->GetSel(m_State.nStart, m_State.nEnd); + m_State.sValue = pEdit->GetText(); + } + } +} + +void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { + ASSERT(pPageView); + + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, TRUE))) { + if (m_State.nIndex >= 0) { + pComboBox->SetSelect(m_State.nIndex); + } else { + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { + pEdit->SetText(m_State.sValue.c_str()); + pEdit->SetSel(m_State.nStart, m_State.nEnd); + } + } + } +} + +CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) { + if (bRestoreValue) + SaveState(pPageView); + + DestroyPDFWindow(pPageView); + + CPWL_Wnd* pRet = NULL; + + if (bRestoreValue) { + RestoreState(pPageView); + pRet = GetPDFWindow(pPageView, FALSE); + } else { + pRet = GetPDFWindow(pPageView, TRUE); + } + + m_pWidget->UpdateField(); + + return pRet; +} + +#ifdef PDF_ENABLE_XFA +FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { + if (CPWL_ComboBox* pComboBox = + static_cast(GetPDFWindow(pPageView, FALSE))) { + if (CPWL_Edit* pEdit = pComboBox->GetEdit()) + return pEdit->IsTextFull(); + } + return FALSE; +} +#endif // PDF_ENABLE_XFA + +void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { + ASSERT(m_pApp); + + if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { + CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; + pEdit->SetCharSet(134); + pEdit->SetCodePage(936); + + pEdit->SetReadyToInput(); + CFX_WideString wsText = pEdit->GetText(); + int nCharacters = wsText.GetLength(); + CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); + unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); + m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, + nCharacters, TRUE); + + pEdit->SetEditNotify(this); + } +} + +void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) { + ASSERT(m_pApp); +} + +void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) { + ASSERT(pEdit); +} + +CFX_WideString CFFL_ComboBox::GetSelectExportText() { + CFX_WideString swRet; + + int nExport = -1; + CPDFSDK_PageView* pPageView = GetCurPageView(); + if (CPWL_ComboBox* pComboBox = + (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { + nExport = pComboBox->GetSelect(); + } + + if (nExport >= 0) { + if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { + swRet = pFormField->GetOptionValue(nExport); + if (swRet.IsEmpty()) + swRet = pFormField->GetOptionLabel(nExport); + } + } + + return swRet; +} diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h new file mode 100644 index 0000000000..b59f22bf36 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_combobox.h @@ -0,0 +1,69 @@ +// 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_COMBOBOX_H_ +#define FPDFSDK_FORMFILLER_CFFL_COMBOBOX_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CBA_FontMap; + +struct FFL_ComboBoxState { + int nIndex; + int nStart; + int nEnd; + CFX_WideString sValue; +}; + +class CFFL_ComboBox : public CFFL_FormFiller, + public IPWL_FocusHandler, + public IPWL_Edit_Notify { + public: + CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); + ~CFFL_ComboBox() override; + + // CFFL_FormFiller: + PWL_CREATEPARAM GetCreateParam() override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; + void SaveData(CPDFSDK_PageView* pPageView) override; + void GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) override; + void SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) override; + FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) override; + void SaveState(CPDFSDK_PageView* pPageView) override; + void RestoreState(CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) override; + + // IPWL_FocusHandler: + void OnSetFocus(CPWL_Wnd* pWnd) override; + void OnKillFocus(CPWL_Wnd* pWnd) override; + + // IPWL_Edit_Notify: + void OnAddUndo(CPWL_Edit* pEdit) override; + +#ifdef PDF_ENABLE_XFA + // CFFL_FormFiller: + FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; +#endif // PDF_ENABLE_XFA + + private: + CFX_WideString GetSelectExportText(); + + CBA_FontMap* m_pFontMap; + FFL_ComboBoxState m_State; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_COMBOBOX_H_ diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp new file mode 100644 index 0000000000..732ea86c4e --- /dev/null +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -0,0 +1,728 @@ +// 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_formfiller.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/include/fsdk_common.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_Utils.h" + +#define GetRed(rgb) ((uint8_t)(rgb)) +#define GetGreen(rgb) ((uint8_t)(((FX_WORD)(rgb)) >> 8)) +#define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) + +#define FFL_HINT_ELAPSE 800 + +CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, + CPDFSDK_Annot* pAnnot) + : m_pApp(pApp), m_pAnnot(pAnnot), m_bValid(FALSE), m_ptOldPos(0, 0) { + m_pWidget = (CPDFSDK_Widget*)pAnnot; +} + +CFFL_FormFiller::~CFFL_FormFiller() { + for (const auto& it : m_Maps) { + CPWL_Wnd* pWnd = it.second; + CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + pWnd->InvalidateProvider(this); + pWnd->Destroy(); + delete pWnd; + delete pData; + } + m_Maps.clear(); +} + +void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, + const CFX_FloatRect& rcWindow) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + pWnd->Move(CFX_FloatRect(rcWindow), TRUE, FALSE); + } +} + +CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + return pWnd->GetWindowRect(); + } + + return CFX_FloatRect(0, 0, 0, 0); +} + +FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + ASSERT(pPageView); + ASSERT(pAnnot); + + CFX_FloatRect rcAnnot = m_pWidget->GetRect(); + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + CFX_FloatRect rcWindow = pWnd->GetWindowRect(); + rcAnnot = PWLtoFFL(rcWindow); + } + + CFX_FloatRect rcWin = rcAnnot; + + CFX_FloatRect rcFocus = GetFocusBox(pPageView); + if (!rcFocus.IsEmpty()) + rcWin.Union(rcFocus); + + CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); + + return rect.GetOutterRect(); +} + +void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + CFX_Matrix mt = GetCurMatrix(); + mt.Concat(*pUser2Device); + pWnd->DrawAppearance(pDevice, &mt); + } else { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (CFFL_IFormFiller::IsVisible(pWidget)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } +} + +void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); +} + +void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot) {} + +void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot) {} + +void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot) {} + +void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) {} + +void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + EndTimer(); + ASSERT(m_pWidget); +} + +FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { + m_bValid = TRUE; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + + if (!rect.Contains((int)point.x, (int)point.y)) + return FALSE; + + return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); + pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); + return TRUE; + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); + return TRUE; + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) { + m_ptOldPos = point; + } + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); + return TRUE; + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + short zDelta, + const CFX_FloatPoint& point) { + if (!IsValid()) + return FALSE; + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { + return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { + pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); + return TRUE; + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); + return TRUE; + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags) { + if (IsValid()) { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView); + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + return pWnd->OnKeyDown(nKeyCode, nFlags); + } + } + + return FALSE; +} + +FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + if (IsValid()) { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView); + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + return pWnd->OnChar(nChar, nFlags); + } + } + + return FALSE; +} + +void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); + CPDFSDK_Document* pDoc = m_pApp->GetSDKDocument(); + CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) + pWnd->SetFocus(); + + m_bValid = TRUE; + FX_RECT rcRect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); +} + +void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { + if (!IsValid()) + return; + + CPDFSDK_PageView* pPageView = GetCurPageView(); + if (!pPageView) + return; + + CommitData(pPageView, nFlag); + + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + pWnd->KillFocus(); + + FX_BOOL bDestroyPDFWindow; + switch (m_pWidget->GetFieldType()) { + case FIELDTYPE_PUSHBUTTON: + case FIELDTYPE_CHECKBOX: + case FIELDTYPE_RADIOBUTTON: + bDestroyPDFWindow = TRUE; + break; + default: + bDestroyPDFWindow = FALSE; + break; + } + EscapeFiller(pPageView, bDestroyPDFWindow); +} + +FX_BOOL CFFL_FormFiller::IsValid() const { + return m_bValid; +} + +PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { + ASSERT(m_pApp); + + PWL_CREATEPARAM cp; + cp.pParentWnd = NULL; + cp.pProvider = this; + cp.rcRectWnd = GetPDFWindowRect(); + + FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; + FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); + if (dwFieldFlag & FIELDFLAG_READONLY) { + dwCreateFlags |= PWS_READONLY; + } + + FX_COLORREF color; + if (m_pWidget->GetFillColor(color)) { + cp.sBackgroundColor = + CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } + + if (m_pWidget->GetBorderColor(color)) { + cp.sBorderColor = + CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } + + cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); + + if (m_pWidget->GetTextColor(color)) { + cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } + + cp.fFontSize = m_pWidget->GetFontSize(); + cp.dwBorderWidth = m_pWidget->GetBorderWidth(); + + int nBorderStyle = m_pWidget->GetBorderStyle(); + + switch (nBorderStyle) { + case BBS_SOLID: + cp.nBorderStyle = PBS_SOLID; + break; + case BBS_DASH: + cp.nBorderStyle = PBS_DASH; + cp.sDash = CPWL_Dash(3, 3, 0); + break; + case BBS_BEVELED: + cp.nBorderStyle = PBS_BEVELED; + cp.dwBorderWidth *= 2; + break; + case BBS_INSET: + cp.nBorderStyle = PBS_INSET; + cp.dwBorderWidth *= 2; + break; + case BBS_UNDERLINE: + cp.nBorderStyle = PBS_UNDERLINED; + break; + } + + if (cp.fFontSize <= 0) { + dwCreateFlags |= PWS_AUTOFONTSIZE; + } + + cp.dwFlags = dwCreateFlags; + cp.pSystemHandler = m_pApp->GetSysHandler(); + return cp; +} + +CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bNew) { + ASSERT(pPageView); + + auto it = m_Maps.find(pPageView); + const bool found = it != m_Maps.end(); + CPWL_Wnd* pWnd = found ? it->second : nullptr; + if (!bNew) + return pWnd; + + if (found) { + CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) { + return ResetPDFWindow( + pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); + } + } else { + PWL_CREATEPARAM cp = GetCreateParam(); + cp.hAttachedWnd = (FX_HWND)m_pWidget; + + CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; + pPrivateData->pWidget = m_pWidget; + pPrivateData->pPageView = pPageView; + pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); + pPrivateData->nValueAge = 0; + + cp.pAttachedData = pPrivateData; + + pWnd = NewPDFWindow(cp, pPageView); + m_Maps[pPageView] = pWnd; + } + + return pWnd; +} + +void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { + auto it = m_Maps.find(pPageView); + if (it == m_Maps.end()) + return; + + CPWL_Wnd* pWnd = it->second; + CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + pWnd->Destroy(); + delete pWnd; + delete pData; + + m_Maps.erase(it); +} + +CFX_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) { + if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) { + if (pPrivateData->pPageView) { + CFX_Matrix mtPageView; + pPrivateData->pPageView->GetCurrentMatrix(mtPageView); + CFX_Matrix mt = GetCurMatrix(); + mt.Concat(mtPageView); + + return mt; + } + } + return CFX_Matrix(1, 0, 0, 1, 0, 0); +} + +CFX_Matrix CFFL_FormFiller::GetCurMatrix() { + CFX_Matrix mt; + + CFX_FloatRect rcDA; + m_pWidget->GetPDFAnnot()->GetRect(rcDA); + + switch (m_pWidget->GetRotate()) { + default: + case 0: + mt = CFX_Matrix(1, 0, 0, 1, 0, 0); + break; + case 90: + mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); + break; + case 180: + mt = CFX_Matrix(-1, 0, 0, -1, rcDA.right - rcDA.left, + rcDA.top - rcDA.bottom); + break; + case 270: + mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); + break; + } + mt.e += rcDA.left; + mt.f += rcDA.bottom; + + return mt; +} + +CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) { + ASSERT(m_pApp); + + return L""; +} + +CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { + CFX_FloatRect rectAnnot; + m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); + + FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; + FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; + if ((m_pWidget->GetRotate() / 90) & 0x01) + return CFX_FloatRect(0, 0, fHeight, fWidth); + + return CFX_FloatRect(0, 0, fWidth, fHeight); +} + +CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView() { + UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + return pSDKDoc ? pSDKDoc->GetPageView(pPage) : nullptr; +} + +CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { + CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); + CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); + if (rcPage.Contains(rcFocus)) + return rcFocus; + } + return CFX_FloatRect(0, 0, 0, 0); +} + +CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { + CFX_Matrix mt; + mt.SetReverse(GetCurMatrix()); + + CFX_FloatRect temp = rect; + mt.TransformRect(temp); + + return temp; +} + +CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { + CFX_Matrix mt = GetCurMatrix(); + + CFX_FloatRect temp = rect; + mt.TransformRect(temp); + + return temp; +} + +CFX_FloatPoint CFFL_FormFiller::FFLtoPWL(const CFX_FloatPoint& point) { + CFX_Matrix mt; + mt.SetReverse(GetCurMatrix()); + + CFX_FloatPoint pt = point; + mt.Transform(pt.x, pt.y); + + return pt; +} + +CFX_FloatPoint CFFL_FormFiller::PWLtoFFL(const CFX_FloatPoint& point) { + CFX_Matrix mt = GetCurMatrix(); + + CFX_FloatPoint pt = point; + mt.Transform(pt.x, pt.y); + + return pt; +} + +CFX_FloatPoint CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, + const CFX_FloatPoint& pt) { + return FFLtoPWL(pt); +} + +CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, + const CFX_FloatRect& rect) { + return rect; +} + +FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, + FX_UINT nFlag) { + if (IsDataChanged(pPageView)) { + FX_BOOL bRC = TRUE; + FX_BOOL bExit = FALSE; + CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); + pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); + if (bExit) + return TRUE; + if (!bRC) { + ResetPDFWindow(pPageView, FALSE); + return TRUE; + } + + pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); + if (bExit) + return TRUE; + if (!bRC) { + ResetPDFWindow(pPageView, FALSE); + return TRUE; + } + + SaveData(pPageView); + pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); + if (bExit) + return TRUE; + + pIFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); + } + return TRUE; +} + +FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { + return FALSE; +} + +void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} + +#ifdef PDF_ENABLE_XFA +FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { + return FALSE; +} +#endif // PDF_ENABLE_XFA + +void CFFL_FormFiller::SetChangeMark() { + m_pApp->FFI_OnChange(); +} + +void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) { + fa.sValue = m_pWidget->GetValue(); +} + +void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) {} + +FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) { + return FALSE; +} + +void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} + +void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} + +CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) { + return GetPDFWindow(pPageView, FALSE); +} + +void CFFL_FormFiller::TimerProc() {} + +IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { + return m_pApp->GetSysHandler(); +} + +void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, + FX_BOOL bDestroyPDFWindow) { + m_bValid = FALSE; + + FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); + InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); + + if (bDestroyPDFWindow) + DestroyPDFWindow(pPageView); +} + +void CFFL_FormFiller::InvalidateRect(double left, + double top, + double right, + double bottom) { + UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); + m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); +} + +CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) + : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(FALSE), m_bMouseDown(FALSE) {} + +CFFL_Button::~CFFL_Button() {} + +void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + m_bMouseIn = TRUE; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); +} + +void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + m_bMouseIn = FALSE; + + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + EndTimer(); + ASSERT(m_pWidget); +} + +FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + CFX_FloatRect rcAnnot = pAnnot->GetRect(); + if (!rcAnnot.Contains(point.x, point.y)) + return FALSE; + + m_bMouseDown = TRUE; + m_bValid = TRUE; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + return TRUE; +} + +FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + CFX_FloatRect rcAnnot = pAnnot->GetRect(); + if (!rcAnnot.Contains(point.x, point.y)) + return FALSE; + + m_bMouseDown = FALSE; + m_pWidget->GetPDFPage(); + + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + return TRUE; +} + +FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(m_pApp); + + return TRUE; +} + +void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + ASSERT(pPageView); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDF_FormControl* pCtrl = pWidget->GetFormControl(); + CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); + + if (eHM != CPDF_FormControl::Push) { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + return; + } + + if (m_bMouseDown) { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } else if (m_bMouseIn) { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, + NULL); + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } else { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } +} + +void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); +} diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h new file mode 100644 index 0000000000..b7d8a9dad6 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_formfiller.h @@ -0,0 +1,203 @@ +// 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_FORMFILLER_H_ +#define FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ + +#include + +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/fsdk_baseform.h" + +class CPDFDoc_Environment; +class CPDFSDK_Annot; +class CPDFSDK_PageView; +class CPDFSDK_Widget; + +class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { + public: + CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); + ~CFFL_FormFiller() override; + + 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, + FX_DWORD dwFlags); + virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags); + + 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); + virtual void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); + + virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + short zDelta, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + + virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags); + virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags); + + void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); + void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); + + // CPWL_TimerHandler + void TimerProc() override; + IFX_SystemHandler* GetSystemHandler() const override; + + // IPWL_Provider + CFX_Matrix GetWindowMatrix(void* pAttachedData) override; + CFX_WideString LoadPopupMenuString(int nIndex) override; + + virtual void GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa); + virtual void SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa); + virtual FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew); + + virtual void SaveState(CPDFSDK_PageView* pPageView); + virtual void RestoreState(CPDFSDK_PageView* pPageView); + + virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue); + + CFX_Matrix GetCurMatrix(); + + CFX_FloatRect FFLtoPWL(const CFX_FloatRect& rect); + CFX_FloatRect PWLtoFFL(const CFX_FloatRect& rect); + CFX_FloatPoint FFLtoPWL(const CFX_FloatPoint& point); + CFX_FloatPoint PWLtoFFL(const CFX_FloatPoint& point); + + CFX_FloatPoint WndtoPWL(CPDFSDK_PageView* pPageView, + const CFX_FloatPoint& pt); + CFX_FloatRect FFLtoWnd(CPDFSDK_PageView* pPageView, + const CFX_FloatRect& rect); + + void SetWindowRect(CPDFSDK_PageView* pPageView, + const CFX_FloatRect& rcWindow); + CFX_FloatRect GetWindowRect(CPDFSDK_PageView* pPageView); + + FX_BOOL CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag); + virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView); + virtual void SaveData(CPDFSDK_PageView* pPageView); + +#ifdef PDF_ENABLE_XFA + virtual FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView); +#endif // PDF_ENABLE_XFA + + CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew); + void DestroyPDFWindow(CPDFSDK_PageView* pPageView); + void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow); + + virtual PWL_CREATEPARAM GetCreateParam(); + virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) = 0; + virtual CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView); + + FX_BOOL IsValid() const; + CFX_FloatRect GetPDFWindowRect() const; + + CPDFSDK_PageView* GetCurPageView(); + void SetChangeMark(); + + virtual void InvalidateRect(double left, + double top, + double right, + double bottom); + CPDFDoc_Environment* GetApp() { return m_pApp; } + CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; } + + protected: + using CFFL_PageView2PDFWindow = std::map; + + CPDFDoc_Environment* m_pApp; + CPDFSDK_Widget* m_pWidget; + CPDFSDK_Annot* m_pAnnot; + + FX_BOOL m_bValid; + CFFL_PageView2PDFWindow m_Maps; + CFX_FloatPoint m_ptOldPos; +}; + +class CFFL_Button : public CFFL_FormFiller { + public: + CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); + ~CFFL_Button() override; + + // CFFL_FormFiller + void OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) override; + void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; + FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) override; + void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) override; + void OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) override; + + protected: + FX_BOOL m_bMouseIn; + FX_BOOL m_bMouseDown; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp new file mode 100644 index 0000000000..09d10996a0 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_iformfiller.cpp @@ -0,0 +1,1016 @@ +// 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 "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/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_Utils.h" + +#define FFL_MAXLISTBOXHEIGHT 140.0f + +CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) + : m_pApp(pApp), m_bNotifying(FALSE) {} + +CFFL_IFormFiller::~CFFL_IFormFiller() { + for (auto& it : m_Maps) + delete it.second; + m_Maps.clear(); +} + +FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_FloatPoint point) { + CFX_FloatRect rc = pAnnot->GetRect(); + if (rc.Contains(point.x, point.y)) + return TRUE; + return FALSE; +} + +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 rcAnnot; + pPDFAnnot->GetRect(rcAnnot); + + CFX_FloatRect rcWin = CPWL_Utils::InflateRect(rcAnnot, 1); + return rcWin.GetOutterRect(); +} + +void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + ASSERT(pPageView); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + + if (IsVisible(pWidget)) { + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + if (pFormFiller->IsValid()) { + pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); + pAnnot->GetPDFPage(); + + CPDFSDK_Document* pDocument = m_pApp->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, + dwFlags); + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + + 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, + FX_UINT nFlag) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_UINT nFlag) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlags); + fa.bShift = m_pApp->FFI_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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDFSDK_Document* pDocument = m_pApp->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, + FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, + FX_UINT nFlags, + short zDelta, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, + FX_UINT nKeyCode, + FX_UINT nFlags) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); + + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) { + return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); + } + + return FALSE; +} + +FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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, FX_UINT nFlag) { + if (!pAnnot) + return FALSE; + + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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* pFormFiller = GetFormFiller(pWidget, FALSE)) { + pFormFiller->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, FX_UINT nFlag) { + if (!pAnnot) + return FALSE; + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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; + FX_DWORD 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; + + 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_pApp, pWidget); + break; + case FIELDTYPE_CHECKBOX: + pFormFiller = new CFFL_CheckBox(m_pApp, pWidget); + break; + case FIELDTYPE_RADIOBUTTON: + pFormFiller = new CFFL_RadioButton(m_pApp, pWidget); + break; + case FIELDTYPE_TEXTFIELD: + pFormFiller = new CFFL_TextField(m_pApp, pWidget); + break; + case FIELDTYPE_LISTBOX: + pFormFiller = new CFFL_ListBox(m_pApp, pWidget); + break; + case FIELDTYPE_COMBOBOX: + pFormFiller = new CFFL_ComboBox(m_pApp, pWidget); + break; + case FIELDTYPE_UNKNOWN: + default: + pFormFiller = nullptr; + break; + } + + if (!pFormFiller) + return nullptr; + + m_Maps[pAnnot] = 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; + + delete it->second; + 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, + FX_DWORD nFlag) { + if (!m_bNotifying) { + if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { + m_bNotifying = TRUE; + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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); + + PDFSDK_FieldAction faOld = fa; + 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, + FX_DWORD nFlag) { + if (!m_bNotifying) { + if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { + m_bNotifying = TRUE; + pWidget->ClearAppModified(); + + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag); + fa.bKeyDown = TRUE; + fa.bRC = TRUE; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE); + pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); + pFormFiller->SaveState(pPageView); + + PDFSDK_FieldAction faOld = fa; + 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, + FX_DWORD nFlag) { + if (!m_bNotifying) { + ASSERT(pWidget); + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)pDocument->GetInterForm(); + pInterForm->OnCalculate(pWidget->GetFormField()); + + m_bNotifying = FALSE; + } +} + +void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + FX_DWORD nFlag) { + if (!m_bNotifying) { + ASSERT(pWidget); + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)pDocument->GetInterForm(); + + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = + pInterForm->OnFormat(pWidget->GetFormField(), bFormated); + + if (bExit) + return; + + if (bFormated) { + pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue.c_str(), + 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, + FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_DWORD 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, + FX_DWORD 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, + FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_UINT 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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, + FX_DWORD 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_pApp->FFI_IsCTRLKeyDown(nFlag); + fa.bShift = m_pApp->FFI_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 new file mode 100644 index 0000000000..a966158625 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_iformfiller.h @@ -0,0 +1,186 @@ +// 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 "fpdfsdk/include/fsdk_define.h" +#include "fpdfsdk/include/pdfwindow/PWL_Edit.h" + +class CFFL_FormFiller; +class CPDFDoc_Environment; +class CPDFSDK_Annot; +class CPDFSDK_PageView; +class CPDFSDK_Widget; + +class CFFL_IFormFiller : public IPWL_Filler_Notify { + public: + explicit CFFL_IFormFiller(CPDFDoc_Environment* pApp); + ~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, + FX_DWORD dwFlags); + + 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, + FX_UINT nFlag); + virtual void OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlag); + + virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + short zDelta, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point); + + virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags); + virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags); + + virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); + virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT 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, + FX_DWORD nFlag); + void OnValidate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bRC, + FX_BOOL& bExit, + FX_DWORD nFlag); + + void OnCalculate(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + FX_DWORD nFlag); + void OnFormat(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bExit, + FX_DWORD nFlag); + void OnButtonUp(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + FX_UINT nFlag); +#ifdef PDF_ENABLE_XFA + void OnClick(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + FX_UINT nFlag); + void OnFull(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + FX_UINT nFlag); + void OnPreOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + FX_UINT nFlag); + void OnPostOpen(CPDFSDK_Widget* pWidget, + CPDFSDK_PageView* pPageView, + FX_BOOL& bReset, + FX_BOOL& bExit, + FX_UINT 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, + FX_DWORD nFlag) override; +#ifdef PDF_ENABLE_XFA + void OnPopupPreOpen(void* pPrivateData, + FX_BOOL& bExit, + FX_DWORD nFlag) override; + void OnPopupPostOpen(void* pPrivateData, + FX_BOOL& bExit, + FX_DWORD nFlag) override; + void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, + FX_BOOL bSameField, + FX_BOOL bNext); +#endif // PDF_ENABLE_XFA + void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); + + CPDFDoc_Environment* m_pApp; + 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_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp new file mode 100644 index 0000000000..f5c777743c --- /dev/null +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -0,0 +1,223 @@ +// 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_listbox.h" + +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_iformfiller.h" +#include "fpdfsdk/include/fsdk_common.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_ListBox.h" + +#define FFL_DEFAULTLISTBOXFONTSIZE 12.0f + +CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) + : CFFL_FormFiller(pApp, pWidget), m_pFontMap(NULL) {} + +CFFL_ListBox::~CFFL_ListBox() { + delete m_pFontMap; +} + +PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { + PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); + + FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); + + if (dwFieldFlag & FIELDFLAG_MULTISELECT) { + cp.dwFlags |= PLBS_MULTIPLESEL; + } + + cp.dwFlags |= PWS_VSCROLL; + + if (cp.dwFlags & PWS_AUTOFONTSIZE) + cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE; + + if (!m_pFontMap) + m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); + cp.pFontMap = m_pFontMap; + + return cp; +} + +CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_ListBox* pWnd = new CPWL_ListBox(); + pWnd->AttachFFLData(this); + pWnd->Create(cp); + + CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); + pWnd->SetFillerNotify(pIFormFiller); + + for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) + pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); + + if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { + m_OriginSelections.clear(); + + FX_BOOL bSetCaret = FALSE; + for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { + if (m_pWidget->IsOptionSelected(i)) { + if (!bSetCaret) { + pWnd->SetCaret(i); + bSetCaret = TRUE; + } + pWnd->Select(i); + m_OriginSelections.insert(i); + } + } + } else { + for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { + if (m_pWidget->IsOptionSelected(i)) { + pWnd->Select(i); + break; + } + } + } + + pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex()); + + return pWnd; +} + +FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); +} + +FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) { + CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE); + if (!pListBox) + return FALSE; + + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { + size_t nSelCount = 0; + for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) { + if (pListBox->IsItemSelected(i)) { + if (m_OriginSelections.count(i) == 0) + return TRUE; + + ++nSelCount; + } + } + + return nSelCount != m_OriginSelections.size(); + } + return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); +} + +void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { + ASSERT(m_pWidget); + + if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { + CFX_IntArray aOldSelect, aNewSelect; + + { + for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { + if (m_pWidget->IsOptionSelected(i)) { + aOldSelect.Add(i); + } + } + } + + int32_t nNewTopIndex = pListBox->GetTopVisibleIndex(); + + m_pWidget->ClearSelection(FALSE); + + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { + for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { + if (pListBox->IsItemSelected(i)) { + m_pWidget->SetOptionSelection(i, TRUE, FALSE); + aNewSelect.Add(i); + } + } + } else { + m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE); + aNewSelect.Add(pListBox->GetCurSel()); + } + + m_pWidget->SetTopVisibleIndex(nNewTopIndex); + m_pWidget->ResetFieldAppearance(TRUE); + m_pWidget->UpdateField(); + SetChangeMark(); + } +} + +void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) { + switch (type) { + case CPDF_AAction::Validate: + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { + fa.sValue = L""; + } else { + if (CPWL_ListBox* pListBox = + (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { + int32_t nCurSel = pListBox->GetCurSel(); + if (nCurSel >= 0) + fa.sValue = m_pWidget->GetOptionLabel(nCurSel); + } + } + break; + case CPDF_AAction::LoseFocus: + case CPDF_AAction::GetFocus: + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { + fa.sValue = L""; + } else { + int32_t nCurSel = m_pWidget->GetSelectedIndex(0); + if (nCurSel >= 0) + fa.sValue = m_pWidget->GetOptionLabel(nCurSel); + } + break; + default: + break; + } +} + +void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) {} + +void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) { + ASSERT(pPageView); + + if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { + for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { + if (pListBox->IsItemSelected(i)) { + m_State.Add(i); + } + } + } +} + +void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView) { + if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { + for (int i = 0, sz = m_State.GetSize(); i < sz; i++) + pListBox->Select(m_State[i]); + } +} + +CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) { + if (bRestoreValue) + SaveState(pPageView); + + DestroyPDFWindow(pPageView); + + CPWL_Wnd* pRet = NULL; + + if (bRestoreValue) { + RestoreState(pPageView); + pRet = GetPDFWindow(pPageView, FALSE); + } else { + pRet = GetPDFWindow(pPageView, TRUE); + } + + m_pWidget->UpdateField(); + + return pRet; +} diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h new file mode 100644 index 0000000000..43fbab6642 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_listbox.h @@ -0,0 +1,45 @@ +// 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_LISTBOX_H_ +#define FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_ + +#include + +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CBA_FontMap; + +class CFFL_ListBox : public CFFL_FormFiller { + public: + CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); + ~CFFL_ListBox() override; + + // CFFL_FormFiller + PWL_CREATEPARAM GetCreateParam() override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; + void SaveData(CPDFSDK_PageView* pPageView) override; + void GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) override; + void SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) override; + void SaveState(CPDFSDK_PageView* pPageView) override; + void RestoreState(CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) override; + + private: + CBA_FontMap* m_pFontMap; + std::set m_OriginSelections; + CFX_ArrayTemplate m_State; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_ diff --git a/fpdfsdk/formfiller/cffl_pushbutton.cpp b/fpdfsdk/formfiller/cffl_pushbutton.cpp new file mode 100644 index 0000000000..9a90f0aca2 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_pushbutton.cpp @@ -0,0 +1,38 @@ +// 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_pushbutton.h" + +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" + +CFFL_PushButton::CFFL_PushButton(CPDFDoc_Environment* pApp, + CPDFSDK_Annot* pAnnot) + : CFFL_Button(pApp, pAnnot) {} + +CFFL_PushButton::~CFFL_PushButton() {} + +CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_PushButton* pWnd = new CPWL_PushButton(); + pWnd->Create(cp); + + return pWnd; +} + +FX_BOOL CFFL_PushButton::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); +} + +void CFFL_PushButton::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) { + CFFL_Button::OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); +} diff --git a/fpdfsdk/formfiller/cffl_pushbutton.h b/fpdfsdk/formfiller/cffl_pushbutton.h new file mode 100644 index 0000000000..0d9d82ea0a --- /dev/null +++ b/fpdfsdk/formfiller/cffl_pushbutton.h @@ -0,0 +1,28 @@ +// 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_PUSHBUTTON_H_ +#define FPDFSDK_FORMFILLER_CFFL_PUSHBUTTON_H_ + +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CFFL_PushButton : public CFFL_Button { + public: + CFFL_PushButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); + ~CFFL_PushButton() override; + + // CFFL_Button + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device, + FX_DWORD dwFlags) override; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_PUSHBUTTON_H_ diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp new file mode 100644 index 0000000000..08263601bb --- /dev/null +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -0,0 +1,121 @@ +// 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_radiobutton.h" + +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/include/pdfwindow/PWL_SpecialButton.h" + +CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, + CPDFSDK_Annot* pWidget) + : CFFL_Button(pApp, pWidget) {} + +CFFL_RadioButton::~CFFL_RadioButton() {} + +CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_RadioButton* pWnd = new CPWL_RadioButton(); + pWnd->Create(cp); + + pWnd->SetCheck(m_pWidget->IsChecked()); + + return pWnd; +} + +FX_BOOL CFFL_RadioButton::OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags) { + switch (nKeyCode) { + case FWL_VKEY_Return: + case FWL_VKEY_Space: + return TRUE; + default: + return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); + } +} + +FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + switch (nChar) { + case FWL_VKEY_Return: + case FWL_VKEY_Space: { + CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + ASSERT(pPageView); + + FX_BOOL bReset = FALSE; + FX_BOOL bExit = FALSE; + + pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit, nFlags); + + if (bReset) + return TRUE; + if (bExit) + return TRUE; + + CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); + + if (CPWL_RadioButton* pWnd = + (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE)) + pWnd->SetCheck(TRUE); + CommitData(pPageView, nFlags); + return TRUE; + } + default: + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); + } +} + +FX_BOOL CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) { + CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); + + if (IsValid()) { + if (CPWL_RadioButton* pWnd = + (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE)) + pWnd->SetCheck(TRUE); + + if (!CommitData(pPageView, nFlags)) + return FALSE; + } + + return TRUE; +} + +FX_BOOL CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView) { + if (CPWL_RadioButton* pWnd = + (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE)) { + return pWnd->IsChecked() != m_pWidget->IsChecked(); + } + + return FALSE; +} + +void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) { + if (CPWL_RadioButton* pWnd = + (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE)) { + bool bNewChecked = pWnd->IsChecked(); + + if (bNewChecked) { + CPDF_FormField* pField = m_pWidget->GetFormField(); + for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { + if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { + if (pCtrl->IsChecked()) { + break; + } + } + } + } + + m_pWidget->SetCheck(bNewChecked, false); + m_pWidget->UpdateField(); + SetChangeMark(); + } +} diff --git a/fpdfsdk/formfiller/cffl_radiobutton.h b/fpdfsdk/formfiller/cffl_radiobutton.h new file mode 100644 index 0000000000..f008d1b40f --- /dev/null +++ b/fpdfsdk/formfiller/cffl_radiobutton.h @@ -0,0 +1,32 @@ +// 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_RADIOBUTTON_H_ +#define FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_ + +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CFFL_RadioButton : public CFFL_Button { + public: + CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); + ~CFFL_RadioButton() override; + + // CFFL_Button + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, + FX_UINT nKeyCode, + FX_UINT nFlags) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + FX_UINT nFlags, + const CFX_FloatPoint& point) override; + FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; + void SaveData(CPDFSDK_PageView* pPageView) override; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_ diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp new file mode 100644 index 0000000000..7399651234 --- /dev/null +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -0,0 +1,292 @@ +// 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_textfield.h" + +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/include/fsdk_common.h" +#include "fpdfsdk/include/fsdk_mgr.h" + +CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) + : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { + m_State.nStart = m_State.nEnd = 0; +} + +CFFL_TextField::~CFFL_TextField() { + for (const auto& it : m_Maps) + it.second->InvalidateFocusHandler(this); + delete m_pFontMap; +} + +PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { + PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); + + int nFlags = m_pWidget->GetFieldFlags(); + + if (nFlags & FIELDFLAG_PASSWORD) { + cp.dwFlags |= PES_PASSWORD; + } + + if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) { + } + + if (nFlags & FIELDFLAG_MULTILINE) { + cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP; + + if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { + cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL; + } + } else { + cp.dwFlags |= PES_CENTER; + + if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { + cp.dwFlags |= PES_AUTOSCROLL; + } + } + + if (nFlags & FIELDFLAG_COMB) { + cp.dwFlags |= PES_CHARARRAY; + } + + if (nFlags & FIELDFLAG_RICHTEXT) { + cp.dwFlags |= PES_RICH; + } + + cp.dwFlags |= PES_UNDO; + + switch (m_pWidget->GetAlignment()) { + default: + case BF_ALIGN_LEFT: + cp.dwFlags |= PES_LEFT; + break; + case BF_ALIGN_MIDDLE: + cp.dwFlags |= PES_MIDDLE; + break; + case BF_ALIGN_RIGHT: + cp.dwFlags |= PES_RIGHT; + break; + } + + if (!m_pFontMap) + m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); + cp.pFontMap = m_pFontMap; + cp.pFocusHandler = this; + + return cp; +} + +CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) { + CPWL_Edit* pWnd = new CPWL_Edit(); + pWnd->AttachFFLData(this); + pWnd->Create(cp); + + CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); + pWnd->SetFillerNotify(pIFormFiller); + + int32_t nMaxLen = m_pWidget->GetMaxLen(); + CFX_WideString swValue = m_pWidget->GetValue(); + + if (nMaxLen > 0) { + if (pWnd->HasFlag(PES_CHARARRAY)) { + pWnd->SetCharArray(nMaxLen); + pWnd->SetAlignFormatV(PEAV_CENTER); + } else { + pWnd->SetLimitChar(nMaxLen); + } + } + + pWnd->SetText(swValue.c_str()); + return pWnd; +} + +FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, + FX_UINT nChar, + FX_UINT nFlags) { + switch (nChar) { + case FWL_VKEY_Return: + if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView); + m_bValid = !m_bValid; + CFX_FloatRect rcAnnot = pAnnot->GetRect(); + m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, + rcAnnot.top, rcAnnot.right, rcAnnot.bottom); + + if (m_bValid) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) + pWnd->SetFocus(); + } else { + if (CommitData(pPageView, nFlags)) { + DestroyPDFWindow(pPageView); + return TRUE; + } + return FALSE; + } + } + break; + case FWL_VKEY_Escape: { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView); + EscapeFiller(pPageView, TRUE); + return TRUE; + } + } + + return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); +} + +FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { + if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) + return pEdit->GetText() != m_pWidget->GetValue(); + + return FALSE; +} + +void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + CFX_WideString sOldValue = m_pWidget->GetValue(); + CFX_WideString sNewValue = pWnd->GetText(); + + m_pWidget->SetValue(sNewValue, FALSE); + m_pWidget->ResetFieldAppearance(TRUE); + m_pWidget->UpdateField(); + SetChangeMark(); + } +} + +void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) { + switch (type) { + case CPDF_AAction::KeyStroke: + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + fa.bFieldFull = pWnd->IsTextFull(); + + fa.sValue = pWnd->GetText(); + + if (fa.bFieldFull) { + fa.sChange = L""; + fa.sChangeEx = L""; + } + } + break; + case CPDF_AAction::Validate: + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + fa.sValue = pWnd->GetText(); + } + break; + case CPDF_AAction::LoseFocus: + case CPDF_AAction::GetFocus: + fa.sValue = m_pWidget->GetValue(); + break; + default: + break; + } +} + +void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) { + switch (type) { + case CPDF_AAction::KeyStroke: + if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + pEdit->SetFocus(); + pEdit->SetSel(fa.nSelStart, fa.nSelEnd); + pEdit->ReplaceSel(fa.sChange.c_str()); + } + break; + default: + break; + } +} + +FX_BOOL CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) { + switch (type) { + case CPDF_AAction::KeyStroke: + return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || + faOld.nSelStart != faNew.nSelStart || + faOld.sChange != faNew.sChange; + default: + break; + } + + return FALSE; +} + +void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { + ASSERT(pPageView); + + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + pWnd->GetSel(m_State.nStart, m_State.nEnd); + m_State.sValue = pWnd->GetText(); + } +} + +void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { + ASSERT(pPageView); + + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) { + pWnd->SetText(m_State.sValue.c_str()); + pWnd->SetSel(m_State.nStart, m_State.nEnd); + } +} + +CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) { + if (bRestoreValue) + SaveState(pPageView); + + DestroyPDFWindow(pPageView); + + CPWL_Wnd* pRet = NULL; + + if (bRestoreValue) { + RestoreState(pPageView); + pRet = GetPDFWindow(pPageView, FALSE); + } else { + pRet = GetPDFWindow(pPageView, TRUE); + } + + m_pWidget->UpdateField(); + + return pRet; +} + +#ifdef PDF_ENABLE_XFA +FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { + if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { + return pWnd->IsTextFull(); + } + + return FALSE; +} +#endif // PDF_ENABLE_XFA + +void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { + ASSERT(m_pApp); + if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { + CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; + pEdit->SetCharSet(134); + pEdit->SetCodePage(936); + + pEdit->SetReadyToInput(); + CFX_WideString wsText = pEdit->GetText(); + int nCharacters = wsText.GetLength(); + CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); + unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); + m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, + nCharacters, TRUE); + + pEdit->SetEditNotify(this); + } +} + +void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {} + +void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {} diff --git a/fpdfsdk/formfiller/cffl_textfield.h b/fpdfsdk/formfiller/cffl_textfield.h new file mode 100644 index 0000000000..d7bfc9ee8d --- /dev/null +++ b/fpdfsdk/formfiller/cffl_textfield.h @@ -0,0 +1,69 @@ +// 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_TEXTFIELD_H_ +#define FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_ + +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +#define BF_ALIGN_LEFT 0 +#define BF_ALIGN_MIDDLE 1 +#define BF_ALIGN_RIGHT 2 + +class CBA_FontMap; + +struct FFL_TextFieldState { + int nStart; + int nEnd; + CFX_WideString sValue; +}; + +class CFFL_TextField : public CFFL_FormFiller, + public IPWL_FocusHandler, + public IPWL_Edit_Notify { + public: + CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); + ~CFFL_TextField() override; + + // CFFL_FormFiller: + PWL_CREATEPARAM GetCreateParam() override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, + CPDFSDK_PageView* pPageView) override; + FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; + FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; + void SaveData(CPDFSDK_PageView* pPageView) override; + void GetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + PDFSDK_FieldAction& fa) override; + void SetActionData(CPDFSDK_PageView* pPageView, + CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& fa) override; + FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, + const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) override; + void SaveState(CPDFSDK_PageView* pPageView) override; + void RestoreState(CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, + FX_BOOL bRestoreValue) override; + + // IPWL_FocusHandler: + void OnSetFocus(CPWL_Wnd* pWnd) override; + void OnKillFocus(CPWL_Wnd* pWnd) override; + + // IPWL_Edit_Notify: + void OnAddUndo(CPWL_Edit* pEdit) override; + +#ifdef PDF_ENABLE_XFA + // CFFL_FormFiller: + FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; +#endif // PDF_ENABLE_XFA + + private: + CBA_FontMap* m_pFontMap; + FFL_TextFieldState m_State; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_ diff --git a/fpdfsdk/fsdk_annothandler.cpp b/fpdfsdk/fsdk_annothandler.cpp index 6683284953..aef902c5a4 100644 --- a/fpdfsdk/fsdk_annothandler.cpp +++ b/fpdfsdk/fsdk_annothandler.cpp @@ -11,7 +11,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/include/fsdk_mgr.h" diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp index 38dd1f2d9f..f2d2c88fa4 100644 --- a/fpdfsdk/fsdk_baseform.cpp +++ b/fpdfsdk/fsdk_baseform.cpp @@ -14,7 +14,7 @@ #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_baseannot.h" #include "fpdfsdk/include/fsdk_define.h" diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp index 1ff1ca7ca3..91bafb10de 100644 --- a/fpdfsdk/fsdk_mgr.cpp +++ b/fpdfsdk/fsdk_mgr.cpp @@ -12,7 +12,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/include/javascript/IJavaScript.h" #include "public/fpdf_ext.h" diff --git a/fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h b/fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h deleted file mode 100644 index c3e2e99646..0000000000 --- a/fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h +++ /dev/null @@ -1,46 +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_INCLUDE_FORMFILLER_FFL_CBA_FONTMAP_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_CBA_FONTMAP_H_ - -#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h" - -class CPDF_Dictionary; -class CPDFSDK_Annot; - -class CBA_FontMap : public CPWL_FontMap { - public: - CBA_FontMap(CPDFSDK_Annot* pAnnot, IFX_SystemHandler* pSystemHandler); - ~CBA_FontMap() override; - - void SetDefaultFont(CPDF_Font* pFont, const CFX_ByteString& sFontName); - - void Reset(); - void SetAPType(const CFX_ByteString& sAPType); - - private: - // CPWL_FontMap: - void Initialize() override; - CPDF_Document* GetDocument() override; - CPDF_Font* FindFontSameCharset(CFX_ByteString& sFontAlias, - int32_t nCharset) override; - void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) override; - - CPDF_Font* FindResFontSameCharset(CPDF_Dictionary* pResDict, - CFX_ByteString& sFontAlias, - int32_t nCharset); - CPDF_Font* GetAnnotDefaultFont(CFX_ByteString& csNameTag); - void AddFontToAnnotDict(CPDF_Font* pFont, const CFX_ByteString& sAlias); - - CPDF_Document* m_pDocument; - CPDF_Dictionary* m_pAnnotDict; - CPDF_Font* m_pDefaultFont; - CFX_ByteString m_sDefaultFontName; - CFX_ByteString m_sAPType; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_CBA_FONTMAP_H_ diff --git a/fpdfsdk/include/formfiller/FFL_CheckBox.h b/fpdfsdk/include/formfiller/FFL_CheckBox.h deleted file mode 100644 index 7536871f16..0000000000 --- a/fpdfsdk/include/formfiller/FFL_CheckBox.h +++ /dev/null @@ -1,32 +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_INCLUDE_FORMFILLER_FFL_CHECKBOX_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_CHECKBOX_H_ - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -class CFFL_CheckBox : public CFFL_Button { - public: - CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget); - ~CFFL_CheckBox() override; - - // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; - void SaveData(CPDFSDK_PageView* pPageView) override; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_CHECKBOX_H_ diff --git a/fpdfsdk/include/formfiller/FFL_ComboBox.h b/fpdfsdk/include/formfiller/FFL_ComboBox.h deleted file mode 100644 index a5ef01b0ea..0000000000 --- a/fpdfsdk/include/formfiller/FFL_ComboBox.h +++ /dev/null @@ -1,69 +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_INCLUDE_FORMFILLER_FFL_COMBOBOX_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_COMBOBOX_H_ - -#include "core/include/fxcrt/fx_string.h" -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -class CBA_FontMap; - -struct FFL_ComboBoxState { - int nIndex; - int nStart; - int nEnd; - CFX_WideString sValue; -}; - -class CFFL_ComboBox : public CFFL_FormFiller, - public IPWL_FocusHandler, - public IPWL_Edit_Notify { - public: - CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); - ~CFFL_ComboBox() override; - - // CFFL_FormFiller: - PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; - void SaveData(CPDFSDK_PageView* pPageView) override; - void GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; - void SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) override; - FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) override; - void SaveState(CPDFSDK_PageView* pPageView) override; - void RestoreState(CPDFSDK_PageView* pPageView) override; - CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) override; - - // IPWL_FocusHandler: - void OnSetFocus(CPWL_Wnd* pWnd) override; - void OnKillFocus(CPWL_Wnd* pWnd) override; - - // IPWL_Edit_Notify: - void OnAddUndo(CPWL_Edit* pEdit) override; - -#ifdef PDF_ENABLE_XFA - // CFFL_FormFiller: - FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; -#endif // PDF_ENABLE_XFA - - private: - CFX_WideString GetSelectExportText(); - - CBA_FontMap* m_pFontMap; - FFL_ComboBoxState m_State; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_COMBOBOX_H_ diff --git a/fpdfsdk/include/formfiller/FFL_FormFiller.h b/fpdfsdk/include/formfiller/FFL_FormFiller.h deleted file mode 100644 index f15d40c7a3..0000000000 --- a/fpdfsdk/include/formfiller/FFL_FormFiller.h +++ /dev/null @@ -1,203 +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_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_ - -#include - -#include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" -#include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" -#include "fpdfsdk/include/fsdk_baseform.h" - -class CPDFDoc_Environment; -class CPDFSDK_Annot; -class CPDFSDK_PageView; -class CPDFSDK_Widget; - -class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { - public: - CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); - ~CFFL_FormFiller() override; - - 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, - FX_DWORD dwFlags); - virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags); - - 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); - virtual void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); - - virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - short zDelta, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - - virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags); - virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags); - - void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); - void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); - - // CPWL_TimerHandler - void TimerProc() override; - IFX_SystemHandler* GetSystemHandler() const override; - - // IPWL_Provider - CFX_Matrix GetWindowMatrix(void* pAttachedData) override; - CFX_WideString LoadPopupMenuString(int nIndex) override; - - virtual void GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa); - virtual void SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa); - virtual FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew); - - virtual void SaveState(CPDFSDK_PageView* pPageView); - virtual void RestoreState(CPDFSDK_PageView* pPageView); - - virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue); - - CFX_Matrix GetCurMatrix(); - - CFX_FloatRect FFLtoPWL(const CFX_FloatRect& rect); - CFX_FloatRect PWLtoFFL(const CFX_FloatRect& rect); - CFX_FloatPoint FFLtoPWL(const CFX_FloatPoint& point); - CFX_FloatPoint PWLtoFFL(const CFX_FloatPoint& point); - - CFX_FloatPoint WndtoPWL(CPDFSDK_PageView* pPageView, - const CFX_FloatPoint& pt); - CFX_FloatRect FFLtoWnd(CPDFSDK_PageView* pPageView, - const CFX_FloatRect& rect); - - void SetWindowRect(CPDFSDK_PageView* pPageView, - const CFX_FloatRect& rcWindow); - CFX_FloatRect GetWindowRect(CPDFSDK_PageView* pPageView); - - FX_BOOL CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag); - virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView); - virtual void SaveData(CPDFSDK_PageView* pPageView); - -#ifdef PDF_ENABLE_XFA - virtual FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView); -#endif // PDF_ENABLE_XFA - - CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew); - void DestroyPDFWindow(CPDFSDK_PageView* pPageView); - void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow); - - virtual PWL_CREATEPARAM GetCreateParam(); - virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) = 0; - virtual CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView); - - FX_BOOL IsValid() const; - CFX_FloatRect GetPDFWindowRect() const; - - CPDFSDK_PageView* GetCurPageView(); - void SetChangeMark(); - - virtual void InvalidateRect(double left, - double top, - double right, - double bottom); - CPDFDoc_Environment* GetApp() { return m_pApp; } - CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; } - - protected: - using CFFL_PageView2PDFWindow = std::map; - - CPDFDoc_Environment* m_pApp; - CPDFSDK_Widget* m_pWidget; - CPDFSDK_Annot* m_pAnnot; - - FX_BOOL m_bValid; - CFFL_PageView2PDFWindow m_Maps; - CFX_FloatPoint m_ptOldPos; -}; - -class CFFL_Button : public CFFL_FormFiller { - public: - CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); - ~CFFL_Button() override; - - // CFFL_FormFiller - void OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) override; - void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; - FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) override; - void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) override; - void OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) override; - - protected: - FX_BOOL m_bMouseIn; - FX_BOOL m_bMouseDown; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_ diff --git a/fpdfsdk/include/formfiller/FFL_IFormFiller.h b/fpdfsdk/include/formfiller/FFL_IFormFiller.h deleted file mode 100644 index 95e4cbed17..0000000000 --- a/fpdfsdk/include/formfiller/FFL_IFormFiller.h +++ /dev/null @@ -1,186 +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_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_ - -#include - -#include "fpdfsdk/include/fsdk_define.h" -#include "fpdfsdk/include/pdfwindow/PWL_Edit.h" - -class CFFL_FormFiller; -class CPDFDoc_Environment; -class CPDFSDK_Annot; -class CPDFSDK_PageView; -class CPDFSDK_Widget; - -class CFFL_IFormFiller : public IPWL_Filler_Notify { - public: - explicit CFFL_IFormFiller(CPDFDoc_Environment* pApp); - ~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, - FX_DWORD dwFlags); - - 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, - FX_UINT nFlag); - virtual void OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlag); - - virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - short zDelta, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point); - - virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags); - virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags); - - virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag); - virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT 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, - FX_DWORD nFlag); - void OnValidate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bRC, - FX_BOOL& bExit, - FX_DWORD nFlag); - - void OnCalculate(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - FX_DWORD nFlag); - void OnFormat(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bExit, - FX_DWORD nFlag); - void OnButtonUp(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - FX_UINT nFlag); -#ifdef PDF_ENABLE_XFA - void OnClick(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - FX_UINT nFlag); - void OnFull(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - FX_UINT nFlag); - void OnPreOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - FX_UINT nFlag); - void OnPostOpen(CPDFSDK_Widget* pWidget, - CPDFSDK_PageView* pPageView, - FX_BOOL& bReset, - FX_BOOL& bExit, - FX_UINT 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, - FX_DWORD nFlag) override; -#ifdef PDF_ENABLE_XFA - void OnPopupPreOpen(void* pPrivateData, - FX_BOOL& bExit, - FX_DWORD nFlag) override; - void OnPopupPostOpen(void* pPrivateData, - FX_BOOL& bExit, - FX_DWORD nFlag) override; - void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, - FX_BOOL bSameField, - FX_BOOL bNext); -#endif // PDF_ENABLE_XFA - void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); - - CPDFDoc_Environment* m_pApp; - CFFL_Widget2Filler m_Maps; - FX_BOOL m_bNotifying; -}; - -class CFFL_PrivateData { - public: - CPDFSDK_Widget* pWidget; - CPDFSDK_PageView* pPageView; - int nWidgetAge; - int nValueAge; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_ diff --git a/fpdfsdk/include/formfiller/FFL_ListBox.h b/fpdfsdk/include/formfiller/FFL_ListBox.h deleted file mode 100644 index fe7fed1020..0000000000 --- a/fpdfsdk/include/formfiller/FFL_ListBox.h +++ /dev/null @@ -1,45 +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_INCLUDE_FORMFILLER_FFL_LISTBOX_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_LISTBOX_H_ - -#include - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -class CBA_FontMap; - -class CFFL_ListBox : public CFFL_FormFiller { - public: - CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget); - ~CFFL_ListBox() override; - - // CFFL_FormFiller - PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; - void SaveData(CPDFSDK_PageView* pPageView) override; - void GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; - void SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) override; - void SaveState(CPDFSDK_PageView* pPageView) override; - void RestoreState(CPDFSDK_PageView* pPageView) override; - CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) override; - - private: - CBA_FontMap* m_pFontMap; - std::set m_OriginSelections; - CFX_ArrayTemplate m_State; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_LISTBOX_H_ diff --git a/fpdfsdk/include/formfiller/FFL_PushButton.h b/fpdfsdk/include/formfiller/FFL_PushButton.h deleted file mode 100644 index a4d0236321..0000000000 --- a/fpdfsdk/include/formfiller/FFL_PushButton.h +++ /dev/null @@ -1,28 +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_INCLUDE_FORMFILLER_FFL_PUSHBUTTON_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_PUSHBUTTON_H_ - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -class CFFL_PushButton : public CFFL_Button { - public: - CFFL_PushButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); - ~CFFL_PushButton() override; - - // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - FX_DWORD dwFlags) override; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_PUSHBUTTON_H_ diff --git a/fpdfsdk/include/formfiller/FFL_RadioButton.h b/fpdfsdk/include/formfiller/FFL_RadioButton.h deleted file mode 100644 index dba2798e30..0000000000 --- a/fpdfsdk/include/formfiller/FFL_RadioButton.h +++ /dev/null @@ -1,32 +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_INCLUDE_FORMFILLER_FFL_RADIOBUTTON_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_RADIOBUTTON_H_ - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -class CFFL_RadioButton : public CFFL_Button { - public: - CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); - ~CFFL_RadioButton() override; - - // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, - FX_UINT nKeyCode, - FX_UINT nFlags) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - FX_UINT nFlags, - const CFX_FloatPoint& point) override; - FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; - void SaveData(CPDFSDK_PageView* pPageView) override; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_RADIOBUTTON_H_ diff --git a/fpdfsdk/include/formfiller/FFL_TextField.h b/fpdfsdk/include/formfiller/FFL_TextField.h deleted file mode 100644 index f810d8ff64..0000000000 --- a/fpdfsdk/include/formfiller/FFL_TextField.h +++ /dev/null @@ -1,69 +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_INCLUDE_FORMFILLER_FFL_TEXTFIELD_H_ -#define FPDFSDK_INCLUDE_FORMFILLER_FFL_TEXTFIELD_H_ - -#include "fpdfsdk/include/formfiller/FFL_FormFiller.h" - -#define BF_ALIGN_LEFT 0 -#define BF_ALIGN_MIDDLE 1 -#define BF_ALIGN_RIGHT 2 - -class CBA_FontMap; - -struct FFL_TextFieldState { - int nStart; - int nEnd; - CFX_WideString sValue; -}; - -class CFFL_TextField : public CFFL_FormFiller, - public IPWL_FocusHandler, - public IPWL_Edit_Notify { - public: - CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); - ~CFFL_TextField() override; - - // CFFL_FormFiller: - PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; - FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) override; - FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView) override; - void SaveData(CPDFSDK_PageView* pPageView) override; - void GetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; - void SetActionData(CPDFSDK_PageView* pPageView, - CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) override; - FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) override; - void SaveState(CPDFSDK_PageView* pPageView) override; - void RestoreState(CPDFSDK_PageView* pPageView) override; - CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, - FX_BOOL bRestoreValue) override; - - // IPWL_FocusHandler: - void OnSetFocus(CPWL_Wnd* pWnd) override; - void OnKillFocus(CPWL_Wnd* pWnd) override; - - // IPWL_Edit_Notify: - void OnAddUndo(CPWL_Edit* pEdit) override; - -#ifdef PDF_ENABLE_XFA - // CFFL_FormFiller: - FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; -#endif // PDF_ENABLE_XFA - - private: - CBA_FontMap* m_pFontMap; - FFL_TextFieldState m_State; -}; - -#endif // FPDFSDK_INCLUDE_FORMFILLER_FFL_TEXTFIELD_H_ diff --git a/pdfium.gyp b/pdfium.gyp index fed93b7828..97d42c5914 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -803,24 +803,24 @@ 'target_name': 'formfiller', 'type': 'static_library', 'sources': [ - 'fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h', - 'fpdfsdk/include/formfiller/FFL_CheckBox.h', - 'fpdfsdk/include/formfiller/FFL_ComboBox.h', - 'fpdfsdk/include/formfiller/FFL_FormFiller.h', - 'fpdfsdk/include/formfiller/FFL_IFormFiller.h', - 'fpdfsdk/include/formfiller/FFL_ListBox.h', - 'fpdfsdk/include/formfiller/FFL_PushButton.h', - 'fpdfsdk/include/formfiller/FFL_RadioButton.h', - 'fpdfsdk/include/formfiller/FFL_TextField.h', - 'fpdfsdk/formfiller/FFL_CBA_Fontmap.cpp', - 'fpdfsdk/formfiller/FFL_CheckBox.cpp', - 'fpdfsdk/formfiller/FFL_ComboBox.cpp', - 'fpdfsdk/formfiller/FFL_FormFiller.cpp', - 'fpdfsdk/formfiller/FFL_IFormFiller.cpp', - 'fpdfsdk/formfiller/FFL_ListBox.cpp', - 'fpdfsdk/formfiller/FFL_PushButton.cpp', - 'fpdfsdk/formfiller/FFL_RadioButton.cpp', - 'fpdfsdk/formfiller/FFL_TextField.cpp', + 'fpdfsdk/formfiller/cba_fontmap.cpp', + 'fpdfsdk/formfiller/cba_fontmap.h', + 'fpdfsdk/formfiller/cffl_checkbox.cpp', + 'fpdfsdk/formfiller/cffl_checkbox.h', + 'fpdfsdk/formfiller/cffl_combobox.cpp', + '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_listbox.cpp', + 'fpdfsdk/formfiller/cffl_listbox.h', + 'fpdfsdk/formfiller/cffl_pushbutton.cpp', + 'fpdfsdk/formfiller/cffl_pushbutton.h', + 'fpdfsdk/formfiller/cffl_radiobutton.cpp', + 'fpdfsdk/formfiller/cffl_radiobutton.h', + 'fpdfsdk/formfiller/cffl_textfield.cpp', + 'fpdfsdk/formfiller/cffl_textfield.h', ], }, { -- cgit v1.2.3