home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / MLEVIEW.ZIP / MLEVIEW.C < prev    next >
Text File  |  1991-04-04  |  51KB  |  1,252 lines

  1. #pragma title("MLEView - A Text File Browser")
  2.  
  3. /*--------------------------------------------------------------------*/
  4. /* MLEView -- A Text File View Utility                                */
  5. /* Copyright (C) W. David Ashley, 1991                                */
  6. /*--------------------------------------------------------------------*/
  7.  
  8.  
  9. #define  INCL_DOS
  10. #define  INCL_WIN
  11. #define  INCL_WINHELP
  12. #define  INCL_WINMLE
  13. #define  INCL_GPI
  14. #define  INCL_GPILCIDS
  15. #include <os2.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <filedlg.h>
  20. #include "MLEView.h"
  21. #include "ezfonts.h"
  22.  
  23.  
  24. #define  LCID_MYFONT  199
  25.  
  26.  
  27. MRESULT EXPENTRY ClientProc      (HWND, USHORT, MPARAM, MPARAM);
  28. MRESULT EXPENTRY AboutDlgProc    (HWND, USHORT, MPARAM, MPARAM);
  29. MRESULT EXPENTRY SetFontDlgProc  (HWND, USHORT, MPARAM, MPARAM);
  30. MRESULT EXPENTRY SampleTextProc  (HWND, USHORT, MPARAM, MPARAM);
  31. MRESULT EXPENTRY SetColorDlgProc (HWND, USHORT, MPARAM, MPARAM);
  32. MRESULT EXPENTRY SampleColorProc (HWND, USHORT, MPARAM, MPARAM);
  33. MRESULT EXPENTRY FindDlgProc     (HWND, USHORT, MPARAM, MPARAM);
  34. static VOID MLEInit              (VOID);
  35. static VOID MLELoad              (VOID);
  36. static VOID FillFontListBox      (HWND);
  37. static VOID FillSizeListBox      (HWND);
  38. static VOID FillForgListBox      (HWND);
  39. static VOID FillBakgListBox      (HWND);
  40.  
  41.  
  42. HAB      hab;                           /* application anchor block   */
  43. ULONG    flFrameFlags = FCF_STANDARD;   /* frame style flags          */
  44. PSZ      pszFile = NULL;                /* select dlg filename        */
  45. PSZ      Filename = NULL;               /* viewed file name           */
  46. HFILE    hFile = 0;                     /* viewed file handle         */
  47. HWND     hwndFrame, hwndClient;         /* handles of app wnds        */
  48. HWND     hwndMLE;                       /* handles of MLE wnd         */
  49. HWND     hwndTitleBar;                  /* handle of title bar wnd    */
  50. HWND     hwndMenu;                      /* handle of menu bar wnd     */
  51. HWND     hwndFont;                      /* handle of font dlg wnd     */
  52. HWND     hwndColor;                     /* handle of color dlg wnd    */
  53. PCHAR    szMLEViewClass = "MLEViewClss";/* class for main client wnd  */
  54. PCHAR    szSampleClass = "SampleClass"; /* class for sample text wnd  */
  55. PCHAR    szSColorClass = "SColorClass"; /* class for color text wnd   */
  56. CHAR     szTitle [] = "MLEView - ";     /* title bar prefix text      */
  57. PCHAR    szTitleText;                   /* title bar text             */
  58. HELPINIT hmiHelpData;                   /* help init strucs           */
  59. HWND     hwndHelpInstance;              /* handle of help window      */
  60. SHORT    sFacenameIndex, sSizeIndex;    /* indexes into Ezf font array*/
  61. HINI     hiniProfile;                   /* profile handle             */
  62. PCHAR    szProfilePath;                 /* full pathname to profile   */
  63. ULONG    ulProfileSize;                 /* size of Profile struct     */
  64. struct   _PROFILE {                     /* profile struct             */
  65.    COLOR    clrText;
  66.    COLOR    clrBackground;
  67.    BOOL     fWordWrap;
  68.    BOOL     fCase;
  69.    BOOL     fWrap;
  70.    FATTRS   fatFont;
  71.    } Profile = {CLR_CYAN, CLR_BLACK, FALSE, TRUE, FALSE,
  72.                 /* FATTRS init */
  73.                 {0, 0, 0, "NULL", 0, 0, 0, 0, 0, 0}};
  74. FATTRS   fat;
  75. FONTMETRICS fm;
  76. struct   _COLORTABLE {                  /* for use by set color dlg   */
  77.    LONG  clr;
  78.    PCHAR szColor;
  79.    } ColorTable [17] = {CLR_BLACK,     "Black",
  80.                         CLR_BLUE,      "Blue",
  81.                         CLR_BROWN,     "Brown",
  82.                         CLR_CYAN,      "Cyan",
  83.                         CLR_DARKBLUE,  "Dark blue",
  84.                         CLR_DARKCYAN,  "Dark cyan",
  85.                         CLR_DARKGRAY,  "Dark gray",
  86.                         CLR_DARKGREEN, "Dark green",
  87.                         CLR_DARKPINK,  "Dark pink",
  88.                         CLR_DARKRED,   "Dark red",
  89.                         CLR_DEFAULT,   "Default",
  90.                         CLR_GREEN,     "Green",
  91.                         CLR_PALEGRAY,  "Pale gray",
  92.                         CLR_PINK,      "Pink",
  93.                         CLR_RED,       "Red",
  94.                         CLR_WHITE,     "White",
  95.                         CLR_YELLOW,    "Yellow"};
  96.  
  97.  
  98. #pragma subtitle ("main Procedure")
  99. #pragma page()
  100.  
  101. int cdecl main (int argc, CHAR * argv []) {
  102.    HMQ    hmq;
  103.    QMSG   qmsg;
  104.    USHORT usVersion;
  105.    USHORT usAction;
  106.    USHORT usMaxPathLen;
  107.    SWP    swp;
  108.  
  109.    /* do file system initialization */
  110.    DosQSysInfo (0, (PBYTE) &usMaxPathLen, sizeof (usMaxPathLen));
  111.    szProfilePath = malloc ((size_t) usMaxPathLen);
  112.    szTitleText = malloc ((size_t) (usMaxPathLen + strlen (szTitle)));
  113.    strcpy (szTitleText, "MLEView");
  114.    Filename = malloc ((size_t) usMaxPathLen);
  115.  
  116.    /* do PM initialization */
  117.    hab = WinInitialize (0);
  118.    hmq = WinCreateMsgQueue (hab, 0);
  119.    WinRegisterClass (hab, szMLEViewClass, ClientProc,
  120.                      CS_SIZEREDRAW, 0);
  121.    WinRegisterClass (hab, szSampleClass, SampleTextProc,
  122.                      CS_SIZEREDRAW, 0);
  123.    WinRegisterClass (hab, szSColorClass, SampleColorProc,
  124.                      CS_SIZEREDRAW, 0);
  125.  
  126.    /* initialize IPF structure */
  127.    hmiHelpData.cb = sizeof (HELPINIT);
  128.    hmiHelpData.ulReturnCode = 0;
  129.    hmiHelpData.pszTutorialName = 0;
  130.    hmiHelpData.phtHelpTable = MAKEP (0xFFFF, IDHT_HELPTABLE);
  131.    hmiHelpData.hmodAccelActionBarModule = 0;
  132.    hmiHelpData.idAccelTable = 0;
  133.    hmiHelpData.idActionBar = 0;
  134.    hmiHelpData.pszHelpWindowTitle = "MLEView Help Window";
  135.    hmiHelpData.hmodHelpTableModule = 0;
  136.    hmiHelpData.usShowPanelId = CMIC_HIDE_PANEL_ID;
  137.    hmiHelpData.pszHelpLibraryName = "MLEView.HLP";
  138.  
  139.    /* get profile data */
  140.    if (DosSearchPath (SEARCH_ENVIRONMENT, "DPATH", "MLEVIEW.INI",
  141.                       szProfilePath, usMaxPathLen) > 0)
  142.       strcpy (szProfilePath, "MLEVIEW.INI");
  143.    if ((hiniProfile = PrfOpenProfile (hab, szProfilePath)) != NULL) {
  144.       PrfQueryProfileSize (hiniProfile, "MLEView", "ViewProfile",
  145.                            &ulProfileSize);
  146.       if (ulProfileSize == sizeof (Profile))
  147.          PrfQueryProfileData (hiniProfile, "MLEView", "ViewProfile",
  148.                               &Profile, &ulProfileSize);
  149.       else
  150.          WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  151.                         "Default Profile in use. This profile\n"
  152.                          "will be saved in the current directory.",
  153.                         "Profile Open/Creation Error",
  154.                         1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  155.       }
  156.    else
  157.       WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  158.                      "Default Profile in use. This profile\n"
  159.                       "will be saved in the current directory.",
  160.                      "Profile Open/Creation Error",
  161.                      1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  162.  
  163.    /* create instance of IPF */
  164.    hwndHelpInstance = WinCreateHelpInstance (hab, &hmiHelpData);
  165.    if (!hwndHelpInstance)
  166.       WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  167.                      "Help Not Available.",
  168.                      "Help Creation Error",
  169.                      1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  170.    else if (hmiHelpData.ulReturnCode) {
  171.       WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  172.                      "Help Terminated Due to Error.",
  173.                      "Help Creation Error",
  174.                      1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  175.       WinDestroyHelpInstance (hwndHelpInstance);
  176.       }
  177.  
  178.    /* create main frame and client windows */
  179.    hwndFrame = WinCreateStdWindow (HWND_DESKTOP, 0L,
  180.                                    &flFrameFlags, szMLEViewClass,
  181.                                    NULL, WS_VISIBLE,
  182.                                    0, ID_RESOURCE, &hwndClient);
  183.    WinQueryWindowPos (hwndClient, &swp);
  184.    hwndMLE = WinCreateWindow (hwndClient, WC_MLE, NULL,
  185.                               MLS_HSCROLL | MLS_VSCROLL |
  186.                               MLS_READONLY | WS_VISIBLE,
  187.                               0, 0, swp.cx, swp.cy,
  188.                               hwndClient, HWND_BOTTOM, 1, NULL, NULL);
  189.    WinSetFocus (HWND_DESKTOP, hwndMLE);
  190.  
  191.    /* associate instance of IPF */
  192.    if (hwndHelpInstance)
  193.       WinAssociateHelpInstance (hwndHelpInstance, hwndFrame);
  194.  
  195.    /* set initial text in the frame title bar */
  196.    hwndTitleBar = WinWindowFromID (hwndFrame, FID_TITLEBAR);
  197.    WinSetWindowText (hwndTitleBar, szTitleText);
  198.  
  199.    /* get frame window menu bar handle and initialize MLE window */
  200.    hwndMenu = WinWindowFromID (WinQueryWindow (hwndClient, QW_PARENT,
  201.                                FALSE), FID_MENU);
  202.    MLEInit ();
  203.  
  204.    /* if a filename was passed as an input argument, process it */
  205.    if (argc > 1) {
  206.       Filename = argv [1];
  207.       DosOpen (Filename, &hFile, &usAction, 0, 0, FILE_OPEN,
  208.                OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE, 0);
  209.       WinPostMsg (hwndClient, WM_USER_LOADFILE, NULL, NULL);
  210.       }
  211.  
  212.    /* window was created invisible, so now show it */
  213.    WinShowWindow (hwndFrame, TRUE);
  214.  
  215.    /* main message loop */
  216.    while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  217.       WinDispatchMsg (hab, &qmsg);
  218.  
  219.    WinDestroyWindow (hwndFrame);
  220.    WinDestroyMsgQueue (hmq);
  221.    WinTerminate (hab);
  222.    return 0;
  223.    }
  224.  
  225.  
  226. #pragma subtitle ("ClientProc Procedure")
  227. #pragma page()
  228.  
  229. /*--------------------------------------------------------------------*/
  230. /* ClientProc - This is the main client window procedure.             */
  231. /*--------------------------------------------------------------------*/
  232.  
  233. MRESULT EXPENTRY ClientProc (HWND hwnd, USHORT msg, MPARAM mp1,
  234.                              MPARAM mp2) {
  235.  
  236.    LONG                 lTextLen;       /* text length of MLE         */
  237.    LONG                 lStart, lEnd;   /* selected text length of MLE*/
  238.    USHORT               usAction;       /* file open action           */
  239.    USHORT               usResult;       /* file open result           */
  240.    SWP                  swp;            /* window position            */
  241.  
  242.    switch (msg) {
  243.  
  244.       case WM_INITMENU:
  245.          switch (SHORT1FROMMP (mp1)) {
  246.             case IDM_EDIT:
  247.                /* Check to see if any text is selected */
  248.                lStart = (LONG) WinSendMsg (hwndMLE, MLM_QUERYSEL,
  249.                                            (MPARAM) MLFQS_MINSEL, 0L);
  250.                lEnd = (LONG) WinSendMsg (hwndMLE, MLM_QUERYSEL,
  251.                                          (MPARAM) MLFQS_MAXSEL, 0L);
  252.                if (lEnd - lStart > 0L)
  253.                   /* enable copy menu option */
  254.                   WinSendMsg (hwndMenu, MM_SETITEMATTR,
  255.                               MPFROM2SHORT (IDM_COPY, TRUE),
  256.                               MPFROM2SHORT (MIA_DISABLED, 0));
  257.                else
  258.                   /* disable copy menu option */
  259.                   WinSendMsg (hwndMenu, MM_SETITEMATTR,
  260.                               MPFROM2SHORT (IDM_COPY, TRUE),
  261.                               MPFROM2SHORT (MIA_DISABLED, MIA_DISABLED));
  262.                return 0;
  263.  
  264.             default:
  265.                break;
  266.             }
  267.  
  268.       case WM_COMMAND:
  269.          switch (COMMANDMSG (&msg) -> cmd) {
  270.             case IDM_OPEN:
  271.                /* File open menu item chosen */
  272.                usResult = FileOpenDlg (HWND_DESKTOP, NULL, NULL,
  273.                                        "*.*", FILE_NORMAL, NULL,
  274.                                        Filename, &hFile, 0L, &usAction,
  275.                                        FILE_NORMAL, FILE_OPEN,
  276.                                        OPEN_ACCESS_READONLY |
  277.                                         OPEN_SHARE_DENYWRITE,
  278.                                        0l);
  279.                if (usResult == FDLG_OK) {
  280.                   WinDestroyWindow (hwndMLE);
  281.                   WinQueryWindowPos (hwndClient, &swp);
  282.                   hwndMLE = WinCreateWindow (hwndClient, WC_MLE, NULL,
  283.                                      MLS_HSCROLL | MLS_VSCROLL |
  284.                                      MLS_READONLY | WS_VISIBLE,
  285.                                      0, 0, swp.cx, swp.cy,
  286.                                      hwnd, HWND_BOTTOM, 1, NULL, NULL);
  287.                   WinSetFocus (HWND_DESKTOP, hwndMLE);
  288.                   MLEInit ();
  289.                   WinSendMsg (hwnd, WM_USER_LOADFILE, 0L, 0L);
  290.                   }
  291.                return 0;
  292.  
  293.             case IDM_SETFONT:
  294.                /* Set font menu item chosen */
  295.                WinDlgBox (HWND_DESKTOP, hwnd, SetFontDlgProc, 0,
  296.                           IDD_SETFONT, NULL);
  297.                return 0;
  298.  
  299.             case IDM_SETCOLORS:
  300.                /* Set colors menu item chosen */
  301.                WinDlgBox (HWND_DESKTOP, hwnd, SetColorDlgProc, 0,
  302.                           IDD_SETCOLORS, NULL);
  303.                return 0;
  304.  
  305.             case IDM_WORDWRAP:
  306.                /* Toggle word wrap menu item */
  307.                if (Profile.fWordWrap) {
  308.                   Profile.fWordWrap = FALSE;
  309.                   WinSendMsg (hwndMenu, MM_SETITEMATTR,
  310.                               MPFROM2SHORT (IDM_WORDWRAP, TRUE),
  311.                               MPFROM2SHORT (MIA_CHECKED, 0));
  312.                   WinSendMsg (hwndMLE, MLM_SETWRAP,
  313.                               MPFROMSHORT (Profile.fWordWrap), 0);
  314.                   }
  315.                else {
  316.                   Profile.fWordWrap = TRUE;
  317.                   WinSendMsg (hwndMenu, MM_SETITEMATTR,
  318.                               MPFROM2SHORT (IDM_WORDWRAP, TRUE),
  319.                               MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  320.                   WinSendMsg (hwndMLE, MLM_SETWRAP,
  321.                               MPFROMSHORT (Profile.fWordWrap), 0);
  322.                   }
  323.                return 0;
  324.  
  325.             case IDM_COPY:
  326.                /* Copy menu item chosen */
  327.                WinSendMsg (hwndMLE, MLM_COPY, 0L, 0L);
  328.                return 0;
  329.  
  330.             case IDM_FIND:
  331.                /* Find menu item chosen */
  332.                WinDlgBox (HWND_DESKTOP, hwnd, FindDlgProc, 0,
  333.                           IDD_FIND, NULL);
  334.                return 0;
  335.  
  336.             case IDM_SELECTALL:
  337.                /* Copy menu item chosen */
  338.                lTextLen = (LONG) WinSendMsg (hwndMLE, MLM_QUERYTEXTLENGTH,
  339.                                              0L, 0L);
  340.                WinSendMsg (hwndMLE, MLM_SETSEL, 0L, MPFROMLONG (lTextLen));
  341.                return 0;
  342.  
  343.             case IDM_EXIT:
  344.                /* Exit menu item chosen */
  345.                WinSendMsg (hwnd, WM_CLOSE, 0L, 0L);
  346.                return 0;
  347.  
  348.             case IDM_HELPFORHELP:
  349.                /* show help for IPF system */
  350.                if (hwndHelpInstance)
  351.                   WinSendMsg (hwndHelpInstance, HM_DISPLAY_HELP, 0L, 0L);
  352.                break;
  353.  
  354.             case IDM_HELPFORVIEW:
  355.                /* show help for MLEView */
  356.                if (hwndHelpInstance)
  357.                   WinSendMsg (hwndHelpInstance, HM_EXT_HELP, 0L, 0L);
  358.                break;
  359.  
  360.             case IDM_KEYS:
  361.                /* show help for keys */
  362.                if (hwndHelpInstance)
  363.                   WinSendMsg (hwndHelpInstance, HM_KEYS_HELP, 0L, 0L);
  364.                break;
  365.  
  366.             case IDM_INDEX:
  367.                /* show help index */
  368.                if (hwndHelpInstance)
  369.                   WinSendMsg (hwndHelpInstance, HM_HELP_INDEX, 0L, 0L);
  370.                break;
  371.  
  372.             case IDM_ABOUT:
  373.                /* About menu item chosen */
  374.                WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc,
  375.                           0, IDD_ABOUT, NULL);
  376.                return 0;
  377.  
  378.             default:
  379.                break;
  380.             }
  381.          break;
  382.  
  383.       case HM_QUERY_KEYS_HELP:
  384.          /* show keys help panel */
  385.          return ((MRESULT) IDXH_KEYSHELP);
  386.  
  387.       case WM_HELP:
  388.          /* All WM_HELP messages should be processed by the default */
  389.          /* window procedure.                                       */
  390.          break;
  391.  
  392.       case HM_ERROR:
  393.          /* there was an error during the display of help */
  394.          if (hwndHelpInstance) {
  395.             switch (LONGFROMMP (mp1)) {
  396.                case HMERR_HELPITEM_NOT_FOUND:
  397.                   WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  398.                                  "Help not available for this resource.",
  399.                                  "Help Note", 1,
  400.                                  MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  401.                   break;
  402.                default:
  403.                   WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  404.                                  "Help terminated due to error.",
  405.                                  "Help Error", 1,
  406.                                  MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  407.                   WinDestroyHelpInstance (hwndHelpInstance);
  408.                   break;
  409.                }
  410.             }
  411.          break;
  412.  
  413.       case HM_HELPSUBITEM_NOT_FOUND:
  414.          /* no associated panel id could be found in help lib */
  415.          if (hwndHelpInstance) {
  416.             WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  417.                            "Help not available for this resource.",
  418.                            "Help Note", 1,
  419.                            MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  420.             return (MRESULT) TRUE;
  421.             }
  422.          break;
  423.  
  424.       case WM_SIZE:
  425.          WinSetWindowPos (hwndMLE, NULL, 0, 0,
  426.                           SHORT1FROMMP (mp2),
  427.                           SHORT2FROMMP (mp2),
  428.                           SWP_MOVE | SWP_SIZE);
  429.          return 0;
  430.  
  431.       case WM_CLOSE:
  432.          /* cleanup */
  433.          if (hwndHelpInstance)
  434.             WinDestroyHelpInstance (hwndHelpInstance);
  435.          if (hiniProfile != 0) {
  436.             PrfWriteProfileData (hiniProfile, "MLEView", "ViewProfile",
  437.                                  &Profile, sizeof (Profile));
  438.             PrfCloseProfile (hiniProfile);
  439.             }
  440.          else
  441.             WinMessageBox (HWND_DESKTOP, hwnd,
  442.                            "Profile not saved.",
  443.                            "Profile Open/Creation Error",
  444.                            1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  445.          break;
  446.  
  447.       case WM_USER_LOADFILE:
  448.          MLELoad ();
  449.          return 0;
  450.  
  451.       default:
  452.          break;
  453.       }
  454.    return WinDefWindowProc (hwnd, msg, mp1, mp2);
  455.    }
  456.  
  457.  
  458. #pragma subtitle ("AboutDlgProc Procedure")
  459. #pragma page()
  460.  
  461. /*--------------------------------------------------------------------*/
  462. /* AboutDlgProc - This procedure handles the About menu selection.    */
  463. /*--------------------------------------------------------------------*/
  464.  
  465. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) {
  466.  
  467.    switch (msg) {
  468.       case WM_COMMAND:
  469.          switch (COMMANDMSG (&msg) -> cmd) {
  470.             case DID_OK:
  471.             case DID_CANCEL:
  472.                WinDismissDlg (hwnd, TRUE);
  473.                return 0;
  474.             }
  475.          break;
  476.       }
  477.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  478.    }
  479.  
  480.  
  481. #pragma subtitle ("MLEInit Procedure")
  482. #pragma page()
  483.  
  484. /*--------------------------------------------------------------------*/
  485. /* MLEInit - initialize the MLE window from the profile.              */
  486. /*--------------------------------------------------------------------*/
  487.  
  488. static VOID MLEInit (VOID) {
  489.    HPS hps;
  490.  
  491.    /* set text limit to infinity */
  492.    WinSendMsg (hwndMLE, MLM_SETTEXTLIMIT, (MPARAM) -1, NULL);
  493.  
  494.    /* set the MLE format to match the clipboard text format */
  495.    WinSendMsg (hwndMLE, MLM_FORMAT, MLFIE_CFTEXT, NULL);
  496.  
  497.    /* set the MLE word wrap */
  498.    WinSendMsg (hwndMLE, MLM_SETWRAP, MPFROMSHORT (Profile.fWordWrap),
  499.                NULL);
  500.    if (Profile.fWordWrap)
  501.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  502.                   MPFROM2SHORT (IDM_WORDWRAP, Profile.fWordWrap),
  503.                   MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED));
  504.    else
  505.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  506.                   MPFROM2SHORT (IDM_WORDWRAP, Profile.fWordWrap),
  507.                   MPFROM2SHORT (MIA_CHECKED, 0));
  508.  
  509.    /* set the MLE font */
  510.    if (strcmp (Profile.fatFont.szFacename, "NULL") == 0)
  511.       /* no font specified in profile so copy the default font */
  512.       WinSendMsg (hwndMLE, MLM_QUERYFONT, &Profile.fatFont, NULL);
  513.    else
  514.       WinSendMsg (hwndMLE, MLM_SETFONT, &Profile.fatFont, NULL);
  515.  
  516.    /* set text and background colors */
  517.    WinSendMsg (hwndMLE, MLM_SETTEXTCOLOR,
  518.                MPFROMLONG (Profile.clrText), NULL);
  519.    WinSendMsg (hwndMLE, MLM_SETBACKCOLOR,
  520.                MPFROMLONG (Profile.clrBackground), NULL);
  521.  
  522.    /* get font attributes */
  523.    hps = WinGetPS (hwndMLE);
  524.    EzfQueryFonts (hps);
  525.    WinReleasePS (hps);
  526.    }
  527.  
  528.  
  529. #pragma subtitle ("MLELoad Procedure")
  530. #pragma page()
  531.  
  532. /*--------------------------------------------------------------------*/
  533. /* MLELoad - loads a file into the MLE window and enables/disables    */
  534. /*           menu options.                                            */
  535. /*--------------------------------------------------------------------*/
  536.  
  537. static VOID MLELoad (VOID) {
  538.    static USHORT usBufSize = 65535;
  539.    SEL           selBuffer;
  540.    PVOID         pBuffer;
  541.    IPT           iptTextLength;
  542.    USHORT        usBytesRead;
  543.  
  544.    /* allocate a buffer for DosRead and the MLE import */
  545.    DosAllocSeg (usBufSize, &selBuffer, SEG_NONSHARED);
  546.    pBuffer = MAKEP (selBuffer, 0);
  547.    WinSendMsg (hwndMLE, MLM_SETIMPORTEXPORT, pBuffer,
  548.                MPFROMSHORT (usBufSize));
  549.  
  550.    /* disable refresh of the MLE window while we load it */
  551.    WinSendMsg (hwndMLE, MLM_DISABLEREFRESH, NULL, NULL);
  552.  
  553.    /* clear the current contents of the MLE */
  554.    iptTextLength = (IPT) WinSendMsg (hwndMLE, MLM_QUERYTEXTLENGTH,
  555.                                      NULL, NULL);
  556.    WinSendMsg (hwndMLE, MLM_DELETE, 0, (MPARAM) iptTextLength);
  557.  
  558.    /* the file is already open so read it and import till done */
  559.    iptTextLength = 0;
  560.    DosRead (hFile, pBuffer, usBufSize, &usBytesRead);
  561.    while (usBytesRead > 0) {
  562.       WinSendMsg (hwndMLE, MLM_IMPORT, (MPARAM) &iptTextLength,
  563.                   MPFROMSHORT (usBytesRead));
  564.       DosRead (hFile, pBuffer, usBufSize, &usBytesRead);
  565.       }
  566.  
  567.    /* delete the DosRead buffer and close file */
  568.    DosFreeSeg (selBuffer);
  569.    DosClose (hFile);
  570.    hFile = 0;
  571.  
  572.    /* enable MLE refreshes */
  573.    WinSendMsg (hwndMLE, MLM_ENABLEREFRESH, NULL, NULL);
  574.  
  575.    /* enable the menu Edit options if text was loaded */
  576.    if (iptTextLength > 0) {
  577.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  578.                   MPFROM2SHORT (IDM_FIND, TRUE),
  579.                   MPFROM2SHORT (MIA_DISABLED, 0));
  580.       WinSendMsg (hwndMenu, MM_SETITEMATTR,
  581.                   MPFROM2SHORT (IDM_SELECTALL, TRUE),
  582.                   MPFROM2SHORT (MIA_DISABLED, 0));
  583.       }
  584.  
  585.    /* set the title window text */
  586.    strcpy (szTitleText, szTitle);
  587.    strcat (szTitleText, Filename);
  588.    WinSetWindowText (hwndTitleBar, szTitleText);
  589.    }
  590.  
  591.  
  592. #pragma subtitle ("SetFontDlgProc Procedure")
  593. #pragma page()
  594.  
  595. /*--------------------------------------------------------------------*/
  596. /* SetFontDlgProc - This procedure handles the selection of fonts.    */
  597. /*--------------------------------------------------------------------*/
  598.  
  599. MRESULT EXPENTRY SetFontDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) {
  600.    static HWND        hwndSample = 0;
  601.    SHORT              sCntr, sSelect;
  602.    CHAR               szItemText[FACESIZE];
  603.    RECTL              rcl;
  604.    HWND               hwndSampGB;
  605.    SWP                swp;
  606.  
  607.    switch (msg) {
  608.       case WM_INITDLG:
  609.          /* get current font attributes */
  610.          hwndFont = hwnd;
  611.          WinSendMsg (hwndMLE, MLM_QUERYFONT, MPFROMP(&fat), 0);
  612.          memmove (&fat, &Profile.fatFont, sizeof (FATTRS));
  613.          strcpy (fm.szFacename, fat.szFacename);
  614.  
  615.          /* fill our list boxes */
  616.          FillFontListBox (hwnd);
  617.          FillSizeListBox (hwnd);
  618.  
  619.          /* fill our check boxes */
  620.          if ((fat.fsSelection & FATTR_SEL_BOLD) > 0)
  621.             WinSendDlgItemMsg (hwnd, IDD_BOLD_CB, BM_SETCHECK,
  622.                                MPFROMSHORT (1), 0);
  623.          else
  624.             WinSendDlgItemMsg (hwnd, IDD_BOLD_CB, BM_SETCHECK,
  625.                                MPFROMSHORT (0), 0);
  626.          if ((fat.fsSelection & FATTR_SEL_ITALIC) > 0)
  627.             WinSendDlgItemMsg (hwnd, IDD_ITALIC_CB, BM_SETCHECK,
  628.                                MPFROMSHORT (1), 0);
  629.          else
  630.             WinSendDlgItemMsg (hwnd, IDD_ITALIC_CB, BM_SETCHECK,
  631.                                MPFROMSHORT (0), 0);
  632.          if ((fat.fsSelection & FATTR_SEL_UNDERSCORE) > 0)
  633.             WinSendDlgItemMsg (hwnd, IDD_UNDERS_CB, BM_SETCHECK,
  634.                                MPFROMSHORT (1), 0);
  635.          else
  636.             WinSendDlgItemMsg (hwnd, IDD_UNDERS_CB, BM_SETCHECK,
  637.                                MPFROMSHORT (0), 0);
  638.          if ((fat.fsSelection & FATTR_SEL_STRIKEOUT) > 0)
  639.             WinSendDlgItemMsg (hwnd, IDD_STRIKE_CB, BM_SETCHECK,
  640.                                MPFROMSHORT (1), 0);
  641.          else
  642.             WinSendDlgItemMsg (hwnd, IDD_STRIKE_CB, BM_SETCHECK,
  643.                                MPFROMSHORT (0), 0);
  644.  
  645.          /* create sample text display window */
  646.          hwndSampGB = WinWindowFromID (hwnd, IDW_SAMPLETEXT);
  647.          WinQueryWindowPos (hwndSampGB, &swp);
  648.          hwndSample = WinCreateWindow (hwnd,
  649.                                        szSampleClass, "", WS_VISIBLE,
  650.                                        swp.x + 5, swp.y + 5,
  651.                                        swp.cx - 10,
  652.                                        swp.cy - 25,
  653.                                        WinQueryWindow (hwnd,
  654.                                                        QW_PARENT,
  655.                                                        FALSE),
  656.                                        HWND_TOP, IDW_SAMPLETEXT1,
  657.                                        NULL, NULL);
  658.          WinEnableWindow (WinWindowFromID (hwnd, IDD_APPLY_BT), FALSE);
  659.          WinEnableWindow (WinWindowFromID (hwnd, DID_OK), FALSE);
  660.          return 0;
  661.  
  662.       case WM_CONTROL:
  663.          switch (SHORT1FROMMP (mp1)) {
  664.             case IDD_FONT_LB:
  665.                if (SHORT2FROMMP (mp1) == LN_SELECT) {
  666.                   FillSizeListBox (hwnd);
  667.                   WinQueryWindowRect (hwndSample, &rcl);
  668.                   WinInvalidateRect (hwndSample, &rcl, FALSE);
  669.                   WinEnableWindow (WinWindowFromID (hwnd,
  670.                                    IDD_APPLY_BT), TRUE);
  671.                   WinEnableWindow (WinWindowFromID (hwnd, DID_OK),
  672.                                    TRUE);
  673.                   return 0;
  674.                   }
  675.                else
  676.                   break;
  677.             case IDD_SIZE_LB:
  678.                if (SHORT2FROMMP (mp1) == LN_SELECT) {
  679.                   WinEnableWindow (WinWindowFromID (hwnd,
  680.                                    IDD_APPLY_BT), TRUE);
  681.                   WinEnableWindow (WinWindowFromID (hwnd, DID_OK),
  682.                                    TRUE);
  683.                   WinQueryWindowRect (hwndSample, &rcl);
  684.                   WinInvalidateRect (hwndSample, &rcl, FALSE);
  685.                   return 0;
  686.                   }
  687.                else
  688.                   break;
  689.             case IDD_BOLD_CB:
  690.                if ((SHORT) WinSendDlgItemMsg (hwnd, IDD_BOLD_CB,
  691.                                       BM_QUERYCHECK, 0, 0) == 1)
  692.                   fat.fsSelection |= FATTR_SEL_BOLD;
  693.                else
  694.                   fat.fsSelection &= ~FATTR_SEL_BOLD;
  695.                WinQueryWindowRect (hwndSample, &rcl);
  696.                WinInvalidateRect (hwndSample, &rcl, FALSE);
  697.                WinEnableWindow (WinWindowFromID (hwnd,
  698.                                 IDD_APPLY_BT), TRUE);
  699.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), TRUE);
  700.                return 0;
  701.             case IDD_ITALIC_CB:
  702.                if ((SHORT) WinSendDlgItemMsg (hwnd, IDD_ITALIC_CB,
  703.                                       BM_QUERYCHECK, 0, 0) == 1)
  704.                   fat.fsSelection |= FATTR_SEL_ITALIC;
  705.                else
  706.                   fat.fsSelection &= ~FATTR_SEL_ITALIC;
  707.                WinQueryWindowRect (hwndSample, &rcl);
  708.                WinInvalidateRect (hwndSample, &rcl, FALSE);
  709.                WinEnableWindow (WinWindowFromID (hwnd,
  710.                                 IDD_APPLY_BT), TRUE);
  711.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), TRUE);
  712.                return 0;
  713.             case IDD_UNDERS_CB:
  714.                if ((SHORT) WinSendDlgItemMsg (hwnd, IDD_UNDERS_CB,
  715.                                       BM_QUERYCHECK, 0, 0) == 1)
  716.                   fat.fsSelection |= FATTR_SEL_UNDERSCORE;
  717.                else
  718.                   fat.fsSelection &= ~FATTR_SEL_UNDERSCORE;
  719.                WinQueryWindowRect (hwndSample, &rcl);
  720.                WinInvalidateRect (hwndSample, &rcl, FALSE);
  721.                WinEnableWindow (WinWindowFromID (hwnd,
  722.                                 IDD_APPLY_BT), TRUE);
  723.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), TRUE);
  724.                return 0;
  725.             case IDD_STRIKE_CB:
  726.                if ((SHORT) WinSendDlgItemMsg (hwnd, IDD_STRIKE_CB,
  727.                                       BM_QUERYCHECK, 0, 0) == 1)
  728.                   fat.fsSelection |= FATTR_SEL_STRIKEOUT;
  729.                else
  730.                   fat.fsSelection &= ~FATTR_SEL_STRIKEOUT;
  731.                WinQueryWindowRect (hwndSample, &rcl);
  732.                WinInvalidateRect (hwndSample, &rcl, FALSE);
  733.                WinEnableWindow (WinWindowFromID (hwnd,
  734.                                 IDD_APPLY_BT), TRUE);
  735.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), TRUE);
  736.                return 0;
  737.             default:
  738.                break;
  739.             }
  740.          break;
  741.  
  742.       case WM_COMMAND:
  743.          switch (COMMANDMSG (&msg) -> cmd) {
  744.             case IDD_APPLY_BT:
  745.                Profile.fatFont.usRecordLength = sizeof (FATTRS);
  746.                Profile.fatFont.fsSelection = fat.fsSelection;
  747.                Profile.fatFont.lMatch = fm.lMatch;
  748.                strcpy (Profile.fatFont.szFacename, fm.szFacename);
  749.                Profile.fatFont.idRegistry = 0;
  750.                Profile.fatFont.usCodePage = fm.usCodePage;
  751.                Profile.fatFont.lMaxBaselineExt = 0;
  752.                Profile.fatFont.lAveCharWidth = 0;
  753.                Profile.fatFont.fsType = 0;
  754.                WinSendMsg (hwndMLE, MLM_SETFONT,
  755.                            MPFROMP (&Profile.fatFont), 0);
  756.                WinEnableWindow (WinWindowFromID (hwnd,
  757.                                 IDD_APPLY_BT), FALSE);
  758.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), FALSE);
  759.                return 0;
  760.             case DID_OK:
  761.                Profile.fatFont.usRecordLength = sizeof (FATTRS);
  762.                Profile.fatFont.fsSelection = fat.fsSelection;
  763.                Profile.fatFont.lMatch = fm.lMatch;
  764.                strcpy (Profile.fatFont.szFacename, fm.szFacename);
  765.                Profile.fatFont.idRegistry = 0;
  766.                Profile.fatFont.usCodePage = fm.usCodePage;
  767.                Profile.fatFont.lMaxBaselineExt = 0;
  768.                Profile.fatFont.lAveCharWidth = 0;
  769.                Profile.fatFont.fsType = 0;
  770.                WinSendMsg (hwndMLE, MLM_SETFONT,
  771.                            MPFROMP (&Profile.fatFont), 0);
  772.                WinDismissDlg (hwnd, TRUE);
  773.                return 0;
  774.             case DID_CANCEL:
  775.                WinDismissDlg (hwnd, TRUE);
  776.                return 0;
  777.             }
  778.          break;
  779.  
  780.       default:
  781.          break;
  782.       }
  783.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  784.    }
  785.  
  786.  
  787. #pragma subtitle ("FillFontListBox Procedure")
  788. #pragma page()
  789.  
  790. /*--------------------------------------------------------------------*/
  791. /* FillFontListBox - fills the font list box in the Set font dialog.  */
  792. /*--------------------------------------------------------------------*/
  793.  
  794. static VOID FillFontListBox (HWND hwnd) {
  795.    SHORT       sCntr;
  796.    PCHAR       sFacename;
  797.  
  798.    WinSendDlgItemMsg (hwnd, IDD_FONT_LB, LM_DELETEALL, 0, 0);
  799.    /* insert each face name */
  800.    for (sCntr = 0; sCntr < EZF_NUMFONTFACES; sCntr++) {
  801.       sFacename = EzfQueryFacename (sCntr);
  802.       WinSendDlgItemMsg (hwnd, IDD_FONT_LB, LM_INSERTITEM,
  803.                          MPFROMSHORT (LIT_END),
  804.                          MPFROMP (sFacename));
  805.       /* try to match inserted facename with current facename */
  806.       if (strncmp (sFacename, fm.szFacename, strlen (sFacename)) == 0)
  807.          WinSendDlgItemMsg (hwnd, IDD_FONT_LB, LM_SELECTITEM,
  808.                             MPFROMSHORT (sCntr),
  809.                             MPFROMSHORT ((BOOL) TRUE));
  810.       }
  811.    }
  812.  
  813.  
  814. #pragma subtitle ("FillSizeListBox Procedure")
  815. #pragma page()
  816.  
  817. /*--------------------------------------------------------------------*/
  818. /* FillSizeListBox - fills the size list box in the Set font dialog.  */
  819. /*--------------------------------------------------------------------*/
  820.  
  821. static VOID FillSizeListBox (HWND hwnd) {
  822.    SHORT       sFaceIndex, sCntr, sSize, sItemsInserted = 0;
  823.    BOOL        fItemSelected = FALSE;
  824.    CHAR        szValue [5];
  825.  
  826.    sFaceIndex = (SHORT) WinSendDlgItemMsg (hwnd, IDD_FONT_LB,
  827.                                            LM_QUERYSELECTION,
  828.                                            MPFROMSHORT (LIT_FIRST), 0);
  829.    WinSendDlgItemMsg (hwnd, IDD_SIZE_LB, LM_DELETEALL, 0, 0);
  830.    for (sCntr = 0; sCntr < EZF_NUMSIZES; sCntr++) {
  831.       /* insert only valid sizes for the selected font */
  832.       if (EzfQueryMatchNum (sFaceIndex, sCntr) != 0L) {
  833.          sSize = EzfQuerySize (sCntr);
  834.          sprintf (szValue, "%2d", sSize / 10);
  835.          WinSendDlgItemMsg (hwnd, IDD_SIZE_LB, LM_INSERTITEM,
  836.                             MPFROMSHORT (LIT_END),
  837.                             MPFROMP (szValue));
  838.          /* try to match the inserted size with old size */
  839.          if (sSize == fm.sNominalPointSize) {
  840.             WinSendDlgItemMsg (hwnd, IDD_SIZE_LB, LM_SELECTITEM,
  841.                                MPFROMSHORT (sItemsInserted),
  842.                                MPFROMSHORT ((BOOL) TRUE));
  843.             fItemSelected = TRUE;
  844.             }
  845.          sItemsInserted++;
  846.          }
  847.       }
  848.    if (fItemSelected == FALSE)
  849.       /* if no item was selected above then select the first item */
  850.       WinSendDlgItemMsg (hwnd, IDD_SIZE_LB, LM_SELECTITEM,
  851.                          MPFROMSHORT (0), MPFROMSHORT ((BOOL) TRUE));
  852.    }
  853.  
  854.  
  855. #pragma subtitle ("SampleTextProc Procedure")
  856. #pragma page()
  857.  
  858. /*--------------------------------------------------------------------*/
  859. /* SampleTextProc - window procedure to display some sample text      */
  860. /*                  of a particular font size and style on the        */
  861. /*                  set font dialog box window.                       */
  862. /*--------------------------------------------------------------------*/
  863.  
  864. MRESULT EXPENTRY SampleTextProc (HWND hwnd, USHORT msg, MPARAM mp1,
  865.                                     MPARAM mp2) {
  866.    static CHAR  szAlphabet [27] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
  867.    HPS          hps;
  868.    POINTL       ptl;
  869.    SHORT        sFacenameIndex, sSizeIndex, sSize, sSelected;
  870.    CHAR         szSizeText[5];
  871.  
  872.    switch (msg) {
  873.       case WM_PAINT:
  874.          hps = WinBeginPaint (hwnd, 0, NULL);
  875.          GpiErase (hps);
  876.          sFacenameIndex = (SHORT) WinSendDlgItemMsg (hwndFont,
  877.                                         IDD_FONT_LB, LM_QUERYSELECTION,
  878.                                         MPFROMSHORT (LIT_FIRST), 0);
  879.          sSelected = (SHORT) WinSendDlgItemMsg (hwndFont, IDD_SIZE_LB,
  880.                                         LM_QUERYSELECTION, 0, 0);
  881.          WinSendDlgItemMsg (hwndFont, IDD_SIZE_LB, LM_QUERYITEMTEXT,
  882.                             MPFROM2SHORT (sSelected, 5), szSizeText);
  883.          sSize = atoi (szSizeText) * 10;
  884.          sSizeIndex = EzfQuerySizeIndex (sSize);
  885.          EzfCreateLogFont (hps, LCID_MYFONT, sFacenameIndex, sSizeIndex,
  886.                            fat.fsSelection);
  887.          GpiSetCharSet (hps, LCID_MYFONT);
  888.          GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm);
  889.          ptl.x = 0;
  890.          ptl.y = fm.lMaxDescender;
  891.          GpiCharStringAt (hps, &ptl, (LONG) strlen (szAlphabet),
  892.                           szAlphabet);
  893.          GpiSetCharSet (hps, LCID_DEFAULT);
  894.          GpiDeleteSetId (hps, LCID_MYFONT);
  895.          WinEndPaint (hps);
  896.          return 0;
  897.  
  898.       default:
  899.          break;
  900.       }
  901.    return WinDefWindowProc (hwnd, msg, mp1, mp2);
  902.    }
  903.  
  904.  
  905. #pragma subtitle ("SetColorDlgProc Procedure")
  906. #pragma page()
  907.  
  908. /*--------------------------------------------------------------------*/
  909. /* SetColorDlgProc - This procedure handles the selection of colors.  */
  910. /*--------------------------------------------------------------------*/
  911.  
  912. MRESULT EXPENTRY SetColorDlgProc (HWND hwnd, USHORT msg, MPARAM mp1,
  913.                                   MPARAM mp2) {
  914.    static HWND        hwndSample = 0;
  915.    RECTL              rcl;
  916.    HWND               hwndSampGB;
  917.    SWP                swp;
  918.    LONG               clrNewB, clrNewT;
  919.    SHORT              sClrIndex;
  920.  
  921.    switch (msg) {
  922.       case WM_INITDLG:
  923.          hwndColor = hwnd;
  924.  
  925.          /* fill our list boxes */
  926.          FillForgListBox (hwnd);
  927.          FillBakgListBox (hwnd);
  928.  
  929.          /* create sample text display window */
  930.          hwndSampGB = WinWindowFromID (hwnd, IDW_COLORTEXT);
  931.          WinQueryWindowPos (hwndSampGB, &swp);
  932.          hwndSample = WinCreateWindow (hwnd,
  933.                                        szSColorClass, "", WS_VISIBLE,
  934.                                        swp.x + 5, swp.y + 5,
  935.                                        swp.cx - 10,
  936.                                        swp.cy - 27,
  937.                                        WinQueryWindow (hwnd,
  938.                                                        QW_PARENT,
  939.                                                        FALSE),
  940.                                        HWND_TOP, IDW_COLORTEXT1,
  941.                                        NULL, NULL);
  942.          WinEnableWindow (WinWindowFromID (hwnd, IDD_APPLYC_BT), FALSE);
  943.          WinEnableWindow (WinWindowFromID (hwnd, DID_OK), FALSE);
  944.          return 0;
  945.  
  946.       case WM_CONTROL:
  947.          switch (SHORT1FROMMP (mp1)) {
  948.             case IDD_FORG_LB:
  949.                if (SHORT2FROMMP (mp1) == LN_SELECT) {
  950.                   WinQueryWindowRect (hwndSample, &rcl);
  951.                   WinInvalidateRect (hwndSample, &rcl, FALSE);
  952.                   WinEnableWindow (WinWindowFromID (hwnd,
  953.                                    IDD_APPLYC_BT), TRUE);
  954.                   WinEnableWindow (WinWindowFromID (hwnd, DID_OK),
  955.                                    TRUE);
  956.                   return 0;
  957.                   }
  958.                else
  959.                   break;
  960.             case IDD_BAKG_LB:
  961.                if (SHORT2FROMMP (mp1) == LN_SELECT) {
  962.                   WinEnableWindow (WinWindowFromID (hwnd,
  963.                                    IDD_APPLYC_BT), TRUE);
  964.                   WinEnableWindow (WinWindowFromID (hwnd, DID_OK),
  965.                                    TRUE);
  966.                   WinQueryWindowRect (hwndSample, &rcl);
  967.                   WinInvalidateRect (hwndSample, &rcl, FALSE);
  968.                   return 0;
  969.                   }
  970.                else
  971.                   break;
  972.             default:
  973.                break;
  974.             }
  975.          break;
  976.  
  977.       case WM_COMMAND:
  978.          switch (COMMANDMSG (&msg) -> cmd) {
  979.             case IDD_APPLYC_BT:
  980.                WinEnableWindow (WinWindowFromID (hwnd,
  981.                                 IDD_APPLYC_BT), FALSE);
  982.                WinEnableWindow (WinWindowFromID (hwnd, DID_OK), FALSE);
  983.                sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  984.                             IDD_FORG_LB, LM_QUERYSELECTION, 0, 0);
  985.                clrNewT = ColorTable[sClrIndex].clr;
  986.                sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  987.                             IDD_BAKG_LB, LM_QUERYSELECTION, 0, 0);
  988.                clrNewB = ColorTable[sClrIndex].clr;
  989.                Profile.clrText = clrNewT;
  990.                Profile.clrBackground = clrNewB;
  991.                WinSendMsg (hwndMLE, MLM_SETBACKCOLOR,
  992.                            MPFROMLONG (clrNewB), 0);
  993.                WinSendMsg (hwndMLE, MLM_SETTEXTCOLOR,
  994.                            MPFROMLONG (clrNewT), 0);
  995.                return 0;
  996.             case DID_OK:
  997.                sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  998.                             IDD_FORG_LB, LM_QUERYSELECTION, 0, 0);
  999.                clrNewT = ColorTable[sClrIndex].clr;
  1000.                sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  1001.                             IDD_BAKG_LB, LM_QUERYSELECTION, 0, 0);
  1002.                clrNewB = ColorTable[sClrIndex].clr;
  1003.                Profile.clrText = clrNewT;
  1004.                Profile.clrBackground = clrNewB;
  1005.                WinSendMsg (hwndMLE, MLM_SETBACKCOLOR,
  1006.                            MPFROMLONG (clrNewB), 0);
  1007.                WinSendMsg (hwndMLE, MLM_SETTEXTCOLOR,
  1008.                            MPFROMLONG (clrNewT), 0);
  1009.                WinDismissDlg (hwnd, TRUE);
  1010.                return 0;
  1011.             case DID_CANCEL:
  1012.                WinDismissDlg (hwnd, TRUE);
  1013.                return 0;
  1014.             }
  1015.          break;
  1016.  
  1017.       default:
  1018.          break;
  1019.       }
  1020.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1021.    }
  1022.  
  1023.  
  1024. #pragma subtitle ("FindDlgProc Procedure")
  1025. #pragma page()
  1026.  
  1027. /*--------------------------------------------------------------------*/
  1028. /* FindDlgProc - This procedure handles the Find text dialog.         */
  1029. /*--------------------------------------------------------------------*/
  1030.  
  1031. MRESULT EXPENTRY FindDlgProc (HWND hwnd, USHORT msg, MPARAM mp1,
  1032.                               MPARAM mp2) {
  1033.    static CHAR           szFindText [81] = "\0";
  1034.    static MLE_SEARCHDATA MLE_SearchData;
  1035.    LONG                  lTextLen, lCursorPos;
  1036.    USHORT                fResult;
  1037.  
  1038.    switch (msg) {
  1039.       case WM_INITDLG:
  1040.          if (strlen (szFindText) == 0)
  1041.             WinSendDlgItemMsg (hwnd, IDD_FINDENTRY, EM_SETTEXTLIMIT,
  1042.                                MPFROMSHORT (80), 0);
  1043.          else {
  1044.             WinSetDlgItemText (hwnd, IDD_FINDENTRY, szFindText);
  1045.             WinSendDlgItemMsg (hwnd, IDD_FINDENTRY, EM_SETSEL,
  1046.                                MPFROM2SHORT (0,
  1047.                                 strlen (szFindText)), 0);
  1048.             }
  1049.          WinSendDlgItemMsg (hwnd, IDD_CASESEN,
  1050.                             BM_SETCHECK, MPFROMSHORT (Profile.fCase), 0);
  1051.          WinSendDlgItemMsg (hwnd, IDD_FINDWRAP,
  1052.                             BM_SETCHECK, MPFROMSHORT (Profile.fWrap), 0);
  1053.          return 0;
  1054.  
  1055.       case WM_CONTROL:
  1056.          switch (SHORT1FROMMP (mp1)) {
  1057.             case IDD_CASESEN:
  1058.                if (Profile.fCase)
  1059.                   Profile.fCase = FALSE;
  1060.                else
  1061.                   Profile.fCase = TRUE;
  1062.                WinSendDlgItemMsg (hwnd, IDD_CASESEN, BM_SETCHECK,
  1063.                                   MPFROMSHORT (Profile.fCase), 0);
  1064.                return 0;
  1065.             case IDD_FINDWRAP:
  1066.                if (Profile.fWrap)
  1067.                   Profile.fWrap = FALSE;
  1068.                else
  1069.                   Profile.fWrap = TRUE;
  1070.                WinSendDlgItemMsg (hwnd, IDD_FINDWRAP, BM_SETCHECK,
  1071.                                   MPFROMSHORT (Profile.fWrap), 0);
  1072.                return 0;
  1073.             default:
  1074.                break;
  1075.             }
  1076.          break;
  1077.  
  1078.       case WM_COMMAND:
  1079.          switch (COMMANDMSG (&msg) -> cmd) {
  1080.             case DID_OK:
  1081.                WinQueryDlgItemText (hwnd, IDD_FINDENTRY, 80,
  1082.                               MPFROMP (&szFindText));
  1083.                if (strlen (szFindText) == 0) {
  1084.                   WinMessageBox (HWND_DESKTOP, hwnd,
  1085.                         "There is no text in the \"Find:\" field.",
  1086.                         "Find Notification",
  1087.                         1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  1088.                   return 0;
  1089.                   }
  1090.                MLE_SearchData.cb = sizeof (MLE_SEARCHDATA);
  1091.                MLE_SearchData.pchFind = szFindText;
  1092.                MLE_SearchData.pchReplace = NULL;
  1093.                MLE_SearchData.cchFind = 0;
  1094.                MLE_SearchData.cchReplace = 0;
  1095.                MLE_SearchData.iptStart = -1;
  1096.                MLE_SearchData.iptStop = -1;
  1097.                MLE_SearchData.cchFound = 0;
  1098.                if (Profile.fCase)
  1099.                   fResult = (USHORT) WinSendMsg (hwndMLE, MLM_SEARCH,
  1100.                               (MPARAM) (LONG) (MLFSEARCH_CASESENSITIVE |
  1101.                               MLFSEARCH_SELECTMATCH),
  1102.                               MPFROMP (&MLE_SearchData));
  1103.                else
  1104.                   fResult = (USHORT) WinSendMsg (hwndMLE, MLM_SEARCH,
  1105.                               (MPARAM) (LONG) MLFSEARCH_SELECTMATCH,
  1106.                               MPFROMP (&MLE_SearchData));
  1107.                if ((fResult == FALSE) && (Profile.fWrap == TRUE)) {
  1108.                   MLE_SearchData.iptStart = 0;
  1109.                   if (Profile.fCase)
  1110.                      fResult = (USHORT) WinSendMsg (hwndMLE, MLM_SEARCH,
  1111.                                  (MPARAM) (LONG) (MLFSEARCH_CASESENSITIVE |
  1112.                                  MLFSEARCH_SELECTMATCH),
  1113.                                  MPFROMP (&MLE_SearchData));
  1114.                   else
  1115.                      fResult = (USHORT) WinSendMsg (hwndMLE, MLM_SEARCH,
  1116.                                  (MPARAM) (LONG) MLFSEARCH_SELECTMATCH,
  1117.                                  MPFROMP (&MLE_SearchData));
  1118.                   }
  1119.                if (!fResult) {
  1120.                   lCursorPos = (LONG) WinSendMsg (hwndMLE,
  1121.                                    MLM_QUERYSEL,
  1122.                                    (MPARAM) (LONG) MLFQS_CURSORSEL, 0);
  1123.                   WinSendMsg (hwndMLE, MLM_SETSEL,
  1124.                               MPFROMLONG (lCursorPos),
  1125.                               MPFROMLONG (lCursorPos));
  1126.                   WinMessageBox (HWND_DESKTOP, hwnd,
  1127.                         "The text in the \"Find:\" field cannot be found.",
  1128.                         "Find Notification",
  1129.                         1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  1130.                   }
  1131.                return 0;
  1132.             case DID_CANCEL:
  1133.                WinDismissDlg (hwnd, TRUE);
  1134.                return 0;
  1135.             }
  1136.          break;
  1137.  
  1138.       default:
  1139.          break;
  1140.       }
  1141.    return WinDefDlgProc (hwnd, msg, mp1, mp2);
  1142.    }
  1143.  
  1144.  
  1145. #pragma subtitle ("FillFontListBox Procedure")
  1146. #pragma page()
  1147.  
  1148. /*--------------------------------------------------------------------*/
  1149. /* FillForgListBox - fills the foreground list box in the Set Color   */
  1150. /*                   dialog.                                          */
  1151. /*--------------------------------------------------------------------*/
  1152.  
  1153. static VOID FillForgListBox (HWND hwnd) {
  1154.    SHORT       sCntr;
  1155.  
  1156.    WinSendDlgItemMsg (hwnd, IDD_BAKG_LB, LM_DELETEALL, 0, 0);
  1157.    /* insert each face name */
  1158.    for (sCntr = 0; sCntr < 17; sCntr++) {
  1159.       WinSendDlgItemMsg (hwnd, IDD_FORG_LB, LM_INSERTITEM,
  1160.                          MPFROMSHORT (LIT_END),
  1161.                          MPFROMP (ColorTable[sCntr].szColor));
  1162.       /* try to match inserted color with current color */
  1163.       if (ColorTable[sCntr].clr == Profile.clrText)
  1164.          WinSendDlgItemMsg (hwnd, IDD_FORG_LB, LM_SELECTITEM,
  1165.                             MPFROMSHORT (sCntr),
  1166.                             MPFROMSHORT ((BOOL) TRUE));
  1167.       }
  1168.    }
  1169.  
  1170.  
  1171. #pragma subtitle ("FillSizeListBox Procedure")
  1172. #pragma page()
  1173.  
  1174. /*--------------------------------------------------------------------*/
  1175. /* FillBakgListBox - fills the background list box in the Set color   */
  1176. /*                   dialog.                                          */
  1177. /*--------------------------------------------------------------------*/
  1178.  
  1179. static VOID FillBakgListBox (HWND hwnd) {
  1180.    SHORT       sCntr;
  1181.  
  1182.    WinSendDlgItemMsg (hwnd, IDD_BAKG_LB, LM_DELETEALL, 0, 0);
  1183.    for (sCntr = 0; sCntr < 17; sCntr++) {
  1184.       WinSendDlgItemMsg (hwnd, IDD_BAKG_LB, LM_INSERTITEM,
  1185.                          MPFROMSHORT (LIT_END),
  1186.                          MPFROMP (ColorTable[sCntr].szColor));
  1187.       /* try to match the inserted color with old color */
  1188.       if (ColorTable[sCntr].clr == Profile.clrBackground)
  1189.          WinSendDlgItemMsg (hwnd, IDD_BAKG_LB, LM_SELECTITEM,
  1190.                             MPFROMSHORT (sCntr),
  1191.                             MPFROMSHORT ((BOOL) TRUE));
  1192.       }
  1193.    }
  1194.  
  1195.  
  1196. #pragma subtitle ("SampleTextProc Procedure")
  1197. #pragma page()
  1198.  
  1199. /*--------------------------------------------------------------------*/
  1200. /* SampleColorProc - window procedure to display some sample text     */
  1201. /*                   of a particular color on the set color dialog    */
  1202. /*                   bow window.                                      */
  1203. /*--------------------------------------------------------------------*/
  1204.  
  1205. MRESULT EXPENTRY SampleColorProc (HWND hwnd, USHORT msg, MPARAM mp1,
  1206.                                   MPARAM mp2) {
  1207.    static PCHAR szText1 = "This is an example of text.";
  1208.    static PCHAR szText2 = "This is an example of selected text.";
  1209.    HPS          hps;
  1210.    POINTL       ptl;
  1211.    SHORT        sClrIndex;
  1212.    LONG         clrNewB, clrNewT;
  1213.    RECTL        rcl;
  1214.  
  1215.    switch (msg) {
  1216.       case WM_PAINT:
  1217.          hps = WinBeginPaint (hwnd, 0, &rcl);
  1218.          GpiSetCharMode (hps, CM_MODE1);
  1219.          GpiQueryFontMetrics (hps, sizeof fm, &fm);
  1220.          /* set background color and fill window with that color */
  1221.          sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  1222.                       IDD_BAKG_LB, LM_QUERYSELECTION, 0, 0);
  1223.          clrNewB = ColorTable[sClrIndex].clr;
  1224.          GpiSetBackColor (hps, clrNewB);
  1225.          WinFillRect (hps, &rcl, clrNewB);
  1226.          /* set foreground color */
  1227.          sClrIndex = (SHORT) WinSendDlgItemMsg (hwndColor,
  1228.                       IDD_FORG_LB, LM_QUERYSELECTION, 0, 0);
  1229.          clrNewT = ColorTable[sClrIndex].clr;
  1230.          GpiSetColor (hps, clrNewT);
  1231.          /* draw the sample text on the screen */
  1232.          ptl.x = 5;
  1233.          ptl.y = (fm.lMaxDescender * 2) + fm.lMaxBaselineExt;
  1234.          GpiCharStringAt (hps, &ptl, (LONG) strlen (szText1),
  1235.                           szText1);
  1236.          /* draw the "selected" sample text on the screen */
  1237.          ptl.x = 5;
  1238.          ptl.y = fm.lMaxDescender * 2;
  1239.          GpiSetMix (hps, FM_NOTCOPYSRC);
  1240.          GpiSetBackMix (hps, BM_XOR);
  1241.          GpiCharStringAt (hps, &ptl, (LONG) strlen (szText2),
  1242.                           szText2);
  1243.          WinEndPaint (hps);
  1244.          return 0;
  1245.  
  1246.       default:
  1247.          break;
  1248.       }
  1249.    return WinDefWindowProc (hwnd, msg, mp1, mp2);
  1250.    }
  1251.  
  1252.