gtk/auto/
menu_shell.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 gio;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::object::ObjectExt;
10use glib::signal::connect_raw;
11use glib::signal::SignalHandlerId;
12use glib::translate::*;
13use glib_sys;
14use gobject_sys;
15use gtk_sys;
16use libc;
17use signal::Inhibit;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use Buildable;
22use Container;
23use DirectionType;
24use MenuDirectionType;
25use MenuItem;
26use Widget;
27
28glib_wrapper! {
29    pub struct MenuShell(Object<gtk_sys::GtkMenuShell, gtk_sys::GtkMenuShellClass, MenuShellClass>) @extends Container, Widget, @implements Buildable;
30
31    match fn {
32        get_type => || gtk_sys::gtk_menu_shell_get_type(),
33    }
34}
35
36pub const NONE_MENU_SHELL: Option<&MenuShell> = None;
37
38pub trait MenuShellExt: 'static {
39    fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool);
40
41    fn append<P: IsA<MenuItem>>(&self, child: &P);
42
43    fn bind_model<P: IsA<gio::MenuModel>>(
44        &self,
45        model: Option<&P>,
46        action_namespace: Option<&str>,
47        with_separators: bool,
48    );
49
50    fn cancel(&self);
51
52    fn deactivate(&self);
53
54    fn deselect(&self);
55
56    fn get_parent_shell(&self) -> Option<Widget>;
57
58    fn get_selected_item(&self) -> Option<Widget>;
59
60    fn get_take_focus(&self) -> bool;
61
62    fn insert<P: IsA<Widget>>(&self, child: &P, position: i32);
63
64    fn prepend<P: IsA<Widget>>(&self, child: &P);
65
66    fn select_first(&self, search_sensitive: bool);
67
68    fn select_item<P: IsA<Widget>>(&self, menu_item: &P);
69
70    fn set_take_focus(&self, take_focus: bool);
71
72    fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId;
73
74    fn emit_activate_current(&self, force_hide: bool);
75
76    fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
77
78    fn emit_cancel(&self);
79
80    fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId;
81
82    fn emit_cycle_focus(&self, direction: DirectionType);
83
84    fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
85
86    fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId;
87
88    fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>(
89        &self,
90        f: F,
91    ) -> SignalHandlerId;
92
93    fn emit_move_current(&self, direction: MenuDirectionType);
94
95    fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>(
96        &self,
97        f: F,
98    ) -> SignalHandlerId;
99
100    fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
101
102    fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
103}
104
105impl<O: IsA<MenuShell>> MenuShellExt for O {
106    fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool) {
107        unsafe {
108            gtk_sys::gtk_menu_shell_activate_item(
109                self.as_ref().to_glib_none().0,
110                menu_item.as_ref().to_glib_none().0,
111                force_deactivate.to_glib(),
112            );
113        }
114    }
115
116    fn append<P: IsA<MenuItem>>(&self, child: &P) {
117        unsafe {
118            gtk_sys::gtk_menu_shell_append(
119                self.as_ref().to_glib_none().0,
120                child.as_ref().to_glib_none().0,
121            );
122        }
123    }
124
125    fn bind_model<P: IsA<gio::MenuModel>>(
126        &self,
127        model: Option<&P>,
128        action_namespace: Option<&str>,
129        with_separators: bool,
130    ) {
131        unsafe {
132            gtk_sys::gtk_menu_shell_bind_model(
133                self.as_ref().to_glib_none().0,
134                model.map(|p| p.as_ref()).to_glib_none().0,
135                action_namespace.to_glib_none().0,
136                with_separators.to_glib(),
137            );
138        }
139    }
140
141    fn cancel(&self) {
142        unsafe {
143            gtk_sys::gtk_menu_shell_cancel(self.as_ref().to_glib_none().0);
144        }
145    }
146
147    fn deactivate(&self) {
148        unsafe {
149            gtk_sys::gtk_menu_shell_deactivate(self.as_ref().to_glib_none().0);
150        }
151    }
152
153    fn deselect(&self) {
154        unsafe {
155            gtk_sys::gtk_menu_shell_deselect(self.as_ref().to_glib_none().0);
156        }
157    }
158
159    fn get_parent_shell(&self) -> Option<Widget> {
160        unsafe {
161            from_glib_none(gtk_sys::gtk_menu_shell_get_parent_shell(
162                self.as_ref().to_glib_none().0,
163            ))
164        }
165    }
166
167    fn get_selected_item(&self) -> Option<Widget> {
168        unsafe {
169            from_glib_none(gtk_sys::gtk_menu_shell_get_selected_item(
170                self.as_ref().to_glib_none().0,
171            ))
172        }
173    }
174
175    fn get_take_focus(&self) -> bool {
176        unsafe {
177            from_glib(gtk_sys::gtk_menu_shell_get_take_focus(
178                self.as_ref().to_glib_none().0,
179            ))
180        }
181    }
182
183    fn insert<P: IsA<Widget>>(&self, child: &P, position: i32) {
184        unsafe {
185            gtk_sys::gtk_menu_shell_insert(
186                self.as_ref().to_glib_none().0,
187                child.as_ref().to_glib_none().0,
188                position,
189            );
190        }
191    }
192
193    fn prepend<P: IsA<Widget>>(&self, child: &P) {
194        unsafe {
195            gtk_sys::gtk_menu_shell_prepend(
196                self.as_ref().to_glib_none().0,
197                child.as_ref().to_glib_none().0,
198            );
199        }
200    }
201
202    fn select_first(&self, search_sensitive: bool) {
203        unsafe {
204            gtk_sys::gtk_menu_shell_select_first(
205                self.as_ref().to_glib_none().0,
206                search_sensitive.to_glib(),
207            );
208        }
209    }
210
211    fn select_item<P: IsA<Widget>>(&self, menu_item: &P) {
212        unsafe {
213            gtk_sys::gtk_menu_shell_select_item(
214                self.as_ref().to_glib_none().0,
215                menu_item.as_ref().to_glib_none().0,
216            );
217        }
218    }
219
220    fn set_take_focus(&self, take_focus: bool) {
221        unsafe {
222            gtk_sys::gtk_menu_shell_set_take_focus(
223                self.as_ref().to_glib_none().0,
224                take_focus.to_glib(),
225            );
226        }
227    }
228
229    fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
230        unsafe extern "C" fn activate_current_trampoline<P, F: Fn(&P, bool) + 'static>(
231            this: *mut gtk_sys::GtkMenuShell,
232            force_hide: glib_sys::gboolean,
233            f: glib_sys::gpointer,
234        ) where
235            P: IsA<MenuShell>,
236        {
237            let f: &F = &*(f as *const F);
238            f(
239                &MenuShell::from_glib_borrow(this).unsafe_cast(),
240                from_glib(force_hide),
241            )
242        }
243        unsafe {
244            let f: Box_<F> = Box_::new(f);
245            connect_raw(
246                self.as_ptr() as *mut _,
247                b"activate-current\0".as_ptr() as *const _,
248                Some(transmute(activate_current_trampoline::<Self, F> as usize)),
249                Box_::into_raw(f),
250            )
251        }
252    }
253
254    fn emit_activate_current(&self, force_hide: bool) {
255        let _ = unsafe {
256            glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
257                .emit("activate-current", &[&force_hide])
258                .unwrap()
259        };
260    }
261
262    fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
263        unsafe extern "C" fn cancel_trampoline<P, F: Fn(&P) + 'static>(
264            this: *mut gtk_sys::GtkMenuShell,
265            f: glib_sys::gpointer,
266        ) where
267            P: IsA<MenuShell>,
268        {
269            let f: &F = &*(f as *const F);
270            f(&MenuShell::from_glib_borrow(this).unsafe_cast())
271        }
272        unsafe {
273            let f: Box_<F> = Box_::new(f);
274            connect_raw(
275                self.as_ptr() as *mut _,
276                b"cancel\0".as_ptr() as *const _,
277                Some(transmute(cancel_trampoline::<Self, F> as usize)),
278                Box_::into_raw(f),
279            )
280        }
281    }
282
283    fn emit_cancel(&self) {
284        let _ = unsafe {
285            glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
286                .emit("cancel", &[])
287                .unwrap()
288        };
289    }
290
291    fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId {
292        unsafe extern "C" fn cycle_focus_trampoline<P, F: Fn(&P, DirectionType) + 'static>(
293            this: *mut gtk_sys::GtkMenuShell,
294            direction: gtk_sys::GtkDirectionType,
295            f: glib_sys::gpointer,
296        ) where
297            P: IsA<MenuShell>,
298        {
299            let f: &F = &*(f as *const F);
300            f(
301                &MenuShell::from_glib_borrow(this).unsafe_cast(),
302                from_glib(direction),
303            )
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                b"cycle-focus\0".as_ptr() as *const _,
310                Some(transmute(cycle_focus_trampoline::<Self, F> as usize)),
311                Box_::into_raw(f),
312            )
313        }
314    }
315
316    fn emit_cycle_focus(&self, direction: DirectionType) {
317        let _ = unsafe {
318            glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
319                .emit("cycle-focus", &[&direction])
320                .unwrap()
321        };
322    }
323
324    fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325        unsafe extern "C" fn deactivate_trampoline<P, F: Fn(&P) + 'static>(
326            this: *mut gtk_sys::GtkMenuShell,
327            f: glib_sys::gpointer,
328        ) where
329            P: IsA<MenuShell>,
330        {
331            let f: &F = &*(f as *const F);
332            f(&MenuShell::from_glib_borrow(this).unsafe_cast())
333        }
334        unsafe {
335            let f: Box_<F> = Box_::new(f);
336            connect_raw(
337                self.as_ptr() as *mut _,
338                b"deactivate\0".as_ptr() as *const _,
339                Some(transmute(deactivate_trampoline::<Self, F> as usize)),
340                Box_::into_raw(f),
341            )
342        }
343    }
344
345    fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId {
346        unsafe extern "C" fn insert_trampoline<P, F: Fn(&P, &Widget, i32) + 'static>(
347            this: *mut gtk_sys::GtkMenuShell,
348            child: *mut gtk_sys::GtkWidget,
349            position: libc::c_int,
350            f: glib_sys::gpointer,
351        ) where
352            P: IsA<MenuShell>,
353        {
354            let f: &F = &*(f as *const F);
355            f(
356                &MenuShell::from_glib_borrow(this).unsafe_cast(),
357                &from_glib_borrow(child),
358                position,
359            )
360        }
361        unsafe {
362            let f: Box_<F> = Box_::new(f);
363            connect_raw(
364                self.as_ptr() as *mut _,
365                b"insert\0".as_ptr() as *const _,
366                Some(transmute(insert_trampoline::<Self, F> as usize)),
367                Box_::into_raw(f),
368            )
369        }
370    }
371
372    fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>(
373        &self,
374        f: F,
375    ) -> SignalHandlerId {
376        unsafe extern "C" fn move_current_trampoline<P, F: Fn(&P, MenuDirectionType) + 'static>(
377            this: *mut gtk_sys::GtkMenuShell,
378            direction: gtk_sys::GtkMenuDirectionType,
379            f: glib_sys::gpointer,
380        ) where
381            P: IsA<MenuShell>,
382        {
383            let f: &F = &*(f as *const F);
384            f(
385                &MenuShell::from_glib_borrow(this).unsafe_cast(),
386                from_glib(direction),
387            )
388        }
389        unsafe {
390            let f: Box_<F> = Box_::new(f);
391            connect_raw(
392                self.as_ptr() as *mut _,
393                b"move-current\0".as_ptr() as *const _,
394                Some(transmute(move_current_trampoline::<Self, F> as usize)),
395                Box_::into_raw(f),
396            )
397        }
398    }
399
400    fn emit_move_current(&self, direction: MenuDirectionType) {
401        let _ = unsafe {
402            glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
403                .emit("move-current", &[&direction])
404                .unwrap()
405        };
406    }
407
408    fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>(
409        &self,
410        f: F,
411    ) -> SignalHandlerId {
412        unsafe extern "C" fn move_selected_trampoline<P, F: Fn(&P, i32) -> Inhibit + 'static>(
413            this: *mut gtk_sys::GtkMenuShell,
414            distance: libc::c_int,
415            f: glib_sys::gpointer,
416        ) -> glib_sys::gboolean
417        where
418            P: IsA<MenuShell>,
419        {
420            let f: &F = &*(f as *const F);
421            f(&MenuShell::from_glib_borrow(this).unsafe_cast(), distance).to_glib()
422        }
423        unsafe {
424            let f: Box_<F> = Box_::new(f);
425            connect_raw(
426                self.as_ptr() as *mut _,
427                b"move-selected\0".as_ptr() as *const _,
428                Some(transmute(move_selected_trampoline::<Self, F> as usize)),
429                Box_::into_raw(f),
430            )
431        }
432    }
433
434    fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
435        unsafe extern "C" fn selection_done_trampoline<P, F: Fn(&P) + 'static>(
436            this: *mut gtk_sys::GtkMenuShell,
437            f: glib_sys::gpointer,
438        ) where
439            P: IsA<MenuShell>,
440        {
441            let f: &F = &*(f as *const F);
442            f(&MenuShell::from_glib_borrow(this).unsafe_cast())
443        }
444        unsafe {
445            let f: Box_<F> = Box_::new(f);
446            connect_raw(
447                self.as_ptr() as *mut _,
448                b"selection-done\0".as_ptr() as *const _,
449                Some(transmute(selection_done_trampoline::<Self, F> as usize)),
450                Box_::into_raw(f),
451            )
452        }
453    }
454
455    fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
456        unsafe extern "C" fn notify_take_focus_trampoline<P, F: Fn(&P) + 'static>(
457            this: *mut gtk_sys::GtkMenuShell,
458            _param_spec: glib_sys::gpointer,
459            f: glib_sys::gpointer,
460        ) where
461            P: IsA<MenuShell>,
462        {
463            let f: &F = &*(f as *const F);
464            f(&MenuShell::from_glib_borrow(this).unsafe_cast())
465        }
466        unsafe {
467            let f: Box_<F> = Box_::new(f);
468            connect_raw(
469                self.as_ptr() as *mut _,
470                b"notify::take-focus\0".as_ptr() as *const _,
471                Some(transmute(notify_take_focus_trampoline::<Self, F> as usize)),
472                Box_::into_raw(f),
473            )
474        }
475    }
476}
477
478impl fmt::Display for MenuShell {
479    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
480        write!(f, "MenuShell")
481    }
482}