Windows: Fix Vista style for use with QProxyStyle.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Fri, 4 May 2012 07:11:13 +0000 (09:11 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 4 May 2012 07:20:07 +0000 (09:20 +0200)
Cleanup the treeview helper window in case XP style cleans
the handle map.
This fixes the drawing of the PE_IndicatorBranch primitives
in Qt Creator.

Task-number:  QTBUG-25395
Change-Id: Iba561709e3d4032a59690c7b9163fb69bfa98619
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/widgets/styles/qwindowsvistastyle.cpp
src/widgets/styles/qwindowsvistastyle_p.h
src/widgets/styles/qwindowsxpstyle_p.h

index 138f5db..6fce426 100644 (file)
@@ -2469,7 +2469,12 @@ void QWindowsVistaStyle::unpolish(QWidget *widget)
 {
     QWindowsXPStyle::unpolish(widget);
 
-    QWindowsVistaStylePrivate *d = const_cast<QWindowsVistaStylePrivate*>(d_func());
+    QWindowsVistaStylePrivate *d = d_func();
+    // Delete the tree view helper in case the XP style cleaned the
+    // theme handle map due to a theme or QStyle change (QProxyStyle).
+    if (!QWindowsXPStylePrivate::hasTheme(QWindowsXPStylePrivate::TreeViewTheme))
+        d->cleanupTreeViewTheming();
+
     d->stopAnimation(widget);
 
 #ifndef QT_NO_LINEEDIT
@@ -2542,8 +2547,7 @@ QWindowsVistaStylePrivate::QWindowsVistaStylePrivate() :
 QWindowsVistaStylePrivate::~QWindowsVistaStylePrivate()
 {
     qDeleteAll(animations);
-    if (m_treeViewHelper)
-        DestroyWindow(m_treeViewHelper);
+    cleanupTreeViewTheming();
 }
 
 void QWindowsVistaStylePrivate::timerEvent()
@@ -2694,6 +2698,14 @@ bool QWindowsVistaStylePrivate::initTreeViewTheming()
     return QWindowsXPStylePrivate::createTheme(QWindowsXPStylePrivate::TreeViewTheme, m_treeViewHelper);
 }
 
+void QWindowsVistaStylePrivate::cleanupTreeViewTheming()
+{
+    if (m_treeViewHelper) {
+        DestroyWindow(m_treeViewHelper);
+        m_treeViewHelper = 0;
+    }
+}
+
 /*!
 \internal
 */
index 78282d0..cdb1227 100644 (file)
@@ -208,6 +208,7 @@ public:
 
 private:
     bool initTreeViewTheming();
+    void cleanupTreeViewTheming();
 
     QList <QWindowsVistaAnimation*> animations;
     QBasicTimer animationTimer;
index 058668d..1ef6009 100644 (file)
@@ -351,6 +351,7 @@ public:
 
     static HTHEME createTheme(int theme, HWND hwnd);
     static QString themeName(int theme);
+    static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
 
     QIcon dockFloat, dockClose;