From 374db28747a90bdced3ad05005e5d5ef406cbc18 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Wed, 4 May 2016 11:19:21 +0400 Subject: [PATCH] Fix wxMSW ListCtrl drawing of horizontal rules for new items When adding a new item to a wxMSW ListCtrl that uses horizontal rules the painting is horizontally clipped to the left of the control and the rightmost column and the rule doesn't extend beyond that as it does when doing a full repaint. Fix by refreshing the part to the right of the rightmost column. This also reverts 02c8973a575d14a66898533293ab58dd30447616 which became unnecessary now. Also see #17158. --- src/msw/listctrl.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 59f70aa200..3f38b4713b 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -709,15 +709,7 @@ bool wxListCtrl::SetColumnWidth(int col, int width) else if ( width == wxLIST_AUTOSIZE_USEHEADER) width = LVSCW_AUTOSIZE_USEHEADER; - if ( !ListView_SetColumnWidth(GetHwnd(), col, width) ) - return false; - - // Failure to explicitly refresh the control with horizontal rules results - // in corrupted rules display. - if ( HasFlag(wxLC_HRULES) ) - Refresh(); - - return true; + return ListView_SetColumnWidth(GetHwnd(), col, width) != 0; } // ---------------------------------------------------------------------------- @@ -3077,6 +3069,9 @@ void wxListCtrl::OnPaint(wxPaintEvent& event) const long top = GetTopItem(); const long bottom = wxMin(top + countPerPage, itemCount - 1); + wxRect clipRect; + dc.GetClippingBox(clipRect); + if (drawHRules) { wxRect itemRect; @@ -3085,9 +3080,24 @@ void wxListCtrl::OnPaint(wxPaintEvent& event) if (GetItemRect(i, itemRect)) { const int cy = itemRect.GetBottom(); - dc.DrawLine(0, cy, clientSize.x, cy); + dc.DrawLine(clipRect.x, cy, clipRect.GetRight() + 1, cy); } } + + /* + The drawing can be clipped horizontally to the rightmost column. This + happens when an item is added (and visible) and results in a + horizontal rule being clipped instead of drawn across the entire list + control. In that case we request for the part to the right of the + rightmost column to be drawn as well. + */ + if ( clipRect.GetRight() != clientSize.GetWidth() - 1 + && clipRect.width) + { + RefreshRect(wxRect(clipRect.GetRight(), clipRect.y, + clientSize.x - clipRect.width, clipRect.height), + false /* erase background? */); + } } if (drawVRules)