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

📄 awfview.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
(***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is TurboPower Async Professional
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1991-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{*                   AWFVIEW.PAS 4.06                    *}
{*********************************************************}
{* Low-level fax viewer                                  *}
{*********************************************************}

{
  Used by the TApdFaxViewer (AdFView.pas). This unit could use
  some updating, originally ported from the DOS code to Windows (BP7),
  then Delphi.  Uses messages to interface with TApdFaxViewer,
  renders on a custom window.
}

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

{Options required for this unit}
{$S-,R-,V-,I-,B-,X+,Q-,J+}

unit AwFView;
  {-Fax viewing}

interface

uses
  WinTypes,
  WinProcs,
  ShellApi,
  Messages,
  SysUtils,
  OoMisc,
  AwFaxCvt;

const
  MaxFaxPages = $FFF0 div SizeOf(TMemoryBitmapDesc);

type
  PFax = ^TFax;
  TFax = array[1..MaxFaxPages] of TMemoryBitmapDesc;

  {$IFNDEF Win32}
  TViewerWndProc = function (Wnd: hWnd; Msg, wParam: Word; lParam: LongInt): LongInt;
  {$ELSE}
  TViewerWndProc = function (Wnd: hWnd; Msg : UINT; wParam: WPARAM; lParam: LPARAM): LongInt; stdcall;
  {$ENDIF}

  {Windows message record}
  {$IFDEF Win32}
  wMsg = record
    hWindow : hWnd;
    Message : UINT;
    case Integer of
      0: (wParam : WPARAM; lParam : LPARAM);
      1: (wParamLo, wParamHi : Word; lParamLo, lParamHi : Word);
  end;
  {$ELSE}
  wMsg = record
    hWindow : hWnd;
    Message : Word;
    case Integer of
      0: (wParam : Word; lParam : LongInt);
      1: (wParamLo, wParamHi : Byte; lParamLo, lParamHi : Word);
  end;

  {$ENDIF}
  {fax bitmap viewer}
  TViewer = class
      vWnd          : HWnd;             {Window handle}

      {for unpacking}
      vUnpacker     : PUnpackFax;       {For unpacking the fax image}
      vImage        : PFax;             {Unpacked fax image}
      vUnpPage      : Cardinal;         {The page being unpacked}
      vLoadWholeFax : Bool;             {TRUE if whole fax should be loaded}
      vBusyCursor   : HCursor;          {Cursor shown while doing lengthy ops}

      {features}
      vDragDrop     : Bool;             {TRUE if the window supports Drag&Drop}

      {display data}
      vFGColor      : LongInt;          {foreground color}
      vBGCOlor      : LongInt;          {background color}
      vScaledWidth  : Cardinal;         {scaled width of the image on the page}
      vScaledHeight : Cardinal;         {scaled height of the image on the page}
      vVScrollInc   : Integer;          {vertical scroll increment}
      vHScrollInc   : Integer;          {horizontal scroll increment}
      vSizing       : Bool;             {TRUE if window is being sized}
      vVScrolling   : Bool;             {TRUE if scrolling vertically}
      vHScrolling   : Bool;             {TRUE if scrolling horizontally}

      {position data}
      vNumPages     : Cardinal;         {Number of pages in fax}
      vOnPage       : Cardinal;         {Current page in viewer}
      vTopRow       : Cardinal;         {Row at top of display}
      vLeftOfs      : Cardinal;         {Left offset}
      vMaxVScroll   : Cardinal;         {Maximum top row}
      vMaxHScroll   : Cardinal;         {Maximum left offset}

      {scaling}
      vHMult        : Cardinal;         {multiplier for width of destination}
      vHDiv         : Cardinal;         {divisor for width of destination}
      vVMult        : Cardinal;         {multipler for height of destination}
      vVDiv         : Cardinal;         {divisor for height of destination}

      {rotation data}
      vRotateDir    : Cardinal;         {Direction of rotation}

      {block marking}
      vMarked       : Bool;             {TRUE if a block is marked}
      vCaptured     : Bool;             {TRUE if mouse captured}
      vAnchorCorner : Cardinal;         {anchored corner of marked rectangle}
      vOutsideEdge  : Bool;             {TRUE if mouse outside client area}
      vMarkTimer    : Cardinal;         {timer for automatic scrolling}
      vMarkRect     : TRect;            {marked rectangle}

      {keyboard data}
      vCtrlDown     : Bool;             {TRUE if control key down}

      vDefWndProc   : TViewerWndProc;   {The default window proc}
      vFileName     : array[0..fsPathName] of Char;
      vComponentName: array[0..255] of Char;
      vUpdating     : Boolean;
      vDesigning    : Boolean;

      {constructors/destructors}
      constructor Create(AWnd : TApdHwnd);
      destructor Destroy; override;

      {image creation/destruction}
      procedure vAllocFax(NumPages : Cardinal);
        {-Allocate memory for the fax}
      procedure vDisposeFax;
        {-Dispose of the current fax}

      {scrollbars}
      procedure vInitScrollbars;
        {-Set scrollbar ranges and initial positions}
      procedure vUpdateScrollThumb(Vert : Bool);
        {-Update the thumb position on the vertical or horizontal scrollbar}
      procedure vCalcMaxScrollPos;
        {-Calculate the maximum horizontal and vertical scrollbar positions}

      {scrolling}
      procedure vScrollUpPrim(Delta : Cardinal);
        {-Scroll the display up Delta rows}
      procedure vScrollDownPrim(Delta : Cardinal);
        {-Scroll the display down Delta rows}
      procedure vScrollLeftPrim(Delta : Cardinal);
        {-Scroll the display left Delta columns}
      procedure vScrollRightPrim(Delta : Cardinal);
        {-Scroll the display right Delta columns}
      procedure vScrollUp;
        {-Scroll the display up vVScrollInc lines}
      procedure vScrollDown;
        {-Scroll the display down vVScrollInc lines}
      procedure vScrollLeft;
        {-Scroll the display left vHScrollInc columns}
      procedure vScrollRight;
        {-Scroll the display left vHScrollInc columns}
      procedure vJumpUp;
        {-Scroll the display up vVScrollInc * 10 lines}
      procedure vJumpDown;
        {-Scroll the display down vVScrollInc * 10 lines}
      procedure vJumpLeft;
        {-Scroll the display left vHScrollInc * 10 columns}
      procedure vJumpRight;
        {-Scroll the display left vHScrollInc * 10 columns}
      procedure vHomeVertical;
        {-Home the vertical display}
      procedure vEndVertical;
        {-Scroll the vertical display to the end}
      procedure vHomeHorizontal;
        {-Home the horizontal display}
      procedure vEndHorizontal;
        {-Scroll the horizontal display to the end}

      {paging}
      procedure vInitPage;
        {-Initialize a new page for viewing}
      procedure vPageUp;
        {-Go to the previous page}
      procedure vPageDown;
        {-Go to the next page}
      procedure vFirstPage;
        {-Go to the first page}
      procedure vLastPage;
        {-Go to the last page}
      function vRotatePage(const PageNum, Direction : Cardinal) : Integer;
        {-Rotate a page}

      {marking}
      procedure vUpdateMarkRect(Client : TRect; X, Y : Integer);
        {-Update the mark rectangle}
      procedure vCopyToClipboard;
        {-Copy the marked bitmap to the clipboard}

      {painting}
      procedure vInvalidateAll;
        {-Invalidate the entire viewer window}
      procedure vPaint(PaintDC : HDC; var PaintInfo : TPaintStruct);
        {-Paint the window}
      procedure vGetMarkClientIntersection(var R : TRect; Mark : TRect);
        {-Find the intersection of the client rect and the marked rect}

      {drag and drop}
      procedure vInitDragDrop(Enabled : Bool);
        {-Initialize drag and drop features}

      {message response}
      function apwViewSetFile(FName : PChar) : Integer;
        {-Set the file name of the file to view}
      procedure apwViewSetFG(Color : LongInt);
        {-Set the foreground color}
      procedure apwViewSetBG(Color : LongInt);
        {-Set the background color}
      procedure apwViewSetScale(Settings : PScaleSettings);
        {-Set scaling factors}
      function apwViewSetWhitespace(FromLines, ToLines : Cardinal) : Integer;
        {-Set whitespace compression factors}
      procedure apwViewSetScroll(HScroll, VScroll : Cardinal);
        {-Set the vertical and horizontal scroll increments}
      function apwViewSelectAll : Integer;
        {-Select entire image}
      function apwViewSelect(R : PRect) : Integer;
        {-Select a portion of fax image}
      function apwViewCopy : Integer;
        {-Copy image data to clipboard}
      function apwViewGetBitmap(Page : Cardinal; Point : PPoint) : HBitmap;
        {-Retrieve the bitmap for page number Page}
      function apwViewGetNumPages : Cardinal;
        {-Retrieve the number of pages in the fax}
      procedure apwViewStartUpdate;
        {-Begin update of scaling parameters}
      procedure apwViewEndUpdate;
        {-End update of scaling parameters}
      procedure apwViewSetWndProc(var Msg : wMsg);
        {-Set the viewer's window procedure}
      function apwViewGotoPage(Page : Cardinal) : Integer;
        {-Set the currently viewed page}
      function apwViewGetCurPage : Integer;
        {-Get the number of the currently viewed page}
      procedure apwViewSetDesignMode(Name : PChar);
        {-Tell the viewer we're in component design mode}
      function apwViewSetRotation(Direction : Cardinal) : Integer;
        {-Rotate the fax bitmaps}
      procedure apwViewSetAutoScale(Kind : Word);
        {-Set the auto scaling mode for the underlying unpacker}
      procedure apwViewGetPageDim(R : PRect);
        {-Get dimensions of current page}
      function apwViewGetPageFlags : Word;                         
        {-Get flags for current page}
      function apwViewSetLoadWholeFax(LoadWhole : Bool) : Integer;
        {-Determine whether whole faxes are loaded into memory or not}
      procedure apwViewSetBusyCursor(NewCursor : HCursor);
        {-Set the cursor that is shown during length operations}
      procedure wmPaint(var Msg : wMsg);
        {-paint the window}
      function wmSize(var Msg : wMsg) : LongInt;
        {-size the window}
      function wmGetDlgCode(var Msg : wMsg) : LongInt;
        {-respond to query about what input we want}
      function wmKeyDown(var Msg : wMsg) : LongInt;
        {-respond to key presses}
      function wmKeyUp(var Msg : wMsg) : LongInt;
        {-respond to key releases}
      procedure wmLButtonDown(var Msg : wMsg);
        {-respond to left button clicks}
      procedure wmLButtonUp(var Msg : wMsg);
        {-respond to left button releases}
      procedure wmMouseMove(var Msg : wMsg);
        {-respond to mouse movements}
      procedure wmTimer(var Msg : wMsg);
        {-respond to automatic scroll timer}
      procedure wmVScroll(var Msg : wMsg);
        {-scroll vertically}
      procedure wmHScroll(var Msg : wMsg);
        {-scroll horizontally}

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

  procedure RegisterFaxViewerClass(Designing : Boolean);

implementation

{Miscellaneous functions}

  function GetViewerPtr(HW : TApdHwnd) : TViewer;
    {-Extract the fax viewer pointer from the window long}
  begin
    GetViewerPtr := TViewer(GetWindowLong(HW, gwl_Viewer));
  end;

  {$IFNDEF Win32}
  procedure ExchangeInts(var I, J : Integer);
    {-Exchange the values in two words.}
    inline(
      $8C/$DB/                 {mov bx,ds       ;save DS}
      $5E/                     {pop si}
      $1F/                     {pop ds          ;DS:SI => J}
      $5F/                     {pop di}
      $07/                     {pop es          ;ES:DI => I}
      $8B/$04/                 {mov ax,[si]     ;AX = J}
      $26/$87/$05/             {xchg ax,es:[di] ;I = J, AX = I}
      $89/$04/                 {mov [si],ax     ;J = I}
      $8E/$DB);                {mov ds,bx       ;restore DS}
  {$ELSE}
  procedure ExchangeInts(var I, J : Integer); assembler; register;
  asm
    push  ebx
    mov   ebx,[eax]
    mov   ecx,[edx]
    mov   [edx],ebx
    mov   [eax],ecx
    pop   ebx
  end;
  {$ENDIF}

{******************************************************************************}

{TViewer}

  constructor TViewer.Create(AWnd : TApdHwnd);
  begin
    if (upInitFaxUnpacker(vUnpacker, nil, nil) < ecOK) then
      Fail;

    vWnd          := AWnd;

    vImage        := nil;
    vLoadWholeFax := False;
    vBusyCursor   := LoadCursor(0, idc_Arrow);

    vDragDrop     := False;

    vFGColor      := DefViewerFG;
    vBGColor      := DefViewerBG;
    vScaledWidth  := 0;
    vScaledHeight := 0;
    vVScrollInc   := DefVScrollInc;
    vHScrollInc   := DefHScrollInc;
    vSizing       := False;
    vVScrolling   := False;
    vHScrolling   := False;

    vNumPages     := 0;
    vOnPage       := 0;
    vTopRow       := 0;
    vLeftOfs      := 0;
    vMaxVScroll   := 0;
    vMaxHScroll   := 0;

    vHMult        := 1;
    vHDiv         := 1;
    vVMult        := 1;
    vVDiv         := 1;

    vRotateDir    := 0;

    vMarked       := False;
    vCaptured     := False;
    vOutsideEdge  := False;

    vCtrlDown     := False;

    vDefWndProc   := DefWindowProc;

    vUpdating     := False;
    vDesigning    := False;
  end;

  destructor TViewer.Destroy;
  begin
    if vCaptured then begin
      ReleaseCapture;
      if vOutsideEdge then
        KillTimer(vWnd, 1);
    end;

    if vDragDrop then
      DragAcceptFiles(vWnd, False);
    upDoneFaxUnpacker(vUnpacker);
    vDisposeFax;
    inherited Destroy;
  end;

  procedure TViewer.vAllocFax(NumPages : Cardinal);
    {-Allocate memory for the fax}
  begin
    {reset fax variables}
    vNumPages := NumPages;
    vOnPage   := 0;
    vTopRow   := 0;
    vLeftOfs  := 0;

    {allocate memory for images}
    vImage := AllocMem(SizeOf(TMemoryBitmapDesc) * vNumPages);
  end;

  procedure TViewer.vDisposeFax;
    {-Dispose of the current fax}
  var
    I : Word;

  begin
    if (vImage = nil) or (vNumPages = 0) then
      Exit;

    {deallocate pages and free bitmaps}
    for I := 1 to vNumPages do
      if (vImage^[I].Bitmap <> 0) then
        DeleteObject(vImage^[I].Bitmap);
    FreeMem(vImage, SizeOf(TMemoryBitmapDesc) * vNumPages);

    {reset fax variables}
    vImage       := nil;
    vNumPages    := 0;
    vOnPage      := 0;
    vTopRow      := 0;
    vLeftOfs     := 0;
    vFileName[0] := #0;
  end;

  procedure TViewer.vInitScrollbars;
    {-Set scrollbar ranges and initial positions}
  begin
    {calculate the maximum position of scroll thumbs}
    vCalcMaxScrollPos;

    {update the scrollbars with their [possibly] new ranges}
    SetScrollRange(vWnd, sb_Vert, 0, vMaxVScroll, False);
    SetScrollRange(vWnd, sb_Horz, 0, vMaxHScroll, False);

    {move scroll thumbs}
    vUpdateScrollThumb(True);
    vUpdateScrollThumb(False);
  end;

  procedure TViewer.vUpdateScrollThumb(Vert : Bool);
    {-Update the thumb position on the vertical or horizontal scrollbar}
  begin
    if Vert then

⌨️ 快捷键说明

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