home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tvision / gravis / gv / gvguid06.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-23  |  4.4 KB  |  194 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 GVGUID06;
  13.  
  14. uses Objects, Drivers, Views, ExtGraph, GVDriver, GVViews, GVMenus, GVApp, MetaGr;
  15.  
  16. const
  17.   FileToRead        = 'GVGUID06.PAS';
  18.   MaxLines          = 100;
  19.   WinCount: Integer =   0;
  20.   cmFileOpen        = 100;
  21.   cmNewWin          = 101;
  22.  
  23. var
  24.   LineCount: Integer;
  25.   Lines: array[0..MaxLines - 1] of PString;
  26.    
  27. type
  28.   TMyApp = object(TApplication)
  29.     procedure InitStatusLine; virtual;
  30.     procedure InitMenuBar; virtual;
  31.     procedure NewWindow;
  32.     procedure HandleEvent(var Event: TEvent); virtual;
  33.   end;
  34.  
  35.   PDemoWindow = ^TDemoWindow;
  36.   TDemoWindow = object(TWindow)
  37.     constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  38.   end;
  39.  
  40.   PInterior = ^TInterior;
  41.   TInterior = object(TGView)
  42.     constructor Init(var Bounds: TRect);
  43.     procedure Draw; virtual;
  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);
  80. begin
  81.   TGView.Init(Bounds);
  82.   GrowMode := gfGrowHiX + gfGrowHiY;
  83. end;
  84.  
  85. procedure TInterior.Draw;
  86. var
  87.   Y: Integer;
  88.   R: TRect;
  89. begin
  90.   SetViewPort;
  91.   HideMouse;
  92.   SetFillStyle (SolidFill, Black);
  93.   Bar (0,0,Size.X-1, Size.Y-1);
  94.   SetGVStyle (ftMonoSpace);
  95.   for Y := 0 to (Size.Y - 1) div 16 do
  96.   begin
  97.     R.Assign (10, 5+Y*16, Size.X-21, 16);
  98.     If Lines[Y]<>nil then OutGVText (R.A, Lines[Y]^, White, White, R.B, False);
  99.   end;
  100.   ShowMouse;
  101.   RestoreViewPort;
  102. end;
  103.  
  104. { TDemoWindow }
  105. constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  106. var
  107.   S: string[3];
  108.   Interior: PInterior;
  109. begin
  110.   Str(WindowNo, S);
  111.   TWindow.Init(Bounds, WinTitle + ' ' + S);
  112.   Delete (Background);
  113.   Dispose (Background, Done);
  114.   GetExtent(Bounds);
  115.   Bounds.Grow(-4,-4);
  116.   Bounds.A.Y:=23;
  117.   Interior := New(PInterior, Init(Bounds));
  118.   Insert(Interior);
  119. end;
  120.  
  121. { TMyApp }
  122. procedure TMyApp.HandleEvent(var Event: TEvent);
  123. begin
  124.   TApplication.HandleEvent(Event);
  125.   if Event.What = evCommand then
  126.   begin
  127.     case Event.Command of
  128.       cmNewWin: NewWindow;
  129.     else
  130.       Exit;
  131.     end;
  132.     ClearEvent(Event);
  133.   end;
  134. end;
  135.  
  136. procedure TMyApp.InitMenuBar;
  137. var R: TRect;
  138. begin
  139.   GetExtent(R);
  140.   R.B.Y := R.A.Y + 21;
  141.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  142.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  143.       NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
  144.       NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
  145.       NewLine(
  146.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  147.       nil))))),
  148.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  149.       NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
  150.       NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
  151.       nil))),
  152.     nil))
  153.   )));
  154. end;
  155.  
  156. procedure TMyApp.InitStatusLine;
  157. var R: TRect;
  158. begin
  159.   GetExtent(R);
  160.   R.A.Y := R.B.Y - 21;
  161.   StatusLine := New(PStatusLine, Init(R,
  162.     NewStatusDef(0, $FFFF,
  163.       NewStatusKey('', kbF10, cmMenu,
  164.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  165.       NewStatusKey('~F4~ New', kbF4, cmNewWin,
  166.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  167.       nil)))),
  168.     nil)
  169.   ));
  170. end;
  171.  
  172. procedure TMyApp.NewWindow;
  173. var
  174.   Window: PDemoWindow;
  175.   R: TRect;
  176. begin
  177.   Inc(WinCount);
  178.   R.Assign(0, 0, 200, 100);
  179.   R.Move(Random(400), Random(300));
  180.   Window := New(PDemoWindow, Init(R, 'Demo Window', WinCount));
  181.   DeskTop^.Insert(Window);
  182. end;
  183.  
  184. var
  185.   MyApp: TMyApp;
  186.  
  187. begin
  188.   ReadFile;
  189.   MyApp.Init;
  190.   MyApp.Run;
  191.   MyApp.Done;
  192.   DoneFile;
  193. end.
  194.