K. Moon | 832a694 | 2022-10-31 20:11:31 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_CPDFSDK_WIDGET_H_ |
| 8 | #define FPDFSDK_CPDFSDK_WIDGET_H_ |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 9 | |
Lei Zhang | 24c6be6 | 2024-02-08 20:06:48 +0000 | [diff] [blame] | 10 | #include <optional> |
| 11 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 12 | #include "core/fpdfdoc/cpdf_aaction.h" |
| 13 | #include "core/fpdfdoc/cpdf_action.h" |
| 14 | #include "core/fpdfdoc/cpdf_annot.h" |
Dan Sinclair | a17a0e2 | 2018-03-28 21:10:35 +0000 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_formfield.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/fx_coordinates.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/unowned_ptr.h" |
Tom Sepez | 1e151c6 | 2021-11-22 23:46:09 +0000 | [diff] [blame] | 18 | #include "core/fxcrt/widestring.h" |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 19 | #include "core/fxge/cfx_color.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_baannot.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 21 | |
Lei Zhang | f342da7 | 2022-04-06 23:54:50 +0000 | [diff] [blame] | 22 | class CFFL_InteractiveFormFiller; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 23 | class CFX_RenderDevice; |
| 24 | class CPDF_Annot; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 25 | class CPDF_FormControl; |
| 26 | class CPDF_FormField; |
Tom Sepez | be0591a | 2021-04-16 18:59:33 +0000 | [diff] [blame] | 27 | class CPDFSDK_FormFillEnvironment; |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 28 | class CPDFSDK_InteractiveForm; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 29 | class CPDFSDK_PageView; |
Tom Sepez | c6b91df | 2021-09-11 02:14:19 +0000 | [diff] [blame] | 30 | struct CFFL_FieldAction; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 31 | |
| 32 | #ifdef PDF_ENABLE_XFA |
| 33 | class CXFA_FFWidget; |
| 34 | class CXFA_FFWidgetHandler; |
Tom Sepez | ea38bf5 | 2020-01-15 23:11:12 +0000 | [diff] [blame] | 35 | |
| 36 | enum PDFSDK_XFAAActionType { |
| 37 | PDFSDK_XFA_Click = 0, |
| 38 | PDFSDK_XFA_Full, |
| 39 | PDFSDK_XFA_PreOpen, |
| 40 | PDFSDK_XFA_PostOpen |
| 41 | }; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 42 | #endif // PDF_ENABLE_XFA |
| 43 | |
Tom Sepez | 5586545 | 2018-08-27 20:18:04 +0000 | [diff] [blame] | 44 | class CPDFSDK_Widget final : public CPDFSDK_BAAnnot { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 45 | public: |
Lei Zhang | caf0bb8 | 2021-06-07 18:41:25 +0000 | [diff] [blame] | 46 | enum ValueChanged : bool { kValueUnchanged = false, kValueChanged = true }; |
| 47 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 48 | CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 49 | CPDFSDK_PageView* pPageView, |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 50 | CPDFSDK_InteractiveForm* pInteractiveForm); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 51 | ~CPDFSDK_Widget() override; |
| 52 | |
Tom Sepez | 2419346 | 2020-02-03 18:01:29 +0000 | [diff] [blame] | 53 | // CPDFSDK_BAAnnot: |
Lei Zhang | 5214eeb | 2022-04-04 23:37:28 +0000 | [diff] [blame] | 54 | void OnLoad() override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 55 | CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 56 | bool IsAppearanceValid() override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 57 | int GetLayoutOrder() const override; |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 58 | void OnDraw(CFX_RenderDevice* pDevice, |
| 59 | const CFX_Matrix& mtUser2Device, |
| 60 | bool bDrawAnnots) override; |
Lei Zhang | 37cef93 | 2022-04-05 18:23:29 +0000 | [diff] [blame] | 61 | bool DoHitTest(const CFX_PointF& point) override; |
Lei Zhang | 23a042f | 2022-04-05 23:45:19 +0000 | [diff] [blame] | 62 | CFX_FloatRect GetViewBBox() override; |
Lei Zhang | f342da7 | 2022-04-06 23:54:50 +0000 | [diff] [blame] | 63 | bool CanUndo() override; |
| 64 | bool CanRedo() override; |
| 65 | bool Undo() override; |
| 66 | bool Redo() override; |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 67 | WideString GetText() override; |
| 68 | WideString GetSelectedText() override; |
Keren Zhu | 74e7eb7 | 2023-01-19 19:21:41 +0000 | [diff] [blame] | 69 | void ReplaceAndKeepSelection(const WideString& text) override; |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 70 | void ReplaceSelection(const WideString& text) override; |
| 71 | bool SelectAllText() override; |
| 72 | bool SetIndexSelected(int index, bool selected) override; |
| 73 | bool IsIndexSelected(int index) override; |
Tom Sepez | aa0b2b9 | 2021-10-28 18:38:22 +0000 | [diff] [blame] | 74 | void DrawAppearance(CFX_RenderDevice* pDevice, |
| 75 | const CFX_Matrix& mtUser2Device, |
| 76 | CPDF_Annot::AppearanceMode mode) override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 77 | |
Tom Sepez | 63150f1 | 2021-09-23 01:28:39 +0000 | [diff] [blame] | 78 | bool IsSignatureWidget() const; |
Tom Sepez | c141554 | 2021-09-21 21:48:59 +0000 | [diff] [blame] | 79 | void SetRect(const CFX_FloatRect& rect); |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 80 | FormFieldType GetFieldType() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 81 | int GetFieldFlags() const; |
| 82 | int GetRotate() const; |
| 83 | |
Lei Zhang | 24c6be6 | 2024-02-08 20:06:48 +0000 | [diff] [blame] | 84 | std::optional<FX_COLORREF> GetFillColor() const; |
| 85 | std::optional<FX_COLORREF> GetBorderColor() const; |
| 86 | std::optional<FX_COLORREF> GetTextColor() const; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 87 | float GetFontSize() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 88 | |
| 89 | int GetSelectedIndex(int nIndex) const; |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 90 | WideString GetValue() const; |
Mansi Awasthi | 23bba0e | 2020-05-15 12:18:25 +0000 | [diff] [blame] | 91 | WideString GetExportValue() const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 92 | WideString GetOptionLabel(int nIndex) const; |
Tom Sepez | cc90b0c | 2022-10-27 19:28:22 +0000 | [diff] [blame] | 93 | WideString GetSelectExportText(int nIndex) const; |
| 94 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 95 | int CountOptions() const; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 96 | bool IsOptionSelected(int nIndex) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 97 | int GetTopVisibleIndex() const; |
| 98 | bool IsChecked() const; |
| 99 | int GetAlignment() const; |
| 100 | int GetMaxLen() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 101 | |
Tom Sepez | 6d6bdc3 | 2021-04-15 22:05:16 +0000 | [diff] [blame] | 102 | void SetCheck(bool bChecked); |
| 103 | void SetValue(const WideString& sValue); |
| 104 | void SetOptionSelection(int index); |
| 105 | void ClearSelection(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 106 | void SetTopVisibleIndex(int index); |
| 107 | |
| 108 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 2419346 | 2020-02-03 18:01:29 +0000 | [diff] [blame] | 109 | CXFA_FFWidget* GetMixXFAWidget() const; |
| 110 | bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const; |
| 111 | bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
Tom Sepez | c6b91df | 2021-09-11 02:14:19 +0000 | [diff] [blame] | 112 | CFFL_FieldAction* data, |
Lei Zhang | 2a4010e | 2021-06-07 19:18:25 +0000 | [diff] [blame] | 113 | const CPDFSDK_PageView* pPageView); |
Tom Sepez | 2419346 | 2020-02-03 18:01:29 +0000 | [diff] [blame] | 114 | void Synchronize(bool bSynchronizeElse); |
Lei Zhang | e858d1f | 2019-07-29 23:43:41 +0000 | [diff] [blame] | 115 | // TODO(thestig): Figure out if the parameter should be used or removed. |
Lei Zhang | caf0bb8 | 2021-06-07 18:41:25 +0000 | [diff] [blame] | 116 | void ResetXFAAppearance(ValueChanged bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 117 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 2419346 | 2020-02-03 18:01:29 +0000 | [diff] [blame] | 118 | |
Lei Zhang | 24c6be6 | 2024-02-08 20:06:48 +0000 | [diff] [blame] | 119 | void ResetAppearance(std::optional<WideString> sValue, |
Lei Zhang | 2c49530 | 2021-10-07 23:13:30 +0000 | [diff] [blame] | 120 | ValueChanged bValueChanged); |
Lei Zhang | 0cbfa4a | 2019-07-29 23:10:11 +0000 | [diff] [blame] | 121 | void ResetFieldAppearance(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 122 | void UpdateField(); |
Lei Zhang | 24c6be6 | 2024-02-08 20:06:48 +0000 | [diff] [blame] | 123 | std::optional<WideString> OnFormat(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 124 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 125 | bool OnAAction(CPDF_AAction::AActionType type, |
Tom Sepez | c6b91df | 2021-09-11 02:14:19 +0000 | [diff] [blame] | 126 | CFFL_FieldAction* data, |
Lei Zhang | 2a4010e | 2021-06-07 19:18:25 +0000 | [diff] [blame] | 127 | const CPDFSDK_PageView* pPageView); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 128 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 129 | CPDF_FormField* GetFormField() const; |
| 130 | CPDF_FormControl* GetFormControl() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 131 | |
| 132 | void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView); |
| 133 | |
| 134 | void SetAppModified(); |
| 135 | void ClearAppModified(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | bool IsAppModified() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 137 | |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 138 | uint32_t GetAppearanceAge() const { return m_nAppearanceAge; } |
| 139 | uint32_t GetValueAge() const { return m_nValueAge; } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 140 | |
Tom Sepez | a5bd2fa | 2022-10-25 17:54:27 +0000 | [diff] [blame] | 141 | bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) const; |
| 142 | bool IsPushHighlighted() const; |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 143 | CFX_Matrix GetMatrix() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 144 | CFX_FloatRect GetClientRect() const; |
| 145 | CFX_FloatRect GetRotatedRect() const; |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 146 | CFX_Color GetTextPWLColor() const; |
| 147 | CFX_Color GetBorderPWLColor() const; |
| 148 | CFX_Color GetFillPWLColor() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 149 | |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 150 | private: |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 151 | // CPDFSDK_Annot::UnsafeInputHandlers: |
| 152 | void OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) override; |
| 153 | void OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) override; |
| 154 | bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 155 | const CFX_PointF& point) override; |
| 156 | bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 157 | const CFX_PointF& point) override; |
| 158 | bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, |
| 159 | const CFX_PointF& point) override; |
| 160 | bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, |
| 161 | const CFX_PointF& point) override; |
| 162 | bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, |
| 163 | const CFX_PointF& point, |
| 164 | const CFX_Vector& delta) override; |
| 165 | bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 166 | const CFX_PointF& point) override; |
| 167 | bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 168 | const CFX_PointF& point) override; |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 169 | bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override; |
| 170 | bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override; |
| 171 | bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override; |
| 172 | bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override; |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 173 | |
Lei Zhang | f342da7 | 2022-04-06 23:54:50 +0000 | [diff] [blame] | 174 | CFFL_InteractiveFormFiller* GetInteractiveFormFiller(); |
| 175 | |
Dan Sinclair | 1917cdd | 2018-01-30 17:29:21 +0000 | [diff] [blame] | 176 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 2419346 | 2020-02-03 18:01:29 +0000 | [diff] [blame] | 177 | CXFA_FFWidgetHandler* GetXFAWidgetHandler() const; |
Lei Zhang | b353f8c | 2018-10-10 18:39:14 +0000 | [diff] [blame] | 178 | CXFA_FFWidget* GetGroupMixXFAWidget() const; |
Dan Sinclair | 1917cdd | 2018-01-30 17:29:21 +0000 | [diff] [blame] | 179 | WideString GetName() const; |
Tom Sepez | be0591a | 2021-04-16 18:59:33 +0000 | [diff] [blame] | 180 | bool HandleXFAAAction(CPDF_AAction::AActionType type, |
Tom Sepez | c6b91df | 2021-09-11 02:14:19 +0000 | [diff] [blame] | 181 | CFFL_FieldAction* data, |
Tom Sepez | be0591a | 2021-04-16 18:59:33 +0000 | [diff] [blame] | 182 | CPDFSDK_FormFillEnvironment* pFormFillEnv); |
Dan Sinclair | 1917cdd | 2018-01-30 17:29:21 +0000 | [diff] [blame] | 183 | #endif // PDF_ENABLE_XFA |
| 184 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 185 | UnownedPtr<CPDFSDK_InteractiveForm> const m_pInteractiveForm; |
Lei Zhang | c1bf998 | 2018-10-09 19:14:15 +0000 | [diff] [blame] | 186 | bool m_bAppModified = false; |
| 187 | uint32_t m_nAppearanceAge = 0; |
| 188 | uint32_t m_nValueAge = 0; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 191 | inline CPDFSDK_Widget* ToCPDFSDKWidget(CPDFSDK_Annot* pAnnot) { |
| 192 | return pAnnot && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET |
| 193 | ? static_cast<CPDFSDK_Widget*>(pAnnot) |
| 194 | : nullptr; |
| 195 | } |
| 196 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 197 | #endif // FPDFSDK_CPDFSDK_WIDGET_H_ |