summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qwindowsxpstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/styles/qwindowsxpstyle.cpp')
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index d8b33f3b0f..63d275a391 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -1,8 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Contact: http://www.qt-project.org/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
@@ -35,6 +34,7 @@
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -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
@@ -159,14 +176,14 @@ HTHEME XPThemeData::handle()
return 0;
if (!htheme && QWindowsXPStylePrivate::handleMap)
- htheme = QWindowsXPStylePrivate::handleMap->operator[](name);
+ htheme = QWindowsXPStylePrivate::handleMap->value(name);
if (!htheme) {
htheme = pOpenThemeData(QWindowsXPStylePrivate::winId(widget), (wchar_t*)name.utf16());
if (htheme) {
if (!QWindowsXPStylePrivate::handleMap)
- QWindowsXPStylePrivate::handleMap = new QMap<QString, HTHEME>;
- QWindowsXPStylePrivate::handleMap->operator[](name) = htheme;
+ QWindowsXPStylePrivate::handleMap = new QWindowsXPStylePrivate::ThemeHandleMap;
+ QWindowsXPStylePrivate::handleMap->insert(name, htheme);
}
}
@@ -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;
@@ -209,7 +223,6 @@ HRGN XPThemeData::mask(QWidget *widget)
// QWindowsXPStylePrivate -------------------------------------------------------------------------
// Static initializations
-QWidget *QWindowsXPStylePrivate::limboWidget = 0;
QPixmap *QWindowsXPStylePrivate::tabbody = 0;
QMap<QString,HTHEME> *QWindowsXPStylePrivate::handleMap = 0;
bool QWindowsXPStylePrivate::use_xp = false;
@@ -289,14 +302,7 @@ void QWindowsXPStylePrivate::cleanup(bool force)
use_xp = false;
cleanupHandleMap();
- if (limboWidget) {
- if (QApplication::closingDown())
- delete limboWidget;
- else
- limboWidget->deleteLater();
- }
delete tabbody;
- limboWidget = 0;
tabbody = 0;
}
@@ -307,11 +313,13 @@ void QWindowsXPStylePrivate::cleanup(bool force)
*/
void QWindowsXPStylePrivate::cleanupHandleMap()
{
+ typedef ThemeHandleMap::const_iterator ConstIterator;
+
if (!handleMap)
return;
- QMap<QString, HTHEME>::Iterator it;
- for (it = handleMap->begin(); it != handleMap->end(); ++it)
+ const ConstIterator cend = handleMap->constEnd();
+ for (ConstIterator it = handleMap->constBegin(); it != cend; ++it)
pCloseThemeData(it.value());
delete handleMap;
handleMap = 0;
@@ -325,20 +333,22 @@ void QWindowsXPStylePrivate::cleanupHandleMap()
*/
HWND QWindowsXPStylePrivate::winId(const QWidget *widget)
{
- if (widget && widget->internalWinId()) {
- QWidget *w = const_cast<QWidget *>(widget);
- return QApplicationPrivate::getHWNDForWidget(w);
- }
- if (!limboWidget) {
- limboWidget = new QWidget(0);
- limboWidget->createWinId();
- limboWidget->setObjectName(QLatin1String("xp_limbo_widget"));
- // We don't need this internal widget to appear in QApplication::topLevelWidgets()
- if (QWidgetPrivate::allWidgets)
- QWidgetPrivate::allWidgets->remove(limboWidget);
- }
+ if (widget)
+ if (const HWND hwnd = QApplicationPrivate::getHWNDForWidget(const_cast<QWidget *>(widget)))
+ return hwnd;
- return QApplicationPrivate::getHWNDForWidget(limboWidget);
+ const QWidgetList toplevels = QApplication::topLevelWidgets();
+ if (!toplevels.isEmpty())
+ if (const HWND topLevelHwnd = QApplicationPrivate::getHWNDForWidget(toplevels.front()))
+ return topLevelHwnd;
+
+ if (QDesktopWidget *desktop = qApp->desktop())
+ if (const HWND desktopHwnd = QApplicationPrivate::getHWNDForWidget(desktop))
+ return desktopHwnd;
+
+ Q_ASSERT(false);
+
+ return 0;
}
/*! \internal
@@ -686,25 +696,18 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
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 ));
- }
-
- bool useFallback = 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();
}
@@ -718,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()));