diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-05-13 09:12:19 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-05-17 14:34:45 +0000 |
commit | af6b700bb8b8e73406e07d0544300706dd1e6f41 (patch) | |
tree | 340875987663795f99cedad72047aca3947b4ff8 /src/widgets/dialogs/qwizard_win.cpp | |
parent | 3eb3007e9c75eea81a2b20749dc61ca31c9bc699 (diff) | |
download | qtbase-af6b700bb8b8e73406e07d0544300706dd1e6f41.tar.gz |
QtWidgets: Increase Windows API level to 0x600 (Windows Vista).
Define WINVER, _WIN32_WINNT for MinGW in win.pri. Directly link to uxtheme and
dwmapi and remove dynamic loading of functions that are present in Windows
Vista onwards.
Remove duplicated declarations of constants that are now present in the SDKs.
Task-number: QTBUG-51673
Change-Id: I695a6673d7250b2788fd2f20aebd222fcabb0d47
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qwizard_win.cpp')
-rw-r--r-- | src/widgets/dialogs/qwizard_win.cpp | 252 |
1 files changed, 44 insertions, 208 deletions
diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 8bc5ba7f56..9d8e7c4b66 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -41,7 +41,6 @@ #ifndef QT_NO_STYLE_WINDOWSVISTA #include "qwizard_win_p.h" -#include <private/qsystemlibrary_p.h> #include <private/qapplication_p.h> #include <qpa/qplatformnativeinterface.h> #include "qwizard.h" @@ -54,112 +53,19 @@ #include <QtWidgets/QDesktopWidget> #include <uxtheme.h> +#include <vssym32.h> +#include <dwmapi.h> Q_DECLARE_METATYPE(QMargins) -QT_BEGIN_NAMESPACE +#ifndef WM_DWMCOMPOSITIONCHANGED +# define WM_DWMCOMPOSITIONCHANGED 0x031E +#endif -//DWM related -typedef struct { //MARGINS - int cxLeftWidth; // width of left border that retains its size - int cxRightWidth; // width of right border that retains its size - int cyTopHeight; // height of top border that retains its size - int cyBottomHeight; // height of bottom border that retains its size -} WIZ_MARGINS; -typedef struct { //DTTOPTS - DWORD dwSize; - DWORD dwFlags; - COLORREF crText; - COLORREF crBorder; - COLORREF crShadow; - int eTextShadowType; - POINT ptShadowOffset; - int iBorderSize; - int iFontPropId; - int iColorPropId; - int iStateId; - BOOL fApplyOverlay; - int iGlowSize; -} WIZ_DTTOPTS; - -typedef struct { - DWORD dwFlags; - DWORD dwMask; -} WIZ_WTA_OPTIONS; - -#define WIZ_WM_THEMECHANGED 0x031A -#define WIZ_WM_DWMCOMPOSITIONCHANGED 0x031E - -enum WIZ_WINDOWTHEMEATTRIBUTETYPE { - WIZ_WTA_NONCLIENT = 1 -}; - -#define WIZ_WTNCA_NODRAWCAPTION 0x00000001 -#define WIZ_WTNCA_NODRAWICON 0x00000002 - -#define WIZ_DT_CENTER 0x00000001 //DT_CENTER -#define WIZ_DT_VCENTER 0x00000004 -#define WIZ_DT_SINGLELINE 0x00000020 -#define WIZ_DT_NOPREFIX 0x00000800 - -enum WIZ_NAVIGATIONPARTS { //NAVIGATIONPARTS - WIZ_NAV_BACKBUTTON = 1, - WIZ_NAV_FORWARDBUTTON = 2, - WIZ_NAV_MENUBUTTON = 3, -}; - -enum WIZ_NAV_BACKBUTTONSTATES { //NAV_BACKBUTTONSTATES - WIZ_NAV_BB_NORMAL = 1, - WIZ_NAV_BB_HOT = 2, - WIZ_NAV_BB_PRESSED = 3, - WIZ_NAV_BB_DISABLED = 4, -}; - -#define WIZ_TMT_CAPTIONFONT (801) //TMT_CAPTIONFONT -#define WIZ_DTT_COMPOSITED (1UL << 13) //DTT_COMPOSITED -#define WIZ_DTT_GLOWSIZE (1UL << 11) //DTT_GLOWSIZE - -#define WIZ_WM_NCMOUSELEAVE 674 //WM_NCMOUSELEAVE - -#define WIZ_WP_CAPTION 1 //WP_CAPTION -#define WIZ_CS_ACTIVE 1 //CS_ACTIVE -#define WIZ_TMT_FILLCOLORHINT 3821 //TMT_FILLCOLORHINT -#define WIZ_TMT_BORDERCOLORHINT 3822 //TMT_BORDERCOLORHINT - -typedef BOOL (WINAPI *PtrDwmDefWindowProc)(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult); -typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled); -typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const WIZ_MARGINS* pMarInset); -typedef HRESULT (WINAPI *PtrSetWindowThemeAttribute)(HWND hwnd, enum WIZ_WINDOWTHEMEATTRIBUTETYPE eAttribute, PVOID pvAttribute, DWORD cbAttribute); - -static PtrDwmDefWindowProc pDwmDefWindowProc = 0; -static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled = 0; -static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea = 0; -static PtrSetWindowThemeAttribute pSetWindowThemeAttribute = 0; - -//Theme related -typedef bool (WINAPI *PtrIsAppThemed)(); -typedef bool (WINAPI *PtrIsThemeActive)(); -typedef HANDLE (WINAPI *PtrOpenThemeData)(HWND hwnd, LPCWSTR pszClassList); -typedef HRESULT (WINAPI *PtrCloseThemeData)(HANDLE hTheme); -typedef HRESULT (WINAPI *PtrGetThemeSysFont)(HANDLE hTheme, int iFontId, LOGFONTW *plf); -typedef HRESULT (WINAPI *PtrDrawThemeTextEx)(HANDLE hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, LPRECT pRect, const WIZ_DTTOPTS *pOptions); -typedef HRESULT (WINAPI *PtrDrawThemeBackground)(HANDLE hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect); -typedef HRESULT (WINAPI *PtrGetThemePartSize)(HANDLE hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz); -typedef HRESULT (WINAPI *PtrGetThemeColor)(HANDLE hTheme, int iPartId, int iStateId, int iPropId, OUT COLORREF *pColor); - -static PtrIsAppThemed pIsAppThemed = 0; -static PtrIsThemeActive pIsThemeActive = 0; -static PtrOpenThemeData pOpenThemeData = 0; -static PtrCloseThemeData pCloseThemeData = 0; -static PtrGetThemeSysFont pGetThemeSysFont = 0; -static PtrDrawThemeTextEx pDrawThemeTextEx = 0; -static PtrDrawThemeBackground pDrawThemeBackground = 0; -static PtrGetThemePartSize pGetThemePartSize = 0; -static PtrGetThemeColor pGetThemeColor = 0; +QT_BEGIN_NAMESPACE int QVistaHelper::instanceCount = 0; int QVistaHelper::m_devicePixelRatio = 1; -bool QVistaHelper::is_vista = false; QVistaHelper::VistaState QVistaHelper::cachedVistaState = QVistaHelper::Dirty; /****************************************************************************** @@ -179,14 +85,6 @@ QSize QVistaBackButton::sizeHint() const ensurePolished(); int size = int(QStyleHelper::dpiScaled(32)); int width = size, height = size; -/* - HANDLE theme = pOpenThemeData(0, L"Navigation"); - SIZE size; - if (pGetThemePartSize(theme, 0, WIZ_NAV_BACKBUTTON, WIZ_NAV_BB_NORMAL, 0, TS_TRUE, &size) == S_OK) { - width = size.cx; - height = size.cy; - } -*/ return QSize(width, height); } @@ -208,7 +106,7 @@ void QVistaBackButton::paintEvent(QPaintEvent *) { QPainter p(this); QRect r = rect(); - HANDLE theme = pOpenThemeData(0, L"Navigation"); + const HANDLE theme = OpenThemeData(0, L"Navigation"); //RECT rect; QPoint origin; const HDC hdc = QVistaHelper::backingStoreDC(parentWidget(), &origin); @@ -225,19 +123,17 @@ void QVistaBackButton::paintEvent(QPaintEvent *) clipRect.left = rDp.left() + xoffsetDp; clipRect.right = rDp.right() + xoffsetDp; - int state = WIZ_NAV_BB_NORMAL; + int state = NAV_BB_NORMAL; if (!isEnabled()) - state = WIZ_NAV_BB_DISABLED; + state = NAV_BB_DISABLED; else if (isDown()) - state = WIZ_NAV_BB_PRESSED; + state = NAV_BB_PRESSED; else if (underMouse()) - state = WIZ_NAV_BB_HOT; - - WIZ_NAVIGATIONPARTS buttonType = (layoutDirection() == Qt::LeftToRight - ? WIZ_NAV_BACKBUTTON - : WIZ_NAV_FORWARDBUTTON); + state = NAV_BB_HOT; - pDrawThemeBackground(theme, hdc, buttonType, state, &clipRect, &clipRect); + DrawThemeBackground(theme, hdc, + layoutDirection() == Qt::LeftToRight ? NAV_BACKBUTTON : NAV_FORWARDBUTTON, + state, &clipRect, &clipRect); } /****************************************************************************** @@ -251,13 +147,10 @@ QVistaHelper::QVistaHelper(QWizard *wizard) , backButton_(0) { QVistaHelper::m_devicePixelRatio = wizard->devicePixelRatio(); - is_vista = resolveSymbols(); if (instanceCount++ == 0) cachedVistaState = Dirty; - if (is_vista) { - backButton_ = new QVistaBackButton(wizard); - backButton_->hide(); - } + backButton_ = new QVistaBackButton(wizard); + backButton_->hide(); // Handle diff between Windows 7 and Vista iconSpacing = QStyleHelper::dpiScaled(7); @@ -292,20 +185,13 @@ void QVistaHelper::updateCustomMargins(bool vistaMargins) bool QVistaHelper::isCompositionEnabled() { - bool value = is_vista; - if (is_vista) { - HRESULT hr; - BOOL bEnabled; - - hr = pDwmIsCompositionEnabled(&bEnabled); - value = (SUCCEEDED(hr) && bEnabled); - } - return value; + BOOL bEnabled; + return SUCCEEDED(DwmIsCompositionEnabled(&bEnabled)) && bEnabled; } bool QVistaHelper::isThemeActive() { - return is_vista && pIsThemeActive(); + return IsThemeActive(); } QVistaHelper::VistaState QVistaHelper::vistaState() @@ -326,11 +212,9 @@ QColor QVistaHelper::basicWindowFrameColor() { DWORD rgb; HWND handle = QApplicationPrivate::getHWNDForWidget(QApplication::desktop()); - HANDLE hTheme = pOpenThemeData(handle, L"WINDOW"); - pGetThemeColor( - hTheme, WIZ_WP_CAPTION, WIZ_CS_ACTIVE, - wizard->isActiveWindow() ? WIZ_TMT_FILLCOLORHINT : WIZ_TMT_BORDERCOLORHINT, - &rgb); + const HANDLE hTheme = OpenThemeData(handle, L"WINDOW"); + GetThemeColor(hTheme, WP_CAPTION, CS_ACTIVE, + wizard->isActiveWindow() ? TMT_FILLCOLORHINT : TMT_BORDERCOLORHINT, &rgb); BYTE r = GetRValue(rgb); BYTE g = GetGValue(rgb); BYTE b = GetBValue(rgb); @@ -341,13 +225,13 @@ bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type) { bool value = false; if (vistaState() == VistaAero) { - WIZ_MARGINS mar = {0, 0, 0, 0}; + MARGINS mar = {0, 0, 0, 0}; if (type == NormalTitleBar) mar.cyTopHeight = 0; else mar.cyTopHeight = (titleBarSize() + topOffset()) * QVistaHelper::m_devicePixelRatio; if (const HWND wizardHandle = wizardHWND()) - if (SUCCEEDED(pDwmExtendFrameIntoClientArea(wizardHandle, &mar))) + if (SUCCEEDED(DwmExtendFrameIntoClientArea(wizardHandle, &mar))) value = true; } return value; @@ -359,7 +243,7 @@ static LOGFONT getCaptionLogFont(HANDLE hTheme) { LOGFONT result = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }; - if (!hTheme || FAILED(pGetThemeSysFont(hTheme, WIZ_TMT_CAPTIONFONT, &result))) { + if (!hTheme || FAILED(GetThemeSysFont(hTheme, TMT_CAPTIONFONT, &result))) { NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, false); @@ -370,10 +254,8 @@ static LOGFONT getCaptionLogFont(HANDLE hTheme) static bool getCaptionQFont(int dpi, QFont *result) { - if (!pOpenThemeData) - return false; const HANDLE hTheme = - pOpenThemeData(QApplicationPrivate::getHWNDForWidget(QApplication::desktop()), L"WINDOW"); + OpenThemeData(QApplicationPrivate::getHWNDForWidget(QApplication::desktop()), L"WINDOW"); if (!hTheme) return false; // Call into QWindowsNativeInterface to convert the LOGFONT into a QFont. @@ -448,16 +330,14 @@ void QVistaHelper::drawTitleBar(QPainter *painter) void QVistaHelper::setTitleBarIconAndCaptionVisible(bool visible) { - if (is_vista) { - WIZ_WTA_OPTIONS opt; - opt.dwFlags = WIZ_WTNCA_NODRAWICON | WIZ_WTNCA_NODRAWCAPTION; - if (visible) - opt.dwMask = 0; - else - opt.dwMask = WIZ_WTNCA_NODRAWICON | WIZ_WTNCA_NODRAWCAPTION; - if (const HWND handle = wizardHWND()) - pSetWindowThemeAttribute(handle, WIZ_WTA_NONCLIENT, &opt, sizeof(WIZ_WTA_OPTIONS)); - } + WTA_OPTIONS opt; + opt.dwFlags = WTNCA_NODRAWICON | WTNCA_NODRAWCAPTION; + if (visible) + opt.dwMask = 0; + else + opt.dwMask = WTNCA_NODRAWICON | WTNCA_NODRAWCAPTION; + if (const HWND handle = wizardHWND()) + SetWindowThemeAttribute(handle, WTA_NONCLIENT, &opt, sizeof(WTA_OPTIONS)); } bool QVistaHelper::winEvent(MSG* msg, long* result) @@ -466,7 +346,7 @@ bool QVistaHelper::winEvent(MSG* msg, long* result) case WM_NCHITTEST: { LRESULT lResult; // Perform hit testing using DWM - if (pDwmDefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam, &lResult)) { + if (DwmDefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam, &lResult)) { // DWM returned a hit, no further processing necessary *result = lResult; } else { @@ -485,7 +365,7 @@ bool QVistaHelper::winEvent(MSG* msg, long* result) default: LRESULT lResult; // Pass to DWM to handle - if (pDwmDefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam, &lResult)) + if (DwmDefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam, &lResult)) *result = lResult; // If the message wasn't handled by DWM, continue processing it as normal else @@ -524,7 +404,7 @@ void QVistaHelper::mouseEvent(QEvent *event) bool QVistaHelper::handleWinEvent(MSG *message, long *result) { - if (message->message == WIZ_WM_THEMECHANGED || message->message == WIZ_WM_DWMCOMPOSITIONCHANGED) + if (message->message == WM_THEMECHANGED || message->message == WM_DWMCOMPOSITIONCHANGED) cachedVistaState = Dirty; bool status = false; @@ -707,7 +587,7 @@ bool QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const Q const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, rect.size() * QVistaHelper::m_devicePixelRatio); HWND handle = QApplicationPrivate::getHWNDForWidget(QApplication::desktop()); - HANDLE hTheme = pOpenThemeData(handle, L"WINDOW"); + const HANDLE hTheme = OpenThemeData(handle, L"WINDOW"); if (!hTheme) return false; // Set up a memory DC and bitmap that we'll draw into HDC dcMem; @@ -732,15 +612,16 @@ bool QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const Q HFONT hOldFont = (HFONT)SelectObject(dcMem, (HGDIOBJ) hCaptionFont); // Draw the text! - WIZ_DTTOPTS dto; - dto.dwSize = sizeof(WIZ_DTTOPTS); - const UINT uFormat = WIZ_DT_SINGLELINE|WIZ_DT_CENTER|WIZ_DT_VCENTER|WIZ_DT_NOPREFIX; + DTTOPTS dto; + memset(&dto, 0, sizeof(dto)); + dto.dwSize = sizeof(dto); + const UINT uFormat = DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX; RECT rctext ={0,0, rectDp.width(), rectDp.height()}; - dto.dwFlags = WIZ_DTT_COMPOSITED|WIZ_DTT_GLOWSIZE; + dto.dwFlags = DTT_COMPOSITED|DTT_GLOWSIZE; dto.iGlowSize = glowSize(); - pDrawThemeTextEx(hTheme, dcMem, 0, 0, (LPCWSTR)text.utf16(), -1, uFormat, &rctext, &dto ); + DrawThemeTextEx(hTheme, dcMem, 0, 0, reinterpret_cast<LPCWSTR>(text.utf16()), -1, uFormat, &rctext, &dto ); BitBlt(hdc, rectDp.left(), rectDp.top(), rectDp.width(), rectDp.height(), dcMem, 0, 0, SRCCOPY); SelectObject(dcMem, (HGDIOBJ) hOldBmp); SelectObject(dcMem, (HGDIOBJ) hOldFont); @@ -813,51 +694,6 @@ int QVistaHelper::captionSizeDp() return GetSystemMetrics(SM_CYCAPTION); } -bool QVistaHelper::resolveSymbols() -{ - static bool tried = false; - if (!tried) { - tried = true; - QSystemLibrary dwmLib(L"dwmapi"); - pDwmIsCompositionEnabled = - (PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); - if (pDwmIsCompositionEnabled) { - pDwmDefWindowProc = (PtrDwmDefWindowProc)dwmLib.resolve("DwmDefWindowProc"); - pDwmExtendFrameIntoClientArea = - (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); - } - QSystemLibrary themeLib(L"uxtheme"); - pIsAppThemed = (PtrIsAppThemed)themeLib.resolve("IsAppThemed"); - if (pIsAppThemed) { - pDrawThemeBackground = (PtrDrawThemeBackground)themeLib.resolve("DrawThemeBackground"); - pGetThemePartSize = (PtrGetThemePartSize)themeLib.resolve("GetThemePartSize"); - pGetThemeColor = (PtrGetThemeColor)themeLib.resolve("GetThemeColor"); - pIsThemeActive = (PtrIsThemeActive)themeLib.resolve("IsThemeActive"); - pOpenThemeData = (PtrOpenThemeData)themeLib.resolve("OpenThemeData"); - pCloseThemeData = (PtrCloseThemeData)themeLib.resolve("CloseThemeData"); - pGetThemeSysFont = (PtrGetThemeSysFont)themeLib.resolve("GetThemeSysFont"); - pDrawThemeTextEx = (PtrDrawThemeTextEx)themeLib.resolve("DrawThemeTextEx"); - pSetWindowThemeAttribute = (PtrSetWindowThemeAttribute)themeLib.resolve("SetWindowThemeAttribute"); - } - } - - return ( - pDwmIsCompositionEnabled != 0 - && pDwmDefWindowProc != 0 - && pDwmExtendFrameIntoClientArea != 0 - && pIsAppThemed != 0 - && pDrawThemeBackground != 0 - && pGetThemePartSize != 0 - && pGetThemeColor != 0 - && pIsThemeActive != 0 - && pOpenThemeData != 0 - && pCloseThemeData != 0 - && pGetThemeSysFont != 0 - && pDrawThemeTextEx != 0 - && pSetWindowThemeAttribute != 0 - ); -} - int QVistaHelper::titleOffset() { int iconOffset = wizard ->windowIcon().isNull() ? 0 : iconSize() + textSpacing; |