Mercurial > projects > dstep
diff 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 |
line wrap: on
line diff
--- a/dstep/foundation/NSKeyValueObserving.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSKeyValueObserving.d Sun Jan 03 22:06:11 2010 +0100 @@ -8,10 +8,13 @@ import dstep.foundation.NSArray; import dstep.foundation.NSIndexSet; +import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSSet; import dstep.foundation.NSString; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; + + import bindings = dstep.foundation.NSKeyValueObserving_bindings; @@ -19,11 +22,54 @@ alias NSUInteger NSKeyValueChange; alias NSUInteger NSKeyValueSetMutationKind; -const NSString NSKeyValueChangeKindKey; -const NSString NSKeyValueChangeNewKey; -const NSString NSKeyValueChangeOldKey; -const NSString NSKeyValueChangeIndexesKey; -const NSString NSKeyValueChangeNotificationIsPriorKey; +private +{ + NSString NSKeyValueChangeKindKey_; + NSString NSKeyValueChangeNewKey_; + NSString NSKeyValueChangeOldKey_; + NSString NSKeyValueChangeIndexesKey_; + NSString NSKeyValueChangeNotificationIsPriorKey_; +} + +NSString NSKeyValueChangeKindKey () +{ + if (NSKeyValueChangeKindKey_) + return NSKeyValueChangeKindKey_; + + return NSKeyValueChangeKindKey_ = new NSString(bindings.NSKeyValueChangeKindKey); +} + +NSString NSKeyValueChangeNewKey () +{ + if (NSKeyValueChangeNewKey_) + return NSKeyValueChangeNewKey_; + + return NSKeyValueChangeNewKey_ = new NSString(bindings.NSKeyValueChangeNewKey); +} + +NSString NSKeyValueChangeOldKey () +{ + if (NSKeyValueChangeOldKey_) + return NSKeyValueChangeOldKey_; + + return NSKeyValueChangeOldKey_ = new NSString(bindings.NSKeyValueChangeOldKey); +} + +NSString NSKeyValueChangeIndexesKey () +{ + if (NSKeyValueChangeIndexesKey_) + return NSKeyValueChangeIndexesKey_; + + return NSKeyValueChangeIndexesKey_ = new NSString(bindings.NSKeyValueChangeIndexesKey); +} + +NSString NSKeyValueChangeNotificationIsPriorKey () +{ + if (NSKeyValueChangeNotificationIsPriorKey_) + return NSKeyValueChangeNotificationIsPriorKey_; + + return NSKeyValueChangeNotificationIsPriorKey_ = new NSString(bindings.NSKeyValueChangeNotificationIsPriorKey); +} enum { @@ -49,35 +95,76 @@ NSKeyValueSetSetMutation = 4 } -static this () -{ - NSKeyValueChangeKindKey = new NSString(bindings.NSKeyValueChangeKindKey); - NSKeyValueChangeNewKey = new NSString(bindings.NSKeyValueChangeNewKey); - NSKeyValueChangeOldKey = new NSString(bindings.NSKeyValueChangeOldKey); - NSKeyValueChangeIndexesKey = new NSString(bindings.NSKeyValueChangeIndexesKey); - NSKeyValueChangeNotificationIsPriorKey = new NSString(bindings.NSKeyValueChangeNotificationIsPriorKey); -} +const TNSKeyValueObserverNotification = ` -template TNSKeyValueObserverNotification () -{ - void willChangeValueForKey (NSString key); - void didChangeValueForKey (NSString key); - void willChange (uint changeKind, NSIndexSet indexes, NSString key); - void didChange (uint changeKind, NSIndexSet indexes, NSString key); - void willChangeValueForKey (NSString key, uint mutationKind, NSSet objects); - void didChangeValueForKey (NSString key, uint mutationKind, NSSet objects); -} + void willChangeValueForKey (NSString key) + { + return invokeObjcSelf!(void, "willChangeValueForKey:", NSString)(key); + } + + void didChangeValueForKey (NSString key) + { + return invokeObjcSelf!(void, "didChangeValueForKey:", NSString)(key); + } + + void willChange (NSKeyValueChange changeKind, NSIndexSet indexes, NSString key) + { + return invokeObjcSelf!(void, "willChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString)(changeKind, indexes, key); + } + + void didChange (NSKeyValueChange changeKind, NSIndexSet indexes, NSString key) + { + return invokeObjcSelf!(void, "didChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString)(changeKind, indexes, key); + } + + void willChangeValueForKey (NSString key, NSKeyValueSetMutationKind mutationKind, NSSet objects) + { + return invokeObjcSelf!(void, "willChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet)(key, mutationKind, objects); + } + + void didChangeValueForKey (NSString key, NSKeyValueSetMutationKind mutationKind, NSSet objects) + { + return invokeObjcSelf!(void, "didChangeValueForKey::withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet)(key, mutationKind, objects); + } + + //mixin ObjcBindMethod!(willChangeValueForKey, void, "willChangeValueForKey:", NSString); + //mixin ObjcBindMethod!(didChangeValueForKey, void, "didChangeValueForKey:", NSString); + //mixin ObjcBindMethod!(willChange, void, "willChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString); + //mixin ObjcBindMethod!(didChange, void, "didChange:valuesAtIndexes:forKey:", NSKeyValueChange, NSIndexSet, NSString); + //mixin ObjcBindMethod!(willChangeValueForKey, void, "willChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet); + //mixin ObjcBindMethod!(didChangeValueForKey, void, "didChangeValueForKey:withSetMutation:usingObjects:", NSString, NSKeyValueSetMutationKind, NSSet); +`; -template TNSKeyValueObservingCustomization () -{ - static NSSet keyPathsForValuesAffectingValueForKey (NSString key); - static bool automaticallyNotifiesObserversForKey (NSString key); - void setObservationInfo (void* observationInfo); - void* observationInfo (); -} +const TNSKeyValueObservingCustomization = ` -template TNSKeyValueObserverRegistration () -{ + static NSSet keyPathsForValuesAffectingValueForKey (NSString key) + { + return invokeObjcSelfClass!(NSSet, "keyPathsForValuesAffectingValueForKey:", NSString)(key); + } + + static bool automaticallyNotifiesObserversForKey (NSString key) + { + return invokeObjcSelfClass!(bool, "automaticallyNotifiesObserversForKey:", NSString)(key); + } + + void setObservationInfo (void* observationInfo) + { + return invokeObjcSelf!(void, "setObservationInfo:", void*)(observationInfo); + } + + void* observationInfo () + { + return invokeObjcSelf!(void*, "observationInfo"); + } + + //mixin ObjcBindClassMethod!(keyPathsForValuesAffectingValueForKey, "keyPathsForValuesAffectingValueForKey:"); + //mixin ObjcBindClassMethod!(automaticallyNotifiesObserversForKey, "automaticallyNotifiesObserversForKey:"); + //mixin ObjcBindMethod!(setObservationInfo, "setObservationInfo:"); + //mixin ObjcBindMethod!(observationInfo, "observationInfo"); +`; + +const TNSKeyValueObserverRegistration = ` + void addObserver (NSObject observer, NSString keyPath, uint options, void* context) { return invokeObjcSelf!(void, "addObserver:forKeyPath:options:context:", NSObject, NSString, uint, void*)(observer, keyPath, options, context); @@ -87,15 +174,24 @@ { return invokeObjcSelf!(void, "removeObserver:forKeyPath:", NSObject, NSString)(observer, keyPath); } -} +`; + +const TNSDeprecatedKeyValueObservingCustomization = ` -template TNSDeprecatedKeyValueObservingCustomization () -{ - static void setKeys (NSArray keys, NSString dependentKey); -} + static void setKeys (NSArray keys, NSString dependentKey) + { + return invokeObjcSelfClass!(void, "setKeys:triggerChangeNotificationsForDependentKey:", NSArray, NSString)(keys, dependentKey); + } + + //mixin ObjcBindClassMethod!(setKeys, "setKeys:triggerChangeNotificationsForDependentKey:"); +`; -template TNSKeyValueObserving () -{ - void observeValueForKeyPath (NSString keyPath, Object object, NSDictionary change, void* context); -} +const TNSKeyValueObserving = ` + void observeValueForKeyPath (NSString keyPath, Object object, NSDictionary change, void* context) + { + return invokeObjcSelf!(void, "observeValueForKeyPath:ofObject:change:context:", NSString, Object, NSDictionary, void*)(keyPath, object, change, context); + } + + //mixin ObjcBindMethod!(observeValueForKeyPath, "observeValueForKeyPath:ofObject:change:context:"); +`; \ No newline at end of file