gtk4/auto/
map_list_model.rs1use crate::ffi;
6#[cfg(feature = "v4_12")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
8use crate::SectionModel;
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
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 let item = from_glib_full(item);
120 let callback = &*(user_data as *mut P);
121 (*callback)(&item).to_glib_full()
122 }
123 let map_func = Some(map_func_func::<P> as _);
124 unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
125 data: glib::ffi::gpointer,
126 ) {
127 let _callback = Box_::from_raw(data as *mut P);
128 }
129 let destroy_call3 = Some(user_destroy_func::<P> as _);
130 let super_callback0: Box_<P> = map_func_data;
131 unsafe {
132 from_glib_full(ffi::gtk_map_list_model_new(
133 model.map(|p| p.upcast()).into_glib_ptr(),
134 map_func,
135 Box_::into_raw(super_callback0) as *mut _,
136 destroy_call3,
137 ))
138 }
139 }
140
141 #[doc(alias = "gtk_map_list_model_get_model")]
147 #[doc(alias = "get_model")]
148 pub fn model(&self) -> Option<gio::ListModel> {
149 unsafe { from_glib_none(ffi::gtk_map_list_model_get_model(self.to_glib_none().0)) }
150 }
151
152 #[doc(alias = "gtk_map_list_model_has_map")]
158 #[doc(alias = "has-map")]
159 pub fn has_map(&self) -> bool {
160 unsafe { from_glib(ffi::gtk_map_list_model_has_map(self.to_glib_none().0)) }
161 }
162
163 #[doc(alias = "gtk_map_list_model_set_map_func")]
177 pub fn set_map_func<P: Fn(&glib::Object) -> glib::Object + 'static>(&self, map_func: P) {
178 let map_func_data: Box_<P> = Box_::new(map_func);
179 unsafe extern "C" fn map_func_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
180 item: *mut glib::gobject_ffi::GObject,
181 user_data: glib::ffi::gpointer,
182 ) -> *mut glib::gobject_ffi::GObject {
183 let item = from_glib_full(item);
184 let callback = &*(user_data as *mut P);
185 (*callback)(&item).to_glib_full()
186 }
187 let map_func = Some(map_func_func::<P> as _);
188 unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
189 data: glib::ffi::gpointer,
190 ) {
191 let _callback = Box_::from_raw(data as *mut P);
192 }
193 let destroy_call3 = Some(user_destroy_func::<P> as _);
194 let super_callback0: Box_<P> = map_func_data;
195 unsafe {
196 ffi::gtk_map_list_model_set_map_func(
197 self.to_glib_none().0,
198 map_func,
199 Box_::into_raw(super_callback0) as *mut _,
200 destroy_call3,
201 );
202 }
203 }
204
205 #[doc(alias = "gtk_map_list_model_set_model")]
213 #[doc(alias = "model")]
214 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
215 unsafe {
216 ffi::gtk_map_list_model_set_model(
217 self.to_glib_none().0,
218 model.map(|p| p.as_ref()).to_glib_none().0,
219 );
220 }
221 }
222
223 #[doc(alias = "has-map")]
224 pub fn connect_has_map_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn notify_has_map_trampoline<F: Fn(&MapListModel) + 'static>(
226 this: *mut ffi::GtkMapListModel,
227 _param_spec: glib::ffi::gpointer,
228 f: glib::ffi::gpointer,
229 ) {
230 let f: &F = &*(f as *const F);
231 f(&from_glib_borrow(this))
232 }
233 unsafe {
234 let f: Box_<F> = Box_::new(f);
235 connect_raw(
236 self.as_ptr() as *mut _,
237 c"notify::has-map".as_ptr() as *const _,
238 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
239 notify_has_map_trampoline::<F> as *const (),
240 )),
241 Box_::into_raw(f),
242 )
243 }
244 }
245
246 #[doc(alias = "model")]
247 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
248 unsafe extern "C" fn notify_model_trampoline<F: Fn(&MapListModel) + 'static>(
249 this: *mut ffi::GtkMapListModel,
250 _param_spec: glib::ffi::gpointer,
251 f: glib::ffi::gpointer,
252 ) {
253 let f: &F = &*(f as *const F);
254 f(&from_glib_borrow(this))
255 }
256 unsafe {
257 let f: Box_<F> = Box_::new(f);
258 connect_raw(
259 self.as_ptr() as *mut _,
260 c"notify::model".as_ptr() as *const _,
261 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262 notify_model_trampoline::<F> as *const (),
263 )),
264 Box_::into_raw(f),
265 )
266 }
267 }
268}