procedure DrawCells(ACol, ARow: Longint; StartX, StartY, StopX, StopY: Integer;
AColor: TColor; IncludeDrawState: TGridDrawState);
var
CurCol, CurRow: Longint;
AWhere, Where, TempRect: TRect;
DrawState: TGridDrawState;
Focused: Boolean;
begin
CurRow := ARow;
Where.Top := StartY;
while (Where.Top < StopY) and (CurRow < RowCount) do
begin
CurCol := ACol;
Where.Left := StartX;
Where.Bottom := Where.Top + RowHeights[CurRow];
while (Where.Left < StopX) and (CurCol < ColCount) do
begin
Where.Right := Where.Left + ColWidths[CurCol];
// if (Where.Right > Where.Left) and RectVisible(Canvas.Handle, Where) then
if (Where.Right > Where.Left) then
begin
DrawState := IncludeDrawState;
if (CurCol = FHotTrackCell.Coord.X) and (CurRow = FHotTrackCell.Coord.Y) then
begin
if (goFixedHotTrack in Options) then Include(DrawState, gdHotTrack);
if FHotTrackCell.Pressed then Include(DrawState, gdPressed);
end;
Focused := IsActiveControl;
if Focused and (CurRow = Row) and (CurCol = Col) then
begin
SetCaretPos(Where.Left, Where.Top);
Include(DrawState, gdFocused);
end;
if PointInGridRect(CurCol, CurRow, Sel) then
Include(DrawState, gdSelected);
// FIX -oSafrad : Editable cell border
// if not (gdFocused in DrawState) or not (goEditing in Options) or
// not FEditorMode or (csDesigning in ComponentState) then
begin
if DefaultDrawing or (csDesigning in ComponentState) then
begin
Canvas.Font := Self.Font;
if (gdSelected in DrawState) and (not (gdFocused in DrawState) or
([goDrawFocusSelected, goRowSelect] * Options <> [])) then
DrawCellHighlight(Where, DrawState, CurCol, CurRow)
else
DrawCellBackground(Where, AColor, DrawState, CurCol, CurRow);
end;
AWhere := Where;
if (gdPressed in DrawState) then
begin
Inc(AWhere.Top);
Inc(AWhere.Left);
end;
DrawCell(CurCol, CurRow, AWhere, DrawState);
if (FixedType = grDisabled) then
if DefaultDrawing and (gdFixed in DrawState) and Ctl3D and
((FrameFlags1 or FrameFlags2) <> 0) and
(FInternalDrawingStyle = gdsClassic) and not (gdPressed in DrawState) then
begin
TempRect := Where;
if (FrameFlags1 and BF_RIGHT) = 0 then Inc(TempRect.Right, DrawInfo.Horz.EffectiveLineWidth)
else
if (FrameFlags1 and BF_BOTTOM) = 0 then Inc(TempRect.Bottom, DrawInfo.Vert.EffectiveLineWidth);
DrawEdge(Canvas.Handle, TempRect, BDR_RAISEDOUTER, FrameFlags1);
DrawEdge(Canvas.Handle, TempRect, BDR_RAISEDOUTER, FrameFlags2);
end;
if DefaultDrawing and not (csDesigning in ComponentState) and (gdFocused in DrawState) and
([goEditing, goAlwaysShowEditor] * Options <> [goEditing, goAlwaysShowEditor])
and not (goRowSelect in Options) then
begin
TempRect := Where;
if (FInternalDrawingStyle = gdsThemed) and (Win32MajorVersion >= 6) then
InflateRect(TempRect, -1, -1);
Canvas.Brush.Style := bsSolid;
if not UseRightToLeftAlignment then DrawFocusRect(Canvas.Handle, TempRect)
else
begin
AWhere := TempRect;
AWhere.Left := TempRect.Right;
AWhere.Right := TempRect.Left;
DrawFocusRect(Canvas.Handle, AWhere);
end;
end;
end;
end;
Where.Left := Where.Right + DrawInfo.Horz.EffectiveLineWidth;
Inc(CurCol);
end;
Where.Top := Where.Bottom + DrawInfo.Vert.EffectiveLineWidth;
Inc(CurRow);
end;
end;
Poniżej fragment procedure TdCustomGrid.Paint;
DrawCells(0, 0, 0, 0, Horz.FixedBoundary, Vert.FixedBoundary, LFixedColor,[gdFixed]);
DrawCells(LeftCol, 0, Horz.FixedBoundary - FColOffset, 0, Horz.GridBoundary,
Vert.FixedBoundary, LFixedColor, [gdFixed]);
DrawCells(0, TopRow, 0, Vert.FixedBoundary, Horz.FixedBoundary,
Vert.GridBoundary, LFixedColor, [gdFixed]);
DrawCells(LeftCol, TopRow, Horz.FixedBoundary - FColOffset,
Vert.FixedBoundary, Horz.GridBoundary, Vert.GridBoundary, FInternalColor, []);
Wcześniej jest rysowana sam ( pusta ) siatka. Po przejściu tych czerech linii na ekranie jest już wszystko narysowane i wypełnione.