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(
13 feature = "pdfium_future",
14 feature = "pdfium_7881",
15 feature = "pdfium_7763",
16 feature = "pdfium_7543",
17 feature = "pdfium_7350"
18))]
19use crate::error::PdfiumError;
20
21#[cfg(doc)]
22use {
23 crate::pdf::document::form::PdfForm,
24 crate::pdf::document::page::annotation::PdfPageAnnotationType,
25 crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
26};
27
28pub struct PdfFormListBoxField<'a> {
37 form_handle: FPDF_FORMHANDLE,
38 annotation_handle: FPDF_ANNOTATION,
39 options: PdfFormFieldOptions<'a>,
40 lifetime: PhantomData<&'a FPDF_ANNOTATION>,
41}
42
43impl<'a> PdfFormListBoxField<'a> {
44 #[inline]
45 pub(crate) fn from_pdfium(
46 form_handle: FPDF_FORMHANDLE,
47 annotation_handle: FPDF_ANNOTATION,
48 ) -> Self {
49 PdfFormListBoxField {
50 form_handle,
51 annotation_handle,
52 options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle),
53 lifetime: PhantomData,
54 }
55 }
56
57 pub fn options(&self) -> &PdfFormFieldOptions<'_> {
59 &self.options
60 }
61
62 #[inline]
64 pub fn value(&self) -> Option<String> {
65 self.options()
66 .iter()
67 .find(|option| option.is_set())
68 .and_then(|option| option.label().cloned())
69 }
70
71 #[inline]
76 pub fn is_sorted(&self) -> bool {
77 self.get_flags_impl()
78 .contains(PdfFormFieldFlags::ChoiceSort)
79 }
80
81 #[cfg(any(
82 feature = "pdfium_future",
83 feature = "pdfium_7881",
84 feature = "pdfium_7763",
85 feature = "pdfium_7543",
86 feature = "pdfium_7350"
87 ))]
88 #[inline]
93 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
94 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
95 }
96
97 pub fn is_multiselect(&self) -> bool {
102 self.get_flags_impl()
103 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
104 }
105
106 #[cfg(any(
107 feature = "pdfium_future",
108 feature = "pdfium_7881",
109 feature = "pdfium_7763",
110 feature = "pdfium_7543",
111 feature = "pdfium_7350"
112 ))]
113 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
118 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
119 }
120
121 pub fn is_commit_on_selection_change(&self) -> bool {
129 self.get_flags_impl()
130 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
131 }
132
133 #[cfg(any(
134 feature = "pdfium_future",
135 feature = "pdfium_7881",
136 feature = "pdfium_7763",
137 feature = "pdfium_7543",
138 feature = "pdfium_7350"
139 ))]
140 pub fn set_is_commit_on_selection_change(
145 &mut self,
146 is_commit_on_selection_change: bool,
147 ) -> Result<(), PdfiumError> {
148 self.update_one_flag_impl(
149 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
150 is_commit_on_selection_change,
151 )
152 }
153}
154
155impl<'a> PdfFormFieldPrivate<'a> for PdfFormListBoxField<'a> {
156 #[inline]
157 fn form_handle(&self) -> FPDF_FORMHANDLE {
158 self.form_handle
159 }
160
161 #[inline]
162 fn annotation_handle(&self) -> FPDF_ANNOTATION {
163 self.annotation_handle
164 }
165}
166
167impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormListBoxField<'a> {}
168
169#[cfg(feature = "thread_safe")]
170unsafe impl<'a> Send for PdfFormListBoxField<'a> {}
171
172#[cfg(feature = "thread_safe")]
173unsafe impl<'a> Sync for PdfFormListBoxField<'a> {}