Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_formfield.h
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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 <stddef.h>
11#include <stdint.h>
12
13#include <utility>
14#include <vector>
15
16#include "core/fpdfdoc/cpdf_aaction.h"
17#include "core/fxcrt/fx_string.h"
18#include "core/fxcrt/retain_ptr.h"
19#include "core/fxcrt/unowned_ptr.h"
20
21class CPDF_Dictionary;
24class CPDF_Object;
25class CPDF_String;
26
27enum class NotificationOption : bool { kDoNotNotify = false, kNotify = true };
28
29enum class FormFieldType : uint8_t {
30 kUnknown = 0,
31 kPushButton = 1,
32 kCheckBox = 2,
33 kRadioButton = 3,
34 kComboBox = 4,
35 kListBox = 5,
36 kTextField = 6,
37 kSignature = 7,
38#ifdef PDF_ENABLE_XFA
39 kXFA = 8, // Generic XFA field, should use value below if possible.
40 kXFA_CheckBox = 9,
41 kXFA_ComboBox = 10,
42 kXFA_ImageField = 11,
43 kXFA_ListBox = 12,
44 kXFA_PushButton = 13,
45 kXFA_Signature = 14,
47#endif // PDF_ENABLE_XFA
48};
49
50// If values are added to FormFieldType, these will need to be updated.
51#ifdef PDF_ENABLE_XFA
52constexpr size_t kFormFieldTypeCount = 16;
53#else // PDF_ENABLE_XFA
55#endif // PDF_ENABLE_XFA
56
58 public:
71
72 CPDF_FormField(CPDF_InteractiveForm* pForm, RetainPtr<CPDF_Dictionary> pDict);
74
76 static WideString GetFullNameForDict(const CPDF_Dictionary* pFieldDict);
78 const CPDF_Dictionary* pFieldDict,
79 const ByteString& name);
81 CPDF_Dictionary* pFieldDict,
82 const ByteString& name);
83
84 WideString GetFullName() const;
85 Type GetType() const { return m_Type; }
86
87 RetainPtr<const CPDF_Object> GetFieldAttr(const ByteString& name) const;
88 RetainPtr<const CPDF_Dictionary> GetFieldDict() const;
89 bool ResetField();
90
91 int CountControls() const;
92 CPDF_FormControl* GetControl(int index) const;
93 int GetControlIndex(const CPDF_FormControl* pControl) const;
94
96
98 WideString GetAlternateName() const;
99 WideString GetMappingName() const;
100
101 uint32_t GetFieldFlags() const;
102 void SetFieldFlags(uint32_t dwFlags);
103
104 bool IsRequired() const { return m_bRequired; }
105 bool IsNoExport() const { return m_bNoExport; }
106
107 WideString GetValue() const;
108 WideString GetDefaultValue() const;
109 bool SetValue(const WideString& value, NotificationOption notify);
110
111 int GetMaxLen() const;
112 int CountSelectedItems() const;
113 int GetSelectedIndex(int index) const;
114
116 bool IsItemSelected(int index) const;
117 bool SetItemSelection(int index, NotificationOption notify);
118
119 int GetDefaultSelectedItem() const;
120 int CountOptions() const;
121 WideString GetOptionLabel(int index) const;
122 WideString GetOptionValue(int index) const;
123 int FindOption(const WideString& csOptValue) const;
124
125 bool CheckControl(int iControlIndex,
126 bool bChecked,
127 NotificationOption notify);
128
129 int GetTopVisibleIndex() const;
130 int CountSelectedOptions() const;
131 int GetSelectedOptionIndex(int index) const;
132 bool IsSelectedOption(const WideString& wsOptValue) const;
133 bool IsSelectedIndex(int iOptIndex) const;
134 void SelectOption(int iOptIndex);
135
136 // Verifies if there is a valid selected indicies (/I) object and whether its
137 // entries are consistent with the value (/V) object.
138 bool UseSelectedIndicesObject() const;
139
140 WideString GetCheckValue(bool bDefault) const;
141
142 private:
143 WideString GetValue(bool bDefault) const;
144 bool SetValue(const WideString& value,
145 bool bDefault,
146 NotificationOption notify);
147 void InitFieldFlags();
148 int FindListSel(CPDF_String* str);
149 WideString GetOptionText(int index, int sub_index) const;
150 bool SetCheckValue(const WideString& value,
151 bool bDefault,
152 NotificationOption notify);
153 void SetItemSelectionSelected(int index, const WideString& opt_value);
154 bool NotifyListOrComboBoxBeforeChange(const WideString& value);
155 void NotifyListOrComboBoxAfterChange();
156
157 RetainPtr<const CPDF_Object> GetFieldAttrInternal(
158 const ByteString& name) const;
159 const CPDF_Dictionary* GetFieldDictInternal() const;
160 RetainPtr<const CPDF_Object> GetDefaultValueObject() const;
161 RetainPtr<const CPDF_Object> GetValueObject() const;
162
163 // For choice fields.
164 RetainPtr<const CPDF_Object> GetSelectedIndicesObject() const;
165
166 // For choice fields.
167 // Value object takes precedence over selected indices object.
168 RetainPtr<const CPDF_Object> GetValueOrSelectedIndicesObject() const;
169
170 const std::vector<UnownedPtr<CPDF_FormControl>>& GetControls() const;
171
172 CPDF_FormField::Type m_Type = kUnknown;
173 bool m_bRequired = false;
174 bool m_bNoExport = false;
175 bool m_bIsMultiSelectListBox = false;
176 bool m_bIsUnison = false;
177 bool m_bUseSelectedIndices = false;
178 UnownedPtr<CPDF_InteractiveForm> const m_pForm;
179 RetainPtr<CPDF_Dictionary> const m_pDict;
180};
181
182#endif // CORE_FPDFDOC_CPDF_FORMFIELD_H_
constexpr CFX_FloatRect(float l, float b, float r, float t)
float Width() const
float Height() const
void Translate(float e, float f)
CPDF_Annot * GetAt(size_t index) const
size_t Count() const
bool Contains(const CPDF_Annot *pAnnot) const
void DisplayAnnots(CPDF_Page *pPage, CFX_RenderDevice *pDevice, CPDF_RenderContext *pContext, bool bPrinting, const CFX_Matrix &mtUser2Device, bool bShowWidget)
~CPDF_AnnotList() override
CPDF_AnnotList(CPDF_Page *pPage)
Subtype GetSubtype() const
const CPDF_Dictionary * GetAnnotDict() const
Definition cpdf_annot.h:83
void SetPopupAnnot(CPDF_Annot *pAnnot)
Definition cpdf_annot.h:103
bool KeyExist(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
CFX_FloatRect GetRectFor(const ByteString &key) const
RetainPtr< const CPDF_Object > GetFieldAttr(const ByteString &name) const
int GetSelectedIndex(int index) const
bool IsSelectedIndex(int iOptIndex) const
bool UseSelectedIndicesObject() const
static WideString GetFullNameForDict(const CPDF_Dictionary *pFieldDict)
int CountOptions() const
int GetDefaultSelectedItem() const
bool IsSelectedOption(const WideString &wsOptValue) const
void SelectOption(int iOptIndex)
WideString GetMappingName() const
WideString GetValue() const
WideString GetFullName() const
static RetainPtr< const CPDF_Object > GetFieldAttrForDict(const CPDF_Dictionary *pFieldDict, const ByteString &name)
int CountControls() const
int FindOption(const WideString &csOptValue) const
uint32_t GetFieldFlags() const
bool IsRequired() const
WideString GetAlternateName() const
bool ClearSelection(NotificationOption notify)
int GetControlIndex(const CPDF_FormControl *pControl) const
int GetSelectedOptionIndex(int index) const
bool SetItemSelection(int index, NotificationOption notify)
int GetMaxLen() const
bool IsItemSelected(int index) const
static RetainPtr< CPDF_Object > GetMutableFieldAttrForDict(CPDF_Dictionary *pFieldDict, const ByteString &name)
WideString GetOptionLabel(int index) const
static absl::optional< FormFieldType > IntToFormFieldType(int value)
bool IsNoExport() const
int CountSelectedOptions() const
int CountSelectedItems() const
WideString GetCheckValue(bool bDefault) const
CPDF_FormControl * GetControl(int index) const
int GetTopVisibleIndex() const
Type GetType() const
FormFieldType GetFieldType() const
WideString GetOptionValue(int index) const
CPDF_AAction GetAdditionalAction() const
RetainPtr< const CPDF_Dictionary > GetFieldDict() const
WideString GetDefaultValue() const
CPDF_FormField(CPDF_InteractiveForm *pForm, RetainPtr< CPDF_Dictionary > pDict)
bool CheckControl(int iControlIndex, bool bChecked, NotificationOption notify)
void SetFieldFlags(uint32_t dwFlags)
bool SetValue(const WideString &value, NotificationOption notify)
static void GenerateFormAP(CPDF_Document *pDoc, CPDF_Dictionary *pAnnotDict, FormType type)
float GetPageWidth() const override
Definition cpdf_page.cpp:55
bool operator==(const char *ptr) const
bool operator!=(const char *ptr) const
Definition bytestring.h:130
NotificationOption
FormFieldType
constexpr size_t kFormFieldTypeCount
constexpr uint32_t kChoiceDoNotSpellCheck
Definition form_flags.h:40
constexpr uint32_t kReadOnly
Definition form_flags.h:13
constexpr uint32_t kChoiceEdit
Definition form_flags.h:37
constexpr uint32_t kButtonPushbutton
Definition form_flags.h:21
constexpr uint32_t kTextFileSelect
Definition form_flags.h:28
constexpr uint32_t kButtonRadiosInUnison
Definition form_flags.h:22
constexpr uint32_t kChoiceSort
Definition form_flags.h:38
constexpr uint32_t kChoiceCombo
Definition form_flags.h:36
constexpr uint32_t kTextPassword
Definition form_flags.h:27
constexpr uint32_t kTextDoNotSpellCheck
Definition form_flags.h:29
constexpr uint32_t kRequired
Definition form_flags.h:14
constexpr uint32_t kButtonNoToggleToOff
Definition form_flags.h:19
constexpr uint32_t kChoiceCommitOnSelChange
Definition form_flags.h:41
constexpr uint32_t kButtonRadio
Definition form_flags.h:20
constexpr uint32_t kChoiceMultiSelect
Definition form_flags.h:39
constexpr uint32_t kNoExport
Definition form_flags.h:15
constexpr uint32_t kTextDoNotScroll
Definition form_flags.h:30
constexpr uint32_t kTextRichText
Definition form_flags.h:32
constexpr uint32_t kTextComb
Definition form_flags.h:31
constexpr uint32_t kTextMultiline
Definition form_flags.h:26