aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/platform/sdl/sdl.cpp14
-rw-r--r--backends/platform/sdl/sdl.h2
-rw-r--r--common/system.h19
-rw-r--r--engines/glk/selection.cpp30
-rw-r--r--gui/console.cpp4
-rw-r--r--gui/widgets/editable.cpp4
6 files changed, 35 insertions, 38 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 39933cc94c..b799d6a026 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -457,18 +457,14 @@ Common::String OSystem_SDL::getSystemLanguage() const {
#endif // USE_DETECTLANG
}
-bool OSystem_SDL::hasTextInClipboard() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
+bool OSystem_SDL::hasTextInClipboard() {
return SDL_HasClipboardText() == SDL_TRUE;
-#else
- return false;
-#endif
}
Common::String OSystem_SDL::getTextFromClipboard() {
if (!hasTextInClipboard()) return "";
-#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.
@@ -485,13 +481,9 @@ Common::String OSystem_SDL::getTextFromClipboard() {
SDL_free(text);
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
@@ -505,10 +497,8 @@ bool OSystem_SDL::setTextInClipboard(const Common::String &text) {
return status == 0;
}
return SDL_SetClipboardText(text.c_str()) == 0;
-#else
- return false;
-#endif
}
+#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 ccbaeddb6d..d2912cbeb8 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -69,10 +69,12 @@ public:
virtual Common::String getSystemLanguage() const;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
// Clipboard
virtual bool hasTextInClipboard();
virtual Common::String getTextFromClipboard();
virtual bool setTextInClipboard(const Common::String &text);
+#endif
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 f17625e215..ae0575f0e8 100644
--- a/common/system.h
+++ b/common/system.h
@@ -216,6 +216,12 @@ protected:
*/
FilesystemFactory *_fsFactory;
+ /**
+ * Used by the default clipboard implementation, for backends that don't
+ * implement clipboard support.
+ */
+ Common::String _clipboard;
+
private:
/**
* Indicate if initBackend() has been called.
@@ -374,8 +380,11 @@ public:
kFeatureDisplayLogFile,
/**
- * The presence of this feature indicates whether the hasTextInClipboard(),
- * getTextFromClipboard() and setTextInClipboard() calls are supported.
+ * The presence of this feature indicates whether the system clipboard is
+ * available. If this feature is not present, the hasTextInClipboard(),
+ * getTextFromClipboard() and setTextInClipboard() calls can still be used,
+ * however it should not be used in scenarios where the user is expected to
+ * copy data outside of the application.
*
* This feature has no associated state.
*/
@@ -1451,7 +1460,7 @@ public:
*
* @return true if there is text in the clipboard, false otherwise
*/
- virtual bool hasTextInClipboard() { return false; }
+ virtual bool hasTextInClipboard() { return !_clipboard.empty(); }
/**
* Returns clipboard contents as a String.
@@ -1462,7 +1471,7 @@ public:
*
* @return clipboard contents ("" if hasTextInClipboard() == false)
*/
- virtual Common::String getTextFromClipboard() { return ""; }
+ virtual Common::String getTextFromClipboard() { return _clipboard; }
/**
* Set the content of the clipboard to the given string.
@@ -1473,7 +1482,7 @@ public:
*
* @return true if the text was properly set in the clipboard, false otherwise
*/
- virtual bool setTextInClipboard(const Common::String &text) { return false; }
+ virtual bool setTextInClipboard(const Common::String &text) { _clipboard = text; return true; }
/**
* Open the given Url in the default browser (if available on the target
diff --git a/engines/glk/selection.cpp b/engines/glk/selection.cpp
index 756df02b09..f5ef012fd2 100644
--- a/engines/glk/selection.cpp
+++ b/engines/glk/selection.cpp
@@ -33,27 +33,23 @@ void Clipboard::clipboardStore(const Common::U32String &text) {
}
void Clipboard::clipboardSend(ClipSource source) {
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
- // Convert unicode string to standard string, since that's all ScummVM supports
- Common::String text;
- for (uint idx = 0; idx < _text.size(); ++idx)
- text += (_text[idx] <= 0x7f) ? (char)_text[idx] : '?';
+ // Convert unicode string to standard string, since that's all ScummVM supports
+ Common::String text;
+ for (uint idx = 0; idx < _text.size(); ++idx)
+ text += (_text[idx] <= 0x7f) ? (char)_text[idx] : '?';
- g_system->setTextInClipboard(text);
- }
+ g_system->setTextInClipboard(text);
}
void Clipboard::clipboardReceive(ClipSource source) {
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
- Windows &windows = *g_vm->_windows;
-
- if (g_system->hasTextInClipboard()) {
- Common::String text = g_system->getTextFromClipboard();
- for (uint idx = 0; idx < text.size(); ++idx) {
- uint c = text[idx];
- if (c != '\r' && c != '\n' && c != '\b' && c != '\t')
- windows.inputHandleKey(c);
- }
+ Windows &windows = *g_vm->_windows;
+
+ if (g_system->hasTextInClipboard()) {
+ Common::String text = g_system->getTextFromClipboard();
+ for (uint idx = 0; idx < text.size(); ++idx) {
+ uint c = text[idx];
+ if (c != '\r' && c != '\n' && c != '\b' && c != '\t')
+ windows.inputHandleKey(c);
}
}
}
diff --git a/gui/console.cpp b/gui/console.cpp
index 79df413534..a47f5b9afd 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -523,7 +523,7 @@ void ConsoleDialog::specialKeys(Common::KeyCode keycode) {
g_gui.scheduleTopDialogRedraw();
break;
case Common::KEYCODE_v:
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && g_system->hasTextInClipboard()) {
+ if (g_system->hasTextInClipboard()) {
Common::String text = g_system->getTextFromClipboard();
insertIntoPrompt(text.c_str());
scrollToCurrent();
@@ -531,7 +531,7 @@ void ConsoleDialog::specialKeys(Common::KeyCode keycode) {
}
break;
case Common::KEYCODE_c:
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
+ {
Common::String userInput = getUserInput();
if (!userInput.empty())
g_system->setTextInClipboard(userInput);
diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp
index 2af078f9f6..048a0b0fcd 100644
--- a/gui/widgets/editable.cpp
+++ b/gui/widgets/editable.cpp
@@ -186,7 +186,7 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
break;
case Common::KEYCODE_v:
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && state.flags & Common::KBD_CTRL) {
+ if (state.flags & Common::KBD_CTRL) {
if (g_system->hasTextInClipboard()) {
String text = g_system->getTextFromClipboard();
for (uint32 i = 0; i < text.size(); ++i) {
@@ -201,7 +201,7 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
break;
case Common::KEYCODE_c:
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && state.flags & Common::KBD_CTRL) {
+ if (state.flags & Common::KBD_CTRL) {
if (!getEditString().empty())
g_system->setTextInClipboard(getEditString());
} else {