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