#endif
public static void SetDataObject(object data) {
- SetDataObject(data, true);
-
+ SetDataObject(data, false); // MSDN says default behavior is to place non-persistent data to clipboard
}
public static void SetDataObject(object data, bool copy) {
+ SetDataObject(data, copy, 10, 100); // MSDN says default behavior is to try 10 times with 100 ms delay
+ }
+
+ internal static void SetDataObjectImpl(object data, bool copy) {
IntPtr clipboard_handle;
XplatUI.ObjectToClipboard converter;
int native_format;
}
XplatUI.ClipboardClose(clipboard_handle);
}
-
+
#if NET_2_0
- [MonoTODO ("Actually respect retryTimes, retryDelay.")]
- public static void SetDataObject (object data, bool copy, int retryTimes, int retryDelay)
+ public
+#else
+ internal
+#endif
+ static void SetDataObject(object data, bool copy, int retryTimes, int retryDelay)
{
if (data == null)
throw new ArgumentNullException("data");
throw new ArgumentOutOfRangeException("retryTimes");
if (retryDelay < 0)
throw new ArgumentOutOfRangeException("retryDelay");
-
- SetDataObject(data, copy);
+
+ // MS implementation actually puts data to clipboard even when retryTimes == 0
+ bool retry = true;
+ do
+ {
+ retry = false;
+ --retryTimes;
+ try
+ {
+ SetDataObjectImpl(data, copy);
+ } catch (ExternalException) {
+ if (retryTimes <= 0)
+ throw;
+ retry = true;
+ Threading.Thread.Sleep(retryDelay);
+ }
+ } while (retry && retryTimes > 0);
}
+#if NET_2_0
[MonoInternalNote ("Needs additional checks for valid paths, see MSDN")]
public static void SetFileDropList (StringCollection filePaths)
{
if (obj == null) {
// Just clear it
- Win32EmptyClipboard();
+ if (!Win32EmptyClipboard())
+ throw new ExternalException("Win32EmptyClipboard");
return;
}
if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
hmem = Marshal.StringToHGlobalAnsi((string)obj);
- Win32SetClipboardData((uint)type, hmem);
+ if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero )
+ throw new ExternalException("Win32SetClipboardData");
return;
} else switch((ClipboardFormats)type) {
case ClipboardFormats.CF_UNICODETEXT: {
hmem = Marshal.StringToHGlobalUni((string)obj);
- Win32SetClipboardData((uint)type, hmem);
+ if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
+ throw new ExternalException("Win32SetClipboardData");
return;
}
case ClipboardFormats.CF_TEXT: {
hmem = Marshal.StringToHGlobalAnsi((string)obj);
- Win32SetClipboardData((uint)type, hmem);
+ if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
+ throw new ExternalException("Win32SetClipboardData");
return;
}
hmem_ptr = Win32GlobalLock(hmem);
Marshal.Copy(data, 0, hmem_ptr, data.Length);
Win32GlobalUnlock(hmem);
- Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem);
+ if (Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem) == IntPtr.Zero)
+ throw new ExternalException("Win32SetClipboardData");
return;
}
hmem_ptr = Win32GlobalLock(hmem);
Marshal.Copy(data, 0, hmem_ptr, data.Length);
Win32GlobalUnlock(hmem);
- Win32SetClipboardData((uint)type, hmem);
+ if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
+ throw new ExternalException("Win32SetClipboardData");
}
return;
}