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_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 PdfFormComboBoxField<'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> PdfFormComboBoxField<'a> {
45 #[inline]
46 pub(crate) fn from_pdfium(
47 form_handle: FPDF_FORMHANDLE,
48 annotation_handle: FPDF_ANNOTATION,
49 ) -> Self {
50 PdfFormComboBoxField {
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]
75 pub fn has_editable_text_box(&self) -> bool {
76 self.get_flags_impl()
77 .contains(PdfFormFieldFlags::ChoiceEdit)
78 }
79
80 #[cfg(any(
81 feature = "pdfium_future",
82 feature = "pdfium_7881",
83 feature = "pdfium_7763",
84 feature = "pdfium_7543",
85 feature = "pdfium_7350"
86 ))]
87 #[inline]
90 pub fn set_has_editable_text_box(
91 &mut self,
92 has_editable_text_box: bool,
93 ) -> Result<(), PdfiumError> {
94 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceEdit, has_editable_text_box)
95 }
96
97 #[inline]
102 pub fn is_sorted(&self) -> bool {
103 self.get_flags_impl()
104 .contains(PdfFormFieldFlags::ChoiceSort)
105 }
106
107 #[cfg(any(
108 feature = "pdfium_future",
109 feature = "pdfium_7881",
110 feature = "pdfium_7763",
111 feature = "pdfium_7543",
112 feature = "pdfium_7350"
113 ))]
114 #[inline]
119 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
120 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
121 }
122
123 pub fn is_multiselect(&self) -> bool {
128 self.get_flags_impl()
129 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
130 }
131
132 #[cfg(any(
133 feature = "pdfium_future",
134 feature = "pdfium_7881",
135 feature = "pdfium_7763",
136 feature = "pdfium_7543",
137 feature = "pdfium_7350"
138 ))]
139 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
144 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
145 }
146
147 pub fn is_spell_checked(&self) -> bool {
155 !self
156 .get_flags_impl()
157 .contains(PdfFormFieldFlags::TextDoNotSpellCheck)
158 }
159
160 #[cfg(any(
161 feature = "pdfium_future",
162 feature = "pdfium_7881",
163 feature = "pdfium_7763",
164 feature = "pdfium_7543",
165 feature = "pdfium_7350"
166 ))]
167 pub fn set_is_spell_checked(&mut self, is_spell_checked: bool) -> Result<(), PdfiumError> {
172 self.update_one_flag_impl(PdfFormFieldFlags::TextDoNotSpellCheck, !is_spell_checked)
173 }
174
175 pub fn is_commit_on_selection_change(&self) -> bool {
183 self.get_flags_impl()
184 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
185 }
186
187 #[cfg(any(
188 feature = "pdfium_future",
189 feature = "pdfium_7881",
190 feature = "pdfium_7763",
191 feature = "pdfium_7543",
192 feature = "pdfium_7350"
193 ))]
194 pub fn set_is_commit_on_selection_change(
199 &mut self,
200 is_commit_on_selection_change: bool,
201 ) -> Result<(), PdfiumError> {
202 self.update_one_flag_impl(
203 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
204 is_commit_on_selection_change,
205 )
206 }
207}
208
209impl<'a> PdfFormFieldPrivate<'a> for PdfFormComboBoxField<'a> {
210 #[inline]
211 fn form_handle(&self) -> FPDF_FORMHANDLE {
212 self.form_handle
213 }
214
215 #[inline]
216 fn annotation_handle(&self) -> FPDF_ANNOTATION {
217 self.annotation_handle
218 }
219}
220
221impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormComboBoxField<'a> {}
222
223#[cfg(feature = "thread_safe")]
224unsafe impl<'a> Send for PdfFormComboBoxField<'a> {}
225
226#[cfg(feature = "thread_safe")]
227unsafe impl<'a> Sync for PdfFormComboBoxField<'a> {}