Skip to main content

pdfium_render/pdf/document/page/field/
button.rs

1//! Defines the [PdfFormPushButtonField] struct, exposing functionality related to a single
2//! form field of type [PdfFormFieldType::PushButton].
3
4use std::marker::PhantomData;
5
6use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
7use crate::pdf::document::page::field::private::internal::PdfFormFieldPrivate;
8use crate::pdfium::PdfiumLibraryBindingsAccessor;
9
10#[cfg(doc)]
11use {
12    crate::pdf::document::form::PdfForm,
13    crate::pdf::document::page::annotation::PdfPageAnnotationType,
14    crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
15};
16
17/// A single `PdfFormField` of type [PdfFormFieldType::PushButton]. The form field object defines
18/// an interactive button widget that can be clicked or tapped by the user.
19///
20/// Form fields in Pdfium are wrapped inside page annotations of type [PdfPageAnnotationType::Widget]
21/// or [PdfPageAnnotationType::XfaWidget]. User-specified values can be retrieved directly from
22/// each form field object by unwrapping the form field from the annotation, or in bulk from the
23/// [PdfForm::field_values()] function.
24pub struct PdfFormPushButtonField<'a> {
25    form_handle: FPDF_FORMHANDLE,
26    annotation_handle: FPDF_ANNOTATION,
27    lifetime: PhantomData<&'a FPDF_ANNOTATION>,
28}
29
30impl<'a> PdfFormPushButtonField<'a> {
31    #[inline]
32    pub(crate) fn from_pdfium(
33        form_handle: FPDF_FORMHANDLE,
34        annotation_handle: FPDF_ANNOTATION,
35    ) -> Self {
36        PdfFormPushButtonField {
37            form_handle,
38            annotation_handle,
39            lifetime: PhantomData,
40        }
41    }
42}
43
44impl<'a> PdfFormFieldPrivate<'a> for PdfFormPushButtonField<'a> {
45    #[inline]
46    fn form_handle(&self) -> FPDF_FORMHANDLE {
47        self.form_handle
48    }
49
50    #[inline]
51    fn annotation_handle(&self) -> FPDF_ANNOTATION {
52        self.annotation_handle
53    }
54}
55
56impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormPushButtonField<'a> {}
57
58#[cfg(feature = "thread_safe")]
59unsafe impl<'a> Send for PdfFormPushButtonField<'a> {}
60
61#[cfg(feature = "thread_safe")]
62unsafe impl<'a> Sync for PdfFormPushButtonField<'a> {}