DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2104
Version: 1.3-current





Link: http://www.fltk.org/str.php?L2104
Version: 1.3-current
--- Fl_win32.cxx.orig   2009-01-11 16:24:42.336344000 -0800
+++ Fl_win32.cxx        2009-01-11 16:33:08.945327728 -0800
@@ -548,11 +548,18 @@
   fl_selection_length[clipboard] = len;
   if (clipboard) {
     // set up for "delayed rendering":
-    if (OpenClipboard(fl_xid(Fl::first_window()))) {
+    if (OpenClipboard(NULL)) {
       // if the system clipboard works, use it
+      int utf16_len = fl_utf8toUtf16(fl_selection_buffer[clipboard], 
fl_selection_length[clipboard], 0, 0);
       EmptyClipboard();
-      SetClipboardData(CF_TEXT, NULL);
+      HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, utf16_len * 2 + 2);
+      LPVOID memLock = GlobalLock(hMem);
+      fl_utf8toUtf16(fl_selection_buffer[clipboard], 
fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len * 2);
+      *((unsigned short*) memLock + utf16_len) = 0;
+      GlobalUnlock(hMem);
+      SetClipboardData(CF_UNICODETEXT, hMem);
       CloseClipboard();
+      GlobalFree(hMem);
       fl_i_own_selection[clipboard] = 0;
     } else {
       // only if it fails, instruct paste() to use the internal buffers
@@ -587,19 +594,25 @@
     Fl::e_text = 0;
   } else {
     if (!OpenClipboard(NULL)) return;
-    HANDLE h = GetClipboardData(CF_TEXT);
+    HANDLE h = GetClipboardData(CF_UNICODETEXT);
     if (h) {
-      Fl::e_text = (LPSTR)GlobalLock(h);
+      unsigned short *memLock = (unsigned short*) GlobalLock(h);
+      int utf16_len = wcslen(memLock);
+      Fl::e_text = (char*) malloc (utf16_len * 4 + 1);
+      int utf8_len = fl_utf8fromwc(Fl::e_text, utf16_len * 4, memLock, 
utf16_len);
+      *(Fl::e_text + utf8_len) = 0;
       LPSTR a,b;
       a = b = Fl::e_text;
       while (*a) { // strip the CRLF pairs ($...@^)
-       if (*a == '\r' && a[1] == '\n') a++;
-       else *b++ = *a++;
+        if (*a == '\r' && a[1] == '\n') a++;
+        else *b++ = *a++;
       }
       *b = 0;
       Fl::e_length = b - Fl::e_text;
       receiver.handle(FL_PASTE);
       GlobalUnlock(h);
+      free(Fl::e_text);
+      Fl::e_text = 0;
     }
     CloseClipboard();
   }
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to