gtk4/auto/
selection_model.rs1use crate::{ffi, Bitset};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSelectionModel")]
16 pub struct SelectionModel(Interface<ffi::GtkSelectionModel, ffi::GtkSelectionModelInterface>) @requires gio::ListModel;
17
18 match fn {
19 type_ => || ffi::gtk_selection_model_get_type(),
20 }
21}
22
23impl SelectionModel {
24 pub const NONE: Option<&'static SelectionModel> = None;
25}
26
27mod sealed {
28 pub trait Sealed {}
29 impl<T: super::IsA<super::SelectionModel>> Sealed for T {}
30}
31
32pub trait SelectionModelExt: IsA<SelectionModel> + sealed::Sealed + 'static {
33 #[doc(alias = "gtk_selection_model_get_selection")]
34 #[doc(alias = "get_selection")]
35 fn selection(&self) -> Bitset {
36 unsafe {
37 from_glib_full(ffi::gtk_selection_model_get_selection(
38 self.as_ref().to_glib_none().0,
39 ))
40 }
41 }
42
43 #[doc(alias = "gtk_selection_model_get_selection_in_range")]
44 #[doc(alias = "get_selection_in_range")]
45 fn selection_in_range(&self, position: u32, n_items: u32) -> Bitset {
46 unsafe {
47 from_glib_full(ffi::gtk_selection_model_get_selection_in_range(
48 self.as_ref().to_glib_none().0,
49 position,
50 n_items,
51 ))
52 }
53 }
54
55 #[doc(alias = "gtk_selection_model_is_selected")]
56 fn is_selected(&self, position: u32) -> bool {
57 unsafe {
58 from_glib(ffi::gtk_selection_model_is_selected(
59 self.as_ref().to_glib_none().0,
60 position,
61 ))
62 }
63 }
64
65 #[doc(alias = "gtk_selection_model_select_all")]
66 fn select_all(&self) -> bool {
67 unsafe {
68 from_glib(ffi::gtk_selection_model_select_all(
69 self.as_ref().to_glib_none().0,
70 ))
71 }
72 }
73
74 #[doc(alias = "gtk_selection_model_select_item")]
75 fn select_item(&self, position: u32, unselect_rest: bool) -> bool {
76 unsafe {
77 from_glib(ffi::gtk_selection_model_select_item(
78 self.as_ref().to_glib_none().0,
79 position,
80 unselect_rest.into_glib(),
81 ))
82 }
83 }
84
85 #[doc(alias = "gtk_selection_model_select_range")]
86 fn select_range(&self, position: u32, n_items: u32, unselect_rest: bool) -> bool {
87 unsafe {
88 from_glib(ffi::gtk_selection_model_select_range(
89 self.as_ref().to_glib_none().0,
90 position,
91 n_items,
92 unselect_rest.into_glib(),
93 ))
94 }
95 }
96
97 #[doc(alias = "gtk_selection_model_selection_changed")]
98 fn selection_changed(&self, position: u32, n_items: u32) {
99 unsafe {
100 ffi::gtk_selection_model_selection_changed(
101 self.as_ref().to_glib_none().0,
102 position,
103 n_items,
104 );
105 }
106 }
107
108 #[doc(alias = "gtk_selection_model_set_selection")]
109 fn set_selection(&self, selected: &Bitset, mask: &Bitset) -> bool {
110 unsafe {
111 from_glib(ffi::gtk_selection_model_set_selection(
112 self.as_ref().to_glib_none().0,
113 selected.to_glib_none().0,
114 mask.to_glib_none().0,
115 ))
116 }
117 }
118
119 #[doc(alias = "gtk_selection_model_unselect_all")]
120 fn unselect_all(&self) -> bool {
121 unsafe {
122 from_glib(ffi::gtk_selection_model_unselect_all(
123 self.as_ref().to_glib_none().0,
124 ))
125 }
126 }
127
128 #[doc(alias = "gtk_selection_model_unselect_item")]
129 fn unselect_item(&self, position: u32) -> bool {
130 unsafe {
131 from_glib(ffi::gtk_selection_model_unselect_item(
132 self.as_ref().to_glib_none().0,
133 position,
134 ))
135 }
136 }
137
138 #[doc(alias = "gtk_selection_model_unselect_range")]
139 fn unselect_range(&self, position: u32, n_items: u32) -> bool {
140 unsafe {
141 from_glib(ffi::gtk_selection_model_unselect_range(
142 self.as_ref().to_glib_none().0,
143 position,
144 n_items,
145 ))
146 }
147 }
148
149 #[doc(alias = "selection-changed")]
150 fn connect_selection_changed<F: Fn(&Self, u32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
151 unsafe extern "C" fn selection_changed_trampoline<
152 P: IsA<SelectionModel>,
153 F: Fn(&P, u32, u32) + 'static,
154 >(
155 this: *mut ffi::GtkSelectionModel,
156 position: std::ffi::c_uint,
157 n_items: std::ffi::c_uint,
158 f: glib::ffi::gpointer,
159 ) {
160 let f: &F = &*(f as *const F);
161 f(
162 SelectionModel::from_glib_borrow(this).unsafe_cast_ref(),
163 position,
164 n_items,
165 )
166 }
167 unsafe {
168 let f: Box_<F> = Box_::new(f);
169 connect_raw(
170 self.as_ptr() as *mut _,
171 b"selection-changed\0".as_ptr() as *const _,
172 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
173 selection_changed_trampoline::<Self, F> as *const (),
174 )),
175 Box_::into_raw(f),
176 )
177 }
178 }
179}
180
181impl<O: IsA<SelectionModel>> SelectionModelExt for O {}