pdfium_render/pdf/document/page/field/
list.rs1use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
5use crate::pdf::document::page::field::options::PdfFormFieldOptions;
6use crate::pdf::document::page::field::private::internal::{
7 PdfFormFieldFlags, PdfFormFieldPrivate,
8};
9use crate::pdfium::PdfiumLibraryBindingsAccessor;
10use std::marker::PhantomData;
11
12#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
13use crate::error::PdfiumError;
14
15#[cfg(doc)]
16use {
17 crate::pdf::document::form::PdfForm,
18 crate::pdf::document::page::annotation::PdfPageAnnotationType,
19 crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
20};
21
22pub struct PdfFormListBoxField<'a> {
31 form_handle: FPDF_FORMHANDLE,
32 annotation_handle: FPDF_ANNOTATION,
33 options: PdfFormFieldOptions<'a>,
34 lifetime: PhantomData<&'a FPDF_ANNOTATION>,
35}
36
37impl<'a> PdfFormListBoxField<'a> {
38 #[inline]
39 pub(crate) fn from_pdfium(
40 form_handle: FPDF_FORMHANDLE,
41 annotation_handle: FPDF_ANNOTATION,
42 ) -> Self {
43 PdfFormListBoxField {
44 form_handle,
45 annotation_handle,
46 options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle),
47 lifetime: PhantomData,
48 }
49 }
50
51 pub fn options(&self) -> &PdfFormFieldOptions<'_> {
53 &self.options
54 }
55
56 #[inline]
58 pub fn value(&self) -> Option<String> {
59 self.options()
60 .iter()
61 .find(|option| option.is_set())
62 .and_then(|option| option.label().cloned())
63 }
64
65 #[inline]
70 pub fn is_sorted(&self) -> bool {
71 self.get_flags_impl()
72 .contains(PdfFormFieldFlags::ChoiceSort)
73 }
74
75 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
76 #[inline]
81 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
82 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
83 }
84
85 pub fn is_multiselect(&self) -> bool {
90 self.get_flags_impl()
91 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
92 }
93
94 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
95 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
100 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
101 }
102
103 pub fn is_commit_on_selection_change(&self) -> bool {
111 self.get_flags_impl()
112 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
113 }
114
115 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
116 pub fn set_is_commit_on_selection_change(
121 &mut self,
122 is_commit_on_selection_change: bool,
123 ) -> Result<(), PdfiumError> {
124 self.update_one_flag_impl(
125 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
126 is_commit_on_selection_change,
127 )
128 }
129}
130
131impl<'a> PdfFormFieldPrivate<'a> for PdfFormListBoxField<'a> {
132 #[inline]
133 fn form_handle(&self) -> FPDF_FORMHANDLE {
134 self.form_handle
135 }
136
137 #[inline]
138 fn annotation_handle(&self) -> FPDF_ANNOTATION {
139 self.annotation_handle
140 }
141}
142
143impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormListBoxField<'a> {}
144
145#[cfg(feature = "thread_safe")]
146unsafe impl<'a> Send for PdfFormListBoxField<'a> {}
147
148#[cfg(feature = "thread_safe")]
149unsafe impl<'a> Sync for PdfFormListBoxField<'a> {}