| Index: fpdfsdk/src/fsdk_baseform.cpp
|
| diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
|
| index 98836e9465b7ddd1dd675d74c2a106d75457cb83..c09182e9d766c9cf63aba50ee33ee7c626991407 100644
|
| --- a/fpdfsdk/src/fsdk_baseform.cpp
|
| +++ b/fpdfsdk/src/fsdk_baseform.cpp
|
| @@ -4,6 +4,10 @@
|
|
|
| // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +#include "../include/fpdfxfa/fpdfxfa_doc.h"
|
| +#include "../include/fpdfxfa/fpdfxfa_util.h"
|
| +#endif
|
| #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
|
| #include "fpdfsdk/include/fsdk_actionhandler.h"
|
| #include "fpdfsdk/include/fsdk_baseannot.h"
|
| @@ -24,12 +28,442 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
|
| : CPDFSDK_BAAnnot(pAnnot, pPageView),
|
| m_pInterForm(pInterForm),
|
| m_nAppAge(0),
|
| +#ifndef PDF_ENABLE_XFA
|
| m_nValueAge(0) {
|
| +#else
|
| + m_nValueAge(0),
|
| + m_hMixXFAWidget(NULL),
|
| + m_pWidgetHandler(NULL) {
|
| +#endif
|
| ASSERT(m_pInterForm != NULL);
|
| }
|
|
|
| CPDFSDK_Widget::~CPDFSDK_Widget() {}
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const {
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
|
| + if (!m_hMixXFAWidget) {
|
| + if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
|
| + CFX_WideString sName;
|
| + if (this->GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| + sName = this->GetAnnotName();
|
| + if (sName.IsEmpty())
|
| + sName = GetName();
|
| + } else
|
| + sName = GetName();
|
| +
|
| + if (!sName.IsEmpty())
|
| + m_hMixXFAWidget = pDocView->GetWidgetByName(sName);
|
| + }
|
| + }
|
| + return m_hMixXFAWidget;
|
| + }
|
| +
|
| + return NULL;
|
| +}
|
| +
|
| +IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
|
| + if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
|
| + CFX_WideString sName = GetName();
|
| + if (!sName.IsEmpty())
|
| + return pDocView->GetWidgetByName(sName);
|
| + }
|
| + }
|
| +
|
| + return nullptr;
|
| +}
|
| +
|
| +IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
|
| + if (!m_pWidgetHandler) {
|
| + if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
|
| + m_pWidgetHandler = pDocView->GetWidgetHandler();
|
| + }
|
| + }
|
| + return m_pWidgetHandler;
|
| + }
|
| +
|
| + return NULL;
|
| +}
|
| +
|
| +static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
|
| + XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
|
| +
|
| + switch (eXFAAAT) {
|
| + case PDFSDK_XFA_Click:
|
| + eEventType = XFA_EVENT_Click;
|
| + break;
|
| + case PDFSDK_XFA_Full:
|
| + eEventType = XFA_EVENT_Full;
|
| + break;
|
| + case PDFSDK_XFA_PreOpen:
|
| + eEventType = XFA_EVENT_PreOpen;
|
| + break;
|
| + case PDFSDK_XFA_PostOpen:
|
| + eEventType = XFA_EVENT_PostOpen;
|
| + break;
|
| + }
|
| +
|
| + return eEventType;
|
| +}
|
| +
|
| +static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
|
| + FX_BOOL bWillCommit) {
|
| + XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
|
| +
|
| + switch (eAAT) {
|
| + case CPDF_AAction::CursorEnter:
|
| + eEventType = XFA_EVENT_MouseEnter;
|
| + break;
|
| + case CPDF_AAction::CursorExit:
|
| + eEventType = XFA_EVENT_MouseExit;
|
| + break;
|
| + case CPDF_AAction::ButtonDown:
|
| + eEventType = XFA_EVENT_MouseDown;
|
| + break;
|
| + case CPDF_AAction::ButtonUp:
|
| + eEventType = XFA_EVENT_MouseUp;
|
| + break;
|
| + case CPDF_AAction::GetFocus:
|
| + eEventType = XFA_EVENT_Enter;
|
| + break;
|
| + case CPDF_AAction::LoseFocus:
|
| + eEventType = XFA_EVENT_Exit;
|
| + break;
|
| + case CPDF_AAction::PageOpen:
|
| + break;
|
| + case CPDF_AAction::PageClose:
|
| + break;
|
| + case CPDF_AAction::PageVisible:
|
| + break;
|
| + case CPDF_AAction::PageInvisible:
|
| + break;
|
| + case CPDF_AAction::KeyStroke:
|
| + if (!bWillCommit) {
|
| + eEventType = XFA_EVENT_Change;
|
| + }
|
| + break;
|
| + case CPDF_AAction::Validate:
|
| + eEventType = XFA_EVENT_Validate;
|
| + break;
|
| + case CPDF_AAction::OpenPage:
|
| + case CPDF_AAction::ClosePage:
|
| + case CPDF_AAction::Format:
|
| + case CPDF_AAction::Calculate:
|
| + case CPDF_AAction::CloseDocument:
|
| + case CPDF_AAction::SaveDocument:
|
| + case CPDF_AAction::DocumentSaved:
|
| + case CPDF_AAction::PrintDocument:
|
| + case CPDF_AAction::DocumentPrinted:
|
| + break;
|
| + }
|
| +
|
| + return eEventType;
|
| +}
|
| +
|
| +FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
| +
|
| + if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| + GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| + if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
|
| + if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
|
| + return TRUE;
|
| + }
|
| + }
|
| +
|
| + {
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
|
| + return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
|
| + }
|
| + }
|
| + }
|
| +
|
| + return FALSE;
|
| +}
|
| +
|
| +FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
|
| + PDFSDK_FieldAction& data,
|
| + CPDFSDK_PageView* pPageView) {
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
|
| + XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
|
| +
|
| + if (eEventType != XFA_EVENT_Unknown) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->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;
|
| +
|
| + if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
|
| + GetFieldType() == FIELDTYPE_RADIOBUTTON) {
|
| + if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
|
| + param.m_pTarget = pAcc;
|
| + pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
| + }
|
| +
|
| + {
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
|
| + param.m_pTarget = pAcc;
|
| + int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
| + return nRet == XFA_EVENTERROR_Sucess;
|
| + }
|
| + } else {
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
|
| + param.m_pTarget = pAcc;
|
| + int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
| + return nRet == XFA_EVENTERROR_Sucess;
|
| + }
|
| +
|
| + if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
|
| + pDocView->UpdateDocView();
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + return FALSE;
|
| +}
|
| +
|
| +void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + CPDF_FormField* pFormField = GetFormField();
|
| + ASSERT(pFormField != NULL);
|
| +
|
| + if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + switch (GetFieldType()) {
|
| + case FIELDTYPE_CHECKBOX:
|
| + case FIELDTYPE_RADIOBUTTON: {
|
| + CPDF_FormControl* pFormCtrl = GetFormControl();
|
| + ASSERT(pFormCtrl != NULL);
|
| +
|
| + XFA_CHECKSTATE eCheckState =
|
| + pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
|
| + pWidgetAcc->SetCheckState(eCheckState);
|
| + } 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);
|
| + }
|
| + } 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);
|
| + }
|
| + }
|
| +
|
| + pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
|
| + break;
|
| + }
|
| +
|
| + if (bSynchronizeElse)
|
| + pWidgetAcc->ProcessValueChanged();
|
| + }
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +}
|
| +
|
| +void CPDFSDK_Widget::SynchronizeXFAValue() {
|
| +#ifdef PDF_ENABLE_XFA
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
|
| + if (!pXFADocView)
|
| + return;
|
| +
|
| + if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
|
| + if (GetXFAWidgetHandler()) {
|
| + CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
|
| + GetFormControl());
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +}
|
| +
|
| +void CPDFSDK_Widget::SynchronizeXFAItems() {
|
| +#ifdef PDF_ENABLE_XFA
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
|
| + if (!pXFADocView)
|
| + return;
|
| +
|
| + if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
|
| + if (GetXFAWidgetHandler())
|
| + SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +}
|
| +
|
| +void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView,
|
| + IXFA_Widget* hWidget,
|
| + CPDF_FormField* pFormField,
|
| + CPDF_FormControl* pFormControl) {
|
| +#ifdef PDF_ENABLE_XFA
|
| + ASSERT(pXFADocView != NULL);
|
| + ASSERT(hWidget != NULL);
|
| +
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
|
| + ASSERT(pFormField != NULL);
|
| + ASSERT(pFormControl != NULL);
|
| +
|
| + switch (pFormField->GetFieldType()) {
|
| + case FIELDTYPE_CHECKBOX: {
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
|
| +
|
| + pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
|
| + bChecked, TRUE);
|
| + }
|
| + } break;
|
| + case FIELDTYPE_RADIOBUTTON: {
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
|
| +
|
| + pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
|
| + bChecked, TRUE);
|
| + }
|
| + } break;
|
| + case FIELDTYPE_TEXTFIELD: {
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + CFX_WideString sValue;
|
| + pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
|
| + pFormField->SetValue(sValue, TRUE);
|
| + }
|
| + } break;
|
| + case FIELDTYPE_LISTBOX: {
|
| + pFormField->ClearSelection(FALSE);
|
| +
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
|
| + int nIndex = pWidgetAcc->GetSelectedItem(i);
|
| +
|
| + if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
|
| + pFormField->SetItemSelection(nIndex, TRUE, TRUE);
|
| + }
|
| + }
|
| + }
|
| + } break;
|
| + case FIELDTYPE_COMBOBOX: {
|
| + pFormField->ClearSelection(FALSE);
|
| +
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
|
| + int nIndex = pWidgetAcc->GetSelectedItem(i);
|
| +
|
| + if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
|
| + pFormField->SetItemSelection(nIndex, TRUE, TRUE);
|
| + }
|
| + }
|
| +
|
| + CFX_WideString sValue;
|
| + pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
|
| + pFormField->SetValue(sValue, TRUE);
|
| + }
|
| + } break;
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +}
|
| +
|
| +void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView,
|
| + IXFA_Widget* hWidget,
|
| + CPDF_FormField* pFormField,
|
| + CPDF_FormControl* pFormControl) {
|
| +#ifdef PDF_ENABLE_XFA
|
| + ASSERT(pXFADocView != NULL);
|
| + ASSERT(hWidget != NULL);
|
| +
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
|
| + ASSERT(pFormField != NULL);
|
| +
|
| + switch (pFormField->GetFieldType()) {
|
| + case FIELDTYPE_LISTBOX: {
|
| + pFormField->ClearSelection(FALSE);
|
| + pFormField->ClearOptions(TRUE);
|
| +
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
|
| + i++) {
|
| + CFX_WideString swText;
|
| + pWidgetAcc->GetChoiceListItem(swText, i);
|
| +
|
| + pFormField->InsertOption(swText, i, TRUE);
|
| + }
|
| + }
|
| + } break;
|
| + case FIELDTYPE_COMBOBOX: {
|
| + pFormField->ClearSelection(FALSE);
|
| + pFormField->ClearOptions(FALSE);
|
| +
|
| + if (CXFA_WidgetAcc* pWidgetAcc =
|
| + pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
|
| + i++) {
|
| + CFX_WideString swText;
|
| + pWidgetAcc->GetChoiceListItem(swText, i);
|
| +
|
| + pFormField->InsertOption(swText, i, FALSE);
|
| + }
|
| + }
|
| +
|
| + pFormField->SetValue(L"", TRUE);
|
| + } break;
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +}
|
| +
|
| +#endif
|
| FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
|
| CPDF_Annot::AppearanceMode mode) {
|
| CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
|
| @@ -76,6 +510,14 @@ int CPDFSDK_Widget::GetFieldType() const {
|
| }
|
|
|
| FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
|
| +#ifdef PDF_ENABLE_XFA
|
| + CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
|
| + int nDocType = pDoc->GetDocType();
|
| + if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
|
| + return TRUE;
|
| +
|
| +#endif
|
| return CPDFSDK_BAAnnot::IsAppearanceValid();
|
| }
|
|
|
| @@ -118,6 +560,13 @@ int CPDFSDK_Widget::GetRotate() const {
|
| return pCtrl->GetRotation() % 360;
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +CFX_WideString CPDFSDK_Widget::GetName() const {
|
| + CPDF_FormField* pFormField = GetFormField();
|
| + return pFormField->GetFullName();
|
| +}
|
| +
|
| +#endif
|
| FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
|
| CPDF_FormControl* pFormCtrl = GetFormControl();
|
| ASSERT(pFormCtrl != NULL);
|
| @@ -168,11 +617,41 @@ FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
|
| }
|
|
|
| int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
|
| +#ifdef PDF_ENABLE_XFA
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + if (nIndex < pWidgetAcc->CountSelectedItems())
|
| + return pWidgetAcc->GetSelectedItem(nIndex);
|
| + }
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +
|
| +#endif
|
| CPDF_FormField* pFormField = GetFormField();
|
| return pFormField->GetSelectedIndex(nIndex);
|
| }
|
|
|
| +#ifndef PDF_ENABLE_XFA
|
| CFX_WideString CPDFSDK_Widget::GetValue() const {
|
| +#else
|
| +CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + CFX_WideString sValue;
|
| + pWidgetAcc->GetValue(sValue, bDisplay ? XFA_VALUEPICTURE_Display
|
| + : XFA_VALUEPICTURE_Edit);
|
| + return sValue;
|
| + }
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +
|
| +#endif
|
| CPDF_FormField* pFormField = GetFormField();
|
| return pFormField->GetValue();
|
| }
|
| @@ -199,6 +678,21 @@ int CPDFSDK_Widget::CountOptions() const {
|
| }
|
|
|
| FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
|
| +#ifdef PDF_ENABLE_XFA
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
|
| + return pWidgetAcc->GetItemState(nIndex);
|
| +
|
| + return FALSE;
|
| + }
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +
|
| +#endif
|
| CPDF_FormField* pFormField = GetFormField();
|
| return pFormField->IsItemSelected(nIndex);
|
| }
|
| @@ -209,6 +703,19 @@ int CPDFSDK_Widget::GetTopVisibleIndex() const {
|
| }
|
|
|
| FX_BOOL CPDFSDK_Widget::IsChecked() const {
|
| +#ifdef PDF_ENABLE_XFA
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
|
| + if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
|
| + if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
|
| + FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
|
| + return bChecked;
|
| + }
|
| + }
|
| + }
|
| +#endif // PDF_ENABLE_XFA
|
| +
|
| +#endif
|
| CPDF_FormControl* pFormCtrl = GetFormControl();
|
| return pFormCtrl->IsChecked();
|
| }
|
| @@ -236,6 +743,12 @@ void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) {
|
|
|
| pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
|
| bNotify);
|
| +#ifdef PDF_ENABLE_XFA
|
| + if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
|
| + ResetAppearance(TRUE);
|
| + if (!bNotify)
|
| + Synchronize(TRUE);
|
| +#endif
|
| }
|
|
|
| void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
|
| @@ -243,6 +756,11 @@ void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
|
| ASSERT(pFormField != NULL);
|
|
|
| pFormField->SetValue(sValue, bNotify);
|
| +#ifdef PDF_ENABLE_XFA
|
| +
|
| + if (!bNotify)
|
| + Synchronize(TRUE);
|
| +#endif
|
| }
|
|
|
| void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
|
| @@ -253,6 +771,11 @@ void CPDFSDK_Widget::SetOptionSelection(int index,
|
| ASSERT(pFormField != NULL);
|
|
|
| pFormField->SetItemSelection(index, bSelected, bNotify);
|
| +#ifdef PDF_ENABLE_XFA
|
| +
|
| + if (!bNotify)
|
| + Synchronize(TRUE);
|
| +#endif
|
| }
|
|
|
| void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
|
| @@ -260,6 +783,11 @@ void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
|
| ASSERT(pFormField != NULL);
|
|
|
| pFormField->ClearSelection(bNotify);
|
| +#ifdef PDF_ENABLE_XFA
|
| +
|
| + if (!bNotify)
|
| + Synchronize(TRUE);
|
| +#endif
|
| }
|
|
|
| void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
|
| @@ -276,6 +804,25 @@ FX_BOOL CPDFSDK_Widget::IsAppModified() const {
|
| return m_bAppModified;
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
|
| + switch (GetFieldType()) {
|
| + case FIELDTYPE_TEXTFIELD:
|
| + case FIELDTYPE_COMBOBOX: {
|
| + FX_BOOL bFormated = FALSE;
|
| + CFX_WideString sValue = this->OnFormat(bFormated);
|
| + if (bFormated)
|
| + this->ResetAppearance(sValue, TRUE);
|
| + else
|
| + this->ResetAppearance(NULL, TRUE);
|
| + } break;
|
| + default:
|
| + this->ResetAppearance(NULL, FALSE);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +#endif
|
| void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
|
| FX_BOOL bValueChanged) {
|
| SetAppModified();
|
| @@ -1127,6 +1674,14 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
|
| FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
|
| FX_FLOAT fFontSize = GetFontSize();
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| + CFX_WideString sValueTmp;
|
| + if (!sValue && (NULL != this->GetMixXFAWidget())) {
|
| + sValueTmp = GetValue(TRUE);
|
| + sValue = sValueTmp;
|
| + }
|
| +
|
| +#endif
|
| if (nMaxLen > 0) {
|
| if (bCharArray) {
|
| pEdit->SetCharArray(nMaxLen);
|
| @@ -1435,6 +1990,47 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
|
| CPDFSDK_PageView* pPageView) {
|
| CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
|
| CPDFDoc_Environment* pEnv = pDocument->GetEnv();
|
| +#ifdef PDF_ENABLE_XFA
|
| +
|
| + CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
|
| + if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
|
| + XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
|
| +
|
| + if (eEventType != XFA_EVENT_Unknown) {
|
| + if (IXFA_WidgetHandler* 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 = data.sChange.GetLength() - 1; i >= 0; i--)
|
| + param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
|
| + param.m_wsPrevText = data.sValue;
|
| +
|
| + CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
|
| + param.m_pTarget = pAcc;
|
| + int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m);
|
| +
|
| + if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
|
| + pDocView->UpdateDocView();
|
| + }
|
| +
|
| + if (nRet == XFA_EVENTERROR_Sucess)
|
| + return TRUE;
|
| + }
|
| + }
|
| + }
|
| +
|
| +#endif
|
| CPDF_Action action = GetAAction(type);
|
|
|
| if (action && action.GetType() != CPDF_Action::Unknown) {
|
| @@ -1507,10 +2103,44 @@ FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
|
| return FALSE;
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot,
|
| + CPDFSDK_PageView* pPageView,
|
| + CPDFSDK_InterForm* pInterForm)
|
| + : CPDFSDK_Annot(pPageView), m_pInterForm(pInterForm), m_hXFAWidget(pAnnot) {
|
| +}
|
| +
|
| +FX_BOOL CPDFSDK_XFAWidget::IsXFAField() {
|
| + return TRUE;
|
| +}
|
| +
|
| +CFX_ByteString CPDFSDK_XFAWidget::GetType() const {
|
| + return FSDK_XFAWIDGET_TYPENAME;
|
| +}
|
| +
|
| +CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const {
|
| + CPDFSDK_PageView* pPageView = GetPageView();
|
| + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
|
| + CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
|
| + IXFA_DocView* pDocView = pDoc->GetXFADocView();
|
| + IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
|
| +
|
| + CFX_RectF rcBBox;
|
| + pWidgetHandler->GetRect(GetXFAWidget(), rcBBox);
|
| +
|
| + return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
|
| + rcBBox.top + rcBBox.height);
|
| +}
|
| +
|
| +#endif
|
| CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
|
| : m_pDocument(pDocument),
|
| m_pInterForm(NULL),
|
| m_bCalculate(TRUE),
|
| +#ifdef PDF_ENABLE_XFA
|
| + m_bXfaCalculate(TRUE),
|
| + m_bXfaValidationsEnabled(TRUE),
|
| +#endif
|
| m_bBusy(FALSE) {
|
| m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE);
|
| m_pInterForm->SetFormNotify(this);
|
| @@ -1524,6 +2154,9 @@ CPDFSDK_InterForm::~CPDFSDK_InterForm() {
|
| delete m_pInterForm;
|
| m_pInterForm = nullptr;
|
| m_Map.clear();
|
| +#ifdef PDF_ENABLE_XFA
|
| + m_XFAMap.RemoveAll();
|
| +#endif
|
| }
|
|
|
| FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
|
| @@ -1629,6 +2262,24 @@ void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
|
| m_Map.erase(pControl);
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget,
|
| + CPDFSDK_XFAWidget* pWidget) {
|
| + m_XFAMap.SetAt(hWidget, pWidget);
|
| +}
|
| +
|
| +void CPDFSDK_InterForm::RemoveXFAMap(IXFA_Widget* hWidget) {
|
| + m_XFAMap.RemoveKey(hWidget);
|
| +}
|
| +
|
| +CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) {
|
| + CPDFSDK_XFAWidget* pWidget = NULL;
|
| + m_XFAMap.Lookup(hWidget, pWidget);
|
| +
|
| + return pWidget;
|
| +}
|
| +
|
| +#endif
|
| void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
|
| m_bCalculate = bEnabled;
|
| }
|
| @@ -1637,6 +2288,22 @@ FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const {
|
| return m_bCalculate;
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +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
|
| #ifdef _WIN32
|
| CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
|
| CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
|
| @@ -2039,6 +2706,27 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
|
| return pFDF ? pFDF->WriteBuf(textBuf) : FALSE;
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
|
| + FX_BOOL bSynchronizeElse) {
|
| + ASSERT(pFormField != NULL);
|
| +
|
| + int x = 0;
|
| + if (m_FieldSynchronizeMap.Lookup(pFormField, x))
|
| + return;
|
| +
|
| + for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
|
| + CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
|
| + ASSERT(pFormCtrl != NULL);
|
| +
|
| + ASSERT(m_pInterForm != NULL);
|
| + if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
|
| + pWidget->Synchronize(bSynchronizeElse);
|
| + }
|
| + }
|
| +}
|
| +
|
| +#endif
|
| CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
|
| const CFX_WideString& sFileExt) {
|
| CFX_WideString sFileName;
|
| @@ -2155,6 +2843,10 @@ int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField,
|
|
|
| int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
|
| CPDF_FormField* pFormField = (CPDF_FormField*)pField;
|
| +#ifdef PDF_ENABLE_XFA
|
| + SynchronizeField(pFormField, FALSE);
|
| +
|
| +#endif
|
| int nType = pFormField->GetFieldType();
|
| if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
|
| OnCalculate(pFormField);
|
|
|