[PATCH 2/3] comctl32: Set the text and bkgnd colours to the default before the item pre-paint notification.

Huw Davies huw at codeweavers.com
Tue Dec 6 04:25:26 CST 2016


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/comctl32/tests/treeview.c | 17 ++++++++++++++---
 dlls/comctl32/treeview.c       |  8 +++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 388124a..9031a83 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -42,6 +42,7 @@ static BOOL g_disp_A_to_W;
 static BOOL g_disp_set_stateimage;
 static BOOL g_beginedit_alter_text;
 static HFONT g_customdraw_font;
+static BOOL g_v6;
 
 #define NUM_MSG_SEQUENCES   3
 #define TREEVIEW_SEQ_INDEX  0
@@ -1261,6 +1262,7 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam,
             {
                 NMTVCUSTOMDRAW *nmcd = (NMTVCUSTOMDRAW*)lParam;
                 COLORREF c0ffee = RGB(0xc0,0xff,0xee), cafe = RGB(0xca,0xfe,0x00);
+                COLORREF text = GetTextColor(nmcd->nmcd.hdc), bkgnd = GetBkColor(nmcd->nmcd.hdc);
 
                 msg.flags |= custdraw;
                 msg.stage = nmcd->nmcd.dwDrawStage;
@@ -1271,15 +1273,23 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam,
                 case CDDS_PREPAINT:
                     return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYITEMERASE|CDRF_NOTIFYPOSTPAINT;
                 case CDDS_ITEMPREPAINT:
-                    nmcd->clrTextBk = c0ffee;
+                    ok(text == nmcd->clrText || (g_v6 && nmcd->clrText == 0xffffffff),
+                       "got %08x vs %08x\n", text, nmcd->clrText);
+                    ok(bkgnd == nmcd->clrTextBk || (g_v6 && nmcd->clrTextBk == 0xffffffff),
+                       "got %08x vs %08x\n", bkgnd, nmcd->clrTextBk);
                     nmcd->clrText = cafe;
+                    nmcd->clrTextBk = c0ffee;
+                    SetTextColor(nmcd->nmcd.hdc, c0ffee);
+                    SetBkColor(nmcd->nmcd.hdc, cafe);
                     if (g_customdraw_font)
                         SelectObject(nmcd->nmcd.hdc, g_customdraw_font);
                     return CDRF_NOTIFYPOSTPAINT|CDRF_NEWFONT;
                 case CDDS_ITEMPOSTPAINT:
                     /* at the point of post paint notification colors are already restored */
-                    ok(GetTextColor(nmcd->nmcd.hdc) != cafe, "got 0%x\n", GetTextColor(nmcd->nmcd.hdc));
-                    ok(GetBkColor(nmcd->nmcd.hdc) != c0ffee, "got 0%x\n", GetBkColor(nmcd->nmcd.hdc));
+                    ok(nmcd->clrText == cafe, "got 0%x\n", nmcd->clrText);
+                    ok(nmcd->clrTextBk == c0ffee, "got 0%x\n", nmcd->clrTextBk);
+                    ok(text != cafe, "got 0%x\n", text);
+                    ok(bkgnd != c0ffee, "got 0%x\n", bkgnd);
                     if (g_customdraw_font)
                         ok(GetCurrentObject(nmcd->nmcd.hdc, OBJ_FONT) != g_customdraw_font, "got %p\n",
                            GetCurrentObject(nmcd->nmcd.hdc, OBJ_FONT));
@@ -2471,6 +2481,7 @@ START_TEST(treeview)
     }
 
     /* comctl32 version 6 tests start here */
+    g_v6 = TRUE;
     test_expandedimage();
     test_htreeitem_layout();
     test_WM_GETDLGCODE();
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index 70d6362..0a155bb 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -2552,6 +2552,8 @@ TREEVIEW_DrawItem(const TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *item)
     }
 
     hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
+    oldTextColor = SetTextColor(hdc, nmcdhdr.clrText);
+    oldTextBkColor = SetBkColor(hdc, nmcdhdr.clrTextBk);
 
     /* The custom draw handler can query the text rectangle,
      * so get ready. */
@@ -2586,9 +2588,9 @@ TREEVIEW_DrawItem(const TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *item)
 
     TREEVIEW_DrawItemLines(infoPtr, hdc, item);
 
-    /* Set colors. Custom draw handler can change these so we do this after it. */
-    oldTextColor = SetTextColor(hdc, nmcdhdr.clrText);
-    oldTextBkColor = SetBkColor(hdc, nmcdhdr.clrTextBk);
+    /* reset colors. Custom draw handler can change them */
+    SetTextColor(hdc, nmcdhdr.clrText);
+    SetBkColor(hdc, nmcdhdr.clrTextBk);
 
     centery = (item->rect.top + item->rect.bottom) / 2;
 
-- 
2.10.2




More information about the wine-patches mailing list