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