blob: ec76bee359447a2f72074833650ffb8ad3affdf1 [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
Lei Zhangc3450652018-10-11 16:54:42 +00007#ifndef FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_
8#define FPDFSDK_CPDFSDK_INTERACTIVEFORM_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"
Lei Zhang4f261ff2018-10-10 18:44:45 +000019#include "third_party/base/optional.h"
jaepark611adb82016-08-17 11:34:36 -070020
21class CPDF_Dictionary;
22class CPDF_FormControl;
23class CPDF_FormField;
Lei Zhang073ecf42018-10-11 16:56:00 +000024class CPDF_InteractiveForm;
jaepark611adb82016-08-17 11:34:36 -070025class CPDF_Object;
dsinclair690c0332016-10-11 09:13:01 -070026class CPDFSDK_FormFillEnvironment;
jaepark611adb82016-08-17 11:34:36 -070027
Lei Zhang073ecf42018-10-11 16:56:00 +000028class CPDFSDK_InteractiveForm final : public IPDF_FormNotify {
jaepark611adb82016-08-17 11:34:36 -070029 public:
Lei Zhang073ecf42018-10-11 16:56:00 +000030 explicit CPDFSDK_InteractiveForm(CPDFSDK_FormFillEnvironment* pFormFillEnv);
31 ~CPDFSDK_InteractiveForm() override;
jaepark611adb82016-08-17 11:34:36 -070032
Lei Zhang073ecf42018-10-11 16:56:00 +000033 CPDF_InteractiveForm* GetInteractiveForm() const {
34 return m_pInteractiveForm.get();
35 }
Tom Sepezcc205132017-05-16 14:01:47 -070036 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
37 return m_pFormFillEnv.Get();
38 }
jaepark611adb82016-08-17 11:34:36 -070039
dsinclairc5267c52016-11-04 15:35:12 -070040 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
Ryan Harrison275e2602017-09-18 14:23:18 -040041 void GetWidgets(const WideString& sFieldName,
Tom Sepezd8ae8f82019-06-12 17:58:33 +000042 std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070043 void GetWidgets(CPDF_FormField* pField,
Tom Sepezd8ae8f82019-06-12 17:58:33 +000044 std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const;
jaepark611adb82016-08-17 11:34:36 -070045
46 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
47 void RemoveMap(CPDF_FormControl* pControl);
48
tsepez4cf55152016-11-02 14:37:54 -070049 void EnableCalculate(bool bEnabled);
50 bool IsCalculateEnabled() const;
jaepark611adb82016-08-17 11:34:36 -070051
52#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -070053 void XfaEnableCalculate(bool bEnabled);
54 bool IsXfaCalculateEnabled() const;
55 bool IsXfaValidationsEnabled();
56 void XfaSetValidationsEnabled(bool bEnabled);
Dan Sinclairce047a62018-01-30 18:15:02 +000057 void SynchronizeField(CPDF_FormField* pFormField);
jaepark611adb82016-08-17 11:34:36 -070058#endif // PDF_ENABLE_XFA
59
Ryan Harrison275e2602017-09-18 14:23:18 -040060 bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue);
61 bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue);
Tom Sepezb9c3e272018-08-14 18:22:06 +000062 void OnCalculate(CPDF_FormField* pFormField);
Lei Zhang4f261ff2018-10-10 18:44:45 +000063 Optional<WideString> OnFormat(CPDF_FormField* pFormField);
jaepark611adb82016-08-17 11:34:36 -070064
65 void ResetFieldAppearance(CPDF_FormField* pFormField,
Lei Zhang3b37f6b2019-07-29 23:31:26 +000066 Optional<WideString> sValue);
jaepark611adb82016-08-17 11:34:36 -070067 void UpdateField(CPDF_FormField* pFormField);
68
tsepez4cf55152016-11-02 14:37:54 -070069 bool DoAction_Hide(const CPDF_Action& action);
70 bool DoAction_SubmitForm(const CPDF_Action& action);
dan sinclair7544a4b2018-03-08 15:19:50 +000071 void DoAction_ResetForm(const CPDF_Action& action);
jaepark611adb82016-08-17 11:34:36 -070072
73 std::vector<CPDF_FormField*> GetFieldFromObjects(
Lei Zhang5cee3f22018-05-25 21:48:49 +000074 const std::vector<const CPDF_Object*>& objects) const;
Ryan Harrison275e2602017-09-18 14:23:18 -040075 bool SubmitFields(const WideString& csDestination,
tsepez4cf55152016-11-02 14:37:54 -070076 const std::vector<CPDF_FormField*>& fields,
77 bool bIncludeOrExclude,
78 bool bUrlEncoded);
Ryan Harrison275e2602017-09-18 14:23:18 -040079 bool SubmitForm(const WideString& sDestination, bool bUrlEncoded);
80 ByteString ExportFormToFDFTextBuf();
81 ByteString ExportFieldsToFDFTextBuf(
Henrique Nakashima5c09f4c2017-08-04 12:28:52 -040082 const std::vector<CPDF_FormField*>& fields,
83 bool bIncludeOrExclude);
jaepark611adb82016-08-17 11:34:36 -070084
Lei Zhang461acb22018-10-10 18:38:03 +000085 bool IsNeedHighLight(FormFieldType fieldType) const;
Ryan Harrison9baf31f2018-01-12 18:36:30 +000086 void RemoveAllHighLights();
87 void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; }
88 uint8_t GetHighlightAlpha() { return m_HighlightAlpha; }
89 void SetHighlightColor(FX_COLORREF clr, FormFieldType fieldType);
90 void SetAllHighlightColors(FX_COLORREF clr);
91 FX_COLORREF GetHighlightColor(FormFieldType fieldType);
jaepark611adb82016-08-17 11:34:36 -070092
93 private:
94 // IPDF_FormNotify:
dan sinclair507fb4e2018-03-08 15:14:09 +000095 bool BeforeValueChange(CPDF_FormField* pField,
96 const WideString& csValue) override;
jaepark611adb82016-08-17 11:34:36 -070097 void AfterValueChange(CPDF_FormField* pField) override;
dan sinclair507fb4e2018-03-08 15:14:09 +000098 bool BeforeSelectionChange(CPDF_FormField* pField,
99 const WideString& csValue) override;
jaepark611adb82016-08-17 11:34:36 -0700100 void AfterSelectionChange(CPDF_FormField* pField) override;
101 void AfterCheckedStatusChange(CPDF_FormField* pField) override;
Lei Zhang073ecf42018-10-11 16:56:00 +0000102 void AfterFormReset(CPDF_InteractiveForm* pForm) override;
jaepark611adb82016-08-17 11:34:36 -0700103
jaepark611adb82016-08-17 11:34:36 -0700104 int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
105 CPDF_Dictionary* pAnnotDict) const;
106
Lei Zhang461acb22018-10-10 18:38:03 +0000107 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
Lei Zhang073ecf42018-10-11 16:56:00 +0000108 std::unique_ptr<CPDF_InteractiveForm> const m_pInteractiveForm;
Lei Zhang461acb22018-10-10 18:38:03 +0000109 std::map<CPDF_FormControl*, CPDFSDK_Widget*> m_Map;
jaepark611adb82016-08-17 11:34:36 -0700110#ifdef PDF_ENABLE_XFA
Lei Zhang461acb22018-10-10 18:38:03 +0000111 bool m_bXfaCalculate = true;
112 bool m_bXfaValidationsEnabled = true;
jaepark611adb82016-08-17 11:34:36 -0700113#endif // PDF_ENABLE_XFA
Lei Zhang461acb22018-10-10 18:38:03 +0000114 bool m_bCalculate = true;
115 bool m_bBusy = false;
Lei Zhang461acb22018-10-10 18:38:03 +0000116 uint8_t m_HighlightAlpha = 0;
Ryan Harrison9baf31f2018-01-12 18:36:30 +0000117 FX_COLORREF m_HighlightColor[kFormFieldTypeCount];
118 bool m_NeedsHighlight[kFormFieldTypeCount];
jaepark611adb82016-08-17 11:34:36 -0700119};
120
Lei Zhangc3450652018-10-11 16:54:42 +0000121#endif // FPDFSDK_CPDFSDK_INTERACTIVEFORM_H_