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

  1. Unit OEdWin;
  2. { fenêtre éditeur }
  3. { K.B. 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 Dos,UDrivers,UTextScr,OGenView,OTxtView,OTEdit;
  14.  
  15. Const erEdObj = 50;
  16.  
  17. Type
  18.  PEdWin=^TEdWin;
  19.  TEdWin=object(TWindow)
  20.   EdObj : PEdObj;
  21.   Constructor Init(x1,y1,l,h:Integer);
  22.   Constructor Load(x1,y1,l,h:Integer; NomDeFichier:PathStr);
  23.   Destructor Done; virtual;
  24.   Procedure Select; virtual;
  25.   Procedure DrawInterior; virtual;
  26.   Procedure HandleEvent(var Event:TEvent); virtual;
  27.   Function  GetErrorMsg:String; virtual;
  28.   End;
  29.  
  30. IMPLEMENTATION
  31.  
  32. { objet TEdWin }
  33.  
  34. Constructor TEdWin.Init(x1,y1,l,h:Integer);
  35. Begin
  36.  TWindow.Init(x1,y1,l,h,' sans nom ');
  37.  Ident:='EDWIN';
  38.  Etat:=Etat or stCurseur;
  39.  EdObj:=New(PEdObj,Init(h-2,l-2));
  40.  if not EdObj^.IsValid
  41.     then ErrorFlag:=erEdObj;
  42. End;
  43.  
  44. Constructor TEdWin.Load(x1,y1,l,h:Integer;NomDeFichier:PathStr);
  45. Begin
  46.  TWindow.Init(x1,y1,l,h,'');
  47.  Ident:='EDWIN';
  48.  Titre:=NomDeFichier;
  49.  Etat:=Etat or stCurseur;
  50.  EdObj:=New(PEdObj,Load(h-2,l-2,NomDeFichier));
  51.  if not EdObj^.IsValid
  52.     then ErrorFlag:=erEdObj;
  53. End;
  54.  
  55. Destructor TEdWin.Done;
  56. Begin
  57.  dispose(EdObj,Done);
  58.  TWindow.Done;
  59. End;
  60.  
  61. Procedure TEdWin.Select;
  62. Var P : TPoint;
  63. Begin
  64.  TWindow.Select;
  65.  if EdObj<>nil
  66.     then begin
  67.           MakeGlobal(Origin,P);
  68.           SetCursorPos(P.X+EdObj^.NrScreenColumn,P.Y+EdObj^.NrScreenLine);
  69.          end;
  70. End;
  71.  
  72. Function TEdWin.GetErrorMsg:String;
  73. Var S : String;
  74. Begin
  75.  case ErrorFlag of
  76.   erEdObj : S:=EdObj^.GetErrorMsg;
  77.   else S:=TWindow.GetErrorMsg;
  78.   end;
  79.  GetErrorMsg:=S;
  80. End;
  81.  
  82. Procedure TEdWin.DrawInterior;
  83. Var i,ALine : Integer;
  84.     S : String;
  85.     P : TPoint;
  86. Begin
  87.  ALine:=EdObj^.FirstScreenLine;
  88.  For i:=1 to Hauteur do
  89.   begin
  90.    if ALine<=EdObj^.NombreItems
  91.       then begin
  92.             S:=EdObj^.Ligne(ALine);
  93.             S:=copy(S,EdObj^.FirstTextCol,EdObj^.NbCols);
  94.             inc(ALine);
  95.            end
  96.       else S:='';
  97.    Ajuste(S,EdObj^.NbCols);
  98.    Ecrire(S,1,i,0);
  99.   end;
  100.  { mise à jour du curseur }
  101.  MakeGlobal(Origin,P);
  102.  SetCursorPos(P.X+EdObj^.NrScreenColumn,P.Y+EdObj^.NrScreenLine);
  103. End;
  104.  
  105. Procedure TEdWin.HandleEvent(var Event:TEvent);
  106. Var P : TPoint;
  107. Begin
  108.  TWindow.HandleEvent(Event);
  109.  case Event.What of
  110.   evKeyDown :
  111.     begin
  112.      with EdObj^ do
  113.       case Event.KeyCode of
  114.         CsLf:  CharLeft;
  115.         CsRg:  CharRight;
  116.         Home:  StartLine;
  117.         Fin:   EndLine;
  118.         CsUp:  CharUp;
  119.         CsDn:  CharDown;
  120.         PgUp:  PageUp;
  121.         PgDn:  PageDown;
  122.         CPgUp: StartText;
  123.         CPgDn: EndText;
  124.         Inser: ChangeInsertMode;
  125.         Suppr: DelChar;
  126.         BSP:   DelPrevChar;
  127.         Tab:   CharTab;
  128.         Ret:   NewLine;
  129.         CtrlY: DelLine;
  130.         else begin
  131.               if (Event.KeyCode<32) or (Event.KeyCode>255)
  132.                  then exit
  133.                  else InsertChar(Chr(Event.KeyCode));
  134.              end;
  135.        end;
  136.     end;
  137.   evMouseAuto :
  138.     begin
  139.      MakeGlobal(Origin,P);
  140.      if Event.LButton and SurCadre(Event.Where)
  141.         then begin
  142.               if Event.Where.Y>P.Y+hauteur div 2
  143.                  then EdObj^.CharDown
  144.                  else EdObj^.CharUp;
  145.              end
  146.         else exit;
  147.     end;
  148.   evMouseLUp :
  149.     begin
  150.      if not MouseInView or (Etat and stSelected=0)
  151.         then exit;
  152.      if not SurCadre(Event.Where)
  153.         then begin
  154.               MakeLocal(Origin,P);
  155.               P.X:=Event.Where.X-P.X;
  156.               P.Y:=Event.Where.Y-P.Y;
  157.               EdObj^.NewPos(P.X,P.Y);
  158.              end
  159.         else exit;
  160.     end;
  161.   else exit;
  162.   end;
  163.  DrawInterior;
  164. End;
  165.  
  166. END.
  167.  
  168. {                         Fin du fichier OEdWin.Pas                         }
  169.