Home | History | Annotate | Line # | Download | only in libcurses
border.c revision 1.1.2.1
      1 /*	$NetBSD: border.c,v 1.1.2.1 2000/03/05 23:26:12 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 "curses.h"
     40 
     41 /*
     42  * wborder --
     43  *	Draw a border around the given window using the specified delimiting
     44  *	characters.
     45  */
     46 int
     47 wborder(win, left, right, top, bottom, topleft, topright, botleft, botright)
     48 	WINDOW	*win;
     49 	chtype	 left, right, top, bottom;
     50 	chtype	 topleft, topright, botleft, botright;
     51 {
     52 	int	 endy, endx, i;
     53 	__LDATA	*fp, *lp;
     54 
     55 	if (!(left & __CHARTEXT)) left = ACS_VLINE;
     56 	if (!(right & __CHARTEXT)) right = ACS_VLINE;
     57 	if (!(top & __CHARTEXT)) top = ACS_HLINE;
     58 	if (!(bottom & __CHARTEXT)) bottom = ACS_HLINE;
     59 	if (!(topleft & __CHARTEXT)) topleft = ACS_ULCORNER;
     60 	if (!(topright & __CHARTEXT)) topright = ACS_URCORNER;
     61 	if (!(botleft & __CHARTEXT)) botleft = ACS_LLCORNER;
     62 	if (!(botright & __CHARTEXT)) botright = ACS_LRCORNER;
     63 
     64 #ifdef DEBUG
     65 	__CTRACE("wborder: left = %c%s", left,
     66 	    left & __ALTCHARSET ? " (A)\n" : "\n");
     67 	__CTRACE("wborder: right = %c%s", right,
     68 	    right & __ALTCHARSET ? " (A)\n" : "\n");
     69 	__CTRACE("wborder: top = %c%s", top,
     70 	    top & __ALTCHARSET ? " (A)\n" : "\n");
     71 	__CTRACE("wborder: bottom = %c%s", bottom,
     72 	    bottom & __ALTCHARSET ? " (A)\n" : "\n");
     73 	__CTRACE("wborder: topleft = %c%s", topleft,
     74 	    topleft & __ALTCHARSET ? " (A)\n" : "\n");
     75 	__CTRACE("wborder: topright = %c%s", topright,
     76 	    topright & __ALTCHARSET ? " (A)\n" : "\n");
     77 	__CTRACE("wborder: botleft = %c%s", botleft,
     78 	    botleft & __ALTCHARSET ? " (A)\n" : "\n");
     79 	__CTRACE("wborder: botright = %c%s", botright,
     80 	    botright & __ALTCHARSET ? " (A)\n" : "\n");
     81 #endif
     82 	endx = win->maxx - 1;
     83 	endy = win->maxy - 1;
     84 	fp = win->lines[0]->line;
     85 	lp = win->lines[endy]->line;
     86 
     87 	/* Sides */
     88 	for (i = 1; i < endy; i++) {
     89 		win->lines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
     90 		win->lines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
     91 		win->lines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
     92 		win->lines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
     93 	}
     94 	for (i = 1; i < endx; i++) {
     95 		fp[i].ch = (wchar_t) top & __CHARTEXT;
     96 		fp[i].attr = (attr_t) top & __ATTRIBUTES;
     97 		lp[i].ch = (wchar_t) bottom & __CHARTEXT;
     98 		lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
     99 	}
    100 
    101 	/* Corners */
    102 	if (!(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN)) {
    103 		fp[0].ch = (wchar_t) topleft & __CHARTEXT;
    104 		fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
    105 		fp[endx].ch = (wchar_t) topright & __CHARTEXT;
    106 		fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
    107 		lp[0].ch = (wchar_t) botleft & __CHARTEXT;
    108 		lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
    109 		lp[endx].ch = (wchar_t) botright & __CHARTEXT;
    110 		lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
    111 	}
    112 	__touchwin(win);
    113 	return (OK);
    114 }
    115