xref: /illumos-gate/usr/src/lib/libxcurses/src/libc/xcurses/prefresh.c (revision 3ce5372277f4657ad0e52d36c979527c4ca22de2)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * prefresh.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/prefresh.c 1.3 1995/06/20 14:34:10 ant Exp $";
41 #endif
42 #endif
43 
44 #include <private.h>
45 
46 /*f
47  * Update newscr with the given pad then display to the terminal.
48  */
49 int
50 prefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc)
51 WINDOW *w;
52 int pminr, pminc, sminr, sminc, smaxr, smaxc;
53 {
54 	int code;
55 
56 #ifdef M_CURSES_TRACE
57 	__m_trace(
58 		"prefresh(%p, %d, %d, %d, %d, %d, %d)",
59 		w, pminr, pminc, sminr, sminc, smaxr, smaxc
60 	);
61 #endif
62 
63 	code = pnoutrefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc);
64 	if (code == OK)
65 		code = doupdate();
66 
67 	return __m_return_code("prefresh", code);
68 }
69 
70 /*f
71  * Update newscr with the given pad.  This allows newscr to
72  * be updated with several windows before doing a doupdate().
73  *
74  * MKS extension permits windows that are not pads to be refreshed
75  * using this function.
76  */
77 int
78 pnoutrefresh(pad, pminr, pminc, sminr, sminc, smaxr, smaxc)
79 WINDOW *pad;
80 int pminr, pminc, sminr, sminc, smaxr, smaxc;
81 {
82 	WINDOW *ns;
83 	int row, dy, dx;
84 
85 #ifdef M_CURSES_TRACE
86 	__m_trace(
87 		"pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)",
88 		pad, pminr, pminc, sminr, sminc, smaxr, smaxc
89 	);
90 #endif
91 
92 	ns = __m_screen->_newscr;
93 
94 	/* Adjust regions to be within bounds. */
95 	if (pminr < 0)
96 		pminr = 0;
97 	if (pminc < 0)
98 		pminc = 0;
99 	if (sminr < 0)
100 		sminr = 0;
101 	if (sminc < 0)
102 		sminc = 0;
103 	if (ns->_maxy <= smaxr)
104 		smaxr = ns->_maxy-1;
105 	if (ns->_maxx <= smaxc)
106 		smaxr = ns->_maxx-1;
107 
108 	if (pad->_maxy <= pminr || pad->_maxx <= pminc
109 	|| smaxr < sminr || smaxc < sminc)
110 		return __m_return_code("pnoutrefresh", ERR);
111 
112 	/* Clear displayed region. */
113 	for (row = sminr; row <= smaxr; ++row)
114 		(void) __m_cc_erase(ns, row, sminc, row, smaxc);
115 
116 	/* Determine the proper maximums in case smaxr and smaxc mapped
117 	 * beyond the bottom and right-hand edges of the pad.
118 	 */
119 	if (pad->_maxx <= pminc + smaxc-sminc+1)
120 		smaxc = sminc + pad->_maxx - 1 - pminc;
121 	if (pad->_maxy <= pminr + smaxr-sminr+1)
122 		smaxr = sminr + pad->_maxy - 1 - pminr;
123 
124 	/* Remember refresh region (inclusive). */
125 	pad->_refy = (short) pminr;
126 	pad->_refx = (short) pminc;
127 	pad->_sminy = (short) sminr;
128 	pad->_sminx = (short) sminc;
129 	pad->_smaxy = (short) smaxr;
130 	pad->_smaxx = (short) smaxc;
131 
132 	(void) copywin(pad, ns, pminr, pminc, sminr, sminc, smaxr, smaxc, 0);
133 
134 	/* Last refreshed window controls W_LEAVE_CURSOR flag. */
135 	ns->_flags &= ~W_LEAVE_CURSOR;
136 	ns->_flags |= pad->_flags
137 		& (W_CLEAR_WINDOW | W_REDRAW_WINDOW | W_LEAVE_CURSOR);
138 	pad->_flags &= ~(W_CLEAR_WINDOW | W_REDRAW_WINDOW);
139 
140 	/* Figure out where to leave the cursor. */
141 	dy = pad->_cury - pminr + pad->_begy;
142 	dx = pad->_curx - pminc + pad->_begx;
143 
144 	ns->_cury = dy < 0 ? 0 : ns->_maxy <= dy ? ns->_maxy-1 : dy;
145 	ns->_curx = dx < 0 ? 0 : ns->_maxx <= dx ? ns->_maxx-1 : dx;
146 
147 	return __m_return_code("pnoutrefresh", OK);
148 }
149