use Buildable;
use Container;
use DirectionType;
use MenuDirectionType;
use MenuItem;
use Widget;
use ffi;
use gio;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::object::ObjectExt;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use libc;
use signal::Inhibit;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib_wrapper! {
pub struct MenuShell(Object<ffi::GtkMenuShell, ffi::GtkMenuShellClass, MenuShellClass>) @extends Container, Widget, @implements Buildable;
match fn {
get_type => || ffi::gtk_menu_shell_get_type(),
}
}
pub const NONE_MENU_SHELL: Option<&MenuShell> = None;
pub trait MenuShellExt: 'static {
fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool);
fn append<P: IsA<MenuItem>>(&self, child: &P);
fn bind_model<'a, 'b, P: IsA<gio::MenuModel> + 'a, Q: Into<Option<&'a P>>, R: Into<Option<&'b str>>>(&self, model: Q, action_namespace: R, with_separators: bool);
fn cancel(&self);
fn deactivate(&self);
fn deselect(&self);
fn get_parent_shell(&self) -> Option<Widget>;
fn get_selected_item(&self) -> Option<Widget>;
fn get_take_focus(&self) -> bool;
fn insert<P: IsA<Widget>>(&self, child: &P, position: i32);
fn prepend<P: IsA<Widget>>(&self, child: &P);
fn select_first(&self, search_sensitive: bool);
fn select_item<P: IsA<Widget>>(&self, menu_item: &P);
fn set_take_focus(&self, take_focus: bool);
fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_activate_current(&self, force_hide: bool);
fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_cancel(&self);
fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_cycle_focus(&self, direction: DirectionType);
fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_move_current(&self, direction: MenuDirectionType);
fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<MenuShell>> MenuShellExt for O {
fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool) {
unsafe {
ffi::gtk_menu_shell_activate_item(self.as_ref().to_glib_none().0, menu_item.as_ref().to_glib_none().0, force_deactivate.to_glib());
}
}
fn append<P: IsA<MenuItem>>(&self, child: &P) {
unsafe {
ffi::gtk_menu_shell_append(self.as_ref().to_glib_none().0, child.as_ref().to_glib_none().0);
}
}
fn bind_model<'a, 'b, P: IsA<gio::MenuModel> + 'a, Q: Into<Option<&'a P>>, R: Into<Option<&'b str>>>(&self, model: Q, action_namespace: R, with_separators: bool) {
let model = model.into();
let action_namespace = action_namespace.into();
unsafe {
ffi::gtk_menu_shell_bind_model(self.as_ref().to_glib_none().0, model.map(|p| p.as_ref()).to_glib_none().0, action_namespace.to_glib_none().0, with_separators.to_glib());
}
}
fn cancel(&self) {
unsafe {
ffi::gtk_menu_shell_cancel(self.as_ref().to_glib_none().0);
}
}
fn deactivate(&self) {
unsafe {
ffi::gtk_menu_shell_deactivate(self.as_ref().to_glib_none().0);
}
}
fn deselect(&self) {
unsafe {
ffi::gtk_menu_shell_deselect(self.as_ref().to_glib_none().0);
}
}
fn get_parent_shell(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_menu_shell_get_parent_shell(self.as_ref().to_glib_none().0))
}
}
fn get_selected_item(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_menu_shell_get_selected_item(self.as_ref().to_glib_none().0))
}
}
fn get_take_focus(&self) -> bool {
unsafe {
from_glib(ffi::gtk_menu_shell_get_take_focus(self.as_ref().to_glib_none().0))
}
}
fn insert<P: IsA<Widget>>(&self, child: &P, position: i32) {
unsafe {
ffi::gtk_menu_shell_insert(self.as_ref().to_glib_none().0, child.as_ref().to_glib_none().0, position);
}
}
fn prepend<P: IsA<Widget>>(&self, child: &P) {
unsafe {
ffi::gtk_menu_shell_prepend(self.as_ref().to_glib_none().0, child.as_ref().to_glib_none().0);
}
}
fn select_first(&self, search_sensitive: bool) {
unsafe {
ffi::gtk_menu_shell_select_first(self.as_ref().to_glib_none().0, search_sensitive.to_glib());
}
}
fn select_item<P: IsA<Widget>>(&self, menu_item: &P) {
unsafe {
ffi::gtk_menu_shell_select_item(self.as_ref().to_glib_none().0, menu_item.as_ref().to_glib_none().0);
}
}
fn set_take_focus(&self, take_focus: bool) {
unsafe {
ffi::gtk_menu_shell_set_take_focus(self.as_ref().to_glib_none().0, take_focus.to_glib());
}
}
fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"activate-current\0".as_ptr() as *const _,
Some(transmute(activate_current_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_activate_current(&self, force_hide: bool) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("activate-current", &[&force_hide]).unwrap() };
}
fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"cancel\0".as_ptr() as *const _,
Some(transmute(cancel_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_cancel(&self) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("cancel", &[]).unwrap() };
}
fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"cycle-focus\0".as_ptr() as *const _,
Some(transmute(cycle_focus_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_cycle_focus(&self, direction: DirectionType) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("cycle-focus", &[&direction]).unwrap() };
}
fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"deactivate\0".as_ptr() as *const _,
Some(transmute(deactivate_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"insert\0".as_ptr() as *const _,
Some(transmute(insert_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"move-current\0".as_ptr() as *const _,
Some(transmute(move_current_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_move_current(&self, direction: MenuDirectionType) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("move-current", &[&direction]).unwrap() };
}
fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"move-selected\0".as_ptr() as *const _,
Some(transmute(move_selected_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"selection-done\0".as_ptr() as *const _,
Some(transmute(selection_done_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"notify::take-focus\0".as_ptr() as *const _,
Some(transmute(notify_take_focus_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
}
unsafe extern "C" fn activate_current_trampoline<P, F: Fn(&P, bool) + 'static>(this: *mut ffi::GtkMenuShell, force_hide: glib_ffi::gboolean, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast(), from_glib(force_hide))
}
unsafe extern "C" fn cancel_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuShell, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn cycle_focus_trampoline<P, F: Fn(&P, DirectionType) + 'static>(this: *mut ffi::GtkMenuShell, direction: ffi::GtkDirectionType, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast(), from_glib(direction))
}
unsafe extern "C" fn deactivate_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuShell, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn insert_trampoline<P, F: Fn(&P, &Widget, i32) + 'static>(this: *mut ffi::GtkMenuShell, child: *mut ffi::GtkWidget, position: libc::c_int, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(child), position)
}
unsafe extern "C" fn move_current_trampoline<P, F: Fn(&P, MenuDirectionType) + 'static>(this: *mut ffi::GtkMenuShell, direction: ffi::GtkMenuDirectionType, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast(), from_glib(direction))
}
unsafe extern "C" fn move_selected_trampoline<P, F: Fn(&P, i32) -> Inhibit + 'static>(this: *mut ffi::GtkMenuShell, distance: libc::c_int, f: glib_ffi::gpointer) -> glib_ffi::gboolean
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast(), distance).to_glib()
}
unsafe extern "C" fn selection_done_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuShell, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_take_focus_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuShell, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuShell> {
let f: &F = transmute(f);
f(&MenuShell::from_glib_borrow(this).unsafe_cast())
}
impl fmt::Display for MenuShell {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MenuShell")
}
}