Mercurial > projects > dstep
diff dstep/appkit/NSNib.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 | |
children | b9de51448c6b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/appkit/NSNib.d Sun Jan 03 22:06:11 2010 +0100 @@ -0,0 +1,106 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Sep 24, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.appkit.NSNib; + +import dstep.appkit.AppKitDefines; +import dstep.foundation.NSArray; +import dstep.foundation.NSBundle; +import dstep.foundation.NSCoder; +import dstep.foundation.NSData; +import dstep.foundation.NSDictionary; +import dstep.foundation.NSObject; +import dstep.foundation.NSString; +import dstep.foundation.NSURL; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc; + +import bindings = dstep.appkit.NSNib_bindings; + +private +{ + NSString NSNibOwner_; + NSString NSNibTopLevelObjects_; +} + +NSString NSNibOwner () +{ + if (NSNibOwner_) + return NSNibOwner_; + + return NSNibOwner_ = new NSString(bindings.NSNibOwner); +} + +NSString NSNibTopLevelObjects () +{ + if (NSNibTopLevelObjects_) + return NSNibTopLevelObjects_; + + return NSNibTopLevelObjects_ = new NSString(bindings.NSNibTopLevelObjects); +} + +class NSNib : NSObject, INSCoding +{ + mixin (ObjcWrap); + + this (NSCoder aDecoder) + { + super(typeof(this).alloc.initWithCoder(aDecoder).objcObject); + } + + void encodeWithCoder (NSCoder aCoder) + { + return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); + } + + typeof(this) initWithCoder (NSCoder aDecoder) + { + return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder); + } + + NSNib initWithContentsOfURL (NSURL nibFileURL) + { + id result = invokeObjcSelf!(id, "initWithContentsOfURL:", NSURL)(nibFileURL); + return result is this.objcObject ? this : (result !is null ? new NSNib(result) : null); + } + + this (NSURL nibFileURL) + { + super(NSNib.alloc.initWithContentsOfURL(nibFileURL).objcObject); + } + + NSNib initWithNibNamed (NSString nibName, NSBundle bundle) + { + id result = invokeObjcSelf!(id, "initWithNibNamed:bundle:", NSString, NSBundle)(nibName, bundle); + return result is this.objcObject ? this : (result !is null ? new NSNib(result) : null); + } + + this (NSString nibName, NSBundle bundle) + { + super(NSNib.alloc.initWithNibNamed(nibName, bundle).objcObject); + } + + bool instantiateNibWithExternalNameTable (NSDictionary externalNameTable) + { + return invokeObjcSelf!(bool, "instantiateNibWithExternalNameTable:", NSDictionary)(externalNameTable); + } + + bool instantiateNibWithOwner (Object owner, ref NSArray topLevelObjects) + { + id objects; + + if (topLevelObjects) + objects = topLevelObjects.objcObject; + + bool result = invokeObjcSelf!(bool, "instantiateNibWithOwner:topLevelObjects:", Object, id*)(owner, &objects); + + if (objects) + topLevelObjects = new NSArray(objects); + + return result; + } +} +