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