home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n13.zip / PMVIEW.C < prev    next >
Text File  |  1990-06-07  |  61KB  |  2,059 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. //=======================================================================
  12.  
  13. #define  INCL_WIN
  14. #define  INCL_VIO
  15. #define  INCL_AVIO
  16.  
  17. #define  AVIOROWS 98
  18. #define  AVIOCOLS 255
  19. #define  PATHLENGTH 255
  20. #define  BUFFERSIZE 16384
  21.  
  22. #include <os2.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26.  
  27. #include "pmview.h"
  28.  
  29. MRESULT  EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM);
  30. MRESULT  EXPENTRY AboutDlgProc (HWND, USHORT, MPARAM, MPARAM);
  31. MRESULT  EXPENTRY FileDlgProc (HWND, USHORT, MPARAM, MPARAM);
  32. MRESULT  EXPENTRY ConfigDlgProc (HWND, USHORT, MPARAM, MPARAM);
  33. MRESULT  EXPENTRY GotoDlgProc (HWND, USHORT, MPARAM, MPARAM);
  34. MRESULT  EXPENTRY SearchDlgProc (HWND, USHORT, MPARAM, MPARAM);
  35. MRESULT  EXPENTRY FontDlgProc (HWND, USHORT, MPARAM, MPARAM);
  36.  
  37. BOOL OpenFile (PCHAR);
  38. PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
  39.               BOOL *fEndOfFile);
  40. LONG MoveViewPtr (LONG lFilePtr, SHORT *ptrRow, BOOL fDispASCII);
  41. SHORT ComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII);
  42. VOID btoa (CHAR cNum, CHAR szOut[], BOOL fBlank);
  43. VOID Myltoa (LONG lNum, CHAR szOut[]);
  44. SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII);
  45. BOOL SearchFile (LONG *lFilePtr);
  46. VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
  47.         HWND hwndMenu);
  48. VOID SetASCII (HWND hwndMenu, LONG *lViewPtr);
  49. VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
  50.           SHORT *psCharHeight);
  51. VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath);
  52. VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden);
  53. VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden);
  54. VOID FillColorBox (HWND hwnd, SHORT iListID);
  55. VOID FillCellSizeBox (HWND hwnd, SHORT iListID);
  56. SHORT GetCellSize (SHORT sHeight, SHORT sWidth);
  57.  
  58. struct VideoStruct {
  59.    USHORT   uslength;
  60.    USHORT   usAdapterType;
  61.    USHORT   usDisplayType;
  62. } VideoData = { 6, 0, 0};
  63.  
  64. struct ParamStruct {
  65.    CHAR     szAttribute[2];
  66.    SHORT    sxWinPos;
  67.    SHORT    syWinPos;
  68.    SHORT    sWinHeight;
  69.    SHORT    sWinWidth;
  70.    SHORT    sCellHeight;
  71.    SHORT    sCellWidth;
  72.    SHORT    sTabStop;
  73.    BOOL     fDispASCII;
  74.    BOOL     fScrollBars;
  75.    BOOL     fIncHiddenFiles;
  76. } Default = {{0x20,0xf0}, -1, 0, 0, 0, 17, 8, 8, TRUE, TRUE, FALSE};
  77.  
  78. struct FileStruct {
  79.    CHAR     szName [PATHLENGTH];
  80.    HFILE    hHandle;
  81.    LONG     lSize;
  82.    BOOL     fValid;
  83. } File = {"", 0, 0L, FALSE};
  84.  
  85. FILESTATUS FileInfo;
  86.  
  87. struct MemBuff {
  88.    USHORT   usBSel;
  89.    USHORT   usBOff;
  90.    USHORT   usDSize;
  91.    LONG     lFilePtr;
  92.    SHORT    sUseCnt;
  93.    BOOL     fValid;
  94. } Buff[4];
  95.  
  96. SHORT sCellSize [10][2] = {{8, 8}, {8, 12}, {8, 14}, {7, 15},
  97.       {7, 25}, {8, 17}, {12, 16}, {12, 20}, {12, 22}, {12, 30}};
  98.  
  99. HAB     hab;
  100.  
  101. CHAR     szNewFile[PATHLENGTH];
  102. LONG     lNewViewPtr;
  103.  
  104. CHAR     szSearchStr[80];
  105. BOOL     fCheckCase = FALSE;
  106. BOOL     fTopSearch = FALSE;
  107. LONG     lLastFound = -1;
  108.  
  109. BOOL     fSaveWinPos;
  110. BOOL     fSaveToDisk = FALSE;
  111. BOOL     fMinimized;
  112. CHAR     szAppName[] = "PMVIEW by Douglas Boling";
  113. CHAR     szKeyName[] = "Profile type 1";
  114.  
  115. //=======================================================================
  116. // Main Proceedure.  Create message queue, parse the command line,
  117. //    allocate memory buffers, create the window, and process the
  118. //    message queue.
  119. //=======================================================================
  120. int main (int argc, char *argv[])
  121.    {
  122.    static   CHAR  szClientClass [] = "PMVIEW";
  123.  
  124.    static   ULONG flFrameFlags = FCF_TITLEBAR       | FCF_SYSMENU  |
  125.                  FCF_SIZEBORDER    | FCF_MINMAX   |
  126.                  FCF_TASKLIST       | FCF_ICON      |
  127.                  FCF_MENU       | FCF_ACCELTABLE |
  128.                  FCF_VERTSCROLL    | FCF_HORZSCROLL |
  129.                  FCF_SHELLPOSITION;
  130.  
  131.    static   SHORT    fsWinPosFlags = SWP_SHOW;
  132.    static   USHORT   usSelector;
  133.    static   HWND     hwndFrame;
  134.    HMQ        hmq;
  135.    HWND     hwndClient;
  136.    QMSG     qmsg;
  137.    SHORT    i;
  138.  
  139.    hab = WinInitialize (0);
  140.    hmq = WinCreateMsgQueue (hab, 0);
  141.  
  142.    for (i = 1; i < argc && i < 4; i++)
  143.       if (strcmp(argv[i],"\\i") == 0 || strcmp (argv[i],"-i") == 0) {
  144.      fMinimized = TRUE;
  145.      fsWinPosFlags |= SWP_MINIMIZE;
  146.       } else
  147.      if (strlen (szNewFile) == 0)
  148.         DosQPathInfo (argv[i], 5, szNewFile, sizeof szNewFile, 0L);
  149.  
  150.    DosAllocSeg( (USHORT) 0, &usSelector, 0 );
  151.    for (i = 0; i < 4; i++) {
  152.       Buff[i].usBSel = usSelector;
  153.       Buff[i].usBOff = i * BUFFERSIZE;
  154.       Buff[i].fValid = FALSE;
  155.    }
  156.    i = sizeof Default;
  157.    WinQueryProfileData (hab, szAppName, szKeyName, &Default, &i);
  158.  
  159.    WinRegisterClass (
  160.            hab,            // Anchor block handle
  161.            szClientClass,        // Name of class being registered
  162.            ClientWndProc,        // Window procedure for class
  163.            CS_SIZEREDRAW,        // Class style
  164.            0);            // Extra bytes to reserve
  165.  
  166.    hwndFrame = WinCreateStdWindow (
  167.            HWND_DESKTOP,        // Parent window handle
  168.            NULL,            // Style of frame window
  169.            &flFrameFlags,        // Pointer to control data
  170.            szClientClass,        // Client window class name
  171.            NULL,            // Title bar text
  172.            0L,            // Style of client window
  173.            NULL,            // Module handle for resources
  174.            ID_RESOURCE,        // ID of resources for window
  175.            &hwndClient);        // Pointer to client window handle
  176.  
  177.    if (Default.sxWinPos != -1)
  178.       fsWinPosFlags |= SWP_MOVE | SWP_SIZE;
  179.  
  180.    WinSetWindowPos (hwndFrame, HWND_TOP, Default.sxWinPos, Default.syWinPos,
  181.              Default.sWinWidth, Default.sWinHeight, fsWinPosFlags);
  182.  
  183.    while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  184.       WinDispatchMsg (hab, &qmsg);
  185.  
  186.    if (File.hHandle)
  187.       DosClose (File.hHandle);
  188.    DosFreeSeg (usSelector);
  189.  
  190.    WinDestroyWindow (hwndFrame);
  191.  
  192.    WinDestroyMsgQueue (hmq);
  193.    WinTerminate (hab);
  194.    return 0;
  195. }
  196. //------------------------------------------------------------------
  197. // Open file.  Open the file, query file information, reset memory
  198. //     buffer structure.
  199. //------------------------------------------------------------------
  200. BOOL OpenFile (PCHAR szNewFileName) {
  201.  
  202.    SHORT       i;
  203.    HFILE       hNewHandle;
  204.    USHORT      usAction;
  205.    BOOL        fGoodRead = FALSE;
  206.  
  207.    if (DosOpen (
  208.     szNewFileName,               // File name
  209.     &hNewHandle,               // File handle
  210.     &usAction,               // Action taken
  211.     0L,                   // File size
  212.     0,                   // File attribute
  213.     1,                   // Open type (Fail if no file.)
  214.     0x20,                   // Open mode (Read, deny write)
  215.     0L))                   // Reserved.
  216.       WinAlarm (HWND_DESKTOP, WA_NOTE);
  217.    else {
  218.       if (File.hHandle)
  219.      DosClose (File.hHandle);
  220.       strcpy (File.szName, szNewFileName);
  221.       File.hHandle = hNewHandle;
  222.       DosQFileInfo (File.hHandle, 1, (PBYTE) &FileInfo,
  223.                  sizeof FileInfo);
  224.       File.lSize = FileInfo.cbFile;
  225.       fGoodRead = TRUE;
  226.       //
  227.       // Reset the memory buffer to purge the old file data.
  228.       //
  229.       for (i = 0; i < 4; i++) {
  230.      Buff[i].lFilePtr = -1;
  231.      Buff[i].sUseCnt = 1;
  232.       }
  233.    }
  234.    return fGoodRead;
  235. }
  236. //------------------------------------------------------------------
  237. // GetFileDataPtr - Return a pointer to file data pointed to by
  238. //            the file pointer.
  239. //------------------------------------------------------------------
  240. PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
  241.               BOOL *fEndOfFile) {
  242.    PCHAR    pcDataPtr;
  243.    ULONG    ulTemp;
  244.    SHORT    i, sLast = -1;
  245.    SHORT    sOldCnt, sNewCnt;
  246.    //
  247.    // Check limits of file.
  248.    //
  249.    *fEndOfFile = FALSE;
  250.    if (lFilePtr >= File.lSize) {
  251.       lFilePtr = File.lSize;
  252.       *fEndOfFile = fForward;
  253.    } else if (lFilePtr <= 0L) {
  254.       lFilePtr = 0L;
  255.       *fEndOfFile = !fForward;
  256.    }
  257.    //
  258.    // See if requested part of the file is in one of the buffers.
  259.    //
  260.    sOldCnt = sNewCnt = Buff[0].sUseCnt;
  261.    for (i = 0; i < 4; i++) {
  262.       sNewCnt = (sNewCnt < Buff[i].sUseCnt) ? Buff[i].sUseCnt : sNewCnt;
  263.       sOldCnt = (sOldCnt > Buff[i].sUseCnt) ? Buff[i].sUseCnt : sOldCnt;
  264.       if (Buff[i].lFilePtr != -1)
  265.      if (lFilePtr >= Buff[i].lFilePtr &&
  266.             lFilePtr < Buff[i].lFilePtr + BUFFERSIZE)
  267.         sLast = i;
  268.    }
  269.    //
  270.    // If requested part not found, determine the oldest buffer to replace,
  271.    //      then read part of the file into that buffer.
  272.    //
  273.    if (sLast == -1) {
  274.       sOldCnt = Buff[0].sUseCnt;
  275.       for (i = 0; i < 4; i++)
  276.      if (sOldCnt >= Buff[i].sUseCnt) {
  277.         sOldCnt = Buff[i].sUseCnt;
  278.         sLast = i;
  279.      }
  280.       Buff[sLast].fValid = TRUE;
  281.       Buff[sLast].lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE;
  282.  
  283.       DosChgFilePtr (File.hHandle, Buff[sLast].lFilePtr, 0, &ulTemp);
  284.  
  285.       DosRead (File.hHandle, MAKEP (Buff[sLast].usBSel,
  286.                Buff[sLast].usBOff), BUFFERSIZE,
  287.                &Buff[sLast].usDSize);
  288.    }
  289.    //
  290.    // Reset LRU count to prevent overflow
  291.    //
  292.    if (sNewCnt > 0x7ff0) {
  293.       sNewCnt -= sOldCnt;
  294.       for (i = 0; i < 4; i++)
  295.      Buff[i].sUseCnt = Buff[i].sUseCnt - sOldCnt;
  296.    }
  297.    Buff[sLast].sUseCnt = ++sNewCnt;
  298.    //
  299.    // Create Pointer, set limits to buffer.
  300.    //
  301.    pcDataPtr = MAKEP (Buff[sLast].usBSel, Buff[sLast].usBOff
  302.              + (USHORT) (lFilePtr - Buff[sLast].lFilePtr));
  303.    if (fForward)
  304.       *usLimit = Buff[sLast].usBOff + Buff[sLast].usDSize - 1;
  305.    else
  306.       *usLimit = Buff[sLast].usBOff;
  307.  
  308.    return pcDataPtr;
  309. }
  310. //------------------------------------------------------------------
  311. // MoveViewPtr - Update view pointer by scrolling the number of
  312. //     lines specified in ptrRow.  If limited by the top or bottom
  313. //     of the file, modify ptrRow to indicate the actual number of
  314. //    rows.
  315. //------------------------------------------------------------------
  316. LONG MoveViewPtr (LONG lFilePtr, SHORT *ptrRow, BOOL fDispASCII) {
  317.    SHORT    i, j, sRow, sRowCount = 0, sOffset = 0;
  318.    USHORT   usLimit;
  319.    PCHAR    pcDataPtr;
  320.    BOOL     fEndOfFile;
  321.  
  322.    pcDataPtr = GetFileDataPtr (lFilePtr, *ptrRow > 0, &usLimit, &fEndOfFile);
  323.    sRow = *ptrRow;
  324.  
  325.    if (fDispASCII)
  326.       if (sRow > 0) {
  327.      for (i=0; i < sRow && !fEndOfFile; i++, sOffset++){
  328.  
  329.         for (j=0; j < AVIOCOLS && *pcDataPtr != 0x0d
  330.               && !fEndOfFile; j++, sOffset++)
  331.            if ((OFFSETOF(pcDataPtr) < usLimit))
  332.           pcDataPtr++;
  333.            else {
  334.           lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  335.           pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
  336.                           &usLimit, &fEndOfFile);
  337.            }
  338.         if ((OFFSETOF(pcDataPtr) < usLimit))
  339.            pcDataPtr++;
  340.         else {
  341.            lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  342.            pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
  343.                        &usLimit, &fEndOfFile);
  344.         }
  345.         if (!fEndOfFile) sRowCount++;
  346.      }
  347.      *ptrRow = sRowCount;
  348.       } else {
  349.      sRow = -sRow;
  350.      for (i=0; i < sRow && !fEndOfFile; i++){
  351.  
  352.         if ((OFFSETOF(pcDataPtr) > usLimit))
  353.            pcDataPtr--;
  354.         else {
  355.            lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
  356.            pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
  357.                        &usLimit, &fEndOfFile);
  358.         }
  359.         if (!fEndOfFile) {
  360.            sRowCount--;
  361.            sOffset--;
  362.         }
  363.         for (j=0; j < AVIOCOLS && !fEndOfFile; j++) {
  364.            if ((OFFSETOF(pcDataPtr) > usLimit)) {
  365.           if (*(pcDataPtr-1) == 0x0d)
  366.              break;
  367.           pcDataPtr--;
  368.            } else {
  369.           lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
  370.           pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
  371.                           &usLimit, &fEndOfFile);
  372.            }
  373.            if (!fEndOfFile) sOffset--;
  374.         }
  375.      }
  376.      *ptrRow = sRowCount;
  377.       }
  378.    else {
  379.       //
  380.       // Align on paragraph
  381.       //
  382.       if (lFilePtr % 16 != 0)
  383.      sOffset -= (SHORT)(lFilePtr % 16);
  384.       sOffset += sRow * 16;
  385.       *ptrRow = sRow;
  386.       //
  387.       //Limit Checking
  388.       //
  389.       if ((lFilePtr == 0 && sRow < 0)
  390.       ||(lFilePtr == File.lSize && sRow > 0)){
  391.      sOffset = 0;
  392.      *ptrRow = 0;
  393.       } else if ((lFilePtr + sOffset) < 0) {
  394.     sOffset = (SHORT) -lFilePtr;
  395.     *ptrRow = sOffset / 16;
  396.       } else if ((lFilePtr + sOffset) > File.lSize) {
  397.     sOffset = (SHORT) (File.lSize - lFilePtr);
  398.     *ptrRow = sOffset / 16;
  399.       }
  400.    }
  401.    return (LONG) sOffset;
  402. }
  403. //------------------------------------------------------------------
  404. // ComputeLines - Compute number of lines between two points in
  405. //     the file.
  406. //------------------------------------------------------------------
  407. SHORT ComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII) {
  408.    USHORT   usLimit;
  409.    SHORT    sCount = 0;
  410.    PCHAR    pcDataPtr;
  411.    BOOL     fEndOfFile = FALSE;
  412.  
  413.    pcDataPtr = GetFileDataPtr (lOldPtr, lOldPtr < lNewPtr, &usLimit,
  414.                    &fEndOfFile);
  415.    if (fDispASCII)
  416.       if (lOldPtr < lNewPtr)
  417.      while (lOldPtr < lNewPtr && !fEndOfFile){
  418.         if (*pcDataPtr == 0x0d)
  419.            sCount++;
  420.         lOldPtr++;
  421.         if ((OFFSETOF(pcDataPtr) < usLimit))
  422.            pcDataPtr++;
  423.         else
  424.            pcDataPtr = GetFileDataPtr (lOldPtr, TRUE, &usLimit,
  425.                        &fEndOfFile);
  426.      }
  427.       else
  428.      while (lOldPtr > lNewPtr && !fEndOfFile) {
  429.         if (*pcDataPtr == 0x0d)
  430.            sCount--;
  431.         lOldPtr--;
  432.         if ((OFFSETOF(pcDataPtr) > usLimit))
  433.            pcDataPtr--;
  434.         else
  435.            pcDataPtr = GetFileDataPtr (lOldPtr, FALSE, &usLimit,
  436.                        &fEndOfFile);
  437.      }
  438.    else
  439.       sCount = (SHORT) ((lNewPtr - lOldPtr) / 16);
  440.    return sCount;
  441. }
  442. //------------------------------------------------------------------
  443. // btoa Convert byte to ASCII
  444. //------------------------------------------------------------------
  445. VOID btoa (CHAR cNum, CHAR szOut[], BOOL fBlank) {
  446.    SHORT    i;
  447.  
  448.    for (i = 2; i > 0; i--)
  449.       if (fBlank)
  450.      szOut[i] = ' ';
  451.       else {
  452.      szOut[i] = (cNum % 16) + 0x30;
  453.       if (szOut[i] > 0x39) szOut[i] += (BYTE) 7;
  454.      cNum /= 16;
  455.       }
  456.    szOut[0] = ' ';
  457.    return;
  458. }
  459. //------------------------------------------------------------------
  460. // Myltoa Convert a long to ASCII with leading zeros
  461. //------------------------------------------------------------------
  462. VOID Myltoa (LONG lNum, CHAR szOut[]) {
  463.    SHORT    i;
  464.  
  465.    for (i = 7; i >= 0; i--) {
  466.       szOut[i + (i+1)/5] = (BYTE) (lNum % 16) + 0x30;
  467.       if (szOut[i + (i+1)/5] > 0x39) szOut[i + (i+1)/5] += (BYTE) 7;
  468.       lNum /= 16;
  469.    }
  470.    szOut[4] = ' ';
  471.    return;
  472. }
  473. //------------------------------------------------------------------
  474. // Display Line
  475. //------------------------------------------------------------------
  476. SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII) {
  477.  
  478.    CHAR     cHexChar, szTempBuff [256];
  479.    SHORT    i, sStart, sBytesPrinted = 0;
  480.    USHORT   usLimit;
  481.    BOOL     fEndOfFile;
  482.    PCHAR    pcDataPtr;
  483.  
  484.    if (fDispASCII) {
  485.       //
  486.       // Print as ASCII until CR or for 255 characters.
  487.       //
  488.       pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
  489.  
  490.       for (i = 0; i <= AVIOCOLS && !fEndOfFile; i++){
  491.      if (*pcDataPtr == 0x0a) {
  492.         if ((OFFSETOF(pcDataPtr) < usLimit))
  493.            pcDataPtr++;
  494.         else {
  495.            lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  496.            pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  497.                        &fEndOfFile);
  498.         }
  499.         szTempBuff[i] = *pcDataPtr;
  500.         sBytesPrinted++;
  501.      } else
  502.         szTempBuff[i] = *pcDataPtr;
  503.  
  504.      if ((OFFSETOF(pcDataPtr) < usLimit))
  505.         pcDataPtr++;
  506.      else {
  507.         lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  508.         pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  509.                     &fEndOfFile);
  510.      }
  511.      sBytesPrinted++;
  512.      //
  513.      // Expand Tab Characters
  514.      //
  515.      if (szTempBuff[i] == 0x09) {
  516.         for (;i % Default.sTabStop != 0 && i <= AVIOCOLS; i++)
  517.            szTempBuff[i] = ' ';
  518.         szTempBuff[i] = ' ';
  519.      }
  520.      //
  521.      // If CR, end of line.
  522.      if (szTempBuff[i] == 0x0d) {
  523.         break;
  524.      }
  525.       }
  526.    } else {
  527.       //
  528.       // Convert from Hex and print.
  529.       //
  530.       pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
  531.       sStart = (SHORT) lLinePtr % 16;
  532.       sBytesPrinted = 0;
  533.       for (i = 0; i < 10; i++)
  534.      szTempBuff[i] = ' ';
  535.  
  536.       if (!fEndOfFile)
  537.      Myltoa (lLinePtr, szTempBuff);
  538.  
  539.       for (i = 0; i < 16; i++){
  540.  
  541.      cHexChar = *pcDataPtr;
  542.  
  543.      btoa (cHexChar, szTempBuff + 10 + (i*3) + (i/8),
  544.            i < sStart || fEndOfFile);
  545.      szTempBuff[i+60+(i/8)] = (i < sStart || fEndOfFile) ? (CHAR) 0x20
  546.                                  : cHexChar;
  547.      if ((OFFSETOF(pcDataPtr) < usLimit))
  548.         pcDataPtr++;
  549.      else {
  550.         lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
  551.         pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
  552.                     &fEndOfFile);
  553.      }
  554.       }
  555.       szTempBuff[34] = ' ';
  556.       szTempBuff[59] = ' ';
  557.       szTempBuff[68] = ' ';
  558.       sBytesPrinted = i - sStart;
  559.       i += 59 + (i/8);
  560.    }
  561.    VioWrtCharStr (szTempBuff, i, sRow, 0, hvps);
  562.    return sBytesPrinted;
  563. }
  564. //------------------------------------------------------------------
  565. // SearchFile - Search the file for the value in szSearchStr.
  566. //    If found, the file pointer is modified to the location in the
  567. //     file.
  568. //------------------------------------------------------------------
  569. BOOL SearchFile (LONG *lFilePtr) {
  570.    USHORT   usLimit;
  571.    PCHAR    pcDataPtr;
  572.    BOOL     fEndOfFile = FALSE, fFound = FALSE;
  573.    CHAR     szCmpBuffer[165];
  574.    SHORT    sBufferLength, sBufferCnt, sSearchLen, i;
  575.    LONG     lLocalPtr, lMarker;
  576.  
  577.    sSearchLen = strlen (szSearchStr);
  578.    lLocalPtr = (fTopSearch) ? 0L : *lFilePtr;
  579.  
  580.    pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit, &fEndOfFile);
  581.  
  582.    while (!fEndOfFile && !fFound) {
  583.  
  584.       sBufferLength = (BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE))
  585.               - sSearchLen;
  586.       if (sBufferLength <= 0) {
  587.  
  588.      for (i = 0; i < BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE); i++)
  589.         *(szCmpBuffer + i) = *(pcDataPtr + i);
  590.  
  591.      sBufferCnt = i;
  592.      lMarker = lLocalPtr;
  593.      lLocalPtr = ((lLocalPtr + BUFFERSIZE) / BUFFERSIZE) * BUFFERSIZE;
  594.  
  595.      pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit,
  596.                      &fEndOfFile);
  597.      if (fEndOfFile)
  598.         break;
  599.      for (i = 0; i < min (sSearchLen + 1,
  600.                   BUFFERSIZE - (usLimit % BUFFERSIZE)); i++)
  601.         *(szCmpBuffer + sBufferCnt + i) = *(pcDataPtr + i);
  602.  
  603.      for (i = 0; i < sBufferCnt; i++)
  604.         if (fCheckCase) {
  605.            if (strncmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
  606.           fFound = TRUE;
  607.           break;
  608.            }
  609.         } else {
  610.            if (strnicmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
  611.           fFound = TRUE;
  612.           break;
  613.            }
  614.         }
  615.      sBufferLength = (BUFFERSIZE - (usLimit%BUFFERSIZE)) - sSearchLen;
  616.       }
  617.       if (fFound) {
  618.      lLocalPtr = lMarker + i;
  619.      break;
  620.       }
  621.       for (i = 0; i < sBufferLength; i++) {
  622.      if (fCheckCase) {
  623.         if (strncmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
  624.            fFound = TRUE;
  625.            break;
  626.         }
  627.      } else {
  628.         if (strnicmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
  629.            fFound = TRUE;
  630.            break;
  631.         }
  632.      }
  633.       }
  634.       lLocalPtr += i;
  635.    }
  636.    if (fFound)
  637.       *lFilePtr = lLocalPtr;
  638.    return fFound;
  639. }
  640. //------------------------------------------------------------------
  641. // ScrollVis - Set Scroll Visibility
  642. //------------------------------------------------------------------
  643. VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
  644.         HWND hwndMenu) {
  645.  
  646.    if (Default.fScrollBars) {
  647.  
  648.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  649.           MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
  650.           MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  651.  
  652.       WinSetParent (hwndVScroll, hwndFrame, FALSE );
  653.       WinSetParent (hwndHScroll, hwndFrame, FALSE );
  654.    } else {
  655.  
  656.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  657.           MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
  658.           MPFROM2SHORT (MIA_CHECKED, 0));
  659.  
  660.       WinSetParent (hwndVScroll, HWND_OBJECT, FALSE );
  661.       WinSetParent (hwndHScroll, HWND_OBJECT, FALSE );
  662.    }
  663.    WinSendMsg ( hwndFrame , WM_UPDATEFRAME ,
  664.    (MPARAM) (FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
  665.    FCF_MENU), NULL);
  666.  
  667.    return;
  668. }
  669. //------------------------------------------------------------------
  670. // Set ASCII - Set ASCII Menu Check marks.
  671. //------------------------------------------------------------------
  672. VOID SetASCII (HWND hwndMenu, LONG *lViewPtr) {
  673.    SHORT sRow = -1;
  674.    if (Default.fDispASCII) {
  675.       if (MIA_CHECKED && WinSendMsg (hwndMenu, MM_QUERYITEMATTR,
  676.                      MPFROM2SHORT (IDM_DISPLAYHEX, TRUE),
  677.                      MPFROM2SHORT (MIA_CHECKED, 0))) {
  678.      *lViewPtr += 2;
  679.      *lViewPtr += MoveViewPtr (*lViewPtr, &sRow, TRUE);
  680.       }
  681.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  682.           MPFROM2SHORT (IDM_DISPLAYHEX, TRUE),
  683.           MPFROM2SHORT (MIA_CHECKED, 0));
  684.  
  685.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  686.           MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
  687.           MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  688.    } else {
  689.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  690.           MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
  691.           MPFROM2SHORT (MIA_CHECKED, 0));
  692.  
  693.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  694.           MPFROM2SHORT (IDM_DISPLAYHEX, TRUE),
  695.           MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  696.    }
  697.    return;
  698. }
  699. //------------------------------------------------------------------
  700. // SetFontSize - Change font size and update menu if necessary.
  701. //------------------------------------------------------------------
  702. VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
  703.           SHORT *psCharHeight) {
  704.    static   CHAR  szSmallPrompt[] = "~Small Font\tCtrl+S";
  705.    static   CHAR  szLargePrompt[] = "~Large Font\tCtrl+S";
  706.  
  707.    VioSetDeviceCellSize (Default.sCellHeight, Default.sCellWidth, hvps);
  708.    VioGetDeviceCellSize (psCharHeight, psCharWidth, hvps);
  709.  
  710.    switch (VideoData.usAdapterType) {
  711.       case 0:
  712.       case 1:                   //CGA, no other cell sizes.
  713.      WinSendMsg (hwndMenu, MM_SETITEMATTR,
  714.              MPFROM2SHORT (IDM_FONTSIZE, 0),
  715.              MPFROM2SHORT (MIA_DISABLED, MIA_CHECKED));
  716.      break;
  717.  
  718.       case 2:                   //EGA
  719.       case 3:                   //VGA
  720.       if (Default.sCellHeight == 8 && Default.sCellWidth == 8)
  721.      WinSendMsg (hwndMenu, MM_SETITEMTEXT,
  722.              MPFROM2SHORT (IDM_FONTSIZE, 0),
  723.              MPFROMP (szLargePrompt));
  724.       else
  725.      WinSendMsg (hwndMenu, MM_SETITEMTEXT,
  726.              MPFROM2SHORT (IDM_FONTSIZE, 0),
  727.              MPFROMP (szSmallPrompt));
  728.      break;
  729.  
  730.       case 7:                   //8514
  731.      break;
  732.       }
  733.    return;
  734. }
  735. //=======================================================================
  736. //
  737. // Client Window Procedure
  738. //
  739. //=======================================================================
  740. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  741.    {
  742.    static   HWND  hwndFrame, hwndMenu, hwndVScroll, hwndHScroll;
  743.  
  744.    static   HVPS  hvps;
  745.    static   HPS   hps;
  746.  
  747.    static   LONG  lViewPtr;
  748.    static   BOOL  fGoMinimize;
  749.  
  750.    static   SHORT sHScroll, sVScrScale, sHPage = 20, sVPage = 20;
  751.    static   SHORT sCharHeight, sCharWidth, sxWinSize, syWinSize;
  752.    static   SHORT sRowsVisible = AVIOROWS;
  753.  
  754.    HDC        hdc;
  755.    SIZEL    sizl;
  756.    SHORT    sRow, sDeltaRows;
  757.    LONG     lTemp;
  758.    SWP        swpWinPos;
  759.    PSWP     pswpWinPos;
  760.    CHAR     szTempBuffer[PATHLENGTH];
  761.  
  762.    switch (msg) {
  763.  
  764.       //--------------------------------------------------------------
  765.       // When the window is created, get and store the handles to
  766.       //   the scroll bars and menu, read the default parameters if
  767.       //   saved before, set the proper attributes for the menu
  768.       //   selections, and create a AVIO presentation space.
  769.       //--------------------------------------------------------------
  770.       case WM_CREATE:
  771.      //
  772.      // If no file specified and not starting as an icon, Query
  773.      // user for a file name.
  774.      //
  775.      if (!File.fValid) {
  776.         if (strlen (szNewFile) == 0) {
  777.            if (!fMinimized)
  778.           if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
  779.              NULL, IDD_OPEN, NULL))
  780.              if (!(File.fValid = OpenFile (szNewFile)))
  781.             WinMessageBox (HWND_DESKTOP, hwnd,
  782.                        "Unable to open the file",
  783.                        File.szName, NULL, MB_OK | MB_ERROR);
  784.         } else
  785.            if (!(File.fValid = OpenFile (szNewFile)))
  786.           WinMessageBox (HWND_DESKTOP, hwnd,
  787.                  "Unable to open the file", File.szName,
  788.                  NULL, MB_OK | MB_ERROR);
  789.         if (File.fValid) {
  790.            if (sHScroll) {
  791.           sHScroll = 0;
  792.           VioSetOrg (0, sHScroll, hvps);
  793.            }
  794.            lViewPtr = 0;
  795.            sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  796.         }
  797.      }
  798.      fMinimized = FALSE;
  799.      //
  800.      // Query the Frame for the necessary window handles.
  801.      //
  802.      hwndFrame = WinQueryWindow (hwnd, QW_PARENT,FALSE);
  803.      hwndMenu = WinWindowFromID (hwndFrame, FID_MENU);
  804.      hwndVScroll = WinWindowFromID (hwndFrame, FID_VERTSCROLL);
  805.      hwndHScroll = WinWindowFromID ( hwndFrame, FID_HORZSCROLL);
  806.      //
  807.      // Set menu attributes.
  808.      //
  809.      sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  810.      ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  811.      SetASCII(hwndMenu, &lViewPtr);
  812.      //
  813.      // Establish AVIO presentation space.
  814.      //
  815.      hdc = WinOpenWindowDC (hwnd);
  816.      sizl.cx = sizl.cy = 0;
  817.      hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT |
  818.                 GPIT_MICRO | GPIA_ASSOC);
  819.      VioCreatePS (&hvps, AVIOROWS, AVIOCOLS, 0, 1, NULL);
  820.      VioAssociate (hdc, hvps);
  821.      VioGetConfig (0, (PVOID) &VideoData, hvps);
  822.  
  823.      SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  824.      VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
  825.  
  826.      if (strlen (File.szName) != 0)
  827.         WinSetWindowText (hwndFrame, File.szName);
  828.      return 0;
  829.  
  830.       //--------------------------------------------------------------
  831.       // Intercept the close message to abort a file open dialog box
  832.       //   when the program is closed from an icon.
  833.       //--------------------------------------------------------------
  834.       case WM_CLOSE:
  835.  
  836.         fMinimized = FALSE;
  837.      break;
  838.  
  839.       //--------------------------------------------------------------
  840.       // If the Window is being restored from an icon without a vaild
  841.       //   file, prompt the user for a file using the file open dialog
  842.       //   box.
  843.       //--------------------------------------------------------------
  844.       case WM_MINMAXFRAME:
  845.  
  846.      if (fMinimized)
  847.         if (!File.fValid) {
  848.            if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc, NULL,
  849.                  IDD_OPEN, NULL)) {
  850.           if (!(File.fValid = OpenFile (szNewFile)))
  851.              WinMessageBox (HWND_DESKTOP, hwnd,
  852.                     "Unable to open the file",
  853.                     File.szName, NULL, MB_OK | MB_ERROR);
  854.           else {
  855.              if (sHScroll) {
  856.             sHScroll = 0;
  857.             VioSetOrg (0, sHScroll, hvps);
  858.              }
  859.              lViewPtr = 0;
  860.              sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  861.              WinSetWindowText (hwndFrame, File.szName);
  862.           }
  863.            } else
  864.           fGoMinimize = TRUE;
  865.         }
  866.      //
  867.      // Record the current state of the program.
  868.      //
  869.      pswpWinPos = PVOIDFROMMP (mp1);
  870.      if (pswpWinPos->fs & SWP_MINIMIZE)
  871.         fMinimized = TRUE;
  872.      else
  873.         fMinimized = FALSE;
  874.      break;
  875.  
  876.       //--------------------------------------------------------------
  877.       // When the GoMimize flag is set send the frame a minimize
  878.       //   message.
  879.       //--------------------------------------------------------------
  880.       case WM_WINDOWPOSCHANGED:
  881.  
  882.         if (fGoMinimize) {
  883.            fGoMinimize = FALSE;
  884.            WinSetWindowPos (hwndFrame, HWND_BOTTOM, 0, 0, 0, 0,
  885.                  SWP_MINIMIZE);
  886.         }
  887.      break;
  888.  
  889.       //--------------------------------------------------------------
  890.       // When the window is resized, record the new window size,
  891.       //   update the horizontal position of the AVIO space and
  892.       //   scroll bar, and notify the frame to modify its windows.
  893.       //--------------------------------------------------------------
  894.       case WM_SIZE:
  895.  
  896.      sxWinSize = SHORT1FROMMP(mp2);
  897.      syWinSize = SHORT2FROMMP(mp2);
  898.  
  899.      if (sHScroll > AVIOCOLS - sxWinSize / sCharWidth) {
  900.         sHScroll = min (max (0, sHScroll),
  901.                  AVIOCOLS - sxWinSize / sCharWidth);
  902.         VioSetOrg (0, sHScroll, hvps);
  903.         WinInvalidateRect (hwnd, NULL, FALSE);
  904.      }
  905.      sHPage = max (sxWinSize / sCharWidth - 1, 0);
  906.      sVPage = max (syWinSize / sCharHeight - 1, 0);
  907.      sRowsVisible = min (syWinSize / sCharHeight + 1, AVIOROWS);
  908.  
  909.      WinSendMsg ( hwndFrame, WM_UPDATEFRAME, (MPARAM) (FCF_TITLEBAR
  910.               | FCF_SYSMENU | FCF_MINMAX | FCF_MENU), NULL);
  911.  
  912.      WinSendMsg (hwndHScroll, SBM_SETSCROLLBAR,
  913.              MPFROM2SHORT (sHScroll, 0),
  914.              MPFROM2SHORT (0, AVIOCOLS - sxWinSize / sCharWidth));
  915.  
  916.      WinSendMsg (hwndHScroll, SBM_SETTHUMBSIZE,
  917.              MPFROM2SHORT (sxWinSize / sCharWidth,
  918.              AVIOCOLS - sxWinSize / sCharWidth), NULL);
  919.  
  920.      WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
  921.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
  922.              MPFROM2SHORT (0, File.lSize/sVScrScale));
  923.  
  924.      WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  925.              MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
  926.                   File.lSize/sVScrScale),NULL);
  927.  
  928.      return WinDefAVioWindowProc (hwnd, msg, mp1, mp2);
  929.  
  930.       //--------------------------------------------------------------
  931.       // Repaint the complete AVIO space by first clearing the window
  932.       //   then writing to the AVIO space.
  933.       //--------------------------------------------------------------
  934.       case WM_PAINT:
  935.  
  936.      WinBeginPaint (hwnd, hps, NULL);
  937.      VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
  938.  
  939.      lTemp = lViewPtr;
  940.      for (sRow = 0; sRow < sRowsVisible; sRow++)
  941.         lTemp += (LONG) DisplayLine (hvps, sRow, lTemp,
  942.                       Default.fDispASCII);
  943.      WinEndPaint (hps);
  944.  
  945.      WinSendMsg (hwndVScroll, SBM_SETPOS,
  946.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
  947.              NULL);
  948.      return 0;
  949.  
  950.       //--------------------------------------------------------------
  951.       // Process each menu selection according to function.
  952.       //--------------------------------------------------------------
  953.       case WM_COMMAND:
  954.  
  955.      switch (COMMANDMSG(&msg)->cmd) {
  956.  
  957.      case IDM_OPEN:
  958.         if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
  959.               NULL, IDD_OPEN, NULL)) {
  960.            if (File.fValid = OpenFile (szNewFile)) {
  961.           if (sHScroll) {
  962.              sHScroll = 0;
  963.              VioSetOrg (0, sHScroll, hvps);
  964.           }
  965.           lViewPtr = 0;
  966.           sVScrScale  = (SHORT) ((File.lSize / 32768) + 1);
  967.  
  968.           WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
  969.                   MPFROM2SHORT (0, 0),
  970.                   MPFROM2SHORT (0, File.lSize/sVScrScale));
  971.           WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
  972.                   MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
  973.                   File.lSize/sVScrScale),NULL);
  974.           WinSetWindowText (hwndFrame, File.szName);
  975.           WinInvalidateRect (hwnd, NULL, FALSE);
  976.            } else
  977.           WinMessageBox (HWND_DESKTOP, hwnd, "Unable to open the file",
  978.                  File.szName, NULL, MB_OK | MB_ERROR);
  979.         }
  980.         return 0;
  981.  
  982.      case IDM_FIND:
  983.         if (WinDlgBox(HWND_DESKTOP, hwnd, SearchDlgProc,
  984.               NULL, IDD_SEARCH, NULL))
  985.            if (strlen (szSearchStr) != 0)
  986.           WinPostMsg (hwnd, WM_COMMAND,
  987.                   MPFROM2SHORT (IDM_REPFIND,0), mp2);
  988.         return 0;
  989.  
  990.      case IDM_REPFIND:
  991.         if (strlen (szSearchStr) == 0) {
  992.            WinPostMsg (hwnd, WM_COMMAND, MPFROM2SHORT (IDM_FIND,0),
  993.                mp2);
  994.            return 0;
  995.         } else {
  996.            //
  997.            //   Check to see if we are on the same line as the last
  998.            // found string.  If so, start search at 1 byte past
  999.            // last found string.
  1000.            //
  1001.            sDeltaRows = 1;
  1002.            lTemp = MoveViewPtr (lViewPtr, &sDeltaRows,
  1003.                        Default.fDispASCII);
  1004.            lTemp += lViewPtr;
  1005.  
  1006.            if (lTemp > lLastFound && lLastFound > lViewPtr)
  1007.           lLastFound++;
  1008.            else
  1009.           lLastFound = lViewPtr;
  1010.            //
  1011.            //   If string found, back up the the start fo the
  1012.            // current line.
  1013.            //
  1014.            WinQueryWindowText (hwndFrame, PATHLENGTH, szTempBuffer);
  1015.            WinSetWindowText (hwndFrame, "Searching");
  1016.            if (SearchFile (&lLastFound)) {
  1017.           lViewPtr = lLastFound;
  1018.           sDeltaRows = -1;
  1019.           lViewPtr += MoveViewPtr (lViewPtr, &sDeltaRows,
  1020.                        Default.fDispASCII);
  1021.           WinInvalidateRect (hwnd, NULL, FALSE);
  1022.           WinSetWindowText (hwndFrame, szTempBuffer);
  1023.            } else {
  1024.           WinSetWindowText (hwndFrame, szTempBuffer);
  1025.           WinMessageBox (HWND_DESKTOP, hwnd, szSearchStr,
  1026.                  "Unable to find the string",
  1027.                  NULL, MB_OK | MB_ICONHAND);
  1028.            }
  1029.         }
  1030.         return 0;
  1031.  
  1032.      case IDM_GOTO:
  1033.         if (WinDlgBox(HWND_DESKTOP, hwnd, GotoDlgProc,
  1034.               NULL, IDD_GOTO, NULL)) {
  1035.            lViewPtr = min (max (lNewViewPtr, 0L), File.lSize);
  1036.            WinInvalidateRect (hwnd, NULL, FALSE);
  1037.         }
  1038.         return 0;
  1039.  
  1040.      case IDM_CONFIGURE:
  1041.         if (WinDlgBox(HWND_DESKTOP, hwnd, ConfigDlgProc,
  1042.               NULL, IDD_CONFIGURE, NULL)) {
  1043.            if (fSaveToDisk) {
  1044.           if (fSaveWinPos) {
  1045.              WinQueryWindowPos (hwndFrame, &swpWinPos);
  1046.              Default.sxWinPos = swpWinPos.x;
  1047.              Default.syWinPos = swpWinPos.y;
  1048.              Default.sWinWidth = swpWinPos.cx;
  1049.              Default.sWinHeight = swpWinPos.cy;
  1050.           }
  1051.           WinWriteProfileData (hab, szAppName, szKeyName,
  1052.                        &Default, sizeof Default);
  1053.            }
  1054.            SetASCII(hwndMenu, &lViewPtr);
  1055.            ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  1056.            SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  1057.            sHPage = max (sxWinSize / sCharWidth - 1, 0);
  1058.            sVPage = max (syWinSize / sCharHeight - 1, 0);
  1059.            sRowsVisible = min (syWinSize / sCharHeight + 1, AVIOROWS);
  1060.            WinInvalidateRect (hwnd, NULL, FALSE);
  1061.         }
  1062.         return 0;
  1063.  
  1064.      case IDM_DISPLAYASCII:
  1065.         if (!Default.fDispASCII) {
  1066.            Default.fDispASCII = TRUE;
  1067.            SetASCII (hwndMenu, &lViewPtr);
  1068.            WinInvalidateRect (hwnd, NULL, FALSE);
  1069.         }
  1070.         return 0;
  1071.  
  1072.      case IDM_DISPLAYHEX:
  1073.         if (Default.fDispASCII) {
  1074.            Default.fDispASCII = FALSE;
  1075.            SetASCII (hwndMenu, &lViewPtr);
  1076.            WinInvalidateRect (hwnd, NULL, FALSE);
  1077.         }
  1078.         return 0;
  1079.  
  1080.      case IDM_DISPSCROLLBARS:
  1081.         if (Default.fScrollBars)
  1082.            Default.fScrollBars = FALSE;
  1083.         else
  1084.            Default.fScrollBars = TRUE;
  1085.  
  1086.         ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
  1087.         return 0;
  1088.  
  1089.      case IDM_FONTSIZE:
  1090.         switch (VideoData.usAdapterType) {
  1091.            case 2:                //EGA
  1092.           if (Default.sCellHeight == 8 && Default.sCellWidth == 8){
  1093.              Default.sCellHeight = sCellSize[1][1];
  1094.              Default.sCellWidth = sCellSize[1][0];
  1095.           } else {
  1096.              Default.sCellHeight = sCellSize[0][1];
  1097.              Default.sCellWidth = sCellSize[0][0];
  1098.           }
  1099.           break;
  1100.  
  1101.            case 3:                //VGA
  1102.           if (Default.sCellHeight == 8 && Default.sCellWidth == 8){
  1103.              Default.sCellHeight = sCellSize[2][1];
  1104.              Default.sCellWidth = sCellSize[2][0];
  1105.           } else {
  1106.              Default.sCellHeight = sCellSize[0][1];
  1107.              Default.sCellWidth = sCellSize[0][0];
  1108.           }
  1109.           break;
  1110.  
  1111.            case 7:                //8514
  1112.           if (!WinDlgBox(HWND_DESKTOP, hwnd, FontDlgProc,
  1113.              NULL, IDD_PICKFONT, NULL))
  1114.              return 0;
  1115.           break;
  1116.         }
  1117.         SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
  1118.         sHPage = max (sxWinSize / sCharWidth - 1, 0);
  1119.         sVPage = max (syWinSize / sCharHeight - 1, 0);
  1120.         sRowsVisible = min (syWinSize / sCharHeight + 1, AVIOROWS);
  1121.         WinInvalidateRect (hwnd, NULL, FALSE);
  1122.         return 0;
  1123.  
  1124.      case IDM_ABOUT:
  1125.         WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,
  1126.               NULL, IDD_ABOUT, NULL);
  1127.         return 0;
  1128.  
  1129.      case IDM_EXIT:
  1130.         WinSendMsg(hwnd, WM_CLOSE, 0L, 0L);
  1131.         return 0;
  1132.       }
  1133.       //--------------------------------------------------------------
  1134.       // Convert cursor keys to scroll bar messages.
  1135.       //--------------------------------------------------------------
  1136.       case WM_CHAR:
  1137.  
  1138.      switch (CHARMSG (&msg) -> vkey) {
  1139.  
  1140.         case VK_UP:
  1141.         case VK_DOWN:
  1142.         case VK_PAGEUP:
  1143.         case VK_PAGEDOWN:
  1144.            return WinSendMsg (hwndVScroll, msg, mp1, mp2);
  1145.  
  1146.         case VK_LEFT:
  1147.         case VK_RIGHT:
  1148.            return WinSendMsg (hwndHScroll, msg, mp1, mp2);
  1149.  
  1150.         case VK_HOME:
  1151.            if (lViewPtr != 0) {
  1152.           lViewPtr = 0;
  1153.           WinInvalidateRect (hwnd, NULL, FALSE);
  1154.            }
  1155.            break;
  1156.  
  1157.         case VK_END:
  1158.            if (lViewPtr != File.lSize - 1) {
  1159.           lViewPtr = File.lSize - 1;
  1160.           WinInvalidateRect (hwnd, NULL, FALSE);
  1161.            }
  1162.            break;
  1163.      }
  1164.      return WinDefWindowProc (hwnd, msg, mp1, mp2);
  1165.  
  1166.       //-----------------------------------------------------------
  1167.       // Process Horizonal Scroll Bar Messages by scrolling across
  1168.       //    the AVIO space.
  1169.       //-----------------------------------------------------------
  1170.       case WM_HSCROLL:
  1171.  
  1172.      switch (SHORT2FROMMP (mp2)) {
  1173.  
  1174.         case SB_LINELEFT:
  1175.  
  1176.            sHScroll -= 1;
  1177.            break;
  1178.  
  1179.         case SB_PAGELEFT:
  1180.  
  1181.            sHScroll -= sHPage;
  1182.            break;
  1183.  
  1184.         case SB_LINERIGHT:
  1185.  
  1186.            sHScroll += 1;
  1187.            break;
  1188.  
  1189.         case SB_PAGERIGHT:
  1190.  
  1191.            sHScroll += sHPage;
  1192.            break;
  1193.  
  1194.         case SB_SLIDERTRACK:
  1195.  
  1196.            sHScroll = SHORT1FROMMP (mp2);
  1197.            break;
  1198.      }
  1199.      sHScroll = min (max (0, sHScroll),
  1200.               AVIOCOLS - sxWinSize / sCharWidth);
  1201.  
  1202.      if (sHScroll != SHORT1FROMMR (WinSendMsg (hwndHScroll,
  1203.                     SBM_QUERYPOS, NULL, NULL))) {
  1204.         VioSetOrg (0, sHScroll, hvps);
  1205.         WinSendMsg (hwndHScroll, SBM_SETPOS,
  1206.             MPFROM2SHORT (sHScroll, 0), NULL);
  1207.      }
  1208.      return 0;
  1209.  
  1210.       //-----------------------------------------------------------
  1211.       // Process Vertical Scroll Bar Messages by scrolling the AVIO
  1212.       //    space and writing the new lines.
  1213.       //-----------------------------------------------------------
  1214.       case WM_VSCROLL:
  1215.  
  1216.      switch (SHORT2FROMMP (mp2)) {
  1217.  
  1218.         case SB_LINEUP:
  1219.  
  1220.            sDeltaRows = -1;
  1221.            break;
  1222.  
  1223.         case SB_PAGEUP:
  1224.  
  1225.            sDeltaRows = -sVPage;
  1226.            break;
  1227.  
  1228.         case SB_LINEDOWN:
  1229.  
  1230.            sDeltaRows = 1;
  1231.            break;
  1232.  
  1233.         case SB_PAGEDOWN:
  1234.  
  1235.            sDeltaRows = sVPage;
  1236.            break;
  1237.  
  1238.         case SB_SLIDERTRACK:
  1239.  
  1240.            lTemp = lViewPtr;
  1241.  
  1242.            lViewPtr = (LONG) (SHORT1FROMMP(mp2) * sVScrScale);
  1243.  
  1244.            sDeltaRows = ComputeLines (lTemp, lViewPtr,
  1245.                    Default.fDispASCII);
  1246.            sDeltaRows = (sDeltaRows > sRowsVisible) ? sRowsVisible : sDeltaRows;
  1247.            sDeltaRows = (sDeltaRows < -sRowsVisible) ? -sRowsVisible : sDeltaRows;
  1248.            break;
  1249.  
  1250.         default:
  1251.            return 0;
  1252.      }
  1253.      if (SHORT2FROMMP (mp2) != SB_SLIDERTRACK)
  1254.         lViewPtr += MoveViewPtr (lViewPtr, &sDeltaRows, Default.fDispASCII);
  1255.  
  1256.      WinSendMsg (hwndVScroll, SBM_SETPOS,
  1257.              MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0), NULL);
  1258.  
  1259.      if (sDeltaRows > 0) {
  1260.         VioScrollUp (0, 0, sRowsVisible, AVIOCOLS, sDeltaRows,
  1261.              Default.szAttribute, hvps);
  1262.  
  1263.         sRow = sRowsVisible-sDeltaRows;
  1264.  
  1265.         lTemp = lViewPtr;
  1266.         lTemp += MoveViewPtr (lTemp, &sRow, Default.fDispASCII);
  1267.  
  1268.         for (sRow = 0; sRow <= sDeltaRows; sRow++)
  1269.            lTemp += DisplayLine (hvps, (sRowsVisible-sDeltaRows) + sRow,
  1270.                      lTemp, Default.fDispASCII);
  1271.      }
  1272.      if (sDeltaRows < 0) {
  1273.         sDeltaRows = -sDeltaRows;
  1274.         VioScrollDn (0, 0, sRowsVisible, AVIOCOLS, sDeltaRows,
  1275.              Default.szAttribute, hvps);
  1276.  
  1277.         lTemp = lViewPtr;
  1278.         for (sRow = 0; sRow <= sDeltaRows; sRow++)
  1279.            lTemp += DisplayLine (hvps, sRow, lTemp, Default.fDispASCII);
  1280.      }
  1281.      return 0;
  1282.  
  1283.       //-----------------------------------------------------------
  1284.       // Destroy the AVIO space nad the presentation space.
  1285.       //-----------------------------------------------------------
  1286.       case WM_DESTROY:
  1287.  
  1288.      VioAssociate (NULL, hvps);
  1289.      VioDestroyPS (hvps);
  1290.      GpiDestroyPS (hps);
  1291.      return 0;
  1292.    }
  1293.    return WinDefWindowProc (hwnd, msg, mp1, mp2);
  1294. }
  1295. //=====================================================================
  1296. // Dialog Procedures
  1297. //=====================================================================
  1298. //------------------------------------------------------------------
  1299. //  About Dialog Box
  1300. //------------------------------------------------------------------
  1301. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1302.    {
  1303.    switch (msg) {
  1304.  
  1305.       case WM_COMMAND:
  1306.  
  1307.      switch (COMMANDMSG(&msg)->cmd) {
  1308.  
  1309.         case DID_OK:
  1310.         case DID_CANCEL:
  1311.             WinDismissDlg (hwnd, TRUE);
  1312.             return 0;
  1313.      }
  1314.    }
  1315.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1316. }
  1317. //------------------------------------------------------------------
  1318. //  Goto Dialog Box
  1319. //------------------------------------------------------------------
  1320. MRESULT EXPENTRY GotoDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1321.    {
  1322.    CHAR  szBuffer[12];
  1323.  
  1324.    switch (msg) {
  1325.  
  1326.       case WM_INITDLG:
  1327.  
  1328.      WinSendDlgItemMsg (hwnd, IDD_NEWOFFSET, EM_CLEAR, NULL, NULL);
  1329.  
  1330.      WinSendDlgItemMsg ( hwnd, IDD_NEWOFFSET, EM_SETTEXTLIMIT,
  1331.                  MPFROM2SHORT (11, 0), NULL);
  1332.      return 0;
  1333.  
  1334.       case WM_COMMAND:
  1335.  
  1336.      switch (COMMANDMSG(&msg)->cmd) {
  1337.  
  1338.         case DID_OK:
  1339.            if (WinQueryDlgItemText (hwnd, IDD_NEWOFFSET, sizeof szBuffer,
  1340.             szBuffer)) {
  1341.           lNewViewPtr = atol (szBuffer);
  1342.           WinDismissDlg (hwnd, TRUE);
  1343.           return 0;
  1344.            }
  1345.         case DID_CANCEL:
  1346.            WinDismissDlg (hwnd, FALSE);
  1347.            return 0;
  1348.      }
  1349.    }
  1350.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1351. }
  1352. //=====================================================================
  1353. // Search Dialog Procedures
  1354. //=====================================================================
  1355. //------------------------------------------------------------------
  1356. //  Search Dialog Box
  1357. //------------------------------------------------------------------
  1358. MRESULT EXPENTRY SearchDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1359.    {
  1360.    switch (msg) {
  1361.  
  1362.       case WM_INITDLG:
  1363.  
  1364.      WinSetDlgItemText ( hwnd, IDD_SRCHSTR, szSearchStr);
  1365.  
  1366.      WinSendDlgItemMsg (hwnd, IDD_CHKCASE, BM_SETCHECK,
  1367.                 MPFROM2SHORT (fCheckCase, 0), NULL);
  1368.  
  1369.      WinSendDlgItemMsg (hwnd, IDD_TOPSEARCH, BM_SETCHECK,
  1370.                 MPFROM2SHORT (fTopSearch, 0), NULL);
  1371.      return 0;
  1372.  
  1373.       case WM_CONTROL:
  1374.  
  1375.      switch (SHORT1FROMMP (mp1)) {
  1376.  
  1377.         case IDD_CHKCASE:
  1378.            switch (SHORT2FROMMP (mp1)) {
  1379.  
  1380.           case BN_CLICKED:
  1381.              if (fCheckCase)
  1382.             fCheckCase = FALSE;
  1383.              else
  1384.             fCheckCase = TRUE;
  1385.              return 0;
  1386.            }
  1387.            break;
  1388.  
  1389.         case IDD_TOPSEARCH:
  1390.            switch (SHORT2FROMMP (mp1)) {
  1391.  
  1392.           case BN_CLICKED:
  1393.              if (fTopSearch)
  1394.             fTopSearch = FALSE;
  1395.              else
  1396.             fTopSearch = TRUE;
  1397.              return 0;
  1398.            }
  1399.            break;
  1400.      }
  1401.      break;
  1402.  
  1403.       case WM_COMMAND:
  1404.  
  1405.      switch (COMMANDMSG(&msg)->cmd) {
  1406.  
  1407.         case DID_OK:
  1408.            WinQueryDlgItemText (hwnd, IDD_SRCHSTR, sizeof szSearchStr,
  1409.             szSearchStr);
  1410.            if (strlen (szSearchStr)) {
  1411.           WinDismissDlg (hwnd, TRUE);
  1412.           return 0;
  1413.            }
  1414.         case DID_CANCEL:
  1415.            WinDismissDlg (hwnd, FALSE);
  1416.            return 0;
  1417.      }
  1418.    }
  1419.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1420. }
  1421. //===================================================================
  1422. // Procedures for File open dialog box
  1423. //===================================================================
  1424. VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath) {
  1425.    static CHAR szDrive [] = "  :";
  1426.    SHORT  sDrive;
  1427.    ULONG  ulDriveMap;
  1428.    USHORT usDriveNum;
  1429.  
  1430.    DosQCurDisk (&usDriveNum, &ulDriveMap);
  1431.  
  1432.    pcCurrentPath[0] = (CHAR) usDriveNum + '@';
  1433.    pcCurrentPath[1] = ':';
  1434.    pcCurrentPath[2] = '\\';
  1435.  
  1436.    WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_DELETEALL, NULL, NULL);
  1437.  
  1438.    for (sDrive = 0; sDrive < 26 ; sDrive++ )
  1439.       if (ulDriveMap & 1L << sDrive) {
  1440.      szDrive [1] = (CHAR) sDrive + 'A';
  1441.  
  1442.      WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_INSERTITEM,
  1443.                   MPFROM2SHORT (LIT_END, 0),
  1444.                   MPFROMP (szDrive));
  1445.       }
  1446.       WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_SELECTITEM,
  1447.                MPFROM2SHORT (usDriveNum - 1, 0),
  1448.                MPFROM2SHORT (TRUE, 0));
  1449. }
  1450. //------------------------------------------------------------------
  1451. //  Fill Directory List Box Procedure
  1452. //------------------------------------------------------------------
  1453. VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden) {
  1454.    static      CHAR  szRootStr[] = "\\";
  1455.    FILEFINDBUF findbuf;
  1456.    HDIR        hDir = 1;
  1457.    USHORT      usCurPathLen = PATHLENGTH, usSearchCount = 1;
  1458.    USHORT      usAttr;
  1459.  
  1460.    if (fIncHidden)
  1461.       usAttr = 0x0017;
  1462.    else
  1463.       usAttr = 0x0015;
  1464.  
  1465.    WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_DELETEALL, NULL, NULL);
  1466.  
  1467.    DosQCurDir (0, pcCurPath + 3 , &usCurPathLen);
  1468.  
  1469.    DosFindFirst ("*.*", &hDir, usAttr, &findbuf, sizeof findbuf,
  1470.          &usSearchCount, 0L);
  1471.  
  1472.    while (usSearchCount) {
  1473.       if (findbuf.attrFile & 0x0010
  1474.       && (findbuf.achName [0] != '.' || findbuf.achName [1] ))
  1475.  
  1476.      if (pcCurPath [strlen(pcCurPath)-1] != '\\'
  1477.          || findbuf.achName[1] != '.' || findbuf.achName [2])
  1478.  
  1479.         WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
  1480.                  MPFROM2SHORT (LIT_SORTASCENDING, 0),
  1481.                  MPFROMP (findbuf.achName));
  1482.  
  1483.       DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
  1484.    }
  1485.    if (pcCurPath [strlen(pcCurPath)-1] != '\\')
  1486.       WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
  1487.               MPFROM2SHORT (0, 0), MPFROMP (szRootStr));
  1488. }
  1489. //------------------------------------------------------------------
  1490. //  Fill File List Box Procedure
  1491. //------------------------------------------------------------------
  1492. VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden) {
  1493.    FILEFINDBUF findbuf;
  1494.    HDIR        hDir = 1;
  1495.    USHORT      usSearchCount = 1;
  1496.    USHORT      usAttr;
  1497.  
  1498.    if (fIncHidden)
  1499.       usAttr = 0x0007;
  1500.    else
  1501.       usAttr = 0x0005;
  1502.  
  1503.    WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_DELETEALL, NULL, NULL);
  1504.  
  1505.    DosFindFirst (pcSearchParam, &hDir, usAttr, &findbuf, sizeof findbuf,
  1506.          &usSearchCount, 0L);
  1507.  
  1508.    while (usSearchCount) {
  1509.       WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_INSERTITEM,
  1510.                MPFROM2SHORT (LIT_SORTASCENDING, 0),
  1511.                MPFROMP (findbuf.achName));
  1512.       DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
  1513.    }
  1514. }
  1515. //------------------------------------------------------------------
  1516. //  File Open Dialog Box Procedure
  1517. //------------------------------------------------------------------
  1518. MRESULT EXPENTRY FileDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1519.    {
  1520.    static      CHAR  szCurrentPath [PATHLENGTH], szFileName[PATHLENGTH] = "*.*";
  1521.    static      BOOL  fIncHidden;
  1522.    CHAR        szBuffer [PATHLENGTH];
  1523.    USHORT      usCurPathLen = PATHLENGTH - 3;
  1524.    SHORT       sSelect;
  1525.    FILEFINDBUF findbuf;
  1526.    HDIR        hDir = 1;
  1527.    USHORT      usSearchCount = 1, usAttr, i;
  1528.  
  1529.    switch (msg) {
  1530.  
  1531.       case WM_INITDLG:
  1532.      fIncHidden = Default.fIncHiddenFiles;
  1533.  
  1534.      strcpy (szFileName, "*.*");
  1535.      FillDriveListBox (hwnd, szCurrentPath);
  1536.      FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  1537.      FillFileListBox (hwnd, szFileName, fIncHidden);
  1538.  
  1539.      WinSendDlgItemMsg (hwnd, IDD_INCHIDDEN, BM_SETCHECK,
  1540.                 MPFROM2SHORT (fIncHidden, 0), NULL);
  1541.  
  1542.      DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
  1543.  
  1544.      WinSendDlgItemMsg ( hwnd, IDD_FILEEDIT, EM_SETTEXTLIMIT,
  1545.                  MPFROM2SHORT (PATHLENGTH, 0), NULL);
  1546.  
  1547.      WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  1548.      return 0;
  1549.  
  1550.       case WM_CONTROL:
  1551.  
  1552.      if (SHORT1FROMMP (mp1) == IDD_DRIVELIST ||
  1553.          SHORT1FROMMP (mp1) == IDD_DIRLIST     ||
  1554.          SHORT1FROMMP (mp1) == IDD_FILELIST) {
  1555.  
  1556.         sSelect = (USHORT) WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
  1557.                     LM_QUERYSELECTION, 0L, 0L);
  1558.  
  1559.         WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
  1560.                   LM_QUERYITEMTEXT,
  1561.                   MPFROM2SHORT (sSelect, sizeof szBuffer),
  1562.                   MPFROMP (szBuffer));
  1563.      }
  1564.  
  1565.      switch (SHORT1FROMMP (mp1)) {
  1566.  
  1567.         case IDD_DRIVELIST:
  1568.            switch (SHORT2FROMMP (mp1)) {
  1569.  
  1570.           case LN_ENTER:
  1571.              szCurrentPath[0] = szBuffer[1];
  1572.              DosSelectDisk (szBuffer [1] - '@');
  1573.  
  1574.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  1575.              if (strcmp(szFileName, "*.*") != 0) {
  1576.             if (szCurrentPath [strlen (szCurrentPath)-1]
  1577.                                 != '\\')
  1578.                strcat (szCurrentPath, "\\");
  1579.             strcat (szCurrentPath, szFileName);
  1580.              }
  1581.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  1582.              FillFileListBox (hwnd, szFileName, fIncHidden);
  1583.  
  1584.              return 0;
  1585.            }
  1586.            break;
  1587.  
  1588.         case IDD_DIRLIST:
  1589.            switch (SHORT2FROMMP (mp1)) {
  1590.  
  1591.           case LN_ENTER:
  1592.  
  1593.              DosChDir (szBuffer, 0L);
  1594.  
  1595.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  1596.              if (strcmp(szFileName, "*.*") != 0) {
  1597.             if (szCurrentPath [strlen (szCurrentPath)-1]
  1598.                                 != '\\')
  1599.                strcat (szCurrentPath, "\\");
  1600.             strcat (szCurrentPath, szFileName);
  1601.              }
  1602.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  1603.              FillFileListBox (hwnd, szFileName, fIncHidden);
  1604.              return 0;
  1605.            }
  1606.            break;
  1607.  
  1608.         case IDD_FILELIST:
  1609.            switch (SHORT2FROMMP (mp1)) {
  1610.  
  1611.           case LN_SELECT:
  1612.  
  1613.              DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
  1614.              if (szCurrentPath [strlen(szCurrentPath)-1] != '\\')
  1615.             strcat (szCurrentPath, "\\");
  1616.              strcat (szCurrentPath, szBuffer);
  1617.  
  1618.              WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
  1619.              return 0;
  1620.  
  1621.           case LN_ENTER:
  1622.  
  1623.              WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
  1624.                       sizeof szCurrentPath,
  1625.                       szCurrentPath);
  1626.              if (DosQPathInfo (szCurrentPath, 5, szBuffer,
  1627.                    sizeof szBuffer, 0L)) {
  1628.             WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
  1629.                          "Unrecognised path", 1,
  1630.                          MB_OK | MB_ERROR);
  1631.             return 0;
  1632.              } else {
  1633.             strcpy (szNewFile, szBuffer);
  1634.             Default.fIncHiddenFiles = fIncHidden;
  1635.             WinDismissDlg (hwnd, TRUE);
  1636.             return 0;
  1637.              }
  1638.            }
  1639.            break;
  1640.  
  1641.         case IDD_INCHIDDEN:
  1642.            switch (SHORT2FROMMP (mp1)) {
  1643.  
  1644.           case BN_CLICKED:
  1645.              if (fIncHidden)
  1646.             fIncHidden = FALSE;
  1647.              else
  1648.             fIncHidden = TRUE;
  1649.              FillFileListBox (hwnd, szFileName, fIncHidden);
  1650.              FillDirListBox (hwnd, szCurrentPath, fIncHidden);
  1651.              return 0;
  1652.            }
  1653.            break;
  1654.      }
  1655.      break;
  1656.  
  1657.       case WM_COMMAND:
  1658.  
  1659.      switch (COMMANDMSG(&msg)->cmd) {
  1660.  
  1661.         case DID_OK:
  1662.            WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
  1663.                     sizeof szCurrentPath,
  1664.                     szCurrentPath);
  1665.            if (DosQPathInfo (szCurrentPath, 5, szBuffer,
  1666.                  sizeof szBuffer, 0L)) {
  1667.           WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
  1668.                        "Unrecognised path", 1,
  1669.                        MB_OK | MB_ERROR);
  1670.           return 0;
  1671.            } else
  1672.           if (strchr (szBuffer, '*') == 0
  1673.               && strchr (szBuffer, '?') == 0) {
  1674.              if (fIncHidden)
  1675.             usAttr = 0x0007;
  1676.              else
  1677.             usAttr = 0x0005;
  1678.              usSearchCount = 1;
  1679.  
  1680.              DosFindFirst (szBuffer, &hDir, usAttr, &findbuf,
  1681.                    sizeof findbuf, &usSearchCount, 0L);
  1682.              if (usSearchCount    == 0) {
  1683.             WinMessageBox (HWND_DESKTOP, hwnd, szBuffer,
  1684.                        "File not Found", 1, MB_OK | MB_ERROR);
  1685.             return 0;
  1686.              } else {
  1687.             strcpy (szNewFile, szBuffer);
  1688.             Default.fIncHiddenFiles = fIncHidden;
  1689.             WinDismissDlg (hwnd, TRUE);
  1690.             return 0;
  1691.              }
  1692.           } else {
  1693.              for (i = strlen(szBuffer); i >= 0; i--)
  1694.             if (szBuffer[i] == '\\')
  1695.                break;
  1696.              strcpy (szFileName, szBuffer + i + 1);
  1697.              FillFileListBox (hwnd, szFileName, fIncHidden);
  1698.              return 0;
  1699.           }
  1700.            break;
  1701.         case DID_CANCEL:
  1702.            WinDismissDlg (hwnd, FALSE);
  1703.            return 0;
  1704.      }
  1705.      break;
  1706.    }
  1707.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1708. }
  1709. //===================================================================
  1710. // Procedures for Configure dialog box
  1711. //===================================================================
  1712. VOID FillColorBox (HWND hwnd, SHORT iListID) {
  1713.  
  1714.    static CHAR szColors [16][12] = { "Black", "Dk. Blue", "Dk. Green",
  1715.       "Dk. Cyan", "Dk. Red", "Dk. Magenta", "Brown", "Gray", "Dk. Gray",
  1716.       "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White"};
  1717.  
  1718.    SHORT  i;
  1719.  
  1720.    WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
  1721.  
  1722.    for (i = 0; i < 16 ; i++ )
  1723.      WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
  1724.                   MPFROM2SHORT (LIT_END, 0),
  1725.                   MPFROMP (szColors[i]));
  1726.    return;
  1727. }
  1728. //------------------------------------------------------------------
  1729. //  Fill Character cell size box
  1730. //------------------------------------------------------------------
  1731. VOID FillCellSizeBox (HWND hwnd, SHORT iListID) {
  1732.  
  1733.    static CHAR szCellSizes [10][8] = {"8 x 8", "8 x 12", "8 x 14", "7 x 15",
  1734.       "7 x 25", "8 x 17", "12 x 16", "12 x 20", "12 x 22", "12 x 30"};
  1735.  
  1736.    SHORT  i, sStart, sEnd;
  1737.  
  1738.    WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
  1739.  
  1740.    WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
  1741.             MPFROM2SHORT (LIT_END, 0), MPFROMP (szCellSizes[0]));
  1742.  
  1743.    switch (VideoData.usAdapterType) {
  1744.       case 0:
  1745.       case 1:                   //CGA, no other cell sizes.
  1746.      sStart = 2;
  1747.      sEnd = 1;
  1748.      break;
  1749.  
  1750.       case 2:                   //EGA
  1751.      sStart = 1;
  1752.      sEnd = 1;
  1753.      break;
  1754.  
  1755.       case 3:                   //VGA
  1756.      sStart = 2;
  1757.      sEnd = 2;
  1758.      break;
  1759.  
  1760.       case 7:                   //8514
  1761.      sStart = 3;
  1762.      sEnd = 9;
  1763.      break;
  1764.       }
  1765.    for (i = sStart; i <= sEnd; i++ )
  1766.       WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
  1767.               MPFROM2SHORT (LIT_END, 0), MPFROMP (szCellSizes[i]));
  1768.    return;
  1769. }
  1770. //------------------------------------------------------------------
  1771. // GetFontSize - Determine font size.
  1772. //------------------------------------------------------------------
  1773. SHORT GetCellSize (SHORT sHeight, SHORT sWidth) {
  1774.  
  1775.    SHORT  i, sIndex = 1, sStart = 1;
  1776.  
  1777.    if (sHeight == sCellSize[0][1] && sWidth == sCellSize[0][0])
  1778.       return 0;
  1779.  
  1780.    if (VideoData.usAdapterType == 3)
  1781.       sStart = 2;
  1782.    else if (VideoData.usAdapterType == 7)
  1783.       sStart = 3;
  1784.    for (i = sStart; i < 10; i++, sIndex++ )
  1785.       if (sHeight == sCellSize[i][1] && sWidth == sCellSize[i][0])
  1786.      break;
  1787.    return sIndex;
  1788. }
  1789. //------------------------------------------------------------------
  1790. //  Configure Dialog Box
  1791. //------------------------------------------------------------------
  1792. MRESULT EXPENTRY ConfigDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1793.    {
  1794.    static   SHORT    sSelect;
  1795.    static   CHAR     szAttribute[2];
  1796.    static   SHORT    sCHeight;
  1797.    static   SHORT    sCWidth;
  1798.    static   SHORT    sTabStop;
  1799.    static   BOOL     fDispASCII;
  1800.    static   BOOL     fScrollBars;
  1801.    static   BOOL     fLocalSaveWinPos;
  1802.  
  1803.    switch (msg) {
  1804.  
  1805.       case WM_INITDLG:
  1806.  
  1807.      szAttribute[1] = Default.szAttribute[1];
  1808.      sCHeight = Default.sCellHeight;
  1809.      sCWidth = Default.sCellWidth;
  1810.      sTabStop = Default.sTabStop;
  1811.      fDispASCII = Default.fDispASCII;
  1812.      fScrollBars = Default.fScrollBars;
  1813.      fLocalSaveWinPos = FALSE;
  1814.  
  1815.      FillColorBox (hwnd, IDD_FCOLOR);
  1816.      FillColorBox (hwnd, IDD_BCOLOR);
  1817.      FillCellSizeBox (hwnd, IDD_CELLSIZE);
  1818.  
  1819.      WinSendDlgItemMsg (hwnd, IDD_BCOLOR, LM_SELECTITEM,
  1820.            MPFROM2SHORT (((szAttribute[1]>>4) & 0x0f), 0),
  1821.            MPFROM2SHORT (TRUE,0));
  1822.  
  1823.      WinSendDlgItemMsg (hwnd, IDD_FCOLOR, LM_SELECTITEM,
  1824.            MPFROM2SHORT ((szAttribute[1] & 0x0f), 0),
  1825.            MPFROM2SHORT (TRUE,0));
  1826.  
  1827.      WinSendDlgItemMsg (hwnd, IDD_CELLSIZE, LM_SELECTITEM,
  1828.            MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
  1829.            MPFROM2SHORT (TRUE,0));
  1830.  
  1831.      WinSendDlgItemMsg (hwnd, IDD_DEFASCII, BM_SETCHECK,
  1832.                 MPFROM2SHORT (fDispASCII, 0), NULL);
  1833.  
  1834.      WinSendDlgItemMsg (hwnd, IDD_DEFHEX, BM_SETCHECK,
  1835.                 MPFROM2SHORT (!fDispASCII, 0), NULL);
  1836.  
  1837.      WinSendDlgItemMsg (hwnd, IDD_DEFSCROLL, BM_SETCHECK,
  1838.                 MPFROM2SHORT (fScrollBars, 0), NULL);
  1839.  
  1840.      WinSendDlgItemMsg (hwnd, IDD_SAVEWINPOS, BM_SETCHECK,
  1841.                 MPFROM2SHORT (fLocalSaveWinPos, 0), NULL);
  1842.  
  1843.      WinSendDlgItemMsg (hwnd, IDD_SAVE, BM_SETCHECK,
  1844.                 MPFROM2SHORT (fSaveToDisk, 0), NULL);
  1845.  
  1846.      WinSetDlgItemShort ( hwnd, IDD_DEFTABS, sTabStop, FALSE);
  1847.      return 0;
  1848.  
  1849.       case WM_CONTROL:
  1850.  
  1851.      if (SHORT1FROMMP (mp1) == IDD_BCOLOR     ||
  1852.          SHORT1FROMMP (mp1) == IDD_FCOLOR     ||
  1853.          SHORT1FROMMP (mp1) == IDD_CELLSIZE) {
  1854.         sSelect = (USHORT) WinSendDlgItemMsg (hwnd,
  1855.               SHORT1FROMMP (mp1), LM_QUERYSELECTION, 0L, 0L);
  1856.      }
  1857.      switch (SHORT1FROMMP (mp1)) {
  1858.  
  1859.         case IDD_BCOLOR:
  1860.            switch (SHORT2FROMMP (mp1)) {
  1861.  
  1862.           case LN_SELECT:
  1863.  
  1864.              szAttribute[1] = (szAttribute[1] & 0x0f)
  1865.                       | ((sSelect << 4) & 0xf0);
  1866.              return 0;
  1867.            }
  1868.            break;
  1869.  
  1870.         case IDD_FCOLOR:
  1871.            switch (SHORT2FROMMP (mp1)) {
  1872.  
  1873.           case LN_SELECT:
  1874.  
  1875.              szAttribute[1] = (szAttribute[1] & 0xf0)
  1876.                       | (sSelect & 0x0f);
  1877.              return 0;
  1878.            }
  1879.            break;
  1880.  
  1881.         case IDD_CELLSIZE:
  1882.            switch (SHORT2FROMMP (mp1)) {
  1883.  
  1884.           case LN_SELECT:
  1885.  
  1886.              if (sSelect != 0)
  1887.             switch (VideoData.usAdapterType) {
  1888.                case 3:               //VGA
  1889.                   sSelect++;
  1890.                   break;
  1891.  
  1892.                case 7:               //8514
  1893.                   sSelect += 2;
  1894.                   break;
  1895.             }
  1896.              sCHeight = sCellSize [sSelect][1];
  1897.              sCWidth = sCellSize [sSelect][0];
  1898.              return 0;
  1899.            }
  1900.            break;
  1901.  
  1902.         case IDD_DEFASCII:
  1903.            switch (SHORT2FROMMP (mp1)) {
  1904.  
  1905.           case BN_CLICKED:
  1906.              fDispASCII = TRUE;
  1907.              return 0;
  1908.            }
  1909.            break;
  1910.  
  1911.         case IDD_DEFHEX:
  1912.            switch (SHORT2FROMMP (mp1)) {
  1913.  
  1914.           case BN_CLICKED:
  1915.              fDispASCII = FALSE;
  1916.              return 0;
  1917.            }
  1918.            break;
  1919.  
  1920.         case IDD_DEFSCROLL:
  1921.            switch (SHORT2FROMMP (mp1)) {
  1922.  
  1923.           case BN_CLICKED:
  1924.              if (fScrollBars)
  1925.             fScrollBars = FALSE;
  1926.              else
  1927.             fScrollBars = TRUE;
  1928.              return 0;
  1929.            }
  1930.            break;
  1931.  
  1932.         case IDD_SAVEWINPOS:
  1933.            switch (SHORT2FROMMP (mp1)) {
  1934.  
  1935.           case BN_CLICKED:
  1936.              if (fLocalSaveWinPos)
  1937.             fLocalSaveWinPos = FALSE;
  1938.              else
  1939.             fLocalSaveWinPos = TRUE;
  1940.              return 0;
  1941.            }
  1942.            break;
  1943.  
  1944.         case IDD_SAVE:
  1945.            switch (SHORT2FROMMP (mp1)) {
  1946.  
  1947.           case BN_CLICKED:
  1948.              if (fSaveToDisk)
  1949.             fSaveToDisk = FALSE;
  1950.              else
  1951.             fSaveToDisk = TRUE;
  1952.              return 0;
  1953.            }
  1954.            break;
  1955.      }
  1956.      break;
  1957.  
  1958.       case WM_COMMAND:
  1959.  
  1960.      switch (COMMANDMSG(&msg)->cmd) {
  1961.  
  1962.           case DID_OK:
  1963.              Default.szAttribute[1] = szAttribute[1];
  1964.              Default.sCellHeight = sCHeight;
  1965.              Default.sCellWidth = sCWidth;
  1966.              Default.fDispASCII = fDispASCII;
  1967.              Default.fScrollBars = fScrollBars;
  1968.              WinQueryDlgItemShort (hwnd, IDD_DEFTABS, &sSelect,
  1969.                        FALSE);
  1970.              sSelect = min (max (1, sSelect), AVIOCOLS - 1);
  1971.              Default.sTabStop = sSelect;
  1972.              fSaveWinPos = fLocalSaveWinPos;
  1973.              WinDismissDlg (hwnd, TRUE);
  1974.              return 1;
  1975.  
  1976.           case DID_CANCEL:
  1977.               WinDismissDlg (hwnd, FALSE);
  1978.               return 0;
  1979.      }
  1980.    }
  1981.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1982. }
  1983. //------------------------------------------------------------------
  1984. //  Font Size Dialog Box
  1985. //------------------------------------------------------------------
  1986. MRESULT EXPENTRY FontDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  1987.    {
  1988.    static   SHORT    sSelect;
  1989.    static   SHORT    sCHeight;
  1990.    static   SHORT    sCWidth;
  1991.  
  1992.    switch (msg) {
  1993.  
  1994.       case WM_INITDLG:
  1995.  
  1996.      sCHeight = Default.sCellHeight;
  1997.      sCWidth = Default.sCellWidth;
  1998.  
  1999.      FillCellSizeBox (hwnd, IDD_FONTS);
  2000.  
  2001.      WinSendDlgItemMsg (hwnd, IDD_FONTS, LM_SELECTITEM,
  2002.            MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
  2003.            MPFROM2SHORT (TRUE,0));
  2004.      return 0;
  2005.  
  2006.       case WM_CONTROL:
  2007.  
  2008.      switch (SHORT1FROMMP (mp1)) {
  2009.  
  2010.         case IDD_FONTS:
  2011.            switch (SHORT2FROMMP (mp1)) {
  2012.  
  2013.           case LN_SELECT:
  2014.              sSelect = (USHORT) WinSendDlgItemMsg (hwnd,
  2015.              IDD_FONTS, LM_QUERYSELECTION, 0L, 0L);
  2016.  
  2017.              if (sSelect != 0)
  2018.             switch (VideoData.usAdapterType) {
  2019.                case 3:               //VGA
  2020.                   sSelect++;
  2021.                   break;
  2022.  
  2023.                case 7:               //8514
  2024.                   sSelect += 2;
  2025.                   break;
  2026.             }
  2027.              sCHeight = sCellSize [sSelect][1];
  2028.              sCWidth = sCellSize [sSelect][0];
  2029.              return 0;
  2030.  
  2031.           case LN_ENTER:
  2032.              Default.sCellHeight = sCHeight;
  2033.              Default.sCellWidth = sCWidth;
  2034.              WinDismissDlg (hwnd, TRUE);
  2035.              return 0;
  2036.  
  2037.            }
  2038.            break;
  2039.      }
  2040.      break;
  2041.  
  2042.       case WM_COMMAND:
  2043.  
  2044.      switch (COMMANDMSG(&msg)->cmd) {
  2045.  
  2046.           case DID_OK:
  2047.              Default.sCellHeight = sCHeight;
  2048.              Default.sCellWidth = sCWidth;
  2049.              WinDismissDlg (hwnd, TRUE);
  2050.              return 0;
  2051.  
  2052.           case DID_CANCEL:
  2053.              WinDismissDlg (hwnd, FALSE);
  2054.              return 0;
  2055.      }
  2056.    }
  2057.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  2058. }
  2059.