gtk4/auto/selection_filter_model.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::{ffi, SelectionModel};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// A list model that presents the selection from a [`SelectionModel`][crate::SelectionModel].
15 ///
16 /// ## Properties
17 ///
18 ///
19 /// #### `item-type`
20 /// The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
21 ///
22 /// Readable
23 ///
24 ///
25 /// #### `model`
26 /// The model being filtered.
27 ///
28 /// Readable | Writeable
29 ///
30 ///
31 /// #### `n-items`
32 /// The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
33 ///
34 /// Readable
35 ///
36 /// # Implements
37 ///
38 /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`]
39 #[doc(alias = "GtkSelectionFilterModel")]
40 pub struct SelectionFilterModel(Object<ffi::GtkSelectionFilterModel, ffi::GtkSelectionFilterModelClass>) @implements gio::ListModel;
41
42 match fn {
43 type_ => || ffi::gtk_selection_filter_model_get_type(),
44 }
45}
46
47impl SelectionFilterModel {
48 /// Creates a new [`SelectionFilterModel`][crate::SelectionFilterModel] that will include the
49 /// selected items from the underlying selection model.
50 /// ## `model`
51 /// the selection model to filter
52 ///
53 /// # Returns
54 ///
55 /// a new [`SelectionFilterModel`][crate::SelectionFilterModel]
56 #[doc(alias = "gtk_selection_filter_model_new")]
57 pub fn new(model: Option<&impl IsA<SelectionModel>>) -> SelectionFilterModel {
58 assert_initialized_main_thread!();
59 unsafe {
60 from_glib_full(ffi::gtk_selection_filter_model_new(
61 model.map(|p| p.as_ref()).to_glib_none().0,
62 ))
63 }
64 }
65
66 /// Gets the model currently filtered or [`None`] if none.
67 ///
68 /// # Returns
69 ///
70 /// The model that gets filtered
71 #[doc(alias = "gtk_selection_filter_model_get_model")]
72 #[doc(alias = "get_model")]
73 pub fn model(&self) -> Option<SelectionModel> {
74 unsafe {
75 from_glib_none(ffi::gtk_selection_filter_model_get_model(
76 self.to_glib_none().0,
77 ))
78 }
79 }
80
81 /// Sets the model to be filtered.
82 ///
83 /// Note that GTK makes no effort to ensure that @model conforms to
84 /// the item type of @self. It assumes that the caller knows what they
85 /// are doing and have set up an appropriate filter to ensure that item
86 /// types match.
87 /// ## `model`
88 /// The model to be filtered
89 #[doc(alias = "gtk_selection_filter_model_set_model")]
90 #[doc(alias = "model")]
91 pub fn set_model(&self, model: Option<&impl IsA<SelectionModel>>) {
92 unsafe {
93 ffi::gtk_selection_filter_model_set_model(
94 self.to_glib_none().0,
95 model.map(|p| p.as_ref()).to_glib_none().0,
96 );
97 }
98 }
99
100 #[doc(alias = "model")]
101 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102 unsafe extern "C" fn notify_model_trampoline<F: Fn(&SelectionFilterModel) + 'static>(
103 this: *mut ffi::GtkSelectionFilterModel,
104 _param_spec: glib::ffi::gpointer,
105 f: glib::ffi::gpointer,
106 ) {
107 let f: &F = &*(f as *const F);
108 f(&from_glib_borrow(this))
109 }
110 unsafe {
111 let f: Box_<F> = Box_::new(f);
112 connect_raw(
113 self.as_ptr() as *mut _,
114 c"notify::model".as_ptr() as *const _,
115 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
116 notify_model_trampoline::<F> as *const (),
117 )),
118 Box_::into_raw(f),
119 )
120 }
121 }
122}