Skip to main content

gtk4/auto/
entry_completion.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{Buildable, CellArea, CellLayout, TreeIter, TreeModel, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// [`EntryCompletion`][crate::EntryCompletion] is an auxiliary object to provide completion functionality
17    /// for [`Entry`][crate::Entry].
18    ///
19    /// It implements the [`CellLayout`][crate::CellLayout] interface, to allow the user
20    /// to add extra cells to the [`TreeView`][crate::TreeView] with completion matches.
21    ///
22    /// “Completion functionality” means that when the user modifies the text
23    /// in the entry, [`EntryCompletion`][crate::EntryCompletion] checks which rows in the model match
24    /// the current content of the entry, and displays a list of matches.
25    /// By default, the matching is done by comparing the entry text
26    /// case-insensitively against the text column of the model (see
27    /// [`set_text_column()`][Self::set_text_column()]), but this can be overridden
28    /// with a custom match function (see [`set_match_func()`][Self::set_match_func()]).
29    ///
30    /// When the user selects a completion, the content of the entry is
31    /// updated. By default, the content of the entry is replaced by the
32    /// text column of the model, but this can be overridden by connecting
33    /// to the [`match-selected`][struct@crate::EntryCompletion#match-selected] signal and updating the
34    /// entry in the signal handler. Note that you should return [`true`] from
35    /// the signal handler to suppress the default behaviour.
36    ///
37    /// To add completion functionality to an entry, use
38    /// [`EntryExt::set_completion()`][crate::prelude::EntryExt::set_completion()].
39    ///
40    /// [`EntryCompletion`][crate::EntryCompletion] uses a [`TreeModelFilter`][crate::TreeModelFilter] model to
41    /// represent the subset of the entire model that is currently matching.
42    /// While the [`EntryCompletion`][crate::EntryCompletion] signals
43    /// [`match-selected`][struct@crate::EntryCompletion#match-selected] and
44    /// [`cursor-on-match`][struct@crate::EntryCompletion#cursor-on-match] take the original model
45    /// and an iter pointing to that model as arguments, other callbacks and
46    /// signals (such as `GtkCellLayoutDataFunc` or
47    /// [`apply-attributes`][struct@crate::CellArea#apply-attributes])]
48    /// will generally take the filter model as argument. As long as you are
49    /// only calling [`TreeModelExtManual::get()`][crate::prelude::TreeModelExtManual::get()], this will make no difference to
50    /// you. If for some reason, you need the original model, use
51    /// [`TreeModelFilterExt::model()`][crate::prelude::TreeModelFilterExt::model()]. Don’t forget to use
52    /// [`TreeModelFilterExt::convert_iter_to_child_iter()`][crate::prelude::TreeModelFilterExt::convert_iter_to_child_iter()] to obtain a
53    /// matching iter.
54    ///
55    /// ## Properties
56    ///
57    ///
58    /// #### `cell-area`
59    ///  The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
60    ///
61    /// If no area is specified when creating the entry completion with
62    /// [`EntryCompletion::with_area()`][crate::EntryCompletion::with_area()], a horizontally oriented
63    /// [`CellAreaBox`][crate::CellAreaBox] will be used.
64    ///
65    /// Readable | Writeable | Construct Only
66    ///
67    ///
68    /// #### `inline-completion`
69    ///  Determines whether the common prefix of the possible completions
70    /// should be inserted automatically in the entry.
71    ///
72    /// Note that this requires text-column to be set, even if you are
73    /// using a custom match function.
74    ///
75    /// Readable | Writeable
76    ///
77    ///
78    /// #### `inline-selection`
79    ///  Determines whether the possible completions on the popup
80    /// will appear in the entry as you navigate through them.
81    ///
82    /// Readable | Writeable
83    ///
84    ///
85    /// #### `minimum-key-length`
86    ///  The minimum key length as set for completion.
87    ///
88    /// Readable | Writeable
89    ///
90    ///
91    /// #### `model`
92    ///  The model used as data source.
93    ///
94    /// Readable | Writeable
95    ///
96    ///
97    /// #### `popup-completion`
98    ///  Determines whether the possible completions should be
99    /// shown in a popup window.
100    ///
101    /// Readable | Writeable
102    ///
103    ///
104    /// #### `popup-set-width`
105    ///  Determines whether the completions popup window will be
106    /// resized to the width of the entry.
107    ///
108    /// Readable | Writeable
109    ///
110    ///
111    /// #### `popup-single-match`
112    ///  Determines whether the completions popup window will shown
113    /// for a single possible completion.
114    ///
115    /// You probably want to set this to [`false`] if you are using
116    /// [`inline-completion`][struct@crate::EntryCompletion#inline-completion].
117    ///
118    /// Readable | Writeable
119    ///
120    ///
121    /// #### `text-column`
122    ///  The column of the model containing the strings.
123    ///
124    /// Note that the strings must be UTF-8.
125    ///
126    /// Readable | Writeable
127    ///
128    /// ## Signals
129    ///
130    ///
131    /// #### `cursor-on-match`
132    ///  Emitted when a match from the cursor is on a match of the list.
133    ///
134    /// The default behaviour is to replace the contents
135    /// of the entry with the contents of the text column in the row
136    /// pointed to by @iter.
137    ///
138    /// Note that @model is the model that was passed to
139    /// [`EntryCompletion::set_model()`][crate::EntryCompletion::set_model()].
140    ///
141    ///
142    ///
143    ///
144    /// #### `insert-prefix`
145    ///  Emitted when the inline autocompletion is triggered.
146    ///
147    /// The default behaviour is to make the entry display the
148    /// whole prefix and select the newly inserted part.
149    ///
150    /// Applications may connect to this signal in order to insert only a
151    /// smaller part of the @prefix into the entry - e.g. the entry used in
152    /// the [`FileChooser`][crate::FileChooser] inserts only the part of the prefix up to the
153    /// next '/'.
154    ///
155    ///
156    ///
157    ///
158    /// #### `match-selected`
159    ///  Emitted when a match from the list is selected.
160    ///
161    /// The default behaviour is to replace the contents of the
162    /// entry with the contents of the text column in the row
163    /// pointed to by @iter.
164    ///
165    /// Note that @model is the model that was passed to
166    /// [`EntryCompletion::set_model()`][crate::EntryCompletion::set_model()].
167    ///
168    ///
169    ///
170    ///
171    /// #### `no-matches`
172    ///  Emitted when the filter model has zero
173    /// number of rows in completion_complete method.
174    ///
175    /// In other words when [`EntryCompletion`][crate::EntryCompletion] is out of suggestions.
176    ///
177    ///
178    ///
179    /// # Implements
180    ///
181    /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`CellLayoutExtManual`][trait@crate::prelude::CellLayoutExtManual]
182    #[doc(alias = "GtkEntryCompletion")]
183    pub struct EntryCompletion(Object<ffi::GtkEntryCompletion>) @implements Buildable, CellLayout;
184
185    match fn {
186        type_ => || ffi::gtk_entry_completion_get_type(),
187    }
188}
189
190impl EntryCompletion {
191    /// Creates a new [`EntryCompletion`][crate::EntryCompletion] object.
192    ///
193    /// # Deprecated since 4.10
194    ///
195    /// GtkEntryCompletion will be removed in GTK 5.
196    ///
197    /// # Returns
198    ///
199    /// A newly created [`EntryCompletion`][crate::EntryCompletion] object
200    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
201    #[allow(deprecated)]
202    #[doc(alias = "gtk_entry_completion_new")]
203    pub fn new() -> EntryCompletion {
204        assert_initialized_main_thread!();
205        unsafe { from_glib_full(ffi::gtk_entry_completion_new()) }
206    }
207
208    /// Creates a new [`EntryCompletion`][crate::EntryCompletion] object using the
209    /// specified @area.
210    ///
211    /// The [`CellArea`][crate::CellArea] is used to layout cells in the underlying
212    /// [`TreeViewColumn`][crate::TreeViewColumn] for the drop-down menu.
213    ///
214    /// # Deprecated since 4.10
215    ///
216    /// GtkEntryCompletion will be removed in GTK 5.
217    /// ## `area`
218    /// the [`CellArea`][crate::CellArea] used to layout cells
219    ///
220    /// # Returns
221    ///
222    /// A newly created [`EntryCompletion`][crate::EntryCompletion] object
223    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
224    #[allow(deprecated)]
225    #[doc(alias = "gtk_entry_completion_new_with_area")]
226    #[doc(alias = "new_with_area")]
227    pub fn with_area(area: &impl IsA<CellArea>) -> EntryCompletion {
228        skip_assert_initialized!();
229        unsafe {
230            from_glib_full(ffi::gtk_entry_completion_new_with_area(
231                area.as_ref().to_glib_none().0,
232            ))
233        }
234    }
235
236    // rustdoc-stripper-ignore-next
237    /// Creates a new builder-pattern struct instance to construct [`EntryCompletion`] objects.
238    ///
239    /// This method returns an instance of [`EntryCompletionBuilder`](crate::builders::EntryCompletionBuilder) which can be used to create [`EntryCompletion`] objects.
240    pub fn builder() -> EntryCompletionBuilder {
241        EntryCompletionBuilder::new()
242    }
243
244    /// Requests a completion operation, or in other words a refiltering of the
245    /// current list with completions, using the current key.
246    ///
247    /// The completion list view will be updated accordingly.
248    ///
249    /// # Deprecated since 4.10
250    ///
251    /// GtkEntryCompletion will be removed in GTK 5.
252    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
253    #[allow(deprecated)]
254    #[doc(alias = "gtk_entry_completion_complete")]
255    pub fn complete(&self) {
256        unsafe {
257            ffi::gtk_entry_completion_complete(self.to_glib_none().0);
258        }
259    }
260
261    /// Computes the common prefix that is shared by all rows in @self
262    /// that start with @key.
263    ///
264    /// If no row matches @key, [`None`] will be returned.
265    /// Note that a text column must have been set for this function to work,
266    /// see [`set_text_column()`][Self::set_text_column()] for details.
267    ///
268    /// # Deprecated since 4.10
269    ///
270    /// GtkEntryCompletion will be removed in GTK 5.
271    /// ## `key`
272    /// The text to complete for
273    ///
274    /// # Returns
275    ///
276    /// The common prefix all rows
277    ///   starting with @key
278    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
279    #[allow(deprecated)]
280    #[doc(alias = "gtk_entry_completion_compute_prefix")]
281    pub fn compute_prefix(&self, key: &str) -> Option<glib::GString> {
282        unsafe {
283            from_glib_full(ffi::gtk_entry_completion_compute_prefix(
284                self.to_glib_none().0,
285                key.to_glib_none().0,
286            ))
287        }
288    }
289
290    /// Get the original text entered by the user that triggered
291    /// the completion or [`None`] if there’s no completion ongoing.
292    ///
293    /// # Deprecated since 4.10
294    ///
295    /// GtkEntryCompletion will be removed in GTK 5.
296    ///
297    /// # Returns
298    ///
299    /// the prefix for the current completion
300    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
301    #[allow(deprecated)]
302    #[doc(alias = "gtk_entry_completion_get_completion_prefix")]
303    #[doc(alias = "get_completion_prefix")]
304    pub fn completion_prefix(&self) -> Option<glib::GString> {
305        unsafe {
306            from_glib_none(ffi::gtk_entry_completion_get_completion_prefix(
307                self.to_glib_none().0,
308            ))
309        }
310    }
311
312    /// Returns whether the common prefix of the possible completions should
313    /// be automatically inserted in the entry.
314    ///
315    /// # Deprecated since 4.10
316    ///
317    /// GtkEntryCompletion will be removed in GTK 5.
318    ///
319    /// # Returns
320    ///
321    /// [`true`] if inline completion is turned on
322    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
323    #[allow(deprecated)]
324    #[doc(alias = "gtk_entry_completion_get_inline_completion")]
325    #[doc(alias = "get_inline_completion")]
326    #[doc(alias = "inline-completion")]
327    pub fn is_inline_completion(&self) -> bool {
328        unsafe {
329            from_glib(ffi::gtk_entry_completion_get_inline_completion(
330                self.to_glib_none().0,
331            ))
332        }
333    }
334
335    /// Returns [`true`] if inline-selection mode is turned on.
336    ///
337    /// # Deprecated since 4.10
338    ///
339    /// GtkEntryCompletion will be removed in GTK 5.
340    ///
341    /// # Returns
342    ///
343    /// [`true`] if inline-selection mode is on
344    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
345    #[allow(deprecated)]
346    #[doc(alias = "gtk_entry_completion_get_inline_selection")]
347    #[doc(alias = "get_inline_selection")]
348    #[doc(alias = "inline-selection")]
349    pub fn is_inline_selection(&self) -> bool {
350        unsafe {
351            from_glib(ffi::gtk_entry_completion_get_inline_selection(
352                self.to_glib_none().0,
353            ))
354        }
355    }
356
357    /// Returns the minimum key length as set for @self.
358    ///
359    /// # Deprecated since 4.10
360    ///
361    /// GtkEntryCompletion will be removed in GTK 5.
362    ///
363    /// # Returns
364    ///
365    /// The currently used minimum key length
366    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
367    #[allow(deprecated)]
368    #[doc(alias = "gtk_entry_completion_get_minimum_key_length")]
369    #[doc(alias = "get_minimum_key_length")]
370    #[doc(alias = "minimum-key-length")]
371    pub fn minimum_key_length(&self) -> i32 {
372        unsafe { ffi::gtk_entry_completion_get_minimum_key_length(self.to_glib_none().0) }
373    }
374
375    /// Returns the model the [`EntryCompletion`][crate::EntryCompletion] is using as data source.
376    ///
377    /// Returns [`None`] if the model is unset.
378    ///
379    /// # Deprecated since 4.10
380    ///
381    /// GtkEntryCompletion will be removed in GTK 5.
382    ///
383    /// # Returns
384    ///
385    /// A [`TreeModel`][crate::TreeModel]
386    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
387    #[allow(deprecated)]
388    #[doc(alias = "gtk_entry_completion_get_model")]
389    #[doc(alias = "get_model")]
390    pub fn model(&self) -> Option<TreeModel> {
391        unsafe { from_glib_none(ffi::gtk_entry_completion_get_model(self.to_glib_none().0)) }
392    }
393
394    /// Returns whether the completions should be presented in a popup window.
395    ///
396    /// # Deprecated since 4.10
397    ///
398    /// GtkEntryCompletion will be removed in GTK 5.
399    ///
400    /// # Returns
401    ///
402    /// [`true`] if popup completion is turned on
403    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
404    #[allow(deprecated)]
405    #[doc(alias = "gtk_entry_completion_get_popup_completion")]
406    #[doc(alias = "get_popup_completion")]
407    #[doc(alias = "popup-completion")]
408    pub fn is_popup_completion(&self) -> bool {
409        unsafe {
410            from_glib(ffi::gtk_entry_completion_get_popup_completion(
411                self.to_glib_none().0,
412            ))
413        }
414    }
415
416    /// Returns whether the completion popup window will be resized to the
417    /// width of the entry.
418    ///
419    /// # Deprecated since 4.10
420    ///
421    /// GtkEntryCompletion will be removed in GTK 5.
422    ///
423    /// # Returns
424    ///
425    /// [`true`] if the popup window will be resized to the width of
426    ///   the entry
427    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
428    #[allow(deprecated)]
429    #[doc(alias = "gtk_entry_completion_get_popup_set_width")]
430    #[doc(alias = "get_popup_set_width")]
431    #[doc(alias = "popup-set-width")]
432    pub fn is_popup_set_width(&self) -> bool {
433        unsafe {
434            from_glib(ffi::gtk_entry_completion_get_popup_set_width(
435                self.to_glib_none().0,
436            ))
437        }
438    }
439
440    /// Returns whether the completion popup window will appear even if there is
441    /// only a single match.
442    ///
443    /// # Deprecated since 4.10
444    ///
445    /// GtkEntryCompletion will be removed in GTK 5.
446    ///
447    /// # Returns
448    ///
449    /// [`true`] if the popup window will appear regardless of the
450    ///    number of matches
451    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
452    #[allow(deprecated)]
453    #[doc(alias = "gtk_entry_completion_get_popup_single_match")]
454    #[doc(alias = "get_popup_single_match")]
455    #[doc(alias = "popup-single-match")]
456    pub fn is_popup_single_match(&self) -> bool {
457        unsafe {
458            from_glib(ffi::gtk_entry_completion_get_popup_single_match(
459                self.to_glib_none().0,
460            ))
461        }
462    }
463
464    /// Returns the column in the model of @self to get strings from.
465    ///
466    /// # Deprecated since 4.10
467    ///
468    /// GtkEntryCompletion will be removed in GTK 5.
469    ///
470    /// # Returns
471    ///
472    /// the column containing the strings
473    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
474    #[allow(deprecated)]
475    #[doc(alias = "gtk_entry_completion_get_text_column")]
476    #[doc(alias = "get_text_column")]
477    #[doc(alias = "text-column")]
478    pub fn text_column(&self) -> i32 {
479        unsafe { ffi::gtk_entry_completion_get_text_column(self.to_glib_none().0) }
480    }
481
482    /// Requests a prefix insertion.
483    ///
484    /// # Deprecated since 4.10
485    ///
486    /// GtkEntryCompletion will be removed in GTK 5.
487    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
488    #[allow(deprecated)]
489    #[doc(alias = "gtk_entry_completion_insert_prefix")]
490    pub fn insert_prefix(&self) {
491        unsafe {
492            ffi::gtk_entry_completion_insert_prefix(self.to_glib_none().0);
493        }
494    }
495
496    /// Sets whether the common prefix of the possible completions should
497    /// be automatically inserted in the entry.
498    ///
499    /// # Deprecated since 4.10
500    ///
501    /// GtkEntryCompletion will be removed in GTK 5.
502    /// ## `inline_completion`
503    /// [`true`] to do inline completion
504    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
505    #[allow(deprecated)]
506    #[doc(alias = "gtk_entry_completion_set_inline_completion")]
507    #[doc(alias = "inline-completion")]
508    pub fn set_inline_completion(&self, inline_completion: bool) {
509        unsafe {
510            ffi::gtk_entry_completion_set_inline_completion(
511                self.to_glib_none().0,
512                inline_completion.into_glib(),
513            );
514        }
515    }
516
517    /// Sets whether it is possible to cycle through the possible completions
518    /// inside the entry.
519    ///
520    /// # Deprecated since 4.10
521    ///
522    /// GtkEntryCompletion will be removed in GTK 5.
523    /// ## `inline_selection`
524    /// [`true`] to do inline selection
525    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
526    #[allow(deprecated)]
527    #[doc(alias = "gtk_entry_completion_set_inline_selection")]
528    #[doc(alias = "inline-selection")]
529    pub fn set_inline_selection(&self, inline_selection: bool) {
530        unsafe {
531            ffi::gtk_entry_completion_set_inline_selection(
532                self.to_glib_none().0,
533                inline_selection.into_glib(),
534            );
535        }
536    }
537
538    /// Sets the match function for @self to be @func.
539    ///
540    /// The match function is used to determine if a row should or
541    /// should not be in the completion list.
542    ///
543    /// # Deprecated since 4.10
544    ///
545    /// GtkEntryCompletion will be removed in GTK 5.
546    /// ## `func`
547    /// the [`EntryCompletion`][crate::EntryCompletion]MatchFunc to use
548    /// ## `func_data`
549    /// user data for @func
550    /// ## `func_notify`
551    /// destroy notify for @func_data.
552    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
553    #[allow(deprecated)]
554    #[doc(alias = "gtk_entry_completion_set_match_func")]
555    pub fn set_match_func<P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static>(
556        &self,
557        func: P,
558    ) {
559        let func_data: Box_<P> = Box_::new(func);
560        unsafe extern "C" fn func_func<
561            P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static,
562        >(
563            completion: *mut ffi::GtkEntryCompletion,
564            key: *const std::ffi::c_char,
565            iter: *mut ffi::GtkTreeIter,
566            user_data: glib::ffi::gpointer,
567        ) -> glib::ffi::gboolean {
568            unsafe {
569                let completion = from_glib_borrow(completion);
570                let key: Borrowed<glib::GString> = from_glib_borrow(key);
571                let iter = from_glib_borrow(iter);
572                let callback = &*(user_data as *mut P);
573                (*callback)(&completion, key.as_str(), &iter).into_glib()
574            }
575        }
576        let func = Some(func_func::<P> as _);
577        unsafe extern "C" fn func_notify_func<
578            P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static,
579        >(
580            data: glib::ffi::gpointer,
581        ) {
582            unsafe {
583                let _callback = Box_::from_raw(data as *mut P);
584            }
585        }
586        let destroy_call3 = Some(func_notify_func::<P> as _);
587        let super_callback0: Box_<P> = func_data;
588        unsafe {
589            ffi::gtk_entry_completion_set_match_func(
590                self.to_glib_none().0,
591                func,
592                Box_::into_raw(super_callback0) as *mut _,
593                destroy_call3,
594            );
595        }
596    }
597
598    /// Requires the length of the search key for @self to be at least
599    /// @length.
600    ///
601    /// This is useful for long lists, where completing using a small
602    /// key takes a lot of time and will come up with meaningless results anyway
603    /// (ie, a too large dataset).
604    ///
605    /// # Deprecated since 4.10
606    ///
607    /// GtkEntryCompletion will be removed in GTK 5.
608    /// ## `length`
609    /// the minimum length of the key in order to start completing
610    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
611    #[allow(deprecated)]
612    #[doc(alias = "gtk_entry_completion_set_minimum_key_length")]
613    #[doc(alias = "minimum-key-length")]
614    pub fn set_minimum_key_length(&self, length: i32) {
615        unsafe {
616            ffi::gtk_entry_completion_set_minimum_key_length(self.to_glib_none().0, length);
617        }
618    }
619
620    /// Sets the model for a [`EntryCompletion`][crate::EntryCompletion].
621    ///
622    /// If @self already has a model set, it will remove it
623    /// before setting the new model. If model is [`None`], then it
624    /// will unset the model.
625    ///
626    /// # Deprecated since 4.10
627    ///
628    /// GtkEntryCompletion will be removed in GTK 5.
629    /// ## `model`
630    /// the [`TreeModel`][crate::TreeModel]
631    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
632    #[allow(deprecated)]
633    #[doc(alias = "gtk_entry_completion_set_model")]
634    #[doc(alias = "model")]
635    pub fn set_model(&self, model: Option<&impl IsA<TreeModel>>) {
636        unsafe {
637            ffi::gtk_entry_completion_set_model(
638                self.to_glib_none().0,
639                model.map(|p| p.as_ref()).to_glib_none().0,
640            );
641        }
642    }
643
644    /// Sets whether the completions should be presented in a popup window.
645    ///
646    /// # Deprecated since 4.10
647    ///
648    /// GtkEntryCompletion will be removed in GTK 5.
649    /// ## `popup_completion`
650    /// [`true`] to do popup completion
651    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
652    #[allow(deprecated)]
653    #[doc(alias = "gtk_entry_completion_set_popup_completion")]
654    #[doc(alias = "popup-completion")]
655    pub fn set_popup_completion(&self, popup_completion: bool) {
656        unsafe {
657            ffi::gtk_entry_completion_set_popup_completion(
658                self.to_glib_none().0,
659                popup_completion.into_glib(),
660            );
661        }
662    }
663
664    /// Sets whether the completion popup window will be resized to be the same
665    /// width as the entry.
666    ///
667    /// # Deprecated since 4.10
668    ///
669    /// GtkEntryCompletion will be removed in GTK 5.
670    /// ## `popup_set_width`
671    /// [`true`] to make the width of the popup the same as the entry
672    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
673    #[allow(deprecated)]
674    #[doc(alias = "gtk_entry_completion_set_popup_set_width")]
675    #[doc(alias = "popup-set-width")]
676    pub fn set_popup_set_width(&self, popup_set_width: bool) {
677        unsafe {
678            ffi::gtk_entry_completion_set_popup_set_width(
679                self.to_glib_none().0,
680                popup_set_width.into_glib(),
681            );
682        }
683    }
684
685    /// Sets whether the completion popup window will appear even if there is
686    /// only a single match.
687    ///
688    /// You may want to set this to [`false`] if you
689    /// are using [`inline-completion`][struct@crate::EntryCompletion#inline-completion].
690    ///
691    /// # Deprecated since 4.10
692    ///
693    /// GtkEntryCompletion will be removed in GTK 5.
694    /// ## `popup_single_match`
695    /// [`true`] if the popup should appear even for a single match
696    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
697    #[allow(deprecated)]
698    #[doc(alias = "gtk_entry_completion_set_popup_single_match")]
699    #[doc(alias = "popup-single-match")]
700    pub fn set_popup_single_match(&self, popup_single_match: bool) {
701        unsafe {
702            ffi::gtk_entry_completion_set_popup_single_match(
703                self.to_glib_none().0,
704                popup_single_match.into_glib(),
705            );
706        }
707    }
708
709    /// Convenience function for setting up the most used case of this code: a
710    /// completion list with just strings.
711    ///
712    /// This function will set up @self
713    /// to have a list displaying all (and just) strings in the completion list,
714    /// and to get those strings from @column in the model of @self.
715    ///
716    /// This functions creates and adds a [`CellRendererText`][crate::CellRendererText] for the selected
717    /// column. If you need to set the text column, but don't want the cell
718    /// renderer, use g_object_set() to set the
719    /// [`text-column`][struct@crate::EntryCompletion#text-column] property directly.
720    ///
721    /// # Deprecated since 4.10
722    ///
723    /// GtkEntryCompletion will be removed in GTK 5.
724    /// ## `column`
725    /// the column in the model of @self to get strings from
726    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
727    #[allow(deprecated)]
728    #[doc(alias = "gtk_entry_completion_set_text_column")]
729    #[doc(alias = "text-column")]
730    pub fn set_text_column(&self, column: i32) {
731        unsafe {
732            ffi::gtk_entry_completion_set_text_column(self.to_glib_none().0, column);
733        }
734    }
735
736    /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
737    ///
738    /// If no area is specified when creating the entry completion with
739    /// [`with_area()`][Self::with_area()], a horizontally oriented
740    /// [`CellAreaBox`][crate::CellAreaBox] will be used.
741    #[doc(alias = "cell-area")]
742    pub fn cell_area(&self) -> Option<CellArea> {
743        ObjectExt::property(self, "cell-area")
744    }
745
746    /// Emitted when a match from the cursor is on a match of the list.
747    ///
748    /// The default behaviour is to replace the contents
749    /// of the entry with the contents of the text column in the row
750    /// pointed to by @iter.
751    ///
752    /// Note that @model is the model that was passed to
753    /// [`set_model()`][Self::set_model()].
754    /// ## `model`
755    /// the [`TreeModel`][crate::TreeModel] containing the matches
756    /// ## `iter`
757    /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
758    ///
759    /// # Returns
760    ///
761    /// [`true`] if the signal has been handled
762    #[doc(alias = "cursor-on-match")]
763    pub fn connect_cursor_on_match<
764        F: Fn(&Self, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
765    >(
766        &self,
767        f: F,
768    ) -> SignalHandlerId {
769        unsafe extern "C" fn cursor_on_match_trampoline<
770            F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
771        >(
772            this: *mut ffi::GtkEntryCompletion,
773            model: *mut ffi::GtkTreeModel,
774            iter: *mut ffi::GtkTreeIter,
775            f: glib::ffi::gpointer,
776        ) -> glib::ffi::gboolean {
777            unsafe {
778                let f: &F = &*(f as *const F);
779                f(
780                    &from_glib_borrow(this),
781                    &from_glib_borrow(model),
782                    &from_glib_borrow(iter),
783                )
784                .into_glib()
785            }
786        }
787        unsafe {
788            let f: Box_<F> = Box_::new(f);
789            connect_raw(
790                self.as_ptr() as *mut _,
791                c"cursor-on-match".as_ptr() as *const _,
792                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
793                    cursor_on_match_trampoline::<F> as *const (),
794                )),
795                Box_::into_raw(f),
796            )
797        }
798    }
799
800    /// Emitted when the inline autocompletion is triggered.
801    ///
802    /// The default behaviour is to make the entry display the
803    /// whole prefix and select the newly inserted part.
804    ///
805    /// Applications may connect to this signal in order to insert only a
806    /// smaller part of the @prefix into the entry - e.g. the entry used in
807    /// the [`FileChooser`][crate::FileChooser] inserts only the part of the prefix up to the
808    /// next '/'.
809    /// ## `prefix`
810    /// the common prefix of all possible completions
811    ///
812    /// # Returns
813    ///
814    /// [`true`] if the signal has been handled
815    #[doc(alias = "insert-prefix")]
816    pub fn connect_insert_prefix<F: Fn(&Self, &str) -> glib::Propagation + 'static>(
817        &self,
818        f: F,
819    ) -> SignalHandlerId {
820        unsafe extern "C" fn insert_prefix_trampoline<
821            F: Fn(&EntryCompletion, &str) -> glib::Propagation + 'static,
822        >(
823            this: *mut ffi::GtkEntryCompletion,
824            prefix: *mut std::ffi::c_char,
825            f: glib::ffi::gpointer,
826        ) -> glib::ffi::gboolean {
827            unsafe {
828                let f: &F = &*(f as *const F);
829                f(
830                    &from_glib_borrow(this),
831                    &glib::GString::from_glib_borrow(prefix),
832                )
833                .into_glib()
834            }
835        }
836        unsafe {
837            let f: Box_<F> = Box_::new(f);
838            connect_raw(
839                self.as_ptr() as *mut _,
840                c"insert-prefix".as_ptr() as *const _,
841                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
842                    insert_prefix_trampoline::<F> as *const (),
843                )),
844                Box_::into_raw(f),
845            )
846        }
847    }
848
849    /// Emitted when a match from the list is selected.
850    ///
851    /// The default behaviour is to replace the contents of the
852    /// entry with the contents of the text column in the row
853    /// pointed to by @iter.
854    ///
855    /// Note that @model is the model that was passed to
856    /// [`set_model()`][Self::set_model()].
857    /// ## `model`
858    /// the [`TreeModel`][crate::TreeModel] containing the matches
859    /// ## `iter`
860    /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
861    ///
862    /// # Returns
863    ///
864    /// [`true`] if the signal has been handled
865    #[doc(alias = "match-selected")]
866    pub fn connect_match_selected<
867        F: Fn(&Self, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
868    >(
869        &self,
870        f: F,
871    ) -> SignalHandlerId {
872        unsafe extern "C" fn match_selected_trampoline<
873            F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
874        >(
875            this: *mut ffi::GtkEntryCompletion,
876            model: *mut ffi::GtkTreeModel,
877            iter: *mut ffi::GtkTreeIter,
878            f: glib::ffi::gpointer,
879        ) -> glib::ffi::gboolean {
880            unsafe {
881                let f: &F = &*(f as *const F);
882                f(
883                    &from_glib_borrow(this),
884                    &from_glib_borrow(model),
885                    &from_glib_borrow(iter),
886                )
887                .into_glib()
888            }
889        }
890        unsafe {
891            let f: Box_<F> = Box_::new(f);
892            connect_raw(
893                self.as_ptr() as *mut _,
894                c"match-selected".as_ptr() as *const _,
895                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
896                    match_selected_trampoline::<F> as *const (),
897                )),
898                Box_::into_raw(f),
899            )
900        }
901    }
902
903    /// Emitted when the filter model has zero
904    /// number of rows in completion_complete method.
905    ///
906    /// In other words when [`EntryCompletion`][crate::EntryCompletion] is out of suggestions.
907    #[doc(alias = "no-matches")]
908    pub fn connect_no_matches<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
909        unsafe extern "C" fn no_matches_trampoline<F: Fn(&EntryCompletion) + 'static>(
910            this: *mut ffi::GtkEntryCompletion,
911            f: glib::ffi::gpointer,
912        ) {
913            unsafe {
914                let f: &F = &*(f as *const F);
915                f(&from_glib_borrow(this))
916            }
917        }
918        unsafe {
919            let f: Box_<F> = Box_::new(f);
920            connect_raw(
921                self.as_ptr() as *mut _,
922                c"no-matches".as_ptr() as *const _,
923                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
924                    no_matches_trampoline::<F> as *const (),
925                )),
926                Box_::into_raw(f),
927            )
928        }
929    }
930
931    #[doc(alias = "inline-completion")]
932    pub fn connect_inline_completion_notify<F: Fn(&Self) + 'static>(
933        &self,
934        f: F,
935    ) -> SignalHandlerId {
936        unsafe extern "C" fn notify_inline_completion_trampoline<
937            F: Fn(&EntryCompletion) + 'static,
938        >(
939            this: *mut ffi::GtkEntryCompletion,
940            _param_spec: glib::ffi::gpointer,
941            f: glib::ffi::gpointer,
942        ) {
943            unsafe {
944                let f: &F = &*(f as *const F);
945                f(&from_glib_borrow(this))
946            }
947        }
948        unsafe {
949            let f: Box_<F> = Box_::new(f);
950            connect_raw(
951                self.as_ptr() as *mut _,
952                c"notify::inline-completion".as_ptr() as *const _,
953                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
954                    notify_inline_completion_trampoline::<F> as *const (),
955                )),
956                Box_::into_raw(f),
957            )
958        }
959    }
960
961    #[doc(alias = "inline-selection")]
962    pub fn connect_inline_selection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
963        unsafe extern "C" fn notify_inline_selection_trampoline<
964            F: Fn(&EntryCompletion) + 'static,
965        >(
966            this: *mut ffi::GtkEntryCompletion,
967            _param_spec: glib::ffi::gpointer,
968            f: glib::ffi::gpointer,
969        ) {
970            unsafe {
971                let f: &F = &*(f as *const F);
972                f(&from_glib_borrow(this))
973            }
974        }
975        unsafe {
976            let f: Box_<F> = Box_::new(f);
977            connect_raw(
978                self.as_ptr() as *mut _,
979                c"notify::inline-selection".as_ptr() as *const _,
980                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
981                    notify_inline_selection_trampoline::<F> as *const (),
982                )),
983                Box_::into_raw(f),
984            )
985        }
986    }
987
988    #[doc(alias = "minimum-key-length")]
989    pub fn connect_minimum_key_length_notify<F: Fn(&Self) + 'static>(
990        &self,
991        f: F,
992    ) -> SignalHandlerId {
993        unsafe extern "C" fn notify_minimum_key_length_trampoline<
994            F: Fn(&EntryCompletion) + 'static,
995        >(
996            this: *mut ffi::GtkEntryCompletion,
997            _param_spec: glib::ffi::gpointer,
998            f: glib::ffi::gpointer,
999        ) {
1000            unsafe {
1001                let f: &F = &*(f as *const F);
1002                f(&from_glib_borrow(this))
1003            }
1004        }
1005        unsafe {
1006            let f: Box_<F> = Box_::new(f);
1007            connect_raw(
1008                self.as_ptr() as *mut _,
1009                c"notify::minimum-key-length".as_ptr() as *const _,
1010                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1011                    notify_minimum_key_length_trampoline::<F> as *const (),
1012                )),
1013                Box_::into_raw(f),
1014            )
1015        }
1016    }
1017
1018    #[doc(alias = "model")]
1019    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1020        unsafe extern "C" fn notify_model_trampoline<F: Fn(&EntryCompletion) + 'static>(
1021            this: *mut ffi::GtkEntryCompletion,
1022            _param_spec: glib::ffi::gpointer,
1023            f: glib::ffi::gpointer,
1024        ) {
1025            unsafe {
1026                let f: &F = &*(f as *const F);
1027                f(&from_glib_borrow(this))
1028            }
1029        }
1030        unsafe {
1031            let f: Box_<F> = Box_::new(f);
1032            connect_raw(
1033                self.as_ptr() as *mut _,
1034                c"notify::model".as_ptr() as *const _,
1035                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1036                    notify_model_trampoline::<F> as *const (),
1037                )),
1038                Box_::into_raw(f),
1039            )
1040        }
1041    }
1042
1043    #[doc(alias = "popup-completion")]
1044    pub fn connect_popup_completion_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1045        unsafe extern "C" fn notify_popup_completion_trampoline<
1046            F: Fn(&EntryCompletion) + 'static,
1047        >(
1048            this: *mut ffi::GtkEntryCompletion,
1049            _param_spec: glib::ffi::gpointer,
1050            f: glib::ffi::gpointer,
1051        ) {
1052            unsafe {
1053                let f: &F = &*(f as *const F);
1054                f(&from_glib_borrow(this))
1055            }
1056        }
1057        unsafe {
1058            let f: Box_<F> = Box_::new(f);
1059            connect_raw(
1060                self.as_ptr() as *mut _,
1061                c"notify::popup-completion".as_ptr() as *const _,
1062                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1063                    notify_popup_completion_trampoline::<F> as *const (),
1064                )),
1065                Box_::into_raw(f),
1066            )
1067        }
1068    }
1069
1070    #[doc(alias = "popup-set-width")]
1071    pub fn connect_popup_set_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1072        unsafe extern "C" fn notify_popup_set_width_trampoline<
1073            F: Fn(&EntryCompletion) + 'static,
1074        >(
1075            this: *mut ffi::GtkEntryCompletion,
1076            _param_spec: glib::ffi::gpointer,
1077            f: glib::ffi::gpointer,
1078        ) {
1079            unsafe {
1080                let f: &F = &*(f as *const F);
1081                f(&from_glib_borrow(this))
1082            }
1083        }
1084        unsafe {
1085            let f: Box_<F> = Box_::new(f);
1086            connect_raw(
1087                self.as_ptr() as *mut _,
1088                c"notify::popup-set-width".as_ptr() as *const _,
1089                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1090                    notify_popup_set_width_trampoline::<F> as *const (),
1091                )),
1092                Box_::into_raw(f),
1093            )
1094        }
1095    }
1096
1097    #[doc(alias = "popup-single-match")]
1098    pub fn connect_popup_single_match_notify<F: Fn(&Self) + 'static>(
1099        &self,
1100        f: F,
1101    ) -> SignalHandlerId {
1102        unsafe extern "C" fn notify_popup_single_match_trampoline<
1103            F: Fn(&EntryCompletion) + 'static,
1104        >(
1105            this: *mut ffi::GtkEntryCompletion,
1106            _param_spec: glib::ffi::gpointer,
1107            f: glib::ffi::gpointer,
1108        ) {
1109            unsafe {
1110                let f: &F = &*(f as *const F);
1111                f(&from_glib_borrow(this))
1112            }
1113        }
1114        unsafe {
1115            let f: Box_<F> = Box_::new(f);
1116            connect_raw(
1117                self.as_ptr() as *mut _,
1118                c"notify::popup-single-match".as_ptr() as *const _,
1119                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1120                    notify_popup_single_match_trampoline::<F> as *const (),
1121                )),
1122                Box_::into_raw(f),
1123            )
1124        }
1125    }
1126
1127    #[doc(alias = "text-column")]
1128    pub fn connect_text_column_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1129        unsafe extern "C" fn notify_text_column_trampoline<F: Fn(&EntryCompletion) + 'static>(
1130            this: *mut ffi::GtkEntryCompletion,
1131            _param_spec: glib::ffi::gpointer,
1132            f: glib::ffi::gpointer,
1133        ) {
1134            unsafe {
1135                let f: &F = &*(f as *const F);
1136                f(&from_glib_borrow(this))
1137            }
1138        }
1139        unsafe {
1140            let f: Box_<F> = Box_::new(f);
1141            connect_raw(
1142                self.as_ptr() as *mut _,
1143                c"notify::text-column".as_ptr() as *const _,
1144                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1145                    notify_text_column_trampoline::<F> as *const (),
1146                )),
1147                Box_::into_raw(f),
1148            )
1149        }
1150    }
1151}
1152
1153impl Default for EntryCompletion {
1154    fn default() -> Self {
1155        Self::new()
1156    }
1157}
1158
1159// rustdoc-stripper-ignore-next
1160/// A [builder-pattern] type to construct [`EntryCompletion`] objects.
1161///
1162/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1163#[must_use = "The builder must be built to be used"]
1164pub struct EntryCompletionBuilder {
1165    builder: glib::object::ObjectBuilder<'static, EntryCompletion>,
1166}
1167
1168impl EntryCompletionBuilder {
1169    fn new() -> Self {
1170        Self {
1171            builder: glib::object::Object::builder(),
1172        }
1173    }
1174
1175    /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
1176    ///
1177    /// If no area is specified when creating the entry completion with
1178    /// [`EntryCompletion::with_area()`][crate::EntryCompletion::with_area()], a horizontally oriented
1179    /// [`CellAreaBox`][crate::CellAreaBox] will be used.
1180    pub fn cell_area(self, cell_area: &impl IsA<CellArea>) -> Self {
1181        Self {
1182            builder: self
1183                .builder
1184                .property("cell-area", cell_area.clone().upcast()),
1185        }
1186    }
1187
1188    /// Determines whether the common prefix of the possible completions
1189    /// should be inserted automatically in the entry.
1190    ///
1191    /// Note that this requires text-column to be set, even if you are
1192    /// using a custom match function.
1193    pub fn inline_completion(self, inline_completion: bool) -> Self {
1194        Self {
1195            builder: self
1196                .builder
1197                .property("inline-completion", inline_completion),
1198        }
1199    }
1200
1201    /// Determines whether the possible completions on the popup
1202    /// will appear in the entry as you navigate through them.
1203    pub fn inline_selection(self, inline_selection: bool) -> Self {
1204        Self {
1205            builder: self.builder.property("inline-selection", inline_selection),
1206        }
1207    }
1208
1209    /// The minimum key length as set for completion.
1210    pub fn minimum_key_length(self, minimum_key_length: i32) -> Self {
1211        Self {
1212            builder: self
1213                .builder
1214                .property("minimum-key-length", minimum_key_length),
1215        }
1216    }
1217
1218    /// The model used as data source.
1219    pub fn model(self, model: &impl IsA<TreeModel>) -> Self {
1220        Self {
1221            builder: self.builder.property("model", model.clone().upcast()),
1222        }
1223    }
1224
1225    /// Determines whether the possible completions should be
1226    /// shown in a popup window.
1227    pub fn popup_completion(self, popup_completion: bool) -> Self {
1228        Self {
1229            builder: self.builder.property("popup-completion", popup_completion),
1230        }
1231    }
1232
1233    /// Determines whether the completions popup window will be
1234    /// resized to the width of the entry.
1235    pub fn popup_set_width(self, popup_set_width: bool) -> Self {
1236        Self {
1237            builder: self.builder.property("popup-set-width", popup_set_width),
1238        }
1239    }
1240
1241    /// Determines whether the completions popup window will shown
1242    /// for a single possible completion.
1243    ///
1244    /// You probably want to set this to [`false`] if you are using
1245    /// [`inline-completion`][struct@crate::EntryCompletion#inline-completion].
1246    pub fn popup_single_match(self, popup_single_match: bool) -> Self {
1247        Self {
1248            builder: self
1249                .builder
1250                .property("popup-single-match", popup_single_match),
1251        }
1252    }
1253
1254    /// The column of the model containing the strings.
1255    ///
1256    /// Note that the strings must be UTF-8.
1257    pub fn text_column(self, text_column: i32) -> Self {
1258        Self {
1259            builder: self.builder.property("text-column", text_column),
1260        }
1261    }
1262
1263    // rustdoc-stripper-ignore-next
1264    /// Build the [`EntryCompletion`].
1265    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1266    pub fn build(self) -> EntryCompletion {
1267        assert_initialized_main_thread!();
1268        self.builder.build()
1269    }
1270}