mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
Fix wxListCtrl::GetSubItemRect(n, 0) when columns are reordered
Sum up all the preceding column widths to find the starting position of the first column, which may not be 0 if the columns have been reordered.
This commit is contained in:
+15
-3
@@ -1382,11 +1382,23 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int code)
|
||||
|
||||
wxCopyRECTToRect(rectWin, rect);
|
||||
|
||||
// there is no way to retrieve the first sub item bounding rectangle using
|
||||
// wxGetListCtrlSubItemRect() as 0 means the whole item, so we need to
|
||||
// truncate it at first column ourselves
|
||||
// We can't use wxGetListCtrlSubItemRect() for the 0th subitem as 0 means
|
||||
// the entire row for this function, so we need to calculate it ourselves.
|
||||
if ( subItem == 0 && code == wxLIST_RECT_BOUNDS )
|
||||
{
|
||||
// Because the columns can be reordered, we need to sum the widths of
|
||||
// all preceding columns to get the correct x position.
|
||||
rect.x = 0;
|
||||
for ( auto col : GetColumnsOrder() )
|
||||
{
|
||||
if ( col == 0 )
|
||||
break;
|
||||
|
||||
rect.x += GetColumnWidth(col);
|
||||
}
|
||||
|
||||
rect.width = GetColumnWidth(0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user