gdk_pixbuf/subclass/
pixbuf_loader.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3// rustdoc-stripper-ignore-next
4//! Traits intended for subclassing [`PixbufLoader`].
5
6use glib::{prelude::*, subclass::prelude::*, translate::*};
7
8use crate::{ffi, PixbufLoader};
9
10pub trait PixbufLoaderImpl: ObjectImpl {
11    fn size_prepared(&self, width: i32, height: i32) {
12        self.parent_size_prepared(width, height)
13    }
14
15    fn area_prepared(&self) {
16        self.parent_area_prepared()
17    }
18
19    fn area_updated(&self, x: i32, y: i32, width: i32, height: i32) {
20        self.parent_area_updated(x, y, width, height)
21    }
22
23    fn closed(&self) {
24        self.parent_closed()
25    }
26}
27
28mod sealed {
29    pub trait Sealed {}
30    impl<T: super::PixbufLoaderImplExt> Sealed for T {}
31}
32
33pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass {
34    fn parent_size_prepared(&self, width: i32, height: i32) {
35        unsafe {
36            let data = Self::type_data();
37            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
38            if let Some(f) = (*parent_class).size_prepared {
39                f(
40                    self.obj()
41                        .unsafe_cast_ref::<PixbufLoader>()
42                        .to_glib_none()
43                        .0,
44                    width,
45                    height,
46                )
47            }
48        }
49    }
50
51    fn parent_area_prepared(&self) {
52        unsafe {
53            let data = Self::type_data();
54            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
55            if let Some(f) = (*parent_class).area_prepared {
56                f(self
57                    .obj()
58                    .unsafe_cast_ref::<PixbufLoader>()
59                    .to_glib_none()
60                    .0)
61            }
62        }
63    }
64
65    fn parent_area_updated(&self, x: i32, y: i32, width: i32, height: i32) {
66        unsafe {
67            let data = Self::type_data();
68            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
69            if let Some(f) = (*parent_class).area_updated {
70                f(
71                    self.obj()
72                        .unsafe_cast_ref::<PixbufLoader>()
73                        .to_glib_none()
74                        .0,
75                    x,
76                    y,
77                    width,
78                    height,
79                )
80            }
81        }
82    }
83
84    fn parent_closed(&self) {
85        unsafe {
86            let data = Self::type_data();
87            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
88            if let Some(f) = (*parent_class).closed {
89                f(self
90                    .obj()
91                    .unsafe_cast_ref::<PixbufLoader>()
92                    .to_glib_none()
93                    .0)
94            }
95        }
96    }
97}
98
99impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T {}
100
101unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader {
102    fn class_init(class: &mut ::glib::Class<Self>) {
103        Self::parent_class_init::<T>(class);
104
105        let klass = class.as_mut();
106        klass.size_prepared = Some(loader_size_prepared::<T>);
107        klass.area_prepared = Some(loader_area_prepared::<T>);
108        klass.area_updated = Some(loader_area_updated::<T>);
109        klass.closed = Some(loader_closed::<T>);
110    }
111}
112
113unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
114    ptr: *mut ffi::GdkPixbufLoader,
115    width: i32,
116    height: i32,
117) {
118    let instance = &*(ptr as *mut T::Instance);
119    let imp = instance.imp();
120
121    imp.size_prepared(width, height)
122}
123
124unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
125    let instance = &*(ptr as *mut T::Instance);
126    let imp = instance.imp();
127
128    imp.area_prepared();
129}
130
131unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
132    ptr: *mut ffi::GdkPixbufLoader,
133    x: i32,
134    y: i32,
135    width: i32,
136    height: i32,
137) {
138    let instance = &*(ptr as *mut T::Instance);
139    let imp = instance.imp();
140
141    imp.area_updated(x, y, width, height)
142}
143
144unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
145    let instance = &*(ptr as *mut T::Instance);
146    let imp = instance.imp();
147
148    imp.closed()
149}