PoDoFo  1.0.0-dev
PdfAction.h
1 
7 #ifndef PDF_ACTION_H
8 #define PDF_ACTION_H
9 
10 #include "PdfDeclarations.h"
11 
12 #include "PdfElement.h"
13 
14 namespace PoDoFo {
15 
16 class PdfDocument;
17 
27 enum class PdfActionType
28 {
29  Unknown = 0,
30  GoTo,
31  GoToR,
32  GoToE,
33  Launch,
34  Thread,
35  URI,
36  Sound,
37  Movie,
38  Hide,
39  Named,
40  SubmitForm,
41  ResetForm,
42  ImportData,
43  JavaScript,
44  SetOCGState,
45  Rendition,
46  Trans,
47  GoTo3DView,
48  RichMediaExecute,
49 };
50 
53 class PODOFO_API PdfAction : public PdfDictionaryElement
54 {
55  friend class PdfDocument;
56  friend class PdfAnnotationActionBase;
57  friend class PdfOutlineItem;
58  friend class PdfActionGoTo;
59  friend class PdfActionGoToR;
60  friend class PdfActionGoToE;
61  friend class PdfActionLaunch;
62  friend class PdfActionThread;
63  friend class PdfActionURI;
64  friend class PdfActionSound;
65  friend class PdfActionMovie;
66  friend class PdfActionHide;
67  friend class PdfActionNamed;
68  friend class PdfActionSubmitForm;
69  friend class PdfActionResetForm;
70  friend class PdfActionImportData;
71  friend class PdfActionJavaScript;
72  friend class PdfActionSetOCGState;
73  friend class PdfActionRendition;
74  friend class PdfActionTrans;
75  friend class PdfActionGoTo3DView;
76  friend class PdfActionRichMediaExecute;
77 
78 private:
79  PdfAction(PdfDocument& doc, PdfActionType action);
80 
81  PdfAction(PdfObject& obj, PdfActionType type);
82 
83 protected:
84  PdfAction(const PdfAction&) = default;
85 
86 public:
90  inline PdfActionType GetType() const { return m_Type; }
91 
92  static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<PdfAction>& action);
93 
94 private:
95  static std::unique_ptr<PdfAction> Create(PdfDocument& doc, PdfActionType type);
96 
97  static std::unique_ptr<PdfAction> Create(const PdfAction& action);
98 
99  template <typename TAction>
100  static constexpr PdfActionType GetActionType();
101 
109  void AddToDictionary(PdfDictionary& dictionary) const;
110 
111 private:
112  PdfActionType m_Type;
113 };
114 
115 
116 class PODOFO_API PdfActionGoTo final : public PdfAction
117 {
118  friend class PdfAction;
119 
120  PdfActionGoTo(PdfDocument& doc);
121 
122  PdfActionGoTo(PdfObject& obj);
123 
124  PdfActionGoTo(const PdfActionGoTo&) = default;
125 public:
126 };
127 
128 class PODOFO_API PdfActionGoToR final : public PdfAction
129 {
130  friend class PdfAction;
131 
132  PdfActionGoToR(PdfDocument& doc);
133 
134  PdfActionGoToR(PdfObject& obj);
135 
136  PdfActionGoToR(const PdfActionGoToR&) = default;
137 public:
138 };
139 
140 class PODOFO_API PdfActionGoToE final : public PdfAction
141 {
142  friend class PdfAction;
143 
144  PdfActionGoToE(PdfDocument& doc);
145 
146  PdfActionGoToE(PdfObject& obj);
147 
148  PdfActionGoToE(const PdfActionGoToE&) = default;
149 public:
150 };
151 
152 class PODOFO_API PdfActionLaunch final : public PdfAction
153 {
154  friend class PdfAction;
155 
156  PdfActionLaunch(PdfDocument& doc);
157 
158  PdfActionLaunch(PdfObject& obj);
159 
160  PdfActionLaunch(const PdfActionLaunch&) = default;
161 public:
162 };
163 
164 class PODOFO_API PdfActionThread final : public PdfAction
165 {
166  friend class PdfAction;
167 
168  PdfActionThread(PdfDocument& doc);
169 
170  PdfActionThread(PdfObject& obj);
171 
172  PdfActionThread(const PdfActionThread&) = default;
173 public:
174 };
175 
176 class PODOFO_API PdfActionURI final : public PdfAction
177 {
178  friend class PdfAction;
179 
180  PdfActionURI(PdfDocument& doc);
181 
182  PdfActionURI(PdfObject& obj);
183 
184  PdfActionURI(const PdfActionURI&) = default;
185 
186 public:
190  void SetURI(nullable<const PdfString&> uri);
191 
195  nullable<const PdfString&> GetURI() const;
196 };
197 
198 class PODOFO_API PdfActionSound final : public PdfAction
199 {
200  friend class PdfAction;
201 
202  PdfActionSound(PdfDocument& doc);
203 
204  PdfActionSound(PdfObject& obj);
205 
206  PdfActionSound(const PdfActionSound&) = default;
207 public:
208 };
209 
210 class PODOFO_API PdfActionMovie final : public PdfAction
211 {
212  friend class PdfAction;
213 
214  PdfActionMovie(PdfDocument& doc);
215 
216  PdfActionMovie(PdfObject& obj);
217 
218  PdfActionMovie(const PdfActionMovie&) = default;
219 public:
220 };
221 
222 class PODOFO_API PdfActionHide final : public PdfAction
223 {
224  friend class PdfAction;
225 
226  PdfActionHide(PdfDocument& doc);
227 
228  PdfActionHide(PdfObject& obj);
229 
230  PdfActionHide(const PdfActionHide&) = default;
231 public:
232 };
233 
234 class PODOFO_API PdfActionNamed final : public PdfAction
235 {
236  friend class PdfAction;
237 
238  PdfActionNamed(PdfDocument& doc);
239 
240  PdfActionNamed(PdfObject& obj);
241 
242  PdfActionNamed(const PdfActionNamed&) = default;
243 public:
244 };
245 
246 class PODOFO_API PdfActionSubmitForm final : public PdfAction
247 {
248  friend class PdfAction;
249 
250  PdfActionSubmitForm(PdfDocument& doc);
251 
252  PdfActionSubmitForm(PdfObject& obj);
253 
254  PdfActionSubmitForm(const PdfActionSubmitForm&) = default;
255 public:
256 };
257 
258 class PODOFO_API PdfActionResetForm final : public PdfAction
259 {
260  friend class PdfAction;
261 
262  PdfActionResetForm(PdfDocument& doc);
263 
264  PdfActionResetForm(PdfObject& obj);
265 
266  PdfActionResetForm(const PdfActionResetForm&) = default;
267 public:
268 };
269 
270 class PODOFO_API PdfActionImportData final : public PdfAction
271 {
272  friend class PdfAction;
273 
274  PdfActionImportData(PdfDocument& doc);
275 
276  PdfActionImportData(PdfObject& obj);
277 
278  PdfActionImportData(const PdfActionImportData&) = default;
279 public:
280 };
281 
282 class PODOFO_API PdfActionJavaScript final : public PdfAction
283 {
284  friend class PdfAction;
285 
286  PdfActionJavaScript(PdfDocument& doc);
287 
288  PdfActionJavaScript(PdfObject& obj);
289 
290  PdfActionJavaScript(const PdfActionJavaScript&) = default;
291 public:
292  void SetScript(nullable<const PdfString&> script);
293 
294  nullable<const PdfString&> GetScript() const;
295 };
296 
297 class PODOFO_API PdfActionSetOCGState final : public PdfAction
298 {
299  friend class PdfAction;
300 
301  PdfActionSetOCGState(PdfDocument& doc);
302 
303  PdfActionSetOCGState(PdfObject& obj);
304 
305  PdfActionSetOCGState(const PdfActionSetOCGState&) = default;
306 public:
307 };
308 
309 class PODOFO_API PdfActionRendition final : public PdfAction
310 {
311  friend class PdfAction;
312 
313  PdfActionRendition(PdfDocument& doc);
314 
315  PdfActionRendition(PdfObject& obj);
316 
317  PdfActionRendition(const PdfActionRendition&) = default;
318 public:
319 };
320 
321 class PODOFO_API PdfActionTrans : public PdfAction
322 {
323  friend class PdfAction;
324 
325  PdfActionTrans(PdfDocument& doc);
326 
327  PdfActionTrans(PdfObject& obj);
328 
329  PdfActionTrans(const PdfActionTrans&) = default;
330 public:
331 };
332 
333 class PODOFO_API PdfActionGoTo3DView final : public PdfAction
334 {
335  friend class PdfAction;
336 
337  PdfActionGoTo3DView(PdfDocument& doc);
338 
339  PdfActionGoTo3DView(PdfObject& obj);
340 
341  PdfActionGoTo3DView(const PdfActionGoTo3DView&) = default;
342 public:
343 };
344 
345 class PODOFO_API PdfActionRichMediaExecute final : public PdfAction
346 {
347  friend class PdfAction;
348 
349  PdfActionRichMediaExecute(PdfDocument& doc);
350 
351  PdfActionRichMediaExecute(PdfObject& obj);
352 
353  PdfActionRichMediaExecute(const PdfActionRichMediaExecute&) = default;
354 public:
355 };
356 
357 template<typename TAction>
358 constexpr PdfActionType PdfAction::GetActionType()
359 {
360  if (std::is_same_v<TAction, PdfActionGoTo>)
361  return PdfActionType::GoTo;
362  else if (std::is_same_v<TAction, PdfActionGoToR>)
363  return PdfActionType::GoToR;
364  else if (std::is_same_v<TAction, PdfActionGoToE>)
365  return PdfActionType::GoToE;
366  else if (std::is_same_v<TAction, PdfActionLaunch>)
367  return PdfActionType::Launch;
368  else if (std::is_same_v<TAction, PdfActionThread>)
369  return PdfActionType::Thread;
370  else if (std::is_same_v<TAction, PdfActionURI>)
371  return PdfActionType::URI;
372  else if (std::is_same_v<TAction, PdfActionSound>)
373  return PdfActionType::Sound;
374  else if (std::is_same_v<TAction, PdfActionMovie>)
375  return PdfActionType::Movie;
376  else if (std::is_same_v<TAction, PdfActionHide>)
377  return PdfActionType::Hide;
378  else if (std::is_same_v<TAction, PdfActionNamed>)
379  return PdfActionType::Named;
380  else if (std::is_same_v<TAction, PdfActionSubmitForm>)
381  return PdfActionType::SubmitForm;
382  else if (std::is_same_v<TAction, PdfActionResetForm>)
383  return PdfActionType::ResetForm;
384  else if (std::is_same_v<TAction, PdfActionImportData>)
385  return PdfActionType::ImportData;
386  else if (std::is_same_v<TAction, PdfActionJavaScript>)
387  return PdfActionType::JavaScript;
388  else if (std::is_same_v<TAction, PdfActionSetOCGState>)
389  return PdfActionType::SetOCGState;
390  else if (std::is_same_v<TAction, PdfActionRendition>)
391  return PdfActionType::Rendition;
392  else if (std::is_same_v<TAction, PdfActionTrans>)
393  return PdfActionType::Trans;
394  else if (std::is_same_v<TAction, PdfActionGoTo3DView>)
395  return PdfActionType::GoTo3DView;
396  else if (std::is_same_v<TAction, PdfActionRichMediaExecute>)
397  return PdfActionType::RichMediaExecute;
398  else
399  return PdfActionType::Unknown;
400 }
401 
402 };
403 
404 #endif // PDF_ACTION_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An action that can be performed in a PDF document.
Definition: PdfAction.h:54
PdfActionType GetType() const
Get the type of this action.
Definition: PdfAction.h:90
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition: PdfDictionary.h:82
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
A PDF outline item has an title and a destination.
Definition: PdfOutlines.h:39
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfActionType
The type of the action.
Definition: PdfAction.h:28
@ Create
Create a new file or truncate existing one for writing/reading.