From ae0cc9fa1015f4ed05344da5e4cf7952963b333b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 May 2014 22:11:46 +0000 Subject: [PATCH] Fix position of the column after drag-move operation in wxGrid. Fix the logic for finding the correct position to drop the column at when ending a drag move operation. The old code dropped it one position too far to the left when it was dropped on the "far" (i.e. right with LTR layout) part of the target column. See #16110. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76446 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/grid.cpp | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 188c4b821e..e292e452ba 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3724,29 +3724,31 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event ) // get the position of the column we're over int pos = XToPos(x); - // we may need to adjust the drop position but don't bother - // checking for it if we can't anyhow - if ( pos > 1 ) - { - // also find the index of the column we're over: notice - // that the existing "col" variable may be invalid but - // we need a valid one here - const int colValid = GetColAt(pos); + // insert the column being dragged either before or after + // it, depending on where exactly it was dropped, so + // find the index of the column we're over: notice + // that the existing "col" variable may be invalid but + // we need a valid one here + const int colValid = GetColAt(pos); - // if we're on the "near" (usually left but right in - // RTL case) part of the column, the actual position we - // should be placed in is actually the one before it - bool onNearPart; - const int middle = GetColLeft(colValid) + - GetColWidth(colValid)/2; - if ( GetLayoutDirection() == wxLayout_LeftToRight ) - onNearPart = (x <= middle); - else // wxLayout_RightToLeft - onNearPart = (x > middle); + // and check if we're on the "near" (usually left but right + // in RTL case) part of the column + bool onNearPart; + const int middle = GetColLeft(colValid) + + GetColWidth(colValid)/2; + if ( GetLayoutDirection() == wxLayout_LeftToRight ) + onNearPart = (x <= middle); + else // wxLayout_RightToLeft + onNearPart = (x > middle); - if ( onNearPart ) - pos--; - } + // adjust for the column being dragged itself + if ( pos < GetColPos(m_dragRowOrCol) ) + pos++; + + // and if it's on the near part of the target column, + // insert it before it, not after + if ( onNearPart ) + pos--; DoEndMoveCol(pos); }