home *** CD-ROM | disk | FTP | other *** search
/ TopWare 18: Liquid / Image.iso / liquid / top1143 / gepackt.exe / BSPQTSW.EXE / EMSLIST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-07-01  |  4.9 KB  |  218 lines

  1. (***************************************
  2. * WG-VISION 1.0   BEISPIELPROGRAMM     *
  3. ****************************************
  4. *                                      *
  5. * Quelltext-Lister unter Verwendung    *
  6. * von Expanded Memory                  *
  7. *                                      *
  8. * Erläuterungen siehe Handbuch         *
  9. *------------------------------------- *
  10. * EMS-Treiber muß geladen sein !       *
  11. * Funktioniert nicht in den Super-VGA- *
  12. * Modi (Sonderzeichensatz)             *
  13. ****************************************
  14. * (c) 1993 Dipl.Phys. Mathias Scholz   *
  15. ***************************************)
  16.  
  17. {$I COMPILER.INC}
  18.  
  19. program Lister;
  20.  
  21. uses WApp,
  22.      WEvent,
  23.      WDecl,
  24.      WViews,
  25.      WDriver,
  26.      WDlg,
  27.      WFileDlg,
  28.      WUtils,
  29.      WEMS,
  30.      WText,
  31.      Graph;
  32.  
  33.  
  34. const cmOpen    = 101;
  35.  
  36. type str128=string[128];
  37.      pStr=^str128;         {String-Pointer}
  38.  
  39. type TApplication=object(TApp)
  40.        procedure InitMenuBar; virtual;
  41.        procedure HandleEvent; virtual;
  42.        procedure LoadFile;
  43.        procedure ListWindow;
  44.      end;
  45.  
  46.      PNewScroller=^TNewScroller;
  47.  
  48.      PScrollWindow=^TScrollWindow;
  49.      TScrollWindow=object(TWindow)
  50.        Scroller:PNewScroller;
  51.        procedure InitWindowScroller; virtual;
  52.        destructor Done; virtual;
  53.      end;
  54.  
  55.      TNewScroller=object(TScroller)
  56.        EMSHandle:word;
  57.        Eintrag:array[1..3072] of pStr;
  58.        destructor Done; virtual;
  59.        procedure CreateData;
  60.        procedure ScrollDraw; virtual;
  61.      end;
  62.  
  63. var MyApp:TApplication;
  64.  
  65. procedure TApplication.InitMenuBar;
  66. begin
  67.   MainMenu('~F~enster',0);
  68.    SubMenu('~D~atei Laden',cmOpen,0,0,false,false);
  69.    NewLine;
  70.    SubMenu('E~x~it  Alt-X',cmCloseApplication,0,altX,false,false);
  71. end;
  72.  
  73. procedure TApplication.HandleEvent;
  74. begin
  75.   EMS^.ShowEMSStatus(453,8,White);
  76.   TProgram.HandleEvent;
  77.   case Event.Command of
  78.    cmOpen    : LoadFile;
  79.   end; {case}
  80.   if Event.Message=msgLoadFile then
  81.    begin
  82.      ListWindow;
  83.      ClearMessage;
  84.    end;
  85. end;
  86.  
  87. procedure TApplication.LoadFile;
  88. var Window:PInputDialog;
  89. begin
  90.   Window:=New(PInputDialog, Init('Dateiauswahl','*.PAS'));
  91.   InsertDesktop(Window);
  92. end;
  93.  
  94. procedure TApplication.ListWindow;
  95. var R:TRect;
  96.     Window:PScrollWindow;
  97. begin
  98.   R.Assign(20,60,616,446);
  99.   Window:=New(PScrollWindow, Init(R,'ScrollWindow / Quelltext-Lister',winDouble+winPanel+winMenu+winKey));
  100.   InsertDesktop(Window);
  101. end;
  102.  
  103. {Implementation TScrollWindow}
  104.  
  105. procedure TScrollWindow.InitWindowScroller;
  106. var R:TRect;
  107.     SBH1,SBV1:PScrollBar;
  108. begin
  109.   R:=Frame^.Area;
  110.   SBH1:=New(PScrollBar, Init(R,HorizDir));
  111.   SBV1:=New(PScrollBar, Init(R,VertDir));
  112.   Scroller:=New(PNewScroller, Init(R,SBH1,SBV1));
  113.   Scroller^.CreateData;
  114.   List^.InsertItem(Scroller);
  115. end;
  116.  
  117. destructor TScrollWindow.Done;
  118. begin
  119.   TWindow.Done;
  120.   Dispose(Scroller, Done);
  121. end;
  122.  
  123. {Implementation TNewScroller}
  124.  
  125. destructor TNewScroller.Done;
  126. begin
  127.   DeAllocatePages(EMSHandle);
  128.   TScroller.Done;
  129. end;
  130.  
  131. procedure TNewScroller.CreateData;
  132. var dat:text;
  133.     LfdPtr:PLine;
  134.     I,k,S,AnzPages:word;
  135.     zz:string[120];
  136.     z:string[4];
  137. begin
  138.   SetFont(Wndw19);
  139.   k:=1; S:=0;
  140.   Assign(dat,Event.InfoString);
  141.   Reset(dat);
  142.   AnzPages:=GetFreePages;
  143.   if AnzPages<=24 then
  144.    begin
  145.      {Hier eventuell Fehlermitteilung einsetzen}
  146.    end
  147.    else
  148.    begin
  149.      EMSHandle:=AllocatePages(24);
  150.      MapHandlePages(EMSHandle,0,0);
  151.      for I:=1 to 3072 do
  152.       begin
  153.         if I mod 128=0 then
  154.          begin
  155.            k:=1;
  156.            MapHandlePages(EMSHandle,0,I div 128);
  157.          end
  158.          else Inc(k);
  159.          Eintrag[I]:=Ptr(PageFrame,(k-1)*128);
  160.          if (I<=3071) and (not Eof(dat)) then
  161.           begin
  162.             ReadLn(dat,zz);
  163.             Str(I:4,z);
  164.             Eintrag[I]^:=z+'  '+zz
  165.           end
  166.          else
  167.           begin
  168.             SetLimit(65,I-1,8,18);
  169.             Close(dat);
  170.             Exit;
  171.           end;
  172.       end;
  173.    end;
  174. end;
  175.  
  176. procedure TNewScroller.ScrollDraw;
  177. var I:integer;
  178.     Max:word;
  179.     LfdPtr:PGroup;
  180.  
  181. function Clip(P,N:byte;z:string):string;
  182. begin
  183.   Clip:=Copy(z,P,N);
  184. end;
  185.  
  186. {--------}
  187.  
  188. begin
  189.   SetFontColor(White,Red);
  190.   Max:=GetHandlePages(EMSHandle);
  191.   Mouse.HideMouse;
  192.   with Border do
  193.    begin
  194.      SetFillStyle(SolidFill,GetPalColor(1));
  195.      SetColor(GetPalColor(2));
  196.      for I:=Delta.Y to WDelta.Y do
  197.       begin
  198.         MapHandlePages(EMSHandle,0,I div 128);
  199.         Bar(A.X,A.Y+(I-Delta.Y)*Py+10,B.X,A.Y+(I-Delta.Y)*Py+10+Py);
  200.         WriteText(A.X+20,A.Y+(I-Delta.Y)*Py+10,Clip(Delta.X,
  201.                   Spalten*8 div 8-5,Eintrag[I]^));
  202.       end;
  203.      if VertiScrollBar<>nil then
  204.       for I:=(WDelta.Y-Delta.Y)+1 to Zeilen do
  205.        Bar(A.X,A.Y+I*Py+10,B.X,A.Y+I*Py+10+Py);
  206.    end;
  207.   Mouse.ShowMouse;
  208. end;
  209.  
  210. {Hauptprogramm}
  211.  
  212. begin
  213.   MyApp.Init('LISTER mit Text in EMS');
  214.   MyApp.Run;
  215.   MyApp.Done;
  216. end.
  217.  
  218.