6b5556dda5b10e9bf88807cadfc0599f795aec71
[reactos.git] / rosapps / dflat32 / edit.c
1 /* --------------- edit.c ----------- */
2
3 #include "dflat.h"
4
5 extern DF_DBOX PrintSetup;
6
7 char DFlatApplication[] = "Edit";
8
9 static char Untitled[] = "Untitled";
10
11 static int wndpos;
12
13 static int MemoPadProc(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
14 static void NewFile(DFWINDOW,char *);
15 static void SelectFile(DFWINDOW);
16 static void PadWindow(DFWINDOW, char *);
17 static void OpenPadWindow(DFWINDOW, char *,char *);
18 static void LoadFile(DFWINDOW);
19 static void PrintPad(DFWINDOW);
20 static void SaveFile(DFWINDOW, int);
21 static void EditDeleteFile(DFWINDOW);
22 static int EditorProc(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
23 static char *NameComponent(char *);
24 static int PrintSetupProc(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
25 static void FixTabMenu(void);
26 #ifndef TURBOC
27 void Calendar(DFWINDOW);
28 #endif
29 //void BarChart(DFWINDOW);
30 char **Argv;
31
32 #define CHARSLINE 80
33 #define LINESPAGE 66
34
35 int main (int argc, char *argv[])
36 {
37 DFWINDOW wnd;
38 FILE *fp;
39
40 if (DfInitialize () == FALSE)
41 return 1;
42
43 Argv = argv;
44 DfLoadConfig ();
45 // if (!DfLoadConfig())
46 // DfCfg.ScreenLines = DF_SCREENHEIGHT;
47 wnd = DfDfCreateWindow (DF_APPLICATION,
48 "FreeDos Edit " DF_VERSION,
49 0, 0, -1, -1,
50 &DfMainMenu,
51 NULL,
52 MemoPadProc,
53 // DF_MOVEABLE |
54 // DF_SIZEABLE |
55 // DF_HASBORDER |
56 // DF_MINMAXBOX |
57 DF_HASSTATUSBAR);
58
59 DfLoadHelpFile ();
60 DfSendMessage (wnd, DFM_SETFOCUS, TRUE, 0);
61
62 // Load the files from args - if the file does not exist, open a new window....
63 while (argc > 1)
64 {
65 // check if the file exists....
66 if (( fp = fopen(argv[1],"r")) == NULL )
67 {
68 // file does not exist - create new window
69 NewFile(wnd,argv[1]);
70 }
71 else
72 PadWindow(wnd, argv[1]);
73 --argc;
74 argv++;
75 }
76
77 while (DfDispatchMessage ())
78 ;
79
80 DfTerminate ();
81
82 return 0;
83 }
84
85 /* ------ open text files and put them into editboxes ----- */
86 static void PadWindow(DFWINDOW wnd, char *FileName)
87 {
88 int ax;
89 struct _finddata_t ff;
90 char path[MAX_PATH];
91 char *cp;
92
93 DfCreatePath(path, FileName, FALSE, FALSE);
94 cp = path+strlen(path);
95 DfCreatePath(path, FileName, TRUE, FALSE);
96 ax = _findfirst(path, &ff);
97 if (ax == -1)
98 return;
99 do
100 {
101 strcpy(cp, ff.name);
102 OpenPadWindow(wnd, path,NULL);
103 }
104 while (_findnext(ax, &ff) == 0);
105 _findclose (ax);
106 }
107
108 /* ------- window processing module for the
109 Edit application window ----- */
110 static int MemoPadProc(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
111 {
112 int rtn;
113 switch (msg)
114 {
115 case DFM_CREATE_WINDOW:
116 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
117 if (DfCfg.InsertMode)
118 DfSetCommandToggle(&DfMainMenu, DF_ID_INSERT);
119 if (DfCfg.WordWrap)
120 DfSetCommandToggle(&DfMainMenu, DF_ID_WRAP);
121 FixTabMenu();
122 return rtn;
123 case DFM_COMMAND:
124 switch ((int)p1)
125 {
126 case DF_ID_NEW:
127 NewFile(wnd,NULL);
128 return TRUE;
129
130 case DF_ID_OPEN:
131 SelectFile(wnd);
132 return TRUE;
133
134 case DF_ID_SAVE:
135 SaveFile(DfInFocus, FALSE);
136 return TRUE;
137
138 case DF_ID_SAVEAS:
139 SaveFile(DfInFocus, TRUE);
140 return TRUE;
141
142 case DF_ID_DELETEFILE:
143 EditDeleteFile(DfInFocus);
144 return TRUE;
145
146 case DF_ID_PRINTSETUP:
147 DfDialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
148 return TRUE;
149
150 case DF_ID_PRINT:
151 PrintPad(DfInFocus);
152 return TRUE;
153
154 case DF_ID_EXIT:
155 if (!DfYesNoBox("Exit FreeDos Edit?"))
156 return FALSE;
157 break;
158
159 case DF_ID_WRAP:
160 DfCfg.WordWrap = DfGetCommandToggle(&DfMainMenu, DF_ID_WRAP);
161 return TRUE;
162
163 case DF_ID_INSERT:
164 DfCfg.InsertMode = DfGetCommandToggle(&DfMainMenu, DF_ID_INSERT);
165 return TRUE;
166
167 case DF_ID_TAB2:
168 DfCfg.Tabs = 2;
169 FixTabMenu();
170 return TRUE;
171
172 case DF_ID_TAB4:
173 DfCfg.Tabs = 4;
174 FixTabMenu();
175 return TRUE;
176
177 case DF_ID_TAB6:
178 DfCfg.Tabs = 6;
179 FixTabMenu();
180 return TRUE;
181
182 case DF_ID_TAB8:
183 DfCfg.Tabs = 8;
184 FixTabMenu();
185 return TRUE;
186
187 case DF_ID_CALENDAR:
188 Calendar(wnd);
189 return TRUE;
190
191 // case DF_ID_BARCHART:
192 // BarChart(wnd);
193 // return TRUE;
194
195 case DF_ID_ABOUT:
196 DfMessageBox(
197 "About D-Flat and FreeDos Edit",
198 " ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n"
199 " ³ ÜÜÜ ÜÜÜ Ü ³\n"
200 " ³ Û Û Û Û Û ³\n"
201 " ³ Û Û Û Û Û ³\n"
202 " ³ Û Û Û Û Û Û ³\n"
203 " ³ ßßß ßßß ßß ³\n"
204 " RÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄU\n"
205 "D-Flat implements the SAA/CUA\n"
206 "interface in a public domain\n"
207 "C language library originally\n"
208 "published in Dr. Dobb's Journal\n"
209 " ------------------------ \n"
210 "FreeDos Edit is a clone of MSDOS\n"
211 "editor for the FREEDOS Project");
212 return TRUE;
213
214 default:
215 break;
216 }
217 break;
218
219 default:
220 break;
221 }
222
223 return DfDefaultWndProc(wnd, msg, p1, p2);
224 }
225
226 /* --- The New command. Open an empty editor window --- */
227 static void NewFile(DFWINDOW wnd, char *FileName)
228 {
229 OpenPadWindow(wnd, Untitled,FileName);
230 }
231
232 /* --- The Open... command. Select a file --- */
233 static void SelectFile(DFWINDOW wnd)
234 {
235 char FileName[MAX_PATH];
236
237 if (DfOpenFileDialogBox("*.*", FileName))
238 {
239 /* see if the document is already in a window */
240 DFWINDOW wnd1 = DfFirstWindow(wnd);
241 while (wnd1 != NULL)
242 {
243 if (wnd1->extension &&
244 stricmp(FileName, wnd1->extension) == 0)
245 {
246 DfSendMessage(wnd1, DFM_SETFOCUS, TRUE, 0);
247 DfSendMessage(wnd1, DFM_RESTORE, 0, 0);
248 return;
249 }
250 wnd1 = DfNextWindow(wnd1);
251 }
252 OpenPadWindow(wnd, FileName, NULL);
253 }
254 }
255
256 /* --- open a document window and load a file --- */
257 static void OpenPadWindow(DFWINDOW wnd, char *FileName,char *NewFileName)
258 {
259 static DFWINDOW wnd1 = NULL;
260 DFWINDOW wwnd;
261 struct stat sb;
262 char *Fname = FileName;
263 char *Fnewname = NewFileName;
264 char *ermsg;
265
266 if (strcmp(FileName, Untitled))
267 {
268 if (stat(FileName, &sb))
269 {
270 ermsg = DfMalloc(strlen(FileName)+20);
271 strcpy(ermsg, "No such file as\n");
272 strcat(ermsg, FileName);
273 DfErrorMessage(ermsg);
274 free(ermsg);
275 return;
276 }
277
278 Fname = NameComponent(FileName);
279
280 // check file size
281 if (sb.st_size > 64000)
282 {
283 ermsg = DfMalloc(strlen(FileName)+20);
284 strcpy(ermsg, "File too large for this version of Edit\n");
285 DfErrorMessage(ermsg);
286 free(ermsg);
287 return;
288 }
289 }
290
291 wwnd = DfWatchIcon();
292 wndpos += 2;
293
294 if (NewFileName != NULL)
295 Fname = NameComponent(NewFileName);
296
297 if (wndpos == 20)
298 wndpos = 2;
299
300 wnd1 = DfDfCreateWindow(DF_EDITBOX,
301 Fname,
302 (wndpos-1)*2, wndpos, 10, 40,
303 NULL, wnd, EditorProc,
304 DF_SHADOW |
305 DF_MINMAXBOX |
306 DF_CONTROLBOX |
307 DF_VSCROLLBAR |
308 DF_HSCROLLBAR |
309 DF_MOVEABLE |
310 DF_HASBORDER |
311 DF_SIZEABLE |
312 DF_MULTILINE);
313
314 if (strcmp(FileName, Untitled))
315 {
316 wnd1->extension = DfMalloc(strlen(FileName)+1);
317 strcpy(wnd1->extension, FileName);
318 LoadFile(wnd1);
319 }
320 DfSendMessage(wwnd, DFM_CLOSE_WINDOW, 0, 0);
321 DfSendMessage(wnd1, DFM_SETFOCUS, TRUE, 0);
322 DfSendMessage(wnd1, DFM_MAXIMIZE, 0, 0);
323 }
324
325 /* --- Load the notepad file into the editor text buffer --- */
326 static void LoadFile(DFWINDOW wnd)
327 {
328 char *Buf = NULL;
329 int recptr = 0;
330 FILE *fp;
331
332 if ((fp = fopen(wnd->extension, "rt")) != NULL)
333 {
334 while (!feof(fp))
335 {
336 DfHandshake();
337 Buf = DfRealloc(Buf, recptr+150);
338 memset(Buf+recptr, 0, 150);
339 fgets(Buf+recptr, 150, fp);
340 recptr += strlen(Buf+recptr);
341 }
342 fclose(fp);
343 if (Buf != NULL)
344 {
345 DfSendMessage(wnd, DFM_SETTEXT, (DF_PARAM) Buf, 0);
346 free(Buf);
347 }
348 }
349 }
350
351 static int LineCtr;
352 static int CharCtr;
353
354 /* ------- print a character -------- */
355 static void PrintChar(FILE *prn, int c)
356 {
357 int i;
358
359 if (c == '\n' || CharCtr == DfCfg.RightMargin)
360 {
361 fputs("\r\n", prn);
362 LineCtr++;
363 if (LineCtr == DfCfg.BottomMargin)
364 {
365 fputc('\f', prn);
366 for (i = 0; i < DfCfg.TopMargin; i++)
367 fputc('\n', prn);
368 LineCtr = DfCfg.TopMargin;
369 }
370 CharCtr = 0;
371 if (c == '\n')
372 return;
373 }
374 if (CharCtr == 0)
375 {
376 for (i = 0; i < DfCfg.LeftMargin; i++)
377 {
378 fputc(' ', prn);
379 CharCtr++;
380 }
381 }
382 CharCtr++;
383 fputc(c, prn);
384 }
385
386 /* --- print the current notepad --- */
387 static void PrintPad(DFWINDOW wnd)
388 {
389 if (*DfCfg.PrinterPort)
390 {
391 FILE *prn;
392 if ((prn = fopen(DfCfg.PrinterPort, "wt")) != NULL)
393 {
394 long percent;
395 BOOL KeepPrinting = TRUE;
396 char *text = DfGetText(wnd);
397 unsigned oldpct = 100, cct = 0, len = strlen(text);
398 DFWINDOW swnd = DfSliderBox(20, DfGetTitle(wnd), "Printing");
399 /* ------- print the notepad text --------- */
400 LineCtr = CharCtr = 0;
401 while (KeepPrinting && *text)
402 {
403 PrintChar(prn, *text++);
404 percent = ((long) ++cct * 100) / len;
405 if ((int)percent != (int)oldpct)
406 {
407 oldpct = (int) percent;
408 KeepPrinting = DfSendMessage(swnd, DFM_PAINT, 0, oldpct);
409 }
410 }
411 if (KeepPrinting)
412 /* ---- user did not cancel ---- */
413 if (oldpct < 100)
414 DfSendMessage(swnd, DFM_PAINT, 0, 100);
415 /* ------- follow with a form feed? --------- */
416 if (DfYesNoBox("Form Feed?"))
417 fputc('\f', prn);
418 fclose(prn);
419 }
420 else
421 DfErrorMessage("Cannot open printer file");
422 }
423 else
424 DfErrorMessage("No printer selected");
425 }
426
427 /* ---------- save a file to disk ------------ */
428 static void SaveFile(DFWINDOW wnd, int Saveas)
429 {
430 FILE *fp;
431 if (wnd->extension == NULL || Saveas) {
432 char FileName[MAX_PATH];
433 if (DfSaveAsDialogBox(FileName)) {
434 if (wnd->extension != NULL)
435 free(wnd->extension);
436 wnd->extension = DfMalloc(strlen(FileName)+1);
437 strcpy(wnd->extension, FileName);
438 DfAddTitle(wnd, NameComponent(FileName));
439 DfSendMessage(wnd, DFM_BORDER, 0, 0);
440 }
441 else
442 return;
443 }
444 if (wnd->extension != NULL)
445 {
446 DFWINDOW mwnd = DfMomentaryMessage("Saving the file");
447 if ((fp = fopen(wnd->extension, "wt")) != NULL)
448 {
449 fwrite(DfGetText(wnd), strlen(DfGetText(wnd)), 1, fp);
450 fclose(fp);
451 wnd->TextChanged = FALSE;
452 }
453 DfSendMessage(mwnd, DFM_CLOSE_WINDOW, 0, 0);
454 }
455 }
456 /* -------- delete a file ------------ */
457 static void EditDeleteFile(DFWINDOW wnd)
458 {
459 if (wnd->extension != NULL) {
460 if (strcmp(wnd->extension, Untitled)) {
461 char *fn = NameComponent(wnd->extension);
462 if (fn != NULL) {
463 char msg[30];
464 sprintf(msg, "Delete %s?", fn);
465 if (DfYesNoBox(msg)) {
466 unlink(wnd->extension);
467 DfSendMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
468 }
469 }
470 }
471 }
472 }
473 /* ------ display the row and column in the statusbar ------ */
474 static void ShowPosition(DFWINDOW wnd)
475 {
476 char status[30];
477 sprintf(status, "Line:%4d Column: %2d",
478 wnd->CurrLine, wnd->CurrCol);
479 DfSendMessage(DfGetParent(wnd), DFM_ADDSTATUS, (DF_PARAM) status, 0);
480 }
481
482 /* window processing module for the editboxes */
483 static int EditorProc(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
484 {
485 int rtn;
486
487 switch (msg)
488 {
489 case DFM_SETFOCUS:
490 if ((int)p1)
491 {
492 wnd->InsertMode = DfGetCommandToggle(&DfMainMenu, DF_ID_INSERT);
493 wnd->WordWrapMode = DfGetCommandToggle(&DfMainMenu, DF_ID_WRAP);
494 }
495 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
496 if ((int)p1 == FALSE)
497 DfSendMessage(DfGetParent(wnd), DFM_ADDSTATUS, 0, 0);
498 else
499 ShowPosition(wnd);
500 return rtn;
501
502 case DFM_KEYBOARD_CURSOR:
503 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
504 ShowPosition(wnd);
505 return rtn;
506
507 case DFM_COMMAND:
508 switch ((int) p1)
509 {
510 case DF_ID_SEARCH:
511 DfSearchText(wnd);
512 return TRUE;
513 case DF_ID_REPLACE:
514 DfReplaceText(wnd);
515 return TRUE;
516 case DF_ID_SEARCHNEXT:
517 DfSearchNext(wnd);
518 return TRUE;
519 case DF_ID_CUT:
520 DfCopyToClipboard(wnd);
521 DfSendMessage(wnd, DFM_COMMAND, DF_ID_DELETETEXT, 0);
522 DfSendMessage(wnd, DFM_PAINT, 0, 0);
523 return TRUE;
524 case DF_ID_COPY:
525 DfCopyToClipboard(wnd);
526 DfClearTextBlock(wnd);
527 DfSendMessage(wnd, DFM_PAINT, 0, 0);
528 return TRUE;
529 case DF_ID_PASTE:
530 DfPasteFromClipboard(wnd);
531 DfSendMessage(wnd, DFM_PAINT, 0, 0);
532 return TRUE;
533 case DF_ID_DELETETEXT:
534 case DF_ID_CLEAR:
535 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
536 DfSendMessage(wnd, DFM_PAINT, 0, 0);
537 return rtn;
538 case DF_ID_HELP:
539 DfDisplayHelp(wnd, "MEMOPADDOC");
540 return TRUE;
541 case DF_ID_WRAP:
542 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_WRAP, 0);
543 wnd->WordWrapMode = DfCfg.WordWrap;
544 return TRUE;
545 case DF_ID_INSERT:
546 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_INSERT, 0);
547 wnd->InsertMode = DfCfg.InsertMode;
548 DfSendMessage(NULL, DFM_SHOW_CURSOR, wnd->InsertMode, 0);
549 return TRUE;
550 default:
551 break;
552 }
553 break;
554
555 case DFM_CLOSE_WINDOW:
556 if (wnd->TextChanged)
557 {
558 char *cp = DfMalloc(25+strlen(DfGetTitle(wnd)));
559 DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
560 strcpy(cp, DfGetTitle(wnd));
561 strcat(cp, "\nText changed. Save it?");
562 if (DfYesNoBox(cp))
563 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_SAVE, 0);
564 free(cp);
565 }
566 wndpos = 0;
567 if (wnd->extension != NULL)
568 {
569 free(wnd->extension);
570 wnd->extension = NULL;
571 }
572 break;
573
574 default:
575 break;
576 }
577
578 return DfDefaultWndProc(wnd, msg, p1, p2);
579 }
580
581 /* -- point to the name component of a file specification -- */
582 static char *NameComponent(char *FileName)
583 {
584 char *Fname;
585 if ((Fname = strrchr(FileName, '\\')) == NULL)
586 if ((Fname = strrchr(FileName, ':')) == NULL)
587 Fname = FileName-1;
588 return Fname + 1;
589 }
590
591 static char *ports[] = {
592 "Lpt1", "Lpt2", "Lpt3",
593 "Com1", "Com2", "Com3", "Com4",
594 NULL
595 };
596
597 static int PrintSetupProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
598 {
599 int rtn, i = 0, mar;
600 char marg[10];
601 DFWINDOW cwnd;
602
603 switch (msg)
604 {
605 case DFM_CREATE_WINDOW:
606 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
607 DfPutItemText(wnd, DF_ID_PRINTERPORT, DfCfg.PrinterPort);
608 while (ports[i] != NULL)
609 DfPutComboListText(wnd, DF_ID_PRINTERPORT, ports[i++]);
610 for (mar = CHARSLINE; mar >= 0; --mar)
611 {
612 sprintf(marg, "%3d", mar);
613 DfPutItemText(wnd, DF_ID_LEFTMARGIN, marg);
614 DfPutItemText(wnd, DF_ID_RIGHTMARGIN, marg);
615 }
616 for (mar = LINESPAGE; mar >= 0; --mar)
617 {
618 sprintf(marg, "%3d", mar);
619 DfPutItemText(wnd, DF_ID_TOPMARGIN, marg);
620 DfPutItemText(wnd, DF_ID_BOTTOMMARGIN, marg);
621 }
622 cwnd = DfControlWindow(&PrintSetup, DF_ID_LEFTMARGIN);
623 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
624 CHARSLINE-DfCfg.LeftMargin, 0);
625 cwnd = DfControlWindow(&PrintSetup, DF_ID_RIGHTMARGIN);
626 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
627 CHARSLINE-DfCfg.RightMargin, 0);
628 cwnd = DfControlWindow(&PrintSetup, DF_ID_TOPMARGIN);
629 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
630 LINESPAGE-DfCfg.TopMargin, 0);
631 cwnd = DfControlWindow(&PrintSetup, DF_ID_BOTTOMMARGIN);
632 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
633 LINESPAGE-DfCfg.BottomMargin, 0);
634 return rtn;
635 case DFM_COMMAND:
636 if ((int) p1 == DF_ID_OK && (int) p2 == 0)
637 {
638 DfGetItemText(wnd, DF_ID_PRINTERPORT, DfCfg.PrinterPort, 4);
639 cwnd = DfControlWindow(&PrintSetup, DF_ID_LEFTMARGIN);
640 DfCfg.LeftMargin = CHARSLINE -
641 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
642 cwnd = DfControlWindow(&PrintSetup, DF_ID_RIGHTMARGIN);
643 DfCfg.RightMargin = CHARSLINE -
644 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
645 cwnd = DfControlWindow(&PrintSetup, DF_ID_TOPMARGIN);
646 DfCfg.TopMargin = LINESPAGE -
647 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
648 cwnd = DfControlWindow(&PrintSetup, DF_ID_BOTTOMMARGIN);
649 DfCfg.BottomMargin = LINESPAGE -
650 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
651 }
652 break;
653 default:
654 break;
655 }
656 return DfDefaultWndProc(wnd, msg, p1, p2);
657 }
658
659 static void FixTabMenu(void)
660 {
661 char *cp = DfGetCommandText(&DfMainMenu, DF_ID_TABS);
662 char *p;
663
664 if (cp != NULL)
665 {
666 p = strchr(cp, '(');
667 if (p != NULL)
668 {
669 // *(p+1) = (char)(DfCfg.Tabs + '0');
670 // if (DfGetClass(DfInFocus) == DF_POPDOWNMENU)
671 // DfSendMessage(DfInFocus, DFM_PAINT, 0, 0);
672 }
673 }
674 }
675
676 void DfPrepFileMenu(void *w, struct DfMenu *mnu)
677 {
678 DFWINDOW wnd = w;
679 DfDeactivateCommand(&DfMainMenu, DF_ID_SAVE);
680 DfDeactivateCommand(&DfMainMenu, DF_ID_SAVEAS);
681 DfDeactivateCommand(&DfMainMenu, DF_ID_DELETEFILE);
682 DfDeactivateCommand(&DfMainMenu, DF_ID_PRINT);
683 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
684 {
685 if (DfIsMultiLine(wnd))
686 {
687 DfActivateCommand(&DfMainMenu, DF_ID_SAVE);
688 DfActivateCommand(&DfMainMenu, DF_ID_SAVEAS);
689 DfActivateCommand(&DfMainMenu, DF_ID_DELETEFILE);
690 DfActivateCommand(&DfMainMenu, DF_ID_PRINT);
691 }
692 }
693 }
694
695 void DfPrepSearchMenu(void *w, struct DfMenu *mnu)
696 {
697 DFWINDOW wnd = w;
698 DfDeactivateCommand(&DfMainMenu, DF_ID_SEARCH);
699 DfDeactivateCommand(&DfMainMenu, DF_ID_REPLACE);
700 DfDeactivateCommand(&DfMainMenu, DF_ID_SEARCHNEXT);
701 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
702 {
703 if (DfIsMultiLine(wnd))
704 {
705 DfActivateCommand(&DfMainMenu, DF_ID_SEARCH);
706 DfActivateCommand(&DfMainMenu, DF_ID_REPLACE);
707 DfActivateCommand(&DfMainMenu, DF_ID_SEARCHNEXT);
708 }
709 }
710 }
711
712 void DfPrepEditMenu(void *w, struct DfMenu *mnu)
713 {
714 DFWINDOW wnd = w;
715 DfDeactivateCommand(&DfMainMenu, DF_ID_CUT);
716 DfDeactivateCommand(&DfMainMenu, DF_ID_COPY);
717 DfDeactivateCommand(&DfMainMenu, DF_ID_CLEAR);
718 DfDeactivateCommand(&DfMainMenu, DF_ID_DELETETEXT);
719 DfDeactivateCommand(&DfMainMenu, DF_ID_PARAGRAPH);
720 DfDeactivateCommand(&DfMainMenu, DF_ID_PASTE);
721 DfDeactivateCommand(&DfMainMenu, DF_ID_UNDO);
722 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
723 {
724 if (DfIsMultiLine(wnd))
725 {
726 if (DfTextBlockMarked(wnd))
727 {
728 DfActivateCommand(&DfMainMenu, DF_ID_CUT);
729 DfActivateCommand(&DfMainMenu, DF_ID_COPY);
730 DfActivateCommand(&DfMainMenu, DF_ID_CLEAR);
731 DfActivateCommand(&DfMainMenu, DF_ID_DELETETEXT);
732 }
733 DfActivateCommand(&DfMainMenu, DF_ID_PARAGRAPH);
734 if (!DfTestAttribute(wnd, DF_READONLY) && DfClipboard != NULL)
735 DfActivateCommand(&DfMainMenu, DF_ID_PASTE);
736 if (wnd->DeletedText != NULL)
737 DfActivateCommand(&DfMainMenu, DF_ID_UNDO);
738 }
739 }
740 }
741
742 /* EOF */