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