You've already forked lazarus-ccr
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
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -492,7 +492,7 @@ begin
|
||||
if FActivated then
|
||||
exit;
|
||||
FUpdatePreviewHandler := FGridPrinter.OnUpdatePreview;
|
||||
ShowPage(1, 100);
|
||||
ShowPage(1);
|
||||
FActivated := true;
|
||||
end;
|
||||
|
||||
|
Reference in New Issue
Block a user