{ cell properties for <TCellPropertiesForDrawCell> }
type
TCellProperties =
record
{ alignment }
Alignment: TAlignment;
{ column is the sort column }
bColIsSortCol: Boolean;
{ asc order }
bAscOrder : Boolean;
{ font properties }
Font:
record
Color: TColor;
end;
{ brush properties }
Brush:
record
Color: TColor;
end;
end;
{ TCellProperties }
protected
FCellPropertiesForDrawCell : TCellPropertiesForDrawCell;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
override;
procedure TEditGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
begin
if DefaultDrawing
then
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
inherited DrawCell(ACol, ARow, ARect, AState);
if Assigned(FCellPropertiesForDrawCell)
then
begin
FCellProperties.Alignment := taLeftJustify;
FCellProperties.Font.Color := Self.Font.Color;
FCellProperties.Brush.Color := Self.Brush.Color;
FCellProperties.bColIsSortCol := False;
FCellProperties.bAscOrder := True;
if (gdSelected
in AState)
then
begin
FCellProperties.Brush.Color := clActiveCaption;
FCellProperties.Font.Color := clWhite;
end
else
begin
FCellProperties.Font.Color := Self.Font.Color;
end;
FCellPropertiesForDrawCell(Self,
ACol, ARow, ARect, AState, FCellProperties);
InternalDrawCell(ACol, ARow,
ARect, AState, FCellProperties);
end;
end;
procedure TEditGrid.InternalDrawCell(ACol, ARow: Longint;
ARect: TRect; AState: TGridDrawState;
const theCellProperties: TCellProperties);
var
c: TCanvas;
begin
c:= Self.Canvas;
if ARow<FixedRows
then
begin
c.Brush.Color:= FixedColor;
end
else
begin
c.Brush.Color := theCellProperties.Brush.Color;
end;
c.Font.Color := theCellProperties.Font.Color;
c.FillRect(ARect);
Inc(ARect.Top,2);
if theCellProperties.Alignment=taCenter
then
begin
Inc(ARect.Left,2);
if theCellProperties.bColIsSortCol
then
begin
ARect.Right:= ARect.Right-16;
end;
DrawText(c.Handle, PChar(Cells[ACol,ARow]),
Length(Cells[ACol,ARow]), ARect,
DT_END_ELLIPSIS
or DT_CENTER
or DT_NOPREFIX);
if theCellProperties.bColIsSortCol
then
begin
ARect.Right:= ARect.Right+16;
end;
end;
{ if theCellProperties.Alignment=taCenter then }
if theCellProperties.bColIsSortCol
then
begin
if theCellProperties.bAscOrder
then
begin
c.Draw(ARect.Right-15,((ARect.Bottom-ARect.Top)
div 2)-6,PicUp);
end
else
begin
c.Draw(ARect.Right-15,((ARect.Bottom-ARect.Top)
div 2)-6,PicDown);
end;
end;
{ right alignment }
if theCellProperties.Alignment=taRightJustify
then
begin
Dec(ARect.Right,2);
DrawText(c.Handle, PChar(Cells[ACol,ARow]),
Length(Cells[ACol,ARow]), ARect,
DT_END_ELLIPSIS
or DT_RIGHT
or DT_NOPREFIX);
end;
{ left alignment }
if theCellProperties.Alignment=taLeftJustify
then
begin
Inc(ARect.Left,2);
DrawText(c.Handle, PChar(Cells[ACol,ARow]),
Length(Cells[ACol,ARow]), ARect,
DT_END_ELLIPSIS
or DT_NOPREFIX);
end;
end;
{ TEditGrid.InternalDrawCell }