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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /* LINTLIBRARY */
30 
31 /*
32  * prefresh.c
33  *
34  * XCurses Library
35  *
36  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
37  *
38  */
39 
40 #ifdef M_RCSID
41 #ifndef lint
42 static char rcsID[] =
43 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44 "libxcurses/src/libc/xcurses/rcs/prefresh.c 1.4 1998/06/03 16:06:14 "
45 "cbates Exp $";
46 #endif
47 #endif
48 
49 #include <private.h>
50 
51 /*
52  * Update newscr with the given pad then display to the terminal.
53  */
54 int
55 prefresh(WINDOW *w, int pminr, int pminc, int sminr, int sminc,
56 	int smaxr, int smaxc)
57 {
58 	int	code;
59 
60 	code = pnoutrefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc);
61 	if (code == OK)
62 		code = doupdate();
63 
64 	return (code);
65 }
66 
67 /*
68  * Update newscr with the given pad.  This allows newscr to
69  * be updated with several windows before doing a doupdate().
70  *
71  * MKS extension permits windows that are not pads to be refreshed
72  * using this function.
73  */
74 int
75 pnoutrefresh(WINDOW *pad, int pminr, int pminc, int sminr, int sminc,
76 	int smaxr, int smaxc)
77 {
78 	WINDOW	*ns;
79 	int	row, dy, dx;
80 
81 	ns = __m_screen->_newscr;
82 
83 	/* Adjust regions to be within bounds. */
84 	if (pminr < 0)
85 		pminr = 0;
86 	if (pminc < 0)
87 		pminc = 0;
88 	if (sminr < 0)
89 		sminr = 0;
90 	if (sminc < 0)
91 		sminc = 0;
92 	if (ns->_maxy <= smaxr)
93 		smaxr = ns->_maxy-1;
94 	if (ns->_maxx <= smaxc)
95 		smaxc = ns->_maxx-1;
96 
97 	if (pad->_maxy <= pminr || pad->_maxx <= pminc ||
98 		smaxr < sminr || smaxc < sminc)
99 		return (ERR);
100 
101 	/* Clear displayed region. */
102 	for (row = sminr; row < smaxr; ++row) {
103 		(void) __m_cc_erase(ns, row, sminc, row, smaxc);
104 	}
105 
106 	/*
107 	 * Determine the proper maximums in case smaxr and smaxc mapped
108 	 * beyond the bottom and right-hand edges of the pad.
109 	 */
110 	if (pad->_maxx <= pminc + smaxc-sminc + 1)
111 		smaxc = sminc + pad->_maxx - 1 - pminc;
112 	if (pad->_maxy <= pminr + smaxr-sminr + 1)
113 		smaxr = sminr + pad->_maxy - 1 - pminr;
114 
115 	/* Remember refresh region (inclusive). */
116 	pad->_refy = (short) pminr;
117 	pad->_refx = (short) pminc;
118 	pad->_sminy = (short) sminr;
119 	pad->_sminx = (short) sminc;
120 	pad->_smaxy = (short) smaxr;
121 	pad->_smaxx = (short) smaxc;
122 
123 	(void) copywin(pad, ns, pminr, pminc, sminr, sminc, smaxr, smaxc, 0);
124 
125 	/* Last refreshed window controls W_LEAVE_CURSOR flag. */
126 	ns->_flags &= ~W_LEAVE_CURSOR;
127 	ns->_flags |= pad->_flags &
128 		(W_CLEAR_WINDOW | W_REDRAW_WINDOW | W_LEAVE_CURSOR);
129 	pad->_flags &= ~(W_CLEAR_WINDOW | W_REDRAW_WINDOW);
130 
131 	/* Figure out where to leave the cursor. */
132 	dy = pad->_cury - pminr + pad->_begy;
133 	dx = pad->_curx - pminc + pad->_begx;
134 
135 	ns->_cury = (dy < 0) ? 0 :
136 		((ns->_maxy <= dy) ? ns->_maxy - 1 : (short) dy);
137 	ns->_curx = (dx < 0) ? 0 :
138 		((ns->_maxx <= dx) ? ns->_maxx - 1 : (short) dx);
139 
140 	return (OK);
141 }
142