1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /* LINTLIBRARY */
28 
29 /*
30  * mvwin.c
31  *
32  * XCurses Library
33  *
34  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
35  *
36  */
37 
38 #ifdef M_RCSID
39 #ifndef lint
40 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/mvwin.c 1.3 "
41 "1995/06/15 19:19:58 ant Exp $";
42 #endif
43 #endif
44 
45 #include <private.h>
46 
47 /*
48  * Move window so that the upper left-hand corner is at (x,y). If the move
49  * would cause the window to be off the screen, it is an error and the
50  * window is not moved.  Moving subwindows is allowed, but should be
51  * avoided.
52  */
53 int
mvwin(WINDOW * w,int by,int bx)54 mvwin(WINDOW *w, int by, int bx)
55 {
56 	int	i, dx, dy;
57 	WINDOW	*parent = w->_parent;
58 
59 	/* Check lower bounds of new window position. */
60 	if (by < 0 || bx < 0)
61 		return (ERR);
62 
63 	if (parent == NULL) {
64 		/* Check upper bounds of normal window. */
65 		if (lines < by + w->_maxy || columns < bx + w->_maxx)
66 			return (ERR);
67 	} else {
68 		/* Check upper bounds of sub-window. */
69 		if (parent->_begy + parent->_maxy < by + w->_maxy ||
70 			parent->_begx + parent->_maxx < bx + w->_maxx)
71 			return (ERR);
72 
73 		/*
74 		 * Move the sub-window's line pointers to the parent
75 		 * window's data.
76 		 */
77 		dy = by - parent->_begy;
78 		dx = bx - parent->_begx;
79 
80 		for (i = 0; i <= w->_maxy; ++i)
81 			w->_line[i] = &parent->_line[dy++][dx];
82 	}
83 
84 	w->_begy = (short) by;
85 	w->_begx = (short) bx;
86 	(void) wtouchln(w, 0, w->_maxy, 1);
87 
88 	return (OK);
89 }
90 
91 int
mvderwin(WINDOW * w,int py,int px)92 mvderwin(WINDOW *w, int py, int px)
93 {
94 	int	code;
95 	WINDOW	*parent;
96 
97 	parent = w->_parent;
98 
99 	if (parent == NULL)
100 		return (ERR);
101 
102 	/* Absolute screen address. */
103 	py += parent->_begy;
104 	px += parent->_begx;
105 
106 	code = mvwin(w, py, px);
107 
108 	return (code);
109 }
110