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  *	Draw a box around a window.
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  *	ls : the character and attributes used for the left side.
50*7c478bd9Sstevel@tonic-gate  *	rs : right side.
51*7c478bd9Sstevel@tonic-gate  *	ts : top side.
52*7c478bd9Sstevel@tonic-gate  *	bs : bottom side.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate #define	_LEFTSIDE	variables[0]
56*7c478bd9Sstevel@tonic-gate #define	_RIGHTSIDE	variables[1]
57*7c478bd9Sstevel@tonic-gate #define	_TOPSIDE	variables[2]
58*7c478bd9Sstevel@tonic-gate #define	_BOTTOMSIDE	variables[3]
59*7c478bd9Sstevel@tonic-gate #define	_TOPLEFT	variables[4]
60*7c478bd9Sstevel@tonic-gate #define	_TOPRIGHT	variables[5]
61*7c478bd9Sstevel@tonic-gate #define	_BOTTOMLEFT	variables[6]
62*7c478bd9Sstevel@tonic-gate #define	_BOTTOMRIGHT	variables[7]
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate static	char	acs_values[] = {
65*7c478bd9Sstevel@tonic-gate 		    'x', /* ACS_VLINE */
66*7c478bd9Sstevel@tonic-gate 		    'x', /* ACS_VLINE */
67*7c478bd9Sstevel@tonic-gate 		    'q', /* ACS_HLINE */
68*7c478bd9Sstevel@tonic-gate 		    'q', /* ACS_HLINE */
69*7c478bd9Sstevel@tonic-gate 		    'l', /* ACS_ULCORNER */
70*7c478bd9Sstevel@tonic-gate 		    'k', /* ACS_URCORNER */
71*7c478bd9Sstevel@tonic-gate 		    'm', /* ACS_LLCORNER */
72*7c478bd9Sstevel@tonic-gate 		    'j' /* ACS_LRCORNER */
73*7c478bd9Sstevel@tonic-gate 		};
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate int
wborder(WINDOW * win,chtype ls,chtype rs,chtype ts,chtype bs,chtype tl,chtype tr,chtype bl,chtype br)76*7c478bd9Sstevel@tonic-gate wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
77*7c478bd9Sstevel@tonic-gate 	chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	int	i, endy = win->_maxy - 1, endx = win->_maxx - 2;
80*7c478bd9Sstevel@tonic-gate 	chtype	**_y = win->_y;	/* register version */
81*7c478bd9Sstevel@tonic-gate 	chtype	*line_ptr, variables[8];
82*7c478bd9Sstevel@tonic-gate 	int	x, sx, xend;
83*7c478bd9Sstevel@tonic-gate 	chtype	wc;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	_LEFTSIDE = ls;
86*7c478bd9Sstevel@tonic-gate 	_RIGHTSIDE = rs;
87*7c478bd9Sstevel@tonic-gate 	_TOPSIDE = ts;
88*7c478bd9Sstevel@tonic-gate 	_BOTTOMSIDE = bs;
89*7c478bd9Sstevel@tonic-gate 	_TOPLEFT = tl;
90*7c478bd9Sstevel@tonic-gate 	_TOPRIGHT = tr;
91*7c478bd9Sstevel@tonic-gate 	_BOTTOMLEFT = bl;
92*7c478bd9Sstevel@tonic-gate 	_BOTTOMRIGHT = br;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
95*7c478bd9Sstevel@tonic-gate 		if (_CHAR(variables[i]) == 0 ||
96*7c478bd9Sstevel@tonic-gate 		    variables[i] & 0xFF00)
97*7c478bd9Sstevel@tonic-gate 			variables[i] = acs_map[acs_values[i]];
98*7c478bd9Sstevel@tonic-gate 		if (ISCBIT(variables[i]))
99*7c478bd9Sstevel@tonic-gate 			variables[i] = _CHAR((RBYTE(variables[i])<<8) | \
100*7c478bd9Sstevel@tonic-gate 			(LBYTE(variables[i])|MBIT)) | CBIT;
101*7c478bd9Sstevel@tonic-gate 		variables[i] &= ~CBIT;
102*7c478bd9Sstevel@tonic-gate 		variables[i] = _WCHAR(win, variables[i]) | _ATTR(variables[i]);
103*7c478bd9Sstevel@tonic-gate 	}
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	/* do top and bottom edges and corners */
106*7c478bd9Sstevel@tonic-gate 	xend = win->_maxx-1;
107*7c478bd9Sstevel@tonic-gate 	x = 0;
108*7c478bd9Sstevel@tonic-gate 	for (; x <= xend; ++x)
109*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(_y[0][x]))
110*7c478bd9Sstevel@tonic-gate 			break;
111*7c478bd9Sstevel@tonic-gate 	for (; xend >= x; --xend)
112*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(_y[0][endx])) {
113*7c478bd9Sstevel@tonic-gate 			int	m;
114*7c478bd9Sstevel@tonic-gate 			wc = RBYTE(_y[0][xend]);
115*7c478bd9Sstevel@tonic-gate 			if ((m = xend + _curs_scrwidth[TYPE(wc)]) > win->_maxx)
116*7c478bd9Sstevel@tonic-gate 				xend -= 1;
117*7c478bd9Sstevel@tonic-gate 			else
118*7c478bd9Sstevel@tonic-gate 				xend = m - 1;
119*7c478bd9Sstevel@tonic-gate 			endx = xend - 1;
120*7c478bd9Sstevel@tonic-gate 			break;
121*7c478bd9Sstevel@tonic-gate 		}
122*7c478bd9Sstevel@tonic-gate 	sx = x == 0 ? 1 : x;
123*7c478bd9Sstevel@tonic-gate 	memSset((line_ptr = &_y[0][sx]), _TOPSIDE, endx);
124*7c478bd9Sstevel@tonic-gate 	if (x == 0)
125*7c478bd9Sstevel@tonic-gate 		*(--line_ptr) = _TOPLEFT;
126*7c478bd9Sstevel@tonic-gate 	if (endx == win->_maxx-2)
127*7c478bd9Sstevel@tonic-gate 		line_ptr[++endx] = _TOPRIGHT;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	xend = win->_maxx-1;
130*7c478bd9Sstevel@tonic-gate 	x = 0;
131*7c478bd9Sstevel@tonic-gate 	for (; x <= xend; ++x)
132*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(_y[endy][x]))
133*7c478bd9Sstevel@tonic-gate 			break;
134*7c478bd9Sstevel@tonic-gate 	for (; xend >= x; --xend)
135*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(_y[endy][xend])) {
136*7c478bd9Sstevel@tonic-gate 			int	m;
137*7c478bd9Sstevel@tonic-gate 			wc = RBYTE(_y[endy][xend]);
138*7c478bd9Sstevel@tonic-gate 			if ((m = xend + _curs_scrwidth[TYPE(wc)]) > win->_maxx)
139*7c478bd9Sstevel@tonic-gate 				xend -= 1;
140*7c478bd9Sstevel@tonic-gate 			else
141*7c478bd9Sstevel@tonic-gate 				xend = m - 1;
142*7c478bd9Sstevel@tonic-gate 			endx = xend - 1;
143*7c478bd9Sstevel@tonic-gate 			break;
144*7c478bd9Sstevel@tonic-gate 		}
145*7c478bd9Sstevel@tonic-gate 	sx = x == 0 ? 1 : x;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	memSset((line_ptr = &_y[endy][sx]), _BOTTOMSIDE, endx);
148*7c478bd9Sstevel@tonic-gate 	if (x == 0)
149*7c478bd9Sstevel@tonic-gate 		*--line_ptr = _BOTTOMLEFT;
150*7c478bd9Sstevel@tonic-gate 	if (endx == win->_maxx-2)
151*7c478bd9Sstevel@tonic-gate 		line_ptr[++endx] = _BOTTOMRIGHT;
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate #ifdef	_VR3_COMPAT_CODE
154*7c478bd9Sstevel@tonic-gate 	if (_y16update) {
155*7c478bd9Sstevel@tonic-gate 		(*_y16update)(win, 1, ++endx, 0, 0);
156*7c478bd9Sstevel@tonic-gate 		(*_y16update)(win, 1, endx--, endy, 0);
157*7c478bd9Sstevel@tonic-gate 	}
158*7c478bd9Sstevel@tonic-gate #endif	/* _VR3_COMPAT_CODE */
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	/* left and right edges */
161*7c478bd9Sstevel@tonic-gate 	while (--endy > 0) {
162*7c478bd9Sstevel@tonic-gate 		wc = _y[endy][0];
163*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(wc) && _curs_scrwidth[TYPE(RBYTE(wc))] == 1)
164*7c478bd9Sstevel@tonic-gate 			_y[endy][0] = _LEFTSIDE;
165*7c478bd9Sstevel@tonic-gate 		wc = _y[endy][endx];
166*7c478bd9Sstevel@tonic-gate 		if (!ISCBIT(wc) && _curs_scrwidth[TYPE(RBYTE(wc))] == 1)
167*7c478bd9Sstevel@tonic-gate 			_y[endy][endx] = _RIGHTSIDE;
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate #ifdef	_VR3_COMPAT_CODE
170*7c478bd9Sstevel@tonic-gate 		if (_y16update) {
171*7c478bd9Sstevel@tonic-gate 			/* LINTED */
172*7c478bd9Sstevel@tonic-gate 			win->_y16[endy][0] =  _TO_OCHTYPE(_LEFTSIDE);
173*7c478bd9Sstevel@tonic-gate 			/* LINTED */
174*7c478bd9Sstevel@tonic-gate 			win->_y16[endy][endx] = _TO_OCHTYPE(_RIGHTSIDE);
175*7c478bd9Sstevel@tonic-gate 		}
176*7c478bd9Sstevel@tonic-gate #endif	/* _VR3_COMPAT_CODE */
177*7c478bd9Sstevel@tonic-gate 	}
178*7c478bd9Sstevel@tonic-gate 	return (wtouchln((win), 0, (win)->_maxy, TRUE));
179*7c478bd9Sstevel@tonic-gate }
180