public static string GetText ()
{
+ return GetText (TextDataFormat.UnicodeText);
+ }
+
+ public static string GetText (TextDataFormat format)
+ {
+ if (!Enum.IsDefined (typeof (TextDataFormat), format))
+ throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for TextDataFormat", format));
+
IDataObject data = GetDataObject ();
if (data == null)
return string.Empty;
- string retval = (string)data.GetData (DataFormats.UnicodeText, true);
+ string retval;
+
+ switch (format) {
+ case TextDataFormat.Text:
+ default:
+ retval = (string)data.GetData (DataFormats.Text, true);
+ break;
+ case TextDataFormat.UnicodeText:
+ retval = (string)data.GetData (DataFormats.UnicodeText, true);
+ break;
+ case TextDataFormat.Rtf:
+ retval = (string)data.GetData (DataFormats.Rtf, true);
+ break;
+ case TextDataFormat.Html:
+ retval = (string)data.GetData (DataFormats.Html, true);
+ break;
+ case TextDataFormat.CommaSeparatedValue:
+ retval = (string)data.GetData (DataFormats.CommaSeparatedValue, true);
+ break;
+ }
return retval == null ? string.Empty : retval;
}
#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
+ public
+#else
+ internal
+#endif
+ static void SetDataObject(object data, bool copy, int retryTimes, int retryDelay)
+ {
+ if (data == null)
+ throw new ArgumentNullException("data");
+ if (retryTimes < 0)
+ throw new ArgumentOutOfRangeException("retryTimes");
+ if (retryDelay < 0)
+ throw new ArgumentOutOfRangeException("retryDelay");
+
+ // 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)