home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1992 / 06 / dflt12 / memopad.c < prev    next >
Text File  |  1992-04-17  |  18KB  |  616 lines

  1. /* --------------- memopad.c ----------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX PrintSetup;
  6.  
  7. char DFlatApplication[] = "MemoPad";
  8.  
  9. static char Untitled[] = "Untitled";
  10. static int wndpos;
  11.  
  12. static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
  13. static void NewFile(WINDOW);
  14. static void SelectFile(WINDOW);
  15. static void PadWindow(WINDOW, char *);
  16. static void OpenPadWindow(WINDOW, char *);
  17. static void LoadFile(WINDOW);
  18. static void PrintPad(WINDOW);
  19. static void SaveFile(WINDOW, int);
  20. static void DeleteFile(WINDOW);
  21. static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
  22. static char *NameComponent(char *);
  23. static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
  24. static void FixTabMenu(void);
  25. #ifndef TURBOC
  26. void Calendar(WINDOW);
  27. #endif
  28. void BarChart(WINDOW);
  29. char **Argv;
  30.  
  31. #define CHARSLINE 80
  32. #define LINESPAGE 66
  33.  
  34. void main(int argc, char *argv[])
  35. {
  36.     WINDOW wnd;
  37.     if (!init_messages())
  38.         return;
  39.     Argv = argv;
  40.     if (!LoadConfig())
  41.         cfg.ScreenLines = SCREENHEIGHT;
  42.     wnd = CreateWindow(APPLICATION,
  43.                         "D-Flat MemoPad " VERSION,
  44.                         0, 0, -1, -1,
  45.                         &MainMenu,
  46.                         NULL,
  47.                         MemoPadProc,
  48.                         MOVEABLE  |
  49.                         SIZEABLE  |
  50.                         HASBORDER |
  51.                         MINMAXBOX |
  52.                         HASSTATUSBAR
  53.                         );
  54.  
  55.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  56.     while (argc > 1)    {
  57.         PadWindow(wnd, argv[1]);
  58.         --argc;
  59.         argv++;
  60.     }
  61.     while (dispatch_message())
  62.         ;
  63. }
  64. /* ------ open text files and put them into editboxes ----- */
  65. static void PadWindow(WINDOW wnd, char *FileName)
  66. {
  67.     int ax, criterr = 1;
  68.     struct ffblk ff;
  69.     char path[64];
  70.     char *cp;
  71.  
  72.     CreatePath(path, FileName, FALSE, FALSE);
  73.     cp = path+strlen(path);
  74.     CreatePath(path, FileName, TRUE, FALSE);
  75.     while (criterr == 1)    {
  76.         ax = findfirst(path, &ff, 0);
  77.         criterr = TestCriticalError();
  78.     }
  79.     while (ax == 0 && !criterr)    {
  80.         strcpy(cp, ff.ff_name);
  81.         OpenPadWindow(wnd, path);
  82.         ax = findnext(&ff);
  83.     }
  84. }
  85. /* ------- window processing module for the
  86.                     memopad application window ----- */
  87. static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  88. {
  89.     int rtn;
  90.     switch (msg)    {
  91.         case CREATE_WINDOW:
  92.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  93.             if (cfg.InsertMode)
  94.                 SetCommandToggle(&MainMenu, ID_INSERT);
  95.             if (cfg.WordWrap)
  96.                 SetCommandToggle(&MainMenu, ID_WRAP);
  97.             FixTabMenu();
  98.             return rtn;
  99.         case COMMAND:
  100.             switch ((int)p1)    {
  101.                 case ID_NEW:
  102.                     NewFile(wnd);
  103.                     return TRUE;
  104.                 case ID_OPEN:
  105.                     SelectFile(wnd);
  106.                     return TRUE;
  107.                 case ID_SAVE:
  108.                     SaveFile(inFocus, FALSE);
  109.                     return TRUE;
  110.                 case ID_SAVEAS:
  111.                     SaveFile(inFocus, TRUE);
  112.                     return TRUE;
  113.                 case ID_DELETEFILE:
  114.                     DeleteFile(inFocus);
  115.                     return TRUE;
  116.                 case ID_PRINTSETUP:
  117.                     DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
  118.                     return TRUE;
  119.                 case ID_PRINT:
  120.                     PrintPad(inFocus);
  121.                     return TRUE;
  122.                 case ID_EXIT:    
  123.                     if (!YesNoBox("Exit Memopad?"))
  124.                         return FALSE;
  125.                     break;
  126.                 case ID_TAB2:
  127.                     cfg.Tabs = 2;
  128.                     FixTabMenu();
  129.                     return TRUE;
  130.                 case ID_TAB4:
  131.                     cfg.Tabs = 4;
  132.                     FixTabMenu();
  133.                     return TRUE;
  134.                 case ID_TAB6:
  135.                     cfg.Tabs = 6;                    
  136.                     FixTabMenu();
  137.                     return TRUE;
  138.                 case ID_TAB8:
  139.                     cfg.Tabs = 8;
  140.                     FixTabMenu();
  141.                     return TRUE;
  142.                 case ID_CALENDAR:
  143. #ifndef TURBOC
  144.                     Calendar(wnd);
  145. #endif
  146.                     return TRUE;
  147.                 case ID_BARCHART:
  148.                     BarChart(wnd);
  149.                     return TRUE;
  150.                 case ID_ABOUT:
  151.                     MessageBox(
  152.                          "About D-Flat and the MemoPad",
  153.                         "   ┌───────────────────────┐\n"
  154.                         "   │    ▄▄▄   ▄▄▄     ▄    │\n"
  155.                         "   │    █  █  █  █    █    │\n"
  156.                         "   │    █  █  █  █    █    │\n"
  157.                         "   │    █  █  █  █ █  █    │\n"
  158.                         "   │    ▀▀▀   ▀▀▀   ▀▀     │\n"
  159.                         "   └───────────────────────┘\n"
  160.                         "D-Flat implements the SAA/CUA\n"
  161.                         "interface in a public domain\n"
  162.                         "C language library originally\n"
  163.                         "published in Dr. Dobb's Journal\n"
  164.                         "    ------------------------ \n"
  165.                         "MemoPad is a multiple document\n"
  166.                         "editor that demonstrates D-Flat");
  167.                     return TRUE;
  168.                 default:
  169.                     break;
  170.             }
  171.             break;
  172.         default:
  173.             break;
  174.     }
  175.     return DefaultWndProc(wnd, msg, p1, p2);
  176. }
  177. /* --- The New command. Open an empty editor window --- */
  178. static void NewFile(WINDOW wnd)
  179. {
  180.     OpenPadWindow(wnd, Untitled);
  181. }
  182. /* --- The Open... command. Select a file  --- */
  183. static void SelectFile(WINDOW wnd)
  184. {
  185.     char FileName[64];
  186.     if (OpenFileDialogBox("*.PAD", FileName))    {
  187.         /* --- see if the document is already in a window --- */
  188.         WINDOW wnd1 = GetFirstChild(wnd);
  189.         while (wnd1 != NULL)    {
  190.             if (stricmp(FileName, wnd1->extension) == 0)    {
  191.                 SendMessage(wnd1, SETFOCUS, TRUE, 0);
  192.                 SendMessage(wnd1, RESTORE, 0, 0);
  193.                 return;
  194.             }
  195.             wnd1 = GetNextChild(wnd, wnd1);
  196.         }
  197.         OpenPadWindow(wnd, FileName);
  198.     }
  199. }
  200.  
  201. /* --- open a document window and load a file --- */
  202. static void OpenPadWindow(WINDOW wnd, char *FileName)
  203. {
  204.     static WINDOW wnd1 = NULL;
  205.     WINDOW wwnd;
  206.     struct stat sb;
  207.     char *Fname = FileName;
  208.     char *ermsg;
  209.     if (strcmp(FileName, Untitled))    {
  210.         if (stat(FileName, &sb))    {
  211.             ermsg = DFmalloc(strlen(FileName)+20);
  212.             strcpy(ermsg, "No such file as\n");
  213.             strcat(ermsg, FileName);
  214.             ErrorMessage(ermsg);
  215.             free(ermsg);
  216.             return;
  217.         }
  218.         Fname = NameComponent(FileName);
  219.     }
  220.     wwnd = WatchIcon();
  221.     wndpos += 2;
  222.     if (wndpos == 20)
  223.         wndpos = 2;
  224.     wnd1 = CreateWindow(EDITBOX,
  225.                 Fname,
  226.                 (wndpos-1)*2, wndpos, 10, 40,
  227.                 NULL, wnd, EditorProc,
  228.                 SHADOW     |
  229.                 MINMAXBOX  |
  230.                 CONTROLBOX |
  231.                 VSCROLLBAR |
  232.                 HSCROLLBAR |
  233.                 MOVEABLE   |
  234.                 HASBORDER  |
  235.                 SIZEABLE   |
  236.                 MULTILINE
  237.     );
  238.     if (strcmp(FileName, Untitled))    {
  239.         wnd1->extension = DFmalloc(strlen(FileName)+1);
  240.         strcpy(wnd1->extension, FileName);
  241.         LoadFile(wnd1);
  242.     }
  243.     SendMessage(wwnd, CLOSE_WINDOW, 0, 0);
  244.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  245. }
  246. /* --- Load the notepad file into the editor text buffer --- */
  247. static void LoadFile(WINDOW wnd)
  248. {
  249.     char *Buf = NULL;
  250.     int recptr = 0;
  251.     FILE *fp;
  252.  
  253.     if ((fp = fopen(wnd->extension, "rt")) != NULL)    {
  254.         while (!feof(fp))    {
  255.             handshake();
  256.             Buf = DFrealloc(Buf, recptr+150);
  257.             fgets(Buf+recptr, 150, fp);
  258.             recptr += strlen(Buf+recptr);
  259.         }
  260.         fclose(fp);
  261.         if (Buf != NULL)    {
  262.             SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
  263.             free(Buf);
  264.         }
  265.     }
  266. }
  267.  
  268. static int LineCtr;
  269. static int CharCtr;
  270.  
  271. /* ------- print a character -------- */
  272. static void PrintChar(FILE *prn, int c)
  273. {
  274.     int i;
  275.     if (c == '\n' || CharCtr == cfg.RightMargin)    {
  276.         fputs("\r\n", prn);
  277.         LineCtr++;
  278.         if (LineCtr == cfg.BottomMargin)    {
  279.             fputc('\f', prn);
  280.             for (i = 0; i < cfg.TopMargin; i++)
  281.                 fputc('\n', prn);
  282.             LineCtr = cfg.TopMargin;
  283.         }
  284.         CharCtr = 0;
  285.         if (c == '\n')
  286.             return;
  287.     }
  288.     if (CharCtr == 0)    {
  289.         for (i = 0; i < cfg.LeftMargin; i++)    {
  290.             fputc(' ', prn);
  291.             CharCtr++;
  292.         }
  293.     }
  294.     CharCtr++;
  295.     fputc(c, prn);
  296. }
  297.  
  298. /* --- print the current notepad --- */
  299. static void PrintPad(WINDOW wnd)
  300. {
  301.     if (*cfg.PrinterPort)    {
  302.         FILE *prn;
  303.         if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)    {
  304.             long percent;
  305.             BOOL KeepPrinting = TRUE;
  306.             unsigned char *text = GetText(wnd);
  307.             unsigned oldpct = 100, cct = 0, len = strlen(text);
  308.             WINDOW swnd = SliderBox(20, GetTitle(wnd), "Printing");
  309.             /* ------- print the notepad text --------- */
  310.             LineCtr = CharCtr = 0;
  311.             while (KeepPrinting && *text)    {
  312.                 PrintChar(prn, *text++);
  313.                 percent = ((long) ++cct * 100) / len;
  314.                 if ((int) percent != oldpct)    {
  315.                     oldpct = (int) percent;
  316.                     KeepPrinting = SendMessage(swnd, PAINT, 0, oldpct);
  317.                 }
  318.             }
  319.             if (KeepPrinting)
  320.                 /* ---- user did not cancel ---- */
  321.                 if (oldpct < 100)
  322.                     SendMessage(swnd, PAINT, 0, 100);
  323.                /* ------- follow with a form feed? --------- */
  324.                if (YesNoBox("Form Feed?"))
  325.                    fputc('\f', prn);
  326.             fclose(prn);
  327.         }
  328.         else
  329.             ErrorMessage("Cannot open printer file");
  330.     }
  331.     else
  332.         ErrorMessage("No printer selected");
  333. }
  334.  
  335. /* ---------- save a file to disk ------------ */
  336. static void SaveFile(WINDOW wnd, int Saveas)
  337. {
  338.     FILE *fp;
  339.     if (wnd->extension == NULL || Saveas)    {
  340.         char FileName[64];
  341.         if (SaveAsDialogBox(FileName))    {
  342.             if (wnd->extension != NULL)
  343.                 free(wnd->extension);
  344.             wnd->extension = DFmalloc(strlen(FileName)+1);
  345.             strcpy(wnd->extension, FileName);
  346.             AddTitle(wnd, NameComponent(FileName));
  347.             SendMessage(wnd, BORDER, 0, 0);
  348.         }
  349.         else
  350.             return;
  351.     }
  352.     if (wnd->extension != NULL)    {
  353.         WINDOW mwnd = MomentaryMessage("Saving the file");
  354.         if ((fp = fopen(wnd->extension, "wt")) != NULL)    {
  355.             fwrite(GetText(wnd), strlen(GetText(wnd)), 1, fp);
  356.             fclose(fp);
  357.             wnd->TextChanged = FALSE;
  358.         }
  359.         SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
  360.     }
  361. }
  362. /* -------- delete a file ------------ */
  363. static void DeleteFile(WINDOW wnd)
  364. {
  365.     if (wnd->extension != NULL)    {
  366.         if (strcmp(wnd->extension, Untitled))    {
  367.             char *fn = NameComponent(wnd->extension);
  368.             if (fn != NULL)    {
  369.                 char msg[30];
  370.                 sprintf(msg, "Delete %s?", fn);
  371.                 if (YesNoBox(msg))    {
  372.                     unlink(wnd->extension);
  373.                     SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  374.                 }
  375.             }
  376.         }
  377.     }
  378. }
  379. /* ------ display the row and column in the statusbar ------ */
  380. static void ShowPosition(WINDOW wnd)
  381. {
  382.     char status[30];
  383.     sprintf(status, "Line:%4d  Column: %2d",
  384.         wnd->CurrLine, wnd->CurrCol);
  385.     SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
  386. }
  387. /* ----- window processing module for the editboxes ----- */
  388. static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  389. {
  390.     int rtn;
  391.     switch (msg)    {
  392.         case SETFOCUS:
  393.             if ((int)p1)    {
  394.                 wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  395.                 wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  396.             }
  397.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  398.             if ((int)p1 == FALSE)
  399.                 SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
  400.             else 
  401.                 ShowPosition(wnd);
  402.             return rtn;
  403.         case KEYBOARD_CURSOR:
  404.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  405.             ShowPosition(wnd);
  406.             return rtn;
  407.         case COMMAND:
  408.             switch ((int) p1)    {
  409.                 case ID_SEARCH:
  410.                     SearchText(wnd);
  411.                     return TRUE;
  412.                 case ID_REPLACE:
  413.                     ReplaceText(wnd);
  414.                     return TRUE;
  415.                 case ID_SEARCHNEXT:
  416.                     SearchNext(wnd);
  417.                     return TRUE;
  418.                 case ID_CUT:
  419.                     CopyToClipboard(wnd);
  420.                     SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
  421.                     SendMessage(wnd, PAINT, 0, 0);
  422.                     return TRUE;
  423.                 case ID_COPY:
  424.                     CopyToClipboard(wnd);
  425.                     ClearTextBlock(wnd);
  426.                     SendMessage(wnd, PAINT, 0, 0);
  427.                     return TRUE;
  428.                 case ID_PASTE:
  429.                     PasteFromClipboard(wnd);
  430.                     SendMessage(wnd, PAINT, 0, 0);
  431.                     return TRUE;
  432.                 case ID_HELP:
  433.                     DisplayHelp(wnd, "MEMOPADDOC");
  434.                     return TRUE;
  435.                 case ID_WRAP:
  436.                     wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  437.                     cfg.WordWrap = wnd->WordWrapMode;
  438.                     return TRUE;
  439.                 case ID_INSERT:
  440.                     wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  441.                     cfg.InsertMode = wnd->InsertMode;
  442.                     SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
  443.                     return TRUE;
  444.                 default:
  445.                     break;
  446.             }
  447.             break;
  448.         case CLOSE_WINDOW:
  449.             if (wnd->TextChanged)    {
  450.                 char *cp = DFmalloc(25+strlen(GetTitle(wnd)));
  451.                 SendMessage(wnd, SETFOCUS, TRUE, 0);
  452.                 strcpy(cp, GetTitle(wnd));
  453.                 strcat(cp, "\nText changed. Save it?");
  454.                 if (YesNoBox(cp))
  455.                     SendMessage(GetParent(wnd),
  456.                         COMMAND, ID_SAVE, 0);
  457.                 free(cp);
  458.             }
  459.             wndpos = 0;
  460.             if (wnd->extension != NULL)    {
  461.                 free(wnd->extension);
  462.                 wnd->extension = NULL;
  463.             }
  464.             break;
  465.         default:
  466.             break;
  467.     }
  468.     return DefaultWndProc(wnd, msg, p1, p2);
  469. }
  470. /* -- point to the name component of a file specification -- */
  471. static char *NameComponent(char *FileName)
  472. {
  473.     char *Fname;
  474.     if ((Fname = strrchr(FileName, '\\')) == NULL)
  475.         if ((Fname = strrchr(FileName, ':')) == NULL)
  476.             Fname = FileName-1;
  477.     return Fname + 1;
  478. }
  479.  
  480. static char *ports[] = {
  481.     "Lpt1",    "Lpt2",    "Lpt3",
  482.     "Com1",    "Com2",    "Com3",    "Com4",
  483.       NULL
  484. };
  485.  
  486. static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  487. {
  488.     int rtn, i = 0, mar;
  489.     char marg[10];
  490.     WINDOW cwnd;
  491.     switch (msg)    {
  492.         case CREATE_WINDOW:
  493.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  494.             PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
  495.             while (ports[i] != NULL)
  496.                 PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
  497.             for (mar = CHARSLINE; mar >= 0; --mar)    {
  498.                 sprintf(marg, "%3d", mar);
  499.                 PutItemText(wnd, ID_LEFTMARGIN, marg);
  500.                 PutItemText(wnd, ID_RIGHTMARGIN, marg);
  501.             }
  502.             for (mar = LINESPAGE; mar >= 0; --mar)    {
  503.                 sprintf(marg, "%3d", mar);
  504.                 PutItemText(wnd, ID_TOPMARGIN, marg);
  505.                 PutItemText(wnd, ID_BOTTOMMARGIN, marg);
  506.             }
  507.             cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  508.             SendMessage(cwnd, LB_SETSELECTION,
  509.                 CHARSLINE-cfg.LeftMargin, 0);
  510.             cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  511.             SendMessage(cwnd, LB_SETSELECTION,
  512.                 CHARSLINE-cfg.RightMargin, 0);
  513.             cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  514.             SendMessage(cwnd, LB_SETSELECTION,
  515.                 LINESPAGE-cfg.TopMargin, 0);
  516.             cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  517.             SendMessage(cwnd, LB_SETSELECTION,
  518.                 LINESPAGE-cfg.BottomMargin, 0);
  519.             return rtn;
  520.         case COMMAND:
  521.             if ((int) p1 == ID_OK && (int) p2 == 0)    {
  522.                 GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
  523.                 cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  524.                 cfg.LeftMargin = CHARSLINE -
  525.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  526.                 cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  527.                 cfg.RightMargin = CHARSLINE -
  528.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  529.                 cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  530.                 cfg.TopMargin = LINESPAGE -
  531.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  532.                 cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  533.                 cfg.BottomMargin = LINESPAGE -
  534.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  535.             }
  536.             break;
  537.         default:
  538.             break;
  539.     }
  540.     return DefaultWndProc(wnd, msg, p1, p2);
  541. }
  542.  
  543. static void FixTabMenu(void)
  544. {
  545.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  546.     if (cp != NULL)    {
  547.         cp = strchr(cp, '(');
  548.         if (cp != NULL)    {
  549.             *(cp+1) = cfg.Tabs + '0';
  550.             if (GetClass(inFocus) == POPDOWNMENU)
  551.                 SendMessage(inFocus, PAINT, 0, 0);
  552.         }
  553.     }
  554. }
  555.  
  556. void PrepFileMenu(void *w, struct Menu *mnu)
  557. {
  558.     WINDOW wnd = w;
  559.     DeactivateCommand(&MainMenu, ID_SAVE);
  560.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  561.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  562.     DeactivateCommand(&MainMenu, ID_PRINT);
  563.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  564.         if (isMultiLine(wnd))    {
  565.             ActivateCommand(&MainMenu, ID_SAVE);
  566.             ActivateCommand(&MainMenu, ID_SAVEAS);
  567.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  568.             ActivateCommand(&MainMenu, ID_PRINT);
  569.         }
  570.     }
  571. }
  572.  
  573. void PrepSearchMenu(void *w, struct Menu *mnu)
  574. {
  575.     WINDOW wnd = w;
  576.     DeactivateCommand(&MainMenu, ID_SEARCH);
  577.     DeactivateCommand(&MainMenu, ID_REPLACE);
  578.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  579.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  580.         if (isMultiLine(wnd))    {
  581.             ActivateCommand(&MainMenu, ID_SEARCH);
  582.             ActivateCommand(&MainMenu, ID_REPLACE);
  583.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  584.         }
  585.     }
  586. }
  587.  
  588. void PrepEditMenu(void *w, struct Menu *mnu)
  589. {
  590.     WINDOW wnd = w;
  591.     DeactivateCommand(&MainMenu, ID_CUT);
  592.     DeactivateCommand(&MainMenu, ID_COPY);
  593.     DeactivateCommand(&MainMenu, ID_CLEAR);
  594.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  595.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  596.     DeactivateCommand(&MainMenu, ID_PASTE);
  597.     DeactivateCommand(&MainMenu, ID_UNDO);
  598.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  599.         if (isMultiLine(wnd))    {
  600.             if (TextBlockMarked(wnd))    {
  601.                 ActivateCommand(&MainMenu, ID_CUT);
  602.                 ActivateCommand(&MainMenu, ID_COPY);
  603.                 ActivateCommand(&MainMenu, ID_CLEAR);
  604.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  605.             }
  606.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  607.             if (!TestAttribute(wnd, READONLY) &&
  608.                         Clipboard != NULL)
  609.                 ActivateCommand(&MainMenu, ID_PASTE);
  610.             if (wnd->DeletedText != NULL)
  611.                 ActivateCommand(&MainMenu, ID_UNDO);
  612.         }
  613.     }
  614. }
  615.  
  616.