Mercurial > projects > dstep
annotate dstep/foundation/NSFormatter.d @ 25:b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 06 Apr 2010 11:37:27 +0200 |
parents | 19885b43130e |
children |
rev | line source |
---|---|
14 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSFormatter; | |
8 | |
9 import dstep.foundation.NSAttributedString; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
10 import dstep.foundation.NSCoder; |
14 | 11 import dstep.foundation.NSDictionary; |
12 import dstep.foundation.NSObject; | |
13 import dstep.foundation.NSRange; | |
14 import dstep.foundation.NSString; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
15 import dstep.foundation.NSZone; |
14 | 16 import dstep.objc.bridge.Bridge; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
17 import dstep.objc.objc; |
14 | 18 |
19 class NSFormatter : NSObject, INSCopying, INSCoding | |
20 { | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
21 mixin ObjcWrap; |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
22 |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
23 this (id object) |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
24 { |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
25 super(object); |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
26 } |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
27 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
28 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
29 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
30 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
31 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
32 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
33 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
34 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
35 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
36 } |
14 | 37 |
38 NSString stringForObjectValue (Object obj) | |
39 { | |
40 return invokeObjcSelf!(NSString, "stringForObjectValue:", Object)(obj); | |
41 } | |
42 | |
43 NSAttributedString attributedStringForObjectValue (Object obj, NSDictionary attrs) | |
44 { | |
45 return invokeObjcSelf!(NSAttributedString, "attributedStringForObjectValue:withDefaultAttributes:", Object, NSDictionary)(obj, attrs); | |
46 } | |
47 | |
48 NSString editingStringForObjectValue (Object obj) | |
49 { | |
50 return invokeObjcSelf!(NSString, "editingStringForObjectValue:", Object)(obj); | |
51 } | |
52 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
53 bool getObjectValue (out NSObject obj, NSString string, ref NSString error) |
14 | 54 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
55 id err; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
56 id object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
57 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
58 if (error) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
59 err = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
60 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
61 bool result = invokeObjcSelf!(bool, "getObjectValue:forString:errorDescription:", id*, NSString, id*)(&object, string, &err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
62 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
63 if (err) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
64 error = new NSString(err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
65 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
66 if (object) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
67 obj = new NSObject(object); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
68 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
69 return result; |
14 | 70 } |
71 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
72 bool isPartialStringValid (NSString partialString, out NSString newString, ref NSString error) |
14 | 73 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
74 id err; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
75 id newStr = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
76 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
77 if (error) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
78 err = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
79 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
80 bool result = invokeObjcSelf!(bool, "isPartialStringValid:newEditingString:errorDescription:", NSString, id*, id*)(partialString, &newStr, &err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
81 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
82 if (err) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
83 error = new NSString(err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
84 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
85 if (newStr) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
86 newString = new NSString(newStr); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
87 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
88 return result; |
14 | 89 } |
90 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
91 bool isPartialStringValid (ref NSString partialStringPtr, NSRangePointer proposedSelRangePtr, NSString origString, NSRange origSelRange, ref NSString error) |
14 | 92 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
93 id partialString = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
94 id err; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
95 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
96 if (error) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
97 err = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
98 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
99 bool result = invokeObjcSelf!(bool, "isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:", id*, NSRangePointer, NSString, NSRange, id*)(&partialString, proposedSelRangePtr, origString, origSelRange, &err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
100 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
101 if (err) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
102 error = new NSString(err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
103 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
104 if (partialString) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
105 partialStringPtr = new NSString(partialString); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
106 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
107 return result; |
14 | 108 } |
109 | |
110 Object copyWithZone (NSZone* zone) | |
111 { | |
112 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
113 } | |
114 | |
115 void encodeWithCoder (NSCoder aCoder) | |
116 { | |
117 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
118 } | |
119 | |
120 Object initWithCoder (NSCoder aDecoder) | |
121 { | |
122 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
123 } | |
124 | |
125 this (NSCoder aDecoder) | |
126 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
127 typeof(this).alloc.initWithCoder(aDecoder); |
14 | 128 } |
129 } | |
130 |