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};
11
12#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
13use crate::error::PdfiumError;
14use crate::pdfium::PdfiumLibraryBindingsAccessor;
15
16#[cfg(doc)]
17use {
18 crate::pdf::document::form::PdfForm,
19 crate::pdf::document::page::annotation::PdfPageAnnotationType,
20 crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
21};
22
23pub struct PdfFormComboBoxField<'a> {
32 form_handle: FPDF_FORMHANDLE,
33 annotation_handle: FPDF_ANNOTATION,
34 options: PdfFormFieldOptions<'a>,
35 lifetime: PhantomData<&'a FPDF_ANNOTATION>,
36}
37
38impl<'a> PdfFormComboBoxField<'a> {
39 #[inline]
40 pub(crate) fn from_pdfium(
41 form_handle: FPDF_FORMHANDLE,
42 annotation_handle: FPDF_ANNOTATION,
43 ) -> Self {
44 PdfFormComboBoxField {
45 form_handle,
46 annotation_handle,
47 options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle),
48 lifetime: PhantomData,
49 }
50 }
51
52 pub fn options(&self) -> &PdfFormFieldOptions<'_> {
54 &self.options
55 }
56
57 #[inline]
59 pub fn value(&self) -> Option<String> {
60 self.options()
61 .iter()
62 .find(|option| option.is_set())
63 .and_then(|option| option.label().cloned())
64 }
65
66 #[inline]
69 pub fn has_editable_text_box(&self) -> bool {
70 self.get_flags_impl()
71 .contains(PdfFormFieldFlags::ChoiceEdit)
72 }
73
74 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
75 #[inline]
78 pub fn set_has_editable_text_box(
79 &mut self,
80 has_editable_text_box: bool,
81 ) -> Result<(), PdfiumError> {
82 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceEdit, has_editable_text_box)
83 }
84
85 #[inline]
90 pub fn is_sorted(&self) -> bool {
91 self.get_flags_impl()
92 .contains(PdfFormFieldFlags::ChoiceSort)
93 }
94
95 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
96 #[inline]
101 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
102 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
103 }
104
105 pub fn is_multiselect(&self) -> bool {
110 self.get_flags_impl()
111 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
112 }
113
114 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
115 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
120 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
121 }
122
123 pub fn is_spell_checked(&self) -> bool {
131 !self
132 .get_flags_impl()
133 .contains(PdfFormFieldFlags::TextDoNotSpellCheck)
134 }
135
136 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
137 pub fn set_is_spell_checked(&mut self, is_spell_checked: bool) -> Result<(), PdfiumError> {
142 self.update_one_flag_impl(PdfFormFieldFlags::TextDoNotSpellCheck, !is_spell_checked)
143 }
144
145 pub fn is_commit_on_selection_change(&self) -> bool {
153 self.get_flags_impl()
154 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
155 }
156
157 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
158 pub fn set_is_commit_on_selection_change(
163 &mut self,
164 is_commit_on_selection_change: bool,
165 ) -> Result<(), PdfiumError> {
166 self.update_one_flag_impl(
167 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
168 is_commit_on_selection_change,
169 )
170 }
171}
172
173impl<'a> PdfFormFieldPrivate<'a> for PdfFormComboBoxField<'a> {
174 #[inline]
175 fn form_handle(&self) -> FPDF_FORMHANDLE {
176 self.form_handle
177 }
178
179 #[inline]
180 fn annotation_handle(&self) -> FPDF_ANNOTATION {
181 self.annotation_handle
182 }
183}
184
185impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormComboBoxField<'a> {}
186
187#[cfg(feature = "thread_safe")]
188unsafe impl<'a> Send for PdfFormComboBoxField<'a> {}
189
190#[cfg(feature = "thread_safe")]
191unsafe impl<'a> Sync for PdfFormComboBoxField<'a> {}