home *** CD-ROM | disk | FTP | other *** search
- //UTILITIES
- //DOUGLAS BOLING
- //PMVIEW.C
-
- //=============================================================================
- // PMVIEW.C -- A file browse program for the OS/2 Presentation Manager.
- //
- // Copyright (c) 1990 Ziff Communications
- //
- // Written by Douglas Boling
- // Modified by K. L. Singer as follows:
- // 1. Fixed bug when displaying ASCII bytes > 7F in Hex display.
- // 2. Corrected to display found search string as top line of Hex display.
- // 3. Added Hex string search option.
- // 4. Corrected inability to scroll past 64K using vertical scroll slider.
- // 5. Corrected random posiition in top line when using vert. scroll slider.
- // 6. Added Hex offset and Line No. options in Search Goto command.
- // 7. Corrected expanding of Tabs.
- // 8. Corrected Hex display when jumping to/near end of file.
- // 9. Modified End key to go to start of last line (ASCII)/16-byte para (Hex).
- // 10. Corrected repeating lines of text between last CR and last byte of file.
- // 11. Corrected to prevent scrolling of Hex display beyond end of file.
- // 12. Added Hex-EBCDIC display option.
- // 13. Corrected to ensure vertical scroll slider visibility in Hex display.
- // 14. Corrected problem introduced by item 5.
- // 15. Modified Open File Dialog to put name of viewed file at top of list box.
- // 16. Corrected incorrect file name displayed in "Unable to open file" msg.
- // 17. Added file name filter retention between Open File dialogs.
- // 18. Added "New" item on File sub-menu to close file and leave PMVIEW active.
- // 19. Changed shortcut key for Exit to Alt-X (from Alt-E) to conform to CUA.
- // 20. Corrected handling of command line option for slash and upper case.
- // 21. Added command line parameter /M to exclude Min. button from frame wndw.
- // 22. Added mnemonic keys for all dialog box items.
- // 23. Modified Open File dialog box to place file entry field at top of box.
- // 24. Modified all dialog boxes to be centered, when possible, in client wndw.
- // 25. Added capability to include wild cards in cmd line file name as filter.
- // 26. Modified title bar and moved Searching... msg to box to conform to CUA.
- // 27. Added on-line help facility.
- // 28. Corrected window status to be active/focus when executed from CMD.
- // 29. Added option to display file position at the bottom of the display.
- // 30. Added hourglass pointer during waiting periods.
- // 31. Added XGA support and selections for all OS/2 1.3 VIO font sizes.
- // 32. Added ability to accept dragged and dropped file from OS/2 1.3 appl.
- // 33. Added ability to accept dragged and dropped file from File Manager.
- // 34. Fixed file position line scrolling into text area on non-VGA dsply.
- // 35. Circumvented OS/2 1.3 XGA Driver bug and improved font list generation.
- // 36. Corrected error recovery when Open File Name entered is zero length.
- // 37. Added test for valid dragged object file name (from OS/2 2.0 WP/appl.).
- // 38. Increased stack size for OS/2 2.0.
- //=============================================================================
-
- #define INCL_DEV
-
- //#define INCL_WIN
- #define INCL_WINACCELERATORS
- #define INCL_WINBUTTONS
- #define INCL_WINCLIPBOARD
- #define INCL_WINDIALOGS
- #define INCL_WINENTRYFIELDS
- #define INCL_WINERRORS
- #define INCL_WINFRAMECTLS
- #define INCL_WINFRAMEMGR
- #define INCL_WINHELP
- #define INCL_WININPUT
- #define INCL_WINLISTBOXES
- #define INCL_WINMENUS
- #define INCL_WINMESSAGEMGR
- #define INCL_WINENTRYFIELDS
- #define INCL_WINPOINTERS
- #define INCL_WINRECTANGLES
- #define INCL_WINSCROLLBARS
- #define INCL_WINSHELLDATA
- #define INCL_WINSYS
- #define INCL_WINWINDOWMGR
-
- #define INCL_WINSTDDRAG
-
- #define INCL_GPIREGIONS
-
- #define INCL_VIO
- #define INCL_AVIO
-
- #define FM_DRAGOVER 0x300
- #define FM_DROP 0x301
-
- #define NO_OF_VIO_SIZES 100
-
- #define AVIOROWS 98
- #define AVIOCOLS 255
- #define PATHLENGTH 255
- #define BUFFERSIZE 16384
-
- #include <os2.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #include "pmview.h"
-
- #define NULL 0L
-
- MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY MessageDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY AboutDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY FileDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY ConfigDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY GotoDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY SearchDlgProc (HWND, USHORT, MPARAM, MPARAM);
- MRESULT EXPENTRY FontDlgProc (HWND, USHORT, MPARAM, MPARAM);
-
- BOOL TestOpenFile (PCHAR);
- BOOL OpenFile (PCHAR);
- PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
- BOOL *fEndOfFile);
- CHAR GetFileChar (LONG lFilePtr);
- LONG MoveViewPtr (LONG lFilePtr, LONG *ptrRow, BOOL fDispASCII);
- LONG lComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII);
- SHORT sComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII);
- VOID btoa (UCHAR cNum, UCHAR szOut[], BOOL fBlank);
- VOID Myltoa (ULONG lNum, UCHAR szOut[]);
- SHORT atob (UCHAR szHStr[], UCHAR szStr[]);
- SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII);
- VOID DisplayFilePos (HPS hps, HWND hwnd, LONG lFilePtr);
- VOID DispStatusLine (HPS hps, HWND hwnd, CHAR * szStatusText);
- BOOL SearchFile (LONG *lFilePtr);
- VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
- HWND hwndMenu);
- VOID SetASCII (HWND hwndMenu, LONG *lViewPtr);
- VOID SetDispFilePos (HWND hwndMenu);
- VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
- SHORT *psCharHeight);
- VOID CenterDlgBox (HWND hwndDialog, HWND hwndParent);
- VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath);
- VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden);
- VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden);
- VOID FillColorBox (HWND hwnd, SHORT iListID);
- VOID FillCellSizeBox (HWND hwnd, SHORT iListID);
- SHORT GetCellSize (SHORT sHeight, SHORT sWidth);
- HWND StartMessageBox (USHORT idDlg, CHAR * szString);
- VOID EndMessageBox (HWND hwndMsgBox);
- VOID SetClipAVIO (HPS hps, HWND hwnd);
-
- HELPINIT helpinit = {
- sizeof( HELPINIT),
- 0L,
- NULL,
- MAKEP(0xFFFF, ID_RESOURCE),
- 0,
- 0,
- 0,
- 0,
- "PM File View Help Facility",
- CMIC_HIDE_PANEL_ID,
- "pmview.hlp"
- };
-
- struct ParamStruct {
- UCHAR szAttribute[2];
- SHORT sxWinPos;
- SHORT syWinPos;
- SHORT sWinHeight;
- SHORT sWinWidth;
- SHORT sCellHeight;
- SHORT sCellWidth;
- SHORT sTabStop;
- BOOL fDispASCII;
- BOOL fScrollBars;
- BOOL fIncHiddenFiles;
- BOOL fDispEBCDIC;
- BOOL fDispFilePos;
- } Default = {{0x20,0xf0}, -1, 0, 0, 0, -1, -1, 8, TRUE, TRUE, FALSE, FALSE,
- FALSE};
-
- struct FileStruct {
- CHAR szName [PATHLENGTH];
- HFILE hHandle;
- LONG lSize;
- BOOL fValid;
- } File = {"", 0, 0L, FALSE};
-
- FILESTATUS FileInfo;
-
- struct MemBuff {
- USHORT usBSel;
- USHORT usBOff;
- USHORT usDSize;
- LONG lFilePtr;
- SHORT sUseCnt;
- BOOL fValid;
- } Buff[4];
-
- SHORT sCellSize[NO_OF_VIO_SIZES][2];
- SHORT sCellSizeCount;
-
- HAB hab;
- HWND hwndFrame;
- HWND hwndClient;
- HWND hwndHelp;
-
- CHAR szNewFile[PATHLENGTH] = "";
- CHAR szWildCardFilename[PATHLENGTH];
- LONG lNewViewPtr;
-
- LONG lRowNumber = 1L;
- LONG lRowPointer = 0L;
- LONG lLastRowNumber = 0L;
- LONG lLastRow = 0L;
-
- CHAR szSearchStr[80];
- CHAR sSearchStr[80];
- CHAR szSearchHStr[80];
- SHORT cbSearchStrLen;
- BOOL fCheckCase = FALSE;
- BOOL fTopSearch = FALSE;
- BOOL fHexString = FALSE;
- BOOL fHexGoto = FALSE;
- BOOL fLineGoto = FALSE;
- BOOL fDecGoto = TRUE;
- LONG lLastFound = -1;
-
- BOOL fSaveWinPos;
- BOOL fSaveToDisk = FALSE;
- BOOL fMinimized;
- CHAR szAppName[] = "PMVIEW by Douglas Boling";
- CHAR szKeyName[] = "Profile type 1";
-
- CHAR szStartTitleText[80];
-
- BOOL fNoMinButton = FALSE;
-
- // 0/8 1/9 2/A 3/B 4/C 5/D 6/E 7/F
- UCHAR caEBtoASCII[256] = { 0x22,0x22,0x22,0x22,0x22,0x9E,0x22,0x22, //0
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //0
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //1
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //1
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //2
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //2
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //3
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, //3
- 0x20,0x5B,0x5D,0x9C,0x9D,0x9E,0x0F,0xE1, //4
- 0x15,0xC4,0x9B,0x2E,0x3C,0x28,0x2B,0xB3, //4
- 0x26,0xF8,0x20,0x5E,0x22,0x27,0x87,0x85, //5
- 0x8A,0x8D,0x21,0x24,0x2A,0x29,0x2B,0xAA, //5
- 0x2D,0x2F,0x95,0x97,0x61,0x6F,0x98,0x85, //6
- 0x84,0x82,0x7C,0x2C,0x25,0x5F,0x3E,0x3F, //6
- 0x8D,0x95,0x97,0x81,0x87,0x84,0x89,0x8B, //7
- 0x94,0x60,0x3A,0x23,0x40,0x27,0x3D,0x22, //7
- 0x81,0x61,0x62,0x63,0x64,0x65,0x66,0x67, //8
- 0x68,0x69,0x83,0x88,0x8C,0x93,0x96,0xA0, //8
- 0x82,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70, //9
- 0x71,0x72,0xA1,0xA2,0xA3,0xA4,0x41,0x45, //9
- 0x49,0x7E,0x73,0x74,0x75,0x76,0x77,0x78, //A
- 0x79,0x7A,0x4F,0x55,0x41,0x4F,0x59,0x4A, //A
- 0x45,0x45,0x49,0x4F,0x55,0x59,0x53,0x8E, //B
- 0x45,0x49,0x99,0x9A,0x41,0x45,0x49,0x4F, //B
- 0x7B,0x41,0x42,0x43,0x44,0x45,0x46,0x47, //C
- 0x48,0x49,0x55,0x41,0x90,0x49,0x20,0x20, //C
- 0x7D,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50, //D
- 0x51,0x52,0x4F,0x55,0xA5,0x20,0x20,0x20, //D
- 0x5C,0x91,0x53,0x54,0x55,0x56,0x57,0x58, //E
- 0x59,0x5A,0xED,0x86,0x87,0x20,0x20,0x3B, //E
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, //F
- 0x38,0x39,0x91,0xED,0x8F,0x80,0x2A,0x20};//F
-
- //=======================================================================
- // Main Proceedure. Create message queue, parse the command line,
- // allocate memory buffers, create the window, and process the
- // message queue.
- //=======================================================================
- int main (int argc, char *argv[])
- {
- static CHAR szClientClass [] = "PMVIEW";
-
- static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
- FCF_SIZEBORDER | FCF_MINMAX |
- FCF_TASKLIST | FCF_ICON |
- FCF_MENU | FCF_ACCELTABLE |
- FCF_VERTSCROLL | FCF_HORZSCROLL |
- FCF_SHELLPOSITION;
-
- static SHORT fsWinPosFlags = SWP_SHOW;
- static USHORT usSelector;
- HMQ hmq;
- QMSG qmsg;
- SHORT i;
-
- if ( !(hab = WinInitialize (0)) )
- exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
-
- if ( !(hmq = WinCreateMsgQueue (hab, 0)) )
- exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
-
- hwndHelp = WinCreateHelpInstance( hab, &helpinit);
-
- fNoMinButton = FALSE;
-
- for (i = 1; i < argc && i < 4; i++)
- if (stricmp(argv[i],"/i") == 0 || stricmp (argv[i],"-i") == 0)
- {
- fMinimized = TRUE;
- fsWinPosFlags |= SWP_MINIMIZE;
- }
- else
- {
- fsWinPosFlags |= SWP_FOCUSACTIVATE | SWP_ACTIVATE;
- if (stricmp(argv[i],"/m") == 0 || stricmp (argv[i],"-m") == 0)
- {
- fNoMinButton = TRUE;
- }
- else
- {
- if (strlen (szNewFile) == 0)
- DosQPathInfo (argv[i], 5, szNewFile, sizeof szNewFile, 0L);
- }
- }
- if ( (strchr (szNewFile, '*') != 0) ||
- (strchr (szNewFile, '?') != 0) )
- {
- strcpy (szWildCardFilename, szNewFile);
- *szNewFile = '\0';
- }
- else
- *szWildCardFilename = '\0';
-
- DosAllocSeg( (USHORT) 0, &usSelector, 0 );
- for (i = 0; i < 4; i++) {
- Buff[i].usBSel = usSelector;
- Buff[i].usBOff = i * BUFFERSIZE;
- Buff[i].fValid = FALSE;
- }
- i = sizeof Default;
- WinQueryProfileData (hab, szAppName, szKeyName, &Default, &i);
-
- WinRegisterClass (
- hab, // Anchor block handle
- szClientClass, // Name of class being registered
- ClientWndProc, // Window procedure for class
- CS_SIZEREDRAW, // Class style
- 0); // Extra bytes to reserve
-
- if (fNoMinButton)
- flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
- FCF_SIZEBORDER | FCF_MAXBUTTON |
- FCF_TASKLIST | FCF_ICON |
- FCF_MENU | FCF_ACCELTABLE |
- FCF_VERTSCROLL | FCF_HORZSCROLL |
- FCF_SHELLPOSITION;
- else
- flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
- FCF_SIZEBORDER | FCF_MINMAX |
- FCF_TASKLIST | FCF_ICON |
- FCF_MENU | FCF_ACCELTABLE |
- FCF_VERTSCROLL | FCF_HORZSCROLL |
- FCF_SHELLPOSITION;
-
- hwndFrame = WinCreateStdWindow (
- HWND_DESKTOP, // Parent window handle
- 0L, // Style of frame window
- &flFrameFlags, // Pointer to control data
- szClientClass, // Client window class name
- "", // Title bar text
- 0L, // Style of client window
- (HMODULE) NULL, // Module handle for resources
- ID_RESOURCE, // ID of resources for window
- &hwndClient); // Pointer to client window handle
-
- if ((NULL == hwndFrame) || (NULL == hwndClient)) {
- /* Make sure the window was created. */
- exit((USHORT)ERRORIDERROR(WinGetLastError(hab)));
- } /* endif */
-
- WinSetWindowUShort(hwndFrame, QWS_ID, ID_RESOURCE);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwndFrame);
-
- if (Default.sxWinPos != -1)
- fsWinPosFlags |= SWP_MOVE | SWP_SIZE;
-
- WinSetWindowPos (hwndFrame, HWND_TOP, Default.sxWinPos, Default.syWinPos,
- Default.sWinWidth, Default.sWinHeight, fsWinPosFlags);
-
- while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
- WinDispatchMsg (hab, &qmsg);
-
- if (File.hHandle)
- DosClose (File.hHandle);
- DosFreeSeg (usSelector);
-
- WinDestroyWindow (hwndFrame);
- if (hwndHelp != NULL)
- WinDestroyHelpInstance( hwndHelp);
- WinDestroyMsgQueue (hmq);
- WinTerminate (hab);
- return 0;
- }
- //------------------------------------------------------------------
- // Test opening file. Open the file and close it. Return TRUE if
- // successful.
- //------------------------------------------------------------------
- BOOL TestOpenFile (PCHAR szNewFileName) {
-
- HFILE hNewHandle;
- USHORT usAction;
- BOOL fGoodRead = FALSE;
-
- if (DosOpen (
- szNewFileName, // File name
- &hNewHandle, // File handle
- &usAction, // Action taken
- 0L, // File size
- 0, // File attribute
- 1, // Open type (Fail if no file.)
- 0x20, // Open mode (Read, deny write)
- 0L)) // Reserved.
- ;
- else {
- if (hNewHandle)
- DosClose (hNewHandle);
- fGoodRead = TRUE;
- }
- return fGoodRead;
- }
- //------------------------------------------------------------------
- // Open file. Open the file, query file information, reset memory
- // buffer structure.
- //------------------------------------------------------------------
- BOOL OpenFile (PCHAR szNewFileName) {
-
- SHORT i;
- HFILE hNewHandle;
- USHORT usAction;
- BOOL fGoodRead = FALSE;
-
- if (DosOpen (
- szNewFileName, // File name
- &hNewHandle, // File handle
- &usAction, // Action taken
- 0L, // File size
- 0, // File attribute
- 1, // Open type (Fail if no file.)
- 0x20, // Open mode (Read, deny write)
- 0L)) // Reserved.
- WinAlarm (HWND_DESKTOP, WA_NOTE);
- else {
- if (File.hHandle)
- DosClose (File.hHandle);
- strcpy (File.szName, szNewFileName);
- File.hHandle = hNewHandle;
- DosQFileInfo (File.hHandle, 1, (PBYTE) &FileInfo,
- sizeof FileInfo);
- File.lSize = FileInfo.cbFile;
- fGoodRead = TRUE;
- //
- // Reset the memory buffer to purge the old file data.
- //
- for (i = 0; i < 4; i++) {
- Buff[i].lFilePtr = -1;
- Buff[i].sUseCnt = 1;
- }
- }
- return fGoodRead;
- }
- //------------------------------------------------------------------
- // GetFileDataPtr - Return a pointer to file data pointed to by
- // the file pointer.
- //------------------------------------------------------------------
- PCHAR GetFileDataPtr (LONG lFilePtr, BOOL fForward, USHORT *usLimit,
- BOOL *fEndOfFile) {
- PCHAR pcDataPtr;
- ULONG ulTemp;
- SHORT i, sLast = -1;
- SHORT sOldCnt, sNewCnt;
- //
- // Check limits of file.
- //
- *fEndOfFile = FALSE;
- if (lFilePtr >= File.lSize) {
- lFilePtr = File.lSize;
- *fEndOfFile = fForward;
- } else if (lFilePtr <= 0L) {
- lFilePtr = 0L;
- *fEndOfFile = !fForward;
- }
- //
- // See if requested part of the file is in one of the buffers.
- //
- sOldCnt = sNewCnt = Buff[0].sUseCnt;
- for (i = 0; i < 4; i++) {
- sNewCnt = (sNewCnt < Buff[i].sUseCnt) ? Buff[i].sUseCnt : sNewCnt;
- sOldCnt = (sOldCnt > Buff[i].sUseCnt) ? Buff[i].sUseCnt : sOldCnt;
- if (Buff[i].lFilePtr != -1)
- if (lFilePtr >= Buff[i].lFilePtr &&
- lFilePtr < Buff[i].lFilePtr + BUFFERSIZE)
- sLast = i;
- }
- //
- // If requested part not found, determine the oldest buffer to replace,
- // then read part of the file into that buffer.
- //
- if (sLast == -1) {
- sOldCnt = Buff[0].sUseCnt;
- for (i = 0; i < 4; i++)
- if (sOldCnt >= Buff[i].sUseCnt) {
- sOldCnt = Buff[i].sUseCnt;
- sLast = i;
- }
- Buff[sLast].fValid = TRUE;
- Buff[sLast].lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE;
-
- DosChgFilePtr (File.hHandle, Buff[sLast].lFilePtr, 0, &ulTemp);
-
- DosRead (File.hHandle, MAKEP (Buff[sLast].usBSel,
- Buff[sLast].usBOff), BUFFERSIZE,
- &Buff[sLast].usDSize);
- }
- //
- // Reset LRU count to prevent overflow
- //
- if (sNewCnt > 0x7ff0) {
- sNewCnt -= sOldCnt;
- for (i = 0; i < 4; i++)
- Buff[i].sUseCnt = Buff[i].sUseCnt - sOldCnt;
- }
- Buff[sLast].sUseCnt = ++sNewCnt;
- //
- // Create Pointer, set limits to buffer.
- //
- pcDataPtr = MAKEP (Buff[sLast].usBSel, Buff[sLast].usBOff
- + (USHORT) (lFilePtr - Buff[sLast].lFilePtr));
- if (fForward)
- *usLimit = Buff[sLast].usBOff + Buff[sLast].usDSize - 1;
- else
- *usLimit = Buff[sLast].usBOff;
-
- return pcDataPtr;
- }
- //------------------------------------------------------------------
- // GetChar - Get character in file at requested file pointer position
- //------------------------------------------------------------------
- CHAR GetFileChar (LONG lFilePtr) {
-
- USHORT usLimit;
- BOOL fEndOfFile;
-
- if (File.fValid)
- return *GetFileDataPtr (lFilePtr, TRUE, &usLimit, &fEndOfFile);
- else
- return '\0';
- }
- //------------------------------------------------------------------
- // MoveViewPtr - Update view pointer by scrolling the number of
- // lines specified in ptrRow. If limited by the top or bottom
- // of the file, modify ptrRow to indicate the actual number of
- // rows.
- //------------------------------------------------------------------
- LONG MoveViewPtr (LONG lFilePtr, LONG *ptrRow, BOOL fDispASCII) {
- SHORT j;
- LONG li;
- LONG lRow, lRowCount = 0L;
- LONG lOffset = 0L;
- LONG lOffsetLastCR = 0L;
- USHORT usLimit;
- PCHAR pcDataPtr;
- BOOL fEndOfFile;
-
- pcDataPtr = GetFileDataPtr (lFilePtr, *ptrRow > 0, &usLimit, &fEndOfFile);
- lRow = *ptrRow;
-
- if (fDispASCII) {
-
- if (lRow > 0L) {
- for (li=0; li < lRow && !fEndOfFile; li++, lOffset++){
-
- for (j=0; j < AVIOCOLS && *pcDataPtr != 0x0d
- && !fEndOfFile; j++, lOffset++)
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else {
- lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
- pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
- &usLimit, &fEndOfFile);
- }
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else {
- lFilePtr = ((lFilePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
- pcDataPtr = GetFileDataPtr (lFilePtr, TRUE,
- &usLimit, &fEndOfFile);
- }
- if (!fEndOfFile) {
- lRowCount++;
- lOffsetLastCR = lOffset + 1;
- }
- }
- if (fEndOfFile) {
- lOffset = lOffsetLastCR;
- }
- *ptrRow = lRowCount;
- } else {
- lRow = -lRow;
- for (li=0; li < lRow && !fEndOfFile; li++){
-
- if ((OFFSETOF(pcDataPtr) > usLimit))
- pcDataPtr--;
- else {
- lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
- pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
- &usLimit, &fEndOfFile);
- }
- if (!fEndOfFile) {
- lRowCount--;
- lOffset--;
- }
- for (j=0; j < AVIOCOLS && !fEndOfFile; j++) {
- if ((OFFSETOF(pcDataPtr) > usLimit)) {
- if (*(pcDataPtr-1) == 0x0d)
- break;
- pcDataPtr--;
- } else {
- lFilePtr = (lFilePtr / BUFFERSIZE) * BUFFERSIZE - 1;
- pcDataPtr = GetFileDataPtr (lFilePtr, FALSE,
- &usLimit, &fEndOfFile);
- }
- if (!fEndOfFile) {
- lOffset--;
- }
- }
- }
- *ptrRow = lRowCount;
- }
- }
-
- else {
- //
- // Align on paragraph
- //
- if (lFilePtr % 16 != 0)
- lOffset -= (lFilePtr % 16);
- lOffset += lRow * 16;
- *ptrRow = lRow;
- //
- //Limit Checking
- //
- if ((lFilePtr == 0L && lRow < 0L)
- ||(lFilePtr == File.lSize && lRow > 0L)){
- lOffset = 0L;
- *ptrRow = 0L;
- } else if ((lFilePtr + lOffset) < 0) {
- lOffset = -lFilePtr;
- *ptrRow = lOffset / 16L;
- } else if ((lFilePtr + lOffset) >= File.lSize) {
- if (lFilePtr % 16 == 0)
- lOffset = (File.lSize - lFilePtr - 1L);
- else
- lOffset = (File.lSize - lFilePtr - 2L);
- *ptrRow = lOffset / 16L;
- }
- }
- return lOffset;
- }
- //------------------------------------------------------------------
- // ComputeLines (SHORT) - Compute number of lines between two points in
- // the file. (Faster (SHORT count variable) version)
- //------------------------------------------------------------------
- SHORT sComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII) {
- USHORT usLimit;
- SHORT sCount = 0L;
- PCHAR pcDataPtr;
- BOOL fEndOfFile = FALSE;
-
- pcDataPtr = GetFileDataPtr (lOldPtr, lOldPtr < lNewPtr, &usLimit,
- &fEndOfFile);
- if (fDispASCII)
- if (lOldPtr < lNewPtr) {
- while (lOldPtr < lNewPtr && !fEndOfFile){
- if (*pcDataPtr == 0x0d)
- sCount++;
- lOldPtr++;
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else
- pcDataPtr = GetFileDataPtr (lOldPtr, TRUE, &usLimit,
- &fEndOfFile);
- }
- }
- else {
- while (lOldPtr > lNewPtr && !fEndOfFile) {
- if (*pcDataPtr == 0x0d)
- sCount--;
- lOldPtr--;
- if ((OFFSETOF(pcDataPtr) > usLimit))
- pcDataPtr--;
- else
- pcDataPtr = GetFileDataPtr (lOldPtr, FALSE, &usLimit,
- &fEndOfFile);
- }
- }
- else
- sCount = (SHORT) ((lNewPtr - lOldPtr) / 16);
- return sCount;
- }
- //------------------------------------------------------------------
- // ComputeLines (LONG) - Compute number of lines between two points in
- // the file. (Slower (LONG count variable) version)
- //------------------------------------------------------------------
- LONG lComputeLines (LONG lOldPtr, LONG lNewPtr, BOOL fDispASCII) {
- USHORT usLimit;
- LONG lCount = 0L;
- PCHAR pcDataPtr;
- BOOL fEndOfFile = FALSE;
-
- if (labs(lNewPtr - lOldPtr) > 65536)
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_WAIT,
- FALSE) );
-
- pcDataPtr = GetFileDataPtr (lOldPtr, lOldPtr < lNewPtr, &usLimit,
- &fEndOfFile);
- if (fDispASCII)
- if (lOldPtr < lNewPtr) {
- while (lOldPtr < lNewPtr && !fEndOfFile){
- if (*pcDataPtr == 0x0d)
- lCount++;
- lOldPtr++;
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else
- pcDataPtr = GetFileDataPtr (lOldPtr, TRUE, &usLimit,
- &fEndOfFile);
- }
- }
- else {
- while (lOldPtr > lNewPtr && !fEndOfFile) {
- if (*pcDataPtr == 0x0d)
- lCount--;
- lOldPtr--;
- if ((OFFSETOF(pcDataPtr) > usLimit))
- pcDataPtr--;
- else
- pcDataPtr = GetFileDataPtr (lOldPtr, FALSE, &usLimit,
- &fEndOfFile);
- }
- }
- else
- lCount = ((lNewPtr - lOldPtr) / 16L);
-
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_ARROW,
- FALSE) );
-
- return lCount;
- }
- //------------------------------------------------------------------
- // btoa Convert byte to ASCII
- //------------------------------------------------------------------
- VOID btoa (UCHAR cNum, UCHAR szOut[], BOOL fBlank) {
- SHORT i;
-
- for (i = 2; i > 0; i--)
- if (fBlank)
- szOut[i] = ' ';
- else {
- szOut[i] = (cNum % (UCHAR) 16) + (UCHAR) 0x30;
- if (szOut[i] > 0x39) szOut[i] += (BYTE) 7;
- cNum /= 16;
- }
- szOut[0] = ' ';
- return;
- }
-
- //------------------------------------------------------------------
- // Myltoa Convert a long to ASCII with leading zeros
- //------------------------------------------------------------------
- VOID Myltoa (ULONG lNum, UCHAR szOut[]) {
- SHORT i;
-
- for (i = 7; i >= 0; i--) {
- szOut[i + (i+1)/5] = (BYTE) (lNum % 16) + (CHAR) 0x30;
- if (szOut[i + (i+1)/5] > 0x39) szOut[i + (i+1)/5] += (BYTE) 7;
- lNum /= 16;
- }
- szOut[4] = ' ';
- return;
- }
-
- //------------------------------------------------------------------
- // atob Convert ASCII Hex string to binary string
- //------------------------------------------------------------------
- SHORT atob (UCHAR szHStr[], UCHAR sStr[]) {
- SHORT inyble;
- SHORT ibyte;
- SHORT i;
- SHORT iDigit;
-
- ibyte = 0;
-
- if (strlen(szHStr) != 0) {
- i = 0;
- for (inyble = 0; inyble < (SHORT) strlen(szHStr); inyble++) {
-
- iDigit = (int) (toupper(szHStr[inyble]) - '0');
- if (iDigit > 9)
- iDigit = iDigit - 7;
- if ((iDigit < 0) || (iDigit > 15)) {
- if (i == 1) {
- i = 0;
- ibyte++;
- }
- continue;
- }
-
- if (i == 0) {
- sStr[ibyte] = (UCHAR) iDigit;
- i = 1;
- }
- else {
- sStr[ibyte] = (sStr[ibyte]*(UCHAR)16) + (UCHAR) iDigit;
- i = 0;
- ibyte++;
- }
- }
- }
- return ibyte;
- }
-
- //------------------------------------------------------------------
- // Display Line
- //------------------------------------------------------------------
- SHORT DisplayLine (HVPS hvps, SHORT sRow, LONG lLinePtr, BOOL fDispASCII) {
-
- UCHAR cHexChar, szTempBuff[256];
- SHORT i, sStart, sBytesPrinted = 0;
- USHORT usLimit;
- BOOL fEndOfFile;
- PCHAR pcDataPtr;
-
-
- if (fDispASCII) {
- //
- // Print as ASCII until CR or for 255 characters.
- //
- pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
-
- for (i = 0; i <= AVIOCOLS && !fEndOfFile; i++){
- if (*pcDataPtr == 0x0a) {
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else {
- lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
- pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
- &fEndOfFile);
- }
- if (fEndOfFile)
- szTempBuff[i] = ' ';
- else
- szTempBuff[i] = *pcDataPtr;
- sBytesPrinted++;
- } else
- szTempBuff[i] = *pcDataPtr;
-
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else {
- lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
- pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
- &fEndOfFile);
- }
- sBytesPrinted++;
- //
- // Expand Tab Characters
- //
- if (szTempBuff[i] == 0x09) {
- for (;(i+1) % Default.sTabStop != 0 && i <= AVIOCOLS; i++)
- szTempBuff[i] = ' ';
- szTempBuff[i] = ' ';
- }
- //
- // If CR, end of line.
- if (szTempBuff[i] == 0x0d) {
- break;
- }
- }
- } else {
- //
- // Convert from Hex and print.
- //
- pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit, &fEndOfFile);
- sStart = (SHORT) (lLinePtr % 16L);
- sBytesPrinted = 0;
- for (i = 0; i < 10; i++)
- szTempBuff[i] = ' ';
-
- if (!fEndOfFile)
- Myltoa (lLinePtr, szTempBuff);
-
- for (i = 0; i < 16; i++){
-
- cHexChar = *pcDataPtr;
-
- btoa (cHexChar, szTempBuff + 10 + (i*3) + (i/8),
- ((i < sStart) || fEndOfFile) );
- if (Default.fDispEBCDIC)
- szTempBuff[i+60+(i/8)] = ((i < sStart) || fEndOfFile) ?
- (CHAR) 0x20 : caEBtoASCII[cHexChar];
- else
- szTempBuff[i+60+(i/8)] = ((i < sStart) || fEndOfFile) ? (CHAR) 0x20
- : cHexChar;
-
-
- if (i >= sStart){
- if ((OFFSETOF(pcDataPtr) < usLimit))
- pcDataPtr++;
- else {
- lLinePtr = ((lLinePtr + BUFFERSIZE)/ BUFFERSIZE) * BUFFERSIZE;
- pcDataPtr = GetFileDataPtr (lLinePtr, TRUE, &usLimit,
- &fEndOfFile);
- }
- }
- }
- szTempBuff[34] = ' ';
- szTempBuff[59] = ' ';
- szTempBuff[68] = ' ';
- sBytesPrinted = i - sStart;
- i += 59 + (i/8);
- }
- VioWrtCharStr (szTempBuff, i, sRow, 0, hvps);
- return sBytesPrinted;
- }
- //------------------------------------------------------------------
- // SearchFile - Search the file for the value in szSearchStr or sSearchStr.
- // If found, the file pointer is modified to the location in the
- // file.
- //------------------------------------------------------------------
- BOOL SearchFile (LONG *lFilePtr) {
- USHORT usLimit;
- PCHAR pcDataPtr;
- BOOL fEndOfFile = FALSE, fFound = FALSE;
- CHAR szCmpBuffer[165];
- SHORT sBufferLength, sBufferCnt, sSearchLen, i;
- LONG lLocalPtr, lMarker;
-
-
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_WAIT,
- FALSE) );
- if (fHexString)
- sSearchLen = cbSearchStrLen;
- else
- sSearchLen = strlen (szSearchStr);
-
- lLocalPtr = (fTopSearch) ? 0L : *lFilePtr;
-
- pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit, &fEndOfFile);
-
- while (!fEndOfFile && !fFound) {
-
- sBufferLength = (BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE))
- - sSearchLen;
- if (sBufferLength <= 0) {
-
- for (i = 0; i < BUFFERSIZE - (SHORT)(lLocalPtr % BUFFERSIZE); i++)
- *(szCmpBuffer + i) = *(pcDataPtr + i);
-
- sBufferCnt = i;
- lMarker = lLocalPtr;
- lLocalPtr = ((lLocalPtr + BUFFERSIZE) / BUFFERSIZE) * BUFFERSIZE;
-
- pcDataPtr = GetFileDataPtr (lLocalPtr, TRUE, &usLimit,
- &fEndOfFile);
- if (fEndOfFile)
- break;
- for (i = 0; i < min (sSearchLen + 1,
- BUFFERSIZE - (usLimit % BUFFERSIZE)); i++)
- *(szCmpBuffer + sBufferCnt + i) = *(pcDataPtr + i);
-
- for (i = 0; i < sBufferCnt; i++)
- if (fHexString) {
- if (memcmp (szCmpBuffer + i, sSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- }
- else
- if (fCheckCase) {
- if (strncmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- } else {
- if (strnicmp (szCmpBuffer + i, szSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- }
- sBufferLength = (BUFFERSIZE - (usLimit%BUFFERSIZE)) - sSearchLen;
- }
- if (fFound) {
- lLocalPtr = lMarker + i;
- break;
- }
- for (i = 0; i < sBufferLength; i++) {
- if (fHexString) {
- if (memcmp (pcDataPtr + i, sSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- }
- else
- if (fCheckCase) {
- if (strncmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- } else {
- if (strnicmp (pcDataPtr + i, szSearchStr, sSearchLen) == 0) {
- fFound = TRUE;
- break;
- }
- }
- }
- lLocalPtr += i;
- }
- if (fFound)
- *lFilePtr = lLocalPtr;
-
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_ARROW,
- FALSE) );
- return fFound;
- }
- //------------------------------------------------------------------
- // ScrollVis - Set Scroll Visibility
- //------------------------------------------------------------------
- VOID ScrollVis (HWND hwndFrame, HWND hwndHScroll, HWND hwndVScroll,
- HWND hwndMenu) {
-
- if (Default.fScrollBars) {
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
-
- WinSetParent (hwndVScroll, hwndFrame, FALSE );
- WinSetParent (hwndHScroll, hwndFrame, FALSE );
- } else {
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPSCROLLBARS, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
-
- WinSetParent (hwndVScroll, HWND_OBJECT, FALSE );
- WinSetParent (hwndHScroll, HWND_OBJECT, FALSE );
- }
- WinSendMsg ( hwndFrame , WM_UPDATEFRAME ,
- (MPARAM) (FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
- FCF_MENU), NULL);
-
- return;
- }
- //------------------------------------------------------------------
- // Set ASCII - Set ASCII Menu Check marks.
- //------------------------------------------------------------------
- VOID SetASCII (HWND hwndMenu, LONG *lViewPtr) {
- LONG lRow = -1;
- if (Default.fDispASCII) {
- if (!(MIA_CHECKED && WinSendMsg (hwndMenu, MM_QUERYITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0)))) {
- *lViewPtr += 2;
- *lViewPtr += MoveViewPtr (*lViewPtr, &lRow, TRUE);
- }
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
- } else {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYASCII, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
-
- if (Default.fDispEBCDIC) {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
- } else {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXASC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPLAYHEXEBC, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
- }
- }
- return;
- }
-
-
-
-
- //------------------------------------------------------------------
- // SetDispFilePos - Set File Position Menu Check Marks.
- //------------------------------------------------------------------
- VOID SetDispFilePos (HWND hwndMenu)
- {
- if (Default.fDispFilePos)
- {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPFILEPOS, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
- }
- else
- {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (IDM_DISPFILEPOS, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0));
- }
- }
- //------------------------------------------------------------------
- // SetFontSize - Change font size and update menu if necessary.
- //------------------------------------------------------------------
- VOID SetFontSize (HWND hwndMenu, HVPS hvps, SHORT *psCharWidth,
- SHORT *psCharHeight) {
-
- VioSetDeviceCellSize (Default.sCellHeight, Default.sCellWidth, hvps);
- VioGetDeviceCellSize (psCharHeight, psCharWidth, hvps);
-
- return;
- }
- //=======================================================================
- //
- // Client Window Procedure
- //
- //=======================================================================
- MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- static HWND hwndFrame, hwndMenu, hwndVScroll, hwndHScroll;
-
- static HVPS hvps;
- static HPS hps;
-
- static LONG lViewPtr;
- static BOOL fGoMinimize;
-
- static SHORT sHScroll, sVScrScale, sHPage = 20, sVPage = 20;
- static SHORT sCharHeight, sCharWidth, sxWinSize, syWinSize;
- static SHORT sRowsVisible = AVIOROWS;
- static SHORT syStatusLine = 0;
-
- static CHAR szBuffer[81];
- static CHAR szDragItemRMF[41];
- static CHAR szDropDirectory[81];
- static CHAR szDropFileName[81];
- static CHAR szDropNewFileName[81];
- static BOOL fDropFile = FALSE;
- static SHORT fsWinPosFlags = SWP_SHOW;
-
- static PDRAGINFO pDragInfo;
- static DRAGITEM DragItem;
-
- static CHAR * pszFMFileList;
-
- HDC hdc;
- SIZEL sizl;
- SHORT sRow;
- SHORT sTempRow;
- LONG lRow;
- SHORT sTemp;
- LONG lDeltaRows;
- LONG lTemp;
- SWP swpWinPos;
- PSWP pswpWinPos;
- CHAR szTempBuffer[PATHLENGTH];
- HWND hwndSearchMsg;
- SHORT i;
-
- BOOL fFileNameOK = FALSE;
-
- LONG lOutCount;
-
- struct VioCellStruct {
- VIOSIZECOUNT VioSizeCount;
- VIOFONTCELLSIZE VioCellSize[NO_OF_VIO_SIZES];
- } OutData;
-
- switch (msg) {
-
- //--------------------------------------------------------------
- // When the window is created, get and store the handles to
- // the scroll bars and menu, read the default parameters if
- // saved before, set the proper attributes for the menu
- // selections, and create a AVIO presentation space.
- //--------------------------------------------------------------
- case WM_CREATE:
-
- WinQueryWindowText (hwndFrame,
- sizeof szStartTitleText,
- szStartTitleText);
- strcpy (szStartTitleText, "PM File View");
-
- //
- // If no file specified and not starting as an icon, Query
- // user for a file name.
- //
- if (!File.fValid) {
- if (strlen (szNewFile) == 0) {
- if (!fMinimized)
- if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
- (HMODULE) NULL, IDD_OPEN, (PVOID) NULL))
- if (!(File.fValid = OpenFile (szNewFile)))
- WinMessageBox (HWND_DESKTOP, hwnd,
- "Unable to open the file",
- szNewFile,
- (USHORT) NULL,
- MB_OK | MB_ERROR);
- } else
- if (!(File.fValid = OpenFile (szNewFile)))
- WinMessageBox (HWND_DESKTOP, hwnd,
- "Unable to open the file", szNewFile,
- (USHORT) NULL, MB_OK | MB_ERROR);
- if (File.fValid) {
- if (sHScroll) {
- sHScroll = 0;
- VioSetOrg (0, sHScroll, hvps);
- }
- lViewPtr = 0L;
- lRowNumber = 1L;
- lLastRowNumber = 0L;
- lLastRow = 0L;
- lRowPointer = lViewPtr;
- sVScrScale = (SHORT) ((File.lSize / 32768) + 1);
- }
- }
- fMinimized = FALSE;
- //
- // Query the Frame for the necessary window handles.
- //
- hwndFrame = WinQueryWindow (hwnd, QW_PARENT,FALSE);
- hwndMenu = WinWindowFromID (hwndFrame, FID_MENU);
- hwndVScroll = WinWindowFromID (hwndFrame, FID_VERTSCROLL);
- hwndHScroll = WinWindowFromID ( hwndFrame, FID_HORZSCROLL);
- //
- // Set menu attributes.
- //
- sVScrScale = (SHORT) ((File.lSize / 32768) + 1);
- ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
- SetASCII (hwndMenu, &lViewPtr);
- SetDispFilePos (hwndMenu);
- //
- // Establish AVIO presentation space.
- //
- hdc = WinOpenWindowDC (hwnd);
- sizl.cx = sizl.cy = 0;
- hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT |
- GPIT_MICRO | GPIA_ASSOC);
- VioCreatePS (&hvps, AVIOROWS, AVIOCOLS, 0, 1, (HVPS) NULL);
- VioAssociate (hdc, hvps);
- if ( (Default.sCellWidth <= 0) || (Default.sCellHeight <= 0) )
- VioGetDeviceCellSize (&Default.sCellHeight,
- &Default.sCellWidth,
- hvps);
-
- //
- // Get available font sizes
- //
- DevEscape(hdc, DEVESC_QUERYVIOCELLSIZES,
- 0L,
- (PBYTE) NULL,
- &lOutCount,
- (PBYTE) &OutData);
- sCellSizeCount = (SHORT) OutData.VioSizeCount.count;
- for (i=0; i<sCellSizeCount; i++)
- {
- sCellSize[i][0] = (SHORT) OutData.VioCellSize[i].cx;
- sCellSize[i][1] = (SHORT)OutData.VioCellSize[i].cy;
- }
-
- SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
- VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
-
- if (strlen (File.szName) != 0)
- {
- sprintf (szTempBuffer, "PM File View - %s", File.szName);
- WinSetWindowText (hwndFrame, szTempBuffer);
- }
- else
- WinSetWindowText (hwndFrame, szStartTitleText);
-
- return 0;
-
- //--------------------------------------------------------------
- // Intercept the close message to abort a file open dialog box
- // when the program is closed from an icon.
- //--------------------------------------------------------------
- case WM_CLOSE:
-
- fMinimized = FALSE;
- break;
-
- //--------------------------------------------------------------
- // If the Window is being restored from an icon without a vaild
- // file, prompt the user for a file using the file open dialog
- // box.
- //--------------------------------------------------------------
- case WM_MINMAXFRAME:
-
- if (fMinimized)
- if (!File.fValid) {
- if (WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc, (HMODULE) NULL,
- IDD_OPEN, (PVOID) NULL)) {
- if (!(File.fValid = OpenFile (szNewFile)))
- WinMessageBox (HWND_DESKTOP, hwnd,
- "Unable to open the file",
- szNewFile, (USHORT) NULL,
- MB_OK | MB_ERROR);
- else {
- if (sHScroll) {
- sHScroll = 0;
- VioSetOrg (0, sHScroll, hvps);
- }
- lViewPtr = 0;
- sVScrScale = (SHORT) ((File.lSize / 32768) + 1);
- sprintf (szTempBuffer, "PM File View - %s", File.szName);
- WinSetWindowText (hwndFrame, szTempBuffer);
- }
- } else
- fGoMinimize = TRUE;
- }
- //
- // Record the current state of the program.
- //
- pswpWinPos = PVOIDFROMMP (mp1);
- if (pswpWinPos->fs & SWP_MINIMIZE)
- fMinimized = TRUE;
- else
- fMinimized = FALSE;
- break;
-
- //--------------------------------------------------------------
- // When the GoMinimize flag is set send the frame a minimize
- // message.
- //--------------------------------------------------------------
- case WM_WINDOWPOSCHANGED:
-
- if (fGoMinimize) {
- fGoMinimize = FALSE;
- WinSetWindowPos (hwndFrame, HWND_BOTTOM, 0, 0, 0, 0,
- SWP_MINIMIZE);
- }
- break;
-
- //--------------------------------------------------------------
- // When the window is resized, record the new window size,
- // update the horizontal position of the AVIO space and
- // scroll bar, and notify the frame to modify its windows.
- //--------------------------------------------------------------
- case WM_SIZE:
-
- sxWinSize = SHORT1FROMMP(mp2);
- syWinSize = SHORT2FROMMP(mp2);
-
- // Set Clipping Rectangle to AVIO text area
- SetClipAVIO (hps, hwnd);
-
- if (sHScroll > AVIOCOLS - sxWinSize / sCharWidth) {
- sHScroll = min (max (0, sHScroll),
- AVIOCOLS - sxWinSize / sCharWidth);
- VioSetOrg (0, sHScroll, hvps);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- if (Default.fDispFilePos)
- syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
- else
- syStatusLine = 0;
- sHPage = max (sxWinSize / sCharWidth - 1, 0);
- sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
-
- sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
- AVIOROWS);
-
- WinSendMsg ( hwndFrame, WM_UPDATEFRAME, (MPARAM) (FCF_TITLEBAR
- | FCF_SYSMENU | FCF_MINMAX | FCF_MENU), NULL);
-
- WinSendMsg (hwndHScroll, SBM_SETSCROLLBAR,
- MPFROM2SHORT (sHScroll, 0),
- MPFROM2SHORT (0, AVIOCOLS - sxWinSize / sCharWidth));
-
- WinSendMsg (hwndHScroll, SBM_SETTHUMBSIZE,
- MPFROM2SHORT (sxWinSize / sCharWidth,
- AVIOCOLS - sxWinSize / sCharWidth), NULL);
-
- WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
- MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
- MPFROM2SHORT (0, (SHORT)(File.lSize/sVScrScale)));
-
-
- if ( (SHORT)((syWinSize/sCharHeight) * 30) <
- (SHORT)(File.lSize/sVScrScale) )
- WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
- MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
- (SHORT)(File.lSize/sVScrScale)),NULL);
- else
- WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
- MPFROM2SHORT( (syWinSize/sCharHeight) * 16,
- (SHORT)(File.lSize/sVScrScale)),NULL);
-
- return WinDefAVioWindowProc (hwnd, msg, mp1, mp2);
-
- //--------------------------------------------------------------
- // Repaint the complete AVIO space by first clearing the window
- // then writing to the AVIO space.
- //--------------------------------------------------------------
- case WM_PAINT:
-
- WinBeginPaint (hwnd, hps, NULL);
- VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
-
- lTemp = lViewPtr;
- for (sRow = 0; sRow < sRowsVisible; sRow++)
- lTemp += (LONG) DisplayLine (hvps, sRow, lTemp,
- Default.fDispASCII);
-
- DisplayFilePos (hps, hwnd, lViewPtr);
- WinEndPaint (hps);
-
- WinSendMsg (hwndVScroll, SBM_SETPOS,
- MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0),
- NULL);
- return 0;
-
- //--------------------------------------------------------------
- // Process each menu selection according to function.
- //--------------------------------------------------------------
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case IDM_NEW:
-
- if (File.hHandle)
- DosClose (File.hHandle);
- VioScrollUp (0, 0, -1, -1, -1, Default.szAttribute, hvps);
-
- *File.szName = '\0';
- File.hHandle = NULL;
- File.lSize = 0L;
- File.fValid = FALSE;
- lRowNumber = 1L;
- lLastRowNumber = 0L;
- lLastRow = 0L;
- lRowPointer = 0L;
-
- WinSetWindowText (hwndFrame, szStartTitleText);
-
- WinPostMsg (hwnd, WM_COMMAND,
- MPFROM2SHORT (IDM_OPEN,0), 0L);
-
- return 0;
-
- case IDM_OPEN:
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_WAIT,
- FALSE) );
- if (fDropFile)
- {
- strcpy (szNewFile, szDropNewFileName);
- fFileNameOK = TRUE;
- fDropFile = FALSE;
- if (fMinimized)
- {
- File.fValid = TRUE; /* Necessary to prevent file dialog */
- fsWinPosFlags = SWP_SHOW | SWP_RESTORE;
- fsWinPosFlags |= SWP_FOCUSACTIVATE | SWP_ACTIVATE;
- if (Default.sxWinPos != -1)
- fsWinPosFlags |= SWP_MOVE | SWP_SIZE;
- WinSetWindowPos (hwndFrame, HWND_TOP, Default.sxWinPos,
- Default.syWinPos,
- Default.sWinWidth,
- Default.sWinHeight,
- fsWinPosFlags);
- fMinimized = FALSE;
- }
- }
- else
- {
- fFileNameOK = WinDlgBox(HWND_DESKTOP, hwnd, FileDlgProc,
- (HMODULE) NULL, IDD_OPEN, (PVOID) NULL);
- }
- if (fFileNameOK) {
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_ARROW,
- FALSE) );
- if (File.fValid = OpenFile (szNewFile)) {
- if (sHScroll) {
- sHScroll = 0;
- VioSetOrg (0, sHScroll, hvps);
- }
- lViewPtr = 0;
- lLastRowNumber = 0L;
- lLastRow = 0L;
- lRowNumber = 1L;
- lRowPointer = lViewPtr;
-
- sVScrScale = (SHORT) ((File.lSize / 32768) + 1);
-
- WinSendMsg (hwndVScroll, SBM_SETSCROLLBAR,
- MPFROM2SHORT (0, 0),
- MPFROM2SHORT (0,
- (SHORT)(File.lSize/sVScrScale)));
- if ( (SHORT)((syWinSize/sCharHeight) * 30) <
- (SHORT)(File.lSize/sVScrScale) )
- WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
- MPFROM2SHORT( (syWinSize/sCharHeight) * 30,
- (SHORT)(File.lSize/sVScrScale)),NULL);
- else
- WinSendMsg (hwndVScroll, SBM_SETTHUMBSIZE,
- MPFROM2SHORT( (syWinSize/sCharHeight) * 16,
- (SHORT)(File.lSize/sVScrScale)),NULL);
- sprintf (szTempBuffer, "PM File View - %s", File.szName);
- WinSetWindowText (hwndFrame, szTempBuffer);
- WinInvalidateRect (hwnd, NULL, FALSE);
- } else {
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_ARROW,
- FALSE) );
- WinMessageBox (HWND_DESKTOP, hwnd, "Unable to open the file",
- szNewFile, (USHORT) NULL, MB_OK | MB_ERROR);
- }
- }
- return 0;
-
- case IDM_FIND:
- if (WinDlgBox(HWND_DESKTOP, hwnd, SearchDlgProc,
- (HMODULE) NULL, IDD_SEARCH, (PVOID) NULL)) {
- if (fHexString) {
- if (strlen (szSearchHStr) != 0)
- WinPostMsg (hwnd, WM_COMMAND,
- MPFROM2SHORT (IDM_REPFIND,0), mp2);
- }
- else
- if (strlen (szSearchStr) != 0)
- WinPostMsg (hwnd, WM_COMMAND,
- MPFROM2SHORT (IDM_REPFIND,0), mp2);
- }
- return 0;
-
- case IDM_REPFIND:
- if ( ((fHexString) && (strlen (szSearchHStr) == 0)) ||
- ((!fHexString) && (strlen (szSearchStr) == 0)) ) {
- WinPostMsg (hwnd, WM_COMMAND, MPFROM2SHORT (IDM_FIND,0),
- mp2);
- return 0;
- } else {
- //
- // Check to see if we are on the same line as the last
- // found string. If so, start search at 1 byte past
- // last found string.
- //
- lDeltaRows = 1L;
- lTemp = MoveViewPtr (lViewPtr, &lDeltaRows,
- Default.fDispASCII);
- lTemp += lViewPtr;
-
- if (lTemp > lLastFound && lLastFound >= lViewPtr)
- lLastFound++;
- else
- lLastFound = lViewPtr;
- //
- // If string found, back up to the start of the
- // current line.
- //
- hwndSearchMsg = StartMessageBox (IDD_SRCHMSG, "");
- if (SearchFile (&lLastFound)) {
-
- lViewPtr = lLastFound;
- if (!Default.fDispASCII)
- lDeltaRows = 0L;
- else
- lDeltaRows = -1L;
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows,
- Default.fDispASCII);
- WinInvalidateRect (hwnd, NULL, FALSE);
- EndMessageBox (hwndSearchMsg);
- } else {
- EndMessageBox (hwndSearchMsg);
- if (fHexString)
- WinMessageBox (HWND_DESKTOP, hwnd, szSearchHStr,
- "Unable to find the hex string",
- (USHORT) NULL, MB_OK | MB_ICONHAND);
- else
- WinMessageBox (HWND_DESKTOP, hwnd, szSearchStr,
- "Unable to find the string",
- (USHORT) NULL, MB_OK | MB_ICONHAND);
- }
- }
- return 0;
-
- case IDM_GOTO:
- if (WinDlgBox(HWND_DESKTOP, hwnd, GotoDlgProc,
- (HMODULE) NULL, IDD_GOTO, (PVOID) NULL)) {
- lViewPtr = min (max (lNewViewPtr, 0L), File.lSize);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- return 0;
-
- case IDM_CONFIGURE:
- if (WinDlgBox(HWND_DESKTOP, hwnd, ConfigDlgProc,
- (HMODULE) NULL, IDD_CONFIGURE, (PVOID) NULL)) {
- if (fSaveToDisk) {
- if (fSaveWinPos) {
- WinQueryWindowPos (hwndFrame, &swpWinPos);
- Default.sxWinPos = swpWinPos.x;
- Default.syWinPos = swpWinPos.y;
- Default.sWinWidth = swpWinPos.cx;
- Default.sWinHeight = swpWinPos.cy;
- }
- WinWriteProfileData (hab, szAppName, szKeyName,
- &Default, sizeof Default);
- }
- SetASCII(hwndMenu, &lViewPtr);
- SetDispFilePos(hwndMenu);
- ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
- SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
- if (Default.fDispFilePos)
- syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
- SV_CYMENU);
- else
- syStatusLine = 0;
- sHPage = max (sxWinSize / sCharWidth - 1, 0);
- sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
- sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
- AVIOROWS);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- return 0;
-
- case IDM_DISPLAYASCII:
- if (!Default.fDispASCII) {
- Default.fDispASCII = TRUE;
- SetASCII (hwndMenu, &lViewPtr);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- return 0;
-
- case IDM_DISPLAYHEXASC:
- if ((Default.fDispASCII) || (Default.fDispEBCDIC)) {
- Default.fDispASCII = FALSE;
- Default.fDispEBCDIC = FALSE;
- SetASCII (hwndMenu, &lViewPtr);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- return 0;
-
- case IDM_DISPLAYHEXEBC:
- if ((Default.fDispASCII) || (!Default.fDispEBCDIC)) {
- Default.fDispASCII = FALSE;
- Default.fDispEBCDIC = TRUE;
- SetASCII (hwndMenu, &lViewPtr);
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- return 0;
-
- case IDM_DISPSCROLLBARS:
- if (Default.fScrollBars)
- Default.fScrollBars = FALSE;
- else
- Default.fScrollBars = TRUE;
-
- ScrollVis (hwndFrame, hwndHScroll, hwndVScroll, hwndMenu);
- return 0;
-
- case IDM_DISPFILEPOS:
- if (Default.fDispFilePos)
- Default.fDispFilePos = FALSE;
- else
- Default.fDispFilePos = TRUE;
-
- SetDispFilePos (hwndMenu);
- if (Default.fDispFilePos)
- syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
- SV_CYMENU);
- else
- {
- syStatusLine = 0;
- }
-
- sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
- sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
- AVIOROWS);
-
- // Set Clipping Rectangle to AVIO text area
- SetClipAVIO (hps, hwnd);
-
- WinInvalidateRect (hwnd, NULL, FALSE);
- return 0;
-
- case IDM_FONTSIZE:
- if (!WinDlgBox(HWND_DESKTOP, hwnd, FontDlgProc,
- (HMODULE) NULL, IDD_PICKFONT, (PVOID) NULL))
- return 0;
- SetFontSize (hwndMenu, hvps, &sCharWidth, &sCharHeight);
- if (Default.fDispFilePos)
- syStatusLine = (SHORT) WinQuerySysValue (HWND_DESKTOP,
- SV_CYMENU);
- else
- syStatusLine = 0;
- sHPage = max (sxWinSize / sCharWidth - 1, 0);
- sVPage = max ((syWinSize-syStatusLine) / sCharHeight - 1, 0);
- sRowsVisible = min ((syWinSize-syStatusLine) / sCharHeight + 1,
- AVIOROWS);
- WinInvalidateRect (hwnd, NULL, FALSE);
- return 0;
-
- case IDM_ABOUT:
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,
- (HMODULE) NULL, IDD_ABOUT, (PVOID) NULL);
- return 0;
-
- case IDM_EXIT:
- WinSendMsg(hwnd, WM_CLOSE, 0L, 0L);
- return 0;
-
- case IDM_HELPFORHELP:
- if (hwndHelp != NULL)
- {
- WinSendMsg( hwndHelp, HM_DISPLAY_HELP, 0L, 0L);
- return 0;
- }
- break;
-
- case IDM_EXTENDEDHELP:
- if (hwndHelp != NULL)
- {
- WinSendMsg( hwndHelp, HM_EXT_HELP, 0L, 0L);
- return 0;
- }
- break;
-
- case IDM_KEYSHELP:
- if (hwndHelp != NULL)
- {
- WinSendMsg( hwndHelp, HM_KEYS_HELP, 0L, 0L);
- return 0;
- }
- break;
-
- case IDM_HELPINDEX:
- if (hwndHelp != NULL)
- {
- WinSendMsg( hwndHelp, HM_HELP_INDEX, 0L, 0L);
- return 0;
- }
- break;
-
- }
- break;
-
- case WM_HELP:
- return (WinDefWindowProc(hwnd, msg, mp1, mp2));
- break; /* let the default handle it */
-
- case HM_QUERY_KEYS_HELP:
- return (MRESULT) IDM_KEYSHELP;
-
- case HM_ERROR:
- WinMessageBox( HWND_DESKTOP, hwnd,
- "A Help Manager error was encountered.",
- "Help Manager Error", 0, MB_OK | MB_WARNING);
- return 0;
-
- //--------------------------------------------------------------
- // Convert cursor keys to scroll bar messages.
- //--------------------------------------------------------------
- case WM_CHAR:
-
- switch (CHARMSG (&msg) -> vkey) {
-
- case VK_UP:
- case VK_DOWN:
- case VK_PAGEUP:
- case VK_PAGEDOWN:
- return WinSendMsg (hwndVScroll, msg, mp1, mp2);
-
- case VK_LEFT:
- case VK_RIGHT:
- return WinSendMsg (hwndHScroll, msg, mp1, mp2);
-
- case VK_HOME:
- if (lViewPtr != 0) {
- lViewPtr = 0L;
- lRowNumber = 1L;
- lRowPointer = 0L;
-
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- break;
-
- case VK_END:
- if (lViewPtr != File.lSize - 1) {
- lViewPtr = File.lSize - 1;
-
- if (Default.fDispASCII)
- lDeltaRows = -1L;
- else
- lDeltaRows = 0L;
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows,
- Default.fDispASCII);
- if (lLastRowNumber > 0L)
- {
- lRowNumber = lLastRowNumber;
- lRowPointer = File.lSize - 1;
- }
-
- WinInvalidateRect (hwnd, NULL, FALSE);
- }
- break;
- }
- return WinDefWindowProc (hwnd, msg, mp1, mp2);
-
- //-----------------------------------------------------------
- // Process Horizonal Scroll Bar Messages by scrolling across
- // the AVIO space.
- //-----------------------------------------------------------
- case WM_HSCROLL:
-
- switch (SHORT2FROMMP (mp2)) {
-
- case SB_LINELEFT:
-
- sHScroll -= 1;
- break;
-
- case SB_PAGELEFT:
-
- sHScroll -= sHPage;
- break;
-
- case SB_LINERIGHT:
-
- sHScroll += 1;
- break;
-
- case SB_PAGERIGHT:
-
- sHScroll += sHPage;
- break;
-
- case SB_SLIDERTRACK:
-
- sHScroll = SHORT1FROMMP (mp2);
- break;
- }
- sHScroll = min (max (0, sHScroll),
- AVIOCOLS - sxWinSize / sCharWidth);
-
- if (sHScroll != (SHORT) SHORT1FROMMR (WinSendMsg (hwndHScroll,
- SBM_QUERYPOS, NULL, NULL))) {
- VioSetOrg (0, sHScroll, hvps);
- DisplayFilePos (hps, hwnd, lViewPtr);
- WinSendMsg (hwndHScroll, SBM_SETPOS,
- MPFROM2SHORT (sHScroll, 0), NULL);
- }
- return 0;
-
- //-----------------------------------------------------------
- // Process Vertical Scroll Bar Messages by scrolling the AVIO
- // space and writing the new lines.
- //-----------------------------------------------------------
- case WM_VSCROLL:
-
- switch (SHORT2FROMMP (mp2)) {
-
- case SB_LINEUP:
-
- lDeltaRows = -1L;
- break;
-
- case SB_PAGEUP:
-
- lDeltaRows = (LONG) -sVPage;
- break;
-
- case SB_LINEDOWN:
-
- lDeltaRows = 1L;
- break;
-
- case SB_PAGEDOWN:
-
- lDeltaRows = (LONG) sVPage;
- break;
-
- case SB_SLIDERTRACK:
-
- lTemp = lViewPtr;
-
- lViewPtr = (LONG) ((LONG)SHORT1FROMMP(mp2) * (LONG)sVScrScale);
- if (Default.fDispASCII) {
- lDeltaRows = -1L;
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
- if (lDeltaRows != 0) {
- lDeltaRows = 1L;
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
- }
- }
- else {
- lDeltaRows = 0L;
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
- }
-
- sTemp = sComputeLines (lTemp, lViewPtr,
- Default.fDispASCII);
- sTemp = (sTemp > sRowsVisible) ? sRowsVisible : sTemp;
- sTemp = (sTemp < -sRowsVisible) ? -sRowsVisible : sTemp;
- lDeltaRows = (LONG) sTemp;
-
- break;
-
- default:
- return 0;
- }
- if (SHORT2FROMMP (mp2) != SB_SLIDERTRACK)
- lViewPtr += MoveViewPtr (lViewPtr, &lDeltaRows, Default.fDispASCII);
- WinSendMsg (hwndVScroll, SBM_SETPOS,
- MPFROM2SHORT ((SHORT)(lViewPtr/sVScrScale), 0), NULL);
-
- if (lDeltaRows > 0L) {
- VioScrollUp (0, 0, sRowsVisible, AVIOCOLS, (SHORT) lDeltaRows,
- Default.szAttribute, hvps);
-
- sRow = sRowsVisible-(SHORT)lDeltaRows;
- sTempRow = sRow;
-
- lTemp = lViewPtr;
- lRow = (LONG) sRow;
- lTemp += MoveViewPtr (lTemp, &lRow, Default.fDispASCII);
- sRow = (SHORT) lRow;
-
- if (sRow == sTempRow) {
- if (!Default.fDispASCII)
- for (sRow = 0; sRow <= (SHORT)lDeltaRows; sRow++)
- lTemp += DisplayLine (hvps,
- (sRowsVisible-(SHORT)lDeltaRows) + sRow,
- lTemp, Default.fDispASCII);
- else
- for (sRow = 0; sRow < (SHORT)lDeltaRows; sRow++)
- lTemp += DisplayLine (hvps,
- (sRowsVisible-(SHORT)lDeltaRows) + sRow,
- lTemp, Default.fDispASCII);
- }
- }
- if (lDeltaRows < 0L) {
- lDeltaRows = -lDeltaRows;
- VioScrollDn (0, 0, sRowsVisible, AVIOCOLS, (SHORT) lDeltaRows,
- Default.szAttribute, hvps);
-
- lTemp = lViewPtr;
- for (sRow = 0; sRow <= (SHORT) lDeltaRows; sRow++)
- lTemp += DisplayLine (hvps, sRow, lTemp, Default.fDispASCII);
- }
- DisplayFilePos (hps, hwnd, lViewPtr);
-
- return 0;
-
- //-----------------------------------------------------------
- // Handle OS/2 1.3 object (file) dragging to this application.
- //-----------------------------------------------------------
- case DM_DRAGOVER:
-
- pDragInfo = (PDRAGINFO) mp1;
- if ( DrgAccessDraginfo (pDragInfo) )
- {
- if (pDragInfo->cditem == 1)
- {
- if (DrgQueryDragitem (pDragInfo,
- sizeof(DragItem),
- &DragItem,
- 0) )
- {
- if (DrgQueryNativeRMF (&DragItem,
- sizeof(szDragItemRMF),
- szDragItemRMF) )
- {
- if ( strncmp (szDragItemRMF, "DRM_OS2FILE", 11) )
- {
- DrgQueryStrName (DragItem.hstrContainerName,
- sizeof(szDropDirectory),
- szDropDirectory);
- DrgQueryStrName (DragItem.hstrSourceName,
- sizeof(szDropFileName),
- szDropFileName);
- strcpy (szBuffer, szDropDirectory);
- if (szBuffer[strlen (szBuffer)-1] != '\\')
- strcat (szBuffer, "\\");
- strcat (szBuffer, szDropFileName);
- if (TestOpenFile (szBuffer))
- {
- return (MRFROM2SHORT(DOR_DROP, DO_UNKNOWN));
- }
- }
- }
- }
- }
- }
- return (MRFROM2SHORT(DOR_NEVERDROP, DO_UNKNOWN));
-
- case DM_DROP:
-
- pDragInfo = (PDRAGINFO) mp1;
- if ( DrgAccessDraginfo (pDragInfo) )
- {
- if (pDragInfo->cditem == 1)
- {
- if (DrgQueryDragitem (pDragInfo,
- sizeof(DragItem),
- &DragItem,
- 0) )
- {
- if (DrgQueryNativeRMF (&DragItem,
- sizeof(szDragItemRMF),
- szDragItemRMF) )
- {
- if ( strncmp (szDragItemRMF, "DRM_OS2FILE", 11) )
- {
- DrgQueryStrName (DragItem.hstrContainerName,
- sizeof(szDropDirectory),
- szDropDirectory);
- DrgQueryStrName (DragItem.hstrSourceName,
- sizeof(szDropFileName),
- szDropFileName);
- strcpy (szBuffer, szDropDirectory);
- if (szBuffer[strlen (szBuffer)-1] != '\\')
- strcat (szBuffer, "\\");
- strcat (szBuffer, szDropFileName);
- strcpy (szDropNewFileName, szBuffer);
- fDropFile = TRUE;
- DrgSendTransferMsg (DragItem.hwndItem, DM_ENDCONVERSATION,
- MPFROMLONG(DragItem.ulItemID),
- MPFROMSHORT(DMFL_TARGETSUCCESSFUL));
- DrgDeleteDraginfoStrHandles (pDragInfo);
- DrgFreeDraginfo (pDragInfo);
- WinPostMsg (hwnd, WM_COMMAND,
- MPFROM2SHORT (IDM_OPEN,0), 0L);
- return 0;
- }
- }
- }
- }
- }
- fDropFile = FALSE;
- return 0;
-
- case DM_DRAGLEAVE:
-
- return 0;
-
- case DM_DROPHELP:
-
- return 0;
-
- //-----------------------------------------------------------
- // Handle File Manager object (file) dragging to this application.
- // Note: This undocumented private File Manager protocol may not
- // be valid in subsequent OS/2 releases.
- //-----------------------------------------------------------
- case FM_DRAGOVER:
-
- // Signal File Manager that we can accept drop by returning TRUE
-
- return MRFROMSHORT(TRUE);
-
- case FM_DROP:
-
- // File Manager sends FM_DROP message. mp1 is pointer to structure
- // containing unknown info. + list of files selected. List of
- // files begins at pointer+8. File names are separated by '\n'
- // (0x0A), and list ends with '\0' (0x00)
- pszFMFileList = PVOIDFROMMP(mp1);
- if (strchr (pszFMFileList+8, 0x0A) == NULL)
- {
- strcpy (szBuffer, pszFMFileList+8);
- }
- else
- {
- strcpy (szBuffer, strtok (pszFMFileList+8, "\n") );
- }
-
- strcpy (szDropNewFileName, szBuffer);
- fDropFile = TRUE;
- WinPostMsg (hwnd, WM_COMMAND,
- MPFROM2SHORT (IDM_OPEN,0), 0L);
-
- return 0;
-
- //-----------------------------------------------------------
- // Destroy the AVIO space and the presentation space.
- //-----------------------------------------------------------
- case WM_DESTROY:
-
- VioAssociate (NULL, hvps);
- VioDestroyPS (hvps);
- GpiDestroyPS (hps);
- return 0;
- }
- return WinDefWindowProc (hwnd, msg, mp1, mp2);
- }
- //=====================================================================
- // Display File Position Procedure
- //=====================================================================
- VOID DisplayFilePos (HPS hps, HWND hwnd, LONG lFilePtr)
- {
- CHAR szFilePosText[50];
-
- if (Default.fDispFilePos)
- {
- if (Default.fDispASCII)
- {
- lRowNumber = lRowNumber +
- lComputeLines (lRowPointer, lFilePtr, TRUE);
- lRowPointer = lFilePtr;
- if (lLastRowNumber < 1L)
- {
- lLastRowNumber = lRowNumber +
- lComputeLines (lRowPointer, (File.lSize-1L),
- TRUE);
- lLastRow = lLastRowNumber;
- if (GetFileChar (File.lSize-1L) == 0x0A)
- lLastRow = lLastRowNumber - 1L;
- }
- sprintf (szFilePosText, "Line %ld of %ld", lRowNumber,
- lLastRow);
- }
- else
- sprintf (szFilePosText, "Byte %ld of %ld (%lX Hex)",
- lFilePtr, (File.lSize-1), (File.lSize-1));
- DispStatusLine (hps, hwnd, szFilePosText);
- }
-
- // Set Clipping Rectangle to AVIO text area
- SetClipAVIO (hps, hwnd);
-
- return;
- }
- //=====================================================================
- // Status Line (File Position) Procedure
- //=====================================================================
- VOID DispStatusLine (HPS hps, HWND hwnd, CHAR * szStatusText)
- {
- RECTL rclStatusLine;
- static HRGN hrgnStatus;
- HRGN hrgnOldClip;
-
- WinQueryWindowRect (hwnd, &rclStatusLine);
- rclStatusLine.yTop = WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
-
- // Set clip rectangle to status line so status line can be redrawn.
- GpiSetClipRegion (hps, NULL, &hrgnOldClip);
- GpiDestroyRegion (hps, hrgnStatus);
- hrgnStatus = GpiCreateRegion (hps, 1L, &rclStatusLine);
- GpiSetClipRegion (hps, hrgnStatus, &hrgnOldClip);
-
- WinDrawBorder (hps, &rclStatusLine, 0, 1, SYSCLR_WINDOWSTATICTEXT,
- SYSCLR_WINDOW,
- DB_STANDARD |
- DB_INTERIOR );
- WinDrawText (hps, 0xFFFF, szStatusText, &rclStatusLine,
- SYSCLR_WINDOWSTATICTEXT,
- SYSCLR_WINDOW,
- DT_CENTER | DT_VCENTER);
-
- }
- //=====================================================================
- // Procedure to Set Clip Rectangle to AVIO (Text) Area
- //=====================================================================
- VOID SetClipAVIO (HPS hps, HWND hwnd)
- {
- RECTL rclVIOSpace;
- static HRGN hrgnVIO;
- HRGN hrgnOldClip;
-
- GpiSetClipRegion (hps, NULL, &hrgnOldClip);
-
- // Following prevents the Status Line (drawn in GPI) from being
- // scrolled up when the AVIO text is scrolled (i.e., the VIO region is
- // the clipped region)
-
- if (Default.fDispFilePos)
- {
- WinQueryWindowRect (hwnd, &rclVIOSpace);
- rclVIOSpace.yBottom = WinQuerySysValue (HWND_DESKTOP, SV_CYMENU);
- GpiDestroyRegion (hps, hrgnVIO);
- hrgnVIO = GpiCreateRegion (hps, 1L, &rclVIOSpace);
- GpiSetClipRegion (hps, hrgnVIO, &hrgnOldClip);
- }
- }
- //=====================================================================
- // Message Box Procedures
- //=====================================================================
-
- HWND StartMessageBox (USHORT idDlg, CHAR * szString)
-
- {
- HWND hwndMsgBox;
-
- hwndMsgBox = WinLoadDlg (hwndClient,
- hwndFrame,
- MessageDlgProc,
- (HMODULE) NULL,
- idDlg,
- (PVOID) NULL);
- if (strlen (szString) > 0)
- WinSetDlgItemText (hwndMsgBox, idDlg, szString);
-
- return hwndMsgBox;
-
- }
-
- VOID EndMessageBox (HWND hwndMsgBox)
-
- {
-
- if (hwndMsgBox != NULL)
- {
- WinDismissDlg (hwndMsgBox, TRUE);
- WinDestroyWindow (hwndMsgBox);
- }
- }
-
- //=====================================================================
- // Dialog Procedures
- //=====================================================================
- //------------------------------------------------------------------
- // Message Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY MessageDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- switch (msg) {
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- case DID_CANCEL:
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //------------------------------------------------------------------
- // About Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_ABOUT);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- CenterDlgBox (hwnd, hwndClient);
-
- return 0;
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- case DID_CANCEL:
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //------------------------------------------------------------------
- // Goto Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY GotoDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- CHAR szBuffer[12];
- LONG lDeltaRows;
-
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_GOTO);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- CenterDlgBox (hwnd, hwndClient);
-
- WinSendDlgItemMsg (hwnd, IDD_NEWOFFSET, EM_CLEAR, NULL, NULL);
-
- WinSendDlgItemMsg ( hwnd, IDD_NEWOFFSET, EM_SETTEXTLIMIT,
- MPFROM2SHORT (11, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_HEXGOTO, BM_SETCHECK,
- MPFROM2SHORT (fHexGoto, 0), NULL);
- WinSendDlgItemMsg (hwnd, IDD_LINEGOTO, BM_SETCHECK,
- MPFROM2SHORT (fLineGoto, 0), NULL);
- WinSendDlgItemMsg (hwnd, IDD_DECGOTO, BM_SETCHECK,
- MPFROM2SHORT (fDecGoto, 0), NULL);
- return 0;
-
-
- case WM_CONTROL:
-
- switch (SHORT1FROMMP (mp1)) {
-
- case IDD_HEXGOTO:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDecGoto = FALSE;
- fLineGoto = FALSE;
- fHexGoto = TRUE;
- return 0;
- }
- break;
-
- case IDD_DECGOTO:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDecGoto = TRUE;
- fLineGoto = FALSE;
- fHexGoto = FALSE;
- return 0;
- }
- break;
-
- case IDD_LINEGOTO:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDecGoto = FALSE;
- fLineGoto = TRUE;
- fHexGoto = FALSE;
- return 0;
- }
- break;
- }
- break;
-
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- if (WinQueryDlgItemText (hwnd, IDD_NEWOFFSET, sizeof szBuffer,
- szBuffer)) {
- if (fHexGoto)
- lNewViewPtr = strtol(szBuffer, NULL, 16);
- else {
- if (fLineGoto) {
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_WAIT,
- FALSE) );
- lDeltaRows = atol(szBuffer) - 1L;
- lNewViewPtr = MoveViewPtr (0L, &lDeltaRows, TRUE);
- lRowNumber = lDeltaRows + 1L;
- lRowPointer = lNewViewPtr;
- WinSetPointer (HWND_DESKTOP,
- WinQuerySysPointer (HWND_DESKTOP,
- SPTR_ARROW,
- FALSE) );
- }
- else
- lNewViewPtr = atol (szBuffer);
- }
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- case DID_CANCEL:
- WinDismissDlg (hwnd, FALSE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //=====================================================================
- // Search Dialog Procedures
- //=====================================================================
- //------------------------------------------------------------------
- // Search Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY SearchDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_SEARCH);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- CenterDlgBox (hwnd, hwndClient);
-
- if (fHexString)
- WinSetDlgItemText ( hwnd, IDD_SRCHSTR, szSearchHStr);
- else
- WinSetDlgItemText ( hwnd, IDD_SRCHSTR, szSearchStr);
-
- WinSendDlgItemMsg (hwnd, IDD_CHKCASE, BM_SETCHECK,
- MPFROM2SHORT (fCheckCase, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_TOPSEARCH, BM_SETCHECK,
- MPFROM2SHORT (fTopSearch, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_HEXSTRING, BM_SETCHECK,
- MPFROM2SHORT (fHexString, 0), NULL);
- return 0;
-
- case WM_CONTROL:
-
- switch (SHORT1FROMMP (mp1)) {
-
- case IDD_CHKCASE:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fCheckCase)
- fCheckCase = FALSE;
- else
- fCheckCase = TRUE;
- return 0;
- }
- break;
-
- case IDD_TOPSEARCH:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fTopSearch)
- fTopSearch = FALSE;
- else
- fTopSearch = TRUE;
- return 0;
- }
- break;
-
- case IDD_HEXSTRING:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fHexString)
- fHexString = FALSE;
- else
- fHexString = TRUE;
- return 0;
- }
- break;
- }
- break;
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- if (fHexString) {
- WinQueryDlgItemText (hwnd, IDD_SRCHSTR, sizeof szSearchHStr,
- szSearchHStr);
- cbSearchStrLen = atob(szSearchHStr, sSearchStr);
- if (cbSearchStrLen) {
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- }
- else {
- WinQueryDlgItemText (hwnd, IDD_SRCHSTR, sizeof szSearchStr,
- szSearchStr);
- if (strlen (szSearchStr)) {
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- }
-
- case DID_CANCEL:
- WinDismissDlg (hwnd, FALSE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //===================================================================
- // Procedures for File open dialog box
- //===================================================================
- //------------------------------------------------------------------
- // Center Dialog Box Procedure
- //------------------------------------------------------------------
- VOID CenterDlgBox (HWND hwndDialog, HWND hwndParent)
- {
- static SWP swpParent;
- static SWP swpDialog;
-
- WinQueryWindowPos (hwndParent, &swpParent);
- WinQueryWindowPos (hwndDialog, &swpDialog);
- if (swpParent.cx > swpDialog.cx)
- swpDialog.x = swpDialog.x + ((swpParent.cx - swpDialog.cx)/2);
- if (swpParent.cy > swpDialog.cy)
- swpDialog.y = swpDialog.y + ((swpParent.cy - swpDialog.cy)/2);
- WinSetWindowPos (hwndDialog,
- swpDialog.hwndInsertBehind,
- swpDialog.x,
- swpDialog.y,
- swpDialog.cx,
- swpDialog.cy,
- swpDialog.fs);
- return;
- }
- //------------------------------------------------------------------
- // Fill Drive List Box Procedure
- //------------------------------------------------------------------
- VOID FillDriveListBox (HWND hwnd, CHAR *pcCurrentPath) {
- static CHAR szDrive [] = " :";
- SHORT sDrive;
- ULONG ulDriveMap;
- USHORT usDriveNum;
-
- DosQCurDisk (&usDriveNum, &ulDriveMap);
-
- pcCurrentPath[0] = (CHAR) usDriveNum + (CHAR) '@';
- pcCurrentPath[1] = ':';
- pcCurrentPath[2] = '\\';
-
- WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_DELETEALL, NULL, NULL);
-
- for (sDrive = 0; sDrive < 26 ; sDrive++ )
- if (ulDriveMap & 1L << sDrive) {
- szDrive [1] = (CHAR) sDrive + (CHAR) 'A';
-
- WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_INSERTITEM,
- MPFROM2SHORT (LIT_END, 0),
- MPFROMP (szDrive));
- }
- WinSendDlgItemMsg (hwnd, IDD_DRIVELIST, LM_SELECTITEM,
- MPFROM2SHORT (usDriveNum - 1, 0),
- MPFROM2SHORT (TRUE, 0));
- }
- //------------------------------------------------------------------
- // Fill Directory List Box Procedure
- //------------------------------------------------------------------
- VOID FillDirListBox (HWND hwnd, CHAR *pcCurPath, BOOL fIncHidden) {
- static CHAR szRootStr[] = "\\";
- FILEFINDBUF findbuf;
- HDIR hDir = 1;
- USHORT usCurPathLen = PATHLENGTH, usSearchCount = 1;
- USHORT usAttr;
-
- if (fIncHidden)
- usAttr = 0x0017;
- else
- usAttr = 0x0015;
-
- WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_DELETEALL, NULL, NULL);
-
- DosQCurDir (0, pcCurPath + 3 , &usCurPathLen);
-
- DosFindFirst ("*.*", &hDir, usAttr, &findbuf, sizeof findbuf,
- &usSearchCount, 0L);
-
- while (usSearchCount) {
- if (findbuf.attrFile & 0x0010
- && (findbuf.achName [0] != '.' || findbuf.achName [1] ))
-
- if (pcCurPath [strlen(pcCurPath)-1] != '\\'
- || findbuf.achName[1] != '.' || findbuf.achName [2])
-
- WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
- MPFROM2SHORT (LIT_SORTASCENDING, 0),
- MPFROMP (findbuf.achName));
-
- DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
- }
- if (pcCurPath [strlen(pcCurPath)-1] != '\\')
- WinSendDlgItemMsg (hwnd, IDD_DIRLIST, LM_INSERTITEM,
- MPFROM2SHORT (0, 0), MPFROMP (szRootStr));
- }
- //------------------------------------------------------------------
- // Fill File List Box Procedure
- //------------------------------------------------------------------
- VOID FillFileListBox (HWND hwnd, CHAR *pcSearchParam, BOOL fIncHidden) {
- FILEFINDBUF findbuf;
- HDIR hDir = 1;
- USHORT usSearchCount = 1;
- USHORT usAttr;
-
- if (fIncHidden)
- usAttr = 0x0007;
- else
- usAttr = 0x0005;
-
- WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_DELETEALL, NULL, NULL);
-
- DosFindFirst (pcSearchParam, &hDir, usAttr, &findbuf, sizeof findbuf,
- &usSearchCount, 0L);
-
- while (usSearchCount) {
- WinSendDlgItemMsg (hwnd, IDD_FILELIST, LM_INSERTITEM,
- MPFROM2SHORT (LIT_SORTASCENDING, 0),
- MPFROMP (findbuf.achName));
- DosFindNext (hDir, &findbuf, sizeof findbuf, &usSearchCount);
- }
- }
- //------------------------------------------------------------------
- // File Open Dialog Box Procedure
- //------------------------------------------------------------------
- MRESULT EXPENTRY FileDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- static CHAR szCurrentPath [PATHLENGTH], szFileName[PATHLENGTH] = "*.*";
- static CHAR szFileNameFilter[PATHLENGTH] = "*.*";
- static BOOL fIncHidden;
- CHAR *pFileName;
- CHAR szBuffer [PATHLENGTH];
- CHAR szFilterText [PATHLENGTH+12];
- CHAR szLastFileName [PATHLENGTH];
- USHORT sLastFileIndex;
- USHORT usCurPathLen = PATHLENGTH - 3;
- SHORT sSelect;
- FILEFINDBUF findbuf;
- HDIR hDir = 1;
- USHORT usSearchCount = 1, usAttr;
- SHORT i;
-
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_OPEN);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- fIncHidden = Default.fIncHiddenFiles;
-
- CenterDlgBox (hwnd, hwndClient);
-
- if (strlen(szWildCardFilename) != 0)
- {
- if (DosQPathInfo (szWildCardFilename, 5, szBuffer,
- sizeof szBuffer, 0L))
- WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
- "Unrecognized path", 1,
- MB_OK | MB_CRITICAL);
- for (i = strlen(szBuffer); i >= 0; i--)
- if (szBuffer[i] == '\\')
- break;
- strcpy (szFileNameFilter, szBuffer + i + 1);
- strcpy (szFilterText, "File Filter: ");
- strcat (szFilterText, szFileNameFilter);
- DosSelectDisk ((USHORT) (*szBuffer - 'A' + 1));
- if (strchr (szBuffer, '\\') != strrchr (szBuffer, '\\'))
- *(strrchr (szBuffer, '\\')) = '\0';
- else
- *(szBuffer+3) = '\0';
- DosChDir (szBuffer+2, 0L);
- *szWildCardFilename = '\0';
- }
- else
- {
- strcpy (szFileName, "*.*");
- strcpy (szFilterText, "File Filter: ");
- strcat (szFilterText, szFileNameFilter);
- }
- WinSetDlgItemText (hwnd, IDD_FILEFILTER, szFilterText);
- FillDriveListBox (hwnd, szCurrentPath);
- FillDirListBox (hwnd, szCurrentPath, fIncHidden);
- FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
-
- WinSendDlgItemMsg (hwnd, IDD_INCHIDDEN, BM_SETCHECK,
- MPFROM2SHORT (fIncHidden, 0), NULL);
-
- DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
-
- WinSendDlgItemMsg ( hwnd, IDD_FILEEDIT, EM_SETTEXTLIMIT,
- MPFROM2SHORT (PATHLENGTH, 0), NULL);
-
- WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
-
-
- pFileName = strrchr(File.szName, '\\');
- if (pFileName != NULL) {
- strcpy (szLastFileName, (pFileName + 1));
- for (i = 0; i < (SHORT) strlen(szLastFileName); i++)
- szLastFileName[i] = (CHAR) toupper(szLastFileName[i]);
- sLastFileIndex = SHORT1FROMMR (
- WinSendDlgItemMsg ( hwnd, IDD_FILELIST, LM_SEARCHSTRING,
- MPFROM2SHORT (LSS_CASESENSITIVE, LIT_FIRST),
- MPFROMP (szLastFileName) )
- );
- if ( (sLastFileIndex != LIT_ERROR) && (sLastFileIndex != LIT_NONE) )
- WinSendDlgItemMsg ( hwnd, IDD_FILELIST, LM_SETTOPINDEX,
- MPFROMSHORT (sLastFileIndex),
- NULL);
- }
-
-
- return 0;
-
- case WM_CONTROL:
-
- if (SHORT1FROMMP (mp1) == IDD_DRIVELIST ||
- SHORT1FROMMP (mp1) == IDD_DIRLIST ||
- SHORT1FROMMP (mp1) == IDD_FILELIST) {
-
- sSelect = (USHORT) SHORT1FROMMR (
- WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
- LM_QUERYSELECTION, 0L, 0L) );
-
- WinSendDlgItemMsg (hwnd, SHORT1FROMMP (mp1),
- LM_QUERYITEMTEXT,
- MPFROM2SHORT (sSelect, sizeof szBuffer),
- MPFROMP (szBuffer));
- }
-
- switch (SHORT1FROMMP (mp1)) {
-
- case IDD_DRIVELIST:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_ENTER:
- szCurrentPath[0] = szBuffer[1];
- DosSelectDisk (szBuffer [1] - '@');
-
- FillDirListBox (hwnd, szCurrentPath, fIncHidden);
- if (strcmp(szFileName, "*.*") != 0) {
- if (szCurrentPath [strlen (szCurrentPath)-1]
- != '\\')
- strcat (szCurrentPath, "\\");
- strcat (szCurrentPath, szFileName);
- }
- WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
- FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
-
- return 0;
- }
- break;
-
- case IDD_DIRLIST:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_ENTER:
-
- DosChDir (szBuffer, 0L);
-
- FillDirListBox (hwnd, szCurrentPath, fIncHidden);
- if (strcmp(szFileName, "*.*") != 0) {
- if (szCurrentPath [strlen (szCurrentPath)-1]
- != '\\')
- strcat (szCurrentPath, "\\");
- strcat (szCurrentPath, szFileName);
- }
- WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
- FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
- return 0;
- }
- break;
-
- case IDD_FILELIST:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_SELECT:
-
- DosQCurDir (0, szCurrentPath + 3, &usCurPathLen);
- if (szCurrentPath [strlen(szCurrentPath)-1] != '\\')
- strcat (szCurrentPath, "\\");
- strcat (szCurrentPath, szBuffer);
-
- WinSetDlgItemText ( hwnd, IDD_FILEEDIT, szCurrentPath);
- return 0;
-
- case LN_ENTER:
-
- WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
- sizeof szCurrentPath,
- szCurrentPath);
- if (DosQPathInfo (szCurrentPath, 5, szBuffer,
- sizeof szBuffer, 0L)) {
- WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
- "Unrecognised path", 1,
- MB_OK | MB_ERROR);
- return 0;
- } else {
- strcpy (szNewFile, szBuffer);
- Default.fIncHiddenFiles = fIncHidden;
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- }
- break;
-
- case IDD_INCHIDDEN:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fIncHidden)
- fIncHidden = FALSE;
- else
- fIncHidden = TRUE;
- FillFileListBox (hwnd, szFileName, fIncHidden);
- FillDirListBox (hwnd, szCurrentPath, fIncHidden);
- return 0;
- }
- break;
- }
- break;
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- if (WinQueryDlgItemText (hwnd, IDD_FILEEDIT,
- sizeof szCurrentPath,
- szCurrentPath) == 0)
- {
- strcpy (szCurrentPath, " ");
- }
- strcpy (szBuffer, szCurrentPath);
- if (DosQPathInfo (szCurrentPath, 5, szBuffer,
- sizeof szBuffer, 0L)) {
- WinMessageBox ( HWND_DESKTOP, hwnd, szBuffer,
- "Unrecognized path", 1,
- MB_OK | MB_ERROR);
- return 0;
- } else
- if (strchr (szBuffer, '*') == 0
- && strchr (szBuffer, '?') == 0) {
- if (fIncHidden)
- usAttr = 0x0007;
- else
- usAttr = 0x0005;
- usSearchCount = 1;
-
- DosFindFirst (szBuffer, &hDir, usAttr, &findbuf,
- sizeof findbuf, &usSearchCount, 0L);
- if (usSearchCount == 0) {
- WinMessageBox (HWND_DESKTOP, hwnd, szBuffer,
- "File not Found", 1, MB_OK | MB_ERROR);
- return 0;
- } else {
- strcpy (szNewFile, szBuffer);
- Default.fIncHiddenFiles = fIncHidden;
- WinDismissDlg (hwnd, TRUE);
- return 0;
- }
- } else {
- for (i = strlen(szBuffer); i >= 0; i--)
- if (szBuffer[i] == '\\')
- break;
- strcpy (szFileNameFilter, szBuffer + i + 1);
- strcpy (szFilterText, "File Filter: ");
- strcat (szFilterText, szFileNameFilter);
- WinSetDlgItemText (hwnd, IDD_FILEFILTER, szFilterText);
- DosSelectDisk ((USHORT) (*szBuffer - 'A' + 1));
- if (strchr (szBuffer, '\\') != strrchr (szBuffer, '\\'))
- *(strrchr (szBuffer, '\\')) = '\0';
- else
- *(szBuffer+3) = '\0';
- DosChDir (szBuffer+2, 0L);
- FillDriveListBox (hwnd, szCurrentPath);
- FillDirListBox (hwnd, szCurrentPath, fIncHidden);
- FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
- FillFileListBox (hwnd, szFileNameFilter, fIncHidden);
- return 0;
- }
- break;
- case DID_CANCEL:
- WinDismissDlg (hwnd, FALSE);
- return 0;
- }
- break;
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //===================================================================
- // Procedures for Configure dialog box
- //===================================================================
- VOID FillColorBox (HWND hwnd, SHORT iListID) {
-
- static CHAR szColors [16][12] = { "Black", "Dk. Blue", "Dk. Green",
- "Dk. Cyan", "Dk. Red", "Dk. Magenta", "Brown", "Gray", "Dk. Gray",
- "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White"};
-
- SHORT i;
-
- WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
-
- for (i = 0; i < 16 ; i++ )
- WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
- MPFROM2SHORT (LIT_END, 0),
- MPFROMP (szColors[i]));
- return;
- }
- //------------------------------------------------------------------
- // Fill Character cell size box
- //------------------------------------------------------------------
- VOID FillCellSizeBox (HWND hwnd, SHORT iListID) {
-
- SHORT i;
- CHAR szBuffer[8];
-
- WinSendDlgItemMsg (hwnd, iListID, LM_DELETEALL, NULL, NULL);
-
- for (i=0; i<sCellSizeCount; i++)
- {
- sprintf (szBuffer, "%2d x %2d", sCellSize[i][0], sCellSize[i][1]);
- WinSendDlgItemMsg (hwnd, iListID, LM_INSERTITEM,
- MPFROM2SHORT (LIT_END, 0),
- MPFROMP (szBuffer));
- }
- return;
- }
- //------------------------------------------------------------------
- // GetFontSize - Determine font size.
- //------------------------------------------------------------------
- SHORT GetCellSize (SHORT sHeight, SHORT sWidth) {
-
- SHORT i, sIndex = 0;
-
- sIndex = 0;
-
- for (i = 0; i < sCellSizeCount; i++ )
- {
- if (sHeight == sCellSize[i][1] && sWidth == sCellSize[i][0])
- {
- sIndex = i;
- break;
- }
- }
- return sIndex;
- }
- //------------------------------------------------------------------
- // Configure Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY ConfigDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- static SHORT sSelect;
- static UCHAR szAttribute[2];
- static SHORT sCHeight;
- static SHORT sCWidth;
- static SHORT sTabStop;
- static BOOL fDispASCII;
- static BOOL fScrollBars;
- static BOOL fDispEBCDIC;
- static BOOL fDispFilePos;
- static BOOL fLocalSaveWinPos;
-
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_CONFIGURE);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- CenterDlgBox (hwnd, hwndClient);
-
- szAttribute[1] = Default.szAttribute[1];
- sCHeight = Default.sCellHeight;
- sCWidth = Default.sCellWidth;
- sTabStop = Default.sTabStop;
- fDispASCII = Default.fDispASCII;
- fScrollBars = Default.fScrollBars;
- fDispEBCDIC = Default.fDispEBCDIC;
- fDispFilePos = Default.fDispFilePos;
- fLocalSaveWinPos = FALSE;
-
- FillColorBox (hwnd, IDD_FCOLOR);
- FillColorBox (hwnd, IDD_BCOLOR);
- FillCellSizeBox (hwnd, IDD_CELLSIZE);
-
- WinSendDlgItemMsg (hwnd, IDD_BCOLOR, LM_SELECTITEM,
- MPFROM2SHORT (((szAttribute[1]>>4) & 0x0f), 0),
- MPFROM2SHORT (TRUE,0));
-
- WinSendDlgItemMsg (hwnd, IDD_FCOLOR, LM_SELECTITEM,
- MPFROM2SHORT ((szAttribute[1] & 0x0f), 0),
- MPFROM2SHORT (TRUE,0));
-
- WinSendDlgItemMsg (hwnd, IDD_CELLSIZE, LM_SELECTITEM,
- MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
- MPFROM2SHORT (TRUE,0));
-
- WinSendDlgItemMsg (hwnd, IDD_DEFASCII, BM_SETCHECK,
- MPFROM2SHORT (fDispASCII, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_DEFHEXASC, BM_SETCHECK,
- MPFROM2SHORT (!fDispASCII, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_DEFHEXEBC, BM_SETCHECK,
- MPFROM2SHORT (fDispEBCDIC, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_DEFSCROLL, BM_SETCHECK,
- MPFROM2SHORT (fScrollBars, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_DEFFILEPOS, BM_SETCHECK,
- MPFROM2SHORT (fDispFilePos, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_SAVEWINPOS, BM_SETCHECK,
- MPFROM2SHORT (fLocalSaveWinPos, 0), NULL);
-
- WinSendDlgItemMsg (hwnd, IDD_SAVE, BM_SETCHECK,
- MPFROM2SHORT (fSaveToDisk, 0), NULL);
-
- WinSetDlgItemShort ( hwnd, IDD_DEFTABS, sTabStop, FALSE);
-
- return 0;
-
- case WM_CONTROL:
-
- if (SHORT1FROMMP (mp1) == IDD_BCOLOR ||
- SHORT1FROMMP (mp1) == IDD_FCOLOR ||
- SHORT1FROMMP (mp1) == IDD_CELLSIZE) {
- sSelect = (USHORT) SHORT1FROMMR (
- WinSendDlgItemMsg (hwnd,
- SHORT1FROMMP (mp1),
- LM_QUERYSELECTION, 0L,
- 0L) );
- }
- switch (SHORT1FROMMP (mp1)) {
-
- case IDD_BCOLOR:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_SELECT:
-
- szAttribute[1] = (szAttribute[1] & (UCHAR) 0x0f)
- | (UCHAR) ((sSelect << 4) & 0xf0);
- return 0;
- }
- break;
-
- case IDD_FCOLOR:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_SELECT:
-
- szAttribute[1] = (szAttribute[1] & (UCHAR) 0xf0)
- | (UCHAR) (sSelect & 0x0f);
- return 0;
- }
- break;
-
- case IDD_CELLSIZE:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_SELECT:
-
- sCHeight = sCellSize [sSelect][1];
- sCWidth = sCellSize [sSelect][0];
- return 0;
- }
- break;
-
- case IDD_DEFASCII:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDispASCII = TRUE;
- fDispEBCDIC = FALSE;
- return 0;
- }
- break;
-
- case IDD_DEFHEXASC:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDispASCII = FALSE;
- fDispEBCDIC = FALSE;
- return 0;
- }
- break;
-
- case IDD_DEFHEXEBC:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- fDispASCII = FALSE;
- fDispEBCDIC = TRUE;
- return 0;
- }
- break;
-
- case IDD_DEFFILEPOS:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fDispFilePos)
- fDispFilePos = FALSE;
- else
- fDispFilePos = TRUE;
- return 0;
- }
- break;
-
- case IDD_DEFSCROLL:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fScrollBars)
- fScrollBars = FALSE;
- else
- fScrollBars = TRUE;
- return 0;
- }
- break;
-
- case IDD_SAVEWINPOS:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fLocalSaveWinPos)
- fLocalSaveWinPos = FALSE;
- else
- fLocalSaveWinPos = TRUE;
- return 0;
- }
- break;
-
- case IDD_SAVE:
- switch (SHORT2FROMMP (mp1)) {
-
- case BN_CLICKED:
- if (fSaveToDisk)
- fSaveToDisk = FALSE;
- else
- fSaveToDisk = TRUE;
- return 0;
- }
- break;
- }
- break;
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- Default.szAttribute[1] = szAttribute[1];
- Default.sCellHeight = sCHeight;
- Default.sCellWidth = sCWidth;
- Default.fDispASCII = fDispASCII;
- Default.fScrollBars = fScrollBars;
- Default.fDispEBCDIC = fDispEBCDIC;
- Default.fDispFilePos = fDispFilePos;
- WinQueryDlgItemShort (hwnd, IDD_DEFTABS, &sSelect,
- FALSE);
- sSelect = min (max (1, sSelect), AVIOCOLS - 1);
- Default.sTabStop = sSelect;
- fSaveWinPos = fLocalSaveWinPos;
- WinDismissDlg (hwnd, TRUE);
- return (MRESULT) 1;
-
- case DID_CANCEL:
- WinDismissDlg (hwnd, FALSE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- //------------------------------------------------------------------
- // Font Size Dialog Box
- //------------------------------------------------------------------
- MRESULT EXPENTRY FontDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- static SHORT sSelect;
- static SHORT sCHeight;
- static SHORT sCWidth;
-
- switch (msg) {
-
- case WM_INITDLG:
-
- WinSetWindowUShort(hwnd, QWS_ID, IDW_PICKFONT);
- if (hwndHelp != NULL)
- WinAssociateHelpInstance( hwndHelp, hwnd);
-
- CenterDlgBox (hwnd, hwndClient);
-
- sCHeight = Default.sCellHeight;
- sCWidth = Default.sCellWidth;
-
- FillCellSizeBox (hwnd, IDD_FONTS);
-
- WinSendDlgItemMsg (hwnd, IDD_FONTS, LM_SELECTITEM,
- MPFROM2SHORT (GetCellSize (sCHeight,sCWidth), 0),
- MPFROM2SHORT (TRUE,0));
- return 0;
-
- case WM_CONTROL:
-
- switch (SHORT1FROMMP (mp1)) {
-
- case IDD_FONTS:
- switch (SHORT2FROMMP (mp1)) {
-
- case LN_SELECT:
- sSelect = (USHORT) SHORT1FROMMR (
- WinSendDlgItemMsg (hwnd,
- IDD_FONTS,
- LM_QUERYSELECTION,
- 0L, 0L) );
-
- sCHeight = sCellSize [sSelect][1];
- sCWidth = sCellSize [sSelect][0];
- return 0;
-
- case LN_ENTER:
- Default.sCellHeight = sCHeight;
- Default.sCellWidth = sCWidth;
- WinDismissDlg (hwnd, TRUE);
- return 0;
-
- }
- break;
- }
- break;
-
- case WM_COMMAND:
-
- switch (COMMANDMSG(&msg)->cmd) {
-
- case DID_OK:
- Default.sCellHeight = sCHeight;
- Default.sCellWidth = sCWidth;
- WinDismissDlg (hwnd, TRUE);
- return 0;
-
- case DID_CANCEL:
- WinDismissDlg (hwnd, FALSE);
- return 0;
- }
- }
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }