Alexandre Julliard : winex11: Add basic support for importing text/ html clipboard format.

Alexandre Julliard julliard at winehq.org
Wed Jan 11 15:45:47 CST 2017


Module: wine
Branch: master
Commit: 8df9a11adebf72f3f1046a2efad6e8c85fc44c40
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8df9a11adebf72f3f1046a2efad6e8c85fc44c40

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Jan 11 20:55:21 2017 +0100

winex11: Add basic support for importing text/html clipboard format.

Based on a patch by Damjan Jovanovic.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winex11.drv/clipboard.c | 47 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/dlls/winex11.drv/clipboard.c b/dlls/winex11.drv/clipboard.c
index 1d7dbad..4cb8cb8 100644
--- a/dlls/winex11.drv/clipboard.c
+++ b/dlls/winex11.drv/clipboard.c
@@ -116,6 +116,7 @@ static HANDLE import_string( Atom type, const void *data, size_t size );
 static HANDLE import_utf8_string( Atom type, const void *data, size_t size );
 static HANDLE import_compound_text( Atom type, const void *data, size_t size );
 static HANDLE import_text( Atom type, const void *data, size_t size );
+static HANDLE import_text_html( Atom type, const void *data, size_t size );
 static HANDLE import_text_uri_list( Atom type, const void *data, size_t size );
 static HANDLE import_targets( Atom type, const void *data, size_t size );
 
@@ -174,7 +175,7 @@ static const struct
     { JFIFW, 0,              XATOM_image_jpeg,          import_data,          export_data },
     { PNGW, 0,               XATOM_image_png,           import_data,          export_data },
     { HTMLFormatW, 0,        XATOM_HTML_Format,         import_data,          export_data },
-    { HTMLFormatW, 0,        XATOM_text_html,           import_data,          export_text_html },
+    { HTMLFormatW, 0,        XATOM_text_html,           import_text_html,     export_text_html },
     { 0, 0,                  XATOM_TARGETS,             import_targets,       export_targets },
     { 0, 0,                  XATOM_MULTIPLE,            NULL,                 export_multiple },
     { 0, 0,                  XATOM_TIMESTAMP,           NULL,                 export_timestamp },
@@ -842,6 +843,50 @@ static HANDLE import_enhmetafile( Atom type, const void *data, size_t size )
 
 
 /**************************************************************************
+ *              import_text_html
+ */
+static HANDLE import_text_html( Atom type, const void *data, size_t size )
+{
+    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-->";
+    char *text = NULL;
+    HANDLE ret;
+    SIZE_T len, total;
+
+    /* Firefox uses UTF-16LE with byte order mark. Convert to UTF-8 without the BOM. */
+    if (size >= sizeof(WCHAR) && ((const WCHAR *)data)[0] == 0xfeff)
+    {
+        len = WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
+                                   NULL, 0, NULL, NULL );
+        if (!(text = HeapAlloc( GetProcessHeap(), 0, len ))) return 0;
+        WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
+                             text, len, NULL, NULL );
+        size = len;
+        data = text;
+    }
+
+    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 */ );
+        memcpy( p, data, size );
+        strcpy( p + size, trailer );
+        TRACE( "returning %s\n", debugstr_a( ret ));
+    }
+    HeapFree( GetProcessHeap(), 0, text );
+    return ret;
+}
+
+
+/**************************************************************************
  *      import_text_uri_list
  *
  *  Import text/uri-list.




More information about the wine-cvs mailing list