LCL: add FixedRowsExtra property to allow derived grids add more fixed rows. Fix issue #29303

This commit is contained in:
Jesus Reyes A 2021-08-10 21:14:11 -05:00
parent e2f89909cf
commit fc83aefbd9

View File

@ -354,6 +354,7 @@ type
FSavedRecord: Integer; FSavedRecord: Integer;
FOnGetCellHint: TDbGridCellHintEvent; FOnGetCellHint: TDbGridCellHintEvent;
FOnRowMoved: TMovedEvent; FOnRowMoved: TMovedEvent;
FFixedRowsExtra: Integer;
procedure EmptyGrid; procedure EmptyGrid;
function GetColumns: TDBGridColumns; function GetColumns: TDBGridColumns;
function GetCurrentColumn: TColumn; function GetCurrentColumn: TColumn;
@ -382,6 +383,7 @@ type
procedure SetCurrentField(const AValue: TField); procedure SetCurrentField(const AValue: TField);
procedure SetDataSource(const AValue: TDataSource); procedure SetDataSource(const AValue: TDataSource);
procedure SetExtraOptions(const AValue: TDBGridExtraOptions); procedure SetExtraOptions(const AValue: TDBGridExtraOptions);
procedure SetFixedRowsExtra(AValue: Integer);
procedure SetOptions(const AValue: TDBGridOptions); procedure SetOptions(const AValue: TDBGridOptions);
procedure SetRowMoved(AValue: TMovedEvent); procedure SetRowMoved(AValue: TMovedEvent);
procedure SetSelectedIndex(const AValue: Integer); procedure SetSelectedIndex(const AValue: Integer);
@ -512,6 +514,7 @@ type
procedure WndProc(var TheMessage : TLMessage); override; procedure WndProc(var TheMessage : TLMessage); override;
property Columns: TDBGridColumns read GetColumns write SetColumns; property Columns: TDBGridColumns read GetColumns write SetColumns;
property FixedRowsExtra: Integer read FFixedRowsExtra write SetFixedRowsExtra;
property GridStatus: TDBGridStatus read FGridStatus write FGridStatus; property GridStatus: TDBGridStatus read FGridStatus write FGridStatus;
property Datalink: TComponentDataLink read FDatalink; property Datalink: TComponentDataLink read FDatalink;
property Options: TDBGridOptions read FOptions write SetOptions default property Options: TDBGridOptions read FOptions write SetOptions default
@ -1191,6 +1194,13 @@ begin
end; end;
procedure TCustomDBGrid.SetFixedRowsExtra(AValue: Integer);
begin
if FFixedRowsExtra = AValue then Exit;
FFixedRowsExtra := AValue;
LayoutChanged;
end;
procedure TCustomDBGrid.SetOptions(const AValue: TDBGridOptions); procedure TCustomDBGrid.SetOptions(const AValue: TDBGridOptions);
var var
OldOptions: TGridOptions; OldOptions: TGridOptions;
@ -1743,7 +1753,7 @@ begin
{$endif} {$endif}
Result := ClientHeight div DefaultRowHeight; Result := ClientHeight div DefaultRowHeight;
if dgTitles in Options then if dgTitles in Options then
Dec(Result, 1); Dec(Result, FixedRows);
end; end;
procedure TCustomDBGrid.UpdateGridColumnSizes; procedure TCustomDBGrid.UpdateGridColumnSizes;
@ -3383,6 +3393,10 @@ var
begin begin
if GetIsCellTitle(aCol, aRow) then if GetIsCellTitle(aCol, aRow) then
inherited DrawColumnText(aCol, aRow, aRect, aState) inherited DrawColumnText(aCol, aRow, aRect, aState)
else if aRow<FixedRows then
// this case is for drawing fixed rows extra, the standard dbgrid
// have nothing to draw here but it must avoid duplicate titles or
// draw some field.
else begin else begin
F := GetFieldFromGridColumn(aCol); F := GetFieldFromGridColumn(aCol);
if F<>nil then begin if F<>nil then begin
@ -3631,7 +3645,8 @@ begin
try try
Result := GetColumnCount; Result := GetColumnCount;
if Result > 0 then begin if Result > 0 then begin
if dgTitles in Options then FRCount := 1 else FRCount := 0; FRCount := FixedRowsExtra;
if dgTitles in Options then Inc(FRCount);
if dgIndicator in Options then FCCount := 1 else FCCount := 0; if dgIndicator in Options then FCCount := 1 else FCCount := 0;
InternalSetColCount(Result + FCCount); InternalSetColCount(Result + FCCount);
if FDataLink.Active then begin if FDataLink.Active then begin