Mercurial > projects > dwt-mac
comparison dwt/dnd/Clipboard.d @ 91:a7e41c09df9e
Ported dwt.dnd.Clipboard
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 19:04:59 +0100 |
parents | d8635bb48c7c |
children |
comparison
equal
deleted
inserted
replaced
90:c7f7f4d7091a | 91:a7e41c09df9e |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.dnd.Clipboard; | 14 module dwt.dnd.Clipboard; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
24 import dwt.internal.cocoa.NSString; | 27 import dwt.internal.cocoa.NSString; |
25 import dwt.internal.cocoa.NSURL; | 28 import dwt.internal.cocoa.NSURL; |
26 import dwt.internal.cocoa.OS; | 29 import dwt.internal.cocoa.OS; |
27 import dwt.widgets.Display; | 30 import dwt.widgets.Display; |
28 | 31 |
32 import tango.core.Thread; | |
33 | |
34 import dwt.dnd.DND; | |
35 import dwt.dnd.Transfer; | |
36 import dwt.dnd.TransferData; | |
37 import dwt.internal.objc.cocoa.Cocoa; | |
38 | |
29 /** | 39 /** |
30 * The <code>Clipboard</code> provides a mechanism for transferring data from one | 40 * The <code>Clipboard</code> provides a mechanism for transferring data from one |
31 * application to another or within an application. | 41 * application to another or within an application. |
32 * | 42 * |
33 * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p> | 43 * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p> |
53 * </ul> | 63 * </ul> |
54 * | 64 * |
55 * @see Clipboard#dispose | 65 * @see Clipboard#dispose |
56 * @see Clipboard#checkSubclass | 66 * @see Clipboard#checkSubclass |
57 */ | 67 */ |
58 public Clipboard(Display display) { | 68 public this(Display display) { |
59 checkSubclass (); | 69 checkSubclass (); |
60 if (display is null) { | 70 if (display is null) { |
61 display = Display.getCurrent(); | 71 display = Display.getCurrent(); |
62 if (display is null) { | 72 if (display is null) { |
63 display = Display.getDefault(); | 73 display = Display.getDefault(); |
64 } | 74 } |
65 } | 75 } |
66 if (display.getThread() !is Thread.currentThread()) { | 76 if (display.getThread() !is Thread.getThis()) { |
67 DND.error(DWT.ERROR_THREAD_INVALID_ACCESS); | 77 DND.error(DWT.ERROR_THREAD_INVALID_ACCESS); |
68 } | 78 } |
69 this.display = display; | 79 this.display = display; |
70 } | 80 } |
71 | 81 |
95 * @exception DWTException <ul> | 105 * @exception DWTException <ul> |
96 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | 106 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
97 * </ul> | 107 * </ul> |
98 */ | 108 */ |
99 protected void checkSubclass () { | 109 protected void checkSubclass () { |
100 String name = getClass().getName (); | 110 String name = this.classinfo.name; |
101 String validName = Clipboard.class.getName(); | 111 String validName = Clipboard.classinfo.name; |
102 if (!validName.equals(name)) { | 112 if (!validName.equals(name)) { |
103 DND.error (DWT.ERROR_INVALID_SUBCLASS); | 113 DND.error (DWT.ERROR_INVALID_SUBCLASS); |
104 } | 114 } |
105 } | 115 } |
106 /** | 116 /** |
126 * </ul> | 136 * </ul> |
127 */ | 137 */ |
128 protected void checkWidget () { | 138 protected void checkWidget () { |
129 Display display = this.display; | 139 Display display = this.display; |
130 if (display is null) DND.error (DWT.ERROR_WIDGET_DISPOSED); | 140 if (display is null) DND.error (DWT.ERROR_WIDGET_DISPOSED); |
131 if (display.getThread() !is Thread.currentThread ()) DND.error (DWT.ERROR_THREAD_INVALID_ACCESS); | 141 if (display.getThread() !is Thread.getThis ()) DND.error (DWT.ERROR_THREAD_INVALID_ACCESS); |
132 if (display.isDisposed()) DND.error(DWT.ERROR_WIDGET_DISPOSED); | 142 if (display.isDisposed()) DND.error(DWT.ERROR_WIDGET_DISPOSED); |
133 } | 143 } |
134 | 144 |
135 /** | 145 /** |
136 * If this clipboard is currently the owner of the data on the system clipboard, | 146 * If this clipboard is currently the owner of the data on the system clipboard, |
195 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | 205 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
196 * </ul> | 206 * </ul> |
197 */ | 207 */ |
198 public void dispose () { | 208 public void dispose () { |
199 if (isDisposed()) return; | 209 if (isDisposed()) return; |
200 if (display.getThread() !is Thread.currentThread()) DND.error(DWT.ERROR_THREAD_INVALID_ACCESS); | 210 if (display.getThread() !is Thread.getThis()) DND.error(DWT.ERROR_THREAD_INVALID_ACCESS); |
201 display = null; | 211 display = null; |
202 } | 212 } |
203 | 213 |
204 /** | 214 /** |
205 * Retrieve the data of the specified type currently available on the system | 215 * Retrieve the data of the specified type currently available on the system |
465 NSString dataType = NSString.stringWith(typeNames[j]); | 475 NSString dataType = NSString.stringWith(typeNames[j]); |
466 pasteboard.addTypes(NSArray.arrayWithObject(dataType), null); | 476 pasteboard.addTypes(NSArray.arrayWithObject(dataType), null); |
467 if (dataType.isEqual(OS.NSStringPboardType) || | 477 if (dataType.isEqual(OS.NSStringPboardType) || |
468 dataType.isEqual(OS.NSRTFPboardType) || | 478 dataType.isEqual(OS.NSRTFPboardType) || |
469 dataType.isEqual(OS.NSHTMLPboardType)) { | 479 dataType.isEqual(OS.NSHTMLPboardType)) { |
470 pasteboard.setString((NSString) tdata, dataType); | 480 pasteboard.setString(cast(NSString) tdata, dataType); |
471 } else if (dataType.isEqual(OS.NSURLPboardType)) { | 481 } else if (dataType.isEqual(OS.NSURLPboardType)) { |
472 NSURL url = (NSURL) tdata; | 482 NSURL url = cast(NSURL) tdata; |
473 url.writeToPasteboard(pasteboard); | 483 url.writeToPasteboard(pasteboard); |
474 } else if (dataType.isEqual(OS.NSFilenamesPboardType)) { | 484 } else if (dataType.isEqual(OS.NSFilenamesPboardType)) { |
475 pasteboard.setPropertyList((NSArray) tdata, dataType); | 485 pasteboard.setPropertyList(cast(NSArray) tdata, dataType); |
476 } else { | 486 } else { |
477 pasteboard.setData((NSData) tdata, dataType); | 487 pasteboard.setData(cast(NSData) tdata, dataType); |
478 } | 488 } |
479 } | 489 } |
480 } | 490 } |
481 } | 491 } |
482 | 492 |
525 public TransferData[] getAvailableTypes(int clipboards) { | 535 public TransferData[] getAvailableTypes(int clipboards) { |
526 checkWidget(); | 536 checkWidget(); |
527 if ((clipboards & DND.CLIPBOARD) is 0) return new TransferData[0]; | 537 if ((clipboards & DND.CLIPBOARD) is 0) return new TransferData[0]; |
528 NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); | 538 NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); |
529 NSArray types = pasteboard.types(); | 539 NSArray types = pasteboard.types(); |
530 int count = (int)/*64*/types.count(); | 540 NSUInteger count = types.count(); |
531 TransferData[] result = new TransferData[count]; | 541 TransferData[] result = new TransferData[count]; |
532 for (int i = 0; i < count; i++) { | 542 for (NSUInteger i = 0; i < count; i++) { |
533 result[i] = new TransferData(); | 543 result[i] = new TransferData(); |
534 result[i].type = Transfer.registerType(new NSString(types.objectAtIndex(i)).getString()); | 544 result[i].type = Transfer.registerType((new NSString(types.objectAtIndex(i))).getString()); |
535 } | 545 } |
536 return result; | 546 return result; |
537 } | 547 } |
538 | 548 |
539 /** | 549 /** |
554 */ | 564 */ |
555 public String[] getAvailableTypeNames() { | 565 public String[] getAvailableTypeNames() { |
556 checkWidget(); | 566 checkWidget(); |
557 NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); | 567 NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); |
558 NSArray types = pasteboard.types(); | 568 NSArray types = pasteboard.types(); |
559 int count = (int)/*64*/types.count(); | 569 int count = cast(int)/*64*/types.count(); |
560 String[] result = new String[count]; | 570 String[] result = new String[count]; |
561 for (int i = 0; i < count; i++) { | 571 for (int i = 0; i < count; i++) { |
562 result[i] = new NSString(types.objectAtIndex(i)).getString(); | 572 result[i] = (new NSString(types.objectAtIndex(i))).getString(); |
563 } | 573 } |
564 return result; | 574 return result; |
565 } | 575 } |
566 } | 576 } |