pdfium_render/pdf/document/page/field/
combo.rs1use std::marker::PhantomData;
5
6use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
7use crate::pdf::document::page::field::options::PdfFormFieldOptions;
8use crate::pdf::document::page::field::private::internal::{
9 PdfFormFieldFlags, PdfFormFieldPrivate,
10};
11use crate::pdfium::PdfiumLibraryBindingsAccessor;
12
13#[cfg(any(
14 feature = "pdfium_future",
15 feature = "pdfium_8125",
16 feature = "pdfium_7881",
17 feature = "pdfium_7763",
18 feature = "pdfium_7543",
19 feature = "pdfium_7350"
20))]
21use crate::error::PdfiumError;
22
23#[cfg(doc)]
24use {
25 crate::pdf::document::form::PdfForm,
26 crate::pdf::document::page::annotation::PdfPageAnnotationType,
27 crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
28};
29
30pub struct PdfFormComboBoxField<'a> {
39 form_handle: FPDF_FORMHANDLE,
40 annotation_handle: FPDF_ANNOTATION,
41 options: PdfFormFieldOptions<'a>,
42 lifetime: PhantomData<&'a FPDF_ANNOTATION>,
43}
44
45impl<'a> PdfFormComboBoxField<'a> {
46 #[inline]
47 pub(crate) fn from_pdfium(
48 form_handle: FPDF_FORMHANDLE,
49 annotation_handle: FPDF_ANNOTATION,
50 ) -> Self {
51 PdfFormComboBoxField {
52 form_handle,
53 annotation_handle,
54 options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle),
55 lifetime: PhantomData,
56 }
57 }
58
59 pub fn options(&self) -> &PdfFormFieldOptions<'_> {
61 &self.options
62 }
63
64 #[inline]
66 pub fn value(&self) -> Option<String> {
67 self.options()
68 .iter()
69 .find(|option| option.is_set())
70 .and_then(|option| option.label().cloned())
71 }
72
73 #[inline]
76 pub fn has_editable_text_box(&self) -> bool {
77 self.get_flags_impl()
78 .contains(PdfFormFieldFlags::ChoiceEdit)
79 }
80
81 #[cfg(any(
82 feature = "pdfium_future",
83 feature = "pdfium_8125",
84 feature = "pdfium_7881",
85 feature = "pdfium_7763",
86 feature = "pdfium_7543",
87 feature = "pdfium_7350"
88 ))]
89 #[inline]
92 pub fn set_has_editable_text_box(
93 &mut self,
94 has_editable_text_box: bool,
95 ) -> Result<(), PdfiumError> {
96 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceEdit, has_editable_text_box)
97 }
98
99 #[inline]
104 pub fn is_sorted(&self) -> bool {
105 self.get_flags_impl()
106 .contains(PdfFormFieldFlags::ChoiceSort)
107 }
108
109 #[cfg(any(
110 feature = "pdfium_future",
111 feature = "pdfium_8125",
112 feature = "pdfium_7881",
113 feature = "pdfium_7763",
114 feature = "pdfium_7543",
115 feature = "pdfium_7350"
116 ))]
117 #[inline]
122 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
123 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
124 }
125
126 pub fn is_multiselect(&self) -> bool {
131 self.get_flags_impl()
132 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
133 }
134
135 #[cfg(any(
136 feature = "pdfium_future",
137 feature = "pdfium_8125",
138 feature = "pdfium_7881",
139 feature = "pdfium_7763",
140 feature = "pdfium_7543",
141 feature = "pdfium_7350"
142 ))]
143 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
148 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
149 }
150
151 pub fn is_spell_checked(&self) -> bool {
159 !self
160 .get_flags_impl()
161 .contains(PdfFormFieldFlags::TextDoNotSpellCheck)
162 }
163
164 #[cfg(any(
165 feature = "pdfium_future",
166 feature = "pdfium_8125",
167 feature = "pdfium_7881",
168 feature = "pdfium_7763",
169 feature = "pdfium_7543",
170 feature = "pdfium_7350"
171 ))]
172 pub fn set_is_spell_checked(&mut self, is_spell_checked: bool) -> Result<(), PdfiumError> {
177 self.update_one_flag_impl(PdfFormFieldFlags::TextDoNotSpellCheck, !is_spell_checked)
178 }
179
180 pub fn is_commit_on_selection_change(&self) -> bool {
188 self.get_flags_impl()
189 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
190 }
191
192 #[cfg(any(
193 feature = "pdfium_future",
194 feature = "pdfium_8125",
195 feature = "pdfium_7881",
196 feature = "pdfium_7763",
197 feature = "pdfium_7543",
198 feature = "pdfium_7350"
199 ))]
200 pub fn set_is_commit_on_selection_change(
205 &mut self,
206 is_commit_on_selection_change: bool,
207 ) -> Result<(), PdfiumError> {
208 self.update_one_flag_impl(
209 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
210 is_commit_on_selection_change,
211 )
212 }
213}
214
215impl<'a> PdfFormFieldPrivate<'a> for PdfFormComboBoxField<'a> {
216 #[inline]
217 fn form_handle(&self) -> FPDF_FORMHANDLE {
218 self.form_handle
219 }
220
221 #[inline]
222 fn annotation_handle(&self) -> FPDF_ANNOTATION {
223 self.annotation_handle
224 }
225}
226
227impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormComboBoxField<'a> {}
228
229#[cfg(feature = "thread_safe")]
230unsafe impl<'a> Send for PdfFormComboBoxField<'a> {}
231
232#[cfg(feature = "thread_safe")]
233unsafe impl<'a> Sync for PdfFormComboBoxField<'a> {}