From 683c2ca914f1987dfbeabca54db5b69ccb5c53e9 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 10 Jul 2011 11:24:37 +1000 Subject: Paste text into different encodings. --- cocoa/ScintillaCocoa.mm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cocoa') diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index e097007c9..714fb93e2 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -1101,9 +1101,26 @@ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selec { if (selectedText != nil) { - char* text = (char*) [data UTF8String]; + CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + CFRange rangeAll = {0, [data length]}; + CFIndex usedLen = 0; + CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', + false, NULL, 0, &usedLen); + + UInt8 *buffer = new UInt8[usedLen]; + + CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', + false, buffer,usedLen, NULL); + bool rectangular = bestType == ScintillaRecPboardType; - selectedText->Copy(text, strlen(text) + 1, SC_CP_UTF8, SC_CHARSET_DEFAULT , rectangular, false); + + int len = usedLen; + char *dest = Document::TransformLineEnds(&len, (char *)buffer, len, pdoc->eolMode); + + selectedText->Set(dest, len+1, pdoc->dbcsCodePage, + vs.styles[STYLE_DEFAULT].characterSet , rectangular, false); + delete []buffer; } return true; } -- cgit v1.2.3