]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/gridg.cpp
reduced flicker when switching focus to/from the report list ctrl under wxGTK
[wxWidgets.git] / src / generic / gridg.cpp
index db89849d024315e861f69f9a7b010ca7c64ec193..3f28058a1496222d581cf42e55bc20b020b0a110 100644 (file)
@@ -2,46 +2,85 @@
 // Name:        gridg.cpp
 // Purpose:     wxGenericGrid
 // Author:      Julian Smart
-// Modified by: Michael Bedward 20 Apr 1999
-//                Added edit in place facility
+// Modified by: Michael Bedward
+//                Added edit in place facility, 20 Apr 1999
+//                Added cursor key control, 29 Jun 1999
+//              Gerhard Gruber
+//                Added keyboard navigation, client data, other fixes
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:    wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
-#pragma implementation "gridg.h"
-#pragma interface
+    #pragma implementation "gridg.h"
+    #pragma interface
 #endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
+#if wxUSE_GRID
+
 #ifndef WX_PRECOMP
-  #include "wx/utils.h"
-  #include "wx/dcclient.h"
-  #include "wx/dcmemory.h"
-  #include "wx/textctrl.h"
+    #include "wx/utils.h"
+    #include "wx/dcclient.h"
+    #include "wx/dcmemory.h"
+    #include "wx/textctrl.h"
+    #include "wx/settings.h"
 #endif
 
 #include <string.h>
 
 #include "wx/string.h"
+
 #include "wx/generic/gridg.h"
-#include "wx/settings.h"
 
-// Set to zero to use no double-buffering
+
+// Values used to adjust the size of the in-place-edit control, and other
+// goodies.  Per-platform tweaks should be done here.
 #ifdef __WXMSW__
-    #define wxUSE_DOUBLE_BUFFERING 1
-#else
-    #define wxUSE_DOUBLE_BUFFERING 0
+#define wxIPE_ADJUST            -2
+#define wxIPE_STYLE             wxNO_BORDER
+#define wxIPE_HIGHLIGHT         1
+#define wxUSE_DOUBLE_BUFFERING  1
+#endif
+
+#ifdef __WXPM__
+#define wxIPE_ADJUST            -1
+#define wxIPE_STYLE             wxNO_BORDER
+#define wxIPE_HIGHLIGHT         1
+#define wxUSE_DOUBLE_BUFFERING  1
+#endif
+
+#ifdef __WXGTK__
+#define wxIPE_ADJUST            -1
+#define wxIPE_STYLE             wxNO_BORDER
+#define wxIPE_HIGHLIGHT         0
+#define wxUSE_DOUBLE_BUFFERING  1
+#endif
+
+#ifdef __WXMOTIF__
+#define wxIPE_ADJUST            2
+#define wxIPE_STYLE             wxNO_BORDER
+#define wxIPE_HIGHLIGHT         0
+#define wxUSE_DOUBLE_BUFFERING  0
 #endif
 
+#ifndef wxIPE_ADJUST
+#define wxIPE_ADJUST            2
+#define wxIPE_STYLE             wxNO_BORDER
+#define wxIPE_HIGHLIGHT         0
+#define wxUSE_DOUBLE_BUFFERING  0
+#endif
+
+
+
 #define wxGRID_DRAG_NONE       0
 #define wxGRID_DRAG_LEFT_RIGHT 1
 #define wxGRID_DRAG_UP_DOWN    2
@@ -56,6 +95,8 @@ BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel)
     EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
     EVT_TEXT(wxGRID_TEXT_CTRL, wxGenericGrid::OnText)
     EVT_TEXT(wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxGenericGrid::OnTextInPlace)
+    EVT_TEXT_ENTER(wxGRID_TEXT_CTRL, wxGenericGrid::OnTextEnter)
+    EVT_TEXT_ENTER(wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxGenericGrid::OnTextInPlaceEnter)
     EVT_COMMAND_SCROLL(wxGRID_HSCROLL, wxGenericGrid::OnGridScroll)
     EVT_COMMAND_SCROLL(wxGRID_VSCROLL, wxGenericGrid::OnGridScroll)
 
@@ -73,8 +114,10 @@ BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel)
 END_EVENT_TABLE()
 
 
-wxGenericGrid::wxGenericGrid(void)
+wxGenericGrid::wxGenericGrid()
 {
+  m_viewWidth = 0;
+  m_viewHeight = 0;
   m_batchCount = 0;
   m_hScrollBar = (wxScrollBar *) NULL;
   m_vScrollBar = (wxScrollBar *) NULL;
@@ -90,9 +133,10 @@ wxGenericGrid::wxGenericGrid(void)
   m_currentRectVisible = FALSE;
   m_editable = TRUE;
 
-  m_editInPlace = TRUE;
+  m_editInPlace = FALSE;
   m_inOnTextInPlace = FALSE;
-  
+  m_inScroll = FALSE;
+
 #if defined(__WIN95__)
   m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
 #elif defined(__WXGTK__)
@@ -105,6 +149,7 @@ wxGenericGrid::wxGenericGrid(void)
   m_dragStartPosition = 0;
   m_dragLastPosition = 0;
   m_divisionPen = wxNullPen;
+  m_highlightPen = wxNullPen;
   m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT;
   m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP;
   m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT;
@@ -133,9 +178,15 @@ wxGenericGrid::wxGenericGrid(void)
   m_textItem = (wxTextCtrl *) NULL;
 }
 
-bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
- long style, const wxString& name)
+bool wxGenericGrid::Create(wxWindow *parent,
+                           wxWindowID id,
+                           const wxPoint& pos,
+                           const wxSize& size,
+                           long style,
+                           const wxString& name)
 {
+  m_viewWidth = 0;
+  m_viewHeight = 0;
   m_batchCount = 0;
   m_editingPanel = (wxPanel *) NULL;
   m_hScrollBar = (wxScrollBar *) NULL;
@@ -151,6 +202,9 @@ bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
   m_textItem = (wxTextCtrl *) NULL;
   m_currentRectVisible = FALSE;
   m_editable = TRUE;
+  m_editInPlace = FALSE;
+  m_inOnTextInPlace = FALSE;
+  m_inScroll = FALSE;
 #if defined(__WIN95__)
   m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
 #elif defined(__WXGTK__)
@@ -163,6 +217,7 @@ bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
   m_dragStartPosition = 0;
   m_dragLastPosition = 0;
   m_divisionPen = * wxThePenList->FindOrCreatePen("LIGHT GREY", 1, wxSOLID);
+  m_highlightPen = * wxBLACK_PEN;
   m_doubleBufferingBitmap = (wxBitmap *) NULL;
 
   if (!m_horizontalSashCursor.Ok())
@@ -215,7 +270,7 @@ bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
   m_textItem = new wxTextCtrl(m_editingPanel, wxGRID_TEXT_CTRL, "",
                               wxPoint(m_editControlPosition.x, m_editControlPosition.y),
                               wxSize(m_editControlPosition.width, -1),
-                              0);
+                              wxTE_PROCESS_ENTER);
   m_textItem->Show(TRUE);
   m_textItem->SetFocus();
   int controlW, controlH;
@@ -233,21 +288,22 @@ bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
 //  SetSize(pos.x, pos.y, size.x, size.y);
 
   m_inPlaceTextItem = new wxTextCtrl( (wxPanel*)this, wxGRID_EDIT_IN_PLACE_TEXT_CTRL, "",
-                                     wxPoint( m_currentRect.x-2, m_currentRect.y-2 ), 
-                                     wxSize( m_currentRect.width+4, m_currentRect.height+4 ), 
-                                     wxNO_BORDER );
-  m_inPlaceTextItem->Show(TRUE);
-  m_inPlaceTextItem->SetFocus();
-  
+                                      wxPoint( m_currentRect.x-wxIPE_ADJUST, m_currentRect.y-wxIPE_ADJUST ),
+                                      wxSize( m_currentRect.width+wxIPE_ADJUST*2, m_currentRect.height+wxIPE_ADJUST*2 ),
+                                      wxNO_BORDER | wxTE_PROCESS_ENTER );
+  m_inPlaceTextItem->Show(m_editInPlace);
+  if ( m_editInPlace )
+    m_inPlaceTextItem->SetFocus();
+
   return TRUE;
 }
 
-wxGenericGrid::~wxGenericGrid(void)
+wxGenericGrid::~wxGenericGrid()
 {
   ClearGrid();
 }
 
-void wxGenericGrid::ClearGrid(void)
+void wxGenericGrid::ClearGrid()
 {
   int i,j;
   if (m_gridCells)
@@ -376,7 +432,7 @@ bool wxGenericGrid::CreateGrid(int nRows, int nCols, wxString **cellValues, shor
 }
 
 // Need to determine various dimensions
-void wxGenericGrid::UpdateDimensions(void)
+void wxGenericGrid::UpdateDimensions()
 {
   int canvasWidth, canvasHeight;
   GetSize(&canvasWidth, &canvasHeight);
@@ -529,8 +585,8 @@ void wxGenericGrid::PaintGrid(wxDC& dc)
 
     /* Hilight present cell */
     SetCurrentRect(m_wCursorRow, m_wCursorColumn);
-    if (m_currentRectVisible && !(m_editable && m_editInPlace))
-      HighlightCell(& dc);
+    if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace)))
+      HighlightCell(& dc, TRUE);
 
     dc.DestroyClippingRegion();
     dc.SetOptimization(TRUE);
@@ -800,8 +856,8 @@ void wxGenericGrid::DrawColumnLabel(wxDC *dc, wxRect *rect, int col)
     rect2.height -= 4;
     dc->SetTextForeground(GetLabelTextColour());
     dc->SetFont(GetLabelTextFont());
-       if ( !cell->GetTextValue().IsNull() )
-       DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxHORIZONTAL));
+        if ( !cell->GetTextValue().IsNull() )
+            DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxHORIZONTAL));
   }
 }
 
@@ -853,8 +909,8 @@ void wxGenericGrid::DrawRowLabel(wxDC *dc, wxRect *rect, int row)
     rect2.height -= 4;
     dc->SetTextForeground(GetLabelTextColour());
     dc->SetFont(GetLabelTextFont());
-       if ( !cell->GetTextValue().IsNull() )
-       DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxVERTICAL));
+        if ( !cell->GetTextValue().IsNull() )
+            DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxVERTICAL));
   }
 }
 
@@ -931,13 +987,13 @@ void wxGenericGrid::DrawCellValue(wxDC *dc, wxRect *rect, int row, int col)
       dc->SetTextForeground(cell->GetTextColour());
       dc->SetFont(cell->GetFont());
 
-         if ( !cell->GetTextValue().IsNull() )
-       DrawTextRect(dc, cell->GetTextValue(), &rect2, cell->GetAlignment());
+          if ( !cell->GetTextValue().IsNull() )
+              DrawTextRect(dc, cell->GetTextValue(), &rect2, cell->GetAlignment());
     }
   }
 }
 
-void wxGenericGrid::AdjustScrollbars(void)
+void wxGenericGrid::AdjustScrollbars()
 {
   int cw, ch;
   GetClientSize(&cw, &ch);
@@ -962,56 +1018,53 @@ void wxGenericGrid::AdjustScrollbars(void)
   int noHorizSteps = 0;
   int noVertSteps = 0;
 
-  if (m_totalGridWidth + vertScrollBarWidth <= cw)
-    noHorizSteps = 0;
-  else
+  if (m_totalGridWidth + vertScrollBarWidth > cw)
   {
-    noHorizSteps = 0;
     int widthCount = 0;
 
     int i;
-       int nx = 0;
+    int nx = 0;
     for (i = m_scrollPosX ; i < m_totalCols; i++)
     {
       widthCount += m_colWidths[i];
-         // A partial bit doesn't count, we still have to scroll to see the
-         // rest of it
+      // A partial bit doesn't count, we still have to scroll to see the
+      // rest of it
       if (widthCount + m_leftOfSheet + m_verticalLabelWidth > (cw-vertScrollBarWidth))
         break;
-         else
-           nx ++;
-
+      else
+           nx ++;
     }
 
     noHorizSteps += nx;
   }
-  if (m_totalGridHeight + horizScrollBarHeight <= ch)
-    noVertSteps = 0;
-  else
+  m_viewWidth = noHorizSteps;
+
+  if (m_totalGridHeight + horizScrollBarHeight > ch)
   {
-    noVertSteps = 0;
     int heightCount = 0;
 
     int i;
-       int ny = 0;
+    int ny = 0;
     for (i = m_scrollPosY ; i < m_totalRows; i++)
     {
       heightCount += m_rowHeights[i];
-         // A partial bit doesn't count, we still have to scroll to see the
-         // rest of it
+      // A partial bit doesn't count, we still have to scroll to see the
+      // rest of it
       if (heightCount + m_topOfSheet + m_horizontalLabelHeight > (ch-horizScrollBarHeight))
         break;
-         else
-           ny ++;
+      else
+        ny ++;
     }
 
     noVertSteps += ny;
   }
 
+  m_viewHeight = noVertSteps;
+
   if (m_totalGridWidth + vertScrollBarWidth <= cw)
   {
-       if ( m_hScrollBar )
-       m_hScrollBar->Show(FALSE);
+    if ( m_hScrollBar )
+        m_hScrollBar->Show(FALSE);
     SetScrollPosX(0);
   }
   else
@@ -1068,7 +1121,7 @@ void wxGenericGrid::AdjustScrollbars(void)
 void wxGenericGrid::OnSize(wxSizeEvent& WXUNUSED(event) )
 {
   if (!m_vScrollBar || !m_hScrollBar)
-         return;
+          return;
 
   AdjustScrollbars();
 
@@ -1350,7 +1403,7 @@ void wxGenericGrid::OnMouseEvent(wxMouseEvent& ev)
         SetCursor(*wxSTANDARD_CURSOR);
         int cw, ch;
         GetClientSize(&cw, &ch);
-               wxSizeEvent evt;
+                wxSizeEvent evt;
         OnSize(evt);
         break;
       }
@@ -1412,21 +1465,21 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col)
   SetGridClippingRegion(dc);
 
   // Remove the highlight from the old cell
-  if ( m_currentRectVisible && !(m_editable && m_editInPlace) )
+  if ( m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace)))
     {
-      HighlightCell(dc);
+      HighlightCell(dc, FALSE);
     }
-  
+
 
   // Highlight the new cell and copy its content to the edit control
   SetCurrentRect(m_wCursorRow, m_wCursorColumn);
   wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn);
   if (cell)
   {
-       if ( cell->GetTextValue().IsNull() )
-               m_textItem->SetValue("");
-       else
-       m_textItem->SetValue(cell->GetTextValue());
+        if ( cell->GetTextValue().IsNull() )
+                m_textItem->SetValue("");
+        else
+            m_textItem->SetValue(cell->GetTextValue());
   }
 
   SetGridClippingRegion(dc);
@@ -1434,37 +1487,69 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col)
 
   if ( m_editable && m_editInPlace )
     {
-      m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2, 
-                                 m_currentRect.width+4, m_currentRect.height+4 );
-
-      if ( cell )
-       {
-         if ( cell->GetTextValue().IsNull() )
-           {
-             m_inPlaceTextItem->SetValue( "" );
-           }
-         else
-           {
-             m_inPlaceTextItem->SetFont( cell->GetFont() );
-             m_inPlaceTextItem->SetValue( cell->GetTextValue() );
-           }
-       }
-      
+      int x, y, width, height;
+      if ( m_currentRect.x <= 0 )
+        {
+          x = 0;
+          width = m_currentRect.width + wxIPE_ADJUST;
+        }
+      else
+        {
+          x = m_currentRect.x - wxIPE_ADJUST;
+          width = m_currentRect.width + wxIPE_ADJUST*2;
+        }
+
+      if ( m_currentRect.y <= 0 )
+        {
+          y = 0;
+          height = m_currentRect.height + wxIPE_ADJUST;
+        }
+      else
+        {
+          y = m_currentRect.y - wxIPE_ADJUST;
+          height = m_currentRect.height + wxIPE_ADJUST*2;
+        }
+
+      m_inPlaceTextItem->SetSize( x, y, width, height );
+
+      if ( cell ) {
+          m_inPlaceTextItem->SetFont( cell->GetFont() );
+          m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour());
+          m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour());
+
+          if ( cell->GetTextValue().IsNull() ) {
+              m_inPlaceTextItem->SetValue( "" );
+          }
+          else {
+              m_inPlaceTextItem->SetValue( cell->GetTextValue() );
+          }
+      }
+
       m_inPlaceTextItem->Show(TRUE);
       m_inPlaceTextItem->SetFocus();
+#if defined(__VISAGECPP__)
+      {
+          int                       highlight = wxIPE_HIGHLIGHT;
+          if (highlight != 0)
+              HighlightCell(dc, TRUE);
+      }
+#else
+      if (wxIPE_HIGHLIGHT != 0)
+          HighlightCell(dc, TRUE);
+#endif
     }
   else
-    {      
+    {
       // 1) Why isn't this needed for Windows??
       // Probably because of the SetValue?? JS.
-      // 2) Arrrrrgh. This isn't needed anywhere, 
+      // 2) Arrrrrgh. This isn't needed anywhere,
       // of course. One hour of debugging... RR.
       //
       // 3) It *is* needed for Motif - michael
       //
-#ifdef __WXMOTIF__
-      if ( !(m_editable && m_editInPlace) )
-          HighlightCell(dc);
+#if defined(__WXMOTIF__)
+      if ((wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace)))
+          HighlightCell(dc, TRUE);
 #endif
     }
 
@@ -1472,15 +1557,15 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col)
 
   OnSelectCell(row, col);
   wxGridEvent g_evt2(GetId(), wxEVT_GRID_SELECT_CELL, this, row, col);
-  GetEventHandler()->ProcessEvent(g_evt2);  
+  GetEventHandler()->ProcessEvent(g_evt2);
 }
 
-wxGridCell *wxGenericGrid::OnCreateCell(void)
+wxGridCell *wxGenericGrid::OnCreateCell()
 {
   return new wxGridCell(this);
 }
 
-void wxGenericGrid::OnChangeLabels(void)
+void wxGenericGrid::OnChangeLabels()
 {
   char buf[100];
   int i;
@@ -1506,7 +1591,7 @@ void wxGenericGrid::OnChangeLabels(void)
   }
 }
 
-void wxGenericGrid::OnChangeSelectionLabel(void)
+void wxGenericGrid::OnChangeSelectionLabel()
 {
   if (!GetEditable())
     return;
@@ -1521,35 +1606,39 @@ void wxGenericGrid::OnChangeSelectionLabel(void)
   }
 }
 
-void wxGenericGrid::HighlightCell(wxDC *dc)
+void wxGenericGrid::HighlightCell(wxDC *dc, bool doHighlight)
 {
-  dc->SetLogicalFunction(wxINVERT);
+  wxPen savePen = dc->GetPen();
+  if (doHighlight)
+      dc->SetPen(m_highlightPen);
+  else
+      dc->SetPen(*wxThePenList->FindOrCreatePen(m_cellBackgroundColour, 1, wxSOLID));
 
   // Top
   dc->DrawLine( m_currentRect.x + 1,
                 m_currentRect.y + 1,
                 m_currentRect.x + m_currentRect.width - 1,
-               m_currentRect.y + 1);
+                m_currentRect.y + 1);
   // Right
   dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
                 m_currentRect.y + 1,
                 m_currentRect.x + m_currentRect.width - 1,
-               m_currentRect.y +m_currentRect.height - 1 );
+                m_currentRect.y + m_currentRect.height - 1 );
   // Bottom
   dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
                 m_currentRect.y + m_currentRect.height - 1,
                 m_currentRect.x + 1,
-               m_currentRect.y + m_currentRect.height - 1);
+                m_currentRect.y + m_currentRect.height - 1);
   // Left
   dc->DrawLine( m_currentRect.x + 1,
                 m_currentRect.y + m_currentRect.height - 1,
-               m_currentRect.x + 1,
-               m_currentRect.y + 1);
+                m_currentRect.x + 1,
+                m_currentRect.y + 1);
 
-  dc->SetLogicalFunction(wxCOPY);
+  dc->SetPen(savePen);
 }
 
-void wxGenericGrid::DrawCellText(void)
+void wxGenericGrid::DrawCellText()
 {
   if (!m_currentRectVisible)
     return;
@@ -1699,21 +1788,21 @@ void wxGenericGrid::DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, i
   {
     case wxRIGHT:
     {
-      x = (rect->x + rect->width - textWidth - 1.0);
-      y = (rect->y + (rect->height - textHeight)/2.0);
+      x = (rect->x + rect->width - textWidth - (float)1.0);
+      y = (rect->y + (rect->height - textHeight)/(float)2.0);
       break;
     }
     case wxCENTRE:
     {
-      x = (rect->x + (rect->width - textWidth)/2.0);
-      y = (rect->y + (rect->height - textHeight)/2.0);
+      x = (rect->x + (rect->width - textWidth)/(float)2.0);
+      y = (rect->y + (rect->height - textHeight)/(float)2.0);
       break;
     }
     case wxLEFT:
     default:
     {
-      x = (rect->x + 1.0);
-      y = (rect->y + (rect->height - textHeight)/2.0);
+      x = (rect->x + (float)1.0);
+      y = (rect->y + (rect->height - textHeight)/(float)2.0);
       break;
     }
   }
@@ -2011,8 +2100,8 @@ void wxGenericGrid::SetEditable(bool edit)
 
     if (m_inPlaceTextItem)
       {
-       m_inPlaceTextItem->Show(TRUE);
-       m_inPlaceTextItem->SetFocus();
+        m_inPlaceTextItem->Show(TRUE);
+        m_inPlaceTextItem->SetFocus();
       }
   }
   else
@@ -2023,10 +2112,10 @@ void wxGenericGrid::SetEditable(bool edit)
       m_textItem->Show(FALSE);
       m_editingPanel->Show(FALSE);
     }
-    
+
     if ( m_inPlaceTextItem )
       {
-       m_inPlaceTextItem->Show(FALSE);
+        m_inPlaceTextItem->Show(FALSE);
       }
   }
   UpdateDimensions();
@@ -2053,37 +2142,39 @@ void wxGenericGrid::SetEditInPlace(bool edit)
   if ( m_editInPlace != edit )
     {
       m_editInPlace = edit;
-      
+
       if ( m_editInPlace )  // switched on
-       {
-         if ( m_currentRectVisible && m_editable )
-           {
-             m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2, 
-                                         m_currentRect.width+4, m_currentRect.height+4 );
-
-             wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn);
-
-             if ( cell )
-               {
-                 if ( cell->GetTextValue().IsNull() )
-                   {
-                     m_inPlaceTextItem->SetValue( "" );
-                   }
-                 else
-                   {
-                     m_inPlaceTextItem->SetFont( cell->GetFont() );
-                     m_inPlaceTextItem->SetValue( cell->GetTextValue() );
-                   }
-               }
-         
-             m_inPlaceTextItem->Show( TRUE );
-             m_inPlaceTextItem->SetFocus();      
-           }
-       }
+        {
+          if ( m_currentRectVisible && m_editable )
+            {
+              m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST,
+                                          m_currentRect.y-wxIPE_ADJUST,
+                                          m_currentRect.width+wxIPE_ADJUST*2,
+                                          m_currentRect.height+wxIPE_ADJUST*2 );
+
+              wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn);
+
+              if ( cell ) {
+                  m_inPlaceTextItem->SetFont( cell->GetFont() );
+                  m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour());
+                  m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour());
+
+                  if ( cell->GetTextValue().IsNull() ) {
+                      m_inPlaceTextItem->SetValue( "" );
+                  }
+                  else {
+                      m_inPlaceTextItem->SetValue( cell->GetTextValue() );
+                  }
+              }
+
+              m_inPlaceTextItem->Show( TRUE );
+              m_inPlaceTextItem->SetFocus();
+            }
+        }
       else  // switched off
-       {
-         m_inPlaceTextItem->Show( FALSE );
-       }
+        {
+          m_inPlaceTextItem->Show( FALSE );
+        }
     }
 }
 
@@ -2488,8 +2579,8 @@ void wxGenericGrid::SetGridCursor(int row, int col)
 
   SetGridClippingRegion(& dc);
 
-  if (m_currentRectVisible && !(m_editable && m_editInPlace) )
-    HighlightCell(& dc);
+  if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace)))
+      HighlightCell(& dc, FALSE);
 
   m_wCursorRow = row;
   m_wCursorColumn = col;
@@ -2499,16 +2590,16 @@ void wxGenericGrid::SetGridCursor(int row, int col)
 
   SetCurrentRect(row, col, cw, ch);
 
-  if (m_currentRectVisible && !(m_editable && m_editInPlace) )
-    HighlightCell(& dc);
+  if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace)))
+      HighlightCell(& dc, TRUE);
 
   dc.DestroyClippingRegion();
   dc.EndDrawing();
 }
 
-/*
- * Grid cell
- */
+// ----------------------------------------------------------------------------
+// Grid cell
+// ----------------------------------------------------------------------------
 
 wxGridCell::wxGridCell(wxGenericGrid *window)
 {
@@ -2535,9 +2626,11 @@ wxGridCell::wxGridCell(wxGenericGrid *window)
     alignment = window->GetCellAlignment();
   else
     alignment = wxLEFT;
+
+  cellData = (void *)NULL;
 }
 
-wxGridCell::~wxGridCell(void)
+wxGridCell::~wxGridCell()
 {
 }
 
@@ -2558,30 +2651,51 @@ void wxGenericGrid::OnText(wxCommandEvent& WXUNUSED(ev) )
       wxGenericGrid *grid = this;
       wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn());
       if (cell && grid->CurrentCellVisible())
-       {
-         cell->SetTextValue(grid->GetTextItem()->GetValue());
-         if ( m_editInPlace && !m_inOnTextInPlace )
-           {
-             m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() );
-           }
-    
-         wxClientDC dc(grid);
-
-         dc.BeginDrawing();
-         grid->SetGridClippingRegion(& dc);
-         grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
-         grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
-         if ( !(m_editable && m_editInPlace ) ) grid->HighlightCell(& dc);
-         dc.DestroyClippingRegion();
-         dc.EndDrawing();
-
-         //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
-         wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid,
-                           grid->GetCursorRow(), grid->GetCursorColumn());
-         GetEventHandler()->ProcessEvent(g_evt);
-
-         //    grid->DrawCellText();
-       }
+        {
+          cell->SetTextValue(grid->GetTextItem()->GetValue());
+          if ( m_editInPlace && !m_inOnTextInPlace )
+            {
+              m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() );
+            }
+
+          if (!m_editInPlace) {
+              wxClientDC dc(grid);
+
+              dc.BeginDrawing();
+              grid->SetGridClippingRegion(& dc);
+              grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
+              grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
+              grid->HighlightCell(& dc, TRUE);
+              dc.DestroyClippingRegion();
+              dc.EndDrawing();
+          }
+
+          //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
+          wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid,
+                            grid->GetCursorRow(), grid->GetCursorColumn());
+          GetEventHandler()->ProcessEvent(g_evt);
+
+          //    grid->DrawCellText();
+        }
+    }
+}
+
+void wxGenericGrid::OnTextEnter(wxCommandEvent& WXUNUSED(ev) )
+{
+  // move the cursor down the current row (if possible)
+  // when the enter key has been pressed
+  //
+  if ( m_editable )
+    {
+      if ( GetCursorRow() < GetRows()-1 )
+        {
+          wxClientDC dc( this );
+          dc.BeginDrawing();
+          OnSelectCellImplementation(& dc,
+                                     GetCursorRow()+1,
+                                     GetCursorColumn() );
+          dc.EndDrawing();
+        }
     }
 }
 
@@ -2592,25 +2706,42 @@ void wxGenericGrid::OnTextInPlace(wxCommandEvent& ev )
       wxGenericGrid *grid = this;
       wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn());
       if (cell && grid->CurrentCellVisible())
-       {
-         m_inOnTextInPlace = TRUE;
-         grid->GetTextItem()->SetValue( m_inPlaceTextItem->GetValue() );
-         OnText( ev );    
-         m_inOnTextInPlace = FALSE;
-       }
+        {
+          m_inOnTextInPlace = TRUE;
+          grid->GetTextItem()->SetValue( m_inPlaceTextItem->GetValue() );
+          OnText( ev );
+          m_inOnTextInPlace = FALSE;
+        }
     }
 }
 
-void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
+void wxGenericGrid::OnTextInPlaceEnter(wxCommandEvent& WXUNUSED(ev) )
 {
-  static bool inScroll = FALSE;
+  // move the cursor down the current row (if possible)
+  // when the enter key has been pressed
+  //
+  if ( m_editable )
+    {
+      if ( GetCursorRow() < GetRows()-1 )
+        {
+          wxClientDC dc( this );
+          dc.BeginDrawing();
+          OnSelectCellImplementation(& dc,
+                                     GetCursorRow()+1,
+                                     GetCursorColumn() );
+          dc.EndDrawing();
+        }
+    }
+}
 
-  if ( inScroll )
-       return;
+void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
+{
+  if ( m_inScroll )
+        return;
 
   if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE);
 
-  inScroll = TRUE;
+  m_inScroll = TRUE;
   wxGenericGrid *win = this;
 
   bool change = FALSE;
@@ -2639,13 +2770,15 @@ void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
 
   if ( m_editInPlace && m_currentRectVisible )
     {
-      m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2, 
-                                 m_currentRect.width+4, m_currentRect.height+4 );
+      m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST,
+                                  m_currentRect.y-wxIPE_ADJUST,
+                                  m_currentRect.width+wxIPE_ADJUST*2,
+                                  m_currentRect.height+wxIPE_ADJUST*2 );
       m_inPlaceTextItem->Show( TRUE );
-      m_inPlaceTextItem->SetFocus();     
+      m_inPlaceTextItem->SetFocus();
     }
 
-  inScroll = FALSE;
+  m_inScroll = FALSE;
 
 }
 
@@ -2699,4 +2832,26 @@ void wxGenericGrid::_OnLabelRightClick(wxGridEvent& ev)
     OnLabelRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
 }
 
+void *wxGenericGrid::SetCellData(void *data, int row, int col)
+{
+    void *rc = NULL;
+
+    wxGridCell *cell = GetCell(row, col);
+    if ( cell )
+        rc = cell->SetCellData(data);
+
+    return rc;
+}
+
+void *wxGenericGrid::GetCellData(int row, int col)
+{
+    void *rc = NULL;
+
+    wxGridCell *cell = GetCell(row, col);
+    if ( cell )
+        rc = cell->GetCellData();
+
+    return rc;
+}
 
+#endif // wxUSE_GRID