home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / INTR_DMO.ZIP / PLS-DISP.INC < prev    next >
Encoding:
Text File  |  1985-10-01  |  9.6 KB  |  294 lines

  1. { CDS-DISP.PAS - Requires STD-CTV.PAS and CDS-UTIL.PAS }
  2.  
  3. procedure Disp_Prompt(prmt_no: Byte);
  4.     begin
  5.       vid_line[MSG_LINE] := prompt_ln[3 * prmt_no + 1];
  6.       vid_line[PROMPT_LINE] := prompt_ln[3 * prmt_no + 2];
  7.       vid_line[CMD_LINE] := prompt_ln[3 * prmt_no + 3];
  8.     end { Disp_Prompt };
  9.  
  10. procedure Disp_Help(help_line,
  11.                     line_no,
  12.                     line_cnt   : Byte;
  13.                     valid_keys : Any_Char);
  14.  
  15.     var xpos, ypos : Byte;
  16.         temp_buf   : Inp_Scrn;
  17.     begin
  18.       temp_buf := cur_scrn;
  19.       Move(help_ln[help_line],vid_line[line_no],(160 * line_cnt));
  20.       Disp_Prompt(HELP_PROMPT);
  21.       xpos := WhereX; ypos := WhereY;
  22.       if (valid_keys <> [ESC]) then
  23.         begin
  24.           Display_Prompt(PROMPT_LINE,'INP','Enter selection ' + ARROW);
  25.           GoToXY(27,PROMPT_LINE);
  26.         end
  27.       else
  28.         GoToXY(29,CMD_LINE);
  29.       repeat
  30.         Read_Kbd(inchr,inctl);
  31.       until (inctl in valid_keys);
  32.       cur_scrn := temp_buf;
  33.     end; { Disp_Help }
  34.  
  35.    procedure Display_Prompt; {  (line    : Byte;
  36.                                  prompt  : Str_10;
  37.                                  msg_str : Str_80); forward declared }
  38.     var hold_pos : Integer;
  39.  
  40.     begin { Display_Prompt }
  41.       GoTo_XY(2,line); hold_pos := cur_pos;
  42.       vid_attr := DIM_VID;
  43.       Write_Usr_Str((prompt + ': ')); vid_attr := BRIGHT_VID;
  44.       Write_Usr_Str(msg_str);
  45.       GoToXY(2 + cur_pos - hold_pos,line);
  46.     end; { Display_Prompt }
  47.  
  48.   procedure Disp_Error_Msg; { (err_msg: Str_80); }
  49.     var  inchr : Char;      { forward defined in STD-UTIL.PAS }
  50.  
  51.     begin
  52.       Disp_Prompt(HELP_PROMPT);
  53.       Display_Prompt(PROMPT_LINE,'ERR',err_msg);
  54.       Beep;
  55.       Read(Kbd,inchr);                  { Pause until key is pressed }
  56.     end; { Disp_Error_Msg }
  57.  
  58.   procedure Disp_IO_Error;   { (device_name: File_ID); }
  59.                              { forward defined in STD-UTIL.PAS }
  60.     var IO_Msg     : Str_80;
  61.         err_str    : string[3];
  62.         valid_keys : Printable_Char;
  63.  
  64.     begin
  65.       Str(io_status:3,err_str);
  66.       IO_Msg := ' error status = ' + err_str;
  67.       Disp_Prompt(ERROR_PROMPT);
  68.       IO_Msg := 'Device/File ' + device_name + IO_Msg;
  69.  
  70.       Display_Prompt(PROMPT_LINE,'MSG',IO_Msg);
  71.       Display_Prompt(MSG_LINE,'INP',
  72.                       'Press CMD: key to enter selection. (A/I) ==> ');
  73.       inchr := Valid_Key(['A','I']);
  74.       if (inchr = 'A') then
  75.         err_flag := TRUE
  76.       else
  77.         io_status := ZERO
  78.     end; { Disp_IO_Error }
  79.  
  80. procedure Load_Inp_Scrn(scrn_id: File_ID; var screen: Scrn_Image);
  81.  
  82.     begin
  83.       Assign(image_file,scrn_id);
  84.       {$I-} Reset(image_file); {$I+} io_status := IOresult;
  85.       if io_status = ZERO then
  86.         begin
  87.           Read(image_file,screen);
  88.           Close(image_file);
  89.         end;
  90.     end { Load_Inp_Scrn };
  91.  
  92.   procedure Disp_Inp_Scrn(scrn_no: Byte);
  93.     begin
  94.       if (scrn_no = ZERO) then
  95.         cur_scrn := buf_scrn
  96.       else
  97.         cur_scrn := vid_buf[scrn_no].buf_scrn;
  98.     end { Disp_Inp_Scrn };
  99.  
  100.     procedure Verify_Exit;
  101.       begin
  102.         vid_line[22] := prompt_ln[3];
  103.         Disp_Prompt(MSG_BOX_PROMPT);
  104.         Display_Prompt(PROMPT_LINE,'INP','Do you want to END this session? (Y/N) ==> ');
  105.         if (Valid_Key(['Y','N',ESC]) = 'Y') then
  106.           end_session := TRUE;
  107.       end; { Verify_Exit }
  108.  
  109.     procedure Verify_Cancel;
  110.       begin
  111.         Disp_Prompt(MSG_BOX_PROMPT);
  112.         Display_Prompt(PROMPT_LINE,'INP','Abandon changes? (Y/N) ' + ARROW);
  113.         if (Valid_Key(['Y','N']) = 'Y') then
  114.           begin
  115.             esc_flag := TRUE;
  116.             modified := FALSE;
  117.           end;
  118.       end; { Verify_Cancel }
  119.  
  120.   procedure Load_Screen(scrn_id: File_ID; var screen_buf: Inp_Scrn);
  121.     var screen_file : file of Inp_Scrn;
  122.  
  123.     begin
  124.       Assign(screen_file,scrn_id);
  125.       {$I-} Reset(screen_file); {$I+} io_status := IOresult;
  126.       if io_status = ZERO then
  127.         begin
  128.           Read(screen_file,screen_buf);
  129.           Close(screen_file);
  130.         end;
  131.     end; { Load_Screen }
  132.  
  133.   procedure Load_Fld_Msgs(file_name: File_ID);
  134.     var inp_text : Text;
  135.         msg_ptr  : Integer;
  136.     begin
  137.       Assign(inp_text,file_name);
  138.       Reset(inp_text); msg_ptr := 1;
  139.       while (not Eof(inp_text)) do
  140.         begin
  141.           ReadLn(inp_text,fld_msg[msg_ptr]);
  142.           msg_ptr := Succ(msg_ptr);
  143.         end;
  144.       Close(inp_text);
  145.     end; { Load_Fld_Msgs }
  146.  
  147.   procedure Load_Menu_Selections(menu_id: File_ID);
  148.     var  menu_file           : Text;
  149.          txt_row, txt_col    : Str_2;
  150.          sel_cnt, int_val    : Integer;
  151.          dummy               : Char;
  152.  
  153.     begin
  154.       Assign(menu_file,menu_id);
  155. {$I-}
  156.       Reset(menu_file); io_status := IOresult;
  157.       if (io_status = ZERO) then
  158.         begin
  159.           ReadLn(menu_file,sel_cnt); io_status := IOresult;
  160.         end;
  161. {$I+}
  162.       FillChar(menu_dat,SizeOf(menu_dat),ZERO);
  163.       if (io_status = ZERO) then
  164.         for i := 1 to sel_cnt do
  165.           with menu_dat[i] do
  166.           begin
  167.             Read(menu_file,txt_row,dummy);
  168.             Read(menu_file,txt_col,dummy);
  169.             ReadLn(menu_file,menu_txt);
  170.             Val(txt_col,int_val,io_status);  xloc := int_val;
  171.             Val(txt_row,int_val,io_status); yloc := int_val;
  172.           end;
  173.       if (io_status = ZERO) then
  174.         Close(menu_file)
  175.       else
  176.         Disp_IO_Error(menu_id);
  177.     end; { Load_Menu_Selections }
  178.  
  179.   procedure Display_Menu_Selection(pntr: Integer; select: Boolean);
  180.     begin
  181.       with menu_dat[pntr] do
  182.       begin
  183.         GoTo_XY(xloc,yloc); vid_attr := REVERSE_VID;
  184.         Write_Usr_Str(Copy(menu_txt,1,3)); vid_attr := BRIGHT_VID;
  185.         if select then vid_attr := REVERSE_VID;
  186.         Write_Usr_Str(Copy(menu_txt,4,40)); Write(Usr,SPACE);
  187.         vid_attr := BRIGHT_VID;
  188.       end;
  189.     end; { Display_Menu_Selection }
  190.  
  191.   procedure Disp_Menu(select_file : File_ID;
  192.                       menu_header : Str_40);
  193.     begin
  194.       cur_scrn := menu_buf;
  195.       Disp_Prompt(MENU_PROMPT); Rev_Video;
  196.       GoTo_XY(9,2); Write_Usr_Str(SPACE + sys_date + SPACE);
  197.       GoTo_XY(54 - (Length(menu_header) div 2),2);
  198.       Write_Usr_Str(menu_header); Norm_Video;
  199.       Load_Menu_Selections(select_file);
  200.       i := 1;
  201.       while (menu_dat[i].menu_txt <> NULL_STR) do
  202.         with menu_dat[i] do
  203.         begin
  204.           if menu_txt <> '*' then
  205.             if (i = 1) then
  206.               Display_Menu_Selection(i,TRUE)
  207.             else
  208.               Display_Menu_Selection(i,FALSE);
  209.           i := Succ(i);
  210.         end;
  211.     end; { Disp_Menu }
  212.  
  213.   function Valid_Menu_Selection(max: Byte): Integer;
  214.     const key_set    : Any_Char = ['0'..'9',BS,ESC,PREV_FLD,NEXT_FLD,
  215.                                     ALT_PREV,ALT_NEXT,ENTER,#94..#103];
  216.  
  217.     var   selection,
  218.           pointer    : Integer;
  219.           xpos, ypos : Byte;
  220.  
  221.     procedure Init_Inp_Fld;
  222.       begin
  223.         GoToXY(xpos,ypos); Write(FILL_CHAR,FILL_CHAR);
  224.         GoToXY(xpos,ypos); selection := ZERO; i := ZERO;
  225.       end; { Init_Inp_Fld }
  226.  
  227.     begin { Valid_Menu_Selection }
  228.       xpos := WhereX; ypos := WhereY;
  229.       inchr := NULL_CHR; pointer := 1;
  230.       Init_Inp_Fld; submenu := FALSE;
  231.       while (i < 3) and (inchr <> ENTER) do
  232.         begin
  233.           inchr := Valid_Key(key_set);
  234.           if (inchr in ['0'..'9']) then
  235.             begin
  236.               if (i = 0) then
  237.                 selection := selection + Ord(inchr) - 48
  238.               else
  239.                 selection := selection * 10 + Ord(inchr) - 48;
  240.               if (selection > max) then
  241.                 begin
  242.                   Beep;
  243.                   Init_Inp_Fld;
  244.                 end
  245.               else
  246.                 begin
  247.                   Write(inchr);
  248.                   i := Succ(i);
  249.                 end;
  250.             end
  251.           else
  252.             case inchr of
  253.               ENTER     : if (selection = ZERO) then
  254.                             selection := pointer;
  255.               BS        : if (i > ZERO) then
  256.                             begin
  257.                               i := Pred(i);
  258.                               Write(BS,SPACE,BS);
  259.                               selection := selection div 10;
  260.                             end
  261.                           else
  262.                             Beep;
  263.               ESC       : begin
  264.                             esc_flag := TRUE;
  265.                             inchr := ENTER;
  266.                             selection := ZERO;
  267.                           end;
  268.               ALT_PREV,
  269.               PREV_FLD  : begin
  270.                             Display_Menu_Selection(pointer,FALSE);
  271.                             if (pointer > 1) then
  272.                               pointer := Pred(pointer)
  273.                             else
  274.                               pointer := max;
  275.                             Display_Menu_Selection(pointer,TRUE);
  276.                             Init_Inp_Fld;
  277.                           end;
  278.               ALT_NEXT,
  279.               NEXT_FLD  : begin
  280.                             Display_Menu_Selection(pointer,FALSE);
  281.                             pointer := (pointer mod max) + 1;
  282.                             Display_Menu_Selection(pointer,TRUE);
  283.                             Init_Inp_Fld;
  284.                           end;
  285.               #94..#103 : begin
  286.                             selection := Ord(inchr) - 93;
  287.                             submenu := TRUE;
  288.                             inchr := ENTER;
  289.                           end;
  290.             end; {case}
  291.         end; {while}
  292.         Valid_Menu_Selection := selection;
  293.     end; { Valid_Menu_Selection }
  294.