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