Mercurial > projects > dstep
comparison dstep/foundation/NSAttributedString.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
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.NSAttributedString; | |
8 | |
9 import dstep.foundation.NSDictionary; | |
10 import dstep.foundation.NSString; | |
11 import dstep.objc.bridge.Bridge; | |
12 import dstep.objc.objc : id; | |
13 | |
14 class NSMutableAttributedString : NSAttributedString | |
15 { | |
16 mixin ObjcWrap; | |
17 mixin TNSExtendedMutableAttributedString; | |
18 | |
19 void replaceCharactersInRange (NSRange range, NSString str) | |
20 { | |
21 return invokeObjcSelf!(void, "replaceCharactersInRange:withString:", NSRange, NSString)(range, str); | |
22 } | |
23 | |
24 void setAttributes (NSDictionary attrs, NSRange range) | |
25 { | |
26 return invokeObjcSelf!(void, "setAttributes:range:", NSDictionary, NSRange)(attrs, range); | |
27 } | |
28 } | |
29 | |
30 class NSAttributedString : NSObject, INSCopying, INSMutableCopying, INSCoding | |
31 { | |
32 mixin ObjcWrap; | |
33 mixin TNSExtendedAttributedString; | |
34 | |
35 NSString string () | |
36 { | |
37 return invokeObjcSelf!(NSString, "string"); | |
38 } | |
39 | |
40 NSDictionary attributesAtIndex (NSUInteger location, NSRangePointer range) | |
41 { | |
42 return invokeObjcSelf!(NSDictionary, "attributesAtIndex:effectiveRange:", NSUInteger, NSRangePointer)(location, range); | |
43 } | |
44 | |
45 Object copyWithZone (NSZone* zone) | |
46 { | |
47 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
48 } | |
49 | |
50 Object mutableCopyWithZone (NSZone* zone) | |
51 { | |
52 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); | |
53 } | |
54 | |
55 void encodeWithCoder (NSCoder aCoder) | |
56 { | |
57 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
58 } | |
59 | |
60 Object initWithCoder (NSCoder aDecoder) | |
61 { | |
62 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
63 } | |
64 | |
65 this (NSCoder aDecoder) | |
66 { | |
67 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
68 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
69 | |
70 if (result) | |
71 objcObject = ret; | |
72 | |
73 dObject = this; | |
74 } | |
75 } | |
76 | |
77 template TNSExtendedAttributedString () | |
78 { | |
79 NSUInteger length () | |
80 { | |
81 return invokeObjcSelf!(NSUInteger, "length"); | |
82 } | |
83 | |
84 Object attribute (NSString attrName, NSUInteger location, NSRangePointer range) | |
85 { | |
86 return invokeObjcSelf!(Object, "attribute:atIndex:effectiveRange:", NSString, NSUInteger, NSRangePointer)(attrName, location, range); | |
87 } | |
88 | |
89 NSAttributedString attributedSubstringFromRange (NSRange range) | |
90 { | |
91 return invokeObjcSelf!(NSAttributedString, "attributedSubstringFromRange:", NSRange)(range); | |
92 } | |
93 | |
94 NSDictionary attributesAtIndex (NSUInteger location, NSRangePointer range, NSRange rangeLimit) | |
95 { | |
96 return invokeObjcSelf!(NSDictionary, "attributesAtIndex:longestEffectiveRange:inRange:", NSUInteger, NSRangePointer, NSRange)(location, range, rangeLimit); | |
97 } | |
98 | |
99 Object attribute (NSString attrName, NSUInteger location, NSRangePointer range, NSRange rangeLimit) | |
100 { | |
101 return invokeObjcSelf!(Object, "attribute:atIndex:longestEffectiveRange:inRange:", NSString, NSUInteger, NSRangePointer, NSRange)(attrName, location, range, rangeLimit); | |
102 } | |
103 | |
104 bool isEqualToAttributedString (NSAttributedString other) | |
105 { | |
106 return invokeObjcSelf!(bool, "isEqualToAttributedString:", NSAttributedString)(other); | |
107 } | |
108 | |
109 Object initWithString (NSString str) | |
110 { | |
111 return invokeObjcSelf!(Object, "initWithString:", NSString)(str); | |
112 } | |
113 | |
114 this (NSString str) | |
115 { | |
116 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
117 id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, str); | |
118 | |
119 if (result) | |
120 objcObject = ret; | |
121 | |
122 dObject = this; | |
123 } | |
124 | |
125 Object initWithString (NSString str, NSDictionary attrs) | |
126 { | |
127 return invokeObjcSelf!(Object, "initWithString:attributes:", NSString, NSDictionary)(str, attrs); | |
128 } | |
129 | |
130 this (NSString str, NSDictionary attrs) | |
131 { | |
132 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
133 id result = Bridge.invokeObjcMethod!(id, "initWithString:attributes:", NSString, NSDictionary)(objcObject, str, attrs); | |
134 | |
135 if (result) | |
136 objcObject = ret; | |
137 | |
138 dObject = this; | |
139 } | |
140 | |
141 Object initWithAttributedString (NSAttributedString attrStr) | |
142 { | |
143 return invokeObjcSelf!(Object, "initWithAttributedString:", NSAttributedString)(attrStr); | |
144 } | |
145 | |
146 this (NSAttributedString attrStr) | |
147 { | |
148 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
149 id result = Bridge.invokeObjcMethod!(id, "initWithAttributedString:", NSAttributedString)(objcObject, attrStr); | |
150 | |
151 if (result) | |
152 objcObject = ret; | |
153 | |
154 dObject = this; | |
155 } | |
156 } | |
157 | |
158 template TNSExtendedMutableAttributedString () | |
159 { | |
160 NSMutableString mutableString () | |
161 { | |
162 return invokeObjcSelf!(NSMutableString, "mutableString"); | |
163 } | |
164 | |
165 void addAttribute (NSString name, Object value, NSRange range) | |
166 { | |
167 return invokeObjcSelf!(void, "addAttribute:value:range:", NSString, Object, NSRange)(name, value, range); | |
168 } | |
169 | |
170 void addAttributes (NSDictionary attrs, NSRange range) | |
171 { | |
172 return invokeObjcSelf!(void, "addAttributes:range:", NSDictionary, NSRange)(attrs, range); | |
173 } | |
174 | |
175 void removeAttribute (NSString name, NSRange range) | |
176 { | |
177 return invokeObjcSelf!(void, "removeAttribute:range:", NSString, NSRange)(name, range); | |
178 } | |
179 | |
180 void replaceCharactersInRange (NSRange range, NSAttributedString attrString) | |
181 { | |
182 return invokeObjcSelf!(void, "replaceCharactersInRange:withAttributedString:", NSRange, NSAttributedString)(range, attrString); | |
183 } | |
184 | |
185 void insertAttributedString (NSAttributedString attrString, NSUInteger loc) | |
186 { | |
187 return invokeObjcSelf!(void, "insertAttributedString:atIndex:", NSAttributedString, NSUInteger)(attrString, loc); | |
188 } | |
189 | |
190 void appendAttributedString (NSAttributedString attrString) | |
191 { | |
192 return invokeObjcSelf!(void, "appendAttributedString:", NSAttributedString)(attrString); | |
193 } | |
194 | |
195 void deleteCharactersInRange (NSRange range) | |
196 { | |
197 return invokeObjcSelf!(void, "deleteCharactersInRange:", NSRange)(range); | |
198 } | |
199 | |
200 void setAttributedString (NSAttributedString attrString) | |
201 { | |
202 return invokeObjcSelf!(void, "setAttributedString:", NSAttributedString)(attrString); | |
203 } | |
204 | |
205 void beginEditing () | |
206 { | |
207 return invokeObjcSelf!(void, "beginEditing"); | |
208 } | |
209 | |
210 void endEditing () | |
211 { | |
212 return invokeObjcSelf!(void, "endEditing"); | |
213 } | |
214 } | |
215 |