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