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