aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Crozat2018-04-11 00:04:48 +0100
committerThierry Crozat2018-04-29 21:47:10 +0100
commite79fc3ac7644552a62ebe459ee5abb024ff73e20 (patch)
tree9bc1dc7138dec3079076fabfa6a44616200eef90
parent0dae57ab2f921eef19aa6f4a357d0569c2036cc8 (diff)
downloadscummvm-rg350-e79fc3ac7644552a62ebe459ee5abb024ff73e20.tar.gz
scummvm-rg350-e79fc3ac7644552a62ebe459ee5abb024ff73e20.tar.bz2
scummvm-rg350-e79fc3ac7644552a62ebe459ee5abb024ff73e20.zip
OSX: Handle encoding conversion for clipboard text
-rw-r--r--backends/platform/sdl/macosx/macosx_wrapper.mm26
1 files changed, 21 insertions, 5 deletions
diff --git a/backends/platform/sdl/macosx/macosx_wrapper.mm b/backends/platform/sdl/macosx/macosx_wrapper.mm
index 0a1478fe59..32dfa040cc 100644
--- a/backends/platform/sdl/macosx/macosx_wrapper.mm
+++ b/backends/platform/sdl/macosx/macosx_wrapper.mm
@@ -24,11 +24,13 @@
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
+#include "common/translation.h"
#include <AppKit/NSPasteboard.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSPathUtilities.h>
#include <AvailabilityMacros.h>
+#include <CoreFoundation/CFString.h>
bool hasTextInClipboardMacOSX() {
return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil;
@@ -43,16 +45,30 @@ Common::String getTextFromClipboardMacOSX() {
NSString *str = [pb stringForType:NSStringPboardType];
if (str == nil)
return Common::String();
- // If the string cannot be represented using the requested encoding we get a null pointer below.
- // This is fine as ScummVM would not know what to do with non-ASCII characters (although maybe
- // we should use NSISOLatin1StringEncoding?).
- return Common::String([str cStringUsingEncoding:NSASCIIStringEncoding]);
+
+ // If translations are supported, use the current TranslationManager charset and otherwise
+ // use ASCII. If the string cannot be represented using the requested encoding we get a null
+ // pointer below, which is fine as ScummVM would not know what to do with the string anyway.
+#ifdef USE_TRANSLATION
+ NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
+ NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
+#else
+ NSStringEncoding encoding = NSISOLatin1StringEncoding;
+#endif
+ return Common::String([str cStringUsingEncoding:encoding]);
}
bool setTextInClipboardMacOSX(const Common::String &text) {
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
- return [pb setString:[NSString stringWithCString:text.c_str() encoding:NSASCIIStringEncoding] forType:NSStringPboardType];
+
+#ifdef USE_TRANSLATION
+ NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
+ NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
+#else
+ NSStringEncoding encoding = NSISOLatin1StringEncoding;
+#endif
+ return [pb setString:[NSString stringWithCString:text.c_str() encoding:encoding] forType:NSStringPboardType];
}
Common::String getDesktopPathMacOSX() {