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