home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / ktools / source / ocrtwin.pas < prev    next >
Pascal/Delphi Source File  |  1994-10-31  |  4KB  |  183 lines

  1. Unit OCrtWin;
  2. { Fenêtre simulant un écran DOS. }
  3. { KB mai-novembre 1994 }
  4.  
  5. {$IFDEF debug}
  6.  {$A+,B-,D+,E-,F-,I+,L+,N-,R+,S+,V-,W+,X+}
  7. {$ELSE}
  8.  {$A+,B-,D-,E-,F-,I+,L-,N-,R-,S-,V-,W+,X+}
  9. {$ENDIF}
  10.  
  11. INTERFACE
  12.  
  13. Uses UDrivers,UTextScr,OGenView,OTxtView;
  14.  
  15. Type
  16.  PCrtWin=^TCrtWin;
  17.  TCrtWin=object(TWindow)
  18.   XPos,YPos:Byte;
  19.   TAttr:Word;
  20.   ReadStr:String;
  21.   Constructor Init(xi,yi,l,h:Integer);
  22.   Procedure DrawInterior;virtual;
  23.   Procedure WinWriteChar(c:Char);
  24.   Procedure WinWrite(S:String);
  25.   Procedure WinWriteln(S:String);
  26.   Procedure EndRead;virtual;
  27.   Procedure HandleEvent(Var Event:TEvent);virtual;
  28.   Procedure Select; virtual;
  29.   Procedure Scroll;
  30.   Procedure GotoNextPos;
  31.   Procedure GotoPrevPos;
  32.   Procedure GotoNextLine;
  33.   Procedure WinGotoXY(x,y:Byte);
  34.   Procedure SetColor(c:Byte);
  35.   End;
  36.  
  37. IMPLEMENTATION
  38.  
  39. { objet TCrtWin }
  40.  
  41. Constructor TCrtWin.Init(xi,yi,l,h:Integer);
  42. Begin
  43.  TWindow.Init(xi,yi,l,h,'');
  44.  Etat:=Etat or stCurseur;
  45.  XPos:=1;
  46.  YPos:=1;
  47.  ReadStr:='';
  48.  TAttr:=GetColor(0);
  49. End;
  50.  
  51. Procedure TCrtWin.DrawInterior;
  52. Var P : TPoint;
  53. Begin
  54.  MakeGlobal(Origin,P);
  55.  SetCursorPos(P.X+xpos,P.Y+ypos);
  56. End;
  57.  
  58. Procedure TCrtWin.Select;
  59. Var P : TPoint;
  60. Begin
  61.  TWindow.Select;
  62.  MakeGlobal(Origin,P);
  63.  SetCursorPos(P.X+xpos,P.Y+ypos);
  64. End;
  65.  
  66. Procedure TCrtWin.WinWriteChar(c:Char);
  67. Begin
  68.  DrawInterior;
  69.  case c of
  70.   #13 : gotonextline;
  71.   #10 :;
  72.    #8 : begin
  73.          gotoprevpos;
  74.          PutCharAttrib(32+256*TAttr,1);
  75.         end;
  76.   else begin
  77.         PutCharAttrib(ord(c)+256*TAttr,1);
  78.         GotoNextPos;
  79.        end;
  80.   end;
  81. End;
  82.  
  83. Procedure TCrtWin.WinWrite(S:String);
  84. Var i:Byte;
  85. Begin
  86.  if S=''
  87.     then exit;
  88.  for i:=1 to length(S) do
  89.    WinWriteChar(S[i]);
  90. End;
  91.  
  92. Procedure TCrtWin.WinWriteln(S:String);
  93. Begin
  94.  WinWrite(S);
  95.  gotonextline;
  96. End;
  97.  
  98. Procedure TCrtWin.EndRead;
  99. Begin
  100.  gotonextline;
  101. End;
  102.  
  103. Procedure TCrtWin.HandleEvent(Var Event:TEvent);
  104. Begin
  105.  TWindow.HandleEvent(Event);
  106.  if Etat and stSelected = 0
  107.     then exit;
  108.  if Event.What=evKeyDown
  109.     then case Event.KeyCode of
  110.            8: WinWriteChar(chr(Event.KeyCode));
  111.           13: begin
  112.                EndRead;
  113.                ReadStr:='';
  114.               end;
  115.           32..255: begin
  116.                     ReadStr:=ReadStr+chr(Event.KeyCode);
  117.                     WinWriteChar(chr(Event.KeyCode));
  118.                    end;
  119.           else exit;
  120.          end;
  121.  Event.What:=evNothing;
  122.  Event.InfoPtr:=@self;
  123. End;
  124.  
  125. Procedure TCrtWin.Scroll;
  126. Var P : TPoint;
  127. Begin
  128.  MakeGlobal(Origin,P);
  129.  ScrollWindowUp(1,TAttr,P.X+1,P.Y+1,
  130.                  P.X+Size.X-2,P.Y+Size.Y-2);
  131. End;
  132.  
  133. Procedure TCrtWin.GotoNextPos;
  134. Begin
  135.  if XPos=Largeur
  136.     then GotoNextLine
  137.     else begin
  138.           inc(XPos);
  139.           DrawInterior;
  140.          end;
  141. End;
  142.  
  143. Procedure TCrtWin.GotoNextLine;
  144. Begin
  145.  XPos:=1;
  146.  if YPos=Hauteur
  147.     then Scroll
  148.     else inc(YPos);
  149.  DrawInterior;
  150. End;
  151.  
  152. Procedure TCrtWin.GotoPrevPos;
  153. Begin
  154.  if XPos=1
  155.     then begin
  156.           if YPos>1
  157.              then begin
  158.                    dec(YPos);
  159.                    XPos:=Largeur;
  160.                   end;
  161.          end
  162.     else dec(XPos);
  163.  DrawInterior;
  164. End;
  165.  
  166. Procedure TCrtWin.WinGotoXY(x,y:Byte);
  167. Begin
  168.  if (x>0) and (x<=Largeur)
  169.     then xpos:=x;
  170.  if (y>0) and (y<=Hauteur)
  171.     then ypos:=y;
  172.  DrawInterior;
  173. End;
  174.  
  175. Procedure TCrtWin.SetColor(c:Byte);
  176. Begin
  177.  TAttr:=c;
  178. End;
  179.  
  180. END.
  181.  
  182. {                        Fin du fichier OCrtWin.Pas                         }
  183.