|
| 1 | +use gtk_sys; |
| 2 | + |
| 3 | +use glib::subclass::prelude::*; |
| 4 | +use glib::translate::*; |
| 5 | +use glib::Cast; |
| 6 | + |
| 7 | +use super::widget::WidgetImpl; |
| 8 | +use DrawingArea; |
| 9 | +use Widget; |
| 10 | + |
| 11 | +pub trait DrawingAreaImpl: DrawingAreaImplExt + WidgetImpl { |
| 12 | + fn resize(&self, drawing_area: &Self::Type, width: i32, height: i32) { |
| 13 | + self.parent_resize(drawing_area, width, height) |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +pub trait DrawingAreaImplExt: ObjectSubclass { |
| 18 | + fn parent_resize(&self, drawing_area: &Self::Type, width: i32, height: i32); |
| 19 | +} |
| 20 | + |
| 21 | +impl<T: DrawingAreaImpl> DrawingAreaImplExt for T { |
| 22 | + fn parent_resize(&self, drawing_area: &Self::Type, width: i32, height: i32) { |
| 23 | + unsafe { |
| 24 | + let data = T::type_data(); |
| 25 | + let parent_class = |
| 26 | + data.as_ref().get_parent_class() as *mut gtk_sys::GtkDrawingAreaClass; |
| 27 | + let f = (*parent_class) |
| 28 | + .resize |
| 29 | + .expect("No parent class impl for \"resize\""); |
| 30 | + f( |
| 31 | + drawing_area |
| 32 | + .unsafe_cast_ref::<DrawingArea>() |
| 33 | + .to_glib_none() |
| 34 | + .0, |
| 35 | + width, |
| 36 | + height, |
| 37 | + ) |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +unsafe impl<T: DrawingAreaImpl> IsSubclassable<T> for DrawingArea { |
| 43 | + fn override_vfuncs(class: &mut glib::Class<Self>) { |
| 44 | + <Widget as IsSubclassable<T>>::override_vfuncs(class); |
| 45 | + |
| 46 | + let klass = class.as_mut(); |
| 47 | + klass.resize = Some(drawing_area_resize::<T>); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +unsafe extern "C" fn drawing_area_resize<T: DrawingAreaImpl>( |
| 52 | + ptr: *mut gtk_sys::GtkDrawingArea, |
| 53 | + width: i32, |
| 54 | + height: i32, |
| 55 | +) { |
| 56 | + let instance = &*(ptr as *mut T::Instance); |
| 57 | + let imp = instance.get_impl(); |
| 58 | + let wrap: Borrowed<DrawingArea> = from_glib_borrow(ptr); |
| 59 | + |
| 60 | + imp.resize(wrap.unsafe_cast_ref(), width, height) |
| 61 | +} |
0 commit comments