Revert "Fix wxMSW ListCtrl drawing of horizontal rules for new items"

This reverts commit 374db28747 (Fix wxMSW ListCtrl drawing of horizontal
rules for new items, 2016-05-04) and also commit bb3177dd3b (Avoid
infinite repaint loop in wxListCtrl with wxLC_HRULES, 2020-07-24) which
fixed one problem with the original change, but not all of them, as it
was still easily possible to get into an infinite repaint loop.

So just return to the simplest and not too bad, even if not optimal,
solution of refreshing everything after changing a column width when
using horizontal rules.

See #17158, #18850.

Closes #18927.
This commit is contained in:
Vadim Zeitlin 2020-10-04 18:19:12 +02:00
parent 5ddb8182d7
commit c91ced2412

View File

@ -788,7 +788,15 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
else if ( width == wxLIST_AUTOSIZE_USEHEADER)
width = LVSCW_AUTOSIZE_USEHEADER;
return ListView_SetColumnWidth(GetHwnd(), col, width) != 0;
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;
}
// ----------------------------------------------------------------------------
@ -3261,12 +3269,7 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH);
// Find the coordinate of the right most visible point: this is not the
// same as GetClientSize().x because the window might not be fully visible,
// it could be clipped by its parent.
const int availableWidth = GetParent()->GetClientSize().x - GetPosition().x;
int visibleWidth = wxMin(GetClientSize().x,
availableWidth - GetWindowBorderSize().x);
wxSize clientSize = GetClientSize();
const int countPerPage = GetCountPerPage();
if (countPerPage < 0)
@ -3278,9 +3281,6 @@ 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;
@ -3289,23 +3289,9 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
if (GetItemRect(i, itemRect))
{
const int cy = itemRect.GetBottom();
dc.DrawLine(clipRect.x, cy, clipRect.GetRight() + 1, cy);
dc.DrawLine(0, cy, clientSize.x, 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() < visibleWidth - 1 && clipRect.width )
{
RefreshRect(wxRect(clipRect.GetRight(), clipRect.y,
visibleWidth - clipRect.width, clipRect.height),
false /* don't erase background */);
}
}
if (drawVRules)
@ -3347,7 +3333,7 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
wxDCBrushChanger changeBrush(dc, GetBackgroundColour());
dc.DrawRectangle(0, topItemRect.GetY() - gap,
visibleWidth, gap);
clientSize.GetWidth(), gap);
}
const int numCols = GetColumnCount();