Mercurial > projects > dstep
comparison dstep/foundation/NSKeyValueObserving.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 |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
6 */ | 6 */ |
7 module dstep.foundation.NSKeyValueObserving; | 7 module dstep.foundation.NSKeyValueObserving; |
8 | 8 |
9 import dstep.foundation.NSArray; | 9 import dstep.foundation.NSArray; |
10 import dstep.foundation.NSIndexSet; | 10 import dstep.foundation.NSIndexSet; |
11 import dstep.foundation.NSObjCRuntime; | |
11 import dstep.foundation.NSSet; | 12 import dstep.foundation.NSSet; |
12 import dstep.foundation.NSString; | 13 import dstep.foundation.NSString; |
13 import dstep.objc.bridge.Bridge; | 14 import dstep.objc.bridge.Bridge; |
14 import dstep.objc.objc : id; | 15 import dstep.objc.objc; |
16 | |
17 | |
15 | 18 |
16 import bindings = dstep.foundation.NSKeyValueObserving_bindings; | 19 import bindings = dstep.foundation.NSKeyValueObserving_bindings; |
17 | 20 |
18 alias NSUInteger NSKeyValueObservingOptions; | 21 alias NSUInteger NSKeyValueObservingOptions; |
19 alias NSUInteger NSKeyValueChange; | 22 alias NSUInteger NSKeyValueChange; |
20 alias NSUInteger NSKeyValueSetMutationKind; | 23 alias NSUInteger NSKeyValueSetMutationKind; |
21 | 24 |
22 const NSString NSKeyValueChangeKindKey; | 25 private |
23 const NSString NSKeyValueChangeNewKey; | 26 { |
24 const NSString NSKeyValueChangeOldKey; | 27 NSString NSKeyValueChangeKindKey_; |
25 const NSString NSKeyValueChangeIndexesKey; | 28 NSString NSKeyValueChangeNewKey_; |
26 const NSString NSKeyValueChangeNotificationIsPriorKey; | 29 NSString NSKeyValueChangeOldKey_; |
30 NSString NSKeyValueChangeIndexesKey_; | |
31 NSString NSKeyValueChangeNotificationIsPriorKey_; | |
32 } | |
33 | |
34 NSString NSKeyValueChangeKindKey () | |
35 { | |
36 if (NSKeyValueChangeKindKey_) | |
37 return NSKeyValueChangeKindKey_; | |
38 | |
39 return NSKeyValueChangeKindKey_ = new NSString(bindings.NSKeyValueChangeKindKey); | |
40 } | |
41 | |
42 NSString NSKeyValueChangeNewKey () | |
43 { | |
44 if (NSKeyValueChangeNewKey_) | |
45 return NSKeyValueChangeNewKey_; | |
46 | |
47 return NSKeyValueChangeNewKey_ = new NSString(bindings.NSKeyValueChangeNewKey); | |
48 } | |
49 | |
50 NSString NSKeyValueChangeOldKey () | |
51 { | |
52 if (NSKeyValueChangeOldKey_) | |
53 return NSKeyValueChangeOldKey_; | |
54 | |
55 return NSKeyValueChangeOldKey_ = new NSString(bindings.NSKeyValueChangeOldKey); | |
56 } | |
57 | |
58 NSString NSKeyValueChangeIndexesKey () | |
59 { | |
60 if (NSKeyValueChangeIndexesKey_) | |
61 return NSKeyValueChangeIndexesKey_; | |
62 | |
63 return NSKeyValueChangeIndexesKey_ = new NSString(bindings.NSKeyValueChangeIndexesKey); | |
64 } | |
65 | |
66 NSString NSKeyValueChangeNotificationIsPriorKey () | |
67 { | |
68 if (NSKeyValueChangeNotificationIsPriorKey_) | |
69 return NSKeyValueChangeNotificationIsPriorKey_; | |
70 | |
71 return NSKeyValueChangeNotificationIsPriorKey_ = new NSString(bindings.NSKeyValueChangeNotificationIsPriorKey); | |
72 } | |
27 | 73 |
28 enum | 74 enum |
29 { | 75 { |
30 NSKeyValueObservingOptionNew = 0x01, | 76 NSKeyValueObservingOptionNew = 0x01, |
31 NSKeyValueObservingOptionOld = 0x02, | 77 NSKeyValueObservingOptionOld = 0x02, |
47 NSKeyValueMinusSetMutation = 2, | 93 NSKeyValueMinusSetMutation = 2, |
48 NSKeyValueIntersectSetMutation = 3, | 94 NSKeyValueIntersectSetMutation = 3, |
49 NSKeyValueSetSetMutation = 4 | 95 NSKeyValueSetSetMutation = 4 |
50 } | 96 } |
51 | 97 |
52 static this () | 98 const TNSKeyValueObserverNotification = ` |
53 { | |
54 NSKeyValueChangeKindKey = new NSString(bindings.NSKeyValueChangeKindKey); | |
55 NSKeyValueChangeNewKey = new NSString(bindings.NSKeyValueChangeNewKey); | |
56 NSKeyValueChangeOldKey = new NSString(bindings.NSKeyValueChangeOldKey); | |
57 NSKeyValueChangeIndexesKey = new NSString(bindings.NSKeyValueChangeIndexesKey); | |
58 NSKeyValueChangeNotificationIsPriorKey = new NSString(bindings.NSKeyValueChangeNotificationIsPriorKey); | |
59 } | |
60 | 99 |
61 template TNSKeyValueObserverNotification () | 100 void willChangeValueForKey (NSString key) |
62 { | 101 { |
63 void willChangeValueForKey (NSString key); | 102 return invokeObjcSelf!(void, "willChangeValueForKey:", NSString)(key); |
64 void didChangeValueForKey (NSString key); | 103 } |
65 void willChange (uint changeKind, NSIndexSet indexes, NSString key); | 104 |
66 void didChange (uint changeKind, NSIndexSet indexes, NSString key); | 105 void didChangeValueForKey (NSString key) |
67 void willChangeValueForKey (NSString key, uint mutationKind, NSSet objects); | 106 { |
68 void didChangeValueForKey (NSString key, uint mutationKind, NSSet objects); | 107 return invokeObjcSelf!(void, "didChangeValueForKey:", NSString)(key); |
69 } | 108 } |
109 | |
110 void willChange (NSKeyValueChange changeKind, NSIndexSet indexes, NSString key) | |
111 { | |
112 return invokeObjcSelf!(void, "willChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString)(changeKind, indexes, key); | |
113 } | |
114 | |
115 void didChange (NSKeyValueChange changeKind, NSIndexSet indexes, NSString key) | |
116 { | |
117 return invokeObjcSelf!(void, "didChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString)(changeKind, indexes, key); | |
118 } | |
119 | |
120 void willChangeValueForKey (NSString key, NSKeyValueSetMutationKind mutationKind, NSSet objects) | |
121 { | |
122 return invokeObjcSelf!(void, "willChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet)(key, mutationKind, objects); | |
123 } | |
124 | |
125 void didChangeValueForKey (NSString key, NSKeyValueSetMutationKind mutationKind, NSSet objects) | |
126 { | |
127 return invokeObjcSelf!(void, "didChangeValueForKey::withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet)(key, mutationKind, objects); | |
128 } | |
129 | |
130 //mixin ObjcBindMethod!(willChangeValueForKey, void, "willChangeValueForKey:", NSString); | |
131 //mixin ObjcBindMethod!(didChangeValueForKey, void, "didChangeValueForKey:", NSString); | |
132 //mixin ObjcBindMethod!(willChange, void, "willChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString); | |
133 //mixin ObjcBindMethod!(didChange, void, "didChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString); | |
134 //mixin ObjcBindMethod!(willChangeValueForKey, void, "willChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet); | |
135 //mixin ObjcBindMethod!(didChangeValueForKey, void, "didChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet); | |
136 `; | |
70 | 137 |
71 template TNSKeyValueObservingCustomization () | 138 const TNSKeyValueObservingCustomization = ` |
72 { | |
73 static NSSet keyPathsForValuesAffectingValueForKey (NSString key); | |
74 static bool automaticallyNotifiesObserversForKey (NSString key); | |
75 void setObservationInfo (void* observationInfo); | |
76 void* observationInfo (); | |
77 } | |
78 | 139 |
79 template TNSKeyValueObserverRegistration () | 140 static NSSet keyPathsForValuesAffectingValueForKey (NSString key) |
80 { | 141 { |
142 return invokeObjcSelfClass!(NSSet, "keyPathsForValuesAffectingValueForKey:", NSString)(key); | |
143 } | |
144 | |
145 static bool automaticallyNotifiesObserversForKey (NSString key) | |
146 { | |
147 return invokeObjcSelfClass!(bool, "automaticallyNotifiesObserversForKey:", NSString)(key); | |
148 } | |
149 | |
150 void setObservationInfo (void* observationInfo) | |
151 { | |
152 return invokeObjcSelf!(void, "setObservationInfo:", void*)(observationInfo); | |
153 } | |
154 | |
155 void* observationInfo () | |
156 { | |
157 return invokeObjcSelf!(void*, "observationInfo"); | |
158 } | |
159 | |
160 //mixin ObjcBindClassMethod!(keyPathsForValuesAffectingValueForKey, "keyPathsForValuesAffectingValueForKey:"); | |
161 //mixin ObjcBindClassMethod!(automaticallyNotifiesObserversForKey, "automaticallyNotifiesObserversForKey:"); | |
162 //mixin ObjcBindMethod!(setObservationInfo, "setObservationInfo:"); | |
163 //mixin ObjcBindMethod!(observationInfo, "observationInfo"); | |
164 `; | |
165 | |
166 const TNSKeyValueObserverRegistration = ` | |
167 | |
81 void addObserver (NSObject observer, NSString keyPath, uint options, void* context) | 168 void addObserver (NSObject observer, NSString keyPath, uint options, void* context) |
82 { | 169 { |
83 return invokeObjcSelf!(void, "addObserver:forKeyPath:options:context:", NSObject, NSString, uint, void*)(observer, keyPath, options, context); | 170 return invokeObjcSelf!(void, "addObserver:forKeyPath:options:context:", NSObject, NSString, uint, void*)(observer, keyPath, options, context); |
84 } | 171 } |
85 | 172 |
86 void removeObserver (NSObject observer, NSString keyPath) | 173 void removeObserver (NSObject observer, NSString keyPath) |
87 { | 174 { |
88 return invokeObjcSelf!(void, "removeObserver:forKeyPath:", NSObject, NSString)(observer, keyPath); | 175 return invokeObjcSelf!(void, "removeObserver:forKeyPath:", NSObject, NSString)(observer, keyPath); |
89 } | 176 } |
90 } | 177 `; |
91 | 178 |
92 template TNSDeprecatedKeyValueObservingCustomization () | 179 const TNSDeprecatedKeyValueObservingCustomization = ` |
93 { | |
94 static void setKeys (NSArray keys, NSString dependentKey); | |
95 } | |
96 | 180 |
97 template TNSKeyValueObserving () | 181 static void setKeys (NSArray keys, NSString dependentKey) |
98 { | 182 { |
99 void observeValueForKeyPath (NSString keyPath, Object object, NSDictionary change, void* context); | 183 return invokeObjcSelfClass!(void, "setKeys:triggerChangeNotificationsForDependentKey:", NSArray, NSString)(keys, dependentKey); |
100 } | 184 } |
185 | |
186 //mixin ObjcBindClassMethod!(setKeys, "setKeys:triggerChangeNotificationsForDependentKey:"); | |
187 `; | |
101 | 188 |
189 const TNSKeyValueObserving = ` | |
190 | |
191 void observeValueForKeyPath (NSString keyPath, Object object, NSDictionary change, void* context) | |
192 { | |
193 return invokeObjcSelf!(void, "observeValueForKeyPath:ofObject:change:context:", NSString, Object, NSDictionary, void*)(keyPath, object, change, context); | |
194 } | |
195 | |
196 //mixin ObjcBindMethod!(observeValueForKeyPath, "observeValueForKeyPath:ofObject:change:context:"); | |
197 `; |