home *** CD-ROM | disk | FTP | other *** search
- /* ==(help/change.c)== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written JPK 26-Sep-88 */
- /* Modified Geo 12-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
-
- #include <stdio.h>
- #include <bench.h>
- #include "help.h"
-
- static PROTO (int movement, (struct help_hdr *, int *, int *, int *, int));
-
- void setup_w(hptr)
- struct help_hdr *hptr;
- {
- /*
- * Check row / col first
- */
- if (hptr->row < 1)
- hptr->row = 1;
- if (hptr->col < 1)
- hptr->col = 1;
-
- /* check window parameters for windowing system size */
- if (hptr->height > (w_nrows - hptr->row))
- {
- hptr->row = w_nrows - hptr->height;
- if (hptr->row < 1)
- hptr->row = 1;
- if (hptr->height > (w_nrows - hptr->row))
- hptr->height = w_nrows - hptr->row;
- }
- if (hptr->width > (w_ncols - hptr->col))
- {
- hptr->col = w_ncols - hptr->width;
- if (hptr->col < 1)
- hptr->col = 1;
- if (hptr->width > (w_ncols - hptr->col))
- hptr->width = w_ncols - hptr->col;
- }
- /* create the box according to the specifications of the header */
- create_w(hptr->row, hptr->col, hptr->height, hptr->width);
-
- if (hptr->box_style != 0xff)
- border_w(hptr->box_style, hptr->box_attr);
- }
-
-
-
-
- void resize_hw(hptr)
- struct help_hdr *hptr;
- {
- int ch = 0;
- int first_time;
- int hmin,hmax;
- int wmin,wmax;
- int old_height;
- int old_width;
- int x = 0, y = 0;
-
- old_height = hptr->height;
- old_width = hptr->width;
- first_time = 1;
-
- hmin = 4;
- hmax = w_nrows - hptr->row;
- wmin = 10;
- wmax = w_ncols - hptr->col + 1;
-
- #ifdef MOUSE
- /*
- draw the help line and initialize the mouse cursor to the top left
- of the help window.
- */
- mouse_level++;
- mouse_set_position(hptr->col + hptr->width -1, hptr->row + hptr->height -1);
- #endif
-
- keys_w(K_UP, "," , K_DOWN , ",", K_LEFT, "," , K_RIGHT, res_prompt,
- K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- flushscr(); /* need to flush as inchar might not get called */
-
- while (ch != K_ESC)
- {
- if (!movement(hptr, &ch, &x, &y, 0)) /* determine mouse/keybrd movement */
- return;
-
- hptr->width += x;
- hptr->height += y;
-
- if (hptr->height < hmin)
- {
- y = 0;
- hptr->height = hmin;
- }
- if (hptr->height > hmax)
- {
- y = 0;
- hptr->height = hmax;
- }
- if (hptr->width < wmin)
- {
- x = 0;
- hptr->width = wmin;
- }
- if (hptr->width > wmax)
- {
- x = 0;
- hptr->width = wmax;
- }
-
- /*
- * redisplay the window (if changes occurred)
- */
- first_time = 0;
- if (x || y)
- {
- delete_w(); /* remove the old window */
- setup_w(hptr); /* get a new window */
- keys_w(K_UP, "," , K_DOWN , ",", K_LEFT, "," , K_RIGHT, res_prompt,
- K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- display(h_part.pos, hptr); /* display contents of the window */
- flushscr(); /* force out changes */
- }
- }
-
- /*
- * aborted.. restore old values
- */
- if (!first_time)
- {
- hptr->height = old_height;
- hptr->width = old_width;
- delete_w();
- setup_w(hptr);
- display(h_part.pos, hptr);
- }
- #ifdef MOUSE
- mouse_delete_level(mouse_level--);
- #endif
- }
-
-
-
-
- void move_w(hptr)
- struct help_hdr * hptr;
- {
- int ch = 0;
- int rmax, cmax;
- int old_row;
- int old_col;
- int x = 0,y = 0;
- int tempr,tempc;
-
- rmax = w_nrows - hptr->height;
- cmax = w_ncols - hptr->width + 1;
-
- old_row = hptr->row;
- old_col = hptr->col;
-
- /*
- draw the help line and initialize the mouse cursor to the top left
- of the help window.
- */
- #ifdef MOUSE
- mouse_level++;
- mouse_set_position(hptr->col , hptr->row);
- #endif
-
- keys_w(K_UP, ",", K_DOWN, ",", K_LEFT, "," ,K_RIGHT, move_prompt,
- K_CR, accept_prompt, K_ESC , exit_prompt, 0);
- flushscr();
-
- /*
- move the window around on the screen using the arrow keys,
- (or mouse... RN Oct, 1989)
- */
- while (ch != K_ESC)
- {
- if (!movement(hptr, &ch, &x, &y, 1))
- return;
-
- /*
- * Test if we have overshot the max coordinates and compensate if needed.
- */
- tempr = hptr->row + y;
- tempc = hptr->col + x;
-
- if (tempc > cmax)
- x-= (tempc - cmax);
- if (tempr > rmax)
- y-= (tempr - rmax);
-
- /*
- * set the new coordinates
- */
- hptr->row += y;
- hptr->col += x;
-
- /*
- * if there was a change in position then move the window
- */
- if (x || y)
- {
- mv_w(y, x); /* move the window */
- flushscr(); /* force out changes */
- x = y = 0;
- }
- }
-
- /*
- * aborted.. reset to original position
- */
- mv_w(old_row - hptr->row,old_col - hptr->col);
- hptr->row = old_row;
- hptr->col = old_col;
- display(h_part.pos, hptr);
-
- #ifdef MOUSE
- mouse_delete_level(mouse_level--); /* remove mouse objects */
- #endif
-
- }
-
-
- static int movement(hptr, ch, x, y, type)
- struct help_hdr *hptr;
- int *ch, *x, *y;
- int type; /* 0 = resize 1 = move */
- {
- #ifdef MOUSE
- if (mouse_present)
- {
- /*
- * if keyboard input we must adjust the mouse cursor to the new position.
- */
- if (*ch && type == 0)
- mouse_set_position(hptr->col + hptr->width -1,
- hptr->row + hptr->height -1); /* bottom right of box */
-
- if (*ch && type == 1)
- mouse_set_position(hptr->col , hptr->row); /* top left of box */
-
- /*
- * move window with the mouse (if present)
- */
- if (!(*ch = inchar_nowait())) /* check if keyboard pressed */
- if (!mouse_hit()) /* check if mouse button down */
- {
- *ch = 0; /* keyboard not pressed */
- if (!type)
- {
- *x = mouse_col - hptr->col - hptr->width + 1; /* hor movement */
- *y = mouse_row - hptr->row - hptr->height + 1;/* ver movement */
- }
- else
- {
- *x = mouse_col - hptr->col; /* horizontal movement */
- *y = mouse_row - hptr->row; /* vertical movement */
- }
- }
- else
- *ch = mouse_waitkey(); /* mouse is down so wait for release */
- }
- else
- {
- *ch = inchar();
- if (type == 0)
- *x = *y = 0;
- }
- #else
- *ch = inchar();
- if (type == 0)
- *x = *y = 0;
- #endif
-
- switch (*ch)
- {
- case K_UP:
- if (type == 0 || (hptr->row > 1 && type == 1))
- (*y)--;
- break;
- case K_DOWN:
- (*y)++;
- break;
- case K_LEFT:
- if (type == 0 || (hptr->col > 1 && type == 1))
- (*x)--;
- break;
- case K_RIGHT:
- (*x)++;
- break;
- case K_CR:
- case M_RELEASE:
- #ifdef MOUSE
- mouse_delete_level(mouse_level--);
- #endif
- return(0);
- default:
- break;
- }
- return(1);
- }
-