1use std::ptr;
2
3use crate::action::{sealed, PdfActionLike};
4use crate::error::Result;
5use crate::ffi;
6use crate::handle::ObjectHandle;
7use crate::util::{c_string, take_string};
8
9#[derive(Debug, Clone)]
11pub struct PdfActionUrl {
12 handle: ObjectHandle,
13}
14
15impl PdfActionUrl {
16 pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
17 Self { handle }
18 }
19
20 pub fn new(url: &str) -> Result<Self> {
22 let url = c_string(url)?;
23 let mut out_action = ptr::null_mut();
24 let mut out_error = ptr::null_mut();
25 let status =
26 unsafe { ffi::pdf_action_url_new(url.as_ptr(), &mut out_action, &mut out_error) };
27 crate::util::status_result(status, out_error)?;
28 Ok(Self::from_handle(crate::util::required_handle(
29 out_action,
30 "PDFActionURL",
31 )?))
32 }
33
34 #[must_use]
36 pub fn url(&self) -> Option<String> {
37 take_string(unsafe { ffi::pdf_action_url_string(self.handle.as_ptr()) })
38 }
39
40 pub fn set_url(&self, url: &str) -> Result<()> {
42 let url = c_string(url)?;
43 let mut out_error = ptr::null_mut();
44 let status = unsafe {
45 ffi::pdf_action_url_set_url(self.handle.as_ptr(), url.as_ptr(), &mut out_error)
46 };
47 crate::util::status_result(status, out_error)
48 }
49
50 #[must_use]
52 pub fn action_type(&self) -> Option<String> {
53 take_string(unsafe { ffi::pdf_action_url_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 PdfActionUrl {}
62
63impl PdfActionLike for PdfActionUrl {
64 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
65 self.as_handle_ptr()
66 }
67}