border.c revision 1.1.2.2 1 1.1.2.2 jdc /* $NetBSD: border.c,v 1.1.2.2 2000/03/06 12:54:03 jdc Exp $ */
2 1.1.2.1 jdc
3 1.1.2.1 jdc /*
4 1.1.2.1 jdc * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1.2.1 jdc * All rights reserved.
6 1.1.2.1 jdc *
7 1.1.2.1 jdc * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 jdc * by Julian Coleman.
9 1.1.2.1 jdc *
10 1.1.2.1 jdc * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 jdc * modification, are permitted provided that the following conditions
12 1.1.2.1 jdc * are met:
13 1.1.2.1 jdc * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 jdc * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 jdc * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 jdc * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 jdc * documentation and/or other materials provided with the distribution.
18 1.1.2.1 jdc * 3. All advertising materials mentioning features or use of this software
19 1.1.2.1 jdc * must display the following acknowledgement:
20 1.1.2.1 jdc * This product includes software developed by the NetBSD
21 1.1.2.1 jdc * Foundation, Inc. and its contributors.
22 1.1.2.1 jdc * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.1 jdc * contributors may be used to endorse or promote products derived
24 1.1.2.1 jdc * from this software without specific prior written permission.
25 1.1.2.1 jdc *
26 1.1.2.1 jdc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.1 jdc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.1 jdc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.1 jdc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.1 jdc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.1 jdc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.1 jdc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.1 jdc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.1 jdc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.1 jdc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.1 jdc * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.1 jdc */
38 1.1.2.1 jdc
39 1.1.2.1 jdc #include "curses.h"
40 1.1.2.1 jdc
41 1.1.2.1 jdc /*
42 1.1.2.1 jdc * wborder --
43 1.1.2.1 jdc * Draw a border around the given window using the specified delimiting
44 1.1.2.1 jdc * characters.
45 1.1.2.1 jdc */
46 1.1.2.1 jdc int
47 1.1.2.1 jdc wborder(win, left, right, top, bottom, topleft, topright, botleft, botright)
48 1.1.2.1 jdc WINDOW *win;
49 1.1.2.1 jdc chtype left, right, top, bottom;
50 1.1.2.1 jdc chtype topleft, topright, botleft, botright;
51 1.1.2.1 jdc {
52 1.1.2.1 jdc int endy, endx, i;
53 1.1.2.1 jdc __LDATA *fp, *lp;
54 1.1.2.1 jdc
55 1.1.2.1 jdc if (!(left & __CHARTEXT)) left = ACS_VLINE;
56 1.1.2.1 jdc if (!(right & __CHARTEXT)) right = ACS_VLINE;
57 1.1.2.1 jdc if (!(top & __CHARTEXT)) top = ACS_HLINE;
58 1.1.2.1 jdc if (!(bottom & __CHARTEXT)) bottom = ACS_HLINE;
59 1.1.2.1 jdc if (!(topleft & __CHARTEXT)) topleft = ACS_ULCORNER;
60 1.1.2.1 jdc if (!(topright & __CHARTEXT)) topright = ACS_URCORNER;
61 1.1.2.1 jdc if (!(botleft & __CHARTEXT)) botleft = ACS_LLCORNER;
62 1.1.2.1 jdc if (!(botright & __CHARTEXT)) botright = ACS_LRCORNER;
63 1.1.2.1 jdc
64 1.1.2.1 jdc #ifdef DEBUG
65 1.1.2.2 jdc __CTRACE("wborder: left = %c, 0x%x\n", left, left & __ATTRIBUTES);
66 1.1.2.2 jdc __CTRACE("wborder: right = %c, 0x%x\n", right, right & __ATTRIBUTES);
67 1.1.2.2 jdc __CTRACE("wborder: top = %c, 0x%x\n", top, top & __ATTRIBUTES);
68 1.1.2.2 jdc __CTRACE("wborder: bottom = %c, 0x%x\n", bottom, bottom & __ATTRIBUTES);
69 1.1.2.2 jdc __CTRACE("wborder: topleft = %c, 0x%x\n", topleft, topleft & __ATTRIBUTES);
70 1.1.2.2 jdc __CTRACE("wborder: topright = %c, 0x%x\n", topright, topright & __ATTRIBUTES);
71 1.1.2.2 jdc __CTRACE("wborder: botleft = %c, 0x%x\n", botleft, botleft & __ATTRIBUTES);
72 1.1.2.2 jdc __CTRACE("wborder: botright = %c, 0x%x\n", botright, botright & __ATTRIBUTES);
73 1.1.2.1 jdc #endif
74 1.1.2.2 jdc
75 1.1.2.2 jdc /* Merge window attributes */
76 1.1.2.2 jdc left |= win->wattr;
77 1.1.2.2 jdc right |= win->wattr;
78 1.1.2.2 jdc top |= win->wattr;
79 1.1.2.2 jdc bottom |= win->wattr;
80 1.1.2.2 jdc topleft |= win->wattr;
81 1.1.2.2 jdc topright |= win->wattr;
82 1.1.2.2 jdc botleft |= win->wattr;
83 1.1.2.2 jdc botright |= win->wattr;
84 1.1.2.2 jdc
85 1.1.2.1 jdc endx = win->maxx - 1;
86 1.1.2.1 jdc endy = win->maxy - 1;
87 1.1.2.1 jdc fp = win->lines[0]->line;
88 1.1.2.1 jdc lp = win->lines[endy]->line;
89 1.1.2.1 jdc
90 1.1.2.1 jdc /* Sides */
91 1.1.2.1 jdc for (i = 1; i < endy; i++) {
92 1.1.2.1 jdc win->lines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
93 1.1.2.1 jdc win->lines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
94 1.1.2.1 jdc win->lines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
95 1.1.2.1 jdc win->lines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
96 1.1.2.1 jdc }
97 1.1.2.1 jdc for (i = 1; i < endx; i++) {
98 1.1.2.1 jdc fp[i].ch = (wchar_t) top & __CHARTEXT;
99 1.1.2.1 jdc fp[i].attr = (attr_t) top & __ATTRIBUTES;
100 1.1.2.1 jdc lp[i].ch = (wchar_t) bottom & __CHARTEXT;
101 1.1.2.1 jdc lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
102 1.1.2.1 jdc }
103 1.1.2.1 jdc
104 1.1.2.1 jdc /* Corners */
105 1.1.2.2 jdc if (!(win->maxx == LINES && win->maxy == COLS &&
106 1.1.2.2 jdc (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
107 1.1.2.1 jdc fp[0].ch = (wchar_t) topleft & __CHARTEXT;
108 1.1.2.1 jdc fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
109 1.1.2.1 jdc fp[endx].ch = (wchar_t) topright & __CHARTEXT;
110 1.1.2.1 jdc fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
111 1.1.2.1 jdc lp[0].ch = (wchar_t) botleft & __CHARTEXT;
112 1.1.2.1 jdc lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
113 1.1.2.1 jdc lp[endx].ch = (wchar_t) botright & __CHARTEXT;
114 1.1.2.1 jdc lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
115 1.1.2.1 jdc }
116 1.1.2.1 jdc __touchwin(win);
117 1.1.2.1 jdc return (OK);
118 1.1.2.1 jdc }
119