diff dwt/dnd/Transfer.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 380af2bdd8e5
children a7e41c09df9e
line wrap: on
line diff
--- a/dwt/dnd/Transfer.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/dnd/Transfer.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -8,7 +8,9 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
-module dwt.dnd;
+module dwt.dnd.Transfer;
+
+import dwt.dwthelper.utils;
 
  
 /**
@@ -22,9 +24,14 @@
  * ByteArrayTransfer class.</p>
  * 
  * @see ByteArrayTransfer
+ * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class Transfer {
-    
+
+static String[] TYPES = new String[4];
+
 /**
  * Returns a list of the platform specific data types that can be converted using 
  * this transfer agent.
@@ -128,15 +135,22 @@
  * @return the unique identifier associated with this data type
  */
 public static int registerType(String formatName) {
-    int length = formatName.length();
-    // TODO - hashcode may not be unique - need another way
-    if (length > 4) return formatName.toHash();
-    int type = 0;
-    if (length > 0) type |= (formatName.charAt(0) & 0xff) << 24;
-    if (length > 1) type |= (formatName.charAt(1) & 0xff) << 16;
-    if (length > 2) type |= (formatName.charAt(2) & 0xff) << 8;
-    if (length > 3) type |= formatName.charAt(3) & 0xff; 
-    return type;
+    /* Note the type 0 is not used */
+    int index = 1;
+    while (index < TYPES.length) {
+        String type = TYPES[index];
+        if (type !is null && formatName.equals(type)) {
+            return index;
+        }
+        index++;
+    }
+    if (index is TYPES.length) {
+        String[] newTypes = new String[TYPES.length + 4];
+        System.arraycopy(TYPES, 0, newTypes, 0, TYPES.length);
+        TYPES = newTypes;
+    }
+    TYPES[index] = formatName;
+    return index;
 }
 
 /**