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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Take a look at the license at the top of the repository in the LICENSE file.

// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`PixbufLoader`](crate::PixbufLoader).

use glib::{subclass::prelude::*, translate::*, Cast};

use crate::PixbufLoader;

pub trait PixbufLoaderImpl: ObjectImpl {
    fn size_prepared(&self, width: i32, height: i32) {
        self.parent_size_prepared(width, height)
    }

    fn area_prepared(&self) {
        self.parent_area_prepared()
    }

    fn area_updated(&self, x: i32, y: i32, width: i32, height: i32) {
        self.parent_area_updated(x, y, width, height)
    }

    fn closed(&self) {
        self.parent_closed()
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::PixbufLoaderImplExt> Sealed for T {}
}

pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass {
    fn parent_size_prepared(&self, width: i32, height: i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
            if let Some(f) = (*parent_class).size_prepared {
                f(
                    self.obj()
                        .unsafe_cast_ref::<PixbufLoader>()
                        .to_glib_none()
                        .0,
                    width,
                    height,
                )
            }
        }
    }

    fn parent_area_prepared(&self) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
            if let Some(f) = (*parent_class).area_prepared {
                f(self
                    .obj()
                    .unsafe_cast_ref::<PixbufLoader>()
                    .to_glib_none()
                    .0)
            }
        }
    }

    fn parent_area_updated(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
            if let Some(f) = (*parent_class).area_updated {
                f(
                    self.obj()
                        .unsafe_cast_ref::<PixbufLoader>()
                        .to_glib_none()
                        .0,
                    x,
                    y,
                    width,
                    height,
                )
            }
        }
    }

    fn parent_closed(&self) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
            if let Some(f) = (*parent_class).closed {
                f(self
                    .obj()
                    .unsafe_cast_ref::<PixbufLoader>()
                    .to_glib_none()
                    .0)
            }
        }
    }
}

impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T {}

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

        let klass = class.as_mut();
        klass.size_prepared = Some(loader_size_prepared::<T>);
        klass.area_prepared = Some(loader_area_prepared::<T>);
        klass.area_updated = Some(loader_area_updated::<T>);
        klass.closed = Some(loader_closed::<T>);
    }
}

unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
    ptr: *mut ffi::GdkPixbufLoader,
    width: i32,
    height: i32,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.size_prepared(width, height)
}

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

    imp.area_prepared();
}

unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
    ptr: *mut ffi::GdkPixbufLoader,
    x: i32,
    y: i32,
    width: i32,
    height: i32,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.area_updated(x, y, width, height)
}

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

    imp.closed()
}