don't use invalid item indices in wxLC_HRULES-drawing code (closes #10484)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-02-09 13:41:25 +00:00
parent 8d6e8e45fe
commit 99366b91eb

View File

@@ -2847,10 +2847,11 @@ WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
// Necessary for drawing hrules and vrules, if specified // Necessary for drawing hrules and vrules, if specified
void wxListCtrl::OnPaint(wxPaintEvent& event) void wxListCtrl::OnPaint(wxPaintEvent& event)
{ {
const int itemCount = GetItemCount();
const bool drawHRules = HasFlag(wxLC_HRULES); const bool drawHRules = HasFlag(wxLC_HRULES);
const bool drawVRules = HasFlag(wxLC_VRULES); const bool drawVRules = HasFlag(wxLC_VRULES);
if (!InReportView() || !(drawHRules || drawVRules)) if (!InReportView() || !(drawHRules || drawVRules) || !itemCount)
{ {
event.Skip(); event.Skip();
return; return;
@@ -2870,12 +2871,10 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
wxSize clientSize = GetClientSize(); wxSize clientSize = GetClientSize();
wxRect itemRect; wxRect itemRect;
int itemCount = GetItemCount();
int i;
if (drawHRules) if (drawHRules)
{ {
long top = GetTopItem(); const long top = GetTopItem();
for (i = top; i < top + GetCountPerPage() + 1; i++) for ( int i = top; i < top + GetCountPerPage() + 1; i++ )
{ {
if (GetItemRect(i, itemRect)) if (GetItemRect(i, itemRect))
{ {
@@ -2889,17 +2888,18 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
{ {
cy = itemRect.GetBottom(); cy = itemRect.GetBottom();
dc.DrawLine(0, cy, clientSize.x, cy); dc.DrawLine(0, cy, clientSize.x, cy);
break;
} }
} }
} }
} }
i = itemCount - 1;
if (drawVRules && (i > -1)) if (drawVRules)
{ {
wxRect firstItemRect; wxRect firstItemRect;
GetItemRect(0, firstItemRect); GetItemRect(0, firstItemRect);
if (GetItemRect(i, itemRect)) if (GetItemRect(itemCount - 1, itemRect))
{ {
// this is a fix for bug 673394: erase the pixels which we would // this is a fix for bug 673394: erase the pixels which we would
// otherwise leave on the screen // otherwise leave on the screen