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