| Index: fpdfsdk/cpdfsdk_widget.cpp
|
| diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/cpdfsdk_widget.cpp
|
| similarity index 61%
|
| rename from fpdfsdk/fsdk_baseform.cpp
|
| rename to fpdfsdk/cpdfsdk_widget.cpp
|
| index 2eda2de85a40419001fc10bc4358a795bb1d589f..3da86aa11f60687337af9f960bffc2b91915531a 100644
|
| --- a/fpdfsdk/fsdk_baseform.cpp
|
| +++ b/fpdfsdk/cpdfsdk_widget.cpp
|
| @@ -1,58 +1,42 @@
|
| -// Copyright 2014 PDFium Authors. All rights reserved.
|
| +// Copyright 2016 PDFium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
|
|
|
| -#include "fpdfsdk/include/fsdk_baseform.h"
|
| +#include "fpdfsdk/include/cpdfsdk_widget.h"
|
|
|
| -#include <algorithm>
|
| -#include <map>
|
| #include <memory>
|
| -#include <vector>
|
|
|
| -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
|
| -#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_dictionary.h"
|
| #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
|
| #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
|
| -#include "core/fpdfdoc/include/cpdf_actionfields.h"
|
| +#include "core/fpdfdoc/include/cpdf_defaultappearance.h"
|
| +#include "core/fpdfdoc/include/cpdf_formcontrol.h"
|
| +#include "core/fpdfdoc/include/cpdf_formfield.h"
|
| +#include "core/fpdfdoc/include/cpdf_iconfit.h"
|
| #include "core/fpdfdoc/include/cpdf_interform.h"
|
| #include "core/fxge/include/cfx_graphstatedata.h"
|
| #include "core/fxge/include/cfx_pathdata.h"
|
| #include "core/fxge/include/cfx_renderdevice.h"
|
| -#include "fpdfsdk/formfiller/cffl_formfiller.h"
|
| +#include "fpdfsdk/formfiller/cba_fontmap.h"
|
| #include "fpdfsdk/fxedit/include/fxet_edit.h"
|
| -#include "fpdfsdk/include/cpdfsdk_annot.h"
|
| -#include "fpdfsdk/include/fsdk_actionhandler.h"
|
| +#include "fpdfsdk/include/cpdfsdk_interform.h"
|
| #include "fpdfsdk/include/fsdk_define.h"
|
| #include "fpdfsdk/include/fsdk_mgr.h"
|
| -#include "fpdfsdk/include/ipdfsdk_annothandler.h"
|
| -#include "fpdfsdk/javascript/ijs_context.h"
|
| -#include "fpdfsdk/javascript/ijs_runtime.h"
|
| +#include "fpdfsdk/pdfwindow/PWL_Edit.h"
|
| #include "fpdfsdk/pdfwindow/PWL_Utils.h"
|
| #include "third_party/base/stl_util.h"
|
|
|
| #ifdef PDF_ENABLE_XFA
|
| #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
|
| -#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h"
|
| #include "xfa/fxfa/include/cxfa_eventparam.h"
|
| +#include "xfa/fxfa/include/fxfa_widget.h"
|
| #include "xfa/fxfa/include/xfa_ffdocview.h"
|
| #include "xfa/fxfa/include/xfa_ffwidget.h"
|
| #include "xfa/fxfa/include/xfa_ffwidgethandler.h"
|
| #endif // PDF_ENABLE_XFA
|
|
|
| -PDFSDK_FieldAction::PDFSDK_FieldAction()
|
| - : bModifier(FALSE),
|
| - bShift(FALSE),
|
| - nCommitKey(0),
|
| - bKeyDown(FALSE),
|
| - nSelEnd(0),
|
| - nSelStart(0),
|
| - bWillCommit(FALSE),
|
| - bFieldFull(FALSE),
|
| - bRC(TRUE) {}
|
| -
|
| CPDFSDK_Widget::Observer::Observer(CPDFSDK_Widget** pWatchedPtr)
|
| : m_pWatchedPtr(pWatchedPtr) {
|
| (*m_pWatchedPtr)->AddObserver(this);
|
| @@ -144,9 +128,8 @@ CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
|
| CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
|
| if (!m_pWidgetHandler) {
|
| - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) {
|
| + if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
|
| m_pWidgetHandler = pDocView->GetWidgetHandler();
|
| - }
|
| }
|
| return m_pWidgetHandler;
|
| }
|
| @@ -207,9 +190,8 @@ static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
|
| case CPDF_AAction::PageInvisible:
|
| break;
|
| case CPDF_AAction::KeyStroke:
|
| - if (!bWillCommit) {
|
| + if (!bWillCommit)
|
| eEventType = XFA_EVENT_Change;
|
| - }
|
| break;
|
| case CPDF_AAction::Validate:
|
| eEventType = XFA_EVENT_Validate;
|
| @@ -230,27 +212,28 @@ static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
|
| }
|
|
|
| FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
|
| - if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
|
| - if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
|
| - XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
| -
|
| - if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| - GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| - if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| - CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
|
| - if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
|
| - return TRUE;
|
| - }
|
| - }
|
| + CXFA_FFWidget* hWidget = GetMixXFAWidget();
|
| + if (!hWidget)
|
| + return FALSE;
|
|
|
| - {
|
| - CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
|
| - return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
|
| - }
|
| + CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
|
| + if (!pXFAWidgetHandler)
|
| + return FALSE;
|
| +
|
| + XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
| +
|
| + CXFA_WidgetAcc* pAcc;
|
| + if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| + GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| + if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| + pAcc = hGroupWidget->GetDataAcc();
|
| + if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
|
| + return TRUE;
|
| }
|
| }
|
|
|
| - return FALSE;
|
| + pAcc = hWidget->GetDataAcc();
|
| + return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
|
| }
|
|
|
| FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
|
| @@ -258,97 +241,105 @@ FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
|
| CPDFSDK_PageView* pPageView) {
|
| CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| - if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
|
| - XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
|
|
| - if (eEventType != XFA_EVENT_Unknown) {
|
| - if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
|
| - CXFA_EventParam param;
|
| - param.m_eType = eEventType;
|
| - param.m_wsChange = data.sChange;
|
| - param.m_iCommitKey = data.nCommitKey;
|
| - param.m_bShift = data.bShift;
|
| - param.m_iSelStart = data.nSelStart;
|
| - param.m_iSelEnd = data.nSelEnd;
|
| - param.m_wsFullText = data.sValue;
|
| - param.m_bKeyDown = data.bKeyDown;
|
| - param.m_bModifier = data.bModifier;
|
| - param.m_wsNewText = data.sValue;
|
| - if (data.nSelEnd > data.nSelStart)
|
| - param.m_wsNewText.Delete(data.nSelStart,
|
| - data.nSelEnd - data.nSelStart);
|
| - for (int i = 0; i < data.sChange.GetLength(); i++)
|
| - param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
|
| - param.m_wsPrevText = data.sValue;
|
| + CXFA_FFWidget* hWidget = GetMixXFAWidget();
|
| + if (!hWidget)
|
| + return FALSE;
|
|
|
| - if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| - GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| - if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| - CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
|
| - param.m_pTarget = pAcc;
|
| - if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) !=
|
| - XFA_EVENTERROR_Success) {
|
| - return FALSE;
|
| - }
|
| - }
|
| - }
|
| - CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
|
| - param.m_pTarget = pAcc;
|
| - int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
| + XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
| + if (eEventType == XFA_EVENT_Unknown)
|
| + return FALSE;
|
|
|
| - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) {
|
| - pDocView->UpdateDocView();
|
| - }
|
| - return nRet == XFA_EVENTERROR_Success;
|
| + CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
|
| + if (!pXFAWidgetHandler)
|
| + return FALSE;
|
| +
|
| + CXFA_EventParam param;
|
| + param.m_eType = eEventType;
|
| + param.m_wsChange = data.sChange;
|
| + param.m_iCommitKey = data.nCommitKey;
|
| + param.m_bShift = data.bShift;
|
| + param.m_iSelStart = data.nSelStart;
|
| + param.m_iSelEnd = data.nSelEnd;
|
| + param.m_wsFullText = data.sValue;
|
| + param.m_bKeyDown = data.bKeyDown;
|
| + param.m_bModifier = data.bModifier;
|
| + param.m_wsNewText = data.sValue;
|
| + if (data.nSelEnd > data.nSelStart)
|
| + param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
|
| +
|
| + for (int i = 0; i < data.sChange.GetLength(); i++)
|
| + param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
|
| + param.m_wsPrevText = data.sValue;
|
| +
|
| + if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| + GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| + if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| + CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
|
| + param.m_pTarget = pAcc;
|
| + if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) !=
|
| + XFA_EVENTERROR_Success) {
|
| + return FALSE;
|
| }
|
| }
|
| }
|
| + CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
|
| + param.m_pTarget = pAcc;
|
| + int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
|
|
| - return FALSE;
|
| + if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
|
| + pDocView->UpdateDocView();
|
| +
|
| + return nRet == XFA_EVENTERROR_Success;
|
| }
|
|
|
| void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
|
| - if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
|
| - CPDF_FormField* pFormField = GetFormField();
|
| - if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
|
| - switch (GetFieldType()) {
|
| - case FIELDTYPE_CHECKBOX:
|
| - case FIELDTYPE_RADIOBUTTON: {
|
| - CPDF_FormControl* pFormCtrl = GetFormControl();
|
| - XFA_CHECKSTATE eCheckState =
|
| - pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
|
| - pWidgetAcc->SetCheckState(eCheckState, true);
|
| - } break;
|
| - case FIELDTYPE_TEXTFIELD:
|
| - pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
|
| - break;
|
| - case FIELDTYPE_LISTBOX: {
|
| - pWidgetAcc->ClearAllSelections();
|
| -
|
| - for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
|
| - int nIndex = pFormField->GetSelectedIndex(i);
|
| - if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
|
| - pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
|
| - }
|
| - } break;
|
| - case FIELDTYPE_COMBOBOX: {
|
| - pWidgetAcc->ClearAllSelections();
|
| -
|
| - for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
|
| - int nIndex = pFormField->GetSelectedIndex(i);
|
| - if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
|
| - pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
|
| - }
|
| - }
|
| + CXFA_FFWidget* hWidget = GetMixXFAWidget();
|
| + if (!hWidget)
|
| + return;
|
| +
|
| + CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
|
| + if (!pWidgetAcc)
|
| + return;
|
|
|
| - pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
|
| - break;
|
| + CPDF_FormField* pFormField = GetFormField();
|
| + switch (GetFieldType()) {
|
| + case FIELDTYPE_CHECKBOX:
|
| + case FIELDTYPE_RADIOBUTTON: {
|
| + CPDF_FormControl* pFormCtrl = GetFormControl();
|
| + XFA_CHECKSTATE eCheckState =
|
| + pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
|
| + pWidgetAcc->SetCheckState(eCheckState, true);
|
| + break;
|
| + }
|
| + case FIELDTYPE_TEXTFIELD:
|
| + pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
|
| + break;
|
| + case FIELDTYPE_LISTBOX: {
|
| + pWidgetAcc->ClearAllSelections();
|
| +
|
| + for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
|
| + int nIndex = pFormField->GetSelectedIndex(i);
|
| + if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
|
| + pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
|
| }
|
| + break;
|
| + }
|
| + case FIELDTYPE_COMBOBOX: {
|
| + pWidgetAcc->ClearAllSelections();
|
|
|
| - if (bSynchronizeElse)
|
| - pWidgetAcc->ProcessValueChanged();
|
| + for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
|
| + int nIndex = pFormField->GetSelectedIndex(i);
|
| + if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
|
| + pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
|
| + }
|
| + pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
|
| + break;
|
| }
|
| }
|
| +
|
| + if (bSynchronizeElse)
|
| + pWidgetAcc->ProcessValueChanged();
|
| }
|
|
|
| void CPDFSDK_Widget::SynchronizeXFAValue() {
|
| @@ -393,7 +384,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
|
| pFormField->GetControlIndex(pFormControl),
|
| pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| case FIELDTYPE_RADIOBUTTON: {
|
| // TODO(weili): Check whether we need to handle checkbox and radio
|
| // button differently, otherwise, merge these two cases.
|
| @@ -402,14 +394,16 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
|
| pFormField->GetControlIndex(pFormControl),
|
| pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| case FIELDTYPE_TEXTFIELD: {
|
| if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
|
| CFX_WideString sValue;
|
| pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
|
| pFormField->SetValue(sValue, TRUE);
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| case FIELDTYPE_LISTBOX: {
|
| pFormField->ClearSelection(FALSE);
|
|
|
| @@ -422,7 +416,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
|
| }
|
| }
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| case FIELDTYPE_COMBOBOX: {
|
| pFormField->ClearSelection(FALSE);
|
|
|
| @@ -439,7 +434,8 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
|
| pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
|
| pFormField->SetValue(sValue, TRUE);
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| }
|
| }
|
|
|
| @@ -462,7 +458,8 @@ void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
|
| pFormField->InsertOption(swText, i, TRUE);
|
| }
|
| }
|
| - } break;
|
| + break;
|
| + }
|
| case FIELDTYPE_COMBOBOX: {
|
| pFormField->ClearSelection(FALSE);
|
| pFormField->ClearOptions(FALSE);
|
| @@ -477,7 +474,8 @@ void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
|
| }
|
|
|
| pFormField->SetValue(L"", TRUE);
|
| - } break;
|
| + break;
|
| + }
|
| }
|
| }
|
| #endif // PDF_ENABLE_XFA
|
| @@ -602,16 +600,15 @@ FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
|
| FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
|
| CPDF_FormControl* pFormCtrl = GetFormControl();
|
| CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
|
| - if (da.HasColor()) {
|
| - FX_ARGB argb;
|
| - int iColorType = COLORTYPE_TRANSPARENT;
|
| - da.GetColor(argb, iColorType);
|
| - color = FX_ARGBTOCOLORREF(argb);
|
| + if (!da.HasColor())
|
| + return FALSE;
|
|
|
| - return iColorType != COLORTYPE_TRANSPARENT;
|
| - }
|
| + FX_ARGB argb;
|
| + int iColorType = COLORTYPE_TRANSPARENT;
|
| + da.GetColor(argb, iColorType);
|
| + color = FX_ARGBTOCOLORREF(argb);
|
|
|
| - return FALSE;
|
| + return iColorType != COLORTYPE_TRANSPARENT;
|
| }
|
|
|
| FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
|
| @@ -775,7 +772,8 @@ void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
|
| FX_BOOL bFormated = FALSE;
|
| CFX_WideString sValue = OnFormat(bFormated);
|
| ResetAppearance(bFormated ? sValue.c_str() : nullptr, TRUE);
|
| - } break;
|
| + break;
|
| + }
|
| default:
|
| ResetAppearance(nullptr, FALSE);
|
| break;
|
| @@ -867,30 +865,31 @@ void CPDFSDK_Widget::UpdateField() {
|
| void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
|
| CPDFSDK_PageView* pPageView) {
|
| int nFieldType = GetFieldType();
|
| - if (m_pInterForm->IsNeedHighLight(nFieldType)) {
|
| - CFX_FloatRect rc = GetRect();
|
| - FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
|
| - uint8_t alpha = m_pInterForm->GetHighlightAlpha();
|
| -
|
| - CFX_FloatRect rcDevice;
|
| - ASSERT(m_pInterForm->GetDocument());
|
| - CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
|
| - if (!pEnv)
|
| - return;
|
| - CFX_Matrix page2device;
|
| - pPageView->GetCurrentMatrix(page2device);
|
| - page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
|
| - rcDevice.left, rcDevice.bottom);
|
| - page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
|
| - rcDevice.right, rcDevice.top);
|
| -
|
| - rcDevice.Normalize();
|
| -
|
| - FX_ARGB argb = ArgbEncode((int)alpha, color);
|
| - FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
|
| - (int)rcDevice.bottom);
|
| - pDevice->FillRect(&rcDev, argb);
|
| - }
|
| + if (!m_pInterForm->IsNeedHighLight(nFieldType))
|
| + return;
|
| +
|
| + CFX_FloatRect rc = GetRect();
|
| + FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
|
| + uint8_t alpha = m_pInterForm->GetHighlightAlpha();
|
| +
|
| + CFX_FloatRect rcDevice;
|
| + ASSERT(m_pInterForm->GetDocument());
|
| + CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
|
| + if (!pEnv)
|
| + return;
|
| + CFX_Matrix page2device;
|
| + pPageView->GetCurrentMatrix(page2device);
|
| + page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
|
| + rcDevice.left, rcDevice.bottom);
|
| + page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
|
| + rcDevice.right, rcDevice.top);
|
| +
|
| + rcDevice.Normalize();
|
| +
|
| + FX_ARGB argb = ArgbEncode((int)alpha, color);
|
| + FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
|
| + (int)rcDevice.bottom);
|
| + pDevice->FillRect(&rcDev, argb);
|
| }
|
|
|
| void CPDFSDK_Widget::ResetAppearance_PushButton() {
|
| @@ -976,29 +975,27 @@ void CPDFSDK_Widget::ResetAppearance_PushButton() {
|
| CFX_WideString csWCaption;
|
| CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
|
|
|
| - if (pControl->HasMKEntry("CA")) {
|
| + if (pControl->HasMKEntry("CA"))
|
| csNormalCaption = pControl->GetNormalCaption();
|
| - }
|
| - if (pControl->HasMKEntry("RC")) {
|
| +
|
| + if (pControl->HasMKEntry("RC"))
|
| csRolloverCaption = pControl->GetRolloverCaption();
|
| - }
|
| - if (pControl->HasMKEntry("AC")) {
|
| +
|
| + if (pControl->HasMKEntry("AC"))
|
| csDownCaption = pControl->GetDownCaption();
|
| - }
|
|
|
| CPDF_Stream* pNormalIcon = nullptr;
|
| CPDF_Stream* pRolloverIcon = nullptr;
|
| CPDF_Stream* pDownIcon = nullptr;
|
|
|
| - if (pControl->HasMKEntry("I")) {
|
| + if (pControl->HasMKEntry("I"))
|
| pNormalIcon = pControl->GetNormalIcon();
|
| - }
|
| - if (pControl->HasMKEntry("RI")) {
|
| +
|
| + if (pControl->HasMKEntry("RI"))
|
| pRolloverIcon = pControl->GetRolloverIcon();
|
| - }
|
| - if (pControl->HasMKEntry("IX")) {
|
| +
|
| + if (pControl->HasMKEntry("IX"))
|
| pDownIcon = pControl->GetDownIcon();
|
| - }
|
|
|
| if (pNormalIcon) {
|
| if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
|
| @@ -1737,9 +1734,9 @@ CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
|
|
|
| CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
|
| CPWL_Color crBackground = GetFillPWLColor();
|
| - if (crBackground.nColorType != COLORTYPE_TRANSPARENT) {
|
| + if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
|
| return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
|
| - }
|
| +
|
| return "";
|
| }
|
|
|
| @@ -1912,9 +1909,8 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
|
| param.m_pTarget = pAcc;
|
| int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
|
|
| - if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) {
|
| + if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
|
| pDocView->UpdateDocView();
|
| - }
|
|
|
| if (nRet == XFA_EVENTERROR_Success)
|
| return TRUE;
|
| @@ -1979,895 +1975,14 @@ FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
|
| CPDF_Annot* pAnnot = GetPDFAnnot();
|
| CFX_FloatRect annotRect;
|
| pAnnot->GetRect(annotRect);
|
| - if (annotRect.Contains(pageX, pageY)) {
|
| - if (!IsVisible())
|
| - return FALSE;
|
| -
|
| - int nFieldFlags = GetFieldFlags();
|
| - if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
|
| - return FALSE;
|
| -
|
| - return TRUE;
|
| - }
|
| - return FALSE;
|
| -}
|
| -
|
| -#ifdef PDF_ENABLE_XFA
|
| -CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot,
|
| - CPDFSDK_PageView* pPageView,
|
| - CPDFSDK_InterForm* pInterForm)
|
| - : CPDFSDK_Annot(pPageView),
|
| - m_pInterForm(pInterForm),
|
| - m_hXFAWidget(pAnnot) {}
|
| -
|
| -FX_BOOL CPDFSDK_XFAWidget::IsXFAField() {
|
| - return TRUE;
|
| -}
|
| -
|
| -CXFA_FFWidget* CPDFSDK_XFAWidget::GetXFAWidget() const {
|
| - return m_hXFAWidget;
|
| -}
|
| -
|
| -CFX_ByteString CPDFSDK_XFAWidget::GetType() const {
|
| - return FSDK_XFAWIDGET_TYPENAME;
|
| -}
|
| -
|
| -CFX_ByteString CPDFSDK_XFAWidget::GetSubType() const {
|
| - return "";
|
| -}
|
| -
|
| -CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const {
|
| - CFX_RectF rcBBox;
|
| - GetXFAWidget()->GetRect(rcBBox);
|
| - return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
|
| - rcBBox.top + rcBBox.height);
|
| -}
|
| -#endif // PDF_ENABLE_XFA
|
| -
|
| -CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
|
| - : m_pDocument(pDocument),
|
| - m_pInterForm(new CPDF_InterForm(m_pDocument->GetPDFDocument())),
|
| -#ifdef PDF_ENABLE_XFA
|
| - m_bXfaCalculate(TRUE),
|
| - m_bXfaValidationsEnabled(TRUE),
|
| -#endif // PDF_ENABLE_XFA
|
| - m_bCalculate(TRUE),
|
| - m_bBusy(FALSE) {
|
| - m_pInterForm->SetFormNotify(this);
|
| - for (int i = 0; i < kNumFieldTypes; ++i)
|
| - m_bNeedHightlight[i] = FALSE;
|
| - m_iHighlightAlpha = 0;
|
| -}
|
| -
|
| -CPDFSDK_InterForm::~CPDFSDK_InterForm() {
|
| - m_Map.clear();
|
| -#ifdef PDF_ENABLE_XFA
|
| - m_XFAMap.clear();
|
| -#endif // PDF_ENABLE_XFA
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
|
| - return FALSE;
|
| -}
|
| -
|
| -CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
|
| - FX_BOOL bNext) const {
|
| - std::unique_ptr<CBA_AnnotIterator> pIterator(
|
| - new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
|
| -
|
| - if (bNext) {
|
| - return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
|
| - }
|
| - return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
|
| -}
|
| -
|
| -CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl,
|
| - bool createIfNeeded) const {
|
| - if (!pControl || !m_pInterForm)
|
| - return nullptr;
|
| -
|
| - CPDFSDK_Widget* pWidget = nullptr;
|
| - const auto it = m_Map.find(pControl);
|
| - if (it != m_Map.end())
|
| - pWidget = it->second;
|
| - if (pWidget)
|
| - return pWidget;
|
| - if (!createIfNeeded)
|
| - return nullptr;
|
| -
|
| - CPDF_Dictionary* pControlDict = pControl->GetWidget();
|
| - CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
|
| - CPDFSDK_PageView* pPage = nullptr;
|
| -
|
| - if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) {
|
| - int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
|
| - if (nPageIndex >= 0) {
|
| - pPage = m_pDocument->GetPageView(nPageIndex);
|
| - }
|
| - }
|
| -
|
| - if (!pPage) {
|
| - int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
|
| - if (nPageIndex >= 0) {
|
| - pPage = m_pDocument->GetPageView(nPageIndex);
|
| - }
|
| - }
|
| -
|
| - if (!pPage)
|
| - return nullptr;
|
| -
|
| - return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::GetWidgets(
|
| - const CFX_WideString& sFieldName,
|
| - std::vector<CPDFSDK_Widget*>* widgets) const {
|
| - for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) {
|
| - CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
|
| - ASSERT(pFormField);
|
| - GetWidgets(pFormField, widgets);
|
| - }
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::GetWidgets(
|
| - CPDF_FormField* pField,
|
| - std::vector<CPDFSDK_Widget*>* widgets) const {
|
| - for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
|
| - CPDF_FormControl* pFormCtrl = pField->GetControl(i);
|
| - ASSERT(pFormCtrl);
|
| - CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, true);
|
| - if (pWidget)
|
| - widgets->push_back(pWidget);
|
| - }
|
| -}
|
| -
|
| -int CPDFSDK_InterForm::GetPageIndexByAnnotDict(
|
| - CPDF_Document* pDocument,
|
| - CPDF_Dictionary* pAnnotDict) const {
|
| - ASSERT(pAnnotDict);
|
| -
|
| - for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) {
|
| - if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) {
|
| - if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) {
|
| - for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) {
|
| - CPDF_Object* pDict = pAnnots->GetDirectObjectAt(j);
|
| - if (pAnnotDict == pDict) {
|
| - return i;
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - return -1;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl,
|
| - CPDFSDK_Widget* pWidget) {
|
| - m_Map[pControl] = pWidget;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
|
| - m_Map.erase(pControl);
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
|
| - m_bCalculate = bEnabled;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const {
|
| - return m_bCalculate;
|
| -}
|
| -
|
| -#ifdef PDF_ENABLE_XFA
|
| -void CPDFSDK_InterForm::AddXFAMap(CXFA_FFWidget* hWidget,
|
| - CPDFSDK_XFAWidget* pWidget) {
|
| - ASSERT(hWidget);
|
| - m_XFAMap[hWidget] = pWidget;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::RemoveXFAMap(CXFA_FFWidget* hWidget) {
|
| - ASSERT(hWidget);
|
| - m_XFAMap.erase(hWidget);
|
| -}
|
| -
|
| -CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(CXFA_FFWidget* hWidget) {
|
| - ASSERT(hWidget);
|
| - auto it = m_XFAMap.find(hWidget);
|
| - return it != m_XFAMap.end() ? it->second : nullptr;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) {
|
| - m_bXfaCalculate = bEnabled;
|
| -}
|
| -FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const {
|
| - return m_bXfaCalculate;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() {
|
| - return m_bXfaValidationsEnabled;
|
| -}
|
| -void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) {
|
| - m_bXfaValidationsEnabled = bEnabled;
|
| -}
|
| -#endif // PDF_ENABLE_XFA
|
| -
|
| -void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - ASSERT(pEnv);
|
| - if (!pEnv->IsJSInitiated())
|
| - return;
|
| -
|
| - if (m_bBusy)
|
| - return;
|
| -
|
| - m_bBusy = TRUE;
|
| -
|
| - if (IsCalculateEnabled()) {
|
| - IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
|
| - pRuntime->SetReaderDocument(m_pDocument);
|
| -
|
| - int nSize = m_pInterForm->CountFieldsInCalculationOrder();
|
| - for (int i = 0; i < nSize; i++) {
|
| - if (CPDF_FormField* pField =
|
| - m_pInterForm->GetFieldInCalculationOrder(i)) {
|
| - int nType = pField->GetFieldType();
|
| - if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
|
| - CPDF_AAction aAction = pField->GetAdditionalAction();
|
| - if (aAction.GetDict() &&
|
| - aAction.ActionExist(CPDF_AAction::Calculate)) {
|
| - CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
|
| - if (action.GetDict()) {
|
| - CFX_WideString csJS = action.GetJavaScript();
|
| - if (!csJS.IsEmpty()) {
|
| - IJS_Context* pContext = pRuntime->NewContext();
|
| - CFX_WideString sOldValue = pField->GetValue();
|
| - CFX_WideString sValue = sOldValue;
|
| - FX_BOOL bRC = TRUE;
|
| - pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
|
| -
|
| - CFX_WideString sInfo;
|
| - FX_BOOL bRet = pContext->RunScript(csJS, &sInfo);
|
| - pRuntime->ReleaseContext(pContext);
|
| -
|
| - if (bRet) {
|
| - if (bRC) {
|
| - if (sValue.Compare(sOldValue) != 0)
|
| - pField->SetValue(sValue, TRUE);
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - m_bBusy = FALSE;
|
| -}
|
| -
|
| -CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
|
| - FX_BOOL& bFormated) {
|
| - CFX_WideString sValue = pFormField->GetValue();
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - ASSERT(pEnv);
|
| - if (!pEnv->IsJSInitiated()) {
|
| - bFormated = FALSE;
|
| - return sValue;
|
| - }
|
| -
|
| - IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
|
| - pRuntime->SetReaderDocument(m_pDocument);
|
| -
|
| - if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) {
|
| - if (pFormField->CountSelectedItems() > 0) {
|
| - int index = pFormField->GetSelectedIndex(0);
|
| - if (index >= 0)
|
| - sValue = pFormField->GetOptionLabel(index);
|
| - }
|
| - }
|
| -
|
| - bFormated = FALSE;
|
| -
|
| - CPDF_AAction aAction = pFormField->GetAdditionalAction();
|
| - if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) {
|
| - CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
|
| - if (action.GetDict()) {
|
| - CFX_WideString script = action.GetJavaScript();
|
| - if (!script.IsEmpty()) {
|
| - CFX_WideString Value = sValue;
|
| -
|
| - IJS_Context* pContext = pRuntime->NewContext();
|
| - pContext->OnField_Format(pFormField, Value, TRUE);
|
| - CFX_WideString sInfo;
|
| - FX_BOOL bRet = pContext->RunScript(script, &sInfo);
|
| - pRuntime->ReleaseContext(pContext);
|
| -
|
| - if (bRet) {
|
| - sValue = Value;
|
| - bFormated = TRUE;
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - return sValue;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
|
| - const FX_WCHAR* sValue,
|
| - FX_BOOL bValueChanged) {
|
| - for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
|
| - CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
|
| - ASSERT(pFormCtrl);
|
| - if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false))
|
| - pWidget->ResetAppearance(sValue, bValueChanged);
|
| - }
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
|
| - for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
|
| - CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
|
| - ASSERT(pFormCtrl);
|
| -
|
| - if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
|
| - UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
|
| - CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false);
|
| - FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
|
| -
|
| - pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
|
| - rcBBox.bottom);
|
| - }
|
| - }
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
|
| - const CFX_WideString& csValue) {
|
| - CPDF_AAction aAction = pFormField->GetAdditionalAction();
|
| - if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke))
|
| - return TRUE;
|
| -
|
| - CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
|
| - if (!action.GetDict())
|
| - return TRUE;
|
| -
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
|
| - PDFSDK_FieldAction fa;
|
| - fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
|
| - fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
|
| - fa.sValue = csValue;
|
| - pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
|
| - m_pDocument, pFormField, fa);
|
| - return fa.bRC;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
|
| - const CFX_WideString& csValue) {
|
| - CPDF_AAction aAction = pFormField->GetAdditionalAction();
|
| - if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate))
|
| - return TRUE;
|
| -
|
| - CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
|
| - if (!action.GetDict())
|
| - return TRUE;
|
| -
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
|
| - PDFSDK_FieldAction fa;
|
| - fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
|
| - fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
|
| - fa.sValue = csValue;
|
| - pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate,
|
| - m_pDocument, pFormField, fa);
|
| - return fa.bRC;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) {
|
| - ASSERT(action.GetDict());
|
| -
|
| - CPDF_ActionFields af(&action);
|
| - std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
|
| - std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
|
| -
|
| - bool bHide = action.GetHideStatus();
|
| - FX_BOOL bChanged = FALSE;
|
| -
|
| - for (CPDF_FormField* pField : fields) {
|
| - for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
|
| - CPDF_FormControl* pControl = pField->GetControl(i);
|
| - ASSERT(pControl);
|
| -
|
| - if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) {
|
| - uint32_t nFlags = pWidget->GetFlags();
|
| - nFlags &= ~ANNOTFLAG_INVISIBLE;
|
| - nFlags &= ~ANNOTFLAG_NOVIEW;
|
| - if (bHide)
|
| - nFlags |= ANNOTFLAG_HIDDEN;
|
| - else
|
| - nFlags &= ~ANNOTFLAG_HIDDEN;
|
| - pWidget->SetFlags(nFlags);
|
| - pWidget->GetPageView()->UpdateView(pWidget);
|
| - bChanged = TRUE;
|
| - }
|
| - }
|
| - }
|
| -
|
| - return bChanged;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) {
|
| - CFX_WideString sDestination = action.GetFilePath();
|
| - if (sDestination.IsEmpty())
|
| - return FALSE;
|
| -
|
| - CPDF_Dictionary* pActionDict = action.GetDict();
|
| - if (pActionDict->KeyExist("Fields")) {
|
| - CPDF_ActionFields af(&action);
|
| - uint32_t dwFlags = action.GetFlags();
|
| - std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
|
| - std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
|
| - if (!fields.empty()) {
|
| - bool bIncludeOrExclude = !(dwFlags & 0x01);
|
| - if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
|
| - return FALSE;
|
| -
|
| - return SubmitFields(sDestination, fields, bIncludeOrExclude, false);
|
| - }
|
| - }
|
| - if (m_pInterForm->CheckRequiredFields(nullptr, true))
|
| - return FALSE;
|
| -
|
| - return SubmitForm(sDestination, FALSE);
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::SubmitFields(
|
| - const CFX_WideString& csDestination,
|
| - const std::vector<CPDF_FormField*>& fields,
|
| - bool bIncludeOrExclude,
|
| - bool bUrlEncoded) {
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| -
|
| - CFX_ByteTextBuf textBuf;
|
| - ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
|
| -
|
| - uint8_t* pBuffer = textBuf.GetBuffer();
|
| - FX_STRSIZE nBufSize = textBuf.GetLength();
|
| -
|
| - if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
|
| - return FALSE;
|
| -
|
| - pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
|
| - return TRUE;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
|
| - CFX_WideString csTxtFile) {
|
| - return TRUE;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
|
| - FX_STRSIZE& nBufSize) {
|
| - CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
|
| - if (pFDF) {
|
| - CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF");
|
| - if (!pMainDict)
|
| - return FALSE;
|
| -
|
| - // Get fields
|
| - CPDF_Array* pFields = pMainDict->GetArrayBy("Fields");
|
| - if (!pFields)
|
| - return FALSE;
|
| -
|
| - CFX_ByteTextBuf fdfEncodedData;
|
| - for (uint32_t i = 0; i < pFields->GetCount(); i++) {
|
| - CPDF_Dictionary* pField = pFields->GetDictAt(i);
|
| - if (!pField)
|
| - continue;
|
| - CFX_WideString name;
|
| - name = pField->GetUnicodeTextBy("T");
|
| - CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
|
| - CFX_ByteString csBValue = pField->GetStringBy("V");
|
| - CFX_WideString csWValue = PDF_DecodeText(csBValue);
|
| - CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
|
| -
|
| - fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
|
| - name_b.ReleaseBuffer();
|
| - fdfEncodedData << "=";
|
| - fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength());
|
| - csValue_b.ReleaseBuffer();
|
| - if (i != pFields->GetCount() - 1)
|
| - fdfEncodedData << "&";
|
| - }
|
| -
|
| - nBufSize = fdfEncodedData.GetLength();
|
| - pBuf = FX_Alloc(uint8_t, nBufSize);
|
| - FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
|
| - }
|
| - return TRUE;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
|
| - const std::vector<CPDF_FormField*>& fields,
|
| - bool bIncludeOrExclude,
|
| - CFX_ByteTextBuf& textBuf) {
|
| - std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF(
|
| - m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude));
|
| - return pFDF ? pFDF->WriteBuf(textBuf) : FALSE;
|
| -}
|
| -
|
| -#ifdef PDF_ENABLE_XFA
|
| -void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
|
| - FX_BOOL bSynchronizeElse) {
|
| - for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
|
| - CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
|
| - if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
|
| - pWidget->Synchronize(bSynchronizeElse);
|
| - }
|
| - }
|
| -}
|
| -#endif // PDF_ENABLE_XFA
|
| -
|
| -CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
|
| - const CFX_WideString& sFileExt) {
|
| - CFX_WideString sFileName;
|
| - return L"";
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
|
| - FX_BOOL bUrlEncoded) {
|
| - if (sDestination.IsEmpty())
|
| + if (!annotRect.Contains(pageX, pageY))
|
| return FALSE;
|
|
|
| - if (!m_pDocument || !m_pInterForm)
|
| + if (!IsVisible())
|
| return FALSE;
|
|
|
| - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
|
| - CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
|
| - CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC());
|
| - if (!pFDFDoc)
|
| + if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
|
| return FALSE;
|
|
|
| - CFX_ByteTextBuf FdfBuffer;
|
| - FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
|
| - delete pFDFDoc;
|
| - if (!bRet)
|
| - return FALSE;
|
| -
|
| - uint8_t* pBuffer = FdfBuffer.GetBuffer();
|
| - FX_STRSIZE nBufSize = FdfBuffer.GetLength();
|
| -
|
| - if (bUrlEncoded) {
|
| - if (!FDFToURLEncodedData(pBuffer, nBufSize))
|
| - return FALSE;
|
| - }
|
| -
|
| - pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
|
| -
|
| - if (bUrlEncoded)
|
| - FX_Free(pBuffer);
|
| -
|
| return TRUE;
|
| }
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) {
|
| - CFDF_Document* pFDF =
|
| - m_pInterForm->ExportToFDF(m_pDocument->GetPath().AsStringC());
|
| - if (!pFDF)
|
| - return FALSE;
|
| -
|
| - FX_BOOL bRet = pFDF->WriteBuf(textBuf);
|
| - delete pFDF;
|
| -
|
| - return bRet;
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
|
| - ASSERT(action.GetDict());
|
| -
|
| - CPDF_Dictionary* pActionDict = action.GetDict();
|
| - if (!pActionDict->KeyExist("Fields"))
|
| - return m_pInterForm->ResetForm(true);
|
| -
|
| - CPDF_ActionFields af(&action);
|
| - uint32_t dwFlags = action.GetFlags();
|
| -
|
| - std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
|
| - std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
|
| - return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true);
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) {
|
| - return FALSE;
|
| -}
|
| -
|
| -std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects(
|
| - const std::vector<CPDF_Object*>& objects) const {
|
| - std::vector<CPDF_FormField*> fields;
|
| - for (CPDF_Object* pObject : objects) {
|
| - if (pObject && pObject->IsString()) {
|
| - CFX_WideString csName = pObject->GetUnicodeText();
|
| - CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
|
| - if (pField)
|
| - fields.push_back(pField);
|
| - }
|
| - }
|
| - return fields;
|
| -}
|
| -
|
| -int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField,
|
| - const CFX_WideString& csValue) {
|
| - int nType = pField->GetFieldType();
|
| - if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD)
|
| - return 0;
|
| -
|
| - if (!OnKeyStrokeCommit(pField, csValue))
|
| - return -1;
|
| -
|
| - if (!OnValidate(pField, csValue))
|
| - return -1;
|
| -
|
| - return 1;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) {
|
| -#ifdef PDF_ENABLE_XFA
|
| - SynchronizeField(pField, FALSE);
|
| -#endif // PDF_ENABLE_XFA
|
| - int nType = pField->GetFieldType();
|
| - if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
|
| - OnCalculate(pField);
|
| - FX_BOOL bFormated = FALSE;
|
| - CFX_WideString sValue = OnFormat(pField, bFormated);
|
| - ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE);
|
| - UpdateField(pField);
|
| - }
|
| -}
|
| -
|
| -int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField,
|
| - const CFX_WideString& csValue) {
|
| - if (pField->GetFieldType() != FIELDTYPE_LISTBOX)
|
| - return 0;
|
| -
|
| - if (!OnKeyStrokeCommit(pField, csValue))
|
| - return -1;
|
| -
|
| - if (!OnValidate(pField, csValue))
|
| - return -1;
|
| -
|
| - return 1;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) {
|
| - if (pField->GetFieldType() == FIELDTYPE_LISTBOX) {
|
| - OnCalculate(pField);
|
| - ResetFieldAppearance(pField, nullptr, TRUE);
|
| - UpdateField(pField);
|
| - }
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) {
|
| - int nType = pField->GetFieldType();
|
| - if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) {
|
| - OnCalculate(pField);
|
| - UpdateField(pField);
|
| - }
|
| -}
|
| -
|
| -int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) {
|
| - return 0;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) {
|
| - OnCalculate(nullptr);
|
| -}
|
| -
|
| -int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) {
|
| - return 0;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) {
|
| - OnCalculate(nullptr);
|
| -}
|
| -
|
| -FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) {
|
| - if (nFieldType < 1 || nFieldType > kNumFieldTypes)
|
| - return FALSE;
|
| - return m_bNeedHightlight[nFieldType - 1];
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::RemoveAllHighLight() {
|
| - for (int i = 0; i < kNumFieldTypes; ++i)
|
| - m_bNeedHightlight[i] = FALSE;
|
| -}
|
| -
|
| -void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) {
|
| - if (nFieldType < 0 || nFieldType > kNumFieldTypes)
|
| - return;
|
| - switch (nFieldType) {
|
| - case 0: {
|
| - for (int i = 0; i < kNumFieldTypes; ++i) {
|
| - m_aHighlightColor[i] = clr;
|
| - m_bNeedHightlight[i] = TRUE;
|
| - }
|
| - break;
|
| - }
|
| - default: {
|
| - m_aHighlightColor[nFieldType - 1] = clr;
|
| - m_bNeedHightlight[nFieldType - 1] = TRUE;
|
| - break;
|
| - }
|
| - }
|
| -}
|
| -
|
| -FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) {
|
| - if (nFieldType < 0 || nFieldType > kNumFieldTypes)
|
| - return FXSYS_RGB(255, 255, 255);
|
| - if (nFieldType == 0)
|
| - return m_aHighlightColor[0];
|
| - return m_aHighlightColor[nFieldType - 1];
|
| -}
|
| -
|
| -CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView,
|
| - const CFX_ByteString& sType,
|
| - const CFX_ByteString& sSubType)
|
| - : m_eTabOrder(STRUCTURE),
|
| - m_pPageView(pPageView),
|
| - m_sType(sType),
|
| - m_sSubType(sSubType) {
|
| - CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
|
| - CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs");
|
| - if (sTabs == "R")
|
| - m_eTabOrder = ROW;
|
| - else if (sTabs == "C")
|
| - m_eTabOrder = COLUMN;
|
| -
|
| - GenerateResults();
|
| -}
|
| -
|
| -CBA_AnnotIterator::~CBA_AnnotIterator() {}
|
| -
|
| -CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() {
|
| - return m_Annots.empty() ? nullptr : m_Annots.front();
|
| -}
|
| -
|
| -CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() {
|
| - return m_Annots.empty() ? nullptr : m_Annots.back();
|
| -}
|
| -
|
| -CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) {
|
| - auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
|
| - if (iter == m_Annots.end())
|
| - return nullptr;
|
| - ++iter;
|
| - if (iter == m_Annots.end())
|
| - iter = m_Annots.begin();
|
| - return *iter;
|
| -}
|
| -
|
| -CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
|
| - auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
|
| - if (iter == m_Annots.end())
|
| - return nullptr;
|
| - if (iter == m_Annots.begin())
|
| - iter = m_Annots.end();
|
| - return *(--iter);
|
| -}
|
| -
|
| -// static
|
| -bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1,
|
| - const CPDFSDK_Annot* p2) {
|
| - return GetAnnotRect(p1).left < GetAnnotRect(p2).left;
|
| -}
|
| -
|
| -// static
|
| -bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1,
|
| - const CPDFSDK_Annot* p2) {
|
| - return GetAnnotRect(p1).top > GetAnnotRect(p2).top;
|
| -}
|
| -
|
| -void CBA_AnnotIterator::GenerateResults() {
|
| - switch (m_eTabOrder) {
|
| - case STRUCTURE: {
|
| - for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
|
| - CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
|
| - if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
|
| - m_Annots.push_back(pAnnot);
|
| - }
|
| - } break;
|
| - case ROW: {
|
| - std::vector<CPDFSDK_Annot*> sa;
|
| - for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
|
| - CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
|
| - if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
|
| - sa.push_back(pAnnot);
|
| - }
|
| -
|
| - std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
|
| - while (!sa.empty()) {
|
| - int nLeftTopIndex = -1;
|
| - FX_FLOAT fTop = 0.0f;
|
| - for (int i = sa.size() - 1; i >= 0; i--) {
|
| - CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
|
| - if (rcAnnot.top > fTop) {
|
| - nLeftTopIndex = i;
|
| - fTop = rcAnnot.top;
|
| - }
|
| - }
|
| - if (nLeftTopIndex >= 0) {
|
| - CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
|
| - CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
|
| - m_Annots.push_back(pLeftTopAnnot);
|
| - sa.erase(sa.begin() + nLeftTopIndex);
|
| -
|
| - std::vector<int> aSelect;
|
| - for (size_t i = 0; i < sa.size(); ++i) {
|
| - CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
|
| - FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
|
| - if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
|
| - aSelect.push_back(i);
|
| - }
|
| - for (size_t i = 0; i < aSelect.size(); ++i)
|
| - m_Annots.push_back(sa[aSelect[i]]);
|
| -
|
| - for (int i = aSelect.size() - 1; i >= 0; --i)
|
| - sa.erase(sa.begin() + aSelect[i]);
|
| - }
|
| - }
|
| - } break;
|
| - case COLUMN: {
|
| - std::vector<CPDFSDK_Annot*> sa;
|
| - for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
|
| - CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
|
| - if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
|
| - sa.push_back(pAnnot);
|
| - }
|
| -
|
| - std::sort(sa.begin(), sa.end(), CompareByTopDescending);
|
| - while (!sa.empty()) {
|
| - int nLeftTopIndex = -1;
|
| - FX_FLOAT fLeft = -1.0f;
|
| - for (int i = sa.size() - 1; i >= 0; --i) {
|
| - CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
|
| - if (fLeft < 0) {
|
| - nLeftTopIndex = 0;
|
| - fLeft = rcAnnot.left;
|
| - } else if (rcAnnot.left < fLeft) {
|
| - nLeftTopIndex = i;
|
| - fLeft = rcAnnot.left;
|
| - }
|
| - }
|
| -
|
| - if (nLeftTopIndex >= 0) {
|
| - CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
|
| - CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
|
| - m_Annots.push_back(pLeftTopAnnot);
|
| - sa.erase(sa.begin() + nLeftTopIndex);
|
| -
|
| - std::vector<int> aSelect;
|
| - for (size_t i = 0; i < sa.size(); ++i) {
|
| - CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
|
| - FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
|
| - if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
|
| - aSelect.push_back(i);
|
| - }
|
| - for (size_t i = 0; i < aSelect.size(); ++i)
|
| - m_Annots.push_back(sa[aSelect[i]]);
|
| -
|
| - for (int i = aSelect.size() - 1; i >= 0; --i)
|
| - sa.erase(sa.begin() + aSelect[i]);
|
| - }
|
| - }
|
| - break;
|
| - }
|
| - }
|
| -}
|
| -
|
| -CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
|
| - CFX_FloatRect rcAnnot;
|
| - pAnnot->GetPDFAnnot()->GetRect(rcAnnot);
|
| - return rcAnnot;
|
| -}
|
|
|