1use std::ptr;
2
3use crate::action::{sealed, PdfActionLike};
4use crate::destination::PdfDestination;
5use crate::error::Result;
6use crate::ffi;
7use crate::handle::ObjectHandle;
8use crate::util::take_string;
9
10#[derive(Debug, Clone)]
11pub struct PdfActionGoTo {
12 handle: ObjectHandle,
13}
14
15impl PdfActionGoTo {
16 pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
17 Self { handle }
18 }
19
20 pub fn new(destination: &PdfDestination) -> Result<Self> {
21 let mut out_action = ptr::null_mut();
22 let mut out_error = ptr::null_mut();
23 let status = unsafe {
24 ffi::pdf_action_goto_new(destination.as_handle_ptr(), &mut out_action, &mut out_error)
25 };
26 crate::util::status_result(status, out_error)?;
27 Ok(Self::from_handle(crate::util::required_handle(
28 out_action,
29 "PDFActionGoTo",
30 )?))
31 }
32
33 #[must_use]
34 pub fn destination(&self) -> Option<PdfDestination> {
35 let ptr = unsafe { ffi::pdf_action_goto_destination(self.handle.as_ptr()) };
36 unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfDestination::from_handle)
37 }
38
39 pub fn set_destination(&self, destination: &PdfDestination) -> Result<()> {
40 let mut out_error = ptr::null_mut();
41 let status = unsafe {
42 ffi::pdf_action_goto_set_destination(
43 self.handle.as_ptr(),
44 destination.as_handle_ptr(),
45 &mut out_error,
46 )
47 };
48 crate::util::status_result(status, out_error)
49 }
50
51 #[must_use]
52 pub fn action_type(&self) -> Option<String> {
53 take_string(unsafe { ffi::pdf_action_goto_type_string(self.handle.as_ptr()) })
54 }
55
56 pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
57 self.handle.as_ptr()
58 }
59}
60
61impl sealed::Sealed for PdfActionGoTo {}
62
63impl PdfActionLike for PdfActionGoTo {
64 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
65 self.as_handle_ptr()
66 }
67}