summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qwindowsxpstyle.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-01-27 11:21:13 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-27 21:16:11 +0100
commitb3dda7c5bfcc22ebbd443c667dad58112ecddb4b (patch)
tree37a33ef1987e1e03d8ecbcf388bb73a60b4e6fb0 /src/widgets/styles/qwindowsxpstyle.cpp
parent69b9943d949a12746711feb490261eed7675e4a8 (diff)
WindowsXP-Style: Draw on DC of backing store for widgets only.
- Check the device type pof the painter passed in. - Introduce convenience functions for retrieving the DC for widgets that default to the top level. Change-Id: I18a8db02c8ffd7a249310a5ffaf3a530f0a3df40 Reviewed-by: Oliver Wolff <oliver.wolff@nokia.com>
Diffstat (limited to 'src/widgets/styles/qwindowsxpstyle.cpp')
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index acc462ff72..3af297024c 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -136,7 +136,24 @@ static const int windowsRightBorder = 12; // right border on windows
extern Q_WIDGETS_EXPORT HDC qt_win_display_dc();
extern QRegion qt_region_from_HRGN(HRGN rgn);
+static inline QBackingStore *backingStoreForWidget(const QWidget *widget)
+{
+ if (QBackingStore *backingStore = widget->backingStore())
+ return backingStore;
+ if (const QWidget *topLevel = widget->nativeParentWidget())
+ if (QBackingStore *topLevelBackingStore = topLevel->backingStore())
+ return topLevelBackingStore;
+ return 0;
+}
+static inline HDC hdcForWidgetBackingStore(const QWidget *widget)
+{
+ if (QBackingStore *backingStore = backingStoreForWidget(widget)) {
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ return static_cast<HDC>(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore));
+ }
+ return 0;
+}
// Theme data helper ------------------------------------------------------------------------------
/* \internal
@@ -197,11 +214,8 @@ HRGN XPThemeData::mask(QWidget *widget)
HRGN hrgn;
HDC dc = 0;
- if (widget) {
- QBackingStore *backingStore = widget->backingStore();
- QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
- dc = static_cast<HDC>(nativeInterface->nativeResourceForBackingStore("getDC", backingStore));
- }
+ if (widget)
+ dc = hdcForWidgetBackingStore(widget);
RECT nativeRect = toRECT(rect);
pGetThemeBackgroundRegion(handle(), dc, partId, stateId, &nativeRect, &hrgn);
return hrgn;
@@ -661,7 +675,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels)
- Theme part is flipped (mirrored horizontally)
else use drawBackgroundDirectly().
*/
-void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData, bool forceFallback)
+void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
{
if (themeData.rect.isEmpty())
return;
@@ -682,24 +696,18 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData, bool forceFa
translucentToplevel = win->testAttribute(Qt::WA_TranslucentBackground);
}
- HDC dc = 0;
- if (themeData.widget) {
- QBackingStore *backingStore = themeData.widget->backingStore();
- QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
- dc = static_cast<HDC>(nativeInterface->nativeResourceForBackingStore("getDC", backingStore ));
- }
-
- const bool useFallback = forceFallback || dc == 0
- || painter->opacity() != 1.0
- || themeData.rotate
- || complexXForm
- || themeData.mirrorVertically
- || (themeData.mirrorHorizontally && pDrawThemeBackgroundEx == 0)
- || translucentToplevel;
- if (!useFallback)
+ // Draw on backing store DC only for real widgets.
+ const bool useFallback = !themeData.widget || painter->device()->devType() != QInternal::Widget
+ || painter->opacity() != 1.0 || themeData.rotate
+ || complexXForm || themeData.mirrorVertically
+ || (themeData.mirrorHorizontally && pDrawThemeBackgroundEx == 0)
+ || translucentToplevel;
+ const HDC dc = useFallback ? HDC(0) : hdcForWidgetBackingStore(themeData.widget);
+ if (dc && !useFallback) {
drawBackgroundDirectly(themeData);
- else
+ } else {
drawBackgroundThruNativeBuffer(themeData);
+ }
painter->restore();
}
@@ -713,11 +721,8 @@ void QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData)
{
QPainter *painter = themeData.painter;
HDC dc = 0;
- if (themeData.widget) {
- QBackingStore *backingStore = themeData.widget->backingStore();
- QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
- dc = static_cast<HDC>(nativeInterface->nativeResourceForBackingStore("getDC", backingStore));
- }
+ if (themeData.widget)
+ dc = hdcForWidgetBackingStore(themeData.widget);
QPoint redirectionDelta(int(painter->deviceMatrix().dx()),
int(painter->deviceMatrix().dy()));