Mercurial > projects > dstep
comparison dstep/appkit/NSPasteboard.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 | |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Sep 24, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.appkit.NSPasteboard; | |
8 | |
9 import dstep.appkit.AppKitDefines; | |
10 import dstep.appkit.NSFileWrapper; | |
11 import dstep.corefoundation.CFBase; | |
12 import dstep.foundation.NSArray; | |
13 import dstep.foundation.NSData; | |
14 import dstep.foundation.NSDictionary; | |
15 import dstep.foundation.NSObjCRuntime; | |
16 import dstep.foundation.NSObject; | |
17 import dstep.foundation.NSString; | |
18 import dstep.foundation.NSURL; | |
19 import dstep.objc.bridge.Bridge; | |
20 import dstep.objc.objc; | |
21 | |
22 import bindings = dstep.appkit.NSPasteboard_bindings; | |
23 | |
24 private | |
25 { | |
26 NSString NSStringPboardType_; | |
27 NSString NSFilenamesPboardType_; | |
28 NSString NSPostScriptPboardType_; | |
29 NSString NSTIFFPboardType_; | |
30 NSString NSRTFPboardType_; | |
31 NSString NSTabularTextPboardType_; | |
32 NSString NSFontPboardType_; | |
33 NSString NSRulerPboardType_; | |
34 NSString NSFileContentsPboardType_; | |
35 NSString NSColorPboardType_; | |
36 NSString NSRTFDPboardType_; | |
37 NSString NSHTMLPboardType_; | |
38 NSString NSPICTPboardType_; | |
39 NSString NSURLPboardType_; | |
40 NSString NSPDFPboardType_; | |
41 NSString NSVCardPboardType_; | |
42 NSString NSFilesPromisePboardType_; | |
43 NSString NSInkTextPboardType_; | |
44 NSString NSMultipleTextSelectionPboardType_; | |
45 NSString NSGeneralPboard_; | |
46 NSString NSFontPboard_; | |
47 NSString NSRulerPboard_; | |
48 NSString NSFindPboard_; | |
49 NSString NSDragPboard_; | |
50 } | |
51 | |
52 NSString NSStringPboardType () | |
53 { | |
54 if (NSStringPboardType_) | |
55 return NSStringPboardType_; | |
56 | |
57 return NSStringPboardType_ = new NSString(bindings.NSStringPboardType); | |
58 } | |
59 | |
60 NSString NSFilenamesPboardType () | |
61 { | |
62 if (NSFilenamesPboardType_) | |
63 return NSFilenamesPboardType_; | |
64 | |
65 return NSFilenamesPboardType_ = new NSString(bindings.NSFilenamesPboardType); | |
66 } | |
67 | |
68 NSString NSPostScriptPboardType () | |
69 { | |
70 if (NSPostScriptPboardType_) | |
71 return NSPostScriptPboardType_; | |
72 | |
73 return NSPostScriptPboardType_ = new NSString(bindings.NSPostScriptPboardType); | |
74 } | |
75 | |
76 NSString NSTIFFPboardType () | |
77 { | |
78 if (NSTIFFPboardType_) | |
79 return NSTIFFPboardType_; | |
80 | |
81 return NSTIFFPboardType_ = new NSString(bindings.NSTIFFPboardType); | |
82 } | |
83 | |
84 NSString NSRTFPboardType () | |
85 { | |
86 if (NSRTFPboardType_) | |
87 return NSRTFPboardType_; | |
88 | |
89 return NSRTFPboardType_ = new NSString(bindings.NSRTFPboardType); | |
90 } | |
91 | |
92 NSString NSTabularTextPboardType () | |
93 { | |
94 if (NSTabularTextPboardType_) | |
95 return NSTabularTextPboardType_; | |
96 | |
97 return NSTabularTextPboardType_ = new NSString(bindings.NSTabularTextPboardType); | |
98 } | |
99 | |
100 NSString NSFontPboardType () | |
101 { | |
102 if (NSFontPboardType_) | |
103 return NSFontPboardType_; | |
104 | |
105 return NSFontPboardType_ = new NSString(bindings.NSFontPboardType); | |
106 } | |
107 | |
108 NSString NSRulerPboardType () | |
109 { | |
110 if (NSRulerPboardType_) | |
111 return NSRulerPboardType_; | |
112 | |
113 return NSRulerPboardType_ = new NSString(bindings.NSRulerPboardType); | |
114 } | |
115 | |
116 NSString NSFileContentsPboardType () | |
117 { | |
118 if (NSFileContentsPboardType_) | |
119 return NSFileContentsPboardType_; | |
120 | |
121 return NSFileContentsPboardType_ = new NSString(bindings.NSFileContentsPboardType); | |
122 } | |
123 | |
124 NSString NSColorPboardType () | |
125 { | |
126 if (NSColorPboardType_) | |
127 return NSColorPboardType_; | |
128 | |
129 return NSColorPboardType_ = new NSString(bindings.NSColorPboardType); | |
130 } | |
131 | |
132 NSString NSRTFDPboardType () | |
133 { | |
134 if (NSRTFDPboardType_) | |
135 return NSRTFDPboardType_; | |
136 | |
137 return NSRTFDPboardType_ = new NSString(bindings.NSRTFDPboardType); | |
138 } | |
139 | |
140 NSString NSHTMLPboardType () | |
141 { | |
142 if (NSHTMLPboardType_) | |
143 return NSHTMLPboardType_; | |
144 | |
145 return NSHTMLPboardType_ = new NSString(bindings.NSHTMLPboardType); | |
146 } | |
147 | |
148 NSString NSPICTPboardType () | |
149 { | |
150 if (NSPICTPboardType_) | |
151 return NSPICTPboardType_; | |
152 | |
153 return NSPICTPboardType_ = new NSString(bindings.NSPICTPboardType); | |
154 } | |
155 | |
156 NSString NSURLPboardType () | |
157 { | |
158 if (NSURLPboardType_) | |
159 return NSURLPboardType_; | |
160 | |
161 return NSURLPboardType_ = new NSString(bindings.NSURLPboardType); | |
162 } | |
163 | |
164 NSString NSPDFPboardType () | |
165 { | |
166 if (NSPDFPboardType_) | |
167 return NSPDFPboardType_; | |
168 | |
169 return NSPDFPboardType_ = new NSString(bindings.NSPDFPboardType); | |
170 } | |
171 | |
172 NSString NSVCardPboardType () | |
173 { | |
174 if (NSVCardPboardType_) | |
175 return NSVCardPboardType_; | |
176 | |
177 return NSVCardPboardType_ = new NSString(bindings.NSVCardPboardType); | |
178 } | |
179 | |
180 NSString NSFilesPromisePboardType () | |
181 { | |
182 if (NSFilesPromisePboardType_) | |
183 return NSFilesPromisePboardType_; | |
184 | |
185 return NSFilesPromisePboardType_ = new NSString(bindings.NSFilesPromisePboardType); | |
186 } | |
187 | |
188 NSString NSInkTextPboardType () | |
189 { | |
190 if (NSInkTextPboardType_) | |
191 return NSInkTextPboardType_; | |
192 | |
193 return NSInkTextPboardType_ = new NSString(bindings.NSInkTextPboardType); | |
194 } | |
195 | |
196 NSString NSMultipleTextSelectionPboardType () | |
197 { | |
198 if (NSMultipleTextSelectionPboardType_) | |
199 return NSMultipleTextSelectionPboardType_; | |
200 | |
201 return NSMultipleTextSelectionPboardType_ = new NSString(bindings.NSMultipleTextSelectionPboardType); | |
202 } | |
203 | |
204 NSString NSGeneralPboard () | |
205 { | |
206 if (NSGeneralPboard_) | |
207 return NSGeneralPboard_; | |
208 | |
209 return NSGeneralPboard_ = new NSString(bindings.NSGeneralPboard); | |
210 } | |
211 | |
212 NSString NSFontPboard () | |
213 { | |
214 if (NSFontPboard_) | |
215 return NSFontPboard_; | |
216 | |
217 return NSFontPboard_ = new NSString(bindings.NSFontPboard); | |
218 } | |
219 | |
220 NSString NSRulerPboard () | |
221 { | |
222 if (NSRulerPboard_) | |
223 return NSRulerPboard_; | |
224 | |
225 return NSRulerPboard_ = new NSString(bindings.NSRulerPboard); | |
226 } | |
227 | |
228 NSString NSFindPboard () | |
229 { | |
230 if (NSFindPboard_) | |
231 return NSFindPboard_; | |
232 | |
233 return NSFindPboard_ = new NSString(bindings.NSFindPboard); | |
234 } | |
235 | |
236 NSString NSDragPboard () | |
237 { | |
238 if (NSDragPboard_) | |
239 return NSDragPboard_; | |
240 | |
241 return NSDragPboard_ = new NSString(bindings.NSDragPboard); | |
242 } | |
243 | |
244 const TNSFileContents = ` | |
245 | |
246 bool writeFileContents (NSString filename) | |
247 { | |
248 return invokeObjcSelf!(bool, "writeFileContents:", NSString)(filename); | |
249 } | |
250 | |
251 NSString readFileContentsType (NSString type, NSString filename) | |
252 { | |
253 return invokeObjcSelf!(NSString, "readFileContentsType:toFile:", NSString, NSString)(type, filename); | |
254 } | |
255 | |
256 bool writeFileWrapper (NSFileWrapper wrapper) | |
257 { | |
258 return invokeObjcSelf!(bool, "writeFileWrapper:", NSFileWrapper)(wrapper); | |
259 } | |
260 | |
261 NSFileWrapper readFileWrapper () | |
262 { | |
263 return invokeObjcSelf!(NSFileWrapper, "readFileWrapper"); | |
264 } | |
265 | |
266 //mixin ObjcBindMethod!(writeFileContents, "writeFileContents:"); | |
267 //mixin ObjcBindMethod!(readFileContentsType, "readFileContentsType:toFile:"); | |
268 //mixin ObjcBindMethod!(writeFileWrapper, "writeFileWrapper:"); | |
269 //mixin ObjcBindMethod!(readFileWrapper, "readFileWrapper"); | |
270 | |
271 `; | |
272 | |
273 const TNSPasteboardSupport = ` | |
274 | |
275 static NSURL URLFromPasteboard (NSPasteboard pasteBoard) | |
276 { | |
277 return invokeObjcSelfClass!(NSURL, "URLFromPasteboard:", NSPasteboard)(pasteBoard); | |
278 } | |
279 | |
280 void writeToPasteboard (NSPasteboard pasteBoard) | |
281 { | |
282 return invokeObjcSelf!(void, "writeToPasteboard:", NSPasteboard)(pasteBoard); | |
283 } | |
284 | |
285 //mixin ObjcBindClassMethod!(URLFromPasteboard, "URLFromPasteboard:"); | |
286 //mixin ObjcBindMethod!(writeToPasteboard, "writeToPasteboard:"); | |
287 | |
288 `; | |
289 | |
290 const TNSPasteboardOwner = ` | |
291 | |
292 void pasteboard (NSPasteboard sender, NSString type) | |
293 { | |
294 return invokeObjcSelf!(void, "pasteboard:provideDataForType:", NSPasteboard, NSString)(sender, type); | |
295 } | |
296 | |
297 void pasteboardChangedOwner (NSPasteboard sender) | |
298 { | |
299 return invokeObjcSelf!(void, "pasteboardChangedOwner:", NSPasteboard)(sender); | |
300 } | |
301 | |
302 //mixin ObjcBindMethod!(pasteboard, "pasteboard:provideDataForType:"); | |
303 //mixin ObjcBindMethod!(pasteboardChangedOwner, "pasteboardChangedOwner:"); | |
304 | |
305 `; | |
306 | |
307 class NSPasteboard : NSObject | |
308 { | |
309 mixin (ObjcWrap); | |
310 | |
311 static NSPasteboard generalPasteboard () | |
312 { | |
313 return invokeObjcSelfClass!(NSPasteboard, "generalPasteboard"); | |
314 } | |
315 | |
316 static NSPasteboard pasteboardWithName (NSString name) | |
317 { | |
318 return invokeObjcSelfClass!(NSPasteboard, "pasteboardWithName:", NSString)(name); | |
319 } | |
320 | |
321 static NSPasteboard pasteboardWithUniqueName () | |
322 { | |
323 return invokeObjcSelfClass!(NSPasteboard, "pasteboardWithUniqueName"); | |
324 } | |
325 | |
326 static NSArray typesFilterableTo (NSString type) | |
327 { | |
328 return invokeObjcSelfClass!(NSArray, "typesFilterableTo:", NSString)(type); | |
329 } | |
330 | |
331 static NSPasteboard pasteboardByFilteringFile (NSString filename) | |
332 { | |
333 return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringFile:", NSString)(filename); | |
334 } | |
335 | |
336 static NSPasteboard pasteboardByFilteringData (NSData data, NSString type) | |
337 { | |
338 return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringData:ofType:", NSData, NSString)(data, type); | |
339 } | |
340 | |
341 static NSPasteboard pasteboardByFilteringTypesInPasteboard (NSPasteboard pboard) | |
342 { | |
343 return invokeObjcSelfClass!(NSPasteboard, "pasteboardByFilteringTypesInPasteboard:", NSPasteboard)(pboard); | |
344 } | |
345 | |
346 NSString name () | |
347 { | |
348 return invokeObjcSelf!(NSString, "name"); | |
349 } | |
350 | |
351 void releaseGlobally () | |
352 { | |
353 return invokeObjcSelf!(void, "releaseGlobally"); | |
354 } | |
355 | |
356 NSInteger declareTypes (NSArray newTypes, Object newOwner) | |
357 { | |
358 return invokeObjcSelf!(NSInteger, "declareTypes:owner:", NSArray, Object)(newTypes, newOwner); | |
359 } | |
360 | |
361 NSInteger addTypes (NSArray newTypes, Object newOwner) | |
362 { | |
363 return invokeObjcSelf!(NSInteger, "addTypes:owner:", NSArray, Object)(newTypes, newOwner); | |
364 } | |
365 | |
366 NSInteger changeCount () | |
367 { | |
368 return invokeObjcSelf!(NSInteger, "changeCount"); | |
369 } | |
370 | |
371 NSArray types () | |
372 { | |
373 return invokeObjcSelf!(NSArray, "types"); | |
374 } | |
375 | |
376 NSString availableTypeFromArray (NSArray types) | |
377 { | |
378 return invokeObjcSelf!(NSString, "availableTypeFromArray:", NSArray)(types); | |
379 } | |
380 | |
381 bool setData (NSData data, NSString dataType) | |
382 { | |
383 return invokeObjcSelf!(bool, "setData:forType:", NSData, NSString)(data, dataType); | |
384 } | |
385 | |
386 NSData dataForType (NSString dataType) | |
387 { | |
388 return invokeObjcSelf!(NSData, "dataForType:", NSString)(dataType); | |
389 } | |
390 | |
391 bool setPropertyList (Object plist, NSString dataType) | |
392 { | |
393 return invokeObjcSelf!(bool, "setPropertyList:forType:", Object, NSString)(plist, dataType); | |
394 } | |
395 | |
396 Object propertyListForType (NSString dataType) | |
397 { | |
398 return invokeObjcSelf!(Object, "propertyListForType:", NSString)(dataType); | |
399 } | |
400 | |
401 bool setString (NSString string, NSString dataType) | |
402 { | |
403 return invokeObjcSelf!(bool, "setString:forType:", NSString, NSString)(string, dataType); | |
404 } | |
405 | |
406 NSString stringForType (NSString dataType) | |
407 { | |
408 return invokeObjcSelf!(NSString, "stringForType:", NSString)(dataType); | |
409 } | |
410 | |
411 // NSFileContents | |
412 bool writeFileContents (NSString filename) | |
413 { | |
414 return invokeObjcSelf!(bool, "writeFileContents:", NSString)(filename); | |
415 } | |
416 | |
417 NSString readFileContentsType (NSString type, NSString filename) | |
418 { | |
419 return invokeObjcSelf!(NSString, "readFileContentsType:toFile:", NSString, NSString)(type, filename); | |
420 } | |
421 | |
422 bool writeFileWrapper (NSFileWrapper wrapper) | |
423 { | |
424 return invokeObjcSelf!(bool, "writeFileWrapper:", NSFileWrapper)(wrapper); | |
425 } | |
426 | |
427 NSFileWrapper readFileWrapper () | |
428 { | |
429 return invokeObjcSelf!(NSFileWrapper, "readFileWrapper"); | |
430 } | |
431 } | |
432 | |
433 NSString NSCreateFilenamePboardType (NSString fileType) | |
434 { | |
435 return Bridge.invokeObjcFunction!(NSString, bindings.NSCreateFilenamePboardType, NSString)(fileType); | |
436 } | |
437 | |
438 NSString NSCreateFileContentsPboardType (NSString fileType) | |
439 { | |
440 return Bridge.invokeObjcFunction!(NSString, bindings.NSCreateFileContentsPboardType, NSString)(fileType); | |
441 } | |
442 | |
443 NSString NSGetFileType (NSString pboardType) | |
444 { | |
445 return Bridge.invokeObjcFunction!(NSString, bindings.NSGetFileType, NSString)(pboardType); | |
446 } | |
447 | |
448 NSArray NSGetFileTypes (NSArray pboardTypes) | |
449 { | |
450 return Bridge.invokeObjcFunction!(NSArray, bindings.NSGetFileTypes, NSArray)(pboardTypes); | |
451 } |