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
|
Top = 96
|
||||||
end
|
end
|
||||||
object GridPrintPreviewDialog1: TGridPrintPreviewDialog
|
object GridPrintPreviewDialog1: TGridPrintPreviewDialog
|
||||||
|
FormParams.Width = 840
|
||||||
|
FormParams.Height = 800
|
||||||
|
FormParams.Position = poDesigned
|
||||||
GridPrinter = GridPrinter1
|
GridPrinter = GridPrinter1
|
||||||
|
Zoom = gpzZoomHeight
|
||||||
Left = 288
|
Left = 288
|
||||||
Top = 96
|
Top = 96
|
||||||
end
|
end
|
||||||
|
@@ -5,38 +5,87 @@ unit GridPrnPreviewDlg;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, GridPrn, GridPrnPreviewForm;
|
Classes, SysUtils, Forms, GridPrn, GridPrnPreviewForm;
|
||||||
|
|
||||||
type
|
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)
|
TGridPrintPreviewDialog = class(TComponent)
|
||||||
private
|
private
|
||||||
FGridPrinter: TGridPrinter;
|
FGridPrinter: TGridPrinter;
|
||||||
|
FFormParams: TGridPrintPreviewFormParams;
|
||||||
FOptions: TGridPrintPreviewOptions;
|
FOptions: TGridPrintPreviewOptions;
|
||||||
|
FZoom: TGridPrintPreviewZoom;
|
||||||
protected
|
protected
|
||||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
procedure Execute;
|
procedure Execute;
|
||||||
published
|
published
|
||||||
|
property FormParams: TGridPrintPreviewFormParams read FFormParams write FFormParams;
|
||||||
property GridPrinter: TGridPrinter read FGridPrinter write FGridPrinter;
|
property GridPrinter: TGridPrinter read FGridPrinter write FGridPrinter;
|
||||||
property Options: TGridPrintPreviewOptions
|
property Options: TGridPrintPreviewOptions
|
||||||
read FOptions write FOptions default DEFAULT_GRIDPRN_OPTIONS;
|
read FOptions write FOptions default DEFAULT_GRIDPRN_OPTIONS;
|
||||||
|
property Zoom: TGridPrintPreviewZoom read FZoom write FZoom default gpzOriginal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
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);
|
constructor TGridPrintPreviewDialog.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
FOptions := DEFAULT_GRIDPRN_OPTIONS;
|
FOptions := DEFAULT_GRIDPRN_OPTIONS;
|
||||||
|
FFormParams := TGridPrintPreviewFormParams.Create(self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TGridPrintPreviewDialog.Destroy;
|
||||||
|
begin
|
||||||
|
FFormParams.Free;
|
||||||
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGridPrintPreviewDialog.Execute;
|
procedure TGridPrintPreviewDialog.Execute;
|
||||||
var
|
var
|
||||||
F: TGridPrintPreviewForm;
|
F: TGridPrintPreviewForm;
|
||||||
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
if FGridPrinter = nil then
|
if FGridPrinter = nil then
|
||||||
exit;
|
exit;
|
||||||
@@ -45,8 +94,28 @@ begin
|
|||||||
try
|
try
|
||||||
F.GridPrinter := FGridPrinter;
|
F.GridPrinter := FGridPrinter;
|
||||||
F.Options := FOptions;
|
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
|
if (F.ShowModal = mrOK) then
|
||||||
FGridPrinter.Print;
|
FGridPrinter.Print;
|
||||||
|
FFormParams.Left := F.RestoredLeft;
|
||||||
|
FFormParams.Top := F.RestoredTop;
|
||||||
|
FFormParams.Width := F.RestoredWidth;
|
||||||
|
FormParams.Height := F.RestoredHeight;
|
||||||
finally
|
finally
|
||||||
F.Free;
|
F.Free;
|
||||||
end;
|
end;
|
||||||
|
@@ -492,7 +492,7 @@ begin
|
|||||||
if FActivated then
|
if FActivated then
|
||||||
exit;
|
exit;
|
||||||
FUpdatePreviewHandler := FGridPrinter.OnUpdatePreview;
|
FUpdatePreviewHandler := FGridPrinter.OnUpdatePreview;
|
||||||
ShowPage(1, 100);
|
ShowPage(1);
|
||||||
FActivated := true;
|
FActivated := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user