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, by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /*
28 * mvwin.c
29 *
30 * XCurses Library
31 *
32 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
33 *
34 */
35
36 #ifdef M_RCSID
37 #ifndef lint
38 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/mvwin.c 1.3 1995/06/15 19:19:58 ant Exp $";
39 #endif
40 #endif
41
42 #include <private.h>
43
44 /*f
45 * Move window so that the upper left-hand corner is at (x,y). If the move
46 * would cause the window to be off the screen, it is an error and the
47 * window is not moved. Moving subwindows is allowed, but should be
48 * avoided.
49 */
50 int
mvwin(w,by,bx)51 mvwin(w, by, bx)
52 WINDOW *w;
53 int by, bx;
54 {
55 int i, dx, dy;
56 WINDOW *parent = w->_parent;
57
58 #ifdef M_CURSES_TRACE
59 __m_trace("mvwin(%p, %d, %d)", w, by, bx);
60 #endif
61
62 /* Check lower bounds of new window position. */
63 if (by < 0 || bx < 0)
64 return __m_return_code("mvwin", ERR);
65
66 if (parent == (WINDOW *) 0) {
67 /* Check upper bounds of normal window. */
68 if (lines < by + w->_maxy || columns < bx + w->_maxx)
69 return __m_return_code("mvwin", ERR);
70 } else {
71 /* Check upper bounds of sub-window. */
72 if (parent->_begy + parent->_maxy < by + w->_maxy
73 || parent->_begx + parent->_maxx < bx + w->_maxx)
74 return __m_return_code("mvwin", ERR);
75
76 /* Move the sub-window's line pointers to the parent
77 * window's data.
78 */
79 dy = by - parent->_begy;
80 dx = bx - parent->_begx;
81
82 for (i = 0; i <= w->_maxy; ++i)
83 w->_line[i] = &parent->_line[dy++][dx];
84 }
85
86 w->_begy = by;
87 w->_begx = bx;
88 (void) wtouchln(w, 0, w->_maxy, 1);
89
90 return __m_return_code("mvwin", OK);
91 }
92
93 int
mvderwin(w,py,px)94 mvderwin(w, py, px)
95 WINDOW *w;
96 int py, px;
97 {
98 int code;
99 WINDOW *parent;
100
101 #ifdef M_CURSES_TRACE
102 __m_trace("mvderwin(%p, %d, %d)", w, py, px);
103 #endif
104
105 parent = w->_parent;
106
107 if (parent == (WINDOW *) 0)
108 return __m_return_code("mvderwin", ERR);
109
110 /* Absolute screen address. */
111 py += parent->_begy;
112 px += parent->_begx;
113
114 code = mvwin(w, py, px);
115
116 return __m_return_code("mvderwin", code);
117 }
118