From 75fbecf616a9b3e2592cffa8000f92237db05640 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sun, 17 Jul 2016 14:01:52 +0600 Subject: GUI: Add Ctrl+V handling in EditableWidget In SDL2 there is SDL_GetClipboardText(), so EditableWidget could support pasting into it. No copying yet, as there is no selecting. --- gui/widgets/editable.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 4f7e584c14..6c63074fd1 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -20,6 +20,13 @@ * */ +#ifdef USE_SDL2 +#define FORBIDDEN_SYMBOL_ALLOW_ALL + +#include +#include +#endif + #include "common/rect.h" #include "common/system.h" #include "gui/widgets/editable.h" @@ -185,6 +192,25 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) { forcecaret = true; break; +#ifdef USE_SDL2 + case Common::KEYCODE_v: + if (state.flags & Common::KBD_CTRL) { + if (SDL_HasClipboardText() == SDL_TRUE) { + char *text = SDL_GetClipboardText(); + if (text != nullptr) { + for (char *ptr = text; *ptr; ++ptr) { + if (tryInsertChar(*ptr, _caretPos)) + ++_caretPos; + } + dirty = true; + } + } + } else { + defaultKeyDownHandler(state, dirty, forcecaret, handled); + } + break; +#endif + #ifdef MACOSX // Let ctrl-a / ctrl-e move the caret to the start / end of the line. // -- cgit v1.2.3 From b9bba9bd4bec1bf00a61c347f411a8ecf9ea69e8 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 26 Jul 2016 12:21:15 +0600 Subject: 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. --- gui/widgets/editable.cpp | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 6c63074fd1..02defe9a56 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -20,13 +20,6 @@ * */ -#ifdef USE_SDL2 -#define FORBIDDEN_SYMBOL_ALLOW_ALL - -#include -#include -#endif - #include "common/rect.h" #include "common/system.h" #include "gui/widgets/editable.h" @@ -192,24 +185,20 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) { forcecaret = true; break; -#ifdef USE_SDL2 - case Common::KEYCODE_v: - if (state.flags & Common::KBD_CTRL) { - if (SDL_HasClipboardText() == SDL_TRUE) { - char *text = SDL_GetClipboardText(); - if (text != nullptr) { - for (char *ptr = text; *ptr; ++ptr) { - if (tryInsertChar(*ptr, _caretPos)) - ++_caretPos; - } - dirty = true; - } + case Common::KEYCODE_v: + if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && state.flags & Common::KBD_CTRL) { + if (g_system->hasTextInClipboard()) { + String text = g_system->getTextFromClipboard(); + for (uint32 i = 0; i < text.size(); ++i) { + if (tryInsertChar(text[i], _caretPos)) + ++_caretPos; } - } else { - defaultKeyDownHandler(state, dirty, forcecaret, handled); + dirty = true; } - break; -#endif + } else { + defaultKeyDownHandler(state, dirty, forcecaret, handled); + } + break; #ifdef MACOSX // Let ctrl-a / ctrl-e move the caret to the start / end of the line. -- cgit v1.2.3