• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_WIDGET_H_
8 #define FPDFSDK_CPDFSDK_WIDGET_H_
9 
10 #include "core/fpdfdoc/cpdf_aaction.h"
11 #include "core/fpdfdoc/cpdf_action.h"
12 #include "core/fpdfdoc/cpdf_annot.h"
13 #include "core/fpdfdoc/cpdf_formfield.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 #include "core/fxcrt/widestring.h"
17 #include "core/fxge/cfx_color.h"
18 #include "fpdfsdk/cpdfsdk_baannot.h"
19 #include "third_party/abseil-cpp/absl/types/optional.h"
20 
21 class CFFL_InteractiveFormFiller;
22 class CFX_RenderDevice;
23 class CPDF_Annot;
24 class CPDF_FormControl;
25 class CPDF_FormField;
26 class CPDFSDK_FormFillEnvironment;
27 class CPDFSDK_InteractiveForm;
28 class CPDFSDK_PageView;
29 struct CFFL_FieldAction;
30 
31 #ifdef PDF_ENABLE_XFA
32 class CXFA_FFWidget;
33 class CXFA_FFWidgetHandler;
34 
35 enum PDFSDK_XFAAActionType {
36   PDFSDK_XFA_Click = 0,
37   PDFSDK_XFA_Full,
38   PDFSDK_XFA_PreOpen,
39   PDFSDK_XFA_PostOpen
40 };
41 #endif  // PDF_ENABLE_XFA
42 
43 class CPDFSDK_Widget final : public CPDFSDK_BAAnnot {
44  public:
45   enum ValueChanged : bool { kValueUnchanged = false, kValueChanged = true };
46 
47   CPDFSDK_Widget(CPDF_Annot* pAnnot,
48                  CPDFSDK_PageView* pPageView,
49                  CPDFSDK_InteractiveForm* pInteractiveForm);
50   ~CPDFSDK_Widget() override;
51 
52   // CPDFSDK_BAAnnot:
53   void OnLoad() override;
54   CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override;
55   bool IsAppearanceValid() override;
56   int GetLayoutOrder() const override;
57   void OnDraw(CFX_RenderDevice* pDevice,
58               const CFX_Matrix& mtUser2Device,
59               bool bDrawAnnots) override;
60   bool DoHitTest(const CFX_PointF& point) override;
61   CFX_FloatRect GetViewBBox() override;
62   bool CanUndo() override;
63   bool CanRedo() override;
64   bool Undo() override;
65   bool Redo() override;
66   WideString GetText() override;
67   WideString GetSelectedText() override;
68   void ReplaceAndKeepSelection(const WideString& text) override;
69   void ReplaceSelection(const WideString& text) override;
70   bool SelectAllText() override;
71   bool SetIndexSelected(int index, bool selected) override;
72   bool IsIndexSelected(int index) override;
73   void DrawAppearance(CFX_RenderDevice* pDevice,
74                       const CFX_Matrix& mtUser2Device,
75                       CPDF_Annot::AppearanceMode mode) override;
76 
77   bool IsSignatureWidget() const;
78   void SetRect(const CFX_FloatRect& rect);
79   FormFieldType GetFieldType() const;
80   int GetFieldFlags() const;
81   int GetRotate() const;
82 
83   absl::optional<FX_COLORREF> GetFillColor() const;
84   absl::optional<FX_COLORREF> GetBorderColor() const;
85   absl::optional<FX_COLORREF> GetTextColor() const;
86   float GetFontSize() const;
87 
88   int GetSelectedIndex(int nIndex) const;
89   WideString GetValue() const;
90   WideString GetExportValue() const;
91   WideString GetOptionLabel(int nIndex) const;
92   WideString GetSelectExportText(int nIndex) const;
93 
94   int CountOptions() const;
95   bool IsOptionSelected(int nIndex) const;
96   int GetTopVisibleIndex() const;
97   bool IsChecked() const;
98   int GetAlignment() const;
99   int GetMaxLen() const;
100 
101   void SetCheck(bool bChecked);
102   void SetValue(const WideString& sValue);
103   void SetOptionSelection(int index);
104   void ClearSelection();
105   void SetTopVisibleIndex(int index);
106 
107 #ifdef PDF_ENABLE_XFA
108   CXFA_FFWidget* GetMixXFAWidget() const;
109   bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const;
110   bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
111                     CFFL_FieldAction* data,
112                     const CPDFSDK_PageView* pPageView);
113   void Synchronize(bool bSynchronizeElse);
114   // TODO(thestig): Figure out if the parameter should be used or removed.
115   void ResetXFAAppearance(ValueChanged bValueChanged);
116 #endif  // PDF_ENABLE_XFA
117 
118   void ResetAppearance(absl::optional<WideString> sValue,
119                        ValueChanged bValueChanged);
120   void ResetFieldAppearance();
121   void UpdateField();
122   absl::optional<WideString> OnFormat();
123 
124   bool OnAAction(CPDF_AAction::AActionType type,
125                  CFFL_FieldAction* data,
126                  const CPDFSDK_PageView* pPageView);
127 
128   CPDF_FormField* GetFormField() const;
129   CPDF_FormControl* GetFormControl() const;
130 
131   void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView);
132 
133   void SetAppModified();
134   void ClearAppModified();
135   bool IsAppModified() const;
136 
GetAppearanceAge()137   uint32_t GetAppearanceAge() const { return m_nAppearanceAge; }
GetValueAge()138   uint32_t GetValueAge() const { return m_nValueAge; }
139 
140   bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) const;
141   bool IsPushHighlighted() const;
142   CFX_Matrix GetMatrix() const;
143   CFX_FloatRect GetClientRect() const;
144   CFX_FloatRect GetRotatedRect() const;
145   CFX_Color GetTextPWLColor() const;
146   CFX_Color GetBorderPWLColor() const;
147   CFX_Color GetFillPWLColor() const;
148 
149  private:
150   // CPDFSDK_Annot::UnsafeInputHandlers:
151   void OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) override;
152   void OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) override;
153   bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
154                      const CFX_PointF& point) override;
155   bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
156                    const CFX_PointF& point) override;
157   bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
158                        const CFX_PointF& point) override;
159   bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
160                    const CFX_PointF& point) override;
161   bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
162                     const CFX_PointF& point,
163                     const CFX_Vector& delta) override;
164   bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
165                      const CFX_PointF& point) override;
166   bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
167                    const CFX_PointF& point) override;
168   bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override;
169   bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override;
170   bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override;
171   bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override;
172 
173   CFFL_InteractiveFormFiller* GetInteractiveFormFiller();
174 
175 #ifdef PDF_ENABLE_XFA
176   CXFA_FFWidgetHandler* GetXFAWidgetHandler() const;
177   CXFA_FFWidget* GetGroupMixXFAWidget() const;
178   WideString GetName() const;
179   bool HandleXFAAAction(CPDF_AAction::AActionType type,
180                         CFFL_FieldAction* data,
181                         CPDFSDK_FormFillEnvironment* pFormFillEnv);
182 #endif  // PDF_ENABLE_XFA
183 
184   UnownedPtr<CPDFSDK_InteractiveForm> const m_pInteractiveForm;
185   bool m_bAppModified = false;
186   uint32_t m_nAppearanceAge = 0;
187   uint32_t m_nValueAge = 0;
188 };
189 
ToCPDFSDKWidget(CPDFSDK_Annot * pAnnot)190 inline CPDFSDK_Widget* ToCPDFSDKWidget(CPDFSDK_Annot* pAnnot) {
191   return pAnnot && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET
192              ? static_cast<CPDFSDK_Widget*>(pAnnot)
193              : nullptr;
194 }
195 
196 #endif  // FPDFSDK_CPDFSDK_WIDGET_H_
197