xref: /original-bsd/lib/libcurses/mvwin.c (revision 730930d2)
1 /*
2  * Copyright (c) 1981, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)mvwin.c	8.2 (Berkeley) 05/04/94";
10 #endif	/* not lint */
11 
12 #include "curses.h"
13 
14 /*
15  * mvwin --
16  *	Relocate the starting position of a window.
17  */
18 int
19 mvwin(win, by, bx)
20 	register WINDOW *win;
21 	register int by, bx;
22 {
23 	register WINDOW *orig;
24 	register int dy, dx;
25 
26 	if (by + win->maxy > LINES || bx + win->maxx > COLS)
27 		return (ERR);
28 	dy = by - win->begy;
29 	dx = bx - win->begx;
30 	orig = win->orig;
31 	if (orig == NULL) {
32 		orig = win;
33 		do {
34 			win->begy += dy;
35 			win->begx += dx;
36 			__swflags(win);
37 			win = win->nextp;
38 		} while (win != orig);
39 	} else {
40 		if (by < orig->begy || win->maxy + dy > orig->maxy)
41 			return (ERR);
42 		if (bx < orig->begx || win->maxx + dx > orig->maxx)
43 			return (ERR);
44 		win->begy = by;
45 		win->begx = bx;
46 		__swflags(win);
47 		__set_subwin(orig, win);
48 	}
49 	__touchwin(win);
50 	return (OK);
51 }
52