gtk 0.1.0

Rust bindings for the GTK+ 3 library
// This file was generated by gir (4d68d19) from gir-files (11e0e6d)
// DO NOT EDIT

use Actionable;
use Bin;
use Container;
use Object;
use PositionType;
use ReliefStyle;
use Widget;
use ffi;
use gdk;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;

glib_wrapper! {
    pub struct Button(Object<ffi::GtkButton>): Bin, Container, Widget, Actionable;

    match fn {
        get_type => || ffi::gtk_button_get_type(),
    }
}

impl Button {
    pub fn new() -> Button {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_button_new()).downcast_unchecked()
        }
    }

    #[cfg(feature = "v3_10")]
    pub fn new_from_icon_name(icon_name: &str, size: i32) -> Button {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_button_new_from_icon_name(icon_name.to_glib_none().0, size)).downcast_unchecked()
        }
    }

    pub fn new_from_stock(stock_id: &str) -> Button {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_button_new_from_stock(stock_id.to_glib_none().0)).downcast_unchecked()
        }
    }

    pub fn new_with_label(label: &str) -> Button {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_button_new_with_label(label.to_glib_none().0)).downcast_unchecked()
        }
    }

    pub fn new_with_mnemonic(label: &str) -> Button {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_button_new_with_mnemonic(label.to_glib_none().0)).downcast_unchecked()
        }
    }
}

pub trait ButtonExt {
    fn clicked(&self);

    fn get_alignment(&self) -> (f32, f32);

    #[cfg(feature = "v3_6")]
    fn get_always_show_image(&self) -> bool;

    fn get_event_window(&self) -> Option<gdk::Window>;

    fn get_focus_on_click(&self) -> bool;

    fn get_image(&self) -> Option<Widget>;

    fn get_image_position(&self) -> PositionType;

    fn get_label(&self) -> Option<String>;

    fn get_relief(&self) -> ReliefStyle;

    fn get_use_stock(&self) -> bool;

    fn get_use_underline(&self) -> bool;

    fn set_alignment(&self, xalign: f32, yalign: f32);

    #[cfg(feature = "v3_6")]
    fn set_always_show_image(&self, always_show: bool);

    fn set_focus_on_click(&self, focus_on_click: bool);

    fn set_image<T: IsA<Widget>>(&self, image: &T);

    fn set_image_position(&self, position: PositionType);

    fn set_label(&self, label: &str);

    fn set_relief(&self, relief: ReliefStyle);

    fn set_use_stock(&self, use_stock: bool);

    fn set_use_underline(&self, use_underline: bool);

    fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> u64;

    fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> u64;
}

impl<O: IsA<Button> + IsA<Object>> ButtonExt for O {
    fn clicked(&self) {
        unsafe {
            ffi::gtk_button_clicked(self.to_glib_none().0);
        }
    }

    fn get_alignment(&self) -> (f32, f32) {
        unsafe {
            let mut xalign = mem::uninitialized();
            let mut yalign = mem::uninitialized();
            ffi::gtk_button_get_alignment(self.to_glib_none().0, &mut xalign, &mut yalign);
            (xalign, yalign)
        }
    }

    #[cfg(feature = "v3_6")]
    fn get_always_show_image(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_button_get_always_show_image(self.to_glib_none().0))
        }
    }

    fn get_event_window(&self) -> Option<gdk::Window> {
        unsafe {
            from_glib_none(ffi::gtk_button_get_event_window(self.to_glib_none().0))
        }
    }

    fn get_focus_on_click(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_button_get_focus_on_click(self.to_glib_none().0))
        }
    }

    fn get_image(&self) -> Option<Widget> {
        unsafe {
            from_glib_none(ffi::gtk_button_get_image(self.to_glib_none().0))
        }
    }

    fn get_image_position(&self) -> PositionType {
        unsafe {
            from_glib(ffi::gtk_button_get_image_position(self.to_glib_none().0))
        }
    }

    fn get_label(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::gtk_button_get_label(self.to_glib_none().0))
        }
    }

    fn get_relief(&self) -> ReliefStyle {
        unsafe {
            from_glib(ffi::gtk_button_get_relief(self.to_glib_none().0))
        }
    }

    fn get_use_stock(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_button_get_use_stock(self.to_glib_none().0))
        }
    }

    fn get_use_underline(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_button_get_use_underline(self.to_glib_none().0))
        }
    }

    fn set_alignment(&self, xalign: f32, yalign: f32) {
        unsafe {
            ffi::gtk_button_set_alignment(self.to_glib_none().0, xalign, yalign);
        }
    }

    #[cfg(feature = "v3_6")]
    fn set_always_show_image(&self, always_show: bool) {
        unsafe {
            ffi::gtk_button_set_always_show_image(self.to_glib_none().0, always_show.to_glib());
        }
    }

    fn set_focus_on_click(&self, focus_on_click: bool) {
        unsafe {
            ffi::gtk_button_set_focus_on_click(self.to_glib_none().0, focus_on_click.to_glib());
        }
    }

    fn set_image<T: IsA<Widget>>(&self, image: &T) {
        unsafe {
            ffi::gtk_button_set_image(self.to_glib_none().0, image.to_glib_none().0);
        }
    }

    fn set_image_position(&self, position: PositionType) {
        unsafe {
            ffi::gtk_button_set_image_position(self.to_glib_none().0, position.to_glib());
        }
    }

    fn set_label(&self, label: &str) {
        unsafe {
            ffi::gtk_button_set_label(self.to_glib_none().0, label.to_glib_none().0);
        }
    }

    fn set_relief(&self, relief: ReliefStyle) {
        unsafe {
            ffi::gtk_button_set_relief(self.to_glib_none().0, relief.to_glib());
        }
    }

    fn set_use_stock(&self, use_stock: bool) {
        unsafe {
            ffi::gtk_button_set_use_stock(self.to_glib_none().0, use_stock.to_glib());
        }
    }

    fn set_use_underline(&self, use_underline: bool) {
        unsafe {
            ffi::gtk_button_set_use_underline(self.to_glib_none().0, use_underline.to_glib());
        }
    }

    fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "activate",
                transmute(activate_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "clicked",
                transmute(clicked_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe extern "C" fn activate_trampoline<T>(this: *mut ffi::GtkButton, f: glib_ffi::gpointer)
where T: IsA<Button> {
    callback_guard!();
    let f: &Box_<Fn(&T) + 'static> = transmute(f);
    f(&Button::from_glib_none(this).downcast_unchecked())
}

unsafe extern "C" fn clicked_trampoline<T>(this: *mut ffi::GtkButton, f: glib_ffi::gpointer)
where T: IsA<Button> {
    callback_guard!();
    let f: &Box_<Fn(&T) + 'static> = transmute(f);
    f(&Button::from_glib_none(this).downcast_unchecked())
}