add library
[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 *ermsg;
264
265 if (strcmp(FileName, Untitled))
266 {
267 if (stat(FileName, &sb))
268 {
269 ermsg = DfMalloc(strlen(FileName)+20);
270 strcpy(ermsg, "No such file as\n");
271 strcat(ermsg, FileName);
272 DfErrorMessage(ermsg);
273 free(ermsg);
274 return;
275 }
276
277 Fname = NameComponent(FileName);
278
279 // check file size
280 if (sb.st_size > 64000)
281 {
282 ermsg = DfMalloc(strlen(FileName)+20);
283 strcpy(ermsg, "File too large for this version of Edit\n");
284 DfErrorMessage(ermsg);
285 free(ermsg);
286 return;
287 }
288 }
289
290 wwnd = DfWatchIcon();
291 wndpos += 2;
292
293 if (NewFileName != NULL)
294 Fname = NameComponent(NewFileName);
295
296 if (wndpos == 20)
297 wndpos = 2;
298
299 wnd1 = DfDfCreateWindow(DF_EDITBOX,
300 Fname,
301 (wndpos-1)*2, wndpos, 10, 40,
302 NULL, wnd, EditorProc,
303 DF_SHADOW |
304 DF_MINMAXBOX |
305 DF_CONTROLBOX |
306 DF_VSCROLLBAR |
307 DF_HSCROLLBAR |
308 DF_MOVEABLE |
309 DF_HASBORDER |
310 DF_SIZEABLE |
311 DF_MULTILINE);
312
313 if (strcmp(FileName, Untitled))
314 {
315 wnd1->extension = DfMalloc(strlen(FileName)+1);
316 strcpy(wnd1->extension, FileName);
317 LoadFile(wnd1);
318 }
319 DfSendMessage(wwnd, DFM_CLOSE_WINDOW, 0, 0);
320 DfSendMessage(wnd1, DFM_SETFOCUS, TRUE, 0);
321 DfSendMessage(wnd1, DFM_MAXIMIZE, 0, 0);
322 }
323
324 /* --- Load the notepad file into the editor text buffer --- */
325 static void LoadFile(DFWINDOW wnd)
326 {
327 char *Buf = NULL;
328 int recptr = 0;
329 FILE *fp;
330
331 if ((fp = fopen(wnd->extension, "rt")) != NULL)
332 {
333 while (!feof(fp))
334 {
335 DfHandshake();
336 Buf = DfRealloc(Buf, recptr+150);
337 memset(Buf+recptr, 0, 150);
338 fgets(Buf+recptr, 150, fp);
339 recptr += strlen(Buf+recptr);
340 }
341 fclose(fp);
342 if (Buf != NULL)
343 {
344 DfSendMessage(wnd, DFM_SETTEXT, (DF_PARAM) Buf, 0);
345 free(Buf);
346 }
347 }
348 }
349
350 static int LineCtr;
351 static int CharCtr;
352
353 /* ------- print a character -------- */
354 static void PrintChar(FILE *prn, int c)
355 {
356 int i;
357
358 if (c == '\n' || CharCtr == DfCfg.RightMargin)
359 {
360 fputs("\r\n", prn);
361 LineCtr++;
362 if (LineCtr == DfCfg.BottomMargin)
363 {
364 fputc('\f', prn);
365 for (i = 0; i < DfCfg.TopMargin; i++)
366 fputc('\n', prn);
367 LineCtr = DfCfg.TopMargin;
368 }
369 CharCtr = 0;
370 if (c == '\n')
371 return;
372 }
373 if (CharCtr == 0)
374 {
375 for (i = 0; i < DfCfg.LeftMargin; i++)
376 {
377 fputc(' ', prn);
378 CharCtr++;
379 }
380 }
381 CharCtr++;
382 fputc(c, prn);
383 }
384
385 /* --- print the current notepad --- */
386 static void PrintPad(DFWINDOW wnd)
387 {
388 if (*DfCfg.PrinterPort)
389 {
390 FILE *prn;
391 if ((prn = fopen(DfCfg.PrinterPort, "wt")) != NULL)
392 {
393 long percent;
394 BOOL KeepPrinting = TRUE;
395 char *text = DfGetText(wnd);
396 unsigned oldpct = 100, cct = 0, len = strlen(text);
397 DFWINDOW swnd = DfSliderBox(20, DfGetTitle(wnd), "Printing");
398 /* ------- print the notepad text --------- */
399 LineCtr = CharCtr = 0;
400 while (KeepPrinting && *text)
401 {
402 PrintChar(prn, *text++);
403 percent = ((long) ++cct * 100) / len;
404 if ((int)percent != (int)oldpct)
405 {
406 oldpct = (int) percent;
407 KeepPrinting = DfSendMessage(swnd, DFM_PAINT, 0, oldpct);
408 }
409 }
410 if (KeepPrinting)
411 /* ---- user did not cancel ---- */
412 if (oldpct < 100)
413 DfSendMessage(swnd, DFM_PAINT, 0, 100);
414 /* ------- follow with a form feed? --------- */
415 if (DfYesNoBox("Form Feed?"))
416 fputc('\f', prn);
417 fclose(prn);
418 }
419 else
420 DfErrorMessage("Cannot open printer file");
421 }
422 else
423 DfErrorMessage("No printer selected");
424 }
425
426 /* ---------- save a file to disk ------------ */
427 static void SaveFile(DFWINDOW wnd, int Saveas)
428 {
429 FILE *fp;
430 if (wnd->extension == NULL || Saveas) {
431 char FileName[MAX_PATH];
432 if (DfSaveAsDialogBox(FileName)) {
433 if (wnd->extension != NULL)
434 free(wnd->extension);
435 wnd->extension = DfMalloc(strlen(FileName)+1);
436 strcpy(wnd->extension, FileName);
437 DfAddTitle(wnd, NameComponent(FileName));
438 DfSendMessage(wnd, DFM_BORDER, 0, 0);
439 }
440 else
441 return;
442 }
443 if (wnd->extension != NULL)
444 {
445 DFWINDOW mwnd = DfMomentaryMessage("Saving the file");
446 if ((fp = fopen(wnd->extension, "wt")) != NULL)
447 {
448 fwrite(DfGetText(wnd), strlen(DfGetText(wnd)), 1, fp);
449 fclose(fp);
450 wnd->TextChanged = FALSE;
451 }
452 DfSendMessage(mwnd, DFM_CLOSE_WINDOW, 0, 0);
453 }
454 }
455 /* -------- delete a file ------------ */
456 static void EditDeleteFile(DFWINDOW wnd)
457 {
458 if (wnd->extension != NULL) {
459 if (strcmp(wnd->extension, Untitled)) {
460 char *fn = NameComponent(wnd->extension);
461 if (fn != NULL) {
462 char msg[30];
463 sprintf(msg, "Delete %s?", fn);
464 if (DfYesNoBox(msg)) {
465 unlink(wnd->extension);
466 DfSendMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
467 }
468 }
469 }
470 }
471 }
472 /* ------ display the row and column in the statusbar ------ */
473 static void ShowPosition(DFWINDOW wnd)
474 {
475 char status[30];
476 sprintf(status, "Line:%4d Column: %2d",
477 wnd->CurrLine, wnd->CurrCol);
478 DfSendMessage(DfGetParent(wnd), DFM_ADDSTATUS, (DF_PARAM) status, 0);
479 }
480
481 /* window processing module for the editboxes */
482 static int EditorProc(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
483 {
484 int rtn;
485
486 switch (msg)
487 {
488 case DFM_SETFOCUS:
489 if ((int)p1)
490 {
491 wnd->InsertMode = DfGetCommandToggle(&DfMainMenu, DF_ID_INSERT);
492 wnd->WordWrapMode = DfGetCommandToggle(&DfMainMenu, DF_ID_WRAP);
493 }
494 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
495 if ((int)p1 == FALSE)
496 DfSendMessage(DfGetParent(wnd), DFM_ADDSTATUS, 0, 0);
497 else
498 ShowPosition(wnd);
499 return rtn;
500
501 case DFM_KEYBOARD_CURSOR:
502 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
503 ShowPosition(wnd);
504 return rtn;
505
506 case DFM_COMMAND:
507 switch ((int) p1)
508 {
509 case DF_ID_SEARCH:
510 DfSearchText(wnd);
511 return TRUE;
512 case DF_ID_REPLACE:
513 DfReplaceText(wnd);
514 return TRUE;
515 case DF_ID_SEARCHNEXT:
516 DfSearchNext(wnd);
517 return TRUE;
518 case DF_ID_CUT:
519 DfCopyToClipboard(wnd);
520 DfSendMessage(wnd, DFM_COMMAND, DF_ID_DELETETEXT, 0);
521 DfSendMessage(wnd, DFM_PAINT, 0, 0);
522 return TRUE;
523 case DF_ID_COPY:
524 DfCopyToClipboard(wnd);
525 DfClearTextBlock(wnd);
526 DfSendMessage(wnd, DFM_PAINT, 0, 0);
527 return TRUE;
528 case DF_ID_PASTE:
529 DfPasteFromClipboard(wnd);
530 DfSendMessage(wnd, DFM_PAINT, 0, 0);
531 return TRUE;
532 case DF_ID_DELETETEXT:
533 case DF_ID_CLEAR:
534 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
535 DfSendMessage(wnd, DFM_PAINT, 0, 0);
536 return rtn;
537 case DF_ID_HELP:
538 DfDisplayHelp(wnd, "MEMOPADDOC");
539 return TRUE;
540 case DF_ID_WRAP:
541 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_WRAP, 0);
542 wnd->WordWrapMode = DfCfg.WordWrap;
543 return TRUE;
544 case DF_ID_INSERT:
545 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_INSERT, 0);
546 wnd->InsertMode = DfCfg.InsertMode;
547 DfSendMessage(NULL, DFM_SHOW_CURSOR, wnd->InsertMode, 0);
548 return TRUE;
549 default:
550 break;
551 }
552 break;
553
554 case DFM_CLOSE_WINDOW:
555 if (wnd->TextChanged)
556 {
557 char *cp = DfMalloc(25+strlen(DfGetTitle(wnd)));
558 DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
559 strcpy(cp, DfGetTitle(wnd));
560 strcat(cp, "\nText changed. Save it?");
561 if (DfYesNoBox(cp))
562 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_SAVE, 0);
563 free(cp);
564 }
565 wndpos = 0;
566 if (wnd->extension != NULL)
567 {
568 free(wnd->extension);
569 wnd->extension = NULL;
570 }
571 break;
572
573 default:
574 break;
575 }
576
577 return DfDefaultWndProc(wnd, msg, p1, p2);
578 }
579
580 /* -- point to the name component of a file specification -- */
581 static char *NameComponent(char *FileName)
582 {
583 char *Fname;
584 if ((Fname = strrchr(FileName, '\\')) == NULL)
585 if ((Fname = strrchr(FileName, ':')) == NULL)
586 Fname = FileName-1;
587 return Fname + 1;
588 }
589
590 static char *ports[] = {
591 "Lpt1", "Lpt2", "Lpt3",
592 "Com1", "Com2", "Com3", "Com4",
593 NULL
594 };
595
596 static int PrintSetupProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
597 {
598 int rtn, i = 0, mar;
599 char marg[10];
600 DFWINDOW cwnd;
601
602 switch (msg)
603 {
604 case DFM_CREATE_WINDOW:
605 rtn = DfDefaultWndProc(wnd, msg, p1, p2);
606 DfPutItemText(wnd, DF_ID_PRINTERPORT, DfCfg.PrinterPort);
607 while (ports[i] != NULL)
608 DfPutComboListText(wnd, DF_ID_PRINTERPORT, ports[i++]);
609 for (mar = CHARSLINE; mar >= 0; --mar)
610 {
611 sprintf(marg, "%3d", mar);
612 DfPutItemText(wnd, DF_ID_LEFTMARGIN, marg);
613 DfPutItemText(wnd, DF_ID_RIGHTMARGIN, marg);
614 }
615 for (mar = LINESPAGE; mar >= 0; --mar)
616 {
617 sprintf(marg, "%3d", mar);
618 DfPutItemText(wnd, DF_ID_TOPMARGIN, marg);
619 DfPutItemText(wnd, DF_ID_BOTTOMMARGIN, marg);
620 }
621 cwnd = DfControlWindow(&PrintSetup, DF_ID_LEFTMARGIN);
622 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
623 CHARSLINE-DfCfg.LeftMargin, 0);
624 cwnd = DfControlWindow(&PrintSetup, DF_ID_RIGHTMARGIN);
625 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
626 CHARSLINE-DfCfg.RightMargin, 0);
627 cwnd = DfControlWindow(&PrintSetup, DF_ID_TOPMARGIN);
628 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
629 LINESPAGE-DfCfg.TopMargin, 0);
630 cwnd = DfControlWindow(&PrintSetup, DF_ID_BOTTOMMARGIN);
631 DfSendMessage(cwnd, DFM_LB_SETSELECTION,
632 LINESPAGE-DfCfg.BottomMargin, 0);
633 return rtn;
634 case DFM_COMMAND:
635 if ((int) p1 == DF_ID_OK && (int) p2 == 0)
636 {
637 DfGetItemText(wnd, DF_ID_PRINTERPORT, DfCfg.PrinterPort, 4);
638 cwnd = DfControlWindow(&PrintSetup, DF_ID_LEFTMARGIN);
639 DfCfg.LeftMargin = CHARSLINE -
640 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
641 cwnd = DfControlWindow(&PrintSetup, DF_ID_RIGHTMARGIN);
642 DfCfg.RightMargin = CHARSLINE -
643 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
644 cwnd = DfControlWindow(&PrintSetup, DF_ID_TOPMARGIN);
645 DfCfg.TopMargin = LINESPAGE -
646 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
647 cwnd = DfControlWindow(&PrintSetup, DF_ID_BOTTOMMARGIN);
648 DfCfg.BottomMargin = LINESPAGE -
649 DfSendMessage(cwnd, DFM_LB_CURRENTSELECTION, 0, 0);
650 }
651 break;
652 default:
653 break;
654 }
655 return DfDefaultWndProc(wnd, msg, p1, p2);
656 }
657
658 static void FixTabMenu(void)
659 {
660 char *cp = DfGetCommandText(&DfMainMenu, DF_ID_TABS);
661 char *p;
662
663 if (cp != NULL)
664 {
665 p = strchr(cp, '(');
666 if (p != NULL)
667 {
668 // *(p+1) = (char)(DfCfg.Tabs + '0');
669 // if (DfGetClass(DfInFocus) == DF_POPDOWNMENU)
670 // DfSendMessage(DfInFocus, DFM_PAINT, 0, 0);
671 }
672 }
673 }
674
675 void DfPrepFileMenu(void *w, struct DfMenu *mnu)
676 {
677 DFWINDOW wnd = w;
678 DfDeactivateCommand(&DfMainMenu, DF_ID_SAVE);
679 DfDeactivateCommand(&DfMainMenu, DF_ID_SAVEAS);
680 DfDeactivateCommand(&DfMainMenu, DF_ID_DELETEFILE);
681 DfDeactivateCommand(&DfMainMenu, DF_ID_PRINT);
682 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
683 {
684 if (DfIsMultiLine(wnd))
685 {
686 DfActivateCommand(&DfMainMenu, DF_ID_SAVE);
687 DfActivateCommand(&DfMainMenu, DF_ID_SAVEAS);
688 DfActivateCommand(&DfMainMenu, DF_ID_DELETEFILE);
689 DfActivateCommand(&DfMainMenu, DF_ID_PRINT);
690 }
691 }
692 }
693
694 void DfPrepSearchMenu(void *w, struct DfMenu *mnu)
695 {
696 DFWINDOW wnd = w;
697 DfDeactivateCommand(&DfMainMenu, DF_ID_SEARCH);
698 DfDeactivateCommand(&DfMainMenu, DF_ID_REPLACE);
699 DfDeactivateCommand(&DfMainMenu, DF_ID_SEARCHNEXT);
700 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
701 {
702 if (DfIsMultiLine(wnd))
703 {
704 DfActivateCommand(&DfMainMenu, DF_ID_SEARCH);
705 DfActivateCommand(&DfMainMenu, DF_ID_REPLACE);
706 DfActivateCommand(&DfMainMenu, DF_ID_SEARCHNEXT);
707 }
708 }
709 }
710
711 void DfPrepEditMenu(void *w, struct DfMenu *mnu)
712 {
713 DFWINDOW wnd = w;
714 DfDeactivateCommand(&DfMainMenu, DF_ID_CUT);
715 DfDeactivateCommand(&DfMainMenu, DF_ID_COPY);
716 DfDeactivateCommand(&DfMainMenu, DF_ID_CLEAR);
717 DfDeactivateCommand(&DfMainMenu, DF_ID_DELETETEXT);
718 DfDeactivateCommand(&DfMainMenu, DF_ID_PARAGRAPH);
719 DfDeactivateCommand(&DfMainMenu, DF_ID_PASTE);
720 DfDeactivateCommand(&DfMainMenu, DF_ID_UNDO);
721 if (wnd != NULL && DfGetClass(wnd) == DF_EDITBOX)
722 {
723 if (DfIsMultiLine(wnd))
724 {
725 if (DfTextBlockMarked(wnd))
726 {
727 DfActivateCommand(&DfMainMenu, DF_ID_CUT);
728 DfActivateCommand(&DfMainMenu, DF_ID_COPY);
729 DfActivateCommand(&DfMainMenu, DF_ID_CLEAR);
730 DfActivateCommand(&DfMainMenu, DF_ID_DELETETEXT);
731 }
732 DfActivateCommand(&DfMainMenu, DF_ID_PARAGRAPH);
733 if (!DfTestAttribute(wnd, DF_READONLY) && DfClipboard != NULL)
734 DfActivateCommand(&DfMainMenu, DF_ID_PASTE);
735 if (wnd->DeletedText != NULL)
736 DfActivateCommand(&DfMainMenu, DF_ID_UNDO);
737 }
738 }
739 }
740
741 /* EOF */