⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adfaxprn.pas

📁 Async Professional 4.04
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*********************************************************}
{*                   ADFAXPRN.PAS 4.04                   *}
{*      Copyright (C) TurboPower Software 1996-2002      *}
{*                 All rights reserved.                  *}
{*********************************************************}

{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}

{Options required for this unit}
{$G+,X+,F+}

unit AdFaxPrn;
  { Apro Fax printer component}

interface

uses
  WinTypes,
  WinProcs,
  SysUtils,
  Classes,
  Graphics,
  Forms,
  Dialogs,
  Printers,
  ooMisc,
  AdFaxCvt;

type
  { Fax Printer Log Codes }
  TFaxPLCode = (lcStart, lcFinish, lcAborted, lcFailed);

  { Fax Printer Property Types }
  TFaxPrintScale    = (psNone, psFitToPage);
  TFaxPrintProgress = (ppIdle, ppComposing, ppRendering, ppSubmitting, ppConverting);

  { Fax Printer Events }
  TFaxPrnNextPageEvent = procedure(Sender: TObject; CP, TP: Word) of object;
  TFaxPLEvent = procedure(Sender: TObject; FaxPLCode: TFaxPLCode) of object;
  TFaxPrintStatusEvent = procedure(Sender: TObject;
    StatusCode: TFaxPrintProgress) of object;
const
  { Fax Printer Log Defaults }
  afpDefFPLFileName      = 'FAXPRINT.LOG';

  { Fax Printer Margin Defaults }
  afpDefFaxHeaderCaption = 'FILE: $F';
  afpDefFaxHeaderEnabled = True;
  afpDefFaxFooterCaption = 'PAGE: $P of $N';
  afpDefFaxFooterEnabled = True;

  { Fax Printer Defaults }
  afpDefFaxPrnCaption    = 'APro Fax Printer';
  afpDefFaxPrintScale    = psFitToPage;
  afpDefFaxMultiPage     = False;

type
  TApdCustomFaxPrinter = class;

  TApdCustomFaxPrinterLog = class(TApdBaseComponent)
   protected
    { Protected declarations }
    FFaxPrinter    : TApdCustomFaxPrinter;
    FLogFileName   : String;
   public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    procedure UpdateLog(const LogCode: TFaxPLCode);

    property FaxPrinter : TApdCustomFaxPrinter
      read FFaxPrinter;
    property LogFileName : String
      read FLogFileName write FLogFileName;
  end;

  TApdCustomFaxPrinterMargin = class(TPersistent)
   protected
    { Protected declarations }
    FCaption : String;
    FEnabled : Boolean;
    FFont    : TFont;
    FHeight  : Word;
   public
    { Public declarations }
    constructor Create; virtual;
    destructor Destroy; override;
    procedure SetFont(const NewFont: TFont);

    property Caption : string
      read FCaption write FCaption;
    property Enabled : Boolean
      read FEnabled write FEnabled;
    property Font : TFont
      read FFont write SetFont;
    property Height : Word
      read FHeight write FHeight default 0;
  end;

  TApdAbstractFaxPrinterStatus = class(TApdBaseComponent)
   protected {private}
    FDisplay : TForm;
    FPosition: TPosition;
    FCtl3D   : Boolean;
    FVisible : Boolean;
    FCaption : String;                                            
   protected
    FFaxPrinter : TApdCustomFaxPrinter;
    procedure SetPosition(const Value: TPosition);
    procedure SetCtl3D(const Value: Boolean);
    procedure SetVisible(const Value: Boolean);
    procedure SetCaption(const Value: String);                     
    procedure GetProperties;
    procedure Show;

   public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure UpdateDisplay(First, Last: Boolean); virtual; abstract;
    procedure CreateDisplay; dynamic; abstract;
    procedure DestroyDisplay; dynamic; abstract;

    property Display: TForm
      read FDisplay write FDisplay;
    property FaxPrinter : TApdCustomFaxPrinter
      read FFaxPrinter;

   published
    property Position : TPosition
      read FPosition write SetPosition;
    property Ctl3D : Boolean
      read FCtl3D write SetCtl3D;
    property Visible : Boolean
      read FVisible write SetVisible;
    property Caption : String
      read FCaption write SetCaption;                            
  end;

  TApdFaxPrinterLog = class(TApdCustomFaxPrinterLog)
   published
    { Published declarations }
    property LogFileName;
  end;

  TApdFaxPrinterMargin = class(TApdCustomFaxPrinterMargin)
   published
    { Published declarations }
    property Caption;
    property Enabled;
    property Font;
  end;

  TApdCustomFaxPrinter = class(TApdBaseComponent)
  {private} public
    { Fax Filename }
    FFileName            : String;
    { Fax Page Counts }
    FTotalFaxPages       : Word;
    FCurrentPrintingPage : Word;
    FFirstPageToPrint    : Word;
    FLastPageToPrint     : Word;

    { Fax properties }
    FFaxResolution       : TFaxResolution;
    FFaxWidth            : TFaxWidth;
    FPrintScale          : TFaxPrintScale;
    FMultiPage           : Boolean;

    { Fax Print Status Dialog }
    FStatusDisplay       : TApdAbstractFaxPrinterStatus;
    FFaxPrintProgress    : TFaxPrintProgress;
    FFaxPrinterLog       : TApdFaxPrinterLog;

    { Fax Print Setup Dialog }
    FPrintDialog         : TPrintDialog;

    { Fax Unpacker }
    FFaxUnpack           : TApdFaxUnpacker;

    { page header/footer information }
    FFaxHeader           : TApdFaxPrinterMargin;
    FFaxFooter           : TApdFaxPrinterMargin;

    { fax printer events }
    FOnNextPage          : TFaxPrnNextPageEvent;
    FOnFaxPrintLog       : TFaxPLEvent;
    FOnFaxPrintStatus    : TFaxPrintStatusEvent;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;

    procedure SetCaption(const Value: String);
    function GetCaption : String;
    procedure SetFaxFileName(const Value: String);
    procedure SetStatusDisplay(const Value: TApdAbstractFaxPrinterStatus);
    procedure SetFaxPrintLog(const Value: TApdFaxPrinterLog);

    function ReplaceHFParams(Value: String; Page: Word): String;
    procedure CreateFaxHeader(FaxCanvas : TCanvas; PN: Word; var AreaRect: TRect); virtual;
    procedure CreateFaxFooter(FaxCanvas : TCanvas; PN: Word; var AreaRect: TRect); virtual; 
    procedure SetFaxPrintProgress(const NewProgress : TFaxPrintProgress);
    procedure FaxPrintLog(LogCode: TFaxPLCode);
  public
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    function PrintSetup : Boolean;                                   
    procedure PrintFax;
    procedure PrintAbort;

    { read only properties }
    property FaxWidth : TFaxWidth
      read FFaxWidth default afcDefFaxCvtWidth;                      
    property FaxResolution : TFaxResolution
      read FFaxResolution default afcDefResolution;
    property TotalFaxPages : Word
      read FTotalFaxPages default 0;
    property CurrentPrintingPage : Word
      read FCurrentPrintingPage default 0;
    property FirstPageToPrint: Word
      read FFirstPageToPrint write FFirstPageToPrint default 0;
    property LastPageToPrint : Word
      read FLastPageToPrint write FLastPageToPrint default 0;
    property PrintProgress : TFaxPrintProgress
      read FFaxPrintProgress write FFaxPrintProgress ;

  {published}
    property Caption : String
      read GetCaption write SetCaption;
    property FaxFooter : TApdFaxPrinterMargin
      read FFaxFooter write FFaxFooter;
    property FaxHeader : TApdFaxPrinterMargin
      read FFaxHeader write FFaxHeader;
    property FaxPrinterLog : TApdFaxPrinterLog
      read FFaxPrinterLog write SetFaxPrintLog;
    property FileName : String
      read FFileName write SetFaxFileName;
    property MultiPage : Boolean
      read FMultiPage write FMultiPage;
    property PrintScale : TFaxPrintScale
      read FPrintScale write FPrintScale default afpDefFaxPrintScale;
    property StatusDisplay : TApdAbstractFaxPrinterStatus
      read FStatusDisplay write SetStatusDisplay;

    property OnNextPage : TFaxPrnNextPageEvent
      read FOnNextPage write FOnNextPage;
    property OnFaxPrintLog : TFaxPLEvent
      read FOnFaxPrintLog write FOnFaxPrintLog;
    property OnFaxPrintStatus : TFaxPrintStatusEvent
      read FOnFaxPrintStatus write FOnFaxPrintStatus;
  end;

  TApdFaxPrinter = class(TApdCustomFaxPrinter)
  published
    property Caption;
    property FaxFooter;
    property FaxHeader;
    property FaxPrinterLog;
    property FileName;
    property MultiPage;
    property PrintScale;
    property StatusDisplay;

    property OnNextPage;
    property OnFaxPrintLog;
    property OnFaxPrintStatus;
  end;

implementation

{$IFDEF TRIALRUN}
  {$I TRIAL07.INC}
  {$I TRIAL03.INC}
  {$I TRIAL01.INC}
{$ENDIF}

{ Misc Stuff }

function SearchForDisplay(const Value: TComponent): TApdAbstractFaxPrinterStatus;

  function FindStatusDisplay(const Value: TComponent): TApdAbstractFaxPrinterStatus;
  var
    I: Integer;
  begin
    Result := nil;
    if not Assigned(Value) then
      exit;
    for I := 0 to Value.ComponentCount-1 do begin
      if Value.Components[I] is TApdAbstractFaxPrinterStatus then begin
        Result := TApdAbstractFaxPrinterStatus(Value.Components[I]);
        exit;
      end;
      Result := FindStatusDisplay(Value.Components[I]);
    end;
  end;

begin
  Result := FindStatusDisplay(Value);
end;

function SearchForPrinterLog(const Value: TComponent): TApdFaxPrinterLog;

  function FindPrinterLog(const Value: TComponent): TApdFaxPrinterLog;
  var
    I: Integer;
  begin
    Result := nil;
    if not Assigned(Value) then
      exit;
    for I := 0 to Value.ComponentCount-1 do begin
      if Value.Components[I] is TApdFaxPrinterLog then begin
        Result := TApdFaxPrinterLog(Value.Components[I]);
        exit;
      end;
      Result := FindPrinterLog(Value.Components[I]);
    end;
  end;

begin
  Result := FindPrinterLog(Value);
end;


{ TApdFaxPrinterLog }

constructor TApdCustomFaxPrinterLog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLogFileName := afpDefFPLFileName;
end;

procedure TApdCustomFaxPrinterLog.UpdateLog(const LogCode: TFaxPLCode);
var
  LogFile : TextFile;
begin
  {Exit if no name specified}
  if (FLogFileName = '') then
    Exit;

  {Create or open the log file}
  try
    AssignFile(LogFile, FLogFileName);
    Append(LogFile);
  except
    on E : EInOutError do
      if E.ErrorCode = 2 then
        {File not found, open as new}
        Rewrite(LogFile)
      else
        {Unexpected error, forward the exception}
        raise;
  end;

  {Write the printer log entry}
  with TApdCustomFaxPrinter(FaxPrinter) do begin
    { TFaxPLCode = (lcStart, lcFinish, lcAborted, lcFailed); }
    case LogCode of
      lcStart  :
        WriteLn(LogFile, 'Printing ', FileName, ' started at ',
                DateTimeToStr(Now));
      lcFinish :
        WriteLn(LogFile, 'Printing ', FileName, ' finished at ',
                DateTimeToStr(Now), ^M^J);
      lcAborted:
        WriteLn(LogFile, 'Printing ', FileName, ' aborted at ',
                DateTimeToStr(Now), ^M^J);
      lcFailed :
        WriteLn(LogFile, 'Printing ', FileName, ' failed at ',
                DateTimeToStr(Now), ^M^J);
    end;
  end;

  Close(LogFile);
  if IOResult <> 0 then ;
end;

{ TApdCustomFaxPrinterMargin }

constructor TApdCustomFaxPrinterMargin.Create;
begin
  inherited Create;
  FCaption := '';
  FEnabled := False;
  FFont    := TFont.Create;
  Height   := 0;
end;

destructor TApdCustomFaxPrinterMargin.Destroy;
begin
  FFont.Free;
  inherited Destroy;
end;

procedure TApdCustomFaxPrinterMargin.SetFont(const NewFont: TFont);
begin
  { Set the font }
  FFont.Assign(NewFont);
end;

{ TApdAbstractFaxPrintStatus }

procedure TApdAbstractFaxPrinterStatus.SetPosition(const Value: TPosition);
begin
  if Value <> FPosition then begin
    FPosition := Value;
    if Assigned(FDisplay) then
      FDisplay.Position := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetCtl3D(const Value: Boolean);
begin
  if Value <> FCtl3D then begin
    FCtl3D := Value;
    if Assigned(FDisplay) then
      FDisplay.Ctl3D := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetVisible(const Value: Boolean);
begin
  if Value <> FVisible then begin
    FVisible := Value;
    if Assigned(FDisplay) then
      FDisplay.Visible := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetCaption(const Value: String);
begin
  if Value <> FCaption then begin
    FCaption := Value;
    if Assigned(FDisplay) then
      FDisplay.Caption := Value;
  end;
end;                                                                    

procedure TApdAbstractFaxPrinterStatus.GetProperties;
begin
  if Assigned(FDisplay) then begin
    Position := FDisplay.Position;
    Ctl3D := FDisplay.Ctl3D;
    Visible := FDisplay.Visible;
    Caption := FDisplay.Caption;                                      
  end;
end;

constructor TApdAbstractFaxPrinterStatus.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Caption := 'Print Status';                                          
  CreateDisplay;
  GetProperties;
end;

destructor TApdAbstractFaxPrinterStatus.Destroy;
begin
  DestroyDisplay;
  inherited Destroy;
end;

procedure TApdAbstractFaxPrinterStatus.Show;
begin
  if Assigned(FDisplay) then
    FDisplay.Show;
end;

{ TApdCustomFaxPrinter }

constructor TApdCustomFaxPrinter.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  { Design time properties }
  Caption              := afpDefFaxPrnCaption;
  FFaxFooter           := TApdFaxPrinterMargin.Create;
  FFaxHeader           := TApdFaxPrinterMargin.Create;
  FFileName            := '';
  FMultiPage           := afpDefFaxMultiPage;
  FPrintScale          := afpDefFaxPrintScale;
  FStatusDisplay       := nil;
  FFaxPrinterLog       := nil;

  { page margin settings }
  FFaxFooter.Caption   := afpDefFaxFooterCaption;
  FFaxFooter.Enabled   := afpDefFaxFooterEnabled;
  FFaxHeader.Caption   := afpDefFaxHeaderCaption;
  FFaxHeader.Enabled   := afpDefFaxHeaderEnabled;

  { run-time / read-only properties }
  FTotalFaxPages       := 0;
  FCurrentPrintingPage := 0;
  FLastPageToPrint     := 0;
  FFaxResolution       := afcDefResolution;
  FFaxWidth            := afcDefFaxCvtWidth;                         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -