• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #ifndef FPDFSDK_CPDFSDK_INTERFORM_H_
8 #define FPDFSDK_CPDFSDK_INTERFORM_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fpdfdoc/cpdf_action.h"
15 #include "core/fpdfdoc/ipdf_formnotify.h"
16 #include "core/fxcrt/unowned_ptr.h"
17 #include "core/fxge/fx_dib.h"
18 #include "fpdfsdk/cpdfsdk_widget.h"
19 
20 class CPDF_Dictionary;
21 class CPDF_FormControl;
22 class CPDF_FormField;
23 class CPDF_InterForm;
24 class CPDF_Object;
25 class CPDFSDK_FormFillEnvironment;
26 
27 #ifdef PDF_ENABLE_XFA
28 class CPDFSDK_XFAWidget;
29 class CXFA_FFWidget;
30 #endif  // PDF_ENABLE_XFA
31 
32 class CPDFSDK_InterForm : public IPDF_FormNotify {
33  public:
34   explicit CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv);
35   ~CPDFSDK_InterForm() override;
36 
GetInterForm()37   CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); }
GetFormFillEnv()38   CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
39     return m_pFormFillEnv.Get();
40   }
41 
42   bool HighlightWidgets();
43 
44   CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const;
45   CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
46   void GetWidgets(const WideString& sFieldName,
47                   std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
48   void GetWidgets(CPDF_FormField* pField,
49                   std::vector<CPDFSDK_Annot::ObservedPtr>* widgets) const;
50 
51   void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
52   void RemoveMap(CPDF_FormControl* pControl);
53 
54   void EnableCalculate(bool bEnabled);
55   bool IsCalculateEnabled() const;
56 
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);
61   void XfaEnableCalculate(bool bEnabled);
62   bool IsXfaCalculateEnabled() const;
63   bool IsXfaValidationsEnabled();
64   void XfaSetValidationsEnabled(bool bEnabled);
65   void SynchronizeField(CPDF_FormField* pFormField, bool bSynchronizeElse);
66 #endif  // PDF_ENABLE_XFA
67 
68   bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue);
69   bool OnValidate(CPDF_FormField* pFormField, const WideString& csValue);
70   void OnCalculate(CPDF_FormField* pFormField = nullptr);
71   WideString OnFormat(CPDF_FormField* pFormField, bool& bFormatted);
72 
73   void ResetFieldAppearance(CPDF_FormField* pFormField,
74                             const WideString* sValue,
75                             bool bValueChanged);
76   void UpdateField(CPDF_FormField* pFormField);
77 
78   bool DoAction_Hide(const CPDF_Action& action);
79   bool DoAction_SubmitForm(const CPDF_Action& action);
80   bool DoAction_ResetForm(const CPDF_Action& action);
81   bool DoAction_ImportData(const CPDF_Action& action);
82 
83   std::vector<CPDF_FormField*> GetFieldFromObjects(
84       const std::vector<CPDF_Object*>& objects) const;
85   bool IsValidField(CPDF_Dictionary* pFieldDict);
86   bool SubmitFields(const WideString& csDestination,
87                     const std::vector<CPDF_FormField*>& fields,
88                     bool bIncludeOrExclude,
89                     bool bUrlEncoded);
90   bool SubmitForm(const WideString& sDestination, bool bUrlEncoded);
91   ByteString ExportFormToFDFTextBuf();
92   ByteString ExportFieldsToFDFTextBuf(
93       const std::vector<CPDF_FormField*>& fields,
94       bool bIncludeOrExclude);
95 
96   bool IsNeedHighLight(FormFieldType fieldType);
97   void RemoveAllHighLights();
SetHighlightAlpha(uint8_t alpha)98   void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; }
GetHighlightAlpha()99   uint8_t GetHighlightAlpha() { return m_HighlightAlpha; }
100   void SetHighlightColor(FX_COLORREF clr, FormFieldType fieldType);
101   void SetAllHighlightColors(FX_COLORREF clr);
102   FX_COLORREF GetHighlightColor(FormFieldType fieldType);
103 
104  private:
105   // IPDF_FormNotify:
106   int BeforeValueChange(CPDF_FormField* pField,
107                         const WideString& csValue) override;
108   void AfterValueChange(CPDF_FormField* pField) override;
109   int BeforeSelectionChange(CPDF_FormField* pField,
110                             const WideString& csValue) override;
111   void AfterSelectionChange(CPDF_FormField* pField) override;
112   void AfterCheckedStatusChange(CPDF_FormField* pField) override;
113   int BeforeFormReset(CPDF_InterForm* pForm) override;
114   void AfterFormReset(CPDF_InterForm* pForm) override;
115   int BeforeFormImportData(CPDF_InterForm* pForm) override;
116   void AfterFormImportData(CPDF_InterForm* pForm) override;
117 
118   bool FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize);
119   int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
120                               CPDF_Dictionary* pAnnotDict) const;
121 
122   using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
123 
124   UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
125   std::unique_ptr<CPDF_InterForm> m_pInterForm;
126   CPDFSDK_WidgetMap m_Map;
127 #ifdef PDF_ENABLE_XFA
128   std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap;
129   bool m_bXfaCalculate;
130   bool m_bXfaValidationsEnabled;
131 #endif  // PDF_ENABLE_XFA
132   bool m_bCalculate;
133   bool m_bBusy;
134 
135   uint8_t m_HighlightAlpha;
136   FX_COLORREF m_HighlightColor[kFormFieldTypeCount];
137   bool m_NeedsHighlight[kFormFieldTypeCount];
138 };
139 
140 #endif  // FPDFSDK_CPDFSDK_INTERFORM_H_
141