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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::Buildable;
use crate::CellArea;
use crate::CellLayout;
use crate::TreeIter;
use crate::TreeModel;
use glib::object::Cast;
use glib::object::IsA;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`EntryCompletion`][crate::EntryCompletion] is an auxiliary object to provide completion functionality
    /// for [`Entry`][crate::Entry].
    ///
    /// It implements the [`CellLayout`][crate::CellLayout] interface, to allow the user
    /// to add extra cells to the [`TreeView`][crate::TreeView] with completion matches.
    ///
    /// “Completion functionality” means that when the user modifies the text
    /// in the entry, [`EntryCompletion`][crate::EntryCompletion] checks which rows in the model match
    /// the current content of the entry, and displays a list of matches.
    /// By default, the matching is done by comparing the entry text
    /// case-insensitively against the text column of the model (see
    /// [`set_text_column()`][Self::set_text_column()]), but this can be overridden
    /// with a custom match function (see [`set_match_func()`][Self::set_match_func()]).
    ///
    /// When the user selects a completion, the content of the entry is
    /// updated. By default, the content of the entry is replaced by the
    /// text column of the model, but this can be overridden by connecting
    /// to the `signal::EntryCompletion::match-selected` signal and updating the
    /// entry in the signal handler. Note that you should return [`true`] from
    /// the signal handler to suppress the default behaviour.
    ///
    /// To add completion functionality to an entry, use
    /// [`EntryExt::set_completion()`][crate::prelude::EntryExt::set_completion()].
    ///
    /// [`EntryCompletion`][crate::EntryCompletion] uses a [`TreeModelFilter`][crate::TreeModelFilter] model to
    /// represent the subset of the entire model that is currently matching.
    /// While the [`EntryCompletion`][crate::EntryCompletion] signals
    /// `signal::EntryCompletion::match-selected` and
    /// `signal::EntryCompletion::cursor-on-match` take the original model
    /// and an iter pointing to that model as arguments, other callbacks and
    /// signals (such as `GtkCellLayoutDataFunc` or
    /// `signal::CellArea::apply-attributes`)]
    /// will generally take the filter model as argument. As long as you are
    /// only calling [`TreeModelExtManual::get()`][crate::prelude::TreeModelExtManual::get()], this will make no difference to
    /// you. If for some reason, you need the original model, use
    /// [`TreeModelFilterExt::model()`][crate::prelude::TreeModelFilterExt::model()]. Don’t forget to use
    /// [`TreeModelFilterExt::convert_iter_to_child_iter()`][crate::prelude::TreeModelFilterExt::convert_iter_to_child_iter()] to obtain a
    /// matching iter.
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`CellLayoutExtManual`][trait@crate::prelude::CellLayoutExtManual]
    #[doc(alias = "GtkEntryCompletion")]
    pub struct EntryCompletion(Object<ffi::GtkEntryCompletion>) @implements Buildable, CellLayout;

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

impl EntryCompletion {
    /// Creates a new [`EntryCompletion`][crate::EntryCompletion] object.
    ///
    /// # Returns
    ///
    /// A newly created [`EntryCompletion`][crate::EntryCompletion] object
    #[doc(alias = "gtk_entry_completion_new")]
    pub fn new() -> EntryCompletion {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_entry_completion_new()) }
    }

    /// Creates a new [`EntryCompletion`][crate::EntryCompletion] object using the
    /// specified @area.
    ///
    /// The [`CellArea`][crate::CellArea] is used to layout cells in the underlying
    /// [`TreeViewColumn`][crate::TreeViewColumn] for the drop-down menu.
    /// ## `area`
    /// the [`CellArea`][crate::CellArea] used to layout cells
    ///
    /// # Returns
    ///
    /// A newly created [`EntryCompletion`][crate::EntryCompletion] object
    #[doc(alias = "gtk_entry_completion_new_with_area")]
    #[doc(alias = "new_with_area")]
    pub fn with_area(area: &impl IsA<CellArea>) -> EntryCompletion {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gtk_entry_completion_new_with_area(
                area.as_ref().to_glib_none().0,
            ))
        }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`EntryCompletion`] objects.
    ///
    /// This method returns an instance of [`EntryCompletionBuilder`](crate::builders::EntryCompletionBuilder) which can be used to create [`EntryCompletion`] objects.
    pub fn builder() -> EntryCompletionBuilder {
        EntryCompletionBuilder::default()
    }

    /// Requests a completion operation, or in other words a refiltering of the
    /// current list with completions, using the current key.
    ///
    /// The completion list view will be updated accordingly.
    #[doc(alias = "gtk_entry_completion_complete")]
    pub fn complete(&self) {
        unsafe {
            ffi::gtk_entry_completion_complete(self.to_glib_none().0);
        }
    }

    /// Computes the common prefix that is shared by all rows in @self
    /// that start with @key.
    ///
    /// If no row matches @key, [`None`] will be returned.
    /// Note that a text column must have been set for this function to work,
    /// see [`set_text_column()`][Self::set_text_column()] for details.
    /// ## `key`
    /// The text to complete for
    ///
    /// # Returns
    ///
    /// The common prefix all rows
    ///   starting with @key
    #[doc(alias = "gtk_entry_completion_compute_prefix")]
    pub fn compute_prefix(&self, key: &str) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::gtk_entry_completion_compute_prefix(
                self.to_glib_none().0,
                key.to_glib_none().0,
            ))
        }
    }

    /// Get the original text entered by the user that triggered
    /// the completion or [`None`] if there’s no completion ongoing.
    ///
    /// # Returns
    ///
    /// the prefix for the current completion
    #[doc(alias = "gtk_entry_completion_get_completion_prefix")]
    #[doc(alias = "get_completion_prefix")]
    pub fn completion_prefix(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_entry_completion_get_completion_prefix(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns whether the common prefix of the possible completions should
    /// be automatically inserted in the entry.
    ///
    /// # Returns
    ///
    /// [`true`] if inline completion is turned on
    #[doc(alias = "gtk_entry_completion_get_inline_completion")]
    #[doc(alias = "get_inline_completion")]
    pub fn is_inline_completion(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_entry_completion_get_inline_completion(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns [`true`] if inline-selection mode is turned on.
    ///
    /// # Returns
    ///
    /// [`true`] if inline-selection mode is on
    #[doc(alias = "gtk_entry_completion_get_inline_selection")]
    #[doc(alias = "get_inline_selection")]
    pub fn is_inline_selection(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_entry_completion_get_inline_selection(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns the minimum key length as set for @self.
    ///
    /// # Returns
    ///
    /// The currently used minimum key length
    #[doc(alias = "gtk_entry_completion_get_minimum_key_length")]
    #[doc(alias = "get_minimum_key_length")]
    pub fn minimum_key_length(&self) -> i32 {
        unsafe { ffi::gtk_entry_completion_get_minimum_key_length(self.to_glib_none().0) }
    }

    /// Returns the model the [`EntryCompletion`][crate::EntryCompletion] is using as data source.
    ///
    /// Returns [`None`] if the model is unset.
    ///
    /// # Returns
    ///
    /// A [`TreeModel`][crate::TreeModel]
    #[doc(alias = "gtk_entry_completion_get_model")]
    #[doc(alias = "get_model")]
    pub fn model(&self) -> Option<TreeModel> {
        unsafe { from_glib_none(ffi::gtk_entry_completion_get_model(self.to_glib_none().0)) }
    }

    /// Returns whether the completions should be presented in a popup window.
    ///
    /// # Returns
    ///
    /// [`true`] if popup completion is turned on
    #[doc(alias = "gtk_entry_completion_get_popup_completion")]
    #[doc(alias = "get_popup_completion")]
    pub fn is_popup_completion(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_entry_completion_get_popup_completion(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns whether the completion popup window will be resized to the
    /// width of the entry.
    ///
    /// # Returns
    ///
    /// [`true`] if the popup window will be resized to the width of
    ///   the entry
    #[doc(alias = "gtk_entry_completion_get_popup_set_width")]
    #[doc(alias = "get_popup_set_width")]
    pub fn is_popup_set_width(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_entry_completion_get_popup_set_width(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns whether the completion popup window will appear even if there is
    /// only a single match.
    ///
    /// # Returns
    ///
    /// [`true`] if the popup window will appear regardless of the
    ///    number of matches
    #[doc(alias = "gtk_entry_completion_get_popup_single_match")]
    #[doc(alias = "get_popup_single_match")]
    pub fn is_popup_single_match(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_entry_completion_get_popup_single_match(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns the column in the model of @self to get strings from.
    ///
    /// # Returns
    ///
    /// the column containing the strings
    #[doc(alias = "gtk_entry_completion_get_text_column")]
    #[doc(alias = "get_text_column")]
    pub fn text_column(&self) -> i32 {
        unsafe { ffi::gtk_entry_completion_get_text_column(self.to_glib_none().0) }
    }

    /// Requests a prefix insertion.
    #[doc(alias = "gtk_entry_completion_insert_prefix")]
    pub fn insert_prefix(&self) {
        unsafe {
            ffi::gtk_entry_completion_insert_prefix(self.to_glib_none().0);
        }
    }

    /// Sets whether the common prefix of the possible completions should
    /// be automatically inserted in the entry.
    /// ## `inline_completion`
    /// [`true`] to do inline completion
    #[doc(alias = "gtk_entry_completion_set_inline_completion")]
    pub fn set_inline_completion(&self, inline_completion: bool) {
        unsafe {
            ffi::gtk_entry_completion_set_inline_completion(
                self.to_glib_none().0,
                inline_completion.into_glib(),
            );
        }
    }

    /// Sets whether it is possible to cycle through the possible completions
    /// inside the entry.
    /// ## `inline_selection`
    /// [`true`] to do inline selection
    #[doc(alias = "gtk_entry_completion_set_inline_selection")]
    pub fn set_inline_selection(&self, inline_selection: bool) {
        unsafe {
            ffi::gtk_entry_completion_set_inline_selection(
                self.to_glib_none().0,
                inline_selection.into_glib(),
            );
        }
    }

    /// Sets the match function for @self to be @func.
    ///
    /// The match function is used to determine if a row should or
    /// should not be in the completion list.
    /// ## `func`
    /// the [`EntryCompletion`][crate::EntryCompletion]MatchFunc to use
    /// ## `func_data`
    /// user data for @func
    /// ## `func_notify`
    /// destroy notify for @func_data.
    #[doc(alias = "gtk_entry_completion_set_match_func")]
    pub fn set_match_func<P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static>(
        &self,
        func: P,
    ) {
        let func_data: Box_<P> = Box_::new(func);
        unsafe extern "C" fn func_func<
            P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static,
        >(
            completion: *mut ffi::GtkEntryCompletion,
            key: *const libc::c_char,
            iter: *mut ffi::GtkTreeIter,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let completion = from_glib_borrow(completion);
            let key: Borrowed<glib::GString> = from_glib_borrow(key);
            let iter = from_glib_borrow(iter);
            let callback: &P = &*(user_data as *mut _);
            let res = (*callback)(&completion, key.as_str(), &iter);
            res.into_glib()
        }
        let func = Some(func_func::<P> as _);
        unsafe extern "C" fn func_notify_func<
            P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static,
        >(
            data: glib::ffi::gpointer,
        ) {
            let _callback: Box_<P> = Box_::from_raw(data as *mut _);
        }
        let destroy_call3 = Some(func_notify_func::<P> as _);
        let super_callback0: Box_<P> = func_data;
        unsafe {
            ffi::gtk_entry_completion_set_match_func(
                self.to_glib_none().0,
                func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call3,
            );
        }
    }

    /// Requires the length of the search key for @self to be at least
    /// @length.
    ///
    /// This is useful for long lists, where completing using a small
    /// key takes a lot of time and will come up with meaningless results anyway
    /// (ie, a too large dataset).
    /// ## `length`
    /// the minimum length of the key in order to start completing
    #[doc(alias = "gtk_entry_completion_set_minimum_key_length")]
    pub fn set_minimum_key_length(&self, length: i32) {
        unsafe {
            ffi::gtk_entry_completion_set_minimum_key_length(self.to_glib_none().0, length);
        }
    }

    /// Sets the model for a [`EntryCompletion`][crate::EntryCompletion].
    ///
    /// If @self already has a model set, it will remove it
    /// before setting the new model. If model is [`None`], then it
    /// will unset the model.
    /// ## `model`
    /// the [`TreeModel`][crate::TreeModel]
    #[doc(alias = "gtk_entry_completion_set_model")]
    pub fn set_model(&self, model: Option<&impl IsA<TreeModel>>) {
        unsafe {
            ffi::gtk_entry_completion_set_model(
                self.to_glib_none().0,
                model.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    /// Sets whether the completions should be presented in a popup window.
    /// ## `popup_completion`
    /// [`true`] to do popup completion
    #[doc(alias = "gtk_entry_completion_set_popup_completion")]
    pub fn set_popup_completion(&self, popup_completion: bool) {
        unsafe {
            ffi::gtk_entry_completion_set_popup_completion(
                self.to_glib_none().0,
                popup_completion.into_glib(),
            );
        }
    }

    /// Sets whether the completion popup window will be resized to be the same
    /// width as the entry.
    /// ## `popup_set_width`
    /// [`true`] to make the width of the popup the same as the entry
    #[doc(alias = "gtk_entry_completion_set_popup_set_width")]
    pub fn set_popup_set_width(&self, popup_set_width: bool) {
        unsafe {
            ffi::gtk_entry_completion_set_popup_set_width(
                self.to_glib_none().0,
                popup_set_width.into_glib(),
            );
        }
    }

    /// Sets whether the completion popup window will appear even if there is
    /// only a single match.
    ///
    /// You may want to set this to [`false`] if you
    /// are using `property::EntryCompletion::inline-completion`.
    /// ## `popup_single_match`
    /// [`true`] if the popup should appear even for a single match
    #[doc(alias = "gtk_entry_completion_set_popup_single_match")]
    pub fn set_popup_single_match(&self, popup_single_match: bool) {
        unsafe {
            ffi::gtk_entry_completion_set_popup_single_match(
                self.to_glib_none().0,
                popup_single_match.into_glib(),
            );
        }
    }

    /// Convenience function for setting up the most used case of this code: a
    /// completion list with just strings.
    ///
    /// This function will set up @self
    /// to have a list displaying all (and just) strings in the completion list,
    /// and to get those strings from @column in the model of @self.
    ///
    /// This functions creates and adds a [`CellRendererText`][crate::CellRendererText] for the selected
    /// column. If you need to set the text column, but don't want the cell
    /// renderer, use g_object_set() to set the
    /// `property::EntryCompletion::text-column` property directly.
    /// ## `column`
    /// the column in the model of @self to get strings from
    #[doc(alias = "gtk_entry_completion_set_text_column")]
    pub fn set_text_column(&self, column: i32) {
        unsafe {
            ffi::gtk_entry_completion_set_text_column(self.to_glib_none().0, column);
        }
    }

    /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
    ///
    /// If no area is specified when creating the entry completion with
    /// [`with_area()`][Self::with_area()], a horizontally oriented
    /// [`CellAreaBox`][crate::CellAreaBox] will be used.
    #[doc(alias = "cell-area")]
    pub fn cell_area(&self) -> Option<CellArea> {
        glib::ObjectExt::property(self, "cell-area")
    }

    /// Emitted when a match from the cursor is on a match of the list.
    ///
    /// The default behaviour is to replace the contents
    /// of the entry with the contents of the text column in the row
    /// pointed to by @iter.
    ///
    /// Note that @model is the model that was passed to
    /// [`set_model()`][Self::set_model()].
    /// ## `model`
    /// the [`TreeModel`][crate::TreeModel] containing the matches
    /// ## `iter`
    /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
    ///
    /// # Returns
    ///
    /// [`true`] if the signal has been handled
    #[doc(alias = "cursor-on-match")]
    pub fn connect_cursor_on_match<
        F: Fn(&Self, &TreeModel, &TreeIter) -> glib::signal::Inhibit + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn cursor_on_match_trampoline<
            F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::signal::Inhibit + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            model: *mut ffi::GtkTreeModel,
            iter: *mut ffi::GtkTreeIter,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &from_glib_borrow(model),
                &from_glib_borrow(iter),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"cursor-on-match\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    cursor_on_match_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the inline autocompletion is triggered.
    ///
    /// The default behaviour is to make the entry display the
    /// whole prefix and select the newly inserted part.
    ///
    /// Applications may connect to this signal in order to insert only a
    /// smaller part of the @prefix into the entry - e.g. the entry used in
    /// the [`FileChooser`][crate::FileChooser] inserts only the part of the prefix up to the
    /// next '/'.
    /// ## `prefix`
    /// the common prefix of all possible completions
    ///
    /// # Returns
    ///
    /// [`true`] if the signal has been handled
    #[doc(alias = "insert-prefix")]
    pub fn connect_insert_prefix<F: Fn(&Self, &str) -> glib::signal::Inhibit + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn insert_prefix_trampoline<
            F: Fn(&EntryCompletion, &str) -> glib::signal::Inhibit + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            prefix: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &glib::GString::from_glib_borrow(prefix),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"insert-prefix\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    insert_prefix_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when a match from the list is selected.
    ///
    /// The default behaviour is to replace the contents of the
    /// entry with the contents of the text column in the row
    /// pointed to by @iter.
    ///
    /// Note that @model is the model that was passed to
    /// [`set_model()`][Self::set_model()].
    /// ## `model`
    /// the [`TreeModel`][crate::TreeModel] containing the matches
    /// ## `iter`
    /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
    ///
    /// # Returns
    ///
    /// [`true`] if the signal has been handled
    #[doc(alias = "match-selected")]
    pub fn connect_match_selected<
        F: Fn(&Self, &TreeModel, &TreeIter) -> glib::signal::Inhibit + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn match_selected_trampoline<
            F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::signal::Inhibit + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            model: *mut ffi::GtkTreeModel,
            iter: *mut ffi::GtkTreeIter,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &from_glib_borrow(model),
                &from_glib_borrow(iter),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"match-selected\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    match_selected_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the filter model has zero
    /// number of rows in completion_complete method.
    ///
    /// In other words when [`EntryCompletion`][crate::EntryCompletion] is out of suggestions.
    #[doc(alias = "no-matches")]
    pub fn connect_no_matches<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn no_matches_trampoline<F: Fn(&EntryCompletion) + 'static>(
            this: *mut ffi::GtkEntryCompletion,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"no-matches\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    no_matches_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "inline-completion")]
    pub fn connect_inline_completion_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_inline_completion_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::inline-completion\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_inline_completion_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "inline-selection")]
    pub fn connect_inline_selection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_inline_selection_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::inline-selection\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_inline_selection_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "minimum-key-length")]
    pub fn connect_minimum_key_length_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_minimum_key_length_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::minimum-key-length\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_minimum_key_length_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "model")]
    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_model_trampoline<F: Fn(&EntryCompletion) + 'static>(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::model\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_model_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "popup-completion")]
    pub fn connect_popup_completion_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_popup_completion_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::popup-completion\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_popup_completion_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "popup-set-width")]
    pub fn connect_popup_set_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_popup_set_width_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::popup-set-width\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_popup_set_width_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "popup-single-match")]
    pub fn connect_popup_single_match_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_popup_single_match_trampoline<
            F: Fn(&EntryCompletion) + 'static,
        >(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::popup-single-match\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_popup_single_match_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "text-column")]
    pub fn connect_text_column_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_text_column_trampoline<F: Fn(&EntryCompletion) + 'static>(
            this: *mut ffi::GtkEntryCompletion,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::text-column\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_text_column_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for EntryCompletion {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`EntryCompletion`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct EntryCompletionBuilder {
    cell_area: Option<CellArea>,
    inline_completion: Option<bool>,
    inline_selection: Option<bool>,
    minimum_key_length: Option<i32>,
    model: Option<TreeModel>,
    popup_completion: Option<bool>,
    popup_set_width: Option<bool>,
    popup_single_match: Option<bool>,
    text_column: Option<i32>,
}

impl EntryCompletionBuilder {
    // rustdoc-stripper-ignore-next
    /// Create a new [`EntryCompletionBuilder`].
    pub fn new() -> Self {
        Self::default()
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`EntryCompletion`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> EntryCompletion {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref cell_area) = self.cell_area {
            properties.push(("cell-area", cell_area));
        }
        if let Some(ref inline_completion) = self.inline_completion {
            properties.push(("inline-completion", inline_completion));
        }
        if let Some(ref inline_selection) = self.inline_selection {
            properties.push(("inline-selection", inline_selection));
        }
        if let Some(ref minimum_key_length) = self.minimum_key_length {
            properties.push(("minimum-key-length", minimum_key_length));
        }
        if let Some(ref model) = self.model {
            properties.push(("model", model));
        }
        if let Some(ref popup_completion) = self.popup_completion {
            properties.push(("popup-completion", popup_completion));
        }
        if let Some(ref popup_set_width) = self.popup_set_width {
            properties.push(("popup-set-width", popup_set_width));
        }
        if let Some(ref popup_single_match) = self.popup_single_match {
            properties.push(("popup-single-match", popup_single_match));
        }
        if let Some(ref text_column) = self.text_column {
            properties.push(("text-column", text_column));
        }
        glib::Object::new::<EntryCompletion>(&properties)
            .expect("Failed to create an instance of EntryCompletion")
    }

    /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
    ///
    /// If no area is specified when creating the entry completion with
    /// [`EntryCompletion::with_area()`][crate::EntryCompletion::with_area()], a horizontally oriented
    /// [`CellAreaBox`][crate::CellAreaBox] will be used.
    pub fn cell_area(mut self, cell_area: &impl IsA<CellArea>) -> Self {
        self.cell_area = Some(cell_area.clone().upcast());
        self
    }

    /// Determines whether the common prefix of the possible completions
    /// should be inserted automatically in the entry.
    ///
    /// Note that this requires text-column to be set, even if you are
    /// using a custom match function.
    pub fn inline_completion(mut self, inline_completion: bool) -> Self {
        self.inline_completion = Some(inline_completion);
        self
    }

    /// Determines whether the possible completions on the popup
    /// will appear in the entry as you navigate through them.
    pub fn inline_selection(mut self, inline_selection: bool) -> Self {
        self.inline_selection = Some(inline_selection);
        self
    }

    pub fn minimum_key_length(mut self, minimum_key_length: i32) -> Self {
        self.minimum_key_length = Some(minimum_key_length);
        self
    }

    pub fn model(mut self, model: &impl IsA<TreeModel>) -> Self {
        self.model = Some(model.clone().upcast());
        self
    }

    /// Determines whether the possible completions should be
    /// shown in a popup window.
    pub fn popup_completion(mut self, popup_completion: bool) -> Self {
        self.popup_completion = Some(popup_completion);
        self
    }

    /// Determines whether the completions popup window will be
    /// resized to the width of the entry.
    pub fn popup_set_width(mut self, popup_set_width: bool) -> Self {
        self.popup_set_width = Some(popup_set_width);
        self
    }

    /// Determines whether the completions popup window will shown
    /// for a single possible completion.
    ///
    /// You probably want to set this to [`false`] if you are using
    /// `property::EntryCompletion::inline-completion`.
    pub fn popup_single_match(mut self, popup_single_match: bool) -> Self {
        self.popup_single_match = Some(popup_single_match);
        self
    }

    /// The column of the model containing the strings.
    ///
    /// Note that the strings must be UTF-8.
    pub fn text_column(mut self, text_column: i32) -> Self {
        self.text_column = Some(text_column);
        self
    }
}

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