home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 September / Chip_1999-09_cd.bin / internet / Jeremy / tp / downloads / lists.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-03  |  5KB  |  219 lines

  1. Unit Lists;
  2. interface
  3.  
  4. type PSeznam = ^TSeznam;
  5.      TSeznam = record
  6.                Name: string[80];
  7.                Prikaz: word;
  8.                Text: string[80];
  9.                nasl: PSeznam;
  10.                pred: PSeznam;
  11.                end;
  12.  
  13. procedure LreadItems(LName: string; LPrikaz: word; LText: string);
  14. function ListBox(x,y: byte; LTitle: string; LMax: byte): word;
  15.  
  16. implementation
  17.  uses crt, savewind, okna, vstupy;
  18.  
  19.  var zs, ps, ks, q: PSeznam;
  20.      LSelect, LNormal: byte;
  21.      LWidth: byte;
  22.      LBuf: pbuf;
  23.      JePrvni: boolean;
  24.  
  25.  const pr_NoCom = 0;
  26.  
  27. procedure LReadItems(LName: string; LPrikaz: word; Ltext: string);
  28. begin
  29.      if Jeprvni then
  30.       begin
  31.            new(zs);
  32.            zs^.pred:=nil;
  33.            zs^.nasl:=nil;
  34.            zs^.name:=LName;
  35.            zs^.prikaz:=LPrikaz;
  36.            zs^.text:=LText;
  37.            ks:=zs;
  38.            JePrvni:=False;
  39.       end
  40.      else
  41.       begin
  42.            new(q);
  43.            q^.Name:=LName;
  44.            q^.Prikaz:=LPrikaz;
  45.            q^.Text:=LText;
  46.            ks^.nasl:=q;
  47.            q^.pred:=ks;
  48.            q^.nasl:=nil;
  49.            ks:=q;
  50.       end;
  51. end;
  52.  
  53. procedure ListNul;
  54. begin
  55.      LWidth:=0;
  56.      JePrvni:=true;
  57.      if zs=nil then exit;
  58.      while zs^.nasl<>nil do
  59.       begin
  60.            ps:=zs;
  61.            zs:=zs^.nasl;
  62.            dispose(ps);
  63.       end;
  64.      Dispose(zs);
  65. end;
  66.  
  67. procedure LWidthLn;
  68. var Q: byte;
  69. begin
  70.      Q:=0;
  71.      ps:=zs;
  72.      if ps=nil then exit;
  73.      while ps^.nasl<>nil do
  74.       begin
  75.            if Length(ps^.name)>Q then Q:=Length(ps^.name);
  76.            ps:=ps^.nasl;
  77.       end;
  78.      if Length(ps^.name)>Q then Q:=Length(ps^.name);
  79.      LWidth:=Q;
  80. end;
  81.  
  82. function ListBox(x,y: byte; LTitle: string; LMax: byte): word;
  83. var
  84.    pos: byte;
  85.    p, kv, zv: PSeznam;
  86.    key: char;
  87. begin
  88.      if zs=nil then
  89.       begin
  90.            ListBox:=pr_NoCom;
  91.            ListNul;
  92.            exit;
  93.       end;
  94.      LWidthLn;
  95.      savewin(x-1,y-1,x+LWidth+1,y+Lmax, LBuf);
  96.      wframe(x,y,x+LWidth,y+LMax-1);
  97.      gotoxy(x+(LWidth div 2)-(Length(LTitle) div 2)-1,y-1);
  98.      textattr:=wcTitle;
  99.      write(' ',LTitle,' ');
  100.  
  101.      window(x,y,x+LWidth,y+LMax-1);
  102.      textattr:=LNormal;
  103.      clrscr;
  104.  
  105.      p:=zs;
  106.      pos:=1;
  107.      gotoxy(1, pos);
  108.      write(p^.name);
  109.      window(1,1,80,25);
  110.  
  111.      textattr:=wcText;
  112.      gotoxy(4,23); write(infoln(p^.text));
  113.      window(x,y,x+LWidth,y+LMax-1);
  114.      textattr:=LNormal;
  115.  
  116.      kv:=p;
  117.      while (P^.nasl<>nil) and (pos<Lmax) do
  118.       begin
  119.            p:=p^.nasl;
  120.            inc(pos);
  121.            gotoxy(1,pos);
  122.            write(p^.name);
  123.            kv:=p;
  124.       end;
  125.      pos:=1;
  126.      zv:=zs;
  127.      p:=zv;
  128.      gotoxy(1, pos);
  129.      Textattr:=LSelect;
  130.      ClrEol;
  131.      write(p^.name);
  132.      Textattr:=LNormal;
  133.  
  134.      repeat
  135.            key:=GetLegalKey([CR, ESC, Up, Down]);
  136.            gotoxy(1, pos);
  137.            ClrEol;
  138.            write(p^.name);
  139.            case key of
  140.            Down:
  141.                 begin
  142.                      if p=kv then
  143.                       begin
  144.                            if p<>ks then
  145.                             begin
  146.                                  zv:=zv^.nasl;
  147.                                  kv:=kv^.nasl;
  148.                                  p:=kv;
  149.                                  gotoxy(1,1);
  150.                                  DelLine;
  151.                             end;
  152.                       end
  153.                      else
  154.                       begin
  155.                            p:=p^.nasl;
  156.                            inc(pos);
  157.                       end;
  158.                 end;
  159.            Up:
  160.               begin
  161.                    if p=zv then
  162.                     begin
  163.                          if p<>zs then
  164.                           begin
  165.                                zv:=zv^.pred;
  166.                                kv:=kv^.pred;
  167.                                p:=zv;
  168.                                gotoxy(1,1);
  169.                                InsLine;
  170.                           end;
  171.                     end
  172.                    else
  173.                     begin
  174.                          p:=p^.pred;
  175.                          dec(pos);
  176.                     end;
  177.               end;
  178.            end; {case}
  179.  
  180.            gotoxy(1, pos);
  181.            TextAttr:=LSelect;
  182.            ClrEol;
  183.            write(p^.name);
  184.            textattr:=LNormal;
  185.  
  186.            window(1,1,80,25);
  187.            textattr:=wcText;
  188.            gotoxy(4,23); write(infoln(p^.text));
  189.            textattr:=LNormal;
  190.            window(x,y,x+LWidth,y+LMax-1);
  191.  
  192.      until key in [CR, ESC];
  193.  
  194.      if key=ESC then ListBox:=pr_NoCom
  195.       else
  196.           ListBox:=p^.prikaz;
  197.  
  198.      window(1,1,80,25);
  199.      Restorewin(x-1,y-1,x+LWidth+1,y+Lmax, LBuf);
  200.      ListNul;
  201. end;
  202.  
  203. var b: byte absolute $0000:$0449;
  204.  
  205. BEGIN
  206.      if b<>7 then
  207.       begin
  208.            LSelect:=16*blue+white;
  209.            LNormal:=16*lightgray+darkgray;
  210.       end
  211.      else
  212.       begin
  213.            LSelect:=16*black+white;
  214.            LNormal:=16*lightgray+black;
  215.       end;
  216.      LWidth:=0;
  217.      JePrvni:=true;
  218. END.
  219.