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