use Actionable;
use Bin;
use Buildable;
use Container;
use Menu;
use Widget;
use ffi;
use glib;
use glib::GString;
use glib::StaticType;
use glib::Value;
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 std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib_wrapper! {
pub struct MenuItem(Object<ffi::GtkMenuItem, ffi::GtkMenuItemClass, MenuItemClass>) @extends Bin, Container, Widget, @implements Buildable, Actionable;
match fn {
get_type => || ffi::gtk_menu_item_get_type(),
}
}
impl MenuItem {
pub fn new() -> MenuItem {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_menu_item_new()).unsafe_cast()
}
}
pub fn new_with_label(label: &str) -> MenuItem {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_menu_item_new_with_label(label.to_glib_none().0)).unsafe_cast()
}
}
pub fn new_with_mnemonic(label: &str) -> MenuItem {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_menu_item_new_with_mnemonic(label.to_glib_none().0)).unsafe_cast()
}
}
}
impl Default for MenuItem {
fn default() -> Self {
Self::new()
}
}
pub const NONE_MENU_ITEM: Option<&MenuItem> = None;
pub trait GtkMenuItemExt: 'static {
fn deselect(&self);
fn get_accel_path(&self) -> Option<GString>;
fn get_label(&self) -> Option<GString>;
fn get_reserve_indicator(&self) -> bool;
fn get_submenu(&self) -> Option<Widget>;
fn get_use_underline(&self) -> bool;
fn select(&self);
fn set_accel_path<'a, P: Into<Option<&'a str>>>(&self, accel_path: P);
fn set_label(&self, label: &str);
fn set_reserve_indicator(&self, reserve: bool);
fn set_submenu<'a, P: IsA<Menu> + 'a, Q: Into<Option<&'a P>>>(&self, submenu: Q);
fn set_use_underline(&self, setting: bool);
fn toggle_size_allocate(&self, allocation: i32);
fn toggle_size_request(&self, requisition: &mut i32);
fn get_property_right_justified(&self) -> bool;
fn set_property_right_justified(&self, right_justified: bool);
fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_activate(&self);
fn connect_activate_item<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_deselect<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_select<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_toggle_size_allocate<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_accel_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_right_justified_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<MenuItem>> GtkMenuItemExt for O {
fn deselect(&self) {
unsafe {
ffi::gtk_menu_item_deselect(self.as_ref().to_glib_none().0);
}
}
fn get_accel_path(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::gtk_menu_item_get_accel_path(self.as_ref().to_glib_none().0))
}
}
fn get_label(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::gtk_menu_item_get_label(self.as_ref().to_glib_none().0))
}
}
fn get_reserve_indicator(&self) -> bool {
unsafe {
from_glib(ffi::gtk_menu_item_get_reserve_indicator(self.as_ref().to_glib_none().0))
}
}
fn get_submenu(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_menu_item_get_submenu(self.as_ref().to_glib_none().0))
}
}
fn get_use_underline(&self) -> bool {
unsafe {
from_glib(ffi::gtk_menu_item_get_use_underline(self.as_ref().to_glib_none().0))
}
}
fn select(&self) {
unsafe {
ffi::gtk_menu_item_select(self.as_ref().to_glib_none().0);
}
}
fn set_accel_path<'a, P: Into<Option<&'a str>>>(&self, accel_path: P) {
let accel_path = accel_path.into();
unsafe {
ffi::gtk_menu_item_set_accel_path(self.as_ref().to_glib_none().0, accel_path.to_glib_none().0);
}
}
fn set_label(&self, label: &str) {
unsafe {
ffi::gtk_menu_item_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
}
}
fn set_reserve_indicator(&self, reserve: bool) {
unsafe {
ffi::gtk_menu_item_set_reserve_indicator(self.as_ref().to_glib_none().0, reserve.to_glib());
}
}
fn set_submenu<'a, P: IsA<Menu> + 'a, Q: Into<Option<&'a P>>>(&self, submenu: Q) {
let submenu = submenu.into();
unsafe {
ffi::gtk_menu_item_set_submenu(self.as_ref().to_glib_none().0, submenu.map(|p| p.as_ref()).to_glib_none().0);
}
}
fn set_use_underline(&self, setting: bool) {
unsafe {
ffi::gtk_menu_item_set_use_underline(self.as_ref().to_glib_none().0, setting.to_glib());
}
}
fn toggle_size_allocate(&self, allocation: i32) {
unsafe {
ffi::gtk_menu_item_toggle_size_allocate(self.as_ref().to_glib_none().0, allocation);
}
}
fn toggle_size_request(&self, requisition: &mut i32) {
unsafe {
ffi::gtk_menu_item_toggle_size_request(self.as_ref().to_glib_none().0, requisition);
}
}
fn get_property_right_justified(&self) -> bool {
unsafe {
let mut value = Value::from_type(<bool as StaticType>::static_type());
gobject_ffi::g_object_get_property(self.to_glib_none().0 as *mut gobject_ffi::GObject, b"right-justified\0".as_ptr() as *const _, value.to_glib_none_mut().0);
value.get().unwrap()
}
}
fn set_property_right_justified(&self, right_justified: bool) {
unsafe {
gobject_ffi::g_object_set_property(self.to_glib_none().0 as *mut gobject_ffi::GObject, b"right-justified\0".as_ptr() as *const _, Value::from(&right_justified).to_glib_none().0);
}
}
fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"activate\0".as_ptr() as *const _,
Some(transmute(activate_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_activate(&self) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("activate", &[]).unwrap() };
}
fn connect_activate_item<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"activate-item\0".as_ptr() as *const _,
Some(transmute(activate_item_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_deselect<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"deselect\0".as_ptr() as *const _,
Some(transmute(deselect_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_select<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"select\0".as_ptr() as *const _,
Some(transmute(select_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_toggle_size_allocate<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"toggle-size-allocate\0".as_ptr() as *const _,
Some(transmute(toggle_size_allocate_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_accel_path_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::accel-path\0".as_ptr() as *const _,
Some(transmute(notify_accel_path_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_label_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::label\0".as_ptr() as *const _,
Some(transmute(notify_label_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_right_justified_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::right-justified\0".as_ptr() as *const _,
Some(transmute(notify_right_justified_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_submenu_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::submenu\0".as_ptr() as *const _,
Some(transmute(notify_submenu_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_use_underline_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::use-underline\0".as_ptr() as *const _,
Some(transmute(notify_use_underline_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
}
unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn activate_item_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn deselect_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn select_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn toggle_size_allocate_trampoline<P, F: Fn(&P, i32) + 'static>(this: *mut ffi::GtkMenuItem, object: libc::c_int, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast(), object)
}
unsafe extern "C" fn notify_accel_path_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_label_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_right_justified_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_submenu_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_use_underline_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkMenuItem, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<MenuItem> {
let f: &F = transmute(f);
f(&MenuItem::from_glib_borrow(this).unsafe_cast())
}
impl fmt::Display for MenuItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MenuItem")
}
}