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