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