[Scummvm-git-logs] scummvm master -> 7bf22fa99613c5815317583bd5e1ac1dff693046

bluegr bluegr at gmail.com
Sat Sep 21 21:16:05 CEST 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
014bef9eab BACKENDS: Add a default clipboard implementation
ec4c846e8c WAGE: Implement global clipboard support
7bf22fa996 BACKENDS: Add EVENT_CLIPBOARD_UPDATE event


Commit: 014bef9eab9fb409cfb3ec66830e033e4aaa29a9
    https://github.com/scummvm/scummvm/commit/014bef9eab9fb409cfb3ec66830e033e4aaa29a9
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-09-21T22:16:01+03:00

Commit Message:
BACKENDS: Add a default clipboard implementation

Changed paths:
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h
    common/system.h
    engines/glk/selection.cpp
    gui/console.cpp
    gui/widgets/editable.cpp


diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 39933cc..b799d6a 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 ccbaedd..d2912cb 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 f17625e..ae0575f 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 756df02..f5ef012 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 79df413..a47f5b9 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 2af078f..048a0b0 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 {


Commit: ec4c846e8cde5ba578bd5385698efaf6d530a716
    https://github.com/scummvm/scummvm/commit/ec4c846e8cde5ba578bd5385698efaf6d530a716
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-09-21T22:16:01+03:00

Commit Message:
WAGE: Implement global clipboard support

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h


diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 6075ee1..51c140f 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -115,6 +115,10 @@ Gui::Gui(WageEngine *engine) {
 
 	_menu->calcDimensions();
 
+	if (g_system->hasTextInClipboard()) {
+		_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
+	}
+
 	_sceneWindow = _wm.addWindow(false, false, false);
 	_sceneWindow->setCallback(sceneWindowCallback, this);
 
@@ -347,22 +351,24 @@ void Gui::clearOutput() {
 }
 
 void Gui::actionCopy() {
-	_clipboard = _consoleWindow->getSelection();
+	g_system->setTextInClipboard(_consoleWindow->getSelection());
 
 	_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
 }
 
 void Gui::actionPaste() {
-	_undobuffer = _engine->_inputText;
+	if (g_system->hasTextInClipboard()) {
+		_undobuffer = _engine->_inputText;
 
-	_consoleWindow->appendInput(_clipboard);
+		_consoleWindow->appendInput(g_system->getTextFromClipboard());
 
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
+		_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
+	}
 }
 
 void Gui::actionUndo() {
 	_consoleWindow->clearInput();
-	_consoleWindow->appendInput(_clipboard);
+	_consoleWindow->appendInput(_undobuffer);
 
 	_menu->enableCommand(kMenuEdit, kMenuActionUndo, false);
 }
@@ -386,7 +392,7 @@ void Gui::actionCut() {
 
 	Common::String input = _consoleWindow->getInput();
 
-	_clipboard = _consoleWindow->cutSelection();
+	g_system->setTextInClipboard(_consoleWindow->cutSelection());
 
 	_undobuffer = input;
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 446cb9d..cb57392 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -168,7 +168,6 @@ private:
 	Graphics::MacMenu *_menu;
 	bool _sceneDirty;
 
-	Common::String _clipboard;
 	Common::String _undobuffer;
 
 	int _commandsMenuId;


Commit: 7bf22fa99613c5815317583bd5e1ac1dff693046
    https://github.com/scummvm/scummvm/commit/7bf22fa99613c5815317583bd5e1ac1dff693046
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-09-21T22:16:01+03:00

Commit Message:
BACKENDS: Add EVENT_CLIPBOARD_UPDATE event

Changed paths:
    backends/events/sdl/sdl-events.cpp
    common/events.h
    engines/wage/gui.cpp


diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index c3c316e..1c661a4 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -650,6 +650,10 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
 		event.path = Common::String(ev.drop.file);
 		SDL_free(ev.drop.file);
 		return true;
+
+	case SDL_CLIPBOARDUPDATE:
+		event.type = Common::EVENT_CLIPBOARD_UPDATE;
+		return true;
 #else
 	case SDL_VIDEOEXPOSE:
 		if (_graphicsManager)
diff --git a/common/events.h b/common/events.h
index cbd6153..134f1ea 100644
--- a/common/events.h
+++ b/common/events.h
@@ -90,7 +90,9 @@ enum EventType {
 
 	EVENT_JOYAXIS_MOTION = 24,
 	EVENT_JOYBUTTON_DOWN = 25,
-	EVENT_JOYBUTTON_UP = 26
+	EVENT_JOYBUTTON_UP = 26,
+
+	EVENT_CLIPBOARD_UPDATE = 27
 };
 
 const int16 JOYAXIS_MIN = -32768;
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 51c140f..609fe35 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -242,6 +242,10 @@ void Gui::regenWeaponsMenu() {
 }
 
 bool Gui::processEvent(Common::Event &event) {
+	if (event.type == Common::EVENT_CLIPBOARD_UPDATE) {
+		_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
+	}
+
 	return _wm.processEvent(event);
 }
 





More information about the Scummvm-git-logs mailing list