+ DrawCell( dc, m_cellsExposed[i] );
+ }
+}
+
+
+void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
+{
+ if ( m_colWidths[coords.GetCol()] <=0 ||
+ m_rowHeights[coords.GetRow()] <= 0 ) return;
+
+#if !WXGRID_DRAW_LINES
+ if ( m_gridLinesEnabled )
+ DrawCellBorder( dc, coords );
+#endif
+
+ DrawCellBackground( dc, coords );
+
+ // TODO: separate functions here for different kinds of cells ?
+ // e.g. text, image
+ //
+ DrawCellValue( dc, coords );
+}
+
+
+void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
+{
+ if ( m_colWidths[coords.GetCol()] <=0 ||
+ m_rowHeights[coords.GetRow()] <= 0 ) return;
+
+ dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
+ int row = coords.GetRow();
+ int col = coords.GetCol();
+
+ // right hand border
+ //
+ dc.DrawLine( m_colRights[col], m_rowBottoms[row] - m_rowHeights[row],
+ m_colRights[col], m_rowBottoms[row] );
+
+ // bottom border
+ //
+ dc.DrawLine( m_colRights[col] - m_colWidths[col], m_rowBottoms[row],
+ m_colRights[col], m_rowBottoms[row] );
+}
+
+
+void wxGrid::DrawCellBackground( wxDC& dc, const wxGridCellCoords& coords )
+{
+ if ( m_colWidths[coords.GetCol()] <=0 ||
+ m_rowHeights[coords.GetRow()] <= 0 ) return;
+
+ int row = coords.GetRow();
+ int col = coords.GetCol();
+
+ dc.SetBackgroundMode( wxSOLID );
+
+ if ( IsInSelection( coords ) )
+ {
+ // TODO: improve this
+ //
+ dc.SetBrush( *wxBLACK_BRUSH );
+ }
+ else
+ {
+ dc.SetBrush( wxBrush(GetCellBackgroundColour(row, col), wxSOLID) );
+ }
+
+ dc.SetPen( *wxTRANSPARENT_PEN );
+
+ dc.DrawRectangle( m_colRights[col] - m_colWidths[col] + 1,
+ m_rowBottoms[row] - m_rowHeights[row] + 1,
+ m_colWidths[col]-1,
+ m_rowHeights[row]-1 );
+}
+
+
+void wxGrid::DrawCellValue( wxDC& dc, const wxGridCellCoords& coords )
+{
+ if ( m_colWidths[coords.GetCol()] <=0 ||
+ m_rowHeights[coords.GetRow()] <= 0 ) return;
+
+ int row = coords.GetRow();
+ int col = coords.GetCol();
+
+ dc.SetBackgroundMode( wxTRANSPARENT );
+
+ if ( IsInSelection( row, col ) )
+ {
+ // TODO: improve this
+ //
+ dc.SetTextBackground( wxColour(0, 0, 0) );
+ dc.SetTextForeground( wxColour(255, 255, 255) );
+ }
+ else
+ {
+ dc.SetTextBackground( GetCellBackgroundColour(row, col) );
+ dc.SetTextForeground( GetCellTextColour(row, col) );
+ }
+ dc.SetFont( GetCellFont(row, col) );
+
+ int hAlign, vAlign;
+ GetCellAlignment( row, col, &hAlign, &vAlign );
+
+ wxRect rect;
+ rect.SetX( m_colRights[col] - m_colWidths[col] + 2 );
+ rect.SetY( m_rowBottoms[row] - m_rowHeights[row] + 2 );
+ rect.SetWidth( m_colWidths[col] - 4 );
+ rect.SetHeight( m_rowHeights[row] - 4 );
+
+ DrawTextRectangle( dc, GetCellValue( row, col ), rect, hAlign, vAlign );
+}
+
+
+
+// TODO: remove this ???
+// This is used to redraw all grid lines e.g. when the grid line colour
+// has been changed
+//
+void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & reg )
+{
+ if ( !m_gridLinesEnabled ||
+ !m_numRows ||
+ !m_numCols ) return;
+
+ int top, bottom, left, right;
+
+ if (reg.IsEmpty()){
+ int cw, ch;
+ m_gridWin->GetClientSize(&cw, &ch);
+
+ // virtual coords of visible area
+ //
+ CalcUnscrolledPosition( 0, 0, &left, &top );
+ CalcUnscrolledPosition( cw, ch, &right, &bottom );
+ }
+ else{
+ wxCoord x, y, w, h;
+ reg.GetBox(x, y, w, h);
+ CalcUnscrolledPosition( x, y, &left, &top );
+ CalcUnscrolledPosition( x + w, y + h, &right, &bottom );
+ }
+
+ // avoid drawing grid lines past the last row and col
+ //
+ right = wxMin( right, m_colRights[m_numCols-1] );
+ bottom = wxMin( bottom, m_rowBottoms[m_numRows-1] );
+
+ dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
+
+ // horizontal grid lines
+ //
+ int i;
+ for ( i = 0; i < m_numRows; i++ )
+ {
+ if ( m_rowBottoms[i] > bottom )