Mercurial > projects > dstep
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSFormatter; | 7 module dstep.foundation.NSFormatter; |
8 | 8 |
9 import dstep.foundation.NSAttributedString; | 9 import dstep.foundation.NSAttributedString; |
10 import dstep.foundation.NSCoder; | |
10 import dstep.foundation.NSDictionary; | 11 import dstep.foundation.NSDictionary; |
11 import dstep.foundation.NSObject; | 12 import dstep.foundation.NSObject; |
12 import dstep.foundation.NSRange; | 13 import dstep.foundation.NSRange; |
13 import dstep.foundation.NSString; | 14 import dstep.foundation.NSString; |
15 import dstep.foundation.NSZone; | |
14 import dstep.objc.bridge.Bridge; | 16 import dstep.objc.bridge.Bridge; |
15 import dstep.objc.objc : id; | 17 import dstep.objc.objc; |
16 | 18 |
17 class NSFormatter : NSObject, INSCopying, INSCoding | 19 class NSFormatter : NSObject, INSCopying, INSCoding |
18 { | 20 { |
19 mixin ObjcWrap; | 21 mixin (ObjcWrap); |
22 | |
23 this () | |
24 { | |
25 super(typeof(this).alloc.init.objcObject); | |
26 } | |
27 | |
28 typeof(this) init () | |
29 { | |
30 return invokeObjcSelf!(typeof(this), "init"); | |
31 } | |
20 | 32 |
21 NSString stringForObjectValue (Object obj) | 33 NSString stringForObjectValue (Object obj) |
22 { | 34 { |
23 return invokeObjcSelf!(NSString, "stringForObjectValue:", Object)(obj); | 35 return invokeObjcSelf!(NSString, "stringForObjectValue:", Object)(obj); |
24 } | 36 } |
31 NSString editingStringForObjectValue (Object obj) | 43 NSString editingStringForObjectValue (Object obj) |
32 { | 44 { |
33 return invokeObjcSelf!(NSString, "editingStringForObjectValue:", Object)(obj); | 45 return invokeObjcSelf!(NSString, "editingStringForObjectValue:", Object)(obj); |
34 } | 46 } |
35 | 47 |
36 bool getObjectValue (id* obj, NSString string, NSString** error) | 48 bool getObjectValue (out NSObject obj, NSString string, ref NSString error) |
37 { | 49 { |
38 return invokeObjcSelf!(bool, "getObjectValue:forString:errorDescription:", id*, NSString, NSString**)(obj, string, error); | 50 id err; |
51 id object; | |
52 | |
53 if (error) | |
54 err = new objc_object; | |
55 | |
56 bool result = invokeObjcSelf!(bool, "getObjectValue:forString:errorDescription:", id*, NSString, id*)(&object, string, &err); | |
57 | |
58 if (err) | |
59 error = new NSString(err); | |
60 | |
61 if (object) | |
62 obj = new NSObject(object); | |
63 | |
64 return result; | |
39 } | 65 } |
40 | 66 |
41 bool isPartialStringValid (NSString partialString, NSString** newString, NSString** error) | 67 bool isPartialStringValid (NSString partialString, out NSString newString, ref NSString error) |
42 { | 68 { |
43 return invokeObjcSelf!(bool, "isPartialStringValid:newEditingString:errorDescription:", NSString, NSString**, NSString**)(partialString, newString, error); | 69 id err; |
70 id newStr = new objc_object; | |
71 | |
72 if (error) | |
73 err = new objc_object; | |
74 | |
75 bool result = invokeObjcSelf!(bool, "isPartialStringValid:newEditingString:errorDescription:", NSString, id*, id*)(partialString, &newStr, &err); | |
76 | |
77 if (err) | |
78 error = new NSString(err); | |
79 | |
80 if (newStr) | |
81 newString = new NSString(newStr); | |
82 | |
83 return result; | |
44 } | 84 } |
45 | 85 |
46 bool isPartialStringValid (NSString** partialStringPtr, NSRangePointer proposedSelRangePtr, NSString origString, NSRange origSelRange, NSString** error) | 86 bool isPartialStringValid (ref NSString partialStringPtr, NSRangePointer proposedSelRangePtr, NSString origString, NSRange origSelRange, ref NSString error) |
47 { | 87 { |
48 return invokeObjcSelf!(bool, "isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:", NSString**, NSRangePointer, NSString, NSRange, NSString**)(partialStringPtr, proposedSelRangePtr, origString, origSelRange, error); | 88 id partialString = new objc_object; |
89 id err; | |
90 | |
91 if (error) | |
92 err = new objc_object; | |
93 | |
94 bool result = invokeObjcSelf!(bool, "isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:", id*, NSRangePointer, NSString, NSRange, id*)(&partialString, proposedSelRangePtr, origString, origSelRange, &err); | |
95 | |
96 if (err) | |
97 error = new NSString(err); | |
98 | |
99 if (partialString) | |
100 partialStringPtr = new NSString(partialString); | |
101 | |
102 return result; | |
49 } | 103 } |
50 | 104 |
51 Object copyWithZone (NSZone* zone) | 105 Object copyWithZone (NSZone* zone) |
52 { | 106 { |
53 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | 107 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); |
63 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 117 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
64 } | 118 } |
65 | 119 |
66 this (NSCoder aDecoder) | 120 this (NSCoder aDecoder) |
67 { | 121 { |
68 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 122 typeof(this).alloc.initWithCoder(aDecoder); |
69 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
70 | |
71 if (result) | |
72 objcObject = ret; | |
73 | |
74 dObject = this; | |
75 } | 123 } |
76 } | 124 } |
77 | 125 |