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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_CPDFSDK_INTERFORM_H_ |
| 8 | #define FPDFSDK_CPDFSDK_INTERFORM_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" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 19 | |
| 20 | class CPDF_Dictionary; |
| 21 | class CPDF_FormControl; |
| 22 | class CPDF_FormField; |
| 23 | class CPDF_InterForm; |
| 24 | class CPDF_Object; |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 25 | class CPDFSDK_FormFillEnvironment; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef PDF_ENABLE_XFA |
| 28 | class CPDFSDK_XFAWidget; |
| 29 | class CXFA_FFWidget; |
| 30 | #endif // PDF_ENABLE_XFA |
| 31 | |
Tom Sepez | 5586545 | 2018-08-27 20:18:04 +0000 | [diff] [blame^] | 32 | class CPDFSDK_InterForm final : public IPDF_FormNotify { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 33 | public: |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 34 | explicit CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 35 | ~CPDFSDK_InterForm() override; |
| 36 | |
| 37 | CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); } |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 38 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { |
| 39 | return m_pFormFillEnv.Get(); |
| 40 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 41 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 42 | bool HighlightWidgets(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 43 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 44 | CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const; |
dsinclair | c5267c5 | 2016-11-04 15:35:12 -0700 | [diff] [blame] | 45 | CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 46 | void GetWidgets(const WideString& sFieldName, |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 47 | std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 48 | void GetWidgets(CPDF_FormField* pField, |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 49 | std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 50 | |
| 51 | void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); |
| 52 | void RemoveMap(CPDF_FormControl* pControl); |
| 53 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 54 | void EnableCalculate(bool bEnabled); |
| 55 | bool IsCalculateEnabled() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 56 | |
| 57 | #ifdef PDF_ENABLE_XFA |
| 58 | void AddXFAMap(CXFA_FFWidget* hWidget, CPDFSDK_XFAWidget* pWidget); |
| 59 | void RemoveXFAMap(CXFA_FFWidget* hWidget); |
| 60 | CPDFSDK_XFAWidget* GetXFAWidget(CXFA_FFWidget* hWidget); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 61 | void XfaEnableCalculate(bool bEnabled); |
| 62 | bool IsXfaCalculateEnabled() const; |
| 63 | bool IsXfaValidationsEnabled(); |
| 64 | void XfaSetValidationsEnabled(bool bEnabled); |
Dan Sinclair | ce047a6 | 2018-01-30 18:15:02 +0000 | [diff] [blame] | 65 | void SynchronizeField(CPDF_FormField* pFormField); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 66 | #endif // PDF_ENABLE_XFA |
| 67 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 68 | bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue); |
| 69 | bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue); |
Tom Sepez | b9c3e27 | 2018-08-14 18:22:06 +0000 | [diff] [blame] | 70 | void OnCalculate(CPDF_FormField* pFormField); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 71 | WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 72 | |
| 73 | void ResetFieldAppearance(CPDF_FormField* pFormField, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 74 | const WideString* sValue, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 75 | bool bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 76 | void UpdateField(CPDF_FormField* pFormField); |
| 77 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 78 | bool DoAction_Hide(const CPDF_Action& action); |
| 79 | bool DoAction_SubmitForm(const CPDF_Action& action); |
dan sinclair | 7544a4b | 2018-03-08 15:19:50 +0000 | [diff] [blame] | 80 | void DoAction_ResetForm(const CPDF_Action& action); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 81 | |
| 82 | std::vector<CPDF_FormField*> GetFieldFromObjects( |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 83 | const std::vector<const CPDF_Object*>& objects) const; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 84 | bool IsValidField(CPDF_Dictionary* pFieldDict); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 85 | bool SubmitFields(const WideString& csDestination, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 86 | const std::vector<CPDF_FormField*>& fields, |
| 87 | bool bIncludeOrExclude, |
| 88 | bool bUrlEncoded); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 89 | bool SubmitForm(const WideString& sDestination, bool bUrlEncoded); |
| 90 | ByteString ExportFormToFDFTextBuf(); |
| 91 | ByteString ExportFieldsToFDFTextBuf( |
Henrique Nakashima | 5c09f4c | 2017-08-04 12:28:52 -0400 | [diff] [blame] | 92 | const std::vector<CPDF_FormField*>& fields, |
| 93 | bool bIncludeOrExclude); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 94 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 95 | bool IsNeedHighLight(FormFieldType fieldType); |
| 96 | void RemoveAllHighLights(); |
| 97 | void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; } |
| 98 | uint8_t GetHighlightAlpha() { return m_HighlightAlpha; } |
| 99 | void SetHighlightColor(FX_COLORREF clr, FormFieldType fieldType); |
| 100 | void SetAllHighlightColors(FX_COLORREF clr); |
| 101 | FX_COLORREF GetHighlightColor(FormFieldType fieldType); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 102 | |
| 103 | private: |
| 104 | // IPDF_FormNotify: |
dan sinclair | 507fb4e | 2018-03-08 15:14:09 +0000 | [diff] [blame] | 105 | bool BeforeValueChange(CPDF_FormField* pField, |
| 106 | const WideString& csValue) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 107 | void AfterValueChange(CPDF_FormField* pField) override; |
dan sinclair | 507fb4e | 2018-03-08 15:14:09 +0000 | [diff] [blame] | 108 | bool BeforeSelectionChange(CPDF_FormField* pField, |
| 109 | const WideString& csValue) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 110 | void AfterSelectionChange(CPDF_FormField* pField) override; |
| 111 | void AfterCheckedStatusChange(CPDF_FormField* pField) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 112 | void AfterFormReset(CPDF_InterForm* pForm) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 113 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 114 | int GetPageIndexByAnnotDict(CPDF_Document* pDocument, |
| 115 | CPDF_Dictionary* pAnnotDict) const; |
| 116 | |
| 117 | using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>; |
| 118 | |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 119 | UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 120 | std::unique_ptr<CPDF_InterForm> m_pInterForm; |
| 121 | CPDFSDK_WidgetMap m_Map; |
| 122 | #ifdef PDF_ENABLE_XFA |
| 123 | std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 124 | bool m_bXfaCalculate; |
| 125 | bool m_bXfaValidationsEnabled; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 126 | #endif // PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 127 | bool m_bCalculate; |
| 128 | bool m_bBusy; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 129 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 130 | uint8_t m_HighlightAlpha; |
| 131 | FX_COLORREF m_HighlightColor[kFormFieldTypeCount]; |
| 132 | bool m_NeedsHighlight[kFormFieldTypeCount]; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 135 | #endif // FPDFSDK_CPDFSDK_INTERFORM_H_ |