xref: /titanic_50/usr/src/ucblib/libcurses/mvwin.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*LINTLIBRARY*/
18 
19 #ifndef lint
20 static char
21 sccsid[] = "@(#)mvwin.c 1.6 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
22 #endif	/* not lint */
23 
24 #include	"curses.ext"
25 
26 /*
27  * relocate the starting position of a window
28  */
29 
30 int
31 mvwin(WINDOW *win, int by, int bx)
32 {
33 	WINDOW	*orig;
34 	int	dy, dx;
35 
36 	if (by + win->_maxy > LINES || bx + win->_maxx > COLS)
37 		return (ERR);
38 	dy = by - win->_begy;
39 	dx = bx - win->_begx;
40 	orig = win->_orig;
41 	if (orig == NULL) {
42 		orig = win;
43 		do {
44 			win->_begy += dy;
45 			win->_begx += dx;
46 			_swflags_(win);
47 			win = win->_nextp;
48 		} while (win != orig);
49 	} else {
50 		if (by < orig->_begy || win->_maxy + dy > orig->_maxy)
51 			return (ERR);
52 		if (bx < orig->_begx || win->_maxx + dx > orig->_maxx)
53 			return (ERR);
54 		win->_begy = (short)by;
55 		win->_begx = (short)bx;
56 		_swflags_(win);
57 		_set_subwin_(orig, win);
58 	}
59 	(void) touchwin(win);
60 	return (OK);
61 }
62