From e9ef99002fbda41d56f2374e562daff473ff39f5 Mon Sep 17 00:00:00 2001 From: Fabien Costantini Date: Mon, 12 Jan 2009 13:55:55 +0000 Subject: STR#2121 fix: Fixed paste from utf16 content would not work in fltk input widgets, thanks manolo for the code fragment. Code inserted into Fl_mac.cxx, tested, regression tested with utf greg japanese example from fltk to fltk, now all test cases work fine in mac os x (10.5.5). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6625 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_mac.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index c937cfb4f..bec0f229f 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -2585,6 +2585,27 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) { i = nFlavor+1; break; } + // accept the utf16 copied buffers (I.e: like in ms Word (r) and other text editors + else if (UTTypeConformsTo(flavorType, CFSTR("public.utf16-plain-text"))) { + err = PasteboardCopyItemFlavorData( myPasteboard, itemID, CFSTR("public.utf16-plain-text"), &flavorData ); + if(err != noErr) continue; + len = CFDataGetLength(flavorData); + CFStringRef mycfs = CFStringCreateWithBytes(NULL, CFDataGetBytePtr(flavorData), len, kCFStringEncodingUnicode, false); + CFRelease (flavorData); + len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(mycfs), kCFStringEncodingUTF8) + 1; + if ( len > fl_selection_buffer_length[1] ) { + fl_selection_buffer_length[1] = len; + delete[] fl_selection_buffer[1]; + fl_selection_buffer[1] = new char[len]; + } + CFStringGetCString(mycfs, fl_selection_buffer[1], len, kCFStringEncodingUTF8); + CFRelease (mycfs); + len = strlen(fl_selection_buffer[1]); + fl_selection_length[1] = len; + for(char *p=fl_selection_buffer[1]; p < fl_selection_buffer[1]+len; p++) if(*p == '\r') *p = '\n'; + i = nFlavor+1; + break; + } } CFRelease (flavorTypeArray); } -- cgit v1.2.3