]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
update to wxPython module
[wxWidgets.git] / src / generic / grid.cpp
index 6f9512c5af5f266500640ecd0e3280dd933502c8..8850bc7742ff79e66edd4b5d752d9150c7c7fd67 100644 (file)
@@ -9,6 +9,8 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
 
 #include "wx/defs.h"
 
@@ -20,8 +22,6 @@
     #pragma implementation "grid.h"
 #endif
 
-// For compilers that support precompilation, includes "wx/wx.h".
-#include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
@@ -187,7 +187,7 @@ wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id,
 // this is a magic incantation which must be done!
 #include <wx/arrimpl.cpp>
 
-WX_DEFINE_OBJARRAY(wxGridStringArray);
+WX_DEFINE_OBJARRAY(wxGridStringArray)
 
 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase )
 
@@ -1860,6 +1860,14 @@ void wxGrid::OnKeyDown( wxKeyEvent& ev )
                 }
                 break;
                 
+            case WXK_PRIOR:
+                MovePageUp();
+                break;
+
+            case WXK_NEXT:
+                MovePageDown();
+                break;
+                
             default:
                 // now try the cell edit control
                 //
@@ -2021,7 +2029,7 @@ void wxGrid::ShowCellEditControl()
                     break;
             }
 
-            // m_cellEditCtrl->SetFocus();
+            m_cellEditCtrl->SetFocus();
         }
     }
 }
@@ -2040,7 +2048,10 @@ void wxGrid::SetEditControlValue( const wxString& value )
     if ( m_table )
     {
         wxString s;
-        s = ( value == wxEmptyString ? GetCellValue(m_currentCellCoords) : value );
+        if ( !value )
+            s = GetCellValue(m_currentCellCoords);
+        else
+            s = value;
 
         if ( IsTopEditControlEnabled() )
         {
@@ -2363,6 +2374,54 @@ bool wxGrid::MoveCursorRight()
     return FALSE;
 }
 
+bool wxGrid::MovePageUp()
+{
+    if ( m_currentCellCoords != wxGridNoCellCoords  &&
+         m_scrollPosY > 0 )
+    {
+        int row = m_currentCellCoords.GetRow();
+        int y = m_rowBottoms[ row ] - m_rowHeights[ row ];
+        while ( row > 0 )
+        {
+            if ( y + m_rowHeights[row-1] > m_bottom ) break;
+            y += m_rowHeights[ --row ];
+        }
+        SetVerticalScrollPos( row );
+
+        SelectCell( row, m_currentCellCoords.GetCol() );
+        return TRUE;
+    }
+    
+    return FALSE;
+}
+
+bool wxGrid::MovePageDown()
+{
+    if ( m_currentCellCoords != wxGridNoCellCoords  &&
+         m_scrollPosY + m_wholeRowsVisible < m_numRows )
+    {
+        if ( m_wholeRowsVisible > 0 )
+        {
+            SetVerticalScrollPos( m_scrollPosY + m_wholeRowsVisible );
+        }
+        else if ( m_scrollPosY < m_numRows - 1 )
+        {
+            SetVerticalScrollPos( m_scrollPosY + 1 );
+        }
+        else
+        {
+            return FALSE;
+        }
+        
+        // m_scrollPosY will have been updated
+        //
+        SelectCell( m_scrollPosY, m_currentCellCoords.GetCol() );
+        return TRUE;
+    }
+    
+    return FALSE;
+}
+
 bool wxGrid::MoveCursorUpBlock()
 {
     if ( m_table &&
@@ -3045,7 +3104,6 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                                 int horizAlign,
                                 int vertAlign )
 {
-    int i;
     long textWidth, textHeight;
     long lineWidth, lineHeight;
     wxArrayString lines;
@@ -3123,7 +3181,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
                 break;
         }
 
-        for ( i = 0;  i < lines.GetCount();  i++ )
+        for ( size_t i = 0;  i < lines.GetCount();  i++ )
         {
             dc.DrawText( lines[i], (long)x, (long)y );
             y += lineHeight;
@@ -3141,10 +3199,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
 void wxGrid::StringToLines( const wxString& value, wxArrayString& lines )
 {
     // TODO: this won't work for WXMAC ? (lines end with '\r')
-    //
+    //       => use wxTextFile functions then (VZ)
     int startPos = 0;
     int pos;
-    while ( startPos < value.Length() )
+    while ( startPos < (int)value.Length() )
     {
         pos = value.Mid(startPos).Find( '\n' );
         if ( pos < 0 )
@@ -3168,7 +3226,7 @@ void wxGrid::StringToLines( const wxString& value, wxArrayString& lines )
         }
         startPos += pos+1;
     }
-    if ( startPos < value.Length() )
+    if ( startPos < (int)value.Length() )
     {
         lines.Add( value.Mid( startPos ) );
     }
@@ -3183,7 +3241,7 @@ void wxGrid::GetTextBoxSize( wxDC& dc,
     long h = 0;
     long lineW, lineH;
 
-    int i;
+    size_t i;
     for ( i = 0;  i < lines.GetCount();  i++ )
     {
         dc.GetTextExtent( lines[i], &lineW, &lineH );
@@ -3296,8 +3354,26 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) )
         //
         if ( ok )
         {
+            if ( m_numCols == 0 ) 
+            {
+                m_table->AppendCols( WXGRID_DEFAULT_NUMBER_COLS );
+                //
+                // TODO: perhaps instead of appending the default number of cols
+                // we should remember what the last non-zero number of cols was ?
+                //
+            }
+            
+            if ( m_currentCellCoords == wxGridNoCellCoords )
+            {
+                // if we have just inserted cols into an empty grid the current
+                // cell will be undefined...
+                //
+                SelectCell( 0, 0 );  
+            }
+            
             if ( !GetBatchCount() ) Refresh();
         }
+
         SetEditControlValue();
         return ok;
     }
@@ -3319,6 +3395,14 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) )
     
     if ( m_table && m_table->AppendRows( numRows ) )
     {
+        if ( m_currentCellCoords == wxGridNoCellCoords )
+        {
+            // if we have just inserted cols into an empty grid the current
+            // cell will be undefined...
+            //
+            SelectCell( 0, 0 );  
+        }
+        
         // the table will have sent the results of the append row
         // operation to this view object as a grid table message
         //
@@ -3374,13 +3458,23 @@ bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
     {
         HideCellEditControl();
         bool ok = m_table->InsertCols( pos, numCols );
+            
+        // the table will have sent the results of the insert col
+        // operation to this view object as a grid table message
+        //
         if ( ok )
         {
-            // the table will have sent the results of the insert col
-            // operation to this view object as a grid table message
-            //
+            if ( m_currentCellCoords == wxGridNoCellCoords )
+            {
+                // if we have just inserted cols into an empty grid the current
+                // cell will be undefined...
+                //
+                SelectCell( 0, 0 );  
+            }
+
             if ( !GetBatchCount() ) Refresh();
         }
+        
         SetEditControlValue();
         return ok;
     }
@@ -3405,6 +3499,13 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) )
        // the table will have sent the results of the append col
        // operation to this view object as a grid table message
        //
+        if ( m_currentCellCoords == wxGridNoCellCoords )
+        {
+            // if we have just inserted cols into an empty grid the current
+            // cell will be undefined...
+            //
+            SelectCell( 0, 0 );  
+        }
        if ( !GetBatchCount() ) Refresh();
        return TRUE;
     }