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 {
15 #[doc(hidden)]
16 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void;
17}
18
19#[derive(Debug, Clone)]
20pub struct PdfAction {
21 handle: ObjectHandle,
22}
23
24impl PdfAction {
25 pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
26 Self { handle }
27 }
28
29 #[must_use]
30 pub fn action_type(&self) -> Option<String> {
31 take_string(unsafe { ffi::pdf_action_type_string(self.handle.as_ptr()) })
32 }
33
34 #[must_use]
35 pub fn as_url(&self) -> Option<PdfActionUrl> {
36 let ptr = unsafe { ffi::pdf_action_as_url(self.handle.as_ptr()) };
37 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionUrl::from_handle)
38 }
39
40 #[must_use]
41 pub fn as_goto(&self) -> Option<PdfActionGoTo> {
42 let ptr = unsafe { ffi::pdf_action_as_goto(self.handle.as_ptr()) };
43 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionGoTo::from_handle)
44 }
45
46 #[must_use]
47 pub fn as_named(&self) -> Option<PdfActionNamed> {
48 let ptr = unsafe { ffi::pdf_action_as_named(self.handle.as_ptr()) };
49 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionNamed::from_handle)
50 }
51
52 #[must_use]
53 pub fn as_remote_goto(&self) -> Option<PdfActionRemoteGoTo> {
54 let ptr = unsafe { ffi::pdf_action_as_remote_goto(self.handle.as_ptr()) };
55 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionRemoteGoTo::from_handle)
56 }
57
58 #[must_use]
59 pub fn as_reset_form(&self) -> Option<PdfActionResetForm> {
60 let ptr = unsafe { ffi::pdf_action_as_reset_form(self.handle.as_ptr()) };
61 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionResetForm::from_handle)
62 }
63
64 pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
65 self.handle.as_ptr()
66 }
67}
68
69impl sealed::Sealed for PdfAction {}
70
71impl PdfActionLike for PdfAction {
72 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
73 self.as_handle_ptr()
74 }
75}