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

  1. Unit OHelpWin;
  2. { fenêtre d'aide }
  3. { K.B. juin-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,
  14.      UDrivers,
  15.      OFHelp,
  16.      OGenView,OTxtView;
  17.  
  18. Const
  19.  cmHelpOk=100;
  20.  
  21. Type
  22.  PHelpWin=^THelpWin;
  23.  THelpWin=object(TWindow)
  24.   Fichier:PHelpFile;
  25.   Choix:Integer;
  26.   Index:Boolean;
  27.   Constructor Init(NomFichier:PathStr);
  28.   Destructor Done;virtual;
  29.   Procedure HandleEvent(Var Event:TEvent);virtual;
  30.   Procedure DrawInterior;virtual;
  31.   Procedure DrawIndex;
  32.   Procedure DrawItem;
  33.   Function GetErrorMsg:String; virtual;
  34.   End;
  35.  
  36. IMPLEMENTATION
  37.  
  38. Constructor THelpWin.Init(NomFichier:PathStr);
  39. Begin
  40.  TWindow.Init(1,2,62,18,' AIDE ');
  41.  PalOffset:=pCyan;
  42.  Fichier:=New(PHelpFile,Init(NomFichier));
  43.  if not Fichier^.IsValid
  44.     then ErrorFlag:=2;
  45.  Choix:=1;
  46.  Index:=true;
  47. End;
  48.  
  49. Destructor THelpWin.Done;
  50. Begin
  51.  dispose(Fichier,Done);
  52.  TWindow.Done;
  53. End;
  54.  
  55. Procedure THelpWin.HandleEvent(Var Event:TEvent);
  56. Var P:TPoint;
  57.     n:Integer;
  58. Begin
  59.  TWindow.HandleEvent(Event);
  60.  if Etat and stSelected=0
  61.     then exit;
  62.  case Event.What of
  63.   evCommand:
  64.    case Event.Command of
  65.     cmHelpOk:
  66.       begin
  67.        Index:=not Index;
  68.       end;
  69.     else exit;
  70.    end;
  71.   evKeyDown:
  72.    case Event.KeyCode of
  73.     Ret : SetCommand(cmHelpOk);
  74.     CsRg: if Index
  75.              then begin
  76.                    if Choix<Fichier^.NombreItems
  77.                       then inc(Choix);
  78.                   end;
  79.     CsLf: if Index
  80.              then begin
  81.                    if Choix>1
  82.                       then dec(Choix);
  83.                   end;
  84.     CsUp: if Index
  85.              then begin
  86.                    if Choix>=4
  87.                       then dec(Choix,3);
  88.                   end;
  89.     CsDn: if Index
  90.              then begin
  91.                    if Choix<=Fichier^.NombreItems-3
  92.                       then inc(Choix,3);
  93.                   end;
  94.     else exit;
  95.    end;
  96.   evMouseLDown:
  97.    begin
  98.     if not Index
  99.        then begin
  100.              repeat
  101.               GetMouseEvent(Event);
  102.              until Event.What=evMouseLUp;
  103.              SetCommand(cmHelpOk);
  104.             end
  105.        else begin
  106.              if MouseInView and not SurCadre(Event.Where)
  107.                 then begin
  108.                       repeat
  109.                        GetMouseEvent(Event)
  110.                       until Event.What=evMouseLUp;
  111.                       MakeLocal(Event.Where,P);
  112.                       n:=3*(P.Y-6)+P.X div 20 +1;
  113.                       if n=Choix
  114.                          then SetCommand(cmHelpOk)
  115.                          else if (n>0) and (n<=Fichier^.NombreItems)
  116.                                  then Choix:=n
  117.                                  else exit;
  118.                      end
  119.                 else exit;
  120.             end;
  121.    end;
  122.   else exit;
  123.   end;
  124.  DrawInterior;
  125.  Event.What:=evNothing;
  126. End;
  127.  
  128. Procedure THelpWin.DrawIndex;
  129. Var i:Integer;
  130.     x,y:Byte;
  131.     S:String;
  132. Begin
  133.  S:=' ';
  134.  Ajuste(S,largeur);
  135.  Ecrire(S,1,1,0);
  136.  Ecrire(S,1,3,0);
  137.  S:=Fichier^.FName+Fichier^.FExt;
  138.  while length(S)<largeur do S:=' '+S+' ';
  139.  Ajuste(S,largeur);
  140.  Ecrire(S,1,2,0);
  141.  x:=1;
  142.  y:=4;
  143.  For i:=1 to Fichier^.NombreItems do
  144.   begin
  145.    S:=Fichier^.Titre(i);
  146.    Ajuste(S,20);
  147.    if i=Choix
  148.       then Ecrire(S,x,y,1)
  149.       else Ecrire(S,x,y,0);
  150.    x:=x+20;
  151.    if x>largeur
  152.       then begin
  153.             x:=1;
  154.             inc(y);
  155.             if y>hauteur then exit;
  156.            end;
  157.   end;
  158.  if x<largeur
  159.     then begin
  160.           S:=' ';
  161.           Ajuste(S,largeur-x);
  162.           Ecrire(S,x,y,0);
  163.           inc(y);
  164.          end;
  165.  S:=' ';
  166.  Ajuste(S,largeur);
  167.  while y<=hauteur do
  168.   begin
  169.    Ecrire(S,1,y,0);
  170.    inc(y);
  171.   end;
  172. End;
  173.  
  174. Procedure THelpWin.DrawItem;
  175. Var y:Byte;
  176.     S:String;
  177.     fini:Boolean;
  178. Begin
  179.  with Fichier^ do
  180.   begin
  181.    y:=1;
  182.    if FindItem(Titre(Choix))
  183.       then repeat
  184.             S:=GetLine;
  185.             fini:=S[1]='#';
  186.             if not fini
  187.                then begin
  188.                      Ajuste(S,Largeur);
  189.                      Ecrire(S,1,y,0);
  190.                      inc(y);
  191.                      if y>hauteur
  192.                         then fini:=true;
  193.                     end;
  194.            until fini;
  195.   end;
  196.  S:=' ';
  197.  Ajuste(S,largeur);
  198.  while y<=hauteur do
  199.   begin
  200.    Ecrire(S,1,y,0);
  201.    inc(y);
  202.   end;
  203. End;
  204.  
  205. Procedure THelpWin.DrawInterior;
  206. Begin
  207.  DrawBegin;
  208.  if Index
  209.     then DrawIndex
  210.     else DrawItem;
  211.  DrawEnd;
  212. End;
  213.  
  214. Function THelpWin.GetErrorMsg:String;
  215. Begin
  216.  case ErrorFlag of
  217.   2: GetErrorMsg:=Fichier^.GetErrorMsg;
  218.   else GetErrorMsg:=TWindow.GetErrorMsg;
  219.   end;
  220. End;
  221.  
  222. END.
  223.  
  224. {                        Fin du fichier OHelpWin.Pas                        }
  225.