gtk4/auto/
map_list_model.rs1#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::SectionModel;
8use crate::ffi;
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16#[cfg(feature = "v4_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18glib::wrapper! {
19 #[doc(alias = "GtkMapListModel")]
81 pub struct MapListModel(Object<ffi::GtkMapListModel, ffi::GtkMapListModelClass>) @implements gio::ListModel, SectionModel;
82
83 match fn {
84 type_ => || ffi::gtk_map_list_model_get_type(),
85 }
86}
87
88#[cfg(not(any(feature = "v4_12")))]
89glib::wrapper! {
90 #[doc(alias = "GtkMapListModel")]
91 pub struct MapListModel(Object<ffi::GtkMapListModel, ffi::GtkMapListModelClass>) @implements gio::ListModel;
92
93 match fn {
94 type_ => || ffi::gtk_map_list_model_get_type(),
95 }
96}
97
98impl MapListModel {
99 #[doc(alias = "gtk_map_list_model_new")]
109 pub fn new<P: Fn(&glib::Object) -> glib::Object + 'static>(
110 model: Option<impl IsA<gio::ListModel>>,
111 map_func: P,
112 ) -> MapListModel {
113 assert_initialized_main_thread!();
114 let map_func_data: Box_<P> = Box_::new(map_func);
115 unsafe extern "C" fn map_func_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
116 item: *mut glib::gobject_ffi::GObject,
117 user_data: glib::ffi::gpointer,
118 ) -> *mut glib::gobject_ffi::GObject {
119 unsafe {
120 let item = from_glib_full(item);
121 let callback = &*(user_data as *mut P);
122 (*callback)(&item).to_glib_full()
123 }
124 }
125 let map_func = Some(map_func_func::<P> as _);
126 unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
127 data: glib::ffi::gpointer,
128 ) {
129 unsafe {
130 let _callback = Box_::from_raw(data as *mut P);
131 }
132 }
133 let destroy_call3 = Some(user_destroy_func::<P> as _);
134 let super_callback0: Box_<P> = map_func_data;
135 unsafe {
136 from_glib_full(ffi::gtk_map_list_model_new(
137 model.map(|p| p.upcast()).into_glib_ptr(),
138 map_func,
139 Box_::into_raw(super_callback0) as *mut _,
140 destroy_call3,
141 ))
142 }
143 }
144
145 #[doc(alias = "gtk_map_list_model_get_model")]
151 #[doc(alias = "get_model")]
152 pub fn model(&self) -> Option<gio::ListModel> {
153 unsafe { from_glib_none(ffi::gtk_map_list_model_get_model(self.to_glib_none().0)) }
154 }
155
156 #[doc(alias = "gtk_map_list_model_has_map")]
162 #[doc(alias = "has-map")]
163 pub fn has_map(&self) -> bool {
164 unsafe { from_glib(ffi::gtk_map_list_model_has_map(self.to_glib_none().0)) }
165 }
166
167 #[doc(alias = "gtk_map_list_model_set_map_func")]
181 pub fn set_map_func<P: Fn(&glib::Object) -> glib::Object + 'static>(&self, map_func: P) {
182 let map_func_data: Box_<P> = Box_::new(map_func);
183 unsafe extern "C" fn map_func_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
184 item: *mut glib::gobject_ffi::GObject,
185 user_data: glib::ffi::gpointer,
186 ) -> *mut glib::gobject_ffi::GObject {
187 unsafe {
188 let item = from_glib_full(item);
189 let callback = &*(user_data as *mut P);
190 (*callback)(&item).to_glib_full()
191 }
192 }
193 let map_func = Some(map_func_func::<P> as _);
194 unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
195 data: glib::ffi::gpointer,
196 ) {
197 unsafe {
198 let _callback = Box_::from_raw(data as *mut P);
199 }
200 }
201 let destroy_call3 = Some(user_destroy_func::<P> as _);
202 let super_callback0: Box_<P> = map_func_data;
203 unsafe {
204 ffi::gtk_map_list_model_set_map_func(
205 self.to_glib_none().0,
206 map_func,
207 Box_::into_raw(super_callback0) as *mut _,
208 destroy_call3,
209 );
210 }
211 }
212
213 #[doc(alias = "gtk_map_list_model_set_model")]
221 #[doc(alias = "model")]
222 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
223 unsafe {
224 ffi::gtk_map_list_model_set_model(
225 self.to_glib_none().0,
226 model.map(|p| p.as_ref()).to_glib_none().0,
227 );
228 }
229 }
230
231 #[doc(alias = "has-map")]
232 pub fn connect_has_map_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
233 unsafe extern "C" fn notify_has_map_trampoline<F: Fn(&MapListModel) + 'static>(
234 this: *mut ffi::GtkMapListModel,
235 _param_spec: glib::ffi::gpointer,
236 f: glib::ffi::gpointer,
237 ) {
238 unsafe {
239 let f: &F = &*(f as *const F);
240 f(&from_glib_borrow(this))
241 }
242 }
243 unsafe {
244 let f: Box_<F> = Box_::new(f);
245 connect_raw(
246 self.as_ptr() as *mut _,
247 c"notify::has-map".as_ptr() as *const _,
248 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
249 notify_has_map_trampoline::<F> as *const (),
250 )),
251 Box_::into_raw(f),
252 )
253 }
254 }
255
256 #[doc(alias = "model")]
257 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
258 unsafe extern "C" fn notify_model_trampoline<F: Fn(&MapListModel) + 'static>(
259 this: *mut ffi::GtkMapListModel,
260 _param_spec: glib::ffi::gpointer,
261 f: glib::ffi::gpointer,
262 ) {
263 unsafe {
264 let f: &F = &*(f as *const F);
265 f(&from_glib_borrow(this))
266 }
267 }
268 unsafe {
269 let f: Box_<F> = Box_::new(f);
270 connect_raw(
271 self.as_ptr() as *mut _,
272 c"notify::model".as_ptr() as *const _,
273 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
274 notify_model_trampoline::<F> as *const (),
275 )),
276 Box_::into_raw(f),
277 )
278 }
279 }
280}