blob: bd1a76087e8138187cb516c96f3f616becd492a5 [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"
Dan Sinclairaee0db02017-09-21 16:53:58 -040016#include "core/fxcrt/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
Tom Sepez55865452018-08-27 20:18:04 +000032class CPDFSDK_InterForm final : public IPDF_FormNotify {
jaepark611adb82016-08-17 11:34:36 -070033 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;
Ryan Harrison275e2602017-09-18 14:23:18 -040046 void GetWidgets(const 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);
Dan Sinclairce047a62018-01-30 18:15:02 +000065 void SynchronizeField(CPDF_FormField* pFormField);
jaepark611adb82016-08-17 11:34:36 -070066#endif // PDF_ENABLE_XFA
67
Ryan Harrison275e2602017-09-18 14:23:18 -040068 bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue);
69 bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue);
Tom Sepezb9c3e272018-08-14 18:22:06 +000070 void OnCalculate(CPDF_FormField* pFormField);
Ryan Harrison275e2602017-09-18 14:23:18 -040071 WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted);
jaepark611adb82016-08-17 11:34:36 -070072
73 void ResetFieldAppearance(CPDF_FormField* pFormField,
Ryan Harrison275e2602017-09-18 14:23:18 -040074 const WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -070075 bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -070076 void UpdateField(CPDF_FormField* pFormField);
77
tsepez4cf55152016-11-02 14:37:54 -070078 bool DoAction_Hide(const CPDF_Action& action);
79 bool DoAction_SubmitForm(const CPDF_Action& action);
dan sinclair7544a4b2018-03-08 15:19:50 +000080 void DoAction_ResetForm(const CPDF_Action& action);
jaepark611adb82016-08-17 11:34:36 -070081
82 std::vector<CPDF_FormField*> GetFieldFromObjects(
Lei Zhang5cee3f22018-05-25 21:48:49 +000083 const std::vector<const CPDF_Object*>& objects) const;
tsepez4cf55152016-11-02 14:37:54 -070084 bool IsValidField(CPDF_Dictionary* pFieldDict);
Ryan Harrison275e2602017-09-18 14:23:18 -040085 bool SubmitFields(const WideString& csDestination,
tsepez4cf55152016-11-02 14:37:54 -070086 const std::vector<CPDF_FormField*>& fields,
87 bool bIncludeOrExclude,
88 bool bUrlEncoded);
Ryan Harrison275e2602017-09-18 14:23:18 -040089 bool SubmitForm(const WideString& sDestination, bool bUrlEncoded);
90 ByteString ExportFormToFDFTextBuf();
91 ByteString ExportFieldsToFDFTextBuf(
Henrique Nakashima5c09f4c2017-08-04 12:28:52 -040092 const std::vector<CPDF_FormField*>& fields,
93 bool bIncludeOrExclude);
jaepark611adb82016-08-17 11:34:36 -070094
Ryan Harrison9baf31f2018-01-12 18:36:30 +000095 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);
jaepark611adb82016-08-17 11:34:36 -0700102
103 private:
104 // IPDF_FormNotify:
dan sinclair507fb4e2018-03-08 15:14:09 +0000105 bool BeforeValueChange(CPDF_FormField* pField,
106 const WideString& csValue) override;
jaepark611adb82016-08-17 11:34:36 -0700107 void AfterValueChange(CPDF_FormField* pField) override;
dan sinclair507fb4e2018-03-08 15:14:09 +0000108 bool BeforeSelectionChange(CPDF_FormField* pField,
109 const WideString& csValue) override;
jaepark611adb82016-08-17 11:34:36 -0700110 void AfterSelectionChange(CPDF_FormField* pField) override;
111 void AfterCheckedStatusChange(CPDF_FormField* pField) override;
jaepark611adb82016-08-17 11:34:36 -0700112 void AfterFormReset(CPDF_InterForm* pForm) override;
jaepark611adb82016-08-17 11:34:36 -0700113
jaepark611adb82016-08-17 11:34:36 -0700114 int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
115 CPDF_Dictionary* pAnnotDict) const;
116
117 using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
118
Dan Sinclairaee0db02017-09-21 16:53:58 -0400119 UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
jaepark611adb82016-08-17 11:34:36 -0700120 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;
tsepez4cf55152016-11-02 14:37:54 -0700124 bool m_bXfaCalculate;
125 bool m_bXfaValidationsEnabled;
jaepark611adb82016-08-17 11:34:36 -0700126#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700127 bool m_bCalculate;
128 bool m_bBusy;
jaepark611adb82016-08-17 11:34:36 -0700129
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000130 uint8_t m_HighlightAlpha;
131 FX_COLORREF m_HighlightColor[kFormFieldTypeCount];
132 bool m_NeedsHighlight[kFormFieldTypeCount];
jaepark611adb82016-08-17 11:34:36 -0700133};
134
dsinclair114e46a2016-09-29 17:18:21 -0700135#endif // FPDFSDK_CPDFSDK_INTERFORM_H_