aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorSupSuper2018-11-20 04:27:29 +0000
committerThierry Crozat2018-12-16 10:48:13 +0000
commit2f2555f728086873eb074af4ca6b46025f405f75 (patch)
tree1a260c426e5560f18524469b8539f1b25e9b8740 /backends
parent28e4d7bb438d75526f700cd954da6f28ebc45a29 (diff)
downloadscummvm-rg350-2f2555f728086873eb074af4ca6b46025f405f75.tar.gz
scummvm-rg350-2f2555f728086873eb074af4ca6b46025f405f75.tar.bz2
scummvm-rg350-2f2555f728086873eb074af4ca6b46025f405f75.zip
WIN32: Move utility functions to a common wrapper
Diffstat (limited to 'backends')
-rw-r--r--backends/platform/sdl/module.mk1
-rw-r--r--backends/platform/sdl/win32/win32-window.cpp22
-rw-r--r--backends/platform/sdl/win32/win32-window.h1
-rw-r--r--backends/platform/sdl/win32/win32.cpp2
-rw-r--r--backends/platform/sdl/win32/win32_wrapper.cpp87
-rw-r--r--backends/platform/sdl/win32/win32_wrapper.h50
-rw-r--r--backends/taskbar/win32/win32-taskbar.cpp102
-rw-r--r--backends/taskbar/win32/win32-taskbar.h12
8 files changed, 174 insertions, 103 deletions
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index bb11aaae97..c5036be727 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -22,6 +22,7 @@ ifdef WIN32
MODULE_OBJS += \
win32/win32-main.o \
win32/win32-window.o \
+ win32/win32_wrapper.o \
win32/win32.o
endif
diff --git a/backends/platform/sdl/win32/win32-window.cpp b/backends/platform/sdl/win32/win32-window.cpp
index de10be6b57..8c01da0e36 100644
--- a/backends/platform/sdl/win32/win32-window.cpp
+++ b/backends/platform/sdl/win32/win32-window.cpp
@@ -35,14 +35,10 @@ void SdlWindow_Win32::setupIcon() {
HMODULE handle = GetModuleHandle(NULL);
HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */));
if (ico) {
- SDL_SysWMinfo wminfo;
- if (getSDLWMInformation(&wminfo)) {
+ HWND hwnd = getHwnd();
+ if (hwnd) {
// Replace the handle to the icon associated with the window class by our custom icon
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SetClassLongPtr(wminfo.info.win.window, GCLP_HICON, (ULONG_PTR)ico);
-#else
- SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico);
-#endif
+ SetClassLongPtr(hwnd, GCLP_HICON, (ULONG_PTR)ico);
// Since there wasn't any default icon, we can't use the return value from SetClassLong
// to check for errors (it would be 0 in both cases: error or no previous value for the
@@ -56,4 +52,16 @@ void SdlWindow_Win32::setupIcon() {
SdlWindow::setupIcon();
}
+HWND SdlWindow_Win32::getHwnd() {
+ SDL_SysWMinfo wminfo;
+ if (getSDLWMInformation(&wminfo)) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ return wminfo.info.win.window;
+#else
+ return wminfo.window;
+#endif
+ }
+ return NULL;
+}
+
#endif
diff --git a/backends/platform/sdl/win32/win32-window.h b/backends/platform/sdl/win32/win32-window.h
index 3bda697bc7..7498e3fc34 100644
--- a/backends/platform/sdl/win32/win32-window.h
+++ b/backends/platform/sdl/win32/win32-window.h
@@ -30,6 +30,7 @@
class SdlWindow_Win32 : public SdlWindow {
public:
virtual void setupIcon();
+ HWND getHwnd();
};
#endif
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index 3de1b9b35c..936662e7fe 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -61,7 +61,7 @@ void OSystem_Win32::init() {
#if defined(USE_TASKBAR)
// Initialize taskbar manager
- _taskbarManager = new Win32TaskbarManager(_window);
+ _taskbarManager = new Win32TaskbarManager((SdlWindow_Win32*)_window);
#endif
// Invoke parent implementation of this method
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
new file mode 100644
index 0000000000..3ff00b6f2d
--- /dev/null
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -0,0 +1,87 @@
+/* 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 "common/scummsys.h"
+// We need certain functions that are excluded by default
+#undef NONLS
+#include <windows.h>
+#if defined(ARRAYSIZE)
+#undef ARRAYSIZE
+#endif
+
+#include "backends/platform/sdl/win32/win32_wrapper.h"
+
+// VerSetConditionMask and VerifyVersionInfo didn't appear until Windows 2000,
+// so we need to check for them at runtime
+LONGLONG VerSetConditionMaskFunc(ULONGLONG dwlConditionMask, DWORD dwTypeMask, BYTE dwConditionMask) {
+ typedef BOOL(WINAPI *VerSetConditionMaskFunction)(ULONGLONG conditionMask, DWORD typeMask, BYTE conditionOperator);
+
+ VerSetConditionMaskFunction verSetConditionMask = (VerSetConditionMaskFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerSetConditionMask");
+ if (verSetConditionMask == NULL)
+ return 0;
+
+ return verSetConditionMask(dwlConditionMask, dwTypeMask, dwConditionMask);
+}
+
+BOOL VerifyVersionInfoFunc(LPOSVERSIONINFOEXA lpVersionInformation, DWORD dwTypeMask, DWORDLONG dwlConditionMask) {
+ typedef BOOL(WINAPI *VerifyVersionInfoFunction)(LPOSVERSIONINFOEXA versionInformation, DWORD typeMask, DWORDLONG conditionMask);
+
+ VerifyVersionInfoFunction verifyVersionInfo = (VerifyVersionInfoFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerifyVersionInfoA");
+ if (verifyVersionInfo == NULL)
+ return FALSE;
+
+ return verifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask);
+}
+
+namespace Win32 {
+
+bool confirmWindowsVersion(int majorVersion, int minorVersion) {
+ OSVERSIONINFOEX versionInfo;
+ DWORDLONG conditionMask = 0;
+
+ ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ versionInfo.dwMajorVersion = majorVersion;
+ versionInfo.dwMinorVersion = minorVersion;
+
+ conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
+ conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
+
+ return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
+}
+
+LPWSTR ansiToUnicode(const char *s) {
+ DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
+
+ if (size > 0) {
+ LPWSTR result = new WCHAR[size];
+ if (MultiByteToWideChar(0, 0, s, -1, result, size) != 0)
+ return result;
+ }
+
+ return NULL;
+}
+
+}
diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h
new file mode 100644
index 0000000000..5722d8844f
--- /dev/null
+++ b/backends/platform/sdl/win32/win32_wrapper.h
@@ -0,0 +1,50 @@
+/* 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_WIN32_WRAPPER_H
+#define PLATFORM_SDL_WIN32_WRAPPER_H
+
+// Helper functions
+namespace Win32 {
+
+/**
+ * Checks if the current running Windows version is greater or equal to the specified version.
+ * See: https://docs.microsoft.com/en-us/windows/desktop/sysinfo/operating-system-version
+ *
+ * @param majorVersion The major version number (x.0)
+ * @param minorVersion The minor version number (0.x)
+ */
+bool confirmWindowsVersion(int majorVersion, int minorVersion);
+/**
+ * Converts a C string into a Windows wide-character string.
+ * Used to interact with Win32 Unicode APIs with no ANSI fallback.
+ *
+ * @param s Source string
+ * @return Converted string
+ *
+ * @note Return value must be freed by the caller.
+ */
+wchar_t *ansiToUnicode(const char *s);
+
+}
+
+#endif
diff --git a/backends/taskbar/win32/win32-taskbar.cpp b/backends/taskbar/win32/win32-taskbar.cpp
index b2810e55b4..1537859243 100644
--- a/backends/taskbar/win32/win32-taskbar.cpp
+++ b/backends/taskbar/win32/win32-taskbar.cpp
@@ -50,20 +50,10 @@
// To assure that including the respective system headers gives us all
// required definitions we set Win7 as minimum version we target.
// See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx#macros_for_conditional_declarations
+ #include <sdkddkver.h>
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN7
- // TODO: We might not need to include this file, the MSDN docs are
- // not really helpful to decide whether we require it or not.
- //
- // Casing of the name is a bit of a mess. MinGW64 seems to use all
- // lowercase, while MSDN docs suggest "SdkDdkVer.h". We are stuck with
- // what MinGW64 uses...
- #include <sdkddkver.h>
-
- // We need certain functions that are excluded by default
- #undef NONLS
- #undef NOICONS
#include <windows.h>
#if defined(ARRAYSIZE)
#undef ARRAYSIZE
@@ -75,6 +65,8 @@
#include "common/scummsys.h"
#include "backends/taskbar/win32/win32-taskbar.h"
+#include "backends/platform/sdl/win32/win32-window.h"
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "common/config-manager.h"
#include "common/textconsole.h"
@@ -83,9 +75,9 @@
// System.Title property key, values taken from http://msdn.microsoft.com/en-us/library/bb787584.aspx
const PROPERTYKEY PKEY_Title = { /* fmtid = */ { 0xF29F85E0, 0x4FF9, 0x1068, { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 } }, /* propID = */ 2 };
-Win32TaskbarManager::Win32TaskbarManager(SdlWindow *window) : _window(window), _taskbar(NULL), _count(0), _icon(NULL) {
+Win32TaskbarManager::Win32TaskbarManager(SdlWindow_Win32 *window) : _window(window), _taskbar(NULL), _count(0), _icon(NULL) {
// Do nothing if not running on Windows 7 or later
- if (!confirmWindowsVersion(10, 0) && !confirmWindowsVersion(6, 1))
+ if (!Win32::confirmWindowsVersion(10, 0) && !Win32::confirmWindowsVersion(6, 1))
return;
CoInitialize(NULL);
@@ -126,7 +118,7 @@ void Win32TaskbarManager::setOverlayIcon(const Common::String &name, const Commo
return;
if (name.empty()) {
- _taskbar->SetOverlayIcon(getHwnd(), NULL, L"");
+ _taskbar->SetOverlayIcon(_window->getHwnd(), NULL, L"");
return;
}
@@ -142,8 +134,8 @@ void Win32TaskbarManager::setOverlayIcon(const Common::String &name, const Commo
}
// Sets the overlay icon
- LPWSTR desc = ansiToUnicode(description.c_str());
- _taskbar->SetOverlayIcon(getHwnd(), pIcon, desc);
+ LPWSTR desc = Win32::ansiToUnicode(description.c_str());
+ _taskbar->SetOverlayIcon(_window->getHwnd(), pIcon, desc);
DestroyIcon(pIcon);
@@ -154,14 +146,14 @@ void Win32TaskbarManager::setProgressValue(int completed, int total) {
if (_taskbar == NULL)
return;
- _taskbar->SetProgressValue(getHwnd(), completed, total);
+ _taskbar->SetProgressValue(_window->getHwnd(), completed, total);
}
void Win32TaskbarManager::setProgressState(TaskbarProgressState state) {
if (_taskbar == NULL)
return;
- _taskbar->SetProgressState(getHwnd(), (TBPFLAG)state);
+ _taskbar->SetProgressState(_window->getHwnd(), (TBPFLAG)state);
}
void Win32TaskbarManager::setCount(int count) {
@@ -169,7 +161,7 @@ void Win32TaskbarManager::setCount(int count) {
return;
if (count == 0) {
- _taskbar->SetOverlayIcon(getHwnd(), NULL, L"");
+ _taskbar->SetOverlayIcon(_window->getHwnd(), NULL, L"");
return;
}
@@ -276,8 +268,8 @@ void Win32TaskbarManager::setCount(int count) {
}
// Sets the overlay icon
- LPWSTR desc = ansiToUnicode(Common::String::format("Found games: %d", count).c_str());
- _taskbar->SetOverlayIcon(getHwnd(), _icon, desc);
+ LPWSTR desc = Win32::ansiToUnicode(Common::String::format("Found games: %d", count).c_str());
+ _taskbar->SetOverlayIcon(_window->getHwnd(), _icon, desc);
delete[] desc;
}
@@ -297,8 +289,8 @@ void Win32TaskbarManager::addRecent(const Common::String &name, const Common::St
// Create a shell link.
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC, IID_IShellLinkW, reinterpret_cast<void **> (&link)))) {
// Convert game name and description to Unicode.
- LPWSTR game = ansiToUnicode(name.c_str());
- LPWSTR desc = ansiToUnicode(description.c_str());
+ LPWSTR game = Win32::ansiToUnicode(name.c_str());
+ LPWSTR desc = Win32::ansiToUnicode(description.c_str());
// Set link properties.
link->SetPath(path);
@@ -308,7 +300,7 @@ void Win32TaskbarManager::addRecent(const Common::String &name, const Common::St
if (iconPath.empty()) {
link->SetIconLocation(path, 0); // No game-specific icon available
} else {
- LPWSTR icon = ansiToUnicode(iconPath.c_str());
+ LPWSTR icon = Win32::ansiToUnicode(iconPath.c_str());
link->SetIconLocation(icon, 0);
@@ -378,66 +370,4 @@ Common::String Win32TaskbarManager::getIconPath(Common::String target) {
return "";
}
-// VerSetConditionMask and VerifyVersionInfo didn't appear until Windows 2000,
-// so we need to check for them at runtime
-LONGLONG VerSetConditionMaskFunc(ULONGLONG dwlConditionMask, DWORD dwTypeMask, BYTE dwConditionMask) {
- typedef BOOL (WINAPI *VerSetConditionMaskFunction)(ULONGLONG conditionMask, DWORD typeMask, BYTE conditionOperator);
-
- VerSetConditionMaskFunction verSetConditionMask = (VerSetConditionMaskFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerSetConditionMask");
- if (verSetConditionMask == NULL)
- return 0;
-
- return verSetConditionMask(dwlConditionMask, dwTypeMask, dwConditionMask);
-}
-
-BOOL VerifyVersionInfoFunc(LPOSVERSIONINFOEXA lpVersionInformation, DWORD dwTypeMask, DWORDLONG dwlConditionMask) {
- typedef BOOL (WINAPI *VerifyVersionInfoFunction)(LPOSVERSIONINFOEXA versionInformation, DWORD typeMask, DWORDLONG conditionMask);
-
- VerifyVersionInfoFunction verifyVersionInfo = (VerifyVersionInfoFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerifyVersionInfoA");
- if (verifyVersionInfo == NULL)
- return FALSE;
-
- return verifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask);
-}
-
-bool Win32TaskbarManager::confirmWindowsVersion(uint majorVersion, uint minorVersion) {
- OSVERSIONINFOEX versionInfo;
- DWORDLONG conditionMask = 0;
-
- ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
- versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- versionInfo.dwMajorVersion = majorVersion;
- versionInfo.dwMinorVersion = minorVersion;
-
- conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
- conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
-
- return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
-}
-
-LPWSTR Win32TaskbarManager::ansiToUnicode(const char *s) {
- DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
-
- if (size > 0) {
- LPWSTR result = new WCHAR[size];
- if (MultiByteToWideChar(0, 0, s, -1, result, size) != 0)
- return result;
- }
-
- return NULL;
-}
-
-HWND Win32TaskbarManager::getHwnd() {
- SDL_SysWMinfo wmi;
- if (_window->getSDLWMInformation(&wmi)) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- return wmi.info.win.window;
-#else
- return wmi.window;
-#endif
- } else {
- return NULL;
- }
-}
-
#endif
diff --git a/backends/taskbar/win32/win32-taskbar.h b/backends/taskbar/win32/win32-taskbar.h
index a5c024b21b..aa7b5710b3 100644
--- a/backends/taskbar/win32/win32-taskbar.h
+++ b/backends/taskbar/win32/win32-taskbar.h
@@ -25,16 +25,15 @@
#if defined(WIN32) && defined(USE_TASKBAR)
-#include "backends/platform/sdl/sdl-window.h"
-
#include "common/str.h"
#include "common/taskbar.h"
+class SdlWindow_Win32;
struct ITaskbarList3;
class Win32TaskbarManager : public Common::TaskbarManager {
public:
- Win32TaskbarManager(SdlWindow *window);
+ Win32TaskbarManager(SdlWindow_Win32 *window);
virtual ~Win32TaskbarManager();
virtual void setOverlayIcon(const Common::String &name, const Common::String &description);
@@ -46,7 +45,7 @@ public:
virtual void clearError();
private:
- SdlWindow *_window;
+ SdlWindow_Win32 *_window;
ITaskbarList3 *_taskbar;
@@ -62,11 +61,6 @@ private:
* @return The icon path (or "" if no icon was found)
*/
Common::String getIconPath(Common::String target);
-
- // Helper functions
- bool confirmWindowsVersion(uint majorVersion, uint minorVersion);
- LPWSTR ansiToUnicode(const char *s);
- HWND getHwnd();
};
#endif