Skip to content

Commit 5d74f74

Browse files
glib: Add missing ObjectImpl vfuncs overrides
1 parent 1fddbfd commit 5d74f74

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

glib/src/subclass/object.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use std::{mem, ptr};
88

99
use super::{prelude::*, Signal};
10-
use crate::{prelude::*, translate::*, Cast, Object, ParamSpec, Value};
10+
use crate::{prelude::*, translate::*, Cast, Object, ParamSpec, Slice, Value};
1111

1212
// rustdoc-stripper-ignore-next
1313
/// Trait for implementors of `glib::Object` subclasses.
@@ -67,6 +67,17 @@ pub trait ObjectImpl: ObjectSubclass + ObjectImplExt {
6767
/// error code but no memory violation) until it is dropped. `dispose()` can be executed more
6868
/// than once.
6969
fn dispose(&self) {}
70+
71+
// rustdoc-stripper-ignore-next
72+
/// Function to be called when property change is notified for with
73+
/// `self.notify("property")`.
74+
fn notify(&self, pspec: &ParamSpec) {
75+
self.parent_notify(pspec)
76+
}
77+
78+
fn dispatch_properties_changed(&self, pspecs: &[ParamSpec]) {
79+
self.parent_dispatch_properties_changed(pspecs)
80+
}
7081
}
7182

7283
#[doc(alias = "get_property")]
@@ -116,6 +127,25 @@ unsafe extern "C" fn constructed<T: ObjectImpl>(obj: *mut gobject_ffi::GObject)
116127
imp.constructed();
117128
}
118129

130+
unsafe extern "C" fn notify<T: ObjectImpl>(
131+
obj: *mut gobject_ffi::GObject,
132+
pspec: *mut gobject_ffi::GParamSpec,
133+
) {
134+
let instance = &*(obj as *mut T::Instance);
135+
let imp = instance.imp();
136+
imp.notify(&from_glib_borrow(pspec));
137+
}
138+
139+
unsafe extern "C" fn dispatch_properties_changed<T: ObjectImpl>(
140+
obj: *mut gobject_ffi::GObject,
141+
n_pspecs: u32,
142+
pspecs: *mut *mut gobject_ffi::GParamSpec,
143+
) {
144+
let instance = &*(obj as *mut T::Instance);
145+
let imp = instance.imp();
146+
imp.dispatch_properties_changed(Slice::from_glib_borrow_num(pspecs, n_pspecs as _));
147+
}
148+
119149
unsafe extern "C" fn dispose<T: ObjectImpl>(obj: *mut gobject_ffi::GObject) {
120150
let instance = &*(obj as *mut T::Instance);
121151
let imp = instance.imp();
@@ -183,6 +213,8 @@ unsafe impl<T: ObjectImpl> IsSubclassable<T> for Object {
183213
klass.set_property = Some(set_property::<T>);
184214
klass.get_property = Some(property::<T>);
185215
klass.constructed = Some(constructed::<T>);
216+
klass.notify = Some(notify::<T>);
217+
klass.dispatch_properties_changed = Some(dispatch_properties_changed::<T>);
186218
klass.dispose = Some(dispose::<T>);
187219

188220
let pspecs = <T as ObjectImpl>::properties();
@@ -220,6 +252,14 @@ pub trait ObjectImplExt: ObjectSubclass {
220252
/// Chain up to the parent class' implementation of `glib::Object::constructed()`.
221253
fn parent_constructed(&self);
222254

255+
// rustdoc-stripper-ignore-next
256+
/// Chain up to the parent class' implementation of `glib::Object::notify()`.
257+
fn parent_notify(&self, pspec: &ParamSpec);
258+
259+
// rustdoc-stripper-ignore-next
260+
/// Chain up to the parent class' implementation of `glib::Object::dispatch_properties_changed()`.
261+
fn parent_dispatch_properties_changed(&self, pspecs: &[ParamSpec]);
262+
223263
// rustdoc-stripper-ignore-next
224264
/// Chain up to parent class signal handler.
225265
fn signal_chain_from_overridden(
@@ -242,6 +282,37 @@ impl<T: ObjectImpl> ObjectImplExt for T {
242282
}
243283
}
244284

285+
#[inline]
286+
fn parent_notify(&self, pspec: &ParamSpec) {
287+
unsafe {
288+
let data = T::type_data();
289+
let parent_class = data.as_ref().parent_class() as *mut gobject_ffi::GObjectClass;
290+
291+
if let Some(ref func) = (*parent_class).notify {
292+
func(
293+
self.obj().unsafe_cast_ref::<Object>().to_glib_none().0,
294+
pspec.to_glib_none().0,
295+
);
296+
}
297+
}
298+
}
299+
300+
#[inline]
301+
fn parent_dispatch_properties_changed(&self, pspecs: &[ParamSpec]) {
302+
unsafe {
303+
let data = T::type_data();
304+
let parent_class = data.as_ref().parent_class() as *mut gobject_ffi::GObjectClass;
305+
306+
if let Some(ref func) = (*parent_class).dispatch_properties_changed {
307+
func(
308+
self.obj().unsafe_cast_ref::<Object>().to_glib_none().0,
309+
pspecs.len() as _,
310+
pspecs.as_ptr() as *mut _,
311+
);
312+
}
313+
}
314+
}
315+
245316
fn signal_chain_from_overridden(
246317
&self,
247318
token: &super::SignalClassHandlerToken,

0 commit comments

Comments
 (0)