From: Vadim Zeitlin Date: Sat, 15 Sep 2012 23:17:57 +0000 (+0000) Subject: Fix wxGrid::PosToLinePos() in presence of hidden rows or columns. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5bce3d57015d67ddfa6700e37909c5564cf2872f Fix wxGrid::PosToLinePos() in presence of hidden rows or columns. The optimization of the binary search inside this function failed if any rows/columns were hidden and so were of zero size. See #14133. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72490 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 8e3c95fc5f..065a4a06cb 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -6502,8 +6502,8 @@ wxGridCellCoords wxGrid::XYToCell(int x, int y) const // compute row or column from some (unscrolled) coordinate value, using either // m_defaultRowHeight/m_defaultColWidth or binary search on array of -// m_rowBottoms/m_colRights to do it quickly (linear search shouldn't be used -// for large grids) +// m_rowBottoms/m_colRights to do it quickly in O(log n) time. +// NOTE: This may not work correctly for reordered columns. int wxGrid::PosToLinePos(int coord, bool clipToMinMax, const wxGridOperations& oper) const @@ -6531,26 +6531,11 @@ int wxGrid::PosToLinePos(int coord, } - // adjust maxPos before starting the binary search - if ( maxPos >= numLines ) - { - maxPos = numLines - 1; - } - else - { - if ( coord >= lineEnds[oper.GetLineAt(this, maxPos)]) - { - minPos = maxPos; - const int minDist = oper.GetMinimalAcceptableLineSize(this); - if ( minDist ) - maxPos = coord / minDist; - else - maxPos = numLines - 1; - } - - if ( maxPos >= numLines ) - maxPos = numLines - 1; - } + // binary search is quite efficient and we can't really make any assumptions + // on where to start here since row and columns could be of size 0 if they are + // hidden. While this could be made more efficient, some profiling will be + // necessary to determine if it really is a performance bottleneck + maxPos = numLines - 1; // check if the position is beyond the last column const int lineAtMaxPos = oper.GetLineAt(this, maxPos);