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::{MenuAttributeIter, MenuLinkIter, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// when the state of the action is equal to the
16 /// target value of the menu item.
17 ///
18 /// This is an Abstract Base Class, you cannot instantiate it.
19 ///
20 /// ## Signals
21 ///
22 ///
23 /// #### `items-changed`
24 /// Emitted when a change has occurred to the menu.
25 ///
26 /// The only changes that can occur to a menu is that items are removed
27 /// or added. Items may not change (except by being removed and added
28 /// back in the same location). This signal is capable of describing
29 /// both of those changes (at the same time).
30 ///
31 /// The signal means that starting at the index @position, @removed
32 /// items were removed and @added items were added in their place. If
33 /// @removed is zero then only items were added. If @added is zero
34 /// then only items were removed.
35 ///
36 /// As an example, if the menu contains items a, b, c, d (in that
37 /// order) and the signal (2, 1, 3) occurs then the new composition of
38 /// the menu will be a, b, \_, \_, \_, d (with each _ representing some
39 /// new item).
40 ///
41 /// Signal handlers may query the model (particularly the added items)
42 /// and expect to see the results of the modification that is being
43 /// reported. The signal is emitted after the modification.
44 ///
45 ///
46 ///
47 /// # Implements
48 ///
49 /// [`MenuModelExt`][trait@crate::prelude::MenuModelExt], [`trait@glib::ObjectExt`]
50 #[doc(alias = "GMenuModel")]
51 pub struct MenuModel(Object<ffi::GMenuModel, ffi::GMenuModelClass>);
52
53 match fn {
54 type_ => || ffi::g_menu_model_get_type(),
55 }
56}
57
58impl MenuModel {
59 pub const NONE: Option<&'static MenuModel> = None;
60}
61
62/// Trait containing all [`struct@MenuModel`] methods.
63///
64/// # Implementors
65///
66/// [`DBusMenuModel`][struct@crate::DBusMenuModel], [`MenuModel`][struct@crate::MenuModel], [`Menu`][struct@crate::Menu]
67pub trait MenuModelExt: IsA<MenuModel> + 'static {
68 //#[doc(alias = "g_menu_model_get_item_attribute")]
69 //#[doc(alias = "get_item_attribute")]
70 //fn is_item_attribute(&self, item_index: i32, attribute: &str, format_string: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
71 // unsafe { TODO: call ffi:g_menu_model_get_item_attribute() }
72 //}
73
74 /// Queries the item at position @item_index in @self for the attribute
75 /// specified by @attribute.
76 ///
77 /// If @expected_type is non-[`None`] then it specifies the expected type of
78 /// the attribute. If it is [`None`] then any type will be accepted.
79 ///
80 /// If the attribute exists and matches @expected_type (or if the
81 /// expected type is unspecified) then the value is returned.
82 ///
83 /// If the attribute does not exist, or does not match the expected type
84 /// then [`None`] is returned.
85 /// ## `item_index`
86 /// the index of the item
87 /// ## `attribute`
88 /// the attribute to query
89 /// ## `expected_type`
90 /// the expected type of the attribute, or
91 /// [`None`]
92 ///
93 /// # Returns
94 ///
95 /// the value of the attribute
96 #[doc(alias = "g_menu_model_get_item_attribute_value")]
97 #[doc(alias = "get_item_attribute_value")]
98 fn item_attribute_value(
99 &self,
100 item_index: i32,
101 attribute: &str,
102 expected_type: Option<&glib::VariantTy>,
103 ) -> Option<glib::Variant> {
104 unsafe {
105 from_glib_full(ffi::g_menu_model_get_item_attribute_value(
106 self.as_ref().to_glib_none().0,
107 item_index,
108 attribute.to_glib_none().0,
109 expected_type.to_glib_none().0,
110 ))
111 }
112 }
113
114 /// Queries the item at position @item_index in @self for the link
115 /// specified by @link.
116 ///
117 /// If the link exists, the linked #GMenuModel is returned. If the link
118 /// does not exist, [`None`] is returned.
119 /// ## `item_index`
120 /// the index of the item
121 /// ## `link`
122 /// the link to query
123 ///
124 /// # Returns
125 ///
126 /// the linked #GMenuModel, or [`None`]
127 #[doc(alias = "g_menu_model_get_item_link")]
128 #[doc(alias = "get_item_link")]
129 #[must_use]
130 fn item_link(&self, item_index: i32, link: &str) -> Option<MenuModel> {
131 unsafe {
132 from_glib_full(ffi::g_menu_model_get_item_link(
133 self.as_ref().to_glib_none().0,
134 item_index,
135 link.to_glib_none().0,
136 ))
137 }
138 }
139
140 /// Query the number of items in @self.
141 ///
142 /// # Returns
143 ///
144 /// the number of items
145 #[doc(alias = "g_menu_model_get_n_items")]
146 #[doc(alias = "get_n_items")]
147 fn n_items(&self) -> i32 {
148 unsafe { ffi::g_menu_model_get_n_items(self.as_ref().to_glib_none().0) }
149 }
150
151 /// Queries if @self is mutable.
152 ///
153 /// An immutable #GMenuModel will never emit the #GMenuModel::items-changed
154 /// signal. Consumers of the model may make optimisations accordingly.
155 ///
156 /// # Returns
157 ///
158 /// [`true`] if the model is mutable (ie: "items-changed" may be
159 /// emitted).
160 #[doc(alias = "g_menu_model_is_mutable")]
161 fn is_mutable(&self) -> bool {
162 unsafe { from_glib(ffi::g_menu_model_is_mutable(self.as_ref().to_glib_none().0)) }
163 }
164
165 /// Requests emission of the #GMenuModel::items-changed signal on @self.
166 ///
167 /// This function should never be called except by #GMenuModel
168 /// subclasses. Any other calls to this function will very likely lead
169 /// to a violation of the interface of the model.
170 ///
171 /// The implementation should update its internal representation of the
172 /// menu before emitting the signal. The implementation should further
173 /// expect to receive queries about the new state of the menu (and
174 /// particularly added menu items) while signal handlers are running.
175 ///
176 /// The implementation must dispatch this call directly from a mainloop
177 /// entry and not in response to calls -- particularly those from the
178 /// #GMenuModel API. Said another way: the menu must not change while
179 /// user code is running without returning to the mainloop.
180 /// ## `position`
181 /// the position of the change
182 /// ## `removed`
183 /// the number of items removed
184 /// ## `added`
185 /// the number of items added
186 #[doc(alias = "g_menu_model_items_changed")]
187 fn items_changed(&self, position: i32, removed: i32, added: i32) {
188 unsafe {
189 ffi::g_menu_model_items_changed(
190 self.as_ref().to_glib_none().0,
191 position,
192 removed,
193 added,
194 );
195 }
196 }
197
198 /// Creates a #GMenuAttributeIter to iterate over the attributes of
199 /// the item at position @item_index in @self.
200 ///
201 /// You must free the iterator with g_object_unref() when you are done.
202 /// ## `item_index`
203 /// the index of the item
204 ///
205 /// # Returns
206 ///
207 /// a new #GMenuAttributeIter
208 #[doc(alias = "g_menu_model_iterate_item_attributes")]
209 fn iterate_item_attributes(&self, item_index: i32) -> MenuAttributeIter {
210 unsafe {
211 from_glib_full(ffi::g_menu_model_iterate_item_attributes(
212 self.as_ref().to_glib_none().0,
213 item_index,
214 ))
215 }
216 }
217
218 /// Creates a #GMenuLinkIter to iterate over the links of the item at
219 /// position @item_index in @self.
220 ///
221 /// You must free the iterator with g_object_unref() when you are done.
222 /// ## `item_index`
223 /// the index of the item
224 ///
225 /// # Returns
226 ///
227 /// a new #GMenuLinkIter
228 #[doc(alias = "g_menu_model_iterate_item_links")]
229 fn iterate_item_links(&self, item_index: i32) -> MenuLinkIter {
230 unsafe {
231 from_glib_full(ffi::g_menu_model_iterate_item_links(
232 self.as_ref().to_glib_none().0,
233 item_index,
234 ))
235 }
236 }
237
238 /// Emitted when a change has occurred to the menu.
239 ///
240 /// The only changes that can occur to a menu is that items are removed
241 /// or added. Items may not change (except by being removed and added
242 /// back in the same location). This signal is capable of describing
243 /// both of those changes (at the same time).
244 ///
245 /// The signal means that starting at the index @position, @removed
246 /// items were removed and @added items were added in their place. If
247 /// @removed is zero then only items were added. If @added is zero
248 /// then only items were removed.
249 ///
250 /// As an example, if the menu contains items a, b, c, d (in that
251 /// order) and the signal (2, 1, 3) occurs then the new composition of
252 /// the menu will be a, b, \_, \_, \_, d (with each _ representing some
253 /// new item).
254 ///
255 /// Signal handlers may query the model (particularly the added items)
256 /// and expect to see the results of the modification that is being
257 /// reported. The signal is emitted after the modification.
258 /// ## `position`
259 /// the position of the change
260 /// ## `removed`
261 /// the number of items removed
262 /// ## `added`
263 /// the number of items added
264 #[doc(alias = "items-changed")]
265 fn connect_items_changed<F: Fn(&Self, i32, i32, i32) + 'static>(
266 &self,
267 f: F,
268 ) -> SignalHandlerId {
269 unsafe extern "C" fn items_changed_trampoline<
270 P: IsA<MenuModel>,
271 F: Fn(&P, i32, i32, i32) + 'static,
272 >(
273 this: *mut ffi::GMenuModel,
274 position: std::ffi::c_int,
275 removed: std::ffi::c_int,
276 added: std::ffi::c_int,
277 f: glib::ffi::gpointer,
278 ) {
279 unsafe {
280 let f: &F = &*(f as *const F);
281 f(
282 MenuModel::from_glib_borrow(this).unsafe_cast_ref(),
283 position,
284 removed,
285 added,
286 )
287 }
288 }
289 unsafe {
290 let f: Box_<F> = Box_::new(f);
291 connect_raw(
292 self.as_ptr() as *mut _,
293 c"items-changed".as_ptr(),
294 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
295 items_changed_trampoline::<Self, F> as *const (),
296 )),
297 Box_::into_raw(f),
298 )
299 }
300 }
301}
302
303impl<O: IsA<MenuModel>> MenuModelExt for O {}