]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
not needed anywhere
[wxWidgets.git] / src / generic / grid.cpp
index e4559c68495211224ccb607621dc8c4a879bb0df..d1cd40d8956cb56fcafc4b6759f2ebe9bbe3ffd5 100644 (file)
 
 #if wxUSE_GRID
 
 
 #if wxUSE_GRID
 
-#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
-    #include "gridg.cpp"
-#else // wxUSE_NEW_GRID
-
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
     #include "wx/dcclient.h"
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
     #include "wx/dcclient.h"
@@ -462,7 +458,7 @@ void wxGridCellEditor::PaintBackground(const wxRect& rectCell,
     wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
     if (gridWindow)
         gridWindow->GetOwner()->PrepareDC(dc);
     wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
     if (gridWindow)
         gridWindow->GetOwner()->PrepareDC(dc);
-    
+
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
     dc.DrawRectangle(rectCell);
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
     dc.DrawRectangle(rectCell);
@@ -579,7 +575,11 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
 #endif
                               );
 
 #endif
                               );
 
-    // TODO: use m_maxChars
+    // set max length allowed in the textctrl, if the parameter was set
+    if (m_maxChars != 0)
+    {
+        ((wxTextCtrl*)m_control)->SetMaxLength(m_maxChars);
+    }
 
     wxGridCellEditor::Create(parent, id, evtHandler);
 }
 
     wxGridCellEditor::Create(parent, id, evtHandler);
 }
@@ -2065,7 +2065,7 @@ void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
     m_attrkind = wxGridCellAttr::Cell;
 
     m_sizeRows = m_sizeCols = 1;
     m_attrkind = wxGridCellAttr::Cell;
 
     m_sizeRows = m_sizeCols = 1;
-    m_overflow = TRUE;
+    m_overflow = UnsetOverflow;
 
     SetDefAttr(attrDefault);
 }
 
     SetDefAttr(attrDefault);
 }
@@ -2137,6 +2137,9 @@ void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
     if ( !HasReadWriteMode()  && mergefrom->HasReadWriteMode() )
         SetReadOnly(mergefrom->IsReadOnly());
 
     if ( !HasReadWriteMode()  && mergefrom->HasReadWriteMode() )
         SetReadOnly(mergefrom->IsReadOnly());
 
+    if (!HasOverflowMode()  && mergefrom->HasOverflowMode() )
+        SetReadOnly(mergefrom->GetOverflow());
+
     SetDefAttr(mergefrom->m_defGridAttr);
 }
 
     SetDefAttr(mergefrom->m_defGridAttr);
 }
 
@@ -3463,7 +3466,7 @@ END_EVENT_TABLE()
 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
 {
     m_owner = parent;
 }
@@ -3529,7 +3532,7 @@ END_EVENT_TABLE()
 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
 {
     m_owner = parent;
 }
@@ -3594,7 +3597,7 @@ END_EVENT_TABLE()
 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent,
                                                   wxWindowID id,
                                                   const wxPoint &pos, const wxSize &size )
 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent,
                                                   wxWindowID id,
                                                   const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
 {
     m_owner = parent;
 }
 {
     m_owner = parent;
 }
@@ -3664,7 +3667,7 @@ wxGridWindow::wxGridWindow( wxGrid *parent,
                             wxWindowID id,
                             const wxPoint &pos,
                             const wxSize &size )
                             wxWindowID id,
                             const wxPoint &pos,
                             const wxSize &size )
-            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxCLIP_CHILDREN,
+            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN,
                         wxT("grid window") )
 
 {
                         wxT("grid window") )
 
 {
@@ -3742,7 +3745,7 @@ void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
-                           bool maxOnOverflow);
+                           bool clipToMinMax);
 
 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
                                           WXGRID_MIN_COL_WIDTH, \
 
 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
                                           WXGRID_MIN_COL_WIDTH, \
@@ -4795,7 +4798,11 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
         if ( row < 0 )
         {
             row = YToRow(y);
         if ( row < 0 )
         {
             row = YToRow(y);
-            SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
+            if ( row >=0 &&
+                !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) )
+           {
+                // no default action at the moment
+           }
         }
         else
         {
         }
         else
         {
@@ -4832,7 +4839,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDown() )
     {
         row = YToRow(y);
     else if ( event.RightDown() )
     {
         row = YToRow(y);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
+        if ( row >=0 &&
+           !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
         {
             // no default action at the moment
         }
         {
             // no default action at the moment
         }
@@ -4844,7 +4852,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDClick() )
     {
         row = YToRow(y);
     else if ( event.RightDClick() )
     {
         row = YToRow(y);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
+        if ( row >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
         {
             // no default action at the moment
         }
         {
             // no default action at the moment
         }
@@ -5010,7 +5019,11 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         if ( col < 0 )
         {
             col = XToCol(x);
         if ( col < 0 )
         {
             col = XToCol(x);
-            SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
+            if ( col >= 0 &&
+                 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) )
+            {
+               // no default action at the moment
+            }
         }
         else
         {
         }
         else
         {
@@ -5047,7 +5060,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDown() )
     {
         col = XToCol(x);
     else if ( event.RightDown() )
     {
         col = XToCol(x);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
+        if ( col >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
         {
             // no default action at the moment
         }
         {
             // no default action at the moment
         }
@@ -5059,7 +5073,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
     else if ( event.RightDClick() )
     {
         col = XToCol(x);
     else if ( event.RightDClick() )
     {
         col = XToCol(x);
-        if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
+        if ( col >= 0 &&
+            !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
         {
             // no default action at the moment
         }
         {
             // no default action at the moment
         }
@@ -5410,15 +5425,28 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
     {
         if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
         {
     {
         if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
         {
-            if ( m_selectingTopLeft != wxGridNoCellCoords &&
-                 m_selectingBottomRight != wxGridNoCellCoords )
+            if (m_winCapture)
             {
             {
-                if (m_winCapture)
-                {
-                    if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
-                    m_winCapture = NULL;
-                }
+                if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
+                m_winCapture = NULL;
+            }
+
+            if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl())
+            {
+                ClearSelection();
+                EnableCellEditControl();
+
+                wxGridCellAttr* attr = GetCellAttr(coords);
+                wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
+                editor->StartingClick();
+                editor->DecRef();
+                attr->DecRef();
 
 
+                m_waitForSlowClick = FALSE;
+            }
+            else if ( m_selectingTopLeft != wxGridNoCellCoords &&
+                 m_selectingBottomRight != wxGridNoCellCoords )
+            {
                 if ( m_selection )
                 {
                     m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
                 if ( m_selection )
                 {
                     m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
@@ -5438,21 +5466,6 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 // drag-shrinking.
                 ShowCellEditControl();
             }
                 // drag-shrinking.
                 ShowCellEditControl();
             }
-            else
-            {
-              if( m_waitForSlowClick && CanEnableCellControl())
-              {
-                EnableCellEditControl();
-
-                wxGridCellAttr* attr = GetCellAttr(coords);
-                wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
-                editor->StartingClick();
-                editor->DecRef();
-                attr->DecRef();
-
-                m_waitForSlowClick = FALSE;
-              }
-            }
         }
         else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
         {
         }
         else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
         {
@@ -5608,10 +5621,9 @@ void wxGrid::DoEndDragResizeRow()
             {
                 int i, cell_rows, cell_cols, subtract_rows = 0;
                 int leftCol = XToCol(left);
             {
                 int i, cell_rows, cell_cols, subtract_rows = 0;
                 int leftCol = XToCol(left);
-                int rightCol = XToCol(left+cw);
+                int rightCol = internalXToCol(left+cw);
                 if (leftCol >= 0)
                 {
                 if (leftCol >= 0)
                 {
-                    if (rightCol < 0) rightCol = m_numCols;
                     for (i=leftCol; i<rightCol; i++)
                     {
                         GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
                     for (i=leftCol; i<rightCol; i++)
                     {
                         GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
@@ -5668,10 +5680,9 @@ void wxGrid::DoEndDragResizeCol()
             {
                 int i, cell_rows, cell_cols, subtract_cols = 0;
                 int topRow = YToRow(top);
             {
                 int i, cell_rows, cell_cols, subtract_cols = 0;
                 int topRow = YToRow(top);
-                int bottomRow = YToRow(top+cw);
+                int bottomRow = internalYToRow(top+cw);
                 if (topRow >= 0)
                 {
                 if (topRow >= 0)
                 {
-                    if (bottomRow < 0) bottomRow = m_numRows;
                     for (i=topRow; i<bottomRow; i++)
                     {
                         GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
                     for (i=topRow; i<bottomRow; i++)
                     {
                         GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
@@ -6917,37 +6928,32 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
     bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
 
     // no gridlines inside multicells, clip them out
     bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
 
     // no gridlines inside multicells, clip them out
-    int leftCol   = XToCol(left);
-    int topRow    = YToRow(top);
-    int rightCol  = XToCol(right);
-    int bottomRow = YToRow(bottom);
+    int leftCol   = internalXToCol(left);
+    int topRow    = internalYToRow(top);
+    int rightCol  = internalXToCol(right);
+    int bottomRow = internalYToRow(bottom);
     wxRegion clippedcells(0, 0, cw, ch);
 
     wxRegion clippedcells(0, 0, cw, ch);
 
-    if ((leftCol >= 0) && (topRow >= 0))
-    {
-        if (rightCol  < 0) rightCol  = m_numCols;
-        if (bottomRow < 0) bottomRow = m_numRows;
 
 
-        int i, j, cell_rows, cell_cols;
-        wxRect rect;
+    int i, j, cell_rows, cell_cols;
+    wxRect rect;
 
 
-        for (j=topRow; j<bottomRow; j++)
+    for (j=topRow; j<bottomRow; j++)
+    {
+        for (i=leftCol; i<rightCol; i++)
         {
         {
-            for (i=leftCol; i<rightCol; i++)
+            GetCellSize( j, i, &cell_rows, &cell_cols );
+            if ((cell_rows > 1) || (cell_cols > 1))
             {
             {
-                GetCellSize( j, i, &cell_rows, &cell_cols );
-                if ((cell_rows > 1) || (cell_cols > 1))
-                {
-                    rect = CellToRect(j,i);
-                    CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
-                    clippedcells.Subtract(rect);
-                }
-                else if ((cell_rows < 0) || (cell_cols < 0))
-                {
-                    rect = CellToRect(j+cell_rows, i+cell_cols);
-                    CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
-                    clippedcells.Subtract(rect);
-                }
+                rect = CellToRect(j,i);
+                CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+                clippedcells.Subtract(rect);
+            }
+            else if ((cell_rows < 0) || (cell_cols < 0))
+            {
+                rect = CellToRect(j+cell_rows, i+cell_cols);
+                CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+                clippedcells.Subtract(rect);
             }
         }
     }
             }
         }
     }
@@ -6957,7 +6963,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
 
     // horizontal grid lines
     //
 
     // horizontal grid lines
     //
-    int i;
+    // already declared above - int i;
     for ( i = internalYToRow(top); i < m_numRows; i++ )
     {
         int bot = GetRowBottom(i) - 1;
     for ( i = internalYToRow(top); i < m_numRows; i++ )
     {
         int bot = GetRowBottom(i) - 1;
@@ -7102,10 +7108,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                                 int textOrientation )
 {
     wxArrayString lines;
                                 int textOrientation )
 {
     wxArrayString lines;
-    
+
     StringToLines( value, lines );
     StringToLines( value, lines );
-    
-    
+
+
     //Forward to new API.
     DrawTextRectangle(  dc,
         lines,
     //Forward to new API.
     DrawTextRectangle(  dc,
         lines,
@@ -7113,7 +7119,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
         horizAlign,
         vertAlign,
         textOrientation );
         horizAlign,
         vertAlign,
         textOrientation );
-    
+
 }
 
 void wxGrid::DrawTextRectangle( wxDC& dc,
 }
 
 void wxGrid::DrawTextRectangle( wxDC& dc,
@@ -7126,20 +7132,20 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
     long textWidth, textHeight;
     long lineWidth, lineHeight;
     int nLines;
     long textWidth, textHeight;
     long lineWidth, lineHeight;
     int nLines;
-    
+
     dc.SetClippingRegion( rect );
     dc.SetClippingRegion( rect );
-    
+
     nLines = lines.GetCount();
     if( nLines > 0 )
     {
         int l;
         float x = 0.0, y = 0.0;
     nLines = lines.GetCount();
     if( nLines > 0 )
     {
         int l;
         float x = 0.0, y = 0.0;
-        
+
         if( textOrientation == wxHORIZONTAL )
             GetTextBoxSize(dc, lines, &textWidth, &textHeight);
         else
             GetTextBoxSize( dc, lines, &textHeight, &textWidth );
         if( textOrientation == wxHORIZONTAL )
             GetTextBoxSize(dc, lines, &textWidth, &textHeight);
         else
             GetTextBoxSize( dc, lines, &textHeight, &textWidth );
-        
+
         switch( vertAlign )
         {
         case wxALIGN_BOTTOM:
         switch( vertAlign )
         {
         case wxALIGN_BOTTOM:
@@ -7148,14 +7154,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
             else
                 x = rect.x + rect.width - textWidth;
             break;
             else
                 x = rect.x + rect.width - textWidth;
             break;
-            
+
         case wxALIGN_CENTRE:
             if( textOrientation == wxHORIZONTAL )
                 y = rect.y + ((rect.height - textHeight)/2);
             else
                 x = rect.x + ((rect.width - textWidth)/2);
             break;
         case wxALIGN_CENTRE:
             if( textOrientation == wxHORIZONTAL )
                 y = rect.y + ((rect.height - textHeight)/2);
             else
                 x = rect.x + ((rect.width - textWidth)/2);
             break;
-            
+
         case wxALIGN_TOP:
         default:
             if( textOrientation == wxHORIZONTAL )
         case wxALIGN_TOP:
         default:
             if( textOrientation == wxHORIZONTAL )
@@ -7164,12 +7170,12 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                 x = rect.x + 1;
             break;
         }
                 x = rect.x + 1;
             break;
         }
-        
+
         // Align each line of a multi-line label
         for( l = 0; l < nLines; l++ )
         {
             dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
         // Align each line of a multi-line label
         for( l = 0; l < nLines; l++ )
         {
             dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
-            
+
             switch( horizAlign )
             {
             case wxALIGN_RIGHT:
             switch( horizAlign )
             {
             case wxALIGN_RIGHT:
@@ -7178,14 +7184,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                 else
                     y = rect.y + lineWidth + 1;
                 break;
                 else
                     y = rect.y + lineWidth + 1;
                 break;
-                
+
             case wxALIGN_CENTRE:
                 if( textOrientation == wxHORIZONTAL )
                     x = rect.x + ((rect.width - lineWidth)/2);
                 else
                     y = rect.y + rect.height - ((rect.height - lineWidth)/2);
                 break;
             case wxALIGN_CENTRE:
                 if( textOrientation == wxHORIZONTAL )
                     x = rect.x + ((rect.width - lineWidth)/2);
                 else
                     y = rect.y + rect.height - ((rect.height - lineWidth)/2);
                 break;
-                
+
             case wxALIGN_LEFT:
             default:
                 if( textOrientation == wxHORIZONTAL )
             case wxALIGN_LEFT:
             default:
                 if( textOrientation == wxHORIZONTAL )
@@ -7194,7 +7200,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                     y = rect.y + rect.height - 1;
                 break;
             }
                     y = rect.y + rect.height - 1;
                 break;
             }
-            
+
             if( textOrientation == wxHORIZONTAL )
             {
                 dc.DrawText( lines[l], (int)x, (int)y );
             if( textOrientation == wxHORIZONTAL )
             {
                 dc.DrawText( lines[l], (int)x, (int)y );
@@ -7598,10 +7604,16 @@ void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords )
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
                            const wxArrayInt& BorderArray, int nMax,
-                           bool maxOnOverflow)
+                           bool clipToMinMax)
 {
 {
+
+    if (coord < 0)
+        return clipToMinMax && (nMax > 0) ? 0 : -1;
+
+
     if (!defaultDist)
         defaultDist = 1;
     if (!defaultDist)
         defaultDist = 1;
+
     size_t i_max = coord / defaultDist,
            i_min = 0;
 
     size_t i_max = coord / defaultDist,
            i_min = 0;
 
@@ -7609,7 +7621,7 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
     {
         if((int) i_max < nMax)
             return i_max;
     {
         if((int) i_max < nMax)
             return i_max;
-        return maxOnOverflow ? nMax - 1 : -1;
+        return clipToMinMax ? nMax - 1 : -1;
     }
 
     if ( i_max >= BorderArray.GetCount())
     }
 
     if ( i_max >= BorderArray.GetCount())
@@ -7625,7 +7637,7 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
             i_max = BorderArray.GetCount() - 1;
     }
     if ( coord >= BorderArray[i_max])
             i_max = BorderArray.GetCount() - 1;
     }
     if ( coord >= BorderArray[i_max])
-        return maxOnOverflow ? (int)i_max : -1;
+        return clipToMinMax ? (int)i_max : -1;
     if ( coord < BorderArray[0] )
         return 0;
 
     if ( coord < BorderArray[0] )
         return 0;
 
@@ -8001,13 +8013,11 @@ bool wxGrid::MovePageUp()
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
-        int newRow = YToRow( y - ch + 1 );
-        if ( newRow == -1 )
-        {
-            newRow = 0;
-        }
-        else if ( newRow == row )
+        int newRow = internalYToRow( y - ch + 1 );
+
+        if ( newRow == row )
         {
         {
+           //row > 0 , so newrow can never be less than 0 here.
             newRow = row - 1;
         }
 
             newRow = row - 1;
         }
 
@@ -8025,20 +8035,17 @@ bool wxGrid::MovePageDown()
     if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE;
 
     int row = m_currentCellCoords.GetRow();
     if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE;
 
     int row = m_currentCellCoords.GetRow();
-    if ( row < m_numRows )
+    if ( (row+1) < m_numRows )
     {
         int cw, ch;
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
     {
         int cw, ch;
         m_gridWin->GetClientSize( &cw, &ch );
 
         int y = GetRowTop(row);
-        int newRow = YToRow( y + ch );
-        if ( newRow == -1 )
+        int newRow = internalYToRow( y + ch );
+        if ( newRow == row )
         {
         {
-            newRow = m_numRows - 1;
-        }
-        else if ( newRow == row )
-        {
-            newRow = row + 1;
+            // row < m_numRows , so newrow can't overflow here.
+           newRow = row + 1;
         }
 
         MakeCellVisible( newRow, m_currentCellCoords.GetCol() );
         }
 
         MakeCellVisible( newRow, m_currentCellCoords.GetCol() );
@@ -10031,7 +10038,5 @@ wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id, wxEventType type,
     m_ctrl = ctrl;
 }
 
     m_ctrl = ctrl;
 }
 
-
-#endif // !wxUSE_NEW_GRID/wxUSE_NEW_GRID
-
 #endif // wxUSE_GRID
 #endif // wxUSE_GRID
+