GridPrinter: Improvements in dbgrid printing. New event OnNewLine.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8634 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-12-03 00:12:07 +00:00
parent debd0c4b9c
commit 2d4523c259
4 changed files with 154 additions and 28 deletions

View File

@ -24,6 +24,9 @@ type
TGridPrnGetRowCountEvent = procedure (Sender: TObject; AGrid: TCustomGrid;
var ARowCount: Integer) of object;
TGridPrnNewLineEvent = procedure (Sender: TObject; AGrid: TCustomGrid;
ARow: Integer) of object;
TGridPrnLinePrintedEvent = procedure (Sender: TObject; AGrid: TCustomGrid;
ARow, ALastCol: Integer) of object;
@ -156,6 +159,7 @@ type
FOnGetColCount: TGridPrnGetColCountEvent;
FOnGetRowCount: TGridPrnGetRowCountEvent;
FOnLinePrinted: TGridPrnLinePrintedEvent;
FOnNewLine: TGridPrnNewLineEvent;
FOnNewPage: TGridPrnNewPageEvent;
FOnPrepareCanvas: TOnPrepareCanvasEvent;
FOnPrintCell: TGridPrnPrintCellEvent;
@ -218,6 +222,7 @@ type
procedure CalcFixedColPos(AStartCol, AEndCol: Integer; var ALeft, ARight: Integer);
procedure CalcFixedRowPos(AStartRow, AEndRow: Integer; var ATop, ABottom: Integer);
procedure DoLinePrinted(ARow, ALastCol: Integer); virtual;
procedure DoNewLine(ARow: Integer); virtual;
procedure DoNewPage(AStartCol, AStartRow, AEndCol, AEndRow: Integer); virtual;
procedure DoPrepareCanvas(ACol, ARow: Integer); virtual;
procedure DoPrintCell(ACanvas: TCanvas; ACol, ARow: Integer; ARect: TRect;
@ -303,6 +308,7 @@ type
property OnGetRowCount: TGridPrnGetRowCountEvent read FOnGetRowCount write FOnGetRowCount;
property OnGetColCount: TGridPrnGetColCountEvent read FOnGetColCount write FOnGetColCount;
property OnLinePrinted: TGridPrnLinePrintedEvent read FOnLinePrinted write FOnLinePrinted; // Finished printing a line
property OnNewLine: TGridPrnNewLineEvent read FOnNewLine write FOnNewLine; // Started printing a new row of cells.
property OnNewPage: TGridPrnNewPageEvent read FOnNewPage write FOnNewPage; // Started printing a new page
property OnPrepareCanvas: TOnPrepareCanvasEvent read FOnPrepareCanvas write FOnPrepareCanvas;
property OnPrintCell: TGridPrnPrintCellEvent read FOnPrintCell write FOnPrintCell;
@ -740,6 +746,12 @@ begin
FOnLinePrinted(Self, FGrid, ARow, ALastCol);
end;
procedure TGridPrinter.DoNewLine(ARow: Integer);
begin
if Assigned(FOnNewLine) then
FOnNewLine(Self, FGrid, ARow);
end;
procedure TGridPrinter.DoNewPage(AStartCol, AStartRow, AEndCol, AEndRow: Integer);
begin
if Assigned(FOnNewPage) then
@ -852,7 +864,7 @@ begin
exit;
lGrid := TGridAccess(FGrid);
if lGrid.Columns.Enabled and (FFixedCols > 0) and (ACol >= FFixedCols) and (ARow = 0) then
if lGrid.Columns.Enabled and (FFixedCols > 0) and (ACol >= FFixedCols) and (ARow = 0) and (FFixedRows > 0) then
begin
col := lGrid.Columns[ACol - FFixedCols];
Result := col.Title.Caption;
@ -1700,6 +1712,7 @@ begin
y := fixedRowsBottom;
for row := AStartRow to AEndRow do
begin
DoNewLine(row);
y2 := y + FRowHeights[row];
PrintRowHeader(ACanvas, row, fixedColsLeft, y);
x := fixedColsRight;