diff options
author | SupSuper | 2018-11-20 04:27:29 +0000 |
---|---|---|
committer | Thierry Crozat | 2018-12-16 10:48:13 +0000 |
commit | 2f2555f728086873eb074af4ca6b46025f405f75 (patch) | |
tree | 1a260c426e5560f18524469b8539f1b25e9b8740 /backends/platform/sdl | |
parent | 28e4d7bb438d75526f700cd954da6f28ebc45a29 (diff) | |
download | scummvm-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/platform/sdl')
-rw-r--r-- | backends/platform/sdl/module.mk | 1 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32-window.cpp | 22 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32-window.h | 1 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32_wrapper.cpp | 87 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32_wrapper.h | 50 |
6 files changed, 155 insertions, 8 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 |