ALL: Move Clipboard support to OSystem
Commit adds kFeatureClipboardSupport. hasTextInClipboard() and getTextFromClipboard(). OSystem_SDL has this feature if SDL2 is used. EditableWidget and StorageWizardDialog use g_system to access clipboard now.
This commit is contained in:
parent
527ab4cdf6
commit
b9bba9bd4b
5 changed files with 99 additions and 58 deletions
|
@ -64,6 +64,11 @@
|
||||||
#include <SDL/SDL_net.h>
|
#include <SDL/SDL_net.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_clipboard.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
OSystem_SDL::OSystem_SDL()
|
OSystem_SDL::OSystem_SDL()
|
||||||
:
|
:
|
||||||
#ifdef USE_OPENGL
|
#ifdef USE_OPENGL
|
||||||
|
@ -171,6 +176,13 @@ void OSystem_SDL::init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSystem_SDL::hasFeature(Feature f) {
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
if (f == kFeatureClipboardSupport) return true;
|
||||||
|
#endif
|
||||||
|
return ModularBackend::hasFeature(f);
|
||||||
|
}
|
||||||
|
|
||||||
void OSystem_SDL::initBackend() {
|
void OSystem_SDL::initBackend() {
|
||||||
// Check if backend has not been initialized
|
// Check if backend has not been initialized
|
||||||
assert(!_inited);
|
assert(!_inited);
|
||||||
|
@ -453,6 +465,26 @@ Common::String OSystem_SDL::getSystemLanguage() const {
|
||||||
#endif // USE_DETECTLANG
|
#endif // USE_DETECTLANG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSystem_SDL::hasTextInClipboard() {
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
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();
|
||||||
|
if (text == nullptr) return "";
|
||||||
|
return text;
|
||||||
|
#else
|
||||||
|
return "";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
uint32 OSystem_SDL::getMillis(bool skipRecord) {
|
uint32 OSystem_SDL::getMillis(bool skipRecord) {
|
||||||
uint32 millis = SDL_GetTicks();
|
uint32 millis = SDL_GetTicks();
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual SdlMixerManager *getMixerManager();
|
virtual SdlMixerManager *getMixerManager();
|
||||||
|
|
||||||
|
virtual bool hasFeature(Feature f);
|
||||||
|
|
||||||
// Override functions from ModularBackend and OSystem
|
// Override functions from ModularBackend and OSystem
|
||||||
virtual void initBackend();
|
virtual void initBackend();
|
||||||
#if defined(USE_TASKBAR)
|
#if defined(USE_TASKBAR)
|
||||||
|
@ -69,6 +71,10 @@ public:
|
||||||
|
|
||||||
virtual Common::String getSystemLanguage() const;
|
virtual Common::String getSystemLanguage() const;
|
||||||
|
|
||||||
|
// Clipboard
|
||||||
|
virtual bool hasTextInClipboard();
|
||||||
|
virtual Common::String getTextFromClipboard();
|
||||||
|
|
||||||
virtual void setWindowCaption(const char *caption);
|
virtual void setWindowCaption(const char *caption);
|
||||||
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
|
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
|
||||||
virtual uint32 getMillis(bool skipRecord = false);
|
virtual uint32 getMillis(bool skipRecord = false);
|
||||||
|
|
|
@ -314,7 +314,15 @@ public:
|
||||||
*
|
*
|
||||||
* This feature has no associated state.
|
* This feature has no associated state.
|
||||||
*/
|
*/
|
||||||
kFeatureDisplayLogFile
|
kFeatureDisplayLogFile,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The presence of this feature indicates whether the hasTextInClipboard()
|
||||||
|
* and getTextFromClipboard() calls are supported.
|
||||||
|
*
|
||||||
|
* This feature has no associated state.
|
||||||
|
*/
|
||||||
|
kFeatureClipboardSupport
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1238,6 +1246,28 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool displayLogFile() { return false; }
|
virtual bool displayLogFile() { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether there is text available in the clipboard.
|
||||||
|
*
|
||||||
|
* The kFeatureClipboardSupport feature flag can be used to
|
||||||
|
* test whether this call has been implemented by the active
|
||||||
|
* backend.
|
||||||
|
*
|
||||||
|
* @return true if there is text in the clipboard, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool hasTextInClipboard() { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns clipboard contents as a String.
|
||||||
|
*
|
||||||
|
* The kFeatureClipboardSupport feature flag can be used to
|
||||||
|
* test whether this call has been implemented by the active
|
||||||
|
* backend.
|
||||||
|
*
|
||||||
|
* @return clipboard contents ("" if hasTextInClipboard() == false)
|
||||||
|
*/
|
||||||
|
virtual Common::String getTextFromClipboard() { return ""; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the locale of the system.
|
* Returns the locale of the system.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,13 +20,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef USE_SDL2
|
|
||||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_clipboard.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "gui/storagewizarddialog.h"
|
#include "gui/storagewizarddialog.h"
|
||||||
#include "gui/gui-manager.h"
|
#include "gui/gui-manager.h"
|
||||||
#include "gui/message.h"
|
#include "gui/message.h"
|
||||||
|
@ -217,11 +210,8 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kPasteCodeCmd: {
|
case kPasteCodeCmd: {
|
||||||
#ifdef USE_SDL2
|
if (g_system->hasTextInClipboard()) {
|
||||||
if (SDL_HasClipboardText() == SDL_TRUE) {
|
Common::String message = g_system->getTextFromClipboard();
|
||||||
char *text = SDL_GetClipboardText();
|
|
||||||
if (text != nullptr) {
|
|
||||||
Common::String message = text;
|
|
||||||
for (uint32 i = 0; i < CODE_FIELDS; ++i) {
|
for (uint32 i = 0; i < CODE_FIELDS; ++i) {
|
||||||
if (message.empty()) break;
|
if (message.empty()) break;
|
||||||
Common::String subcode = "";
|
Common::String subcode = "";
|
||||||
|
@ -241,8 +231,6 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
|
||||||
handleCommand(sender, kCodeBoxCmd, data);
|
handleCommand(sender, kCodeBoxCmd, data);
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kConnectCmd: {
|
case kConnectCmd: {
|
||||||
|
@ -302,11 +290,7 @@ void StorageWizardDialog::containerWidgetsReflow() {
|
||||||
}
|
}
|
||||||
if (_openUrlWidget) _openUrlWidget->setVisible(true);
|
if (_openUrlWidget) _openUrlWidget->setVisible(true);
|
||||||
if (_pasteCodeWidget) {
|
if (_pasteCodeWidget) {
|
||||||
#ifdef USE_SDL2
|
bool visible = showFields && g_system->hasFeature(OSystem::kFeatureClipboardSupport);
|
||||||
bool visible = showFields;
|
|
||||||
#else
|
|
||||||
bool visible = false;
|
|
||||||
#endif
|
|
||||||
_pasteCodeWidget->setVisible(visible);
|
_pasteCodeWidget->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef USE_SDL2
|
|
||||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_clipboard.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "common/rect.h"
|
#include "common/rect.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
#include "gui/widgets/editable.h"
|
#include "gui/widgets/editable.h"
|
||||||
|
@ -192,24 +185,20 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
|
||||||
forcecaret = true;
|
forcecaret = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef USE_SDL2
|
|
||||||
case Common::KEYCODE_v:
|
case Common::KEYCODE_v:
|
||||||
if (state.flags & Common::KBD_CTRL) {
|
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && state.flags & Common::KBD_CTRL) {
|
||||||
if (SDL_HasClipboardText() == SDL_TRUE) {
|
if (g_system->hasTextInClipboard()) {
|
||||||
char *text = SDL_GetClipboardText();
|
String text = g_system->getTextFromClipboard();
|
||||||
if (text != nullptr) {
|
for (uint32 i = 0; i < text.size(); ++i) {
|
||||||
for (char *ptr = text; *ptr; ++ptr) {
|
if (tryInsertChar(text[i], _caretPos))
|
||||||
if (tryInsertChar(*ptr, _caretPos))
|
|
||||||
++_caretPos;
|
++_caretPos;
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
defaultKeyDownHandler(state, dirty, forcecaret, handled);
|
defaultKeyDownHandler(state, dirty, forcecaret, handled);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
// Let ctrl-a / ctrl-e move the caret to the start / end of the line.
|
// Let ctrl-a / ctrl-e move the caret to the start / end of the line.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue