gtk 0.6.0

Rust bindings for the GTK+ 3 library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use EventController;
use EventSequenceState;
use ffi;
use gdk;
use gdk_ffi;
use glib::StaticType;
use glib::Value;
use glib::object::Cast;
use glib::object::IsA;
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;
use std::mem::transmute;

glib_wrapper! {
    pub struct Gesture(Object<ffi::GtkGesture, ffi::GtkGestureClass, GestureClass>) @extends EventController;

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

pub const NONE_GESTURE: Option<&Gesture> = None;

pub trait GestureExt: 'static {
    fn get_bounding_box(&self) -> Option<gdk::Rectangle>;

    fn get_bounding_box_center(&self) -> Option<(f64, f64)>;

    fn get_device(&self) -> Option<gdk::Device>;

    fn get_group(&self) -> Vec<Gesture>;

    fn get_last_event<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> Option<gdk::Event>;

    fn get_last_updated_sequence(&self) -> Option<gdk::EventSequence>;

    fn get_point<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> Option<(f64, f64)>;

    fn get_sequence_state(&self, sequence: &gdk::EventSequence) -> EventSequenceState;

    fn get_sequences(&self) -> Vec<gdk::EventSequence>;

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

    fn group<P: IsA<Gesture>>(&self, gesture: &P);

    fn handles_sequence<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> bool;

    fn is_active(&self) -> bool;

    fn is_grouped_with<P: IsA<Gesture>>(&self, other: &P) -> bool;

    fn is_recognized(&self) -> bool;

    fn set_sequence_state(&self, sequence: &gdk::EventSequence, state: EventSequenceState) -> bool;

    fn set_state(&self, state: EventSequenceState) -> bool;

    fn set_window<'a, P: IsA<gdk::Window> + 'a, Q: Into<Option<&'a P>>>(&self, window: Q);

    fn ungroup(&self);

    fn get_property_n_points(&self) -> u32;

    fn connect_begin<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_cancel<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_end<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_sequence_state_changed<F: Fn(&Self, &gdk::EventSequence, EventSequenceState) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_update<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;

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

impl<O: IsA<Gesture>> GestureExt for O {
    fn get_bounding_box(&self) -> Option<gdk::Rectangle> {
        unsafe {
            let mut rect = gdk::Rectangle::uninitialized();
            let ret = from_glib(ffi::gtk_gesture_get_bounding_box(self.as_ref().to_glib_none().0, rect.to_glib_none_mut().0));
            if ret { Some(rect) } else { None }
        }
    }

    fn get_bounding_box_center(&self) -> Option<(f64, f64)> {
        unsafe {
            let mut x = mem::uninitialized();
            let mut y = mem::uninitialized();
            let ret = from_glib(ffi::gtk_gesture_get_bounding_box_center(self.as_ref().to_glib_none().0, &mut x, &mut y));
            if ret { Some((x, y)) } else { None }
        }
    }

    fn get_device(&self) -> Option<gdk::Device> {
        unsafe {
            from_glib_none(ffi::gtk_gesture_get_device(self.as_ref().to_glib_none().0))
        }
    }

    fn get_group(&self) -> Vec<Gesture> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_gesture_get_group(self.as_ref().to_glib_none().0))
        }
    }

    fn get_last_event<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> Option<gdk::Event> {
        let sequence = sequence.into();
        unsafe {
            from_glib_none(ffi::gtk_gesture_get_last_event(self.as_ref().to_glib_none().0, mut_override(sequence.to_glib_none().0)))
        }
    }

    fn get_last_updated_sequence(&self) -> Option<gdk::EventSequence> {
        unsafe {
            from_glib_none(ffi::gtk_gesture_get_last_updated_sequence(self.as_ref().to_glib_none().0))
        }
    }

    fn get_point<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> Option<(f64, f64)> {
        let sequence = sequence.into();
        unsafe {
            let mut x = mem::uninitialized();
            let mut y = mem::uninitialized();
            let ret = from_glib(ffi::gtk_gesture_get_point(self.as_ref().to_glib_none().0, mut_override(sequence.to_glib_none().0), &mut x, &mut y));
            if ret { Some((x, y)) } else { None }
        }
    }

    fn get_sequence_state(&self, sequence: &gdk::EventSequence) -> EventSequenceState {
        unsafe {
            from_glib(ffi::gtk_gesture_get_sequence_state(self.as_ref().to_glib_none().0, mut_override(sequence.to_glib_none().0)))
        }
    }

    fn get_sequences(&self) -> Vec<gdk::EventSequence> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_gesture_get_sequences(self.as_ref().to_glib_none().0))
        }
    }

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

    fn group<P: IsA<Gesture>>(&self, gesture: &P) {
        unsafe {
            ffi::gtk_gesture_group(self.as_ref().to_glib_none().0, gesture.as_ref().to_glib_none().0);
        }
    }

    fn handles_sequence<'a, P: Into<Option<&'a gdk::EventSequence>>>(&self, sequence: P) -> bool {
        let sequence = sequence.into();
        unsafe {
            from_glib(ffi::gtk_gesture_handles_sequence(self.as_ref().to_glib_none().0, mut_override(sequence.to_glib_none().0)))
        }
    }

    fn is_active(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_is_active(self.as_ref().to_glib_none().0))
        }
    }

    fn is_grouped_with<P: IsA<Gesture>>(&self, other: &P) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_is_grouped_with(self.as_ref().to_glib_none().0, other.as_ref().to_glib_none().0))
        }
    }

    fn is_recognized(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_is_recognized(self.as_ref().to_glib_none().0))
        }
    }

    fn set_sequence_state(&self, sequence: &gdk::EventSequence, state: EventSequenceState) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_set_sequence_state(self.as_ref().to_glib_none().0, mut_override(sequence.to_glib_none().0), state.to_glib()))
        }
    }

    fn set_state(&self, state: EventSequenceState) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_set_state(self.as_ref().to_glib_none().0, state.to_glib()))
        }
    }

    fn set_window<'a, P: IsA<gdk::Window> + 'a, Q: Into<Option<&'a P>>>(&self, window: Q) {
        let window = window.into();
        unsafe {
            ffi::gtk_gesture_set_window(self.as_ref().to_glib_none().0, window.map(|p| p.as_ref()).to_glib_none().0);
        }
    }

    fn ungroup(&self) {
        unsafe {
            ffi::gtk_gesture_ungroup(self.as_ref().to_glib_none().0);
        }
    }

    fn get_property_n_points(&self) -> u32 {
        unsafe {
            let mut value = Value::from_type(<u32 as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0 as *mut gobject_ffi::GObject, b"n-points\0".as_ptr() as *const _, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn connect_begin<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"begin\0".as_ptr() as *const _,
                Some(transmute(begin_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_cancel<F: Fn(&Self, &gdk::EventSequence) + '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 connect_end<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"end\0".as_ptr() as *const _,
                Some(transmute(end_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_sequence_state_changed<F: Fn(&Self, &gdk::EventSequence, EventSequenceState) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"sequence-state-changed\0".as_ptr() as *const _,
                Some(transmute(sequence_state_changed_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_update<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"update\0".as_ptr() as *const _,
                Some(transmute(update_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_window_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::window\0".as_ptr() as *const _,
                Some(transmute(notify_window_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }
}

unsafe extern "C" fn begin_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(this: *mut ffi::GtkGesture, sequence: *mut gdk_ffi::GdkEventSequence, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sequence))
}

unsafe extern "C" fn cancel_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(this: *mut ffi::GtkGesture, sequence: *mut gdk_ffi::GdkEventSequence, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sequence))
}

unsafe extern "C" fn end_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(this: *mut ffi::GtkGesture, sequence: *mut gdk_ffi::GdkEventSequence, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sequence))
}

unsafe extern "C" fn sequence_state_changed_trampoline<P, F: Fn(&P, &gdk::EventSequence, EventSequenceState) + 'static>(this: *mut ffi::GtkGesture, sequence: *mut gdk_ffi::GdkEventSequence, state: ffi::GtkEventSequenceState, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sequence), from_glib(state))
}

unsafe extern "C" fn update_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(this: *mut ffi::GtkGesture, sequence: *mut gdk_ffi::GdkEventSequence, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sequence))
}

unsafe extern "C" fn notify_window_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GtkGesture, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Gesture> {
    let f: &F = transmute(f);
    f(&Gesture::from_glib_borrow(this).unsafe_cast())
}

impl fmt::Display for Gesture {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Gesture")
    }
}