diff --git a/Xwt.Gtk/Xwt.GtkBackend/Util.cs b/Xwt.Gtk/Xwt.GtkBackend/Util.cs
index d382a3b3..34f2f549 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/Util.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/Util.cs
@@ -144,13 +144,26 @@ namespace Xwt.GtkBackend
list.Remove ("STRING");
}
entries = (Gtk.TargetEntry[])list;
- }
- else if (type == TransferDataType.Rtf) {
+ } else if (type == TransferDataType.Rtf) {
Gdk.Atom atom;
- if (Platform.IsMac)
+ if (Platform.IsMac) {
atom = Gdk.Atom.Intern ("NSRTFPboardType", false); //TODO: use public.rtf when dep on MacOS 10.6
- else
+ } else if (Platform.IsWindows) {
+ atom = Gdk.Atom.Intern ("Rich Text Format", false);
+ } else {
atom = Gdk.Atom.Intern ("text/rtf", false);
+ }
+ entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (atom, 0, id) };
+ }
+ else if (type == TransferDataType.Html) {
+ Gdk.Atom atom;
+ if (Platform.IsMac) {
+ atom = Gdk.Atom.Intern ("Apple HTML pasteboard type", false); //TODO: use public.rtf when dep on MacOS 10.6
+ } else if (Platform.IsWindows) {
+ atom = Gdk.Atom.Intern ("HTML Format", false);
+ } else {
+ atom = Gdk.Atom.Intern ("text/html", false);
+ }
entries = new Gtk.TargetEntry[] { new Gtk.TargetEntry (atom, 0, id) };
}
else {
diff --git a/Xwt.Mac/Xwt.Mac/Util.cs b/Xwt.Mac/Xwt.Mac/Util.cs
index 45100dba..81a5935f 100644
--- a/Xwt.Mac/Xwt.Mac/Util.cs
+++ b/Xwt.Mac/Xwt.Mac/Util.cs
@@ -163,6 +163,8 @@ namespace Xwt.Mac
return NSPasteboard.NSStringType;
if (dt == TransferDataType.Rtf)
return NSPasteboard.NSRtfType;
+ if (dt == TransferDataType.Html)
+ return NSPasteboard.NSHtmlType;
if (dt == TransferDataType.Image)
return NSPasteboard.NSTiffType;
diff --git a/Xwt.Mac/Xwt.Mac/ViewBackend.cs b/Xwt.Mac/Xwt.Mac/ViewBackend.cs
index 8064556a..4006bf13 100755
--- a/Xwt.Mac/Xwt.Mac/ViewBackend.cs
+++ b/Xwt.Mac/Xwt.Mac/ViewBackend.cs
@@ -644,6 +644,7 @@ namespace Xwt.Mac
if (type == TransferDataType.Uri) return NSPasteboard.NSFilenamesType;
if (type == TransferDataType.Image) return NSPasteboard.NSPictType;
if (type == TransferDataType.Rtf) return NSPasteboard.NSRtfType;
+ if (type == TransferDataType.Html) return NSPasteboard.NSHtmlType;
return type.Id;
}
@@ -657,6 +658,8 @@ namespace Xwt.Mac
return TransferDataType.Image;
if (type == NSPasteboard.NSRtfType)
return TransferDataType.Rtf;
+ if (type == NSPasteboard.NSHtmlType)
+ return TransferDataType.Html;
return TransferDataType.FromId (type);
}
diff --git a/Xwt.WPF/Xwt.WPFBackend/ClipboardBackend.cs b/Xwt.WPF/Xwt.WPFBackend/ClipboardBackend.cs
index d5ed5722..ba7f4eaa 100644
--- a/Xwt.WPF/Xwt.WPFBackend/ClipboardBackend.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/ClipboardBackend.cs
@@ -46,8 +46,38 @@ namespace Xwt.WPFBackend
throw new ArgumentNullException ("type");
if (dataSource == null)
throw new ArgumentNullException ("dataSource");
+ if (type == TransferDataType.Html) {
+ WindowsClipboard.SetData (type.ToWpfDataFormat (), GenerateCFHtml (dataSource ().ToString ()));
+ } else {
+ WindowsClipboard.SetData (type.ToWpfDataFormat (), dataSource ());
+ }
+ }
- WindowsClipboard.SetData (type.ToWpfDataFormat (), dataSource ());
+ static readonly string emptyCFHtmlHeader = GenerateCFHtmlHeader (0, 0, 0, 0);
+
+ ///
+ /// Generates a CF_HTML cliboard format document
+ ///
+ string GenerateCFHtml (string htmlFragment)
+ {
+ int startHTML = emptyCFHtmlHeader.Length;
+ int startFragment = startHTML;
+ int endFragment = startFragment + System.Text.Encoding.UTF8.GetByteCount (htmlFragment);
+ int endHTML = endFragment;
+ return GenerateCFHtmlHeader (startHTML, endHTML, startFragment, endFragment) + htmlStart + htmlFragment + htmlEnd;
+ }
+
+ ///
+ /// Generates a CF_HTML clipboard format header.
+ ///
+ static string GenerateCFHtmlHeader (int startHTML, int endHTML, int startFragment, int endFragment)
+ {
+ return
+ "Version:0.9" + Environment.NewLine +
+ string.Format ("StartHTML: {0:d8}", startHTML) + Environment.NewLine +
+ string.Format ("EndHTML: {0:d8}", endHTML) + Environment.NewLine +
+ string.Format ("StartFragment: {0:d8}", startFragment) + Environment.NewLine +
+ string.Format ("EndFragment: {0:d8}", endFragment) + Environment.NewLine;
}
public override bool IsTypeAvailable (TransferDataType type)
diff --git a/Xwt.WPF/Xwt.WPFBackend/DataConverter.cs b/Xwt.WPF/Xwt.WPFBackend/DataConverter.cs
index 45cdef9f..0aa55a8d 100644
--- a/Xwt.WPF/Xwt.WPFBackend/DataConverter.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/DataConverter.cs
@@ -273,6 +273,7 @@ namespace Xwt.WPFBackend
{
if (type == TransferDataType.Text) return DataFormats.UnicodeText;
if (type == TransferDataType.Rtf) return DataFormats.Rtf;
+ if (type == TransferDataType.Html) return DataFormats.Html;
if (type == TransferDataType.Uri) return DataFormats.FileDrop;
if (type == TransferDataType.Image) return DataFormats.Bitmap;
return type.Id;
@@ -284,6 +285,7 @@ namespace Xwt.WPFBackend
if (type == DataFormats.Rtf) return TransferDataType.Rtf;
if (type == DataFormats.FileDrop) return TransferDataType.Uri;
if (type == DataFormats.Bitmap) return TransferDataType.Image;
+ if (type == DataFormats.Html) return TransferDataType.Html;
return TransferDataType.FromId (type);
}
diff --git a/Xwt/Xwt/TransferDataType.cs b/Xwt/Xwt/TransferDataType.cs
index 5adb5ac2..3613beac 100644
--- a/Xwt/Xwt/TransferDataType.cs
+++ b/Xwt/Xwt/TransferDataType.cs
@@ -56,12 +56,17 @@ namespace Xwt
/// The RTF data type
///
public static readonly TransferDataType Rtf = FromId ("rtf");
-
+
///
/// The image data type
///
public static readonly TransferDataType Image = FromId ("image");
-
+
+ ///
+ /// The HTML data type
+ ///
+ public static readonly TransferDataType Html = FromId ("html");
+
private TransferDataType (string id)
{
this.id = id;