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