use Actionable;
use Bin;
use Buildable;
use Container;
use ToolItem;
use Widget;
use ffi;
use glib;
use glib::GString;
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 std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib_wrapper! {
pub struct ToolButton(Object<ffi::GtkToolButton, ffi::GtkToolButtonClass, ToolButtonClass>) @extends ToolItem, Bin, Container, Widget, @implements Buildable, Actionable;
match fn {
get_type => || ffi::gtk_tool_button_get_type(),
}
}
impl ToolButton {
pub fn new<'a, 'b, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>, R: Into<Option<&'b str>>>(icon_widget: Q, label: R) -> ToolButton {
assert_initialized_main_thread!();
let icon_widget = icon_widget.into();
let label = label.into();
unsafe {
ToolItem::from_glib_none(ffi::gtk_tool_button_new(icon_widget.map(|p| p.as_ref()).to_glib_none().0, label.to_glib_none().0)).unsafe_cast()
}
}
}
pub const NONE_TOOL_BUTTON: Option<&ToolButton> = None;
pub trait ToolButtonExt: 'static {
fn get_icon_name(&self) -> Option<GString>;
fn get_icon_widget(&self) -> Option<Widget>;
fn get_label(&self) -> Option<GString>;
fn get_label_widget(&self) -> Option<Widget>;
fn get_use_underline(&self) -> bool;
fn set_icon_name<'a, P: Into<Option<&'a str>>>(&self, icon_name: P);
fn set_icon_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, icon_widget: Q);
fn set_label<'a, P: Into<Option<&'a str>>>(&self, label: P);
fn set_label_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, label_widget: Q);
fn set_use_underline(&self, use_underline: bool);
fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_clicked(&self);
fn connect_property_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_icon_widget_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_label_widget_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<ToolButton>> ToolButtonExt for O {
fn get_icon_name(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_icon_name(self.as_ref().to_glib_none().0))
}
}
fn get_icon_widget(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_icon_widget(self.as_ref().to_glib_none().0))
}
}
fn get_label(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_label(self.as_ref().to_glib_none().0))
}
}
fn get_label_widget(&self) -> Option<Widget> {
unsafe {
from_glib_none(ffi::gtk_tool_button_get_label_widget(self.as_ref().to_glib_none().0))
}
}
fn get_use_underline(&self) -> bool {
unsafe {
from_glib(ffi::gtk_tool_button_get_use_underline(self.as_ref().to_glib_none().0))
}
}
fn set_icon_name<'a, P: Into<Option<&'a str>>>(&self, icon_name: P) {
let icon_name = icon_name.into();
unsafe {
ffi::gtk_tool_button_set_icon_name(self.as_ref().to_glib_none().0, icon_name.to_glib_none().0);
}
}
fn set_icon_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, icon_widget: Q) {
let icon_widget = icon_widget.into();
unsafe {
ffi::gtk_tool_button_set_icon_widget(self.as_ref().to_glib_none().0, icon_widget.map(|p| p.as_ref()).to_glib_none().0);
}
}
fn set_label<'a, P: Into<Option<&'a str>>>(&self, label: P) {
let label = label.into();
unsafe {
ffi::gtk_tool_button_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
}
}
fn set_label_widget<'a, P: IsA<Widget> + 'a, Q: Into<Option<&'a P>>>(&self, label_widget: Q) {
let label_widget = label_widget.into();
unsafe {
ffi::gtk_tool_button_set_label_widget(self.as_ref().to_glib_none().0, label_widget.map(|p| p.as_ref()).to_glib_none().0);
}
}
fn set_use_underline(&self, use_underline: bool) {
unsafe {
ffi::gtk_tool_button_set_use_underline(self.as_ref().to_glib_none().0, use_underline.to_glib());
}
}
fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"clicked\0".as_ptr() as *const _,
Some(transmute(clicked_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn emit_clicked(&self) {
let _ = unsafe { glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_ffi::GObject).emit("clicked", &[]).unwrap() };
}
fn connect_property_icon_name_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::icon-name\0".as_ptr() as *const _,
Some(transmute(notify_icon_name_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_icon_widget_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::icon-widget\0".as_ptr() as *const _,
Some(transmute(notify_icon_widget_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_label_widget_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-widget\0".as_ptr() as *const _,
Some(transmute(notify_label_widget_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 clicked_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_icon_name_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_icon_widget_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_label_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_label_widget_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_use_underline_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkToolButton, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ToolButton> {
let f: &F = transmute(f);
f(&ToolButton::from_glib_borrow(this).unsafe_cast())
}
impl fmt::Display for ToolButton {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ToolButton")
}
}