home *** CD-ROM | disk | FTP | other *** search
- Unit PrevForm;
-
- {
- Print Preview
- Version 2.0
- by Ben Ziegler
-
- Updated on:
- - April 11, 1998
- - December 18, 1997
-
- TODO:
- Printing in a thread (Refresh Next buttons as new pages come, etc)
- {
-
- Program Title: Ben Zeigler's Print Preview Component
- Program FileName: PrevForm.pas
- Creation Date: You'll have to ask Ben
- Notes: Created by Ben Ziegler (bziegler@Radix.Net)
- Required Files: Requires PrevPrinter & FormSettings & Res files Components
- Programming Language: Delphi 5 now...
- Targeted OS: 32-bit calls everywhere -- Win32
-
- Version Date Programmer Notes
- 2.00 ?????? BZ Initial release by Ben.
- 3.00 ?????? JGW Initial release by JGW for Delhpi 5. I have attempted
- to support several things. Notably the ability to have
- landscape and portrait plots at the same time as well as
- a bounding box-zoom control but didn't succeed. Mostly, I
- changed things to be compatable with all of the other code I had,
- and altered a few things based upon the kind of users I had--they
- got confused a lot.
- 3.01 09Feb01 JGW Problem: The original method of drawing was to simply
- take the metafile created and draw it to the canvas as is. What
- happened, however, was that whenever you changed printers, the
- metafile still had the attributes of the old printer, and even
- with minor differences, the printouts became inconsistant. And
- attempting to simply alter the metafiles was even more inconsistent.
- Solution (one of many I'm sure): Since metafiles are vectored,
- I will simply use StretchDraw to print the metafile and to view
- it on the screen. And since the bounds of the metafile seem to be
- variable, I picked a happy median that worked.
- Fun stuff, windows.
- 3.02 05May2001 jgw Added additional support so that the previewed images can be
- copied to the clipboard as jpeg's. This is intended to give support
- to sharing "pages" over HTML-based email. Because of this, it now
- requires the jpeg support that comes with delphi. If you don't have
- it, then comment out all "SaveAsJpeg" support.
-
- }
-
- Interface
-
- Uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, Buttons, PrevPrinter, Menus;
-
- Const
- crZoom = 40;
- ZOOMFACTOR = 1.5;
-
- Type
- TPreviewForm = Class( TForm )
- ToolBarPanel: TPanel;
- GridBut: TSpeedButton;
- ZoomCursorBut: TSpeedButton;
- HandCursorBut: TSpeedButton;
- OnePageBut: TSpeedButton;
- TwoPageBut: TSpeedButton;
- PrintBut: TButton;
- NextPageBut: TButton;
- PrevPageBut: TButton;
- CloseBut: TButton;
- AboutBut: TButton;
- ZoomBox: TComboBox;
- StatBarPanel: TPanel;
- CurPageLabel: TPanel;
- ZoomLabel: TPanel;
- Panel1: TPanel;
- HintLabel: TLabel;
- MoveButPanel: TPanel;
- FirstPageSpeed: TSpeedButton;
- PrevPageSpeed: TSpeedButton;
- NextPageSpeed: TSpeedButton;
- LastPageSpeed: TSpeedButton;
- PageNumSpeed: TSpeedButton;
- ScrollBox1: TScrollBox;
- ContainPanel: TPanel;
- PagePanel: TPanel;
- PB1: TPaintBox;
- PagePanel2: TPanel;
- PB2: TPaintBox;
- PrintDialog1: TPrintDialog;
- FitPageBut: TSpeedButton;
- FitWidthBut: TSpeedButton;
- SavePicture: TSaveDialog;
- CopyToClipboard: TButton;
- spdNewZoom: TSpeedButton;
- lbXYLoc: TLabel;
- PrinterSetupDialog1: TPrinterSetupDialog;
- CopyToClipboard2: TButton;
- PopupMenu1: TPopupMenu;
- spdMenu: TSpeedButton;
- SaveasEMF1: TMenuItem;
- SaveasJpeg1: TMenuItem;
- N1: TMenuItem;
- CopytoClipboardasEMF1: TMenuItem;
- CopytoClipboardasJpeg1: TMenuItem;
- N2: TMenuItem;
- Close1: TMenuItem;
- Procedure FormCreate( Sender: TObject );
- Procedure CloseButClick( Sender: TObject );
- Procedure FormClose( Sender: TObject; Var Action: TCloseAction );
- Procedure ScrollBox1Resize( Sender: TObject );
- Procedure PBPaint( Sender: TObject );
- Procedure GridButClick( Sender: TObject );
- Procedure FormShow( Sender: TObject );
- Procedure ZoomBoxChange( Sender: TObject );
- Procedure TwoPageButClick( Sender: TObject );
- Procedure NextPageButClick( Sender: TObject );
- Procedure PrevPageButClick( Sender: TObject );
- Procedure FirstPageSpeedClick( Sender: TObject );
- Procedure LastPageSpeedClick( Sender: TObject );
- Procedure ZoomCursorButClick( Sender: TObject );
- Procedure HandCursorButClick( Sender: TObject );
- Procedure PB1MouseDown( Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer );
- Procedure PB1MouseMove( Sender: TObject; Shift: TShiftState; X,
- Y: Integer );
- Procedure PB1MouseUp( Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer );
- Procedure PrintButClick( Sender: TObject );
- Procedure PageNumSpeedClick( Sender: TObject );
- Procedure OnePageButMouseUp( Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer );
- Procedure FitPageButClick( Sender: TObject );
- Procedure FitWidthButClick( Sender: TObject );
- Procedure AboutButClick( Sender: TObject );
- Procedure CopyToClipboardClick( Sender: TObject );
- Procedure FormKeyDown( Sender: TObject; Var Key: Word;
- Shift: TShiftState );
- Procedure FormKeyUp( Sender: TObject; Var Key: Word;
- Shift: TShiftState );
- Procedure lbXYLocClick( Sender: TObject );
- Procedure CopyToClipboard2Click( Sender: TObject );
- procedure spdMenuClick(Sender: TObject);
- procedure SaveasJpeg1Click(Sender: TObject);
- Protected
- RightShiftDown: Boolean;
- LeftShiftDown: Boolean;
- FCurPage: integer;
- OldHint: TNotifyEvent;
- DownX, DownY: integer;
- Moving: boolean;
- MouseOrigin: TPoint;
- PrevPoint: TPoint;
- NewOrigin: TPoint;
- OldOrigin: TPoint;
- MouseDragging: Boolean;
- Aspect: Single;
- Procedure DrawMetaFile( PB: TPaintBox; mf: TMetaFile );
- Procedure OnHint( Sender: TObject );
- Procedure SetCurPage( Val: integer );
- Procedure CheckEnable;
- Property CurPage: integer Read FCurPage Write SetCurPage;
- Public
- Zoom: double;
- PrevPrinterObj: TPreviewPrinter;
- End;
-
- Implementation
-
- Uses Gopage, Clipbrd, Printers, Jpeg;
-
- {$R *.DFM}
- {$R GRID.RES}
-
- Function MaxInt( Int1, Int2: Integer ): Integer;
- Begin
- If Int1 > Int2 Then
- Result := Int1
- Else
- Result := Int2;
- End; {MaxInt}
-
- Function MinInt( Int1, Int2: Integer ): Integer;
- Begin
- If Int1 < Int2 Then
- Result := Int1
- Else
- Result := Int2;
- End; {MinInt}
-
- Function MaxFloat( Int1, Int2: Single ): Single;
- Begin
- If Int1 > Int2 Then
- Result := Int1
- Else
- Result := Int2;
- End; {MaxInt}
-
- Function MinFloat( Int1, Int2: Single ): Single;
- Begin
- If Int1 < Int2 Then
- Result := Int1
- Else
- Result := Int2;
- End; {MinInt}
-
- Procedure TPreviewForm.FormCreate( Sender: TObject );
- Begin
- ZoomBox.ItemIndex := 0;
- WindowState := wsMaximized;
- Screen.Cursors[ crZoom ] := LoadCursor( hInstance, 'ZOOM_CURSOR' );
- ZoomCursorButClick( Nil );
- Caption := Application.Title;
- MouseDragging := False;
- RightShiftDown := False;
- LeftShiftDown := False;
- NewOrigin.X := 0;
- NewOrigin.Y := 0;
- End;
-
- Procedure TPreviewForm.CloseButClick( Sender: TObject );
- Begin
- Close;
- End;
-
- Procedure TPreviewForm.FormClose( Sender: TObject;
- Var Action: TCloseAction );
- Begin
- Action := caFree;
- Application.OnHint := OldHint;
- End;
-
- Procedure TPreviewForm.ScrollBox1Resize( Sender: TObject );
- Const
- BORD = 20;
- Var
- z: double;
- tmp: integer;
- TotWid: integer;
- Begin
- Aspect := MinInt( ScrollBox1.ClientWidth, ScrollBox1.ClientHeight ) /
- MaxInt( ScrollBox1.ClientWidth, ScrollBox1.ClientHeight );
- Case ZoomBox.ItemIndex Of
- 0: FitPageBut.Down := True;
- 1: FitWidthBut.Down := True;
- Else
- Begin
- FitPageBut.Down := False;
- FitWidthBut.Down := False;
- End;
- End;
-
- If ZoomBox.ItemIndex = -1 Then
- ZoomBox.ItemIndex := 0;
-
- Case ZoomBox.ItemIndex Of
- 0:
- z := ( ( ScrollBox1.ClientHeight - BORD ) / PixelsPerInch ) /
- ( PrevPrinterObj.PageHeight / PrevPrinterObj.PixelsPerInchY );
- 1:
- z := ( ( ScrollBox1.ClientWidth - BORD ) / PixelsPerInch ) /
- ( PrevPrinterObj.PageWidth / PrevPrinterObj.PixelsPerInchX );
- 2: z := Zoom;
- 3: z := 0.25;
- 4: z := 0.50;
- 5: z := 0.75;
- 6: z := 1.00;
- 7: z := 1.25;
- 8: z := 1.50;
- 9: z := 2.00;
- 10: z := 3.00;
- 11: z := 4.00;
- Else
- z := 1;
- End;
-
- If z > 20 Then
- z := 20
- Else If z < 0.15 Then
- z := 0.15;
- If ZoomBox.ItemIndex <> 0 Then OnePageBut.Down := True;
-
- // Page Width and height *should* change by orientations...
- PagePanel.Height := TRUNC( PixelsPerInch * z * PrevPrinterObj.PageHeight / PrevPrinterObj.PixelsPerInchY );
- PagePanel.Width := TRUNC( PixelsPerInch * z * PrevPrinterObj.PageWidth / PrevPrinterObj.PixelsPerInchX );
-
- PagePanel2.Visible := TwoPageBut.Down;
- If TwoPageBut.Down Then
- Begin
- PagePanel2.Width := PagePanel.Width;
- PagePanel2.Height := PagePanel.Height;
- End;
-
- TotWid := PagePanel.Width + BORD;
- If TwoPageBut.Down Then
- TotWid := TotWid + PagePanel2.Width + BORD;
-
- // Resize the Contain Panel
- tmp := PagePanel.Height + BORD;
- If tmp < ScrollBox1.ClientHeight Then tmp := ScrollBox1.ClientHeight - 1;
- ContainPanel.Height := tmp;
-
- tmp := TotWid;
- If tmp < ScrollBox1.ClientWidth Then tmp := ScrollBox1.ClientWidth - 1;
- ContainPanel.Width := tmp;
-
- // Center the Page Panel
- If PagePanel.Height + BORD < ContainPanel.Height Then
- Begin
- PagePanel.Top := ContainPanel.Height Div 2 - PagePanel.Height Div 2;
- End
- Else
- Begin
- PagePanel.Top := BORD Div 2;
- End;
- PagePanel2.Top := PagePanel.Top;
-
- If TotWid < ContainPanel.Width Then
- Begin
- PagePanel.Left := ContainPanel.Width Div 2 - ( TotWid - BORD ) Div 2;
- End
- Else
- Begin
- PagePanel.Left := BORD Div 2;
- End;
- PagePanel2.Left := PagePanel.Left + PagePanel.Width + BORD;
-
- // Set the Zoom Variable
- Zoom := z;
- ZoomLabel.Caption := Format( '%1.0n', [ z * 100 ] ) + '%';
- End;
-
- Procedure TPreviewForm.DrawMetaFile( PB: TPaintBox; mf: TMetaFile );
- Begin
- // PB.Canvas.Draw(0, 0, mf);
- Case PrevPrinterObj.Orientation Of
- poLandscape:
- PB.Canvas.StretchDraw( Rect( 0, 0, Round( 10.75 * PrevPrinterObj.PixelsPerInchX ),
- Round( 8.15 * PrevPrinterObj.PixelsPerInchY ) ), MF );
- poPortrait:
- PB.Canvas.StretchDraw( Rect( 0, 0, Round( 8.15 * PrevPrinterObj.PixelsPerInchX ),
- Round( 10.75 * PrevPrinterObj.PixelsPerInchY ) ), MF );
- End;
- End;
-
- Procedure TPreviewForm.PBPaint( Sender: TObject );
- Var
- PB: TPaintBox;
- x1, y1: integer;
- x, y: integer;
- Draw: boolean;
- Page: integer;
- Begin
- PB := Sender As TPaintBox;
-
- If PB = PB1 Then
- Begin
- Draw := CurPage < PrevPrinterObj.LastAvailPage;
- Page := CurPage;
- End
- Else
- Begin
- // PB2
- Draw := TwoPageBut.Down And ( CurPage + 1 < PrevPrinterObj.LastAvailPage );
- Page := CurPage + 1;
- End;
-
- SetMapMode( PB.Canvas.Handle, MM_ANISOTROPIC );
- SetWindowExtEx( PB.Canvas.Handle, PrevPrinterObj.PageWidth, PrevPrinterObj.PageHeight, Nil );
- SetViewportExtEx( PB.Canvas.Handle, PB.Width, PB.Height, Nil );
-
- If Draw Then
- DrawMetaFile( PB, PrevPrinterObj.MetaFiles[ Page ] );
-
- If GridBut.Down Then
- Begin
- PB.Canvas.Pen.Color := clLtGray;
-
- For x := 1 To PrevPrinterObj.PageWidth Div PrevPrinterObj.PixelsPerInchX Do
- Begin
- x1 := Round( PrevPrinterObj.PixelsPerInchX * x );
- PB.Canvas.MoveTo( x1, 0 );
- PB.Canvas.LineTo( x1, PrevPrinterObj.PageHeight );
- End;
-
- For y := 1 To PrevPrinterObj.PageHeight Div PrevPrinterObj.PixelsPerInchY Do
- Begin
- y1 := Round( PrevPrinterObj.PixelsPerInchY * y );
- PB.Canvas.MoveTo( 0, y1 );
- PB.Canvas.LineTo( PrevPrinterObj.PageWidth, y1 );
- End;
- End;
- End;
-
- Procedure TPreviewForm.GridButClick( Sender: TObject );
- Begin
- PB1.Invalidate;
- PB2.Invalidate;
- End;
-
- Procedure TPreviewForm.OnHint( Sender: TObject );
- Begin
- HintLabel.Caption := Application.Hint;
- End;
-
- Procedure TPreviewForm.FormShow( Sender: TObject );
- Begin
- CurPage := 0;
- OldHint := Application.OnHint;
- Application.OnHint := OnHint;
- CheckEnable;
- End;
-
- Procedure TPreviewForm.SetCurPage( Val: integer );
- Var
- tmp: integer;
- Begin
- FCurPage := Val;
- tmp := 0;
- If PrevPrinterObj <> Nil Then tmp := PrevPrinterObj.LastAvailPage;
- CurPageLabel.Caption := Format( 'Page %d of %d', [ Val + 1, tmp ] );
- PB1.Invalidate;
- PB2.Invalidate;
- End;
-
- Procedure TPreviewForm.ZoomBoxChange( Sender: TObject );
- Begin
- ScrollBox1Resize( Nil );
- ScrollBox1Resize( Nil );
- End;
-
- Procedure TPreviewForm.TwoPageButClick( Sender: TObject );
- Begin
- ZoomBox.ItemIndex := 0;
- ScrollBox1Resize( Nil );
- End;
-
- Procedure TPreviewForm.NextPageButClick( Sender: TObject );
- Begin
- CurPage := CurPage + 1;
- CheckEnable;
- End;
-
- Procedure TPreviewForm.PrevPageButClick( Sender: TObject );
- Begin
- CurPage := CurPage - 1;
- CheckEnable;
- End;
-
- Procedure TPreviewForm.CheckEnable;
- Begin
- NextPageBut.Enabled := CurPage + 1 < PrevPrinterObj.LastAvailPage;
- PrevPageBut.Enabled := CurPage > 0;
-
- NextPageSpeed.Enabled := NextPageBut.Enabled;
- PrevPageSpeed.Enabled := PrevPageBut.Enabled;
-
- FirstPageSpeed.Enabled := PrevPageBut.Enabled;
- LastPageSPeed.Enabled := NextPageBut.Enabled;
-
- PageNumSpeed.Enabled := PrevPrinterObj.LastAvailPage > 1;
- End;
-
- Procedure TPreviewForm.FirstPageSpeedClick( Sender: TObject );
- Begin
- CurPage := 0;
- CheckEnable;
- End;
-
- Procedure TPreviewForm.LastPageSpeedClick( Sender: TObject );
- Begin
- CurPage := PrevPrinterObj.LastAvailPage - 1;
- CheckEnable;
- End;
-
- Procedure TPreviewForm.ZoomCursorButClick( Sender: TObject );
- Begin
- PB1.Cursor := crZoom;
- PB2.Cursor := crZoom;
- End;
-
- Procedure TPreviewForm.HandCursorButClick( Sender: TObject );
- Begin
- PB1.Cursor := crHandPoint;
- PB2.Cursor := crHandPoint;
- End;
-
- Procedure TPreviewForm.PB1MouseDown( Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer );
- Var
- sx, sy: single;
- nx, ny: integer;
- Begin
- If ( ZoomCursorBut.Down ) Then
- Begin
- sx := X / PagePanel.Width;
- sy := Y / PagePanel.Height;
-
- If ssLeft In Shift Then
- Zoom := Zoom * ZOOMFACTOR;
- If ssRight In Shift Then
- Zoom := Zoom / ZOOMFACTOR;
- ZoomBox.ItemIndex := 2;
- ScrollBox1Resize( Nil );
-
- nx := TRUNC( sx * PagePanel.Width );
- ny := TRUNC( sy * PagePanel.Height );
- ScrollBox1.HorzScrollBar.Position := nx - ScrollBox1.Width Div 2;
- ScrollBox1.VertScrollBar.Position := ny - ScrollBox1.Height Div 2;
- End
- Else If ( spdNewZoom.Down ) And ( ssLeft In Shift ) Then
- Begin
- SetCapture( PB1.Canvas.Handle );
- MouseOrigin := Point( X, Y );
- PrevPoint := Point( X, Y );
- NewOrigin := Point( X, Y );
- PB1.Canvas.Pen.Color := clBlack;
- PB1.Canvas.Pen.Style := psDot;
- MouseDragging := TRUE;
- End
- Else If ( spdNewZoom.Down ) And ( ssRight In Shift ) Then
- Begin
- ZoomBox.ItemIndex := 0;
- Zoom := 100.0;
- ScrollBox1.HorzScrollBar.Position := 0;
- ScrollBox1.VertScrollBar.Position := 0;
- ScrollBox1Resize( Nil );
- Pb1.Invalidate;
- MouseDragging := False;
- End;
- If HandCursorBut.Down Then
- Begin
- DownX := X;
- DownY := Y;
- Moving := True;
- End;
- End;
-
- Procedure TPreviewForm.PB1MouseMove( Sender: TObject; Shift: TShiftState; X,
- Y: Integer );
- Var
- newWidth, NewHeight: LongInt;
- x1, x2, y1, y2: LongInt;
- Begin
- If ( moving ) And Not ( MouseDragging ) Then
- Begin
- ScrollBox1.HorzScrollBar.Position := ScrollBox1.HorzScrollBar.Position + ( DownX - X );
- ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position + ( DownY - Y );
- End
- Else If MouseDragging Then
- Begin
- With PB1.Canvas Do
- Begin
- SetROP2( Handle, R2_XORPEN );
- NewWidth := MaxInt( X, MouseOrigin.X ) - MinInt( X, MouseOrigin.X );
- NewHeight := MaxInt( Y, MouseOrigin.Y ) - MinInt( Y, MouseOrigin.Y );
-
- (*
- This is "Zooming Code" that doesn't...work... ahem... help?
- if ScrollBox1.ClientWidth > ScrollBox1.ClientHeight then
- begin
- if NewHeight > NewWidth then // This should read that "Aspect" is the
- NewWidth := Round( NewHeight / Aspect ) // percentage the small is of the larger;
- else // I just need to do the resizing
- NewHeight := Round( NewWidth * Aspect );
- end
- else
- begin
- if NewWidth > NewHeight then // This should read that "Aspect" is the
- NewHeight := Round( NewWidth / Aspect ) // percentage the small is of the larger;
- else // I just need to do the resizing
- NewWidth := Round( NewHeight * Aspect );
- end;*)
-
- If ( MouseOrigin.x <> PrevPoint.x ) Or ( MouseOrigin.y <> PrevPoint.y ) Then
- PolyLine( [ MouseOrigin, Point( MouseOrigin.X, PrevPoint.Y ),
- PrevPoint, Point( PrevPoint.X, MouseOrigin.Y ),
- MouseOrigin ] );
-
- NewOrigin.X := ( MinInt( MouseOrigin.X, X ) - MaxInt( MouseOrigin.X, X ) ) Div 2 + MinInt( MouseOrigin.X, X );
- NewOrigin.Y := ( MinInt( MouseOrigin.Y, Y ) - MaxInt( MouseOrigin.Y, Y ) ) Div 2 + MinInt( MouseOrigin.Y, Y );
-
- { // More zooming code
- if ( X > MouseOrigin.X ) then
- PrevPoint.X := MouseOrigin.X + NewWidth
- else if ( X < MouseOrigin.X ) then
- MouseOrigin.X := PrevPoint.X + NewWidth;
- if ( Y > MouseOrigin.Y ) then
- PrevPoint.Y := MouseOrigin.Y + NewHeight
- else if ( Y < MouseOrigin.Y ) then
- MouseOrigin.Y := PrevPoint.Y + NewHeight;}
-
- PrevPoint := Point( X, Y );
- PolyLine( [ MouseOrigin, Point( MouseOrigin.X, PrevPoint.Y ),
- PrevPoint, Point( PrevPoint.X, MouseOrigin.Y ),
- MouseOrigin ] );
-
- End;
- End;
- (*
- I was using this to try and debug the zooming box...
- if MouseDragging then
- begin
- lbXYLoc.Caption := '[ ( ' + IntToStr(X) + ', ' + IntToStr(Y) + ' ) ' + IntToStr( NewWidth ) + ',' + IntToStr( NewHeight ) + ' ]';
- lbXYLoc.Caption := lbXYLoc.Caption + ' [ L:' + IntToStr( PB1.Left ) + ', T:' + IntToStr( PB1.Top ) + ' ]';
- end
- else
- lbXYLoc.Caption := '[ ( ' + IntToStr(X) + ', ' + IntToStr(Y) + ' ) ' + IntToStr( ContainPanel.Top ) + ',' + IntToStr( ContainPanel.Left) + ' ]';*)
- End;
-
- Procedure TPreviewForm.PB1MouseUp( Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer );
- Var
- NewWidth, NewHeight: LongInt;
- OffsetX, OffsetY: LongInt;
- Target, sx, sy: single;
- Begin
- Moving := False;
-
- If MouseDragging Then
- Begin
- MouseDragging := FALSE;
- ReleaseCapture;
- NewOrigin.X := ( MinInt( MouseOrigin.X, X ) - MaxInt( MouseOrigin.X, X ) ) Div 2 + MinInt( MouseOrigin.X, X );
- NewOrigin.Y := ( MinInt( MouseOrigin.Y, Y ) - MaxInt( MouseOrigin.Y, Y ) ) Div 2 + MinInt( MouseOrigin.Y, Y );
-
- With PB1.Canvas Do
- Begin
- SetROP2( Handle, R2_XORPEN );
- PolyLine( [ MouseOrigin, Point( MouseOrigin.X, PrevPoint.Y ),
- PrevPoint, Point( PrevPoint.X, MouseOrigin.Y ),
- MouseOrigin ] );
- End;
- NewWidth := MaxInt( X, MouseOrigin.X ) - MinInt( X, MouseOrigin.X );
- NewHeight := MaxInt( Y, MouseOrigin.Y ) - MinInt( Y, MouseOrigin.Y );
-
- If NewWidth <> 0 Then
- NewWidth := ScrollBox1.ClientWidth Div ( ScrollBox1.ClientWidth Div NewWidth ) //Pb1.Width div (PB1.Width div NewWidth)
- Else
- NewWidth := ScrollBox1.ClientWidth;
- If NewHeight <> 0 Then
- NewHeight := ScrollBox1.ClientHeight Div ( ScrollBox1.ClientHeight Div NewHeight ) //Pb1.Height div (PB1.Height div NewHeight)
- Else
- NewHeight := ScrollBox1.ClientHeight;
-
- If ScrollBox1.ClientWidth > ScrollBox1.ClientHeight Then
- Begin
- If NewHeight > NewWidth Then // This should read that "Aspect" is the
- NewWidth := Round( NewHeight / Aspect ) // percentage the small is of the larger;
- Else // I just need to do the resizing
- NewHeight := Round( NewWidth * Aspect );
- End
- Else
- Begin
- If NewWidth > NewHeight Then // This should read that "Aspect" is the
- NewHeight := Round( NewWidth / Aspect ) // percentage the small is of the larger;
- Else // I just need to do the resizing
- NewWidth := Round( NewHeight * Aspect );
- End;
-
- If NewWidth <> 0 Then
- sx := ScrollBox1.ClientWidth / ( NewWidth )
- Else
- Sx := 1;
- If NewHeight <> 0 Then
- sy := ScrollBox1.ClientHeight / ( NewHeight )
- Else
- Sy := 1;
-
- Target := MinFloat( Sx, SY );
- If Target = 0 Then
- Target := 1;
-
- { NewOrigin.X := Round( MouseOrigin.X * Target + ( ContainPanel.Left * Target )) ;
- NewOrigin.Y := Round( MouseOrigin.Y * Target + ( ContainPanel.Top * Target ));}
- NewOrigin.X := Round( ( MouseOrigin.X + ContainPanel.Left + ( NewWidth Div 2 ) ) * Sx );
- NewOrigin.Y := Round( ( MouseOrigin.Y + ContainPanel.Top + ( NewHeight Div 2 ) ) * Sy );
- ZoomBox.ItemIndex := 2;
- Zoom := Target;
- ScrollBox1Resize( Nil );
-
- // Original Code
- Panel1.Width := Round( Sx * Panel1.Width );
- Panel1.Height := Round( Sy * Panel1.Height );
-
- With ScrollBox1 Do
- Begin
- HorzScrollBar.Range := Pb1.Width;
- VertScrollBar.Range := Pb1.Height;
- HorzScrollBar.Position := NewOrigin.X - ( NewWidth Div 2 );
- VertScrollBar.Position := NewOrigin.Y - ( NewHeight Div 2 );
- End;
-
- //ScrollBox1.HorzScrollBar.Position := ( NewOrigin.X );
- //ScrollBox1.VertScrollBar.Position := ( NewOrigin.Y );
-
- PB1.Invalidate;
- End;
- End;
-
- Procedure TPreviewForm.PrintButClick( Sender: TObject );
- Begin
- PrevPrinterObj.CurPageIndex := CurPage;
- PrevPrinterObj.PrintDialog;
- PB1.Repaint;
- PB2.Repaint;
- End;
-
- Procedure TPreviewForm.PageNumSpeedClick( Sender: TObject );
- Var
- gp: TGoPageForm;
- Begin
- gp := TGoPageForm.Create( Self );
- gp.PageNum.MaxValue := PrevPrinterObj.LastAvailPage;
- gp.PageNum.Value := CurPage + 1;
-
- If gp.ShowModal = mrOK Then
- Begin
- CurPage := gp.PageNum.Value - 1;
- CheckEnable;
- End;
- gp.Free;
- End;
-
- Procedure TPreviewForm.OnePageButMouseUp( Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
- Begin
- ZoomBox.ItemIndex := 0;
- ScrollBox1Resize( Nil );
- End;
-
- Procedure TPreviewForm.FitPageButClick( Sender: TObject );
- Begin
- ZoomBox.ItemIndex := 0;
- ZoomBoxChange( Nil );
- End;
-
- Procedure TPreviewForm.FitWidthButClick( Sender: TObject );
- Begin
- ZoomBox.ItemIndex := 1;
- ZoomBoxChange( Nil );
- End;
-
- Procedure TPreviewForm.AboutButClick( Sender: TObject );
- Var
- X: LongInt;
- Begin
- If SavePicture.Execute Then
- Begin
- For X := 0 To PrevPrinterObj.PageNumber - 1 Do
- Begin
- If Not ( ( X > -1 ) And ( X < PrevPrinterObj.PageTitles.Count ) ) Then
- PrevPrinterObj.MetaFiles[ X ].SaveToFile( Copy( SavePicture.FileName, 1,
- Pos( '.', SavePicture.FileName ) - 1 ) + IntToStr( X + 1 ) + '.EMF' )
- Else
- PrevPrinterObj.MetaFiles[ X ].SaveToFile( PrevPrinterObj.PageTitles[ x ] + IntToStr( X + 1 ) + '.EMF' )
- End;
- End;
- End;
-
- Procedure TPreviewForm.CopyToClipboardClick( Sender: TObject );
- Begin
- Clipboard.Assign( PrevPrinterObj.MetaFiles[ FCurPage ] );
- End;
-
- Procedure TPreviewForm.FormKeyDown( Sender: TObject; Var Key: Word;
- Shift: TShiftState );
- Begin
- If ssRight In Shift Then
- RightShiftDown := True
- Else
- RightShiftDown := False;
- If ssLeft In Shift Then
- LeftShiftDown := True
- Else
- LeftShiftDown := False;
- End;
-
- Procedure TPreviewForm.FormKeyUp( Sender: TObject; Var Key: Word;
- Shift: TShiftState );
- Begin
- If ssRight In Shift Then
- RightShiftDown := True
- Else
- RightShiftDown := False;
- If ssLeft In Shift Then
- LeftShiftDown := True
- Else
- LeftShiftDown := False;
- End;
-
- Procedure TPreviewForm.lbXYLocClick( Sender: TObject );
- Begin
- lbXYLoc.Caption := '( ' + IntToStr( ScrollBox1.HorzScrollBar.Position ) + ', ' + IntToStr( ScrollBox1.VertScrollBar.Position ) + ' )';
- End;
-
- Procedure TPreviewForm.CopyToClipboard2Click( Sender: TObject );
- Var
- aBitmap: TBitmap;
- aJpeg: TJpegImage;
- OldCursor: TCursor;
- Begin
- aBitmap := TBitmap.Create;
- aJpeg := TJpegImage.Create;
- OldCursor := Screen.Cursor;
- try
- Screen.Cursor := crHourglass;
- aBitmap.Width := GetDeviceCaps( Printer.Handle, PHYSICALWIDTH );
- aBitmap.Height := GetDeviceCaps( Printer.Handle, PHYSICALHEIGHT );
-
- aBitmap.Canvas.Brush.Color := clWhite;
- aBitmap.Canvas.FillRect( Rect( 0, 0, aBitmap.Width, aBitmap.Height ) );
-
- Windows.PlayEnhMetaFile(
- aBitmap.Canvas.Handle,
- PrevPrinterObj.Metafiles[ FCurPage ].Handle,
- Rect( 0, 0, aBitmap.Width, aBitmap.Height ) );
-
- aJpeg.CompressionQuality := 100;
- aJpeg.Assign( aBitmap );
- aJpeg.Compress;
-
- Clipboard.Assign( aJpeg );
- finally
- aJpeg.Free;
- aBitmap.Free;
- Screen.Cursor := OldCursor;
- end;
- End;
-
- procedure TPreviewForm.spdMenuClick(Sender: TObject);
- var
- P: TPoint;
- begin
- P := ClientToScreen( Point(0, Self.Top+spdMenu.Height-Self.Top) );
- PopupMenu1.Popup( P.X+spdMenu.Left, P.Y );
- end;
-
- procedure TPreviewForm.SaveasJpeg1Click(Sender: TObject);
- Var
- X: LongInt;
- aWid, aHei: LongInt;
- aBitmap: TBitmap;
- aJpeg: TJpegImage;
- OldCursor: TCursor;
- Begin
- SavePicture.Filter := 'JPEG Files|*.jpg;*.jpeg|All Files|*.*';
- try
- If SavePicture.Execute Then
- Begin
- aBitmap := TBitmap.Create;
- aJpeg := TJpegImage.Create;
- OldCursor := Screen.Cursor;
- try
- Screen.Cursor := crHourglass;
-
- aWid := GetDeviceCaps( Printer.Handle, PHYSICALWIDTH );
- aHei := GetDeviceCaps( Printer.Handle, PHYSICALHEIGHT );
- For X := 0 To PrevPrinterObj.PageNumber - 1 Do
- Begin
- aBitmap.Width := aWid;
- aBitmap.Height := aHei;
- aBitmap.Canvas.Brush.Color := clWhite;
- aBitmap.Canvas.FillRect( Rect( 0, 0, aBitmap.Width, aBitmap.Height ) );
-
- Windows.PlayEnhMetaFile( aBitmap.Canvas.Handle,
- PrevPrinterObj.Metafiles[ X ].Handle,
- Rect( 0, 0, aBitmap.Width, aBitmap.Height ) );
-
- aJpeg.CompressionQuality := 100;
- aJpeg.Assign( aBitmap );
- aJpeg.Compress;
-
- If Not ( ( X > -1 ) And ( X < PrevPrinterObj.PageTitles.Count ) ) Then
- aJpeg.SaveToFile( Copy( SavePicture.FileName, 1,
- Pos( '.', SavePicture.FileName ) - 1 ) + IntToStr( X + 1 ) + '.JPG' )
- Else
- aJpeg.SaveToFile( PrevPrinterObj.PageTitles[ x ] + IntToStr( X + 1 ) + '.JPG' );
- Application.ProcessMessages;
- End;
- finally
- aJpeg.Free;
- aBitmap.Free;
- Screen.Cursor := OldCursor;
-
- end;
- End;
- finally
- SavePicture.Filter := 'Windows MetaFiles|*.WMF|All Files|*.*';
- end;
- end;
-
- End.
-
-