]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/generic/private/grid.h
Add some missing wxGraphicsContext methods
[wxWidgets.git] / include / wx / generic / private / grid.h
index b1b5e8546a78430676b82d66974165e5adf967f7..df581d4ce3e5ffc9d55eb99af16ce333dca97e6a 100644 (file)
 
 #if wxUSE_GRID
 
+// Internally used (and hence intentionally not exported) event telling wxGrid
+// to hide the currently shown editor.
+wxDECLARE_EVENT( wxEVT_GRID_HIDE_EDITOR, wxCommandEvent );
+
 // ----------------------------------------------------------------------------
 // array classes
 // ----------------------------------------------------------------------------
@@ -301,6 +305,8 @@ public:
         m_owner = owner;
     }
 
+    virtual wxWindow *GetMainWindowOfCompositeControl() { return m_owner; }
+
     virtual bool AcceptsFocus() const { return false; }
 
     wxGrid *GetOwner() { return m_owner; }
@@ -551,7 +557,7 @@ public:
     // NB: As GetLineAt(), currently this is always identity for rows.
     virtual int GetLinePos(const wxGrid *grid, int line) const = 0;
 
-    // Return the index of the line just before the given one.
+    // Return the index of the line just before the given one or wxNOT_FOUND.
     virtual int GetLineBefore(const wxGrid* grid, int line) const = 0;
 
     // Get the row or column label window
@@ -624,7 +630,7 @@ public:
         { return line; } // TODO: implement row reordering
 
     virtual int GetLineBefore(const wxGrid* WXUNUSED(grid), int line) const
-        { return line ? line - 1 : line; }
+        { return line - 1; }
 
     virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
         { return grid->GetGridRowLabelWindow(); }
@@ -690,7 +696,10 @@ public:
         { return grid->GetColPos(line); }
 
     virtual int GetLineBefore(const wxGrid* grid, int line) const
-        { return grid->GetColAt(wxMax(0, grid->GetColPos(line) - 1)); }
+    {
+        int posBefore = grid->GetColPos(line) - 1;
+        return posBefore >= 0 ? grid->GetColAt(posBefore) : wxNOT_FOUND;
+    }
 
     virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
         { return grid->GetGridColLabelWindow(); }
@@ -760,6 +769,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 +792,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 +833,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 +848,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