1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ 8 #define FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ 9 10 #include <map> 11 #include <memory> 12 #include <vector> 13 14 #include "core/fpdfdoc/cpdf_action.h" 15 #include "core/fpdfdoc/cpdf_interactiveform.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "core/fxge/fx_dib.h" 18 #include "fpdfsdk/cpdfsdk_widget.h" 19 #include "third_party/base/optional.h" 20 21 class CPDF_Dictionary; 22 class CPDF_FormControl; 23 class CPDF_FormField; 24 class CPDF_Object; 25 class CPDFSDK_FormFillEnvironment; 26 27 class CPDFSDK_InteractiveForm final 28 : public CPDF_InteractiveForm::NotifierIface { 29 public: 30 explicit CPDFSDK_InteractiveForm(CPDFSDK_FormFillEnvironment* pFormFillEnv); 31 ~CPDFSDK_InteractiveForm() override; 32 GetInteractiveForm()33 CPDF_InteractiveForm* GetInteractiveForm() const { 34 return m_pInteractiveForm.get(); 35 } GetFormFillEnv()36 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { 37 return m_pFormFillEnv.Get(); 38 } 39 40 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; 41 void GetWidgets(const WideString& sFieldName, 42 std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const; 43 void GetWidgets(CPDF_FormField* pField, 44 std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const; 45 46 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); 47 void RemoveMap(CPDF_FormControl* pControl); 48 49 void EnableCalculate(bool bEnabled); 50 bool IsCalculateEnabled() const; 51 52 #ifdef PDF_ENABLE_XFA 53 void XfaEnableCalculate(bool bEnabled); 54 bool IsXfaCalculateEnabled() const; 55 bool IsXfaValidationsEnabled(); 56 void XfaSetValidationsEnabled(bool bEnabled); 57 void SynchronizeField(CPDF_FormField* pFormField); 58 #endif // PDF_ENABLE_XFA 59 60 bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue); 61 bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue); 62 void OnCalculate(CPDF_FormField* pFormField); 63 Optional<WideString> OnFormat(CPDF_FormField* pFormField); 64 65 void ResetFieldAppearance(CPDF_FormField* pFormField, 66 Optional<WideString> sValue); 67 void UpdateField(CPDF_FormField* pFormField); 68 69 bool DoAction_Hide(const CPDF_Action& action); 70 bool DoAction_SubmitForm(const CPDF_Action& action); 71 void DoAction_ResetForm(const CPDF_Action& action); 72 73 std::vector<CPDF_FormField*> GetFieldFromObjects( 74 const std::vector<const CPDF_Object*>& objects) const; 75 bool SubmitFields(const WideString& csDestination, 76 const std::vector<CPDF_FormField*>& fields, 77 bool bIncludeOrExclude, 78 bool bUrlEncoded); 79 bool SubmitForm(const WideString& sDestination, bool bUrlEncoded); 80 ByteString ExportFormToFDFTextBuf(); 81 ByteString ExportFieldsToFDFTextBuf( 82 const std::vector<CPDF_FormField*>& fields, 83 bool bIncludeOrExclude); 84 85 bool IsNeedHighLight(FormFieldType fieldType) const; 86 void RemoveAllHighLights(); SetHighlightAlpha(uint8_t alpha)87 void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; } GetHighlightAlpha()88 uint8_t GetHighlightAlpha() { return m_HighlightAlpha; } 89 void SetHighlightColor(FX_COLORREF clr, FormFieldType fieldType); 90 void SetAllHighlightColors(FX_COLORREF clr); 91 FX_COLORREF GetHighlightColor(FormFieldType fieldType); 92 93 private: 94 // CPDF_InteractiveForm::NotifierIface: 95 bool BeforeValueChange(CPDF_FormField* pField, 96 const WideString& csValue) override; 97 void AfterValueChange(CPDF_FormField* pField) override; 98 bool BeforeSelectionChange(CPDF_FormField* pField, 99 const WideString& csValue) override; 100 void AfterSelectionChange(CPDF_FormField* pField) override; 101 void AfterCheckedStatusChange(CPDF_FormField* pField) override; 102 void AfterFormReset(CPDF_InteractiveForm* pForm) override; 103 104 int GetPageIndexByAnnotDict(CPDF_Document* pDocument, 105 CPDF_Dictionary* pAnnotDict) const; 106 107 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; 108 std::unique_ptr<CPDF_InteractiveForm> const m_pInteractiveForm; 109 std::map<CPDF_FormControl*, CPDFSDK_Widget*> m_Map; 110 #ifdef PDF_ENABLE_XFA 111 bool m_bXfaCalculate = true; 112 bool m_bXfaValidationsEnabled = true; 113 #endif // PDF_ENABLE_XFA 114 bool m_bCalculate = true; 115 bool m_bBusy = false; 116 uint8_t m_HighlightAlpha = 0; 117 FX_COLORREF m_HighlightColor[kFormFieldTypeCount]; 118 bool m_NeedsHighlight[kFormFieldTypeCount]; 119 }; 120 121 #endif // FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ 122