[go: up one dir, main page]

gtk4/auto/
tree_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, TreeListRow};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GtkTreeListModel")]
15    pub struct TreeListModel(Object<ffi::GtkTreeListModel, ffi::GtkTreeListModelClass>) @implements gio::ListModel;
16
17    match fn {
18        type_ => || ffi::gtk_tree_list_model_get_type(),
19    }
20}
21
22impl TreeListModel {
23    #[doc(alias = "gtk_tree_list_model_new")]
24    pub fn new<P: Fn(&glib::Object) -> Option<gio::ListModel> + 'static>(
25        root: impl IsA<gio::ListModel>,
26        passthrough: bool,
27        autoexpand: bool,
28        create_func: P,
29    ) -> TreeListModel {
30        assert_initialized_main_thread!();
31        let create_func_data: Box_<P> = Box_::new(create_func);
32        unsafe extern "C" fn create_func_func<
33            P: Fn(&glib::Object) -> Option<gio::ListModel> + 'static,
34        >(
35            item: *mut glib::gobject_ffi::GObject,
36            user_data: glib::ffi::gpointer,
37        ) -> *mut gio::ffi::GListModel {
38            let item = from_glib_borrow(item);
39            let callback = &*(user_data as *mut P);
40            (*callback)(&item).to_glib_full()
41        }
42        let create_func = Some(create_func_func::<P> as _);
43        unsafe extern "C" fn user_destroy_func<
44            P: Fn(&glib::Object) -> Option<gio::ListModel> + 'static,
45        >(
46            data: glib::ffi::gpointer,
47        ) {
48            let _callback = Box_::from_raw(data as *mut P);
49        }
50        let destroy_call5 = Some(user_destroy_func::<P> as _);
51        let super_callback0: Box_<P> = create_func_data;
52        unsafe {
53            from_glib_full(ffi::gtk_tree_list_model_new(
54                root.upcast().into_glib_ptr(),
55                passthrough.into_glib(),
56                autoexpand.into_glib(),
57                create_func,
58                Box_::into_raw(super_callback0) as *mut _,
59                destroy_call5,
60            ))
61        }
62    }
63
64    #[doc(alias = "gtk_tree_list_model_get_autoexpand")]
65    #[doc(alias = "get_autoexpand")]
66    #[doc(alias = "autoexpand")]
67    pub fn is_autoexpand(&self) -> bool {
68        unsafe {
69            from_glib(ffi::gtk_tree_list_model_get_autoexpand(
70                self.to_glib_none().0,
71            ))
72        }
73    }
74
75    #[doc(alias = "gtk_tree_list_model_get_child_row")]
76    #[doc(alias = "get_child_row")]
77    pub fn child_row(&self, position: u32) -> Option<TreeListRow> {
78        unsafe {
79            from_glib_full(ffi::gtk_tree_list_model_get_child_row(
80                self.to_glib_none().0,
81                position,
82            ))
83        }
84    }
85
86    #[doc(alias = "gtk_tree_list_model_get_model")]
87    #[doc(alias = "get_model")]
88    pub fn model(&self) -> gio::ListModel {
89        unsafe { from_glib_none(ffi::gtk_tree_list_model_get_model(self.to_glib_none().0)) }
90    }
91
92    #[doc(alias = "gtk_tree_list_model_get_passthrough")]
93    #[doc(alias = "get_passthrough")]
94    #[doc(alias = "passthrough")]
95    pub fn is_passthrough(&self) -> bool {
96        unsafe {
97            from_glib(ffi::gtk_tree_list_model_get_passthrough(
98                self.to_glib_none().0,
99            ))
100        }
101    }
102
103    #[doc(alias = "gtk_tree_list_model_get_row")]
104    #[doc(alias = "get_row")]
105    pub fn row(&self, position: u32) -> Option<TreeListRow> {
106        unsafe {
107            from_glib_full(ffi::gtk_tree_list_model_get_row(
108                self.to_glib_none().0,
109                position,
110            ))
111        }
112    }
113
114    #[doc(alias = "gtk_tree_list_model_set_autoexpand")]
115    #[doc(alias = "autoexpand")]
116    pub fn set_autoexpand(&self, autoexpand: bool) {
117        unsafe {
118            ffi::gtk_tree_list_model_set_autoexpand(self.to_glib_none().0, autoexpand.into_glib());
119        }
120    }
121
122    #[doc(alias = "autoexpand")]
123    pub fn connect_autoexpand_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
124        unsafe extern "C" fn notify_autoexpand_trampoline<F: Fn(&TreeListModel) + 'static>(
125            this: *mut ffi::GtkTreeListModel,
126            _param_spec: glib::ffi::gpointer,
127            f: glib::ffi::gpointer,
128        ) {
129            let f: &F = &*(f as *const F);
130            f(&from_glib_borrow(this))
131        }
132        unsafe {
133            let f: Box_<F> = Box_::new(f);
134            connect_raw(
135                self.as_ptr() as *mut _,
136                c"notify::autoexpand".as_ptr() as *const _,
137                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
138                    notify_autoexpand_trampoline::<F> as *const (),
139                )),
140                Box_::into_raw(f),
141            )
142        }
143    }
144
145    #[doc(alias = "model")]
146    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
147        unsafe extern "C" fn notify_model_trampoline<F: Fn(&TreeListModel) + 'static>(
148            this: *mut ffi::GtkTreeListModel,
149            _param_spec: glib::ffi::gpointer,
150            f: glib::ffi::gpointer,
151        ) {
152            let f: &F = &*(f as *const F);
153            f(&from_glib_borrow(this))
154        }
155        unsafe {
156            let f: Box_<F> = Box_::new(f);
157            connect_raw(
158                self.as_ptr() as *mut _,
159                c"notify::model".as_ptr() as *const _,
160                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161                    notify_model_trampoline::<F> as *const (),
162                )),
163                Box_::into_raw(f),
164            )
165        }
166    }
167}