7
7
use std:: { mem, ptr} ;
8
8
9
9
use super :: { prelude:: * , Signal } ;
10
- use crate :: { prelude:: * , translate:: * , Cast , Object , ParamSpec , Value } ;
10
+ use crate :: { prelude:: * , translate:: * , Cast , Object , ParamSpec , Slice , Value } ;
11
11
12
12
// rustdoc-stripper-ignore-next
13
13
/// Trait for implementors of `glib::Object` subclasses.
@@ -67,6 +67,17 @@ pub trait ObjectImpl: ObjectSubclass + ObjectImplExt {
67
67
/// error code but no memory violation) until it is dropped. `dispose()` can be executed more
68
68
/// than once.
69
69
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
+ }
70
81
}
71
82
72
83
#[ doc( alias = "get_property" ) ]
@@ -116,6 +127,25 @@ unsafe extern "C" fn constructed<T: ObjectImpl>(obj: *mut gobject_ffi::GObject)
116
127
imp. constructed ( ) ;
117
128
}
118
129
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
+
119
149
unsafe extern "C" fn dispose < T : ObjectImpl > ( obj : * mut gobject_ffi:: GObject ) {
120
150
let instance = & * ( obj as * mut T :: Instance ) ;
121
151
let imp = instance. imp ( ) ;
@@ -183,6 +213,8 @@ unsafe impl<T: ObjectImpl> IsSubclassable<T> for Object {
183
213
klass. set_property = Some ( set_property :: < T > ) ;
184
214
klass. get_property = Some ( property :: < T > ) ;
185
215
klass. constructed = Some ( constructed :: < T > ) ;
216
+ klass. notify = Some ( notify :: < T > ) ;
217
+ klass. dispatch_properties_changed = Some ( dispatch_properties_changed :: < T > ) ;
186
218
klass. dispose = Some ( dispose :: < T > ) ;
187
219
188
220
let pspecs = <T as ObjectImpl >:: properties ( ) ;
@@ -220,6 +252,14 @@ pub trait ObjectImplExt: ObjectSubclass {
220
252
/// Chain up to the parent class' implementation of `glib::Object::constructed()`.
221
253
fn parent_constructed ( & self ) ;
222
254
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
+
223
263
// rustdoc-stripper-ignore-next
224
264
/// Chain up to parent class signal handler.
225
265
fn signal_chain_from_overridden (
@@ -242,6 +282,37 @@ impl<T: ObjectImpl> ObjectImplExt for T {
242
282
}
243
283
}
244
284
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
+
245
316
fn signal_chain_from_overridden (
246
317
& self ,
247
318
token : & super :: SignalClassHandlerToken ,
0 commit comments