blob: b031345158cfcc3dcb46011d1f5218dd4538e83a [file] [log] [blame]
jaepark611adb82016-08-17 11:34:36 -07001// 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
dsinclair114e46a2016-09-29 17:18:21 -07007#ifndef FPDFSDK_CPDFSDK_INTERFORM_H_
8#define FPDFSDK_CPDFSDK_INTERFORM_H_
jaepark611adb82016-08-17 11:34:36 -07009
10#include <map>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050011#include <memory>
jaepark611adb82016-08-17 11:34:36 -070012#include <vector>
13
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpdf_action.h"
15#include "core/fpdfdoc/ipdf_formnotify.h"
Tom Sepezcc205132017-05-16 14:01:47 -070016#include "core/fxcrt/cfx_unowned_ptr.h"
dsinclair74a34fc2016-09-29 16:41:42 -070017#include "core/fxge/fx_dib.h"
tsepez8fa82792017-01-11 09:32:33 -080018#include "fpdfsdk/cpdfsdk_widget.h"
jaepark611adb82016-08-17 11:34:36 -070019
20class CPDF_Dictionary;
21class CPDF_FormControl;
22class CPDF_FormField;
23class CPDF_InterForm;
24class CPDF_Object;
dsinclair690c0332016-10-11 09:13:01 -070025class CPDFSDK_FormFillEnvironment;
jaepark611adb82016-08-17 11:34:36 -070026
27#ifdef PDF_ENABLE_XFA
28class CPDFSDK_XFAWidget;
29class CXFA_FFWidget;
30#endif // PDF_ENABLE_XFA
31
32class CPDFSDK_InterForm : public IPDF_FormNotify {
33 public:
dsinclair690c0332016-10-11 09:13:01 -070034 explicit CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv);
jaepark611adb82016-08-17 11:34:36 -070035 ~CPDFSDK_InterForm() override;
36
37 CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); }
Tom Sepezcc205132017-05-16 14:01:47 -070038 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
39 return m_pFormFillEnv.Get();
40 }
jaepark611adb82016-08-17 11:34:36 -070041
tsepez4cf55152016-11-02 14:37:54 -070042 bool HighlightWidgets();
jaepark611adb82016-08-17 11:34:36 -070043
tsepez4cf55152016-11-02 14:37:54 -070044 CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const;
dsinclairc5267c52016-11-04 15:35:12 -070045 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
jaepark611adb82016-08-17 11:34:36 -070046 void GetWidgets(const CFX_WideString& sFieldName,
tsepez8fa82792017-01-11 09:32:33 -080047 std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070048 void GetWidgets(CPDF_FormField* pField,
tsepez8fa82792017-01-11 09:32:33 -080049 std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070050
51 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
52 void RemoveMap(CPDF_FormControl* pControl);
53
tsepez4cf55152016-11-02 14:37:54 -070054 void EnableCalculate(bool bEnabled);
55 bool IsCalculateEnabled() const;
jaepark611adb82016-08-17 11:34:36 -070056
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);
tsepez4cf55152016-11-02 14:37:54 -070061 void XfaEnableCalculate(bool bEnabled);
62 bool IsXfaCalculateEnabled() const;
63 bool IsXfaValidationsEnabled();
64 void XfaSetValidationsEnabled(bool bEnabled);
65 void SynchronizeField(CPDF_FormField* pFormField, bool bSynchronizeElse);
jaepark611adb82016-08-17 11:34:36 -070066#endif // PDF_ENABLE_XFA
67
tsepez4cf55152016-11-02 14:37:54 -070068 bool OnKeyStrokeCommit(CPDF_FormField* pFormField,
69 const CFX_WideString& csValue);
70 bool OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue);
jaepark611adb82016-08-17 11:34:36 -070071 void OnCalculate(CPDF_FormField* pFormField = nullptr);
tsepez4cf55152016-11-02 14:37:54 -070072 CFX_WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted);
jaepark611adb82016-08-17 11:34:36 -070073
74 void ResetFieldAppearance(CPDF_FormField* pFormField,
tsepeza31da742016-09-08 11:28:14 -070075 const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -070076 bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -070077 void UpdateField(CPDF_FormField* pFormField);
78
tsepez4cf55152016-11-02 14:37:54 -070079 bool DoAction_Hide(const CPDF_Action& action);
80 bool DoAction_SubmitForm(const CPDF_Action& action);
81 bool DoAction_ResetForm(const CPDF_Action& action);
82 bool DoAction_ImportData(const CPDF_Action& action);
jaepark611adb82016-08-17 11:34:36 -070083
84 std::vector<CPDF_FormField*> GetFieldFromObjects(
85 const std::vector<CPDF_Object*>& objects) const;
tsepez4cf55152016-11-02 14:37:54 -070086 bool IsValidField(CPDF_Dictionary* pFieldDict);
87 bool SubmitFields(const CFX_WideString& csDestination,
88 const std::vector<CPDF_FormField*>& fields,
89 bool bIncludeOrExclude,
90 bool bUrlEncoded);
91 bool SubmitForm(const CFX_WideString& sDestination, bool bUrlEncoded);
Henrique Nakashima5c09f4c2017-08-04 12:28:52 -040092 CFX_ByteString ExportFormToFDFTextBuf();
93 CFX_ByteString ExportFieldsToFDFTextBuf(
94 const std::vector<CPDF_FormField*>& fields,
95 bool bIncludeOrExclude);
jaepark611adb82016-08-17 11:34:36 -070096 CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt);
97
tsepez4cf55152016-11-02 14:37:54 -070098 bool IsNeedHighLight(int nFieldType);
jaepark611adb82016-08-17 11:34:36 -070099 void RemoveAllHighLight();
100 void SetHighlightAlpha(uint8_t alpha) { m_iHighlightAlpha = alpha; }
101 uint8_t GetHighlightAlpha() { return m_iHighlightAlpha; }
102 void SetHighlightColor(FX_COLORREF clr, int nFieldType);
103 FX_COLORREF GetHighlightColor(int nFieldType);
104
105 private:
106 // IPDF_FormNotify:
107 int BeforeValueChange(CPDF_FormField* pField,
108 const CFX_WideString& csValue) override;
109 void AfterValueChange(CPDF_FormField* pField) override;
110 int BeforeSelectionChange(CPDF_FormField* pField,
111 const CFX_WideString& csValue) override;
112 void AfterSelectionChange(CPDF_FormField* pField) override;
113 void AfterCheckedStatusChange(CPDF_FormField* pField) override;
114 int BeforeFormReset(CPDF_InterForm* pForm) override;
115 void AfterFormReset(CPDF_InterForm* pForm) override;
116 int BeforeFormImportData(CPDF_InterForm* pForm) override;
117 void AfterFormImportData(CPDF_InterForm* pForm) override;
118
tsepez4cf55152016-11-02 14:37:54 -0700119 bool FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize);
jaepark611adb82016-08-17 11:34:36 -0700120 int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
121 CPDF_Dictionary* pAnnotDict) const;
122
123 using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
124
Tom Sepezcc205132017-05-16 14:01:47 -0700125 CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
jaepark611adb82016-08-17 11:34:36 -0700126 std::unique_ptr<CPDF_InterForm> m_pInterForm;
127 CPDFSDK_WidgetMap m_Map;
128#ifdef PDF_ENABLE_XFA
129 std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap;
tsepez4cf55152016-11-02 14:37:54 -0700130 bool m_bXfaCalculate;
131 bool m_bXfaValidationsEnabled;
jaepark611adb82016-08-17 11:34:36 -0700132 static const int kNumFieldTypes = 7;
133#else // PDF_ENABLE_XFA
134 static const int kNumFieldTypes = 6;
135#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700136 bool m_bCalculate;
137 bool m_bBusy;
jaepark611adb82016-08-17 11:34:36 -0700138
139 FX_COLORREF m_aHighlightColor[kNumFieldTypes];
140 uint8_t m_iHighlightAlpha;
tsepez4cf55152016-11-02 14:37:54 -0700141 bool m_bNeedHightlight[kNumFieldTypes];
jaepark611adb82016-08-17 11:34:36 -0700142};
143
dsinclair114e46a2016-09-29 17:18:21 -0700144#endif // FPDFSDK_CPDFSDK_INTERFORM_H_