From acece00ae291d143c3b712a98814a64b9dd43f14 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周一, 11 12月 2023 17:12:41 +0800 Subject: [PATCH] Remove VersionHelper --- src/widgets/widgetwindowagent.cpp | 2 src/core/qwindowkit_windows.h | 31 +++++++++++++++ src/core/qwindowkit_windows.cpp | 22 +++++++++++ src/core/windowagentbase.cpp | 13 ++++-- src/core/windowagentbase_p.h | 6 +++ src/core/contexts/win32windowcontext.cpp | 10 ++--- 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 2168e44..07ab1d2 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -22,7 +22,6 @@ #include <shellscalingapi.h> #include <dwmapi.h> #include <timeapi.h> -#include <versionhelpers.h> #include "nativeeventfilter.h" @@ -195,23 +194,22 @@ } static inline bool isWin8OrGreater() { - static const bool result = ::IsWindows8OrGreater(); + static const bool result = IsWindows8OrGreater_Real(); return result; } static inline bool isWin8Point1OrGreater() { - static const bool result = ::IsWindows8Point1OrGreater(); + static const bool result = IsWindows8Point1OrGreater_Real(); return result; } static inline bool isWin10OrGreater() { - static const bool result = ::IsWindows10OrGreater(); + static const bool result = IsWindows10OrGreater_Real(); return result; } static inline bool isWin11OrGreater() { - static const bool result = ::IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN10), - LOBYTE(_WIN32_WINNT_WIN10), 22000); + static const bool result = IsWindows11OrGreater_Real(); return result; } diff --git a/src/core/qwindowkit_windows.cpp b/src/core/qwindowkit_windows.cpp index c8f8c2d..826c454 100644 --- a/src/core/qwindowkit_windows.cpp +++ b/src/core/qwindowkit_windows.cpp @@ -1 +1,23 @@ #include "qwindowkit_windows.h" + +namespace QWK { + + typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + + RTL_OSVERSIONINFOW GetRealOSVersion() { + HMODULE hMod = GetModuleHandleW(L"ntdll.dll"); + if (hMod) { + auto fxPtr = reinterpret_cast<RtlGetVersionPtr>(GetProcAddress(hMod, "RtlGetVersion")); + if (fxPtr != nullptr) { + RTL_OSVERSIONINFOW rovi = {0}; + rovi.dwOSVersionInfoSize = sizeof(rovi); + if (0 == fxPtr(&rovi)) { + return rovi; + } + } + } + RTL_OSVERSIONINFOW rovi = {0}; + return rovi; + } + +} \ No newline at end of file diff --git a/src/core/qwindowkit_windows.h b/src/core/qwindowkit_windows.h index b36f429..ecdb4b1 100644 --- a/src/core/qwindowkit_windows.h +++ b/src/core/qwindowkit_windows.h @@ -4,6 +4,8 @@ #include <QtCore/qt_windows.h> #include <QtCore/qglobal.h> +#include <QWKCore/qwkcoreglobal.h> + #ifndef GET_X_LPARAM # define GET_X_LPARAM(lp) (static_cast<int>(static_cast<short>(LOWORD(lp)))) #endif @@ -45,4 +47,33 @@ # define WM_NCUAHDRAWFRAME (0x00AF) #endif +namespace QWK { + + QWK_CORE_EXPORT RTL_OSVERSIONINFOW GetRealOSVersion(); + + inline bool IsWindows10OrGreater_Real() { + RTL_OSVERSIONINFOW rovi = GetRealOSVersion(); + return (rovi.dwMajorVersion > 10) || + (rovi.dwMajorVersion == 10 && rovi.dwMinorVersion >= 0); + } + + inline bool IsWindows11OrGreater_Real() { + RTL_OSVERSIONINFOW rovi = GetRealOSVersion(); + return (rovi.dwMajorVersion > 10) || + (rovi.dwMajorVersion == 10 && rovi.dwMinorVersion >= 0 && + rovi.dwBuildNumber >= 22000); + } + + inline bool IsWindows8Point1OrGreater_Real() { + RTL_OSVERSIONINFOW rovi = GetRealOSVersion(); + return (rovi.dwMajorVersion > 6) || (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion >= 3); + } + + inline bool IsWindows8OrGreater_Real() { + RTL_OSVERSIONINFOW rovi = GetRealOSVersion(); + return (rovi.dwMajorVersion > 6) || (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion >= 2); + } + +} + #endif // QWINDOWKIT_WINDOWS_H diff --git a/src/core/windowagentbase.cpp b/src/core/windowagentbase.cpp index 94d1fca..65b7dad 100644 --- a/src/core/windowagentbase.cpp +++ b/src/core/windowagentbase.cpp @@ -13,6 +13,9 @@ namespace QWK { + WindowAgentBasePrivate::WindowContextFactoryMethod + WindowAgentBasePrivate::windowContextFactoryMethod = nullptr; + WindowAgentBasePrivate::WindowAgentBasePrivate() : q_ptr(nullptr), context(nullptr) { } @@ -22,15 +25,15 @@ } AbstractWindowContext *WindowAgentBasePrivate::createContext() const { - return + if (windowContextFactoryMethod) { + return windowContextFactoryMethod(); + } #ifdef Q_OS_WINDOWS - new Win32WindowContext() + return new Win32WindowContext(); #else - new QtWindowContext() + return new QtWindowContext(); #endif - ; } - bool WindowAgentBasePrivate::setup(QObject *host, WindowItemDelegate *delegate) { std::unique_ptr<AbstractWindowContext> ctx(createContext()); diff --git a/src/core/windowagentbase_p.h b/src/core/windowagentbase_p.h index 0fffb9c..f0e4a2d 100644 --- a/src/core/windowagentbase_p.h +++ b/src/core/windowagentbase_p.h @@ -22,6 +22,12 @@ std::unique_ptr<AbstractWindowContext> context; + public: + using WindowContextFactoryMethod = AbstractWindowContext *(*) (); + + static WindowContextFactoryMethod windowContextFactoryMethod; + + private: Q_DISABLE_COPY_MOVE(WindowAgentBasePrivate) }; diff --git a/src/widgets/widgetwindowagent.cpp b/src/widgets/widgetwindowagent.cpp index c85f14e..bde4f98 100644 --- a/src/widgets/widgetwindowagent.cpp +++ b/src/widgets/widgetwindowagent.cpp @@ -22,7 +22,7 @@ QPainter painter(widget); QRect rect = e->rect(); QRegion region = e->region(); - void *a[3] = { + void *a[] = { &painter, &rect, ®ion, -- Gitblit v1.9.1