PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfAnnotationActionBase.h
1// SPDX-FileCopyrightText: 2022 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_ANNOTATION_ACTION_BASE_H
5#define PDF_ANNOTATION_ACTION_BASE_H
6
7#include "PdfAnnotation.h"
8#include "PdfAction.h"
9#include "PdfDictionary.h"
10
11namespace PoDoFo {
12
13 class PODOFO_API PdfAppearanceCharacteristics final : public PdfDictionaryElement
14 {
15 template<typename T>
16 friend class PdfAppearanceCharacteristicsProvider;
17
18 private:
19 PdfAppearanceCharacteristics(PdfDocument& parent);
20 PdfAppearanceCharacteristics(PdfObject& obj);
21
22 public:
23 void SetBorderColor(nullable<const PdfColor&> color);
24
25 PdfColor GetBorderColor() const;
26
27 void SetBackgroundColor(nullable<const PdfColor&> color);
28
29 PdfColor GetBackgroundColor() const;
30
31 void SetRolloverCaption(nullable<const PdfString&> text);
32
33 nullable<const PdfString&> GetRolloverCaption() const;
34
35 void SetAlternateCaption(nullable<const PdfString&> text);
36
37 nullable<const PdfString&> GetAlternateCaption() const;
38
39 void SetCaption(nullable<const PdfString&> text);
40
41 nullable<const PdfString&> GetCaption() const;
42 };
43
44 template <typename T>
45 class PdfAppearanceCharacteristicsProvider
46 {
47 friend class PdfAnnotationWidget;
48 friend class PdfAnnotationScreen;
49
50 public:
51 PdfAppearanceCharacteristicsProvider()
52 {
53 auto& dict = static_cast<T&>(*this).GetDictionary();
54 auto mkObj = dict.FindKey("MK");
55 if (mkObj != nullptr)
56 m_AppearanceCharacteristics.reset(new PdfAppearanceCharacteristics(*mkObj));
57 }
58
59 public:
60 PdfAppearanceCharacteristics& GetOrCreateAppearanceCharacteristics()
61 {
62 if (m_AppearanceCharacteristics == nullptr)
63 {
64 auto& ref = static_cast<T&>(*this);
65 m_AppearanceCharacteristics.reset(new PdfAppearanceCharacteristics(ref.GetDocument()));
66 ref.GetDictionary().AddKeyIndirect("MK"_n, m_AppearanceCharacteristics->GetObject());
67 }
68
69 return *m_AppearanceCharacteristics;
70 }
71
72 PdfAppearanceCharacteristics* GetAppearanceCharacteristics()
73 {
74 return m_AppearanceCharacteristics.get();
75 }
76
77 const PdfAppearanceCharacteristics* GetAppearanceCharacteristics() const
78 {
79 return m_AppearanceCharacteristics.get();
80 }
81
82 private:
83 std::unique_ptr<PdfAppearanceCharacteristics> m_AppearanceCharacteristics;
84 };
85
86 class PODOFO_API PdfAnnotationActionBase : public PdfAnnotation
87 {
88 friend class PdfAnnotationWidget;
89 friend class PdfAnnotationLink;
90 friend class PdfAnnotationScreen;
91
92 private:
93 PdfAnnotationActionBase(PdfPage& page, PdfAnnotationType annotType, const Rect& rect);
94 PdfAnnotationActionBase(PdfObject& obj, PdfAnnotationType annotType);
95
96 public:
101 void SetAction(nullable<const PdfAction&> action);
102
108 nullable<PdfAction&> GetAction();
109 nullable<const PdfAction&> GetAction() const;
110
111 protected:
112 virtual void onActionSet();
113 void ResetAction();
114
115 private:
116 nullable<PdfAction&> getAction();
117
118 private:
119 nullable<std::unique_ptr<PdfAction>> m_Action;
120 };
121}
122
123#endif // PDF_ANNOTATION_ACTION_BASE_H
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13