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_WIDGET_H_ 8 #define FPDFSDK_CPDFSDK_WIDGET_H_ 9 10 #include <set> 11 12 #include "core/fpdfdoc/cpdf_aaction.h" 13 #include "core/fpdfdoc/cpdf_action.h" 14 #include "core/fpdfdoc/cpdf_annot.h" 15 #include "core/fxcrt/fx_coordinates.h" 16 #include "core/fxcrt/fx_string.h" 17 #include "core/fxcrt/unowned_ptr.h" 18 #include "core/fxge/cfx_color.h" 19 #include "fpdfsdk/cpdfsdk_baannot.h" 20 #include "fpdfsdk/pdfsdk_fieldaction.h" 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: 39 #ifdef PDF_ENABLE_XFA 40 CXFA_FFWidget* GetMixXFAWidget() const; 41 CXFA_FFWidget* GetGroupMixXFAWidget(); 42 CXFA_FFWidgetHandler* GetXFAWidgetHandler() const; 43 44 bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT); 45 bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, 46 PDFSDK_FieldAction& data, 47 CPDFSDK_PageView* pPageView); 48 49 void Synchronize(bool bSynchronizeElse); 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 68 bool IsSignatureWidget() const override; 69 CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override; 70 bool IsAppearanceValid() override; 71 72 int GetLayoutOrder() const override; 73 74 FormFieldType GetFieldType() const; 75 int GetFieldFlags() const; 76 int GetRotate() const; 77 78 bool GetFillColor(FX_COLORREF& color) const; 79 bool GetBorderColor(FX_COLORREF& color) const; 80 bool GetTextColor(FX_COLORREF& color) const; 81 float GetFontSize() const; 82 83 int GetSelectedIndex(int nIndex) const; 84 #ifndef PDF_ENABLE_XFA 85 WideString GetValue() const; 86 #else 87 WideString GetValue(bool bDisplay = true) const; 88 #endif // PDF_ENABLE_XFA 89 WideString GetDefaultValue() const; 90 WideString GetOptionLabel(int nIndex) const; 91 int CountOptions() const; 92 bool IsOptionSelected(int nIndex) const; 93 int GetTopVisibleIndex() const; 94 bool IsChecked() const; 95 int GetAlignment() const; 96 int GetMaxLen() const; 97 #ifdef PDF_ENABLE_XFA 98 WideString GetName() const; 99 #endif // PDF_ENABLE_XFA 100 WideString GetAlternateName() const; 101 102 void SetCheck(bool bChecked, bool bNotify); 103 void SetValue(const WideString& sValue, bool bNotify); 104 void SetDefaultValue(const WideString& sValue); 105 void SetOptionSelection(int index, bool bSelected, bool bNotify); 106 void ClearSelection(bool bNotify); 107 void SetTopVisibleIndex(int index); 108 109 #ifdef PDF_ENABLE_XFA 110 void ResetAppearance(bool bValueChanged); 111 #endif // PDF_ENABLE_XFA 112 void ResetAppearance(const WideString* sValue, bool bValueChanged); 113 void ResetFieldAppearance(bool bValueChanged); 114 void UpdateField(); 115 WideString OnFormat(bool& bFormatted); 116 117 bool OnAAction(CPDF_AAction::AActionType type, 118 PDFSDK_FieldAction& data, 119 CPDFSDK_PageView* pPageView); 120 GetInterForm()121 CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); } 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(); 131 bool IsAppModified() const; 132 GetAppearanceAge()133 uint32_t GetAppearanceAge() const { return m_nAppearanceAge; } GetValueAge()134 uint32_t GetValueAge() const { return m_nValueAge; } 135 136 bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode); 137 void DrawAppearance(CFX_RenderDevice* pDevice, 138 const CFX_Matrix& mtUser2Device, 139 CPDF_Annot::AppearanceMode mode, 140 const CPDF_RenderOptions* pOptions) override; 141 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 UnownedPtr<CPDFSDK_InterForm> const m_pInterForm; 151 bool m_bAppModified; 152 uint32_t m_nAppearanceAge; 153 uint32_t m_nValueAge; 154 155 #ifdef PDF_ENABLE_XFA 156 mutable UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget; 157 mutable UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler; 158 #endif // PDF_ENABLE_XFA 159 }; 160 161 #endif // FPDFSDK_CPDFSDK_WIDGET_H_ 162