home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOOL_INC.ZIP / TOP.INC < prev    next >
Encoding:
Text File  |  1988-01-29  |  4.2 KB  |  176 lines

  1.  
  2. (*
  3.  * top - utility library for simple "pull-down" windows
  4.  *        uses functions in popup.inc
  5.  *
  6.  * written by Samuel H. Smith, 11-nov-87
  7.  *
  8.  *)
  9.  
  10.  
  11. procedure select_pulled(pullno:   integer;
  12.                         var sel:  char);
  13.    (* select and execute a pulldown window *)
  14. var
  15.    save: window_save_rec;
  16. begin
  17.    save_window(save);
  18.    window(1,1,80,25);
  19.    pulldown(wherex-0,wherey+1,pullno,pull_table[pullno],sel);
  20.    restore_window(save);
  21. end;
  22.  
  23.  
  24. procedure top_menu(topx,topy:   integer;
  25.                    var top:     pulldown_rec);
  26.    {top level pulldown window processor; display the top level window
  27.     and process pulldowns related to it}
  28.  
  29.    procedure display_entry(entry: integer);
  30.    var
  31.       i,x: integer;
  32.    begin
  33.       x := topx+1;
  34.       for i := 1 to entry-1 do
  35.          x := x + LEN(top.line[i].title) + 3;
  36.  
  37.       gotoxy(x,topy);
  38.       disp(' '+top.line[entry].title+' ');
  39.       gotoxy(x+1,topy);
  40.    end;
  41.  
  42.    procedure display_top;
  43.       {open a pulldown window at top-left x and y location.
  44.        use the top record to describe the options}
  45.    var
  46.       i,
  47.       j:                  integer;
  48.       active:             integer;
  49.    begin
  50.  
  51.    (* count active entries *)
  52.       active := 0;
  53.       for i := 1 to max_pulldown do
  54.          with top.line[i] do
  55.             if action <> unused_entry then
  56.                inc(active);
  57.  
  58.  
  59.    (* display the border *)
  60.       window(1,1,80,25);
  61.       setcolor(top.border_fg, top.border_bg);
  62.  
  63.       if topy > 1 then
  64.       begin
  65.          gotoxy(topx,topy-1);
  66.          disp('┌');
  67.          for i := 1 to active-1 do
  68.             disp(make_string('─',LEN(top.line[i].title)+2) + '┬');
  69.          disp(make_string('─',LEN(top.line[active].title)+2) + '┐');
  70.       end;
  71.  
  72.       gotoxy(topx,topy);
  73.       disp('│');
  74.       for i := 1 to active do
  75.          disp(make_string(' ',LEN(top.line[i].title)+2) + '│');
  76.  
  77.       gotoxy(topx,topy+1);
  78.       disp('└');
  79.       for i := 1 to active-1 do
  80.          disp(make_string('─',LEN(top.line[i].title)+2) + '┴');
  81.       disp(make_string('─',LEN(top.line[active].title)+2) + '┘');
  82.  
  83.    (* print option descriptions *)
  84.       setcolor(top.text_fg, top.text_bg);
  85.       for i := 1 to active do
  86.          display_entry(i);
  87.    end;
  88.  
  89.  
  90.    procedure pick_top;
  91.       {select an entry from a pulldown window.
  92.        the pulldown must already be on the display}
  93.    var
  94.       pulled:  boolean;
  95.       found:   integer;
  96.       entry:   integer;
  97.       i:       integer;
  98.       sel:     char;
  99.  
  100.       procedure moveby(by: integer);
  101.       begin
  102.          repeat
  103.             entry := entry + by;
  104.             if entry > max_pulldown then
  105.                entry := 1
  106.             else if entry < 1 then
  107.                entry := max_pulldown;
  108.          until top.line[entry].action <> unused_entry;
  109.       end;
  110.  
  111.       procedure select_top;
  112.       begin
  113.          sel := upcase(getkey);
  114.       end;
  115.  
  116.  
  117.    begin
  118.       (* pick the initial selection *)
  119.       pulled := false;
  120.       entry := 0;
  121.       moveby(1);
  122.  
  123.       (* process top level options *)
  124.       repeat
  125.          setcolor(top.select_fg, top.select_bg);
  126.          display_entry(entry);
  127.  
  128.          if pulled then
  129.             select_pulled(top.line[entry].action,sel)
  130.          else
  131.             select_top;
  132.  
  133.          setcolor(top.text_fg, top.text_bg);
  134.          display_entry(entry);
  135.  
  136.          case sel of
  137.             LEFT:      moveby(-1);
  138.             RIGHT:     moveby(1);
  139.  
  140.             DOWN,
  141.             NEWLINE:   pulled := true;
  142.             ESC:       pulled := false;
  143.  
  144.             quit_sel:  exit;
  145.  
  146.             else
  147.             begin
  148.                (* test for capitalized letters *)
  149.                found := 0;
  150.                for i := max_pulldown downto 1 do
  151.                with top.line[i] do
  152.                   if pos(sel, title) > 0 then
  153.                   begin
  154.                      entry := i;
  155.                      found := -1;
  156.                   end;
  157.  
  158.                if found = 0 then
  159.                begin
  160.                   if pulldown_key(0,entry,sel) then
  161.                      exit;
  162.                end;
  163.             end;
  164.          end;
  165.  
  166.       until true=false;
  167.    end;
  168.  
  169.  
  170. begin {pulldown}
  171.    display_top;
  172.    pick_top;
  173.    window(1,1,80,25);
  174. end;
  175.  
  176.