home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tvision / gravis / gv / gvguid08.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-23  |  5.1 KB  |  217 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. { modifiziert für Graphics Vision von Stefan Milius }
  11.  
  12. program GVGUID08;
  13.  
  14. uses Objects, Drivers, GVDriver, Views, GVViews, GVMenus, GVApp,
  15.      MetaGr, ExtGraph;
  16.  
  17. const
  18.   FileToRead        = 'GVGUID08.PAS';
  19.   MaxLines          = 100;
  20.   WinCount: Integer =   0;
  21.   cmFileOpen        = 100;
  22.   cmNewWin          = 101;
  23.  
  24. var
  25.   LineCount: Integer;
  26.   Lines: array[0..MaxLines - 1] of PString;
  27.    
  28. type
  29.   TMyApp = object(TApplication)
  30.     procedure HandleEvent(var Event: TEvent); virtual;
  31.     procedure InitMenuBar; virtual;
  32.     procedure InitStatusLine; virtual;
  33.     procedure NewWindow;
  34.   end;
  35.  
  36.   PInterior = ^TInterior;
  37.   TInterior = object(TScroller)
  38.     constructor Init(var Bounds: TRect; AHScrollBar,
  39.       AVScrollBar: PScrollBar);
  40.     procedure Draw; virtual;
  41.   end;
  42.  
  43.   PDemoWindow = ^TDemoWindow;
  44.   TDemoWindow = object(TWindow)
  45.     constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  46.     procedure MakeInterior(Bounds: TRect);
  47.   end;
  48.  
  49. procedure ReadFile;
  50. var
  51.   F: Text;
  52.   S: String;
  53. begin
  54.   LineCount := 0;
  55.   Assign(F, FileToRead);
  56.   {$I-}
  57.   Reset(F);
  58.   {$I+}
  59.   if IOResult <> 0 then
  60.   begin
  61.     Writeln('Cannot open ', FileToRead);
  62.     Halt(1);
  63.   end;
  64.   while not Eof(F) and (LineCount < MaxLines) do
  65.   begin
  66.     Readln(F, S);
  67.     Lines[LineCount] := NewStr(S);
  68.     Inc(LineCount);
  69.   end;
  70.   Close(F);
  71. end;
  72.  
  73. procedure DoneFile;
  74. var
  75.   I: Integer;
  76. begin
  77.   for I := 0 to LineCount - 1 do
  78.     if Lines[I] <> nil then DisposeStr(Lines[i]);
  79. end;
  80.  
  81. { TInterior }
  82. constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
  83.   AVScrollBar: PScrollBar);
  84. begin
  85.   TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
  86.   GrowMode := gfGrowHiX + gfGrowHiY;
  87.   SetLimit(128, LineCount);
  88. end;
  89.  
  90. procedure TInterior.Draw;
  91. var I: Integer;
  92.     C: Byte;
  93.     R: TRect;
  94.     S: String;
  95. Begin
  96.   SetViewPort;
  97.   HideMouse;
  98.   { Hintergrund }
  99.   SetFillStyle (SolidFill, Black);
  100.   Bar (0,0,Size.X-1,Size.Y-1);
  101.   { Text }
  102.   SetGVStyle (ftMonoSpace);
  103.   R.Assign (0, 0, Size.X, 18);
  104.   C:=White;
  105.   For I:=Delta.Y to Delta.Y+ Trunc (Size.Y/TextSize.Y) do
  106.     If I<LineCount then Begin
  107.       If Lines[I]<>nil then S:=Lines [I]^
  108.                        else S:='';
  109.       Delete (S, 1, Delta.X);
  110.       OutGVText (R.A, S, C, C, R.B, false);
  111.       R.Move (0,18);
  112.       R.B.Y:=18;
  113.     End;
  114.   ShowMouse;
  115.   RestoreViewPort;
  116. End;
  117.  
  118. { TDemoWindow }
  119. constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String;
  120.   WindowNo: Word);
  121. var
  122.   S: string[3];
  123. begin
  124.   Str(WindowNo, S);
  125.   TWindow.Init(Bounds, WinTitle + ' ' + S);
  126.   Delete (Background); Dispose (Background, Done);
  127.   MakeInterior(Bounds);
  128. end;
  129.  
  130. procedure TDemoWindow.MakeInterior(Bounds: TRect);
  131. var
  132.   HScrollBar, VScrollBar: PScrollBar;
  133.   Interior: PInterior;
  134. begin
  135.   VScrollBar := StandardScrollBar(sbVertical + sbHandleKeyboard);
  136.   HScrollBar := StandardScrollBar(sbHorizontal + sbHandleKeyboard);
  137.   GetExtent(Bounds);
  138.   Bounds.Grow(-4,-4);
  139.   Bounds.A.Y:=23; Dec (Bounds.B.X, 17); Dec (Bounds.B.Y, 17);
  140.   Interior := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
  141.   Insert(Interior);
  142. end;
  143.  
  144. { TMyApp }
  145. procedure TMyApp.HandleEvent(var Event: TEvent);
  146. begin
  147.   TApplication.HandleEvent(Event);
  148.   if Event.What = evCommand then
  149.   begin
  150.     case Event.Command of
  151.       cmNewWin: NewWindow;
  152.     else
  153.       Exit;
  154.     end;
  155.     ClearEvent(Event);
  156.   end;
  157. end;
  158.  
  159. procedure TMyApp.InitMenuBar;
  160. var R: TRect;
  161. begin
  162.   GetExtent(R);
  163.   R.B.Y := R.A.Y + 21;
  164.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  165.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  166.       NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
  167.       NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
  168.       NewLine(
  169.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  170.       nil))))),
  171.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  172.       NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
  173.       NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
  174.       nil))),
  175.     nil))
  176.   )));
  177. end;
  178.  
  179. procedure TMyApp.InitStatusLine;
  180. var R: TRect;
  181. begin
  182.   GetExtent(R);
  183.   R.A.Y := R.B.Y - 21;
  184.   StatusLine := New(PStatusLine, Init(R,
  185.     NewStatusDef(0, $FFFF,
  186.       NewStatusKey('', kbF10, cmMenu,
  187.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  188.       NewStatusKey('~F4~ New', kbF4, cmNewWin,
  189.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  190.       nil)))),
  191.     nil)
  192.   ));
  193. end;
  194.  
  195. procedure TMyApp.NewWindow;
  196. var
  197.   Window: PDemoWindow;
  198.   R: TRect;
  199. begin
  200.   Inc(WinCount);
  201.   R.Assign(0, 0, 200, 100);
  202.   R.Move(Random(400), Random(300));
  203.   Window := New(PDemoWindow, Init(R, 'Demo Window', WinCount));
  204.   DeskTop^.Insert(Window);
  205. end;
  206.  
  207. var
  208.   MyApp: TMyApp;
  209.  
  210. begin
  211.   ReadFile;
  212.   MyApp.Init;
  213.   MyApp.Run;
  214.   MyApp.Done;
  215.   DoneFile;
  216. end.
  217.