1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::Fuse;
use glib::{subclass::prelude::*, translate::ToGlibPtr};

pub trait FuseImpl: ObjectImpl {
    fn get_widget(&self) -> gtk::Widget;
    /// <para>Called when the Fuse appears to the user.</para>
    fn shown(&self);
    /// <para>Called when the Fuse disappear to the user.</para>
    /// <para>This is not called when the Fuse got destroyed or the window is closed, use ~Fuse &lpar;&rpar; instead.</para>
    fn hidden(&self);
}

unsafe impl<T: FuseImpl> IsSubclassable<T> for Fuse {
    fn class_init(class: &mut glib::Class<Self>) {
        Self::parent_class_init::<T>(class);

        let klass = class.as_mut();
        klass.get_widget = Some(get_widget::<T>);
        klass.shown = Some(shown::<T>);
        klass.hidden = Some(hidden::<T>);
    }
}

unsafe extern "C" fn get_widget<T: FuseImpl>(
    ptr: *mut ffi::FuseboxFuse,
) -> *mut gtk::ffi::GtkWidget {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.get_widget().to_glib_full()
}

unsafe extern "C" fn shown<T: FuseImpl>(ptr: *mut ffi::FuseboxFuse) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.shown();
}

unsafe extern "C" fn hidden<T: FuseImpl>(ptr: *mut ffi::FuseboxFuse) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.hidden();
}