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