gio/auto/
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;
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 = "GListModel")]
16    pub struct ListModel(Interface<ffi::GListModel, ffi::GListModelInterface>);
17
18    match fn {
19        type_ => || ffi::g_list_model_get_type(),
20    }
21}
22
23impl ListModel {
24    pub const NONE: Option<&'static ListModel> = None;
25}
26
27pub trait ListModelExt: IsA<ListModel> + 'static {
28    #[doc(alias = "g_list_model_get_item_type")]
29    #[doc(alias = "get_item_type")]
30    fn item_type(&self) -> glib::types::Type {
31        unsafe {
32            from_glib(ffi::g_list_model_get_item_type(
33                self.as_ref().to_glib_none().0,
34            ))
35        }
36    }
37
38    #[doc(alias = "g_list_model_get_n_items")]
39    #[doc(alias = "get_n_items")]
40    fn n_items(&self) -> u32 {
41        unsafe { ffi::g_list_model_get_n_items(self.as_ref().to_glib_none().0) }
42    }
43
44    #[doc(alias = "g_list_model_get_object")]
45    #[doc(alias = "get_object")]
46    fn item(&self, position: u32) -> Option<glib::Object> {
47        unsafe {
48            from_glib_full(ffi::g_list_model_get_object(
49                self.as_ref().to_glib_none().0,
50                position,
51            ))
52        }
53    }
54
55    #[doc(alias = "g_list_model_items_changed")]
56    fn items_changed(&self, position: u32, removed: u32, added: u32) {
57        unsafe {
58            ffi::g_list_model_items_changed(
59                self.as_ref().to_glib_none().0,
60                position,
61                removed,
62                added,
63            );
64        }
65    }
66
67    #[doc(alias = "items-changed")]
68    fn connect_items_changed<F: Fn(&Self, u32, u32, u32) + 'static>(
69        &self,
70        f: F,
71    ) -> SignalHandlerId {
72        unsafe extern "C" fn items_changed_trampoline<
73            P: IsA<ListModel>,
74            F: Fn(&P, u32, u32, u32) + 'static,
75        >(
76            this: *mut ffi::GListModel,
77            position: std::ffi::c_uint,
78            removed: std::ffi::c_uint,
79            added: std::ffi::c_uint,
80            f: glib::ffi::gpointer,
81        ) {
82            let f: &F = &*(f as *const F);
83            f(
84                ListModel::from_glib_borrow(this).unsafe_cast_ref(),
85                position,
86                removed,
87                added,
88            )
89        }
90        unsafe {
91            let f: Box_<F> = Box_::new(f);
92            connect_raw(
93                self.as_ptr() as *mut _,
94                c"items-changed".as_ptr() as *const _,
95                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
96                    items_changed_trampoline::<Self, F> as *const (),
97                )),
98                Box_::into_raw(f),
99            )
100        }
101    }
102}
103
104impl<O: IsA<ListModel>> ListModelExt for O {}