home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / TP.7_1 / TP / EXAMPLES / TVDEMO / TVEDIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-05  |  4.2 KB  |  178 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision Editor Demo                     }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program TVEdit;
  9.  
  10. {$M 8192,8192,655360}
  11. {$X+,S-}
  12.  
  13. { This program demonstrates the use of the Editors units.
  14.   See EDITORS.DOC in the \DOC directory.
  15. }
  16.  
  17. uses Dos, Objects, Drivers, Memory, Views, Menus, Dialogs,
  18.   StdDlg, MsgBox, App, Calc, Editors;
  19.  
  20. const
  21.   HeapSize = 32 * (1024 div 16);
  22.  
  23. const
  24.   cmCalculator = 101;
  25.   cmShowClip   = 102;
  26.  
  27. type
  28.   PEditorApp = ^TEditorApp;
  29.   TEditorApp = object(TApplication)
  30.     constructor Init;
  31.     procedure HandleEvent(var Event: TEvent); virtual;
  32.     procedure InitMenuBar; virtual;
  33.     procedure InitStatusLine; virtual;
  34.     procedure OutOfMemory; virtual;
  35.   end;
  36.  
  37. var
  38.   EditorApp: TEditorApp;
  39.   ClipWindow: PEditWindow;
  40.  
  41. function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
  42. var
  43.   P: PWindow;
  44.   R: TRect;
  45. begin
  46.   DeskTop^.GetExtent(R);
  47.   P := New(PEditWindow, Init(R, FileName, wnNoNumber));
  48.   if not Visible then P^.Hide;
  49.   OpenEditor := PEditWindow(Application^.InsertWindow(P));
  50. end;
  51.  
  52. constructor TEditorApp.Init;
  53. var
  54.   H: Word;
  55.   R: TRect;
  56. begin
  57.   MaxHeapSize := HeapSize;
  58.   inherited Init;
  59.   DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
  60.     cmUndo, cmFind, cmReplace, cmSearchAgain]);
  61.   EditorDialog := StdEditorDialog;
  62.   ClipWindow := OpenEditor('', False);
  63.   if ClipWindow <> nil then
  64.   begin
  65.     Clipboard := ClipWindow^.Editor;
  66.     Clipboard^.CanUndo := False;
  67.   end;
  68. end;
  69.  
  70. procedure TEditorApp.HandleEvent(var Event: TEvent);
  71.  
  72. procedure FileOpen;
  73. var
  74.   FileName: FNameStr;
  75. begin
  76.   FileName := '*.*';
  77.   if ExecuteDialog(New(PFileDialog, Init('*.*', 'Open file',
  78.     '~N~ame', fdOpenButton, 100)), @FileName) <> cmCancel then
  79.     OpenEditor(FileName, True);
  80. end;
  81.  
  82. procedure FileNew;
  83. begin
  84.   OpenEditor('', True);
  85. end;
  86.  
  87. procedure ChangeDir;
  88. begin
  89.   ExecuteDialog(New(PChDirDialog, Init(cdNormal, 0)), nil);
  90. end;
  91.  
  92. procedure ShowClip;
  93. begin
  94.   ClipWindow^.Select;
  95.   ClipWindow^.Show;
  96. end;
  97.  
  98. procedure Calculator;
  99. begin
  100.   InsertWindow(New(PCalculator, Init));
  101. end;
  102.  
  103. begin
  104.   inherited HandleEvent(Event);
  105.   case Event.What of
  106.     evCommand:
  107.       case Event.Command of
  108.         cmOpen: FileOpen;
  109.         cmNew: FileNew;
  110.         cmChangeDir: ChangeDir;
  111.         cmCalculator: Calculator;
  112.         cmShowClip: ShowClip;
  113.       else
  114.         Exit;
  115.       end;
  116.   else
  117.     Exit;
  118.   end;
  119.   ClearEvent(Event);
  120. end;
  121.  
  122. procedure TEditorApp.InitMenuBar;
  123. var
  124.   R: TRect;
  125. begin
  126.   GetExtent(R);
  127.   R.B.Y := R.A.Y + 1;
  128.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  129.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  130.       StdFileMenuItems(
  131.       nil)),
  132.     NewSubMenu('~E~dit', hcNoContext, NewMenu(
  133.       StdEditMenuItems(
  134.       nil)),
  135.     NewSubMenu('~S~earch', hcNoContext, NewMenu(
  136.       NewItem('~F~ind...', '', kbNoKey, cmFind, hcNoContext,
  137.       NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcNoContext,
  138.       NewItem('~S~earch again', '', kbNoKey, cmSearchAgain, hcNoContext,
  139.       nil)))),
  140.     NewSubMenu('~W~indows', hcNoContext, NewMenu(
  141.       StdWindowMenuItems(
  142.       NewLine(
  143.       NewItem('Ca~l~culator', '', kbNoKey, cmCalculator, hcNoContext,
  144.       nil)))),
  145.     nil)))))));
  146. end;
  147.  
  148. procedure TEditorApp.InitStatusLine;
  149. var
  150.   R: TRect;
  151. begin
  152.   GetExtent(R);
  153.   R.A.Y := R.B.Y - 1;
  154.   New(StatusLine, Init(R,
  155.     NewStatusDef(0, $FFFF,
  156.       NewStatusKey('~F2~ Save', kbF2, cmSave,
  157.       NewStatusKey('~F3~ Open', kbF3, cmOpen,
  158.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  159.       NewStatusKey('~F5~ Zoom', kbF5, cmZoom,
  160.       NewStatusKey('~F6~ Next', kbF6, cmNext,
  161.       NewStatusKey('~F10~ Menu', kbF10, cmMenu,
  162.       NewStatusKey('', kbCtrlF5, cmResize,
  163.       nil))))))),
  164.     nil)));
  165. end;
  166.  
  167. procedure TEditorApp.OutOfMemory;
  168. begin
  169.   MessageBox('Not enough memory for this operation.',
  170.     nil, mfError + mfOkButton);
  171. end;
  172.  
  173. begin
  174.   EditorApp.Init;
  175.   EditorApp.Run;
  176.   EditorApp.Done;
  177. end.
  178.