jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 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 | |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 7 | #ifndef FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ |
| 8 | #define FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <map> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 11 | #include <memory> |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_action.h" |
| 15 | #include "core/fpdfdoc/ipdf_formnotify.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 16 | #include "core/fxcrt/unowned_ptr.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 17 | #include "core/fxge/fx_dib.h" |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_widget.h" |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 19 | #include "third_party/base/optional.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 20 | |
| 21 | class CPDF_Dictionary; |
| 22 | class CPDF_FormControl; |
| 23 | class CPDF_FormField; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 24 | class CPDF_InteractiveForm; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 25 | class CPDF_Object; |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 26 | class CPDFSDK_FormFillEnvironment; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 27 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 28 | class CPDFSDK_InteractiveForm final : public IPDF_FormNotify { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 29 | public: |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 30 | explicit CPDFSDK_InteractiveForm(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
| 31 | ~CPDFSDK_InteractiveForm() override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 32 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 33 | CPDF_InteractiveForm* GetInteractiveForm() const { |
| 34 | return m_pInteractiveForm.get(); |
| 35 | } |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 36 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { |
| 37 | return m_pFormFillEnv.Get(); |
| 38 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 39 | |
dsinclair | c5267c5 | 2016-11-04 15:35:12 -0700 | [diff] [blame] | 40 | CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 41 | void GetWidgets(const WideString& sFieldName, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 42 | std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 43 | void GetWidgets(CPDF_FormField* pField, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 44 | std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 45 | |
| 46 | void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); |
| 47 | void RemoveMap(CPDF_FormControl* pControl); |
| 48 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 49 | void EnableCalculate(bool bEnabled); |
| 50 | bool IsCalculateEnabled() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 51 | |
| 52 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 53 | void XfaEnableCalculate(bool bEnabled); |
| 54 | bool IsXfaCalculateEnabled() const; |
| 55 | bool IsXfaValidationsEnabled(); |
| 56 | void XfaSetValidationsEnabled(bool bEnabled); |
Dan Sinclair | ce047a6 | 2018-01-30 18:15:02 +0000 | [diff] [blame] | 57 | void SynchronizeField(CPDF_FormField* pFormField); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 58 | #endif // PDF_ENABLE_XFA |
| 59 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 60 | bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue); |
| 61 | bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue); |
Tom Sepez | b9c3e27 | 2018-08-14 18:22:06 +0000 | [diff] [blame] | 62 | void OnCalculate(CPDF_FormField* pFormField); |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 63 | Optional<WideString> OnFormat(CPDF_FormField* pFormField); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 64 | |
| 65 | void ResetFieldAppearance(CPDF_FormField* pFormField, |
Lei Zhang | 3b37f6b | 2019-07-29 23:31:26 +0000 | [diff] [blame] | 66 | Optional<WideString> sValue); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 67 | void UpdateField(CPDF_FormField* pFormField); |
| 68 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 69 | bool DoAction_Hide(const CPDF_Action& action); |
| 70 | bool DoAction_SubmitForm(const CPDF_Action& action); |
dan sinclair | 7544a4b | 2018-03-08 15:19:50 +0000 | [diff] [blame] | 71 | void DoAction_ResetForm(const CPDF_Action& action); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 72 | |
| 73 | std::vector<CPDF_FormField*> GetFieldFromObjects( |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 74 | const std::vector<const CPDF_Object*>& objects) const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 75 | bool SubmitFields(const WideString& csDestination, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 76 | const std::vector<CPDF_FormField*>& fields, |
| 77 | bool bIncludeOrExclude, |
| 78 | bool bUrlEncoded); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 79 | bool SubmitForm(const WideString& sDestination, bool bUrlEncoded); |
| 80 | ByteString ExportFormToFDFTextBuf(); |
| 81 | ByteString ExportFieldsToFDFTextBuf( |
Henrique Nakashima | 5c09f4c | 2017-08-04 12:28:52 -0400 | [diff] [blame] | 82 | const std::vector<CPDF_FormField*>& fields, |
| 83 | bool bIncludeOrExclude); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 84 | |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 85 | bool IsNeedHighLight(FormFieldType fieldType) const; |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 86 | void RemoveAllHighLights(); |
| 87 | void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; } |
| 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); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 92 | |
| 93 | private: |
| 94 | // IPDF_FormNotify: |
dan sinclair | 507fb4e | 2018-03-08 15:14:09 +0000 | [diff] [blame] | 95 | bool BeforeValueChange(CPDF_FormField* pField, |
| 96 | const WideString& csValue) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 97 | void AfterValueChange(CPDF_FormField* pField) override; |
dan sinclair | 507fb4e | 2018-03-08 15:14:09 +0000 | [diff] [blame] | 98 | bool BeforeSelectionChange(CPDF_FormField* pField, |
| 99 | const WideString& csValue) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 100 | void AfterSelectionChange(CPDF_FormField* pField) override; |
| 101 | void AfterCheckedStatusChange(CPDF_FormField* pField) override; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 102 | void AfterFormReset(CPDF_InteractiveForm* pForm) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 103 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 104 | int GetPageIndexByAnnotDict(CPDF_Document* pDocument, |
| 105 | CPDF_Dictionary* pAnnotDict) const; |
| 106 | |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 107 | UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 108 | std::unique_ptr<CPDF_InteractiveForm> const m_pInteractiveForm; |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 109 | std::map<CPDF_FormControl*, CPDFSDK_Widget*> m_Map; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 110 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 111 | bool m_bXfaCalculate = true; |
| 112 | bool m_bXfaValidationsEnabled = true; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 113 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 114 | bool m_bCalculate = true; |
| 115 | bool m_bBusy = false; |
Lei Zhang | 461acb2 | 2018-10-10 18:38:03 +0000 | [diff] [blame] | 116 | uint8_t m_HighlightAlpha = 0; |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 117 | FX_COLORREF m_HighlightColor[kFormFieldTypeCount]; |
| 118 | bool m_NeedsHighlight[kFormFieldTypeCount]; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 121 | #endif // FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_ |