use std::marker::PhantomData;
use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
use crate::pdf::document::page::field::options::PdfFormFieldOptions;
use crate::pdf::document::page::field::private::internal::{
PdfFormFieldFlags, PdfFormFieldPrivate,
};
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
use crate::error::PdfiumError;
use crate::pdfium::PdfiumLibraryBindingsAccessor;
#[cfg(doc)]
use {
crate::pdf::document::form::PdfForm,
crate::pdf::document::page::annotation::PdfPageAnnotationType,
crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
};
pub struct PdfFormComboBoxField<'a> {
form_handle: FPDF_FORMHANDLE,
annotation_handle: FPDF_ANNOTATION,
options: PdfFormFieldOptions<'a>,
lifetime: PhantomData<&'a FPDF_ANNOTATION>,
}
impl<'a> PdfFormComboBoxField<'a> {
#[inline]
pub(crate) fn from_pdfium(
form_handle: FPDF_FORMHANDLE,
annotation_handle: FPDF_ANNOTATION,
) -> Self {
PdfFormComboBoxField {
form_handle,
annotation_handle,
options: PdfFormFieldOptions::from_pdfium(form_handle, annotation_handle),
lifetime: PhantomData,
}
}
pub fn options(&self) -> &PdfFormFieldOptions<'_> {
&self.options
}
#[inline]
pub fn value(&self) -> Option<String> {
self.options()
.iter()
.find(|option| option.is_set())
.and_then(|option| option.label().cloned())
}
#[inline]
pub fn has_editable_text_box(&self) -> bool {
self.get_flags_impl()
.contains(PdfFormFieldFlags::ChoiceEdit)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
#[inline]
pub fn set_has_editable_text_box(
&mut self,
has_editable_text_box: bool,
) -> Result<(), PdfiumError> {
self.update_one_flag_impl(PdfFormFieldFlags::ChoiceEdit, has_editable_text_box)
}
#[inline]
pub fn is_sorted(&self) -> bool {
self.get_flags_impl()
.contains(PdfFormFieldFlags::ChoiceSort)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
#[inline]
pub fn set_is_sorted(&mut self, is_sorted: bool) -> Result<(), PdfiumError> {
self.update_one_flag_impl(PdfFormFieldFlags::ChoiceSort, is_sorted)
}
pub fn is_multiselect(&self) -> bool {
self.get_flags_impl()
.contains(PdfFormFieldFlags::ChoiceMultiSelect)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
pub fn set_is_multiselect(&mut self, is_multiselect: bool) -> Result<(), PdfiumError> {
self.update_one_flag_impl(PdfFormFieldFlags::ChoiceMultiSelect, is_multiselect)
}
pub fn is_spell_checked(&self) -> bool {
!self
.get_flags_impl()
.contains(PdfFormFieldFlags::TextDoNotSpellCheck)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
pub fn set_is_spell_checked(&mut self, is_spell_checked: bool) -> Result<(), PdfiumError> {
self.update_one_flag_impl(PdfFormFieldFlags::TextDoNotSpellCheck, !is_spell_checked)
}
pub fn is_commit_on_selection_change(&self) -> bool {
self.get_flags_impl()
.contains(PdfFormFieldFlags::ChoiceCommitOnSelectionChange)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
pub fn set_is_commit_on_selection_change(
&mut self,
is_commit_on_selection_change: bool,
) -> Result<(), PdfiumError> {
self.update_one_flag_impl(
PdfFormFieldFlags::ChoiceCommitOnSelectionChange,
is_commit_on_selection_change,
)
}
}
impl<'a> PdfFormFieldPrivate<'a> for PdfFormComboBoxField<'a> {
#[inline]
fn form_handle(&self) -> FPDF_FORMHANDLE {
self.form_handle
}
#[inline]
fn annotation_handle(&self) -> FPDF_ANNOTATION {
self.annotation_handle
}
}
impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormComboBoxField<'a> {}
#[cfg(feature = "thread_safe")]
unsafe impl<'a> Send for PdfFormComboBoxField<'a> {}
#[cfg(feature = "thread_safe")]
unsafe impl<'a> Sync for PdfFormComboBoxField<'a> {}