Merge pull request #179 from mkrueger/master
Added Html clipboard format/fixed some issues with RTF in the GTK backend.
This commit is contained in:
Коммит
c413486f73
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a CF_HTML cliboard format document
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a CF_HTML clipboard format header.
|
||||
/// </summary>
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,12 +56,17 @@ namespace Xwt
|
|||
/// The RTF data type
|
||||
/// </summary>
|
||||
public static readonly TransferDataType Rtf = FromId ("rtf");
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The image data type
|
||||
/// </summary>
|
||||
public static readonly TransferDataType Image = FromId ("image");
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The HTML data type
|
||||
/// </summary>
|
||||
public static readonly TransferDataType Html = FromId ("html");
|
||||
|
||||
private TransferDataType (string id)
|
||||
{
|
||||
this.id = id;
|
||||
|
|
Загрузка…
Ссылка в новой задаче