+ // interestingly enough 10.2 (and below?) have GetDataBrowserItemPartBounds
+ // giving root window coordinates but 10.3 and above give client coordinates
+ // so we only compare using root window coordinates on 10.3 and up
+ if ( UMAGetSystemVersion() < 0x1030 )
+ MacClientToRootWindow(&point.x, &point.y);
+
+ // get column property ID (req. for call to itempartbounds)
+ DataBrowserTableViewColumnID colId = 0;
+ err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId);
+ wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
+
+ // OK, first we need to find the first visible item we have -
+ // this will be the "low" for our binary search. There is no real
+ // easy way around this, as we will need to do a SLOW linear search
+ // until we find a visible item, but we can do a cheap calculation
+ // via the row height to speed things up a bit
+ UInt32 scrollx, scrolly;
+ err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly);
+ wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));
+
+ UInt16 height;
+ err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height);
+ wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
+
+ // these indices are 0-based, as usual, so we need to add 1 to them when
+ // passing them to data browser functions which use 1-based indices
+ int low = scrolly / height,
+ high = GetCount() - 1;
+
+ // search for the first visible item (note that the scroll guess above
+ // is the low bounds of where the item might lie so we only use that as a
+ // starting point - we should reach it within 1 or 2 iterations of the loop)
+ while ( low <= high )
+ {
+ Rect bounds;
+ err = GetDataBrowserItemPartBounds(
+ m_peer->GetControlRef(), low + 1, colId,
+ kDataBrowserPropertyEnclosingPart,
+ &bounds); // note +1 to translate to Mac ID
+ if ( err == noErr )
+ break;
+
+ // errDataBrowserItemNotFound is expected as it simply means that the
+ // item is not currently visible -- but other errors are not
+ wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
+ wxT("Unexpected error from GetDataBrowserItemPartBounds") );
+
+ low++;
+ }