Mercurial > projects > dstep
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
4 * Version: Initial created: Aug 3, 2009 | 4 * Version: Initial created: Aug 3, 2009 |
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.NSAttributedString; | 7 module dstep.foundation.NSAttributedString; |
8 | 8 |
9 /*import dstep.appkit.NSFileWrapper; | |
10 import dstep.appkit.NSStringDrawing; | |
11 import dstep.appkit.NSTextAttachment; | |
12 import dstep.appkit.NSTextList; | |
13 import dstep.appkit.NSTextTable;*/ | |
14 import dstep.foundation.NSArray; | |
15 import dstep.foundation.NSCoder; | |
16 import dstep.foundation.NSData; | |
17 import dstep.foundation.NSError; | |
9 import dstep.foundation.NSDictionary; | 18 import dstep.foundation.NSDictionary; |
19 import dstep.foundation.NSGeometry; | |
20 import dstep.foundation.NSObjCRuntime; | |
21 import dstep.foundation.NSObject; | |
22 import dstep.foundation.NSRange; | |
10 import dstep.foundation.NSString; | 23 import dstep.foundation.NSString; |
24 import dstep.foundation.NSURL; | |
25 import dstep.foundation.NSZone; | |
11 import dstep.objc.bridge.Bridge; | 26 import dstep.objc.bridge.Bridge; |
12 import dstep.objc.objc : id; | 27 import dstep.objc.objc; |
28 | |
29 const TNSExtendedAttributedString = ` | |
30 | |
31 NSUInteger length () | |
32 { | |
33 return invokeObjcSelf!(NSUInteger, "length"); | |
34 } | |
35 | |
36 Object attribute (NSString attrName, NSUInteger location, NSRangePointer range) | |
37 { | |
38 return invokeObjcSelf!(Object, "attribute:atIndex:effectiveRange:", NSString, NSUInteger, NSRangePointer)(attrName, location, range); | |
39 } | |
40 | |
41 NSAttributedString attributedSubstringFromRange (NSRange range) | |
42 { | |
43 return invokeObjcSelf!(NSAttributedString, "attributedSubstringFromRange:", NSRange)(range); | |
44 } | |
45 | |
46 NSDictionary attributesAtIndex (NSUInteger location, NSRangePointer range, NSRange rangeLimit) | |
47 { | |
48 return invokeObjcSelf!(NSDictionary, "attributesAtIndex:longestEffectiveRange:inRange:", NSUInteger, NSRangePointer, NSRange)(location, range, rangeLimit); | |
49 } | |
50 | |
51 Object attribute (NSString attrName, NSUInteger location, NSRangePointer range, NSRange rangeLimit) | |
52 { | |
53 return invokeObjcSelf!(Object, "attribute:atIndex:longestEffectiveRange:inRange:", NSString, NSUInteger, NSRangePointer, NSRange)(attrName, location, range, rangeLimit); | |
54 } | |
55 | |
56 bool isEqualToAttributedString (NSAttributedString other) | |
57 { | |
58 return invokeObjcSelf!(bool, "isEqualToAttributedString:", NSAttributedString)(other); | |
59 } | |
60 | |
61 Object initWithString (NSString str) | |
62 { | |
63 return invokeObjcSelf!(Object, "initWithString:", NSString)(str); | |
64 } | |
65 | |
66 this (NSString str) | |
67 { | |
68 typeof(this).alloc.initWithString(str); | |
69 } | |
70 | |
71 Object initWithString (NSString str, NSDictionary attrs) | |
72 { | |
73 return invokeObjcSelf!(Object, "initWithString:attributes:", NSString, NSDictionary)(str, attrs); | |
74 } | |
75 | |
76 this (NSString str, NSDictionary attrs) | |
77 { | |
78 typeof(this).alloc.initWithString(str, attrs); | |
79 } | |
80 | |
81 Object initWithAttributedString (NSAttributedString attrStr) | |
82 { | |
83 return invokeObjcSelf!(Object, "initWithAttributedString:", NSAttributedString)(attrStr); | |
84 } | |
85 | |
86 this (NSAttributedString attrStr) | |
87 { | |
88 typeof(this).alloc.initWithAttributedString(attrStr); | |
89 } | |
90 `; | |
91 | |
92 const TNSExtendedMutableAttributedString = ` | |
93 | |
94 NSMutableString mutableString () | |
95 { | |
96 return invokeObjcSelf!(NSMutableString, "mutableString"); | |
97 } | |
98 | |
99 void addAttribute (NSString name, Object value, NSRange range) | |
100 { | |
101 return invokeObjcSelf!(void, "addAttribute:value:range:", NSString, Object, NSRange)(name, value, range); | |
102 } | |
103 | |
104 void addAttributes (NSDictionary attrs, NSRange range) | |
105 { | |
106 return invokeObjcSelf!(void, "addAttributes:range:", NSDictionary, NSRange)(attrs, range); | |
107 } | |
108 | |
109 void removeAttribute (NSString name, NSRange range) | |
110 { | |
111 return invokeObjcSelf!(void, "removeAttribute:range:", NSString, NSRange)(name, range); | |
112 } | |
113 | |
114 void replaceCharactersInRange (NSRange range, NSAttributedString attrString) | |
115 { | |
116 return invokeObjcSelf!(void, "replaceCharactersInRange:withAttributedString:", NSRange, NSAttributedString)(range, attrString); | |
117 } | |
118 | |
119 void insertAttributedString (NSAttributedString attrString, NSUInteger loc) | |
120 { | |
121 return invokeObjcSelf!(void, "insertAttributedString:atIndex:", NSAttributedString, NSUInteger)(attrString, loc); | |
122 } | |
123 | |
124 void appendAttributedString (NSAttributedString attrString) | |
125 { | |
126 return invokeObjcSelf!(void, "appendAttributedString:", NSAttributedString)(attrString); | |
127 } | |
128 | |
129 void deleteCharactersInRange (NSRange range) | |
130 { | |
131 return invokeObjcSelf!(void, "deleteCharactersInRange:", NSRange)(range); | |
132 } | |
133 | |
134 void setAttributedString (NSAttributedString attrString) | |
135 { | |
136 return invokeObjcSelf!(void, "setAttributedString:", NSAttributedString)(attrString); | |
137 } | |
138 | |
139 void beginEditing () | |
140 { | |
141 return invokeObjcSelf!(void, "beginEditing"); | |
142 } | |
143 | |
144 void endEditing () | |
145 { | |
146 return invokeObjcSelf!(void, "endEditing"); | |
147 } | |
148 `; | |
13 | 149 |
14 class NSMutableAttributedString : NSAttributedString | 150 class NSMutableAttributedString : NSAttributedString |
15 { | 151 { |
16 mixin ObjcWrap; | 152 mixin (ObjcWrap); |
17 mixin TNSExtendedMutableAttributedString; | 153 |
154 this () | |
155 { | |
156 super(typeof(this).alloc.init.objcObject); | |
157 } | |
158 | |
159 typeof(this) init () | |
160 { | |
161 return invokeObjcSelf!(typeof(this), "init"); | |
162 } | |
18 | 163 |
19 void replaceCharactersInRange (NSRange range, NSString str) | 164 void replaceCharactersInRange (NSRange range, NSString str) |
20 { | 165 { |
21 return invokeObjcSelf!(void, "replaceCharactersInRange:withString:", NSRange, NSString)(range, str); | 166 return invokeObjcSelf!(void, "replaceCharactersInRange:withString:", NSRange, NSString)(range, str); |
22 } | 167 } |
23 | 168 |
24 void setAttributes (NSDictionary attrs, NSRange range) | 169 void setAttributes (NSDictionary attrs, NSRange range) |
25 { | 170 { |
26 return invokeObjcSelf!(void, "setAttributes:range:", NSDictionary, NSRange)(attrs, range); | 171 return invokeObjcSelf!(void, "setAttributes:range:", NSDictionary, NSRange)(attrs, range); |
172 } | |
173 | |
174 // NSExtendedMutableAttributedString | |
175 /*NSMutableString mutableString () | |
176 { | |
177 return invokeObjcSelf!(NSMutableString, "mutableString"); | |
178 }*/ | |
179 | |
180 void addAttribute (NSString name, Object value, NSRange range) | |
181 { | |
182 return invokeObjcSelf!(void, "addAttribute:value:range:", NSString, Object, NSRange)(name, value, range); | |
183 } | |
184 | |
185 void addAttributes (NSDictionary attrs, NSRange range) | |
186 { | |
187 return invokeObjcSelf!(void, "addAttributes:range:", NSDictionary, NSRange)(attrs, range); | |
188 } | |
189 | |
190 void removeAttribute (NSString name, NSRange range) | |
191 { | |
192 return invokeObjcSelf!(void, "removeAttribute:range:", NSString, NSRange)(name, range); | |
193 } | |
194 | |
195 void replaceCharactersInRange (NSRange range, NSAttributedString attrString) | |
196 { | |
197 return invokeObjcSelf!(void, "replaceCharactersInRange:withAttributedString:", NSRange, NSAttributedString)(range, attrString); | |
198 } | |
199 | |
200 void insertAttributedString (NSAttributedString attrString, NSUInteger loc) | |
201 { | |
202 return invokeObjcSelf!(void, "insertAttributedString:atIndex:", NSAttributedString, NSUInteger)(attrString, loc); | |
203 } | |
204 | |
205 void appendAttributedString (NSAttributedString attrString) | |
206 { | |
207 return invokeObjcSelf!(void, "appendAttributedString:", NSAttributedString)(attrString); | |
208 } | |
209 | |
210 void deleteCharactersInRange (NSRange range) | |
211 { | |
212 return invokeObjcSelf!(void, "deleteCharactersInRange:", NSRange)(range); | |
213 } | |
214 | |
215 void setAttributedString (NSAttributedString attrString) | |
216 { | |
217 return invokeObjcSelf!(void, "setAttributedString:", NSAttributedString)(attrString); | |
218 } | |
219 | |
220 /*void beginEditing () | |
221 { | |
222 return invokeObjcSelf!(void, "beginEditing"); | |
223 } | |
224 | |
225 void endEditing () | |
226 { | |
227 return invokeObjcSelf!(void, "endEditing"); | |
228 }*/ | |
229 | |
230 // NSMutableAttributedStringKitAdditions | |
231 bool readFromURL (NSURL url, NSDictionary opts, ref NSDictionary dict, ref NSError error) | |
232 { | |
233 id __arg2; | |
234 id __arg3; | |
235 | |
236 if (dict) | |
237 __arg2 = dict.objcObject; | |
238 | |
239 if (error) | |
240 __arg3 = error.objcObject; | |
241 | |
242 bool result = invokeObjcSelf!(bool, "readFromURL:options:documentAttributes:error:", NSURL, NSDictionary, id*, id*)(url, opts, &__arg2, &__arg3); | |
243 | |
244 if (__arg2) | |
245 dict = new NSDictionary(__arg2); | |
246 if (__arg3) | |
247 error = new NSError(__arg3); | |
248 | |
249 return result; | |
250 } | |
251 | |
252 bool readFromData (NSData data, NSDictionary opts, ref NSDictionary dict, ref NSError error) | |
253 { | |
254 id __arg2; | |
255 id __arg3; | |
256 | |
257 if (dict) | |
258 __arg2 = dict.objcObject; | |
259 | |
260 if (error) | |
261 __arg3 = error.objcObject; | |
262 | |
263 bool result = invokeObjcSelf!(bool, "readFromData:options:documentAttributes:error:", NSData, NSDictionary, id*, id*)(data, opts, &__arg2, &__arg3); | |
264 | |
265 if (__arg2) | |
266 dict = new NSDictionary(__arg2); | |
267 if (__arg3) | |
268 error = new NSError(__arg3); | |
269 | |
270 return result; | |
271 } | |
272 | |
273 bool readFromURL (NSURL url, NSDictionary options, ref NSDictionary dict) | |
274 { | |
275 id __arg2; | |
276 | |
277 if (dict) | |
278 __arg2 = dict.objcObject; | |
279 | |
280 bool result = invokeObjcSelf!(bool, "readFromURL:options:documentAttributes:", NSURL, NSDictionary, id*)(url, options, &__arg2); | |
281 | |
282 if (__arg2) | |
283 dict = new NSDictionary(__arg2); | |
284 | |
285 return result; | |
286 } | |
287 | |
288 bool readFromData (NSData data, NSDictionary options, ref NSDictionary dict) | |
289 { | |
290 id __arg2; | |
291 | |
292 if (dict) | |
293 __arg2 = dict.objcObject; | |
294 | |
295 bool result = invokeObjcSelf!(bool, "readFromData:options:documentAttributes:", NSData, NSDictionary, id*)(data, options, &__arg2); | |
296 | |
297 if (__arg2) | |
298 dict = new NSDictionary(__arg2); | |
299 | |
300 return result; | |
301 } | |
302 | |
303 void superscriptRange (NSRange range) | |
304 { | |
305 return invokeObjcSelf!(void, "superscriptRange:", NSRange)(range); | |
306 } | |
307 | |
308 void subscriptRange (NSRange range) | |
309 { | |
310 return invokeObjcSelf!(void, "subscriptRange:", NSRange)(range); | |
311 } | |
312 | |
313 void unscriptRange (NSRange range) | |
314 { | |
315 return invokeObjcSelf!(void, "unscriptRange:", NSRange)(range); | |
316 } | |
317 | |
318 void applyFontTraits (uint traitMask, NSRange range) | |
319 { | |
320 return invokeObjcSelf!(void, "applyFontTraits:range:", uint, NSRange)(traitMask, range); | |
321 } | |
322 | |
323 void setAlignment (uint alignment, NSRange range) | |
324 { | |
325 return invokeObjcSelf!(void, "setAlignment:range:", uint, NSRange)(alignment, range); | |
326 } | |
327 | |
328 void setBaseWritingDirection (int writingDirection, NSRange range) | |
329 { | |
330 return invokeObjcSelf!(void, "setBaseWritingDirection:range:", int, NSRange)(writingDirection, range); | |
331 } | |
332 | |
333 void fixAttributesInRange (NSRange range) | |
334 { | |
335 return invokeObjcSelf!(void, "fixAttributesInRange:", NSRange)(range); | |
336 } | |
337 | |
338 void fixFontAttributeInRange (NSRange range) | |
339 { | |
340 return invokeObjcSelf!(void, "fixFontAttributeInRange:", NSRange)(range); | |
341 } | |
342 | |
343 void fixParagraphStyleAttributeInRange (NSRange range) | |
344 { | |
345 return invokeObjcSelf!(void, "fixParagraphStyleAttributeInRange:", NSRange)(range); | |
346 } | |
347 | |
348 void fixAttachmentAttributeInRange (NSRange range) | |
349 { | |
350 return invokeObjcSelf!(void, "fixAttachmentAttributeInRange:", NSRange)(range); | |
351 } | |
352 | |
353 // NSMutableAttributedStringAttachmentConveniences | |
354 void updateAttachmentsFromPath (NSString path) | |
355 { | |
356 return invokeObjcSelf!(void, "updateAttachmentsFromPath:", NSString)(path); | |
27 } | 357 } |
28 } | 358 } |
29 | 359 |
30 class NSAttributedString : NSObject, INSCopying, INSMutableCopying, INSCoding | 360 class NSAttributedString : NSObject, INSCopying, INSMutableCopying, INSCoding |
31 { | 361 { |
32 mixin ObjcWrap; | 362 mixin (ObjcWrap); |
33 mixin TNSExtendedAttributedString; | 363 |
364 | |
365 this () | |
366 { | |
367 super(typeof(this).alloc.init.objcObject); | |
368 } | |
369 | |
370 typeof(this) init () | |
371 { | |
372 return invokeObjcSelf!(typeof(this), "init"); | |
373 } | |
34 | 374 |
35 NSString string () | 375 NSString string () |
36 { | 376 { |
37 return invokeObjcSelf!(NSString, "string"); | 377 return invokeObjcSelf!(NSString, "string"); |
38 } | 378 } |
62 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 402 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
63 } | 403 } |
64 | 404 |
65 this (NSCoder aDecoder) | 405 this (NSCoder aDecoder) |
66 { | 406 { |
67 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 407 typeof(this).alloc.initWithCoder(aDecoder); |
68 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | 408 } |
69 | 409 |
70 if (result) | 410 mixin (TNSExtendedAttributedString); |
71 objcObject = ret; | 411 //mixin (TNSAttributedStringAttachmentConveniences); |
72 | 412 //mixin (dstep.appkit.NSAttributedString.TNSExtendedAttributedString); |
73 dObject = this; | 413 //mixin (dstep.appkit.NSAttributedString.TNSDeprecatedKitAdditions); |
74 } | 414 //mixin (TNSStringDrawing); |
415 //mixin (dstep.appkit.NSAttributedString.TNSAttributedStringKitAdditions); | |
75 } | 416 } |
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 |