pdfium_render/pdf/document/page/field/
list.rs1use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
5use crate::bindings::PdfiumLibraryBindings;
6use crate::pdf::document::page::field::options::PdfFormFieldOptions;
7use crate::pdf::document::page::field::private::internal::{
8 PdfFormFieldFlags, PdfFormFieldPrivate,
9};
10
11#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
12use crate::error::PdfiumError;
13
14#[cfg(doc)]
15use {
16 crate::pdf::document::form::PdfForm,
17 crate::pdf::document::page::annotation::PdfPageAnnotationType,
18 crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
19};
20
21pub struct PdfFormListBoxField<'a> {
30 form_handle: FPDF_FORMHANDLE,
31 annotation_handle: FPDF_ANNOTATION,
32 options: PdfFormFieldOptions<'a>,
33 bindings: &'a dyn PdfiumLibraryBindings,
34}
35
36impl<'a> PdfFormListBoxField<'a> {
37 #[inline]
38 pub(crate) fn from_pdfium(
39 form_handle: FPDF_FORMHANDLE,
40 annotation_handle: FPDF_ANNOTATION,
41 bindings: &'a dyn PdfiumLibraryBindings,
42 ) -> Self {
43 PdfFormListBoxField {
44 form_handle,
45 annotation_handle,
46 options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle, bindings),
47 bindings,
48 }
49 }
50
51 #[inline]
53 pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings {
54 self.bindings
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]
76 pub fn is_sorted(&self) -> bool {
77 self.get_flags_impl()
78 .contains(PdfFormFieldFlags::ChoiceSort)
79 }
80
81 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
82 #[inline]
87 pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
88 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
89 }
90
91 pub fn is_multiselect(&self) -> bool {
96 self.get_flags_impl()
97 .contains(PdfFormFieldFlags::ChoiceMultiSelect)
98 }
99
100 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
101 pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
106 self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
107 }
108
109 pub fn is_commit_on_selection_change(&self) -> bool {
117 self.get_flags_impl()
118 .contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
119 }
120
121 #[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
122 pub fn set_is_commit_on_selection_change(
127 &mut self,
128 is_commit_on_selection_change: bool,
129 ) -> Result<(), PdfiumError> {
130 self.update_one_flag_impl(
131 PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
132 is_commit_on_selection_change,
133 )
134 }
135}
136
137impl<'a> PdfFormFieldPrivate<'a> for PdfFormListBoxField<'a> {
138 #[inline]
139 fn form_handle(&self) -> FPDF_FORMHANDLE {
140 self.form_handle
141 }
142
143 #[inline]
144 fn annotation_handle(&self) -> FPDF_ANNOTATION {
145 self.annotation_handle
146 }
147
148 #[inline]
149 fn bindings(&self) -> &dyn PdfiumLibraryBindings {
150 self.bindings
151 }
152}