jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 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 | |
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 | |
| 10 | #include <set> |
| 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" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 15 | #include "core/fxcrt/fx_coordinates.h" |
| 16 | #include "core/fxcrt/fx_string.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/unowned_ptr.h" |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 18 | #include "core/fxge/cfx_color.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_baannot.h" |
| 20 | #include "fpdfsdk/pdfsdk_fieldaction.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 21 | |
| 22 | class CFX_RenderDevice; |
| 23 | class CPDF_Annot; |
| 24 | class CPDF_Dictionary; |
| 25 | class CPDF_FormControl; |
| 26 | class CPDF_FormField; |
| 27 | class CPDF_RenderOptions; |
| 28 | class CPDF_Stream; |
| 29 | class CPDFSDK_InterForm; |
| 30 | class CPDFSDK_PageView; |
| 31 | |
| 32 | #ifdef PDF_ENABLE_XFA |
| 33 | class CXFA_FFWidget; |
| 34 | class CXFA_FFWidgetHandler; |
| 35 | #endif // PDF_ENABLE_XFA |
| 36 | |
| 37 | class CPDFSDK_Widget : public CPDFSDK_BAAnnot { |
| 38 | public: |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 39 | #ifdef PDF_ENABLE_XFA |
| 40 | CXFA_FFWidget* GetMixXFAWidget() const; |
| 41 | CXFA_FFWidget* GetGroupMixXFAWidget(); |
| 42 | CXFA_FFWidgetHandler* GetXFAWidgetHandler() const; |
| 43 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 44 | bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT); |
| 45 | bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 46 | PDFSDK_FieldAction& data, |
| 47 | CPDFSDK_PageView* pPageView); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 48 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 49 | void Synchronize(bool bSynchronizeElse); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 50 | void SynchronizeXFAValue(); |
| 51 | void SynchronizeXFAItems(); |
| 52 | |
| 53 | static void SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
| 54 | CXFA_FFWidget* hWidget, |
| 55 | CPDF_FormField* pFormField, |
| 56 | CPDF_FormControl* pFormControl); |
| 57 | static void SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, |
| 58 | CXFA_FFWidget* hWidget, |
| 59 | CPDF_FormField* pFormField, |
| 60 | CPDF_FormControl* pFormControl); |
| 61 | #endif // PDF_ENABLE_XFA |
| 62 | |
| 63 | CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 64 | CPDFSDK_PageView* pPageView, |
| 65 | CPDFSDK_InterForm* pInterForm); |
| 66 | ~CPDFSDK_Widget() override; |
| 67 | |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 68 | bool IsSignatureWidget() const override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 69 | CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 70 | bool IsAppearanceValid() override; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 71 | |
| 72 | int GetLayoutOrder() const override; |
| 73 | |
| 74 | int GetFieldType() const; |
| 75 | int GetFieldFlags() const; |
| 76 | int GetRotate() const; |
| 77 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 78 | bool GetFillColor(FX_COLORREF& color) const; |
| 79 | bool GetBorderColor(FX_COLORREF& color) const; |
| 80 | bool GetTextColor(FX_COLORREF& color) const; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 81 | float GetFontSize() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 82 | |
| 83 | int GetSelectedIndex(int nIndex) const; |
| 84 | #ifndef PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 85 | WideString GetValue() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 86 | #else |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 87 | WideString GetValue(bool bDisplay = true) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 88 | #endif // PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 89 | WideString GetDefaultValue() const; |
| 90 | WideString GetOptionLabel(int nIndex) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 91 | int CountOptions() const; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 92 | bool IsOptionSelected(int nIndex) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 93 | int GetTopVisibleIndex() const; |
| 94 | bool IsChecked() const; |
| 95 | int GetAlignment() const; |
| 96 | int GetMaxLen() const; |
| 97 | #ifdef PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 98 | WideString GetName() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 99 | #endif // PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 100 | WideString GetAlternateName() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 101 | |
| 102 | void SetCheck(bool bChecked, bool bNotify); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 103 | void SetValue(const WideString& sValue, bool bNotify); |
| 104 | void SetDefaultValue(const WideString& sValue); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 105 | void SetOptionSelection(int index, bool bSelected, bool bNotify); |
| 106 | void ClearSelection(bool bNotify); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 107 | void SetTopVisibleIndex(int index); |
| 108 | |
| 109 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 110 | void ResetAppearance(bool bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 111 | #endif // PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 112 | void ResetAppearance(const WideString* sValue, bool bValueChanged); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 113 | void ResetFieldAppearance(bool bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 114 | void UpdateField(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 115 | WideString OnFormat(bool& bFormatted); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 116 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 117 | bool OnAAction(CPDF_AAction::AActionType type, |
| 118 | PDFSDK_FieldAction& data, |
| 119 | CPDFSDK_PageView* pPageView); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 120 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame] | 121 | CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 122 | CPDF_FormField* GetFormField() const; |
| 123 | CPDF_FormControl* GetFormControl() const; |
| 124 | static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm, |
| 125 | const CPDF_Dictionary* pAnnotDict); |
| 126 | |
| 127 | void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView); |
| 128 | |
| 129 | void SetAppModified(); |
| 130 | void ClearAppModified(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 131 | bool IsAppModified() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 132 | |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 133 | uint32_t GetAppearanceAge() const { return m_nAppearanceAge; } |
| 134 | uint32_t GetValueAge() const { return m_nValueAge; } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 135 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 137 | void DrawAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 138 | const CFX_Matrix& mtUser2Device, |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 139 | CPDF_Annot::AppearanceMode mode, |
| 140 | const CPDF_RenderOptions* pOptions) override; |
| 141 | |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 142 | CFX_Matrix GetMatrix() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 143 | CFX_FloatRect GetClientRect() const; |
| 144 | CFX_FloatRect GetRotatedRect() const; |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 145 | CFX_Color GetTextPWLColor() const; |
| 146 | CFX_Color GetBorderPWLColor() const; |
| 147 | CFX_Color GetFillPWLColor() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 148 | |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 149 | private: |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 150 | UnownedPtr<CPDFSDK_InterForm> const m_pInterForm; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 151 | bool m_bAppModified; |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 152 | uint32_t m_nAppearanceAge; |
| 153 | uint32_t m_nValueAge; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 154 | |
| 155 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 156 | mutable UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget; |
| 157 | mutable UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 158 | #endif // PDF_ENABLE_XFA |
| 159 | }; |
| 160 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 161 | #endif // FPDFSDK_CPDFSDK_WIDGET_H_ |