m_owner->DrawHighlight( dc, dirtyCells );
}
+void wxGrid::Render( wxDC& dc,
+ const wxPoint& position,
+ const wxSize& size,
+ const wxGridCellCoords& topLeft,
+ const wxGridCellCoords& bottomRight,
+ int style )
+{
+ wxCHECK_RET( bottomRight.GetCol() < GetNumberCols(),
+ "Invalid right column" );
+ wxCHECK_RET( bottomRight.GetRow() < GetNumberRows(),
+ "Invalid bottom row" );
+
+ // store user settings and reset later
+
+ // remove grid selection, don't paint selection colour
+ // unless we have wxGRID_DRAW_SELECTION
+ // block selections are the only ones catered for here
+ wxGridCellCoordsArray selectedCells;
+ bool hasSelection = IsSelection();
+ if ( hasSelection && !( style & wxGRID_DRAW_SELECTION ) )
+ {
+ selectedCells = GetSelectionBlockTopLeft();
+ // non block selections may not have a bottom right
+ if ( GetSelectionBlockBottomRight().size() )
+ selectedCells.Add( GetSelectionBlockBottomRight()[ 0 ] );
+
+ ClearSelection();
+ }
+
+ // store user device origin
+ wxCoord userOriginX, userOriginY;
+ dc.GetDeviceOrigin( &userOriginX, &userOriginY );
+
+ // store user scale
+ double scaleUserX, scaleUserY;
+ dc.GetUserScale( &scaleUserX, &scaleUserY );
+
+ // set defaults if necessary
+ wxGridCellCoords leftTop( topLeft ), rightBottom( bottomRight );
+ if ( leftTop.GetCol() < 0 )
+ leftTop.SetCol(0);
+ if ( leftTop.GetRow() < 0 )
+ leftTop.SetRow(0);
+ if ( rightBottom.GetCol() < 0 )
+ rightBottom.SetCol(GetNumberCols() - 1);
+ if ( rightBottom.GetRow() < 0 )
+ rightBottom.SetRow(GetNumberRows() - 1);
+
+ // get grid offset, size and cell parameters
+ wxPoint pointOffSet;
+ wxSize sizeGrid;
+ wxGridCellCoordsArray renderCells;
+ wxArrayInt arrayCols;
+ wxArrayInt arrayRows;
+
+ GetRenderSizes( leftTop, rightBottom,
+ pointOffSet, sizeGrid,
+ renderCells,
+ arrayCols, arrayRows );
+
+ // add headers/labels to dimensions
+ if ( style & wxGRID_DRAW_ROWS_HEADER )
+ sizeGrid.x += GetRowLabelSize();
+ if ( style & wxGRID_DRAW_COLS_HEADER )
+ sizeGrid.y += GetColLabelSize();
+
+ // get render start position in logical units
+ wxPoint positionRender = GetRenderPosition( dc, position );
+
+ wxCoord originX = dc.LogicalToDeviceX( positionRender.x );
+ wxCoord originY = dc.LogicalToDeviceY( positionRender.y );
+
+ dc.SetDeviceOrigin( originX, originY );
+
+ SetRenderScale( dc, positionRender, size, sizeGrid );
+
+ // draw row headers at specified origin
+ if ( GetRowLabelSize() > 0 && ( style & wxGRID_DRAW_ROWS_HEADER ) )
+ {
+ if ( style & wxGRID_DRAW_COLS_HEADER )
+ {
+ DrawCornerLabel( dc ); // do only if both col and row labels drawn
+ originY += dc.LogicalToDeviceYRel( GetColLabelSize() );
+ }
+
+ originY -= dc.LogicalToDeviceYRel( pointOffSet.y );
+ dc.SetDeviceOrigin( originX, originY );
+
+ DrawRowLabels( dc, arrayRows );
+
+ // reset for columns
+ if ( style & wxGRID_DRAW_COLS_HEADER )
+ originY -= dc.LogicalToDeviceYRel( GetColLabelSize() );
+
+ originY += dc.LogicalToDeviceYRel( pointOffSet.y );
+ // X offset so we don't overwrite row labels
+ originX += dc.LogicalToDeviceXRel( GetRowLabelSize() );
+ }
+
+ // subtract col offset where startcol > 0
+ originX -= dc.LogicalToDeviceXRel( pointOffSet.x );
+ // no y offset for col labels, they are at the Y origin
+
+ // draw column labels
+ if ( style & wxGRID_DRAW_COLS_HEADER )
+ {
+ dc.SetDeviceOrigin( originX, originY );
+ DrawColLabels( dc, arrayCols );
+ // don't overwrite the labels, increment originY
+ originY += dc.LogicalToDeviceYRel( GetColLabelSize() );
+ }
+
+ // set device origin to draw grid cells and lines
+ originY -= dc.LogicalToDeviceYRel( pointOffSet.y );
+ dc.SetDeviceOrigin( originX, originY );
+
+ // draw cell area background
+ dc.SetBrush( GetDefaultCellBackgroundColour() );
+ dc.SetPen( *wxTRANSPARENT_PEN );
+ // subtract headers from grid area dimensions
+ wxSize sizeCells( sizeGrid );
+ if ( style & wxGRID_DRAW_ROWS_HEADER )
+ sizeCells.x -= GetRowLabelSize();
+ if ( style & wxGRID_DRAW_COLS_HEADER )
+ sizeCells.y -= GetColLabelSize();
+
+ dc.DrawRectangle( pointOffSet, sizeCells );
+
+ // draw cells
+ DrawGridCellArea( dc, renderCells );
+
+ // draw grid lines
+ if ( style & wxGRID_DRAW_CELL_LINES )
+ {
+ wxRegion regionClip( pointOffSet.x, pointOffSet.y,
+ sizeCells.x, sizeCells.y );
+
+ DrawRangeGridLines(dc, regionClip, renderCells[0], renderCells.Last());
+ }
+
+ // draw render rectangle bounding lines
+ DoRenderBox( dc, style,
+ pointOffSet, sizeCells,
+ leftTop, rightBottom );
+
+ // restore user setings
+ dc.SetDeviceOrigin( userOriginX, userOriginY );
+ dc.SetUserScale( scaleUserX, scaleUserY );
+
+ if ( selectedCells.size() && !( style & wxGRID_DRAW_SELECTION ) )
+ {
+ SelectBlock( selectedCells[ 0 ].GetRow(),
+ selectedCells[ 0 ].GetCol(),
+ selectedCells[ selectedCells.size() -1 ].GetRow(),
+ selectedCells[ selectedCells.size() -1 ].GetCol() );
+ }
+}
+
+void
+wxGrid::SetRenderScale(wxDC& dc,
+ const wxPoint& pos, const wxSize& size,
+ const wxSize& sizeGrid )
+{
+ double scaleX, scaleY;
+ wxSize sizeTemp;
+
+ if ( size.GetWidth() != wxDefaultSize.GetWidth() ) // size.x was specified
+ sizeTemp.SetWidth( size.GetWidth() );
+ else
+ sizeTemp.SetWidth( dc.DeviceToLogicalXRel( dc.GetSize().GetWidth() )
+ - pos.x );
+
+ if ( size.GetHeight() != wxDefaultSize.GetHeight() ) // size.y was specified
+ sizeTemp.SetHeight( size.GetHeight() );
+ else
+ sizeTemp.SetHeight( dc.DeviceToLogicalYRel( dc.GetSize().GetHeight() )
+ - pos.y );
+
+ scaleX = (double)( (double) sizeTemp.GetWidth() / (double) sizeGrid.GetWidth() );
+ scaleY = (double)( (double) sizeTemp.GetHeight() / (double) sizeGrid.GetHeight() );
+
+ dc.SetUserScale( wxMin( scaleX, scaleY), wxMin( scaleX, scaleY ) );
+}
+
+// get grid rendered size, origin offset and fill cell arrays
+void wxGrid::GetRenderSizes( const wxGridCellCoords& topLeft,
+ const wxGridCellCoords& bottomRight,
+ wxPoint& pointOffSet, wxSize& sizeGrid,
+ wxGridCellCoordsArray& renderCells,
+ wxArrayInt& arrayCols, wxArrayInt& arrayRows )
+{
+ pointOffSet.x = 0;
+ pointOffSet.y = 0;
+ sizeGrid.SetWidth( 0 );
+ sizeGrid.SetHeight( 0 );
+
+ int col, row;
+
+ wxGridSizesInfo sizeinfo = GetColSizes();
+ for ( col = 0; col <= bottomRight.GetCol(); col++ )
+ {
+ if ( col < topLeft.GetCol() )
+ {
+ pointOffSet.x += sizeinfo.GetSize( col );
+ }
+ else
+ {
+ for ( row = topLeft.GetRow(); row <= bottomRight.GetRow(); row++ )
+ {
+ renderCells.Add( wxGridCellCoords( row, col ));
+ arrayRows.Add( row ); // column labels rendered in DrawColLabels
+ }
+ arrayCols.Add( col ); // row labels rendered in DrawRowLabels
+ sizeGrid.x += sizeinfo.GetSize( col );
+ }
+ }
+
+ sizeinfo = GetRowSizes();
+ for ( row = 0; row <= bottomRight.GetRow(); row++ )
+ {
+ if ( row < topLeft.GetRow() )
+ pointOffSet.y += sizeinfo.GetSize( row );
+ else
+ sizeGrid.y += sizeinfo.GetSize( row );
+ }
+}
+
+// get render start position
+// if position not specified use dc draw extents MaxX and MaxY
+wxPoint wxGrid::GetRenderPosition( wxDC& dc, const wxPoint& position )
+{
+ wxPoint positionRender( position );
+
+ if ( !positionRender.IsFullySpecified() )
+ {
+ if ( positionRender.x == wxDefaultPosition.x )
+ positionRender.x = dc.MaxX();
+
+ if ( positionRender.y == wxDefaultPosition.y )
+ positionRender.y = dc.MaxY();
+ }
+
+ return positionRender;
+}
+
+// draw render rectangle bounding lines
+// useful where there is multi cell row or col clipping and no cell border
+void wxGrid::DoRenderBox( wxDC& dc, const int& style,
+ const wxPoint& pointOffSet,
+ const wxSize& sizeCells,
+ const wxGridCellCoords& topLeft,
+ const wxGridCellCoords& bottomRight )
+{
+ if ( !( style & wxGRID_DRAW_BOX_RECT ) )
+ return;
+
+ int bottom = pointOffSet.y + sizeCells.GetY(),
+ right = pointOffSet.x + sizeCells.GetX() - 1;
+
+ // horiz top line if we are not drawing column header/labels
+ if ( !( style & wxGRID_DRAW_COLS_HEADER ) )
+ {
+ int left = pointOffSet.x;
+ left += ( style & wxGRID_DRAW_COLS_HEADER )
+ ? - GetRowLabelSize() : 0;
+ dc.SetPen( GetRowGridLinePen( topLeft.GetRow() ) );
+ dc.DrawLine( left,
+ pointOffSet.y,
+ right,
+ pointOffSet.y );
+ }
+
+ // horiz bottom line
+ dc.SetPen( GetRowGridLinePen( bottomRight.GetRow() ) );
+ dc.DrawLine( pointOffSet.x, bottom - 1, right, bottom - 1 );
+
+ // left vertical line if we are not drawing row header/labels
+ if ( !( style & wxGRID_DRAW_ROWS_HEADER ) )
+ {
+ int top = pointOffSet.y;
+ top += ( style & wxGRID_DRAW_COLS_HEADER )
+ ? - GetColLabelSize() : 0;
+ dc.SetPen( GetColGridLinePen( topLeft.GetCol() ) );
+ dc.DrawLine( pointOffSet.x -1,
+ top,
+ pointOffSet.x - 1,
+ bottom - 1 );
+ }
+
+ // right vertical line
+ dc.SetPen( GetColGridLinePen( bottomRight.GetCol() ) );
+ dc.DrawLine( right, pointOffSet.y, right, bottom - 1 );
+}
+
void wxGridWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
{
wxWindow::ScrollWindow( dx, dy, rect );