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 CORE_FPDFDOC_CPDF_FORMFIELD_H_ 8 #define CORE_FPDFDOC_CPDF_FORMFIELD_H_ 9 10 #include <vector> 11 12 #include "core/fpdfdoc/cpdf_aaction.h" 13 #include "core/fpdfdoc/cpdf_formfield.h" 14 #include "core/fxcrt/fx_basic.h" 15 #include "core/fxcrt/fx_string.h" 16 #include "core/fxcrt/fx_system.h" 17 #include "third_party/base/stl_util.h" 18 19 #define FIELDTYPE_UNKNOWN 0 20 #define FIELDTYPE_PUSHBUTTON 1 21 #define FIELDTYPE_CHECKBOX 2 22 #define FIELDTYPE_RADIOBUTTON 3 23 #define FIELDTYPE_COMBOBOX 4 24 #define FIELDTYPE_LISTBOX 5 25 #define FIELDTYPE_TEXTFIELD 6 26 #define FIELDTYPE_SIGNATURE 7 27 28 #define FORMFLAG_READONLY 0x01 29 #define FORMFLAG_REQUIRED 0x02 30 #define FORMFLAG_NOEXPORT 0x04 31 32 class CPDF_Dictionary; 33 class CPDF_Font; 34 class CPDF_FormControl; 35 class CPDF_InterForm; 36 class CPDF_String; 37 38 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, 39 const FX_CHAR* name, 40 int nLevel = 0); 41 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict); 42 43 class CPDF_FormField { 44 public: 45 enum Type { 46 Unknown, 47 PushButton, 48 RadioButton, 49 CheckBox, 50 Text, 51 RichText, 52 File, 53 ListBox, 54 ComboBox, 55 Sign 56 }; 57 58 CFX_WideString GetFullName() const; 59 GetType()60 Type GetType() const { return m_Type; } GetFlags()61 uint32_t GetFlags() const { return m_Flags; } 62 GetFieldDict()63 CPDF_Dictionary* GetFieldDict() const { return m_pDict; } SetFieldDict(CPDF_Dictionary * pDict)64 void SetFieldDict(CPDF_Dictionary* pDict) { m_pDict = pDict; } 65 66 bool ResetField(bool bNotify = false); 67 CountControls()68 int CountControls() const { 69 return pdfium::CollectionSize<int>(m_ControlList); 70 } 71 GetControl(int index)72 CPDF_FormControl* GetControl(int index) const { return m_ControlList[index]; } 73 74 int GetControlIndex(const CPDF_FormControl* pControl) const; 75 int GetFieldType() const; 76 77 CPDF_AAction GetAdditionalAction() const; 78 CFX_WideString GetAlternateName() const; 79 CFX_WideString GetMappingName() const; 80 81 uint32_t GetFieldFlags() const; 82 CFX_ByteString GetDefaultStyle() const; 83 CFX_WideString GetRichTextString() const; 84 85 CFX_WideString GetValue() const; 86 CFX_WideString GetDefaultValue() const; 87 bool SetValue(const CFX_WideString& value, bool bNotify = false); 88 89 int GetMaxLen() const; 90 int CountSelectedItems() const; 91 int GetSelectedIndex(int index) const; 92 93 bool ClearSelection(bool bNotify = false); 94 bool IsItemSelected(int index) const; 95 bool SetItemSelection(int index, bool bSelected, bool bNotify = false); 96 97 bool IsItemDefaultSelected(int index) const; 98 99 int GetDefaultSelectedItem() const; 100 int CountOptions() const; 101 102 CFX_WideString GetOptionLabel(int index) const; 103 CFX_WideString GetOptionValue(int index) const; 104 105 int FindOption(CFX_WideString csOptLabel) const; 106 int FindOptionValue(const CFX_WideString& csOptValue) const; 107 108 bool CheckControl(int iControlIndex, bool bChecked, bool bNotify = false); 109 110 int GetTopVisibleIndex() const; 111 int CountSelectedOptions() const; 112 113 int GetSelectedOptionIndex(int index) const; 114 bool IsOptionSelected(int iOptIndex) const; 115 116 bool SelectOption(int iOptIndex, bool bSelected, bool bNotify = false); 117 118 bool ClearSelectedOptions(bool bNotify = false); 119 120 #ifdef PDF_ENABLE_XFA 121 bool ClearOptions(bool bNotify = false); 122 123 int InsertOption(CFX_WideString csOptLabel, 124 int index = -1, 125 bool bNotify = false); 126 #endif // PDF_ENABLE_XFA 127 GetFontSize()128 FX_FLOAT GetFontSize() const { return m_FontSize; } GetFont()129 CPDF_Font* GetFont() const { return m_pFont; } 130 131 private: 132 friend class CPDF_InterForm; 133 friend class CPDF_FormControl; 134 135 CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict); 136 ~CPDF_FormField(); 137 138 CFX_WideString GetValue(bool bDefault) const; 139 bool SetValue(const CFX_WideString& value, bool bDefault, bool bNotify); 140 141 void SyncFieldFlags(); 142 int FindListSel(CPDF_String* str); 143 CFX_WideString GetOptionText(int index, int sub_index) const; 144 145 void LoadDA(); 146 CFX_WideString GetCheckValue(bool bDefault) const; 147 bool SetCheckValue(const CFX_WideString& value, bool bDefault, bool bNotify); 148 149 bool NotifyBeforeSelectionChange(const CFX_WideString& value); 150 void NotifyAfterSelectionChange(); 151 152 bool NotifyBeforeValueChange(const CFX_WideString& value); 153 void NotifyAfterValueChange(); 154 155 bool NotifyListOrComboBoxBeforeChange(const CFX_WideString& value); 156 void NotifyListOrComboBoxAfterChange(); 157 158 CPDF_FormField::Type m_Type; 159 uint32_t m_Flags; 160 CPDF_InterForm* const m_pForm; 161 CPDF_Dictionary* m_pDict; 162 std::vector<CPDF_FormControl*> m_ControlList; // Owned by InterForm parent. 163 FX_FLOAT m_FontSize; 164 CPDF_Font* m_pFont; 165 }; 166 167 #endif // CORE_FPDFDOC_CPDF_FORMFIELD_H_ 168