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
27pub trait SelectionModelExt: IsA<SelectionModel> + 'static {
28 #[doc(alias = "gtk_selection_model_get_selection")]
29 #[doc(alias = "get_selection")]
30 fn selection(&self) -> Bitset {
31 unsafe {
32 from_glib_full(ffi::gtk_selection_model_get_selection(
33 self.as_ref().to_glib_none().0,
34 ))
35 }
36 }
37
38 #[doc(alias = "gtk_selection_model_get_selection_in_range")]
39 #[doc(alias = "get_selection_in_range")]
40 fn selection_in_range(&self, position: u32, n_items: u32) -> Bitset {
41 unsafe {
42 from_glib_full(ffi::gtk_selection_model_get_selection_in_range(
43 self.as_ref().to_glib_none().0,
44 position,
45 n_items,
46 ))
47 }
48 }
49
50 #[doc(alias = "gtk_selection_model_is_selected")]
51 fn is_selected(&self, position: u32) -> bool {
52 unsafe {
53 from_glib(ffi::gtk_selection_model_is_selected(
54 self.as_ref().to_glib_none().0,
55 position,
56 ))
57 }
58 }
59
60 #[doc(alias = "gtk_selection_model_select_all")]
61 fn select_all(&self) -> bool {
62 unsafe {
63 from_glib(ffi::gtk_selection_model_select_all(
64 self.as_ref().to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "gtk_selection_model_select_item")]
70 fn select_item(&self, position: u32, unselect_rest: bool) -> bool {
71 unsafe {
72 from_glib(ffi::gtk_selection_model_select_item(
73 self.as_ref().to_glib_none().0,
74 position,
75 unselect_rest.into_glib(),
76 ))
77 }
78 }
79
80 #[doc(alias = "gtk_selection_model_select_range")]
81 fn select_range(&self, position: u32, n_items: u32, unselect_rest: bool) -> bool {
82 unsafe {
83 from_glib(ffi::gtk_selection_model_select_range(
84 self.as_ref().to_glib_none().0,
85 position,
86 n_items,
87 unselect_rest.into_glib(),
88 ))
89 }
90 }
91
92 #[doc(alias = "gtk_selection_model_selection_changed")]
93 fn selection_changed(&self, position: u32, n_items: u32) {
94 unsafe {
95 ffi::gtk_selection_model_selection_changed(
96 self.as_ref().to_glib_none().0,
97 position,
98 n_items,
99 );
100 }
101 }
102
103 #[doc(alias = "gtk_selection_model_set_selection")]
104 fn set_selection(&self, selected: &Bitset, mask: &Bitset) -> bool {
105 unsafe {
106 from_glib(ffi::gtk_selection_model_set_selection(
107 self.as_ref().to_glib_none().0,
108 selected.to_glib_none().0,
109 mask.to_glib_none().0,
110 ))
111 }
112 }
113
114 #[doc(alias = "gtk_selection_model_unselect_all")]
115 fn unselect_all(&self) -> bool {
116 unsafe {
117 from_glib(ffi::gtk_selection_model_unselect_all(
118 self.as_ref().to_glib_none().0,
119 ))
120 }
121 }
122
123 #[doc(alias = "gtk_selection_model_unselect_item")]
124 fn unselect_item(&self, position: u32) -> bool {
125 unsafe {
126 from_glib(ffi::gtk_selection_model_unselect_item(
127 self.as_ref().to_glib_none().0,
128 position,
129 ))
130 }
131 }
132
133 #[doc(alias = "gtk_selection_model_unselect_range")]
134 fn unselect_range(&self, position: u32, n_items: u32) -> bool {
135 unsafe {
136 from_glib(ffi::gtk_selection_model_unselect_range(
137 self.as_ref().to_glib_none().0,
138 position,
139 n_items,
140 ))
141 }
142 }
143
144 #[doc(alias = "selection-changed")]
145 fn connect_selection_changed<F: Fn(&Self, u32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
146 unsafe extern "C" fn selection_changed_trampoline<
147 P: IsA<SelectionModel>,
148 F: Fn(&P, u32, u32) + 'static,
149 >(
150 this: *mut ffi::GtkSelectionModel,
151 position: std::ffi::c_uint,
152 n_items: std::ffi::c_uint,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(
157 SelectionModel::from_glib_borrow(this).unsafe_cast_ref(),
158 position,
159 n_items,
160 )
161 }
162 unsafe {
163 let f: Box_<F> = Box_::new(f);
164 connect_raw(
165 self.as_ptr() as *mut _,
166 c"selection-changed".as_ptr() as *const _,
167 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
168 selection_changed_trampoline::<Self, F> as *const (),
169 )),
170 Box_::into_raw(f),
171 )
172 }
173 }
174}
175
176impl<O: IsA<SelectionModel>> SelectionModelExt for O {}