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" |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 15 | #include "core/fxcrt/cfx_unowned_ptr.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/fx_coordinates.h" |
| 17 | #include "core/fxcrt/fx_string.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 |
| 85 | CFX_WideString GetValue() const; |
| 86 | #else |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 87 | CFX_WideString GetValue(bool bDisplay = true) const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 88 | #endif // PDF_ENABLE_XFA |
| 89 | CFX_WideString GetDefaultValue() const; |
| 90 | CFX_WideString GetOptionLabel(int nIndex) const; |
| 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 |
| 98 | CFX_WideString GetName() const; |
| 99 | #endif // PDF_ENABLE_XFA |
| 100 | CFX_WideString GetAlternateName() const; |
| 101 | |
| 102 | void SetCheck(bool bChecked, bool bNotify); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 103 | void SetValue(const CFX_WideString& sValue, bool bNotify); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 104 | void SetDefaultValue(const CFX_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 |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 112 | void ResetAppearance(const CFX_WideString* sValue, bool bValueChanged); |
| 113 | void ResetFieldAppearance(bool bValueChanged); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 114 | void UpdateField(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 115 | CFX_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 | |
| 133 | int32_t GetAppearanceAge() const; |
| 134 | int32_t GetValueAge() const; |
| 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, |
| 138 | const CFX_Matrix* pUser2Device, |
| 139 | CPDF_Annot::AppearanceMode mode, |
| 140 | const CPDF_RenderOptions* pOptions) override; |
| 141 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 142 | private: |
| 143 | void ResetAppearance_PushButton(); |
| 144 | void ResetAppearance_CheckBox(); |
| 145 | void ResetAppearance_RadioButton(); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 146 | void ResetAppearance_ComboBox(const CFX_WideString* sValue); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 147 | void ResetAppearance_ListBox(); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 148 | void ResetAppearance_TextField(const CFX_WideString* sValue); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 149 | |
| 150 | CFX_FloatRect GetClientRect() const; |
| 151 | CFX_FloatRect GetRotatedRect() const; |
| 152 | |
| 153 | CFX_ByteString GetBackgroundAppStream() const; |
| 154 | CFX_ByteString GetBorderAppStream() const; |
| 155 | CFX_Matrix GetMatrix() const; |
| 156 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame^] | 157 | CFX_Color GetTextPWLColor() const; |
| 158 | CFX_Color GetBorderPWLColor() const; |
| 159 | CFX_Color GetFillPWLColor() const; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 160 | |
| 161 | void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage); |
| 162 | void RemoveAppearance(const CFX_ByteString& sAPType); |
| 163 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame] | 164 | CFX_UnownedPtr<CPDFSDK_InterForm> const m_pInterForm; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 165 | bool m_bAppModified; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 166 | int32_t m_nAppAge; |
| 167 | int32_t m_nValueAge; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 168 | |
| 169 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 170 | mutable CFX_UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget; |
| 171 | mutable CFX_UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 172 | #endif // PDF_ENABLE_XFA |
| 173 | }; |
| 174 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 175 | #endif // FPDFSDK_CPDFSDK_WIDGET_H_ |