diff options
-rw-r--r-- | core/include/fpdfdoc/fpdf_doc.h | 22 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_baseform.h | 31 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_baseform.cpp | 154 |
3 files changed, 94 insertions, 113 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index a99d10ed58..7ade012bf0 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -1005,23 +1005,21 @@ class CPDF_FormNotify { public: virtual ~CPDF_FormNotify() {} - virtual int BeforeValueChange(const CPDF_FormField* pField, - CFX_WideString& csValue) { + virtual int BeforeValueChange(CPDF_FormField* pField, + const CFX_WideString& csValue) { return 0; } - virtual int AfterValueChange(const CPDF_FormField* pField) { return 0; } - - virtual int BeforeSelectionChange(const CPDF_FormField* pField, - CFX_WideString& csValue) { + virtual void AfterValueChange(CPDF_FormField* pField) {} + virtual int BeforeSelectionChange(CPDF_FormField* pField, + const CFX_WideString& csValue) { return 0; } - virtual int AfterSelectionChange(const CPDF_FormField* pField) { return 0; } - + virtual void AfterSelectionChange(CPDF_FormField* pField) {} virtual void AfterCheckedStatusChange(CPDF_FormField* pField) {} - virtual int BeforeFormReset(const CPDF_InterForm* pForm) { return 0; } - virtual int AfterFormReset(const CPDF_InterForm* pForm) { return 0; } - virtual int BeforeFormImportData(const CPDF_InterForm* pForm) { return 0; } - virtual int AfterFormImportData(const CPDF_InterForm* pForm) { return 0; } + virtual int BeforeFormReset(CPDF_InterForm* pForm) { return 0; } + virtual void AfterFormReset(CPDF_InterForm* pForm) {} + virtual int BeforeFormImportData(CPDF_InterForm* pForm) { return 0; } + virtual void AfterFormImportData(CPDF_InterForm* pForm) {} }; FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h index 6722382a25..28caa7b7b8 100644 --- a/fpdfsdk/include/fsdk_baseform.h +++ b/fpdfsdk/include/fsdk_baseform.h @@ -282,12 +282,9 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { void XfaSetValidationsEnabled(FX_BOOL bEnabled); #endif // PDF_ENABLE_XFA - void OnKeyStrokeCommit(CPDF_FormField* pFormField, - CFX_WideString& csValue, - FX_BOOL& bRC); - void OnValidate(CPDF_FormField* pFormField, - CFX_WideString& csValue, - FX_BOOL& bRC); + FX_BOOL OnKeyStrokeCommit(CPDF_FormField* pFormField, + const CFX_WideString& csValue); + FX_BOOL OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue); void OnCalculate(CPDF_FormField* pFormField = NULL); CFX_WideString OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormated); @@ -320,18 +317,18 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { #endif // PDF_ENABLE_XFA private: - // CPDF_FormNotify - int BeforeValueChange(const CPDF_FormField* pField, - CFX_WideString& csValue) override; - int AfterValueChange(const CPDF_FormField* pField) override; - int BeforeSelectionChange(const CPDF_FormField* pField, - CFX_WideString& csValue) override; - int AfterSelectionChange(const CPDF_FormField* pField) override; + // CPDF_FormNotify: + int BeforeValueChange(CPDF_FormField* pField, + const CFX_WideString& csValue) override; + void AfterValueChange(CPDF_FormField* pField) override; + int BeforeSelectionChange(CPDF_FormField* pField, + const CFX_WideString& csValue) override; + void AfterSelectionChange(CPDF_FormField* pField) override; void AfterCheckedStatusChange(CPDF_FormField* pField) override; - int BeforeFormReset(const CPDF_InterForm* pForm) override; - int AfterFormReset(const CPDF_InterForm* pForm) override; - int BeforeFormImportData(const CPDF_InterForm* pForm) override; - int AfterFormImportData(const CPDF_InterForm* pForm) override; + int BeforeFormReset(CPDF_InterForm* pForm) override; + void AfterFormReset(CPDF_InterForm* pForm) override; + int BeforeFormImportData(CPDF_InterForm* pForm) override; + void AfterFormImportData(CPDF_InterForm* pForm) override; FX_BOOL FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile); diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 78bb20e353..00ab6c2ef0 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -2322,46 +2322,46 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { } } -void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, - CFX_WideString& csValue, - FX_BOOL& bRC) { +FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, + const CFX_WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); - if (aAction && aAction.ActionExist(CPDF_AAction::KeyStroke)) { - CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); - if (action) { - 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); - bRC = fa.bRC; - } - } -} + if (!aAction || !aAction.ActionExist(CPDF_AAction::KeyStroke)) + return TRUE; + + CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); + if (!action) + return TRUE; -void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, - CFX_WideString& csValue, - FX_BOOL& bRC) { + 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 && aAction.ActionExist(CPDF_AAction::Validate)) { - CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); - if (action) { - 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); - bRC = fa.bRC; - } - } + if (!aAction || !aAction.ActionExist(CPDF_AAction::Validate)) + return TRUE; + + CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); + if (!action) + 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) { @@ -2608,67 +2608,55 @@ std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( return fields; } -int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, - CFX_WideString& csValue) { - CPDF_FormField* pFormField = (CPDF_FormField*)pField; - int nType = pFormField->GetFieldType(); - if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { - FX_BOOL bRC = TRUE; - OnKeyStrokeCommit(pFormField, csValue, bRC); - if (bRC) { - OnValidate(pFormField, csValue, bRC); - return bRC ? 1 : -1; - } +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; - } - return 0; + + if (!OnValidate(pField, csValue)) + return -1; + + return 1; } -int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) { - CPDF_FormField* pFormField = (CPDF_FormField*)pField; +void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { #ifdef PDF_ENABLE_XFA - SynchronizeField(pFormField, FALSE); + SynchronizeField(pField, FALSE); #endif // PDF_ENABLE_XFA - int nType = pFormField->GetFieldType(); + int nType = pField->GetFieldType(); if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { - OnCalculate(pFormField); + OnCalculate(pField); FX_BOOL bFormated = FALSE; - CFX_WideString sValue = OnFormat(pFormField, bFormated); - if (bFormated) - ResetFieldAppearance(pFormField, sValue.c_str(), TRUE); - else - ResetFieldAppearance(pFormField, NULL, TRUE); - UpdateField(pFormField); + CFX_WideString sValue = OnFormat(pField, bFormated); + ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); + UpdateField(pField); } - return 0; } -int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, - CFX_WideString& csValue) { - CPDF_FormField* pFormField = (CPDF_FormField*)pField; - if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) +int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, + const CFX_WideString& csValue) { + if (pField->GetFieldType() != FIELDTYPE_LISTBOX) return 0; - FX_BOOL bRC = TRUE; - OnKeyStrokeCommit(pFormField, csValue, bRC); - if (!bRC) + if (!OnKeyStrokeCommit(pField, csValue)) return -1; - OnValidate(pFormField, csValue, bRC); - if (!bRC) + if (!OnValidate(pField, csValue)) return -1; return 1; } -int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField) { - CPDF_FormField* pFormField = (CPDF_FormField*)pField; - if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX) { - OnCalculate(pFormField); - ResetFieldAppearance(pFormField, NULL, TRUE); - UpdateField(pFormField); +void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) { + if (pField->GetFieldType() == FIELDTYPE_LISTBOX) { + OnCalculate(pField); + ResetFieldAppearance(pField, NULL, TRUE); + UpdateField(pField); } - return 0; } void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { @@ -2679,22 +2667,20 @@ void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { } } -int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm) { +int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) { return 0; } -int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm) { +void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) { OnCalculate(nullptr); - return 0; } -int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm) { +int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) { return 0; } -int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm) { +void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) { OnCalculate(nullptr); - return 0; } FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { |