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