poppler/auto/
form_field.rs1use crate::{FormButtonType, FormChoiceType, FormFieldType, FormTextType, ffi};
7#[cfg(feature = "v21_12")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
9use crate::{SignatureInfo, SignatureValidationFlags};
10#[cfg(feature = "v21_12")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
12use glib::prelude::*;
13use glib::translate::*;
14#[cfg(feature = "v21_12")]
15#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
16use std::{boxed::Box as Box_, pin::Pin};
17
18glib::wrapper! {
19 #[doc(alias = "PopplerFormField")]
20 pub struct FormField(Object<ffi::PopplerFormField>);
21
22 match fn {
23 type_ => || ffi::poppler_form_field_get_type(),
24 }
25}
26
27impl FormField {
28 #[doc(alias = "poppler_form_field_button_get_button_type")]
29 pub fn button_get_button_type(&self) -> FormButtonType {
30 unsafe {
31 from_glib(ffi::poppler_form_field_button_get_button_type(
32 self.to_glib_none().0,
33 ))
34 }
35 }
36
37 #[doc(alias = "poppler_form_field_button_get_state")]
38 pub fn button_get_state(&self) -> bool {
39 unsafe {
40 from_glib(ffi::poppler_form_field_button_get_state(
41 self.to_glib_none().0,
42 ))
43 }
44 }
45
46 #[doc(alias = "poppler_form_field_button_set_state")]
47 pub fn button_set_state(&self, state: bool) {
48 unsafe {
49 ffi::poppler_form_field_button_set_state(self.to_glib_none().0, state.into_glib());
50 }
51 }
52
53 #[doc(alias = "poppler_form_field_choice_can_select_multiple")]
54 pub fn choice_can_select_multiple(&self) -> bool {
55 unsafe {
56 from_glib(ffi::poppler_form_field_choice_can_select_multiple(
57 self.to_glib_none().0,
58 ))
59 }
60 }
61
62 #[doc(alias = "poppler_form_field_choice_commit_on_change")]
63 pub fn choice_commit_on_change(&self) -> bool {
64 unsafe {
65 from_glib(ffi::poppler_form_field_choice_commit_on_change(
66 self.to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "poppler_form_field_choice_do_spell_check")]
72 pub fn choice_do_spell_check(&self) -> bool {
73 unsafe {
74 from_glib(ffi::poppler_form_field_choice_do_spell_check(
75 self.to_glib_none().0,
76 ))
77 }
78 }
79
80 #[doc(alias = "poppler_form_field_choice_get_choice_type")]
81 pub fn choice_get_choice_type(&self) -> FormChoiceType {
82 unsafe {
83 from_glib(ffi::poppler_form_field_choice_get_choice_type(
84 self.to_glib_none().0,
85 ))
86 }
87 }
88
89 #[doc(alias = "poppler_form_field_choice_get_item")]
90 pub fn choice_get_item(&self, index: i32) -> Option<glib::GString> {
91 unsafe {
92 from_glib_full(ffi::poppler_form_field_choice_get_item(
93 self.to_glib_none().0,
94 index,
95 ))
96 }
97 }
98
99 #[doc(alias = "poppler_form_field_choice_get_n_items")]
100 pub fn choice_get_n_items(&self) -> i32 {
101 unsafe { ffi::poppler_form_field_choice_get_n_items(self.to_glib_none().0) }
102 }
103
104 #[doc(alias = "poppler_form_field_choice_get_text")]
105 pub fn choice_get_text(&self) -> Option<glib::GString> {
106 unsafe {
107 from_glib_full(ffi::poppler_form_field_choice_get_text(
108 self.to_glib_none().0,
109 ))
110 }
111 }
112
113 #[doc(alias = "poppler_form_field_choice_is_editable")]
114 pub fn choice_is_editable(&self) -> bool {
115 unsafe {
116 from_glib(ffi::poppler_form_field_choice_is_editable(
117 self.to_glib_none().0,
118 ))
119 }
120 }
121
122 #[doc(alias = "poppler_form_field_choice_is_item_selected")]
123 pub fn choice_is_item_selected(&self, index: i32) -> bool {
124 unsafe {
125 from_glib(ffi::poppler_form_field_choice_is_item_selected(
126 self.to_glib_none().0,
127 index,
128 ))
129 }
130 }
131
132 #[doc(alias = "poppler_form_field_choice_select_item")]
133 pub fn choice_select_item(&self, index: i32) {
134 unsafe {
135 ffi::poppler_form_field_choice_select_item(self.to_glib_none().0, index);
136 }
137 }
138
139 #[doc(alias = "poppler_form_field_choice_set_text")]
140 pub fn choice_set_text(&self, text: &str) {
141 unsafe {
142 ffi::poppler_form_field_choice_set_text(self.to_glib_none().0, text.to_glib_none().0);
143 }
144 }
145
146 #[doc(alias = "poppler_form_field_choice_toggle_item")]
147 pub fn choice_toggle_item(&self, index: i32) {
148 unsafe {
149 ffi::poppler_form_field_choice_toggle_item(self.to_glib_none().0, index);
150 }
151 }
152
153 #[doc(alias = "poppler_form_field_choice_unselect_all")]
154 pub fn choice_unselect_all(&self) {
155 unsafe {
156 ffi::poppler_form_field_choice_unselect_all(self.to_glib_none().0);
157 }
158 }
159
160 #[cfg(feature = "v0_88")]
175 #[cfg_attr(docsrs, doc(cfg(feature = "v0_88")))]
176 #[doc(alias = "poppler_form_field_get_alternate_ui_name")]
177 #[doc(alias = "get_alternate_ui_name")]
178 pub fn alternate_ui_name(&self) -> Option<glib::GString> {
179 unsafe {
180 from_glib_full(ffi::poppler_form_field_get_alternate_ui_name(
181 self.to_glib_none().0,
182 ))
183 }
184 }
185
186 #[doc(alias = "poppler_form_field_get_field_type")]
187 #[doc(alias = "get_field_type")]
188 pub fn field_type(&self) -> FormFieldType {
189 unsafe {
190 from_glib(ffi::poppler_form_field_get_field_type(
191 self.to_glib_none().0,
192 ))
193 }
194 }
195
196 #[doc(alias = "poppler_form_field_get_font_size")]
197 #[doc(alias = "get_font_size")]
198 pub fn font_size(&self) -> f64 {
199 unsafe { ffi::poppler_form_field_get_font_size(self.to_glib_none().0) }
200 }
201
202 #[doc(alias = "poppler_form_field_get_id")]
203 #[doc(alias = "get_id")]
204 pub fn id(&self) -> i32 {
205 unsafe { ffi::poppler_form_field_get_id(self.to_glib_none().0) }
206 }
207
208 #[doc(alias = "poppler_form_field_get_mapping_name")]
209 #[doc(alias = "get_mapping_name")]
210 pub fn mapping_name(&self) -> Option<glib::GString> {
211 unsafe {
212 from_glib_full(ffi::poppler_form_field_get_mapping_name(
213 self.to_glib_none().0,
214 ))
215 }
216 }
217
218 #[doc(alias = "poppler_form_field_get_name")]
219 #[doc(alias = "get_name")]
220 pub fn name(&self) -> Option<glib::GString> {
221 unsafe { from_glib_full(ffi::poppler_form_field_get_name(self.to_glib_none().0)) }
222 }
223
224 #[doc(alias = "poppler_form_field_get_partial_name")]
225 #[doc(alias = "get_partial_name")]
226 pub fn partial_name(&self) -> Option<glib::GString> {
227 unsafe {
228 from_glib_full(ffi::poppler_form_field_get_partial_name(
229 self.to_glib_none().0,
230 ))
231 }
232 }
233
234 #[doc(alias = "poppler_form_field_is_read_only")]
235 pub fn is_read_only(&self) -> bool {
236 unsafe { from_glib(ffi::poppler_form_field_is_read_only(self.to_glib_none().0)) }
237 }
238
239 #[cfg(feature = "v21_12")]
240 #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
241 #[doc(alias = "poppler_form_field_signature_validate_async")]
242 pub fn signature_validate_async<P: FnOnce(Result<SignatureInfo, glib::Error>) + 'static>(
243 &self,
244 flags: SignatureValidationFlags,
245 cancellable: Option<&impl IsA<gio::Cancellable>>,
246 callback: P,
247 ) {
248 let main_context = glib::MainContext::ref_thread_default();
249 let is_main_context_owner = main_context.is_owner();
250 let has_acquired_main_context = (!is_main_context_owner)
251 .then(|| main_context.acquire().ok())
252 .flatten();
253 assert!(
254 is_main_context_owner || has_acquired_main_context.is_some(),
255 "Async operations only allowed if the thread is owning the MainContext"
256 );
257
258 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
259 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
260 unsafe extern "C" fn signature_validate_async_trampoline<
261 P: FnOnce(Result<SignatureInfo, glib::Error>) + 'static,
262 >(
263 _source_object: *mut glib::gobject_ffi::GObject,
264 res: *mut gio::ffi::GAsyncResult,
265 user_data: glib::ffi::gpointer,
266 ) {
267 unsafe {
268 let mut error = std::ptr::null_mut();
269 let ret = ffi::poppler_form_field_signature_validate_finish(
270 _source_object as *mut _,
271 res,
272 &mut error,
273 );
274 let result = if error.is_null() {
275 Ok(from_glib_full(ret))
276 } else {
277 Err(from_glib_full(error))
278 };
279 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
280 Box_::from_raw(user_data as *mut _);
281 let callback: P = callback.into_inner();
282 callback(result);
283 }
284 }
285 let callback = signature_validate_async_trampoline::<P>;
286 unsafe {
287 ffi::poppler_form_field_signature_validate_async(
288 self.to_glib_none().0,
289 flags.into_glib(),
290 cancellable.map(|p| p.as_ref()).to_glib_none().0,
291 Some(callback),
292 Box_::into_raw(user_data) as *mut _,
293 );
294 }
295 }
296
297 #[cfg(feature = "v21_12")]
298 #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
299 pub fn signature_validate_future(
300 &self,
301 flags: SignatureValidationFlags,
302 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SignatureInfo, glib::Error>> + 'static>>
303 {
304 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
305 obj.signature_validate_async(flags, Some(cancellable), move |res| {
306 send.resolve(res);
307 });
308 }))
309 }
310
311 #[cfg(feature = "v21_12")]
312 #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
313 #[doc(alias = "poppler_form_field_signature_validate_sync")]
314 pub fn signature_validate_sync(
315 &self,
316 flags: SignatureValidationFlags,
317 cancellable: Option<&impl IsA<gio::Cancellable>>,
318 ) -> Result<SignatureInfo, glib::Error> {
319 unsafe {
320 let mut error = std::ptr::null_mut();
321 let ret = ffi::poppler_form_field_signature_validate_sync(
322 self.to_glib_none().0,
323 flags.into_glib(),
324 cancellable.map(|p| p.as_ref()).to_glib_none().0,
325 &mut error,
326 );
327 if error.is_null() {
328 Ok(from_glib_full(ret))
329 } else {
330 Err(from_glib_full(error))
331 }
332 }
333 }
334
335 #[doc(alias = "poppler_form_field_text_do_scroll")]
336 pub fn text_do_scroll(&self) -> bool {
337 unsafe {
338 from_glib(ffi::poppler_form_field_text_do_scroll(
339 self.to_glib_none().0,
340 ))
341 }
342 }
343
344 #[doc(alias = "poppler_form_field_text_do_spell_check")]
345 pub fn text_do_spell_check(&self) -> bool {
346 unsafe {
347 from_glib(ffi::poppler_form_field_text_do_spell_check(
348 self.to_glib_none().0,
349 ))
350 }
351 }
352
353 #[doc(alias = "poppler_form_field_text_get_max_len")]
354 pub fn text_get_max_len(&self) -> i32 {
355 unsafe { ffi::poppler_form_field_text_get_max_len(self.to_glib_none().0) }
356 }
357
358 #[doc(alias = "poppler_form_field_text_get_text")]
359 pub fn text_get_text(&self) -> Option<glib::GString> {
360 unsafe { from_glib_full(ffi::poppler_form_field_text_get_text(self.to_glib_none().0)) }
361 }
362
363 #[doc(alias = "poppler_form_field_text_get_text_type")]
364 pub fn text_get_text_type(&self) -> FormTextType {
365 unsafe {
366 from_glib(ffi::poppler_form_field_text_get_text_type(
367 self.to_glib_none().0,
368 ))
369 }
370 }
371
372 #[doc(alias = "poppler_form_field_text_is_password")]
373 pub fn text_is_password(&self) -> bool {
374 unsafe {
375 from_glib(ffi::poppler_form_field_text_is_password(
376 self.to_glib_none().0,
377 ))
378 }
379 }
380
381 #[doc(alias = "poppler_form_field_text_is_rich_text")]
382 pub fn text_is_rich_text(&self) -> bool {
383 unsafe {
384 from_glib(ffi::poppler_form_field_text_is_rich_text(
385 self.to_glib_none().0,
386 ))
387 }
388 }
389
390 #[doc(alias = "poppler_form_field_text_set_text")]
391 pub fn text_set_text(&self, text: &str) {
392 unsafe {
393 ffi::poppler_form_field_text_set_text(self.to_glib_none().0, text.to_glib_none().0);
394 }
395 }
396}