Home | History | Annotate | Line # | Download | only in libcurses
border.c revision 1.15.10.3
      1  1.15.10.3  pgoyette /*	$NetBSD: border.c,v 1.15.10.3 2017/03/20 06:56:59 pgoyette 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  *
     19        1.2     blymn  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.2     blymn  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.2     blymn  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.2     blymn  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.2     blymn  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.2     blymn  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.2     blymn  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.2     blymn  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.2     blymn  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.2     blymn  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.2     blymn  * POSSIBILITY OF SUCH DAMAGE.
     30        1.2     blymn  */
     31        1.6     blymn 
     32        1.6     blymn #include <sys/cdefs.h>
     33        1.6     blymn #ifndef lint
     34  1.15.10.3  pgoyette __RCSID("$NetBSD: border.c,v 1.15.10.3 2017/03/20 06:56:59 pgoyette Exp $");
     35        1.6     blymn #endif				/* not lint */
     36        1.2     blymn 
     37       1.10     blymn #include <stdlib.h>
     38       1.10     blymn #include <string.h>
     39       1.10     blymn 
     40        1.2     blymn #include "curses.h"
     41        1.2     blymn #include "curses_private.h"
     42        1.2     blymn 
     43        1.4     blymn #ifndef _CURSES_USE_MACROS
     44        1.4     blymn 
     45        1.4     blymn /*
     46        1.4     blymn  * border --
     47       1.10     blymn  *	Draw a border around stdscr using the specified
     48        1.4     blymn  *	delimiting characters.
     49        1.4     blymn  */
     50        1.4     blymn int
     51        1.4     blymn border(chtype left, chtype right, chtype top, chtype bottom, chtype topleft,
     52        1.4     blymn        chtype topright, chtype botleft, chtype botright)
     53        1.4     blymn {
     54        1.4     blymn 	return wborder(stdscr, left, right, top, bottom, topleft, topright,
     55       1.10     blymn 	    botleft, botright);
     56        1.4     blymn }
     57        1.4     blymn 
     58        1.4     blymn #endif
     59        1.4     blymn 
     60        1.2     blymn /*
     61        1.2     blymn  * wborder --
     62        1.2     blymn  *	Draw a border around the given window using the specified delimiting
     63        1.2     blymn  *	characters.
     64        1.2     blymn  */
     65        1.2     blymn int
     66        1.4     blymn wborder(WINDOW *win, chtype left, chtype right, chtype top, chtype bottom,
     67        1.4     blymn 	chtype topleft, chtype topright, chtype botleft, chtype botright)
     68        1.2     blymn {
     69       1.13  drochner #ifndef HAVE_WCHAR
     70        1.2     blymn 	int	 endy, endx, i;
     71        1.2     blymn 	__LDATA	*fp, *lp;
     72        1.2     blymn 
     73        1.7       jdc 	if (!(left & __CHARTEXT))
     74        1.7       jdc 		left |= ACS_VLINE;
     75        1.7       jdc 	if (!(right & __CHARTEXT))
     76        1.7       jdc 		right |= ACS_VLINE;
     77        1.7       jdc 	if (!(top & __CHARTEXT))
     78        1.7       jdc 		top |= ACS_HLINE;
     79        1.7       jdc 	if (!(bottom & __CHARTEXT))
     80        1.7       jdc 		bottom |= ACS_HLINE;
     81        1.7       jdc 	if (!(topleft & __CHARTEXT))
     82        1.7       jdc 		topleft |= ACS_ULCORNER;
     83        1.7       jdc 	if (!(topright & __CHARTEXT))
     84        1.7       jdc 		topright |= ACS_URCORNER;
     85        1.7       jdc 	if (!(botleft & __CHARTEXT))
     86        1.7       jdc 		botleft |= ACS_LLCORNER;
     87        1.7       jdc 	if (!(botright & __CHARTEXT))
     88        1.7       jdc 		botright |= ACS_LRCORNER;
     89        1.2     blymn 
     90        1.2     blymn #ifdef DEBUG
     91        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: left = %c, 0x%x\n",
     92        1.9       jdc 	    left & __CHARTEXT, left & __ATTRIBUTES);
     93        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: right = %c, 0x%x\n",
     94        1.9       jdc 	    right & __CHARTEXT, right & __ATTRIBUTES);
     95        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: top = %c, 0x%x\n",
     96        1.9       jdc 	    top & __CHARTEXT, top & __ATTRIBUTES);
     97        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: bottom = %c, 0x%x\n",
     98        1.9       jdc 	    bottom & __CHARTEXT, bottom & __ATTRIBUTES);
     99        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: topleft = %c, 0x%x\n",
    100        1.9       jdc 	    topleft & __CHARTEXT, topleft & __ATTRIBUTES);
    101        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: topright = %c, 0x%x\n",
    102        1.9       jdc 	    topright & __CHARTEXT, topright & __ATTRIBUTES);
    103        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: botleft = %c, 0x%x\n",
    104        1.9       jdc 	    botleft & __CHARTEXT, botleft & __ATTRIBUTES);
    105        1.9       jdc 	__CTRACE(__CTRACE_INPUT, "wborder: botright = %c, 0x%x\n",
    106        1.9       jdc 	    botright & __CHARTEXT, botright & __ATTRIBUTES);
    107        1.2     blymn #endif
    108        1.2     blymn 
    109        1.8       jdc 	/* Merge window and background attributes */
    110        1.3       jdc 	left |= (left & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    111        1.8       jdc 	left |= (left & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    112        1.3       jdc 	right |= (right & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    113        1.8       jdc 	right |= (right & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    114        1.3       jdc 	top |= (top & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    115        1.8       jdc 	top |= (top & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    116        1.3       jdc 	bottom |= (bottom & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    117        1.8       jdc 	bottom |= (bottom & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    118        1.3       jdc 	topleft |= (topleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    119        1.8       jdc 	topleft |= (topleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    120        1.3       jdc 	topright |= (topright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    121        1.8       jdc 	topright |= (topright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    122        1.3       jdc 	botleft |= (botleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    123        1.8       jdc 	botleft |= (botleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    124        1.3       jdc 	botright |= (botright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
    125        1.8       jdc 	botright |= (botright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
    126        1.2     blymn 
    127        1.2     blymn 	endx = win->maxx - 1;
    128        1.2     blymn 	endy = win->maxy - 1;
    129       1.12       roy 	fp = win->alines[0]->line;
    130       1.12       roy 	lp = win->alines[endy]->line;
    131        1.2     blymn 
    132        1.2     blymn 	/* Sides */
    133        1.2     blymn 	for (i = 1; i < endy; i++) {
    134       1.12       roy 		win->alines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
    135       1.12       roy 		win->alines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
    136       1.12       roy 		win->alines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
    137       1.12       roy 		win->alines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
    138        1.2     blymn 	}
    139        1.2     blymn 	for (i = 1; i < endx; i++) {
    140        1.2     blymn 		fp[i].ch = (wchar_t) top & __CHARTEXT;
    141        1.2     blymn 		fp[i].attr = (attr_t) top & __ATTRIBUTES;
    142        1.2     blymn 		lp[i].ch = (wchar_t) bottom & __CHARTEXT;
    143        1.2     blymn 		lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
    144        1.2     blymn 	}
    145        1.2     blymn 
    146        1.2     blymn 	/* Corners */
    147  1.15.10.3  pgoyette 	if (!(win->maxy == LINES && win->maxx == COLS &&
    148        1.2     blymn 	    (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
    149        1.2     blymn 		fp[0].ch = (wchar_t) topleft & __CHARTEXT;
    150        1.2     blymn 		fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
    151        1.2     blymn 		fp[endx].ch = (wchar_t) topright & __CHARTEXT;
    152        1.2     blymn 		fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
    153        1.2     blymn 		lp[0].ch = (wchar_t) botleft & __CHARTEXT;
    154        1.2     blymn 		lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
    155        1.2     blymn 		lp[endx].ch = (wchar_t) botright & __CHARTEXT;
    156        1.2     blymn 		lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
    157       1.10     blymn 	}
    158       1.10     blymn 	__touchwin(win);
    159  1.15.10.2  pgoyette 	return OK;
    160       1.13  drochner #else /* HAVE_WCHAR */
    161       1.13  drochner 	cchar_t ls, rs, ts, bs, tl, tr, bl, br;
    162       1.13  drochner 	cchar_t *lsp, *rsp, *tsp, *bsp, *tlp, *trp, *blp, *brp;
    163       1.13  drochner 
    164       1.14     blymn #define S(in, out, def) \
    165       1.13  drochner 	if (in & __CHARTEXT) { \
    166       1.13  drochner 		__cursesi_chtype_to_cchar(in, &out); \
    167       1.14     blymn 	} else { \
    168       1.14     blymn 		memcpy(&out, def, sizeof(cchar_t)); \
    169       1.14     blymn 		out.attributes |= in & __ATTRIBUTES; \
    170       1.14     blymn 	} \
    171       1.14     blymn 	out##p = &out;
    172       1.14     blymn 
    173       1.14     blymn 	S(left, ls, WACS_VLINE);
    174       1.14     blymn 	S(right, rs, WACS_VLINE);
    175       1.14     blymn 	S(top, ts, WACS_HLINE);
    176       1.14     blymn 	S(bottom, bs, WACS_HLINE);
    177       1.14     blymn 	S(topleft, tl, WACS_ULCORNER);
    178       1.14     blymn 	S(topright, tr, WACS_URCORNER);
    179       1.14     blymn 	S(botleft, bl, WACS_LLCORNER);
    180       1.14     blymn 	S(botright, br, WACS_LRCORNER);
    181       1.13  drochner #undef S
    182       1.13  drochner 	return wborder_set(win, lsp, rsp, tsp, bsp, tlp, trp, blp, brp);
    183       1.13  drochner #endif /* HAVE_WCHAR */
    184       1.10     blymn }
    185       1.10     blymn 
    186       1.10     blymn int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
    187       1.10     blymn 	   const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
    188       1.10     blymn 	   const cchar_t *bl, const cchar_t *br)
    189       1.10     blymn {
    190       1.10     blymn #ifndef HAVE_WCHAR
    191       1.10     blymn 	return ERR;
    192       1.10     blymn #else
    193       1.10     blymn 	return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
    194       1.10     blymn #endif /* HAVE_WCHAR */
    195       1.10     blymn }
    196       1.10     blymn 
    197       1.10     blymn int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
    198       1.10     blymn 		const cchar_t *ts, const cchar_t *bs,
    199       1.10     blymn 		const cchar_t *tl, const cchar_t *tr,
    200       1.10     blymn 		const cchar_t *bl, const cchar_t *br)
    201       1.10     blymn {
    202       1.10     blymn #ifndef HAVE_WCHAR
    203       1.10     blymn 	return ERR;
    204       1.10     blymn #else
    205       1.10     blymn 	int	 endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw;
    206       1.10     blymn 	cchar_t left, right, bottom, top, topleft, topright, botleft, botright;
    207       1.10     blymn 	nschar_t *np, *tnp;
    208       1.10     blymn 
    209  1.15.10.2  pgoyette 	if (ls && wcwidth(ls->vals[0]))
    210  1.15.10.2  pgoyette 		memcpy(&left, ls, sizeof(cchar_t));
    211       1.10     blymn 	else
    212  1.15.10.2  pgoyette 		memcpy(&left, WACS_VLINE, sizeof(cchar_t));
    213  1.15.10.2  pgoyette 	if (rs && wcwidth( rs->vals[0]))
    214  1.15.10.2  pgoyette 		memcpy(&right, rs, sizeof(cchar_t));
    215       1.10     blymn 	else
    216  1.15.10.2  pgoyette 		memcpy(&right, WACS_VLINE, sizeof(cchar_t));
    217  1.15.10.2  pgoyette 	if (ts && wcwidth( ts->vals[0]))
    218  1.15.10.2  pgoyette 		memcpy(&top, ts, sizeof(cchar_t));
    219       1.10     blymn 	else
    220  1.15.10.2  pgoyette 		memcpy( &top, WACS_HLINE, sizeof(cchar_t));
    221  1.15.10.2  pgoyette 	if (bs && wcwidth( bs->vals[0]))
    222  1.15.10.2  pgoyette 		memcpy(&bottom, bs, sizeof(cchar_t));
    223       1.10     blymn 	else
    224  1.15.10.2  pgoyette 		memcpy(&bottom, WACS_HLINE, sizeof(cchar_t));
    225  1.15.10.2  pgoyette 	if (tl && wcwidth(tl->vals[0]))
    226  1.15.10.2  pgoyette 		memcpy( &topleft, tl, sizeof(cchar_t));
    227       1.10     blymn 	else
    228  1.15.10.2  pgoyette 		memcpy(&topleft, WACS_ULCORNER, sizeof(cchar_t));
    229  1.15.10.2  pgoyette 	if (tr && wcwidth( tr->vals[0]))
    230  1.15.10.2  pgoyette 		memcpy(&topright, tr, sizeof(cchar_t));
    231       1.10     blymn 	else
    232  1.15.10.2  pgoyette 		memcpy(&topright, WACS_URCORNER, sizeof( cchar_t ));
    233  1.15.10.2  pgoyette 	if (bl && wcwidth( bl->vals[0]))
    234  1.15.10.2  pgoyette 		memcpy(&botleft, bl, sizeof(cchar_t));
    235       1.10     blymn 	else
    236  1.15.10.2  pgoyette 		memcpy(&botleft, WACS_LLCORNER, sizeof(cchar_t));
    237  1.15.10.2  pgoyette 	if (br && wcwidth( br->vals[0]))
    238  1.15.10.2  pgoyette 		memcpy(&botright, br, sizeof(cchar_t));
    239       1.10     blymn 	else
    240  1.15.10.2  pgoyette 		memcpy(&botright, WACS_LRCORNER, sizeof(cchar_t));
    241       1.10     blymn 
    242       1.10     blymn #ifdef DEBUG
    243       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n",
    244       1.10     blymn 	    left.vals[0], left.attributes );
    245       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n",
    246       1.10     blymn 	    right.vals[0], right.attributes );
    247       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n",
    248       1.10     blymn 	    top.vals[0], top.attributes );
    249       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n",
    250       1.10     blymn 	    bottom.vals[0], bottom.attributes );
    251       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n",
    252       1.10     blymn 	    topleft.vals[0], topleft.attributes );
    253       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n",
    254       1.10     blymn 	    topright.vals[0], topright.attributes );
    255       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n",
    256       1.10     blymn 	    botleft.vals[0], botleft.attributes );
    257       1.10     blymn 	__CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n",
    258       1.10     blymn 	    botright.vals[0], botright.attributes );
    259       1.10     blymn #endif
    260       1.10     blymn 
    261       1.10     blymn 	/* Merge window attributes */
    262       1.10     blymn 	left.attributes |= (left.attributes & __COLOR) ?
    263       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    264       1.15       jdc 	left.attributes |= (left.attributes & __COLOR) ?
    265       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    266       1.10     blymn 	right.attributes |= (right.attributes & __COLOR) ?
    267       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    268       1.15       jdc 	right.attributes |= (right.attributes & __COLOR) ?
    269       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    270       1.10     blymn 	top.attributes |= (top.attributes & __COLOR) ?
    271       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    272       1.15       jdc 	top.attributes |= (top.attributes & __COLOR) ?
    273       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    274       1.10     blymn 	bottom.attributes |= (bottom.attributes & __COLOR) ?
    275       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    276       1.15       jdc 	bottom.attributes |= (bottom.attributes & __COLOR) ?
    277       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    278       1.10     blymn 	topleft.attributes |= (topleft.attributes & __COLOR) ?
    279       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    280       1.15       jdc 	topleft.attributes |= (topleft.attributes & __COLOR) ?
    281       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    282       1.10     blymn 	topright.attributes |= (topright.attributes & __COLOR) ?
    283       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    284       1.15       jdc 	topright.attributes |= (topright.attributes & __COLOR) ?
    285       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    286       1.10     blymn 	botleft.attributes |= (botleft.attributes & __COLOR) ?
    287       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    288       1.15       jdc 	botleft.attributes |= (botleft.attributes & __COLOR) ?
    289       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    290       1.10     blymn 	botright.attributes |= (botright.attributes & __COLOR) ?
    291       1.10     blymn 		(win->wattr & ~__COLOR) : win->wattr;
    292       1.15       jdc 	botright.attributes |= (botright.attributes & __COLOR) ?
    293       1.15       jdc 		(win->battr & ~__COLOR) : win->battr;
    294       1.10     blymn 
    295       1.10     blymn 	endx = win->maxx - 1;
    296       1.10     blymn 	endy = win->maxy - 1;
    297       1.10     blymn 
    298       1.10     blymn 	/* Sides */
    299       1.10     blymn 	for (i = 1; i < endy; i++) {
    300       1.10     blymn 		/* left border */
    301  1.15.10.2  pgoyette 		cw = wcwidth(left.vals[0]);
    302       1.13  drochner 		if (cw < 0)
    303       1.13  drochner 			cw = 1;
    304       1.10     blymn 		for ( j = 0; j < cw; j++ ) {
    305  1.15.10.2  pgoyette 			win->alines[i]->line[j].ch = left.vals[0];
    306       1.12       roy 			win->alines[i]->line[j].attr = left.attributes;
    307       1.12       roy 			np = win->alines[i]->line[j].nsp;
    308       1.10     blymn 			if (np) {
    309  1.15.10.2  pgoyette 				while (np) {
    310       1.10     blymn 					tnp = np->next;
    311  1.15.10.2  pgoyette 					free(np);
    312       1.10     blymn 					np = tnp;
    313       1.10     blymn 				}
    314       1.12       roy 				win->alines[i]->line[j].nsp = NULL;
    315       1.10     blymn 			}
    316  1.15.10.2  pgoyette 			if (j)
    317  1.15.10.2  pgoyette 				SET_WCOL(win->alines[i]->line[j], -j);
    318       1.10     blymn 			else {
    319  1.15.10.2  pgoyette 				SET_WCOL(win->alines[i]->line[j], cw);
    320  1.15.10.2  pgoyette 				if (left.elements > 1) {
    321       1.10     blymn 					for (k = 1; k < left.elements; k++) {
    322  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    323       1.10     blymn 						if (!np)
    324       1.10     blymn 							return ERR;
    325       1.10     blymn 						np->ch = left.vals[ k ];
    326       1.12       roy 						np->next = win->alines[i]->line[j].nsp;
    327       1.12       roy 						win->alines[i]->line[j].nsp
    328       1.10     blymn 							= np;
    329       1.10     blymn 					}
    330       1.10     blymn 				}
    331       1.10     blymn 			}
    332       1.10     blymn 		}
    333  1.15.10.2  pgoyette 		for (j = cw; WCOL(win->alines[i]->line[j]) < 0; j++) {
    334       1.10     blymn #ifdef DEBUG
    335       1.10     blymn 			__CTRACE(__CTRACE_INPUT,
    336       1.10     blymn 			    "wborder_set: clean out partial char[%d]", j);
    337       1.10     blymn #endif /* DEBUG */
    338       1.12       roy 			win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch);
    339       1.10     blymn 			if (_cursesi_copy_nsp(win->bnsp,
    340       1.12       roy 					      &win->alines[i]->line[j]) == ERR)
    341       1.10     blymn 				return ERR;
    342  1.15.10.2  pgoyette 			SET_WCOL(win->alines[i]->line[j], 1);
    343       1.10     blymn 		}
    344       1.10     blymn 		/* right border */
    345  1.15.10.2  pgoyette 		cw = wcwidth(right.vals[0]);
    346       1.13  drochner 		if (cw < 0)
    347       1.13  drochner 			cw = 1;
    348       1.12       roy 		pcw = WCOL( win->alines[i]->line[endx - cw]);
    349       1.10     blymn 		for ( j = endx - cw + 1; j <= endx; j++ ) {
    350  1.15.10.2  pgoyette 			win->alines[i]->line[j].ch = right.vals[0];
    351       1.12       roy 			win->alines[i]->line[j].attr = right.attributes;
    352       1.12       roy 			np = win->alines[i]->line[j].nsp;
    353       1.10     blymn 			if (np) {
    354  1.15.10.2  pgoyette 				while (np) {
    355       1.10     blymn 					tnp = np->next;
    356  1.15.10.2  pgoyette 					free(np);
    357       1.10     blymn 					np = tnp;
    358       1.10     blymn 				}
    359       1.12       roy 				win->alines[i]->line[j].nsp = NULL;
    360       1.10     blymn 			}
    361  1.15.10.2  pgoyette 			if (j == endx - cw + 1) {
    362  1.15.10.2  pgoyette 				SET_WCOL(win->alines[i]->line[j], cw);
    363  1.15.10.2  pgoyette 				if (right.elements > 1) {
    364       1.10     blymn 					for (k = 1; k < right.elements; k++) {
    365  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    366       1.10     blymn 						if (!np)
    367       1.10     blymn 							return ERR;
    368       1.10     blymn 						np->ch = right.vals[ k ];
    369       1.12       roy 						np->next = win->alines[i]->line[j].nsp;
    370       1.12       roy 						win->alines[i]->line[j].nsp
    371       1.10     blymn 							= np;
    372       1.10     blymn 					}
    373       1.10     blymn 				}
    374       1.10     blymn 			} else
    375  1.15.10.2  pgoyette 				SET_WCOL(win->alines[i]->line[j],
    376  1.15.10.2  pgoyette 					 endx - cw + 1 - j);
    377       1.10     blymn 		}
    378  1.15.10.2  pgoyette 		if (pcw != 1) {
    379       1.10     blymn #ifdef DEBUG
    380       1.10     blymn 			__CTRACE(__CTRACE_INPUT,
    381       1.10     blymn 			    "wborder_set: clean out partial chars[%d:%d]",
    382       1.10     blymn 			    endx - cw + pcw, endx - cw );
    383       1.10     blymn #endif /* DEBUG */
    384       1.10     blymn 			k = pcw < 0 ? endx -cw + pcw : endx - cw;
    385  1.15.10.2  pgoyette 			for (j = endx - cw; j >= k; j--) {
    386       1.12       roy 				win->alines[i]->line[j].ch
    387       1.10     blymn 					= (wchar_t)btowc(win->bch);
    388       1.10     blymn 				if (_cursesi_copy_nsp(win->bnsp,
    389       1.12       roy 					       &win->alines[i]->line[j]) == ERR)
    390       1.10     blymn 					return ERR;
    391       1.12       roy 				win->alines[i]->line[j].attr = win->battr;
    392  1.15.10.2  pgoyette 				SET_WCOL(win->alines[i]->line[j], 1);
    393       1.10     blymn 			}
    394       1.10     blymn 		}
    395       1.10     blymn 	}
    396  1.15.10.2  pgoyette 	tlcw = wcwidth(topleft.vals[0]);
    397       1.13  drochner 	if (tlcw < 0)
    398       1.13  drochner 		tlcw = 1;
    399  1.15.10.2  pgoyette 	blcw = wcwidth(botleft.vals[0]);
    400       1.13  drochner 	if (blcw < 0)
    401       1.13  drochner 		blcw = 1;
    402  1.15.10.2  pgoyette 	trcw = wcwidth(topright.vals[0]);
    403       1.13  drochner 	if (trcw < 0)
    404       1.13  drochner 		trcw = 1;
    405  1.15.10.2  pgoyette 	brcw = wcwidth(botright.vals[0]);
    406       1.13  drochner 	if (brcw < 0)
    407       1.13  drochner 		brcw = 1;
    408       1.10     blymn 	/* upper border */
    409  1.15.10.2  pgoyette 	cw = wcwidth(top.vals[0]);
    410       1.13  drochner 	if (cw < 0)
    411       1.13  drochner 		cw = 1;
    412  1.15.10.2  pgoyette 	for (i = tlcw; i <= min( endx - cw, endx - trcw); i += cw) {
    413  1.15.10.2  pgoyette 		for (j = 0; j < cw; j++) {
    414  1.15.10.2  pgoyette 			win->alines[0]->line[i + j].ch = top.vals[0];
    415  1.15.10.2  pgoyette 			win->alines[0]->line[i + j].attr = top.attributes;
    416  1.15.10.2  pgoyette 			np = win->alines[0]->line[i + j].nsp;
    417       1.10     blymn 			if (np) {
    418  1.15.10.2  pgoyette 				while (np) {
    419       1.10     blymn 					tnp = np->next;
    420  1.15.10.2  pgoyette 					free(np);
    421       1.10     blymn 					np = tnp;
    422       1.10     blymn 				}
    423  1.15.10.2  pgoyette 				win->alines[0]->line[i + j].nsp = NULL;
    424       1.10     blymn 			}
    425  1.15.10.2  pgoyette 			if (j)
    426  1.15.10.2  pgoyette 				SET_WCOL(win->alines[ 0 ]->line[ i + j ], -j);
    427       1.10     blymn 			else {
    428  1.15.10.2  pgoyette 				SET_WCOL(win->alines[ 0 ]->line[ i + j ], cw);
    429       1.10     blymn 				if ( top.elements > 1 ) {
    430  1.15.10.2  pgoyette 					for (k = 1; k < top.elements; k++) {
    431  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    432       1.10     blymn 						if (!np)
    433       1.10     blymn 							return ERR;
    434  1.15.10.2  pgoyette 						np->ch = top.vals[k];
    435       1.12       roy 						np->next = win->alines[0]->line[i + j].nsp;
    436       1.12       roy 						win->alines[0]->line[i + j].nsp
    437       1.10     blymn 							= np;
    438       1.10     blymn 					}
    439       1.10     blymn 				}
    440       1.10     blymn 			}
    441       1.10     blymn 		}
    442       1.10     blymn 	}
    443  1.15.10.2  pgoyette 	while (i <= endx - trcw) {
    444       1.12       roy 		win->alines[0]->line[i].ch =
    445  1.15.10.2  pgoyette 			(wchar_t)btowc((int) win->bch);
    446       1.10     blymn 		if (_cursesi_copy_nsp(win->bnsp,
    447       1.12       roy 				      &win->alines[0]->line[i]) == ERR)
    448       1.10     blymn 			return ERR;
    449  1.15.10.2  pgoyette 		win->alines[0]->line[i].attr = win->battr;
    450  1.15.10.2  pgoyette 		SET_WCOL(win->alines[0]->line[i], 1);
    451       1.10     blymn 		i++;
    452       1.10     blymn 	}
    453       1.10     blymn 	/* lower border */
    454  1.15.10.2  pgoyette 	for (i = blcw; i <= min( endx - cw, endx - brcw); i += cw) {
    455  1.15.10.2  pgoyette 		for (j = 0; j < cw; j++) {
    456  1.15.10.2  pgoyette 			win->alines[endy]->line[i + j].ch = bottom.vals[0];
    457       1.12       roy 			win->alines[endy]->line[i + j].attr = bottom.attributes;
    458  1.15.10.2  pgoyette 			np = win->alines[endy]->line[i + j].nsp;
    459       1.10     blymn 			if (np) {
    460  1.15.10.2  pgoyette 				while (np) {
    461       1.10     blymn 					tnp = np->next;
    462  1.15.10.2  pgoyette 					free(np);
    463       1.10     blymn 					np = tnp;
    464       1.10     blymn 				}
    465  1.15.10.2  pgoyette 				win->alines[endy]->line[i + j].nsp = NULL;
    466       1.10     blymn 			}
    467  1.15.10.2  pgoyette 			if (j)
    468  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i + j], -j);
    469       1.10     blymn 			else {
    470  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i + j], cw);
    471  1.15.10.2  pgoyette 				if (bottom.elements > 1) {
    472  1.15.10.2  pgoyette 					for (k = 1; k < bottom.elements; k++) {
    473  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    474  1.15.10.1  pgoyette 						if (!np)
    475       1.10     blymn 							return ERR;
    476       1.10     blymn 						np->ch = bottom.vals[ k ];
    477       1.12       roy 						np->next = win->alines[endy]->line[i + j].nsp;
    478       1.12       roy 						win->alines[endy]->line[i + j].nsp = np;
    479       1.10     blymn 					}
    480       1.10     blymn 				}
    481       1.10     blymn 			}
    482       1.10     blymn 		}
    483       1.10     blymn 	}
    484  1.15.10.2  pgoyette 	while (i <= endx - brcw) {
    485  1.15.10.2  pgoyette 		win->alines[endy]->line[i].ch = (wchar_t)btowc((int) win->bch );
    486       1.10     blymn 		if (_cursesi_copy_nsp(win->bnsp,
    487       1.12       roy 				      &win->alines[endy]->line[i]) == ERR)
    488       1.10     blymn 			return ERR;
    489  1.15.10.2  pgoyette 		win->alines[endy]->line[i].attr = win->battr;
    490  1.15.10.2  pgoyette 		SET_WCOL(win->alines[endy]->line[ i ], 1);
    491       1.10     blymn 		i++;
    492       1.10     blymn 	}
    493       1.10     blymn 
    494       1.10     blymn 	/* Corners */
    495  1.15.10.3  pgoyette 	if (!(win->maxy == LINES && win->maxx == COLS &&
    496       1.10     blymn 		(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
    497  1.15.10.2  pgoyette 		for (i = 0; i < tlcw; i++) {
    498  1.15.10.2  pgoyette 			win->alines[0]->line[i].ch = topleft.vals[0];
    499  1.15.10.2  pgoyette 			win->alines[0]->line[i].attr = topleft.attributes;
    500  1.15.10.2  pgoyette 			np = win->alines[0]->line[i].nsp;
    501       1.10     blymn 			if (np) {
    502  1.15.10.2  pgoyette 				while (np) {
    503       1.10     blymn 					tnp = np->next;
    504  1.15.10.2  pgoyette 					free(np);
    505       1.10     blymn 					np = tnp;
    506       1.10     blymn 				}
    507  1.15.10.2  pgoyette 				win->alines[0]->line[i].nsp = NULL;
    508       1.10     blymn 			}
    509  1.15.10.2  pgoyette 			if (i)
    510  1.15.10.2  pgoyette 				SET_WCOL(win->alines[0]->line[i], -i);
    511       1.10     blymn 			else {
    512  1.15.10.2  pgoyette 				SET_WCOL(win->alines[0]->line[i], tlcw);
    513  1.15.10.2  pgoyette 				if (topleft.elements > 1) {
    514  1.15.10.2  pgoyette 					for (k = 1; k < topleft.elements; k++)
    515  1.15.10.2  pgoyette 					{
    516  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    517       1.10     blymn 						if (!np)
    518       1.10     blymn 							return ERR;
    519  1.15.10.2  pgoyette 						np->ch = topleft.vals[k];
    520  1.15.10.2  pgoyette 						np->next = win->alines[0]->line[i].nsp;
    521  1.15.10.2  pgoyette 						win->alines[0]->line[i].nsp = np;
    522       1.10     blymn 					}
    523       1.10     blymn 				}
    524       1.10     blymn 			}
    525       1.10     blymn 		}
    526  1.15.10.2  pgoyette 		for (i = endx - trcw + 1; i <= endx; i++) {
    527  1.15.10.2  pgoyette 			win->alines[0]->line[i].ch = topright.vals[0];
    528  1.15.10.2  pgoyette 			win->alines[0]->line[i].attr = topright.attributes;
    529  1.15.10.2  pgoyette 			np = win->alines[0]->line[i].nsp;
    530       1.10     blymn 			if (np) {
    531  1.15.10.2  pgoyette 				while (np) {
    532       1.10     blymn 					tnp = np->next;
    533  1.15.10.2  pgoyette 					free(np);
    534       1.10     blymn 					np = tnp;
    535       1.10     blymn 				}
    536  1.15.10.2  pgoyette 				win->alines[0]->line[i].nsp = NULL;
    537       1.10     blymn 			}
    538  1.15.10.2  pgoyette 			if (i == endx - trcw + 1) {
    539  1.15.10.2  pgoyette 				SET_WCOL(win->alines[0]->line[i], trcw);
    540  1.15.10.2  pgoyette 				if (topright.elements > 1) {
    541  1.15.10.2  pgoyette 					for (k = 1; k < topright.elements;k ++)
    542  1.15.10.2  pgoyette 					{
    543  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    544       1.10     blymn 						if (!np)
    545       1.10     blymn 							return ERR;
    546  1.15.10.2  pgoyette 						np->ch = topright.vals[k];
    547       1.12       roy 						np->next = win->alines[0]->line[i].nsp;
    548  1.15.10.2  pgoyette 						win->alines[ 0 ]->line[i].nsp = np;
    549       1.10     blymn 					}
    550       1.10     blymn 				}
    551       1.10     blymn 			} else
    552  1.15.10.2  pgoyette 				SET_WCOL(win->alines[0]->line[i],
    553  1.15.10.2  pgoyette 					 endx - trcw + 1 - i);
    554       1.10     blymn 		}
    555  1.15.10.2  pgoyette 		for (i = 0; i < blcw; i++) {
    556  1.15.10.2  pgoyette 			win->alines[endy]->line[i].ch = botleft.vals[0];
    557  1.15.10.2  pgoyette 			win->alines[endy]->line[i].attr = botleft.attributes;
    558       1.12       roy 			np = win->alines[ endy ]->line[i].nsp;
    559       1.10     blymn 			if (np) {
    560  1.15.10.2  pgoyette 				while (np) {
    561       1.10     blymn 					tnp = np->next;
    562  1.15.10.2  pgoyette 					free(np);
    563       1.10     blymn 					np = tnp;
    564       1.10     blymn 				}
    565  1.15.10.2  pgoyette 				win->alines[endy]->line[i].nsp = NULL;
    566       1.10     blymn 			}
    567  1.15.10.2  pgoyette 			if (i)
    568  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i], -i);
    569       1.10     blymn 			else {
    570  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i], blcw);
    571  1.15.10.2  pgoyette 				if (botleft.elements > 1) {
    572  1.15.10.2  pgoyette 					for (k = 1; k < botleft.elements; k++) {
    573  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    574       1.10     blymn 						if (!np)
    575       1.10     blymn 							return ERR;
    576       1.10     blymn 						np->ch = botleft.vals[ k ];
    577       1.12       roy 						np->next = win->alines[endy]->line[i].nsp;
    578  1.15.10.2  pgoyette 						win->alines[endy]->line[i].nsp = np;
    579       1.10     blymn 					}
    580       1.10     blymn 				}
    581       1.10     blymn 			}
    582       1.10     blymn 		}
    583  1.15.10.2  pgoyette 		for (i = endx - brcw + 1; i <= endx; i++) {
    584  1.15.10.2  pgoyette 			win->alines[endy]->line[i].ch = botright.vals[0];
    585  1.15.10.2  pgoyette 			win->alines[endy]->line[i].attr = botright.attributes;
    586  1.15.10.2  pgoyette 			np = win->alines[endy]->line[i].nsp;
    587       1.10     blymn 			if (np) {
    588  1.15.10.2  pgoyette 				while (np) {
    589       1.10     blymn 					tnp = np->next;
    590  1.15.10.2  pgoyette 					free(np);
    591       1.10     blymn 					np = tnp;
    592       1.10     blymn 				}
    593  1.15.10.2  pgoyette 				win->alines[endy]->line[i].nsp = NULL;
    594       1.10     blymn 			}
    595  1.15.10.2  pgoyette 			if (i == endx - brcw + 1) {
    596  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i], brcw);
    597  1.15.10.2  pgoyette 				if (botright.elements > 1) {
    598  1.15.10.2  pgoyette 					for (k = 1; k < botright.elements; k++){
    599  1.15.10.1  pgoyette 						np = malloc(sizeof(nschar_t));
    600       1.10     blymn 						if (!np)
    601       1.10     blymn 							return ERR;
    602  1.15.10.2  pgoyette 						np->ch = botright.vals[k];
    603       1.12       roy 						np->next = win->alines[endy]->line[i].nsp;
    604  1.15.10.2  pgoyette 						win->alines[endy]->line[i].nsp = np;
    605       1.10     blymn 					}
    606       1.10     blymn 				}
    607       1.10     blymn 			} else
    608  1.15.10.2  pgoyette 				SET_WCOL(win->alines[endy]->line[i],
    609  1.15.10.2  pgoyette 					 endx - brcw + 1 - i);
    610       1.10     blymn 		}
    611        1.2     blymn 	}
    612        1.2     blymn 	__touchwin(win);
    613  1.15.10.2  pgoyette 	return OK;
    614       1.10     blymn #endif /* HAVE_WCHAR */
    615        1.2     blymn }
    616