home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 March
/
Chip_1999-03_cd.bin
/
zkuste
/
delphi
/
D12
/
ALREP.ZIP
/
alprev.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-08-13
|
5KB
|
202 lines
unit alprev;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, AlRep;
type
tAlPreview = class(TScrollBox) // tScrollingWinControl ???
private
{ Private-Deklarationen }
fPage : integer;
fZoom : integer;
pbxPage : tPaintbox;
FTitle : string;
fBusy : boolean;
procedure SetPageNumber(value:integer);
function GetPageCount:integer;
procedure SetZoom (value:integer);
procedure UpdatePage(Sender:tObject);
protected
{ Protected-Deklarationen }
public
FPages : tPages;
{ Public-Deklarationen }
constructor Create (aOwner:tComponent); override;
destructor Destroy; override;
procedure FirstPage;
procedure LastPage;
procedure NextPage;
procedure PrevPage;
procedure Print (pfrom,pto:integer);
property PageNumber:integer read fPage write SetPageNumber;
property Zoom:integer read fZoom write SetZoom default 100;
property PageCount:integer read GetPageCount;
property Busy:boolean read FBusy;
// property Pages:tPages read FPages write FPages;
published
{ Published-Deklarationen }
property Title:string read FTitle write FTitle;
end;
procedure Register;
implementation
uses
Printers;
constructor tAlPreview.Create(aOwner:tComponent);
begin
inherited Create (aOwner);
fPage := 1;
fZoom := 100;
fBusy := false;
if NOT (csDesigning in ComponentState) then
begin
pbxPage := tPaintBox.Create(Self);
pbxPage.Parent := Self;
pbxPage.Left := 15;
pbxPage.Top := 15;
pbxPage.Width := 823; // Din A4 screen width
pbxPage.Height := 1164; // Din A4 screen height
pbxPage.ParentColor := false;
pbxPage.Color := clWindow;
FPages := tPages.Create;
pbxPage.OnPaint := UpdatePage;
end;
end;
destructor tAlPreview.Destroy;
begin
if not (csDesigning in ComponentState) then
begin
fPages.Clear;
fPages.Free;
pbxPage.Free;
end;
inherited destroy;
end;
procedure tAlPreview.UpdatePage(Sender:tObject);
begin
pbxPage.Width := Round(AlPrinter.PageWidth*fZoom/100.0);
pbxPage.Height := Round(AlPrinter.PageHeight*fZoom/100.0);
VertScrollBar.Range := pbxPage.Height+30;
HorzScrollBar.Range := pbxPage.Width+30;
pbxPage.Canvas.Brush.Color := clWindow;
pbxPage.Canvas.FillRect (pbxPage.ClientRect);
if (fPage>0) and (fPage<=PageCount) then
pbxPage.Canvas.StretchDraw(pbxPage.ClientRect,FPages[fPage-1]);
end;
procedure tAlPreview.SetPageNumber(value:integer);
begin
if (value>0) and (value<=AlPrinter.PageCount) then
begin
fPage := value;
UpdatePage (Self);
end;
end;
function tAlPreview.GetPageCount:integer;
begin
result := FPages.Count;
end;
procedure tAlPreview.SetZoom(value:integer);
begin
if value<>fZoom then
if (value>=25) and (value<=200) then
begin
fZoom := value;
UpdatePage (Self);
end;
end;
procedure tAlPreview.FirstPage;
begin
SetPageNumber (1);
end;
procedure tAlPreview.LastPage;
begin
if {AlPrinter.}PageCount>0 then
SetPageNumber ({AlPrinter.}PageCount);
end;
procedure tAlPreview.NextPage;
begin
if fPage<{AlPrinter.}PageCount then
begin
inc (fPage);
UpdatePage (Self);
end;
end;
procedure tAlPreview.PrevPage;
begin
if fPage>1 then
begin
dec(fPage);
UpdatePage (Self);
end;
end;
procedure tAlPreview.Print (pFrom,pTo:integer);
var
i : Integer;
s : String;
begin
FBusy := true;
if PageCount > 0 then
begin
Printer.Title := Title;
if not Printer.Printing then
Printer.BeginDoc;
i := pFrom;
// if Assigned(Print_Preview) then
// s := Print_Preview.Panel2.Caption;
try
// if Assigned(Print_Preview) then
// begin
// Print_Preview.Panel2.Caption :=
// Format('Printing page %d of %d',[1, PageCount]);
// Print_Preview.Panel2.repaint;
// end;
Printer.Canvas.StretchDraw( Rect(0,0,Printer.PageWidth,
Printer.PageHeight),
FPages[i-1]);
for i := pFrom+1 to pTo do
begin
// if Assigned(Print_Preview) then
// begin
// Print_Preview.Panel2.Caption :=
// Format('Printing page %d of %d',[i, PageCount]);
// Print_Preview.Panel2.repaint;
// end;
Printer.NewPage;
Printer.Canvas.StretchDraw( Rect(0,0,Printer.PageWidth,
Printer.PageHeight),
FPages[i-1]);
end;
finally
Printer.EndDoc;
// if Assigned(Print_Preview) then
// Print_Preview.Panel2.Caption := s;
end; // try ... finally
end; // if PageCount>0
FBusy := false;
end; // procedure tAlPreview.Print
procedure Register;
begin
RegisterComponents('AlRep', [tAlPreview]);
end;
end.