view 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 source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Aug 3, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.foundation.NSKeyValueObserving;

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;



import bindings = dstep.foundation.NSKeyValueObserving_bindings;

alias NSUInteger NSKeyValueObservingOptions;
alias NSUInteger NSKeyValueChange;
alias NSUInteger NSKeyValueSetMutationKind;

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
{
	NSKeyValueObservingOptionNew = 0x01,
	NSKeyValueObservingOptionOld = 0x02,
	NSKeyValueObservingOptionInitial = 0x04,
	NSKeyValueObservingOptionPrior = 0x08
}

enum
{
	NSKeyValueChangeSetting = 1,
	NSKeyValueChangeInsertion = 2,
	NSKeyValueChangeRemoval = 3,
	NSKeyValueChangeReplacement = 4
}

enum
{
	NSKeyValueUnionSetMutation = 1,
	NSKeyValueMinusSetMutation = 2,
	NSKeyValueIntersectSetMutation = 3,
	NSKeyValueSetSetMutation = 4
}

const TNSKeyValueObserverNotification = `

	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);
`;

const TNSKeyValueObservingCustomization = `

	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);
	}

	void removeObserver (NSObject observer, NSString keyPath)
	{
		return invokeObjcSelf!(void, "removeObserver:forKeyPath:", NSObject, NSString)(observer, keyPath);
	}
`;

const TNSDeprecatedKeyValueObservingCustomization = `

	static void setKeys (NSArray keys, NSString dependentKey)
	{
		return invokeObjcSelfClass!(void, "setKeys:triggerChangeNotificationsForDependentKey:", NSArray, NSString)(keys, dependentKey);
	}
	
	//mixin ObjcBindClassMethod!(setKeys, "setKeys:triggerChangeNotificationsForDependentKey:");
`;

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:");
`;