1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{FormButtonType, FormChoiceType, FormFieldType, FormTextType};
#[cfg(feature = "v21_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
use crate::{SignatureInfo, SignatureValidationFlags};
#[cfg(feature = "v21_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
use glib::prelude::*;
use glib::translate::*;
use std::fmt;
#[cfg(feature = "v21_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
use std::{boxed::Box as Box_, pin::Pin, ptr};

glib::wrapper! {
    ///
    #[doc(alias = "PopplerFormField")]
    pub struct FormField(Object<ffi::PopplerFormField>);

    match fn {
        type_ => || ffi::poppler_form_field_get_type(),
    }
}

impl FormField {
    /// Gets the button type of `self`
    ///
    /// # Returns
    ///
    /// [`FormButtonType`][crate::FormButtonType] of `self`
    #[doc(alias = "poppler_form_field_button_get_button_type")]
    pub fn button_get_button_type(&self) -> FormButtonType {
        unsafe {
            from_glib(ffi::poppler_form_field_button_get_button_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Queries a [`FormField`][crate::FormField] and returns its current state. Returns [`true`] if
    /// `self` is pressed in and [`false`] if it is raised.
    ///
    /// # Returns
    ///
    /// current state of `self`
    #[doc(alias = "poppler_form_field_button_get_state")]
    pub fn button_get_state(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_button_get_state(
                self.to_glib_none().0,
            ))
        }
    }

    /// Sets the status of `self`. Set to [`true`] if you want the [`FormField`][crate::FormField]
    /// to be 'pressed in', and [`false`] to raise it.
    /// ## `state`
    /// [`true`] or [`false`]
    #[doc(alias = "poppler_form_field_button_set_state")]
    pub fn button_set_state(&self, state: bool) {
        unsafe {
            ffi::poppler_form_field_button_set_state(self.to_glib_none().0, state.into_glib());
        }
    }

    /// Checks whether `self` allows multiple choices to be selected
    ///
    /// # Returns
    ///
    /// [`true`] if `self` allows multiple choices to be selected
    #[doc(alias = "poppler_form_field_choice_can_select_multiple")]
    pub fn choice_can_select_multiple(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_can_select_multiple(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "poppler_form_field_choice_commit_on_change")]
    pub fn choice_commit_on_change(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_commit_on_change(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether spell checking should be done for the contents of `self`
    ///
    /// # Returns
    ///
    /// [`true`] if spell checking should be done for `self`
    #[doc(alias = "poppler_form_field_choice_do_spell_check")]
    pub fn choice_do_spell_check(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_do_spell_check(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the choice type of `self`
    ///
    /// # Returns
    ///
    /// [`FormChoiceType`][crate::FormChoiceType] of `self`
    #[doc(alias = "poppler_form_field_choice_get_choice_type")]
    pub fn choice_get_choice_type(&self) -> FormChoiceType {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_get_choice_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns the contents of the item on `self` at the given index
    /// ## `index`
    /// the index of the item
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_choice_get_item")]
    pub fn choice_get_item(&self, index: i32) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::poppler_form_field_choice_get_item(
                self.to_glib_none().0,
                index,
            ))
        }
    }

    /// Returns the number of items on `self`
    ///
    /// # Returns
    ///
    /// the number of items on `self`
    #[doc(alias = "poppler_form_field_choice_get_n_items")]
    pub fn choice_get_n_items(&self) -> i32 {
        unsafe { ffi::poppler_form_field_choice_get_n_items(self.to_glib_none().0) }
    }

    /// Retrieves the contents of `self`.
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_choice_get_text")]
    pub fn choice_get_text(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::poppler_form_field_choice_get_text(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether `self` is editable
    ///
    /// # Returns
    ///
    /// [`true`] if `self` is editable
    #[doc(alias = "poppler_form_field_choice_is_editable")]
    pub fn choice_is_editable(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_is_editable(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether the item at the given index on `self` is currently selected
    /// ## `index`
    /// the index of the item
    ///
    /// # Returns
    ///
    /// [`true`] if item at `index` is currently selected
    #[doc(alias = "poppler_form_field_choice_is_item_selected")]
    pub fn choice_is_item_selected(&self, index: i32) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_choice_is_item_selected(
                self.to_glib_none().0,
                index,
            ))
        }
    }

    /// Selects the item at the given index on `self`
    /// ## `index`
    /// the index of the item
    #[doc(alias = "poppler_form_field_choice_select_item")]
    pub fn choice_select_item(&self, index: i32) {
        unsafe {
            ffi::poppler_form_field_choice_select_item(self.to_glib_none().0, index);
        }
    }

    /// Sets the text in `self` to the given value, replacing the current contents
    /// ## `text`
    /// the new text
    #[doc(alias = "poppler_form_field_choice_set_text")]
    pub fn choice_set_text(&self, text: &str) {
        unsafe {
            ffi::poppler_form_field_choice_set_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }

    /// Changes the state of the item at the given index
    /// ## `index`
    /// the index of the item
    #[doc(alias = "poppler_form_field_choice_toggle_item")]
    pub fn choice_toggle_item(&self, index: i32) {
        unsafe {
            ffi::poppler_form_field_choice_toggle_item(self.to_glib_none().0, index);
        }
    }

    /// Unselects all the items on `self`
    #[doc(alias = "poppler_form_field_choice_unselect_all")]
    pub fn choice_unselect_all(&self) {
        unsafe {
            ffi::poppler_form_field_choice_unselect_all(self.to_glib_none().0);
        }
    }

    //#[doc(alias = "poppler_form_field_get_action")]
    //#[doc(alias = "get_action")]
    //pub fn action(&self) -> /*Ignored*/Option<Action> {
    //    unsafe { TODO: call ffi:poppler_form_field_get_action() }
    //}

    //#[cfg(feature = "v0_72")]
    //#[cfg_attr(docsrs, doc(cfg(feature = "v0_72")))]
    //#[doc(alias = "poppler_form_field_get_additional_action")]
    //#[doc(alias = "get_additional_action")]
    //pub fn additional_action(&self, type_: AdditionalActionType) -> /*Ignored*/Option<Action> {
    //    unsafe { TODO: call ffi:poppler_form_field_get_additional_action() }
    //}

    /// Gets the alternate ui name of `self`. This name is also commonly
    /// used by pdf producers/readers to show it as a tooltip when `self` area
    /// is hovered by a pointing device (eg. mouse).
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[cfg(feature = "v0_88")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_88")))]
    #[doc(alias = "poppler_form_field_get_alternate_ui_name")]
    #[doc(alias = "get_alternate_ui_name")]
    pub fn alternate_ui_name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::poppler_form_field_get_alternate_ui_name(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the type of `self`
    ///
    /// # Returns
    ///
    /// [`FormFieldType`][crate::FormFieldType] of `self`
    #[doc(alias = "poppler_form_field_get_field_type")]
    #[doc(alias = "get_field_type")]
    pub fn field_type(&self) -> FormFieldType {
        unsafe {
            from_glib(ffi::poppler_form_field_get_field_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the font size of `self`
    ///
    /// WARNING: This function always returns 0. Contact the poppler
    /// mailing list if you're interested in implementing it properly
    ///
    /// # Returns
    ///
    /// the font size of `self`
    #[doc(alias = "poppler_form_field_get_font_size")]
    #[doc(alias = "get_font_size")]
    pub fn font_size(&self) -> f64 {
        unsafe { ffi::poppler_form_field_get_font_size(self.to_glib_none().0) }
    }

    /// Gets the id of `self`
    ///
    /// # Returns
    ///
    /// the id of `self`
    #[doc(alias = "poppler_form_field_get_id")]
    #[doc(alias = "get_id")]
    pub fn id(&self) -> i32 {
        unsafe { ffi::poppler_form_field_get_id(self.to_glib_none().0) }
    }

    /// Gets the mapping name of `self` that is used when
    /// exporting interactive form field data from the document
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_get_mapping_name")]
    #[doc(alias = "get_mapping_name")]
    pub fn mapping_name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::poppler_form_field_get_mapping_name(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the fully qualified name of `self`. It's constructed by concatenating
    /// the partial field names of the field and all of its ancestors.
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::poppler_form_field_get_name(self.to_glib_none().0)) }
    }

    /// Gets the partial name of `self`.
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_get_partial_name")]
    #[doc(alias = "get_partial_name")]
    pub fn partial_name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::poppler_form_field_get_partial_name(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether `self` is read only
    ///
    /// # Returns
    ///
    /// [`true`] if `self` is read only
    #[doc(alias = "poppler_form_field_is_read_only")]
    pub fn is_read_only(&self) -> bool {
        unsafe { from_glib(ffi::poppler_form_field_is_read_only(self.to_glib_none().0)) }
    }

    /// Asynchronously validates the cryptographic signature contained in `signature_field`.
    /// ## `flags`
    /// [`SignatureValidationFlags`][crate::SignatureValidationFlags] flags influencing process of validation of the field signature
    /// ## `cancellable`
    /// optional [`gio::Cancellable`][crate::gio::Cancellable] object
    /// ## `callback`
    /// a `GAsyncReadyCallback` to call when the signature is validated
    #[cfg(feature = "v21_12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
    #[doc(alias = "poppler_form_field_signature_validate_async")]
    pub fn signature_validate_async<P: FnOnce(Result<SignatureInfo, glib::Error>) + 'static>(
        &self,
        flags: SignatureValidationFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn signature_validate_async_trampoline<
            P: FnOnce(Result<SignatureInfo, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut gio::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = ptr::null_mut();
            let ret = ffi::poppler_form_field_signature_validate_finish(
                _source_object as *mut _,
                res,
                &mut error,
            );
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = signature_validate_async_trampoline::<P>;
        unsafe {
            ffi::poppler_form_field_signature_validate_async(
                self.to_glib_none().0,
                flags.into_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    #[cfg(feature = "v21_12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
    pub fn signature_validate_future(
        &self,
        flags: SignatureValidationFlags,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<SignatureInfo, glib::Error>> + 'static>>
    {
        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
            obj.signature_validate_async(flags, Some(cancellable), move |res| {
                send.resolve(res);
            });
        }))
    }

    /// Synchronously validates the cryptographic signature contained in `signature_field`.
    /// ## `flags`
    /// [`SignatureValidationFlags`][crate::SignatureValidationFlags] flags influencing process of validation of the field signature
    /// ## `cancellable`
    /// optional [`gio::Cancellable`][crate::gio::Cancellable] object
    ///
    /// # Returns
    ///
    /// a [`SignatureInfo`][crate::SignatureInfo] structure containing signature metadata and validation status
    ///  Free the returned structure with `poppler_signature_info_free()`.
    #[cfg(feature = "v21_12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v21_12")))]
    #[doc(alias = "poppler_form_field_signature_validate_sync")]
    pub fn signature_validate_sync(
        &self,
        flags: SignatureValidationFlags,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<SignatureInfo, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::poppler_form_field_signature_validate_sync(
                self.to_glib_none().0,
                flags.into_glib(),
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "poppler_form_field_text_do_scroll")]
    pub fn text_do_scroll(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_text_do_scroll(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether spell checking should be done for the contents of `self`
    ///
    /// # Returns
    ///
    /// [`true`] if spell checking should be done for `self`
    #[doc(alias = "poppler_form_field_text_do_spell_check")]
    pub fn text_do_spell_check(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_text_do_spell_check(
                self.to_glib_none().0,
            ))
        }
    }

    /// Retrieves the maximum allowed length of the text in `self`
    ///
    /// # Returns
    ///
    /// the maximum allowed number of characters in `self`, or -1 if there is no maximum.
    #[doc(alias = "poppler_form_field_text_get_max_len")]
    pub fn text_get_max_len(&self) -> i32 {
        unsafe { ffi::poppler_form_field_text_get_max_len(self.to_glib_none().0) }
    }

    /// Retrieves the contents of `self`.
    ///
    /// # Returns
    ///
    /// a new allocated string. It must be freed with `g_free()` when done.
    #[doc(alias = "poppler_form_field_text_get_text")]
    pub fn text_get_text(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::poppler_form_field_text_get_text(self.to_glib_none().0)) }
    }

    /// Gets the text type of `self`.
    ///
    /// # Returns
    ///
    /// [`FormTextType`][crate::FormTextType] of `self`
    #[doc(alias = "poppler_form_field_text_get_text_type")]
    pub fn text_get_text_type(&self) -> FormTextType {
        unsafe {
            from_glib(ffi::poppler_form_field_text_get_text_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether content of `self` is a password and it must be hidden
    ///
    /// # Returns
    ///
    /// [`true`] if the content of `self` is a password
    #[doc(alias = "poppler_form_field_text_is_password")]
    pub fn text_is_password(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_text_is_password(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether the contents of `self` are rich text
    ///
    /// # Returns
    ///
    /// [`true`] if the contents of `self` are rich text
    #[doc(alias = "poppler_form_field_text_is_rich_text")]
    pub fn text_is_rich_text(&self) -> bool {
        unsafe {
            from_glib(ffi::poppler_form_field_text_is_rich_text(
                self.to_glib_none().0,
            ))
        }
    }

    /// Sets the text in `self` to the given value, replacing the current contents.
    /// ## `text`
    /// the new text
    #[doc(alias = "poppler_form_field_text_set_text")]
    pub fn text_set_text(&self, text: &str) {
        unsafe {
            ffi::poppler_form_field_text_set_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }
}

impl fmt::Display for FormField {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("FormField")
    }
}