Fix wxDataViewCtrl::GetItemRect() in wxGTK and enable its test

A couple of fixes compared to the previous commit:

- Use the correct gtk_tree_view_get_cell_area() rather than
  gtk_tree_view_get_background_area() which doesn't work correctly
  for the items which are not shown because their parent is collapsed.
- Translate logical coordinates to physical ones using
  gtk_tree_view_convert_bin_window_to_widget_coords().

With these fixes, the unit tests for this function pass and can now be
enabled under wxGTK as well.

See https://github.com/wxWidgets/wxWidgets/pull/990
This commit is contained in:
Vadim Zeitlin
2018-11-04 18:25:16 +01:00
parent 94a2595f5b
commit fad50e74b7
2 changed files with 51 additions and 5 deletions

View File

@@ -5304,7 +5304,15 @@ wxDataViewCtrl::GetItemRect(const wxDataViewItem& item,
wxGtkTreePath path(m_internal->get_path( &iter ));
GdkRectangle item_rect;
gtk_tree_view_get_background_area(GTK_TREE_VIEW(m_treeview), path, gcolumn, &item_rect);
gtk_tree_view_get_cell_area(GTK_TREE_VIEW(m_treeview), path, gcolumn, &item_rect);
// GTK returns rectangles with the position and height, but not width, for
// some reason, set to 0 if the item is not currently shown, so an explicit
// check is needed as this rectangle is not quite the empty rectangle we're
// supposed to return in this case.
if ( item_rect.height == 0 )
return wxRect();
// If column is NULL we compute the combined width of all the columns
if ( !column )
{
@@ -5318,6 +5326,33 @@ wxDataViewCtrl::GetItemRect(const wxDataViewItem& item,
}
item_rect.width = width;
}
// We need to convert logical coordinates to physical ones, i.e. the
// rectangle of the topmost item should start at ~0, even if it's a 100th
// item shown on top only because the window is scrolled.
#if GTK_CHECK_VERSION(2, 12, 0)
if ( wx_is_at_least_gtk2(12) )
{
gtk_tree_view_convert_bin_window_to_widget_coords
(
GTK_TREE_VIEW(m_treeview),
item_rect.x, item_rect.y,
&item_rect.x, &item_rect.y
);
if ( item_rect.y > GetClientSize().y ||
item_rect.y + item_rect.height < 0 )
{
// If it turns out that the item is not visible at all, indicate it
// by returning an empty rectangle for it.
return wxRect();
}
}
//else: There doesn't seem to be anything reasonable to do here, so we'll
// just return wrong values with the very old GTK+ versions if the
// window is scrolled.
#endif // GTK+ 2.12+
return wxRectFromGDKRect(&item_rect);
}