+ int row = m_currentCellCoords.GetRow();
+ int col = m_currentCellCoords.GetCol();
+
+ if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
+ return;
+
+ wxRect rect = CellToRect(row, col);
+
+ // hmmm... what could we do here to show that the cell is disabled?
+ // for now, I just draw a thinner border than for the other ones, but
+ // it doesn't look really good
+
+ int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth;
+
+ if (penWidth > 0)
+ {
+ // The center of the drawn line is where the position/width/height of
+ // the rectangle is actually at (on wxMSW at least), so the
+ // size of the rectangle is reduced to compensate for the thickness of
+ // the line. If this is too strange on non-wxMSW platforms then
+ // please #ifdef this appropriately.
+ rect.x += penWidth / 2;
+ rect.y += penWidth / 2;
+ rect.width -= penWidth - 1;
+ rect.height -= penWidth - 1;
+
+ // Now draw the rectangle
+ // use the cellHighlightColour if the cell is inside a selection, this
+ // will ensure the cell is always visible.
+ dc.SetPen(wxPen(IsInSelection(row,col) ? m_selectionForeground
+ : m_cellHighlightColour,
+ penWidth));
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle(rect);
+ }
+}
+
+wxPen wxGrid::GetDefaultGridLinePen()
+{
+ return wxPen(GetGridLineColour());
+}
+
+wxPen wxGrid::GetRowGridLinePen(int WXUNUSED(row))
+{
+ return GetDefaultGridLinePen();
+}
+
+wxPen wxGrid::GetColGridLinePen(int WXUNUSED(col))
+{
+ return GetDefaultGridLinePen();
+}
+
+void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
+{
+ int row = coords.GetRow();
+ int col = coords.GetCol();
+ if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
+ return;
+
+
+ wxRect rect = CellToRect( row, col );
+
+ // right hand border
+ dc.SetPen( GetColGridLinePen(col) );
+ dc.DrawLine( rect.x + rect.width, rect.y,
+ rect.x + rect.width, rect.y + rect.height + 1 );
+
+ // bottom border
+ dc.SetPen( GetRowGridLinePen(row) );
+ dc.DrawLine( rect.x, rect.y + rect.height,
+ rect.x + rect.width, rect.y + rect.height);
+}
+
+void wxGrid::DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells)
+{
+ // This if block was previously in wxGrid::OnPaint but that doesn't
+ // seem to get called under wxGTK - MB
+ //
+ if ( m_currentCellCoords == wxGridNoCellCoords &&
+ m_numRows && m_numCols )
+ {
+ m_currentCellCoords.Set(0, 0);
+ }
+
+ if ( IsCellEditControlShown() )
+ {
+ // don't show highlight when the edit control is shown
+ return;
+ }
+
+ // if the active cell was repainted, repaint its highlight too because it
+ // might have been damaged by the grid lines
+ size_t count = cells.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxGridCellCoords cell = cells[n];
+
+ // If we are using attributes, then we may have just exposed another
+ // cell in a partially-visible merged cluster of cells. If the "anchor"
+ // (upper left) cell of this merged cluster is the cell indicated by
+ // m_currentCellCoords, then we need to refresh the cell highlight even
+ // though the "anchor" itself is not part of our update segment.
+ if ( CanHaveAttributes() )
+ {
+ int rows = 0,
+ cols = 0;
+ GetCellSize(cell.GetRow(), cell.GetCol(), &rows, &cols);
+
+ if ( rows < 0 )
+ cell.SetRow(cell.GetRow() + rows);
+
+ if ( cols < 0 )
+ cell.SetCol(cell.GetCol() + cols);
+ }
+
+ if ( cell == m_currentCellCoords )
+ {
+ wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
+ DrawCellHighlight(dc, attr);
+ attr->DecRef();
+
+ break;
+ }
+ }
+}
+
+// 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 & WXUNUSED(reg) )
+{
+ if ( !m_gridLinesEnabled )
+ return;
+
+ int top, bottom, left, right;
+
+ int cw, ch;
+ m_gridWin->GetClientSize(&cw, &ch);
+ CalcUnscrolledPosition( 0, 0, &left, &top );
+ CalcUnscrolledPosition( cw, ch, &right, &bottom );
+
+ // avoid drawing grid lines past the last row and col
+ if ( m_gridLinesClipHorz )
+ {
+ if ( !m_numCols )
+ return;
+
+ const int lastColRight = GetColRight(GetColAt(m_numCols - 1));
+ if ( right > lastColRight )
+ right = lastColRight;
+ }
+
+ if ( m_gridLinesClipVert )
+ {
+ if ( !m_numRows )
+ return;
+
+ const int lastRowBottom = GetRowBottom(m_numRows - 1);
+ if ( bottom > lastRowBottom )
+ bottom = lastRowBottom;
+ }
+
+ // no gridlines inside multicells, clip them out
+ int leftCol = GetColPos( internalXToCol(left) );
+ int topRow = internalYToRow(top);
+ int rightCol = GetColPos( internalXToCol(right) );
+ int bottomRow = internalYToRow(bottom);
+
+ wxRegion clippedcells(0, 0, cw, ch);
+
+ int cell_rows, cell_cols;
+ wxRect rect;
+
+ for ( int j = topRow; j <= bottomRow; j++ )
+ {
+ for ( int colPos = leftCol; colPos <= rightCol; colPos++ )
+ {
+ int i = GetColAt( colPos );
+
+ 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);
+ }
+ }
+ }
+
+ dc.SetDeviceClippingRegion( clippedcells );
+
+
+ // horizontal grid lines
+ for ( int i = internalYToRow(top); i < m_numRows; i++ )
+ {
+ int bot = GetRowBottom(i) - 1;
+
+ if ( bot > bottom )
+ break;
+
+ if ( bot >= top )
+ {
+ dc.SetPen( GetRowGridLinePen(i) );
+ dc.DrawLine( left, bot, right, bot );
+ }
+ }
+
+ // vertical grid lines
+ for ( int colPos = leftCol; colPos < m_numCols; colPos++ )
+ {
+ int i = GetColAt( colPos );
+
+ int colRight = GetColRight(i);
+#ifdef __WXGTK__
+ if (GetLayoutDirection() != wxLayout_RightToLeft)
+#endif
+ colRight--;
+
+ if ( colRight > right )
+ break;
+
+ if ( colRight >= left )
+ {
+ dc.SetPen( GetColGridLinePen(i) );
+ dc.DrawLine( colRight, top, colRight, bottom );
+ }
+ }
+
+ dc.DestroyClippingRegion();
+}
+
+void wxGrid::DrawRowLabels( wxDC& dc, const wxArrayInt& rows)
+{
+ if ( !m_numRows )
+ return;
+
+ const size_t numLabels = rows.GetCount();
+ for ( size_t i = 0; i < numLabels; i++ )
+ {
+ DrawRowLabel( dc, rows[i] );
+ }
+}
+
+void wxGrid::DrawRowLabel( wxDC& dc, int row )
+{
+ if ( GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0 )
+ return;
+
+ wxRect rect;