From 970f82df6c8f116807c62ed5ec1bc3fd57169cc8 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Date: Thu, 13 Nov 2014 09:00:51 +0100
Subject: [PATCH] WIP: Separate iconicThumbnailPixmap/iconicLivePreviewPixmap.

Ignore update messages if no pixmap is set.

TODO: Does not work, unfortunately. Investigate why LONG result is 0?

Task-number: QTBUG-42608
Change-Id: I621055f6e09ee678ca77a50ccbb5fbb298d464fd
---
 src/winextras/qwinthumbnailtoolbar.cpp | 46 ++++++++++++++++++++++------------
 src/winextras/qwinthumbnailtoolbar_p.h |  4 +--
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/winextras/qwinthumbnailtoolbar.cpp b/src/winextras/qwinthumbnailtoolbar.cpp
index a0118f7..68ddd3e 100644
--- a/src/winextras/qwinthumbnailtoolbar.cpp
+++ b/src/winextras/qwinthumbnailtoolbar.cpp
@@ -380,33 +380,41 @@ QPixmap QWinThumbnailToolBar::iconicLivePreviewPixmap() const
     return d->iconicLivePreview.pixmap();
 }
 
-inline void QWinThumbnailToolBarPrivate::updateIconicThumbnail(const MSG *message)
+inline bool QWinThumbnailToolBarPrivate::updateIconicThumbnail(const MSG *message)
 {
     qtDwmApiDll.init();
     if (!qtDwmApiDll.dwmSetIconicThumbnail || !iconicThumbnail)
-        return;
+        return false;
     const QSize maxSize(HIWORD(message->lParam), LOWORD(message->lParam));
-    if (const HBITMAP bitmap = iconicThumbnail.bitmap(maxSize)) {
-        const HRESULT hr = qtDwmApiDll.dwmSetIconicThumbnail(message->hwnd, bitmap, dWM_SIT_DISPLAYFRAME);
-        if (FAILED(hr))
-            qWarning() << QWinThumbnailToolBarPrivate::msgComFailed("DwmSetIconicThumbnail", hr);
+    const HBITMAP bitmap = iconicThumbnail.bitmap(maxSize);
+    if (!bitmap)
+        return false;
+    const HRESULT hr = qtDwmApiDll.dwmSetIconicThumbnail(message->hwnd, bitmap, dWM_SIT_DISPLAYFRAME);
+    if (FAILED(hr)) {
+        qWarning() << QWinThumbnailToolBarPrivate::msgComFailed("DwmSetIconicThumbnail", hr);
+        return false;
     }
+    return true;
 }
 
-inline void QWinThumbnailToolBarPrivate::updateIconicLivePreview(const MSG *message)
+inline bool QWinThumbnailToolBarPrivate::updateIconicLivePreview(const MSG *message)
 {
     qtDwmApiDll.init();
     if (!qtDwmApiDll.dwmSetIconicLivePreviewBitmap || !iconicLivePreview)
-        return;
+        return false;
     RECT rect;
     GetClientRect(message->hwnd, &rect);
     const QSize maxSize(rect.right, rect.bottom);
     POINT offset = {0, 0};
-    if (const HBITMAP bitmap = iconicLivePreview.bitmap(maxSize)) {
-        const HRESULT hr = qtDwmApiDll.dwmSetIconicLivePreviewBitmap(message->hwnd, bitmap, &offset, dWM_SIT_DISPLAYFRAME);
-        if (FAILED(hr))
-            qWarning() << QWinThumbnailToolBarPrivate::msgComFailed("DwmSetIconicLivePreviewBitmap", hr);
+    const HBITMAP bitmap = iconicLivePreview.bitmap(maxSize);
+    if (!bitmap)
+        return false;
+    const HRESULT hr = qtDwmApiDll.dwmSetIconicLivePreviewBitmap(message->hwnd, bitmap, &offset, dWM_SIT_DISPLAYFRAME);
+    if (FAILED(hr)) {
+        qWarning() << QWinThumbnailToolBarPrivate::msgComFailed("DwmSetIconicLivePreviewBitmap", hr);
+        return false;
     }
+    return true;
 }
 
 /*!
@@ -561,17 +569,23 @@ bool QWinThumbnailToolBarPrivate::nativeEventFilter(const QByteArray &, void *me
             return true;
         }
         break;
-    case WM_DWMSENDICONICTHUMBNAIL:
+    case WM_DWMSENDICONICTHUMBNAIL: {
         withinIconicThumbnailRequest = true;
         emit q_func()->iconicThumbnailPixmapRequested();
         withinIconicThumbnailRequest = false;
-        updateIconicThumbnail(msg);
+        const bool success = updateIconicThumbnail(msg) ? 0 : 1;
+        if (result)
+            *result = success ? 0 : 1;
+    }
         return true;
-    case WM_DWMSENDICONICLIVEPREVIEWBITMAP:
+    case WM_DWMSENDICONICLIVEPREVIEWBITMAP: {
         withinIconicLivePreviewRequest = true;
         emit q_func()->iconicLivePreviewPixmapRequested();
         withinIconicLivePreviewRequest = false;
-        updateIconicLivePreview(msg);
+        const bool success = updateIconicLivePreview(msg);
+        if (result)
+            *result = success ? 0 : 1;
+    }
         return true;
     }
     return false;
diff --git a/src/winextras/qwinthumbnailtoolbar_p.h b/src/winextras/qwinthumbnailtoolbar_p.h
index 87df367..a7cfc01 100644
--- a/src/winextras/qwinthumbnailtoolbar_p.h
+++ b/src/winextras/qwinthumbnailtoolbar_p.h
@@ -97,8 +97,8 @@ private:
     bool hasHandle() const;
     HWND handle() const;
     void updateIconicPixmapsEnabled(bool invalidate);
-    void updateIconicThumbnail(const MSG *message);
-    void updateIconicLivePreview(const MSG *message);
+    bool updateIconicThumbnail(const MSG *message);
+    bool updateIconicLivePreview(const MSG *message);
 
     QWinThumbnailToolBar *q_ptr;
     Q_DECLARE_PUBLIC(QWinThumbnailToolBar)
-- 
1.9.1

