gio/auto/
menu_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, MenuAttributeIter, MenuLinkIter};
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 = "GMenuModel")]
16    pub struct MenuModel(Object<ffi::GMenuModel, ffi::GMenuModelClass>);
17
18    match fn {
19        type_ => || ffi::g_menu_model_get_type(),
20    }
21}
22
23impl MenuModel {
24    pub const NONE: Option<&'static MenuModel> = None;
25}
26
27pub trait MenuModelExt: IsA<MenuModel> + 'static {
28    //#[doc(alias = "g_menu_model_get_item_attribute")]
29    //#[doc(alias = "get_item_attribute")]
30    //fn is_item_attribute(&self, item_index: i32, attribute: &str, format_string: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
31    //    unsafe { TODO: call ffi:g_menu_model_get_item_attribute() }
32    //}
33
34    #[doc(alias = "g_menu_model_get_item_attribute_value")]
35    #[doc(alias = "get_item_attribute_value")]
36    fn item_attribute_value(
37        &self,
38        item_index: i32,
39        attribute: &str,
40        expected_type: Option<&glib::VariantTy>,
41    ) -> Option<glib::Variant> {
42        unsafe {
43            from_glib_full(ffi::g_menu_model_get_item_attribute_value(
44                self.as_ref().to_glib_none().0,
45                item_index,
46                attribute.to_glib_none().0,
47                expected_type.to_glib_none().0,
48            ))
49        }
50    }
51
52    #[doc(alias = "g_menu_model_get_item_link")]
53    #[doc(alias = "get_item_link")]
54    #[must_use]
55    fn item_link(&self, item_index: i32, link: &str) -> Option<MenuModel> {
56        unsafe {
57            from_glib_full(ffi::g_menu_model_get_item_link(
58                self.as_ref().to_glib_none().0,
59                item_index,
60                link.to_glib_none().0,
61            ))
62        }
63    }
64
65    #[doc(alias = "g_menu_model_get_n_items")]
66    #[doc(alias = "get_n_items")]
67    fn n_items(&self) -> i32 {
68        unsafe { ffi::g_menu_model_get_n_items(self.as_ref().to_glib_none().0) }
69    }
70
71    #[doc(alias = "g_menu_model_is_mutable")]
72    fn is_mutable(&self) -> bool {
73        unsafe { from_glib(ffi::g_menu_model_is_mutable(self.as_ref().to_glib_none().0)) }
74    }
75
76    #[doc(alias = "g_menu_model_items_changed")]
77    fn items_changed(&self, position: i32, removed: i32, added: i32) {
78        unsafe {
79            ffi::g_menu_model_items_changed(
80                self.as_ref().to_glib_none().0,
81                position,
82                removed,
83                added,
84            );
85        }
86    }
87
88    #[doc(alias = "g_menu_model_iterate_item_attributes")]
89    fn iterate_item_attributes(&self, item_index: i32) -> MenuAttributeIter {
90        unsafe {
91            from_glib_full(ffi::g_menu_model_iterate_item_attributes(
92                self.as_ref().to_glib_none().0,
93                item_index,
94            ))
95        }
96    }
97
98    #[doc(alias = "g_menu_model_iterate_item_links")]
99    fn iterate_item_links(&self, item_index: i32) -> MenuLinkIter {
100        unsafe {
101            from_glib_full(ffi::g_menu_model_iterate_item_links(
102                self.as_ref().to_glib_none().0,
103                item_index,
104            ))
105        }
106    }
107
108    #[doc(alias = "items-changed")]
109    fn connect_items_changed<F: Fn(&Self, i32, i32, i32) + 'static>(
110        &self,
111        f: F,
112    ) -> SignalHandlerId {
113        unsafe extern "C" fn items_changed_trampoline<
114            P: IsA<MenuModel>,
115            F: Fn(&P, i32, i32, i32) + 'static,
116        >(
117            this: *mut ffi::GMenuModel,
118            position: std::ffi::c_int,
119            removed: std::ffi::c_int,
120            added: std::ffi::c_int,
121            f: glib::ffi::gpointer,
122        ) {
123            let f: &F = &*(f as *const F);
124            f(
125                MenuModel::from_glib_borrow(this).unsafe_cast_ref(),
126                position,
127                removed,
128                added,
129            )
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                c"items-changed".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    items_changed_trampoline::<Self, F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143}
144
145impl<O: IsA<MenuModel>> MenuModelExt for O {}