view dstep/foundation/NSRunLoop.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 7ff919f595d5
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.NSRunLoop;

import dstep.corefoundation.CFRunLoop;
import dstep.foundation.NSArray;
import dstep.foundation.NSDate;
import dstep.foundation.NSObject;
import dstep.foundation.NSPort;
import dstep.foundation.NSTimer;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc : id;

import bindings = dstep.foundation.NSRunLoop_bindings;

const NSString NSDefaultRunLoopMode;
const NSString NSRunLoopCommonModes;

static this ()
{
	NSDefaultRunLoopMode = new NSString(bindings.NSDefaultRunLoopMode);
	NSRunLoopCommonModes = new NSString(bindings.NSRunLoopCommonModes);
}

class NSRunLoop : NSObject
{
	mixin ObjcWrap;
	mixin TNSOrderedPerform;
	mixin TNSRunLoopConveniences;

	static NSRunLoop currentRunLoop ()
	{
		return invokeObjcSelfClass!(NSRunLoop, "currentRunLoop"return result is this.objcObject ? this : (result !is null ? new NSRunLoop(result) : null);	}

	static NSRunLoop mainRunLoop ()
	{
		return invokeObjcSelfClass!(NSRunLoop, "mainRunLoop"return result is this.objcObject ? this : (result !is null ? new NSRunLoop(result) : null);	}

	NSString currentMode ()
	{
		return invokeObjcSelf!(NSString, "currentMode");
	}

	CFRunLoopRef getCFRunLoop ()
	{
		return invokeObjcSelf!(CFRunLoopRef, "getCFRunLoop");
	}

	void addTimer (NSTimer timer, NSString mode)
	{
		return invokeObjcSelf!(void, "addTimer:forMode:", NSTimer, NSString)(timer, mode);
	}

	void addPort (NSPort aPort, NSString mode)
	{
		return invokeObjcSelf!(void, "addPort:forMode:", NSPort, NSString)(aPort, mode);
	}

	void removePort (NSPort aPort, NSString mode)
	{
		return invokeObjcSelf!(void, "removePort:forMode:", NSPort, NSString)(aPort, mode);
	}

	NSDate limitDateForMode (NSString mode)
	{
		return invokeObjcSelf!(NSDate, "limitDateForMode:", NSString)(mode);
	}

	void acceptInputForMode (NSString mode, NSDate limitDate)
	{
		return invokeObjcSelf!(void, "acceptInputForMode:beforeDate:", NSString, NSDate)(mode, limitDate);
	}
}

template TNSOrderedPerform ()
{
	void performSelector (SEL aSelector, Object target, Object arg, NSUInteger order, NSArray modes)
	{
		return invokeObjcSelf!(void, "performSelector:target:argument:order:modes:", SEL, Object, Object, NSUInteger, NSArray)(aSelector, target, arg, order, modes);
	}

	void cancelPerformSelector (SEL aSelector, Object target, Object arg)
	{
		return invokeObjcSelf!(void, "cancelPerformSelector:target:argument:", SEL, Object, Object)(aSelector, target, arg);
	}

	void cancelPerformSelectorsWithTarget (Object target)
	{
		return invokeObjcSelf!(void, "cancelPerformSelectorsWithTarget:", Object)(target);
	}
}

template TNSDelayedPerforming ()
{
	void performSelector (SEL aSelector, Object anArgument, double delay, NSArray modes);
	void performSelector (SEL aSelector, Object anArgument, double delay);
	static void cancelPreviousPerformRequestsWithTarget (Object aTarget, SEL aSelector, Object anArgument);
	static void cancelPreviousPerformRequestsWithTarget (Object aTarget);
}

template TNSRunLoopConveniences ()
{
	void run ()
	{
		return invokeObjcSelf!(void, "run");
	}

	void runUntilDate (NSDate limitDate)
	{
		return invokeObjcSelf!(void, "runUntilDate:", NSDate)(limitDate);
	}

	bool runMode (NSString mode, NSDate limitDate)
	{
		return invokeObjcSelf!(bool, "runMode:beforeDate:", NSString, NSDate)(mode, limitDate);
	}

	void configureAsServer ()
	{
		return invokeObjcSelf!(void, "configureAsServer");
	}
}