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 This is what seems to work for me: // call this when you create a selection: void Fl::copy(const char *stuff, int len, int clipboard) { if (!stuff || len<0) return; // Convert \n -> \r\n (for old apps like Notepad, DOS) Lf2CrlfConvert buf(stuff, len); len = buf.GetLength(); stuff = buf.GetValue(); if (len+1 > fl_selection_buffer_length[clipboard]) { delete[] fl_selection_buffer[clipboard]; fl_selection_buffer[clipboard] = new char[len+100]; fl_selection_buffer_length[clipboard] = len+100; } memcpy(fl_selection_buffer[clipboard], stuff, len); fl_selection_buffer[clipboard][len] = 0; // needed for direct paste fl_selection_length[clipboard] = len; if (clipboard) { // set up for "delayed rendering": if (OpenClipboard(NULL)) { // fl_xid(Fl::first_window()))) { // if the system clipboard works, use it int utf16_len = fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], 0, 0); EmptyClipboard(); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, utf16_len * 2 + 2); LPVOID memLock = GlobalLock(hMem); // CopyMemory(memLock, fl_selection_buffer[clipboard], fl_selection_length[clipboard] + 1); 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 fl_i_own_selection[clipboard] = 1; } } } // Call this when a "paste" operation happens: void Fl::paste(Fl_Widget &receiver, int clipboard) { if (!clipboard || fl_i_own_selection[clipboard]) { // We already have it, do it quickly without window server. // Notice that the text is clobbered if set_selection is // called in response to FL_PASTE! // Convert \r\n -> \n char *i = fl_selection_buffer[clipboard]; if (i==0L) { Fl::e_text = 0; return; } Fl::e_text = new char[fl_selection_length[clipboard]+1]; char *o = Fl::e_text; while (*i) { if ( *i == '\r' && *(i+1) == '\n') i++; else *o++ = *i++; } *o = 0; Fl::e_length = o - Fl::e_text; receiver.handle(FL_PASTE); delete [] Fl::e_text; Fl::e_text = 0; } else { if (!OpenClipboard(NULL)) return; HANDLE h = GetClipboardData(CF_UNICODETEXT); if (h) { unsigned short *memLock = (unsigned short*) GlobalLock(h); /* if (!memLock) { // Give it a second go... h = GetClipboardData(CF_UNICODETEXT); memLock = (unsigned short*) GlobalLock(h); } */ int utf16_len = wcslen(memLock); // int utf8_len = fl_utf8fromwc(memLock, utf16_len, 0, 0); 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; // GlobalUnlock(h); // Fl::e_text = (LPSTR)GlobalLock(h); LPSTR a,b; a = b = Fl::e_text; while (*a) { // strip the CRLF pairs ($...@^) 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(); } } Link: http://www.fltk.org/str.php?L2104 Version: 1.3-current _______________________________________________ fltk-bugs mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-bugs
