1use crate::action_goto::PdfActionGoTo;
2use crate::action_named::PdfActionNamed;
3use crate::action_remote_goto::PdfActionRemoteGoTo;
4use crate::action_url::PdfActionUrl;
5use crate::ffi;
6use crate::handle::ObjectHandle;
7use crate::util::take_string;
8
9pub(crate) mod sealed {
10 pub trait Sealed {}
11}
12
13pub trait PdfActionLike: sealed::Sealed {
14 #[doc(hidden)]
15 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void;
16}
17
18#[derive(Debug, Clone)]
19pub struct PdfAction {
20 handle: ObjectHandle,
21}
22
23impl PdfAction {
24 pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
25 Self { handle }
26 }
27
28 #[must_use]
29 pub fn action_type(&self) -> Option<String> {
30 take_string(unsafe { ffi::pdf_action_type_string(self.handle.as_ptr()) })
31 }
32
33 #[must_use]
34 pub fn as_url(&self) -> Option<PdfActionUrl> {
35 let ptr = unsafe { ffi::pdf_action_as_url(self.handle.as_ptr()) };
36 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionUrl::from_handle)
37 }
38
39 #[must_use]
40 pub fn as_goto(&self) -> Option<PdfActionGoTo> {
41 let ptr = unsafe { ffi::pdf_action_as_goto(self.handle.as_ptr()) };
42 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionGoTo::from_handle)
43 }
44
45 #[must_use]
46 pub fn as_named(&self) -> Option<PdfActionNamed> {
47 let ptr = unsafe { ffi::pdf_action_as_named(self.handle.as_ptr()) };
48 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionNamed::from_handle)
49 }
50
51 #[must_use]
52 pub fn as_remote_goto(&self) -> Option<PdfActionRemoteGoTo> {
53 let ptr = unsafe { ffi::pdf_action_as_remote_goto(self.handle.as_ptr()) };
54 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionRemoteGoTo::from_handle)
55 }
56
57 pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
58 self.handle.as_ptr()
59 }
60}
61
62impl sealed::Sealed for PdfAction {}
63
64impl PdfActionLike for PdfAction {
65 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
66 self.as_handle_ptr()
67 }
68}