]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix keyboard navigation in wxGrid with hidden columns.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 19 Jul 2011 22:35:37 +0000 (22:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 19 Jul 2011 22:35:37 +0000 (22:35 +0000)
The hidden columns (i.e. those whose size was set to 0) should be skipped when
find the previous/next column to select when the user presses Left/Right
cursor arrow keys in wxGrid, otherwise the focus could completely disappear as
it was invisible when it was set to a hidden column.

Closes #13281.

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

docs/changes.txt
include/wx/generic/private/grid.h

index bd4bc0f8db35a453265d0c0f046572e2104a86be..22a7ec3bdcd4ca55a59654a16b26f66780c30519 100644 (file)
@@ -440,6 +440,7 @@ Major new features in this release
 All (GUI):
 
 - Support float, double and file name values in wxGenericValidator (troelsk).
+- Fix keyboard navigation in wxGrid with hidden columns (ivan_14_32).
 
 OSX:
 
index b1b5e8546a78430676b82d66974165e5adf967f7..b1eb3a7adf63ed66adf62d5fb8f242796afaa497 100644 (file)
@@ -760,6 +760,12 @@ protected:
         return m_oper.GetLineAt(m_grid, pos);
     }
 
+    // Check if the given line is visible, i.e. has non 0 size.
+    bool IsLineVisible(int line) const
+    {
+        return m_oper.GetLineSize(m_grid, line) != 0;
+    }
+
 
     wxGrid * const m_grid;
     const wxGridOperations& m_oper;
@@ -777,14 +783,38 @@ public:
     {
         wxASSERT_MSG( m_oper.Select(coords) >= 0, "invalid row/column" );
 
-        return GetLinePos(coords) == 0;
+        int pos = GetLinePos(coords);
+        while ( pos )
+        {
+            // Check the previous line.
+            int line = GetLineAt(--pos);
+            if ( IsLineVisible(line) )
+            {
+                // There is another visible line before this one, hence it's
+                // not at boundary.
+                return false;
+            }
+        }
+
+        // We reached the boundary without finding any visible lines.
+        return true;
     }
 
     virtual void Advance(wxGridCellCoords& coords) const
     {
-        wxASSERT( !IsAtBoundary(coords) );
-
-        m_oper.Set(coords, GetLineAt(GetLinePos(coords) - 1));
+        int pos = GetLinePos(coords);
+        for ( ;; )
+        {
+            // This is not supposed to happen if IsAtBoundary() returned false.
+            wxCHECK_RET( pos, "can't advance when already at boundary" );
+
+            int line = GetLineAt(--pos);
+            if ( IsLineVisible(line) )
+            {
+                m_oper.Set(coords, line);
+                break;
+            }
+        }
     }
 
     virtual int MoveByPixelDistance(int line, int distance) const
@@ -794,6 +824,8 @@ public:
     }
 };
 
+// Please refer to the comments above when reading this class code, it's
+// absolutely symmetrical to wxGridBackwardOperations.
 class wxGridForwardOperations : public wxGridDirectionOperations
 {
 public:
@@ -807,14 +839,32 @@ public:
     {
         wxASSERT_MSG( m_oper.Select(coords) < m_numLines, "invalid row/column" );
 
-        return GetLinePos(coords) == m_numLines - 1;
+        int pos = GetLinePos(coords);
+        while ( pos < m_numLines - 1 )
+        {
+            int line = GetLineAt(++pos);
+            if ( IsLineVisible(line) )
+                return false;
+        }
+
+        return true;
     }
 
     virtual void Advance(wxGridCellCoords& coords) const
     {
-        wxASSERT( !IsAtBoundary(coords) );
-
-        m_oper.Set(coords, GetLineAt(GetLinePos(coords) + 1));
+        int pos = GetLinePos(coords);
+        for ( ;; )
+        {
+            wxCHECK_RET( pos < m_numLines - 1,
+                         "can't advance when already at boundary" );
+
+            int line = GetLineAt(++pos);
+            if ( IsLineVisible(line) )
+            {
+                m_oper.Set(coords, line);
+                break;
+            }
+        }
     }
 
     virtual int MoveByPixelDistance(int line, int distance) const