xref: /titanic_50/usr/src/lib/libcurses/screen/prefresh.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
45*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
46*7c478bd9Sstevel@tonic-gate #include	"curses_inc.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Pad refresh. These routines are provided for upward compatibility
50*7c478bd9Sstevel@tonic-gate  * with the 'pad' structure of Sys V.2. Since windows now can be of
51*7c478bd9Sstevel@tonic-gate  * arbitrary size and derived windows can be moved within their
52*7c478bd9Sstevel@tonic-gate  * parent windows effortlessly, a separate notion of 'pad' as
53*7c478bd9Sstevel@tonic-gate  * a larger-than-screen window is no longer necessary.
54*7c478bd9Sstevel@tonic-gate  *
55*7c478bd9Sstevel@tonic-gate  * pminy, pminx: the area (pminy, pminx, maxy, maxx) of pad is refreshed
56*7c478bd9Sstevel@tonic-gate  * sminy, sminx, smaxy, smaxx: the screen area to be affected.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate int
prefresh(WINDOW * pad,int pminy,int pminx,int sminy,int sminx,int smaxy,int smaxx)60*7c478bd9Sstevel@tonic-gate prefresh(WINDOW *pad, int pminy, int pminx, int sminy,
61*7c478bd9Sstevel@tonic-gate 	int sminx, int smaxy, int smaxx)
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate 	return (_prefresh(wrefresh, pad, pminy, pminx, sminy,
64*7c478bd9Sstevel@tonic-gate 	    sminx, smaxy, smaxx));
65*7c478bd9Sstevel@tonic-gate }
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate int
_prefresh(int (* func)(WINDOW *),WINDOW * pad,int pminy,int pminx,int sminy,int sminx,int smaxy,int smaxx)68*7c478bd9Sstevel@tonic-gate _prefresh(int (*func)(WINDOW *), WINDOW *pad, int pminy, int pminx,
69*7c478bd9Sstevel@tonic-gate 	int sminy, int sminx, int smaxy, int smaxx)
70*7c478bd9Sstevel@tonic-gate {
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	/*
73*7c478bd9Sstevel@tonic-gate 	 * If pad->_padwin doesn't exist(meaning that this is
74*7c478bd9Sstevel@tonic-gate 	 * the first call to p*refresh) create it as a derived window
75*7c478bd9Sstevel@tonic-gate 	 */
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 	if (!pad->_padwin) {
78*7c478bd9Sstevel@tonic-gate 		if ((pad->_padwin = derwin(pad, pad->_maxy, pad->_maxx,
79*7c478bd9Sstevel@tonic-gate 		    0, 0)) == NULL) {
80*7c478bd9Sstevel@tonic-gate 			goto bad;
81*7c478bd9Sstevel@tonic-gate 		}
82*7c478bd9Sstevel@tonic-gate 	/* else  pad->_padwin->_use_idl = TRUE; */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	/*
85*7c478bd9Sstevel@tonic-gate 	 * The following makes parent window to run in fast mode
86*7c478bd9Sstevel@tonic-gate 	 * by creating an illusion that it has no derived windows
87*7c478bd9Sstevel@tonic-gate 	 */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 		pad->_ndescs--;
90*7c478bd9Sstevel@tonic-gate 	}
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	if (_padjust(pad, pminy, pminx, sminy, sminx, smaxy, smaxx) == ERR)
93*7c478bd9Sstevel@tonic-gate bad:
94*7c478bd9Sstevel@tonic-gate 		return (ERR);
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	(*func)(pad->_padwin);
97*7c478bd9Sstevel@tonic-gate 	return (OK);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate int
_padjust(WINDOW * pad,int pminy,int pminx,int sminy,int sminx,int smaxy,int smaxx)101*7c478bd9Sstevel@tonic-gate _padjust(WINDOW *pad, int pminy, int pminx, int sminy,
102*7c478bd9Sstevel@tonic-gate 	int sminx, int smaxy, int smaxx)
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	short	prows, pcols, y;
105*7c478bd9Sstevel@tonic-gate 	WINDOW	*padwin = pad->_padwin;
106*7c478bd9Sstevel@tonic-gate 	chtype	**p_y, **o_y;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	/* make sure the area requested to be updated is on the pad */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	if ((pminy >= pad->_maxy) || (pminx >= pad->_maxx))
111*7c478bd9Sstevel@tonic-gate 		return (ERR);
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	/* determine the area of the pad to be updated 	*/
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	if (pminy < 0)
116*7c478bd9Sstevel@tonic-gate 		pminy = 0;
117*7c478bd9Sstevel@tonic-gate 	if (pminx < 0)
118*7c478bd9Sstevel@tonic-gate 		pminx = 0;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	/* determine the screen area affected */
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 	if (sminy < 0)
123*7c478bd9Sstevel@tonic-gate 		sminy = 0;
124*7c478bd9Sstevel@tonic-gate 	if (sminx < 0)
125*7c478bd9Sstevel@tonic-gate 		sminx = 0;
126*7c478bd9Sstevel@tonic-gate 	if (smaxy < sminy)
127*7c478bd9Sstevel@tonic-gate 		smaxy = LINES - 1;
128*7c478bd9Sstevel@tonic-gate 	if (smaxx < sminx)
129*7c478bd9Sstevel@tonic-gate 		smaxx = COLS - 1;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	/*
132*7c478bd9Sstevel@tonic-gate 	 * Modify the area of the pad to be updated taking into
133*7c478bd9Sstevel@tonic-gate 	 * consideration screen parameters.
134*7c478bd9Sstevel@tonic-gate 	 */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	if ((prows = (smaxy - sminy) + 1) > (y = pad->_maxy - pminy))
137*7c478bd9Sstevel@tonic-gate 		prows = y;
138*7c478bd9Sstevel@tonic-gate 	if ((pcols = (smaxx - sminx) + 1) > (y = pad->_maxx - pminx))
139*7c478bd9Sstevel@tonic-gate 		pcols = y;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	if (((padwin->_cury = pad->_cury - pminy) < 0) ||
142*7c478bd9Sstevel@tonic-gate 	    (padwin->_cury >= prows))
143*7c478bd9Sstevel@tonic-gate 		padwin->_cury = 0;
144*7c478bd9Sstevel@tonic-gate 	if (((padwin->_curx = pad->_curx - pminx) < 0) ||
145*7c478bd9Sstevel@tonic-gate 	    (padwin->_curx >= pcols))
146*7c478bd9Sstevel@tonic-gate 		padwin->_curx = 0;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	padwin->_leave = pad->_leave;
149*7c478bd9Sstevel@tonic-gate 	padwin->_use_idl = pad->_use_idl;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	/*
153*7c478bd9Sstevel@tonic-gate 	 * If padwin refers to the same derwin, return.  Otherwise
154*7c478bd9Sstevel@tonic-gate 	 * update the coordinates and malloc'ed areas of the padwin
155*7c478bd9Sstevel@tonic-gate 	 */
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	if ((padwin->_begy == sminy) && (padwin->_begx == sminx) &&
158*7c478bd9Sstevel@tonic-gate 	    (padwin->_maxy == prows) && (padwin->_maxx == pcols) &&
159*7c478bd9Sstevel@tonic-gate 	    (padwin->_y[0] == (pad->_y[pminy] + pminx)) &&
160*7c478bd9Sstevel@tonic-gate 	    (!(pad->_flags & _WINSDEL))) {
161*7c478bd9Sstevel@tonic-gate 		goto good;
162*7c478bd9Sstevel@tonic-gate 	}
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	/* update the coordinates of the pad */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	padwin->_maxy = prows;
167*7c478bd9Sstevel@tonic-gate 	padwin->_maxx = pcols;
168*7c478bd9Sstevel@tonic-gate 	/* LINTED */
169*7c478bd9Sstevel@tonic-gate 	padwin->_begy = (short)sminy;
170*7c478bd9Sstevel@tonic-gate 	/* LINTED */
171*7c478bd9Sstevel@tonic-gate 	padwin->_begx = (short)sminx;
172*7c478bd9Sstevel@tonic-gate 	/* LINTED */
173*7c478bd9Sstevel@tonic-gate 	padwin->_pary = (short)pminy;
174*7c478bd9Sstevel@tonic-gate 	/* LINTED */
175*7c478bd9Sstevel@tonic-gate 	padwin->_parx = (short)pminx;
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	/* update the malloc'ed areas */
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	p_y = padwin->_y;
180*7c478bd9Sstevel@tonic-gate 	o_y = pad->_y;
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	for (y = 0; y < prows; y++, pminy++)
183*7c478bd9Sstevel@tonic-gate 		p_y[y] = o_y[pminy] + pminx;
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 	(void) wtouchln(padwin, 0, prows, TRUE);
186*7c478bd9Sstevel@tonic-gate good:
187*7c478bd9Sstevel@tonic-gate 	return (OK);
188*7c478bd9Sstevel@tonic-gate }
189