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::{PixbufLoader, ffi};
9
10pub trait PixbufLoaderImpl: ObjectImpl + ObjectSubclass<Type: IsA<PixbufLoader>> {
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
28pub trait PixbufLoaderImplExt: PixbufLoaderImpl {
29    fn parent_size_prepared(&self, width: i32, height: i32) {
30        unsafe {
31            let data = Self::type_data();
32            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
33            if let Some(f) = (*parent_class).size_prepared {
34                f(
35                    self.obj()
36                        .unsafe_cast_ref::<PixbufLoader>()
37                        .to_glib_none()
38                        .0,
39                    width,
40                    height,
41                )
42            }
43        }
44    }
45
46    fn parent_area_prepared(&self) {
47        unsafe {
48            let data = Self::type_data();
49            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
50            if let Some(f) = (*parent_class).area_prepared {
51                f(self
52                    .obj()
53                    .unsafe_cast_ref::<PixbufLoader>()
54                    .to_glib_none()
55                    .0)
56            }
57        }
58    }
59
60    fn parent_area_updated(&self, x: i32, y: i32, width: i32, height: i32) {
61        unsafe {
62            let data = Self::type_data();
63            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
64            if let Some(f) = (*parent_class).area_updated {
65                f(
66                    self.obj()
67                        .unsafe_cast_ref::<PixbufLoader>()
68                        .to_glib_none()
69                        .0,
70                    x,
71                    y,
72                    width,
73                    height,
74                )
75            }
76        }
77    }
78
79    fn parent_closed(&self) {
80        unsafe {
81            let data = Self::type_data();
82            let parent_class = data.as_ref().parent_class() as *mut ffi::GdkPixbufLoaderClass;
83            if let Some(f) = (*parent_class).closed {
84                f(self
85                    .obj()
86                    .unsafe_cast_ref::<PixbufLoader>()
87                    .to_glib_none()
88                    .0)
89            }
90        }
91    }
92}
93
94impl<T: PixbufLoaderImpl> PixbufLoaderImplExt for T {}
95
96unsafe impl<T: PixbufLoaderImpl> IsSubclassable<T> for PixbufLoader {
97    fn class_init(class: &mut ::glib::Class<Self>) {
98        Self::parent_class_init::<T>(class);
99
100        let klass = class.as_mut();
101        klass.size_prepared = Some(loader_size_prepared::<T>);
102        klass.area_prepared = Some(loader_area_prepared::<T>);
103        klass.area_updated = Some(loader_area_updated::<T>);
104        klass.closed = Some(loader_closed::<T>);
105    }
106}
107
108unsafe extern "C" fn loader_size_prepared<T: PixbufLoaderImpl>(
109    ptr: *mut ffi::GdkPixbufLoader,
110    width: i32,
111    height: i32,
112) {
113    unsafe {
114        let instance = &*(ptr as *mut T::Instance);
115        let imp = instance.imp();
116
117        imp.size_prepared(width, height)
118    }
119}
120
121unsafe extern "C" fn loader_area_prepared<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
122    unsafe {
123        let instance = &*(ptr as *mut T::Instance);
124        let imp = instance.imp();
125
126        imp.area_prepared();
127    }
128}
129
130unsafe extern "C" fn loader_area_updated<T: PixbufLoaderImpl>(
131    ptr: *mut ffi::GdkPixbufLoader,
132    x: i32,
133    y: i32,
134    width: i32,
135    height: i32,
136) {
137    unsafe {
138        let instance = &*(ptr as *mut T::Instance);
139        let imp = instance.imp();
140
141        imp.area_updated(x, y, width, height)
142    }
143}
144
145unsafe extern "C" fn loader_closed<T: PixbufLoaderImpl>(ptr: *mut ffi::GdkPixbufLoader) {
146    unsafe {
147        let instance = &*(ptr as *mut T::Instance);
148        let imp = instance.imp();
149
150        imp.closed()
151    }
152}