home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 4.ddi / DOCDEMOS.ZIP / TVGUID08.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-10-23  |  4.7 KB  |  203 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal 6.0                             }
  4. {   Demo program from the Turbo Vision Guide     }
  5. {                                                }
  6. {   Copyright (c) 1990 by Borland International  }
  7. {                                                }
  8. {************************************************}
  9.  
  10. program TVGUID08;
  11.  
  12. uses Objects, Drivers, Views, Menus, App;
  13.  
  14. const
  15.   FileToRead        = 'TVGUID08.PAS';
  16.   MaxLines          = 100;
  17.   WinCount: Integer =   0;
  18.   cmFileOpen        = 100;
  19.   cmNewWin          = 101;
  20.  
  21. var
  22.   LineCount: Integer;
  23.   Lines: array[0..MaxLines - 1] of PString;
  24.    
  25. type
  26.   TMyApp = object(TApplication)
  27.     procedure HandleEvent(var Event: TEvent); virtual;
  28.     procedure InitMenuBar; virtual;
  29.     procedure InitStatusLine; virtual;
  30.     procedure NewWindow;
  31.   end;
  32.  
  33.   PInterior = ^TInterior;
  34.   TInterior = object(TScroller)
  35.     constructor Init(var Bounds: TRect; AHScrollBar,
  36.       AVScrollBar: PScrollBar);
  37.     procedure Draw; virtual;
  38.   end;
  39.  
  40.   PDemoWindow = ^TDemoWindow;
  41.   TDemoWindow = object(TWindow)
  42.     constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  43.     procedure MakeInterior(Bounds: TRect);
  44.   end;
  45.  
  46. procedure ReadFile;
  47. var
  48.   F: Text;
  49.   S: String;
  50. begin
  51.   LineCount := 0;
  52.   Assign(F, FileToRead);
  53.   {$I-}
  54.   Reset(F);
  55.   {$I+}
  56.   if IOResult <> 0 then
  57.   begin
  58.     Writeln('Cannot open ', FileToRead);
  59.     Halt(1);
  60.   end;
  61.   while not Eof(F) and (LineCount < MaxLines) do
  62.   begin
  63.     Readln(F, S);
  64.     Lines[LineCount] := NewStr(S);
  65.     Inc(LineCount);
  66.   end;
  67.   Close(F);
  68. end;
  69.  
  70. procedure DoneFile;
  71. var
  72.   I: Integer;
  73. begin
  74.   for I := 0 to LineCount - 1 do
  75.     if Lines[I] <> nil then DisposeStr(Lines[i]);
  76. end;
  77.  
  78. { TInterior }
  79. constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
  80.   AVScrollBar: PScrollBar);
  81. begin
  82.   TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
  83.   GrowMode := gfGrowHiX + gfGrowHiY;
  84.   Options := Options or ofFramed;
  85.   SetLimit(128, LineCount);
  86. end;
  87.  
  88. procedure TInterior.Draw;
  89. var
  90.   Color: Byte;
  91.   I, Y: Integer;
  92.   B: TDrawBuffer;
  93. begin
  94.   Color := GetColor(1);
  95.   for Y := 0 to Size.Y - 1 do
  96.   begin
  97.     MoveChar(B, ' ', Color, Size.X);
  98.     i := Delta.Y + Y;
  99.     if (I < LineCount) and (Lines[I] <> nil) then
  100.       MoveStr(B, Copy(Lines[I]^, Delta.X + 1, Size.X), Color);
  101.     WriteLine(0, Y, Size.X, 1, B);
  102.   end;
  103. end;
  104.  
  105. { TDemoWindow }
  106. constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String;
  107.   WindowNo: Word);
  108. var
  109.   S: string[3];
  110. begin
  111.   Str(WindowNo, S);
  112.   TWindow.Init(Bounds, WinTitle + ' ' + S, wnNoNumber);
  113.   MakeInterior(Bounds);
  114. end;
  115.  
  116. procedure TDemoWindow.MakeInterior(Bounds: TRect);
  117. var
  118.   HScrollBar, VScrollBar: PScrollBar;
  119.   Interior: PInterior;
  120.   R: TRect;
  121. begin
  122.   VScrollBar := StandardScrollBar(sbVertical + sbHandleKeyboard);
  123.   HScrollBar := StandardScrollBar(sbHorizontal + sbHandleKeyboard);
  124.   GetExtent(Bounds);
  125.   Bounds.Grow(-1,-1);
  126.   Interior := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
  127.   Insert(Interior);
  128. end;
  129.  
  130. { TMyApp }
  131. procedure TMyApp.HandleEvent(var Event: TEvent);
  132. begin
  133.   TApplication.HandleEvent(Event);
  134.   if Event.What = evCommand then
  135.   begin
  136.     case Event.Command of
  137.       cmNewWin: NewWindow;
  138.     else
  139.       Exit;
  140.     end;
  141.     ClearEvent(Event);
  142.   end;
  143. end;
  144.  
  145. procedure TMyApp.InitMenuBar;
  146. var R: TRect;
  147. begin
  148.   GetExtent(R);
  149.   R.B.Y := R.A.Y + 1;
  150.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  151.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  152.       NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
  153.       NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
  154.       NewLine(
  155.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  156.       nil))))),
  157.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  158.       NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
  159.       NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
  160.       nil))),
  161.     nil))
  162.   )));
  163. end;
  164.  
  165. procedure TMyApp.InitStatusLine;
  166. var R: TRect;
  167. begin
  168.   GetExtent(R);
  169.   R.A.Y := R.B.Y - 1;
  170.   StatusLine := New(PStatusLine, Init(R,
  171.     NewStatusDef(0, $FFFF,
  172.       NewStatusKey('', kbF10, cmMenu,
  173.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  174.       NewStatusKey('~F4~ New', kbF4, cmNewWin,
  175.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  176.       nil)))),
  177.     nil)
  178.   ));
  179. end;
  180.  
  181. procedure TMyApp.NewWindow;
  182. var
  183.   Window: PDemoWindow;
  184.   R: TRect;
  185. begin
  186.   Inc(WinCount);
  187.   R.Assign(0, 0, 24, 7);
  188.   R.Move(Random(55), Random(16));
  189.   Window := New(PDemoWindow, Init(R, 'Demo Window', WinCount));
  190.   DeskTop^.Insert(Window);
  191. end;
  192.  
  193. var
  194.   MyApp: TMyApp;
  195.  
  196. begin
  197.   ReadFile;
  198.   MyApp.Init;
  199.   MyApp.Run;
  200.   MyApp.Done;
  201.   DoneFile;
  202. end.
  203.