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::{ffi, Buildable, CellArea, CellLayout, TreeIter, TreeModel};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
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 let completion = from_glib_borrow(completion);
569 let key: Borrowed<glib::GString> = from_glib_borrow(key);
570 let iter = from_glib_borrow(iter);
571 let callback = &*(user_data as *mut P);
572 (*callback)(&completion, key.as_str(), &iter).into_glib()
573 }
574 let func = Some(func_func::<P> as _);
575 unsafe extern "C" fn func_notify_func<
576 P: Fn(&EntryCompletion, &str, &TreeIter) -> bool + 'static,
577 >(
578 data: glib::ffi::gpointer,
579 ) {
580 let _callback = Box_::from_raw(data as *mut P);
581 }
582 let destroy_call3 = Some(func_notify_func::<P> as _);
583 let super_callback0: Box_<P> = func_data;
584 unsafe {
585 ffi::gtk_entry_completion_set_match_func(
586 self.to_glib_none().0,
587 func,
588 Box_::into_raw(super_callback0) as *mut _,
589 destroy_call3,
590 );
591 }
592 }
593
594 /// Requires the length of the search key for @self to be at least
595 /// @length.
596 ///
597 /// This is useful for long lists, where completing using a small
598 /// key takes a lot of time and will come up with meaningless results anyway
599 /// (ie, a too large dataset).
600 ///
601 /// # Deprecated since 4.10
602 ///
603 /// GtkEntryCompletion will be removed in GTK 5.
604 /// ## `length`
605 /// the minimum length of the key in order to start completing
606 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
607 #[allow(deprecated)]
608 #[doc(alias = "gtk_entry_completion_set_minimum_key_length")]
609 #[doc(alias = "minimum-key-length")]
610 pub fn set_minimum_key_length(&self, length: i32) {
611 unsafe {
612 ffi::gtk_entry_completion_set_minimum_key_length(self.to_glib_none().0, length);
613 }
614 }
615
616 /// Sets the model for a [`EntryCompletion`][crate::EntryCompletion].
617 ///
618 /// If @self already has a model set, it will remove it
619 /// before setting the new model. If model is [`None`], then it
620 /// will unset the model.
621 ///
622 /// # Deprecated since 4.10
623 ///
624 /// GtkEntryCompletion will be removed in GTK 5.
625 /// ## `model`
626 /// the [`TreeModel`][crate::TreeModel]
627 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
628 #[allow(deprecated)]
629 #[doc(alias = "gtk_entry_completion_set_model")]
630 #[doc(alias = "model")]
631 pub fn set_model(&self, model: Option<&impl IsA<TreeModel>>) {
632 unsafe {
633 ffi::gtk_entry_completion_set_model(
634 self.to_glib_none().0,
635 model.map(|p| p.as_ref()).to_glib_none().0,
636 );
637 }
638 }
639
640 /// Sets whether the completions should be presented in a popup window.
641 ///
642 /// # Deprecated since 4.10
643 ///
644 /// GtkEntryCompletion will be removed in GTK 5.
645 /// ## `popup_completion`
646 /// [`true`] to do popup completion
647 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
648 #[allow(deprecated)]
649 #[doc(alias = "gtk_entry_completion_set_popup_completion")]
650 #[doc(alias = "popup-completion")]
651 pub fn set_popup_completion(&self, popup_completion: bool) {
652 unsafe {
653 ffi::gtk_entry_completion_set_popup_completion(
654 self.to_glib_none().0,
655 popup_completion.into_glib(),
656 );
657 }
658 }
659
660 /// Sets whether the completion popup window will be resized to be the same
661 /// width as the entry.
662 ///
663 /// # Deprecated since 4.10
664 ///
665 /// GtkEntryCompletion will be removed in GTK 5.
666 /// ## `popup_set_width`
667 /// [`true`] to make the width of the popup the same as the entry
668 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
669 #[allow(deprecated)]
670 #[doc(alias = "gtk_entry_completion_set_popup_set_width")]
671 #[doc(alias = "popup-set-width")]
672 pub fn set_popup_set_width(&self, popup_set_width: bool) {
673 unsafe {
674 ffi::gtk_entry_completion_set_popup_set_width(
675 self.to_glib_none().0,
676 popup_set_width.into_glib(),
677 );
678 }
679 }
680
681 /// Sets whether the completion popup window will appear even if there is
682 /// only a single match.
683 ///
684 /// You may want to set this to [`false`] if you
685 /// are using [`inline-completion`][struct@crate::EntryCompletion#inline-completion].
686 ///
687 /// # Deprecated since 4.10
688 ///
689 /// GtkEntryCompletion will be removed in GTK 5.
690 /// ## `popup_single_match`
691 /// [`true`] if the popup should appear even for a single match
692 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
693 #[allow(deprecated)]
694 #[doc(alias = "gtk_entry_completion_set_popup_single_match")]
695 #[doc(alias = "popup-single-match")]
696 pub fn set_popup_single_match(&self, popup_single_match: bool) {
697 unsafe {
698 ffi::gtk_entry_completion_set_popup_single_match(
699 self.to_glib_none().0,
700 popup_single_match.into_glib(),
701 );
702 }
703 }
704
705 /// Convenience function for setting up the most used case of this code: a
706 /// completion list with just strings.
707 ///
708 /// This function will set up @self
709 /// to have a list displaying all (and just) strings in the completion list,
710 /// and to get those strings from @column in the model of @self.
711 ///
712 /// This functions creates and adds a [`CellRendererText`][crate::CellRendererText] for the selected
713 /// column. If you need to set the text column, but don't want the cell
714 /// renderer, use g_object_set() to set the
715 /// [`text-column`][struct@crate::EntryCompletion#text-column] property directly.
716 ///
717 /// # Deprecated since 4.10
718 ///
719 /// GtkEntryCompletion will be removed in GTK 5.
720 /// ## `column`
721 /// the column in the model of @self to get strings from
722 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
723 #[allow(deprecated)]
724 #[doc(alias = "gtk_entry_completion_set_text_column")]
725 #[doc(alias = "text-column")]
726 pub fn set_text_column(&self, column: i32) {
727 unsafe {
728 ffi::gtk_entry_completion_set_text_column(self.to_glib_none().0, column);
729 }
730 }
731
732 /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
733 ///
734 /// If no area is specified when creating the entry completion with
735 /// [`with_area()`][Self::with_area()], a horizontally oriented
736 /// [`CellAreaBox`][crate::CellAreaBox] will be used.
737 #[doc(alias = "cell-area")]
738 pub fn cell_area(&self) -> Option<CellArea> {
739 ObjectExt::property(self, "cell-area")
740 }
741
742 /// Emitted when a match from the cursor is on a match of the list.
743 ///
744 /// The default behaviour is to replace the contents
745 /// of the entry with the contents of the text column in the row
746 /// pointed to by @iter.
747 ///
748 /// Note that @model is the model that was passed to
749 /// [`set_model()`][Self::set_model()].
750 /// ## `model`
751 /// the [`TreeModel`][crate::TreeModel] containing the matches
752 /// ## `iter`
753 /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
754 ///
755 /// # Returns
756 ///
757 /// [`true`] if the signal has been handled
758 #[doc(alias = "cursor-on-match")]
759 pub fn connect_cursor_on_match<
760 F: Fn(&Self, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
761 >(
762 &self,
763 f: F,
764 ) -> SignalHandlerId {
765 unsafe extern "C" fn cursor_on_match_trampoline<
766 F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
767 >(
768 this: *mut ffi::GtkEntryCompletion,
769 model: *mut ffi::GtkTreeModel,
770 iter: *mut ffi::GtkTreeIter,
771 f: glib::ffi::gpointer,
772 ) -> glib::ffi::gboolean {
773 let f: &F = &*(f as *const F);
774 f(
775 &from_glib_borrow(this),
776 &from_glib_borrow(model),
777 &from_glib_borrow(iter),
778 )
779 .into_glib()
780 }
781 unsafe {
782 let f: Box_<F> = Box_::new(f);
783 connect_raw(
784 self.as_ptr() as *mut _,
785 c"cursor-on-match".as_ptr() as *const _,
786 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
787 cursor_on_match_trampoline::<F> as *const (),
788 )),
789 Box_::into_raw(f),
790 )
791 }
792 }
793
794 /// Emitted when the inline autocompletion is triggered.
795 ///
796 /// The default behaviour is to make the entry display the
797 /// whole prefix and select the newly inserted part.
798 ///
799 /// Applications may connect to this signal in order to insert only a
800 /// smaller part of the @prefix into the entry - e.g. the entry used in
801 /// the [`FileChooser`][crate::FileChooser] inserts only the part of the prefix up to the
802 /// next '/'.
803 /// ## `prefix`
804 /// the common prefix of all possible completions
805 ///
806 /// # Returns
807 ///
808 /// [`true`] if the signal has been handled
809 #[doc(alias = "insert-prefix")]
810 pub fn connect_insert_prefix<F: Fn(&Self, &str) -> glib::Propagation + 'static>(
811 &self,
812 f: F,
813 ) -> SignalHandlerId {
814 unsafe extern "C" fn insert_prefix_trampoline<
815 F: Fn(&EntryCompletion, &str) -> glib::Propagation + 'static,
816 >(
817 this: *mut ffi::GtkEntryCompletion,
818 prefix: *mut std::ffi::c_char,
819 f: glib::ffi::gpointer,
820 ) -> glib::ffi::gboolean {
821 let f: &F = &*(f as *const F);
822 f(
823 &from_glib_borrow(this),
824 &glib::GString::from_glib_borrow(prefix),
825 )
826 .into_glib()
827 }
828 unsafe {
829 let f: Box_<F> = Box_::new(f);
830 connect_raw(
831 self.as_ptr() as *mut _,
832 c"insert-prefix".as_ptr() as *const _,
833 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
834 insert_prefix_trampoline::<F> as *const (),
835 )),
836 Box_::into_raw(f),
837 )
838 }
839 }
840
841 /// Emitted when a match from the list is selected.
842 ///
843 /// The default behaviour is to replace the contents of the
844 /// entry with the contents of the text column in the row
845 /// pointed to by @iter.
846 ///
847 /// Note that @model is the model that was passed to
848 /// [`set_model()`][Self::set_model()].
849 /// ## `model`
850 /// the [`TreeModel`][crate::TreeModel] containing the matches
851 /// ## `iter`
852 /// a [`TreeIter`][crate::TreeIter] positioned at the selected match
853 ///
854 /// # Returns
855 ///
856 /// [`true`] if the signal has been handled
857 #[doc(alias = "match-selected")]
858 pub fn connect_match_selected<
859 F: Fn(&Self, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
860 >(
861 &self,
862 f: F,
863 ) -> SignalHandlerId {
864 unsafe extern "C" fn match_selected_trampoline<
865 F: Fn(&EntryCompletion, &TreeModel, &TreeIter) -> glib::Propagation + 'static,
866 >(
867 this: *mut ffi::GtkEntryCompletion,
868 model: *mut ffi::GtkTreeModel,
869 iter: *mut ffi::GtkTreeIter,
870 f: glib::ffi::gpointer,
871 ) -> glib::ffi::gboolean {
872 let f: &F = &*(f as *const F);
873 f(
874 &from_glib_borrow(this),
875 &from_glib_borrow(model),
876 &from_glib_borrow(iter),
877 )
878 .into_glib()
879 }
880 unsafe {
881 let f: Box_<F> = Box_::new(f);
882 connect_raw(
883 self.as_ptr() as *mut _,
884 c"match-selected".as_ptr() as *const _,
885 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
886 match_selected_trampoline::<F> as *const (),
887 )),
888 Box_::into_raw(f),
889 )
890 }
891 }
892
893 /// Emitted when the filter model has zero
894 /// number of rows in completion_complete method.
895 ///
896 /// In other words when [`EntryCompletion`][crate::EntryCompletion] is out of suggestions.
897 #[doc(alias = "no-matches")]
898 pub fn connect_no_matches<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
899 unsafe extern "C" fn no_matches_trampoline<F: Fn(&EntryCompletion) + 'static>(
900 this: *mut ffi::GtkEntryCompletion,
901 f: glib::ffi::gpointer,
902 ) {
903 let f: &F = &*(f as *const F);
904 f(&from_glib_borrow(this))
905 }
906 unsafe {
907 let f: Box_<F> = Box_::new(f);
908 connect_raw(
909 self.as_ptr() as *mut _,
910 c"no-matches".as_ptr() as *const _,
911 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
912 no_matches_trampoline::<F> as *const (),
913 )),
914 Box_::into_raw(f),
915 )
916 }
917 }
918
919 #[doc(alias = "inline-completion")]
920 pub fn connect_inline_completion_notify<F: Fn(&Self) + 'static>(
921 &self,
922 f: F,
923 ) -> SignalHandlerId {
924 unsafe extern "C" fn notify_inline_completion_trampoline<
925 F: Fn(&EntryCompletion) + 'static,
926 >(
927 this: *mut ffi::GtkEntryCompletion,
928 _param_spec: glib::ffi::gpointer,
929 f: glib::ffi::gpointer,
930 ) {
931 let f: &F = &*(f as *const F);
932 f(&from_glib_borrow(this))
933 }
934 unsafe {
935 let f: Box_<F> = Box_::new(f);
936 connect_raw(
937 self.as_ptr() as *mut _,
938 c"notify::inline-completion".as_ptr() as *const _,
939 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
940 notify_inline_completion_trampoline::<F> as *const (),
941 )),
942 Box_::into_raw(f),
943 )
944 }
945 }
946
947 #[doc(alias = "inline-selection")]
948 pub fn connect_inline_selection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
949 unsafe extern "C" fn notify_inline_selection_trampoline<
950 F: Fn(&EntryCompletion) + 'static,
951 >(
952 this: *mut ffi::GtkEntryCompletion,
953 _param_spec: glib::ffi::gpointer,
954 f: glib::ffi::gpointer,
955 ) {
956 let f: &F = &*(f as *const F);
957 f(&from_glib_borrow(this))
958 }
959 unsafe {
960 let f: Box_<F> = Box_::new(f);
961 connect_raw(
962 self.as_ptr() as *mut _,
963 c"notify::inline-selection".as_ptr() as *const _,
964 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
965 notify_inline_selection_trampoline::<F> as *const (),
966 )),
967 Box_::into_raw(f),
968 )
969 }
970 }
971
972 #[doc(alias = "minimum-key-length")]
973 pub fn connect_minimum_key_length_notify<F: Fn(&Self) + 'static>(
974 &self,
975 f: F,
976 ) -> SignalHandlerId {
977 unsafe extern "C" fn notify_minimum_key_length_trampoline<
978 F: Fn(&EntryCompletion) + 'static,
979 >(
980 this: *mut ffi::GtkEntryCompletion,
981 _param_spec: glib::ffi::gpointer,
982 f: glib::ffi::gpointer,
983 ) {
984 let f: &F = &*(f as *const F);
985 f(&from_glib_borrow(this))
986 }
987 unsafe {
988 let f: Box_<F> = Box_::new(f);
989 connect_raw(
990 self.as_ptr() as *mut _,
991 c"notify::minimum-key-length".as_ptr() as *const _,
992 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
993 notify_minimum_key_length_trampoline::<F> as *const (),
994 )),
995 Box_::into_raw(f),
996 )
997 }
998 }
999
1000 #[doc(alias = "model")]
1001 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1002 unsafe extern "C" fn notify_model_trampoline<F: Fn(&EntryCompletion) + 'static>(
1003 this: *mut ffi::GtkEntryCompletion,
1004 _param_spec: glib::ffi::gpointer,
1005 f: glib::ffi::gpointer,
1006 ) {
1007 let f: &F = &*(f as *const F);
1008 f(&from_glib_borrow(this))
1009 }
1010 unsafe {
1011 let f: Box_<F> = Box_::new(f);
1012 connect_raw(
1013 self.as_ptr() as *mut _,
1014 c"notify::model".as_ptr() as *const _,
1015 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1016 notify_model_trampoline::<F> as *const (),
1017 )),
1018 Box_::into_raw(f),
1019 )
1020 }
1021 }
1022
1023 #[doc(alias = "popup-completion")]
1024 pub fn connect_popup_completion_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1025 unsafe extern "C" fn notify_popup_completion_trampoline<
1026 F: Fn(&EntryCompletion) + 'static,
1027 >(
1028 this: *mut ffi::GtkEntryCompletion,
1029 _param_spec: glib::ffi::gpointer,
1030 f: glib::ffi::gpointer,
1031 ) {
1032 let f: &F = &*(f as *const F);
1033 f(&from_glib_borrow(this))
1034 }
1035 unsafe {
1036 let f: Box_<F> = Box_::new(f);
1037 connect_raw(
1038 self.as_ptr() as *mut _,
1039 c"notify::popup-completion".as_ptr() as *const _,
1040 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1041 notify_popup_completion_trampoline::<F> as *const (),
1042 )),
1043 Box_::into_raw(f),
1044 )
1045 }
1046 }
1047
1048 #[doc(alias = "popup-set-width")]
1049 pub fn connect_popup_set_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1050 unsafe extern "C" fn notify_popup_set_width_trampoline<
1051 F: Fn(&EntryCompletion) + 'static,
1052 >(
1053 this: *mut ffi::GtkEntryCompletion,
1054 _param_spec: glib::ffi::gpointer,
1055 f: glib::ffi::gpointer,
1056 ) {
1057 let f: &F = &*(f as *const F);
1058 f(&from_glib_borrow(this))
1059 }
1060 unsafe {
1061 let f: Box_<F> = Box_::new(f);
1062 connect_raw(
1063 self.as_ptr() as *mut _,
1064 c"notify::popup-set-width".as_ptr() as *const _,
1065 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1066 notify_popup_set_width_trampoline::<F> as *const (),
1067 )),
1068 Box_::into_raw(f),
1069 )
1070 }
1071 }
1072
1073 #[doc(alias = "popup-single-match")]
1074 pub fn connect_popup_single_match_notify<F: Fn(&Self) + 'static>(
1075 &self,
1076 f: F,
1077 ) -> SignalHandlerId {
1078 unsafe extern "C" fn notify_popup_single_match_trampoline<
1079 F: Fn(&EntryCompletion) + 'static,
1080 >(
1081 this: *mut ffi::GtkEntryCompletion,
1082 _param_spec: glib::ffi::gpointer,
1083 f: glib::ffi::gpointer,
1084 ) {
1085 let f: &F = &*(f as *const F);
1086 f(&from_glib_borrow(this))
1087 }
1088 unsafe {
1089 let f: Box_<F> = Box_::new(f);
1090 connect_raw(
1091 self.as_ptr() as *mut _,
1092 c"notify::popup-single-match".as_ptr() as *const _,
1093 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1094 notify_popup_single_match_trampoline::<F> as *const (),
1095 )),
1096 Box_::into_raw(f),
1097 )
1098 }
1099 }
1100
1101 #[doc(alias = "text-column")]
1102 pub fn connect_text_column_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1103 unsafe extern "C" fn notify_text_column_trampoline<F: Fn(&EntryCompletion) + 'static>(
1104 this: *mut ffi::GtkEntryCompletion,
1105 _param_spec: glib::ffi::gpointer,
1106 f: glib::ffi::gpointer,
1107 ) {
1108 let f: &F = &*(f as *const F);
1109 f(&from_glib_borrow(this))
1110 }
1111 unsafe {
1112 let f: Box_<F> = Box_::new(f);
1113 connect_raw(
1114 self.as_ptr() as *mut _,
1115 c"notify::text-column".as_ptr() as *const _,
1116 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1117 notify_text_column_trampoline::<F> as *const (),
1118 )),
1119 Box_::into_raw(f),
1120 )
1121 }
1122 }
1123}
1124
1125impl Default for EntryCompletion {
1126 fn default() -> Self {
1127 Self::new()
1128 }
1129}
1130
1131// rustdoc-stripper-ignore-next
1132/// A [builder-pattern] type to construct [`EntryCompletion`] objects.
1133///
1134/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1135#[must_use = "The builder must be built to be used"]
1136pub struct EntryCompletionBuilder {
1137 builder: glib::object::ObjectBuilder<'static, EntryCompletion>,
1138}
1139
1140impl EntryCompletionBuilder {
1141 fn new() -> Self {
1142 Self {
1143 builder: glib::object::Object::builder(),
1144 }
1145 }
1146
1147 /// The [`CellArea`][crate::CellArea] used to layout cell renderers in the treeview column.
1148 ///
1149 /// If no area is specified when creating the entry completion with
1150 /// [`EntryCompletion::with_area()`][crate::EntryCompletion::with_area()], a horizontally oriented
1151 /// [`CellAreaBox`][crate::CellAreaBox] will be used.
1152 pub fn cell_area(self, cell_area: &impl IsA<CellArea>) -> Self {
1153 Self {
1154 builder: self
1155 .builder
1156 .property("cell-area", cell_area.clone().upcast()),
1157 }
1158 }
1159
1160 /// Determines whether the common prefix of the possible completions
1161 /// should be inserted automatically in the entry.
1162 ///
1163 /// Note that this requires text-column to be set, even if you are
1164 /// using a custom match function.
1165 pub fn inline_completion(self, inline_completion: bool) -> Self {
1166 Self {
1167 builder: self
1168 .builder
1169 .property("inline-completion", inline_completion),
1170 }
1171 }
1172
1173 /// Determines whether the possible completions on the popup
1174 /// will appear in the entry as you navigate through them.
1175 pub fn inline_selection(self, inline_selection: bool) -> Self {
1176 Self {
1177 builder: self.builder.property("inline-selection", inline_selection),
1178 }
1179 }
1180
1181 /// The minimum key length as set for completion.
1182 pub fn minimum_key_length(self, minimum_key_length: i32) -> Self {
1183 Self {
1184 builder: self
1185 .builder
1186 .property("minimum-key-length", minimum_key_length),
1187 }
1188 }
1189
1190 /// The model used as data source.
1191 pub fn model(self, model: &impl IsA<TreeModel>) -> Self {
1192 Self {
1193 builder: self.builder.property("model", model.clone().upcast()),
1194 }
1195 }
1196
1197 /// Determines whether the possible completions should be
1198 /// shown in a popup window.
1199 pub fn popup_completion(self, popup_completion: bool) -> Self {
1200 Self {
1201 builder: self.builder.property("popup-completion", popup_completion),
1202 }
1203 }
1204
1205 /// Determines whether the completions popup window will be
1206 /// resized to the width of the entry.
1207 pub fn popup_set_width(self, popup_set_width: bool) -> Self {
1208 Self {
1209 builder: self.builder.property("popup-set-width", popup_set_width),
1210 }
1211 }
1212
1213 /// Determines whether the completions popup window will shown
1214 /// for a single possible completion.
1215 ///
1216 /// You probably want to set this to [`false`] if you are using
1217 /// [`inline-completion`][struct@crate::EntryCompletion#inline-completion].
1218 pub fn popup_single_match(self, popup_single_match: bool) -> Self {
1219 Self {
1220 builder: self
1221 .builder
1222 .property("popup-single-match", popup_single_match),
1223 }
1224 }
1225
1226 /// The column of the model containing the strings.
1227 ///
1228 /// Note that the strings must be UTF-8.
1229 pub fn text_column(self, text_column: i32) -> Self {
1230 Self {
1231 builder: self.builder.property("text-column", text_column),
1232 }
1233 }
1234
1235 // rustdoc-stripper-ignore-next
1236 /// Build the [`EntryCompletion`].
1237 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1238 pub fn build(self) -> EntryCompletion {
1239 assert_initialized_main_thread!();
1240 self.builder.build()
1241 }
1242}