home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / HELP / CHANGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-23  |  6.8 KB  |  313 lines

  1. /* ==(help/change.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. #include <stdio.h>
  15. #include <bench.h>
  16. #include "help.h"
  17.  
  18. static PROTO (int movement, (struct help_hdr *, int *, int *, int *, int));
  19.  
  20. void setup_w(hptr)
  21. struct    help_hdr *hptr;
  22. {
  23.     /*
  24.     * Check row / col first
  25.     */
  26.     if (hptr->row < 1)
  27.         hptr->row = 1;
  28.     if (hptr->col < 1)
  29.         hptr->col = 1;
  30.  
  31.     /* check window parameters for windowing system size */
  32.     if (hptr->height > (w_nrows - hptr->row))
  33.     {
  34.         hptr->row = w_nrows - hptr->height;
  35.         if (hptr->row < 1)
  36.             hptr->row = 1;
  37.         if (hptr->height > (w_nrows - hptr->row))
  38.             hptr->height = w_nrows - hptr->row;
  39.     }
  40.     if (hptr->width > (w_ncols - hptr->col))
  41.     {
  42.         hptr->col = w_ncols - hptr->width;
  43.         if (hptr->col < 1)
  44.             hptr->col = 1;
  45.         if (hptr->width > (w_ncols - hptr->col))
  46.             hptr->width = w_ncols - hptr->col;
  47.     }
  48.     /* create the box according to the specifications of the header */
  49.     create_w(hptr->row, hptr->col, hptr->height, hptr->width);
  50.  
  51.     if (hptr->box_style  !=  0xff)
  52.         border_w(hptr->box_style, hptr->box_attr);
  53. }
  54.  
  55.  
  56.  
  57.  
  58. void resize_hw(hptr)
  59. struct help_hdr *hptr;
  60. {
  61.     int        ch = 0;
  62.     int        first_time;
  63.     int        hmin,hmax;
  64.     int        wmin,wmax;
  65.     int        old_height;
  66.     int        old_width;
  67.     int      x = 0, y = 0;
  68.  
  69.     old_height = hptr->height;
  70.     old_width  = hptr->width;
  71.     first_time = 1;
  72.  
  73.     hmin = 4;
  74.     hmax = w_nrows - hptr->row;
  75.     wmin = 10;
  76.     wmax = w_ncols - hptr->col + 1;
  77.  
  78. #ifdef MOUSE
  79.     /*
  80.         draw the help line and initialize the mouse cursor to the top left
  81.         of the help window.
  82.     */
  83.     mouse_level++;
  84.     mouse_set_position(hptr->col + hptr->width -1, hptr->row + hptr->height -1);
  85. #endif
  86.  
  87.     keys_w(K_UP, "," , K_DOWN , ",", K_LEFT, "," , K_RIGHT, res_prompt, 
  88.         K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  89.     flushscr(); /* need to flush as inchar might not get called */
  90.  
  91.     while (ch != K_ESC)
  92.     {
  93.         if (!movement(hptr, &ch, &x, &y, 0)) /* determine mouse/keybrd movement */
  94.             return;
  95.  
  96.         hptr->width += x;
  97.         hptr->height += y;
  98.  
  99.         if (hptr->height < hmin)
  100.         {
  101.             y = 0;
  102.             hptr->height = hmin;
  103.         }
  104.         if (hptr->height  >  hmax)
  105.         {
  106.             y = 0;
  107.             hptr->height = hmax;
  108.         }
  109.         if (hptr->width  <  wmin)
  110.         {
  111.             x = 0;
  112.             hptr->width = wmin;
  113.         }
  114.         if (hptr->width  >  wmax)
  115.         {
  116.             x = 0;
  117.             hptr->width = wmax;
  118.         }
  119.  
  120.         /* 
  121.         * redisplay the window (if changes occurred)
  122.         */
  123.         first_time = 0;
  124.         if (x || y)
  125.         {
  126.             delete_w();          /* remove the old window                   */
  127.             setup_w(hptr);       /* get a new window                        */
  128.             keys_w(K_UP, "," , K_DOWN , ",", K_LEFT, "," , K_RIGHT, res_prompt, 
  129.                 K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  130.             display(h_part.pos, hptr);    /* display contents of the window */
  131.             flushscr();                   /* force out changes              */
  132.         }
  133.     }
  134.  
  135.     /*
  136.     * aborted..   restore old values
  137.     */
  138.     if (!first_time)
  139.     {
  140.         hptr->height = old_height;
  141.         hptr->width  = old_width;
  142.         delete_w();
  143.         setup_w(hptr);
  144.         display(h_part.pos, hptr);
  145.     }
  146. #ifdef MOUSE
  147.     mouse_delete_level(mouse_level--);
  148. #endif
  149. }
  150.  
  151.  
  152.  
  153.  
  154. void move_w(hptr)
  155. struct help_hdr * hptr;
  156. {
  157.     int        ch = 0;
  158.     int        rmax, cmax;
  159.     int        old_row;
  160.     int        old_col;
  161.     int      x = 0,y = 0;
  162.     int      tempr,tempc;
  163.  
  164.     rmax = w_nrows - hptr->height;
  165.     cmax = w_ncols - hptr->width + 1;
  166.  
  167.     old_row = hptr->row;
  168.     old_col = hptr->col;
  169.  
  170.     /*
  171.         draw the help line and initialize the mouse cursor to the top left
  172.         of the help window.
  173.     */
  174. #ifdef MOUSE
  175.     mouse_level++;
  176.     mouse_set_position(hptr->col , hptr->row); 
  177. #endif
  178.  
  179.     keys_w(K_UP, ",", K_DOWN, ",", K_LEFT, "," ,K_RIGHT, move_prompt,
  180.         K_CR, accept_prompt, K_ESC , exit_prompt, 0);
  181.     flushscr();
  182.  
  183.     /* 
  184.         move the window around on the screen using the arrow keys,
  185.        (or mouse... RN Oct, 1989)
  186.     */
  187.     while (ch !=  K_ESC)
  188.     {
  189.         if (!movement(hptr, &ch, &x, &y, 1))
  190.             return;
  191.  
  192.         /*
  193.         * Test if we have overshot the max coordinates and compensate if needed.
  194.         */
  195.         tempr = hptr->row + y;
  196.         tempc = hptr->col + x;
  197.  
  198.         if (tempc > cmax)
  199.             x-= (tempc - cmax);
  200.         if (tempr > rmax)
  201.             y-= (tempr - rmax);
  202.  
  203.         /*
  204.         * set the new coordinates
  205.         */
  206.         hptr->row += y;
  207.         hptr->col += x;
  208.  
  209.         /*
  210.         * if there was a change in position then move the window
  211.         */
  212.         if (x || y)
  213.         {
  214.             mv_w(y, x);        /* move the window                             */
  215.             flushscr();          /* force out changes                           */ 
  216.             x = y = 0;
  217.         }
  218.     }
  219.  
  220.     /*
  221.     * aborted..   reset to original position
  222.     */
  223.     mv_w(old_row - hptr->row,old_col - hptr->col);
  224.     hptr->row = old_row;
  225.     hptr->col = old_col;
  226.     display(h_part.pos, hptr);
  227.  
  228. #ifdef MOUSE
  229.     mouse_delete_level(mouse_level--); /* remove mouse objects */
  230. #endif
  231.  
  232. }
  233.  
  234.  
  235. static int movement(hptr, ch, x, y, type)
  236. struct help_hdr *hptr;
  237. int *ch, *x, *y;
  238. int type;         /* 0 = resize  1 = move */
  239. {
  240. #ifdef MOUSE
  241.     if (mouse_present)
  242.     {
  243.         /*
  244.         * if keyboard input we must adjust the mouse cursor to the new position.
  245.         */
  246.         if (*ch && type == 0)
  247.             mouse_set_position(hptr->col + hptr->width -1, 
  248.                 hptr->row + hptr->height -1);            /* bottom right of box */
  249.     
  250.         if (*ch && type == 1)
  251.             mouse_set_position(hptr->col , hptr->row);  /* top left of box     */
  252.  
  253.         /* 
  254.         * move window with the mouse (if present)
  255.         */
  256.         if (!(*ch = inchar_nowait()))            /* check if keyboard pressed  */
  257.             if (!mouse_hit())                     /* check if mouse button down */
  258.             {
  259.                 *ch = 0;                           /* keyboard not pressed       */
  260.                 if (!type)
  261.                 {
  262.                     *x = mouse_col - hptr->col - hptr->width + 1; /* hor movement */
  263.                    *y = mouse_row - hptr->row - hptr->height + 1;/* ver movement */
  264.                 }
  265.                 else
  266.                 {
  267.                     *x = mouse_col - hptr->col;            /* horizontal movement */
  268.                    *y = mouse_row - hptr->row;            /* vertical movement   */
  269.                 }
  270.             }
  271.             else
  272.                 *ch = mouse_waitkey();      /* mouse is down so wait for release */
  273.     }
  274.     else
  275.     {
  276.         *ch = inchar();
  277.         if (type == 0)
  278.             *x = *y = 0; 
  279.     }
  280. #else
  281.     *ch = inchar();
  282.     if (type == 0)
  283.         *x = *y = 0; 
  284. #endif
  285.  
  286.     switch (*ch)
  287.     {
  288.     case K_UP:
  289.         if (type == 0 || (hptr->row > 1 && type == 1))
  290.             (*y)--;
  291.         break;
  292.     case K_DOWN:
  293.         (*y)++;
  294.         break;
  295.     case K_LEFT:
  296.         if (type == 0 || (hptr->col > 1 && type == 1))
  297.             (*x)--;
  298.         break;
  299.     case K_RIGHT:
  300.         (*x)++;
  301.         break;
  302.     case K_CR:
  303.     case M_RELEASE:
  304. #ifdef MOUSE
  305.         mouse_delete_level(mouse_level--);
  306. #endif
  307.         return(0);
  308.     default:
  309.         break;
  310.     }
  311.     return(1);
  312. }
  313.