From 7e2453190658529fee2d710aabc57f5f3f968c05 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 12 Nov 2022 23:35:27 +0000 Subject: [PATCH] GridPrinter: Add properties to TGridPrintPreviewDialog to determine preview form size and position, as well as initial zoom. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8616 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/multi-language/main.lfm | 4 + .../gridprinter/source/gridprnpreviewdlg.pas | 73 ++++++++++++++++++- .../gridprinter/source/gridprnpreviewform.pas | 2 +- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/components/gridprinter/examples/multi-language/main.lfm b/components/gridprinter/examples/multi-language/main.lfm index 8fc3348b0..403932aee 100644 --- a/components/gridprinter/examples/multi-language/main.lfm +++ b/components/gridprinter/examples/multi-language/main.lfm @@ -155,7 +155,11 @@ object MainForm: TMainForm Top = 96 end object GridPrintPreviewDialog1: TGridPrintPreviewDialog + FormParams.Width = 840 + FormParams.Height = 800 + FormParams.Position = poDesigned GridPrinter = GridPrinter1 + Zoom = gpzZoomHeight Left = 288 Top = 96 end diff --git a/components/gridprinter/source/gridprnpreviewdlg.pas b/components/gridprinter/source/gridprnpreviewdlg.pas index a0ef21b85..bf6583d4b 100644 --- a/components/gridprinter/source/gridprnpreviewdlg.pas +++ b/components/gridprinter/source/gridprnpreviewdlg.pas @@ -5,38 +5,87 @@ unit GridPrnPreviewDlg; interface uses - Classes, SysUtils, GridPrn, GridPrnPreviewForm; + Classes, SysUtils, Forms, GridPrn, GridPrnPreviewForm; type + TGridPrintPreviewDialog = class; // forward declaration + + TGridPrintPreviewZoom = (gpzOriginal, gpzZoomWidth, gpzZoomHeight); + + TGridPrintPreviewFormParams = class(TPersistent) + private + FOwner: TGridPrintPreviewDialog; + FLeft: Integer; + FTop: Integer; + FWidth: Integer; + FHeight: Integer; + FPosition: TPosition; + public + constructor Create(AOwner: TGridPrintPreviewDialog); + published + property Left: Integer read FLeft write FLeft default 0; + property Top: Integer read FTop write FTop default 0; + property Width: Integer read FWidth write FWidth default 800; + property Height: Integer read FHeight write FHeight default 600; + property Position: TPosition read FPosition write FPosition default poMainFormCenter; + end; + TGridPrintPreviewDialog = class(TComponent) private FGridPrinter: TGridPrinter; + FFormParams: TGridPrintPreviewFormParams; FOptions: TGridPrintPreviewOptions; + FZoom: TGridPrintPreviewZoom; protected procedure Notification(AComponent: TComponent; Operation: TOperation); override; public constructor Create(AOwner: TComponent); override; + destructor Destroy; override; procedure Execute; published + property FormParams: TGridPrintPreviewFormParams read FFormParams write FFormParams; property GridPrinter: TGridPrinter read FGridPrinter write FGridPrinter; property Options: TGridPrintPreviewOptions read FOptions write FOptions default DEFAULT_GRIDPRN_OPTIONS; + property Zoom: TGridPrintPreviewZoom read FZoom write FZoom default gpzOriginal; end; implementation uses - Controls; + Controls, LCLIntf, LCLType; + +{ TGridPrintPreviewFormParams } + +constructor TGridPrintPreviewFormParams.Create(AOwner: TGridPrintPreviewDialog); +begin + inherited Create; + FOwner := AOwner; + FWidth := 800; + FHeight := 600; + FPosition := poMainFormCenter; +end; + + +{ TGridPrintPreviewDialog } constructor TGridPrintPreviewDialog.Create(AOwner: TComponent); begin inherited; FOptions := DEFAULT_GRIDPRN_OPTIONS; + FFormParams := TGridPrintPreviewFormParams.Create(self); +end; + +destructor TGridPrintPreviewDialog.Destroy; +begin + FFormParams.Free; + inherited; end; procedure TGridPrintPreviewDialog.Execute; var F: TGridPrintPreviewForm; + R: TRect; begin if FGridPrinter = nil then exit; @@ -45,8 +94,28 @@ begin try F.GridPrinter := FGridPrinter; F.Options := FOptions; + R := Screen.WorkAreaRect; + if FFormParams.Width > R.Width then FFormParams.Width := R.Width; + if FFormParams.Height > R.Height then FFormParams.Height := R.Height; + if FFormParams.Left < R.Left then FFormParams.Left := R.Left; + if FFormParams.Top < R.Top then FFormParams.Top := R.Top; + if FFormParams.Left + FFormParams.Width > R.Right then + FFormParams.Left := R.Right - FFormParams.Width - GetSystemMetrics(SM_CXSIZEFRAME); + if FFormParams.Top + FFormParams.Height > R.Bottom then + FFormParams.Top := R.Bottom - FFormParams.Height - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYSIZEFRAME); + F.SetBounds(FFormParams.Left, FFormParams.Top, FFormParams.Width, FFormParams.Height); + F.Position := FFormParams.Position; + case FZoom of + gpzOriginal: F.acZoom100.Checked := true; + gpzZoomWidth: F.ZoomToFitWidth; + gpzZoomHeight: F.ZoomToFitHeight; + end; if (F.ShowModal = mrOK) then FGridPrinter.Print; + FFormParams.Left := F.RestoredLeft; + FFormParams.Top := F.RestoredTop; + FFormParams.Width := F.RestoredWidth; + FormParams.Height := F.RestoredHeight; finally F.Free; end; diff --git a/components/gridprinter/source/gridprnpreviewform.pas b/components/gridprinter/source/gridprnpreviewform.pas index a0c463770..05c39af27 100644 --- a/components/gridprinter/source/gridprnpreviewform.pas +++ b/components/gridprinter/source/gridprnpreviewform.pas @@ -492,7 +492,7 @@ begin if FActivated then exit; FUpdatePreviewHandler := FGridPrinter.OnUpdatePreview; - ShowPage(1, 100); + ShowPage(1); FActivated := true; end;