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_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 PdfFormComboBoxField<'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> PdfFormComboBoxField<'a> {
44 #[inline]
45 pub(crate) fn from_pdfium(
46 form_handle: FPDF_FORMHANDLE,
47 annotation_handle: FPDF_ANNOTATION,
48 ) -> Self {
49 PdfFormComboBoxField {
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]
74 pub fn has_editable_text_box(&self) -> bool {
75 self.get_flags_impl()
76 .contains(PdfFormFieldFlags::ChoiceEdit)
77 }
78
79 #[cfg(any(
80 feature = "pdfium_future",
81 feature = "pdfium_7763",
82 feature = "pdfium_7543",
83 feature = "pdfium_7350"
84 ))]
85 #[inline]
88 pub fn set_has_editable_text_box(
89 &mut self,
90 has_editable_text_box: bool,
91 ) -> Result<(), PdfiumError> {
92 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceEdit, has_editable_text_box)
93 }
94
95 #[inline]
100 pub fn is_sorted(&self) -> bool {
101 self.get_flags_impl()
102 .contains(PdfFormFieldFlags::ChoiceSort)
103 }
104
105 #[cfg(any(
106 feature = "pdfium_future",
107 feature = "pdfium_7763",
108 feature = "pdfium_7543",
109 feature = "pdfium_7350"
110 ))]
111 #[inline]
116 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
117 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
118 }
119
120 pub fn is_multiselect(&self) -> bool {
125 self.get_flags_impl()
126 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
127 }
128
129 #[cfg(any(
130 feature = "pdfium_future",
131 feature = "pdfium_7763",
132 feature = "pdfium_7543",
133 feature = "pdfium_7350"
134 ))]
135 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
140 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
141 }
142
143 pub fn is_spell_checked(&self) -> bool {
151 !self
152 .get_flags_impl()
153 .contains(PdfFormFieldFlags::TextDoNotSpellCheck)
154 }
155
156 #[cfg(any(
157 feature = "pdfium_future",
158 feature = "pdfium_7763",
159 feature = "pdfium_7543",
160 feature = "pdfium_7350"
161 ))]
162 pub fn set_is_spell_checked(&mut self, is_spell_checked: bool) -> Result<(), PdfiumError> {
167 self.update_one_flag_impl(PdfFormFieldFlags::TextDoNotSpellCheck, !is_spell_checked)
168 }
169
170 pub fn is_commit_on_selection_change(&self) -> bool {
178 self.get_flags_impl()
179 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
180 }
181
182 #[cfg(any(
183 feature = "pdfium_future",
184 feature = "pdfium_7763",
185 feature = "pdfium_7543",
186 feature = "pdfium_7350"
187 ))]
188 pub fn set_is_commit_on_selection_change(
193 &mut self,
194 is_commit_on_selection_change: bool,
195 ) -> Result<(), PdfiumError> {
196 self.update_one_flag_impl(
197 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
198 is_commit_on_selection_change,
199 )
200 }
201}
202
203impl<'a> PdfFormFieldPrivate<'a> for PdfFormComboBoxField<'a> {
204 #[inline]
205 fn form_handle(&self) -> FPDF_FORMHANDLE {
206 self.form_handle
207 }
208
209 #[inline]
210 fn annotation_handle(&self) -> FPDF_ANNOTATION {
211 self.annotation_handle
212 }
213}
214
215impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormComboBoxField<'a> {}
216
217#[cfg(feature = "thread_safe")]
218unsafe impl<'a> Send for PdfFormComboBoxField<'a> {}
219
220#[cfg(feature = "thread_safe")]
221unsafe impl<'a> Sync for PdfFormComboBoxField<'a> {}