aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/macosx/macosx.cpp18
-rw-r--r--backends/platform/sdl/macosx/macosx.h5
-rw-r--r--backends/platform/sdl/macosx/macosx_wrapper.h31
-rw-r--r--backends/platform/sdl/macosx/macosx_wrapper.mm48
-rw-r--r--backends/platform/sdl/module.mk1
-rw-r--r--backends/platform/sdl/posix/posix.cpp51
-rw-r--r--backends/platform/sdl/posix/posix.h4
-rw-r--r--backends/platform/sdl/sdl-sys.h101
-rw-r--r--backends/platform/sdl/sdl-window.cpp2
-rw-r--r--backends/platform/sdl/sdl.cpp53
-rw-r--r--backends/platform/sdl/sdl.h9
-rw-r--r--backends/platform/sdl/win32/win32.cpp12
-rw-r--r--backends/platform/sdl/win32/win32.h2
13 files changed, 333 insertions, 4 deletions
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index 7652c0d833..212af6723e 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -33,6 +33,7 @@
#include "backends/platform/sdl/macosx/macosx.h"
#include "backends/updates/macosx/macosx-updates.h"
#include "backends/taskbar/macosx/macosx-taskbar.h"
+#include "backends/platform/sdl/macosx/macosx_wrapper.h"
#include "common/archive.h"
#include "common/config-manager.h"
@@ -106,7 +107,7 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit
}
bool OSystem_MacOSX::hasFeature(Feature f) {
- if (f == kFeatureDisplayLogFile)
+ if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport || f == kFeatureOpenUrl)
return true;
return OSystem_POSIX::hasFeature(f);
}
@@ -124,6 +125,21 @@ bool OSystem_MacOSX::displayLogFile() {
return err != noErr;
}
+bool OSystem_MacOSX::hasTextInClipboard() {
+ return hasTextInClipboardMacOSX();
+}
+
+Common::String OSystem_MacOSX::getTextFromClipboard() {
+ return getTextFromClipboardMacOSX();
+}
+
+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);
+ CFRelease(urlRef);
+ return err != noErr;
+}
+
Common::String OSystem_MacOSX::getSystemLanguage() const {
#if defined(USE_DETECTLANG) && defined(USE_TRANSLATION)
CFArrayRef availableLocalizations = CFBundleCopyBundleLocalizations(CFBundleGetMainBundle());
diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h
index 6905284a5f..929f2f91fa 100644
--- a/backends/platform/sdl/macosx/macosx.h
+++ b/backends/platform/sdl/macosx/macosx.h
@@ -33,6 +33,11 @@ public:
virtual bool displayLogFile();
+ virtual bool hasTextInClipboard();
+ virtual Common::String getTextFromClipboard();
+
+ virtual bool openUrl(const Common::String &url);
+
virtual Common::String getSystemLanguage() const;
virtual void init();
diff --git a/backends/platform/sdl/macosx/macosx_wrapper.h b/backends/platform/sdl/macosx/macosx_wrapper.h
new file mode 100644
index 0000000000..3b346fc486
--- /dev/null
+++ b/backends/platform/sdl/macosx/macosx_wrapper.h
@@ -0,0 +1,31 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef PLATFORM_SDL_MACOSX_WRAPPER_H
+#define PLATFORM_SDL_MACOSX_WRAPPER_H
+
+#include <common/str.h>
+
+bool hasTextInClipboardMacOSX();
+Common::String getTextFromClipboardMacOSX();
+
+#endif
diff --git a/backends/platform/sdl/macosx/macosx_wrapper.mm b/backends/platform/sdl/macosx/macosx_wrapper.mm
new file mode 100644
index 0000000000..8ec9eac5ac
--- /dev/null
+++ b/backends/platform/sdl/macosx/macosx_wrapper.mm
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/platform/sdl/macosx/macosx_wrapper.h"
+
+#include <AppKit/NSPasteboard.h>
+#include <Foundation/NSArray.h>
+
+bool hasTextInClipboardMacOSX() {
+ return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil;
+}
+
+Common::String getTextFromClipboardMacOSX() {
+ if (!hasTextInClipboardMacOSX())
+ return Common::String();
+ // 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];
+ if (str == nil)
+ return Common::String();
+ // If the string cannot be represented using the requested encoding we get a null pointer below.
+ // This is fine as ScummVM would not know what to do with non-ASCII characters (although maybe
+ // we should use NSISOLatin1StringEncoding?).
+ return Common::String([str cStringUsingEncoding:NSASCIIStringEncoding]);
+}
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index 74dd506d31..84ce272d3c 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -14,6 +14,7 @@ ifdef MACOSX
MODULE_OBJS += \
macosx/macosx-main.o \
macosx/macosx.o \
+ macosx/macosx_wrapper.o \
macosx/appmenu_osx.o
endif
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index 0d5f39736a..b805a452cf 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -25,6 +25,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h
+#define FORBIDDEN_SYMBOL_EXCEPTION_system
#include "common/scummsys.h"
@@ -40,6 +41,9 @@
#include "backends/audiocd/linux/linux-audiocd.h"
#endif
+#include "common/textconsole.h"
+
+#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -78,7 +82,7 @@ void OSystem_POSIX::initBackend() {
}
bool OSystem_POSIX::hasFeature(Feature f) {
- if (f == kFeatureDisplayLogFile)
+ if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl)
return true;
return OSystem_SDL::hasFeature(f);
}
@@ -261,6 +265,51 @@ bool OSystem_POSIX::displayLogFile() {
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}
+bool OSystem_POSIX::openUrl(const Common::String &url) {
+ // inspired by Qt's "qdesktopservices_x11.cpp"
+
+ // try "standards"
+ if (launchBrowser("xdg-open", url))
+ return true;
+ if (launchBrowser(getenv("DEFAULT_BROWSER"), url))
+ return true;
+ if (launchBrowser(getenv("BROWSER"), url))
+ return true;
+
+ // try desktop environment specific tools
+ if (launchBrowser("gnome-open", url)) // gnome
+ return true;
+ if (launchBrowser("kfmclient openURL", url)) // kde
+ return true;
+ if (launchBrowser("exo-open", url)) // xfce
+ return true;
+
+ // try browser names
+ if (launchBrowser("firefox", url))
+ return true;
+ if (launchBrowser("mozilla", url))
+ return true;
+ if (launchBrowser("netscape", url))
+ return true;
+ if (launchBrowser("opera", url))
+ return true;
+ if (launchBrowser("chromium-browser", url))
+ return true;
+ if (launchBrowser("google-chrome", url))
+ return true;
+
+ warning("openUrl() (POSIX) failed to open URL");
+ return false;
+}
+
+bool OSystem_POSIX::launchBrowser(const Common::String& client, const Common::String &url) {
+ // FIXME: system's input must be heavily escaped
+ // well, when url's specified by user
+ // it's OK now (urls are hardcoded somewhere in GUI)
+ Common::String cmd = client + " " + url;
+ return (system(cmd.c_str()) != -1);
+}
+
AudioCDManager *OSystem_POSIX::createAudioCDManager() {
#ifdef USE_LINUXCD
diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h
index 050463c273..e5110ff632 100644
--- a/backends/platform/sdl/posix/posix.h
+++ b/backends/platform/sdl/posix/posix.h
@@ -35,6 +35,8 @@ public:
virtual bool displayLogFile();
+ virtual bool openUrl(const Common::String &url);
+
virtual void init();
virtual void initBackend();
@@ -63,6 +65,8 @@ protected:
virtual Common::WriteStream *createLogFile();
virtual AudioCDManager *createAudioCDManager();
+
+ bool launchBrowser(const Common::String& client, const Common::String &url);
};
#endif
diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h
index 551605a4b4..9ebd123bb4 100644
--- a/backends/platform/sdl/sdl-sys.h
+++ b/backends/platform/sdl/sdl-sys.h
@@ -67,6 +67,57 @@ typedef struct { int FAKE; } FAKE_FILE;
#define system FAKE_system
#endif
+// Fix compilation with MacPorts SDL 2
+// It needs various (usually forbidden) symbols from time.h
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
+ #undef asctime
+ #define asctime FAKE_asctime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
+ #undef clock
+ #define clock FAKE_clock
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
+ #undef ctime
+ #define ctime FAKE_ctime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
+ #undef difftime
+ #define difftime FAKE_difftime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
+ #undef getdate
+ #define getdate FAKE_getdate
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
+ #undef gmtime
+ #define gmtime FAKE_gmtime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
+ #undef localtime
+ #define localtime FAKE_localtime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
+ #undef mktime
+ #define mktime FAKE_mktime
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
+ #undef time
+ #define time FAKE_time
+ #endif
+
+#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
// HACK: SDL might include windows.h which defines its own ARRAYSIZE.
// However, we want to use the version from common/util.h. Thus, we make sure
// that we actually have this definition after including the SDL headers.
@@ -176,6 +227,56 @@ typedef struct { int FAKE; } FAKE_FILE;
#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+// re-forbid all those time.h symbols again (if they were forbidden)
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
+ #undef asctime
+ #define asctime(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
+ #undef clock
+ #define clock() FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
+ #undef ctime
+ #define ctime(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
+ #undef difftime
+ #define difftime(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
+ #undef getdate
+ #define getdate(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
+ #undef gmtime
+ #define gmtime(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
+ #undef localtime
+ #define localtime(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
+ #undef mktime
+ #define mktime(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
+ #undef time
+ #define time(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+#endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
// SDL 2 has major API changes. We redefine constants which got renamed to
// ease the transition. This is sometimes dangerous because the values changed
// too!
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 6d35f77ae0..609186a061 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -150,7 +150,7 @@ bool SdlWindow::hasMouseFocus() const {
void SdlWindow::warpMouseInWindow(uint x, uint y) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_window) {
+ if (_window && hasMouseFocus()) {
SDL_WarpMouseInWindow(_window, x, y);
}
#else
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index dca6891fef..18f2a49bdd 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -60,6 +60,14 @@
#endif // !WIN32
#endif
+#ifdef USE_SDL_NET
+#include <SDL_net.h>
+#endif
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#include <SDL_clipboard.h>
+#endif
+
OSystem_SDL::OSystem_SDL()
:
#ifdef USE_OPENGL
@@ -73,6 +81,9 @@ OSystem_SDL::OSystem_SDL()
#endif
_inited(false),
_initedSDL(false),
+#ifdef USE_SDL_NET
+ _initedSDLnet(false),
+#endif
_logger(0),
_mixerManager(0),
_eventSource(0),
@@ -120,6 +131,10 @@ OSystem_SDL::~OSystem_SDL() {
delete _logger;
_logger = 0;
+#ifdef USE_SDL_NET
+ if (_initedSDLnet) SDLNet_Quit();
+#endif
+
SDL_Quit();
}
@@ -160,6 +175,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() {
// Check if backend has not been initialized
assert(!_inited);
@@ -294,6 +316,17 @@ void OSystem_SDL::initSDL() {
_initedSDL = true;
}
+
+#ifdef USE_SDL_NET
+ // Check if SDL_net has not been initialized
+ if (!_initedSDLnet) {
+ // Initialize SDL_net
+ if (SDLNet_Init() == -1)
+ error("Could not initialize SDL_net: %s", SDLNet_GetError());
+
+ _initedSDLnet = true;
+ }
+#endif
}
void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
@@ -431,6 +464,26 @@ Common::String OSystem_SDL::getSystemLanguage() const {
#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 millis = SDL_GetTicks();
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 1fe670c5c3..17b4e9b001 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -55,6 +55,8 @@ public:
*/
virtual SdlMixerManager *getMixerManager();
+ virtual bool hasFeature(Feature f);
+
// Override functions from ModularBackend and OSystem
virtual void initBackend();
#if defined(USE_TASKBAR)
@@ -69,6 +71,10 @@ public:
virtual Common::String getSystemLanguage() const;
+ // Clipboard
+ virtual bool hasTextInClipboard();
+ virtual Common::String getTextFromClipboard();
+
virtual void setWindowCaption(const char *caption);
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
virtual uint32 getMillis(bool skipRecord = false);
@@ -81,6 +87,9 @@ public:
protected:
bool _inited;
bool _initedSDL;
+#ifdef USE_SDL_NET
+ bool _initedSDLnet;
+#endif
/**
* Mixer manager that configures and setups SDL for
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index fcc0849624..99c71a49e0 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -94,7 +94,7 @@ void OSystem_Win32::initBackend() {
bool OSystem_Win32::hasFeature(Feature f) {
- if (f == kFeatureDisplayLogFile)
+ if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl)
return true;
return OSystem_SDL::hasFeature(f);
@@ -135,6 +135,16 @@ bool OSystem_Win32::displayLogFile() {
return false;
}
+bool OSystem_Win32::openUrl(const Common::String &url) {
+ const uint64 result = (uint64)ShellExecute(0, 0, /*(wchar_t*)nativeFilePath.utf16()*/url.c_str(), 0, 0, SW_SHOWNORMAL);
+ // ShellExecute returns a value greater than 32 if successful
+ if (result <= 32) {
+ warning("ShellExecute failed: error = %u", result);
+ return false;
+ }
+ return true;
+}
+
Common::String OSystem_Win32::getDefaultConfigFileName() {
char configFile[MAXPATHLEN];
diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h
index ca0843e834..636ebae88f 100644
--- a/backends/platform/sdl/win32/win32.h
+++ b/backends/platform/sdl/win32/win32.h
@@ -36,6 +36,8 @@ public:
virtual bool displayLogFile();
+ virtual bool openUrl(const Common::String &url);
+
protected:
/**
* The path of the currently open log file, if any.