Cleanup QWizard Windows implementation

Since DWM composition is now always enabled and can't be disabled,
The code for VistaBasic style is now dead code in reality, just remove
them.

Change-Id: Iab2ba9b11ed573b240814ab5e26dec656de42ed2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Yuhang Zhao 2022-11-25 11:33:33 +08:00
parent 97b32fa0b6
commit 4e52a4c7e3
3 changed files with 102 additions and 192 deletions

View File

@ -328,8 +328,7 @@ void QWizardHeader::setup(const QWizardLayoutInfo &info, const QString &title,
{ {
bool modern = ((info.wizStyle == QWizard::ModernStyle) bool modern = ((info.wizStyle == QWizard::ModernStyle)
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
|| ((info.wizStyle == QWizard::AeroStyle || vistaDisabled()
&& QVistaHelper::vistaState() == QVistaHelper::Classic) || vistaDisabled())
#endif #endif
); );
@ -535,7 +534,6 @@ public:
void updatePixmap(QWizard::WizardPixmap which); void updatePixmap(QWizard::WizardPixmap which);
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
bool vistaDisabled() const; bool vistaDisabled() const;
bool isVistaThemeEnabled(QVistaHelper::VistaState state) const;
bool handleAeroStyleChange(); bool handleAeroStyleChange();
#endif #endif
bool isVistaThemeEnabled() const; bool isVistaThemeEnabled() const;
@ -604,7 +602,7 @@ public:
QPointer<QShortcut> vistaNextShortcut; QPointer<QShortcut> vistaNextShortcut;
# endif # endif
bool vistaInitPending = true; bool vistaInitPending = true;
QVistaHelper::VistaState vistaState = QVistaHelper::Dirty; bool vistaDirty = true;
bool vistaStateChanged = false; bool vistaStateChanged = false;
bool inHandleAeroStyleChange = false; bool inHandleAeroStyleChange = false;
#endif #endif
@ -888,7 +886,7 @@ QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage()
info.wizStyle = wizStyle; info.wizStyle = wizStyle;
if (info.wizStyle == QWizard::AeroStyle if (info.wizStyle == QWizard::AeroStyle
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
&& (QVistaHelper::vistaState() == QVistaHelper::Classic || vistaDisabled()) && vistaDisabled()
#endif #endif
) )
info.wizStyle = QWizard::ModernStyle; info.wizStyle = QWizard::ModernStyle;
@ -1520,13 +1518,6 @@ bool QWizardPrivate::vistaDisabled() const
return v.isValid() && v.toBool(); return v.isValid() && v.toBool();
} }
bool QWizardPrivate::isVistaThemeEnabled(QVistaHelper::VistaState state) const
{
return wizStyle == QWizard::AeroStyle
&& QVistaHelper::vistaState() == state
&& !vistaDisabled();
}
bool QWizardPrivate::handleAeroStyleChange() bool QWizardPrivate::handleAeroStyleChange()
{ {
Q_Q(QWizard); Q_Q(QWizard);
@ -1550,7 +1541,6 @@ bool QWizardPrivate::handleAeroStyleChange()
if (isVistaThemeEnabled()) { if (isVistaThemeEnabled()) {
const int topOffset = vistaHelper->topOffset(q); const int topOffset = vistaHelper->topOffset(q);
const int topPadding = vistaHelper->topPadding(q); const int topPadding = vistaHelper->topPadding(q);
if (isVistaThemeEnabled(QVistaHelper::VistaAero)) {
if (isWindow) { if (isWindow) {
vistaHelper->setDWMTitleBar(QVistaHelper::ExtendedTitleBar); vistaHelper->setDWMTitleBar(QVistaHelper::ExtendedTitleBar);
q->installEventFilter(vistaHelper); q->installEventFilter(vistaHelper);
@ -1562,13 +1552,6 @@ bool QWizardPrivate::handleAeroStyleChange()
- qMin(topOffset, topPadding + 1)); - qMin(topOffset, topPadding + 1));
vistaMargins = true; vistaMargins = true;
vistaHelper->backButton()->show(); vistaHelper->backButton()->show();
} else {
if (isWindow)
vistaHelper->setDWMTitleBar(QVistaHelper::NormalTitleBar);
q->setMouseTracking(true);
antiFlickerWidget->move(0, topOffset);
vistaHelper->backButton()->move(0, -1); // ### should ideally work with (0, 0)
}
if (isWindow) if (isWindow)
vistaHelper->setTitleBarIconAndCaptionVisible(false); vistaHelper->setTitleBarIconAndCaptionVisible(false);
QObject::connect( QObject::connect(
@ -1597,8 +1580,7 @@ bool QWizardPrivate::handleAeroStyleChange()
bool QWizardPrivate::isVistaThemeEnabled() const bool QWizardPrivate::isVistaThemeEnabled() const
{ {
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
return isVistaThemeEnabled(QVistaHelper::VistaAero) return wizStyle == QWizard::AeroStyle && !vistaDisabled();
|| isVistaThemeEnabled(QVistaHelper::VistaBasic);
#else #else
return false; return false;
#endif #endif
@ -1755,13 +1737,6 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *)
painter.fillRect(0, buttonLayoutTop, width(), height() - buttonLayoutTop, brush); painter.fillRect(0, buttonLayoutTop, width(), height() - buttonLayoutTop, brush);
painter.setPen(QPen(QBrush(QColor(223, 223, 223)), 0)); // ### hardcoded for now painter.setPen(QPen(QBrush(QColor(223, 223, 223)), 0)); // ### hardcoded for now
painter.drawLine(0, buttonLayoutTop, width(), buttonLayoutTop); painter.drawLine(0, buttonLayoutTop, width(), buttonLayoutTop);
if (wizardPrivate->isVistaThemeEnabled(QVistaHelper::VistaBasic)) {
if (window()->isActiveWindow())
painter.setPen(QPen(QBrush(QColor(169, 191, 214)), 0)); // ### hardcoded for now
else
painter.setPen(QPen(QBrush(QColor(182, 193, 204)), 0)); // ### hardcoded for now
painter.drawLine(0, 0, width(), 0);
}
} }
} }
#endif #endif
@ -3171,11 +3146,6 @@ bool QWizard::event(QEvent *event)
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
else if (event->type() == QEvent::Show && d->vistaInitPending) { else if (event->type() == QEvent::Show && d->vistaInitPending) {
d->vistaInitPending = false; d->vistaInitPending = false;
// Do not force AeroStyle when in Classic theme.
// Note that d->handleAeroStyleChange() needs to be called in any case as it does some
// necessary initialization, like ensures that the Aero specific back button is hidden if
// Aero theme isn't active.
if (QVistaHelper::vistaState() != QVistaHelper::Classic)
d->wizStyle = AeroStyle; d->wizStyle = AeroStyle;
d->handleAeroStyleChange(); d->handleAeroStyleChange();
} }
@ -3206,7 +3176,6 @@ void QWizard::resizeEvent(QResizeEvent *event)
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
if (d->isVistaThemeEnabled()) { if (d->isVistaThemeEnabled()) {
heightOffset = d->vistaHelper->topOffset(this); heightOffset = d->vistaHelper->topOffset(this);
if (d->isVistaThemeEnabled(QVistaHelper::VistaAero))
heightOffset += d->vistaHelper->titleBarSize(); heightOffset += d->vistaHelper->titleBarSize();
} }
#endif #endif
@ -3234,11 +3203,6 @@ void QWizard::paintEvent(QPaintEvent * event)
} }
#if QT_CONFIG(style_windowsvista) #if QT_CONFIG(style_windowsvista)
else if (d->isVistaThemeEnabled()) { else if (d->isVistaThemeEnabled()) {
if (d->isVistaThemeEnabled(QVistaHelper::VistaBasic)) {
QPainter painter(this);
QColor color = d->vistaHelper->basicWindowFrameColor();
painter.fillRect(0, 0, width(), QVistaHelper::topOffset(this), color);
}
d->vistaHelper->paintEvent(event); d->vistaHelper->paintEvent(event);
} }
#else #else
@ -3257,12 +3221,12 @@ bool QWizard::nativeEvent(const QByteArray &eventType, void *message, qintptr *r
if (d->isVistaThemeEnabled() && eventType == "windows_generic_MSG") { if (d->isVistaThemeEnabled() && eventType == "windows_generic_MSG") {
MSG *windowsMessage = static_cast<MSG *>(message); MSG *windowsMessage = static_cast<MSG *>(message);
const bool winEventResult = d->vistaHelper->handleWinEvent(windowsMessage, result); const bool winEventResult = d->vistaHelper->handleWinEvent(windowsMessage, result);
if (QVistaHelper::vistaState() != d->vistaState) { if (d->vistaDirty) {
// QTBUG-78300: When Qt::AA_NativeWindows is set, delay further // QTBUG-78300: When Qt::AA_NativeWindows is set, delay further
// window creation until after the platform window creation events. // window creation until after the platform window creation events.
if (windowsMessage->message == WM_GETICON) { if (windowsMessage->message == WM_GETICON) {
d->vistaStateChanged = true; d->vistaStateChanged = true;
d->vistaState = QVistaHelper::vistaState(); d->vistaDirty = false;
setWizardStyle(AeroStyle); setWizardStyle(AeroStyle);
} }
} }

View File

@ -33,9 +33,7 @@ Q_DECLARE_METATYPE(QMargins)
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
int QVistaHelper::instanceCount = 0;
int QVistaHelper::m_devicePixelRatio = 1; int QVistaHelper::m_devicePixelRatio = 1;
QVistaHelper::VistaState QVistaHelper::cachedVistaState = QVistaHelper::Dirty;
/****************************************************************************** /******************************************************************************
** QVistaBackButton ** QVistaBackButton
@ -118,18 +116,14 @@ QVistaHelper::QVistaHelper(QWizard *wizard)
, backButton_(0) , backButton_(0)
{ {
QVistaHelper::m_devicePixelRatio = wizard->devicePixelRatio(); QVistaHelper::m_devicePixelRatio = wizard->devicePixelRatio();
if (instanceCount++ == 0)
cachedVistaState = Dirty;
backButton_ = new QVistaBackButton(wizard); backButton_ = new QVistaBackButton(wizard);
backButton_->hide(); backButton_->hide();
iconSpacing = QStyleHelper::dpiScaled(7, wizard); iconSpacing = QStyleHelper::dpiScaled(7, wizard);
} }
QVistaHelper::~QVistaHelper() QVistaHelper::~QVistaHelper() = default;
{
--instanceCount;
}
void QVistaHelper::updateCustomMargins(bool vistaMargins) 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() void QVistaHelper::disconnectBackButton()
{ {
if (backButton_) // Leave QStyleSheetStyle's connections on destroyed() intact. if (backButton_) // Leave QStyleSheetStyle's connections on destroyed() intact.
@ -188,18 +164,16 @@ QColor QVistaHelper::basicWindowFrameColor()
bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type) bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type)
{ {
bool value = false;
if (vistaState() == VistaAero) {
MARGINS mar = {0, 0, 0, 0}; MARGINS mar = {0, 0, 0, 0};
if (type == NormalTitleBar) if (type == NormalTitleBar)
mar.cyTopHeight = 0; mar.cyTopHeight = 0;
else else
mar.cyTopHeight = (titleBarSize() + topOffset(wizard)) * QVistaHelper::m_devicePixelRatio; mar.cyTopHeight = (titleBarSize() + topOffset(wizard)) * QVistaHelper::m_devicePixelRatio;
if (const HWND wizardHandle = wizardHWND()) if (const HWND wizardHandle = wizardHWND()) {
if (SUCCEEDED(DwmExtendFrameIntoClientArea(wizardHandle, &mar))) if (SUCCEEDED(DwmExtendFrameIntoClientArea(wizardHandle, &mar)))
value = true; return true;
} }
return value; return false;
} }
Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &);
@ -235,7 +209,7 @@ void QVistaHelper::drawTitleBar(QPainter *painter)
const bool isWindow = wizard->isWindow(); const bool isWindow = wizard->isWindow();
const HDC hdc = QVistaHelper::backingStoreDC(wizard, &origin); const HDC hdc = QVistaHelper::backingStoreDC(wizard, &origin);
if (vistaState() == VistaAero && isWindow) if (isWindow)
drawBlackRect(QRect(0, 0, wizard->width(), drawBlackRect(QRect(0, 0, wizard->width(),
titleBarSize() + topOffset(wizard)), hdc); titleBarSize() + topOffset(wizard)), hdc);
// The button is positioned in QWizardPrivate::handleAeroStyleChange(), // The button is positioned in QWizardPrivate::handleAeroStyleChange(),
@ -250,15 +224,9 @@ void QVistaHelper::drawTitleBar(QPainter *painter)
font = QApplication::font("QMdiSubWindowTitleBar"); font = QApplication::font("QMdiSubWindowTitleBar");
const QFontMetrics fontMetrics(font); const QFontMetrics fontMetrics(font);
const QRect brect = fontMetrics.boundingRect(text); const QRect brect = fontMetrics.boundingRect(text);
int textHeight = brect.height(); const int glowOffset = glowSize(wizard);
int textWidth = brect.width(); int textHeight = brect.height() + 2 * glowOffset;
int glowOffset = 0; int textWidth = brect.width() + 2 * glowOffset;
if (vistaState() == VistaAero) {
glowOffset = glowSize(wizard);
textHeight += 2 * glowOffset;
textWidth += 2 * glowOffset;
}
const int titleLeft = (wizard->layoutDirection() == Qt::LeftToRight const int titleLeft = (wizard->layoutDirection() == Qt::LeftToRight
? titleOffset() - glowOffset ? titleOffset() - glowOffset
@ -365,11 +333,8 @@ void QVistaHelper::mouseEvent(QEvent *event)
bool QVistaHelper::handleWinEvent(MSG *message, qintptr *result) bool QVistaHelper::handleWinEvent(MSG *message, qintptr *result)
{ {
if (message->message == WM_THEMECHANGED || message->message == WM_DWMCOMPOSITIONCHANGED)
cachedVistaState = Dirty;
bool status = false; bool status = false;
if (wizard->wizardStyle() == QWizard::AeroStyle && vistaState() == VistaAero) { if (wizard->wizardStyle() == QWizard::AeroStyle) {
status = winEvent(message, result); status = winEvent(message, result);
if (message->message == WM_NCPAINT) if (message->message == WM_NCPAINT)
wizard->update(); wizard->update();
@ -382,8 +347,6 @@ void QVistaHelper::resizeEvent(QResizeEvent * event)
Q_UNUSED(event); Q_UNUSED(event);
rtTop = QRect (0, 0, wizard->width(), frameSize()); rtTop = QRect (0, 0, wizard->width(), frameSize());
int height = captionSize() + topOffset(wizard); int height = captionSize() + topOffset(wizard);
if (vistaState() == VistaBasic)
height -= titleBarSize();
rtTitle = QRect (0, frameSize(), wizard->width(), height); rtTitle = QRect (0, frameSize(), wizard->width(), height);
} }
@ -422,7 +385,7 @@ void QVistaHelper::mouseMoveEvent(QMouseEvent *event)
} }
wizard->setGeometry(rect); wizard->setGeometry(rect);
} else if (vistaState() == VistaAero) { } else {
setMouseCursor(event->pos()); setMouseCursor(event->pos());
} }
event->ignore(); event->ignore();
@ -440,10 +403,9 @@ void QVistaHelper::mousePressEvent(QMouseEvent *event)
if (rtTitle.contains(event->pos())) { if (rtTitle.contains(event->pos())) {
change = movePosition; change = movePosition;
} else if (rtTop.contains(event->pos())) } else if (rtTop.contains(event->pos()))
change = (vistaState() == VistaAero) ? resizeTop : movePosition; change = resizeTop;
if (change != noChange) { if (change != noChange) {
if (vistaState() == VistaAero)
setMouseCursor(event->pos()); setMouseCursor(event->pos());
pressed = true; pressed = true;
pressedPos = event->pos(); pressedPos = event->pos();
@ -458,7 +420,6 @@ void QVistaHelper::mouseReleaseEvent(QMouseEvent *event)
if (pressed) { if (pressed) {
pressed = false; pressed = false;
wizard->releaseMouse(); wizard->releaseMouse();
if (vistaState() == VistaAero)
setMouseCursor(event->pos()); setMouseCursor(event->pos());
} }
event->ignore(); event->ignore();
@ -547,14 +508,15 @@ HWND QVistaHelper::wizardHWND() const
return 0; 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; Q_UNUSED(painter);
if (vistaState() == VistaAero) {
const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio, const QRect rectDp = QRect(rect.topLeft() * QVistaHelper::m_devicePixelRatio,
rect.size() * QVistaHelper::m_devicePixelRatio); rect.size() * QVistaHelper::m_devicePixelRatio);
const HANDLE hTheme = OpenThemeData(GetDesktopWindow(), L"WINDOW"); const HANDLE hTheme = OpenThemeData(GetDesktopWindow(), L"WINDOW");
if (!hTheme) return false; if (!hTheme)
return;
// Set up a memory DC and bitmap that we'll draw into // Set up a memory DC and bitmap that we'll draw into
HDC dcMem; HDC dcMem;
HBITMAP bmp; HBITMAP bmp;
@ -595,16 +557,10 @@ bool QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const Q
DeleteObject(hCaptionFont); DeleteObject(hCaptionFont);
DeleteDC(dcMem); DeleteDC(dcMem);
//ReleaseDC(hwnd, hdc); //ReleaseDC(hwnd, hdc);
} else if (vistaState() == VistaBasic) {
painter->drawText(rect, text);
}
return value;
} }
bool QVistaHelper::drawBlackRect(const QRect &rect, HDC hdc) void 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 // 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); rect.size() * QVistaHelper::m_devicePixelRatio);
@ -630,8 +586,6 @@ bool QVistaHelper::drawBlackRect(const QRect &rect, HDC hdc)
DeleteObject(bmp); DeleteObject(bmp);
DeleteDC(dcMem); DeleteDC(dcMem);
} }
return value;
}
int QVistaHelper::frameSizeDp() int QVistaHelper::frameSizeDp()
{ {
@ -661,8 +615,6 @@ int QVistaHelper::glowSize(const QPaintDevice *device)
int QVistaHelper::topOffset(const QPaintDevice *device) int QVistaHelper::topOffset(const QPaintDevice *device)
{ {
if (vistaState() != VistaAero)
return titleBarSize() + 3;
static const int aeroOffset = QStyleHelper::dpiScaled(13, device); static const int aeroOffset = QStyleHelper::dpiScaled(13, device);
return aeroOffset + titleBarSize(); return aeroOffset + titleBarSize();
} }

View File

@ -64,8 +64,6 @@ public:
void disconnectBackButton(); void disconnectBackButton();
void hideBackButton() { if (backButton_) backButton_->hide(); } void hideBackButton() { if (backButton_) backButton_->hide(); }
QColor basicWindowFrameColor(); QColor basicWindowFrameColor();
enum VistaState { VistaAero, VistaBasic, Classic, Dirty };
static VistaState vistaState();
static int titleBarSize() { return QVistaHelper::titleBarSizeDp() / QVistaHelper::m_devicePixelRatio; } static int titleBarSize() { return QVistaHelper::titleBarSizeDp() / QVistaHelper::m_devicePixelRatio; }
static int titleBarSizeDp() { return QVistaHelper::frameSizeDp() + QVistaHelper::captionSizeDp(); } static int titleBarSizeDp() { return QVistaHelper::frameSizeDp() + QVistaHelper::captionSizeDp(); }
static int topPadding(const QPaintDevice *device) { // padding under text static int topPadding(const QPaintDevice *device) { // padding under text
@ -77,8 +75,8 @@ public:
private: private:
HWND wizardHWND() const; HWND wizardHWND() const;
bool drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc); void drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc);
static bool drawBlackRect(const QRect &rect, HDC hdc); static void drawBlackRect(const QRect &rect, HDC hdc);
static int frameSize() { return QVistaHelper::frameSizeDp() / QVistaHelper::m_devicePixelRatio; } static int frameSize() { return QVistaHelper::frameSizeDp() / QVistaHelper::m_devicePixelRatio; }
static int frameSizeDp(); static int frameSizeDp();
@ -102,10 +100,6 @@ private:
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;
static int instanceCount;
static VistaState cachedVistaState;
static bool isCompositionEnabled();
static bool isThemeActive();
enum Changes { resizeTop, movePosition, noChange } change; enum Changes { resizeTop, movePosition, noChange } change;
QPoint pressedPos; QPoint pressedPos;
bool pressed; bool pressed;