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" |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/cfx_unowned_ptr.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 17 | #include "core/fxcrt/fx_basic.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 18 | #include "core/fxge/fx_dib.h" |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_widget.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; |
| 24 | class CPDF_InterForm; |
| 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 | |
| 28 | #ifdef PDF_ENABLE_XFA |
| 29 | class CPDFSDK_XFAWidget; |
| 30 | class CXFA_FFWidget; |
| 31 | #endif // PDF_ENABLE_XFA |
| 32 | |
| 33 | class CPDFSDK_InterForm : public IPDF_FormNotify { |
| 34 | public: |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 35 | explicit CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 36 | ~CPDFSDK_InterForm() override; |
| 37 | |
| 38 | CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); } |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 39 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { |
| 40 | return m_pFormFillEnv.Get(); |
| 41 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 42 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 43 | bool HighlightWidgets(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 44 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 45 | CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const; |
dsinclair | c5267c5 | 2016-11-04 15:35:12 -0700 | [diff] [blame] | 46 | CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 47 | void GetWidgets(const CFX_WideString& sFieldName, |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 48 | std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 49 | void GetWidgets(CPDF_FormField* pField, |
tsepez | 8fa8279 | 2017-01-11 09:32:33 -0800 | [diff] [blame] | 50 | std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 51 | |
| 52 | void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); |
| 53 | void RemoveMap(CPDF_FormControl* pControl); |
| 54 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 55 | void EnableCalculate(bool bEnabled); |
| 56 | bool IsCalculateEnabled() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 57 | |
| 58 | #ifdef PDF_ENABLE_XFA |
| 59 | void AddXFAMap(CXFA_FFWidget* hWidget, CPDFSDK_XFAWidget* pWidget); |
| 60 | void RemoveXFAMap(CXFA_FFWidget* hWidget); |
| 61 | CPDFSDK_XFAWidget* GetXFAWidget(CXFA_FFWidget* hWidget); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 62 | void XfaEnableCalculate(bool bEnabled); |
| 63 | bool IsXfaCalculateEnabled() const; |
| 64 | bool IsXfaValidationsEnabled(); |
| 65 | void XfaSetValidationsEnabled(bool bEnabled); |
| 66 | void SynchronizeField(CPDF_FormField* pFormField, bool bSynchronizeElse); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 67 | #endif // PDF_ENABLE_XFA |
| 68 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 69 | bool OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| 70 | const CFX_WideString& csValue); |
| 71 | bool OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 72 | void OnCalculate(CPDF_FormField* pFormField = nullptr); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 73 | CFX_WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 74 | |
| 75 | void ResetFieldAppearance(CPDF_FormField* pFormField, |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 76 | const CFX_WideString* sValue, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 77 | bool bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 78 | void UpdateField(CPDF_FormField* pFormField); |
| 79 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 80 | bool DoAction_Hide(const CPDF_Action& action); |
| 81 | bool DoAction_SubmitForm(const CPDF_Action& action); |
| 82 | bool DoAction_ResetForm(const CPDF_Action& action); |
| 83 | bool DoAction_ImportData(const CPDF_Action& action); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 84 | |
| 85 | std::vector<CPDF_FormField*> GetFieldFromObjects( |
| 86 | const std::vector<CPDF_Object*>& objects) const; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 87 | bool IsValidField(CPDF_Dictionary* pFieldDict); |
| 88 | bool SubmitFields(const CFX_WideString& csDestination, |
| 89 | const std::vector<CPDF_FormField*>& fields, |
| 90 | bool bIncludeOrExclude, |
| 91 | bool bUrlEncoded); |
| 92 | bool SubmitForm(const CFX_WideString& sDestination, bool bUrlEncoded); |
Henrique Nakashima | 1952d17 | 2017-08-04 15:41:58 +0000 | [diff] [blame] | 93 | bool ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf); |
| 94 | bool ExportFieldsToFDFTextBuf(const std::vector<CPDF_FormField*>& fields, |
| 95 | bool bIncludeOrExclude, |
| 96 | CFX_ByteTextBuf& textBuf); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 97 | CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt); |
| 98 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 99 | bool IsNeedHighLight(int nFieldType); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 100 | void RemoveAllHighLight(); |
| 101 | void SetHighlightAlpha(uint8_t alpha) { m_iHighlightAlpha = alpha; } |
| 102 | uint8_t GetHighlightAlpha() { return m_iHighlightAlpha; } |
| 103 | void SetHighlightColor(FX_COLORREF clr, int nFieldType); |
| 104 | FX_COLORREF GetHighlightColor(int nFieldType); |
| 105 | |
| 106 | private: |
| 107 | // IPDF_FormNotify: |
| 108 | int BeforeValueChange(CPDF_FormField* pField, |
| 109 | const CFX_WideString& csValue) override; |
| 110 | void AfterValueChange(CPDF_FormField* pField) override; |
| 111 | int BeforeSelectionChange(CPDF_FormField* pField, |
| 112 | const CFX_WideString& csValue) override; |
| 113 | void AfterSelectionChange(CPDF_FormField* pField) override; |
| 114 | void AfterCheckedStatusChange(CPDF_FormField* pField) override; |
| 115 | int BeforeFormReset(CPDF_InterForm* pForm) override; |
| 116 | void AfterFormReset(CPDF_InterForm* pForm) override; |
| 117 | int BeforeFormImportData(CPDF_InterForm* pForm) override; |
| 118 | void AfterFormImportData(CPDF_InterForm* pForm) override; |
| 119 | |
Henrique Nakashima | 1952d17 | 2017-08-04 15:41:58 +0000 | [diff] [blame] | 120 | bool FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 121 | bool FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 122 | int GetPageIndexByAnnotDict(CPDF_Document* pDocument, |
| 123 | CPDF_Dictionary* pAnnotDict) const; |
| 124 | |
| 125 | using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>; |
| 126 | |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 127 | CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 128 | std::unique_ptr<CPDF_InterForm> m_pInterForm; |
| 129 | CPDFSDK_WidgetMap m_Map; |
| 130 | #ifdef PDF_ENABLE_XFA |
| 131 | std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 132 | bool m_bXfaCalculate; |
| 133 | bool m_bXfaValidationsEnabled; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 134 | static const int kNumFieldTypes = 7; |
| 135 | #else // PDF_ENABLE_XFA |
| 136 | static const int kNumFieldTypes = 6; |
| 137 | #endif // PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 138 | bool m_bCalculate; |
| 139 | bool m_bBusy; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 140 | |
| 141 | FX_COLORREF m_aHighlightColor[kNumFieldTypes]; |
| 142 | uint8_t m_iHighlightAlpha; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 143 | bool m_bNeedHightlight[kNumFieldTypes]; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 146 | #endif // FPDFSDK_CPDFSDK_INTERFORM_H_ |