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