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