1*51ffecc1SBen Gras /* $NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $ */
2*51ffecc1SBen Gras
3*51ffecc1SBen Gras /*
4*51ffecc1SBen Gras * Copyright (c) 1981, 1993, 1994
5*51ffecc1SBen Gras * The Regents of the University of California. All rights reserved.
6*51ffecc1SBen Gras *
7*51ffecc1SBen Gras * Redistribution and use in source and binary forms, with or without
8*51ffecc1SBen Gras * modification, are permitted provided that the following conditions
9*51ffecc1SBen Gras * are met:
10*51ffecc1SBen Gras * 1. Redistributions of source code must retain the above copyright
11*51ffecc1SBen Gras * notice, this list of conditions and the following disclaimer.
12*51ffecc1SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
13*51ffecc1SBen Gras * notice, this list of conditions and the following disclaimer in the
14*51ffecc1SBen Gras * documentation and/or other materials provided with the distribution.
15*51ffecc1SBen Gras * 3. Neither the name of the University nor the names of its contributors
16*51ffecc1SBen Gras * may be used to endorse or promote products derived from this software
17*51ffecc1SBen Gras * without specific prior written permission.
18*51ffecc1SBen Gras *
19*51ffecc1SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*51ffecc1SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*51ffecc1SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*51ffecc1SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*51ffecc1SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*51ffecc1SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*51ffecc1SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*51ffecc1SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*51ffecc1SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*51ffecc1SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*51ffecc1SBen Gras * SUCH DAMAGE.
30*51ffecc1SBen Gras */
31*51ffecc1SBen Gras
32*51ffecc1SBen Gras #include <sys/cdefs.h>
33*51ffecc1SBen Gras #ifndef lint
34*51ffecc1SBen Gras #if 0
35*51ffecc1SBen Gras static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
36*51ffecc1SBen Gras #else
37*51ffecc1SBen Gras __RCSID("$NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $");
38*51ffecc1SBen Gras #endif
39*51ffecc1SBen Gras #endif /* not lint */
40*51ffecc1SBen Gras
41b7061124SArun Thomas #include <stdlib.h>
42b7061124SArun Thomas
43*51ffecc1SBen Gras #include "curses.h"
44*51ffecc1SBen Gras #include "curses_private.h"
45b7061124SArun Thomas
46b7061124SArun Thomas
47*51ffecc1SBen Gras static WINDOW *__makenew(SCREEN *screen, int nlines, int ncols, int by,
48*51ffecc1SBen Gras int bx, int sub, int ispad);
49*51ffecc1SBen Gras static WINDOW *__subwin(WINDOW *orig, int nlines, int ncols, int by, int bx,
50*51ffecc1SBen Gras int ispad);
51*51ffecc1SBen Gras
52*51ffecc1SBen Gras /*
53*51ffecc1SBen Gras * derwin --
54*51ffecc1SBen Gras * Create a new window in the same manner as subwin but (by, bx)
55*51ffecc1SBen Gras * are relative to the origin of window orig instead of absolute.
56*51ffecc1SBen Gras */
57*51ffecc1SBen Gras WINDOW *
derwin(WINDOW * orig,int nlines,int ncols,int by,int bx)58*51ffecc1SBen Gras derwin(WINDOW *orig, int nlines, int ncols, int by, int bx)
59*51ffecc1SBen Gras {
60*51ffecc1SBen Gras
61*51ffecc1SBen Gras return __subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx,
62*51ffecc1SBen Gras FALSE);
63*51ffecc1SBen Gras }
64*51ffecc1SBen Gras
65*51ffecc1SBen Gras /*
66*51ffecc1SBen Gras * subpad --
67*51ffecc1SBen Gras * Create a new pad in the same manner as subwin but (by, bx)
68*51ffecc1SBen Gras * are relative to the origin of window orig instead of absolute.
69*51ffecc1SBen Gras */
70*51ffecc1SBen Gras WINDOW *
subpad(WINDOW * orig,int nlines,int ncols,int by,int bx)71*51ffecc1SBen Gras subpad(WINDOW *orig, int nlines, int ncols, int by, int bx)
72*51ffecc1SBen Gras {
73*51ffecc1SBen Gras
74*51ffecc1SBen Gras return __subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx,
75*51ffecc1SBen Gras TRUE);
76*51ffecc1SBen Gras }
77*51ffecc1SBen Gras
78*51ffecc1SBen Gras /*
79*51ffecc1SBen Gras * dupwin --
80*51ffecc1SBen Gras * Create a copy of the given window.
81*51ffecc1SBen Gras */
82*51ffecc1SBen Gras WINDOW *
dupwin(WINDOW * win)83*51ffecc1SBen Gras dupwin(WINDOW *win)
84*51ffecc1SBen Gras {
85*51ffecc1SBen Gras WINDOW *new_one;
86*51ffecc1SBen Gras
87*51ffecc1SBen Gras if ((new_one = __newwin(_cursesi_screen, win->maxy, win->maxx,
88*51ffecc1SBen Gras win->begy, win->begx, FALSE)) == NULL)
89*51ffecc1SBen Gras return NULL;
90*51ffecc1SBen Gras
91*51ffecc1SBen Gras overwrite(win, new_one);
92*51ffecc1SBen Gras return new_one;
93*51ffecc1SBen Gras }
94*51ffecc1SBen Gras
95*51ffecc1SBen Gras /*
96*51ffecc1SBen Gras * newwin --
97*51ffecc1SBen Gras * Allocate space for and set up defaults for a new window.
98*51ffecc1SBen Gras */
99*51ffecc1SBen Gras WINDOW *
newwin(int nlines,int ncols,int by,int bx)100*51ffecc1SBen Gras newwin(int nlines, int ncols, int by, int bx)
101*51ffecc1SBen Gras {
102*51ffecc1SBen Gras return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE);
103*51ffecc1SBen Gras }
104*51ffecc1SBen Gras
105*51ffecc1SBen Gras /*
106*51ffecc1SBen Gras * newpad --
107*51ffecc1SBen Gras * Allocate space for and set up defaults for a new pad.
108*51ffecc1SBen Gras */
109*51ffecc1SBen Gras WINDOW *
newpad(int nlines,int ncols)110*51ffecc1SBen Gras newpad(int nlines, int ncols)
111*51ffecc1SBen Gras {
112*51ffecc1SBen Gras if (nlines < 1 || ncols < 1)
113*51ffecc1SBen Gras return NULL;
114*51ffecc1SBen Gras return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE);
115*51ffecc1SBen Gras }
116*51ffecc1SBen Gras
117*51ffecc1SBen Gras WINDOW *
__newwin(SCREEN * screen,int nlines,int ncols,int by,int bx,int ispad)118*51ffecc1SBen Gras __newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad)
119*51ffecc1SBen Gras {
120*51ffecc1SBen Gras WINDOW *win;
121*51ffecc1SBen Gras __LINE *lp;
122*51ffecc1SBen Gras int i, j;
123*51ffecc1SBen Gras int maxy, maxx;
124*51ffecc1SBen Gras __LDATA *sp;
125*51ffecc1SBen Gras
126*51ffecc1SBen Gras if (by < 0 || bx < 0)
127*51ffecc1SBen Gras return (NULL);
128*51ffecc1SBen Gras
129*51ffecc1SBen Gras maxy = nlines > 0 ? nlines : LINES - by + nlines;
130*51ffecc1SBen Gras maxx = ncols > 0 ? ncols : COLS - bx + ncols;
131*51ffecc1SBen Gras
132*51ffecc1SBen Gras if ((win = __makenew(screen, maxy, maxx, by, bx, 0, ispad)) == NULL)
133*51ffecc1SBen Gras return (NULL);
134*51ffecc1SBen Gras
135*51ffecc1SBen Gras win->bch = ' ';
136*51ffecc1SBen Gras if (__using_color)
137*51ffecc1SBen Gras win->battr = __default_color;
138*51ffecc1SBen Gras else
139*51ffecc1SBen Gras win->battr = 0;
140*51ffecc1SBen Gras win->nextp = win;
141*51ffecc1SBen Gras win->ch_off = 0;
142*51ffecc1SBen Gras win->orig = NULL;
143*51ffecc1SBen Gras win->reqy = nlines;
144*51ffecc1SBen Gras win->reqx = ncols;
145*51ffecc1SBen Gras
146*51ffecc1SBen Gras #ifdef DEBUG
147*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "newwin: win->ch_off = %d\n", win->ch_off);
148*51ffecc1SBen Gras #endif
149*51ffecc1SBen Gras
150*51ffecc1SBen Gras for (i = 0; i < maxy; i++) {
151*51ffecc1SBen Gras lp = win->alines[i];
152*51ffecc1SBen Gras if (ispad)
153*51ffecc1SBen Gras lp->flags = __ISDIRTY;
154*51ffecc1SBen Gras else
155*51ffecc1SBen Gras lp->flags = 0;
156*51ffecc1SBen Gras for (sp = lp->line, j = 0; j < maxx; j++, sp++) {
157*51ffecc1SBen Gras sp->attr = 0;
158*51ffecc1SBen Gras #ifndef HAVE_WCHAR
159*51ffecc1SBen Gras sp->ch = win->bch;
160*51ffecc1SBen Gras #else
161*51ffecc1SBen Gras sp->ch = ( wchar_t )btowc(( int ) win->bch );
162*51ffecc1SBen Gras sp->nsp = NULL;
163*51ffecc1SBen Gras SET_WCOL( *sp, 1 );
164*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
165*51ffecc1SBen Gras }
166*51ffecc1SBen Gras lp->hash = __hash((char *)(void *)lp->line,
167*51ffecc1SBen Gras (size_t) (ncols * __LDATASIZE));
168*51ffecc1SBen Gras }
169*51ffecc1SBen Gras return (win);
170*51ffecc1SBen Gras }
171*51ffecc1SBen Gras
172*51ffecc1SBen Gras WINDOW *
subwin(WINDOW * orig,int nlines,int ncols,int by,int bx)173*51ffecc1SBen Gras subwin(WINDOW *orig, int nlines, int ncols, int by, int bx)
174*51ffecc1SBen Gras {
175*51ffecc1SBen Gras
176*51ffecc1SBen Gras return __subwin(orig, nlines, ncols, by, bx, FALSE);
177*51ffecc1SBen Gras }
178*51ffecc1SBen Gras
179*51ffecc1SBen Gras static WINDOW *
__subwin(WINDOW * orig,int nlines,int ncols,int by,int bx,int ispad)180*51ffecc1SBen Gras __subwin(WINDOW *orig, int nlines, int ncols, int by, int bx, int ispad)
181b7061124SArun Thomas {
182b7061124SArun Thomas int i;
183*51ffecc1SBen Gras __LINE *lp;
184b7061124SArun Thomas WINDOW *win;
185*51ffecc1SBen Gras int maxy, maxx;
186b7061124SArun Thomas
187*51ffecc1SBen Gras #ifdef DEBUG
188*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "subwin: (%p, %d, %d, %d, %d, %d)\n",
189*51ffecc1SBen Gras orig, nlines, ncols, by, bx, ispad);
190*51ffecc1SBen Gras #endif
191*51ffecc1SBen Gras if (orig == NULL || orig->orig != NULL)
192*51ffecc1SBen Gras return NULL;
193b7061124SArun Thomas
194*51ffecc1SBen Gras /* Make sure window fits inside the original one. */
195*51ffecc1SBen Gras maxy = nlines > 0 ? nlines : orig->maxy + orig->begy - by + nlines;
196*51ffecc1SBen Gras maxx = ncols > 0 ? ncols : orig->maxx + orig->begx - bx + ncols;
197*51ffecc1SBen Gras if (by < orig->begy || bx < orig->begx
198*51ffecc1SBen Gras || by + maxy > orig->maxy + orig->begy
199*51ffecc1SBen Gras || bx + maxx > orig->maxx + orig->begx)
200*51ffecc1SBen Gras return (NULL);
201*51ffecc1SBen Gras if ((win = __makenew(_cursesi_screen, maxy, maxx,
202*51ffecc1SBen Gras by, bx, 1, ispad)) == NULL)
203*51ffecc1SBen Gras return (NULL);
204*51ffecc1SBen Gras win->bch = orig->bch;
205*51ffecc1SBen Gras win->battr = orig->battr;
206*51ffecc1SBen Gras win->reqy = nlines;
207*51ffecc1SBen Gras win->reqx = ncols;
208*51ffecc1SBen Gras win->nextp = orig->nextp;
209*51ffecc1SBen Gras orig->nextp = win;
210*51ffecc1SBen Gras win->orig = orig;
211b7061124SArun Thomas
212*51ffecc1SBen Gras /* Initialize flags here so that refresh can also use __set_subwin. */
213*51ffecc1SBen Gras for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++)
214*51ffecc1SBen Gras lp->flags = 0;
215*51ffecc1SBen Gras __set_subwin(orig, win);
216b7061124SArun Thomas return (win);
217b7061124SArun Thomas }
218*51ffecc1SBen Gras /*
219*51ffecc1SBen Gras * This code is shared with mvwin().
220*51ffecc1SBen Gras */
221*51ffecc1SBen Gras void
__set_subwin(WINDOW * orig,WINDOW * win)222*51ffecc1SBen Gras __set_subwin(WINDOW *orig, WINDOW *win)
223*51ffecc1SBen Gras {
224*51ffecc1SBen Gras int i;
225*51ffecc1SBen Gras __LINE *lp, *olp;
226*51ffecc1SBen Gras #ifdef HAVE_WCHAR
227*51ffecc1SBen Gras __LDATA *cp;
228*51ffecc1SBen Gras int j;
229*51ffecc1SBen Gras nschar_t *np;
230*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
231b7061124SArun Thomas
232*51ffecc1SBen Gras win->ch_off = win->begx - orig->begx;
233*51ffecc1SBen Gras /* Point line pointers to line space. */
234*51ffecc1SBen Gras for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) {
235*51ffecc1SBen Gras win->alines[i] = lp;
236*51ffecc1SBen Gras olp = orig->alines[i + win->begy - orig->begy];
237*51ffecc1SBen Gras #ifdef DEBUG
238*51ffecc1SBen Gras lp->sentinel = SENTINEL_VALUE;
239*51ffecc1SBen Gras #endif
240*51ffecc1SBen Gras lp->line = &olp->line[win->ch_off];
241*51ffecc1SBen Gras lp->firstchp = &olp->firstch;
242*51ffecc1SBen Gras lp->lastchp = &olp->lastch;
243*51ffecc1SBen Gras #ifndef HAVE_WCHAR
244*51ffecc1SBen Gras lp->hash = __hash((char *)(void *)lp->line,
245*51ffecc1SBen Gras (size_t) (win->maxx * __LDATASIZE));
246*51ffecc1SBen Gras #else
247*51ffecc1SBen Gras for ( cp = lp->line, j = 0; j < win->maxx; j++, cp++ ) {
248*51ffecc1SBen Gras lp->hash = __hash_more( &cp->ch,
249*51ffecc1SBen Gras sizeof( wchar_t ), lp->hash );
250*51ffecc1SBen Gras lp->hash = __hash_more( &cp->attr,
251*51ffecc1SBen Gras sizeof( wchar_t ), lp->hash );
252*51ffecc1SBen Gras if ( cp->nsp ) {
253*51ffecc1SBen Gras np = cp->nsp;
254*51ffecc1SBen Gras while ( np ) {
255*51ffecc1SBen Gras lp->hash = __hash_more( &np->ch,
256*51ffecc1SBen Gras sizeof( wchar_t ), lp->hash );
257*51ffecc1SBen Gras np = np->next;
258*51ffecc1SBen Gras }
259*51ffecc1SBen Gras }
260*51ffecc1SBen Gras }
261*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
262*51ffecc1SBen Gras }
263b7061124SArun Thomas
264*51ffecc1SBen Gras #ifdef DEBUG
265*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "__set_subwin: win->ch_off = %d\n",
266*51ffecc1SBen Gras win->ch_off);
267*51ffecc1SBen Gras #endif
268*51ffecc1SBen Gras }
269*51ffecc1SBen Gras /*
270*51ffecc1SBen Gras * __makenew --
271*51ffecc1SBen Gras * Set up a window buffer and returns a pointer to it.
272*51ffecc1SBen Gras */
273*51ffecc1SBen Gras static WINDOW *
__makenew(SCREEN * screen,int nlines,int ncols,int by,int bx,int sub,int ispad)274*51ffecc1SBen Gras __makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub,
275*51ffecc1SBen Gras int ispad)
276b7061124SArun Thomas {
277b7061124SArun Thomas WINDOW *win;
278*51ffecc1SBen Gras __LINE *lp;
279*51ffecc1SBen Gras struct __winlist *wlp, *wlp2;
280*51ffecc1SBen Gras int i;
281b7061124SArun Thomas
282*51ffecc1SBen Gras
283*51ffecc1SBen Gras #ifdef DEBUG
284*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: (%d, %d, %d, %d)\n",
285*51ffecc1SBen Gras nlines, ncols, by, bx);
286*51ffecc1SBen Gras #endif
287*51ffecc1SBen Gras if (nlines <= 0 || ncols <= 0)
288*51ffecc1SBen Gras return NULL;
289*51ffecc1SBen Gras
290*51ffecc1SBen Gras if ((win = malloc(sizeof(WINDOW))) == NULL)
291*51ffecc1SBen Gras return (NULL);
292*51ffecc1SBen Gras #ifdef DEBUG
293*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win = %p\n", win);
294*51ffecc1SBen Gras #endif
295*51ffecc1SBen Gras
296*51ffecc1SBen Gras /* Set up line pointer array and line space. */
297*51ffecc1SBen Gras if ((win->alines = malloc(nlines * sizeof(__LINE *))) == NULL) {
298b7061124SArun Thomas free(win);
299*51ffecc1SBen Gras return NULL;
300*51ffecc1SBen Gras }
301*51ffecc1SBen Gras if ((win->lspace = malloc(nlines * sizeof(__LINE))) == NULL) {
302*51ffecc1SBen Gras free(win->alines);
303*51ffecc1SBen Gras free(win);
304*51ffecc1SBen Gras return NULL;
305*51ffecc1SBen Gras }
306*51ffecc1SBen Gras /* Don't allocate window and line space if it's a subwindow */
307*51ffecc1SBen Gras if (sub)
308*51ffecc1SBen Gras win->wspace = NULL;
309*51ffecc1SBen Gras else {
310*51ffecc1SBen Gras /*
311*51ffecc1SBen Gras * Allocate window space in one chunk.
312*51ffecc1SBen Gras */
313*51ffecc1SBen Gras if ((win->wspace =
314*51ffecc1SBen Gras malloc(ncols * nlines * sizeof(__LDATA))) == NULL) {
315*51ffecc1SBen Gras free(win->lspace);
316*51ffecc1SBen Gras free(win->alines);
317*51ffecc1SBen Gras free(win);
318*51ffecc1SBen Gras return NULL;
319*51ffecc1SBen Gras }
320*51ffecc1SBen Gras /*
321*51ffecc1SBen Gras * Append window to window list.
322*51ffecc1SBen Gras */
323*51ffecc1SBen Gras if ((wlp = malloc(sizeof(struct __winlist))) == NULL) {
324*51ffecc1SBen Gras free(win->wspace);
325*51ffecc1SBen Gras free(win->lspace);
326*51ffecc1SBen Gras free(win->alines);
327*51ffecc1SBen Gras free(win);
328*51ffecc1SBen Gras return NULL;
329*51ffecc1SBen Gras }
330*51ffecc1SBen Gras wlp->winp = win;
331*51ffecc1SBen Gras wlp->nextp = NULL;
332*51ffecc1SBen Gras if (screen->winlistp == NULL)
333*51ffecc1SBen Gras screen->winlistp = wlp;
334*51ffecc1SBen Gras else {
335*51ffecc1SBen Gras wlp2 = screen->winlistp;
336*51ffecc1SBen Gras while (wlp2->nextp != NULL)
337*51ffecc1SBen Gras wlp2 = wlp2->nextp;
338*51ffecc1SBen Gras wlp2->nextp = wlp;
339*51ffecc1SBen Gras }
340*51ffecc1SBen Gras /*
341*51ffecc1SBen Gras * Point line pointers to line space, and lines themselves into
342*51ffecc1SBen Gras * window space.
343*51ffecc1SBen Gras */
344*51ffecc1SBen Gras for (lp = win->lspace, i = 0; i < nlines; i++, lp++) {
345*51ffecc1SBen Gras win->alines[i] = lp;
346*51ffecc1SBen Gras lp->line = &win->wspace[i * ncols];
347*51ffecc1SBen Gras #ifdef DEBUG
348*51ffecc1SBen Gras lp->sentinel = SENTINEL_VALUE;
349*51ffecc1SBen Gras #endif
350*51ffecc1SBen Gras lp->firstchp = &lp->firstch;
351*51ffecc1SBen Gras lp->lastchp = &lp->lastch;
352*51ffecc1SBen Gras if (ispad) {
353*51ffecc1SBen Gras lp->firstch = 0;
354*51ffecc1SBen Gras lp->lastch = ncols;
355b7061124SArun Thomas } else {
356*51ffecc1SBen Gras lp->firstch = ncols;
357*51ffecc1SBen Gras lp->lastch = 0;
358b7061124SArun Thomas }
359b7061124SArun Thomas }
360*51ffecc1SBen Gras }
361*51ffecc1SBen Gras #ifdef DEBUG
362*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: ncols = %d\n", ncols);
363*51ffecc1SBen Gras #endif
364*51ffecc1SBen Gras win->screen = screen;
365*51ffecc1SBen Gras win->cury = win->curx = 0;
366*51ffecc1SBen Gras win->maxy = nlines;
367*51ffecc1SBen Gras win->maxx = ncols;
368*51ffecc1SBen Gras win->reqy = nlines;
369*51ffecc1SBen Gras win->reqx = ncols;
370*51ffecc1SBen Gras
371*51ffecc1SBen Gras win->begy = by;
372*51ffecc1SBen Gras win->begx = bx;
373*51ffecc1SBen Gras win->flags = (__IDLINE | __IDCHAR);
374*51ffecc1SBen Gras win->delay = -1;
375*51ffecc1SBen Gras win->wattr = 0;
376*51ffecc1SBen Gras #ifdef HAVE_WCHAR
377*51ffecc1SBen Gras win->bnsp = NULL;
378*51ffecc1SBen Gras SET_BGWCOL( *win, 1 );
379*51ffecc1SBen Gras #endif /* HAVE_WCHAR */
380*51ffecc1SBen Gras win->scr_t = 0;
381*51ffecc1SBen Gras win->scr_b = win->maxy - 1;
382*51ffecc1SBen Gras if (ispad) {
383*51ffecc1SBen Gras win->flags |= __ISPAD;
384*51ffecc1SBen Gras win->pbegy = 0;
385*51ffecc1SBen Gras win->pbegx = 0;
386*51ffecc1SBen Gras win->sbegy = 0;
387*51ffecc1SBen Gras win->sbegx = 0;
388*51ffecc1SBen Gras win->smaxy = 0;
389*51ffecc1SBen Gras win->smaxx = 0;
390*51ffecc1SBen Gras } else
391*51ffecc1SBen Gras __swflags(win);
392*51ffecc1SBen Gras #ifdef DEBUG
393*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->wattr = %08x\n", win->wattr);
394*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->flags = %#.4x\n", win->flags);
395*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->maxy = %d\n", win->maxy);
396*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->maxx = %d\n", win->maxx);
397*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->begy = %d\n", win->begy);
398*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->begx = %d\n", win->begx);
399*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->scr_t = %d\n", win->scr_t);
400*51ffecc1SBen Gras __CTRACE(__CTRACE_WINDOW, "makenew: win->scr_b = %d\n", win->scr_b);
401*51ffecc1SBen Gras #endif
402b7061124SArun Thomas return (win);
403b7061124SArun Thomas }
404b7061124SArun Thomas
405*51ffecc1SBen Gras void
__swflags(WINDOW * win)406*51ffecc1SBen Gras __swflags(WINDOW *win)
407b7061124SArun Thomas {
408*51ffecc1SBen Gras win->flags &= ~(__ENDLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK);
409*51ffecc1SBen Gras if (win->begx + win->maxx == COLS && !(win->flags & __ISPAD)) {
410*51ffecc1SBen Gras win->flags |= __ENDLINE;
411*51ffecc1SBen Gras if (win->begx == 0 && win->maxy == LINES && win->begy == 0)
412*51ffecc1SBen Gras win->flags |= __FULLWIN;
413*51ffecc1SBen Gras if (win->begy + win->maxy == LINES)
414*51ffecc1SBen Gras win->flags |= __SCROLLWIN;
415*51ffecc1SBen Gras }
416b7061124SArun Thomas }
417