2008-02-03 12:05:55 +00:00
|
|
|
{*********************************************************}
|
|
|
|
{* VPPRTPRVDLG.PAS 1.03 *}
|
|
|
|
{*********************************************************}
|
|
|
|
|
|
|
|
{* ***** BEGIN LICENSE BLOCK ***** *}
|
|
|
|
{* Version: MPL 1.1 *}
|
|
|
|
{* *}
|
|
|
|
{* The contents of this file are subject to the Mozilla Public License *}
|
|
|
|
{* Version 1.1 (the "License"); you may not use this file except in *}
|
|
|
|
{* compliance with the License. You may obtain a copy of the License at *}
|
|
|
|
{* http://www.mozilla.org/MPL/ *}
|
|
|
|
{* *}
|
|
|
|
{* Software distributed under the License is distributed on an "AS IS" basis, *}
|
|
|
|
{* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License *}
|
|
|
|
{* for the specific language governing rights and limitations under the *}
|
|
|
|
{* License. *}
|
|
|
|
{* *}
|
|
|
|
{* The Original Code is TurboPower Visual PlanIt *}
|
|
|
|
{* *}
|
|
|
|
{* The Initial Developer of the Original Code is TurboPower Software *}
|
|
|
|
{* *}
|
|
|
|
{* Portions created by TurboPower Software Inc. are Copyright (C) 2002 *}
|
|
|
|
{* TurboPower Software Inc. All Rights Reserved. *}
|
|
|
|
{* *}
|
|
|
|
{* Contributor(s): *}
|
|
|
|
{* *}
|
|
|
|
{* ***** END LICENSE BLOCK ***** *}
|
|
|
|
|
|
|
|
unit VpPrtPrvDlg;
|
|
|
|
|
|
|
|
{$I vp.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF LCL}
|
2016-06-07 16:34:18 +00:00
|
|
|
LMessages, LCLProc, LCLType, LCLIntf, LResources,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ELSE}
|
2016-06-21 13:48:55 +00:00
|
|
|
Windows, Messages,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
SysUtils,
|
|
|
|
Classes,
|
|
|
|
Graphics,
|
|
|
|
Controls,
|
|
|
|
Forms,
|
|
|
|
Dialogs,
|
|
|
|
StdCtrls,
|
|
|
|
ExtCtrls,
|
|
|
|
{$IFDEF VERSION6} Variants, {$ENDIF}
|
|
|
|
VpMisc,
|
|
|
|
VpBase,
|
|
|
|
VpException,
|
|
|
|
VpData,
|
|
|
|
VpPrtPrv,
|
|
|
|
VpSR,
|
|
|
|
VpBaseDS,
|
|
|
|
VpDlg,
|
|
|
|
Buttons,
|
|
|
|
VpPrtFmtCBox,
|
|
|
|
Printers, ImgList, ComCtrls, ToolWin, ActnList;
|
|
|
|
|
|
|
|
type
|
|
|
|
TVpPrintPreviewDialog = class;
|
|
|
|
|
2016-06-21 13:19:39 +00:00
|
|
|
{ TfrmPrintPreview }
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
TfrmPrintPreview = class(TForm)
|
|
|
|
Panel1: TPanel;
|
|
|
|
cboxZoom: TComboBox;
|
|
|
|
btnCancel: TToolButton;
|
|
|
|
VpPrintPreview1: TVpPrintPreview;
|
|
|
|
VpPrintFormatComboBox1: TVpPrintFormatComboBox;
|
2008-02-03 12:05:55 +00:00
|
|
|
ToolBar1: TToolBar;
|
|
|
|
btnPrint: TToolButton;
|
|
|
|
ToolButton3: TToolButton;
|
|
|
|
btnFirstPage: TToolButton;
|
|
|
|
btnPrevPage: TToolButton;
|
|
|
|
btnNextPage: TToolButton;
|
|
|
|
btnLastPage: TToolButton;
|
|
|
|
imMain: TImageList;
|
|
|
|
ToolButton8: TToolButton;
|
|
|
|
actMain: TActionList;
|
|
|
|
actPrint: TAction;
|
|
|
|
actFirstPage: TAction;
|
|
|
|
actPrevPage: TAction;
|
|
|
|
actNextPage: TAction;
|
|
|
|
actLastPage: TAction;
|
|
|
|
actCancel: TAction;
|
|
|
|
|
|
|
|
procedure OKBtnClick (Sender : TObject);
|
|
|
|
procedure cboxZoomChange(Sender: TObject);
|
|
|
|
procedure actPrintExecute(Sender: TObject);
|
|
|
|
procedure actFirstPageExecute(Sender: TObject);
|
|
|
|
procedure actPrevPageExecute(Sender: TObject);
|
|
|
|
procedure actNextPageExecute(Sender: TObject);
|
|
|
|
procedure actLastPageExecute(Sender: TObject);
|
|
|
|
procedure actMainUpdate(Action: TBasicAction; var Handled: Boolean);
|
|
|
|
procedure actCancelExecute(Sender: TObject);
|
2016-06-21 13:19:39 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2016-07-03 15:42:06 +00:00
|
|
|
procedure VpPrintFormatComboBox1Change(Sender: TObject);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
procedure SetCaptions;
|
|
|
|
|
|
|
|
public
|
2016-06-21 13:48:55 +00:00
|
|
|
Resource: TVpResource;
|
|
|
|
Contact: TVpContact;
|
|
|
|
ReturnCode: TVpEditorReturnCode;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TVpPrintPreviewDialog = class (TVpBaseDialog)
|
|
|
|
private
|
2016-06-21 13:48:55 +00:00
|
|
|
FControlLink: TVpControlLink;
|
|
|
|
FAutoPrint: Boolean;
|
|
|
|
FBottomMargin: Extended;
|
|
|
|
FEndDate: TDateTime;
|
|
|
|
FLeftMargin: Extended;
|
|
|
|
FMarginUnits: TVpItemMeasurement;
|
|
|
|
FRightMargin: Extended;
|
|
|
|
FStartDate: TDateTime;
|
|
|
|
FTopMargin: Extended;
|
|
|
|
FZoomFactor: TVpPPZoomFactor;
|
|
|
|
FWindowState: TWindowState;
|
|
|
|
FPrinter: TPrinter;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
protected
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
|
|
procedure SetAutoPrint(const v: Boolean);
|
|
|
|
procedure SetBottomMargin(const v: Extended);
|
|
|
|
procedure SetControlLink(const v: TVpControlLink);
|
|
|
|
procedure SetEndDate(const v: TDateTime);
|
|
|
|
procedure SetLeftMargin(const v: Extended);
|
|
|
|
procedure SetMarginUnits(const v: TVpItemMeasurement);
|
|
|
|
procedure SetRightMargin(const v: Extended);
|
|
|
|
procedure SetStartDate(const v: TDateTime);
|
|
|
|
procedure SetTopMargin(const v: Extended);
|
|
|
|
procedure SetZoomFactor(const v: TVpPPZoomFactor);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
public
|
2016-06-21 13:48:55 +00:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
function Execute: Boolean; override;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
property Printer: TPrinter read FPrinter write FPrinter;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
published
|
2016-06-21 13:48:55 +00:00
|
|
|
property AutoPrint: Boolean read FAutoPrint write SetAutoPrint default False;
|
|
|
|
property BottomMargin: Extended read FBottomMargin write SetBottomMargin;
|
|
|
|
property ControlLink: TVpControlLink read FControlLink write SetControlLink;
|
|
|
|
property EndDate: TDateTime read FEndDate write SetEndDate;
|
|
|
|
property LeftMargin: Extended read FLeftMargin write SetLeftMargin;
|
|
|
|
property MarginUnits: TVpItemMeasurement read FMarginUnits write SetMarginUnits default imInches;
|
|
|
|
property RightMargin: Extended read FRightMargin write SetRightMargin;
|
|
|
|
property StartDate: TDateTime read FStartDate write SetStartDate;
|
|
|
|
property TopMargin: Extended read FTopMargin write SetTopMargin;
|
|
|
|
property WindowState: TWindowState read FWindowState write FWindowState default wsNormal;
|
|
|
|
property ZoomFactor: TVpPPZoomFactor read FZoomFactor write SetZoomFactor default zfFitToControl;
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
property DataStore;
|
|
|
|
property Options;
|
|
|
|
property Placement;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2016-06-07 16:34:18 +00:00
|
|
|
{$IFDEF LCL}
|
|
|
|
{$R *.lfm}
|
|
|
|
{$ELSE}
|
|
|
|
{$R *.dfm}
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
SetCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.SetCaptions;
|
|
|
|
begin
|
|
|
|
Self.Caption := RSDlgPrintPreview;
|
2016-06-21 13:48:55 +00:00
|
|
|
actPrint.Caption := RSPrintPrvPrint;
|
|
|
|
actPrint.Hint := RSPrintPrvPrintHint;
|
|
|
|
actFirstPage.Caption := RSPrintPrvFirstPage;
|
|
|
|
actFirstPage.Hint := RSPrintPrvFirstPageHint;
|
|
|
|
actPrevPage.Caption := RSPrintPrvPrevPage;
|
|
|
|
actPrevPage.Hint := RsPrintPrvPrevPageHint;
|
|
|
|
actNextPage.Caption := RSPrintPrvNextPage;
|
|
|
|
actNextPage.Hint := RSPrintPrvNextPageHint;
|
|
|
|
actLastPage.Caption := RSPrintPrvLastPage;
|
|
|
|
actLastPage.Hint := RSPrintPrvLastPageHint;
|
|
|
|
actCancel.Caption := RSPrintPrvCancel;
|
|
|
|
actCancel.Hint := RSPrintPrvCancelHint;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-07-03 15:42:06 +00:00
|
|
|
procedure TfrmPrintPreview.VpPrintFormatComboBox1Change(Sender: TObject);
|
|
|
|
begin
|
|
|
|
VpPrintPreview1.ForceUpdate;
|
|
|
|
VpPrintPreview1.FirstPage;
|
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
procedure TfrmPrintPreview.OKBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtCommit;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
constructor TVpPrintPreviewDialog.Create(AOwner: TComponent);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
inherited Create (AOwner);
|
|
|
|
FPlacement.Height := 480;
|
2016-07-03 14:47:03 +00:00
|
|
|
FPlacement.Width := 720;
|
2016-06-21 13:48:55 +00:00
|
|
|
StartDate := Now;
|
|
|
|
EndDate := Now + 7;
|
|
|
|
FZoomFactor := zfFitToControl;
|
|
|
|
FWindowState := wsNormal;
|
|
|
|
FAutoPrint := False;
|
|
|
|
FControlLink := SearchControlLink(Owner);
|
|
|
|
FPrinter := Printer;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
function TVpPrintPreviewDialog.Execute: Boolean;
|
2008-02-03 12:05:55 +00:00
|
|
|
var
|
2016-06-21 13:48:55 +00:00
|
|
|
EditForm: TfrmPrintPreview;
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
2016-06-21 13:48:55 +00:00
|
|
|
Application.CreateForm(TfrmPrintPreview, EditForm);
|
2008-02-03 12:05:55 +00:00
|
|
|
try
|
|
|
|
DoFormPlacement(EditForm);
|
|
|
|
EditForm.WindowState := WindowState;
|
|
|
|
EditForm.VpPrintPreview1.ControlLink := ControlLink;
|
|
|
|
EditForm.VpPrintFormatComboBox1.ControlLink := ControlLink;
|
|
|
|
EditForm.VpPrintPreview1.StartDate := StartDate;
|
|
|
|
EditForm.VpPrintPreview1.EndDate := EndDate;
|
|
|
|
EditForm.VpPrintPreview1.ZoomFactor := ZoomFactor;
|
|
|
|
EditForm.cboxZoom.ItemIndex := Integer (ZoomFactor);
|
|
|
|
EditForm.VpPrintPreview1.Printer := Printer;
|
2016-07-02 21:13:54 +00:00
|
|
|
EditForm.VpPrintPreview1.ForceUpdate;
|
2008-02-03 12:05:55 +00:00
|
|
|
EditForm.VpPrintPreview1.FirstPage;
|
|
|
|
EditForm.ShowModal;
|
|
|
|
if EditForm.ReturnCode = rtCommit then begin
|
|
|
|
Result := True;
|
|
|
|
end;
|
2016-06-21 13:48:55 +00:00
|
|
|
if AutoPrint and Assigned(FControlLink) and Result then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
Printer.BeginDoc;
|
|
|
|
try
|
2016-06-21 13:48:55 +00:00
|
|
|
FControlLink.Printer.Print(Printer, StartDate, EndDate);
|
2008-02-03 12:05:55 +00:00
|
|
|
finally
|
|
|
|
Printer.EndDoc;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
EditForm.Release;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
{ Handle new/deleted components}
|
|
|
|
procedure TVpPrintPreviewDialog.Notification(AComponent: TComponent;
|
|
|
|
Operation : TOperation);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
2016-06-21 13:48:55 +00:00
|
|
|
inherited Notification(AComponent, Operation);
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
if Operation = opRemove then begin
|
|
|
|
{Owned components going away}
|
|
|
|
if AComponent = FControlLink then begin
|
|
|
|
FControlLink := nil;
|
|
|
|
end;
|
2016-06-21 13:48:55 +00:00
|
|
|
end else
|
|
|
|
if Operation = opInsert then begin
|
2008-02-03 12:05:55 +00:00
|
|
|
if AComponent is TVpControlLink then begin
|
|
|
|
if not Assigned (FControlLink) then begin
|
|
|
|
FControlLink := TVpControlLink (AComponent);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetAutoPrint(const v: Boolean);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FAutoPrint then
|
|
|
|
FAutoPrint := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetBottomMargin(const v: Extended);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FBottomMargin then
|
|
|
|
FBottomMargin := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetControlLink(const v: TVpControlLink);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if FControlLink <> v then
|
|
|
|
FControlLink := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetEndDate(const v: TDateTime);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FEndDate then
|
|
|
|
FEndDate := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetLeftMargin(const v: Extended);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FLeftMargin then
|
|
|
|
FLeftMargin := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetMarginUnits(const v: TVpItemMeasurement);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FMarginUnits then
|
|
|
|
FMarginUnits := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetRightMargin(const v: Extended);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FRightMargin then
|
|
|
|
FRightMargin := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetStartDate(const v: TDateTime);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FStartDate then
|
|
|
|
FStartDate := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetTopMargin(const v: Extended);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FTopMargin then
|
|
|
|
FTopMargin := v;
|
|
|
|
end;
|
|
|
|
|
2016-06-21 13:48:55 +00:00
|
|
|
procedure TVpPrintPreviewDialog.SetZoomFactor(const v: TVpPPZoomFactor);
|
2008-02-03 12:05:55 +00:00
|
|
|
begin
|
|
|
|
if v <> FZoomFactor then
|
|
|
|
FZoomFactor := v;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.cboxZoomChange(Sender: TObject);
|
|
|
|
begin
|
2016-06-21 13:19:39 +00:00
|
|
|
VpPrintPreview1.ZoomFactor := TVpPPZoomFactor(cboxZoom.ItemIndex);
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actPrintExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtCommit;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actFirstPageExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
VpPrintPreview1.FirstPage;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actPrevPageExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
VpPrintPreview1.PrevPage;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actNextPageExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
VpPrintPreview1.NextPage;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actLastPageExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
VpPrintPreview1.LastPage;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actMainUpdate(Action: TBasicAction;
|
|
|
|
var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
if VpPrintPreview1.IsFirstPage then begin
|
|
|
|
actFirstPage.Enabled := False;
|
|
|
|
actPrevPage.Enabled := False;
|
|
|
|
end else begin
|
|
|
|
actFirstPage.Enabled := True;
|
|
|
|
actPrevPage.Enabled := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if VpPrintPreview1.IsLastPage then begin
|
|
|
|
actLastPage.Enabled := False;
|
|
|
|
actNextPage.Enabled := False;
|
|
|
|
end else begin
|
|
|
|
actLastPage.Enabled := True;
|
|
|
|
actNextPage.Enabled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.actCancelExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmPrintPreview.FormKeyDown(Sender: TObject; var Key: Word;
|
|
|
|
Shift: TShiftState);
|
|
|
|
begin
|
|
|
|
if Key = VK_ESCAPE then
|
|
|
|
actCancel.Execute;
|
|
|
|
end;
|
2016-06-07 16:34:18 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
end.
|
|
|
|
|