diff --git a/gtk4/src/subclass/widget.rs b/gtk4/src/subclass/widget.rs index 4fe0dc2bb129..939216fcd6f1 100644 --- a/gtk4/src/subclass/widget.rs +++ b/gtk4/src/subclass/widget.rs @@ -5,7 +5,13 @@ use std::{boxed::Box as Box_, collections::HashMap, fmt, future::Future}; -use glib::{clone::Downgrade, subclass::SignalId, translate::*, GString, Variant}; +use glib::{ + clone::Downgrade, + property::{Property, PropertyGet}, + subclass::SignalId, + translate::*, + GString, Variant, +}; use crate::{ ffi, prelude::*, subclass::prelude::*, AccessibleRole, BuilderRustScope, BuilderScope, @@ -1211,13 +1217,19 @@ pub unsafe trait WidgetClassExt: ClassStruct { unsafe impl WidgetClassExt for T where T::Type: WidgetImpl {} #[derive(Debug, PartialEq, Eq)] -#[repr(C)] +#[repr(transparent)] pub struct TemplateChild where T: ObjectType + FromGlibPtrNone<*mut ::GlibType>, { ptr: *mut ::GlibType, - should_drop: bool, +} + +impl Property for TemplateChild +where + T: ObjectType + FromGlibPtrNone<*mut ::GlibType>, +{ + type Value = T::Value; } impl Default for TemplateChild @@ -1229,59 +1241,18 @@ where Self { ptr: std::ptr::null_mut(), - should_drop: false, } } } -impl glib::HasParamSpec for TemplateChild -where - T: ObjectType + IsA + FromGlibPtrNone<*mut ::GlibType>, -{ - type ParamSpec = glib::ParamSpecObject; - type SetValue = T; - type BuilderFn = fn(&str) -> glib::ParamSpecObjectBuilder; - - fn param_spec_builder() -> Self::BuilderFn { - Self::ParamSpec::builder - } -} - -impl ToValue for TemplateChild -where - T: ToValue + ObjectType + FromGlibPtrNone<*mut ::GlibType>, -{ - #[inline] - fn to_value(&self) -> glib::Value { - T::to_value(&self.get()) - } - - #[inline] - fn value_type(&self) -> glib::Type { - T::static_type() - } -} - -impl glib::value::ValueType for TemplateChild +impl PropertyGet for TemplateChild where - T: glib::value::ValueType + ObjectType + FromGlibPtrNone<*mut ::GlibType>, + T: Property + ObjectType + FromGlibPtrNone<*mut ::GlibType>, { - type Type = ::Type; -} + type Value = T; -unsafe impl<'a, T> glib::value::FromValue<'a> for TemplateChild -where - T: ObjectType + FromGlibPtrNone<*mut ::GlibType>, -{ - type Checker = glib::value::GenericValueTypeChecker; - - #[inline] - unsafe fn from_value(value: &'a glib::Value) -> Self { - skip_assert_initialized!(); - TemplateChild { - ptr: T::from_value(value).into_glib_ptr(), - should_drop: true, - } + fn get R>(&self, f: F) -> R { + f(&self.get()) } } @@ -1314,19 +1285,6 @@ where } } -impl Drop for TemplateChild -where - T: ObjectType + FromGlibPtrNone<*mut ::GlibType>, -{ - fn drop(&mut self) { - if self.should_drop { - unsafe { - crate::glib::gobject_ffi::g_object_unref(self.ptr as *mut _); - } - } - } -} - impl TemplateChild where T: ObjectType + FromGlibPtrNone<*mut ::GlibType>,