Mercurial > projects > dstep
comparison dstep/foundation/NSNotification.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
4 * Version: Initial created: Aug 3, 2009 | 4 * Version: Initial created: Aug 3, 2009 |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSNotification; | 7 module dstep.foundation.NSNotification; |
8 | 8 |
9 import dstep.foundation.NSCoder; | |
9 import dstep.foundation.NSDictionary; | 10 import dstep.foundation.NSDictionary; |
10 import dstep.foundation.NSObject; | 11 import dstep.foundation.NSObject; |
11 import dstep.foundation.NSString; | 12 import dstep.foundation.NSString; |
13 import dstep.foundation.NSZone; | |
12 import dstep.objc.bridge.Bridge; | 14 import dstep.objc.bridge.Bridge; |
13 import dstep.objc.objc : id; | 15 import dstep.objc.objc; |
16 | |
17 const TNSNotificationCreation = ` | |
18 | |
19 static Object notificationWithName (NSString aName, Object anObject) | |
20 { | |
21 return invokeObjcSuperClass!(Object, "notificationWithName:object:", NSString, Object)(aName, anObject); | |
22 } | |
23 | |
24 static Object notificationWithName (NSString aName, Object anObject, NSDictionary aUserInfo) | |
25 { | |
26 return invokeObjcSuperClass!(Object, "notificationWithName:object:userInfo:", NSString, Object, NSDictionary)(aName, anObject, aUserInfo); | |
27 } | |
28 `; | |
14 | 29 |
15 class NSNotification : NSObject, INSCopying, INSCoding | 30 class NSNotification : NSObject, INSCopying, INSCoding |
16 { | 31 { |
17 mixin ObjcWrap; | 32 mixin (ObjcWrap); |
18 mixin TNSNotificationCreation; | 33 |
34 this () | |
35 { | |
36 super(typeof(this).alloc.init.objcObject); | |
37 } | |
38 | |
39 typeof(this) init () | |
40 { | |
41 return invokeObjcSelf!(typeof(this), "init"); | |
42 } | |
19 | 43 |
20 NSString name () | 44 NSString name () |
21 { | 45 { |
22 return invokeObjcSelf!(NSString, "name"); | 46 return invokeObjcSelf!(NSString, "name"); |
23 } | 47 } |
47 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 71 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
48 } | 72 } |
49 | 73 |
50 this (NSCoder aDecoder) | 74 this (NSCoder aDecoder) |
51 { | 75 { |
52 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 76 typeof(this).alloc.initWithCoder(aDecoder); |
53 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | 77 } |
54 | 78 |
55 if (result) | 79 // TNSNotificationCreation |
56 objcObject = ret; | 80 static Object notificationWithName (NSString aName, Object anObject) |
57 | 81 { |
58 dObject = this; | 82 return invokeObjcSuperClass!(Object, "notificationWithName:object:", NSString, Object)(aName, anObject); |
83 } | |
84 | |
85 static Object notificationWithName (NSString aName, Object anObject, NSDictionary aUserInfo) | |
86 { | |
87 return invokeObjcSuperClass!(Object, "notificationWithName:object:userInfo:", NSString, Object, NSDictionary)(aName, anObject, aUserInfo); | |
59 } | 88 } |
60 } | 89 } |
61 | 90 |
62 class NSNotificationCenter : NSObject | 91 class NSNotificationCenter : NSObject |
63 { | 92 { |
64 mixin ObjcWrap; | 93 mixin (ObjcWrap); |
94 | |
95 this () | |
96 { | |
97 super(typeof(this).alloc.init.objcObject); | |
98 } | |
99 | |
100 typeof(this) init () | |
101 { | |
102 return invokeObjcSelf!(typeof(this), "init"); | |
103 } | |
65 | 104 |
66 static Object defaultCenter () | 105 static Object defaultCenter () |
67 { | 106 { |
68 return invokeObjcSelfClass!(Object, "defaultCenter"); | 107 return invokeObjcSuperClass!(Object, "defaultCenter"); |
69 } | 108 } |
70 | 109 |
71 void addObserver (Object observer, SEL aSelector, NSString aName, Object anObject) | 110 void addObserver (Object observer, SEL aSelector, NSString aName, Object anObject) |
72 { | 111 { |
73 return invokeObjcSelf!(void, "addObserver:selector:name:object:", Object, SEL, NSString, Object)(observer, aSelector, aName, anObject); | 112 return invokeObjcSelf!(void, "addObserver:selector:name:object:", Object, SEL, NSString, Object)(observer, aSelector, aName, anObject); |
96 void removeObserver (Object observer, NSString aName, Object anObject) | 135 void removeObserver (Object observer, NSString aName, Object anObject) |
97 { | 136 { |
98 return invokeObjcSelf!(void, "removeObserver:name:object:", Object, NSString, Object)(observer, aName, anObject); | 137 return invokeObjcSelf!(void, "removeObserver:name:object:", Object, NSString, Object)(observer, aName, anObject); |
99 } | 138 } |
100 } | 139 } |
101 | |
102 template TNSNotificationCreation () | |
103 { | |
104 static Object notificationWithName (NSString aName, Object anObject) | |
105 { | |
106 return invokeObjcSelfClass!(Object, "notificationWithName:object:", NSString, Object)(aName, anObject); | |
107 } | |
108 | |
109 static Object notificationWithName (NSString aName, Object anObject, NSDictionary aUserInfo) | |
110 { | |
111 return invokeObjcSelfClass!(Object, "notificationWithName:object:userInfo:", NSString, Object, NSDictionary)(aName, anObject, aUserInfo); | |
112 } | |
113 } | |
114 |