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

📄 adfview.pas

📁 Async Professional 4.04
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*********************************************************}
{*                   ADFVIEW.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}
{$I+,G+,X+,F+}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}

unit AdFView;
  {-Fax viewer component}

interface

uses
  WinTypes,
  WinProcs,
  SysUtils,
  Classes,
  Graphics,
  Messages,
  Controls,
  StdCtrls,
  Forms,
  OoMisc,
  AwFView,
  AdExcept,
{$IFDEF TRIALRUN}
  {$I TRIAL08.INC}
{$ENDIF}
  AdFaxCvt;

type
  TViewerRotation = (vr0, vr90, vr180, vr270);

const
  afvDefViewBorderStyle       = bsSingle;
  afvDefFGColor               = clBlack;
  afvDefBGColor               = clWhite;
  afvDefScaling               = False;
  afvDefHorizMult             = 1;
  afvDefHorizDiv              = 1;
  afvDefVertMult              = 1;
  afvDefVertDiv               = 1;
  afvDefViewAutoScaleMode     = asDoubleHeight;                      
  afvDefWhitespaceCompression = False;
  afvDefWhitespaceFrom        = 0;
  afvDefWhitespaceTo          = 0;
  afvDefHorizScroll           = DefHScrollInc;
  afvDefVertScroll            = DefHScrollInc;
  afvDefFileName              = '';
  afvDefAcceptDragged         = True;
  afvDefLoadWholeFax          = False;
  afvDefViewerHeight          = 50;
  afvDefViewerWidth           = 100;
  afvDefRotation              = vr0;
  afvDefBusyCursor            = crDefault;

type
  TViewerFileDropEvent = procedure(Sender : TObject; FileName : String) of object;
  TViewerErrorEvent = procedure(Sender : TObject; ErrorCode : Integer) of object;

  {base fax viewer component}
  TApdCustomFaxViewer = class(TApdBaseWinControl)
  protected {private}
    {.Z+}
    {property fields}
    FBorderStyle           : TBorderStyle;
    FFGColor               : TColor;
    FBGColor               : TColor;
    FScaling               : Boolean;
    FHorizMult             : Cardinal;
    FHorizDiv              : Cardinal;
    FVertMult              : Cardinal;
    FVertDiv               : Cardinal;
    FAutoScaleMode         : TAutoScaleMode;
    FWhitespaceCompression : Boolean;
    FWhitespaceFrom        : Cardinal;
    FWhitespaceTo          : Cardinal;
    FHorizScroll           : Cardinal;
    FVertScroll            : Cardinal;
    FFileName              : String;
    FAcceptDragged         : Boolean;
    FLoadWholeFax          : Boolean;
    FRotation              : TViewerRotation;
    FBusyCursor            : TCursor;
    FFileDrop              : TViewerFileDropEvent;
    FPageChange            : TNotifyEvent;
    FViewerError           : TViewerErrorEvent;
    HasBeenCreated         : Boolean;

    procedure CreateWnd; override;
    procedure CreateParams(var Params : TCreateParams); override;
    procedure SetName(const NewName : TComponentName); override;

    {property set methods}
    procedure SetBorderStyle(const NewStyle : TBorderStyle);
    procedure SetFGColor(const NewColor : TColor);
    procedure SetBGColor(const NewColor : TColor);
    procedure SetScaling(const NewScaling : Boolean);
    procedure SetHorizMult(const NewHorizMult : Cardinal);
    procedure SetHorizDiv(const NewHorizDiv : Cardinal);
    procedure SetVertMult(const NewVertMult : Cardinal);
    procedure SetVertDiv(const NewVertDiv : Cardinal);
    procedure SetAutoScaleMode(const NewAutoScaleMode : TAutoScaleMode);
    procedure SetWhitespaceCompression(const NewCompression : Boolean);
    procedure SetWhitespaceFrom(const NewWhitespaceFrom : Cardinal);
    procedure SetWhitespaceTo(const NewWhitespaceTo : Cardinal);
    procedure SetHorizScroll(const NewHorizScroll : Cardinal);
    procedure SetVertScroll(const NewVertScroll : Cardinal);
    procedure SetAcceptDragged(const NewAccept : Boolean);
    procedure SetLoadWholeFax(const NewLoadWholeFax : Boolean);
    procedure SetFileName(const NewFileName : String);
    procedure SetRotation(const NewRotation : TViewerRotation);
    procedure SetBusyCursor(const NewBusyCursor : TCursor);
    procedure SetActivePage(const NewPage : Cardinal);

    {property get methods}
    function GetPageBitmaps(const PageNum : Integer) : TBitmap;
    function GetNumPages : Cardinal;
    function GetActivePage : Cardinal;
    function GetPageWidth : Cardinal;
    function GetPageHeight : Cardinal;
    function GetPageFlags : Word;                                    

    {event virtual methods}
    procedure FileDropped; virtual;
      {-Called when a file is dropped into the viewer}
    procedure PageChange(var Msg : TMessage); message apw_ViewNotifyPage;
      {-Called when the active page changes}
    procedure ViewerError(var Msg : TMessage); message apw_ViewerError;
      {-Called when an error occurs and no result can be returned}

    procedure FillScaleSettings(var Settings : TScaleSettings);
      {-Fill a TScaleSettings structure with current scaling settings}

    procedure wmDropFiles(var Msg : wMsg); message wm_DropFiles;
      {-get a dropped file}

    procedure wmEraseBkGnd(var Msg : TMessage); message wm_EraseBkGnd; 
      {-erase background}

  public
    {creation/destriction}
    constructor Create(AOwner : TComponent); override;
      {-Create a TApdCustomFaxViewer component}
    {.Z-}

    {public methods}
    procedure BeginUpdate;
      {-Begin changing the properties of the viewer--no visual changes}
    procedure EndUpdate;
      {-Invalidates the window and repaints}
    procedure FirstPage;
      {-Move to first page}
    procedure LastPage;
      {-Move to last page}
    procedure NextPage;
      {-Move to next page}
    procedure PrevPage;
      {-Move to previous page}
    procedure SelectRegion(const R : TRect);
      {-Select the image bounded by R}
    procedure SelectImage;
      {-Select entire image}
    procedure CopyToClipBoard;
      {-Copy selected text to clipboard}

    {public properties}
    property BorderStyle : TBorderStyle
      read FBorderStyle write SetBorderStyle default afvDefViewBorderStyle;
    property FGColor : TColor
      read FFGColor write SetFGColor default afvDefFGColor;
    property BGColor : TColor
      read FBGColor write SetBGColor default afvDefBGColor;
    property Scaling : Boolean
      read FScaling write SetScaling;
    property HorizMult : Cardinal
      read FHorizMult write SetHorizMult default afvDefHorizMult;
    property HorizDiv : Cardinal
      read FHorizDiv write SetHorizDiv default afvDefHorizDiv;
    property VertMult : Cardinal
      read FVertMult write SetVertMult default afvDefVertMult;
    property VertDiv : Cardinal
      read FVertDiv write SetVertDiv default afvDefVertDiv;
    property AutoScaleMode : TAutoScaleMode
      read  FAutoScaleMode write SetAutoScaleMode default afvDefViewAutoScaleMode; 
    property WhitespaceCompression : Boolean
      read FWhitespaceCompression write SetWhitespaceCompression default afvDefWhitespaceCompression;
    property WhitespaceFrom : Cardinal
      read FWhitespaceFrom write SetWhitespaceFrom default afvDefWhitespaceFrom;
    property WhitespaceTo : Cardinal
      read FWhitespaceTo write SetWhitespaceTo default afvDefWhitespaceTo;
    property HorizScroll : Cardinal
      read FHorizScroll write SetHorizScroll default afvDefHorizScroll;
    property VertScroll : Cardinal
      read FVertScroll write SetVertScroll default afvDefVertScroll;
    property AcceptDragged : Boolean
      read FAcceptDragged write SetAcceptDragged default afvDefAcceptDragged;
    property LoadWholeFax : Boolean
      read FLoadWholeFax write SetLoadWholeFax default afvDefLoadWholeFax;
    property FileName : String
      read FFileName write SetFileName;
    property Rotation : TViewerRotation
      read FRotation write SetRotation default afvDefRotation;
    property BusyCursor : TCursor
      read FBusyCursor write SetBusyCursor default afvDefBusyCursor;

    {unpublished in TApdFaxViewer}
    property PageBitmaps[const Index : Integer] : TBitmap
      read GetPageBitmaps;
    property NumPages : Cardinal
      read GetNumPages;
    property ActivePage : Cardinal
      read GetActivePage write SetActivePage;
    property PageWidth : Cardinal
      read GetPageWidth;
    property PageHeight : Cardinal
      read GetPageHeight;
    property PageFlags : Word
      read GetPageFlags;                            

    {events}
    property OnDropFile : TViewerFileDropEvent
      read FFileDrop write FFileDrop;
    property OnPageChange : TNotifyEvent
      read FPageChange write FPageChange;
    property OnViewerError : TViewerErrorEvent
      read FViewerError write FViewerError;
  end;

  {fax viewer component}
  TApdFaxViewer = class(TApdCustomFaxViewer)
  published
    {published properties}
    property Version;                                           
    property BorderStyle;
    property FGColor;
    property BGColor;
    property Scaling;
    property HorizMult;
    property HorizDiv;
    property VertMult;
    property VertDiv;
    property AutoScaleMode;
    property WhitespaceCompression;
    property WhitespaceFrom;
    property WhitespaceTo;
    property HorizScroll;
    property VertScroll;
    property AcceptDragged;
    property LoadWholeFax;
    property BusyCursor;
    property FileName;

    {published events}
    property OnDropFile;
    property OnPageChange;
    property OnViewerError;

    {published inherited properties}
    property Align;
    property Ctl3D;
    property Cursor;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property TabOrder;
    property TabStop;
    property Visible;

    {Published inherited events}
    property OnClick;
    property OnDblClick;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;

implementation

{$IFDEF TRIALRUN}
  {$I TRIAL03.INC}
  {$I TRIAL02.INC}
{$ENDIF}

  procedure TApdCustomFaxViewer.CreateWnd;
  var
    Opt      : Word;
    Settings : TScaleSettings;
    TempZ    : array[0..255] of Char;

  begin
    inherited CreateWnd;

    HasBeenCreated := True;

    if csDesigning in ComponentState then
      SendMessage(Handle, apw_ViewSetDesignMode, 0, LongInt(StrPCopy(TempZ, Name)));

    SendMessage(Handle, apw_ViewSetFG, 0, FGColor);
    SendMessage(Handle, apw_ViewSetBG, 0, BGColor);

    if not (csDesigning in ComponentState) then begin
      if FScaling then begin
        FillScaleSettings(Settings);
        SendMessage(Handle, apw_ViewSetScale, 0, LongInt(@Settings));
      end;
      if FWhitespaceCompression then
        SendMessage(Handle, apw_ViewSetWhitespace, FWhitespaceFrom, FWhitespaceTo);
      SendMessage(Handle, apw_ViewSetScroll, FHorizScroll, FVertScroll);
      SendMessage(Handle, apw_ViewSetScroll, FHorizScroll, FVertScroll);
      case FAutoScaleMode of
        asDoubleHeight: Opt := ufAutoDoubleHeight;
        asHalfWidth   : Opt := ufAutoHalfWidth;
        else
          Opt := 0;
      end;
      SendMessage(Handle, apw_ViewSetAutoScale, Opt, 0);

      if not (csDesigning in ComponentState) then
        CheckException(Self, SendMessage(Handle, apw_ViewSetFile, 0, LongInt(StrPCopy(TempZ, FFileName))));

      SendMessage(Handle, apw_ViewsetLoadWholeFax, Ord(FLoadWholeFax), 0);
      SendMessage(Handle, apw_ViewSetBusyCursor, Screen.Cursors[BusyCursor], 0);
    end;
  end;

  procedure TApdCustomFaxViewer.CreateParams(var Params : TCreateParams);
  begin
    inherited CreateParams(Params);

    if csDesigning in ComponentState then begin
      RegisterFaxViewerClass(True);
      CreateSubClass(Params, FaxViewerClassNameDesign);
    end else begin
      RegisterFaxViewerClass(False);
      CreateSubClass(Params, FaxViewerClassName);
      Params.Style := Params.Style or vws_DragDrop;
    end;

    if (FBorderStyle = bsSingle) then
      Params.Style := Params.Style or ws_Border;
  end;

  procedure TApdCustomFaxViewer.SetName(const NewName : TComponentName);
  var
    TempZ : array[0..255] of Char;

  begin
    inherited SetName(NewName);

    if (csDesigning in ComponentState) and HasBeenCreated then
      SendMessage(Handle, apw_ViewSetDesignMode, 0, LongInt(StrPCopy(TempZ, NewName)));
  end;

  procedure TApdCustomFaxViewer.SetBorderStyle(const NewStyle : TBorderStyle);
  begin
    if (NewStyle = FBorderStyle) then
      Exit;

    FBorderStyle := NewStyle;
    if HandleAllocated then
      RecreateWnd;
  end;

  procedure TApdCustomFaxViewer.SetFGColor(const NewColor : TColor);
  begin
    if NewColor <> FFGColor then begin
      FFGColor := NewColor;
      SendMessage(Handle, apw_ViewSetFG, 0, NewColor);
      Invalidate;
    end;                                                          
  end;

  procedure TApdCustomFaxViewer.SetBGColor(const NewColor : TColor);
  begin
    if NewColor <> FBGColor then begin
      FBGColor := NewColor;
      SendMessage(Handle, apw_ViewSetBG, 0, NewColor);
      Invalidate;
    end;                                                         
  end;

  procedure TApdCustomFaxViewer.SetScaling(const NewScaling : Boolean);
  var
    Settings : TScaleSettings;

  begin
    if (FScaling <> NewScaling) then begin
      FScaling := NewScaling;

      if not FScaling then
        with Settings do begin

⌨️ 快捷键说明

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