aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/platform/sdl/macosx/macosx.cpp4
-rw-r--r--backends/platform/sdl/macosx/macosx.h1
-rw-r--r--backends/platform/sdl/macosx/macosx_wrapper.h1
-rw-r--r--backends/platform/sdl/macosx/macosx_wrapper.mm8
-rw-r--r--backends/platform/sdl/sdl.cpp9
-rw-r--r--backends/platform/sdl/sdl.h1
-rw-r--r--common/system.h15
7 files changed, 36 insertions, 3 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..0a1478fe59 100644
--- a/backends/platform/sdl/macosx/macosx_wrapper.mm
+++ b/backends/platform/sdl/macosx/macosx_wrapper.mm
@@ -40,7 +40,7 @@ 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.
@@ -49,6 +49,12 @@ Common::String getTextFromClipboardMacOSX() {
return Common::String([str cStringUsingEncoding:NSASCIIStringEncoding]);
}
+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];
+}
+
Common::String getDesktopPathMacOSX() {
// The recommanded method is to use NSFileManager.
// NSUrl *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask] firstObject];
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 3082a69ebf..8a60e9231b 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -513,6 +513,15 @@ Common::String OSystem_SDL::getTextFromClipboard() {
#endif
}
+bool OSystem_SDL::setTextInClipboard(const Common::String &text) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ // FIXME: The string we get from SDL is in UTF-8 and should probably be converted.
+ 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);
diff --git a/common/system.h b/common/system.h
index 206c3134c4..a0034ee874 100644
--- a/common/system.h
+++ b/common/system.h
@@ -324,8 +324,8 @@ public:
kFeatureDisplayLogFile,
/**
- * The presence of this feature indicates whether the hasTextInClipboard()
- * and getTextFromClipboard() calls are supported.
+ * The presence of this feature indicates whether the hasTextInClipboard(),
+ * getTextFromClipboard() and setTextInClipboard() calls are supported.
*
* This feature has no associated state.
*/
@@ -1336,6 +1336,17 @@ public:
virtual Common::String getTextFromClipboard() { return ""; }
/**
+ * Set the content of the clipboard to the given string.
+ *
+ * The kFeatureClipboardSupport feature flag can be used to
+ * test whether this call has been implemented by the active
+ * backend.
+ *
+ * @return true if the text was properly set in the clipboard, false otherwise
+ */
+ virtual bool setTextInClipboard(const Common::String &text) { return false; }
+
+ /**
* Open the given Url in the default browser (if available on the target
* system).
*