1use glib::object::{Cast, IsA};
6use glib::signal::{connect_raw, SignalHandlerId};
7use glib::translate::*;
8use glib_sys;
9use gtk_sys;
10use std::boxed::Box as Box_;
11use std::mem::transmute;
12use Switch;
13
14pub trait SwitchExtManual: 'static {
15 fn connect_changed_active<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
16}
17
18impl<O: IsA<Switch>> SwitchExtManual for O {
19 fn connect_changed_active<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
20 unsafe extern "C" fn changed_active_trampoline<T, F: Fn(&T) + 'static>(
21 this: *mut gtk_sys::GtkSwitch,
22 _gparamspec: glib_sys::gpointer,
23 f: glib_sys::gpointer,
24 ) where
25 T: IsA<Switch>,
26 {
27 let f: &F = &*(f as *const F);
28 f(&Switch::from_glib_borrow(this).unsafe_cast())
29 }
30 unsafe {
31 let f: Box_<F> = Box_::new(f);
32 connect_raw(
33 self.to_glib_none().0 as *mut _,
34 b"notify::active\0".as_ptr() as *mut _,
35 Some(transmute(changed_active_trampoline::<Self, F> as usize)),
36 Box_::into_raw(f),
37 )
38 }
39 }
40}