summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabien Costantini <fabien@onepost.net>2009-01-12 12:43:03 +0000
committerFabien Costantini <fabien@onepost.net>2009-01-12 12:43:03 +0000
commit84920d7cf1d004849ebcea7eb1cdd5ca2e9abc36 (patch)
tree077f3f9727973be9cbf275517d4c42760d0e2978 /src
parenteec7f80e949dd78874741a6c17fe66ec74cec3a5 (diff)
STR #2104 fix: applied patch from sadysta, modified it to harmonize with existing win32 code like global alloc code, wchar_t type use. Added a wchar.h include for gcc win32 targets, compiled and tested under vc2005, gcc mingw, gcc cygwin.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6624 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_win32.cxx29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index 8ff28b0e8..94da4d1a8 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -61,6 +61,10 @@
#include <winuser.h>
#include <commctrl.h>
+#if defined(__GNUC__) && __GNUC__ >= 3
+# include <wchar.h>
+#endif
+
// The following include files require GCC 3.x or a non-GNU compiler...
#if !defined(__GNUC__) || __GNUC__ >= 3
# include <ole2.h>
@@ -548,11 +552,17 @@ void Fl::copy(const char *stuff, int len, int clipboard) {
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(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
+ LPVOID memLock = GlobalLock(hMem);
+ fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len * 2);
+ 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 +597,26 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) {
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);
+ wchar_t *memLock = (wchar_t*) 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();
}