[go: up one dir, main page]

gtk4/auto/
map_list_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;
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")]
20    pub struct MapListModel(Object<ffi::GtkMapListModel, ffi::GtkMapListModelClass>) @implements gio::ListModel, SectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_map_list_model_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkMapListModel")]
30    pub struct MapListModel(Object<ffi::GtkMapListModel, ffi::GtkMapListModelClass>) @implements gio::ListModel;
31
32    match fn {
33        type_ => || ffi::gtk_map_list_model_get_type(),
34    }
35}
36
37impl MapListModel {
38    #[doc(alias = "gtk_map_list_model_new")]
39    pub fn new<P: Fn(&glib::Object) -> glib::Object + 'static>(
40        model: Option<impl IsA<gio::ListModel>>,
41        map_func: P,
42    ) -> MapListModel {
43        assert_initialized_main_thread!();
44        let map_func_data: Box_<P> = Box_::new(map_func);
45        unsafe extern "C" fn map_func_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
46            item: *mut glib::gobject_ffi::GObject,
47            user_data: glib::ffi::gpointer,
48        ) -> *mut glib::gobject_ffi::GObject {
49            let item = from_glib_full(item);
50            let callback = &*(user_data as *mut P);
51            (*callback)(&item).to_glib_full()
52        }
53        let map_func = Some(map_func_func::<P> as _);
54        unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
55            data: glib::ffi::gpointer,
56        ) {
57            let _callback = Box_::from_raw(data as *mut P);
58        }
59        let destroy_call3 = Some(user_destroy_func::<P> as _);
60        let super_callback0: Box_<P> = map_func_data;
61        unsafe {
62            from_glib_full(ffi::gtk_map_list_model_new(
63                model.map(|p| p.upcast()).into_glib_ptr(),
64                map_func,
65                Box_::into_raw(super_callback0) as *mut _,
66                destroy_call3,
67            ))
68        }
69    }
70
71    #[doc(alias = "gtk_map_list_model_get_model")]
72    #[doc(alias = "get_model")]
73    pub fn model(&self) -> Option<gio::ListModel> {
74        unsafe { from_glib_none(ffi::gtk_map_list_model_get_model(self.to_glib_none().0)) }
75    }
76
77    #[doc(alias = "gtk_map_list_model_has_map")]
78    #[doc(alias = "has-map")]
79    pub fn has_map(&self) -> bool {
80        unsafe { from_glib(ffi::gtk_map_list_model_has_map(self.to_glib_none().0)) }
81    }
82
83    #[doc(alias = "gtk_map_list_model_set_map_func")]
84    pub fn set_map_func<P: Fn(&glib::Object) -> glib::Object + 'static>(&self, map_func: P) {
85        let map_func_data: Box_<P> = Box_::new(map_func);
86        unsafe extern "C" fn map_func_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
87            item: *mut glib::gobject_ffi::GObject,
88            user_data: glib::ffi::gpointer,
89        ) -> *mut glib::gobject_ffi::GObject {
90            let item = from_glib_full(item);
91            let callback = &*(user_data as *mut P);
92            (*callback)(&item).to_glib_full()
93        }
94        let map_func = Some(map_func_func::<P> as _);
95        unsafe extern "C" fn user_destroy_func<P: Fn(&glib::Object) -> glib::Object + 'static>(
96            data: glib::ffi::gpointer,
97        ) {
98            let _callback = Box_::from_raw(data as *mut P);
99        }
100        let destroy_call3 = Some(user_destroy_func::<P> as _);
101        let super_callback0: Box_<P> = map_func_data;
102        unsafe {
103            ffi::gtk_map_list_model_set_map_func(
104                self.to_glib_none().0,
105                map_func,
106                Box_::into_raw(super_callback0) as *mut _,
107                destroy_call3,
108            );
109        }
110    }
111
112    #[doc(alias = "gtk_map_list_model_set_model")]
113    #[doc(alias = "model")]
114    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
115        unsafe {
116            ffi::gtk_map_list_model_set_model(
117                self.to_glib_none().0,
118                model.map(|p| p.as_ref()).to_glib_none().0,
119            );
120        }
121    }
122
123    #[doc(alias = "has-map")]
124    pub fn connect_has_map_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
125        unsafe extern "C" fn notify_has_map_trampoline<F: Fn(&MapListModel) + 'static>(
126            this: *mut ffi::GtkMapListModel,
127            _param_spec: glib::ffi::gpointer,
128            f: glib::ffi::gpointer,
129        ) {
130            let f: &F = &*(f as *const F);
131            f(&from_glib_borrow(this))
132        }
133        unsafe {
134            let f: Box_<F> = Box_::new(f);
135            connect_raw(
136                self.as_ptr() as *mut _,
137                c"notify::has-map".as_ptr() as *const _,
138                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
139                    notify_has_map_trampoline::<F> as *const (),
140                )),
141                Box_::into_raw(f),
142            )
143        }
144    }
145
146    #[doc(alias = "model")]
147    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
148        unsafe extern "C" fn notify_model_trampoline<F: Fn(&MapListModel) + 'static>(
149            this: *mut ffi::GtkMapListModel,
150            _param_spec: glib::ffi::gpointer,
151            f: glib::ffi::gpointer,
152        ) {
153            let f: &F = &*(f as *const F);
154            f(&from_glib_borrow(this))
155        }
156        unsafe {
157            let f: Box_<F> = Box_::new(f);
158            connect_raw(
159                self.as_ptr() as *mut _,
160                c"notify::model".as_ptr() as *const _,
161                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
162                    notify_model_trampoline::<F> as *const (),
163                )),
164                Box_::into_raw(f),
165            )
166        }
167    }
168}