2
// "$Id: fl_dnd_win32.cxx 7563 2010-04-28 03:15:47Z greg.ercolano $"
2
// "$Id: fl_dnd_win32.cxx 8028 2010-12-14 19:46:55Z AlbrechtS $"
4
4
// Drag & Drop code for the Fast Light Tool Kit (FLTK).
6
// Copyright 1998-2009 by Bill Spitzak and others.
6
// Copyright 1998-2010 by Bill Spitzak and others.
8
8
// This library is free software; you can redistribute it and/or
9
9
// modify it under the terms of the GNU Library General Public
177
172
HWND hwnd = fl_xid( (Fl_Window*)w );
178
173
if (fillCurrentDragData(data)) {
179
174
int old_event = Fl::e_number;
176
a = b = currDragData;
177
while (*a) { // strip the CRLF pairs
178
if (*a == '\r' && a[1] == '\n') a++;
182
Fl::e_text = currDragData;
183
Fl::e_length = b - currDragData;
180
184
Fl::belowmouse()->handle(Fl::e_number = FL_PASTE); // e_text will be invalid after this call
181
185
Fl::e_number = old_event;
182
186
SetForegroundWindow( hwnd );
211
215
// clear currDrag* for a new drag event
212
216
clearCurrentDragData();
214
// fill currDrag* with ASCII data, if available
219
// fill currDrag* with UTF-8 data, if available
215
220
FORMATETC fmt = { 0 };
216
221
STGMEDIUM medium = { 0 };
217
222
fmt.tymed = TYMED_HGLOBAL;
218
223
fmt.dwAspect = DVASPECT_CONTENT;
225
fmt.cfFormat = CF_UNICODETEXT;
226
// if it is UNICODE text, return a UTF-8-converted copy of it
227
if ( data->GetData( &fmt, &medium )==S_OK )
229
void *stuff = GlobalLock( medium.hGlobal );
231
const wchar_t *wstuff = (const wchar_t *)stuff;
232
while (*wstuff++) srclen++;
233
wstuff = (const wchar_t *)stuff;
234
unsigned utf8len = fl_utf8fromwc(NULL, 0, wstuff, srclen);
235
currDragSize = utf8len;
236
currDragData = (char*)malloc(utf8len + 1);
237
fl_utf8fromwc(currDragData, currDragSize+1, wstuff, srclen+1); // include null-byte
238
GlobalUnlock( medium.hGlobal );
239
ReleaseStgMedium( &medium );
241
return currDragResult;
220
243
fmt.cfFormat = CF_TEXT;
221
// if it is ASCII text, return a copy of it
244
// if it is CP1252 text, return a UTF-8-converted copy of it
222
245
if ( data->GetData( &fmt, &medium )==S_OK )
224
250
void *stuff = GlobalLock( medium.hGlobal );
225
Fl::e_length = strlen((char*)stuff);
226
Fl::e_text = strdup((char*)stuff);
251
currDragData = (char*)malloc(3 * strlen((char*)stuff) + 10);
253
last = p + strlen(p);
256
u = fl_utf8decode(p, last, &len);
258
len = fl_utf8encode(u, q);
262
currDragSize = q - currDragData;
263
currDragData = (char*)realloc(currDragData, currDragSize + 1);
227
264
GlobalUnlock( medium.hGlobal );
228
265
ReleaseStgMedium( &medium );
229
266
currDragResult = 1;
256
Fl::e_text = (char*) malloc(nn * 5 + 1);
293
currDragData = (char*) malloc(nn * 5 + 1);
257
294
// Fl::e_length = fl_unicode2utf(bu, nn, Fl::e_text);
258
Fl::e_length = fl_utf8fromwc(Fl::e_text, (nn*5+1), bu, nn);
259
Fl::e_text[Fl::e_length] = 0;
295
currDragSize = fl_utf8fromwc(currDragData, (nn*5+1), bu, nn);
296
currDragData[currDragSize] = 0;
262
299
// Fl::belowmouse()->handle(FL_DROP);
416
// GetData currently allows ASCII text through Global Memory only
453
// GetData currently allows UNICODE text through Global Memory only
417
454
HRESULT STDMETHODCALLTYPE GetData( FORMATETC *pformatetcIn, STGMEDIUM *pmedium ) {
418
455
if ((pformatetcIn->dwAspect & DVASPECT_CONTENT) &&
419
456
(pformatetcIn->tymed & TYMED_HGLOBAL) &&
420
(pformatetcIn->cfFormat == CF_TEXT))
457
(pformatetcIn->cfFormat == CF_UNICODETEXT))
422
HGLOBAL gh = GlobalAlloc( GHND, fl_selection_length[0]+1 );
459
int utf16_len = fl_utf8toUtf16(fl_selection_buffer[0], fl_selection_length[0], 0, 0);
460
HGLOBAL gh = GlobalAlloc( GHND, utf16_len * 2 + 2 );
423
461
char *pMem = (char*)GlobalLock( gh );
424
memmove( pMem, fl_selection_buffer[0], fl_selection_length[0] );
425
pMem[ fl_selection_length[0] ] = 0;
462
fl_utf8toUtf16(fl_selection_buffer[0], fl_selection_length[0], (unsigned short*)pMem, utf16_len + 1);
426
463
// HGLOBAL gh = GlobalAlloc( GHND| GMEM_SHARE,
427
464
// (fl_selection_length[0]+4) * sizeof(short)
428
465
// + sizeof(DROPFILES));
519
549
if ( ret==DRAGDROP_S_DROP ) return 1; // or DD_S_CANCEL
525
// Always indicate DnD failed when using GCC < 3...
528
#endif // !__GNUC__ || __GNUC__ >= 3
532
// End of "$Id: fl_dnd_win32.cxx 7563 2010-04-28 03:15:47Z greg.ercolano $".
554
// End of "$Id: fl_dnd_win32.cxx 8028 2010-12-14 19:46:55Z AlbrechtS $".