Mercurial > projects > dstep
comparison dstep/objc/bridge/Bridge.d @ 19:ae08a08f44d3
Added IBOutlet
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 17 Jan 2010 16:25:24 +0100 |
parents | b2693af5a569 |
children | 6255d355d752 |
comparison
equal
deleted
inserted
replaced
18:b2693af5a569 | 19:ae08a08f44d3 |
---|---|
177 } | 177 } |
178 | 178 |
179 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; | 179 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; |
180 | 180 |
181 /** | 181 /** |
182 * Makes the given field available as an IBOutlet. | |
183 * | |
184 * Mixes in a method that is called by the Objective-C side to set the value of the | |
185 * given field. | |
186 * | |
187 * Mixes in: $(D_PSYMBOL ObjcBindMethod) | |
188 * | |
189 * Examples: | |
190 * --- | |
191 * class AppController : NSObject | |
192 * { | |
193 * NSButton button; | |
194 * mixin IBOutlet!(button); | |
195 * } | |
196 * --- | |
197 * | |
198 * Params: | |
199 * field = the field make available as an IBOutlet | |
200 */ | |
201 template IBOutlet (alias field) | |
202 { | |
203 static assert (is(typeof(field) : Object), dstep.objc.bridge.Bridge.buildIBOutletErrorMessage!(field)); | |
204 | |
205 void __setMethod (typeof(field) value) | |
206 { | |
207 field = value; | |
208 } | |
209 | |
210 mixin dstep.objc.bridge.Bridge.ObjcBindMethod!(__setMethod, "set" ~ dstep.objc.bridge.Bridge.toUpper(field.stringof[0]) ~ field.stringof[1 .. $] ~ ":"); | |
211 } | |
212 | |
213 char toUpper (char c) | |
214 { | |
215 if (c >= 'a' && c <= 'z') | |
216 return c - 32; | |
217 | |
218 return c; | |
219 } | |
220 | |
221 template buildIBOutletErrorMessage (alias field) | |
222 { | |
223 const buildIBOutletErrorMessage = `The type "` ~ typeof(field).stringof ~ `" of the given field "` ~ field.stringof ~ `" in the class "` ~ typeof(this).stringof ~ `" is not a valid IBOutlet type. IBOutlets can only be of the type Object (or any of its subclasses)`; | |
224 } | |
225 | |
226 /** | |
182 * Binds a selector to an instance method. | 227 * Binds a selector to an instance method. |
183 * | 228 * |
184 * This will create a receiver function which will forward the call to $(D_PARAM method), | 229 * This will create a receiver function which will forward the call to $(D_PARAM method), |
185 * decapsulating arguments and encapsulating the return value as appropriate. | 230 * decapsulating arguments and encapsulating the return value as appropriate. |
186 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build | 231 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build |
202 * Params: | 247 * Params: |
203 * method = the method to bind | 248 * method = the method to bind |
204 */ | 249 */ |
205 template IBAction (alias method) | 250 template IBAction (alias method) |
206 { | 251 { |
207 static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "dstep.objc.bridge.Bridge.IBAction: an action method is only allowed to have one parameter"); | 252 static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "An action method is only allowed to have one parameter"); |
208 static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "dstep.objc.bridge.Bridge.IBAction: an action method can only have a parameter of the type Object (or any of its subclasses)"); | 253 static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "An action method can only have a parameter of the type Object (or any of its subclasses)"); |
209 | 254 |
210 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); | 255 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); |
211 } | 256 } |
212 | 257 |
213 /** | 258 /** |
261 * method = the method to bind | 306 * method = the method to bind |
262 * selector = the selector to bind the method to | 307 * selector = the selector to bind the method to |
263 */ | 308 */ |
264 template ObjcBindMethod (alias method, string selector) | 309 template ObjcBindMethod (alias method, string selector) |
265 { | 310 { |
266 version (Tango) | 311 mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); |
267 mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); | |
268 | |
269 /*else | |
270 mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method));*/ | |
271 } | 312 } |
272 | 313 |
273 /** | 314 /** |
274 * Binds a selector to an instance method. | 315 * Binds a selector to an instance method. |
275 * | 316 * |
403 * method = the method to bind | 444 * method = the method to bind |
404 * selector = the selector to bind the method to | 445 * selector = the selector to bind the method to |
405 */ | 446 */ |
406 template ObjcBindClassMethod (alias method, string selector) | 447 template ObjcBindClassMethod (alias method, string selector) |
407 { | 448 { |
408 version (Tango) | 449 mixin ObjcBindClassMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); |
409 mixin ObjcBindClassMethod!(method, tango.core.Traits.ReturnTypeOf!(method), selector, tango.core.Traits.ParameterTupleOf!(method)); | |
410 | |
411 else | |
412 mixin ObjcBindClassMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method)); | |
413 } | 450 } |
414 | 451 |
415 /** | 452 /** |
416 * Binds a selector to a class (static) method. | 453 * Binds a selector to a class (static) method. |
417 * | 454 * |
521 * mixin ObjcBindFunction!(foo); | 558 * mixin ObjcBindFunction!(foo); |
522 * --- | 559 * --- |
523 */ | 560 */ |
524 template ObjcBindFunction (alias func) | 561 template ObjcBindFunction (alias func) |
525 { | 562 { |
526 mixin ObjcBindFunction!(func, ReturnTypeOf!(func), ParameterTupleOf!(func)); | 563 mixin ObjcBindFunction!(func, dstep.objc.bridge.Bridge.ReturnTypeOf!(func), dstep.objc.bridge.Bridge.ParameterTupleOf!(func)); |
527 } | 564 } |
528 | 565 |
529 /** | 566 /** |
530 * Binds a D free function to an Objective-C free function. | 567 * Binds a D free function to an Objective-C free function. |
531 * | 568 * |