xref: /illumos-gate/usr/src/lib/libxcurses/src/libc/xcurses/wscrl.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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  * wscrl.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/wscrl.c 1.4 1995/07/26 17:43:20 ant Exp $";
39 #endif
40 #endif
41 
42 #include <private.h>
43 #include <string.h>
44 
45 /*f
46  * For positive n scroll the window up n lines (line i+n becomes i);
47  * otherwise scroll the window down n lines.
48  */
49 int
50 wscrl(w, n)
51 WINDOW *w;
52 int n;
53 {
54 	int y, x, width, start, finish, to;
55 
56 #ifdef M_CURSES_TRACE
57 	__m_trace("wscrl(%p, %d)", w, n);
58 #endif
59 
60 	if (n == 0)
61 		return __m_return_code("wscrl", OK);
62 
63 	/* Shuffle pointers in order to scroll.  The region
64 	 * from start to finish inclusive will be moved to
65 	 * either the top or bottom of _line[].
66 	 */
67 	if (0 < n) {
68 		start = w->_top;
69 		finish = w->_top + n - 1;
70 		to = w->_bottom;
71 	} else {
72 		start = w->_bottom + n;
73 		finish = w->_bottom - 1;
74 		to = w->_top;
75 	}
76 
77 	/* Blank out new lines. */
78 	if (__m_cc_erase(w, start, 0, finish, w->_maxx-1) == -1)
79 		return __m_return_code("wscrl", ERR);
80 
81 	/* Scroll lines by shuffling pointers. */
82 	(void) __m_ptr_move((void **) w->_line, w->_maxy, start, finish, to);
83 
84 	if ((w->_flags & W_FULL_WINDOW)
85 	&& w->_top == 0 && w->_bottom == w->_maxy)
86 		w->_scroll += n;
87 	else
88 		w->_scroll = 0;
89 
90 	(void) wtouchln(w, 0, w->_maxy, 1);
91 
92 	WSYNC(w);
93 
94 	return __m_return_code("wscrl", WFLUSH(w));
95 }
96