home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ed32eng1.zip / source / edlg.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  8KB  |  275 lines

  1. /* Ported to the EMX-GCC-Copiler 0.8h by Thomas K. Götz
  2.  * Date: February 1994
  3.  * All changes are marked with my insignia: tkg
  4.  */
  5.  
  6. /* The third argument in every DlgProc has been changed from USHORT to ULONG 
  7.  * without further comment (tkg)
  8.  */
  9.  
  10.  
  11. #define INCL_WINHELP
  12. #define INCL_WIN
  13. #define INCL_GPI
  14. #define INCL_DOS
  15. #include <os2.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include "edit.h"
  20. #include "edlg.h"
  21.  
  22. /* window procedure for about box */
  23. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  24. {
  25.    switch (msg) {
  26.       case WM_COMMAND:
  27.          switch (SHORT1FROMMP (mp1)) {
  28.             case DID_OK:
  29.             case DID_CANCEL:
  30.                WinDismissDlg (hwnd, TRUE);
  31.                return 0;
  32.             default:
  33.                break;
  34.          }
  35.    }
  36.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  37. }
  38.  
  39.  
  40. /* The functions
  41.  * 1. VOID FillDirListBox (HWND hwnd, CHAR *pcCurrentPath)
  42.  * 2. VOID FillFileListBox (HWND hwnd)
  43.  * 3. MRESULT EXPENTRY OpenDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  44.  * 4. MRESULT EXPENTRY SaveasDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  45.  * have been deleted. The Open- and SaveAs-Dialogs will now
  46.  * be done by the Standard-File-Dialog of PM
  47.  */
  48.  
  49.  
  50.  
  51.  
  52. /* determine if pathname is a valid file or directory */
  53. /* by Charles Petzold, from Programming the OS/2 Presentation Manager */
  54. SHORT ParseFileName (CHAR *pcOut, CHAR *pcIn)
  55. {
  56. /*
  57.  *   Input:    pcOut -- Pointer to parsed file specification.
  58.  *             pcIn  -- Pointer to raw file specification.
  59.  *                      
  60.  *   Returns:      0 -- pcIn had invalid drive or directory.
  61.  *                 1 -- pcIn was empty or had no filename.
  62.  *                 2 -- pcOut points to drive, full dir, and file name.
  63.  *
  64.  *   Changes current drive and directory per pcIn string.
  65.  */
  66.  
  67.    CHAR *pcLastSlash, *pcFileOnly;
  68.    ULONG ulDriveMap;
  69.    ULONG ulDriveNum;      /* (tkg) */
  70.    ULONG ulDirLen = 64L;
  71.  
  72.    strupr (pcIn);
  73.  
  74.    /* If input string is empty, return 1 */
  75.    if (pcIn[0] == '\0')
  76.       return 1;
  77.  
  78.    /* Get drive from input string or current drive */
  79.    if (pcIn[1] == ':') {
  80.       /* if (DosSelectDisk (pcIn[0] - '@')) now: (tkg */
  81.       if (DosSetDefaultDisk (pcIn[0] - '@'))
  82.          return 0;
  83.  
  84.       pcIn += 2;
  85.    }
  86.    /* DosQCurDisk (&usDriveNum, &ulDriveMap); now: (tkg) */
  87.    DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap);
  88.  
  89.    *pcOut++ = (CHAR)((CHAR) ulDriveNum + '@');
  90.    *pcOut++ = ':';
  91.    *pcOut++ = '\\';
  92.  
  93.    /* If rest of string is empty, return 1 */
  94.    if (pcIn[0] == '\0')
  95.       return 1;
  96.  
  97.    /* Search for last backslash.  If none, could be directory. */
  98.    if (NULL == (pcLastSlash = strrchr (pcIn, '\\'))) {
  99.       /* if (!DosChDir (pcIn, 0L)) now: (tkg) */
  100.       if (!DosSetCurrentDir (pcIn))
  101.          return 1;
  102.  
  103.       /* Otherwise, get current dir & attach input filename */
  104.       /* DosQCurDir (0, pcOut, &usDirLen); now: */
  105.       DosQueryCurrentDir (0, pcOut, &ulDirLen);
  106.  
  107.       if (strlen (pcIn) > 12)
  108.          return 0;
  109.  
  110.       if (*(pcOut + strlen (pcOut) - 1) != '\\')
  111.          strcat (pcOut++, "\\");
  112.  
  113.       strcat (pcOut, pcIn);
  114.       return 2;
  115.    }
  116.    
  117.    /* If the only backslash is at beginning, change to root */
  118.    if (pcIn == pcLastSlash) {
  119.       /* DosChDir ("\\", 0L); now: (tkg) */
  120.       DosSetCurrentDir ("\\");
  121.  
  122.       if (pcIn[1] == '\0')
  123.          return 1;
  124.  
  125.       strcpy (pcOut, pcIn + 1);
  126.       return 2;
  127.    }
  128.    
  129.    /* Attempt to change directory -- Get current dir if OK */
  130.    *pcLastSlash = '\0';
  131.  
  132.    /* if (DosChDir (pcIn, 0L)) now: (tkg) */
  133.    if (DosSetCurrentDir (pcIn))
  134.       return 0;
  135.  
  136.    /* DosQCurDir (0, pcOut, &usDirLen); now: (tkg) */
  137.    DosQueryCurrentDir (0, pcOut, &ulDirLen);
  138.  
  139.    /* Append input filename, if any */
  140.    pcFileOnly = pcLastSlash + 1;
  141.  
  142.    if (*pcFileOnly == '\0')
  143.       return 1;
  144.  
  145.    if (strlen (pcFileOnly) > 12)
  146.       return 0;
  147.  
  148.    if (*(pcOut + strlen (pcOut) - 1) != '\\')
  149.       strcat (pcOut++, "\\");
  150.  
  151.    strcat (pcOut, pcFileOnly);
  152.    return 2;
  153. }
  154.  
  155.  
  156. /* window procedure for find (text search) dialog box */
  157. MRESULT EXPENTRY FindDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  158. {
  159.    switch (msg) {
  160.       case WM_INITDLG:
  161.         WinSendDlgItemMsg (hwnd, DID_FINDTEXT, EM_SETTEXTLIMIT,
  162.            MPFROM2SHORT (50, 0), NULL);
  163.          WinSetDlgItemText (hwnd, DID_FINDTEXT, szFind);
  164.          WinSetFocus (HWND_DESKTOP, WinWindowFromID (hwnd, DID_FINDTEXT));
  165.          return (MRESULT) TRUE;
  166.          
  167.       case WM_COMMAND:
  168.          switch (SHORT1FROMMP (mp1)) {
  169.             case DID_OK:
  170.                if (WinQueryDlgItemText (hwnd, DID_FINDTEXT, 60, szFind))
  171.                   WinDismissDlg (hwnd, DID_OK);
  172.                else
  173.                   WinDismissDlg (hwnd, DID_CANCEL);
  174.                return 0;
  175.                
  176.             case DID_CANCEL:
  177.                WinDismissDlg (hwnd, DID_CANCEL);
  178.                return 0;
  179.                
  180.             default:
  181.                break;
  182.          }
  183.    }
  184.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  185. }
  186.  
  187.  
  188. /* window procedure for replace (text search and replace) dialog box */
  189. MRESULT EXPENTRY ReplaceDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  190. {
  191.    BOOL FAR *pb;
  192.    
  193.    switch (msg) {
  194.       case WM_INITDLG:
  195.          WinSendDlgItemMsg (hwnd, DID_NEWTEXT, EM_SETTEXTLIMIT,
  196.             MPFROM2SHORT (50, 0), NULL);
  197.          WinSendDlgItemMsg (hwnd, DID_OLDTEXT, EM_SETTEXTLIMIT,
  198.             MPFROM2SHORT (50, 0), NULL);
  199.          WinSetDlgItemText (hwnd, DID_OLDTEXT, szFind);
  200.          WinSetDlgItemText (hwnd, DID_NEWTEXT, szReplace);
  201.          pb = (PVOID) mp2;   /* TRUE if first entry */
  202.          if (*pb) {
  203.             WinEnableWindow (WinWindowFromID (hwnd, DID_DOREPLACE), FALSE);
  204.             WinEnableWindow (WinWindowFromID (hwnd, DID_REPLACEALL), FALSE);
  205.             WinSetFocus (HWND_DESKTOP, WinWindowFromID (hwnd, DID_OLDTEXT));
  206.          }
  207.          else
  208.             WinSetFocus (HWND_DESKTOP, WinWindowFromID (hwnd, DID_NEWTEXT));
  209.          return (MRESULT) TRUE;
  210.          
  211.       case WM_COMMAND:
  212.          switch (SHORT1FROMMP (mp1)) {
  213.             case DID_OK:
  214.                if (WinQueryDlgItemText (hwnd, DID_OLDTEXT, 60, szFind)) {
  215.                   WinQueryDlgItemText (hwnd, DID_NEWTEXT, 60, szReplace);
  216.                   WinDismissDlg (hwnd, DID_OK);
  217.                }
  218.                else
  219.                   WinDismissDlg (hwnd, DID_CANCEL);
  220.                return 0;
  221.                
  222.             case DID_DOREPLACE:
  223.                if (WinQueryDlgItemText (hwnd, DID_NEWTEXT, 60, szReplace))
  224.                   WinDismissDlg (hwnd, DID_DOREPLACE);
  225.                else
  226.                   WinDismissDlg (hwnd, DID_CANCEL);
  227.                break;
  228.                
  229.             case DID_REPLACEALL:
  230.                if (WinQueryDlgItemText (hwnd, DID_NEWTEXT, 60, szReplace))
  231.                   WinDismissDlg (hwnd, DID_REPLACEALL);
  232.                else
  233.                   WinDismissDlg (hwnd, DID_CANCEL);
  234.                break;
  235.                
  236.             case DID_CANCEL:
  237.                WinDismissDlg (hwnd, DID_CANCEL);
  238.                return 0;
  239.                
  240.             default:
  241.                break;
  242.          }
  243.    }
  244.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  245. }
  246.  
  247.  
  248. /* window procedure for find (text search) dialog box */
  249. MRESULT EXPENTRY GoLnDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  250. {
  251.    switch (msg) {
  252.       case WM_INITDLG:
  253.          WinSetFocus (HWND_DESKTOP, WinWindowFromID (hwnd, DID_LINENBR));
  254.          return (MRESULT) TRUE;
  255.          
  256.       case WM_COMMAND:
  257.          switch (SHORT1FROMMP (mp1)) {
  258.             case DID_OK:
  259.                if (WinQueryDlgItemText (hwnd, DID_LINENBR, 20, szLine))
  260.                   WinDismissDlg (hwnd, DID_OK);
  261.                else
  262.                   WinDismissDlg (hwnd, DID_CANCEL);
  263.                return 0;
  264.                
  265.             case DID_CANCEL:
  266.                WinDismissDlg (hwnd, DID_CANCEL);
  267.                return 0;
  268.                
  269.             default:
  270.                break;
  271.          }
  272.    }
  273.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  274. }
  275.