summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2010-12-12 21:49:54 +0000
committerManolo Gouy <Manolo>2010-12-12 21:49:54 +0000
commit726feebff6e288b6abe4248a1f01e426e7c161db (patch)
treeb9f3da7378bc2203f436ea4f6c824bf6977b4102 /src
parent808417739ec2ed226c5b471951f86ed8be943784 (diff)
Hopefully last fix for STR #2472. The DnD receive code has been changed from accepting
ASCII text and transmitting it unchanged to the FLTK widget into accepting either UTF-16 or CP1252 text and in both cases transmitting it to FLTK recoded into UTF-8. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8021 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_dnd_win32.cxx38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/fl_dnd_win32.cxx b/src/fl_dnd_win32.cxx
index 7673af165..92b195ef4 100644
--- a/src/fl_dnd_win32.cxx
+++ b/src/fl_dnd_win32.cxx
@@ -220,13 +220,45 @@ private:
fmt.tymed = TYMED_HGLOBAL;
fmt.dwAspect = DVASPECT_CONTENT;
fmt.lindex = -1;
+ fmt.cfFormat = CF_UNICODETEXT;
+ // if it is UNICODE text, return a UTF-8-converted copy of it
+ if ( data->GetData( &fmt, &medium )==S_OK )
+ {
+ void *stuff = GlobalLock( medium.hGlobal );
+ unsigned srclen = 0;
+ const wchar_t *wstuff = (const wchar_t *)stuff;
+ while(*wstuff++) srclen++;
+ wstuff = (const wchar_t *)stuff;
+ unsigned utf8len = fl_utf8fromwc(NULL, 0, wstuff, srclen);
+ Fl::e_length = utf8len;
+ Fl::e_text = (char*)malloc(utf8len + 1);
+ fl_utf8fromwc(Fl::e_text, Fl::e_length, wstuff, srclen);
+ GlobalUnlock( medium.hGlobal );
+ ReleaseStgMedium( &medium );
+ currDragResult = 1;
+ return currDragResult;
+ }
fmt.cfFormat = CF_TEXT;
- // if it is ASCII text, return a copy of it
+ // if it is CP1252 text, return a UTF-8-converted copy of it
if ( data->GetData( &fmt, &medium )==S_OK )
{
+ int len;
+ char *p, *q, *last;
+ unsigned u;
void *stuff = GlobalLock( medium.hGlobal );
- Fl::e_length = strlen((char*)stuff);
- Fl::e_text = strdup((char*)stuff);
+ Fl::e_text = (char*)malloc(3 * strlen((char*)stuff) + 10);
+ p = (char*)stuff;
+ last = p + strlen(p);
+ q = Fl::e_text;
+ while (p < last) {
+ u = fl_utf8decode(p, last, &len);
+ p += len;
+ len = fl_utf8encode(u, q);
+ q += len;
+ }
+ *q = 0;
+ Fl::e_length = q - Fl::e_text;
+ Fl::e_text = (char*)realloc(Fl::e_text, Fl::e_length + 1);
GlobalUnlock( medium.hGlobal );
ReleaseStgMedium( &medium );
currDragResult = 1;