blob: b613c731ba5f9d369f403ba0c50b804f10e770d1 [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"
dsinclaira52ab742016-09-29 13:59:29 -070017#include "core/fxcrt/fx_basic.h"
dsinclair74a34fc2016-09-29 16:41:42 -070018#include "core/fxge/fx_dib.h"
tsepez8fa82792017-01-11 09:32:33 -080019#include "fpdfsdk/cpdfsdk_widget.h"
jaepark611adb82016-08-17 11:34:36 -070020
21class CPDF_Dictionary;
22class CPDF_FormControl;
23class CPDF_FormField;
24class CPDF_InterForm;
25class CPDF_Object;
dsinclair690c0332016-10-11 09:13:01 -070026class CPDFSDK_FormFillEnvironment;
jaepark611adb82016-08-17 11:34:36 -070027
28#ifdef PDF_ENABLE_XFA
29class CPDFSDK_XFAWidget;
30class CXFA_FFWidget;
31#endif // PDF_ENABLE_XFA
32
33class CPDFSDK_InterForm : public IPDF_FormNotify {
34 public:
dsinclair690c0332016-10-11 09:13:01 -070035 explicit CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv);
jaepark611adb82016-08-17 11:34:36 -070036 ~CPDFSDK_InterForm() override;
37
38 CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); }
Tom Sepezcc205132017-05-16 14:01:47 -070039 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
40 return m_pFormFillEnv.Get();
41 }
jaepark611adb82016-08-17 11:34:36 -070042
tsepez4cf55152016-11-02 14:37:54 -070043 bool HighlightWidgets();
jaepark611adb82016-08-17 11:34:36 -070044
tsepez4cf55152016-11-02 14:37:54 -070045 CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const;
dsinclairc5267c52016-11-04 15:35:12 -070046 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
jaepark611adb82016-08-17 11:34:36 -070047 void GetWidgets(const CFX_WideString& sFieldName,
tsepez8fa82792017-01-11 09:32:33 -080048 std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070049 void GetWidgets(CPDF_FormField* pField,
tsepez8fa82792017-01-11 09:32:33 -080050 std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070051
52 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
53 void RemoveMap(CPDF_FormControl* pControl);
54
tsepez4cf55152016-11-02 14:37:54 -070055 void EnableCalculate(bool bEnabled);
56 bool IsCalculateEnabled() const;
jaepark611adb82016-08-17 11:34:36 -070057
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);
tsepez4cf55152016-11-02 14:37:54 -070062 void XfaEnableCalculate(bool bEnabled);
63 bool IsXfaCalculateEnabled() const;
64 bool IsXfaValidationsEnabled();
65 void XfaSetValidationsEnabled(bool bEnabled);
66 void SynchronizeField(CPDF_FormField* pFormField, bool bSynchronizeElse);
jaepark611adb82016-08-17 11:34:36 -070067#endif // PDF_ENABLE_XFA
68
tsepez4cf55152016-11-02 14:37:54 -070069 bool OnKeyStrokeCommit(CPDF_FormField* pFormField,
70 const CFX_WideString& csValue);
71 bool OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue);
jaepark611adb82016-08-17 11:34:36 -070072 void OnCalculate(CPDF_FormField* pFormField = nullptr);
tsepez4cf55152016-11-02 14:37:54 -070073 CFX_WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted);
jaepark611adb82016-08-17 11:34:36 -070074
75 void ResetFieldAppearance(CPDF_FormField* pFormField,
tsepeza31da742016-09-08 11:28:14 -070076 const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -070077 bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -070078 void UpdateField(CPDF_FormField* pFormField);
79
tsepez4cf55152016-11-02 14:37:54 -070080 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);
jaepark611adb82016-08-17 11:34:36 -070084
85 std::vector<CPDF_FormField*> GetFieldFromObjects(
86 const std::vector<CPDF_Object*>& objects) const;
tsepez4cf55152016-11-02 14:37:54 -070087 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 Nakashima1952d172017-08-04 15:41:58 +000093 bool ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf);
94 bool ExportFieldsToFDFTextBuf(const std::vector<CPDF_FormField*>& fields,
95 bool bIncludeOrExclude,
96 CFX_ByteTextBuf& textBuf);
jaepark611adb82016-08-17 11:34:36 -070097 CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt);
98
tsepez4cf55152016-11-02 14:37:54 -070099 bool IsNeedHighLight(int nFieldType);
jaepark611adb82016-08-17 11:34:36 -0700100 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 Nakashima1952d172017-08-04 15:41:58 +0000120 bool FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile);
tsepez4cf55152016-11-02 14:37:54 -0700121 bool FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize);
jaepark611adb82016-08-17 11:34:36 -0700122 int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
123 CPDF_Dictionary* pAnnotDict) const;
124
125 using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
126
Tom Sepezcc205132017-05-16 14:01:47 -0700127 CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
jaepark611adb82016-08-17 11:34:36 -0700128 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;
tsepez4cf55152016-11-02 14:37:54 -0700132 bool m_bXfaCalculate;
133 bool m_bXfaValidationsEnabled;
jaepark611adb82016-08-17 11:34:36 -0700134 static const int kNumFieldTypes = 7;
135#else // PDF_ENABLE_XFA
136 static const int kNumFieldTypes = 6;
137#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700138 bool m_bCalculate;
139 bool m_bBusy;
jaepark611adb82016-08-17 11:34:36 -0700140
141 FX_COLORREF m_aHighlightColor[kNumFieldTypes];
142 uint8_t m_iHighlightAlpha;
tsepez4cf55152016-11-02 14:37:54 -0700143 bool m_bNeedHightlight[kNumFieldTypes];
jaepark611adb82016-08-17 11:34:36 -0700144};
145
dsinclair114e46a2016-09-29 17:18:21 -0700146#endif // FPDFSDK_CPDFSDK_INTERFORM_H_