use Buildable;
use Orientable;
use Widget;
use ffi;
use glib::GString;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_ffi;
use pango;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib_wrapper! {
pub struct ProgressBar(Object<ffi::GtkProgressBar, ffi::GtkProgressBarClass, ProgressBarClass>) @extends Widget, @implements Buildable, Orientable;
match fn {
get_type => || ffi::gtk_progress_bar_get_type(),
}
}
impl ProgressBar {
pub fn new() -> ProgressBar {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_progress_bar_new()).unsafe_cast()
}
}
}
impl Default for ProgressBar {
fn default() -> Self {
Self::new()
}
}
pub const NONE_PROGRESS_BAR: Option<&ProgressBar> = None;
pub trait ProgressBarExt: 'static {
fn get_ellipsize(&self) -> pango::EllipsizeMode;
fn get_fraction(&self) -> f64;
fn get_inverted(&self) -> bool;
fn get_pulse_step(&self) -> f64;
fn get_show_text(&self) -> bool;
fn get_text(&self) -> Option<GString>;
fn pulse(&self);
fn set_ellipsize(&self, mode: pango::EllipsizeMode);
fn set_fraction(&self, fraction: f64);
fn set_inverted(&self, inverted: bool);
fn set_pulse_step(&self, fraction: f64);
fn set_show_text(&self, show_text: bool);
fn set_text<'a, P: Into<Option<&'a str>>>(&self, text: P);
fn connect_property_ellipsize_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_fraction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_pulse_step_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_show_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<ProgressBar>> ProgressBarExt for O {
fn get_ellipsize(&self) -> pango::EllipsizeMode {
unsafe {
from_glib(ffi::gtk_progress_bar_get_ellipsize(self.as_ref().to_glib_none().0))
}
}
fn get_fraction(&self) -> f64 {
unsafe {
ffi::gtk_progress_bar_get_fraction(self.as_ref().to_glib_none().0)
}
}
fn get_inverted(&self) -> bool {
unsafe {
from_glib(ffi::gtk_progress_bar_get_inverted(self.as_ref().to_glib_none().0))
}
}
fn get_pulse_step(&self) -> f64 {
unsafe {
ffi::gtk_progress_bar_get_pulse_step(self.as_ref().to_glib_none().0)
}
}
fn get_show_text(&self) -> bool {
unsafe {
from_glib(ffi::gtk_progress_bar_get_show_text(self.as_ref().to_glib_none().0))
}
}
fn get_text(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::gtk_progress_bar_get_text(self.as_ref().to_glib_none().0))
}
}
fn pulse(&self) {
unsafe {
ffi::gtk_progress_bar_pulse(self.as_ref().to_glib_none().0);
}
}
fn set_ellipsize(&self, mode: pango::EllipsizeMode) {
unsafe {
ffi::gtk_progress_bar_set_ellipsize(self.as_ref().to_glib_none().0, mode.to_glib());
}
}
fn set_fraction(&self, fraction: f64) {
unsafe {
ffi::gtk_progress_bar_set_fraction(self.as_ref().to_glib_none().0, fraction);
}
}
fn set_inverted(&self, inverted: bool) {
unsafe {
ffi::gtk_progress_bar_set_inverted(self.as_ref().to_glib_none().0, inverted.to_glib());
}
}
fn set_pulse_step(&self, fraction: f64) {
unsafe {
ffi::gtk_progress_bar_set_pulse_step(self.as_ref().to_glib_none().0, fraction);
}
}
fn set_show_text(&self, show_text: bool) {
unsafe {
ffi::gtk_progress_bar_set_show_text(self.as_ref().to_glib_none().0, show_text.to_glib());
}
}
fn set_text<'a, P: Into<Option<&'a str>>>(&self, text: P) {
let text = text.into();
unsafe {
ffi::gtk_progress_bar_set_text(self.as_ref().to_glib_none().0, text.to_glib_none().0);
}
}
fn connect_property_ellipsize_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::ellipsize\0".as_ptr() as *const _,
Some(transmute(notify_ellipsize_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_fraction_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::fraction\0".as_ptr() as *const _,
Some(transmute(notify_fraction_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_inverted_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::inverted\0".as_ptr() as *const _,
Some(transmute(notify_inverted_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_pulse_step_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::pulse-step\0".as_ptr() as *const _,
Some(transmute(notify_pulse_step_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_show_text_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::show-text\0".as_ptr() as *const _,
Some(transmute(notify_show_text_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_text_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::text\0".as_ptr() as *const _,
Some(transmute(notify_text_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
}
unsafe extern "C" fn notify_ellipsize_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_fraction_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_inverted_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_pulse_step_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_show_text_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn notify_text_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkProgressBar, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<ProgressBar> {
let f: &F = transmute(f);
f(&ProgressBar::from_glib_borrow(this).unsafe_cast())
}
impl fmt::Display for ProgressBar {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ProgressBar")
}
}