-void wxGrid::DrawGridLines( wxDC& dc )
-{
- if ( !m_gridLinesEnabled || !m_numRows || !m_numCols ) return;
-
- int i;
- int cw, ch;
- GetClientSize(&cw, &ch);
-
- dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
-
- // horizontal grid lines
- //
- int rowTop = m_top + m_colLabelHeight + m_rowHeights[m_scrollPosY];
- for ( i = m_scrollPosY + 1; i <= m_numRows; i++ )
- {
- if ( rowTop > ch ) break;
-
- dc.DrawLine( m_left + m_rowLabelWidth + 1, rowTop,
- m_right, rowTop);
-
- if ( i < m_numRows ) rowTop += m_rowHeights[i];
- }
-
-
- // vertical grid lines
- //
- int colLeft = m_left + m_rowLabelWidth + m_colWidths[m_scrollPosX];
- for ( i = m_scrollPosX + 1; i <= m_numCols; i++ )
- {
- if ( colLeft > cw ) break;
-
- dc.DrawLine( colLeft, m_top + m_colLabelHeight + 1,
- colLeft, m_bottom );
-
- if ( i < m_numCols ) colLeft += m_colWidths[i];
- }
-}
-
-
-void wxGrid::DrawCells( wxDC& dc )
-{
- if ( !m_numRows || !m_numCols ) return;
-
- int row, col;
-
- int cw, ch;
- GetClientSize( &cw, &ch );
-
- wxRect rect;
-
- if ( m_table )
- {
- rect.y = m_top + m_colLabelHeight;
- for ( row = m_scrollPosY; row < m_numRows; row++ )
- {
- if ( rect.y > ch ) break;
-
- rect.height = m_rowHeights[ row ];
- rect.x = m_left + m_rowLabelWidth;
-
- for ( col = m_scrollPosX; col < m_numCols; col++ )
- {
- if ( rect.x > cw ) break;
-
- rect.width = m_colWidths[col];
- DrawCellBackground( dc, rect, row, col );
- DrawCellValue( dc, rect, row, col );
- rect.x += rect.width;
- }
- rect.y += rect.height;
- }
- }
-}
-
-
-void wxGrid::DrawCellBackground( wxDC& dc, const wxRect& rect, int row, int col )
-{
- wxRect rect2;
- rect2 = rect;
- rect2.x += 1;
- rect2.y += 1;
- rect2.width -= 2;
- rect2.height -= 2;
-
- dc.SetBackgroundMode( wxSOLID );
-
- if ( IsInSelection( row, col ) )
- {
- // TODO: improve this
- //
- dc.SetBrush( *wxBLACK_BRUSH );
- }
- else
- {
- dc.SetBrush( wxBrush(GetCellBackgroundColour(row, col), wxSOLID) );
- }
- dc.SetPen( *wxTRANSPARENT_PEN );
- dc.DrawRectangle( rect2 );
-}
-
-
-// This draws a text value in the given cell. If useValueArg is FALSE
-// (the default) then the grid table value will be used
-//
-void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col,
- const wxString& value, bool useValueArg )
-{
- wxRect rect2;
- rect2 = rect;
- rect2.x += 3;
- rect2.y += 2;
- rect2.width -= 5;
- rect2.height -= 4;
-
- 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 );
-
- if ( useValueArg )
- {
- DrawTextRectangle( dc, value, rect2, hAlign, vAlign );
- }
- else
- {
- DrawTextRectangle( dc, GetCellValue( row, col ), rect2, hAlign, vAlign );
- }
-}
-
-
-// this is used to echo text being entered into the top edit control when
-// in-place editing is turned off
-//
-void wxGrid::DrawCellValue( const wxGridCellCoords& coords, const wxString& value )
-{
- if ( IsVisible( coords ) )
- {
- int row = coords.GetRow();
- int col = coords.GetCol();
- wxRect rect;
- rect.x = m_colRights[ col ] - m_colWidths[ col ];
- rect.y = m_rowBottoms[ row ] - m_rowHeights[ row ];
- rect.width = m_colWidths[ col ];
- rect.height = m_rowHeights[ row ];
-
- wxClientDC dc( this );
- DrawCellBackground( dc, rect, row, col );
- DrawCellValue( dc, rect, row, col, value, TRUE );
- }
-}
-
-
-void wxGrid::DrawCellHighlight( wxDC& dc, int row, int col )
-{
- // TODO: bounds checking on row, col ?
- //
-
- if ( row >= m_scrollPosY && col >= m_scrollPosX )
- {
- long x, y;
-
- int cw, ch;
- GetClientSize( &cw, &ch );
-
- x = m_colRights[col] - m_colWidths[col];
- if ( x >= cw ) return;
-
- y = m_rowBottoms[row] - m_rowHeights[row];
- if ( y >= ch ) return;
-
- dc.SetLogicalFunction( wxINVERT );
- dc.SetPen( wxPen(GetCellHighlightColour(), 2, wxSOLID) );
- dc.SetBrush( *wxTRANSPARENT_BRUSH );
-
- dc.DrawRectangle( x-2, y-2,
- m_colWidths[col] + 6,
- m_rowHeights[row] + 6 );
-
- dc.SetLogicalFunction( wxCOPY );
- }
-}
-
-
-// This function is handy when you just want to update one or a few
-// cells. For example, it is used by SetCellValue()
-//
-void wxGrid::DrawCell( int row, int col )
-{
- if ( !GetBatchCount() )
- {
- if ( !IsVisible( wxGridCellCoords(row, col) ) ) return;
-
- int cw, ch;
- GetClientSize( &cw, &ch );
-
- wxRect rect( CellToRect( row, col ) );
-
- if ( m_table )
- {
- wxClientDC dc( this );
- DrawCellBackground( dc, rect, row, col );
- DrawCellValue( dc, rect, row, col );
- }
- }
-}
-
-
-// this is just to make other code more obvious
-//
-void wxGrid::HideCurrentCellHighlight( wxDC& dc )
-{
- if ( m_currentCellHighlighted &&
- m_currentCellCoords != wxGridNoCellCoords )
- {
- DrawCellHighlight( dc, m_currentCellCoords );
- m_currentCellHighlighted = FALSE;
- }
-}
-
-
-// this is just to make other code more obvious
-//
-void wxGrid::ShowCurrentCellHighlight( wxDC& dc )
-{
- if ( !m_currentCellHighlighted &&
- m_currentCellCoords != wxGridNoCellCoords )
- {
- DrawCellHighlight( dc, m_currentCellCoords );
- m_currentCellHighlighted = TRUE;
- }
-}
-
-
-void wxGrid::DrawTextRectangle( wxDC& dc,
- const wxString& value,
- const wxRect& rect,
- int horizAlign,
- int vertAlign )
-{
- long textWidth, textHeight;
- long lineWidth, lineHeight;
- wxArrayString lines;
-
- // see if we are already clipping
- //
- wxRect clipRect;
- dc.GetClippingBox( clipRect );
-
- bool alreadyClipping = TRUE;
- wxRect intersectRect;
-
- if ( clipRect.x == 0 && clipRect.y == 0 &&
- clipRect.width == 0 && clipRect.height == 0)
- {
- alreadyClipping = FALSE;
- intersectRect = rect;
- }
- else
- {
- // Find the intersection of the clipping rectangle and our
- // rectangle
- //
- wxRegion region( rect );
- region.Intersect( clipRect );
- if ( region.IsEmpty() )
- {
- // nothing to do
- //
- return;
- }
- intersectRect = region.GetBox();
- }
-
- if ( alreadyClipping ) dc.DestroyClippingRegion();
-
- dc.SetClippingRegion( intersectRect );
-
- StringToLines( value, lines );
- if ( lines.GetCount() )
- {
- GetTextBoxSize( dc, lines, &textWidth, &textHeight );
- dc.GetTextExtent( lines[0], &lineWidth, &lineHeight );
-
- float x, y;
- switch ( horizAlign )
- {
- case wxRIGHT:
- x = rect.x + (rect.width - textWidth - 1);
- break;
-
- case wxCENTRE:
- x = rect.x + ((rect.width - textWidth)/2);
- break;
-
- case wxLEFT:
- default:
- x = rect.x + 1;
- break;
- }
-
- switch ( vertAlign )
- {
- case wxBOTTOM:
- y = rect.y + (rect.height - textHeight - 1);
- break;