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