From c402d35df807096b199c9f1adfcad4dfabb70697 Mon Sep 17 00:00:00 2001 From: Olli Werwolff Date: Wed, 17 Aug 2011 09:59:08 +0200 Subject: Readded (and fixed) WindowsXP and -Vista styles There are still issues in WindowsVista style and qwizard_win's icon will not be shown but these will be fixed in upcoming commits. Change-Id: I22705694f07bea7461333b053804a09bab661706 Reviewed-on: http://codereview.qt.nokia.com/3073 Reviewed-by: Qt Sanity Bot Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qwizard_win.cpp | 2 +- src/widgets/kernel/qapplication_p.h | 2 +- src/widgets/styles/qwindowsxpstyle.cpp | 69 +++++++++++++++++++++++++++------- src/widgets/styles/styles.pri | 1 - 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 6c2a67639b..6177700d8c 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -353,7 +353,7 @@ void QVistaHelper::drawTitleBar(QPainter *painter) if (!wizard->windowIcon().isNull()) { QRect rect(leftMargin(), verticalCenter - iconSize() / 2, iconSize(), iconSize()); - HICON hIcon = wizard->windowIcon().pixmap(iconSize()).toWinHICON(); + HICON hIcon = 0; //###FIXME wizard->windowIcon().pixmap(iconSize()).toWinHICON(); DrawIconEx(hdc, rect.left(), rect.top(), hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT); DestroyIcon(hIcon); } diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index c4a9a15064..097e0e521a 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -518,7 +518,7 @@ public: #ifdef Q_OS_WIN static HWND getHWNDForWidget(QWidget *widget) { - QWindow *window = qobject_cast(widget); + QWindow *window = widget->windowHandle(); return static_cast ("handle", QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", window)); } #endif diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index ce5694c181..cbaf16989a 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -196,9 +196,12 @@ HRGN XPThemeData::mask(QWidget *widget) return 0; HRGN hrgn; - QBackingStore *backingStore = widget->backingStore(); - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); + HDC dc = 0; + if (widget) { + QBackingStore *backingStore = widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); + } RECT nativeRect = toRECT(rect); pGetThemeBackgroundRegion(handle(), dc, partId, stateId, &nativeRect, &hrgn); return hrgn; @@ -212,6 +215,32 @@ QMap *QWindowsXPStylePrivate::handleMap = 0; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting +static void qt_add_rect(HRGN &winRegion, QRect r) +{ + HRGN rgn = CreateRectRgn(r.left(), r.top(), r.x() + r.width(), r.y() + r.height()); + if (rgn) { + HRGN dest = CreateRectRgn(0,0,0,0); + int result = CombineRgn(dest, winRegion, rgn, RGN_OR); + if (result) { + DeleteObject(winRegion); + winRegion = dest; + } + DeleteObject(rgn); + } +} + +static HRGN qt_hrgn_from_qregion(const QRegion ®ion) +{ + HRGN hRegion = CreateRectRgn(0,0,0,0); + if (region.rectCount() == 1) { + qt_add_rect(hRegion, region.boundingRect()); + return hRegion; + } + foreach (const QRect &rect, region.rects()) + qt_add_rect(hRegion, rect); + return hRegion; +} + /* \internal Checks if the theme engine can/should be used, or if we should fall back to Windows style. @@ -657,9 +686,13 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) translucentToplevel = win->testAttribute(Qt::WA_TranslucentBackground); } - QBackingStore *backingStore = themeData.widget->backingStore(); - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore )); + HDC dc = 0; + if (themeData.widget) { + QBackingStore *backingStore = themeData.widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore )); + } + bool useFallback = dc == 0 || painter->opacity() != 1.0 || themeData.rotate @@ -684,9 +717,12 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) void QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData) { QPainter *painter = themeData.painter; - QBackingStore *backingStore= themeData.widget->backingStore(); - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); + HDC dc = 0; + if (themeData.widget) { + QBackingStore *backingStore = themeData.widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); + } QPoint redirectionDelta(int(painter->deviceMatrix().dx()), int(painter->deviceMatrix().dy())); @@ -699,7 +735,8 @@ void QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData) sysRgn &= area; if (painter->hasClipping()) sysRgn &= painter->clipRegion().translated(redirectionDelta); - SelectClipRgn(dc, sysRgn.handle()); + HRGN hrgn = qt_hrgn_from_qregion(sysRgn); + SelectClipRgn(dc, hrgn); #ifdef DEBUG_XP_STYLE printf("---[ DIRECT PAINTING ]------------------> Name(%-10s) Part(%d) State(%d)\n", @@ -744,13 +781,17 @@ void QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData) } // Set the clip region, if used.. - if (themeData.noBorder || themeData.noContent) - SelectClipRgn(dc, extraClip.handle()); + if (themeData.noBorder || themeData.noContent) { + DeleteObject(hrgn); + hrgn = qt_hrgn_from_qregion(extraClip); + SelectClipRgn(dc, hrgn); + } } pDrawThemeBackground(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &(drawOptions.rcClip)); } SelectClipRgn(dc, 0); + DeleteObject(hrgn); } /*! \internal @@ -916,9 +957,11 @@ void QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa } else { // Set the clip region, if used.. if (addBorderContentClipping) { - SelectClipRgn(dc, extraClip.handle()); + HRGN hrgn = qt_hrgn_from_qregion(extraClip); + SelectClipRgn(dc, hrgn); // Compensate for the noBorder area difference (noContent has the same area) drawOptions.rcClip = themeData.toRECT(rect.adjusted(dx, dy, dr, db)); + DeleteObject(hrgn); } pDrawThemeBackground(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawOptions.rcClip), 0); diff --git a/src/widgets/styles/styles.pri b/src/widgets/styles/styles.pri index e6ebf6e7e3..b20caf726e 100644 --- a/src/widgets/styles/styles.pri +++ b/src/widgets/styles/styles.pri @@ -40,7 +40,6 @@ contains( styles, all ) { } x11|qpa|!macx-*:styles -= mac -win32:qpa:styles -= windowsxp windowsvista x11{ QMAKE_CXXFLAGS += $$QT_CFLAGS_QGTKSTYLE -- cgit v1.2.3