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