changeset 1754:eeec5ceec7a5

Enable unicode cut and paste on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 16 Jun 2012 08:49:10 +0000
parents 87c215963fdc
children 9f7fc4fca5a6
files win/dw.c
diffstat 1 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Sat Jun 16 06:24:08 2012 +0000
+++ b/win/dw.c	Sat Jun 16 08:49:10 2012 +0000
@@ -11556,20 +11556,26 @@
 char * API dw_clipboard_get_text(void)
 {
    HANDLE handle;
-   char *tmp, *ret = NULL;
+   char *ret = NULL;
+   TCHAR *tmp;
+#ifdef UNICODE
+   int type = CF_UNICODETEXT;
+#else   
+   int type = CF_TEXT;
+#endif
 
    if ( !OpenClipboard( NULL ) )
       return ret;
 
-   if ( ( handle = GetClipboardData( CF_TEXT) ) == NULL )
+   if ( ( handle = GetClipboardData(type) ) == NULL )
    {
       CloseClipboard();
       return ret;
    }
 
-   if ( (tmp = GlobalLock(handle)) && strlen(tmp) )
-   {
-        ret = _strdup(tmp);
+   if ( (tmp = GlobalLock(handle)) && _tcslen(tmp) )
+   {
+        ret = _strdup(WideToUTF8(tmp));
         GlobalUnlock(handle);
    }
    CloseClipboard();
@@ -11585,6 +11591,20 @@
 {
    HGLOBAL ptr1;
    LPTSTR ptr2;
+   TCHAR *buf;
+#ifdef UNICODE
+   int type = CF_UNICODETEXT;
+   char *src = calloc(len + 1, 1);
+
+   memcpy(src, str, len);
+   buf = UTF8toWide(src);
+   free(src);
+   len = _tcslen(buf);
+#else   
+   int type = CF_TEXT;
+   
+   buf = str;
+#endif
 
    if ( !OpenClipboard( NULL ) )
       return;
@@ -11596,16 +11616,14 @@
 
    ptr2 = GlobalLock( ptr1 );
 
-   memcpy( (char *)ptr2, str, len + 1);
+   memcpy(ptr2, buf, (len + 1) * sizeof(TCHAR));
    GlobalUnlock( ptr1 );
    EmptyClipboard();
 
-   SetClipboardData( CF_TEXT, ptr1 );
+   SetClipboardData( type, ptr1 );
 
    CloseClipboard();
    GlobalFree( ptr1 );
-
-   return;
 }
 
 /*