home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / PMVIEW5C.ZIP / PMVIEW.C next >
C/C++ Source or Header  |  1992-04-23  |  97KB  |  3,266 lines

  1. //UTILITIES
  2. //DOUGLAS BOLING
  3. //PMVIEW.C
  4.  
  5. //=============================================================================
  6. // PMVIEW.C -- A file browse program for the OS/2 Presentation Manager.
  7. //
  8. // Copyright (c) 1990 Ziff Communications
  9. //
  10. // Written by Douglas Boling
  11. // Modified by K. L. Singer as follows:
  12. //  1. Fixed bug when displaying ASCII bytes > 7F in Hex display.
  13. //  2. Corrected to display found search string as top line of Hex display.
  14. //  3. Added Hex string search option.
  15. //  4. Corrected inability to scroll past 64K using vertical scroll slider.
  16. //  5. Corrected random posiition in top line when using vert. scroll slider.
  17. //  6. Added Hex offset and Line No. options in Search Goto command.
  18. //  7. Corrected expanding of Tabs.
  19. //  8. Corrected Hex display when jumping to/near end of file.
  20. //  9. Modified End key to go to start of last line (ASCII)/16-byte para (Hex).
  21. // 10. Corrected repeating lines of text between last CR and last byte of file.
  22. // 11. Corrected to prevent scrolling of Hex display beyond end of file.
  23. // 12. Added Hex-EBCDIC display option.
  24. // 13. Corrected to ensure vertical scroll slider visibility in Hex display.
  25. // 14. Corrected problem introduced by item 5.
  26. // 15. Modified Open File Dialog to put name of viewed file at top of list box.
  27. // 16. Corrected incorrect file name displayed in "Unable to open file" msg.
  28. // 17. Added file name filter retention between Open File dialogs.
  29. // 18. Added "New" item on File sub-menu to close file and leave PMVIEW active.
  30. // 19. Changed shortcut key for Exit to Alt-X (from Alt-E) to conform to CUA.
  31. // 20. Corrected handling of command line option for slash and upper case.
  32. // 21. Added command line parameter /M to exclude Min. button from frame wndw.
  33. // 22. Added mnemonic keys for all dialog box items.
  34. // 23. Modified Open File dialog box to place file entry field at top of box.
  35. // 24. Modified all dialog boxes to be centered, when possible, in client wndw.
  36. // 25. Added capability to include wild cards in cmd line file name as filter.
  37. // 26. Modified title bar and moved Searching... msg to box to conform to CUA.
  38. // 27. Added on-line help facility.
  39. // 28. Corrected window status to be active/focus when executed from CMD.
  40. // 29. Added option to display file position at the bottom of the display.
  41. // 30. Added hourglass pointer during waiting periods.
  42. // 31. Added XGA support and selections for all OS/2 1.3 VIO font sizes.
  43. // 32. Added ability to accept dragged and dropped file from OS/2 1.3 appl.
  44. // 33. Added ability to accept dragged and dropped file from File Manager.
  45. // 34. Fixed file position line scrolling into text area on non-VGA dsply.
  46. // 35. Circumvented OS/2 1.3 XGA Driver bug and improved font list generation.
  47. // 36. Corrected error recovery when Open File Name entered is zero length.
  48. // 37. Added test for valid dragged object file name (from OS/2 2.0 WP/appl.).
  49. // 38. Increased stack size for OS/2 2.0.
  50. // 39. Corrected error of not initializing buffer count for QUERYVIOCELLSIZES.
  51. //=============================================================================
  52.  
  53. #define INCL_DEV
  54.  
  55. //#define INCL_WIN
  56. #define INCL_WINACCELERATORS
  57. #define INCL_WINBUTTONS
  58. #define INCL_WINCLIPBOARD
  59. #define INCL_WINDIALOGS
  60. #define INCL_WINENTRYFIELDS
  61. #define INCL_WINERRORS
  62. #define INCL_WINFRAMECTLS
  63. #define INCL_WINFRAMEMGR
  64. #define INCL_WINHELP
  65. #define INCL_WININPUT
  66. #define INCL_WINLISTBOXES
  67. #define INCL_WINMENUS
  68. #define INCL_WINMESSAGEMGR
  69. #define INCL_WINENTRYFIELDS
  70. #define INCL_WINPOINTERS
  71. #define INCL_WINRECTANGLES
  72. #define INCL_WINSCROLLBARS
  73. #define INCL_WINSHELLDATA
  74. #define INCL_WINSYS
  75. #define INCL_WINWINDOWMGR
  76.  
  77. #define  INCL_WINSTDDRAG
  78.  
  79. #define  INCL_GPIREGIONS
  80.  
  81. #define  INCL_VIO
  82. #define  INCL_AVIO
  83.  
  84. #define  FM_DRAGOVER 0x300
  85. #define  FM_DROP     0x301
  86.  
  87. #define  NO_OF_VIO_SIZES 100
  88.  
  89. #define  AVIOROWS 98
  90. #define  AVIOCOLS 255
  91. #define  PATHLENGTH 255
  92. #define  BUFFERSIZE 16384
  93.  
  94. #include <os2.h>
  95. #include <stdio.h>
  96. #include <string.h>
  97. #include <stdlib.h>
  98.  
  99. #include "pmview.h"
  100.  
  101. #define  NULL 0L
  102.  
  103. MRESULT  EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM);
  104. MRESULT  EXPENTRY MessageDlgProc (HWND, USHORT, MPARAM, MPARAM);
  105. MRESULT  EXPENTRY AboutDlgProc (HWND, USHORT, MPARAM, MPARAM);
  106. MRESULT  EXPENTRY FileDlgProc (HWND, USHORT, MPARAM, MPARAM);
  107. MRESULT  EXPENTRY ConfigDlgProc (HWND, USHORT, MPARAM, MPARAM);
  108. MRESULT  EXPENTRY GotoDlgProc (HWND, USHORT, MPARAM, MPARAM);
  109. MRESULT  EXPENTRY SearchDlgProc (HWND, USHORT, MPARAM, MPARAM);
  110. MRESULT  EXPENTRY FontDlgProc (HWND, USHORT, MPARAM, MPARAM);
  111.  
  112. BOOL TestOpenFile (PCHAR);
  113. BOOL OpenFile (PCHAR);
  114. PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
  115.               BOOL *fEndOfFile);
  116. CHAR GetFileChar (LONG lFilePtr);
  117. LONG MoveViewPtr (LONG lFilePtr, LONG *ptrRow, BOOL fDispASCII);
  118. LONG lComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII);
  119. SHORT sComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII);
  120. VOID btoa (UCHAR cNum, UCHAR szOut[], BOOL fBlank);
  121. VOID Myltoa (ULONG lNum, UCHAR szOut[]);
  122. SHORT atob (UCHAR szHStr[], UCHAR szStr[]);
  123. SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII);
  124. VOID DisplayFilePos (HPS hps, HWND hwnd, LONG lFilePtr);
  125. VOID DispStatusLine (HPS hps, HWND hwnd, CHAR * szStatusText);
  126. BOOL SearchFile (LONG *lFilePtr);
  127. VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
  128.         HWND hwndMenu);
  129. VOID SetASCII (HWND hwndMenu, LONG *lViewPtr);
  130. VOID SetDispFilePos (HWND hwndMenu);
  131. VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
  132.           SHORT *psCharHeight);
  133. VOID CenterDlgBox (HWND hwndDialog, HWND hwndParent);
  134. VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath);
  135. VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden);
  136. VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden);
  137. VOID FillColorBox (HWND hwnd, SHORT iListID);
  138. VOID FillCellSizeBox (HWND hwnd, SHORT iListID);
  139. SHORT GetCellSize (SHORT sHeight, SHORT sWidth);
  140. HWND StartMessageBox (USHORT idDlg, CHAR * szString);
  141. VOID EndMessageBox (HWND hwndMsgBox);
  142. VOID SetClipAVIO (HPS hps, HWND hwnd);
  143.  
  144. HELPINIT helpinit = {
  145.              sizeof( HELPINIT),
  146.              0L,
  147.              NULL,
  148.              MAKEP(0xFFFF, ID_RESOURCE),
  149.              0,
  150.              0,
  151.              0,
  152.              0,
  153.              "PM File View Help Facility",
  154.              CMIC_HIDE_PANEL_ID,
  155.              "pmview.hlp"
  156.             };
  157.  
  158. struct ParamStruct {
  159.    UCHAR    szAttribute[2];
  160.    SHORT    sxWinPos;
  161.    SHORT    syWinPos;
  162.    SHORT    sWinHeight;
  163.    SHORT    sWinWidth;
  164.    SHORT    sCellHeight;
  165.    SHORT    sCellWidth;
  166.    SHORT    sTabStop;
  167.    BOOL     fDispASCII;
  168.    BOOL     fScrollBars;
  169.    BOOL     fIncHiddenFiles;
  170.    BOOL     fDispEBCDIC;
  171.    BOOL     fDispFilePos;
  172. } Default = {{0x20,0xf0}, -1, 0, 0, 0, -1, -1, 8, TRUE, TRUE, FALSE, FALSE,
  173.          FALSE};
  174.  
  175. struct FileStruct {
  176.    CHAR     szName [PATHLENGTH];
  177.    HFILE    hHandle;
  178.    LONG     lSize;
  179.    BOOL     fValid;
  180. } File = {"", 0, 0L, FALSE};
  181.  
  182. FILESTATUS FileInfo;
  183.  
  184. struct MemBuff {
  185.    USHORT   usBSel;
  186.    USHORT   usBOff;
  187.    USHORT   usDSize;
  188.    LONG     lFilePtr;
  189.    SHORT    sUseCnt;
  190.    BOOL     fValid;
  191. } Buff[4];
  192.  
  193. SHORT sCellSize[NO_OF_VIO_SIZES][2];
  194. SHORT sCellSizeCount;
  195.  
  196. HAB     hab;
  197. HWND     hwndFrame;
  198. HWND     hwndClient;
  199. HWND     hwndHelp;
  200.  
  201. CHAR     szNewFile[PATHLENGTH] = "";
  202. CHAR     szWildCardFilename[PATHLENGTH];
  203. LONG     lNewViewPtr;
  204.  
  205. LONG     lRowNumber = 1L;
  206. LONG     lRowPointer = 0L;
  207. LONG     lLastRowNumber = 0L;
  208. LONG     lLastRow = 0L;
  209.  
  210. CHAR     szSearchStr[80];
  211. CHAR     sSearchStr[80];
  212. CHAR     szSearchHStr[80];
  213. SHORT     cbSearchStrLen;
  214. BOOL     fCheckCase = FALSE;
  215. BOOL     fTopSearch = FALSE;
  216. BOOL     fHexString = FALSE;
  217. BOOL     fHexGoto = FALSE;
  218. BOOL     fLineGoto = FALSE;
  219. BOOL     fDecGoto = TRUE;
  220. LONG     lLastFound = -1;
  221.  
  222. BOOL     fSaveWinPos;
  223. BOOL     fSaveToDisk = FALSE;
  224. BOOL     fMinimized;
  225. CHAR     szAppName[] = "PMVIEW by Douglas Boling";
  226. CHAR     szKeyName[] = "Profile type 1";
  227.  
  228. CHAR     szStartTitleText[80];
  229.  
  230. BOOL     fNoMinButton = FALSE;
  231.  
  232. //                0/8  1/9  2/A  3/B    4/C  5/D  6/E  7/F
  233. UCHAR caEBtoASCII[256] = { 0x22,0x22,0x22,0x22,0x22,0x9E,0x22,0x22, //0
  234.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //0
  235.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //1
  236.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //1
  237.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //2
  238.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //2
  239.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //3
  240.                0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //3
  241.                0x20,0x5B,0x5D,0x9C,0x9D,0x9E,0x0F,0xE1, //4
  242.                0x15,0xC4,0x9B,0x2E,0x3C,0x28,0x2B,0xB3, //4
  243.                0x26,0xF8,0x20,0x5E,0x22,0x27,0x87,0x85, //5
  244.                0x8A,0x8D,0x21,0x24,0x2A,0x29,0x2B,0xAA, //5
  245.                0x2D,0x2F,0x95,0x97,0x61,0x6F,0x98,0x85, //6
  246.                0x84,0x82,0x7C,0x2C,0x25,0x5F,0x3E,0x3F, //6
  247.                0x8D,0x95,0x97,0x81,0x87,0x84,0x89,0x8B, //7
  248.                0x94,0x60,0x3A,0x23,0x40,0x27,0x3D,0x22, //7
  249.                0x81,0x61,0x62,0x63,0x64,0x65,0x66,0x67, //8
  250.                0x68,0x69,0x83,0x88,0x8C,0x93,0x96,0xA0, //8
  251.                0x82,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70, //9
  252.                0x71,0x72,0xA1,0xA2,0xA3,0xA4,0x41,0x45, //9
  253.                0x49,0x7E,0x73,0x74,0x75,0x76,0x77,0x78, //A
  254.                0x79,0x7A,0x4F,0x55,0x41,0x4F,0x59,0x4A, //A
  255.                0x45,0x45,0x49,0x4F,0x55,0x59,0x53,0x8E, //B
  256.                0x45,0x49,0x99,0x9A,0x41,0x45,0x49,0x4F, //B
  257.                0x7B,0x41,0x42,0x43,0x44,0x45,0x46,0x47, //C
  258.                0x48,0x49,0x55,0x41,0x90,0x49,0x20,0x20, //C
  259.                0x7D,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50, //D
  260.                0x51,0x52,0x4F,0x55,0xA5,0x20,0x20,0x20, //D
  261.                0x5C,0x91,0x53,0x54,0x55,0x56,0x57,0x58, //E
  262.                0x59,0x5A,0xED,0x86,0x87,0x20,0x20,0x3B, //E
  263.                0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, //F
  264.                0x38,0x39,0x91,0xED,0x8F,0x80,0x2A,0x20};//F
  265.  
  266. //=======================================================================
  267. // Main Proceedure.  Create message queue, parse the command line,
  268. //    allocate memory buffers, create the window, and process the
  269. //    message queue.
  270. //=======================================================================
  271. int main (int argc, char *argv[])
  272.    {
  273.    static   CHAR  szClientClass [] = "PMVIEW";
  274.  
  275.    static   ULONG flFrameFlags = FCF_TITLEBAR       | FCF_SYSMENU  |
  276.                  FCF_SIZEBORDER    | FCF_MINMAX   |
  277.                  FCF_TASKLIST       | FCF_ICON      |
  278.                  FCF_MENU       | FCF_ACCELTABLE |
  279.                  FCF_VERTSCROLL    | FCF_HORZSCROLL |
  280.                  FCF_SHELLPOSITION;
  281.  
  282.    static   SHORT    fsWinPosFlags = SWP_SHOW;
  283.    static   USHORT   usSelector;
  284.    HMQ        hmq;
  285.    QMSG     qmsg;
  286.    SHORT    i;
  287.  
  288.    if ( !(hab = WinInitialize (0)) )
  289.      exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
  290.  
  291.    if ( !(hmq = WinCreateMsgQueue (hab, 0)) )
  292.      exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
  293.  
  294.    hwndHelp = WinCreateHelpInstance( hab, &helpinit);
  295.  
  296.    fNoMinButton = FALSE;
  297.  
  298.    for (i = 1; i < argc && i < 4; i++)
  299.       if (stricmp(argv[i],"/i") == 0 || stricmp (argv[i],"-i") == 0)
  300.      {
  301.      fMinimized = TRUE;
  302.      fsWinPosFlags |= SWP_MINIMIZE;
  303.      }
  304.       else
  305.      {
  306.      fsWinPosFlags |= SWP_FOCUSACTIVATE | SWP_ACTIVATE;
  307.      if (stricmp(argv[i],"/m") == 0 || stricmp (argv[i],"-m") == 0)
  308.         {
  309.         fNoMinButton = TRUE;
  310.         }
  311.      else
  312.         {
  313.         if (strlen (szNewFile) == 0)
  314.            DosQPathInfo (argv[i], 5, szNewFile, sizeof szNewFile, 0L);
  315.         }
  316.      }
  317.    if ( (strchr (szNewFile, '*') != 0) ||
  318.     (strchr (szNewFile, '?') != 0) )
  319.      {
  320.      strcpy (szWildCardFilename, szNewFile);
  321.      *szNewFile = '\0';
  322.      }
  323.    else
  324.      *szWildCardFilename = '\0';
  325.  
  326.    DosAllocSeg( (USHORT) 0, &usSelector, 0 );
  327.    for (i = 0; i < 4; i++) {
  328.       Buff[i].usBSel = usSelector;
  329.       Buff[i].usBOff = i * BUFFERSIZE;
  330.       Buff[i].fValid = FALSE;
  331.    }
  332.    i = sizeof Default;
  333.    WinQueryProfileData (hab, szAppName, szKeyName, &Default, &i);
  334.  
  335.    WinRegisterClass (
  336.            hab,            // Anchor block handle
  337.            szClientClass,        // Name of class being registered
  338.            ClientWndProc,        // Window procedure for class
  339.            CS_SIZEREDRAW,        // Class style
  340.            0);            // Extra bytes to reserve
  341.  
  342.    if (fNoMinButton)
  343.      flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
  344.             FCF_SIZEBORDER    | FCF_MAXBUTTON |
  345.             FCF_TASKLIST      | FCF_ICON     |
  346.             FCF_MENU          | FCF_ACCELTABLE |
  347.             FCF_VERTSCROLL    | FCF_HORZSCROLL |
  348.             FCF_SHELLPOSITION;
  349.    else
  350.      flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
  351.             FCF_SIZEBORDER    | FCF_MINMAX   |
  352.             FCF_TASKLIST      | FCF_ICON     |
  353.             FCF_MENU          | FCF_ACCELTABLE |
  354.             FCF_VERTSCROLL    | FCF_HORZSCROLL |
  355.             FCF_SHELLPOSITION;
  356.  
  357.    hwndFrame = WinCreateStdWindow (
  358.            HWND_DESKTOP,        // Parent window handle
  359.            0L,            // Style of frame window
  360.            &flFrameFlags,        // Pointer to control data
  361.            szClientClass,        // Client window class name
  362.            "",                  // Title bar text
  363.            0L,            // Style of client window
  364.            (HMODULE) NULL,        // Module handle for resources
  365.            ID_RESOURCE,        // ID of resources for window
  366.            &hwndClient);        // Pointer to client window handle
  367.  
  368.    if ((NULL == hwndFrame) || (NULL == hwndClient)) {
  369.       /* Make sure the window was created.    */
  370.       exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
  371.    } /* endif */
  372.  
  373.    WinSetWindowUShort(hwndFrame, QWS_ID, ID_RESOURCE);
  374.    if (hwndHelp != NULL)
  375.      WinAssociateHelpInstance( hwndHelp, hwndFrame);
  376.  
  377.    if (Default.sxWinPos != -1)
  378.       fsWinPosFlags |= SWP_MOVE | SWP_SIZE;
  379.  
  380.    WinSetWindowPos (hwndFrame, HWND_TOP, Default.sxWinPos, Default.syWinPos,
  381.              Default.sWinWidth, Default.sWinHeight, fsWinPosFlags);
  382.  
  383.    while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  384.       WinDispatchMsg (hab, &qmsg);
  385.  
  386.    if (File.hHandle)
  387.       DosClose (File.hHandle);
  388.    DosFreeSeg (usSelector);
  389.  
  390.    WinDestroyWindow (hwndFrame);
  391.    if (hwndHelp != NULL)
  392.      WinDestroyHelpInstance( hwndHelp);
  393.    WinDestroyMsgQueue (hmq);
  394.    WinTerminate (hab);
  395.    return 0;
  396. }
  397. //------------------------------------------------------------------
  398. // Test opening file.  Open the file and close it.  Return TRUE if
  399. //     successful.
  400. //------------------------------------------------------------------
  401. BOOL TestOpenFile (PCHAR szNewFileName) {
  402.  
  403.    HFILE       hNewHandle;
  404.    USHORT      usAction;
  405.    BOOL        fGoodRead = FALSE;
  406.  
  407.    if (DosOpen (
  408.     szNewFileName,               // File name
  409.     &hNewHandle,               // File handle
  410.     &usAction,               // Action taken
  411.     0L,                   // File size
  412.     0,                   // File attribute
  413.     1,                   // Open type (Fail if no file.)
  414.     0x20,                   // Open mode (Read, deny write)
  415.     0L))                   // Reserved.
  416.      ;
  417.    else {
  418.      if (hNewHandle)
  419.        DosClose (hNewHandle);
  420.      fGoodRead = TRUE;
  421.    }
  422.    return fGoodRead;
  423. }
  424. //------------------------------------------------------------------
  425. // Open file.  Open the file, query file information, reset memory
  426. //     buffer structure.
  427. //------------------------------------------------------------------
  428. BOOL OpenFile (PCHAR szNewFileName) {
  429.  
  430.    SHORT       i;
  431.    HFILE       hNewHandle;
  432.    USHORT      usAction;
  433.    BOOL        fGoodRead = FALSE;
  434.  
  435.    if (DosOpen (
  436.     szNewFileName,               // File name
  437.     &hNewHandle,               // File handle
  438.     &usAction,               // Action taken
  439.     0L,                   // File size
  440.     0,                   // File attribute
  441.     1,                   // Open type (Fail if no file.)
  442.     0x20,                   // Open mode (Read, deny write)
  443.     0L))                   // Reserved.
  444.       WinAlarm (HWND_DESKTOP, WA_NOTE);
  445.    else {
  446.       if (File.hHandle)
  447.      DosClose (File.hHandle);
  448.       strcpy (File.szName, szNewFileName);
  449.       File.hHandle = hNewHandle;
  450.       DosQFileInfo (File.hHandle, 1, (PBYTE) &FileInfo,
  451.                  sizeof FileInfo);
  452.       File.lSize = FileInfo.cbFile;
  453.       fGoodRead = TRUE;
  454.       //
  455.       // Reset the memory buffer to purge the old file data.
  456.       //
  457.       for (i = 0; i < 4; i++) {
  458.      Buff[i].lFilePtr = -1;
  459.      Buff[i].sUseCnt = 1;
  460.       }
  461.    }
  462.    return fGoodRead;
  463. }
  464. //------------------------------------------------------------------
  465. // GetFileDataPtr - Return a pointer to file data pointed to by
  466. //            the file pointer.
  467. //------------------------------------------------------------------
  468. PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
  469.               BOOL *fEndOfFile) {
  470.    PCHAR    pcDataPtr;
  471.    ULONG    ulTemp;
  472.    SHORT    i, sLast = -1;
  473.    SHORT    sOldCnt, sNewCnt;
  474.    //
  475.    // Check limits of file.
  476.    //
  477.    *fEndOfFile = FALSE;
  478.    if (lFilePtr >= File.lSize) {
  479.       lFilePtr = File.lSize;
  480.       *fEndOfFile = fForward;
  481.    } else if (lFilePtr <= 0L) {
  482.       lFilePtr = 0L;
  483.       *fEndOfFile = !fForward;
  484.    }
  485.    //
  486.    // See if requested part of the file is in one of the buffers.
  487.    //
  488.    sOldCnt = sNewCnt = Buff[0].sUseCnt;
  489.    for (i = 0; i < 4; i++) {
  490.       sNewCnt = (sNewCnt < Buff[i].sUseCnt) ? Buff[i].sUseCnt : sNewCnt;
  491.       sOldCnt = (sOldCnt > Buff[i].sUseCnt) ? Buff[i].sUseCnt : sOldCnt;
  492.       if (Buff[i].lFilePtr != -1)
  493.      if (lFilePtr >= Buff[i].lFilePtr &&
  494.             lFilePtr < Buff[i].lFilePtr + BUFFERSIZE)
  495.         sLast = i;
  496.    }
  497.    //
  498.    // If requested part not found, determine the oldest buffer to replace,
  499.    //      then read part of the file into that buffer.
  500.    //
  501.    if (sLast == -1) {
  502.       sOldCnt = Buff[0].sUseCnt;
  503.       for (i = 0; i < 4; i++)
  504.      if (sOldCnt >= Buff[i].sUseCnt) {
  505.         sOldCnt = Buff[i].sUseCnt;
  506.         sLast = i;
  507.      }
  508.       Buff[sLast].fValid = TRUE;
  509.       Buff[sLast].lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE;
  510.  
  511.       DosChgFilePtr (File.hHandle, Buff[sLast].lFilePtr, 0, &ulTemp);
  512.  
  513.       DosRead (File.hHandle, MAKEP (Buff[sLast].usBSel,
  514.                Buff[sLast].usBOff), BUFFERSIZE,
  515.                &Buff[sLast].usDSize);
  516.    }
  517.    //
  518.    // Reset LRU count to prevent overflow
  519.    //
  520.    if (sNewCnt > 0x7ff0) {
  521.       sNewCnt -= sOldCnt;
  522.       for (i = 0; i < 4; i++)
  523.      Buff[i].sUseCnt = Buff[i].sUseCnt - sOldCnt;
  524.    }
  525.    Buff[sLast].sUseCnt = ++sNewCnt;
  526.    //
  527.    // Create Pointer, set limits to buffer.
  528.    //
  529.    pcDataPtr = MAKEP (Buff[sLast].usBSel, Buff[sLast].usBOff
  530.              + (USHORT) (lFilePtr - Buff[sLast].lFilePtr));
  531.    if (fForward)
  532.       *usLimit = Buff[sLast].usBOff + Buff[sLast].usDSize - 1;
  533.    else
  534.       *usLimit = Buff[sLast].usBOff;
  535.  
  536.    return pcDataPtr;
  537. }
  538. //------------------------------------------------------------------
  539. // GetChar - Get character in file at requested file pointer position
  540. //------------------------------------------------------------------
  541. CHAR GetFileChar (LONG lFilePtr) {
  542.  
  543.    USHORT   usLimit;
  544.    BOOL     fEndOfFile;
  545.  
  546.    if (File.fValid)
  547.      return *GetFileDataPtr (lFilePtr, TRUE, &usLimit, &fEndOfFile);
  548.    else
  549.      return '\0';
  550. }
  551. //------------------------------------------------------------------
  552. // MoveViewPtr - Update view pointer by scrolling the number of
  553. //     lines specified in ptrRow.  If limited by the top or bottom
  554. //     of the file, modify ptrRow to indicate the actual number of
  555. //    rows.
  556. //------------------------------------------------------------------
  557. LONG MoveViewPtr (LONG lFilePtr, LONG *ptrRow, BOOL fDispASCII) {
  558.    SHORT    j;
  559.    LONG     li;
  560.    LONG     lRow, lRowCount = 0L;
  561.    LONG     lOffset = 0L;
  562.    LONG     lOffsetLastCR = 0L;
  563.    USHORT   usLimit;
  564.    PCHAR    pcDataPtr;
  565.    BOOL     fEndOfFile;
  566.  
  567.    pcDataPtr = GetFileDataPtr (lFilePtr, *ptrRow > 0, &usLimit, &fEndOfFile);
  568.    lRow = *ptrRow;
  569.  
  570.    if (fDispASCII) {
  571.  
  572.       if (lRow > 0L) {
  573.      for (li=0; li < lRow && !fEndOfFile; li++, lOffset++){
  574.  
  575.         for (j=0; j < AVIOCOLS && *pcDataPtr != 0x0d
  576.               && !fEndOfFile; j++, lOffset++)
  577.            if ((OFFSETOF(pcDataPtr) < usLimit))
  578.           pcDataPtr++;
  579.            else {
  580.           lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  581.           pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
  582.                           &usLimit, &fEndOfFile);
  583.            }
  584.         if ((OFFSETOF(pcDataPtr) < usLimit))
  585.            pcDataPtr++;
  586.         else {
  587.            lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  588.            pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
  589.                        &usLimit, &fEndOfFile);
  590.         }
  591.         if (!fEndOfFile) {
  592.            lRowCount++;
  593.            lOffsetLastCR = lOffset + 1;
  594.         }
  595.      }
  596.      if (fEndOfFile) {
  597.         lOffset = lOffsetLastCR;
  598.      }
  599.      *ptrRow = lRowCount;
  600.       } else {
  601.      lRow = -lRow;
  602.      for (li=0; li < lRow && !fEndOfFile; li++){
  603.  
  604.         if ((OFFSETOF(pcDataPtr) > usLimit))
  605.            pcDataPtr--;
  606.         else {
  607.            lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
  608.            pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
  609.                        &usLimit, &fEndOfFile);
  610.         }
  611.         if (!fEndOfFile) {
  612.            lRowCount--;
  613.            lOffset--;
  614.         }
  615.         for (j=0; j < AVIOCOLS && !fEndOfFile; j++) {
  616.            if ((OFFSETOF(pcDataPtr) > usLimit)) {
  617.           if (*(pcDataPtr-1) == 0x0d)
  618.              break;
  619.           pcDataPtr--;
  620.            } else {
  621.           lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
  622.           pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
  623.                           &usLimit, &fEndOfFile);
  624.            }
  625.            if (!fEndOfFile) {
  626.           lOffset--;
  627.            }
  628.         }
  629.      }
  630.      *ptrRow = lRowCount;
  631.       }
  632.    }
  633.  
  634.    else {
  635.       //
  636.       // Align on paragraph
  637.       //
  638.       if (lFilePtr % 16 != 0)
  639.      lOffset -= (lFilePtr % 16);
  640.       lOffset += lRow * 16;
  641.       *ptrRow = lRow;
  642.       //
  643.       //Limit Checking
  644.       //
  645.       if ((lFilePtr == 0L && lRow < 0L)
  646.       ||(lFilePtr == File.lSize && lRow > 0L)){
  647.      lOffset = 0L;
  648.      *ptrRow = 0L;
  649.       } else if ((lFilePtr + lOffset) < 0) {
  650.     lOffset =  -lFilePtr;
  651.     *ptrRow = lOffset / 16L;
  652.       } else if ((lFilePtr + lOffset) >= File.lSize) {
  653.        if (lFilePtr % 16 == 0)
  654.          lOffset = (File.lSize - lFilePtr - 1L);
  655.        else
  656.          lOffset = (File.lSize - lFilePtr - 2L);
  657.     *ptrRow = lOffset / 16L;
  658.       }
  659.    }
  660.    return lOffset;
  661. }
  662. //------------------------------------------------------------------
  663. // ComputeLines (SHORT) - Compute number of lines between two points in
  664. //     the file. (Faster (SHORT count variable) version)
  665. //------------------------------------------------------------------
  666. SHORT sComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII) {
  667.    USHORT   usLimit;
  668.    SHORT    sCount = 0L;
  669.    PCHAR    pcDataPtr;
  670.    BOOL     fEndOfFile = FALSE;
  671.  
  672.    pcDataPtr = GetFileDataPtr (lOldPtr, lOldPtr < lNewPtr, &usLimit,
  673.                    &fEndOfFile);
  674.    if (fDispASCII)
  675.       if (lOldPtr < lNewPtr) {
  676.      while (lOldPtr < lNewPtr && !fEndOfFile){
  677.         if (*pcDataPtr == 0x0d)
  678.            sCount++;
  679.         lOldPtr++;
  680.         if ((OFFSETOF(pcDataPtr) < usLimit))
  681.            pcDataPtr++;
  682.         else
  683.            pcDataPtr = GetFileDataPtr (lOldPtr, TRUE, &usLimit,
  684.                        &fEndOfFile);
  685.      }
  686.       }
  687.       else {
  688.      while (lOldPtr > lNewPtr && !fEndOfFile) {
  689.         if (*pcDataPtr == 0x0d)
  690.            sCount--;
  691.         lOldPtr--;
  692.         if ((OFFSETOF(pcDataPtr) > usLimit))
  693.            pcDataPtr--;
  694.         else
  695.            pcDataPtr = GetFileDataPtr (lOldPtr, FALSE, &usLimit,
  696.                        &fEndOfFile);
  697.      }
  698.       }
  699.    else
  700.       sCount = (SHORT) ((lNewPtr - lOldPtr) / 16);
  701.    return sCount;
  702. }
  703. //------------------------------------------------------------------
  704. // ComputeLines (LONG) - Compute number of lines between two points in
  705. //     the file. (Slower (LONG count variable) version)
  706. //------------------------------------------------------------------
  707. LONG lComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII) {
  708.    USHORT   usLimit;
  709.    LONG     lCount = 0L;
  710.    PCHAR    pcDataPtr;
  711.    BOOL     fEndOfFile = FALSE;
  712.  
  713.    if (labs(lNewPtr - lOldPtr) > 65536)
  714.      WinSetPointer (HWND_DESKTOP,
  715.             WinQuerySysPointer (HWND_DESKTOP,
  716.                     SPTR_WAIT,
  717.                     FALSE) );
  718.  
  719.    pcDataPtr = GetFileDataPtr (lOldPtr, lOldPtr < lNewPtr, &usLimit,
  720.                    &fEndOfFile);
  721.    if (fDispASCII)
  722.       if (lOldPtr < lNewPtr) {
  723.      while (lOldPtr < lNewPtr && !fEndOfFile){
  724.         if (*pcDataPtr == 0x0d)
  725.            lCount++;
  726.         lOldPtr++;
  727.         if ((OFFSETOF(pcDataPtr) < usLimit))
  728.            pcDataPtr++;
  729.         else
  730.            pcDataPtr = GetFileDataPtr (lOldPtr, TRUE, &usLimit,
  731.                        &fEndOfFile);
  732.      }
  733.       }
  734.       else {
  735.      while (lOldPtr > lNewPtr && !fEndOfFile) {
  736.         if (*pcDataPtr == 0x0d)
  737.            lCount--;
  738.         lOldPtr--;
  739.         if ((OFFSETOF(pcDataPtr) > usLimit))
  740.            pcDataPtr--;
  741.         else
  742.            pcDataPtr = GetFileDataPtr (lOldPtr, FALSE, &usLimit,
  743.                        &fEndOfFile);
  744.      }
  745.       }
  746.    else
  747.       lCount = ((lNewPtr - lOldPtr) / 16L);
  748.  
  749.    WinSetPointer (HWND_DESKTOP,
  750.           WinQuerySysPointer (HWND_DESKTOP,
  751.                       SPTR_ARROW,
  752.                       FALSE) );
  753.  
  754.    return lCount;
  755. }
  756. //------------------------------------------------------------------
  757. // btoa Convert byte to ASCII
  758. //------------------------------------------------------------------
  759. VOID btoa (UCHAR cNum, UCHAR szOut[], BOOL fBlank) {
  760.    SHORT    i;
  761.  
  762.    for (i = 2; i > 0; i--)
  763.       if (fBlank)
  764.      szOut[i] = ' ';
  765.       else {
  766.      szOut[i] = (cNum % (UCHAR) 16) + (UCHAR) 0x30;
  767.      if (szOut[i] > 0x39) szOut[i] += (BYTE) 7;
  768.         cNum /= 16;
  769.       }
  770.    szOut[0] = ' ';
  771.    return;
  772. }
  773.  
  774. //------------------------------------------------------------------
  775. // Myltoa Convert a long to ASCII with leading zeros
  776. //------------------------------------------------------------------
  777. VOID Myltoa (ULONG lNum, UCHAR szOut[]) {
  778.    SHORT    i;
  779.  
  780.    for (i = 7; i >= 0; i--) {
  781.       szOut[i + (i+1)/5] = (BYTE) (lNum % 16) + (CHAR) 0x30;
  782.       if (szOut[i + (i+1)/5] > 0x39) szOut[i + (i+1)/5] += (BYTE) 7;
  783.       lNum /= 16;
  784.    }
  785.    szOut[4] = ' ';
  786.    return;
  787. }
  788.  
  789. //------------------------------------------------------------------
  790. // atob Convert ASCII Hex string to binary string
  791. //------------------------------------------------------------------
  792. SHORT atob (UCHAR szHStr[], UCHAR sStr[]) {
  793.    SHORT    inyble;
  794.    SHORT    ibyte;
  795.    SHORT    i;
  796.    SHORT    iDigit;
  797.  
  798.    ibyte = 0;
  799.  
  800.    if (strlen(szHStr) != 0) {
  801.      i = 0;
  802.      for (inyble = 0; inyble < (SHORT) strlen(szHStr); inyble++) {
  803.  
  804.        iDigit = (int) (toupper(szHStr[inyble]) - '0');
  805.        if (iDigit > 9)
  806.      iDigit = iDigit - 7;
  807.        if ((iDigit < 0) || (iDigit > 15)) {
  808.      if (i == 1) {
  809.        i = 0;
  810.        ibyte++;
  811.        }
  812.      continue;
  813.      }
  814.  
  815.        if (i == 0) {
  816.      sStr[ibyte] = (UCHAR) iDigit;
  817.      i = 1;
  818.      }
  819.        else {
  820.      sStr[ibyte] = (sStr[ibyte]*(UCHAR)16) + (UCHAR) iDigit;
  821.      i = 0;
  822.      ibyte++;
  823.      }
  824.        }
  825.      }
  826.    return ibyte;
  827. }
  828.  
  829. //------------------------------------------------------------------
  830. // Display Line
  831. //------------------------------------------------------------------
  832. SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII) {
  833.  
  834.    UCHAR    cHexChar, szTempBuff[256];
  835.    SHORT    i, sStart, sBytesPrinted = 0;
  836.    USHORT   usLimit;
  837.    BOOL     fEndOfFile;
  838.    PCHAR    pcDataPtr;
  839.  
  840.  
  841.    if (fDispASCII) {
  842.       //
  843.       // Print as ASCII until CR or for 255 characters.
  844.       //
  845.       pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
  846.  
  847.       for (i = 0; i <= AVIOCOLS && !fEndOfFile; i++){
  848.      if (*pcDataPtr == 0x0a) {
  849.         if ((OFFSETOF(pcDataPtr) < usLimit))
  850.            pcDataPtr++;
  851.         else {
  852.            lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  853.            pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  854.                        &fEndOfFile);
  855.         }
  856.         if (fEndOfFile)
  857.           szTempBuff[i] = ' ';
  858.         else
  859.           szTempBuff[i] = *pcDataPtr;
  860.         sBytesPrinted++;
  861.      } else
  862.         szTempBuff[i] = *pcDataPtr;
  863.  
  864.      if ((OFFSETOF(pcDataPtr) < usLimit))
  865.         pcDataPtr++;
  866.      else {
  867.         lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  868.         pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  869.                     &fEndOfFile);
  870.      }
  871.      sBytesPrinted++;
  872.      //
  873.      // Expand Tab Characters
  874.      //
  875.      if (szTempBuff[i] == 0x09) {
  876.         for (;(i+1) % Default.sTabStop != 0 && i <= AVIOCOLS; i++)
  877.            szTempBuff[i] = ' ';
  878.         szTempBuff[i] = ' ';
  879.      }
  880.      //
  881.      // If CR, end of line.
  882.      if (szTempBuff[i] == 0x0d) {
  883.         break;
  884.      }
  885.       }
  886.    } else {
  887.       //
  888.       // Convert from Hex and print.
  889.       //
  890.       pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
  891.       sStart = (SHORT) (lLinePtr % 16L);
  892.       sBytesPrinted = 0;
  893.       for (i = 0; i < 10; i++)
  894.      szTempBuff[i] = ' ';
  895.  
  896.       if (!fEndOfFile)
  897.      Myltoa (lLinePtr, szTempBuff);
  898.  
  899.       for (i = 0; i < 16; i++){
  900.  
  901.      cHexChar = *pcDataPtr;
  902.  
  903.      btoa (cHexChar, szTempBuff + 10 + (i*3) + (i/8),
  904.            ((i < sStart) || fEndOfFile) );
  905.      if (Default.fDispEBCDIC)
  906.         szTempBuff[i+60+(i/8)] = ((i < sStart) || fEndOfFile) ?
  907.                       (CHAR) 0x20 : caEBtoASCII[cHexChar];
  908.      else
  909.         szTempBuff[i+60+(i/8)] = ((i < sStart) || fEndOfFile) ? (CHAR) 0x20
  910.                                   : cHexChar;
  911.  
  912.  
  913.      if (i >= sStart){
  914.         if ((OFFSETOF(pcDataPtr) < usLimit))
  915.            pcDataPtr++;
  916.         else {
  917.            lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  918.            pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  919.                        &fEndOfFile);
  920.         }
  921.      }
  922.       }
  923.       szTempBuff[34] = ' ';
  924.       szTempBuff[59] = ' ';
  925.       szTempBuff[68] = ' ';
  926.       sBytesPrinted = i - sStart;
  927.       i += 59 + (i/8);
  928.    }
  929.    VioWrtCharStr (szTempBuff, i, sRow, 0, hvps);
  930.    return sBytesPrinted;
  931. }
  932. //------------------------------------------------------------------
  933. // SearchFile - Search the file for the value in szSearchStr or sSearchStr.
  934. //    If found, the file pointer is modified to the location in the
  935. //     file.
  936. //------------------------------------------------------------------
  937. BOOL SearchFile (LONG *lFilePtr) {
  938.    USHORT   usLimit;
  939.    PCHAR    pcDataPtr;
  940.    BOOL     fEndOfFile = FALSE, fFound = FALSE;
  941.    CHAR     szCmpBuffer[165];
  942.    SHORT    sBufferLength, sBufferCnt, sSearchLen, i;
  943.    LONG     lLocalPtr, lMarker;
  944.  
  945.  
  946.    WinSetPointer (HWND_DESKTOP,
  947.           WinQuerySysPointer (HWND_DESKTOP,
  948.                       SPTR_WAIT,
  949.                       FALSE) );
  950.    if (fHexString)
  951.      sSearchLen = cbSearchStrLen;
  952.    else
  953.      sSearchLen = strlen (szSearchStr);
  954.  
  955.    lLocalPtr = (fTopSearch) ? 0L : *lFilePtr;
  956.  
  957.    pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit, &fEndOfFile);
  958.  
  959.    while (!fEndOfFile && !fFound) {
  960.  
  961.       sBufferLength = (BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE))
  962.               - sSearchLen;
  963.       if (sBufferLength <= 0) {
  964.  
  965.      for (i = 0; i < BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE); i++)
  966.         *(szCmpBuffer + i) = *(pcDataPtr + i);
  967.  
  968.      sBufferCnt = i;
  969.      lMarker = lLocalPtr;
  970.      lLocalPtr = ((lLocalPtr + BUFFERSIZE) / BUFFERSIZE) * BUFFERSIZE;
  971.  
  972.      pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit,
  973.                      &fEndOfFile);
  974.      if (fEndOfFile)
  975.         break;
  976.      for (i = 0; i < min (sSearchLen + 1,
  977.                   BUFFERSIZE - (usLimit % BUFFERSIZE)); i++)
  978.         *(szCmpBuffer + sBufferCnt + i) = *(pcDataPtr + i);
  979.  
  980.      for (i = 0; i < sBufferCnt; i++)
  981.         if (fHexString) {
  982.            if (memcmp (szCmpBuffer + i, sSearchStr, sSearchLen) == 0) {
  983.           fFound = TRUE;
  984.           break;
  985.           }
  986.            }
  987.         else
  988.            if (fCheckCase) {
  989.           if (strncmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
  990.              fFound = TRUE;
  991.              break;
  992.           }
  993.            } else {
  994.           if (strnicmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
  995.              fFound = TRUE;
  996.              break;
  997.           }
  998.            }
  999.      sBufferLength = (BUFFERSIZE - (usLimit%BUFFERSIZE)) - sSearchLen;
  1000.       }
  1001.       if (fFound) {
  1002.      lLocalPtr = lMarker + i;
  1003.      break;
  1004.       }
  1005.       for (i = 0; i < sBufferLength; i++) {
  1006.         if (fHexString) {
  1007.            if (memcmp (pcDataPtr + i, sSearchStr, sSearchLen) == 0) {
  1008.           fFound = TRUE;
  1009.           break;
  1010.            }
  1011.         }
  1012.      else
  1013.         if (fCheckCase) {
  1014.            if (strncmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
  1015.           fFound = TRUE;
  1016.           break;
  1017.            }
  1018.         } else {
  1019.            if (strnicmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
  1020.           fFound = TRUE;
  1021.           break;
  1022.            }
  1023.         }
  1024.       }
  1025.       lLocalPtr += i;
  1026.    }
  1027.    if (fFound)
  1028.       *lFilePtr = lLocalPtr;
  1029.  
  1030.    WinSetPointer (HWND_DESKTOP,
  1031.           WinQuerySysPointer (HWND_DESKTOP,
  1032.                       SPTR_ARROW,
  1033.                       FALSE) );
  1034.    return fFound;
  1035. }
  1036. //------------------------------------------------------------------
  1037. // ScrollVis - Set Scroll Visibility
  1038. //------------------------------------------------------------------
  1039. VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
  1040.         HWND hwndMenu) {
  1041.  
  1042.    if (Default.fScrollBars) {
  1043.  
  1044.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1045.           MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
  1046.           MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  1047.  
  1048.       WinSetParent (hwndVScroll, hwndFrame, FALSE );
  1049.       WinSetParent (hwndHScroll, hwndFrame, FALSE );
  1050.    } else {
  1051.  
  1052.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1053.           MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
  1054.           MPFROM2SHORT (MIA_CHECKED, 0));
  1055.  
  1056.       WinSetParent (hwndVScroll, HWND_OBJECT, FALSE );
  1057.       WinSetParent (hwndHScroll, HWND_OBJECT, FALSE );
  1058.    }
  1059.    WinSendMsg ( hwndFrame , WM_UPDATEFRAME ,
  1060.    (MPARAM) (FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
  1061.    FCF_MENU), NULL);
  1062.  
  1063.    return;
  1064. }
  1065. //------------------------------------------------------------------
  1066. // Set ASCII - Set ASCII Menu Check marks.
  1067. //------------------------------------------------------------------
  1068. VOID SetASCII (HWND hwndMenu, LONG *lViewPtr) {
  1069.    LONG  lRow = -1;
  1070.    if (Default.fDispASCII) {
  1071.       if (!(MIA_CHECKED && WinSendMsg (hwndMenu, MM_QUERYITEMATTR,
  1072.                    MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
  1073.                    MPFROM2SHORT (MIA_CHECKED, 0)))) {
  1074.      *lViewPtr += 2;
  1075.      *lViewPtr += MoveViewPtr (*lViewPtr, &lRow, TRUE);
  1076.       }
  1077.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1078.           MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
  1079.           MPFROM2SHORT (MIA_CHECKED, 0));
  1080.  
  1081.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1082.           MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
  1083.           MPFROM2SHORT (MIA_CHECKED, 0));
  1084.  
  1085.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1086.           MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
  1087.           MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  1088.    } else {
  1089.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1090.           MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
  1091.           MPFROM2SHORT (MIA_CHECKED, 0));
  1092.  
  1093.       if (Default.fDispEBCDIC) {
  1094.      WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1095.              MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
  1096.              MPFROM2SHORT (MIA_CHECKED, 0));
  1097.  
  1098.      WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1099.              MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
  1100.              MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  1101.       } else {
  1102.      WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1103.              MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
  1104.              MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  1105.  
  1106.      WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1107.              MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
  1108.              MPFROM2SHORT (MIA_CHECKED, 0));
  1109.       }
  1110.    }
  1111.    return;
  1112. }
  1113.  
  1114.  
  1115.  
  1116.  
  1117. //------------------------------------------------------------------
  1118. // SetDispFilePos - Set File Position Menu Check Marks.
  1119. //------------------------------------------------------------------
  1120. VOID SetDispFilePos (HWND hwndMenu)
  1121.   {
  1122.   if (Default.fDispFilePos)
  1123.     {
  1124.     WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1125.         MPFROM2SHORT (IDM_DISPFILEPOS, TRUE),
  1126.         MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  1127.     }
  1128.   else
  1129.     {
  1130.     WinSendMsg (hwndMenu, MM_SETITEMATTR,
  1131.         MPFROM2SHORT (IDM_DISPFILEPOS, TRUE),
  1132.         MPFROM2SHORT (MIA_CHECKED, 0));
  1133.     }
  1134.   }
  1135. //------------------------------------------------------------------
  1136. // SetFontSize - Change font size and update menu if necessary.
  1137. //------------------------------------------------------------------
  1138. VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
  1139.           SHORT *psCharHeight) {
  1140.  
  1141.    VioSetDeviceCellSize (Default.sCellHeight, Default.sCellWidth, hvps);
  1142.    VioGetDeviceCellSize (psCharHeight, psCharWidth, hvps);
  1143.  
  1144.    return;
  1145. }
  1146. //=======================================================================
  1147. //
  1148. // Client Window Procedure
  1149. //
  1150. //=======================================================================
  1151. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1152.    {
  1153.    static   HWND  hwndFrame, hwndMenu, hwndVScroll, hwndHScroll;
  1154.  
  1155.    static   HVPS  hvps;
  1156.    static   HPS   hps;
  1157.  
  1158.    static   LONG  lViewPtr;
  1159.    static   BOOL  fGoMinimize;
  1160.  
  1161.    static   SHORT sHScroll, sVScrScale, sHPage = 20, sVPage = 20;
  1162.    static   SHORT sCharHeight, sCharWidth, sxWinSize, syWinSize;
  1163.    static   SHORT sRowsVisible = AVIOROWS;
  1164.    static   SHORT syStatusLine = 0;
  1165.  
  1166.    static   CHAR  szBuffer[81];
  1167.    static   CHAR  szDragItemRMF[41];
  1168.    static   CHAR  szDropDirectory[81];
  1169.    static   CHAR  szDropFileName[81];
  1170.    static   CHAR  szDropNewFileName[81];
  1171.    static   BOOL  fDropFile = FALSE;
  1172.    static   SHORT fsWinPosFlags = SWP_SHOW;
  1173.  
  1174.    static   PDRAGINFO pDragInfo;
  1175.    static   DRAGITEM  DragItem;
  1176.  
  1177.    static   CHAR * pszFMFileList;
  1178.  
  1179.    HDC        hdc;
  1180.    SIZEL    sizl;
  1181.    SHORT    sRow;
  1182.    SHORT    sTempRow;
  1183.    LONG     lRow;
  1184.    SHORT    sTemp;
  1185.    LONG     lDeltaRows;
  1186.    LONG     lTemp;
  1187.    SWP        swpWinPos;
  1188.    PSWP     pswpWinPos;
  1189.    CHAR     szTempBuffer[PATHLENGTH];
  1190.    HWND     hwndSearchMsg;
  1191.    SHORT    i;
  1192.  
  1193.    BOOL     fFileNameOK = FALSE;
  1194.  
  1195.    LONG     lOutCount;
  1196.  
  1197.    struct VioCellStruct {
  1198.       VIOSIZECOUNT    VioSizeCount;
  1199.       VIOFONTCELLSIZE VioCellSize[NO_OF_VIO_SIZES];
  1200.    } OutData;
  1201.  
  1202.    switch (msg) {
  1203.  
  1204.       //--------------------------------------------------------------
  1205.       // When the window is created, get and store the handles to
  1206.       //   the scroll bars and menu, read the default parameters if
  1207.       //   saved before, set the proper attributes for the menu
  1208.       //   selections, and create a AVIO presentation space.
  1209.       //--------------------------------------------------------------
  1210.       case WM_CREATE:
  1211.  
  1212.      WinQueryWindowText (hwndFrame,
  1213.                  sizeof szStartTitleText,
  1214.                  szStartTitleText);
  1215.      strcpy (szStartTitleText, "PM File View");
  1216.  
  1217.      //
  1218.      // If no file specified and not starting as an icon, Query
  1219.      // user for a file name.
  1220.      //
  1221.      if (!File.fValid) {
  1222.         if (strlen (szNewFile) == 0) {
  1223.            if (!fMinimized)
  1224.           if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
  1225.              (HMODULE) NULL, IDD_OPEN, (PVOID) NULL))
  1226.              if (!(File.fValid = OpenFile (szNewFile)))
  1227.             WinMessageBox (HWND_DESKTOP, hwnd,
  1228.                        "Unable to open the file",
  1229.                        szNewFile,
  1230.                        (USHORT) NULL,
  1231.                        MB_OK | MB_ERROR);
  1232.         } else
  1233.            if (!(File.fValid = OpenFile (szNewFile)))
  1234.           WinMessageBox (HWND_DESKTOP, hwnd,
  1235.                  "Unable to open the file", szNewFile,
  1236.                  (USHORT) NULL, MB_OK | MB_ERROR);
  1237.         if (File.fValid) {
  1238.            if (sHScroll) {
  1239.           sHScroll = 0;
  1240.           VioSetOrg (0, sHScroll, hvps);
  1241.            }
  1242.            lViewPtr = 0L;
  1243.            lRowNumber = 1L;
  1244.            lLastRowNumber = 0L;
  1245.            lLastRow = 0L;
  1246.            lRowPointer = lViewPtr;
  1247.            sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  1248.         }
  1249.      }
  1250.      fMinimized = FALSE;
  1251.      //
  1252.      // Query the Frame for the necessary window handles.
  1253.      //
  1254.      hwndFrame = WinQueryWindow (hwnd, QW_PARENT,FALSE);
  1255.      hwndMenu = WinWindowFromID (hwndFrame, FID_MENU);
  1256.      hwndVScroll = WinWindowFromID (hwndFrame, FID_VERTSCROLL);
  1257.      hwndHScroll = WinWindowFromID ( hwndFrame, FID_HORZSCROLL);
  1258.      //
  1259.      // Set menu attributes.
  1260.      //
  1261.      sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  1262.      ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  1263.      SetASCII (hwndMenu, &lViewPtr);
  1264.      SetDispFilePos (hwndMenu);
  1265.      //
  1266.      // Establish AVIO presentation space.
  1267.      //
  1268.      hdc = WinOpenWindowDC (hwnd);
  1269.      sizl.cx = sizl.cy = 0;
  1270.      hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT |
  1271.                 GPIT_MICRO | GPIA_ASSOC);
  1272.      VioCreatePS (&hvps, AVIOROWS, AVIOCOLS, 0, 1, (HVPS) NULL);
  1273.      VioAssociate (hdc, hvps);
  1274.      if ( (Default.sCellWidth <= 0) || (Default.sCellHeight <= 0) )
  1275.        VioGetDeviceCellSize (&Default.sCellHeight,
  1276.                  &Default.sCellWidth,
  1277.                  hvps);
  1278.  
  1279.      //
  1280.      // Get available font sizes
  1281.      //
  1282.      lOutCount = (LONG) sizeof(OutData);
  1283.      DevEscape(hdc, DEVESC_QUERYVIOCELLSIZES,
  1284.             0L,
  1285.             (PBYTE) NULL,
  1286.             &lOutCount,
  1287.             (PBYTE) &OutData);
  1288.      sCellSizeCount = (SHORT) OutData.VioSizeCount.count;
  1289.      for (i=0; i<sCellSizeCount; i++)
  1290.        {
  1291.        sCellSize[i][0] = (SHORT) OutData.VioCellSize[i].cx;
  1292.        sCellSize[i][1] = (SHORT)OutData.VioCellSize[i].cy;
  1293.        }
  1294.  
  1295.      SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  1296.      VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
  1297.  
  1298.      if (strlen (File.szName) != 0)
  1299.         {
  1300.         sprintf (szTempBuffer, "PM File View - %s", File.szName);
  1301.         WinSetWindowText (hwndFrame, szTempBuffer);
  1302.         }
  1303.      else
  1304.         WinSetWindowText (hwndFrame, szStartTitleText);
  1305.  
  1306.      return 0;
  1307.  
  1308.       //--------------------------------------------------------------
  1309.       // Intercept the close message to abort a file open dialog box
  1310.       //   when the program is closed from an icon.
  1311.       //--------------------------------------------------------------
  1312.       case WM_CLOSE:
  1313.  
  1314.         fMinimized = FALSE;
  1315.      break;
  1316.  
  1317.       //--------------------------------------------------------------
  1318.       // If the Window is being restored from an icon without a vaild
  1319.       //   file, prompt the user for a file using the file open dialog
  1320.       //   box.
  1321.       //--------------------------------------------------------------
  1322.       case WM_MINMAXFRAME:
  1323.  
  1324.      if (fMinimized)
  1325.         if (!File.fValid) {
  1326.            if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc, (HMODULE) NULL,
  1327.                  IDD_OPEN, (PVOID) NULL)) {
  1328.           if (!(File.fValid = OpenFile (szNewFile)))
  1329.              WinMessageBox (HWND_DESKTOP, hwnd,
  1330.                     "Unable to open the file",
  1331.                     szNewFile, (USHORT) NULL,
  1332.                     MB_OK | MB_ERROR);
  1333.           else {
  1334.              if (sHScroll) {
  1335.             sHScroll = 0;
  1336.             VioSetOrg (0, sHScroll, hvps);
  1337.              }
  1338.              lViewPtr = 0;
  1339.              sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  1340.              sprintf (szTempBuffer, "PM File View - %s", File.szName);
  1341.              WinSetWindowText (hwndFrame, szTempBuffer);
  1342.           }
  1343.            } else
  1344.           fGoMinimize = TRUE;
  1345.         }
  1346.      //
  1347.      // Record the current state of the program.
  1348.      //
  1349.      pswpWinPos = PVOIDFROMMP (mp1);
  1350.      if (pswpWinPos->fs & SWP_MINIMIZE)
  1351.         fMinimized = TRUE;
  1352.      else
  1353.         fMinimized = FALSE;
  1354.      break;
  1355.  
  1356.       //--------------------------------------------------------------
  1357.       // When the GoMinimize flag is set send the frame a minimize
  1358.       //   message.
  1359.       //--------------------------------------------------------------
  1360.       case WM_WINDOWPOSCHANGED:
  1361.  
  1362.         if (fGoMinimize) {
  1363.            fGoMinimize = FALSE;
  1364.            WinSetWindowPos (hwndFrame, HWND_BOTTOM, 0, 0, 0, 0,
  1365.                  SWP_MINIMIZE);
  1366.         }
  1367.      break;
  1368.  
  1369.       //--------------------------------------------------------------
  1370.       // When the window is resized, record the new window size,
  1371.       //   update the horizontal position of the AVIO space and
  1372.       //   scroll bar, and notify the frame to modify its windows.
  1373.       //--------------------------------------------------------------
  1374.       case WM_SIZE:
  1375.  
  1376.      sxWinSize = SHORT1FROMMP(mp2);
  1377.      syWinSize = SHORT2FROMMP(mp2);
  1378.  
  1379.      // Set Clipping Rectangle to AVIO text area
  1380.      SetClipAVIO (hps, hwnd);
  1381.  
  1382.      if (sHScroll > AVIOCOLS - sxWinSize / sCharWidth) {
  1383.         sHScroll = min (max (0, sHScroll),
  1384.                  AVIOCOLS - sxWinSize / sCharWidth);
  1385.         VioSetOrg (0, sHScroll, hvps);
  1386.         WinInvalidateRect (hwnd, NULL, FALSE);
  1387.      }
  1388.      if (Default.fDispFilePos)
  1389.        syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
  1390.      else
  1391.        syStatusLine = 0;
  1392.      sHPage = max (sxWinSize / sCharWidth - 1, 0);
  1393.      sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
  1394.  
  1395.      sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
  1396.                  AVIOROWS);
  1397.  
  1398.      WinSendMsg ( hwndFrame, WM_UPDATEFRAME, (MPARAM) (FCF_TITLEBAR
  1399.               | FCF_SYSMENU | FCF_MINMAX | FCF_MENU), NULL);
  1400.  
  1401.      WinSendMsg (hwndHScroll, SBM_SETSCROLLBAR,
  1402.              MPFROM2SHORT (sHScroll, 0),
  1403.              MPFROM2SHORT (0, AVIOCOLS - sxWinSize / sCharWidth));
  1404.  
  1405.      WinSendMsg (hwndHScroll, SBM_SETTHUMBSIZE,
  1406.              MPFROM2SHORT (sxWinSize / sCharWidth,
  1407.              AVIOCOLS - sxWinSize / sCharWidth), NULL);
  1408.  
  1409.      WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
  1410.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
  1411.              MPFROM2SHORT (0, (SHORT)(File.lSize/sVScrScale)));
  1412.  
  1413.  
  1414.      if ( (SHORT)((syWinSize/sCharHeight) * 30) <
  1415.           (SHORT)(File.lSize/sVScrScale) )
  1416.         WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  1417.             MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
  1418.             (SHORT)(File.lSize/sVScrScale)),NULL);
  1419.      else
  1420.         WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  1421.             MPFROM2SHORT( (syWinSize/sCharHeight) * 16,
  1422.             (SHORT)(File.lSize/sVScrScale)),NULL);
  1423.  
  1424.      return WinDefAVioWindowProc (hwnd, msg, mp1, mp2);
  1425.  
  1426.       //--------------------------------------------------------------
  1427.       // Repaint the complete AVIO space by first clearing the window
  1428.       //   then writing to the AVIO space.
  1429.       //--------------------------------------------------------------
  1430.       case WM_PAINT:
  1431.  
  1432.      WinBeginPaint (hwnd, hps, NULL);
  1433.      VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
  1434.  
  1435.      lTemp = lViewPtr;
  1436.      for (sRow = 0; sRow < sRowsVisible; sRow++)
  1437.         lTemp += (LONG) DisplayLine (hvps, sRow, lTemp,
  1438.                       Default.fDispASCII);
  1439.  
  1440.      DisplayFilePos (hps, hwnd, lViewPtr);
  1441.      WinEndPaint (hps);
  1442.  
  1443.      WinSendMsg (hwndVScroll, SBM_SETPOS,
  1444.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
  1445.              NULL);
  1446.      return 0;
  1447.  
  1448.       //--------------------------------------------------------------
  1449.       // Process each menu selection according to function.
  1450.       //--------------------------------------------------------------
  1451.       case WM_COMMAND:
  1452.  
  1453.      switch (COMMANDMSG(&msg)->cmd) {
  1454.  
  1455.      case IDM_NEW:
  1456.  
  1457.         if (File.hHandle)
  1458.            DosClose (File.hHandle);
  1459.         VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
  1460.  
  1461.         *File.szName = '\0';
  1462.         File.hHandle = NULL;
  1463.         File.lSize = 0L;
  1464.         File.fValid = FALSE;
  1465.         lRowNumber = 1L;
  1466.         lLastRowNumber = 0L;
  1467.         lLastRow = 0L;
  1468.         lRowPointer = 0L;
  1469.  
  1470.         WinSetWindowText (hwndFrame, szStartTitleText);
  1471.  
  1472.         WinPostMsg (hwnd, WM_COMMAND,
  1473.             MPFROM2SHORT (IDM_OPEN,0), 0L);
  1474.  
  1475.         return 0;
  1476.  
  1477.      case IDM_OPEN:
  1478.         WinSetPointer (HWND_DESKTOP,
  1479.                WinQuerySysPointer (HWND_DESKTOP,
  1480.                            SPTR_WAIT,
  1481.                            FALSE) );
  1482.         if (fDropFile)
  1483.           {
  1484.           strcpy (szNewFile, szDropNewFileName);
  1485.           fFileNameOK = TRUE;
  1486.           fDropFile = FALSE;
  1487.           if (fMinimized)
  1488.         {
  1489.         File.fValid = TRUE; /* Necessary to prevent file dialog */
  1490.         fsWinPosFlags = SWP_SHOW | SWP_RESTORE;
  1491.         fsWinPosFlags |= SWP_FOCUSACTIVATE | SWP_ACTIVATE;
  1492.         if (Default.sxWinPos != -1)
  1493.            fsWinPosFlags |= SWP_MOVE | SWP_SIZE;
  1494.         WinSetWindowPos (hwndFrame, HWND_TOP, Default.sxWinPos,
  1495.                               Default.syWinPos,
  1496.                               Default.sWinWidth,
  1497.                               Default.sWinHeight,
  1498.                               fsWinPosFlags);
  1499.         fMinimized = FALSE;
  1500.         }
  1501.           }
  1502.         else
  1503.           {
  1504.           fFileNameOK = WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
  1505.                       (HMODULE) NULL, IDD_OPEN, (PVOID) NULL);
  1506.           }
  1507.         if (fFileNameOK) {
  1508.            WinSetPointer (HWND_DESKTOP,
  1509.                   WinQuerySysPointer (HWND_DESKTOP,
  1510.                           SPTR_ARROW,
  1511.                           FALSE) );
  1512.            if (File.fValid = OpenFile (szNewFile)) {
  1513.           if (sHScroll) {
  1514.              sHScroll = 0;
  1515.              VioSetOrg (0, sHScroll, hvps);
  1516.           }
  1517.           lViewPtr = 0;
  1518.           lLastRowNumber = 0L;
  1519.           lLastRow = 0L;
  1520.           lRowNumber = 1L;
  1521.           lRowPointer = lViewPtr;
  1522.  
  1523.           sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  1524.  
  1525.           WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
  1526.                   MPFROM2SHORT (0, 0),
  1527.                   MPFROM2SHORT (0,
  1528.                         (SHORT)(File.lSize/sVScrScale)));
  1529.           if ( (SHORT)((syWinSize/sCharHeight) * 30) <
  1530.                (SHORT)(File.lSize/sVScrScale) )
  1531.              WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  1532.                  MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
  1533.                  (SHORT)(File.lSize/sVScrScale)),NULL);
  1534.           else
  1535.              WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  1536.                  MPFROM2SHORT( (syWinSize/sCharHeight) * 16,
  1537.                  (SHORT)(File.lSize/sVScrScale)),NULL);
  1538.           sprintf (szTempBuffer, "PM File View - %s", File.szName);
  1539.           WinSetWindowText (hwndFrame, szTempBuffer);
  1540.           WinInvalidateRect (hwnd, NULL, FALSE);
  1541.            } else {
  1542.           WinSetPointer (HWND_DESKTOP,
  1543.                  WinQuerySysPointer (HWND_DESKTOP,
  1544.                              SPTR_ARROW,
  1545.                              FALSE) );
  1546.           WinMessageBox (HWND_DESKTOP, hwnd, "Unable to open the file",
  1547.                  szNewFile, (USHORT) NULL, MB_OK | MB_ERROR);
  1548.            }
  1549.         }
  1550.         return 0;
  1551.  
  1552.      case IDM_FIND:
  1553.         if (WinDlgBox(HWND_DESKTOP, hwnd, SearchDlgProc,
  1554.               (HMODULE) NULL, IDD_SEARCH, (PVOID) NULL)) {
  1555.            if (fHexString) {
  1556.          if (strlen (szSearchHStr) != 0)
  1557.             WinPostMsg (hwnd, WM_COMMAND,
  1558.                 MPFROM2SHORT (IDM_REPFIND,0), mp2);
  1559.          }
  1560.            else
  1561.          if (strlen (szSearchStr) != 0)
  1562.             WinPostMsg (hwnd, WM_COMMAND,
  1563.                 MPFROM2SHORT (IDM_REPFIND,0), mp2);
  1564.            }
  1565.         return 0;
  1566.  
  1567.      case IDM_REPFIND:
  1568.         if ( ((fHexString) && (strlen (szSearchHStr) == 0)) ||
  1569.          ((!fHexString) && (strlen (szSearchStr) == 0)) ) {
  1570.            WinPostMsg (hwnd, WM_COMMAND, MPFROM2SHORT (IDM_FIND,0),
  1571.                mp2);
  1572.            return 0;
  1573.         } else {
  1574.            //
  1575.            //   Check to see if we are on the same line as the last
  1576.            // found string.  If so, start search at 1 byte past
  1577.            // last found string.
  1578.            //
  1579.            lDeltaRows = 1L;
  1580.            lTemp = MoveViewPtr (lViewPtr, &lDeltaRows,
  1581.                        Default.fDispASCII);
  1582.            lTemp += lViewPtr;
  1583.  
  1584.            if (lTemp > lLastFound && lLastFound >= lViewPtr)
  1585.           lLastFound++;
  1586.            else
  1587.           lLastFound = lViewPtr;
  1588.            //
  1589.            //   If string found, back up to the start of the
  1590.            // current line.
  1591.            //
  1592.            hwndSearchMsg = StartMessageBox (IDD_SRCHMSG, "");
  1593.            if (SearchFile (&lLastFound)) {
  1594.  
  1595.           lViewPtr = lLastFound;
  1596.           if (!Default.fDispASCII)
  1597.              lDeltaRows = 0L;
  1598.           else
  1599.              lDeltaRows = -1L;
  1600.           lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows,
  1601.                        Default.fDispASCII);
  1602.           WinInvalidateRect (hwnd, NULL, FALSE);
  1603.           EndMessageBox (hwndSearchMsg);
  1604.            } else {
  1605.           EndMessageBox (hwndSearchMsg);
  1606.           if (fHexString)
  1607.             WinMessageBox (HWND_DESKTOP, hwnd, szSearchHStr,
  1608.                    "Unable to find the hex string",
  1609.                    (USHORT) NULL, MB_OK | MB_ICONHAND);
  1610.           else
  1611.             WinMessageBox (HWND_DESKTOP, hwnd, szSearchStr,
  1612.                    "Unable to find the string",
  1613.                    (USHORT) NULL, MB_OK | MB_ICONHAND);
  1614.            }
  1615.         }
  1616.         return 0;
  1617.  
  1618.      case IDM_GOTO:
  1619.         if (WinDlgBox(HWND_DESKTOP, hwnd, GotoDlgProc,
  1620.               (HMODULE) NULL, IDD_GOTO, (PVOID) NULL)) {
  1621.            lViewPtr = min (max (lNewViewPtr, 0L), File.lSize);
  1622.            WinInvalidateRect (hwnd, NULL, FALSE);
  1623.         }
  1624.         return 0;
  1625.  
  1626.      case IDM_CONFIGURE:
  1627.         if (WinDlgBox(HWND_DESKTOP, hwnd, ConfigDlgProc,
  1628.               (HMODULE) NULL, IDD_CONFIGURE, (PVOID) NULL)) {
  1629.            if (fSaveToDisk) {
  1630.           if (fSaveWinPos) {
  1631.              WinQueryWindowPos (hwndFrame, &swpWinPos);
  1632.              Default.sxWinPos = swpWinPos.x;
  1633.              Default.syWinPos = swpWinPos.y;
  1634.              Default.sWinWidth = swpWinPos.cx;
  1635.              Default.sWinHeight = swpWinPos.cy;
  1636.           }
  1637.           WinWriteProfileData (hab, szAppName, szKeyName,
  1638.                        &Default, sizeof Default);
  1639.            }
  1640.            SetASCII(hwndMenu, &lViewPtr);
  1641.            SetDispFilePos(hwndMenu);
  1642.            ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  1643.            SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  1644.            if (Default.fDispFilePos)
  1645.          syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
  1646.                               SV_CYMENU);
  1647.            else
  1648.          syStatusLine = 0;
  1649.            sHPage = max (sxWinSize / sCharWidth - 1, 0);
  1650.            sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
  1651.            sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
  1652.                    AVIOROWS);
  1653.            WinInvalidateRect (hwnd, NULL, FALSE);
  1654.         }
  1655.         return 0;
  1656.  
  1657.      case IDM_DISPLAYASCII:
  1658.         if (!Default.fDispASCII) {
  1659.            Default.fDispASCII = TRUE;
  1660.            SetASCII (hwndMenu, &lViewPtr);
  1661.            WinInvalidateRect (hwnd, NULL, FALSE);
  1662.         }
  1663.         return 0;
  1664.  
  1665.      case IDM_DISPLAYHEXASC:
  1666.         if ((Default.fDispASCII) || (Default.fDispEBCDIC)) {
  1667.            Default.fDispASCII = FALSE;
  1668.            Default.fDispEBCDIC = FALSE;
  1669.            SetASCII (hwndMenu, &lViewPtr);
  1670.            WinInvalidateRect (hwnd, NULL, FALSE);
  1671.         }
  1672.         return 0;
  1673.  
  1674.      case IDM_DISPLAYHEXEBC:
  1675.         if ((Default.fDispASCII) || (!Default.fDispEBCDIC)) {
  1676.            Default.fDispASCII = FALSE;
  1677.            Default.fDispEBCDIC = TRUE;
  1678.            SetASCII (hwndMenu, &lViewPtr);
  1679.            WinInvalidateRect (hwnd, NULL, FALSE);
  1680.         }
  1681.         return 0;
  1682.  
  1683.      case IDM_DISPSCROLLBARS:
  1684.         if (Default.fScrollBars)
  1685.            Default.fScrollBars = FALSE;
  1686.         else
  1687.            Default.fScrollBars = TRUE;
  1688.  
  1689.         ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  1690.         return 0;
  1691.  
  1692.      case IDM_DISPFILEPOS:
  1693.         if (Default.fDispFilePos)
  1694.            Default.fDispFilePos = FALSE;
  1695.         else
  1696.            Default.fDispFilePos = TRUE;
  1697.  
  1698.         SetDispFilePos (hwndMenu);
  1699.         if (Default.fDispFilePos)
  1700.           syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
  1701.                                SV_CYMENU);
  1702.         else
  1703.           {
  1704.           syStatusLine = 0;
  1705.           }
  1706.  
  1707.         sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
  1708.         sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
  1709.                 AVIOROWS);
  1710.  
  1711.         // Set Clipping Rectangle to AVIO text area
  1712.         SetClipAVIO (hps, hwnd);
  1713.  
  1714.         WinInvalidateRect (hwnd, NULL, FALSE);
  1715.         return 0;
  1716.  
  1717.      case IDM_FONTSIZE:
  1718.         if (!WinDlgBox(HWND_DESKTOP, hwnd, FontDlgProc,
  1719.                (HMODULE) NULL, IDD_PICKFONT, (PVOID) NULL))
  1720.            return 0;
  1721.         SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  1722.         if (Default.fDispFilePos)
  1723.           syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
  1724.                                SV_CYMENU);
  1725.         else
  1726.           syStatusLine = 0;
  1727.         sHPage = max (sxWinSize / sCharWidth - 1, 0);
  1728.         sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
  1729.         sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
  1730.                 AVIOROWS);
  1731.         WinInvalidateRect (hwnd, NULL, FALSE);
  1732.         return 0;
  1733.  
  1734.      case IDM_ABOUT:
  1735.         WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,
  1736.               (HMODULE) NULL, IDD_ABOUT, (PVOID) NULL);
  1737.         return 0;
  1738.  
  1739.      case IDM_EXIT:
  1740.         WinSendMsg(hwnd, WM_CLOSE, 0L, 0L);
  1741.         return 0;
  1742.  
  1743.      case IDM_HELPFORHELP:
  1744.        if (hwndHelp != NULL)
  1745.          {
  1746.          WinSendMsg( hwndHelp, HM_DISPLAY_HELP, 0L, 0L);
  1747.          return 0;
  1748.          }
  1749.        break;
  1750.  
  1751.      case IDM_EXTENDEDHELP:
  1752.        if (hwndHelp != NULL)
  1753.          {
  1754.          WinSendMsg( hwndHelp, HM_EXT_HELP, 0L, 0L);
  1755.          return 0;
  1756.          }
  1757.        break;
  1758.  
  1759.      case IDM_KEYSHELP:
  1760.        if (hwndHelp != NULL)
  1761.          {
  1762.          WinSendMsg( hwndHelp, HM_KEYS_HELP, 0L, 0L);
  1763.          return 0;
  1764.          }
  1765.        break;
  1766.  
  1767.      case IDM_HELPINDEX:
  1768.        if (hwndHelp != NULL)
  1769.          {
  1770.          WinSendMsg( hwndHelp, HM_HELP_INDEX, 0L, 0L);
  1771.          return 0;
  1772.          }
  1773.        break;
  1774.  
  1775.       }
  1776.       break;
  1777.  
  1778.       case WM_HELP:
  1779.     return (WinDefWindowProc(hwnd, msg, mp1, mp2));
  1780.     break;    /* let the default handle it */
  1781.  
  1782.       case HM_QUERY_KEYS_HELP:
  1783.     return (MRESULT) IDM_KEYSHELP;
  1784.  
  1785.       case HM_ERROR:
  1786.     WinMessageBox( HWND_DESKTOP, hwnd,
  1787.       "A Help Manager error was encountered.",
  1788.       "Help Manager Error", 0, MB_OK | MB_WARNING);
  1789.       return 0;
  1790.  
  1791.       //--------------------------------------------------------------
  1792.       // Convert cursor keys to scroll bar messages.
  1793.       //--------------------------------------------------------------
  1794.       case WM_CHAR:
  1795.  
  1796.      switch (CHARMSG (&msg) -> vkey) {
  1797.  
  1798.         case VK_UP:
  1799.         case VK_DOWN:
  1800.         case VK_PAGEUP:
  1801.         case VK_PAGEDOWN:
  1802.            return WinSendMsg (hwndVScroll, msg, mp1, mp2);
  1803.  
  1804.         case VK_LEFT:
  1805.         case VK_RIGHT:
  1806.            return WinSendMsg (hwndHScroll, msg, mp1, mp2);
  1807.  
  1808.         case VK_HOME:
  1809.            if (lViewPtr != 0) {
  1810.           lViewPtr = 0L;
  1811.           lRowNumber = 1L;
  1812.           lRowPointer = 0L;
  1813.  
  1814.           WinInvalidateRect (hwnd, NULL, FALSE);
  1815.            }
  1816.            break;
  1817.  
  1818.         case VK_END:
  1819.            if (lViewPtr != File.lSize - 1) {
  1820.           lViewPtr = File.lSize - 1;
  1821.  
  1822.           if (Default.fDispASCII)
  1823.             lDeltaRows = -1L;
  1824.           else
  1825.             lDeltaRows = 0L;
  1826.           lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows,
  1827.                              Default.fDispASCII);
  1828.           if (lLastRowNumber > 0L)
  1829.             {
  1830.             lRowNumber = lLastRowNumber;
  1831.             lRowPointer = File.lSize - 1;
  1832.             }
  1833.  
  1834.           WinInvalidateRect (hwnd, NULL, FALSE);
  1835.            }
  1836.            break;
  1837.      }
  1838.      return WinDefWindowProc (hwnd, msg, mp1, mp2);
  1839.  
  1840.       //-----------------------------------------------------------
  1841.       // Process Horizonal Scroll Bar Messages by scrolling across
  1842.       //    the AVIO space.
  1843.       //-----------------------------------------------------------
  1844.       case WM_HSCROLL:
  1845.  
  1846.      switch (SHORT2FROMMP (mp2)) {
  1847.  
  1848.         case SB_LINELEFT:
  1849.  
  1850.            sHScroll -= 1;
  1851.            break;
  1852.  
  1853.         case SB_PAGELEFT:
  1854.  
  1855.            sHScroll -= sHPage;
  1856.            break;
  1857.  
  1858.         case SB_LINERIGHT:
  1859.  
  1860.            sHScroll += 1;
  1861.            break;
  1862.  
  1863.         case SB_PAGERIGHT:
  1864.  
  1865.            sHScroll += sHPage;
  1866.            break;
  1867.  
  1868.         case SB_SLIDERTRACK:
  1869.  
  1870.            sHScroll = SHORT1FROMMP (mp2);
  1871.            break;
  1872.      }
  1873.      sHScroll = min (max (0, sHScroll),
  1874.               AVIOCOLS - sxWinSize / sCharWidth);
  1875.  
  1876.      if (sHScroll != (SHORT) SHORT1FROMMR (WinSendMsg (hwndHScroll,
  1877.                            SBM_QUERYPOS, NULL, NULL))) {
  1878.         VioSetOrg (0, sHScroll, hvps);
  1879.         DisplayFilePos (hps, hwnd, lViewPtr);
  1880.         WinSendMsg (hwndHScroll, SBM_SETPOS,
  1881.             MPFROM2SHORT (sHScroll, 0), NULL);
  1882.      }
  1883.      return 0;
  1884.  
  1885.       //-----------------------------------------------------------
  1886.       // Process Vertical Scroll Bar Messages by scrolling the AVIO
  1887.       //    space and writing the new lines.
  1888.       //-----------------------------------------------------------
  1889.       case WM_VSCROLL:
  1890.  
  1891.      switch (SHORT2FROMMP (mp2)) {
  1892.  
  1893.         case SB_LINEUP:
  1894.  
  1895.            lDeltaRows = -1L;
  1896.            break;
  1897.  
  1898.         case SB_PAGEUP:
  1899.  
  1900.            lDeltaRows = (LONG) -sVPage;
  1901.            break;
  1902.  
  1903.         case SB_LINEDOWN:
  1904.  
  1905.            lDeltaRows = 1L;
  1906.            break;
  1907.  
  1908.         case SB_PAGEDOWN:
  1909.  
  1910.            lDeltaRows = (LONG) sVPage;
  1911.            break;
  1912.  
  1913.         case SB_SLIDERTRACK:
  1914.  
  1915.            lTemp = lViewPtr;
  1916.  
  1917.            lViewPtr = (LONG) ((LONG)SHORT1FROMMP(mp2) * (LONG)sVScrScale);
  1918.            if (Default.fDispASCII) {
  1919.          lDeltaRows = -1L;
  1920.          lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
  1921.          if (lDeltaRows != 0) {
  1922.             lDeltaRows = 1L;
  1923.             lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
  1924.          }
  1925.            }
  1926.            else {
  1927.          lDeltaRows = 0L;
  1928.          lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
  1929.            }
  1930.  
  1931.            sTemp = sComputeLines (lTemp, lViewPtr,
  1932.                          Default.fDispASCII);
  1933.            sTemp = (sTemp > sRowsVisible) ? sRowsVisible : sTemp;
  1934.            sTemp = (sTemp < -sRowsVisible) ? -sRowsVisible : sTemp;
  1935.            lDeltaRows = (LONG) sTemp;
  1936.  
  1937.            break;
  1938.  
  1939.         default:
  1940.            return 0;
  1941.      }
  1942.      if (SHORT2FROMMP (mp2) != SB_SLIDERTRACK)
  1943.         lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
  1944.      WinSendMsg (hwndVScroll, SBM_SETPOS,
  1945.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0), NULL);
  1946.  
  1947.      if (lDeltaRows > 0L) {
  1948.         VioScrollUp (0, 0, sRowsVisible, AVIOCOLS, (SHORT) lDeltaRows,
  1949.              Default.szAttribute, hvps);
  1950.  
  1951.         sRow = sRowsVisible-(SHORT)lDeltaRows;
  1952.         sTempRow = sRow;
  1953.  
  1954.         lTemp = lViewPtr;
  1955.         lRow = (LONG) sRow;
  1956.         lTemp += MoveViewPtr (lTemp, &lRow, Default.fDispASCII);
  1957.         sRow = (SHORT) lRow;
  1958.  
  1959.         if (sRow == sTempRow) {
  1960.            if (!Default.fDispASCII)
  1961.           for (sRow = 0; sRow <= (SHORT)lDeltaRows; sRow++)
  1962.              lTemp += DisplayLine (hvps,
  1963.                        (sRowsVisible-(SHORT)lDeltaRows) + sRow,
  1964.                        lTemp, Default.fDispASCII);
  1965.            else
  1966.           for (sRow = 0; sRow < (SHORT)lDeltaRows; sRow++)
  1967.              lTemp += DisplayLine (hvps,
  1968.                        (sRowsVisible-(SHORT)lDeltaRows) + sRow,
  1969.                        lTemp, Default.fDispASCII);
  1970.         }
  1971.      }
  1972.      if (lDeltaRows < 0L) {
  1973.         lDeltaRows = -lDeltaRows;
  1974.         VioScrollDn (0, 0, sRowsVisible, AVIOCOLS, (SHORT) lDeltaRows,
  1975.              Default.szAttribute, hvps);
  1976.  
  1977.         lTemp = lViewPtr;
  1978.         for (sRow = 0; sRow <= (SHORT) lDeltaRows; sRow++)
  1979.            lTemp += DisplayLine (hvps, sRow, lTemp, Default.fDispASCII);
  1980.      }
  1981.      DisplayFilePos (hps, hwnd, lViewPtr);
  1982.  
  1983.      return 0;
  1984.  
  1985.       //-----------------------------------------------------------
  1986.       // Handle OS/2 1.3 object (file) dragging to this application.
  1987.       //-----------------------------------------------------------
  1988.       case DM_DRAGOVER:
  1989.  
  1990.      pDragInfo = (PDRAGINFO) mp1;
  1991.      if ( DrgAccessDraginfo (pDragInfo) )
  1992.        {
  1993.        if (pDragInfo->cditem == 1)
  1994.          {
  1995.          if (DrgQueryDragitem (pDragInfo,
  1996.                    sizeof(DragItem),
  1997.                    &DragItem,
  1998.                    0) )
  1999.            {
  2000.            if (DrgQueryNativeRMF (&DragItem,
  2001.                       sizeof(szDragItemRMF),
  2002.                       szDragItemRMF) )
  2003.          {
  2004.          if ( strncmp (szDragItemRMF, "DRM_OS2FILE", 11) )
  2005.            {
  2006.            DrgQueryStrName (DragItem.hstrContainerName,
  2007.                     sizeof(szDropDirectory),
  2008.                     szDropDirectory);
  2009.            DrgQueryStrName (DragItem.hstrSourceName,
  2010.                     sizeof(szDropFileName),
  2011.                     szDropFileName);
  2012.            strcpy (szBuffer, szDropDirectory);
  2013.            if (szBuffer[strlen (szBuffer)-1] != '\\')
  2014.               strcat (szBuffer, "\\");
  2015.            strcat (szBuffer, szDropFileName);
  2016.            if (TestOpenFile (szBuffer))
  2017.              {
  2018.              return (MRFROM2SHORT(DOR_DROP, DO_UNKNOWN));
  2019.              }
  2020.            }
  2021.          }
  2022.            }
  2023.          }
  2024.        }
  2025.      return (MRFROM2SHORT(DOR_NEVERDROP, DO_UNKNOWN));
  2026.  
  2027.       case DM_DROP:
  2028.  
  2029.      pDragInfo = (PDRAGINFO) mp1;
  2030.      if ( DrgAccessDraginfo (pDragInfo) )
  2031.        {
  2032.        if (pDragInfo->cditem == 1)
  2033.          {
  2034.          if (DrgQueryDragitem (pDragInfo,
  2035.                    sizeof(DragItem),
  2036.                    &DragItem,
  2037.                    0) )
  2038.            {
  2039.            if (DrgQueryNativeRMF (&DragItem,
  2040.                       sizeof(szDragItemRMF),
  2041.                       szDragItemRMF) )
  2042.          {
  2043.          if ( strncmp (szDragItemRMF, "DRM_OS2FILE", 11) )
  2044.            {
  2045.            DrgQueryStrName (DragItem.hstrContainerName,
  2046.                     sizeof(szDropDirectory),
  2047.                     szDropDirectory);
  2048.            DrgQueryStrName (DragItem.hstrSourceName,
  2049.                     sizeof(szDropFileName),
  2050.                     szDropFileName);
  2051.            strcpy (szBuffer, szDropDirectory);
  2052.            if (szBuffer[strlen (szBuffer)-1] != '\\')
  2053.               strcat (szBuffer, "\\");
  2054.            strcat (szBuffer, szDropFileName);
  2055.            strcpy (szDropNewFileName, szBuffer);
  2056.            fDropFile = TRUE;
  2057.            DrgSendTransferMsg (DragItem.hwndItem, DM_ENDCONVERSATION,
  2058.                        MPFROMLONG(DragItem.ulItemID),
  2059.                        MPFROMSHORT(DMFL_TARGETSUCCESSFUL));
  2060.            DrgDeleteDraginfoStrHandles (pDragInfo);
  2061.            DrgFreeDraginfo (pDragInfo);
  2062.            WinPostMsg (hwnd, WM_COMMAND,
  2063.                    MPFROM2SHORT (IDM_OPEN,0), 0L);
  2064.            return 0;
  2065.            }
  2066.          }
  2067.            }
  2068.          }
  2069.        }
  2070.      fDropFile = FALSE;
  2071.      return 0;
  2072.  
  2073.       case DM_DRAGLEAVE:
  2074.  
  2075.      return 0;
  2076.  
  2077.       case DM_DROPHELP:
  2078.  
  2079.      return 0;
  2080.  
  2081.       //-----------------------------------------------------------
  2082.       // Handle File Manager object (file) dragging to this application.
  2083.       // Note: This undocumented private File Manager protocol may not
  2084.       //       be valid in subsequent OS/2 releases.
  2085.       //-----------------------------------------------------------
  2086.       case FM_DRAGOVER:
  2087.  
  2088.      // Signal File Manager that we can accept drop by returning TRUE
  2089.  
  2090.      return MRFROMSHORT(TRUE);
  2091.  
  2092.       case FM_DROP:
  2093.  
  2094.      // File Manager sends FM_DROP message.  mp1 is pointer to structure
  2095.      //   containing unknown info. + list of files selected.  List of
  2096.      //   files begins at pointer+8.  File names are separated by '\n'
  2097.      //   (0x0A), and list ends with '\0' (0x00)
  2098.      pszFMFileList = PVOIDFROMMP(mp1);
  2099.      if (strchr (pszFMFileList+8, 0x0A) == NULL)
  2100.        {
  2101.        strcpy (szBuffer, pszFMFileList+8);
  2102.        }
  2103.      else
  2104.        {
  2105.        strcpy (szBuffer, strtok (pszFMFileList+8, "\n") );
  2106.        }
  2107.  
  2108.      strcpy (szDropNewFileName, szBuffer);
  2109.      fDropFile = TRUE;
  2110.      WinPostMsg (hwnd, WM_COMMAND,
  2111.              MPFROM2SHORT (IDM_OPEN,0), 0L);
  2112.  
  2113.      return 0;
  2114.  
  2115.       //-----------------------------------------------------------
  2116.       // Destroy the AVIO space and the presentation space.
  2117.       //-----------------------------------------------------------
  2118.       case WM_DESTROY:
  2119.  
  2120.      VioAssociate (NULL, hvps);
  2121.      VioDestroyPS (hvps);
  2122.      GpiDestroyPS (hps);
  2123.      return 0;
  2124.    }
  2125.    return WinDefWindowProc (hwnd, msg, mp1, mp2);
  2126. }
  2127. //=====================================================================
  2128. // Display File Position Procedure
  2129. //=====================================================================
  2130. VOID DisplayFilePos (HPS hps, HWND hwnd, LONG lFilePtr)
  2131.   {
  2132.   CHAR       szFilePosText[50];
  2133.  
  2134.   if (Default.fDispFilePos)
  2135.     {
  2136.     if (Default.fDispASCII)
  2137.       {
  2138.       lRowNumber = lRowNumber +
  2139.             lComputeLines (lRowPointer, lFilePtr, TRUE);
  2140.       lRowPointer = lFilePtr;
  2141.       if (lLastRowNumber < 1L)
  2142.     {
  2143.     lLastRowNumber = lRowNumber +
  2144.             lComputeLines (lRowPointer, (File.lSize-1L),
  2145.                             TRUE);
  2146.     lLastRow = lLastRowNumber;
  2147.     if (GetFileChar (File.lSize-1L) == 0x0A)
  2148.       lLastRow = lLastRowNumber - 1L;
  2149.     }
  2150.       sprintf (szFilePosText, "Line %ld of %ld", lRowNumber,
  2151.                          lLastRow);
  2152.       }
  2153.     else
  2154.       sprintf (szFilePosText, "Byte %ld of %ld (%lX Hex)",
  2155.                   lFilePtr, (File.lSize-1), (File.lSize-1));
  2156.     DispStatusLine (hps, hwnd, szFilePosText);
  2157.     }
  2158.  
  2159.   // Set Clipping Rectangle to AVIO text area
  2160.   SetClipAVIO (hps, hwnd);
  2161.  
  2162.   return;
  2163.   }
  2164. //=====================================================================
  2165. // Status Line (File Position) Procedure
  2166. //=====================================================================
  2167. VOID DispStatusLine (HPS hps, HWND hwnd, CHAR * szStatusText)
  2168.   {
  2169.      RECTL    rclStatusLine;
  2170.   static HRGN    hrgnStatus;
  2171.      HRGN    hrgnOldClip;
  2172.  
  2173.   WinQueryWindowRect (hwnd, &rclStatusLine);
  2174.   rclStatusLine.yTop = WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
  2175.  
  2176.   // Set clip rectangle to status line so status line can be redrawn.
  2177.   GpiSetClipRegion (hps, NULL, &hrgnOldClip);
  2178.   GpiDestroyRegion (hps, hrgnStatus);
  2179.   hrgnStatus = GpiCreateRegion (hps, 1L, &rclStatusLine);
  2180.   GpiSetClipRegion (hps, hrgnStatus, &hrgnOldClip);
  2181.  
  2182.   WinDrawBorder (hps, &rclStatusLine, 0, 1, SYSCLR_WINDOWSTATICTEXT,
  2183.                         SYSCLR_WINDOW,
  2184.                         DB_STANDARD |
  2185.                         DB_INTERIOR );
  2186.   WinDrawText (hps, 0xFFFF, szStatusText, &rclStatusLine,
  2187.                       SYSCLR_WINDOWSTATICTEXT,
  2188.                       SYSCLR_WINDOW,
  2189.                       DT_CENTER | DT_VCENTER);
  2190.  
  2191.   }
  2192. //=====================================================================
  2193. // Procedure to Set Clip Rectangle to AVIO (Text) Area
  2194. //=====================================================================
  2195. VOID SetClipAVIO (HPS hps, HWND hwnd)
  2196.   {
  2197.      RECTL    rclVIOSpace;
  2198.   static HRGN    hrgnVIO;
  2199.      HRGN    hrgnOldClip;
  2200.  
  2201.   GpiSetClipRegion (hps, NULL, &hrgnOldClip);
  2202.  
  2203.   // Following prevents the Status Line (drawn in GPI) from being
  2204.   //   scrolled up when the AVIO text is scrolled (i.e., the VIO region is
  2205.   //   the clipped region)
  2206.  
  2207.   if (Default.fDispFilePos)
  2208.     {
  2209.     WinQueryWindowRect (hwnd, &rclVIOSpace);
  2210.     rclVIOSpace.yBottom = WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
  2211.     GpiDestroyRegion (hps, hrgnVIO);
  2212.     hrgnVIO = GpiCreateRegion (hps, 1L, &rclVIOSpace);
  2213.     GpiSetClipRegion (hps, hrgnVIO, &hrgnOldClip);
  2214.     }
  2215.   }
  2216. //=====================================================================
  2217. // Message Box Procedures
  2218. //=====================================================================
  2219.  
  2220. HWND StartMessageBox (USHORT idDlg, CHAR * szString)
  2221.  
  2222.   {
  2223.   HWND     hwndMsgBox;
  2224.  
  2225.   hwndMsgBox = WinLoadDlg (hwndClient,
  2226.                hwndFrame,
  2227.                MessageDlgProc,
  2228.                (HMODULE) NULL,
  2229.                idDlg,
  2230.                (PVOID) NULL);
  2231.   if (strlen (szString) > 0)
  2232.     WinSetDlgItemText (hwndMsgBox, idDlg, szString);
  2233.  
  2234.   return hwndMsgBox;
  2235.  
  2236.   }
  2237.  
  2238. VOID EndMessageBox (HWND hwndMsgBox)
  2239.  
  2240.   {
  2241.  
  2242.   if (hwndMsgBox != NULL)
  2243.     {
  2244.     WinDismissDlg (hwndMsgBox, TRUE);
  2245.     WinDestroyWindow (hwndMsgBox);
  2246.     }
  2247.   }
  2248.  
  2249. //=====================================================================
  2250. // Dialog Procedures
  2251. //=====================================================================
  2252. //------------------------------------------------------------------
  2253. //  Message Dialog Box
  2254. //------------------------------------------------------------------
  2255. MRESULT EXPENTRY MessageDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2256.    {
  2257.    switch (msg) {
  2258.  
  2259.       case WM_COMMAND:
  2260.  
  2261.      switch (COMMANDMSG(&msg)->cmd) {
  2262.  
  2263.         case DID_OK:
  2264.         case DID_CANCEL:
  2265.             WinDismissDlg (hwnd, TRUE);
  2266.             return 0;
  2267.      }
  2268.    }
  2269.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2270. }
  2271. //------------------------------------------------------------------
  2272. //  About Dialog Box
  2273. //------------------------------------------------------------------
  2274. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2275.    {
  2276.    switch (msg) {
  2277.  
  2278.       case WM_INITDLG:
  2279.  
  2280.      WinSetWindowUShort(hwnd, QWS_ID, IDW_ABOUT);
  2281.      if (hwndHelp != NULL)
  2282.        WinAssociateHelpInstance( hwndHelp, hwnd);
  2283.  
  2284.      CenterDlgBox (hwnd, hwndClient);
  2285.  
  2286.      return 0;
  2287.  
  2288.       case WM_COMMAND:
  2289.  
  2290.      switch (COMMANDMSG(&msg)->cmd) {
  2291.  
  2292.         case DID_OK:
  2293.         case DID_CANCEL:
  2294.             WinDismissDlg (hwnd, TRUE);
  2295.             return 0;
  2296.      }
  2297.    }
  2298.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2299. }
  2300. //------------------------------------------------------------------
  2301. //  Goto Dialog Box
  2302. //------------------------------------------------------------------
  2303. MRESULT EXPENTRY GotoDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2304.    {
  2305.    CHAR  szBuffer[12];
  2306.    LONG  lDeltaRows;
  2307.  
  2308.    switch (msg) {
  2309.  
  2310.       case WM_INITDLG:
  2311.  
  2312.      WinSetWindowUShort(hwnd, QWS_ID, IDW_GOTO);
  2313.      if (hwndHelp != NULL)
  2314.        WinAssociateHelpInstance( hwndHelp, hwnd);
  2315.  
  2316.      CenterDlgBox (hwnd, hwndClient);
  2317.  
  2318.      WinSendDlgItemMsg (hwnd, IDD_NEWOFFSET, EM_CLEAR, NULL, NULL);
  2319.  
  2320.      WinSendDlgItemMsg ( hwnd, IDD_NEWOFFSET, EM_SETTEXTLIMIT,
  2321.                  MPFROM2SHORT (11, 0), NULL);
  2322.  
  2323.      WinSendDlgItemMsg (hwnd, IDD_HEXGOTO, BM_SETCHECK,
  2324.                 MPFROM2SHORT (fHexGoto, 0), NULL);
  2325.      WinSendDlgItemMsg (hwnd, IDD_LINEGOTO, BM_SETCHECK,
  2326.                 MPFROM2SHORT (fLineGoto, 0), NULL);
  2327.      WinSendDlgItemMsg (hwnd, IDD_DECGOTO, BM_SETCHECK,
  2328.                 MPFROM2SHORT (fDecGoto, 0), NULL);
  2329.      return 0;
  2330.  
  2331.  
  2332.       case WM_CONTROL:
  2333.  
  2334.      switch (SHORT1FROMMP (mp1)) {
  2335.  
  2336.         case IDD_HEXGOTO:
  2337.            switch (SHORT2FROMMP (mp1)) {
  2338.  
  2339.           case BN_CLICKED:
  2340.              fDecGoto = FALSE;
  2341.              fLineGoto = FALSE;
  2342.              fHexGoto = TRUE;
  2343.              return 0;
  2344.            }
  2345.            break;
  2346.  
  2347.         case IDD_DECGOTO:
  2348.            switch (SHORT2FROMMP (mp1)) {
  2349.  
  2350.           case BN_CLICKED:
  2351.              fDecGoto = TRUE;
  2352.              fLineGoto = FALSE;
  2353.              fHexGoto = FALSE;
  2354.              return 0;
  2355.            }
  2356.            break;
  2357.  
  2358.         case IDD_LINEGOTO:
  2359.            switch (SHORT2FROMMP (mp1)) {
  2360.  
  2361.           case BN_CLICKED:
  2362.              fDecGoto = FALSE;
  2363.              fLineGoto = TRUE;
  2364.              fHexGoto = FALSE;
  2365.              return 0;
  2366.            }
  2367.            break;
  2368.      }
  2369.      break;
  2370.  
  2371.  
  2372.       case WM_COMMAND:
  2373.  
  2374.      switch (COMMANDMSG(&msg)->cmd) {
  2375.  
  2376.         case DID_OK:
  2377.            if (WinQueryDlgItemText (hwnd, IDD_NEWOFFSET, sizeof szBuffer,
  2378.             szBuffer)) {
  2379.           if (fHexGoto)
  2380.             lNewViewPtr = strtol(szBuffer, NULL, 16);
  2381.           else {
  2382.             if (fLineGoto) {
  2383.               WinSetPointer (HWND_DESKTOP,
  2384.                      WinQuerySysPointer (HWND_DESKTOP,
  2385.                              SPTR_WAIT,
  2386.                              FALSE) );
  2387.               lDeltaRows = atol(szBuffer) - 1L;
  2388.               lNewViewPtr = MoveViewPtr (0L, &lDeltaRows, TRUE);
  2389.               lRowNumber = lDeltaRows + 1L;
  2390.               lRowPointer = lNewViewPtr;
  2391.               WinSetPointer (HWND_DESKTOP,
  2392.                      WinQuerySysPointer (HWND_DESKTOP,
  2393.                              SPTR_ARROW,
  2394.                              FALSE) );
  2395.               }
  2396.             else
  2397.               lNewViewPtr = atol (szBuffer);
  2398.             }
  2399.           WinDismissDlg (hwnd, TRUE);
  2400.           return 0;
  2401.            }
  2402.         case DID_CANCEL:
  2403.            WinDismissDlg (hwnd, FALSE);
  2404.            return 0;
  2405.      }
  2406.    }
  2407.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2408. }
  2409. //=====================================================================
  2410. // Search Dialog Procedures
  2411. //=====================================================================
  2412. //------------------------------------------------------------------
  2413. //  Search Dialog Box
  2414. //------------------------------------------------------------------
  2415. MRESULT EXPENTRY SearchDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2416.    {
  2417.    switch (msg) {
  2418.  
  2419.       case WM_INITDLG:
  2420.  
  2421.      WinSetWindowUShort(hwnd, QWS_ID, IDW_SEARCH);
  2422.      if (hwndHelp != NULL)
  2423.        WinAssociateHelpInstance( hwndHelp, hwnd);
  2424.  
  2425.      CenterDlgBox (hwnd, hwndClient);
  2426.  
  2427.      if (fHexString)
  2428.        WinSetDlgItemText ( hwnd, IDD_SRCHSTR, szSearchHStr);
  2429.      else
  2430.        WinSetDlgItemText ( hwnd, IDD_SRCHSTR, szSearchStr);
  2431.  
  2432.      WinSendDlgItemMsg (hwnd, IDD_CHKCASE, BM_SETCHECK,
  2433.                 MPFROM2SHORT (fCheckCase, 0), NULL);
  2434.  
  2435.      WinSendDlgItemMsg (hwnd, IDD_TOPSEARCH, BM_SETCHECK,
  2436.                 MPFROM2SHORT (fTopSearch, 0), NULL);
  2437.  
  2438.      WinSendDlgItemMsg (hwnd, IDD_HEXSTRING, BM_SETCHECK,
  2439.                 MPFROM2SHORT (fHexString, 0), NULL);
  2440.      return 0;
  2441.  
  2442.       case WM_CONTROL:
  2443.  
  2444.      switch (SHORT1FROMMP (mp1)) {
  2445.  
  2446.         case IDD_CHKCASE:
  2447.            switch (SHORT2FROMMP (mp1)) {
  2448.  
  2449.           case BN_CLICKED:
  2450.              if (fCheckCase)
  2451.             fCheckCase = FALSE;
  2452.              else
  2453.             fCheckCase = TRUE;
  2454.              return 0;
  2455.            }
  2456.            break;
  2457.  
  2458.         case IDD_TOPSEARCH:
  2459.            switch (SHORT2FROMMP (mp1)) {
  2460.  
  2461.           case BN_CLICKED:
  2462.              if (fTopSearch)
  2463.             fTopSearch = FALSE;
  2464.              else
  2465.             fTopSearch = TRUE;
  2466.              return 0;
  2467.            }
  2468.            break;
  2469.  
  2470.         case IDD_HEXSTRING:
  2471.            switch (SHORT2FROMMP (mp1)) {
  2472.  
  2473.           case BN_CLICKED:
  2474.              if (fHexString)
  2475.             fHexString = FALSE;
  2476.              else
  2477.             fHexString = TRUE;
  2478.              return 0;
  2479.            }
  2480.            break;
  2481.      }
  2482.      break;
  2483.  
  2484.       case WM_COMMAND:
  2485.  
  2486.      switch (COMMANDMSG(&msg)->cmd) {
  2487.  
  2488.         case DID_OK:
  2489.            if (fHexString) {
  2490.          WinQueryDlgItemText (hwnd, IDD_SRCHSTR, sizeof szSearchHStr,
  2491.               szSearchHStr);
  2492.          cbSearchStrLen = atob(szSearchHStr, sSearchStr);
  2493.          if (cbSearchStrLen) {
  2494.             WinDismissDlg (hwnd, TRUE);
  2495.             return 0;
  2496.             }
  2497.          }
  2498.            else {
  2499.          WinQueryDlgItemText (hwnd, IDD_SRCHSTR, sizeof szSearchStr,
  2500.               szSearchStr);
  2501.          if (strlen (szSearchStr)) {
  2502.             WinDismissDlg (hwnd, TRUE);
  2503.             return 0;
  2504.             }
  2505.          }
  2506.  
  2507.         case DID_CANCEL:
  2508.            WinDismissDlg (hwnd, FALSE);
  2509.            return 0;
  2510.      }
  2511.    }
  2512.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2513. }
  2514. //===================================================================
  2515. // Procedures for File open dialog box
  2516. //===================================================================
  2517. //------------------------------------------------------------------
  2518. //  Center Dialog Box Procedure
  2519. //------------------------------------------------------------------
  2520. VOID CenterDlgBox (HWND hwndDialog, HWND hwndParent)
  2521.   {
  2522.   static SWP   swpParent;
  2523.   static SWP   swpDialog;
  2524.  
  2525.   WinQueryWindowPos (hwndParent, &swpParent);
  2526.   WinQueryWindowPos (hwndDialog, &swpDialog);
  2527.   if (swpParent.cx > swpDialog.cx)
  2528.     swpDialog.x = swpDialog.x + ((swpParent.cx - swpDialog.cx)/2);
  2529.   if (swpParent.cy > swpDialog.cy)
  2530.     swpDialog.y = swpDialog.y + ((swpParent.cy - swpDialog.cy)/2);
  2531.   WinSetWindowPos (hwndDialog,
  2532.            swpDialog.hwndInsertBehind,
  2533.            swpDialog.x,
  2534.            swpDialog.y,
  2535.            swpDialog.cx,
  2536.            swpDialog.cy,
  2537.            swpDialog.fs);
  2538.   return;
  2539.   }
  2540. //------------------------------------------------------------------
  2541. //  Fill Drive List Box Procedure
  2542. //------------------------------------------------------------------
  2543. VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath) {
  2544.    static CHAR szDrive [] = "  :";
  2545.    SHORT  sDrive;
  2546.    ULONG  ulDriveMap;
  2547.    USHORT usDriveNum;
  2548.  
  2549.    DosQCurDisk (&usDriveNum, &ulDriveMap);
  2550.  
  2551.    pcCurrentPath[0] = (CHAR) usDriveNum + (CHAR) '@';
  2552.    pcCurrentPath[1] = ':';
  2553.    pcCurrentPath[2] = '\\';
  2554.  
  2555.    WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_DELETEALL, NULL, NULL);
  2556.  
  2557.    for (sDrive = 0; sDrive < 26 ; sDrive++ )
  2558.       if (ulDriveMap & 1L << sDrive) {
  2559.      szDrive [1] = (CHAR) sDrive + (CHAR) 'A';
  2560.  
  2561.      WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_INSERTITEM,
  2562.                   MPFROM2SHORT (LIT_END, 0),
  2563.                   MPFROMP (szDrive));
  2564.       }
  2565.       WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_SELECTITEM,
  2566.                MPFROM2SHORT (usDriveNum - 1, 0),
  2567.                MPFROM2SHORT (TRUE, 0));
  2568. }
  2569. //------------------------------------------------------------------
  2570. //  Fill Directory List Box Procedure
  2571. //------------------------------------------------------------------
  2572. VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden) {
  2573.    static      CHAR  szRootStr[] = "\\";
  2574.    FILEFINDBUF findbuf;
  2575.    HDIR        hDir = 1;
  2576.    USHORT      usCurPathLen = PATHLENGTH, usSearchCount = 1;
  2577.    USHORT      usAttr;
  2578.  
  2579.    if (fIncHidden)
  2580.       usAttr = 0x0017;
  2581.    else
  2582.       usAttr = 0x0015;
  2583.  
  2584.    WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_DELETEALL, NULL, NULL);
  2585.  
  2586.    DosQCurDir (0, pcCurPath + 3 , &usCurPathLen);
  2587.  
  2588.    DosFindFirst ("*.*", &hDir, usAttr, &findbuf, sizeof findbuf,
  2589.          &usSearchCount, 0L);
  2590.  
  2591.    while (usSearchCount) {
  2592.       if (findbuf.attrFile & 0x0010
  2593.       && (findbuf.achName [0] != '.' || findbuf.achName [1] ))
  2594.  
  2595.      if (pcCurPath [strlen(pcCurPath)-1] != '\\'
  2596.          || findbuf.achName[1] != '.' || findbuf.achName [2])
  2597.  
  2598.         WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
  2599.                  MPFROM2SHORT (LIT_SORTASCENDING, 0),
  2600.                  MPFROMP (findbuf.achName));
  2601.  
  2602.       DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
  2603.    }
  2604.    if (pcCurPath [strlen(pcCurPath)-1] != '\\')
  2605.       WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
  2606.               MPFROM2SHORT (0, 0), MPFROMP (szRootStr));
  2607. }
  2608. //------------------------------------------------------------------
  2609. //  Fill File List Box Procedure
  2610. //------------------------------------------------------------------
  2611. VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden) {
  2612.    FILEFINDBUF findbuf;
  2613.    HDIR        hDir = 1;
  2614.    USHORT      usSearchCount = 1;
  2615.    USHORT      usAttr;
  2616.  
  2617.    if (fIncHidden)
  2618.       usAttr = 0x0007;
  2619.    else
  2620.       usAttr = 0x0005;
  2621.  
  2622.    WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_DELETEALL, NULL, NULL);
  2623.  
  2624.    DosFindFirst (pcSearchParam, &hDir, usAttr, &findbuf, sizeof findbuf,
  2625.          &usSearchCount, 0L);
  2626.  
  2627.    while (usSearchCount) {
  2628.       WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_INSERTITEM,
  2629.                MPFROM2SHORT (LIT_SORTASCENDING, 0),
  2630.                MPFROMP (findbuf.achName));
  2631.       DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
  2632.    }
  2633. }
  2634. //------------------------------------------------------------------
  2635. //  File Open Dialog Box Procedure
  2636. //------------------------------------------------------------------
  2637. MRESULT EXPENTRY FileDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2638.    {
  2639.    static      CHAR  szCurrentPath [PATHLENGTH], szFileName[PATHLENGTH] = "*.*";
  2640.    static      CHAR  szFileNameFilter[PATHLENGTH] = "*.*";
  2641.    static      BOOL  fIncHidden;
  2642.    CHAR        *pFileName;
  2643.    CHAR        szBuffer [PATHLENGTH];
  2644.    CHAR        szFilterText [PATHLENGTH+12];
  2645.    CHAR        szLastFileName [PATHLENGTH];
  2646.    USHORT      sLastFileIndex;
  2647.    USHORT      usCurPathLen = PATHLENGTH - 3;
  2648.    SHORT       sSelect;
  2649.    FILEFINDBUF findbuf;
  2650.    HDIR        hDir = 1;
  2651.    USHORT      usSearchCount = 1, usAttr;
  2652.    SHORT       i;
  2653.  
  2654.    switch (msg) {
  2655.  
  2656.       case WM_INITDLG:
  2657.  
  2658.      WinSetWindowUShort(hwnd, QWS_ID, IDW_OPEN);
  2659.      if (hwndHelp != NULL)
  2660.        WinAssociateHelpInstance( hwndHelp, hwnd);
  2661.  
  2662.      fIncHidden = Default.fIncHiddenFiles;
  2663.  
  2664.      CenterDlgBox (hwnd, hwndClient);
  2665.  
  2666.      if (strlen(szWildCardFilename) != 0)
  2667.        {
  2668.        if (DosQPathInfo (szWildCardFilename, 5, szBuffer,
  2669.                  sizeof szBuffer, 0L))
  2670.           WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
  2671.                    "Unrecognized path", 1,
  2672.                    MB_OK | MB_CRITICAL);
  2673.        for (i = strlen(szBuffer); i >= 0; i--)
  2674.           if (szBuffer[i] == '\\')
  2675.          break;
  2676.        strcpy (szFileNameFilter, szBuffer + i + 1);
  2677.        strcpy (szFilterText, "File Filter: ");
  2678.        strcat (szFilterText, szFileNameFilter);
  2679.        DosSelectDisk ((USHORT) (*szBuffer - 'A' + 1));
  2680.        if (strchr (szBuffer, '\\') != strrchr (szBuffer, '\\'))
  2681.          *(strrchr (szBuffer, '\\')) = '\0';
  2682.        else
  2683.          *(szBuffer+3) = '\0';
  2684.        DosChDir (szBuffer+2, 0L);
  2685.        *szWildCardFilename = '\0';
  2686.        }
  2687.      else
  2688.        {
  2689.        strcpy (szFileName, "*.*");
  2690.        strcpy (szFilterText, "File Filter: ");
  2691.        strcat (szFilterText, szFileNameFilter);
  2692.        }
  2693.      WinSetDlgItemText (hwnd, IDD_FILEFILTER, szFilterText);
  2694.      FillDriveListBox (hwnd, szCurrentPath);
  2695.      FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  2696.      FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
  2697.  
  2698.      WinSendDlgItemMsg (hwnd, IDD_INCHIDDEN, BM_SETCHECK,
  2699.                 MPFROM2SHORT (fIncHidden, 0), NULL);
  2700.  
  2701.      DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
  2702.  
  2703.      WinSendDlgItemMsg ( hwnd, IDD_FILEEDIT, EM_SETTEXTLIMIT,
  2704.                  MPFROM2SHORT (PATHLENGTH, 0), NULL);
  2705.  
  2706.      WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  2707.  
  2708.  
  2709.      pFileName = strrchr(File.szName, '\\');
  2710.      if (pFileName != NULL) {
  2711.         strcpy (szLastFileName, (pFileName + 1));
  2712.         for (i = 0; i < (SHORT) strlen(szLastFileName); i++)
  2713.            szLastFileName[i] = (CHAR) toupper(szLastFileName[i]);
  2714.         sLastFileIndex = SHORT1FROMMR (
  2715.            WinSendDlgItemMsg ( hwnd, IDD_FILELIST, LM_SEARCHSTRING,
  2716.                     MPFROM2SHORT (LSS_CASESENSITIVE, LIT_FIRST),
  2717.                     MPFROMP (szLastFileName) )
  2718.                     );
  2719.         if ( (sLastFileIndex != LIT_ERROR) && (sLastFileIndex != LIT_NONE) )
  2720.            WinSendDlgItemMsg ( hwnd, IDD_FILELIST, LM_SETTOPINDEX,
  2721.                    MPFROMSHORT (sLastFileIndex),
  2722.                    NULL);
  2723.      }
  2724.  
  2725.  
  2726.      return 0;
  2727.  
  2728.       case WM_CONTROL:
  2729.  
  2730.      if (SHORT1FROMMP (mp1) == IDD_DRIVELIST ||
  2731.          SHORT1FROMMP (mp1) == IDD_DIRLIST     ||
  2732.          SHORT1FROMMP (mp1) == IDD_FILELIST) {
  2733.  
  2734.         sSelect = (USHORT) SHORT1FROMMR (
  2735.               WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
  2736.                          LM_QUERYSELECTION, 0L, 0L) );
  2737.  
  2738.         WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
  2739.                   LM_QUERYITEMTEXT,
  2740.                   MPFROM2SHORT (sSelect, sizeof szBuffer),
  2741.                   MPFROMP (szBuffer));
  2742.      }
  2743.  
  2744.      switch (SHORT1FROMMP (mp1)) {
  2745.  
  2746.         case IDD_DRIVELIST:
  2747.            switch (SHORT2FROMMP (mp1)) {
  2748.  
  2749.           case LN_ENTER:
  2750.              szCurrentPath[0] = szBuffer[1];
  2751.              DosSelectDisk (szBuffer [1] - '@');
  2752.  
  2753.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  2754.              if (strcmp(szFileName, "*.*") != 0) {
  2755.             if (szCurrentPath [strlen (szCurrentPath)-1]
  2756.                                 != '\\')
  2757.                strcat (szCurrentPath, "\\");
  2758.             strcat (szCurrentPath, szFileName);
  2759.              }
  2760.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  2761.              FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
  2762.  
  2763.              return 0;
  2764.            }
  2765.            break;
  2766.  
  2767.         case IDD_DIRLIST:
  2768.            switch (SHORT2FROMMP (mp1)) {
  2769.  
  2770.           case LN_ENTER:
  2771.  
  2772.              DosChDir (szBuffer, 0L);
  2773.  
  2774.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  2775.              if (strcmp(szFileName, "*.*") != 0) {
  2776.             if (szCurrentPath [strlen (szCurrentPath)-1]
  2777.                                 != '\\')
  2778.                strcat (szCurrentPath, "\\");
  2779.             strcat (szCurrentPath, szFileName);
  2780.              }
  2781.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  2782.              FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
  2783.              return 0;
  2784.            }
  2785.            break;
  2786.  
  2787.         case IDD_FILELIST:
  2788.            switch (SHORT2FROMMP (mp1)) {
  2789.  
  2790.           case LN_SELECT:
  2791.  
  2792.              DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
  2793.              if (szCurrentPath [strlen(szCurrentPath)-1] != '\\')
  2794.             strcat (szCurrentPath, "\\");
  2795.              strcat (szCurrentPath, szBuffer);
  2796.  
  2797.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  2798.              return 0;
  2799.  
  2800.           case LN_ENTER:
  2801.  
  2802.              WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
  2803.                       sizeof szCurrentPath,
  2804.                       szCurrentPath);
  2805.              if (DosQPathInfo (szCurrentPath, 5, szBuffer,
  2806.                    sizeof szBuffer, 0L)) {
  2807.             WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
  2808.                          "Unrecognised path", 1,
  2809.                          MB_OK | MB_ERROR);
  2810.             return 0;
  2811.              } else {
  2812.             strcpy (szNewFile, szBuffer);
  2813.             Default.fIncHiddenFiles = fIncHidden;
  2814.             WinDismissDlg (hwnd, TRUE);
  2815.             return 0;
  2816.              }
  2817.            }
  2818.            break;
  2819.  
  2820.         case IDD_INCHIDDEN:
  2821.            switch (SHORT2FROMMP (mp1)) {
  2822.  
  2823.           case BN_CLICKED:
  2824.              if (fIncHidden)
  2825.             fIncHidden = FALSE;
  2826.              else
  2827.             fIncHidden = TRUE;
  2828.              FillFileListBox (hwnd, szFileName, fIncHidden);
  2829.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  2830.              return 0;
  2831.            }
  2832.            break;
  2833.      }
  2834.      break;
  2835.  
  2836.       case WM_COMMAND:
  2837.  
  2838.      switch (COMMANDMSG(&msg)->cmd) {
  2839.  
  2840.         case DID_OK:
  2841.            if (WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
  2842.                     sizeof szCurrentPath,
  2843.                     szCurrentPath) == 0)
  2844.          {
  2845.          strcpy (szCurrentPath, " ");
  2846.          }
  2847.            strcpy (szBuffer, szCurrentPath);
  2848.            if (DosQPathInfo (szCurrentPath, 5, szBuffer,
  2849.                  sizeof szBuffer, 0L)) {
  2850.           WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
  2851.                        "Unrecognized path", 1,
  2852.                        MB_OK | MB_ERROR);
  2853.           return 0;
  2854.            } else
  2855.           if (strchr (szBuffer, '*') == 0
  2856.               && strchr (szBuffer, '?') == 0) {
  2857.              if (fIncHidden)
  2858.             usAttr = 0x0007;
  2859.              else
  2860.             usAttr = 0x0005;
  2861.              usSearchCount = 1;
  2862.  
  2863.              DosFindFirst (szBuffer, &hDir, usAttr, &findbuf,
  2864.                    sizeof findbuf, &usSearchCount, 0L);
  2865.              if (usSearchCount    == 0) {
  2866.             WinMessageBox (HWND_DESKTOP, hwnd, szBuffer,
  2867.                        "File not Found", 1, MB_OK | MB_ERROR);
  2868.             return 0;
  2869.              } else {
  2870.             strcpy (szNewFile, szBuffer);
  2871.             Default.fIncHiddenFiles = fIncHidden;
  2872.             WinDismissDlg (hwnd, TRUE);
  2873.             return 0;
  2874.              }
  2875.           } else {
  2876.              for (i = strlen(szBuffer); i >= 0; i--)
  2877.             if (szBuffer[i] == '\\')
  2878.                break;
  2879.              strcpy (szFileNameFilter, szBuffer + i + 1);
  2880.              strcpy (szFilterText, "File Filter: ");
  2881.              strcat (szFilterText, szFileNameFilter);
  2882.              WinSetDlgItemText (hwnd, IDD_FILEFILTER, szFilterText);
  2883.              DosSelectDisk ((USHORT) (*szBuffer - 'A' + 1));
  2884.              if (strchr (szBuffer, '\\') != strrchr (szBuffer, '\\'))
  2885.                *(strrchr (szBuffer, '\\')) = '\0';
  2886.              else
  2887.                *(szBuffer+3) = '\0';
  2888.              DosChDir (szBuffer+2, 0L);
  2889.              FillDriveListBox (hwnd, szCurrentPath);
  2890.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  2891.              FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
  2892.              FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
  2893.              return 0;
  2894.           }
  2895.            break;
  2896.         case DID_CANCEL:
  2897.            WinDismissDlg (hwnd, FALSE);
  2898.            return 0;
  2899.      }
  2900.      break;
  2901.    }
  2902.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2903. }
  2904. //===================================================================
  2905. // Procedures for Configure dialog box
  2906. //===================================================================
  2907. VOID FillColorBox (HWND hwnd, SHORT iListID) {
  2908.  
  2909.    static CHAR szColors [16][12] = { "Black", "Dk. Blue", "Dk. Green",
  2910.       "Dk. Cyan", "Dk. Red", "Dk. Magenta", "Brown", "Gray", "Dk. Gray",
  2911.       "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White"};
  2912.  
  2913.    SHORT  i;
  2914.  
  2915.    WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
  2916.  
  2917.    for (i = 0; i < 16 ; i++ )
  2918.      WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
  2919.                   MPFROM2SHORT (LIT_END, 0),
  2920.                   MPFROMP (szColors[i]));
  2921.    return;
  2922. }
  2923. //------------------------------------------------------------------
  2924. //  Fill Character cell size box
  2925. //------------------------------------------------------------------
  2926. VOID FillCellSizeBox (HWND hwnd, SHORT iListID) {
  2927.  
  2928.    SHORT  i;
  2929.    CHAR   szBuffer[8];
  2930.  
  2931.    WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
  2932.  
  2933.    for (i=0; i<sCellSizeCount; i++)
  2934.      {
  2935.      sprintf (szBuffer, "%2d x %2d", sCellSize[i][0], sCellSize[i][1]);
  2936.      WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
  2937.              MPFROM2SHORT (LIT_END, 0),
  2938.              MPFROMP (szBuffer));
  2939.      }
  2940.    return;
  2941. }
  2942. //------------------------------------------------------------------
  2943. // GetFontSize - Determine font size.
  2944. //------------------------------------------------------------------
  2945. SHORT GetCellSize (SHORT sHeight, SHORT sWidth) {
  2946.  
  2947.    SHORT  i, sIndex = 0;
  2948.  
  2949.    sIndex = 0;
  2950.  
  2951.    for (i = 0; i < sCellSizeCount; i++ )
  2952.      {
  2953.      if (sHeight == sCellSize[i][1] && sWidth == sCellSize[i][0])
  2954.        {
  2955.        sIndex = i;
  2956.        break;
  2957.        }
  2958.      }
  2959.    return sIndex;
  2960. }
  2961. //------------------------------------------------------------------
  2962. //  Configure Dialog Box
  2963. //------------------------------------------------------------------
  2964. MRESULT EXPENTRY ConfigDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  2965.    {
  2966.    static   SHORT    sSelect;
  2967.    static   UCHAR    szAttribute[2];
  2968.    static   SHORT    sCHeight;
  2969.    static   SHORT    sCWidth;
  2970.    static   SHORT    sTabStop;
  2971.    static   BOOL     fDispASCII;
  2972.    static   BOOL     fScrollBars;
  2973.    static   BOOL     fDispEBCDIC;
  2974.    static   BOOL     fDispFilePos;
  2975.    static   BOOL     fLocalSaveWinPos;
  2976.  
  2977.    switch (msg) {
  2978.  
  2979.       case WM_INITDLG:
  2980.  
  2981.      WinSetWindowUShort(hwnd, QWS_ID, IDW_CONFIGURE);
  2982.      if (hwndHelp != NULL)
  2983.        WinAssociateHelpInstance( hwndHelp, hwnd);
  2984.  
  2985.      CenterDlgBox (hwnd, hwndClient);
  2986.  
  2987.      szAttribute[1] = Default.szAttribute[1];
  2988.      sCHeight = Default.sCellHeight;
  2989.      sCWidth = Default.sCellWidth;
  2990.      sTabStop = Default.sTabStop;
  2991.      fDispASCII = Default.fDispASCII;
  2992.      fScrollBars = Default.fScrollBars;
  2993.      fDispEBCDIC = Default.fDispEBCDIC;
  2994.      fDispFilePos = Default.fDispFilePos;
  2995.      fLocalSaveWinPos = FALSE;
  2996.  
  2997.      FillColorBox (hwnd, IDD_FCOLOR);
  2998.      FillColorBox (hwnd, IDD_BCOLOR);
  2999.      FillCellSizeBox (hwnd, IDD_CELLSIZE);
  3000.  
  3001.      WinSendDlgItemMsg (hwnd, IDD_BCOLOR, LM_SELECTITEM,
  3002.            MPFROM2SHORT (((szAttribute[1]>>4) & 0x0f), 0),
  3003.            MPFROM2SHORT (TRUE,0));
  3004.  
  3005.      WinSendDlgItemMsg (hwnd, IDD_FCOLOR, LM_SELECTITEM,
  3006.            MPFROM2SHORT ((szAttribute[1] & 0x0f), 0),
  3007.            MPFROM2SHORT (TRUE,0));
  3008.  
  3009.      WinSendDlgItemMsg (hwnd, IDD_CELLSIZE, LM_SELECTITEM,
  3010.            MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
  3011.            MPFROM2SHORT (TRUE,0));
  3012.  
  3013.      WinSendDlgItemMsg (hwnd, IDD_DEFASCII, BM_SETCHECK,
  3014.                 MPFROM2SHORT (fDispASCII, 0), NULL);
  3015.  
  3016.      WinSendDlgItemMsg (hwnd, IDD_DEFHEXASC, BM_SETCHECK,
  3017.                 MPFROM2SHORT (!fDispASCII, 0), NULL);
  3018.  
  3019.      WinSendDlgItemMsg (hwnd, IDD_DEFHEXEBC, BM_SETCHECK,
  3020.                 MPFROM2SHORT (fDispEBCDIC, 0), NULL);
  3021.  
  3022.      WinSendDlgItemMsg (hwnd, IDD_DEFSCROLL, BM_SETCHECK,
  3023.                 MPFROM2SHORT (fScrollBars, 0), NULL);
  3024.  
  3025.      WinSendDlgItemMsg (hwnd, IDD_DEFFILEPOS, BM_SETCHECK,
  3026.                 MPFROM2SHORT (fDispFilePos, 0), NULL);
  3027.  
  3028.      WinSendDlgItemMsg (hwnd, IDD_SAVEWINPOS, BM_SETCHECK,
  3029.                 MPFROM2SHORT (fLocalSaveWinPos, 0), NULL);
  3030.  
  3031.      WinSendDlgItemMsg (hwnd, IDD_SAVE, BM_SETCHECK,
  3032.                 MPFROM2SHORT (fSaveToDisk, 0), NULL);
  3033.  
  3034.      WinSetDlgItemShort ( hwnd, IDD_DEFTABS, sTabStop, FALSE);
  3035.  
  3036.      return 0;
  3037.  
  3038.       case WM_CONTROL:
  3039.  
  3040.      if (SHORT1FROMMP (mp1) == IDD_BCOLOR     ||
  3041.          SHORT1FROMMP (mp1) == IDD_FCOLOR     ||
  3042.          SHORT1FROMMP (mp1) == IDD_CELLSIZE) {
  3043.         sSelect = (USHORT) SHORT1FROMMR (
  3044.                    WinSendDlgItemMsg (hwnd,
  3045.                           SHORT1FROMMP (mp1),
  3046.                           LM_QUERYSELECTION, 0L,
  3047.                           0L) );
  3048.      }
  3049.      switch (SHORT1FROMMP (mp1)) {
  3050.  
  3051.         case IDD_BCOLOR:
  3052.            switch (SHORT2FROMMP (mp1)) {
  3053.  
  3054.           case LN_SELECT:
  3055.  
  3056.              szAttribute[1] = (szAttribute[1] & (UCHAR) 0x0f)
  3057.                       | (UCHAR) ((sSelect << 4) & 0xf0);
  3058.              return 0;
  3059.            }
  3060.            break;
  3061.  
  3062.         case IDD_FCOLOR:
  3063.            switch (SHORT2FROMMP (mp1)) {
  3064.  
  3065.           case LN_SELECT:
  3066.  
  3067.              szAttribute[1] = (szAttribute[1] & (UCHAR) 0xf0)
  3068.                       | (UCHAR) (sSelect & 0x0f);
  3069.              return 0;
  3070.            }
  3071.            break;
  3072.  
  3073.         case IDD_CELLSIZE:
  3074.            switch (SHORT2FROMMP (mp1)) {
  3075.  
  3076.           case LN_SELECT:
  3077.  
  3078.              sCHeight = sCellSize [sSelect][1];
  3079.              sCWidth = sCellSize [sSelect][0];
  3080.              return 0;
  3081.            }
  3082.            break;
  3083.  
  3084.         case IDD_DEFASCII:
  3085.            switch (SHORT2FROMMP (mp1)) {
  3086.  
  3087.           case BN_CLICKED:
  3088.              fDispASCII = TRUE;
  3089.              fDispEBCDIC = FALSE;
  3090.              return 0;
  3091.            }
  3092.            break;
  3093.  
  3094.         case IDD_DEFHEXASC:
  3095.            switch (SHORT2FROMMP (mp1)) {
  3096.  
  3097.           case BN_CLICKED:
  3098.              fDispASCII = FALSE;
  3099.              fDispEBCDIC = FALSE;
  3100.              return 0;
  3101.            }
  3102.            break;
  3103.  
  3104.         case IDD_DEFHEXEBC:
  3105.            switch (SHORT2FROMMP (mp1)) {
  3106.  
  3107.           case BN_CLICKED:
  3108.              fDispASCII = FALSE;
  3109.              fDispEBCDIC = TRUE;
  3110.              return 0;
  3111.            }
  3112.            break;
  3113.  
  3114.         case IDD_DEFFILEPOS:
  3115.            switch (SHORT2FROMMP (mp1)) {
  3116.  
  3117.           case BN_CLICKED:
  3118.              if (fDispFilePos)
  3119.             fDispFilePos = FALSE;
  3120.              else
  3121.             fDispFilePos = TRUE;
  3122.              return 0;
  3123.            }
  3124.            break;
  3125.  
  3126.         case IDD_DEFSCROLL:
  3127.            switch (SHORT2FROMMP (mp1)) {
  3128.  
  3129.           case BN_CLICKED:
  3130.              if (fScrollBars)
  3131.             fScrollBars = FALSE;
  3132.              else
  3133.             fScrollBars = TRUE;
  3134.              return 0;
  3135.            }
  3136.            break;
  3137.  
  3138.         case IDD_SAVEWINPOS:
  3139.            switch (SHORT2FROMMP (mp1)) {
  3140.  
  3141.           case BN_CLICKED:
  3142.              if (fLocalSaveWinPos)
  3143.             fLocalSaveWinPos = FALSE;
  3144.              else
  3145.             fLocalSaveWinPos = TRUE;
  3146.              return 0;
  3147.            }
  3148.            break;
  3149.  
  3150.         case IDD_SAVE:
  3151.            switch (SHORT2FROMMP (mp1)) {
  3152.  
  3153.           case BN_CLICKED:
  3154.              if (fSaveToDisk)
  3155.             fSaveToDisk = FALSE;
  3156.              else
  3157.             fSaveToDisk = TRUE;
  3158.              return 0;
  3159.            }
  3160.            break;
  3161.      }
  3162.      break;
  3163.  
  3164.       case WM_COMMAND:
  3165.  
  3166.      switch (COMMANDMSG(&msg)->cmd) {
  3167.  
  3168.           case DID_OK:
  3169.              Default.szAttribute[1] = szAttribute[1];
  3170.              Default.sCellHeight = sCHeight;
  3171.              Default.sCellWidth = sCWidth;
  3172.              Default.fDispASCII = fDispASCII;
  3173.              Default.fScrollBars = fScrollBars;
  3174.              Default.fDispEBCDIC = fDispEBCDIC;
  3175.              Default.fDispFilePos = fDispFilePos;
  3176.              WinQueryDlgItemShort (hwnd, IDD_DEFTABS, &sSelect,
  3177.                        FALSE);
  3178.              sSelect = min (max (1, sSelect), AVIOCOLS - 1);
  3179.              Default.sTabStop = sSelect;
  3180.              fSaveWinPos = fLocalSaveWinPos;
  3181.              WinDismissDlg (hwnd, TRUE);
  3182.              return (MRESULT) 1;
  3183.  
  3184.           case DID_CANCEL:
  3185.               WinDismissDlg (hwnd, FALSE);
  3186.               return 0;
  3187.      }
  3188.    }
  3189.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  3190. }
  3191. //------------------------------------------------------------------
  3192. //  Font Size Dialog Box
  3193. //------------------------------------------------------------------
  3194. MRESULT EXPENTRY FontDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  3195.    {
  3196.    static   SHORT    sSelect;
  3197.    static   SHORT    sCHeight;
  3198.    static   SHORT    sCWidth;
  3199.  
  3200.    switch (msg) {
  3201.  
  3202.       case WM_INITDLG:
  3203.  
  3204.      WinSetWindowUShort(hwnd, QWS_ID, IDW_PICKFONT);
  3205.      if (hwndHelp != NULL)
  3206.        WinAssociateHelpInstance( hwndHelp, hwnd);
  3207.  
  3208.      CenterDlgBox (hwnd, hwndClient);
  3209.  
  3210.      sCHeight = Default.sCellHeight;
  3211.      sCWidth = Default.sCellWidth;
  3212.  
  3213.      FillCellSizeBox (hwnd, IDD_FONTS);
  3214.  
  3215.      WinSendDlgItemMsg (hwnd, IDD_FONTS, LM_SELECTITEM,
  3216.            MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
  3217.            MPFROM2SHORT (TRUE,0));
  3218.      return 0;
  3219.  
  3220.       case WM_CONTROL:
  3221.  
  3222.      switch (SHORT1FROMMP (mp1)) {
  3223.  
  3224.         case IDD_FONTS:
  3225.            switch (SHORT2FROMMP (mp1)) {
  3226.  
  3227.           case LN_SELECT:
  3228.              sSelect = (USHORT) SHORT1FROMMR (
  3229.                     WinSendDlgItemMsg (hwnd,
  3230.                                IDD_FONTS,
  3231.                                LM_QUERYSELECTION,
  3232.                                0L, 0L) );
  3233.  
  3234.              sCHeight = sCellSize [sSelect][1];
  3235.              sCWidth = sCellSize [sSelect][0];
  3236.              return 0;
  3237.  
  3238.           case LN_ENTER:
  3239.              Default.sCellHeight = sCHeight;
  3240.              Default.sCellWidth = sCWidth;
  3241.              WinDismissDlg (hwnd, TRUE);
  3242.              return 0;
  3243.  
  3244.            }
  3245.            break;
  3246.      }
  3247.      break;
  3248.  
  3249.       case WM_COMMAND:
  3250.  
  3251.      switch (COMMANDMSG(&msg)->cmd) {
  3252.  
  3253.           case DID_OK:
  3254.              Default.sCellHeight = sCHeight;
  3255.              Default.sCellWidth = sCWidth;
  3256.              WinDismissDlg (hwnd, TRUE);
  3257.              return 0;
  3258.  
  3259.           case DID_CANCEL:
  3260.              WinDismissDlg (hwnd, FALSE);
  3261.              return 0;
  3262.      }
  3263.    }
  3264.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  3265. }
  3266.