changeset 91:a7e41c09df9e

Ported dwt.dnd.Clipboard
author Jacob Carlborg <doob@me.com>
date Tue, 30 Dec 2008 19:04:59 +0100
parents c7f7f4d7091a
children 370410b7852f
files dwt/dnd/Clipboard.d dwt/dnd/Transfer.d
diffstat 2 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dnd/Clipboard.d	Tue Dec 30 18:54:31 2008 +0100
+++ b/dwt/dnd/Clipboard.d	Tue Dec 30 19:04:59 2008 +0100
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.dnd.Clipboard;
 
@@ -26,6 +29,13 @@
 import dwt.internal.cocoa.OS;
 import dwt.widgets.Display;
 
+import tango.core.Thread;
+
+import dwt.dnd.DND;
+import dwt.dnd.Transfer;
+import dwt.dnd.TransferData;
+import dwt.internal.objc.cocoa.Cocoa;
+
 /**
  * The <code>Clipboard</code> provides a mechanism for transferring data from one
  * application to another or within an application.
@@ -55,7 +65,7 @@
  * @see Clipboard#dispose
  * @see Clipboard#checkSubclass
  */
-public Clipboard(Display display) { 
+public this(Display display) { 
     checkSubclass ();
     if (display is null) {
         display = Display.getCurrent();
@@ -63,7 +73,7 @@
             display = Display.getDefault();
         }
     }
-    if (display.getThread() !is Thread.currentThread()) {
+    if (display.getThread() !is Thread.getThis()) {
         DND.error(DWT.ERROR_THREAD_INVALID_ACCESS);
     }
     this.display = display;
@@ -97,8 +107,8 @@
  * </ul>
  */
 protected void checkSubclass () {
-    String name = getClass().getName ();
-    String validName = Clipboard.class.getName();
+    String name = this.classinfo.name;
+    String validName = Clipboard.classinfo.name;
     if (!validName.equals(name)) {
         DND.error (DWT.ERROR_INVALID_SUBCLASS);
     }
@@ -128,7 +138,7 @@
 protected void checkWidget () {
     Display display = this.display;
     if (display is null) DND.error (DWT.ERROR_WIDGET_DISPOSED);
-    if (display.getThread() !is Thread.currentThread ()) DND.error (DWT.ERROR_THREAD_INVALID_ACCESS);
+    if (display.getThread() !is Thread.getThis ()) DND.error (DWT.ERROR_THREAD_INVALID_ACCESS);
     if (display.isDisposed()) DND.error(DWT.ERROR_WIDGET_DISPOSED);
 }
 
@@ -197,7 +207,7 @@
  */
 public void dispose () {
     if (isDisposed()) return;
-    if (display.getThread() !is Thread.currentThread()) DND.error(DWT.ERROR_THREAD_INVALID_ACCESS);
+    if (display.getThread() !is Thread.getThis()) DND.error(DWT.ERROR_THREAD_INVALID_ACCESS);
     display = null;
 }
 
@@ -467,14 +477,14 @@
             if (dataType.isEqual(OS.NSStringPboardType) || 
                     dataType.isEqual(OS.NSRTFPboardType) ||
                     dataType.isEqual(OS.NSHTMLPboardType)) {
-                pasteboard.setString((NSString) tdata, dataType);
+                pasteboard.setString(cast(NSString) tdata, dataType);
             } else if (dataType.isEqual(OS.NSURLPboardType)) {
-                NSURL url = (NSURL) tdata;
+                NSURL url = cast(NSURL) tdata;
                 url.writeToPasteboard(pasteboard);
             } else if (dataType.isEqual(OS.NSFilenamesPboardType)) {
-                pasteboard.setPropertyList((NSArray) tdata, dataType);
+                pasteboard.setPropertyList(cast(NSArray) tdata, dataType);
             } else {
-                pasteboard.setData((NSData) tdata, dataType);
+                pasteboard.setData(cast(NSData) tdata, dataType);
             }
         }
     }
@@ -527,11 +537,11 @@
     if ((clipboards & DND.CLIPBOARD) is 0) return new TransferData[0];
     NSPasteboard pasteboard = NSPasteboard.generalPasteboard();
     NSArray types = pasteboard.types();
-    int count = (int)/*64*/types.count();
+    NSUInteger count = types.count();
     TransferData[] result = new TransferData[count];
-    for (int i = 0; i < count; i++) {
+    for (NSUInteger i = 0; i < count; i++) {
         result[i] = new TransferData();
-        result[i].type = Transfer.registerType(new NSString(types.objectAtIndex(i)).getString());
+        result[i].type = Transfer.registerType((new NSString(types.objectAtIndex(i))).getString());
     }
     return result;
 }
@@ -556,10 +566,10 @@
     checkWidget();
     NSPasteboard pasteboard = NSPasteboard.generalPasteboard();
     NSArray types = pasteboard.types();
-    int count = (int)/*64*/types.count();
+    int count = cast(int)/*64*/types.count();
     String[] result = new String[count];
     for (int i = 0; i < count; i++) {
-        result[i] = new NSString(types.objectAtIndex(i)).getString();
+        result[i] = (new NSString(types.objectAtIndex(i))).getString();
     }
     return result;
 }
--- a/dwt/dnd/Transfer.d	Tue Dec 30 18:54:31 2008 +0100
+++ b/dwt/dnd/Transfer.d	Tue Dec 30 19:04:59 2008 +0100
@@ -162,7 +162,7 @@
  * 
  * @since 3.1
  */
-protected bool validate(Object object) {
+/*protected */bool validate(Object object) {
     return true;
 }
 }