diff --git a/examples/src/bin/basic_subclass.rs b/examples/src/bin/basic_subclass.rs index e2c0244312f5..ce2a43418879 100644 --- a/examples/src/bin/basic_subclass.rs +++ b/examples/src/bin/basic_subclass.rs @@ -113,7 +113,7 @@ mod imp_win { } glib_wrapper! { - pub struct SimpleWindow(ObjectSubclass) + pub struct SimpleWindow(ObjectSubclass) @extends gtk::Widget, gtk::Container, gtk::Bin, gtk::Window, gtk::ApplicationWindow; } diff --git a/examples/src/bin/listbox_model.rs b/examples/src/bin/listbox_model.rs index 33a669635ba1..075c2dc5a32f 100644 --- a/examples/src/bin/listbox_model.rs +++ b/examples/src/bin/listbox_model.rs @@ -319,7 +319,7 @@ mod row_data { // Public part of the RowData type. This behaves like a normal gtk-rs-style GObject // binding glib_wrapper! { - pub struct RowData(ObjectSubclass); + pub struct RowData(ObjectSubclass); } // Constructor for new instances. This simply calls glib::Object::new() with diff --git a/gio/src/subclass/application.rs b/gio/src/subclass/application.rs index 53ec1bb1e00b..da41fb5b847b 100644 --- a/gio/src/subclass/application.rs +++ b/gio/src/subclass/application.rs @@ -303,11 +303,11 @@ impl ApplicationImplExt for T { } } -unsafe impl IsSubclassable for ApplicationClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Application { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gio_sys::GApplicationClass); + let klass = &mut *(class.as_mut() as *mut gio_sys::GApplicationClass); klass.activate = Some(application_activate::); klass.after_emit = Some(application_after_emit::); klass.before_emit = Some(application_before_emit::); diff --git a/gio/src/subclass/input_stream.rs b/gio/src/subclass/input_stream.rs index 5f75d45168ef..bf035fa43180 100644 --- a/gio/src/subclass/input_stream.rs +++ b/gio/src/subclass/input_stream.rs @@ -151,11 +151,11 @@ impl InputStreamImplExt for T { } } -unsafe impl IsSubclassable for InputStreamClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for InputStream { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gio_sys::GInputStreamClass); + let klass = &mut *(class.as_mut() as *mut gio_sys::GInputStreamClass); klass.read_fn = Some(stream_read::); klass.close_fn = Some(stream_close::); klass.skip = Some(stream_skip::); diff --git a/gio/src/subclass/io_stream.rs b/gio/src/subclass/io_stream.rs index 3e6ad4ca1662..4c75ec259288 100644 --- a/gio/src/subclass/io_stream.rs +++ b/gio/src/subclass/io_stream.rs @@ -95,11 +95,11 @@ impl IOStreamImplExt for T { } } -unsafe impl IsSubclassable for IOStreamClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for IOStream { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gio_sys::GIOStreamClass); + let klass = &mut *(class.as_mut() as *mut gio_sys::GIOStreamClass); klass.get_input_stream = Some(stream_get_input_stream::); klass.get_output_stream = Some(stream_get_output_stream::); klass.close_fn = Some(stream_close::); diff --git a/gio/src/subclass/output_stream.rs b/gio/src/subclass/output_stream.rs index d6cddda9ca8a..8588338fd62a 100644 --- a/gio/src/subclass/output_stream.rs +++ b/gio/src/subclass/output_stream.rs @@ -191,11 +191,11 @@ impl OutputStreamImplExt for T { } } -unsafe impl IsSubclassable for OutputStreamClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for OutputStream { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gio_sys::GOutputStreamClass); + let klass = &mut *(class.as_mut() as *mut gio_sys::GOutputStreamClass); klass.write_fn = Some(stream_write::); klass.close_fn = Some(stream_close::); klass.flush = Some(stream_flush::); diff --git a/glib/src/lib.rs b/glib/src/lib.rs index adf943ffd03f..6a760ee9cf93 100644 --- a/glib/src/lib.rs +++ b/glib/src/lib.rs @@ -104,8 +104,8 @@ pub use closure::Closure; pub use error::{BoolError, Error}; pub use file_error::FileError; pub use object::{ - Cast, InitiallyUnowned, InitiallyUnownedClass, IsA, IsClassFor, Object, ObjectClass, ObjectExt, - ObjectType, SendWeakRef, WeakRef, + Cast, InitiallyUnowned, InitiallyUnownedClass, IsA, Object, ObjectClass, ObjectExt, ObjectType, + SendWeakRef, WeakRef, }; pub use signal::{ signal_handler_block, signal_handler_disconnect, signal_handler_unblock, diff --git a/glib/src/object.rs b/glib/src/object.rs index 352315ef21d9..74ca5a18ea78 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -52,8 +52,6 @@ pub unsafe trait ObjectType: type GlibType: 'static; /// type of the FFI Class structure. type GlibClassType: 'static; - /// type of the Rust Class structure. - type RustClassType: 'static; fn as_object_ref(&self) -> &ObjectRef; fn as_ptr(&self) -> *mut Self::GlibType; @@ -83,108 +81,18 @@ pub trait UnsafeFrom { /// implementations exist. pub unsafe trait IsA: ObjectType + AsRef + 'static {} -/// Trait for mapping a class struct type to its corresponding instance type. -pub unsafe trait IsClassFor: Sized + 'static { - /// Corresponding Rust instance type for this class. - type Instance: ObjectType; - - /// Get the type id for this class. - fn get_type(&self) -> Type { - unsafe { - let klass = self as *const _ as *const gobject_sys::GTypeClass; - from_glib((*klass).g_type) - } - } - - /// Casts this class to a reference to a parent type's class. - fn upcast_ref(&self) -> &U - where - Self::Instance: IsA, - U::Instance: ObjectType, - { - unsafe { - let klass = self as *const _ as *const U; - &*klass - } - } - - /// Casts this class to a mutable reference to a parent type's class. - fn upcast_ref_mut(&mut self) -> &mut U - where - Self::Instance: IsA, - U::Instance: ObjectType, - { - unsafe { - let klass = self as *mut _ as *mut U; - &mut *klass - } - } - - /// Casts this class to a reference to a child type's class or - /// fails if this class is not implementing the child class. - fn downcast_ref(&self) -> Option<&U> - where - U::Instance: IsA, - Self::Instance: ObjectType, - { - if !self.get_type().is_a(&U::Instance::static_type()) { - return None; - } - - unsafe { - let klass = self as *const _ as *const U; - Some(&*klass) - } - } - - /// Casts this class to a mutable reference to a child type's class or - /// fails if this class is not implementing the child class. - fn downcast_ref_mut(&mut self) -> Option<&mut U> - where - U::Instance: IsA, - Self::Instance: ObjectType, - { - if !self.get_type().is_a(&U::Instance::static_type()) { - return None; - } - - unsafe { - let klass = self as *mut _ as *mut U; - Some(&mut *klass) - } - } - - /// Gets the class struct corresponding to `type_`. - /// - /// This will return `None` if `type_` is not a subclass of `Self`. - fn from_type(type_: Type) -> Option> { - if !type_.is_a(&Self::Instance::static_type()) { - return None; - } - - unsafe { - let ptr = gobject_sys::g_type_class_ref(type_.to_glib()); - if ptr.is_null() { - None - } else { - Some(ClassRef(ptr::NonNull::new_unchecked(ptr as *mut Self))) - } - } - } -} - #[derive(Debug)] -pub struct ClassRef(ptr::NonNull); +pub struct ClassRef(ptr::NonNull>); -impl ops::Deref for ClassRef { - type Target = T; +impl ops::Deref for ClassRef { + type Target = Class; - fn deref(&self) -> &T { + fn deref(&self) -> &Class { unsafe { self.0.as_ref() } } } -impl Drop for ClassRef { +impl Drop for ClassRef { fn drop(&mut self) { unsafe { gobject_sys::g_type_class_unref(self.0.as_ptr() as *mut _); @@ -192,8 +100,8 @@ impl Drop for ClassRef { } } -unsafe impl Send for ClassRef {} -unsafe impl Sync for ClassRef {} +unsafe impl Send for ClassRef {} +unsafe impl Sync for ClassRef {} /// Upcasting and downcasting support. /// @@ -721,7 +629,7 @@ macro_rules! glib_weak_impl { /// ObjectType implementations for Object types. See `glib_wrapper!`. #[macro_export] macro_rules! glib_object_wrapper { - (@generic_impl [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ty, @get_type $get_type_expr:expr) => { + (@generic_impl [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, @get_type $get_type_expr:expr) => { $(#[$attr])* // Always derive Hash/Ord (and below impl Debug, PartialEq, Eq, PartialOrd) for object // types. Due to inheritance and up/downcasting we must implement these by pointer or @@ -754,7 +662,6 @@ macro_rules! glib_object_wrapper { unsafe impl $crate::object::ObjectType for $name { type GlibType = $ffi_name; type GlibClassType = $ffi_class_name; - type RustClassType = $rust_class_name; fn as_object_ref(&self) -> &$crate::object::ObjectRef { &self.0 @@ -1109,92 +1016,43 @@ macro_rules! glib_object_wrapper { }; // If there is no parent class, i.e. only glib::Object - (@munch_first_impl $name:ident, $rust_class_name:ident, ) => { + (@munch_first_impl $name:ident, ) => { $crate::glib_object_wrapper!(@munch_impls $name, ); - - impl ::std::ops::Deref for $rust_class_name { - type Target = <$crate::object::Object as $crate::object::ObjectType>::RustClassType; - - fn deref(&self) -> &Self::Target { - $crate::object::IsClassFor::upcast_ref(self) - } - } - - impl ::std::ops::DerefMut for $rust_class_name { - fn deref_mut(&mut self) -> &mut Self::Target { - $crate::object::IsClassFor::upcast_ref_mut(self) - } + unsafe impl $crate::object::ParentClassIs for $name { + type Parent = $crate::object::Object; } }; // If there is only one parent class - (@munch_first_impl $name:ident, $rust_class_name:ident, $super_name:path) => { + (@munch_first_impl $name:ident, $super_name:path) => { $crate::glib_object_wrapper!(@munch_impls $name, $super_name); - - impl ::std::ops::Deref for $rust_class_name { - type Target = <$super_name as $crate::object::ObjectType>::RustClassType; - - fn deref(&self) -> &Self::Target { - $crate::object::IsClassFor::upcast_ref(self) - } - } - - impl ::std::ops::DerefMut for $rust_class_name { - fn deref_mut(&mut self) -> &mut Self::Target { - $crate::object::IsClassFor::upcast_ref_mut(self) - } + unsafe impl $crate::object::ParentClassIs for $name { + type Parent = $super_name; } }; // If there is more than one parent class - (@munch_first_impl $name:ident, $rust_class_name:ident, $super_name:path, $($implements:tt)*) => { + (@munch_first_impl $name:ident, $super_name:path, $($implements:tt)*) => { $crate::glib_object_wrapper!(@munch_impls $name, $super_name); - - impl ::std::ops::Deref for $rust_class_name { - type Target = <$super_name as $crate::object::ObjectType>::RustClassType; - - fn deref(&self) -> &Self::Target { - $crate::object::IsClassFor::upcast_ref(self) - } - } - - impl ::std::ops::DerefMut for $rust_class_name { - fn deref_mut(&mut self) -> &mut Self::Target { - $crate::object::IsClassFor::upcast_ref_mut(self) - } + unsafe impl $crate::object::ParentClassIs for $name { + type Parent = $super_name; } - $crate::glib_object_wrapper!(@munch_impls $name, $($implements)*); }; - (@class_impl $name:ident, $ffi_class_name:ty, $rust_class_name:ident) => { - #[repr(transparent)] - #[derive(Debug)] - pub struct $rust_class_name($ffi_class_name); - - unsafe impl $crate::object::IsClassFor for $rust_class_name { - type Instance = $name; - } - - unsafe impl Send for $rust_class_name { } - unsafe impl Sync for $rust_class_name { } - }; - // This case is only for glib::Object itself below. All other cases have glib::Object in its // parent class list - (@object [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident, @get_type $get_type_expr:expr) => { - $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, + (@object [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, @get_type $get_type_expr:expr) => { + $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr); - $crate::glib_object_wrapper!(@class_impl $name, $ffi_class_name, $rust_class_name); }; - (@object [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident, + (@object [$($attr:meta)*] $name:ident, $ffi_name:ty, $ffi_class_name:ty, @get_type $get_type_expr:expr, @extends [$($extends:tt)*], @implements [$($implements:tt)*]) => { - $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, + $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr); - $crate::glib_object_wrapper!(@munch_first_impl $name, $rust_class_name, $($extends)*); + $crate::glib_object_wrapper!(@munch_first_impl $name, $($extends)*); $crate::glib_object_wrapper!(@munch_impls $name, $($implements)*); - $crate::glib_object_wrapper!(@class_impl $name, $ffi_class_name, $rust_class_name); #[doc(hidden)] impl AsRef<$crate::object::Object> for $name { @@ -1208,7 +1066,7 @@ macro_rules! glib_object_wrapper { }; (@interface [$($attr:meta)*] $name:ident, $ffi_name:ty, @get_type $get_type_expr:expr, @requires [$($requires:tt)*]) => { - $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, (), (), + $crate::glib_object_wrapper!(@generic_impl [$($attr)*] $name, $ffi_name, (), @get_type $get_type_expr); $crate::glib_object_wrapper!(@munch_impls $name, $($requires)*); @@ -1226,8 +1084,9 @@ macro_rules! glib_object_wrapper { glib_object_wrapper!(@object [doc = "The base class in the object hierarchy."] - Object, GObject, GObjectClass, ObjectClass, @get_type gobject_sys::g_object_get_type() + Object, GObject, GObjectClass, @get_type gobject_sys::g_object_get_type() ); +pub type ObjectClass = Class; impl Object { pub fn new(type_: Type, properties: &[(&str, &dyn ToValue)]) -> Result { @@ -2570,3 +2429,128 @@ impl<'a> BindingBuilder<'a> { } } } + +#[repr(transparent)] +pub struct Class(T::GlibClassType); + +impl Class { + /// Get the type id for this class. + pub fn get_type(&self) -> Type { + unsafe { + let klass = self as *const _ as *const gobject_sys::GTypeClass; + from_glib((*klass).g_type) + } + } + + /// Casts this class to a reference to a parent type's class. + pub fn upcast_ref(&self) -> &Class + where + T: IsA, + { + unsafe { + let klass = self as *const _ as *const Class; + &*klass + } + } + + /// Casts this class to a mutable reference to a parent type's class. + pub fn upcast_ref_mut(&mut self) -> &mut Class + where + T: IsA, + { + unsafe { + let klass = self as *mut _ as *mut Class; + &mut *klass + } + } + + /// Casts this class to a reference to a child type's class or + /// fails if this class is not implementing the child class. + pub fn downcast_ref(&self) -> Option<&Class> + where + U: IsA, + { + if !self.get_type().is_a(&U::static_type()) { + return None; + } + + unsafe { + let klass = self as *const _ as *const Class; + Some(&*klass) + } + } + + /// Casts this class to a mutable reference to a child type's class or + /// fails if this class is not implementing the child class. + pub fn downcast_ref_mut(&mut self) -> Option<&mut Class> + where + U: IsA, + { + if !self.get_type().is_a(&U::static_type()) { + return None; + } + + unsafe { + let klass = self as *mut _ as *mut Class; + Some(&mut *klass) + } + } + + /// Gets the class struct corresponding to `type_`. + /// + /// This will return `None` if `type_` is not a subclass of `Self`. + pub fn from_type(type_: Type) -> Option> { + if !type_.is_a(&T::static_type()) { + return None; + } + + unsafe { + let ptr = gobject_sys::g_type_class_ref(type_.to_glib()); + if ptr.is_null() { + None + } else { + Some(ClassRef(ptr::NonNull::new_unchecked(ptr as *mut Self))) + } + } + } +} + +unsafe impl Send for Class {} +unsafe impl Sync for Class {} + +impl AsRef for Class { + fn as_ref(&self) -> &T::GlibClassType { + &self.0 + } +} + +impl AsMut for Class { + fn as_mut(&mut self) -> &mut T::GlibClassType { + &mut self.0 + } +} + +// This should require Self: IsA, but that seems to cause a cycle error +pub unsafe trait ParentClassIs: ObjectType { + type Parent: ObjectType; +} + +impl ops::Deref for Class { + type Target = Class; + + fn deref(&self) -> &Self::Target { + unsafe { + let klass = self as *const _ as *const Self::Target; + &*klass + } + } +} + +impl ops::DerefMut for Class { + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { + let klass = self as *mut _ as *mut Self::Target; + &mut *klass + } + } +} diff --git a/glib/src/prelude.rs b/glib/src/prelude.rs index 1a293f28529e..953dd937b6ee 100644 --- a/glib/src/prelude.rs +++ b/glib/src/prelude.rs @@ -1,6 +1,6 @@ //! Traits and essential types intended for blanket imports. pub use { - Cast, Continue, IsA, IsClassFor, ObjectExt, ObjectType, ParamSpecType, StaticType, - StaticVariantType, ToSendValue, ToValue, ToVariant, + Cast, Continue, IsA, ObjectExt, ObjectType, ParamSpecType, StaticType, StaticVariantType, + ToSendValue, ToValue, ToVariant, }; diff --git a/glib/src/subclass/mod.rs b/glib/src/subclass/mod.rs index 9679a9b3f16d..012f631fd397 100644 --- a/glib/src/subclass/mod.rs +++ b/glib/src/subclass/mod.rs @@ -195,7 +195,7 @@ //! //! // Optionally, define a wrapper type to make it more ergonomic to use from Rust //! glib_wrapper! { -//! pub struct SimpleObject(ObjectSubclass); +//! pub struct SimpleObject(ObjectSubclass); //! } //! //! impl SimpleObject { diff --git a/glib/src/subclass/object.rs b/glib/src/subclass/object.rs index 45cd61f9bf5d..d1412cbea77b 100644 --- a/glib/src/subclass/object.rs +++ b/glib/src/subclass/object.rs @@ -269,10 +269,10 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static { unsafe impl ObjectClassSubclassExt for ObjectClass {} -unsafe impl IsSubclassable for ObjectClass { - fn override_vfuncs(&mut self) { +unsafe impl IsSubclassable for Object { + fn override_vfuncs(class: &mut ::object::Class) { unsafe { - let klass = &mut *(self as *mut Self as *mut gobject_sys::GObjectClass); + let klass = &mut *(class.as_mut() as *mut gobject_sys::GObjectClass); klass.set_property = Some(set_property::); klass.get_property = Some(get_property::); klass.constructed = Some(constructed::); diff --git a/glib/src/subclass/simple.rs b/glib/src/subclass/simple.rs index 556d5bdc072f..b5f99f18ccb1 100644 --- a/glib/src/subclass/simple.rs +++ b/glib/src/subclass/simple.rs @@ -56,7 +56,7 @@ unsafe impl super::types::ClassStruct for ClassStruct { } impl ops::Deref for ClassStruct { - type Target = <::ParentType as ObjectType>::RustClassType; + type Target = ::object::Class<::ParentType>; fn deref(&self) -> &Self::Target { unsafe { &*(self as *const _ as *const Self::Target) } diff --git a/glib/src/subclass/types.rs b/glib/src/subclass/types.rs index ae6e0e18eafb..16ec2f19ab45 100644 --- a/glib/src/subclass/types.rs +++ b/glib/src/subclass/types.rs @@ -12,7 +12,7 @@ use std::marker; use std::mem; use std::ptr; use translate::*; -use {Closure, IsA, IsClassFor, SignalFlags, StaticType, Type, Value}; +use {Closure, IsA, SignalFlags, StaticType, Type, Value}; /// A newly registered `glib::Type` that is currently still being initialized. /// @@ -102,23 +102,22 @@ pub unsafe trait ClassStruct: Sized + 'static { /// This is automatically called during type initialization. fn override_vfuncs(&mut self) where - <::ParentType as ObjectType>::RustClassType: - IsSubclassable, + ::ParentType: IsSubclassable, { unsafe { let base = &mut *(self as *mut _ - as *mut <::ParentType as ObjectType>::RustClassType); - base.override_vfuncs(); + as *mut ::object::Class<::ParentType>); + <::ParentType as IsSubclassable>::override_vfuncs(base); } } } /// Trait for subclassable class structs. -pub unsafe trait IsSubclassable: IsClassFor { +pub unsafe trait IsSubclassable: ObjectType { /// Override the virtual methods of this class for the given subclass. /// /// This is automatically called during type initialization. - fn override_vfuncs(&mut self); + fn override_vfuncs(class: &mut ::object::Class); } /// Trait for implementable interfaces. @@ -379,7 +378,7 @@ unsafe extern "C" fn class_init( klass: glib_sys::gpointer, _klass_data: glib_sys::gpointer, ) where - <::ParentType as ObjectType>::RustClassType: IsSubclassable, + ::ParentType: IsSubclassable, { let mut data = T::type_data(); @@ -460,7 +459,7 @@ unsafe extern "C" fn finalize(obj: *mut gobject_sys::GObject) /// [`glib_object_subclass!`]: ../../macro.glib_object_subclass.html pub fn register_type() -> Type where - <::ParentType as ObjectType>::RustClassType: IsSubclassable, + ::ParentType: IsSubclassable, { // GLib aligns the type private data to two gsizes so we can't safely store any type there that // requires a bigger alignment. diff --git a/glib/src/wrapper.rs b/glib/src/wrapper.rs index ceebbb79c689..c5e7d5f6f316 100644 --- a/glib/src/wrapper.rs +++ b/glib/src/wrapper.rs @@ -329,144 +329,156 @@ macro_rules! glib_wrapper { // Object, no class struct, no parents or interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $rust_class_name:ident>); + pub struct $name:ident(Object<$ffi_name:ty $(, $rust_class_name:ident)?>); match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, $rust_class_name, @get_type $get_type_expr, @extends [], @implements []); + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, @get_type $get_type_expr, @extends [], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, class struct, no parents or interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident>); + pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty $(, $rust_class_name:ident)?>); match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, @get_type $get_type_expr, @extends [], @implements []); + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr, @extends [], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, no class struct, parents, no interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $rust_class_name:ident>) @extends $($extends:path),+; + pub struct $name:ident(Object<$ffi_name:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, @get_type $get_type_expr, @extends [$($extends),+], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, class struct, parents, no interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident>) @extends $($extends:path),+; + pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr, @extends [$($extends),+], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, no class struct, no parents, interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $rust_class_name:ident>) @implements $($implements:path),+; + pub struct $name:ident(Object<$ffi_name:ty $(, $rust_class_name:ident)?>) @implements $($implements:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, @get_type $get_type_expr, @extends [], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, class struct, no parents, interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident>) @implements $($implements:path),+; + pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty $(, $rust_class_name:ident)?>) @implements $($implements:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr, @extends [], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, no class struct, parents and interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $rust_class_name:ident>) @extends $($extends:path),+, @implements $($implements:path),+; + pub struct $name:ident(Object<$ffi_name:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+, @implements $($implements:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, ::std::os::raw::c_void, @get_type $get_type_expr, @extends [$($extends),+], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Object, class struct, parents and interfaces ( $(#[$attr:meta])* - pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty, $rust_class_name:ident>) @extends $($extends:path),+, @implements $($implements:path),+; + pub struct $name:ident(Object<$ffi_name:ty, $ffi_class_name:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+, @implements $($implements:path),+; match fn { get_type => || $get_type_expr:expr, } ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, $ffi_name, $ffi_class_name, @get_type $get_type_expr, @extends [$($extends),+], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // ObjectSubclass, no parents or interfaces ( $(#[$attr:meta])* - pub struct $name:ident(ObjectSubclass<$subclass:ty, $rust_class_name:ident>); + pub struct $name:ident(ObjectSubclass<$subclass:ty $(, $rust_class_name:ident)?>); ) => { use glib::translate::ToGlib; - $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, @get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()), @extends [], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // ObjectSubclass, no parents, interfaces ( $(#[$attr:meta])* - pub struct $name:ident(ObjectSubclass<$subclass:ty, $rust_class_name:ident>) @implements $($implements:path),+; + pub struct $name:ident(ObjectSubclass<$subclass:ty $(, $rust_class_name:ident)?>) @implements $($implements:path),+; ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, @get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()), @extends [], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // ObjectSubclass, parents, no interfaces ( $(#[$attr:meta])* - pub struct $name:ident(ObjectSubclass<$subclass:ty, $rust_class_name:ident>) @extends $($extends:path),+; + pub struct $name:ident(ObjectSubclass<$subclass:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+; ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, @get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()), @extends [$($extends),+], @implements []); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // ObjectSubclass, parents and interfaces ( $(#[$attr:meta])* - pub struct $name:ident(ObjectSubclass<$subclass:ty, $rust_class_name:ident>) @extends $($extends:path),+, @implements $($implements:path),+; + pub struct $name:ident(ObjectSubclass<$subclass:ty $(, $rust_class_name:ident)?>) @extends $($extends:path),+, @implements $($implements:path),+; ) => { - $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, $rust_class_name, + $crate::glib_object_wrapper!(@object [$($attr)*] $name, <$subclass as $crate::subclass::types::ObjectSubclass>::Instance, <$subclass as $crate::subclass::types::ObjectSubclass>::Class, @get_type $crate::translate::ToGlib::to_glib(&<$subclass as $crate::subclass::types::ObjectSubclass>::get_type()), @extends [$($extends),+], @implements [$($implements),+]); + $( pub type $rust_class_name = $crate::object::Class<$name>; )? }; // Interface, no prerequisites diff --git a/gtk/src/subclass/application.rs b/gtk/src/subclass/application.rs index fbdef3a0d269..d188b55f2aa0 100644 --- a/gtk/src/subclass/application.rs +++ b/gtk/src/subclass/application.rs @@ -5,7 +5,6 @@ use glib::translate::*; use glib::subclass::prelude::*; use Application; -use ApplicationClass; use Window; pub trait GtkApplicationImpl: @@ -49,8 +48,8 @@ impl GtkApplicationImplExt for T { } } -unsafe impl IsSubclassable for ApplicationClass { - fn override_vfuncs(&mut self) { +unsafe impl IsSubclassable for Application { + fn override_vfuncs(class: &mut ::glib::object::Class) { unsafe extern "C" fn application_window_added( ptr: *mut gtk_sys::GtkApplication, wptr: *mut gtk_sys::GtkWindow, @@ -82,13 +81,13 @@ unsafe impl IsSubclassable for ApplicationClass { imp.startup(&wrap) } - >::override_vfuncs(self); + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkApplicationClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkApplicationClass); klass.window_added = Some(application_window_added::); klass.window_removed = Some(application_window_removed::); // Chain our startup handler in here - let klass = &mut *(self as *mut Self as *mut gio_sys::GApplicationClass); + let klass = &mut class.as_mut().parent_class; klass.startup = Some(application_startup::); } } diff --git a/gtk/src/subclass/application_window.rs b/gtk/src/subclass/application_window.rs index 8ba9efc8cc4a..5989ffae5bb6 100644 --- a/gtk/src/subclass/application_window.rs +++ b/gtk/src/subclass/application_window.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::window::WindowImpl; -use ApplicationWindowClass; -use WindowClass; +use ApplicationWindow; +use Window; pub trait ApplicationWindowImpl: WindowImpl {} -unsafe impl IsSubclassable for ApplicationWindowClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for ApplicationWindow { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/bin.rs b/gtk/src/subclass/bin.rs index 6c0484369c5e..edc04e839935 100644 --- a/gtk/src/subclass/bin.rs +++ b/gtk/src/subclass/bin.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use BinClass; -use ContainerClass; +use Bin; +use Container; pub trait BinImpl: ContainerImpl {} -unsafe impl IsSubclassable for BinClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Bin { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/box_.rs b/gtk/src/subclass/box_.rs index b41e03017fb7..eef8fd46f489 100644 --- a/gtk/src/subclass/box_.rs +++ b/gtk/src/subclass/box_.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use BoxClass; -use ContainerClass; +use Box; +use Container; pub trait BoxImpl: ContainerImpl {} -unsafe impl IsSubclassable for BoxClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Box { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer.rs b/gtk/src/subclass/cell_renderer.rs index 2b8e634ee514..09108d6dc472 100644 --- a/gtk/src/subclass/cell_renderer.rs +++ b/gtk/src/subclass/cell_renderer.rs @@ -11,11 +11,10 @@ use glib::object::IsA; use glib::subclass::prelude::*; use glib::translate::*; use glib::GString; -use glib::ObjectClass; +use glib::Object; use CellEditable; use CellRenderer; -use CellRendererClass; use CellRendererState; use SizeRequestMode; use Widget; @@ -436,11 +435,11 @@ impl CellRendererImplExt for T { } } -unsafe impl IsSubclassable for CellRendererClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRenderer { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkCellRendererClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkCellRendererClass); klass.get_request_mode = Some(cell_renderer_get_request_mode::); klass.get_preferred_width = Some(cell_renderer_get_preferred_width::); klass.get_preferred_height_for_width = diff --git a/gtk/src/subclass/cell_renderer_accel.rs b/gtk/src/subclass/cell_renderer_accel.rs index bd8195249c32..19692f0a5f64 100644 --- a/gtk/src/subclass/cell_renderer_accel.rs +++ b/gtk/src/subclass/cell_renderer_accel.rs @@ -9,8 +9,7 @@ use glib::GString; use super::cell_renderer_text::CellRendererTextImpl; use CellRendererAccel; -use CellRendererAccelClass; -use CellRendererTextClass; +use CellRendererText; pub trait CellRendererAccelImpl: CellRendererAccelImplExt + CellRendererTextImpl { fn accel_edited( @@ -78,11 +77,11 @@ impl CellRendererAccelImplExt for T { } } -unsafe impl IsSubclassable for CellRendererAccelClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererAccel { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkCellRendererAccelClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkCellRendererAccelClass); klass.accel_edited = Some(cell_renderer_accel_edited::); klass.accel_cleared = Some(cell_renderer_accel_cleared::); } diff --git a/gtk/src/subclass/cell_renderer_combo.rs b/gtk/src/subclass/cell_renderer_combo.rs index 2358381d21f7..ab397229459f 100644 --- a/gtk/src/subclass/cell_renderer_combo.rs +++ b/gtk/src/subclass/cell_renderer_combo.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::cell_renderer_text::CellRendererTextImpl; -use CellRendererComboClass; -use CellRendererTextClass; +use CellRendererCombo; +use CellRendererText; pub trait CellRendererComboImpl: CellRendererTextImpl {} -unsafe impl IsSubclassable for CellRendererComboClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererCombo { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer_pixbuf.rs b/gtk/src/subclass/cell_renderer_pixbuf.rs index 8bfc99d2051a..d5061d73813d 100644 --- a/gtk/src/subclass/cell_renderer_pixbuf.rs +++ b/gtk/src/subclass/cell_renderer_pixbuf.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::cell_renderer::CellRendererImpl; -use CellRendererClass; -use CellRendererPixbufClass; +use CellRenderer; +use CellRendererPixbuf; pub trait CellRendererPixbufImpl: CellRendererImpl {} -unsafe impl IsSubclassable for CellRendererPixbufClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererPixbuf { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer_progress.rs b/gtk/src/subclass/cell_renderer_progress.rs index d8211cc73e42..0c038534f166 100644 --- a/gtk/src/subclass/cell_renderer_progress.rs +++ b/gtk/src/subclass/cell_renderer_progress.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::cell_renderer::CellRendererImpl; -use CellRendererClass; -use CellRendererProgressClass; +use CellRenderer; +use CellRendererProgress; pub trait CellRendererProgressImpl: CellRendererImpl {} -unsafe impl IsSubclassable for CellRendererProgressClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererProgress { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer_spin.rs b/gtk/src/subclass/cell_renderer_spin.rs index e86fc3198984..2911cd357b73 100644 --- a/gtk/src/subclass/cell_renderer_spin.rs +++ b/gtk/src/subclass/cell_renderer_spin.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::cell_renderer_text::CellRendererTextImpl; -use CellRendererSpinClass; -use CellRendererTextClass; +use CellRendererSpin; +use CellRendererText; pub trait CellRendererSpinImpl: CellRendererTextImpl {} -unsafe impl IsSubclassable for CellRendererSpinClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererSpin { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer_spinner.rs b/gtk/src/subclass/cell_renderer_spinner.rs index 8f066936635b..34c95f406dbf 100644 --- a/gtk/src/subclass/cell_renderer_spinner.rs +++ b/gtk/src/subclass/cell_renderer_spinner.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::cell_renderer::CellRendererImpl; -use CellRendererClass; -use CellRendererSpinnerClass; +use CellRenderer; +use CellRendererSpinner; pub trait CellRendererSpinnerImpl: CellRendererImpl {} -unsafe impl IsSubclassable for CellRendererSpinnerClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererSpinner { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/cell_renderer_text.rs b/gtk/src/subclass/cell_renderer_text.rs index 651ad6acebf1..4a946e07bb77 100644 --- a/gtk/src/subclass/cell_renderer_text.rs +++ b/gtk/src/subclass/cell_renderer_text.rs @@ -7,9 +7,8 @@ use glib::translate::*; use glib::GString; use super::cell_renderer::CellRendererImpl; -use CellRendererClass; +use CellRenderer; use CellRendererText; -use CellRendererTextClass; pub trait CellRendererTextImpl: CellRendererTextImplExt + CellRendererImpl { fn edited(&self, renderer: &CellRendererText, path: &str, new_text: &str) { @@ -38,11 +37,11 @@ impl CellRendererTextImplExt for T { } } -unsafe impl IsSubclassable for CellRendererTextClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererText { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkCellRendererTextClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkCellRendererTextClass); klass.edited = Some(cell_renderer_text_edited::); } } diff --git a/gtk/src/subclass/cell_renderer_toggle.rs b/gtk/src/subclass/cell_renderer_toggle.rs index 436eadaa9d4c..7bd7e255edcc 100644 --- a/gtk/src/subclass/cell_renderer_toggle.rs +++ b/gtk/src/subclass/cell_renderer_toggle.rs @@ -7,9 +7,8 @@ use glib::translate::*; use glib::GString; use super::cell_renderer::CellRendererImpl; -use CellRendererClass; +use CellRenderer; use CellRendererToggle; -use CellRendererToggleClass; pub trait CellRendererToggleImpl: CellRendererToggleImplExt + CellRendererImpl { fn toggled(&self, renderer: &CellRendererToggle, path: &str) { @@ -34,11 +33,11 @@ impl CellRendererToggleImplExt for T { } } -unsafe impl IsSubclassable for CellRendererToggleClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for CellRendererToggle { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkCellRendererToggleClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkCellRendererToggleClass); klass.toggled = Some(cell_renderer_toggle_toggled::); } } diff --git a/gtk/src/subclass/container.rs b/gtk/src/subclass/container.rs index 5737a8161c00..b6e6205fdc2e 100644 --- a/gtk/src/subclass/container.rs +++ b/gtk/src/subclass/container.rs @@ -6,9 +6,7 @@ use glib::subclass::prelude::*; use super::widget::WidgetImpl; use Container; -use ContainerClass; use Widget; -use WidgetClass; use WidgetPath; pub trait ContainerImpl: ContainerImplExt + WidgetImpl { @@ -131,11 +129,11 @@ impl ContainerImplExt for T { } } -unsafe impl IsSubclassable for ContainerClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Container { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkContainerClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkContainerClass); klass.add = Some(container_add::); klass.remove = Some(container_remove::); klass.check_resize = Some(container_check_resize::); diff --git a/gtk/src/subclass/dialog.rs b/gtk/src/subclass/dialog.rs index 8301d77bcf35..e4319f485f95 100644 --- a/gtk/src/subclass/dialog.rs +++ b/gtk/src/subclass/dialog.rs @@ -6,9 +6,8 @@ use glib::subclass::prelude::*; use super::window::WindowImpl; use Dialog; -use DialogClass; use ResponseType; -use WindowClass; +use Window; pub trait DialogImpl: DialogImplExt + WindowImpl { fn response(&self, dialog: &Dialog, response: ResponseType) { @@ -47,11 +46,11 @@ impl DialogImplExt for T { } } -unsafe impl IsSubclassable for DialogClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Dialog { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkDialogClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkDialogClass); klass.response = Some(dialog_response::); klass.close = Some(dialog_close::); } diff --git a/gtk/src/subclass/drawing_area.rs b/gtk/src/subclass/drawing_area.rs index 34a83cca1871..2ea736d9ac21 100644 --- a/gtk/src/subclass/drawing_area.rs +++ b/gtk/src/subclass/drawing_area.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::widget::WidgetImpl; -use DrawingAreaClass; -use WidgetClass; +use DrawingArea; +use Widget; pub trait DrawingAreaImpl: WidgetImpl {} -unsafe impl IsSubclassable for DrawingAreaClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for DrawingArea { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/event_box.rs b/gtk/src/subclass/event_box.rs index e4f975de9e4c..e284a4c1aa8d 100644 --- a/gtk/src/subclass/event_box.rs +++ b/gtk/src/subclass/event_box.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::bin::BinImpl; -use BinClass; -use EventBoxClass; +use Bin; +use EventBox; pub trait EventBoxImpl: BinImpl {} -unsafe impl IsSubclassable for EventBoxClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for EventBox { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/fixed.rs b/gtk/src/subclass/fixed.rs index c77454232acf..d6c2358e7bee 100644 --- a/gtk/src/subclass/fixed.rs +++ b/gtk/src/subclass/fixed.rs @@ -5,13 +5,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use ContainerClass; -use FixedClass; +use Container; +use Fixed; pub trait FixedImpl: ContainerImpl {} -unsafe impl IsSubclassable for FixedClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Fixed { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/header_bar.rs b/gtk/src/subclass/header_bar.rs index aaad581440e7..700b7d473ea1 100644 --- a/gtk/src/subclass/header_bar.rs +++ b/gtk/src/subclass/header_bar.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use ContainerClass; -use HeaderBarClass; +use Container; +use HeaderBar; pub trait HeaderBarImpl: ContainerImpl {} -unsafe impl IsSubclassable for HeaderBarClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for HeaderBar { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/icon_view.rs b/gtk/src/subclass/icon_view.rs index ee7b3779a6b9..f971e52f9258 100644 --- a/gtk/src/subclass/icon_view.rs +++ b/gtk/src/subclass/icon_view.rs @@ -7,9 +7,8 @@ use glib::subclass::prelude::*; use glib::translate::*; use super::container::ContainerImpl; -use ContainerClass; +use Container; use IconView; -use IconViewClass; use MovementStep; use TreePath; @@ -140,11 +139,11 @@ impl IconViewImplExt for T { } } -unsafe impl IsSubclassable for IconViewClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for IconView { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkIconViewClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkIconViewClass); klass.item_activated = Some(icon_view_item_activated::); klass.selection_changed = Some(icon_view_selection_changed::); klass.select_all = Some(icon_view_select_all::); diff --git a/gtk/src/subclass/list_box.rs b/gtk/src/subclass/list_box.rs index fd464b33c4d3..7a4b753ee481 100644 --- a/gtk/src/subclass/list_box.rs +++ b/gtk/src/subclass/list_box.rs @@ -10,9 +10,8 @@ use super::{container::ContainerImpl, widget::WidgetImpl}; use libc::c_int; -use ContainerClass; +use Container; use ListBox; -use ListBoxClass; use ListBoxRow; use MovementStep; @@ -146,11 +145,11 @@ impl ListBoxImplExt for T { } } -unsafe impl IsSubclassable for ListBoxClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for ListBox { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkListBoxClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkListBoxClass); klass.activate_cursor_row = Some(list_box_activate_cursor_row::); klass.move_cursor = Some(list_box_move_cursor::); klass.row_activated = Some(list_box_row_activated::); diff --git a/gtk/src/subclass/list_box_row.rs b/gtk/src/subclass/list_box_row.rs index 3e0f4fe11ad0..2e83440d3451 100644 --- a/gtk/src/subclass/list_box_row.rs +++ b/gtk/src/subclass/list_box_row.rs @@ -2,9 +2,8 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use BinClass; +use Bin; use ListBoxRow; -use ListBoxRowClass; use glib::subclass::prelude::*; use glib::translate::*; @@ -21,11 +20,11 @@ pub trait ListBoxRowImplExt { fn list_box_row_activate(&self, list_box_row: &ListBoxRow); } -unsafe impl IsSubclassable for ListBoxRowClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for ListBoxRow { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkListBoxRowClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkListBoxRowClass); klass.activate = Some(list_box_row_activate::); } } diff --git a/gtk/src/subclass/plug.rs b/gtk/src/subclass/plug.rs index ad0845206162..69eae36ac11e 100644 --- a/gtk/src/subclass/plug.rs +++ b/gtk/src/subclass/plug.rs @@ -8,8 +8,7 @@ use glib::translate::*; use super::window::WindowImpl; use Plug; -use PlugClass; -use WindowClass; +use Window; pub trait PlugImpl: PlugImplExt + WindowImpl { fn embedded(&self, plug: &Plug) { @@ -33,11 +32,11 @@ impl PlugImplExt for T { } } -unsafe impl IsSubclassable for PlugClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Plug { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkPlugClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkPlugClass); klass.embedded = Some(plug_embedded::); } } diff --git a/gtk/src/subclass/socket.rs b/gtk/src/subclass/socket.rs index 84a0159e1c1a..bc3281acfda1 100644 --- a/gtk/src/subclass/socket.rs +++ b/gtk/src/subclass/socket.rs @@ -8,9 +8,8 @@ use glib::translate::*; use super::container::ContainerImpl; use crate::Inhibit; -use ContainerClass; +use Container; use Socket; -use SocketClass; pub trait SocketImpl: SocketImplExt + ContainerImpl { fn plug_added(&self, socket: &Socket) { @@ -51,11 +50,11 @@ impl SocketImplExt for T { } } -unsafe impl IsSubclassable for SocketClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Socket { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkSocketClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkSocketClass); klass.plug_added = Some(socket_plug_added::); klass.plug_removed = Some(socket_plug_removed::); } diff --git a/gtk/src/subclass/stack.rs b/gtk/src/subclass/stack.rs index 647dc02ad3f1..333b58b9f314 100644 --- a/gtk/src/subclass/stack.rs +++ b/gtk/src/subclass/stack.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use ContainerClass; -use StackClass; +use Container; +use Stack; pub trait StackImpl: ContainerImpl {} -unsafe impl IsSubclassable for StackClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Stack { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/tree_view.rs b/gtk/src/subclass/tree_view.rs index 65e1e50f984a..691a39effd5d 100644 --- a/gtk/src/subclass/tree_view.rs +++ b/gtk/src/subclass/tree_view.rs @@ -1,13 +1,13 @@ use glib::subclass::prelude::*; use super::container::ContainerImpl; -use ContainerClass; -use TreeViewClass; +use Container; +use TreeView; pub trait TreeViewImpl: ContainerImpl {} -unsafe impl IsSubclassable for TreeViewClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for TreeView { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); } } diff --git a/gtk/src/subclass/widget.rs b/gtk/src/subclass/widget.rs index 7c4adb156754..4fd2f73840d7 100644 --- a/gtk/src/subclass/widget.rs +++ b/gtk/src/subclass/widget.rs @@ -6,7 +6,7 @@ use std::mem; use glib::translate::*; use glib::subclass::prelude::*; -use glib::ObjectClass; +use glib::Object; use crate::DragResult; use crate::Inhibit; @@ -18,7 +18,6 @@ use cairo_sys; use Allocation; use SizeRequestMode; use Widget; -use WidgetClass; use WidgetExt; pub trait WidgetImpl: WidgetImplExt + ObjectImpl { @@ -915,11 +914,11 @@ impl WidgetImplExt for T { } } -unsafe impl IsSubclassable for WidgetClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Widget { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkWidgetClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkWidgetClass); klass.adjust_baseline_allocation = Some(widget_adjust_baseline_allocation::); klass.adjust_baseline_request = Some(widget_adjust_baseline_request::); klass.adjust_size_allocation = Some(widget_adjust_size_allocation::); diff --git a/gtk/src/subclass/window.rs b/gtk/src/subclass/window.rs index 097e1bde1168..e7e5b0a4031e 100644 --- a/gtk/src/subclass/window.rs +++ b/gtk/src/subclass/window.rs @@ -5,10 +5,9 @@ use glib::translate::*; use glib::subclass::prelude::*; use super::bin::BinImpl; -use BinClass; +use Bin; use Widget; use Window; -use WindowClass; pub trait WindowImpl: WindowImplExt + BinImpl { fn set_focus(&self, window: &Window, focus: Option<&Widget>) { @@ -94,11 +93,11 @@ impl WindowImplExt for T { } } -unsafe impl IsSubclassable for WindowClass { - fn override_vfuncs(&mut self) { - >::override_vfuncs(self); +unsafe impl IsSubclassable for Window { + fn override_vfuncs(class: &mut ::glib::object::Class) { + >::override_vfuncs(class); unsafe { - let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkWindowClass); + let klass = &mut *(class.as_mut() as *mut gtk_sys::GtkWindowClass); klass.set_focus = Some(window_set_focus::); klass.activate_focus = Some(window_activate_focus::); klass.activate_default = Some(window_activate_default::);