Return empty rectangle from GetItemRect() if item is not visible

This was already the case if the item was not visible because its parent
was not expanded, but now make it also true for the items which are not
visible due to the current scrollbar position.

Add unit tests checking for this and also verifying that GetItemRect()
returns the coordinates in the physical window coordinates.
This commit is contained in:
Vadim Zeitlin
2018-11-04 17:50:55 +01:00
parent 9b7757c44d
commit 9460038b3f
3 changed files with 43 additions and 4 deletions

View File

@@ -3839,6 +3839,14 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
GetOwner()->CalcScrolledPosition( itemRect.x, itemRect.y,
&itemRect.x, &itemRect.y );
// Check if the rectangle is completely outside of the currently visible
// area and, if so, return an empty rectangle to indicate that the item is
// not visible.
if ( itemRect.GetBottom() < 0 || itemRect.GetTop() > GetClientSize().y )
{
return wxRect();
}
return itemRect;
}
@@ -5853,8 +5861,11 @@ wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item,
// Convert position from the main window coordinates to the control coordinates.
// (They can be different due to the presence of the header.).
wxRect r = m_clientArea->GetItemRect(item, column);
const wxPoint ctrlPos = ScreenToClient(m_clientArea->ClientToScreen(r.GetPosition()));
r.SetPosition(ctrlPos);
if ( r.width || r.height )
{
const wxPoint ctrlPos = ScreenToClient(m_clientArea->ClientToScreen(r.GetPosition()));
r.SetPosition(ctrlPos);
}
return r;
}