view dstep/foundation/NSFormatter.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
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.NSFormatter;

import dstep.foundation.NSAttributedString;
import dstep.foundation.NSCoder;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSObject;
import dstep.foundation.NSRange;
import dstep.foundation.NSString;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

class NSFormatter : NSObject, INSCopying, INSCoding
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	NSString stringForObjectValue (Object obj)
	{
		return invokeObjcSelf!(NSString, "stringForObjectValue:", Object)(obj);
	}

	NSAttributedString attributedStringForObjectValue (Object obj, NSDictionary attrs)
	{
		return invokeObjcSelf!(NSAttributedString, "attributedStringForObjectValue:withDefaultAttributes:", Object, NSDictionary)(obj, attrs);
	}

	NSString editingStringForObjectValue (Object obj)
	{
		return invokeObjcSelf!(NSString, "editingStringForObjectValue:", Object)(obj);
	}

	bool getObjectValue (out NSObject obj, NSString string, ref NSString error)
	{
		id err;
		id object;
		
		if (error)
			err = new objc_object;
		
		bool result = invokeObjcSelf!(bool, "getObjectValue:forString:errorDescription:", id*, NSString, id*)(&object, string, &err);
		
		if (err)
			error = new NSString(err);
		
		if (object)
			obj = new NSObject(object);
		
		return result;
	}

	bool isPartialStringValid (NSString partialString, out NSString newString, ref NSString error)
	{
		id err;
		id newStr = new objc_object;
		
		if (error)
			err = new objc_object;
		
		bool result = invokeObjcSelf!(bool, "isPartialStringValid:newEditingString:errorDescription:", NSString, id*, id*)(partialString, &newStr, &err);
		
		if (err)
			error = new NSString(err);
		
		if (newStr)
			newString = new NSString(newStr);
		
		return result;
	}

	bool isPartialStringValid (ref NSString partialStringPtr, NSRangePointer proposedSelRangePtr, NSString origString, NSRange origSelRange, ref NSString error)
	{
		id partialString = new objc_object;
		id err;
		
		if (error)
			err = new objc_object;			
		
		bool result = invokeObjcSelf!(bool, "isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:", id*, NSRangePointer, NSString, NSRange, id*)(&partialString, proposedSelRangePtr, origString, origSelRange, &err);
		
		if (err)
			error = new NSString(err);
		
		if (partialString)
			partialStringPtr = new NSString(partialString);
		
		return result;
	}

	Object copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
	}

	void encodeWithCoder (NSCoder aCoder)
	{
		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
	}

	Object initWithCoder (NSCoder aDecoder)
	{
		return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
	}

	this (NSCoder aDecoder)
	{
		typeof(this).alloc.initWithCoder(aDecoder);
	}
}