14#include "PdfAnnotationWidget.h"
16#include "PdfFieldChildrenCollection.h"
22class PdfAnnotationWidget;
31class PODOFO_API PdfField :
public PdfDictionaryElement
33 friend class PdfSignature;
34 friend class PdfButton;
35 friend class PdChoiceField;
36 friend class PdfTextBox;
38 friend class PdfAcroForm;
39 friend class PdfAnnotationWidget;
40 friend class PdfFieldChildrenCollectionBase;
45 PdfButton_NoToggleOff = 0x0004000,
46 PdfButton_Radio = 0x0008000,
47 PdfButton_PushButton = 0x0010000,
48 PdfButton_RadioInUnison = 0x2000000,
49 PdfListField_Combo = 0x0020000,
50 PdfListField_Edit = 0x0040000,
51 PdfListField_Sort = 0x0080000,
52 PdfListField_MultiSelect = 0x0200000,
53 PdfListField_NoSpellcheck = 0x0400000,
54 PdfListField_CommitOnSelChange = 0x4000000
58 PdfField(PdfAcroForm& acroform, PdfFieldType fieldType,
59 const std::shared_ptr<PdfField>& parent);
61 PdfField(PdfAnnotationWidget& widget, PdfFieldType fieldType,
62 const std::shared_ptr<PdfField>& parent);
64 PdfField(PdfObject& obj, PdfAcroForm* acroform, PdfFieldType fieldType);
70 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<PdfField>& field);
72 PdfField* GetParentSafe();
73 const PdfField* GetParentSafe()
const;
82 void SetHighlightingMode(PdfHighlightingMode mode);
97 void SetName(nullable<const PdfString&> name);
105 PdfObject* GetValueObject();
106 const PdfObject* GetValueObject()
const;
110 nullable<const PdfString&> GetName()
const;
114 nullable<const PdfString&> GetNameRaw()
const;
120 std::string GetFullName(
bool skipEscapePartialName =
false)
const;
129 void SetAlternateName(nullable<const PdfString&> name);
133 nullable<const PdfString&> GetAlternateName()
const;
141 void SetMappingName(nullable<const PdfString&> name);
145 nullable<const PdfString&> GetMappingName()
const;
155 void SetReadOnly(
bool readOnly);
162 bool IsReadOnly()
const;
169 void SetRequired(
bool required);
176 bool IsRequired()
const;
184 void SetNoExport(
bool exprt);
191 bool IsNoExport()
const;
193 void SetMouseEnterAction(
const PdfAction& action);
194 void SetMouseLeaveAction(
const PdfAction& action);
195 void SetMouseDownAction(
const PdfAction& action);
196 void SetMouseUpAction(
const PdfAction& action);
198 void SetFocusEnterAction(
const PdfAction& action);
199 void SetFocusLeaveAction(
const PdfAction& action);
201 void SetPageOpenAction(
const PdfAction& action);
202 void SetPageCloseAction(
const PdfAction& action);
204 void SetPageVisibleAction(
const PdfAction& action);
205 void SetPageInvisibleAction(
const PdfAction& action);
207 void SetKeystrokeAction(
const PdfAction& action);
208 void SetValidateAction(
const PdfAction& action);
213 PdfAnnotationWidget* GetWidget() {
return m_Widget; }
215 const PdfAnnotationWidget* GetWidget()
const {
return m_Widget; }
217 PdfAnnotationWidget& MustGetWidget();
219 const PdfAnnotationWidget& MustGetWidget()
const;
221 PdfFieldChildrenCollectionBase& GetChildren();
223 const PdfFieldChildrenCollectionBase& GetChildren()
const;
235 void SetFieldFlag(int64_t value,
bool set);
245 bool GetFieldFlag(int64_t value,
bool defvalue)
const;
252 static bool GetFieldFlags(
const PdfObject& obj, int64_t& value);
254 virtual PdfObject* getValueObject()
const;
256 void AssertTerminalField()
const;
258 template <
typename TField>
259 TField* GetParentTyped(PdfFieldType type)
const;
262 template <
typename TField>
265 void SetWidget(PdfAnnotationWidget& widget) { m_Widget = &widget; }
266 void SetAcroForm(PdfAcroForm& acroform) { m_AcroForm = &acroform; }
270 static PdfField&
Create(
const std::string_view& name,
271 PdfAnnotationWidget& widget, PdfFieldType fieldType);
274 static std::unique_ptr<PdfField>
Create(
const std::string_view& name,
275 PdfAcroForm& acroform, PdfFieldType fieldType);
276 static std::unique_ptr<PdfField>
Create(PdfObject& obj, PdfAcroForm& acroform,
277 PdfFieldType fieldType);
280 std::unique_ptr<PdfField> CreateChild();
281 std::unique_ptr<PdfField> CreateChild(PdfPage& page,
const Rect& rect);
282 void SetParent(
const std::shared_ptr<PdfField>& parent) { m_Parent = parent; }
285 PdfField(
const PdfField& rhs) =
delete;
286 PdfField& operator=(
const PdfField& rhs) =
delete;
289 static std::unique_ptr<PdfField> createField(PdfAnnotationWidget& widget,
290 PdfFieldType type,
const std::shared_ptr<PdfField>& parent,
bool insertInAcroform);
292 static std::unique_ptr<PdfField> createField(PdfAcroForm& acroform, PdfFieldType type,
293 const std::shared_ptr<PdfField>& parent);
295 static void linkFieldObjectToParent(
const std::shared_ptr<PdfField>& field, PdfField& parentField,
296 const std::vector<std::string>& parentKeys,
bool setParent,
bool moveKeysToParent);
301 void setName(
const PdfString& name);
302 void addAlternativeAction(
const PdfName& name,
const PdfAction& action);
303 static bool tryCreateField(PdfObject& obj, PdfFieldType type,
304 std::unique_ptr<PdfField>& field);
305 std::unique_ptr<PdfField> createChildField(PdfPage* page,
const Rect& rect);
307 std::shared_ptr<PdfField> GetPtr();
308 PdfField* getParentTyped(PdfFieldType type)
const;
311 PdfAnnotationWidget* m_Widget;
312 PdfAcroForm* m_AcroForm;
314 nullable<std::shared_ptr<PdfField>> m_Parent;
315 std::unique_ptr<PdfFieldChildrenCollectionBase> m_Children;
318template<
typename TField>
319TField* PdfField::GetParentTyped(
PdfFieldType type)
const
321 return static_cast<TField*
>(getParentTyped(type));
324template<
typename TField>
327 if (std::is_same_v<TField, PdfPushButton>)
328 return PdfFieldType::PushButton;
329 else if (std::is_same_v<TField, PdfCheckBox>)
330 return PdfFieldType::CheckBox;
331 else if (std::is_same_v<TField, PdfRadioButton>)
332 return PdfFieldType::RadioButton;
333 else if (std::is_same_v<TField, PdfTextBox>)
334 return PdfFieldType::TextBox;
335 else if (std::is_same_v<TField, PdfComboBox>)
336 return PdfFieldType::ComboBox;
337 else if (std::is_same_v<TField, PdfListBox>)
338 return PdfFieldType::ListBox;
339 else if (std::is_same_v<TField, PdfSignature>)
340 return PdfFieldType::Signature;
342 return PdfFieldType::Unknown;
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:650
@ Create
Create a new file or truncate existing one for writing/reading.
PdfHighlightingMode
The possible highlighting modes for a PdfField.
Definition PdfDeclarations.h:670