procedure TCustomGrid.PrepareCanvas(aCol, aRow: Integer; aState: TGridDrawState);
var
AColor: TColor;
CurrentTextStyle: TTextStyle;
IsSelected: boolean;
gc: TGridColumn;
begin
if DefaultDrawing then begin
Canvas.Pen.Mode := pmCopy;
GetSelectedState(aState, IsSelected);
if IsSelected then begin
{bug fix}
if FEditorMode then
Canvas.Brush.Color := Color
else {}
Canvas.Brush.Color := SelectedColor;
SetCanvasFont(GetColumnFont(aCol, False));
if not IsCellButtonColumn(point(aCol,aRow)) then
Canvas.Font.Color := clHighlightText;
FLastFont:=nil;
end else begin
AColor := GetColumnColor(aCol, gdFixed in AState);
if (gdFixed in AState) and (gdHot in aState) then
aColor := FFixedHotColor;
if not (gdFixed in AState) and (FAlternateColor<>AColor) then begin
if AColor=Color then begin
// column color = grid Color, Allow override color
// 1. default color after fixed rows
// 2. always use absolute alternate color based in odd & even row
if (FAltColorStartNormal and Odd(ARow-FixedRows)) {(1)} or
(not FAltColorStartNormal and Odd(ARow)) {(2)} then
AColor := FAlternateColor;
end;
end;
if (gdRowHighlight in aState) and not (gdFixed in AState) then
Canvas.Brush.Color := ColorToRGB(AColor) xor $1F1F1F
else Canvas.Brush.Color := AColor;
SetCanvasFont(GetColumnFont(aCol, ((gdFixed in aState) and (aRow < FFixedRows))));
end;
CurrentTextStyle := DefaultTextStyle;
CurrentTextStyle.Alignment := BidiFlipAlignment(GetColumnAlignment(aCol, gdFixed in AState), UseRightToLeftAlignment);
CurrentTextStyle.Layout := GetColumnLayout(aCol, gdFixed in AState);
CurrentTextStyle.ShowPrefix := ((gdFixed in aState) and (aRow < FFixedRows)) and GetTitleShowPrefix(aCol);
CurrentTextStyle.RightToLeft := UseRightToLeftReading;
CurrentTextStyle.EndEllipsis := (goCellEllipsis in Options);
gc := ColumnFromGridColumn(aCol);
CurrentTextStyle.SingleLine := (gc = nil) or (not gc.Title.MultiLine);
Canvas.TextStyle := CurrentTextStyle;
end else begin
CurrentTextStyle := DefaultTextStyle;
CurrentTextStyle.Alignment := BidiFlipAlignment(CurrentTextStyle.Alignment, UseRightToLeftAlignment);
CurrentTextStyle.RightToLeft := UseRightToLeftAlignment;
Canvas.TextStyle := CurrentTextStyle;
Canvas.Brush.Color := clWindow;
Canvas.Font.Color := clWindowText;
end;
DoPrepareCanvas(aCol, aRow, aState);
end;
procedure TCustomGrid.EditorPos;
var
msg: TGridMessage;
CellR: TRect;
{bug fix}
EditorTop: integer; {}
begin
{$ifdef dbgGrid} DebugLn('Grid.EditorPos INIT');{$endif}
if FEditor<>nil then begin
// send editor position
Msg.LclMsg.msg:=GM_SETPOS;
Msg.Grid:=Self;
Msg.Col:=FCol;
Msg.Row:=FRow;
FEditor.Dispatch(Msg);
// send editor bounds
CellR:=CellRect(FCol,FRow);
if (CellR.Top<FGCache.FixedHeight) or (CellR.Top>FGCache.ClientHeight) or
(UseRightToLeftAlignment and ((CellR.Right-1>FlipX(FGCache.FixedWidth)) or (CellR.Right<0))) or
(not UseRightToLeftAlignment and ((CellR.Left<FGCache.FixedWidth) or (CellR.Left>FGCache.ClientWidth)))
then
// if editor will be out of sight, make the out of sight coords fixed
// this should avoid range check errors on widgetsets that can't handle
// high control coords (like GTK2)
CellR := Bounds(-FEditor.Width-100, -FEditor.Height-100, CellR.Right-CellR.Left, CellR.Bottom-CellR.Top);
if FEditorOptions and EO_AUTOSIZE = EO_AUTOSIZE then begin
{bug fix}
if EditorBorderStyle = bsNone then begin
Dec(CellR.Right);
Dec(CellR.Bottom);
end;
if (FEditor = FStringEditor) then begin
case GetColumnLayout(FCol, False) of
tlTop: EditorTop:=CellR.Top+constCellPadding;
tlCenter: EditorTop:=CellR.Top+(CellR.Bottom-CellR.Top-Canvas.TextHeight(' ')) div 2;
tlBottom: EditorTop:=CellR.Bottom-constCellPadding-Canvas.TextHeight(' ')+1;
end;
if EditorTop>CellR.Top then CellR.Top:=EditorTop;
end;
{if EditorBorderStyle = bsNone then
InflateRect(CellR, -1, -1);}
FEditor.BoundsRect := CellR;
end else begin
Msg.LclMsg.msg:=GM_SETBOUNDS;
Msg.CellRect:=CellR;
Msg.Grid:=Self;
Msg.Col:=FCol;
Msg.Row:=FRow;
FEditor.Dispatch(Msg);
end;
end;
{$ifdef dbgGrid} DebugLn('Grid.EditorPos END');{$endif}
end;