1use glib::object::Cast;
6use glib::object::IsA;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib_sys;
11use gtk_sys;
12use std::boxed::Box as Box_;
13use std::fmt;
14use std::mem::transmute;
15use Orientation;
16
17glib_wrapper! {
18 pub struct Orientable(Interface<gtk_sys::GtkOrientable>);
19
20 match fn {
21 get_type => || gtk_sys::gtk_orientable_get_type(),
22 }
23}
24
25pub const NONE_ORIENTABLE: Option<&Orientable> = None;
26
27pub trait OrientableExt: 'static {
28 fn get_orientation(&self) -> Orientation;
29
30 fn set_orientation(&self, orientation: Orientation);
31
32 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
33}
34
35impl<O: IsA<Orientable>> OrientableExt for O {
36 fn get_orientation(&self) -> Orientation {
37 unsafe {
38 from_glib(gtk_sys::gtk_orientable_get_orientation(
39 self.as_ref().to_glib_none().0,
40 ))
41 }
42 }
43
44 fn set_orientation(&self, orientation: Orientation) {
45 unsafe {
46 gtk_sys::gtk_orientable_set_orientation(
47 self.as_ref().to_glib_none().0,
48 orientation.to_glib(),
49 );
50 }
51 }
52
53 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
54 unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
55 this: *mut gtk_sys::GtkOrientable,
56 _param_spec: glib_sys::gpointer,
57 f: glib_sys::gpointer,
58 ) where
59 P: IsA<Orientable>,
60 {
61 let f: &F = &*(f as *const F);
62 f(&Orientable::from_glib_borrow(this).unsafe_cast())
63 }
64 unsafe {
65 let f: Box_<F> = Box_::new(f);
66 connect_raw(
67 self.as_ptr() as *mut _,
68 b"notify::orientation\0".as_ptr() as *const _,
69 Some(transmute(notify_orientation_trampoline::<Self, F> as usize)),
70 Box_::into_raw(f),
71 )
72 }
73 }
74}
75
76impl fmt::Display for Orientable {
77 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78 write!(f, "Orientable")
79 }
80}