1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use super :: InitializingType ;
3
+ use super :: { InitializingType , Signal } ;
4
4
use crate :: translate:: * ;
5
- use crate :: { IsA , Object , ObjectExt , ParamSpec , SignalFlags , StaticType , Type , Value } ;
5
+ use crate :: { IsA , Object , ObjectExt , ParamSpec , StaticType , Type } ;
6
6
use std:: marker;
7
7
use std:: mem;
8
8
@@ -97,6 +97,11 @@ pub trait ObjectInterface: Sized + 'static {
97
97
fn properties ( ) -> & ' static [ ParamSpec ] {
98
98
& [ ]
99
99
}
100
+
101
+ /// Signals installed for this interface.
102
+ fn signals ( ) -> & ' static [ Signal ] {
103
+ & [ ]
104
+ }
100
105
}
101
106
102
107
pub trait ObjectInterfaceExt : ObjectInterface {
@@ -114,117 +119,6 @@ pub trait ObjectInterfaceExt: ObjectInterface {
114
119
& * ( interface as * const Self )
115
120
}
116
121
}
117
-
118
- /// Add a new signal to the interface.
119
- ///
120
- /// This can be emitted later by `glib::Object::emit` and external code
121
- /// can connect to the signal to get notified about emissions.
122
- fn add_signal ( & mut self , name : & str , flags : SignalFlags , arg_types : & [ Type ] , ret_type : Type ) {
123
- unsafe {
124
- super :: types:: add_signal (
125
- * ( self as * mut _ as * mut ffi:: GType ) ,
126
- name,
127
- flags,
128
- arg_types,
129
- ret_type,
130
- ) ;
131
- }
132
- }
133
-
134
- /// Add a new signal with class handler to the interface.
135
- ///
136
- /// This can be emitted later by `glib::Object::emit` and external code
137
- /// can connect to the signal to get notified about emissions.
138
- ///
139
- /// The class handler will be called during the signal emission at the corresponding stage.
140
- fn add_signal_with_class_handler < F > (
141
- & mut self ,
142
- name : & str ,
143
- flags : SignalFlags ,
144
- arg_types : & [ Type ] ,
145
- ret_type : Type ,
146
- class_handler : F ,
147
- ) where
148
- F : Fn ( & super :: SignalClassHandlerToken , & [ Value ] ) -> Option < Value > + Send + Sync + ' static ,
149
- {
150
- unsafe {
151
- super :: types:: add_signal_with_class_handler (
152
- * ( self as * mut _ as * mut ffi:: GType ) ,
153
- name,
154
- flags,
155
- arg_types,
156
- ret_type,
157
- class_handler,
158
- ) ;
159
- }
160
- }
161
-
162
- /// Add a new signal with accumulator to the interface.
163
- ///
164
- /// This can be emitted later by `glib::Object::emit` and external code
165
- /// can connect to the signal to get notified about emissions.
166
- ///
167
- /// The accumulator function is used for accumulating the return values of
168
- /// multiple signal handlers. The new value is passed as second argument and
169
- /// should be combined with the old value in the first argument. If no further
170
- /// signal handlers should be called, `false` should be returned.
171
- fn add_signal_with_accumulator < F > (
172
- & mut self ,
173
- name : & str ,
174
- flags : SignalFlags ,
175
- arg_types : & [ Type ] ,
176
- ret_type : Type ,
177
- accumulator : F ,
178
- ) where
179
- F : Fn ( & super :: SignalInvocationHint , & mut Value , & Value ) -> bool + Send + Sync + ' static ,
180
- {
181
- unsafe {
182
- super :: types:: add_signal_with_accumulator (
183
- * ( self as * mut _ as * mut ffi:: GType ) ,
184
- name,
185
- flags,
186
- arg_types,
187
- ret_type,
188
- accumulator,
189
- ) ;
190
- }
191
- }
192
-
193
- /// Add a new signal with accumulator and class handler to the interface.
194
- ///
195
- /// This can be emitted later by `glib::Object::emit` and external code
196
- /// can connect to the signal to get notified about emissions.
197
- ///
198
- /// The accumulator function is used for accumulating the return values of
199
- /// multiple signal handlers. The new value is passed as second argument and
200
- /// should be combined with the old value in the first argument. If no further
201
- /// signal handlers should be called, `false` should be returned.
202
- ///
203
- /// The class handler will be called during the signal emission at the corresponding stage.
204
- fn add_signal_with_class_handler_and_accumulator < F , G > (
205
- & mut self ,
206
- name : & str ,
207
- flags : SignalFlags ,
208
- arg_types : & [ Type ] ,
209
- ret_type : Type ,
210
- class_handler : F ,
211
- accumulator : G ,
212
- ) where
213
- F : Fn ( & super :: SignalClassHandlerToken , & [ Value ] ) -> Option < Value > + Send + Sync + ' static ,
214
- G : Fn ( & super :: SignalInvocationHint , & mut Value , & Value ) -> bool + Send + Sync + ' static ,
215
- {
216
- unsafe {
217
- super :: types:: add_signal_with_class_handler_and_accumulator (
218
- * ( self as * mut _ as * mut ffi:: GType ) ,
219
- name,
220
- flags,
221
- arg_types,
222
- ret_type,
223
- class_handler,
224
- accumulator,
225
- ) ;
226
- }
227
- }
228
122
}
229
123
230
124
impl < T : ObjectInterface > ObjectInterfaceExt for T { }
@@ -243,6 +137,12 @@ unsafe extern "C" fn interface_init<T: ObjectInterface>(
243
137
) ;
244
138
}
245
139
140
+ let type_ = T :: get_type ( ) ;
141
+ let signals = <T as ObjectInterface >:: signals ( ) ;
142
+ for signal in signals {
143
+ signal. register ( type_) ;
144
+ }
145
+
246
146
iface. interface_init ( ) ;
247
147
}
248
148
0 commit comments