diff dwt/dnd/Transfer.d @ 320:da968414c383

Merge changes SWT 3.4.1
author Frank Benoit <benoit@tionex.de>
date Mon, 03 Nov 2008 21:58:40 +0100
parents fd9c62a2998e
children a3b84f877e63
line wrap: on
line diff
--- a/dwt/dnd/Transfer.d	Thu Oct 23 23:41:09 2008 +0200
+++ b/dwt/dnd/Transfer.d	Mon Nov 03 21:58:40 2008 +0100
@@ -35,6 +35,29 @@
  */
 public abstract class Transfer {
 
+private static final int RETRY_LIMIT = 10;
+/* 
+ * Feature in Windows. When another application has control
+ * of the clipboard, the clipboard is locked and it's not
+ * possible to retrieve data until the other application is
+ * finished. To allow other applications to get the
+ * data, use PeekMessage() to enable cross thread
+ * message sends.
+ */
+int getData(IDataObject dataObject, FORMATETC pFormatetc, STGMEDIUM pmedium) {
+    if (dataObject.GetData(pFormatetc, pmedium) is COM.S_OK) return COM.S_OK;
+    try {Thread.sleep(0.050);} catch (Exception t) {}
+    int result = dataObject.GetData(pFormatetc, pmedium);
+    int retryCount = 0;
+    while (result !is COM.S_OK && retryCount++ < RETRY_LIMIT) {
+        MSG msg = new MSG();
+        OS.PeekMessage(msg, 0, 0, 0, OS.PM_NOREMOVE | OS.PM_NOYIELD);
+        try {Thread.sleep(0.050);} catch (Exception t) {}
+        result = dataObject.GetData(pFormatetc, pmedium);
+    }
+    return result;
+}
+
 /**
  * Returns a list of the platform specific data types that can be converted using
  * this transfer agent.