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
10mod sealed {
11 pub trait Sealed {}
12 impl<T: glib::object::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 unsafe {
25 let f: &F = &*(f as *const F);
26 f(Switch::from_glib_borrow(this).unsafe_cast_ref())
27 }
28 }
29 unsafe {
30 let f: Box_<F> = Box_::new(f);
31 connect_raw(
32 self.to_glib_none().0 as *mut _,
33 c"notify::active".as_ptr() as *mut _,
34 Some(transmute::<*const (), unsafe extern "C" fn()>(
35 changed_active_trampoline::<Self, F> as *const (),
36 )),
37 Box_::into_raw(f),
38 )
39 }
40 }
41}
42
43impl<O: IsA<Switch>> SwitchExtManual for O {}