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/taskbar | |
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/taskbar')
-rw-r--r-- | backends/taskbar/win32/win32-taskbar.cpp | 102 | ||||
-rw-r--r-- | backends/taskbar/win32/win32-taskbar.h | 12 |
2 files changed, 19 insertions, 95 deletions
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 |