Skip to main content

gtk/subclass/
list_box_row.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ListBoxRow;
4
5use glib::subclass::prelude::*;
6use glib::translate::*;
7use glib::Cast;
8
9use super::bin::BinImpl;
10
11pub trait ListBoxRowImpl: ListBoxRowImplExt + BinImpl {
12    fn activate(&self) {
13        self.parent_activate()
14    }
15}
16
17mod sealed {
18    pub trait Sealed {}
19    impl<T: super::ListBoxRowImpl> Sealed for T {}
20}
21
22pub trait ListBoxRowImplExt: ObjectSubclass + sealed::Sealed {
23    fn parent_activate(&self) {
24        unsafe {
25            let data = Self::type_data();
26            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkListBoxRowClass;
27            if let Some(f) = (*parent_class).activate {
28                f(self.obj().unsafe_cast_ref::<ListBoxRow>().to_glib_none().0)
29            }
30        }
31    }
32}
33
34impl<T: ListBoxRowImpl> ListBoxRowImplExt for T {}
35
36unsafe impl<T: ListBoxRowImpl> IsSubclassable<T> for ListBoxRow {
37    fn class_init(class: &mut ::glib::Class<Self>) {
38        Self::parent_class_init::<T>(class);
39
40        if !crate::rt::is_initialized() {
41            panic!("GTK has to be initialized first");
42        }
43
44        let klass = class.as_mut();
45        klass.activate = Some(list_box_row_activate::<T>);
46    }
47}
48
49unsafe extern "C" fn list_box_row_activate<T: ListBoxRowImpl>(ptr: *mut ffi::GtkListBoxRow) {
50    let instance = &*(ptr as *mut T::Instance);
51    let imp = instance.imp();
52
53    imp.activate()
54}