home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / HELP / DISPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  5.1 KB  |  252 lines

  1. /* ==( help/display.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   JPK  26-Sep-88                        */
  9. /* Modified  Geo  12-Dec-89  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *  12-Dec-89  Geo - V2 version with variable lines
  17.  *  25-Oct-89  Geo - 1.32 Merge
  18.  *
  19.  *
  20. */
  21.  
  22. /* 
  23.  * Routines in this file:
  24.  *
  25.  * int getline(char *, int, int)
  26.  *    gets the next line of help from the help text file
  27.  *
  28.  * static void tbdisp_w(int, int, int, int, int, char *, int)
  29.  *    displays the line in the window
  30.  *
  31.  * void display(int, struct help_hdr)
  32.  *     uses getline and tbdisp_w to display a window full of help
  33.  *
  34.  * void display_help(struct help_hdr)
  35.  *     gets input for help and controls the display of help
  36.  *
  37.  */
  38.  
  39. # include <stdio.h>
  40. # include <bench.h>
  41. # include "help.h"
  42.  
  43. # ifdef ANSI
  44. static int getline(char *, int, int);
  45. static void tbdisp_w(int, int, int, int, int, char *, int);
  46. # else
  47. static int getline();
  48. static void tbdisp_w();
  49. # endif
  50.  
  51. static int right;
  52. static int end_reached = 0;
  53. static char eoh[] = "*** End of Help ***";
  54.  
  55. static int getline(line, lmax, num)
  56.     char    * line;
  57.     int    lmax;
  58.     int num;
  59. {
  60.     if (read_help_index(num) == TRUE)
  61.     {
  62.         if (read_help(line, (h_tdx.size>lmax ?lmax :h_tdx.size), &h_tdx)
  63.             != FALSE)
  64.         {
  65.             return(TRUE);
  66.         }
  67.     }
  68.     return(-1);
  69. }
  70.  
  71. static void    tbdisp_w(row, col, attr, battr, n, buf, tab)
  72.     int        row, col;
  73.     int        attr;
  74.     int        battr;
  75.     int        n;
  76.     char    * buf;
  77.     int        tab;
  78. {
  79.     int i, k;
  80.     int a = 0;
  81.  
  82.     for (i = 0; i < n; i++)
  83.     {
  84.         if (*buf == '\0')
  85.             break;
  86.  
  87.         if (*buf == '^')
  88.             a = 1 - a;
  89.         else if (*buf == '\t')
  90.         {
  91.             for (k = (i % tab); k < tab && i < n; k++, i++)
  92.                 poke_w(row, col++, a ? battr : attr, ' ');
  93.             i--;
  94.         }
  95.         else
  96.             poke_w(row, col++, a ? battr : attr, *buf);
  97.         buf++;
  98.     }
  99.     if (i  <  n)
  100.         rephoriz_w(row, col, a ? battr : attr, n - i, ' ');
  101. }
  102.  
  103.  
  104. void display(first, hptr)
  105.     int first;
  106.     struct    help_hdr * hptr;
  107. {
  108.     char    *line;
  109.     int    i, j;
  110.     int    col;
  111.  
  112.     line = (char *)alloc(w_ncols);
  113.  
  114.     for (i=2; i < hptr->height; i++)
  115.     {
  116.         j = 0;
  117.         col = 2;
  118.         if (getline(line, w_ncols, first) != -1)
  119.         {
  120.             while (j < right && line[j] != '\0')
  121.                 j++;
  122.             line[hptr->width-2+j] = '\0';
  123.         }
  124.         else
  125.             line[0] = '\0';
  126.  
  127.         tbdisp_w(i, col, hptr->disp_attr, hptr->box_attr, hptr->width-2,
  128.             line+j, hptr->tabs);
  129.         first++;
  130.     }
  131.     if (end_reached)
  132.     {
  133.         /* put out a end of help message */
  134.         tbdisp_w(hptr->height-1, 2, hptr->disp_attr, hptr->box_attr,
  135.             hptr->width-2, eoh, hptr->tabs);
  136.         end_reached = 0;
  137.     }
  138.     free(line);
  139. }
  140.  
  141. void display_help(hptr)
  142.     struct help_hdr *hptr;
  143. {
  144.     int    ch;
  145.     int    last_col;
  146.     int    page;
  147.     int    max_first;
  148.  
  149.     /* set buffer display parameters */
  150.     last_col  = w_ncols - hptr->width;
  151.     page = hptr->height - 2;
  152.     max_first = (h_part.len > page  ?  h_part.len-page+1 : 1);
  153.  
  154.     /* initialize the help window */
  155.     setup_w(hptr);
  156.     h_part.pos = 1;
  157.     right = 0;
  158.  
  159. # ifdef MOUSE
  160.     mouse_level++;
  161. # endif
  162.  
  163.     /* display a user prompt line */
  164.     keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
  165.  
  166.     /* display the buffer and allow user to scroll thru it */
  167.     display(h_part.pos, hptr);
  168.     while ((ch = inchar())  !=  K_ESC)
  169.     {
  170.         switch(ch)
  171.         {
  172. # ifdef MOUSE
  173.         case M_PRESS:
  174.         case M_RELEASE:
  175.             { /* Start forced local block */
  176.             int dummy;
  177.  
  178.                 mouse_click( &dummy , ch ); 
  179.  
  180.             } /* End forced local block */
  181.             break;
  182. # endif
  183.         case K_UP:
  184.             h_part.pos--;
  185.             h_part.pos = (h_part.pos < 1 ? 1 : h_part.pos);
  186.             break;
  187.  
  188.         case K_CR:
  189.         case K_DOWN:
  190.             h_part.pos++;
  191.             h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
  192.             break;
  193.  
  194.         case K_PGUP:
  195.             h_part.pos -= (page - 1);
  196.             if(h_part.pos  <  1)
  197.                 h_part.pos = 1;
  198.             break;
  199.  
  200.         case K_PGDN:
  201.             h_part.pos += (page - 1);
  202.             h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
  203.             break;
  204.  
  205.         case K_LEFT:
  206.             if(right  >  0)
  207.                 right--;
  208.             break;
  209.  
  210.         case K_RIGHT:
  211.             if(right  <  last_col)
  212.                 right++;
  213.             break;
  214.  
  215.         case K_HOME:
  216.             h_part.pos = 1;
  217.             right = 0;
  218.             break;
  219.  
  220.         case K_END:
  221.             h_part.pos = max_first;
  222.             right = 0;
  223.             break;
  224.  
  225.         case K_F2:
  226.             popup_menu(hptr);
  227.             /* Due to resizing and moving */
  228.             keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
  229.             last_col  = w_ncols - hptr->width;
  230.             page = hptr->height - 2;
  231.             if (h_part.len  >  page)
  232.                 max_first = h_part.len - page + 1;
  233.             else
  234.                 max_first = 1;
  235.             border_w(hptr->box_style, hptr->box_attr);
  236.             break;
  237.  
  238.         default:
  239.             continue;
  240.         }
  241.         if (h_part.pos  ==  max_first)
  242.             end_reached = 1;
  243.         display(h_part.pos, hptr);
  244.     }
  245.     /* delete help window */
  246.     delete_w();
  247.  
  248. # ifdef MOUSE
  249.     mouse_delete_level( mouse_level-- );
  250. # endif
  251. }
  252.