Skip to content

Commit

Permalink
Slightly improve wxMSW ListCtrl drawing of vertical rules
Browse files Browse the repository at this point in the history
Draw the vertical rules with Y coordinates related to the top and bottom
visible item which makes more sense than using the first and last item.
  • Loading branch information
discnl committed May 4, 2016
1 parent 761f05c commit d382107
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/msw/listctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3066,12 +3066,20 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
dc.SetBrush(* wxTRANSPARENT_BRUSH);

wxSize clientSize = GetClientSize();
wxRect itemRect;

const int countPerPage = GetCountPerPage();
if (countPerPage < 0)
{
// Can be -1 in which case it's useless to try to draw rules.
return;
}

const long top = GetTopItem();
const long bottom = wxMin(top + countPerPage, itemCount - 1);

if (drawHRules)
{
const long top = GetTopItem();
const long bottom = wxMin(top + GetCountPerPage(), itemCount - 1);
wxRect itemRect;
for ( long i = top; i <= bottom; i++ )
{
if (GetItemRect(i, itemRect))
Expand All @@ -3084,10 +3092,10 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)

if (drawVRules)
{
wxRect firstItemRect;
GetItemRect(0, firstItemRect);
wxRect topItemRect, bottomItemRect;
GetItemRect(top, topItemRect);

if (GetItemRect(itemCount - 1, itemRect))
if (GetItemRect(bottom, bottomItemRect))
{
/*
This is a fix for ticket #747: erase the pixels which we would
Expand Down Expand Up @@ -3119,7 +3127,7 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(GetBackgroundColour()));
dc.DrawRectangle(0, firstItemRect.GetY() - gap,
dc.DrawRectangle(0, topItemRect.GetY() - gap,
clientSize.GetWidth(), gap);

dc.SetPen(pen);
Expand All @@ -3136,13 +3144,13 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
return;
}

int x = itemRect.GetX();
int x = bottomItemRect.GetX();
for (int col = 0; col < numCols; col++)
{
int colWidth = GetColumnWidth(indexArray[col]);
x += colWidth ;
dc.DrawLine(x-1, firstItemRect.GetY() - gap,
x-1, itemRect.GetBottom());
dc.DrawLine(x-1, topItemRect.GetY() - gap,
x-1, bottomItemRect.GetBottom());
}
}
}
Expand Down

0 comments on commit d382107

Please sign in to comment.