home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPW73.ZIP / TPW73.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-11  |  15.4 KB  |  550 lines

  1. {$A+,B-,D+,E-,F-,I-,L+,N-,O-,R-,S-,V-}
  2.  
  3. unit TPW73;
  4.  
  5. interface
  6.  
  7. uses dos,crt;
  8.  
  9. type
  10.   ItemList  = array [1..15] of string;
  11.   vmenurec  = record
  12.                 item:itemlist;
  13.                 liveitem : string;
  14.                 itemcount,startpos,curntpos,
  15.                 hlattr,flattr,noattr,bartype:integer;
  16.                 flon:boolean;
  17.               end;
  18.   hmenurec  = record
  19.                 item    : itemlist;
  20.                 subitem : string;
  21.                 itemcount,startpos,curntpos,hlattr,flattr:integer;
  22.                 menuspaces,barloc:integer;
  23.                 flon:boolean;
  24.               end;
  25.   str76     = string[76];
  26.   lstarray  = array[0..1000] of ^str76;
  27.  
  28. var
  29.   winspeed : word;
  30.   HeapTop  : ^Integer;
  31.   ch1,ch2  : char;
  32.   stathold : word;
  33.  
  34. procedure SPrint   (row,col:integer;strdat:string;tattr:integer);
  35. procedure SFill    (row,col,rows,cols:integer;ch:char;tattr:integer);
  36. procedure SColor   (row,col,rows,cols,tattr:integer);
  37. procedure SPrintc  (row,colL,colR:integer;strdat:string;tattr:integer);
  38. procedure openwin  (row,col,rows,cols,wtattr,wbtattr,brdrsel,stattr,shadow,zoom:integer);
  39. procedure fakewin  (row,col,rows,cols,wtattr,wbtattr,brdrsel,stattr,shadow,zoom:integer);
  40. procedure titlewin (dir,tattr:integer;title:string);
  41. procedure closewin;
  42. procedure printwin (row,col:integer;strdat:string);
  43. procedure printcwin(row:integer;strdat:string);
  44. procedure scrollwin(dir:char);
  45. procedure MakeHMenu(var menu:hmenurec);
  46. procedure MakeVMenu(var menu:vmenurec);
  47. procedure CursorOff;
  48. procedure CursorOn;
  49. procedure Getkey(var ch1:char; var ch2:char);
  50. function  Attr     (fore,back:integer):integer;
  51. function  CurDisplay : byte;
  52. function  MakeLmenu(PtrArray:lstarray;NumRecs,StartPos:integer;hlattr:integer):integer;
  53.  
  54. implementation
  55.  
  56. const
  57.   ftable : array [0..16,1..6] of char =
  58.              ('      ' , '┌┐└┘│─' , '╔╗╚╝║═' , '╒╕╘╛│═' , '╓╖╙╜║─',
  59.                          '██████' , '░░░░░░' , '▒▒▒▒▒▒' , '▓▓▓▓▓▓' ,
  60.                          '┬┬└┘│─' , '╦╦╚╝║═' , '╤╤╘╛│═' , '╥╥╙╜║─',
  61.                          '├┤└┘│─' , '╠╣╚╝║═' , '╞╡╘╛│═' , '╟╢╙╜║─');
  62.  
  63. type
  64.   BytePtr  = ^Byte;
  65.   ScrRec   = Record
  66.                 wrow, wrows,wcol,wcols,wattr,wbattr,
  67.                 wbrdr,wshdw,wlastx,wlasty:integer;
  68.               end;
  69.  
  70. var
  71.   ScrStat   : array [0..30] of ScrRec;
  72.   ScrPtr    : array [1..30] of BytePtr;
  73.   IDX       : byte;
  74.   hmenuopen : boolean;
  75.   vmenuopen : boolean;
  76.   movbar    : integer;
  77.  
  78. {$L TPW73}
  79. procedure SPrint;     external;
  80. procedure SFill;      external;
  81. procedure SColor;     external;
  82. procedure openbox (row,col,rows,cols,wattr,wbattr,brdrsel,zoom,sattr,shadow:integer;ScrPtr:BytePtr); external;
  83. procedure closebox(row,col,rows,cols,shadow:integer;ScrPtr:byteptr);                                 external;
  84. procedure titlebox(loc,row,col,rows,cols:integer;strdat:string;tattr:integer);                       external;
  85. procedure scroll  (dir:char;memarr:byteptr;row,col,rows,cols:integer);                               external;
  86. procedure cursoroff;  external;
  87. procedure cursoron;   external;
  88. function  CurDisplay; external;
  89. function  attr;       external;
  90.  
  91. procedure getkey;
  92. begin
  93.   ch2 := #0;
  94.   ch1 := readkey;
  95.   If ch1 = #0 then ch2 := readkey;
  96. end;
  97.  
  98. procedure openwin;
  99. var
  100.   wsize:integer;
  101. begin
  102.   if shadow <1 then wsize:=(cols*rows*2) else wsize:=((rows+1)*(cols+2)*2);
  103.   ScrStat[IDX].wlastx := wherex;
  104.   ScrStat[IDX].wlasty := wherey;
  105.   IDX:= IDX+1;
  106.   with ScrStat[IDX] do
  107.   begin
  108.     wrow  := row; wcol  := col;   wrows := rows;   wbattr := wbtattr;
  109.     wcols := cols;wattr := wtattr;wbrdr := brdrsel;wshdw  := shadow;
  110.   end;
  111.   getmem(ScrPtr[IDX],wsize);
  112.   openbox(row,col,rows,cols,wtattr,wbtattr,brdrsel,zoom,stattr,shadow,ScrPtr[IDX]);
  113.   window(col+1,row+1,col+cols-2,row+rows-2);
  114.   textattr := wtattr;
  115.   gotoxy(1,1);
  116. end;
  117.  
  118. procedure titlewin;
  119. begin
  120.   with ScrStat[IDX] do titlebox(dir,wrow,wcol,wrows,wcols,title,tattr);
  121. end;
  122.  
  123. procedure closewin;
  124. var
  125.   wsize:integer;
  126. begin
  127.   if idx > 0 then
  128.     with ScrStat[IDX] do
  129.     begin
  130.       if wshdw < 1 then wsize:=(wcols*wrows*2) else wsize:=((wrows+1)*(wcols+2)*2);
  131.       closebox(wrow,wcol,wrows,wcols,wshdw,ScrPtr[IDX]);
  132.       freemem(ScrPtr[IDX],wsize);
  133.     end;
  134.     IDX:=IDX-1;
  135.     with ScrStat[IDX] do
  136.     begin
  137.       if IDX=0 then window(1,1,80,25)
  138.           else window(wcol+1,wrow+1,wcol+wcols-2,wrow+wrows-2);
  139.       textattr:=wattr;
  140.       gotoxy(wlastx,wlasty);
  141.     end;
  142. end;
  143.  
  144. procedure printwin;
  145. begin
  146.   with ScrStat[IDX] do SPrint(wrow+row,wcol+col,strdat,wattr);
  147. end;
  148.  
  149. procedure Sprintc;
  150. var
  151.   col : integer;
  152. begin
  153.   col := (((colr-coll) shr 1) + coll) - ((length(strdat) shr 1));
  154.   sprint(row,col,strdat,tattr);
  155. end;
  156.  
  157. procedure printcwin;
  158. begin
  159.   with ScrStat[IDX] do SPrintc(wrow+row,wcol,wcol+wcols,strdat,wattr);
  160. end;
  161.  
  162. procedure fakewin;
  163. begin
  164.   openbox(row,col,rows,cols,wtattr,wbtattr,brdrsel,zoom,stattr,shadow,NIL);
  165. end;
  166.  
  167. procedure scrollwin;
  168. var
  169.   wsize : integer;
  170.   memarr : byteptr;
  171. begin
  172.   with ScrStat[IDX] do
  173.   begin
  174.    wsize := (wcols-2)*(wrows-3)*2;
  175.    getmem(memarr,wsize);
  176.    if dir = 'U' then
  177.    begin
  178.      scroll('U',memarr,wrow+2,wcol+1,wrows-3,wcols-2);
  179.      sfill(wrow+wrows-2,wcol+1,1,wcols-3,' ',wattr);
  180.    end
  181.    else
  182.    begin
  183.      scroll('D',memarr,wrow+1,wcol+1,wrows-3,wcols-2);
  184.      sfill(wrow+1,wcol+1,1,wcols-3,' ',wattr);
  185.    end;
  186.    freemem(memarr,wsize);
  187.  end;
  188. end;
  189.  
  190. procedure MakeHMenu;
  191. var
  192.   done : boolean;
  193.   mpos : integer;
  194.   itemlen : integer;
  195.  
  196. {}procedure turnon;
  197.   var
  198.     x : integer;
  199.   begin
  200.     with ScrStat[IDX],menu do
  201.     begin
  202.       itemlen := 0;
  203.       for x := 1 to curntpos-1 do itemlen := itemlen +length(item[x])+menuspaces;
  204.       SColor(wrow+barloc,wcol+menuspaces+itemlen,1,length(item[curntpos]),hlattr);
  205.     end;
  206.   end;
  207.  
  208. {}procedure turnoff;
  209.   begin
  210.     with ScrStat[IDX], menu do
  211.     begin
  212.       SColor(wrow+barloc,wcol+menuspaces+itemlen,1,length(item[curntpos]),textattr);
  213.       if flon then SPrint(wrow+barloc,wcol+menuspaces+itemlen,item[curntpos][1],FLattr);
  214.     end;
  215.   end;
  216.  
  217. begin
  218.   itemlen := 0;
  219.   done := false;
  220.   hmenuopen := true;
  221.   with ScrStat[IDX],menu do
  222.   begin
  223.     for mpos := 1 to itemcount do
  224.     begin
  225.       SPrint(wrow+barloc,wcol+menuspaces+itemlen,item[mpos],textattr);
  226.       if flon then SPrint(wrow+barloc,wcol+menuspaces+itemlen,item[mpos][1],FLattr);
  227.       itemlen := itemlen + length(item[mpos])+menuspaces;
  228.     end;
  229.     if curntpos = 0 then if startpos = 0 then curntpos:=1 else curntpos := startpos;
  230.     if vmenuopen then
  231.     begin
  232.       curntpos := curntpos + movbar;
  233.       if curntpos > itemcount then curntpos := 1;
  234.       if curntpos < 1 then curntpos := itemcount;
  235.     end;
  236.     movbar := 0;
  237.     repeat
  238.       turnon;
  239.       if vmenuopen and (subitem[curntpos] = '1') then done := true
  240.       else
  241.       begin
  242.         getkey(ch1,ch2);
  243.         if ch2 in [#75,#77,#71,#79] then
  244.         begin
  245.           turnoff;
  246.           case ch2 of
  247.             #75 : dec(curntpos);
  248.             #77 : inc(curntpos);
  249.             #71 : curntpos := 1;
  250.             #79 : curntpos := itemcount;
  251.           end;
  252.           if curntpos > itemcount then curntpos := 1;
  253.           if curntpos < 1 then curntpos := itemcount;
  254.         end;
  255.         if flon then
  256.           for mpos := 1 to itemcount do
  257.             if upcase(ch1) = upcase(item[mpos][1]) then
  258.               begin
  259.                 turnoff;
  260.                 curntpos := mpos;
  261.                 turnon;
  262.                 done := true;
  263.               end;
  264.         if ch1 = #13 then done := true;
  265.         if ch1 = #27 then
  266.           begin
  267.             curntpos := 0;
  268.             done := true;
  269.            hmenuopen := false;
  270.           end;
  271.         if (ch2 = #80) and (subitem[curntpos] = '1') then done := true;
  272.       end;
  273.     until done;
  274.   end;
  275. end;
  276.  
  277. procedure MakeVMenu;
  278. var
  279.   done:boolean;
  280.   mdone:boolean;
  281.   mpos : integer;
  282.  
  283. {}procedure turnon;
  284.   begin
  285.     with ScrStat[IDX],menu do
  286.     begin
  287.       case bartype of
  288.         1 : SColor(wrow+curntpos,wcol+1,1,wcols-2,hlattr);
  289.         2 : SColor(wrow+curntpos,wcol+(wcols shr 1) - (length(item[curntpos]) shr 1)-1,1,
  290.                      length(item[curntpos]) + 2,hlattr);
  291.         3 : SPrint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1-2,'═',hlattr);
  292.       end;
  293.     end;
  294.   end;
  295.  
  296. {}procedure turnoff;
  297.   begin
  298.     with ScrStat[IDX], menu do
  299.     begin
  300.       case bartype of
  301.         3 : SPrint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1-2,'  ',textattr)
  302.         else
  303.             SColor(wrow+curntpos,wcol+1,1,wcols-2,textattr);
  304.             if flon then SPrint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1,
  305.                                    item[curntpos][1],FLattr);
  306.       end;
  307.     end;
  308.   end;
  309.  
  310. begin
  311.   done := false;
  312.   vmenuopen := true;
  313.   with ScrStat[IDX],menu do
  314.   begin
  315.     if curntpos = 0 then if startpos = 0 then curntpos:=1 else curntpos := startpos;
  316.     while liveitem[curntpos] <> '1' do inc(curntpos);
  317.     if curntpos > itemcount then
  318.     begin
  319.       startpos := 0;
  320.       curntpos := 0;
  321.       done := true;
  322.       vmenuopen := false;
  323.       exit;
  324.     end;
  325.     for mpos := 1 to itemcount do
  326.     begin
  327.       if liveitem[mpos] = '0' then
  328.         SPrint(wrow+mpos,wcol+(wcols shr 1)-length(item[mpos]) shr 1,item[mpos],noattr)
  329.       else begin
  330.         SPrint(wrow+mpos,wcol+(wcols shr 1)-length(item[mpos]) shr 1,item[mpos],textattr);
  331.         if flon then SColor(wrow+mpos,wcol+(wcols shr 1)-length(item[mpos]) shr 1,1,1,FLattr);
  332.       end;
  333.     end;
  334.     repeat
  335.       turnon;
  336.       getkey(ch1,ch2);
  337.       if ch2 in [#72,#80,#71,#79] then
  338.       begin
  339.         turnoff;
  340.         case ch2 of
  341.           #72 : begin
  342.                   dec(curntpos);
  343.                   if curntpos < 1 then curntpos := itemcount;
  344.                   while liveitem[curntpos] = '0' do
  345.                   begin
  346.                     dec(curntpos);
  347.                     if curntpos < 1 then curntpos := itemcount;
  348.                   end;
  349.                 end;
  350.           #80 : begin
  351.                   inc(curntpos);
  352.                   if curntpos > itemcount then curntpos := 1;
  353.                   while liveitem[curntpos] = '0' do
  354.                   begin
  355.                     inc(curntpos);
  356.                     if curntpos > itemcount then curntpos := 1;
  357.                   end;
  358.                 end;
  359.           #71 : begin
  360.                   curntpos := 1;
  361.                   while liveitem[curntpos] = '0' do inc(curntpos);
  362.                 end;
  363.           #79 : begin
  364.                   curntpos := itemcount;
  365.                   while liveitem[curntpos] = '0' do dec(curntpos);
  366.                 end;
  367.         end;
  368.       end;
  369.       if hmenuopen and (ch2 in [#75,#77]) then
  370.       begin
  371.         case ch2 of
  372.           #75 : movbar := -1;
  373.           #77 : movbar := 1;
  374.         end;
  375.         done := true;
  376.         startpos := curntpos;
  377.         curntpos := 0;
  378.       end;
  379.       if flon then
  380.         for mpos := 1 to itemcount do
  381.         begin
  382.           if (upcase(ch1) = upcase(item[mpos][1])) and
  383.              (liveitem[mpos] <> '0')  then
  384.             begin
  385.               turnoff;
  386.               curntpos := mpos;
  387.               startpos := curntpos;
  388.               turnon;
  389.               done := true;
  390.             end;
  391.         end;
  392.       if ch1 = #13 then done := true;
  393.       if ch1 = #27 then
  394.         begin
  395.           curntpos := 0;
  396.           done := true;
  397.           vmenuopen := false;
  398.         end;
  399.     until done;
  400.   end;
  401. end;
  402.  
  403. function MakeLmenu;
  404.  
  405. var
  406.   barpos,i : integer;
  407.   recpos   : integer;
  408.  
  409. {}procedure drawlist;
  410.   var j,k : integer;
  411.   begin
  412.     with ScrStat[IDX] do
  413.     begin
  414.       Sfill(wrow+1,wcol+1,wrows-2,wcols-2,' ',wattr);
  415.       if NumRecs - recpos + 1< i then
  416.       begin
  417.          k := NumRecs-recpos+1;
  418.       end else k := i;
  419.       For j := 1 to k do
  420.       begin
  421.         printwin(j,2,PtrArray[j-1+recpos]^);
  422.       end;
  423.       if NumRecs - recpos + 1< i then BarPos := j;
  424.     end;
  425.   end;
  426.  
  427. begin
  428.   BarPos := 1;
  429.   with ScrStat[IDX] do
  430.   begin
  431.     if NumRecs > wrows-2 then i := wrows-2 else i := NumRecs;
  432.     recpos := startpos;
  433.     drawlist;
  434.     if startpos <> 0 then barpos := 1;
  435.     repeat
  436.       Scolor(wrow+BarPos,wcol+1,1,wcols-2,hlattr);
  437.       getkey(ch1,ch2);
  438.       Scolor(wrow+BarPos,wcol+1,1,wcols-2,wattr);
  439.       Case ch2 of
  440.         #80 : begin
  441.                 if recpos < NumRecs then
  442.                 begin
  443.                   inc(BarPos);
  444.                   inc(recpos);
  445.                   if BarPos > i then
  446.                   begin
  447.                     dec(BarPos);
  448.                     if recpos <= NumRecs then Scrollwin('U')
  449.                       else recpos := NumRecs;
  450.                   end;
  451.                 end;
  452.               end;
  453.         #72 : Begin
  454.                 if recpos > 1 then
  455.                 begin
  456.                   dec(BarPos);
  457.                   dec(recpos);
  458.                   if BarPos < 1 then
  459.                   begin
  460.                     inc(BarPos);
  461.                     if recpos > 0 then Scrollwin('D')
  462.                       else recpos := 1;
  463.                   end;
  464.                 end;
  465.               end;
  466.         #73 : Begin
  467.                 if recpos  > 1 then
  468.                 Begin
  469.                   if (BarPos = 1) then
  470.                   begin
  471.                     recpos := recpos - i;
  472.                     If recpos < 1 then recpos := 1;
  473.                     Drawlist;
  474.                     BarPos := 1;
  475.                   end
  476.                   else
  477.                   begin
  478.                     recpos := recpos - BarPos + 1;
  479.                     BarPos := 1;
  480.                   end;
  481.                 end;
  482.               end;
  483.         #81 : Begin
  484.                 if recpos < NumRecs then
  485.                 Begin
  486.                   if (BarPos = i) then
  487.                   begin
  488.                     recpos := recpos + 1;
  489.                     Drawlist;
  490.                     recpos := recpos + BarPos-1;
  491.                   end
  492.                   else
  493.                   begin
  494.                     if recpos + i - barpos > numrecs then
  495.                     begin
  496.                       barpos := barpos + numrecs - recpos;
  497.                       recpos := numrecs;
  498.                     end
  499.                     else
  500.                     begin
  501.                       recpos := recpos + i - BarPos;
  502.                       BarPos := i;
  503.                     end;
  504.                   end;
  505.                 end;
  506.               end;
  507.         #71 : Begin
  508.                 if recpos <> 1 then
  509.                 Begin
  510.                   recpos := 1;
  511.                   BarPos := 1;
  512.                   if i <> NumRecs then Drawlist;
  513.                 end;
  514.               end;
  515.         #79 : Begin
  516.                 if recpos <> NumRecs then
  517.                 begin
  518.                   recpos := NumRecs - i + 1;
  519.                   if i <> NumRecs then Drawlist;
  520.                   recpos := NumRecs;
  521.                   BarPos := i;
  522.                 end;
  523.               end;
  524.       end;
  525.       if ch1 <> #27 then Sprint(wrow+BarPos,wcol+2,PtrArray[recpos]^,hlattr);
  526.     until (ch1 = #13) or (ch1 = #27);
  527.     if ch1 = #27 then recpos := 0;
  528.   end;
  529.   MakeLmenu := recpos;
  530. end;
  531.  
  532. begin
  533.   IDX := 0;
  534.   with ScrStat[IDX] do
  535.   begin
  536.     Wrow    := 1;
  537.     Wcol    := 1;
  538.     Wrows   := 25;
  539.     Wcols   := 80;
  540.     Wattr   := textattr;
  541.     Wlastx  := WhereX;
  542.     Wlasty  := WhereY;
  543.   end;
  544.   vmenuopen := false;
  545.   hmenuopen := false;
  546.   movbar := 0;
  547.   winspeed := 500;
  548. end.
  549.  
  550.