summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2013-09-23 15:01:54 +0000
committerManolo Gouy <Manolo>2013-09-23 15:01:54 +0000
commitcedcc3f52e7d60ed13f3e825147f9590cb1045dd (patch)
treee0a5e17951d0a9d890ba5f09cbba9e8012bd90e9
parent25ff26df1207da4a7d5ceef4502f025d65533a07 (diff)
Fixed implementation of paste with NSPasteboard that did not work well under Mac OS 10.5
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9985 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_cocoa.mm28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 11aaa47eb..2c45e9f94 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -2740,9 +2740,8 @@ static void clipboard_check(void)
/*
* create a selection
- * owner: widget that created the selection
* stuff: pointer to selected data
- * size of selected data
+ * len: size of selected data
*/
void Fl::copy(const char *stuff, int len, int clipboard) {
if (!stuff || len<0) return;
@@ -2771,17 +2770,36 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) {
fl_selection_length[1] = 0;
NSPasteboard *clip = [NSPasteboard generalPasteboard];
- NSString *found = [clip availableTypeFromArray:[NSArray arrayWithObject:utf8_format]];
+ NSString *found = [clip availableTypeFromArray:[NSArray arrayWithObjects:utf8_format, @"public.utf16-plain-text", @"com.apple.traditional-mac-plain-text", nil]];
if (found) {
NSData *data = [clip dataForType:found];
if (data) {
- NSInteger len = [data length] + 1;
+ NSInteger len;
+ char *aux_c;
+ if (![found isEqualToString:utf8_format]) {
+ NSString *auxstring;
+ auxstring = (NSString *)CFStringCreateWithBytes(NULL,
+ (const UInt8*)[data bytes],
+ [data length],
+ [found isEqualToString:@"public.utf16-plain-text"] ? kCFStringEncodingUnicode : kCFStringEncodingMacRoman,
+ false);
+ aux_c = strdup([auxstring UTF8String]);
+ [auxstring release];
+ len = strlen(aux_c) + 1;
+ }
+ else len = [data length] + 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];
}
- [data getBytes:fl_selection_buffer[1]];
+ if (![found isEqualToString:utf8_format]) {
+ strcpy(fl_selection_buffer[1], aux_c);
+ free(aux_c);
+ }
+ else {
+ [data getBytes:fl_selection_buffer[1]];
+ }
fl_selection_buffer[1][len - 1] = 0;
fl_selection_length[1] = len - 1;
convert_crlf(fl_selection_buffer[1], len - 1); // turn all \r characters into \n: