summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fsdk_baseform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/fsdk_baseform.cpp')
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp122
1 files changed, 41 insertions, 81 deletions
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index c09182e9d7..c86bbc8601 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -4,10 +4,6 @@
// 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"
@@ -17,6 +13,11 @@
#include "fpdfsdk/include/javascript/IJavaScript.h"
#include "third_party/base/nonstd_unique_ptr.h"
+#ifdef PDF_ENABLE_XFA
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
+#endif // PDF_ENABLE_XFA
+
#define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
@@ -28,14 +29,13 @@ 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_nValueAge(0)
+#ifdef PDF_ENABLE_XFA
+ ,
m_hMixXFAWidget(NULL),
- m_pWidgetHandler(NULL) {
-#endif
- ASSERT(m_pInterForm != NULL);
+ m_pWidgetHandler(NULL)
+#endif // PDF_ENABLE_XFA
+{
}
CPDFSDK_Widget::~CPDFSDK_Widget() {}
@@ -253,7 +253,6 @@ FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
}
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();
@@ -303,11 +302,9 @@ void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
}
}
}
-#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();
@@ -320,11 +317,9 @@ void CPDFSDK_Widget::SynchronizeXFAValue() {
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();
@@ -335,14 +330,12 @@ void CPDFSDK_Widget::SynchronizeXFAItems() {
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);
@@ -411,14 +404,12 @@ void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView,
} 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);
@@ -460,10 +451,9 @@ void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView,
} break;
}
}
-#endif // PDF_ENABLE_XFA
}
+#endif // PDF_ENABLE_XFA
-#endif
FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
CPDF_Annot::AppearanceMode mode) {
CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
@@ -516,8 +506,7 @@ FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
int nDocType = pDoc->GetDocType();
if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
return TRUE;
-
-#endif
+#endif // PDF_ENABLE_XFA
return CPDFSDK_BAAnnot::IsAppearanceValid();
}
@@ -565,8 +554,8 @@ CFX_WideString CPDFSDK_Widget::GetName() const {
CPDF_FormField* pFormField = GetFormField();
return pFormField->GetFullName();
}
+#endif // PDF_ENABLE_XFA
-#endif
FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
CPDF_FormControl* pFormCtrl = GetFormControl();
ASSERT(pFormCtrl != NULL);
@@ -618,7 +607,6 @@ 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)) {
@@ -628,17 +616,12 @@ int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
}
}
#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
+CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
@@ -649,9 +632,9 @@ CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
}
}
}
+#else
+CFX_WideString CPDFSDK_Widget::GetValue() const {
#endif // PDF_ENABLE_XFA
-
-#endif
CPDF_FormField* pFormField = GetFormField();
return pFormField->GetValue();
}
@@ -679,7 +662,6 @@ 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)) {
@@ -691,8 +673,6 @@ FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
}
}
#endif // PDF_ENABLE_XFA
-
-#endif
CPDF_FormField* pFormField = GetFormField();
return pFormField->IsItemSelected(nIndex);
}
@@ -704,7 +684,6 @@ 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)) {
@@ -714,8 +693,6 @@ FX_BOOL CPDFSDK_Widget::IsChecked() const {
}
}
#endif // PDF_ENABLE_XFA
-
-#endif
CPDF_FormControl* pFormCtrl = GetFormControl();
return pFormCtrl->IsChecked();
}
@@ -736,11 +713,7 @@ int CPDFSDK_Widget::GetMaxLen() const {
void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) {
CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
CPDF_FormField* pFormField = pFormCtrl->GetField();
- ASSERT(pFormField != NULL);
-
pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
bNotify);
#ifdef PDF_ENABLE_XFA
@@ -748,19 +721,16 @@ void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) {
ResetAppearance(TRUE);
if (!bNotify)
Synchronize(TRUE);
-#endif
+#endif // PDF_ENABLE_XFA
}
void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
pFormField->SetValue(sValue, bNotify);
#ifdef PDF_ENABLE_XFA
-
if (!bNotify)
Synchronize(TRUE);
-#endif
+#endif // PDF_ENABLE_XFA
}
void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
@@ -768,26 +738,20 @@ void CPDFSDK_Widget::SetOptionSelection(int index,
FX_BOOL bSelected,
FX_BOOL bNotify) {
CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
pFormField->SetItemSelection(index, bSelected, bNotify);
#ifdef PDF_ENABLE_XFA
-
if (!bNotify)
Synchronize(TRUE);
-#endif
+#endif // PDF_ENABLE_XFA
}
void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
pFormField->ClearSelection(bNotify);
#ifdef PDF_ENABLE_XFA
-
if (!bNotify)
Synchronize(TRUE);
-#endif
+#endif // PDF_ENABLE_XFA
}
void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
@@ -821,8 +785,8 @@ void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
break;
}
}
+#endif // PDF_ENABLE_XFA
-#endif
void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
FX_BOOL bValueChanged) {
SetAppModified();
@@ -1680,8 +1644,8 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
sValueTmp = GetValue(TRUE);
sValue = sValueTmp;
}
+#endif // PDF_ENABLE_XFA
-#endif
if (nMaxLen > 0) {
if (bCharArray) {
pEdit->SetCharArray(nMaxLen);
@@ -1990,8 +1954,8 @@ 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
+#ifdef PDF_ENABLE_XFA
CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
@@ -2029,10 +1993,9 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
}
}
}
+#endif // PDF_ENABLE_XFA
-#endif
CPDF_Action action = GetAAction(type);
-
if (action && action.GetType() != CPDF_Action::Unknown) {
CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
return pActionHandler->DoAction_Field(action, type, pDocument,
@@ -2131,16 +2094,16 @@ CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const {
return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
rcBBox.top + rcBBox.height);
}
+#endif // PDF_ENABLE_XFA
-#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
+#endif // PDF_ENABLE_XFA
+ m_bCalculate(TRUE),
m_bBusy(FALSE) {
m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE);
m_pInterForm->SetFormNotify(this);
@@ -2156,7 +2119,7 @@ CPDFSDK_InterForm::~CPDFSDK_InterForm() {
m_Map.clear();
#ifdef PDF_ENABLE_XFA
m_XFAMap.RemoveAll();
-#endif
+#endif // PDF_ENABLE_XFA
}
FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
@@ -2262,6 +2225,14 @@ 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(IXFA_Widget* hWidget,
CPDFSDK_XFAWidget* pWidget) {
@@ -2279,16 +2250,6 @@ CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) {
return pWidget;
}
-#endif
-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::XfaEnableCalculate(FX_BOOL bEnabled) {
m_bXfaCalculate = bEnabled;
}
@@ -2302,8 +2263,8 @@ FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() {
void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) {
m_bXfaValidationsEnabled = bEnabled;
}
+#endif // PDF_ENABLE_XFA
-#endif
#ifdef _WIN32
CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
@@ -2362,7 +2323,7 @@ CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
return pRetStream;
}
-#endif
+#endif // _WIN32
void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
ASSERT(m_pDocument != NULL);
@@ -2725,8 +2686,8 @@ void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
}
}
}
+#endif // PDF_ENABLE_XFA
-#endif
CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
const CFX_WideString& sFileExt) {
CFX_WideString sFileName;
@@ -2845,8 +2806,7 @@ int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
#ifdef PDF_ENABLE_XFA
SynchronizeField(pFormField, FALSE);
-
-#endif
+#endif // PDF_ENABLE_XFA
int nType = pFormField->GetFieldType();
if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
OnCalculate(pFormField);