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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
use gtk_sys; use glib::translate::*; use glib::subclass::prelude::*; use super::widget::WidgetImpl; use Container; use ContainerClass; use Widget; use WidgetClass; use WidgetPath; pub trait ContainerImpl: ContainerImplExt + WidgetImpl + 'static { fn add(&self, container: &Container, widget: &Widget) { self.parent_add(container, widget) } fn remove(&self, container: &Container, widget: &Widget) { self.parent_remove(container, widget) } fn check_resize(&self, container: &Container) { self.parent_check_resize(container) } fn set_focus_child(&self, container: &Container, widget: Option<&Widget>) { self.parent_set_focus_child(container, widget) } fn child_type(&self, container: &Container) -> glib::Type { self.parent_child_type(container) } fn get_path_for_child(&self, container: &Container, widget: &Widget) -> WidgetPath { self.parent_get_path_for_child(container, widget) } } pub trait ContainerImplExt { fn parent_add(&self, container: &Container, widget: &Widget); fn parent_remove(&self, container: &Container, widget: &Widget); fn parent_check_resize(&self, container: &Container); fn parent_set_focus_child(&self, container: &Container, widget: Option<&Widget>); fn parent_child_type(&self, container: &Container) -> glib::Type; fn parent_get_path_for_child(&self, container: &Container, widget: &Widget) -> WidgetPath; } impl<T: ContainerImpl + ObjectImpl> ContainerImplExt for T { fn parent_add(&self, container: &Container, widget: &Widget) { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; if let Some(f) = (*parent_class).add { f(container.to_glib_none().0, widget.to_glib_none().0) } } } fn parent_remove(&self, container: &Container, widget: &Widget) { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; if let Some(f) = (*parent_class).remove { f(container.to_glib_none().0, widget.to_glib_none().0) } } } fn parent_check_resize(&self, container: &Container) { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; if let Some(f) = (*parent_class).check_resize { f(container.to_glib_none().0) } } } fn parent_set_focus_child(&self, container: &Container, widget: Option<&Widget>) { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; if let Some(f) = (*parent_class).set_focus_child { f(container.to_glib_none().0, widget.to_glib_none().0) } } } fn parent_child_type(&self, container: &Container) -> glib::Type { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; if let Some(f) = (*parent_class).child_type { from_glib(f(container.to_glib_none().0)) } else { glib::Type::Unit } } } fn parent_get_path_for_child(&self, container: &Container, widget: &Widget) -> WidgetPath { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkContainerClass; let f = (*parent_class) .get_path_for_child .expect("No parent class impl for \"get_path_for_child\""); from_glib_none(f(container.to_glib_none().0, widget.to_glib_none().0)) } } } unsafe impl<T: ObjectSubclass + ContainerImpl> IsSubclassable<T> for ContainerClass { fn override_vfuncs(&mut self) { <WidgetClass as IsSubclassable<T>>::override_vfuncs(self); unsafe { let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkContainerClass); klass.add = Some(container_add::<T>); klass.remove = Some(container_remove::<T>); klass.check_resize = Some(container_check_resize::<T>); klass.set_focus_child = Some(container_set_focus_child::<T>); klass.child_type = Some(container_child_type::<T>); klass.get_path_for_child = Some(container_get_path_for_child::<T>); } } } unsafe extern "C" fn container_add<T: ObjectSubclass>( ptr: *mut gtk_sys::GtkContainer, wdgtptr: *mut gtk_sys::GtkWidget, ) where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr); imp.add(&wrap, &widget) } unsafe extern "C" fn container_remove<T: ObjectSubclass>( ptr: *mut gtk_sys::GtkContainer, wdgtptr: *mut gtk_sys::GtkWidget, ) where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr); imp.remove(&wrap, &widget) } unsafe extern "C" fn container_check_resize<T: ObjectSubclass>(ptr: *mut gtk_sys::GtkContainer) where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); imp.check_resize(&wrap) } unsafe extern "C" fn container_set_focus_child<T: ObjectSubclass>( ptr: *mut gtk_sys::GtkContainer, wdgtptr: *mut gtk_sys::GtkWidget, ) where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); let widget: Borrowed<Option<Widget>> = from_glib_borrow(wdgtptr); imp.set_focus_child(&wrap, widget.as_ref().as_ref()) } unsafe extern "C" fn container_child_type<T: ObjectSubclass>( ptr: *mut gtk_sys::GtkContainer, ) -> glib_sys::GType where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); imp.child_type(&wrap).to_glib() } unsafe extern "C" fn container_get_path_for_child<T: ObjectSubclass>( ptr: *mut gtk_sys::GtkContainer, wdgtptr: *mut gtk_sys::GtkWidget, ) -> *mut gtk_sys::GtkWidgetPath where T: ContainerImpl, { let instance = &*(ptr as *mut T::Instance); let imp = instance.get_impl(); let wrap: Borrowed<Container> = from_glib_borrow(ptr); let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr); imp.get_path_for_child(&wrap, &widget).to_glib_none().0 }