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