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