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