xref: /onnv-gate/usr/src/lib/libcurses/screen/wborder.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*0Sstevel@tonic-gate  * The Regents of the University of California
33*0Sstevel@tonic-gate  * All Rights Reserved
34*0Sstevel@tonic-gate  *
35*0Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*0Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*0Sstevel@tonic-gate  * contributors.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*LINTLIBRARY*/
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #include	<sys/types.h>
45*0Sstevel@tonic-gate #include	<stdlib.h>
46*0Sstevel@tonic-gate #include	"curses_inc.h"
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /*
49*0Sstevel@tonic-gate  *	Draw a box around a window.
50*0Sstevel@tonic-gate  *
51*0Sstevel@tonic-gate  *	ls : the character and attributes used for the left side.
52*0Sstevel@tonic-gate  *	rs : right side.
53*0Sstevel@tonic-gate  *	ts : top side.
54*0Sstevel@tonic-gate  *	bs : bottom side.
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #define	_LEFTSIDE	variables[0]
58*0Sstevel@tonic-gate #define	_RIGHTSIDE	variables[1]
59*0Sstevel@tonic-gate #define	_TOPSIDE	variables[2]
60*0Sstevel@tonic-gate #define	_BOTTOMSIDE	variables[3]
61*0Sstevel@tonic-gate #define	_TOPLEFT	variables[4]
62*0Sstevel@tonic-gate #define	_TOPRIGHT	variables[5]
63*0Sstevel@tonic-gate #define	_BOTTOMLEFT	variables[6]
64*0Sstevel@tonic-gate #define	_BOTTOMRIGHT	variables[7]
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate static	char	acs_values[] = {
67*0Sstevel@tonic-gate 		    'x', /* ACS_VLINE */
68*0Sstevel@tonic-gate 		    'x', /* ACS_VLINE */
69*0Sstevel@tonic-gate 		    'q', /* ACS_HLINE */
70*0Sstevel@tonic-gate 		    'q', /* ACS_HLINE */
71*0Sstevel@tonic-gate 		    'l', /* ACS_ULCORNER */
72*0Sstevel@tonic-gate 		    'k', /* ACS_URCORNER */
73*0Sstevel@tonic-gate 		    'm', /* ACS_LLCORNER */
74*0Sstevel@tonic-gate 		    'j' /* ACS_LRCORNER */
75*0Sstevel@tonic-gate 		};
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate int
wborder(WINDOW * win,chtype ls,chtype rs,chtype ts,chtype bs,chtype tl,chtype tr,chtype bl,chtype br)78*0Sstevel@tonic-gate wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
79*0Sstevel@tonic-gate 	chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate 	int	i, endy = win->_maxy - 1, endx = win->_maxx - 2;
82*0Sstevel@tonic-gate 	chtype	**_y = win->_y;	/* register version */
83*0Sstevel@tonic-gate 	chtype	*line_ptr, variables[8];
84*0Sstevel@tonic-gate 	int	x, sx, xend;
85*0Sstevel@tonic-gate 	chtype	wc;
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	_LEFTSIDE = ls;
88*0Sstevel@tonic-gate 	_RIGHTSIDE = rs;
89*0Sstevel@tonic-gate 	_TOPSIDE = ts;
90*0Sstevel@tonic-gate 	_BOTTOMSIDE = bs;
91*0Sstevel@tonic-gate 	_TOPLEFT = tl;
92*0Sstevel@tonic-gate 	_TOPRIGHT = tr;
93*0Sstevel@tonic-gate 	_BOTTOMLEFT = bl;
94*0Sstevel@tonic-gate 	_BOTTOMRIGHT = br;
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
97*0Sstevel@tonic-gate 		if (_CHAR(variables[i]) == 0 ||
98*0Sstevel@tonic-gate 		    variables[i] & 0xFF00)
99*0Sstevel@tonic-gate 			variables[i] = acs_map[acs_values[i]];
100*0Sstevel@tonic-gate 		if (ISCBIT(variables[i]))
101*0Sstevel@tonic-gate 			variables[i] = _CHAR((RBYTE(variables[i])<<8) | \
102*0Sstevel@tonic-gate 			(LBYTE(variables[i])|MBIT)) | CBIT;
103*0Sstevel@tonic-gate 		variables[i] &= ~CBIT;
104*0Sstevel@tonic-gate 		variables[i] = _WCHAR(win, variables[i]) | _ATTR(variables[i]);
105*0Sstevel@tonic-gate 	}
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	/* do top and bottom edges and corners */
108*0Sstevel@tonic-gate 	xend = win->_maxx-1;
109*0Sstevel@tonic-gate 	x = 0;
110*0Sstevel@tonic-gate 	for (; x <= xend; ++x)
111*0Sstevel@tonic-gate 		if (!ISCBIT(_y[0][x]))
112*0Sstevel@tonic-gate 			break;
113*0Sstevel@tonic-gate 	for (; xend >= x; --xend)
114*0Sstevel@tonic-gate 		if (!ISCBIT(_y[0][endx])) {
115*0Sstevel@tonic-gate 			int	m;
116*0Sstevel@tonic-gate 			wc = RBYTE(_y[0][xend]);
117*0Sstevel@tonic-gate 			if ((m = xend + _curs_scrwidth[TYPE(wc)]) > win->_maxx)
118*0Sstevel@tonic-gate 				xend -= 1;
119*0Sstevel@tonic-gate 			else
120*0Sstevel@tonic-gate 				xend = m - 1;
121*0Sstevel@tonic-gate 			endx = xend - 1;
122*0Sstevel@tonic-gate 			break;
123*0Sstevel@tonic-gate 		}
124*0Sstevel@tonic-gate 	sx = x == 0 ? 1 : x;
125*0Sstevel@tonic-gate 	memSset((line_ptr = &_y[0][sx]), _TOPSIDE, endx);
126*0Sstevel@tonic-gate 	if (x == 0)
127*0Sstevel@tonic-gate 		*(--line_ptr) = _TOPLEFT;
128*0Sstevel@tonic-gate 	if (endx == win->_maxx-2)
129*0Sstevel@tonic-gate 		line_ptr[++endx] = _TOPRIGHT;
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	xend = win->_maxx-1;
132*0Sstevel@tonic-gate 	x = 0;
133*0Sstevel@tonic-gate 	for (; x <= xend; ++x)
134*0Sstevel@tonic-gate 		if (!ISCBIT(_y[endy][x]))
135*0Sstevel@tonic-gate 			break;
136*0Sstevel@tonic-gate 	for (; xend >= x; --xend)
137*0Sstevel@tonic-gate 		if (!ISCBIT(_y[endy][xend])) {
138*0Sstevel@tonic-gate 			int	m;
139*0Sstevel@tonic-gate 			wc = RBYTE(_y[endy][xend]);
140*0Sstevel@tonic-gate 			if ((m = xend + _curs_scrwidth[TYPE(wc)]) > win->_maxx)
141*0Sstevel@tonic-gate 				xend -= 1;
142*0Sstevel@tonic-gate 			else
143*0Sstevel@tonic-gate 				xend = m - 1;
144*0Sstevel@tonic-gate 			endx = xend - 1;
145*0Sstevel@tonic-gate 			break;
146*0Sstevel@tonic-gate 		}
147*0Sstevel@tonic-gate 	sx = x == 0 ? 1 : x;
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 	memSset((line_ptr = &_y[endy][sx]), _BOTTOMSIDE, endx);
150*0Sstevel@tonic-gate 	if (x == 0)
151*0Sstevel@tonic-gate 		*--line_ptr = _BOTTOMLEFT;
152*0Sstevel@tonic-gate 	if (endx == win->_maxx-2)
153*0Sstevel@tonic-gate 		line_ptr[++endx] = _BOTTOMRIGHT;
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate #ifdef	_VR3_COMPAT_CODE
156*0Sstevel@tonic-gate 	if (_y16update) {
157*0Sstevel@tonic-gate 		(*_y16update)(win, 1, ++endx, 0, 0);
158*0Sstevel@tonic-gate 		(*_y16update)(win, 1, endx--, endy, 0);
159*0Sstevel@tonic-gate 	}
160*0Sstevel@tonic-gate #endif	/* _VR3_COMPAT_CODE */
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 	/* left and right edges */
163*0Sstevel@tonic-gate 	while (--endy > 0) {
164*0Sstevel@tonic-gate 		wc = _y[endy][0];
165*0Sstevel@tonic-gate 		if (!ISCBIT(wc) && _curs_scrwidth[TYPE(RBYTE(wc))] == 1)
166*0Sstevel@tonic-gate 			_y[endy][0] = _LEFTSIDE;
167*0Sstevel@tonic-gate 		wc = _y[endy][endx];
168*0Sstevel@tonic-gate 		if (!ISCBIT(wc) && _curs_scrwidth[TYPE(RBYTE(wc))] == 1)
169*0Sstevel@tonic-gate 			_y[endy][endx] = _RIGHTSIDE;
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate #ifdef	_VR3_COMPAT_CODE
172*0Sstevel@tonic-gate 		if (_y16update) {
173*0Sstevel@tonic-gate 			/* LINTED */
174*0Sstevel@tonic-gate 			win->_y16[endy][0] =  _TO_OCHTYPE(_LEFTSIDE);
175*0Sstevel@tonic-gate 			/* LINTED */
176*0Sstevel@tonic-gate 			win->_y16[endy][endx] = _TO_OCHTYPE(_RIGHTSIDE);
177*0Sstevel@tonic-gate 		}
178*0Sstevel@tonic-gate #endif	/* _VR3_COMPAT_CODE */
179*0Sstevel@tonic-gate 	}
180*0Sstevel@tonic-gate 	return (wtouchln((win), 0, (win)->_maxy, TRUE));
181*0Sstevel@tonic-gate }
182