diff options
Diffstat (limited to 'src/widgets/dialogs/qwizard_win.cpp')
-rw-r--r-- | src/widgets/dialogs/qwizard_win.cpp | 242 |
1 files changed, 97 insertions, 145 deletions
diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index e95f0e3b7b..2c4f049e88 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -33,9 +33,7 @@ Q_DECLARE_METATYPE(QMargins) QT_BEGIN_NAMESPACE -int QVistaHelper::instanceCount = 0; -int QVistaHelper::m_devicePixelRatio = 1; -QVistaHelper::VistaState QVistaHelper::cachedVistaState = QVistaHelper::Dirty; +qreal QVistaHelper::m_devicePixelRatio = 1.0; /****************************************************************************** ** QVistaBackButton @@ -84,7 +82,7 @@ void QVistaBackButton::paintEvent(QPaintEvent *) RECT clipRect; int xoffset = origin.x() + QWidget::mapToParent(r.topLeft()).x() - 1; int yoffset = origin.y() + QWidget::mapToParent(r.topLeft()).y() - 1; - const int dpr = devicePixelRatio(); + const qreal dpr = devicePixelRatio(); const QRect rDp = QRect(r.topLeft() * dpr, r.size() * dpr); const int xoffsetDp = xoffset * dpr; const int yoffsetDp = yoffset * dpr; @@ -118,18 +116,14 @@ QVistaHelper::QVistaHelper(QWizard *wizard) , backButton_(0) { QVistaHelper::m_devicePixelRatio = wizard->devicePixelRatio(); - if (instanceCount++ == 0) - cachedVistaState = Dirty; + backButton_ = new QVistaBackButton(wizard); backButton_->hide(); iconSpacing = QStyleHelper::dpiScaled(7, wizard); } -QVistaHelper::~QVistaHelper() -{ - --instanceCount; -} +QVistaHelper::~QVistaHelper() = default; void QVistaHelper::updateCustomMargins(bool vistaMargins) { @@ -150,24 +144,6 @@ void QVistaHelper::updateCustomMargins(bool vistaMargins) } } -bool QVistaHelper::isCompositionEnabled() -{ - return true; -} - -bool QVistaHelper::isThemeActive() -{ - return IsThemeActive(); -} - -QVistaHelper::VistaState QVistaHelper::vistaState() -{ - if (instanceCount == 0 || cachedVistaState == Dirty) - cachedVistaState = - isCompositionEnabled() ? VistaAero : isThemeActive() ? VistaBasic : Classic; - return cachedVistaState; -} - void QVistaHelper::disconnectBackButton() { if (backButton_) // Leave QStyleSheetStyle's connections on destroyed() intact. @@ -188,18 +164,16 @@ QColor QVistaHelper::basicWindowFrameColor() bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type) { - bool value = false; - if (vistaState() == VistaAero) { - MARGINS mar = {0, 0, 0, 0}; - if (type == NormalTitleBar) - mar.cyTopHeight = 0; - else - mar.cyTopHeight = (titleBarSize() + topOffset(wizard)) * QVistaHelper::m_devicePixelRatio; - if (const HWND wizardHandle = wizardHWND()) - if (SUCCEEDED(DwmExtendFrameIntoClientArea(wizardHandle, &mar))) - value = true; + MARGINS mar = {0, 0, 0, 0}; + if (type == NormalTitleBar) + mar.cyTopHeight = 0; + else + mar.cyTopHeight = (titleBarSize() + topOffset(wizard)) * QVistaHelper::m_devicePixelRatio; + if (const HWND wizardHandle = wizardHWND()) { + if (SUCCEEDED(DwmExtendFrameIntoClientArea(wizardHandle, &mar))) + return true; } - return value; + return false; } Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); @@ -235,7 +209,7 @@ void QVistaHelper::drawTitleBar(QPainter *painter) const bool isWindow = wizard->isWindow(); const HDC hdc = QVistaHelper::backingStoreDC(wizard, &origin); - if (vistaState() == VistaAero && isWindow) + if (isWindow) drawBlackRect(QRect(0, 0, wizard->width(), titleBarSize() + topOffset(wizard)), hdc); // The button is positioned in QWizardPrivate::handleAeroStyleChange(), @@ -250,15 +224,9 @@ void QVistaHelper::drawTitleBar(QPainter *painter) font = QApplication::font("QMdiSubWindowTitleBar"); const QFontMetrics fontMetrics(font); const QRect brect = fontMetrics.boundingRect(text); - int textHeight = brect.height(); - int textWidth = brect.width(); - int glowOffset = 0; - - if (vistaState() == VistaAero) { - glowOffset = glowSize(wizard); - textHeight += 2 * glowOffset; - textWidth += 2 * glowOffset; - } + const int glowOffset = glowSize(wizard); + int textHeight = brect.height() + 2 * glowOffset; + int textWidth = brect.width() + 2 * glowOffset; const int titleLeft = (wizard->layoutDirection() == Qt::LeftToRight ? titleOffset() - glowOffset @@ -365,11 +333,8 @@ void QVistaHelper::mouseEvent(QEvent *event) bool QVistaHelper::handleWinEvent(MSG *message, qintptr *result) { - if (message->message == WM_THEMECHANGED || message->message == WM_DWMCOMPOSITIONCHANGED) - cachedVistaState = Dirty; - bool status = false; - if (wizard->wizardStyle() == QWizard::AeroStyle && vistaState() == VistaAero) { + if (wizard->wizardStyle() == QWizard::AeroStyle) { status = winEvent(message, result); if (message->message == WM_NCPAINT) wizard->update(); @@ -382,8 +347,6 @@ void QVistaHelper::resizeEvent(QResizeEvent * event) Q_UNUSED(event); rtTop = QRect (0, 0, wizard->width(), frameSize()); int height = captionSize() + topOffset(wizard); - if (vistaState() == VistaBasic) - height -= titleBarSize(); rtTitle = QRect (0, frameSize(), wizard->width(), height); } @@ -422,7 +385,7 @@ void QVistaHelper::mouseMoveEvent(QMouseEvent *event) } wizard->setGeometry(rect); - } else if (vistaState() == VistaAero) { + } else { setMouseCursor(event->pos()); } event->ignore(); @@ -440,11 +403,10 @@ void QVistaHelper::mousePressEvent(QMouseEvent *event) if (rtTitle.contains(event->pos())) { change = movePosition; } else if (rtTop.contains(event->pos())) - change = (vistaState() == VistaAero) ? resizeTop : movePosition; + change = resizeTop; if (change != noChange) { - if (vistaState() == VistaAero) - setMouseCursor(event->pos()); + setMouseCursor(event->pos()); pressed = true; pressedPos = event->pos(); } else { @@ -458,8 +420,7 @@ void QVistaHelper::mouseReleaseEvent(QMouseEvent *event) if (pressed) { pressed = false; wizard->releaseMouse(); - if (vistaState() == VistaAero) - setMouseCursor(event->pos()); + setMouseCursor(event->pos()); } event->ignore(); } @@ -547,95 +508,88 @@ HWND QVistaHelper::wizardHWND() const return 0; } -bool QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc) +void QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc) { - bool value = false; - if (vistaState() == VistaAero) { - const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, - rect.size() * QVistaHelper::m_devicePixelRatio); - const HANDLE hTheme = OpenThemeData(GetDesktopWindow(), L"WINDOW"); - if (!hTheme) return false; - // Set up a memory DC and bitmap that we'll draw into - HDC dcMem; - HBITMAP bmp; - BITMAPINFO dib; - ZeroMemory(&dib, sizeof(dib)); - dcMem = CreateCompatibleDC(hdc); - - dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - dib.bmiHeader.biWidth = rectDp.width(); - dib.bmiHeader.biHeight = -rectDp.height(); - dib.bmiHeader.biPlanes = 1; - dib.bmiHeader.biBitCount = 32; - dib.bmiHeader.biCompression = BI_RGB; - - bmp = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); - - // Set up the DC - const LOGFONT captionLogFont = getCaptionLogFont(hTheme); - const HFONT hCaptionFont = CreateFontIndirect(&captionLogFont); - auto hOldBmp = reinterpret_cast<HBITMAP>(SelectObject(dcMem, (HGDIOBJ) bmp)); - auto hOldFont = reinterpret_cast<HFONT>(SelectObject(dcMem, (HGDIOBJ) hCaptionFont)); - - // Draw the text! - 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 = DTT_COMPOSITED|DTT_GLOWSIZE; - dto.iGlowSize = glowSize(wizard); - - 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); - DeleteObject(bmp); - DeleteObject(hCaptionFont); - DeleteDC(dcMem); - //ReleaseDC(hwnd, hdc); - } else if (vistaState() == VistaBasic) { - painter->drawText(rect, text); - } - return value; -} + Q_UNUSED(painter); -bool QVistaHelper::drawBlackRect(const QRect &rect, HDC hdc) -{ - bool value = false; - if (vistaState() == VistaAero) { - // Set up a memory DC and bitmap that we'll draw into - const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, + const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, + rect.size() * QVistaHelper::m_devicePixelRatio); + const HANDLE hTheme = OpenThemeData(GetDesktopWindow(), L"WINDOW"); + if (!hTheme) + return; + // Set up a memory DC and bitmap that we'll draw into + HDC dcMem; + HBITMAP bmp; + BITMAPINFO dib; + ZeroMemory(&dib, sizeof(dib)); + dcMem = CreateCompatibleDC(hdc); + + dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + dib.bmiHeader.biWidth = rectDp.width(); + dib.bmiHeader.biHeight = -rectDp.height(); + dib.bmiHeader.biPlanes = 1; + dib.bmiHeader.biBitCount = 32; + dib.bmiHeader.biCompression = BI_RGB; + + bmp = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); + + // Set up the DC + const LOGFONT captionLogFont = getCaptionLogFont(hTheme); + const HFONT hCaptionFont = CreateFontIndirect(&captionLogFont); + auto hOldBmp = reinterpret_cast<HBITMAP>(SelectObject(dcMem, (HGDIOBJ) bmp)); + auto hOldFont = reinterpret_cast<HFONT>(SelectObject(dcMem, (HGDIOBJ) hCaptionFont)); + + // Draw the text! + 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 = DTT_COMPOSITED|DTT_GLOWSIZE; + dto.iGlowSize = glowSize(wizard); + + 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); + DeleteObject(bmp); + DeleteObject(hCaptionFont); + DeleteDC(dcMem); + //ReleaseDC(hwnd, hdc); +} + +void QVistaHelper::drawBlackRect(const QRect &rect, HDC hdc) +{ + // Set up a memory DC and bitmap that we'll draw into + const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, rect.size() * QVistaHelper::m_devicePixelRatio); - HDC dcMem; - HBITMAP bmp; - BITMAPINFO dib; - ZeroMemory(&dib, sizeof(dib)); - dcMem = CreateCompatibleDC(hdc); - - dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - dib.bmiHeader.biWidth = rectDp.width(); - dib.bmiHeader.biHeight = -rectDp.height(); - dib.bmiHeader.biPlanes = 1; - dib.bmiHeader.biBitCount = 32; - dib.bmiHeader.biCompression = BI_RGB; - - bmp = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); - auto hOldBmp = reinterpret_cast<HBITMAP>(SelectObject(dcMem, (HGDIOBJ) bmp)); - - BitBlt(hdc, rectDp.left(), rectDp.top(), rectDp.width(), rectDp.height(), dcMem, 0, 0, SRCCOPY); - SelectObject(dcMem, (HGDIOBJ) hOldBmp); - - DeleteObject(bmp); - DeleteDC(dcMem); - } - return value; + HDC dcMem; + HBITMAP bmp; + BITMAPINFO dib; + ZeroMemory(&dib, sizeof(dib)); + dcMem = CreateCompatibleDC(hdc); + + dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + dib.bmiHeader.biWidth = rectDp.width(); + dib.bmiHeader.biHeight = -rectDp.height(); + dib.bmiHeader.biPlanes = 1; + dib.bmiHeader.biBitCount = 32; + dib.bmiHeader.biCompression = BI_RGB; + + bmp = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); + auto hOldBmp = reinterpret_cast<HBITMAP>(SelectObject(dcMem, (HGDIOBJ) bmp)); + + BitBlt(hdc, rectDp.left(), rectDp.top(), rectDp.width(), rectDp.height(), dcMem, 0, 0, SRCCOPY); + SelectObject(dcMem, (HGDIOBJ) hOldBmp); + + DeleteObject(bmp); + DeleteDC(dcMem); } int QVistaHelper::frameSizeDp() { - return GetSystemMetrics(SM_CYSIZEFRAME); + return GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); } int QVistaHelper::captionSizeDp() @@ -661,8 +615,6 @@ int QVistaHelper::glowSize(const QPaintDevice *device) int QVistaHelper::topOffset(const QPaintDevice *device) { - if (vistaState() != VistaAero) - return titleBarSize() + 3; static const int aeroOffset = QStyleHelper::dpiScaled(13, device); return aeroOffset + titleBarSize(); } |