Fix off-by-1 bugs in wxGrid::GetFirstFullyVisible{Row,Column}()

These functions always returned the first partially visible line, not
the first fully visible one as intended because IsXXXShown() always
returned true when it applied to that line and we need to increment the
index first, before calling it -- even if this requires writing the loop
in a slightly uglier way.

This fixes bugs in commits 0920a1646b (Make wxGrid row selecting more
user friendly, 2020-03-04) and 89dd47edee (Make wxGrid column selecting
more user friendly, 2020-03-04).
This commit is contained in:
Vadim Zeitlin
2020-04-11 23:59:44 +02:00
parent b095e67ac3
commit 1cb2ec06ee

View File

@@ -7848,9 +7848,13 @@ int wxGrid::GetFirstFullyVisibleRow() const
if ( GetRowTop(row) - 2 < y )
{
// Use the next visible row.
for ( ; row < m_numRows; ++row )
for ( ;; )
{
if ( IsRowShown(row) )
// But we can't go beyond the last row anyhow.
if ( row == m_numRows - 1 )
break;
if ( IsRowShown(++row) )
break;
}
}
@@ -7882,9 +7886,12 @@ int wxGrid::GetFirstFullyVisibleColumn() const
if ( GetColLeft(col) < x )
{
// Use the next visible column.
for ( ; col < m_numCols; ++col )
for ( ;; )
{
if ( IsColShown(GetColAt(col)) )
if ( col == m_numCols - 1 )
break;
if ( IsColShown(GetColAt(++col)) )
break;
}
}