Mercurial > projects > dstep
diff dstep/foundation/NSAttributedString.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 diff
--- a/dstep/foundation/NSAttributedString.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSAttributedString.d Sun Jan 03 22:06:11 2010 +0100 @@ -6,76 +6,28 @@ */ module dstep.foundation.NSAttributedString; +/*import dstep.appkit.NSFileWrapper; +import dstep.appkit.NSStringDrawing; +import dstep.appkit.NSTextAttachment; +import dstep.appkit.NSTextList; +import dstep.appkit.NSTextTable;*/ +import dstep.foundation.NSArray; +import dstep.foundation.NSCoder; +import dstep.foundation.NSData; +import dstep.foundation.NSError; import dstep.foundation.NSDictionary; +import dstep.foundation.NSGeometry; +import dstep.foundation.NSObjCRuntime; +import dstep.foundation.NSObject; +import dstep.foundation.NSRange; import dstep.foundation.NSString; +import dstep.foundation.NSURL; +import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; - -class NSMutableAttributedString : NSAttributedString -{ - mixin ObjcWrap; - mixin TNSExtendedMutableAttributedString; - - void replaceCharactersInRange (NSRange range, NSString str) - { - return invokeObjcSelf!(void, "replaceCharactersInRange:withString:", NSRange, NSString)(range, str); - } - - void setAttributes (NSDictionary attrs, NSRange range) - { - return invokeObjcSelf!(void, "setAttributes:range:", NSDictionary, NSRange)(attrs, range); - } -} - -class NSAttributedString : NSObject, INSCopying, INSMutableCopying, INSCoding -{ - mixin ObjcWrap; - mixin TNSExtendedAttributedString; - - NSString string () - { - return invokeObjcSelf!(NSString, "string"); - } +import dstep.objc.objc; - NSDictionary attributesAtIndex (NSUInteger location, NSRangePointer range) - { - return invokeObjcSelf!(NSDictionary, "attributesAtIndex:effectiveRange:", NSUInteger, NSRangePointer)(location, range); - } - - Object copyWithZone (NSZone* zone) - { - return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); - } - - Object mutableCopyWithZone (NSZone* zone) - { - return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); - } - - void encodeWithCoder (NSCoder aCoder) - { - return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); - } +const TNSExtendedAttributedString = ` - Object initWithCoder (NSCoder aDecoder) - { - return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); - } - - this (NSCoder aDecoder) - { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); - - if (result) - objcObject = ret; - - dObject = this; - } -} - -template TNSExtendedAttributedString () -{ NSUInteger length () { return invokeObjcSelf!(NSUInteger, "length"); @@ -113,13 +65,7 @@ this (NSString str) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, str); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithString(str); } Object initWithString (NSString str, NSDictionary attrs) @@ -129,13 +75,7 @@ this (NSString str, NSDictionary attrs) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithString:attributes:", NSString, NSDictionary)(objcObject, str, attrs); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithString(str, attrs); } Object initWithAttributedString (NSAttributedString attrStr) @@ -145,18 +85,12 @@ this (NSAttributedString attrStr) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithAttributedString:", NSAttributedString)(objcObject, attrStr); - - if (result) - objcObject = ret; + typeof(this).alloc.initWithAttributedString(attrStr); + } +`; - dObject = this; - } -} +const TNSExtendedMutableAttributedString = ` -template TNSExtendedMutableAttributedString () -{ NSMutableString mutableString () { return invokeObjcSelf!(NSMutableString, "mutableString"); @@ -211,5 +145,272 @@ { return invokeObjcSelf!(void, "endEditing"); } +`; + +class NSMutableAttributedString : NSAttributedString +{ + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + + void replaceCharactersInRange (NSRange range, NSString str) + { + return invokeObjcSelf!(void, "replaceCharactersInRange:withString:", NSRange, NSString)(range, str); + } + + void setAttributes (NSDictionary attrs, NSRange range) + { + return invokeObjcSelf!(void, "setAttributes:range:", NSDictionary, NSRange)(attrs, range); + } + + // NSExtendedMutableAttributedString + /*NSMutableString mutableString () + { + return invokeObjcSelf!(NSMutableString, "mutableString"); + }*/ + + void addAttribute (NSString name, Object value, NSRange range) + { + return invokeObjcSelf!(void, "addAttribute:value:range:", NSString, Object, NSRange)(name, value, range); + } + + void addAttributes (NSDictionary attrs, NSRange range) + { + return invokeObjcSelf!(void, "addAttributes:range:", NSDictionary, NSRange)(attrs, range); + } + + void removeAttribute (NSString name, NSRange range) + { + return invokeObjcSelf!(void, "removeAttribute:range:", NSString, NSRange)(name, range); + } + + void replaceCharactersInRange (NSRange range, NSAttributedString attrString) + { + return invokeObjcSelf!(void, "replaceCharactersInRange:withAttributedString:", NSRange, NSAttributedString)(range, attrString); + } + + void insertAttributedString (NSAttributedString attrString, NSUInteger loc) + { + return invokeObjcSelf!(void, "insertAttributedString:atIndex:", NSAttributedString, NSUInteger)(attrString, loc); + } + + void appendAttributedString (NSAttributedString attrString) + { + return invokeObjcSelf!(void, "appendAttributedString:", NSAttributedString)(attrString); + } + + void deleteCharactersInRange (NSRange range) + { + return invokeObjcSelf!(void, "deleteCharactersInRange:", NSRange)(range); + } + + void setAttributedString (NSAttributedString attrString) + { + return invokeObjcSelf!(void, "setAttributedString:", NSAttributedString)(attrString); + } + + /*void beginEditing () + { + return invokeObjcSelf!(void, "beginEditing"); + } + + void endEditing () + { + return invokeObjcSelf!(void, "endEditing"); + }*/ + + // NSMutableAttributedStringKitAdditions + bool readFromURL (NSURL url, NSDictionary opts, ref NSDictionary dict, ref NSError error) + { + id __arg2; + id __arg3; + + if (dict) + __arg2 = dict.objcObject; + + if (error) + __arg3 = error.objcObject; + + bool result = invokeObjcSelf!(bool, "readFromURL:options:documentAttributes:error:", NSURL, NSDictionary, id*, id*)(url, opts, &__arg2, &__arg3); + + if (__arg2) + dict = new NSDictionary(__arg2); + if (__arg3) + error = new NSError(__arg3); + + return result; + } + + bool readFromData (NSData data, NSDictionary opts, ref NSDictionary dict, ref NSError error) + { + id __arg2; + id __arg3; + + if (dict) + __arg2 = dict.objcObject; + + if (error) + __arg3 = error.objcObject; + + bool result = invokeObjcSelf!(bool, "readFromData:options:documentAttributes:error:", NSData, NSDictionary, id*, id*)(data, opts, &__arg2, &__arg3); + + if (__arg2) + dict = new NSDictionary(__arg2); + if (__arg3) + error = new NSError(__arg3); + + return result; + } + + bool readFromURL (NSURL url, NSDictionary options, ref NSDictionary dict) + { + id __arg2; + + if (dict) + __arg2 = dict.objcObject; + + bool result = invokeObjcSelf!(bool, "readFromURL:options:documentAttributes:", NSURL, NSDictionary, id*)(url, options, &__arg2); + + if (__arg2) + dict = new NSDictionary(__arg2); + + return result; + } + + bool readFromData (NSData data, NSDictionary options, ref NSDictionary dict) + { + id __arg2; + + if (dict) + __arg2 = dict.objcObject; + + bool result = invokeObjcSelf!(bool, "readFromData:options:documentAttributes:", NSData, NSDictionary, id*)(data, options, &__arg2); + + if (__arg2) + dict = new NSDictionary(__arg2); + + return result; + } + + void superscriptRange (NSRange range) + { + return invokeObjcSelf!(void, "superscriptRange:", NSRange)(range); + } + + void subscriptRange (NSRange range) + { + return invokeObjcSelf!(void, "subscriptRange:", NSRange)(range); + } + + void unscriptRange (NSRange range) + { + return invokeObjcSelf!(void, "unscriptRange:", NSRange)(range); + } + + void applyFontTraits (uint traitMask, NSRange range) + { + return invokeObjcSelf!(void, "applyFontTraits:range:", uint, NSRange)(traitMask, range); + } + + void setAlignment (uint alignment, NSRange range) + { + return invokeObjcSelf!(void, "setAlignment:range:", uint, NSRange)(alignment, range); + } + + void setBaseWritingDirection (int writingDirection, NSRange range) + { + return invokeObjcSelf!(void, "setBaseWritingDirection:range:", int, NSRange)(writingDirection, range); + } + + void fixAttributesInRange (NSRange range) + { + return invokeObjcSelf!(void, "fixAttributesInRange:", NSRange)(range); + } + + void fixFontAttributeInRange (NSRange range) + { + return invokeObjcSelf!(void, "fixFontAttributeInRange:", NSRange)(range); + } + + void fixParagraphStyleAttributeInRange (NSRange range) + { + return invokeObjcSelf!(void, "fixParagraphStyleAttributeInRange:", NSRange)(range); + } + + void fixAttachmentAttributeInRange (NSRange range) + { + return invokeObjcSelf!(void, "fixAttachmentAttributeInRange:", NSRange)(range); + } + + // NSMutableAttributedStringAttachmentConveniences + void updateAttachmentsFromPath (NSString path) + { + return invokeObjcSelf!(void, "updateAttachmentsFromPath:", NSString)(path); + } } +class NSAttributedString : NSObject, INSCopying, INSMutableCopying, INSCoding +{ + mixin (ObjcWrap); + + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + + NSString string () + { + return invokeObjcSelf!(NSString, "string"); + } + + NSDictionary attributesAtIndex (NSUInteger location, NSRangePointer range) + { + return invokeObjcSelf!(NSDictionary, "attributesAtIndex:effectiveRange:", NSUInteger, NSRangePointer)(location, range); + } + + Object copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); + } + + Object mutableCopyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "mutableCopyWithZone:", 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); + } + + mixin (TNSExtendedAttributedString); + //mixin (TNSAttributedStringAttachmentConveniences); + //mixin (dstep.appkit.NSAttributedString.TNSExtendedAttributedString); + //mixin (dstep.appkit.NSAttributedString.TNSDeprecatedKitAdditions); + //mixin (TNSStringDrawing); + //mixin (dstep.appkit.NSAttributedString.TNSAttributedStringKitAdditions); +} \ No newline at end of file