12#include "PdfAnnotationWidget.h"
14#include "PdfFieldChildrenCollection.h"
20class PdfAnnotationWidget;
29class PODOFO_API PdfField :
public PdfDictionaryElement
31 friend class PdfSignature;
32 friend class PdfButton;
33 friend class PdChoiceField;
34 friend class PdfTextBox;
36 friend class PdfAcroForm;
37 friend class PdfAnnotationWidget;
38 friend class PdfFieldChildrenCollectionBase;
43 PdfButton_NoToggleOff = 0x0004000,
44 PdfButton_Radio = 0x0008000,
45 PdfButton_PushButton = 0x0010000,
46 PdfButton_RadioInUnison = 0x2000000,
47 PdfListField_Combo = 0x0020000,
48 PdfListField_Edit = 0x0040000,
49 PdfListField_Sort = 0x0080000,
50 PdfListField_MultiSelect = 0x0200000,
51 PdfListField_NoSpellcheck = 0x0400000,
52 PdfListField_CommitOnSelChange = 0x4000000
56 PdfField(PdfAcroForm& acroform, PdfFieldType fieldType,
57 std::shared_ptr<PdfField>&& parent);
59 PdfField(PdfAnnotationWidget& widget, PdfFieldType fieldType,
60 std::shared_ptr<PdfField>&& parent);
62 PdfField(PdfObject& obj, PdfAcroForm* acroform, PdfFieldType fieldType);
67 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<PdfField>& field);
69 PdfField* GetParentSafe();
70 const PdfField* GetParentSafe()
const;
78 void SetHighlightingMode(PdfHighlightingMode mode);
90 void SetName(nullable<const PdfString&> name);
97 PdfObject* GetValueObject();
98 const PdfObject* GetValueObject()
const;
101 nullable<const PdfString&> GetName()
const;
104 nullable<const PdfString&> GetNameRaw()
const;
109 std::string GetFullName(
bool skipEscapePartialName =
false)
const;
116 void SetAlternateName(nullable<const PdfString&> name);
119 nullable<const PdfString&> GetAlternateName()
const;
125 void SetMappingName(nullable<const PdfString&> name);
128 nullable<const PdfString&> GetMappingName()
const;
137 void SetReadOnly(
bool readOnly);
142 bool IsReadOnly()
const;
148 void SetRequired(
bool required);
153 bool IsRequired()
const;
160 void SetNoExport(
bool exprt);
165 bool IsNoExport()
const;
167 void SetMouseEnterAction(
const PdfAction& action);
168 void SetMouseLeaveAction(
const PdfAction& action);
169 void SetMouseDownAction(
const PdfAction& action);
170 void SetMouseUpAction(
const PdfAction& action);
172 void SetFocusEnterAction(
const PdfAction& action);
173 void SetFocusLeaveAction(
const PdfAction& action);
175 void SetPageOpenAction(
const PdfAction& action);
176 void SetPageCloseAction(
const PdfAction& action);
178 void SetPageVisibleAction(
const PdfAction& action);
179 void SetPageInvisibleAction(
const PdfAction& action);
181 void SetKeystrokeAction(
const PdfAction& action);
182 void SetValidateAction(
const PdfAction& action);
187 PdfAnnotationWidget* GetWidget() {
return m_Widget; }
189 const PdfAnnotationWidget* GetWidget()
const {
return m_Widget; }
191 PdfAnnotationWidget& MustGetWidget();
193 const PdfAnnotationWidget& MustGetWidget()
const;
195 PdfFieldChildrenCollectionBase& GetChildren();
197 const PdfFieldChildrenCollectionBase& GetChildren()
const;
207 void SetFieldFlag(int64_t value,
bool set);
215 bool GetFieldFlag(int64_t value,
bool defvalue)
const;
220 static bool GetFieldFlags(
const PdfObject& obj, int64_t& value);
222 virtual PdfObject* getValueObject()
const;
224 void AssertTerminalField()
const;
226 template <
typename TField>
227 TField* GetParentTyped(PdfFieldType type)
const;
230 template <
typename TField>
233 void SetWidget(PdfAnnotationWidget& widget) { m_Widget = &widget; }
234 void SetAcroForm(PdfAcroForm& acroform) { m_AcroForm = &acroform; }
238 static PdfField&
Create(
const std::string_view& name,
239 PdfAnnotationWidget& widget, PdfFieldType fieldType);
242 static std::unique_ptr<PdfField>
Create(
const std::string_view& name,
243 PdfAcroForm& acroform, PdfFieldType fieldType);
244 static std::unique_ptr<PdfField>
Create(PdfObject& obj, PdfAcroForm& acroform,
245 PdfFieldType fieldType);
248 std::unique_ptr<PdfField> CreateChild();
249 std::unique_ptr<PdfField> CreateChild(PdfPage& page,
const Rect& rect);
250 void SetParent(std::shared_ptr<PdfField>&& parent);
253 PdfField(
const PdfField& rhs) =
delete;
254 PdfField& operator=(
const PdfField& rhs) =
delete;
257 static std::unique_ptr<PdfField> createField(PdfAnnotationWidget& widget,
258 PdfFieldType type, std::shared_ptr<PdfField>&& parent,
bool insertInAcroform);
260 static std::unique_ptr<PdfField> createField(PdfAcroForm& acroform, PdfFieldType type,
261 std::shared_ptr<PdfField>&& parent);
263 static void linkFieldObjectToParent(
const std::shared_ptr<PdfField>& field, PdfField& parentField,
264 cspan<std::string_view> parentKeys,
bool setParent,
bool moveKeysToParent);
269 void ensureAccessibilityIfNeeded(
const std::string_view& fieldName);
270 void setName(
const PdfString& name);
271 void addAlternativeAction(
const PdfName& name,
const PdfAction& action);
272 static bool tryCreateField(PdfObject& obj, PdfFieldType type,
273 std::unique_ptr<PdfField>& field);
274 std::unique_ptr<PdfField> createChildField(PdfPage* page,
const Rect& rect);
276 std::shared_ptr<PdfField> GetPtr();
277 PdfField* getParentTyped(PdfFieldType type)
const;
278 std::string_view getFieldTypeDisplayName()
const;
281 PdfAnnotationWidget* m_Widget;
282 PdfAcroForm* m_AcroForm;
284 nullable<std::shared_ptr<PdfField>> m_Parent;
285 std::unique_ptr<PdfFieldChildrenCollectionBase> m_Children;
288template<
typename TField>
289TField* PdfField::GetParentTyped(
PdfFieldType type)
const
291 return static_cast<TField*
>(getParentTyped(type));
294template<
typename TField>
297 if (std::is_same_v<TField, PdfPushButton>)
298 return PdfFieldType::PushButton;
299 else if (std::is_same_v<TField, PdfCheckBox>)
300 return PdfFieldType::CheckBox;
301 else if (std::is_same_v<TField, PdfRadioButton>)
302 return PdfFieldType::RadioButton;
303 else if (std::is_same_v<TField, PdfTextBox>)
304 return PdfFieldType::TextBox;
305 else if (std::is_same_v<TField, PdfComboBox>)
306 return PdfFieldType::ComboBox;
307 else if (std::is_same_v<TField, PdfListBox>)
308 return PdfFieldType::ListBox;
309 else if (std::is_same_v<TField, PdfSignature>)
310 return PdfFieldType::Signature;
312 return PdfFieldType::Unknown;
This file should be included as the FIRST file in every header of PoDoFo lib.
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:610
@ Create
Create a new file or truncate existing one for writing/reading.
PdfHighlightingMode
The possible highlighting modes for a PdfField.
Definition PdfDeclarations.h:629