1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
//------------------------------------------------------------------------------
procedure TStringGridSLTAssistant.DrawCellButton(ACol, ARow: Integer; const ACaption: string; AEnabled: Boolean; ABackgroundColor: TColor; AState: TGridDrawState);
const
CSelected: array[TGridDrawingStyle] of TThemedGrid = (
tgClassicCellSelected, tgCellSelected, tgGradientCellSelected);
var
uState: UINT;
tbState: TThemedButton;
Details: TThemedElementDetails;
StyleColor: TColor;
Buffer: Vcl.Graphics.TBitmap;
vRect, BufferRect: TRect;
vText: string;
begin
if StyleServices.Enabled then
begin
vRect := StringGrid.CellRect(ACol, ARow); // Rect Plus fiable que celui fourni par OnDrawCell !
// J'utilise un Buffer temporaire pour dessiner le ThemedButton Button dans le TStringGrid
Buffer := Vcl.Graphics.TBitmap.Create();
try
BufferRect := Rect(0, 0, vRect.Width, vRect.Height);
Buffer.SetSize(BufferRect.Width, BufferRect.Height);
if ABackgroundColor = clNone then
begin
// On dessine un fond normal assurant normalement un bon constrate avec le Button
Details := StyleServices.GetElementDetails(tgCellNormal);
StyleServices.GetElementColor(Details, ecFillColor, StyleColor);
end
else
StyleColor := ABackgroundColor;
// Même si la cellule est sélectionné, on laisse un fond neutre pour mieux voir le Button
// Force un fond opaque pour cacher le texte !
Buffer.Canvas.Brush.Color := StyleColor;
Buffer.Canvas.Brush.Style := bsSolid;
Buffer.Canvas.FillRect(BufferRect);
if not AEnabled then
tbState := tbPushButtonNormal
else
tbState := tbPushButtonDisabled;
InflateRect(BufferRect, -1, -1); // Pour ne pas superposer le button et le rectangle de sélection
Details := StyleServices.GetElementDetails(tbState);
StyleServices.DrawElement(Buffer.Canvas.Handle, Details, BufferRect, BufferRect);
vText := ACaption;
BufferRect.Left := BufferRect.Left + 2; // Pour ne pas superposer le texte
Buffer.Canvas.Brush.Style := bsClear;
Buffer.Canvas.TextRect(BufferRect, vText, [tfCenter, tfSingleLine, tfVerticalCenter]);
// Dessin final
StringGrid.Canvas.Draw(vRect.Left, vRect.Top, Buffer);
finally
Buffer.Free();
end;
end
else
begin
uState := 0;
if not AEnabled then
uState := uState or DFCS_INACTIVE;
StringGrid.Canvas.FillRect(vRect);
InflateRect(vRect, -1, -1); // Pour ne pas superposer le button et le rectangle de sélection
DrawFrameControl(StringGrid.Canvas.Handle, vRect, DFC_BUTTON, uState);
vText := ACaption;
vRect.Left := vRect.Left + 2; // Pour ne pas superposer le texte
StringGrid.Canvas.Brush.Style := bsClear;
StringGrid.Canvas.TextRect(vRect, vText, [tfCenter, tfSingleLine, tfVerticalCenter]);
end;
end; |
Partager