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