home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 December
/
Chip_2001-12_cd1.bin
/
zkuste
/
delphi
/
kolekce
/
d56
/
DM2KVCL.ZIP
/
PAGEDLG.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
2000-09-25
|
6KB
|
158 lines
{****************************************************************************}
{ Data Master 2000 }
{****************************************************************************}
unit PageDlg;
{$B-}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin, ExtCtrls, Buttons, Printers;
type
TPageSetupForm = class(TForm)
MainBevel: TBevel;
OkBitBtn: TBitBtn;
CancelBitBtn: TBitBtn;
HelpBitBtn: TBitBtn;
PreviewPB: TPaintBox;
GroupBox: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
LeftSE: TSpinEdit;
TopSE: TSpinEdit;
WidthSE: TSpinEdit;
HeightSE: TSpinEdit;
procedure PreviewPBPaint(Sender: TObject);
procedure PreviewPBMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PreviewPBMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PreviewPBMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SEChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
PageW,PageH: integer; {printer's props buffers}
sizing: boolean; {true when user resizes frame with mouse}
FXo,FYo,FPlotWidth,FPlotHeight: integer; {coordinate buffers}
Org,Temp: TPoint; {for mouse resizing}
x0,y0,x1,y1,g,fw,fh,fx,fy: longint; {used in paint & mouse handlers}
function InPage(X,Y: integer): boolean; {true when x,y belongs leaf}
public
{ Public declarations }
Xo,Yo,PlotWidth,PlotHeight: integer; {coords of plot on the page}
procedure Execute;
end;
var PageSetupForm: TPageSetupForm;
implementation // this unit is exact copy of version 9.0!
{$R *.DFM}
procedure TPageSetupForm.Execute;
begin
with PreviewPB do Width:=Height; {!!!! must be square!!!}
if (PageW=Printer.PageWidth) and (PageH=Printer.PageHeight) then
begin {set current frame coords to previous ONLY if W,H are same!}
LeftSE.Value:=round(Xo/PageW*100); TopSE.Value:=round(Yo/PageH*100);
WidthSE.Value:=round(PlotWidth/PageW*100);
HeightSE.Value:=round(PlotHeight/PageH*100);
end else
begin PageW:=Printer.PageWidth; PageH:=Printer.PageHeight; end;
SEChange(Self); {copy once more to Fxxx...}
if ShowModal=mrOk then
begin Xo:=FXo; Yo:=FYo; PlotWidth:=FPlotWidth; PlotHeight:=FPlotHeight; end;
end;
procedure TPageSetupForm.PreviewPBPaint(Sender: TObject);
begin {using ONLY X0,Y0,PlotWidth,PlotHeight values}
g:=round(PreviewPB.Width*0.03);
with PreviewPB.Canvas do
begin
if PageH>PageW then {portrait?}
begin
y0:=g; y1:=PreviewPB.Height;
x0:=round(PreviewPB.Width*(1-PageW/PageH)/2); x1:=PreviewPB.Width-x0;
end else {landscape?}
begin
x0:=g; x1:=PreviewPB.Width;
y0:=round(PreviewPB.Width*(1-PageH/PageW)/2); y1:=PreviewPB.Height-y0;
end;
Brush.Color:=clBlack; Rectangle(x0,y0,x1,y1); {paint shade}
Brush.Color:=clWhite; y0:=y0-g; y1:=y1-g; x0:=x0-g; x1:=x1-g;
Rectangle(x0,y0,x1,y1); {paint leaf}
fx:=round((x1-x0)*FXo/PageW); fw:=round((x1-x0)*FPlotWidth/PageW); {frame}
fy:=round((y1-y0)*FYo/PageH); fh:=round((y1-y0)*FPlotHeight/PageH);{coord}
Brush.Color:=clBlack; FrameRect(Rect(x0+fx,y0+fy,x0+fx+fw,y0+fy+fh));
end;
end;
function CorRect(x1,y1,x2,y2: integer): TRect; {check: x1<x2, y1,y2}
var i: integer;
begin {TAKEN FROM WINGRAF!}
if x1>x2 then begin i:=x1; x1:=x2; x2:=i; end;
if y1>y2 then begin i:=y1; y1:=y2; y2:=i; end;
Result:=Rect(x1,y1,x2,y2);
end;
function TPageSetupForm.InPage(X,Y: integer): boolean;
begin Result:=(x0<X) and (x1>X) and (y0<Y) and (y1>Y); end;
procedure TPageSetupForm.PreviewPBMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Sizing or (not InPage(X,Y)) then Exit;
Org:=Point(X,Y); Temp:=Org; Sizing:=true;
end;
procedure TPageSetupForm.PreviewPBMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if Sizing and InPage(X,Y) then
begin
PreviewPB.Canvas.Brush.Color:=clWhite;
PreviewPB.Canvas.DrawFocusRect(CorRect(Org.X, Org.Y, Temp.X, Temp.Y));
Temp:=Point(X,Y);
PreviewPB.Canvas.DrawFocusRect(CorRect(Org.X, Org.Y, Temp.X, Temp.Y));
end;
end;
procedure TPageSetupForm.PreviewPBMouseUp(Sender: TObject;
Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
var R: TRect; w,h: integer;
begin
if Sizing and InPage(X,Y) then
begin
Sizing:=false; R:=CorRect(Org.X, Org.Y, Temp.X, Temp.Y);
w:=round((R.Right-R.Left)/(x1-x0)*100);
if w>WidthSE.MinValue then WidthSE.Value:=w;
h:=round((R.Bottom-R.Top)/(y1-y0)*100);
if h>HeightSE.MinValue then HeightSE.Value:=h;
LeftSE.Value:=round((R.Left-x0)/(x1-x0)*100);
TopSE.Value:=round((R.Top-y0)/(y1-y0)*100);
PreviewPB.Refresh;
end;
end;
procedure TPageSetupForm.SEChange(Sender: TObject);
begin
FXo:=round(LeftSE.Value*PageW/100); FYo:=round(TopSE.Value*PageH/100);
FPlotWidth:=round(WidthSE.Value*PageW/100);
FPlotHeight:=round(HeightSE.Value*PageH/100); PreviewPB.Refresh;
end;
procedure TPageSetupForm.FormCreate(Sender: TObject);
begin {set initial values from spinedits}
if Printer.Printers.Count=0 then Exit;{else error if no printers installed!}
PageW:=Printer.PageWidth; PageH:=Printer.PageHeight;
SEChange(Self);
Xo:=FXo; Yo:=FYo; PlotWidth:=FPlotWidth; PlotHeight:=FPlotHeight;
end;
end.