Handle header and scrolling in wxOSX wxDataViewCtrl::HitTest()

Fix the result of this function for the controls using headers and/or
being scrolled, as it didn't take neither into the account before as
could be seen by checking it interactively in the dataview sample, see
the parent commit.

See #22789.
This commit is contained in:
Vojtěch Bubník 2022-10-03 02:44:57 +02:00 committed by Vadim Zeitlin
parent 99f5ea62f9
commit f2da7beb36

View file

@ -2583,8 +2583,29 @@ void wxCocoaDataViewControl::DoSetIndent(int indent)
[m_OutlineView setIndentationPerLevel:static_cast<CGFloat>(indent)];
}
void wxCocoaDataViewControl::HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
void wxCocoaDataViewControl::HitTest(const wxPoint& point_, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
{
// Assume no item by default.
columnPtr = NULL;
item = wxDataViewItem();
// Make a copy before modifying it.
wxPoint point(point_);
// First check that the point is not inside the header area and adjust it
// by its offset.
if (NSTableHeaderView* const headerView = [m_OutlineView headerView])
{
if (point.y < headerView.visibleRect.size.height)
return;
}
// Convert from the window coordinates to the virtual scrolled view coordinates.
NSScrollView *scrollView = [m_OutlineView enclosingScrollView];
const NSRect& visibleRect = scrollView.contentView.visibleRect;
point.x += visibleRect.origin.x;
point.y += visibleRect.origin.y;
NSPoint const nativePoint = wxToNSPoint((NSScrollView*) GetWXWidget(),point);
int indexColumn;
@ -2598,11 +2619,6 @@ void wxCocoaDataViewControl::HitTest(const wxPoint& point, wxDataViewItem& item,
columnPtr = GetColumn(indexColumn);
item = wxDataViewItem([[m_OutlineView itemAtRow:indexRow] pointer]);
}
else
{
columnPtr = NULL;
item = wxDataViewItem();
}
}
void wxCocoaDataViewControl::SetRowHeight(int height)