diff options
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r-- | backends/platform/sdl/macosx/macosx.cpp | 4 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.h | 1 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx_wrapper.h | 1 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx_wrapper.mm | 32 | ||||
-rw-r--r-- | backends/platform/sdl/psp2/psp2-main.cpp | 4 | ||||
-rw-r--r-- | backends/platform/sdl/psp2/psp2.cpp | 8 | ||||
-rw-r--r-- | backends/platform/sdl/riscos/riscos-main.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/riscos/riscos.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/riscos/riscos.mk | 3 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 34 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 1 |
11 files changed, 76 insertions, 16 deletions
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index 8ecbe7306c..62037200ea 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -124,6 +124,10 @@ Common::String OSystem_MacOSX::getTextFromClipboard() { return getTextFromClipboardMacOSX(); } +bool OSystem_MacOSX::setTextInClipboard(const Common::String &text) { + return setTextInClipboardMacOSX(text); +} + bool OSystem_MacOSX::openUrl(const Common::String &url) { CFURLRef urlRef = CFURLCreateWithBytes (NULL, (UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL); OSStatus err = LSOpenCFURLRef(urlRef, NULL); diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index ba07364681..5ef30baa64 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -35,6 +35,7 @@ public: virtual bool hasTextInClipboard(); virtual Common::String getTextFromClipboard(); + virtual bool setTextInClipboard(const Common::String &text); virtual bool openUrl(const Common::String &url); diff --git a/backends/platform/sdl/macosx/macosx_wrapper.h b/backends/platform/sdl/macosx/macosx_wrapper.h index 84f0c1b2ba..ca4e433890 100644 --- a/backends/platform/sdl/macosx/macosx_wrapper.h +++ b/backends/platform/sdl/macosx/macosx_wrapper.h @@ -27,6 +27,7 @@ bool hasTextInClipboardMacOSX(); Common::String getTextFromClipboardMacOSX(); +bool setTextInClipboardMacOSX(const Common::String &text); Common::String getDesktopPathMacOSX(); #endif diff --git a/backends/platform/sdl/macosx/macosx_wrapper.mm b/backends/platform/sdl/macosx/macosx_wrapper.mm index 02516e5ffe..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; @@ -40,13 +42,33 @@ Common::String getTextFromClipboardMacOSX() { // Note: on OS X 10.6 and above it is recommanded to use NSPasteboardTypeString rather than NSStringPboardType. // But since we still target older version use NSStringPboardType. NSPasteboard *pb = [NSPasteboard generalPasteboard]; - NSString* str = [pb stringForType:NSStringPboardType]; + 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]; + +#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() { diff --git a/backends/platform/sdl/psp2/psp2-main.cpp b/backends/platform/sdl/psp2/psp2-main.cpp index 0bdf0b34bc..70cc52388e 100644 --- a/backends/platform/sdl/psp2/psp2-main.cpp +++ b/backends/platform/sdl/psp2/psp2-main.cpp @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) { scePowerSetBusClockFrequency(222); scePowerSetGpuClockFrequency(222); scePowerSetGpuXbarClockFrequency(166); - + // Create our OSystem instance g_system = new OSystem_PSP2(); assert(g_system); @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { // Free OSystem delete (OSystem_PSP2 *)g_system; - + #ifdef __PSP2_DEBUG__ psp2shell_exit(); #endif diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp index 3034b6d886..80604a69d5 100644 --- a/backends/platform/sdl/psp2/psp2.cpp +++ b/backends/platform/sdl/psp2/psp2.cpp @@ -55,11 +55,11 @@ OSystem_PSP2::OSystem_PSP2(Common::String baseConfigName) } void OSystem_PSP2::init() { - + #if __PSP2_DEBUG__ gDebugLevel = 3; #endif - + // Initialze File System Factory sceIoMkdir("ux0:data", 0755); sceIoMkdir("ux0:data/scummvm", 0755); @@ -71,7 +71,7 @@ void OSystem_PSP2::init() { } void OSystem_PSP2::initBackend() { - + ConfMan.set("joystick_num", 0); ConfMan.registerDefault("fullscreen", true); ConfMan.registerDefault("aspect_ratio", false); @@ -105,7 +105,7 @@ void OSystem_PSP2::initBackend() { ConfMan.setBool("frontpanel_touchpad_mode", false); } - + // Create the savefile manager if (_savefileManager == 0) _savefileManager = new DefaultSaveFileManager("ux0:data/scummvm/saves"); diff --git a/backends/platform/sdl/riscos/riscos-main.cpp b/backends/platform/sdl/riscos/riscos-main.cpp index 2ff8294c1a..3f7058e3b8 100644 --- a/backends/platform/sdl/riscos/riscos-main.cpp +++ b/backends/platform/sdl/riscos/riscos-main.cpp @@ -29,7 +29,7 @@ #include "base/main.h" int main(int argc, char *argv[]) { - + // Create our OSystem instance g_system = new OSystem_RISCOS(); assert(g_system); diff --git a/backends/platform/sdl/riscos/riscos.cpp b/backends/platform/sdl/riscos/riscos.cpp index 0cdbceb902..73c0fdae03 100644 --- a/backends/platform/sdl/riscos/riscos.cpp +++ b/backends/platform/sdl/riscos/riscos.cpp @@ -101,4 +101,4 @@ Common::WriteStream *OSystem_RISCOS::createLogFile() { } #endif -
+ diff --git a/backends/platform/sdl/riscos/riscos.mk b/backends/platform/sdl/riscos/riscos.mk index 534b7aeb52..0a3061fd3a 100644 --- a/backends/platform/sdl/riscos/riscos.mk +++ b/backends/platform/sdl/riscos/riscos.mk @@ -21,4 +21,5 @@ ifdef DYNAMIC_MODULES endif mkdir -p !ScummVM/docs cp ${srcdir}/dists/riscos/!Help,feb !ScummVM/!Help,feb - cp $(DIST_FILES_DOCS) !ScummVM/docs
\ No newline at end of file + cp $(DIST_FILES_DOCS) !ScummVM/docs + cp -r ${srcdir}/doc/* !ScummVM/docs diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 3082a69ebf..72af6d592a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -33,6 +33,7 @@ #include "gui/EventRecorder.h" #include "common/taskbar.h" #include "common/textconsole.h" +#include "common/translation.h" #include "backends/saves/default/default-saves.h" @@ -502,17 +503,46 @@ Common::String OSystem_SDL::getTextFromClipboard() { #if SDL_VERSION_ATLEAST(2, 0, 0) char *text = SDL_GetClipboardText(); + // The string returned by SDL is in UTF-8. Convert to the + // current TranslationManager encoding or ISO-8859-1. +#ifdef USE_TRANSLATION + char *conv_text = SDL_iconv_string(TransMan.getCurrentCharset().c_str(), "UTF-8", text, SDL_strlen(text) + 1); +#else + char *conv_text = SDL_iconv_string("ISO-8859-1", "UTF-8", text, SDL_strlen(text) + 1); +#endif + if (conv_text) { + SDL_free(text); + text = conv_text; + } Common::String strText = text; SDL_free(text); - // FIXME: The string returned by SDL is in UTF-8, it is not clear - // what encoding should be used for the returned string. return strText; #else return ""; #endif } +bool OSystem_SDL::setTextInClipboard(const Common::String &text) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + // The encoding we need to use is UTF-8. Assume we currently have the + // current TranslationManager encoding or ISO-8859-1. +#ifdef USE_TRANSLATION + char *utf8_text = SDL_iconv_string("UTF-8", TransMan.getCurrentCharset().c_str(), text.c_str(), text.size() + 1); +#else + char *utf8_text = SDL_iconv_string("UTF-8", "ISO-8859-1", text.c_str(), text.size() + 1); +#endif + if (utf8_text) { + int status = SDL_SetClipboardText(utf8_text); + SDL_free(utf8_text); + return status == 0; + } + return SDL_SetClipboardText(text.c_str()) == 0; +#else + return false; +#endif +} + uint32 OSystem_SDL::getMillis(bool skipRecord) { uint32 millis = SDL_GetTicks(); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 61513fa65f..c746d2d2dd 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -72,6 +72,7 @@ public: // Clipboard virtual bool hasTextInClipboard(); virtual Common::String getTextFromClipboard(); + virtual bool setTextInClipboard(const Common::String &text); virtual void setWindowCaption(const char *caption); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); |