]> git.saurik.com Git - wxWidgets.git/commitdiff
Drop the column being dragged at the correct position in wxGrid.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 3 Jun 2010 10:35:53 +0000 (10:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 3 Jun 2010 10:35:53 +0000 (10:35 +0000)
The column was being always dropped after the column at drop position but this
was incorrect and didn't correspond to the visual feedback drawn by
wxHeaderCtrl: if the drop position is over the "near" part of the column, the
column should be dropped before it instead.

Do the check for this in wxGrid code too now.

Closes #12120.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/grid.cpp

index 315fbda05d02276e0e0a84710e0eab4e697ddd27..074490df823e2334fd7d47e9d5fc66fec2fefee4 100644 (file)
@@ -3469,7 +3469,34 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
                 }
                 else
                 {
                 }
                 else
                 {
-                    DoEndMoveCol(XToPos(x));
+                    // 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);
+
+                        // 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 near;
+                        const int middle = GetColLeft(colValid) +
+                                                GetColWidth(colValid)/2;
+                        if ( GetLayoutDirection() == wxLayout_LeftToRight )
+                            near = x <= middle;
+                        else // wxLayout_RightToLeft
+                            near = x > middle;
+
+                        if ( near )
+                            pos--;
+                    }
+
+                    DoEndMoveCol(pos);
                 }
                 break;
 
                 }
                 break;