From f6b34ce173830e470ae01597c7c1d66eaee58617 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Aug 2019 12:25:41 +0200 Subject: Windows QPA: Update theme fonts when the primary screen changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call into the theme to update the fonts on a change. This at least helps in the case of disabled High DPI scaling. Task-number: QTBUG-77144 Change-Id: I2c8fd85259403eaaeea56cd096f99116fc6bba9a Reviewed-by: André de la Rocha Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsscreen.cpp | 6 ++++++ src/plugins/platforms/windows/qwindowstheme.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 4137a4bd9a..cecd06f5a4 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -42,6 +42,7 @@ #include "qwindowswindow.h" #include "qwindowsintegration.h" #include "qwindowscursor.h" +#include "qwindowstheme.h" #include @@ -547,10 +548,13 @@ bool QWindowsScreenManager::handleScreenChanges() // Look for changed monitors, add new ones const WindowsScreenDataList newDataList = monitorData(); const bool lockScreen = newDataList.size() == 1 && (newDataList.front().flags & QWindowsScreenData::LockScreen); + bool primaryScreenChanged = false; for (const QWindowsScreenData &newData : newDataList) { const int existingIndex = indexOfMonitor(m_screens, newData.name); if (existingIndex != -1) { m_screens.at(existingIndex)->handleChanges(newData); + if (existingIndex == 0) + primaryScreenChanged = true; } else { QWindowsScreen *newScreen = new QWindowsScreen(newData); m_screens.push_back(newScreen); @@ -567,6 +571,8 @@ bool QWindowsScreenManager::handleScreenChanges() removeScreen(i); } // for existing screens } // not lock screen + if (primaryScreenChanged) + QWindowsTheme::instance()->refreshFonts(); return true; } diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index c132f20167..28c69e4ec1 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -85,6 +85,8 @@ public: static bool useNativeMenus(); + void refreshFonts(); + static const char *name; private: @@ -92,7 +94,6 @@ private: void clearPalettes(); void refreshPalettes(); void clearFonts(); - void refreshFonts(); void refreshIconPixmapSizes(); static QWindowsTheme *m_instance; -- cgit v1.2.3 From 43983b0b6fe2ca0d6f42edcec19115fb16753b75 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 2 Sep 2019 16:45:00 +0200 Subject: Remove QOperatingSystemVersion::WindowsVista The minimum supported version is Windows 7. Remove QOperatingSystemVersion::WindowsVista added by b0cd007335853f283c47ffb0f5611d14e6dbe84b and replace with "true" wherever it was used. Change-Id: I08c0208467b655a921b6773f77d8bc099be69031 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index c4ada66ca9..feb2bc824b 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -84,8 +84,7 @@ static const int windowsRightBorder = 15; // right border on windows */ bool QWindowsVistaStylePrivate::useVista() { - return QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista - && QWindowsVistaStylePrivate::useXP(); + return QWindowsVistaStylePrivate::useXP(); } /* \internal -- cgit v1.2.3 From 891b1f51b937ce3052de48dcf8416c875cf52326 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 28 Aug 2019 18:51:46 +0300 Subject: Android: Fix cmake generator Fixes: QTBUG-29859 Change-Id: Id0b5f9ab8b4866483361ba9f15cf51dc0d2627d0 Reviewed-by: Alexandru Croitor --- src/plugins/platforms/android/android.pro | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 78632a9bea..346df84038 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -93,7 +93,3 @@ qtConfig(vulkan) { PLUGIN_TYPE = platforms load(qt_plugin) - -#Non-standard install directory, QTBUG-29859 -DESTDIR = $$DESTDIR/android -target.path = $${target.path}/android -- cgit v1.2.3 From c2e32a29c3736c79cd6e7b669147d61764d0ff9e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:25:35 +0200 Subject: QWindowsUiaTextRangeProvider: replace ephemeral QList with QVLA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QList is horribly inefficient™. Since the container only lives for the duration of the function call, use QVLA instead. Change-Id: I2d179caef37bb78efface5547ff8bfcdc8f9a6ac Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp index 8e395669f8..d8b8f7281d 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp @@ -48,6 +48,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -227,7 +228,7 @@ HRESULT QWindowsUiaTextRangeProvider::GetBoundingRectangles(SAFEARRAY **pRetVal) return UIA_E_ELEMENTNOTAVAILABLE; int len = textInterface->characterCount(); - QList rectList; + QVarLengthArray rectList; if ((m_startOffset >= 0) && (m_endOffset <= len) && (m_startOffset < m_endOffset)) { int start, end; -- cgit v1.2.3 From 94902905ec203626abc050744d14898674dc2bbd Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Sun, 11 Aug 2019 17:06:48 +0200 Subject: Windows QPA: Preferably use DXGI to obtain adapter info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWindowsOpenGLTester used Direct3D9 to determine GPU properties such as the vendor ID. Prefer the more modern DXGI, if available. Change-Id: Ie6b20dbe2d69bacb28d5d4e4e3459709ddc58537 Reviewed-by: André de la Rocha --- .../platforms/windows/qwindowsopengltester.cpp | 256 +++++++++++++++++++-- src/plugins/platforms/windows/windows.pri | 2 + 2 files changed, 235 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index afc1991e2c..63ecbfe0ea 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,8 @@ #include #include #include +#include +#include QT_BEGIN_NAMESPACE @@ -80,52 +83,259 @@ static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIF return result; } -class QDirect3D9Handle +class QGraphicsAdapterInfo { public: - Q_DISABLE_COPY_MOVE(QDirect3D9Handle) + Q_DISABLE_COPY_MOVE(QGraphicsAdapterInfo) - QDirect3D9Handle(); - ~QDirect3D9Handle(); + QGraphicsAdapterInfo(); + ~QGraphicsAdapterInfo(); - bool isValid() const { return m_direct3D9 != nullptr; } + bool isValid() const; - UINT adapterCount() const { return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; } + UINT adapterCount() const; bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; private: + QSystemLibrary m_dxgilib; + IDXGIFactory1 *m_dxgiFactory1 = nullptr; + QSystemLibrary m_d3d9lib; IDirect3D9 *m_direct3D9 = nullptr; + + /* This is a value from the DXGI_ADAPTER_FLAG enum. + * However, it's not available in dxgi.h from MinGW, + * so define it here in any case. */ + enum { DXGI_ADAPTER_FLAG_SOFTWARE = 2 }; + + UINT adapterCountDXGI() const; + bool retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; + + UINT adapterCountD3D9() const; + bool retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; }; -QDirect3D9Handle::QDirect3D9Handle() : +QGraphicsAdapterInfo::QGraphicsAdapterInfo() : + m_dxgilib(QStringLiteral("dxgi")), m_d3d9lib(QStringLiteral("d3d9")) { - using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); + using PtrCreateDXGIFactory1 = HRESULT (WINAPI *)(REFIID, void**); - if (m_d3d9lib.load()) { - if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) - m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); + if (m_dxgilib.load()) { + if (auto createDXGIFactory1 = (PtrCreateDXGIFactory1)m_dxgilib.resolve("CreateDXGIFactory1")) + createDXGIFactory1(IID_PPV_ARGS(&m_dxgiFactory1)); + } + + if (!m_dxgiFactory1) { + using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); + + if (m_d3d9lib.load()) { + if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) + m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); + } } } -QDirect3D9Handle::~QDirect3D9Handle() +QGraphicsAdapterInfo::~QGraphicsAdapterInfo() { + if (m_dxgiFactory1) + m_dxgiFactory1->Release(); if (m_direct3D9) m_direct3D9->Release(); } -bool QDirect3D9Handle::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +bool QGraphicsAdapterInfo::isValid() const +{ + return m_dxgiFactory1 != nullptr || m_direct3D9 != nullptr; +} + +UINT QGraphicsAdapterInfo::adapterCount() const +{ + if (m_dxgiFactory1) + return adapterCountDXGI(); + if (m_direct3D9) + return adapterCountD3D9(); + return 0; +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +{ + if (m_dxgiFactory1) + return retrieveAdapterIdentifierDXGI(n, adapterIdentifier); + if (m_direct3D9) + return retrieveAdapterIdentifierD3D9(n, adapterIdentifier); + return false; +} + +UINT QGraphicsAdapterInfo::adapterCountDXGI() const +{ + /* DXGI doesn't have an adapterCount(), instead we have to call EnumAdapters1() + * until DXGI_ERROR_NOT_FOUND is returned. */ + UINT n = 0; + + IDXGIAdapter1 *adapter; + while (SUCCEEDED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) { + adapter->Release(); + ++n; + } + + return n; +} + +// Detect whether we are running under 64-bit Windows. +static bool isWow64Process() +{ + typedef BOOL (WINAPI *IsWow64ProcessPtr)(HANDLE hProcess, PBOOL Wow64Process); + IsWow64ProcessPtr IsWow64Process = (IsWow64ProcessPtr)QLibrary::resolve( + QStringLiteral("kernel32.dll"), "IsWow64Process"); + + if (IsWow64Process) { + BOOL IsWow64 = FALSE; + if (IsWow64Process(GetCurrentProcess(), &IsWow64)) + return IsWow64; + } + return false; +} + +// Read a string value from registry +static QString regGetString(HKEY key, const wchar_t* valueName) +{ + QVarLengthArray buf (MAX_PATH); + LRESULT res; + DWORD bufSize = buf.size() * sizeof(wchar_t); + res = RegGetValue(key, nullptr, valueName, + RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, + buf.data(), &bufSize); + if (res == ERROR_MORE_DATA) { + buf.resize(bufSize / sizeof(wchar_t)); + bufSize = buf.size() * sizeof(wchar_t); + res = RegGetValue(key, nullptr, valueName, + RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, + buf.data(), &bufSize); + } + /* In case of REG_MULTI_SZ, this returns just the first string, + * but that is sufficient for our purposes. */ + if (res == ERROR_SUCCESS) + return QString::fromWCharArray(buf.data()); + return QString(); +} + +// Read driver name given a DeviceKey +static QString retrieveDriverName(const wchar_t *driverKey) +{ + /* Kernel-style prefix, maps to HKLM + * (see https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/registry-key-object-routines) */ + static const wchar_t prefixMappingHKLM[] = L"\\Registry\\Machine\\"; + const size_t prefixMappingHKLMLen = wcslen(prefixMappingHKLM); + if (wcsnicmp(driverKey, prefixMappingHKLM, prefixMappingHKLMLen) != 0) + return QString(); + + driverKey += prefixMappingHKLMLen; + QString driverPath; + HKEY key; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, driverKey, 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { + const wchar_t *valueName = + isWow64Process() ? L"UserModeDriverNameWow" : L"UserModeDriverName"; + driverPath = regGetString(key, valueName); + RegCloseKey(key); + } + if (!driverPath.isEmpty()) { + int fileNameSep = driverPath.lastIndexOf(QLatin1Char('\\')); + if (fileNameSep >= 0) + driverPath = driverPath.mid(fileNameSep + 1); + return driverPath; + } + return QString(); +} + +// Retrieve driver name for a display device from registry. +static QString driverNameForDevice(const wchar_t *displayDevice) +{ + QString driverName; + DISPLAY_DEVICE dd; + memset(&dd, 0, sizeof(dd)); + dd.cb = sizeof(dd); + for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) { + if (wcsicmp(displayDevice, dd.DeviceName) == 0) { + // DeviceKey is documented as "internal", but it's a registry key in kernel format + driverName = retrieveDriverName(dd.DeviceKey); + break; + } + } + if (driverName.isEmpty()) { + /* Fall back to driver name from EnumDisplaySettings. + * This is only a fallback as on Windows 10 this just returns an device-independent + * name. OTOH, it's possible to recognize RDP connections from the driver name. */ + DEVMODE devMode; + if (EnumDisplaySettings(displayDevice, ENUM_CURRENT_SETTINGS, &devMode)) + driverName = QString::fromWCharArray(devMode.dmDeviceName); + } + return driverName; +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +{ + IDXGIAdapter1 *adapter; + if (FAILED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) + return false; + + bool result = false; + + DXGI_ADAPTER_DESC1 adapterDesc; + if (SUCCEEDED(adapter->GetDesc1(&adapterDesc))) { + if ((adapterDesc.VendorId != 0) && (adapterDesc.DeviceId != 0) // Don't use adapter description of Software Devices + && ((adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0)) { + memset(adapterIdentifier, 0, sizeof(*adapterIdentifier)); + WideCharToMultiByte(1252, 0, adapterDesc.Description, -1, + adapterIdentifier->Description, + sizeof(adapterIdentifier->Description), nullptr, nullptr); + adapterIdentifier->Description[sizeof(adapterIdentifier->Description) - 1] = 0; + adapterIdentifier->VendorId = adapterDesc.VendorId; + adapterIdentifier->DeviceId = adapterDesc.DeviceId; + adapterIdentifier->SubSysId = adapterDesc.SubSysId; + adapterIdentifier->Revision = adapterDesc.Revision; + + LARGE_INTEGER umdVersion; + if (SUCCEEDED(adapter->CheckInterfaceSupport(__uuidof(ID3D10Device), &umdVersion))) { + adapterIdentifier->DriverVersion = umdVersion; + result = true; + } + + /* DXGI doesn't expose the driver name, but we can get it from the registry. + * But we need a device name to follow. */ + IDXGIOutput *output = nullptr; + if (SUCCEEDED(adapter->EnumOutputs (0, &output))) { + DXGI_OUTPUT_DESC outputDesc; + if (SUCCEEDED(output->GetDesc (&outputDesc))) { + QString driverName = driverNameForDevice(outputDesc.DeviceName); + qstrncpy(adapterIdentifier->Driver, driverName.toLatin1().constData(), + sizeof(adapterIdentifier->Driver)); + } + output->Release(); + } + } + } + + adapter->Release(); + + return result; +} + +UINT QGraphicsAdapterInfo::adapterCountD3D9() const +{ + return m_direct3D9->GetAdapterCount(); +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const { - return m_direct3D9 - && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); + return SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); } GpuDescription GpuDescription::detect() { GpuDescription result; - QDirect3D9Handle direct3D9; - if (!direct3D9.isValid()) + QGraphicsAdapterInfo adapterInfo; + if (!adapterInfo.isValid()) return result; D3DADAPTER_IDENTIFIER9 adapterIdentifier; @@ -136,7 +346,7 @@ GpuDescription GpuDescription::detect() // and D3D uses by default. Therefore querying any additional adapters is // futile and not useful for our purposes in general, except for // identifying a few special cases later on. - if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) { + if (adapterInfo.retrieveAdapterIdentifier(0, &adapterIdentifier)) { result = adapterIdentifierToGpuDescription(adapterIdentifier); isAMD = result.vendorId == VENDOR_ID_AMD; } @@ -145,9 +355,9 @@ GpuDescription GpuDescription::detect() // when starting apps on a screen connected to the Intel card) by looking // for a default AMD adapter and an additional non-AMD one. if (isAMD) { - const UINT adapterCount = direct3D9.adapterCount(); + const UINT adapterCount = adapterInfo.adapterCount(); for (UINT adp = 1; adp < adapterCount; ++adp) { - if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier) + if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier) && adapterIdentifier.VendorId != VENDOR_ID_AMD) { // Bingo. Now figure out the display for the AMD card. DISPLAY_DEVICE dd; @@ -172,11 +382,11 @@ GpuDescription GpuDescription::detect() QVector GpuDescription::detectAll() { QVector result; - QDirect3D9Handle direct3D9; - if (const UINT adapterCount = direct3D9.adapterCount()) { + QGraphicsAdapterInfo adapterInfo; + if (const UINT adapterCount = adapterInfo.adapterCount()) { for (UINT adp = 0; adp < adapterCount; ++adp) { D3DADAPTER_IDENTIFIER9 adapterIdentifier; - if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)) + if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier)) result.append(adapterIdentifierToGpuDescription(adapterIdentifier)); } } diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index 95ba961df1..7de6369541 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -12,6 +12,8 @@ LIBS += -lshlwapi -lwtsapi32 QMAKE_USE_PRIVATE += \ advapi32 \ d3d9/nolink \ + d3d11/nolink \ + dxgi/nolink \ ole32 \ shell32 \ user32 \ -- cgit v1.2.3 From e77877f2079a74918c139b8ea7f6dc927246c20f Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Wed, 26 Jul 2017 11:27:30 +0200 Subject: Windows QPA: Also wrap DescribePixelFormat() GDI and the software rendering opengl32sw.dll may have very different pixel formats so use wglDescribePixelFormat() in that case. This mirrors the existing behavior for SetPixelFormat(). Change-Id: I55e658ab69bad84bb10cc5a042d62e84c005c0e6 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsglcontext.cpp | 12 +++++++++--- src/plugins/platforms/windows/qwindowsglcontext.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 101db75d0b..64b83e2bc4 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -196,6 +196,7 @@ bool QWindowsOpengl32DLL::init(bool softwareRendering) wglShareLists = reinterpret_cast(resolve("wglShareLists")); wglSwapBuffers = reinterpret_cast(resolve("wglSwapBuffers")); wglSetPixelFormat = reinterpret_cast(resolve("wglSetPixelFormat")); + wglDescribePixelFormat = reinterpret_cast(resolve("wglDescribePixelFormat")); glGetError = reinterpret_cast(resolve("glGetError")); glGetIntegerv = reinterpret_cast(resolve("glGetIntegerv")); @@ -214,6 +215,11 @@ BOOL QWindowsOpengl32DLL::setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRI return moduleIsNotOpengl32() ? wglSetPixelFormat(dc, pf, pfd) : SetPixelFormat(dc, pf, pfd); } +int QWindowsOpengl32DLL::describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd) +{ + return moduleIsNotOpengl32() ? wglDescribePixelFormat(dc, pf, size, pfd) : DescribePixelFormat(dc, pf, size, pfd); +} + QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *context) { return new QWindowsGLContext(this, context); @@ -322,11 +328,11 @@ static inline bool static void describeFormats(HDC hdc) { - const int pfiMax = DescribePixelFormat(hdc, 0, 0, nullptr); + const int pfiMax = QOpenGLStaticContext::opengl32.describePixelFormat(hdc, 0, 0, nullptr); for (int i = 0; i < pfiMax; i++) { PIXELFORMATDESCRIPTOR pfd; initPixelFormatDescriptor(&pfd); - DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); qCDebug(lcQpaGl) << '#' << i << '/' << pfiMax << ':' << pfd; } } @@ -617,7 +623,7 @@ static int choosePixelFormat(HDC hdc, // Verify if format is acceptable. Note that the returned // formats have been observed to not contain PFD_SUPPORT_OPENGL, ignore. initPixelFormatDescriptor(obtainedPfd); - DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); if (!isAcceptableFormat(additional, *obtainedPfd, true)) { qCDebug(lcQpaGl) << __FUNCTION__ << " obtained px #" << pixelFormat << " not acceptable=" << *obtainedPfd; diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 1abe2eb390..e962af39c2 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -107,6 +107,7 @@ struct QWindowsOpengl32DLL // Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc. BOOL swapBuffers(HDC dc); BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); // WGL HGLRC (WINAPI * wglCreateContext)(HDC dc); @@ -130,6 +131,7 @@ private: // For Mesa llvmpipe shipped with a name other than opengl32.dll BOOL (WINAPI * wglSwapBuffers)(HDC dc); BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); }; class QOpenGLStaticContext : public QWindowsStaticOpenGLContext -- cgit v1.2.3 From b1698e9bc2ca0668f5b5f0e7af2274eb2a0cb7e0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:44:16 +0200 Subject: QWinRTUia*: remove anti-pattern passing new'ed QSharedPointer into lambdas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QSharedPointer is made for passing around by value. It is unclear why in so many repeated cases a QSharedPointer is created on the stack, then a copy of it is new'ed up, passed into a lambda to be deleted inside it. First, it requires an additional heap allocation. Because it's passed as a raw pointer to QSharedPointer, however, there's also always the danger that it's leaked by seemingly-innocuous changes such as adding an early return from the lambda (and some of them could really use one, with the ifs nesting several levels deep). All this is not needed, though. It's perfectly ok to store a copy of a QSharedPointer, by value, in a lambda, and keep one copy outside it. Poor man's std::future, if you will. So, do away with all that, just pass the shared pointer by value into the lambda, and, as a drive-by, replace some ephemeral QLists with QVLAs. In one case, replace a QPair with a struct to make the code using that type more accessible ('first' and 'second' are really, really bad variable names if they, in fact, represent 'startOffset' and 'endOffset'). Also port directly to shared_ptr / make_shared. Saves one memory allocation each, due to the co-allocation of payload and control block, and even though there's QSharedPointer::create, which does this, too, std::shared_ptr is simply much lighter on the use of atomics (copying a QSP ups two ref counts, copying a std::shared_ptr just one). Since these variables live behind the API boundary, there's no reason not to prefer the more efficient alternative. Change-Id: I4b9fe30e56df5106fc2ab7a0b55b2b8316cca5fe Reviewed-by: Oliver Wolff Reviewed-by: Mårten Nordheim --- .../uiautomation/qwinrtuiagriditemprovider.cpp | 12 +++---- .../winrt/uiautomation/qwinrtuiagridprovider.cpp | 12 +++---- .../winrt/uiautomation/qwinrtuiamainprovider.cpp | 26 +++++++-------- .../winrt/uiautomation/qwinrtuiamainprovider.h | 2 +- .../qwinrtuiaselectionitemprovider.cpp | 10 +++--- .../uiautomation/qwinrtuiaselectionprovider.cpp | 18 +++++----- .../uiautomation/qwinrtuiatableitemprovider.cpp | 18 +++++----- .../winrt/uiautomation/qwinrtuiatableprovider.cpp | 18 +++++----- .../winrt/uiautomation/qwinrtuiatextprovider.cpp | 38 ++++++++++++---------- .../uiautomation/qwinrtuiatextrangeprovider.cpp | 21 ++++++------ 10 files changed, 85 insertions(+), 90 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp index 524000b618..355dbf7d20 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -105,19 +107,17 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ContainingGrid(IIRawEle *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { if (QAccessibleInterface *table = tableCellInterface->table()) { - **ptrElementId = idForAccessible(table); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(table); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp index e469991de2..3bd90f6850 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,21 +106,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::GetItem(INT32 row, INT32 column *returnValue = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { if ((row >= 0) && (row < tableInterface->rowCount()) && (column >= 0) && (column < tableInterface->columnCount())) { if (QAccessibleInterface *cell = tableInterface->cellAt(row, column)) { - **ptrElementId = idForAccessible(cell); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(cell); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp index 6f3ad6dcd2..0b1db306bd 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp @@ -64,6 +64,8 @@ #include #include +#include + using namespace QWinRTUiAutomation; using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; @@ -179,7 +181,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderForAccessibleId(QAccessible::Id elemen } // Returns an array of IIRawElementProviderSimple instances for a list of accessible interface ids. -HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList &elementIds, +HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QVarLengthArray &elementIds, UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) { @@ -190,7 +192,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList rawProviderList; - for (auto elementId : qAsConst(elementIds)) { + for (auto elementId : elementIds) { IIRawElementProviderSimple *rawProvider; if (SUCCEEDED(rawProviderForAccessibleId(elementId, &rawProvider))) rawProviderList.append(rawProvider); @@ -515,10 +517,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector>(new QList); - auto ptrChildren = new QSharedPointer>(children); + auto children = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrChildren]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, children]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -526,11 +527,10 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVectorload(childId); if (!childAcc->state().invisible) - (*ptrChildren)->append(childId); + children->append(childId); } } } - delete ptrChildren; return S_OK; }))) { return E_FAIL; @@ -538,7 +538,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector> peerVector = Make(); - for (auto childId : qAsConst(*children)) { + for (auto childId : *children) { if (ComPtr provider = providerForAccessibleId(childId)) { IAutomationPeer *peer; if (SUCCEEDED(provider.CopyTo(&peer))) @@ -750,10 +750,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // Scale coordinates from High DPI screens? auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId, point]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId, point]() { // Controls can be embedded within grouping elements. By default returns the innermost control. QAccessibleInterface *target = accessibleForId(accid); while (QAccessibleInterface *tmpacc = target->childAt(point.X, point.Y)) { @@ -761,9 +760,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // For accessibility tools it may be better to return the text element instead of its subcomponents. if (target->textInterface()) break; } - **ptrElementId = idForAccessible(target); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); - delete ptrElementId; + *elementId = idForAccessible(target); + QWinRTUiaMetadataCache::instance()->load(*elementId); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h index 384a166cf7..23a6e56ae7 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h @@ -69,7 +69,7 @@ public: virtual ~QWinRTUiaMainProvider(); static QWinRTUiaMainProvider *providerForAccessibleId(QAccessible::Id id); static HRESULT rawProviderForAccessibleId(QAccessible::Id elementId, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue); - static HRESULT rawProviderArrayForAccessibleIdList(const QList &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); + static HRESULT rawProviderArrayForAccessibleIdList(const QVarLengthArray &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); static void notifyFocusChange(QAccessibleEvent *event); static void notifyVisibilityChange(QAccessibleEvent *event); static void notifyStateChange(QAccessibleStateChangeEvent *event); diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp index 9bc88272ba..2cb5aa685c 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -94,21 +96,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_SelectionContainer *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // Radio buttons do not require a container. if (accessible->role() == QAccessible::ListItem) { if (QAccessibleInterface *parent = accessible->parent()) { if (parent->role() == QAccessible::List) { - **ptrElementId = idForAccessible(parent); + *elementId = idForAccessible(parent); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp index 9e61a8df61..4d825351c8 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -89,10 +91,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo *value = false; auto accid = id(); - auto selectionRequired = QSharedPointer(new bool(false)); - auto ptrSelectionRequired = new QSharedPointer(selectionRequired); + auto selectionRequired = std::make_shared(false); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelectionRequired]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selectionRequired]() { // Initially returns false if none are selected. After the first selection, it may be required. bool anySelected = false; if (QAccessibleInterface *accessible = accessibleForId(accid)) { @@ -105,9 +106,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo } } } - **ptrSelectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; + *selectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; } - delete ptrSelectionRequired; return S_OK; }))) { return E_FAIL; @@ -128,10 +128,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -139,12 +138,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur if (childAcc->state().selected) { QAccessible::Id childId = idForAccessible(childAcc); QWinRTUiaMetadataCache::instance()->load(childId); - (*ptrElementIds)->append(childId); + elementIds->append(childId); } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp index 1af74a8b72..7cd953de87 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -79,21 +81,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT3 *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList headers = tableCellInterface->columnHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -113,21 +113,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 * *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList headers = tableCellInterface->rowHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp index e71ade3c1f..d763b320b1 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -91,10 +93,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->columnCount(); ++i) { @@ -105,14 +106,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -132,10 +132,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->rowCount(); ++i) { @@ -146,14 +145,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp index aa120377df..cd7420f360 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,26 +106,26 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu *returnValueSize = 0; *returnValue = nullptr; + struct Selection { int startOffset, endOffset; }; + auto accid = id(); - auto selections = QSharedPointer>>(new QList>); - auto ptrSelections = new QSharedPointer>>(selections); + auto selections = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelections]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selections]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { for (int i = 0; i < textInterface->selectionCount(); ++i) { - QPair sel; - textInterface->selection(i, &sel.first, &sel.second); - (*ptrSelections)->append(sel); + int startOffset, endOffset; + textInterface->selection(i, &startOffset, &endOffset); + selections->append({startOffset, endOffset}); } - if ((*ptrSelections)->size() == 0) { + if (selections->size() == 0) { // If there is no selection, we return an array with a single degenerate (empty) text range at the cursor position. - QPair sel(textInterface->cursorPosition(), textInterface->cursorPosition()); - (*ptrSelections)->append(sel); + auto cur = textInterface->cursorPosition(); + selections->append({cur, cur}); } } } - delete ptrSelections; return S_OK; }))) { return E_FAIL; @@ -137,9 +139,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu if (!providerArray) return E_OUTOFMEMORY; - for (int i = 0; i < selCount; ++i) { - ComPtr textRangeProvider = Make(id(), (*selections)[i].first, (*selections)[i].second); - textRangeProvider.CopyTo(&providerArray[i]); + auto dst = providerArray; + for (auto sel : *selections) { + ComPtr textRangeProvider + = Make(id(), sel.startOffset, sel.endOffset); + textRangeProvider.CopyTo(dst++); } *returnValueSize = selCount; *returnValue = providerArray; @@ -184,14 +188,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromPoint(ABI::Windows::Fo const QPoint pt(screenLocation.X, screenLocation.Y); auto accid = id(); - auto offset = QSharedPointer(new int); - auto ptrOffset = new QSharedPointer(offset); + auto offset = std::make_shared(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, ptrOffset]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, offset]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) if (QAccessibleTextInterface *textInterface = accessible->textInterface()) - **ptrOffset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); - delete ptrOffset; + *offset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp index fc3778d652..ca15feaff9 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -212,10 +214,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT auto accid = id(); auto startOffset = m_startOffset; auto endOffset = m_endOffset; - auto rects = QSharedPointer>(new QList); - auto ptrRects = new QSharedPointer>(rects); + auto rects = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, ptrRects]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, rects]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { int len = textInterface->characterCount(); @@ -233,7 +234,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT qMin(startRect.y(), endRect.y()), qMax(startRect.x() + startRect.width(), endRect.x() + endRect.width()) - qMin(startRect.x(), endRect.x()), qMax(startRect.y() + startRect.height(), endRect.y() + endRect.height()) - qMin(startRect.y(), endRect.y())); - (*ptrRects)->append(lineRect); + rects->append(lineRect); } if (end >= len) break; textInterface->textAfterOffset(end + 1, QAccessible::LineBoundary, &start, &end); @@ -241,7 +242,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT } } } - delete ptrRects; return S_OK; }))) { return E_FAIL; @@ -251,11 +251,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT if (!doubleArray) return E_OUTOFMEMORY; - for (int i = 0; i < rects->size(); ++i) { - doubleArray[i*4] = (*rects)[i].left(); - doubleArray[i*4+1] = (*rects)[i].top(); - doubleArray[i*4+2] = (*rects)[i].width(); - doubleArray[i*4+3] = (*rects)[i].height(); + DOUBLE *dst = doubleArray; + for (auto rect : *rects) { + *dst++ = rect.left(); + *dst++ = rect.top(); + *dst++ = rect.width(); + *dst++ = rect.height(); } *returnValue = doubleArray; *returnValueSize = 4 * rects->size(); -- cgit v1.2.3 From bc34784d053ebf9b0d167e9398052fcc80d8af87 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sun, 8 Sep 2019 10:27:47 +0200 Subject: Handle robustness with OpenGL < 4.0 We need to have the right idea of robustness, so check for extension. Fixes: QTBUG-78107 Change-Id: I26987269e5c50bee20e2e3cc6d75f91a6c9af25e Reviewed-by: Laszlo Agocs --- .../gl_integrations/xcb_glx/qglxintegration.cpp | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index 5e5fefca90..2b77062b16 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); +typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint); #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 @@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param) return QByteArray(); } +static bool hasGlExtension(const QSurfaceFormat &format, const char *ext) +{ + if (format.majorVersion() < 3) { + auto exts = reinterpret_cast(glGetString(GL_EXTENSIONS)); + return exts && strstr(exts, ext); + } else { + auto glGetStringi = reinterpret_cast( + glXGetProcAddress(reinterpret_cast("glGetStringi"))); + if (glGetStringi) { + GLint n = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + for (GLint i = 0; i < n; ++i) { + const char *p = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + if (p && !strcmp(p, ext)) + return true; + } + } + return false; + } +} + static void updateFormatFromContext(QSurfaceFormat &format) { // Update the version, profile, and context bit of the format @@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format) format.setOption(QSurfaceFormat::StereoBuffers); if (format.renderableType() == QSurfaceFormat::OpenGL) { - if (format.version() >= qMakePair(4, 0)) { + if (hasGlExtension(format, "GL_ARB_robustness")) { GLint value = 0; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value); if (value == GL_LOSE_CONTEXT_ON_RESET_ARB) -- cgit v1.2.3 From 137cbd1c7200809cc3945c6d4b6deee560cdc9fc Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 29 Aug 2019 23:58:58 +0200 Subject: Cocoa: Set the accepted action to be the one from the response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By setting the accepted action to be the one from the response it will enable the user to set the drop action in their code and this will be reflected at the platform level. Change-Id: I7b9459b228c00ef01d91649b3405316729713164 Fixes: QTBUG-77427 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_dragging.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 37e972dba9..41b96b2df6 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -270,6 +270,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin // The drag was started from within the application response = QWindowSystemInterface::handleDrop(target, nativeDrag->dragMimeData(), point, qtAllowed, buttons, modifiers); + nativeDrag->setAcceptedAction(response.acceptedAction()); } else { QCocoaDropData mimeData(sender.draggingPasteboard); response = QWindowSystemInterface::handleDrop(target, &mimeData, @@ -282,6 +283,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin { Q_UNUSED(session); Q_UNUSED(screenPoint); + Q_UNUSED(operation); if (!m_platformWindow) return; @@ -290,8 +292,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin if (!target) return; - QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); - nativeDrag->setAcceptedAction(qt_mac_mapNSDragOperation(operation)); + QCocoaIntegration::instance()->drag(); // Qt starts drag-and-drop on a mouse button press event. Cococa in // this case won't send the matching release event, so we have to -- cgit v1.2.3 From 117175a2f2ecab990f65eefd32b42be22f9aa3ce Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 11 Sep 2019 17:56:14 +0200 Subject: macOS dark mode: set the link color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-71740 Change-Id: I49f49338c7f3a28845de63c2a6bf2dc8495dd108 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoasystemsettings.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index 9b6dc94d33..cb25bd7d81 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -52,6 +52,8 @@ @property (class, strong, readonly) NSColor *unemphasizedSelectedTextColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSColor *unemphasizedSelectedContentBackgroundColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSArray *alternatingContentBackgroundColors NS_AVAILABLE_MAC(10_14); +// Missing from non-Mojave SDKs, even if introduced in 10.10 +@property (class, strong, readonly) NSColor *linkColor NS_AVAILABLE_MAC(10_10); @end #endif @@ -111,6 +113,8 @@ QPalette * qt_mac_createSystemPalette() palette->setBrush(QPalette::ToolTipBase, qt_mac_toQBrush([NSColor controlColor])); + palette->setColor(QPalette::Normal, QPalette::Link, qt_mac_toQColor([NSColor linkColor])); + return palette; } -- cgit v1.2.3 From 6eaa1d07e1e86f1535b8294645f75972dc69184b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Sep 2019 09:24:29 +0200 Subject: Eliminate the last QList in QtBase production code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QList is horribly inefficient™ (on 32-bit platforms). Fix by using a QVector instead. Change-Id: Id85cb71404f329049c3e9997e51113035569e1b4 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/eglfs/api/qeglfscursor_p.h | 4 +++- .../platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h index 89c2e89f58..8768f9dd8c 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h @@ -59,6 +59,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QOpenGLShaderProgram; @@ -143,7 +145,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList hotSpots; + QVector hotSpots; QImage image; // valid until it's uploaded } m_cursorAtlas; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h index c96dd585d3..d47b579238 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h @@ -41,7 +41,7 @@ #define QEGLFSKMSGBMCURSOR_H #include -#include +#include #include #include @@ -110,7 +110,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList hotSpots; + QVector hotSpots; QImage image; } m_cursorAtlas; }; -- cgit v1.2.3 From 29e40c1f6f630803747ca615f99d2813df57fc52 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:49:09 +0200 Subject: QWinRTUiaValueProvider: optimize SetValue() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code followed a pattern used elsewhere whereby a return value is transmitted out of a task executed on a separate thread by way of shared ownership of the value using QSharedPointer. In the present case, however, the pattern was applied to an argument of the task, not its return value, so remove all the sharing machinery and just copy the argument (a QString) into the task (a lambda). Change-Id: Ib997322ed70201781b6012c7e4f945b124b05868 Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp index 21389b74d2..255d8ee49e 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp @@ -96,24 +96,22 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) qCDebug(lcQpaUiAutomation) << __FUNCTION__; auto accid = id(); - auto tmpValue = QSharedPointer(new QString); - auto ptrValue = new QSharedPointer(tmpValue); - *tmpValue = hStrToQStr(value); + QString tmpValue = hStrToQStr(value); - QEventDispatcherWinRT::runOnMainThread([accid, ptrValue]() { + QEventDispatcherWinRT::runOnMainThread([accid, tmpValue]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // First sets the value as a text. - accessible->setText(QAccessible::Value, **ptrValue); + accessible->setText(QAccessible::Value, tmpValue); // Then, if the control supports the value interface (range value) // and the supplied text can be converted to a number, and that number // lies within the min/max limits, sets it as the control's current (numeric) value. if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { bool ok = false; - double numval = (*ptrValue)->toDouble(&ok); + double numval = tmpValue.toDouble(&ok); if (ok) { double minimum = valueInterface->minimumValue().toDouble(); double maximum = valueInterface->maximumValue().toDouble(); @@ -124,7 +122,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) } } QWinRTUiaMetadataCache::instance()->load(accid); - delete ptrValue; return S_OK; }, 0); -- cgit v1.2.3 From 4534522ff0f189418d828fd29b9d417b5a1b5d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 13 Sep 2019 18:37:00 +0200 Subject: macOS: Keep default NSWindow background unless window is frameless The logic was changed in ee82f8661 to only draw a window background when the window was textured, and otherwise ask for a clear window background. This has an unfortunate side-effect on macOS 10.15 that the window's title bar will be partially transparent and reflect the content under the window, with a blur effect. It also inadvertently broke the use-case of setting the NSWindow background color explicitly. With this patch we're back to the behavior before ee82f8661, and users who still want to have a non-borderless window with a clear background can still do this by setting the background color to the clear color manually. Task-number: QTBUG-77637 Change-Id: I8a11bc46e6393b29a37f002ea123a987048106b9 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qnswindow.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 68cb270457..6b4e110af2 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -255,8 +255,8 @@ static bool isMouseEvent(NSEvent *ev) - (NSColor *)backgroundColor { - return self.styleMask & NSWindowStyleMaskTexturedBackground ? - [super backgroundColor] : [NSColor clearColor]; + return self.styleMask == NSWindowStyleMaskBorderless ? + [NSColor clearColor] : [super backgroundColor]; } - (void)sendEvent:(NSEvent*)theEvent -- cgit v1.2.3 From e2431b619da5c53d34df0b46105deb4450ed0c1f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 15 Sep 2019 19:49:32 +0200 Subject: QPSQL: Fix crash when a prepared statement is deleted after the db was removed When a prepared statement is still alive after the database was removed with QSqlDatabase::removeDatabase(), the cleanup routine is trying to access the driver which is no longer alive which results in a crash. Fix it by checking if the driver is still alive similar to 5f66486cc254e1483f776d3058f96db493fd26e5. Fixes: QTBUG-43889 Change-Id: Ib466a76d014e32c055d203bda15b075ad3dff3d9 Reviewed-by: Andy Shaw Reviewed-by: Jesus Fernandez --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 0bae45382d..28be7bdc38 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t) void QPSQLResultPrivate::deallocatePreparedStmt() { - const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; - PGresult *result = drv_d_func()->exec(stmt); + if (drv_d_func()) { + const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; + PGresult *result = drv_d_func()->exec(stmt); - if (PQresultStatus(result) != PGRES_COMMAND_OK) - qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); - PQclear(result); + if (PQresultStatus(result) != PGRES_COMMAND_OK) + qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); + PQclear(result); + } preparedStmtId.clear(); } -- cgit v1.2.3 From 72522517688d68a25a543a1da2497a4b8f6b424b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Sep 2019 09:43:21 +0200 Subject: Brush up the Windows styles - use range-based for loops where possible - use nullptr - use member initialization - remove a lot of C-style casts - use override - fix some signedness warnings - add some missing break statements Task-number: QTBUG-76493 Change-Id: Ica6ed65ec29e958406e54d816b8a679ed81bd177 Reviewed-by: Oliver Wolff --- src/plugins/styles/windowsvista/main.cpp | 4 +- .../styles/windowsvista/qwindowsvistastyle.cpp | 110 +++++++------- .../styles/windowsvista/qwindowsvistastyle_p_p.h | 2 +- .../styles/windowsvista/qwindowsxpstyle.cpp | 158 ++++++++++----------- .../styles/windowsvista/qwindowsxpstyle_p_p.h | 61 ++++---- 5 files changed, 165 insertions(+), 170 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/windowsvista/main.cpp b/src/plugins/styles/windowsvista/main.cpp index d5048e45b7..5e7bcf5e6e 100644 --- a/src/plugins/styles/windowsvista/main.cpp +++ b/src/plugins/styles/windowsvista/main.cpp @@ -48,7 +48,7 @@ class QWindowsVistaStylePlugin : public QStylePlugin Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json") public: - QStyle *create(const QString &key); + QStyle *create(const QString &key) override; }; QStyle *QWindowsVistaStylePlugin::create(const QString &key) @@ -56,7 +56,7 @@ QStyle *QWindowsVistaStylePlugin::create(const QString &key) if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0) return new QWindowsVistaStyle(); - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index feb2bc824b..e213d65946 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -91,7 +90,7 @@ bool QWindowsVistaStylePrivate::useVista() Checks and returns the style object */ inline QObject *styleObject(const QStyleOption *option) { - return option ? option->styleObject : 0; + return option ? option->styleObject : nullptr; } /* \internal @@ -116,7 +115,7 @@ static inline QImage createAnimationBuffer(const QStyleOption *option, const QWi Used by animations to clone a styleoption and shift its offset */ QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { - QStyleOption *styleOption = 0; + QStyleOption *styleOption = nullptr; if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) styleOption = new QStyleOptionSlider(*slider); else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) @@ -297,7 +296,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = oldState && @@ -315,7 +314,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (doTransition) { QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); @@ -340,7 +339,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt // The end state of the transition is simply the result we would have painted // if the style was not animated. - styleOption->styleObject = 0; + styleOption->styleObject = nullptr; styleOption->state = option->state; proxy()->drawPrimitive(element, styleOption, &endPainter, widget); @@ -355,7 +354,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt //translate state flags to UXTHEME states : if (element == PE_FrameLineEdit) { - theme = OpenThemeData(0, L"Edit"); + theme = OpenThemeData(nullptr, L"Edit"); partId = EP_EDITBORDER_NOSCROLL; if (oldState & State_MouseOver) @@ -373,7 +372,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt toState = ETS_NORMAL; } else { - theme = OpenThemeData(0, L"Button"); + theme = OpenThemeData(nullptr, L"Button"); if (element == PE_IndicatorRadioButton) partId = BP_RADIOBUTTON; else if (element == PE_IndicatorCheckBox) @@ -389,7 +388,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (theme && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState, TMT_TRANSITIONDURATIONS, &duration))) { - t->setDuration(duration); + t->setDuration(int(duration)); } t->setStartTime(QTime::currentTime()); @@ -534,7 +533,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt else if (state & State_MouseOver) stateId = EBS_HOT; - XPThemeData theme(0, painter, QWindowsXPStylePrivate::EditTheme, + XPThemeData theme(nullptr, painter, QWindowsXPStylePrivate::EditTheme, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(element, option, painter, widget); @@ -581,27 +580,26 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else { - int stateId = ETS_NORMAL; - if (!(state & State_Enabled)) - stateId = ETS_DISABLED; - else if (state & State_ReadOnly) - stateId = ETS_READONLY; - else if (state & State_MouseOver) - stateId = ETS_HOT; - else if (state & State_HasFocus) - stateId = ETS_SELECTED; - XPThemeData theme(widget, painter, - QWindowsXPStylePrivate::EditTheme, - EP_EDITBORDER_NOSCROLL, stateId, option->rect); - theme.noContent = true; - painter->save(); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - painter->setClipRegion(clipRegion); - d->drawBackground(theme); - painter->restore(); } + int stateId = ETS_NORMAL; + if (!(state & State_Enabled)) + stateId = ETS_DISABLED; + else if (state & State_ReadOnly) + stateId = ETS_READONLY; + else if (state & State_MouseOver) + stateId = ETS_HOT; + else if (state & State_HasFocus) + stateId = ETS_SELECTED; + XPThemeData theme(widget, painter, + QWindowsXPStylePrivate::EditTheme, + EP_EDITBORDER_NOSCROLL, stateId, option->rect); + theme.noContent = true; + painter->save(); + QRegion clipRegion = option->rect; + clipRegion -= option->rect.adjusted(2, 2, -2, -2); + painter->setClipRegion(clipRegion); + d->drawBackground(theme); + painter->restore(); } break; @@ -724,7 +722,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt d->drawBackground(theme); } else { QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget); - break;; + break; } QPixmapCache::insert(key, pixmap); } @@ -770,7 +768,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt case PE_Widget: { #if QT_CONFIG(dialogbuttonbox) - const QDialogButtonBox *buttonBox = 0; + const QDialogButtonBox *buttonBox = nullptr; if (qobject_cast (widget)) buttonBox = widget->findChild(QLatin1String("qt_msgbox_buttonbox")); @@ -844,7 +842,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool wasDefault = false; @@ -870,7 +868,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QImage startImage = createAnimationBuffer(option, widget); QPainter startPainter(&startImage); @@ -892,12 +890,12 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption DWORD duration = 0; - const HTHEME theme = OpenThemeData(0, L"Button"); + const HTHEME theme = OpenThemeData(nullptr, L"Button"); int fromState = buttonStateId(oldState, BP_PUSHBUTTON); int toState = buttonStateId(option->state, BP_PUSHBUTTON); if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK) - t->setDuration(duration); + t->setDuration(int(duration)); else t->setDuration(0); t->setStartTime(QTime::currentTime()); @@ -983,7 +981,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_DROPDOWNBUTTON); if (theme.isValid()) { const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option); @@ -992,7 +990,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption mbih = qRound(size.height()); } } - QRect ir = subElementRect(SE_PushButtonContents, option, 0); + QRect ir = subElementRect(SE_PushButtonContents, option, nullptr); QStyleOptionButton newBtn = *btn; newBtn.rect = QStyle::visualRect(option->direction, option->rect, QRect(ir.right() - mbiw - 2, @@ -1137,7 +1135,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText; QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), QIcon::Normal); - uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; + int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; @@ -1177,7 +1175,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int checkcol = qRound(qreal(25) * factor); const int gutterWidth = qRound(qreal(3) * factor); { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; themeSize.partId = MENU_POPUPCHECK; @@ -1394,7 +1392,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget); int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget); const QDockWidget *dw = qobject_cast(widget); - bool isFloating = dw != 0 && dw->isFloating(); + bool isFloating = dw && dw->isFloating(); QRect r = option->rect.adjusted(0, 2, -1, -3); QRect titleRect = r; @@ -1411,7 +1409,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -1517,8 +1515,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle int oldActiveControls = styleObject->property("_q_stylecontrols").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - styleObject->setProperty("_q_stylestate", (int)option->state); - styleObject->setProperty("_q_stylecontrols", (int)option->activeSubControls); + styleObject->setProperty("_q_stylestate", int(option->state)); + styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || @@ -1562,8 +1560,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // Draw transition source if (!anim) { - styleOption->state = (QStyle::State)oldState; - styleOption->activeSubControls = (QStyle::SubControl)oldActiveControls; + styleOption->state = QStyle::State(oldState); + styleOption->activeSubControls = QStyle::SubControl(oldActiveControls); proxy()->drawComplexControl(control, styleOption, &startPainter, widget); } else { anim->paint(&startPainter, option); @@ -1814,7 +1812,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // That however breaks with QtQuickControls where this results in transparent // spinbox background, so if there's no "widget" passed (QtQuickControls case), // let ftheme.noContent be false, which fixes the spinbox rendering in QQC - ftheme.noContent = (widget != NULL); + ftheme.noContent = (widget != nullptr); d->drawBackground(ftheme); } if (sub & SC_SpinBoxUp) { @@ -1871,7 +1869,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget); int minimumHeight; { - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; @@ -1939,7 +1937,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; - const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"Button"); + const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"Button"); if (theme) { int stateId = PBS_NORMAL; if (!(option->state & State_Enabled)) @@ -1954,7 +1952,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1972,7 +1970,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int y = option->rect.y(); int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, option, widget); - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::HeaderTheme, HP_HEADERSORTARROW, HSAS_SORTEDDOWN, option->rect); @@ -2045,7 +2043,7 @@ static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBa bool isMinimized = tb->titleBarState & Qt::WindowMinimized; bool isMaximized = tb->titleBarState & Qt::WindowMaximized; - const uint flags = tb->titleBarFlags; + const auto flags = tb->titleBarFlags; bool retVal = false; switch (sc) { case QStyle::SC_TitleBarContextHelpButton: @@ -2103,7 +2101,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co if (option) { if (QStyleHintReturnMask *mask = qstyleoption_cast(returnData)) { ret = true; - XPThemeData themeData(widget, 0, + XPThemeData themeData(widget, nullptr, QWindowsXPStylePrivate::ToolTipTheme, TTP_STANDARD, TTSS_NORMAL, option->rect); mask->region = d->region(themeData); @@ -2112,7 +2110,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co break; case SH_Table_GridLineColor: if (option) - ret = option->palette.color(QPalette::Base).darker(118).rgb(); + ret = int(option->palette.color(QPalette::Base).darker(118).rgb()); else ret = -1; break; @@ -2323,7 +2321,7 @@ void QWindowsVistaStyle::polish(QWidget *widget) //we do not have to care about unpolishing widget->setContentsMargins(3, 0, 4, 0); COLORREF bgRef; - HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"TOOLTIP"); + HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"TOOLTIP"); if (theme && SUCCEEDED(GetThemeColor(theme, TTP_STANDARD, TTSS_NORMAL, TMT_TEXTCOLOR, &bgRef))) { QColor textColor = QColor::fromRgb(bgRef); QPalette pal; @@ -2463,7 +2461,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon, switch(standardIcon) { case SP_CommandLink: { - XPThemeData theme(0, 0, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_COMMANDLINKGLYPH, CMDLGS_NORMAL); if (theme.isValid()) { diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index d66b17e9f8..8fef9f9927 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -162,7 +162,7 @@ class QWindowsVistaAnimation : public QBlendStyleAnimation public: QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { } - virtual bool isUpdateNeeded() const; + bool isUpdateNeeded() const override; void paint(QPainter *painter, const QStyleOption *option); }; diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index e2c5bdc924..bf80138b32 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -117,7 +117,7 @@ static inline QBackingStore *backingStoreForWidget(const QWidget *widget) if (const QWidget *topLevel = widget->nativeParentWidget()) if (QBackingStore *topLevelBackingStore = topLevel->backingStore()) return topLevelBackingStore; - return 0; + return nullptr; } static inline HDC hdcForWidgetBackingStore(const QWidget *widget) @@ -127,7 +127,7 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget) if (nativeInterface) return static_cast(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); } - return 0; + return nullptr; } // Theme data helper ------------------------------------------------------------------------------ @@ -148,7 +148,7 @@ bool XPThemeData::isValid() HTHEME XPThemeData::handle() { if (!QWindowsXPStylePrivate::useXP()) - return 0; + return nullptr; if (!htheme) htheme = QWindowsXPStylePrivate::createTheme(theme, QWindowsXPStylePrivate::winId(widget)); @@ -175,10 +175,10 @@ RECT XPThemeData::toRECT(const QRect &qr) HRGN XPThemeData::mask(QWidget *widget) { if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId)) - return 0; + return nullptr; HRGN hrgn; - HDC dc = 0; + HDC dc = nullptr; if (widget) dc = hdcForWidgetBackingStore(widget); RECT nativeRect = toRECT(rect); @@ -188,7 +188,7 @@ HRGN XPThemeData::mask(QWidget *widget) // QWindowsXPStylePrivate ------------------------------------------------------------------------- // Static initializations -HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0; +HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = nullptr; HTHEME QWindowsXPStylePrivate::m_themes[NThemes]; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting @@ -227,7 +227,7 @@ bool QWindowsXPStylePrivate::useXP(bool update) { if (!update) return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QApplication::instance()); + return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); } /* \internal @@ -241,7 +241,7 @@ void QWindowsXPStylePrivate::init(bool force) ref.ref(); useXP(true); - std::fill(m_themes, m_themes + NThemes, HTHEME(0)); + std::fill(m_themes, m_themes + NThemes, nullptr); } /* \internal @@ -253,12 +253,12 @@ void QWindowsXPStylePrivate::cleanup(bool force) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } if(bufferDC) DeleteDC(bufferDC); - bufferDC = 0; + bufferDC = nullptr; if (ref.deref() && !force) return; @@ -282,7 +282,7 @@ void QWindowsXPStylePrivate::cleanup(bool force) static inline HWND createTreeViewHelperWindow() { if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = 0; + void *hwnd = nullptr; void *wndProc = reinterpret_cast(DefWindowProc); if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, Q_RETURN_ARG(void*, hwnd), @@ -292,7 +292,7 @@ static inline HWND createTreeViewHelperWindow() return reinterpret_cast(hwnd); } } - return 0; + return nullptr; } bool QWindowsXPStylePrivate::initVistaTreeViewTheming() @@ -305,7 +305,7 @@ bool QWindowsXPStylePrivate::initVistaTreeViewTheming() qWarning("Unable to create the treeview helper window."); return false; } - if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) { + if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", nullptr))) { qErrnoWarning("SetWindowTheme() failed."); cleanupVistaTreeViewTheming(); return false; @@ -317,7 +317,7 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() { if (m_vistaTreeViewHelper) { DestroyWindow(m_vistaTreeViewHelper); - m_vistaTreeViewHelper = 0; + m_vistaTreeViewHelper = nullptr; } } @@ -328,11 +328,12 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() */ void QWindowsXPStylePrivate::cleanupHandleMap() { - for (int i = 0; i < NThemes; ++i) - if (m_themes[i]) { - CloseThemeData(m_themes[i]); - m_themes[i] = 0; + for (auto &theme : m_themes) { + if (theme) { + CloseThemeData(theme); + theme = nullptr; } + } QWindowsXPStylePrivate::cleanupVistaTreeViewTheming(); } @@ -340,7 +341,7 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) { if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) { qWarning("Invalid parameters #%d, %p", theme, hwnd); - return 0; + return nullptr; } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; @@ -427,16 +428,16 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } w = qMax(bufferW, w); h = qMax(bufferH, h); if (!bufferDC) { - HDC displayDC = GetDC(0); + HDC displayDC = GetDC(nullptr); bufferDC = CreateCompatibleDC(displayDC); - ReleaseDC(0, displayDC); + ReleaseDC(nullptr, displayDC); } // Define the header @@ -450,22 +451,22 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) bmi.bmiHeader.biCompression = BI_RGB; // Create the pixmap - bufferPixels = 0; - bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0); + bufferPixels = nullptr; + bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, reinterpret_cast(&bufferPixels), nullptr, 0); GdiFlush(); - nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); + nullBitmap = static_cast(SelectObject(bufferDC, bufferBitmap)); if (Q_UNLIKELY(!bufferBitmap)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } if (Q_UNLIKELY(!bufferPixels)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } bufferW = w; bufferH = h; @@ -493,7 +494,7 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData) */ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) { - HRGN hRgn = 0; + HRGN hRgn = nullptr; const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget); RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor)); if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId, @@ -502,12 +503,12 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) } HRGN dest = CreateRectRgn(0, 0, 0, 0); - const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR; + const bool success = CombineRgn(dest, hRgn, nullptr, RGN_COPY) != ERROR; QRegion region; if (success) { - int numBytes = GetRegionData(dest, 0, 0); + const auto numBytes = GetRegionData(dest, 0, nullptr); if (numBytes == 0) return QRegion(); @@ -551,7 +552,7 @@ bool QWindowsXPStylePrivate::hasAlphaChannel(const QRect &rect) int firstAlpha = -1; for (int y = startY; y < h/2; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { int alpha = (*buffer) >> 24; if (firstAlpha == -1) @@ -580,7 +581,7 @@ bool QWindowsXPStylePrivate::fixAlphaChannel(const QRect &rect) bool hasFixedAlphaValue = false; for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { uint pixel = *buffer; int alpha = qAlpha(pixel); @@ -612,7 +613,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels) // Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255. for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { if (allPixels) { *buffer |= 0xFF000000; @@ -668,7 +669,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) return true; QPainter *painter = themeData.painter; - Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); + Q_ASSERT_X(painter != nullptr, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); if (!painter || !painter->isActive()) return false; @@ -706,7 +707,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) } } - const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0); + const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr; const bool result = dc ? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio) : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio); @@ -740,7 +741,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa { QPainter *painter = themeData.painter; - const auto deviceTransform = painter->deviceTransform(); + const auto &deviceTransform = painter->deviceTransform(); const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy()); const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect(); @@ -771,7 +772,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0); const HRESULT result = DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions); - SelectClipRgn(dc, 0); + SelectClipRgn(dc, nullptr); DeleteObject(hrgn); return SUCCEEDED(result); } @@ -1099,9 +1100,7 @@ QWindowsXPStyle::QWindowsXPStyle() /*! Destroys the style. */ -QWindowsXPStyle::~QWindowsXPStyle() -{ -} +QWindowsXPStyle::~QWindowsXPStyle() = default; /*! \reimp */ void QWindowsXPStyle::unpolish(QApplication *app) @@ -1157,7 +1156,7 @@ void QWindowsXPStyle::polish(QWidget *widget) if (!d->hasInitColors) { // Get text color for group box labels COLORREF cref; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, 0, 0); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, 0, 0); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref); d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref); @@ -1270,7 +1269,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; if (widget) { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme); HTHEME theme = buttontheme.handle(); if (theme) { int stateId; @@ -1288,7 +1287,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1468,7 +1467,7 @@ case PE_Frame: return; themeNumber = QWindowsXPStylePrivate::ListViewTheme; partId = LVP_LISTGROUP; - XPThemeData theme(widget, 0, themeNumber, partId, 0); + XPThemeData theme(widget, nullptr, themeNumber, partId); if (!(flags & State_Enabled)) stateId = ETS_DISABLED; @@ -1496,9 +1495,9 @@ case PE_Frame: p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment)); p->setPen(oldPen); return; - } else if (fillType == BT_NONE) { - return; } + if (fillType == BT_NONE) + return; } break; } @@ -1514,7 +1513,8 @@ case PE_Frame: p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else if (qstyleoption_cast(option)) { + } + if (qstyleoption_cast(option)) { themeNumber = QWindowsXPStylePrivate::EditTheme; partId = EP_EDITTEXT; noContent = true; @@ -1538,7 +1538,7 @@ case PE_Frame: if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) { p->fillRect(panel->rect, panel->palette.brush(QPalette::Base)); } else { - XPThemeData theme(0, p, themeNumber, partId, stateId, rect); + XPThemeData theme(nullptr, p, themeNumber, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(pe, option, p, widget); return; @@ -1587,9 +1587,9 @@ case PE_Frame: wchar_t themeFileName[maxlength]; wchar_t themeColor[maxlength]; // Due to a a scaling issue with the XP Silver theme, tab gradients are not used with it - if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, NULL, 0) == S_OK) { - wchar_t *offset = 0; - if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != NULL) { + if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, nullptr, 0) == S_OK) { + wchar_t *offset = nullptr; + if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != nullptr) { offset++; if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic")) { useGradient = false; @@ -1820,7 +1820,7 @@ case PE_Frame: bef_v -= delta; aft_h += delta; aft_v += delta; - XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme); + XPThemeData theme(nullptr, p, QWindowsXPStylePrivate::XpTreeViewTheme); theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size); theme.partId = TVP_GLYPH; theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED; @@ -1912,7 +1912,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op { themeNumber = QWindowsXPStylePrivate::StatusTheme; partId = SP_GRIPPER; - XPThemeData theme(0, p, themeNumber, partId, 0); + XPThemeData theme(nullptr, p, themeNumber, partId); QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); size.rheight()--; if (const QStyleOptionSizeGrip *sg = qstyleoption_cast(option)) { @@ -1980,7 +1980,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_SPLITBUTTONDROPDOWN); if (theme.isValid()) { @@ -2309,7 +2309,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget != nullptr && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -2775,7 +2775,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo break; v = nextInterval; } - if (lines.size() > 0) { + if (!lines.isEmpty()) { p->save(); p->translate(slrect.topLeft()); p->drawLines(lines.constData(), lines.size()); @@ -2923,7 +2923,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo p->save(); p->setClipRect(menuarea); tool.rect = option->rect; - proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0); + proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, nullptr); p->restore(); } // Draw arrow @@ -3223,7 +3223,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } } -static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = 0) +static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) { if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) return pb->orientation; @@ -3234,27 +3234,27 @@ int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, cons { switch (pm) { case QStyle::PM_IndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); case QStyle::PM_IndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ExclusiveIndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); case QStyle::PM_ExclusiveIndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ProgressBarChunkWidth: return progressBarOrientation(option) == Qt::Horizontal - ? XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() - : XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); + ? XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() + : XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); case QStyle::PM_SliderThickness: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); case QStyle::PM_TitleBarHeight: return widget && (widget->windowType() == Qt::Tool) ? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME) : GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME); case QStyle::PM_MdiSubWindowFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); case QStyle::PM_DockWidgetFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); default: break; } @@ -3620,7 +3620,7 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt case CT_LineEdit: case CT_ComboBox: { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { const qreal factor = QWindowsXPStylePrivate::nativeMetricScaleFactor(widget); const QMarginsF borderSize = buttontheme.margins() * factor; @@ -3741,11 +3741,11 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const titleBarRect.setHeight(tbHeight); XPThemeData themeData; if (titlebar->titleBarState & Qt::WindowMinimized) { - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MINCAPTION, CS_ACTIVE, titleBarRect); } else - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_CAPTION, CS_ACTIVE, titleBarRect); mask->region = d->region(themeData) + @@ -3774,10 +3774,8 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const /*! \reimp */ QPalette QWindowsXPStyle::standardPalette() const { - if (QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal) - return *QApplicationPrivate::sys_pal; - else - return QWindowsStyle::standardPalette(); + return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal + ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette(); } /*! @@ -3795,7 +3793,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt if (qstyleoption_cast(option)) { if (widget && widget->isWindow()) { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size); @@ -3826,9 +3824,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MAXBUTTON, MAXBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3862,7 +3860,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockClose.isNull()) { - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3896,9 +3894,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_RESTOREBUTTON, RBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h index 60f9d7e9b7..ad7754e3d4 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h @@ -100,11 +100,11 @@ class QDebug; class XPThemeData { public: - explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, const QRect &r = QRect()) - : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), + : widget(w), painter(p), theme(themeIn), partId(part), stateId(state), mirrorHorizontally(false), mirrorVertically(false), noBorder(false), - noContent(false), rotate(0), rect(r) + noContent(false), rect(r) {} HRGN mask(QWidget *widget); @@ -117,17 +117,17 @@ public: QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS); QMarginsF margins(int propId = TMT_CONTENTMARGINS); - static QSizeF themeSize(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, int part = 0, int state = 0); - static QMarginsF themeMargins(const QRect &rect, const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0); + static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); - static QMarginsF themeMargins(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); const QWidget *widget; QPainter *painter; int theme; - HTHEME htheme; + HTHEME htheme = nullptr; int partId; int stateId; @@ -135,18 +135,18 @@ public: uint mirrorVertically : 1; uint noBorder : 1; uint noContent : 1; - uint rotate; + uint rotate = 0; QRect rect; }; struct ThemeMapKey { - int theme; - int partId; - int stateId; - bool noBorder; - bool noContent; + int theme = 0; + int partId = -1; + int stateId = -1; + bool noBorder = false; + bool noContent = false; - ThemeMapKey() : partId(-1), stateId(-1) {} + ThemeMapKey() = default; ThemeMapKey(const XPThemeData &data) : theme(data.theme), partId(data.partId), stateId(data.stateId), noBorder(data.noBorder), noContent(data.noContent) {} @@ -171,7 +171,7 @@ enum AlphaChannelType { }; struct ThemeMapData { - AlphaChannelType alphaType; // Which type of alpha on part & state + AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state bool dataValid : 1; // Only used to detect if hash value is ok bool partIsTransparent : 1; @@ -217,15 +217,13 @@ public: }; QWindowsXPStylePrivate() - : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), - bufferPixels(0), bufferW(0), bufferH(0) { init(); } ~QWindowsXPStylePrivate() { cleanup(); } - static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); - static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); + static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); + static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); static HWND winId(const QWidget *widget); @@ -251,10 +249,10 @@ public: bool fixAlphaChannel(const QRect &rect); bool swapAlphaChannel(const QRect &rect, bool allPixels = false); - QRgb groupBoxTextColor; - QRgb groupBoxTextColorDisabled; - QRgb sliderTickColor; - bool hasInitColors; + QRgb groupBoxTextColor = 0; + QRgb groupBoxTextColorDisabled = 0; + QRgb sliderTickColor = 0; + bool hasInitColors = false; static HTHEME createTheme(int theme, HWND hwnd); static QString themeName(int theme); @@ -277,11 +275,12 @@ private: static bool use_xp; QHash alphaCache; - HDC bufferDC; - HBITMAP bufferBitmap; - HBITMAP nullBitmap; - uchar *bufferPixels; - int bufferW, bufferH; + HDC bufferDC = nullptr; + HBITMAP bufferBitmap = nullptr; + HBITMAP nullBitmap = nullptr; + uchar *bufferPixels = nullptr; + int bufferW = 0; + int bufferH = 0; static HWND m_vistaTreeViewHelper; static HTHEME m_themes[NThemes]; @@ -292,7 +291,7 @@ inline QSizeF XPThemeData::size() QSizeF result(0, 0); if (isValid()) { SIZE size; - if (SUCCEEDED(GetThemePartSize(handle(), 0, partId, stateId, 0, TS_TRUE, &size))) + if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size))) result = QSize(size.cx, size.cy); } return result; @@ -304,7 +303,7 @@ inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId) if (isValid()) { MARGINS margins; RECT rect = XPThemeData::toRECT(qRect); - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, &rect, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; @@ -315,7 +314,7 @@ inline QMarginsF XPThemeData::margins(int propId) QMarginsF result(0, 0, 0 ,0); if (isValid()) { MARGINS margins; - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, NULL, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; -- cgit v1.2.3