[PATCH 1/3] winemac: Add basic support for importing the public.html pasteboard format.
Ken Thomases
ken at codeweavers.com
Fri Jan 13 13:36:20 CST 2017
Continue exporting in the original format under org.winehq.registered.HTML Format
for fidelity when copying and pasting within Wine.
Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
dlls/winemac.drv/clipboard.c | 62 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 53 insertions(+), 9 deletions(-)
diff --git a/dlls/winemac.drv/clipboard.c b/dlls/winemac.drv/clipboard.c
index fc1589f..fdd1110 100644
--- a/dlls/winemac.drv/clipboard.c
+++ b/dlls/winemac.drv/clipboard.c
@@ -70,6 +70,7 @@ static HANDLE import_clipboard_data(CFDataRef data);
static HANDLE import_bmp_to_bitmap(CFDataRef data);
static HANDLE import_bmp_to_dib(CFDataRef data);
static HANDLE import_enhmetafile(CFDataRef data);
+static HANDLE import_html(CFDataRef data);
static HANDLE import_metafilepict(CFDataRef data);
static HANDLE import_nsfilenames_to_hdrop(CFDataRef data);
static HANDLE import_utf8_to_text(CFDataRef data);
@@ -177,13 +178,15 @@ static const struct
CFStringRef type;
DRVIMPORTFUNC import;
DRVEXPORTFUNC export;
+ BOOL synthesized;
} builtin_format_names[] =
{
{ wszRichTextFormat, CFSTR("public.rtf"), import_clipboard_data, export_clipboard_data },
{ wszGIF, CFSTR("com.compuserve.gif"), import_clipboard_data, export_clipboard_data },
{ wszJFIF, CFSTR("public.jpeg"), import_clipboard_data, export_clipboard_data },
{ wszPNG, CFSTR("public.png"), import_clipboard_data, export_clipboard_data },
- { wszHTMLFormat, CFSTR("public.html"), import_clipboard_data, export_clipboard_data },
+ { wszHTMLFormat, NULL, import_clipboard_data, export_clipboard_data },
+ { wszHTMLFormat, CFSTR("public.html"), import_html, NULL, TRUE },
{ CFSTR_SHELLURLW, CFSTR("public.url"), import_utf8_to_text, export_text_to_utf8 },
};
@@ -355,24 +358,32 @@ static void register_builtin_formats(void)
list_add_tail(&format_list, &format->entry);
}
- LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
- {
- if (format->synthesized)
- format->natural_format = natural_format_for_format(format->format_id);
- }
-
/* Register known mappings between Windows formats and Mac types */
for (i = 0; i < sizeof(builtin_format_names)/sizeof(builtin_format_names[0]); i++)
{
if (!(format = HeapAlloc(GetProcessHeap(), 0, sizeof(*format)))) break;
format->format_id = RegisterClipboardFormatW(builtin_format_names[i].name);
- format->type = CFRetain(builtin_format_names[i].type);
format->import_func = builtin_format_names[i].import;
format->export_func = builtin_format_names[i].export;
- format->synthesized = FALSE;
+ format->synthesized = builtin_format_names[i].synthesized;
format->natural_format = NULL;
+
+ if (builtin_format_names[i].type)
+ format->type = CFRetain(builtin_format_names[i].type);
+ else
+ {
+ format->type = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%S"),
+ registered_name_type_prefix, builtin_format_names[i].name);
+ }
+
list_add_tail(&format_list, &format->entry);
}
+
+ LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
+ {
+ if (format->synthesized)
+ format->natural_format = natural_format_for_format(format->format_id);
+ }
}
@@ -616,6 +627,39 @@ static HANDLE import_enhmetafile(CFDataRef data)
/**************************************************************************
+ * import_html
+ *
+ * Import HTML data.
+ */
+static HANDLE import_html(CFDataRef data)
+{
+ static const char header[] =
+ "Version:0.9\n"
+ "StartHTML:0000000100\n"
+ "EndHTML:%010lu\n"
+ "StartFragment:%010lu\n"
+ "EndFragment:%010lu\n"
+ "<!--StartFragment-->";
+ static const char trailer[] = "\n<!--EndFragment-->";
+ HANDLE ret;
+ SIZE_T len, total;
+ size_t size = CFDataGetLength(data);
+
+ len = strlen(header) + 12; /* 3 * 4 extra chars for %010lu */
+ total = len + size + sizeof(trailer);
+ if ((ret = GlobalAlloc(GMEM_FIXED, total)))
+ {
+ char *p = ret;
+ p += sprintf(p, header, total - 1, len, len + size + 1 /* include the final \n in the data */);
+ CFDataGetBytes(data, CFRangeMake(0, size), (UInt8*)p);
+ strcpy(p + size, trailer);
+ TRACE("returning %s\n", debugstr_a(ret));
+ }
+ return ret;
+}
+
+
+/**************************************************************************
* import_metafilepict
*
* Import metafile picture data, converting it to CF_METAFILEPICT.
--
2.10.2
More information about the wine-patches
mailing list