Exemple #1
0
/*
 * wbkgd --
 *	Set new background and new background attributes.
 */
int
wbkgd(WINDOW *win, chtype ch)
{
	int	y, x;

#ifdef DEBUG
	__CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n",
	    win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES);
#endif

	/* Background attributes (check colour). */
	if (__using_color && !(ch & __COLOR))
		ch |= __default_color;

	win->battr = (attr_t) ch & __ATTRIBUTES;
	wbkgdset(win, ch);
	for (y = 0; y < win->maxy; y++)
		for (x = 0; x < win->maxx; x++) {
			/* Copy character if space */
			if (ch & A_CHARTEXT && win->alines[y]->line[x].ch == ' ')
				win->alines[y]->line[x].ch = ch & __CHARTEXT;
			/* Merge attributes */
			if (win->alines[y]->line[x].attr & __ALTCHARSET)
				win->alines[y]->line[x].attr =
				    (ch & __ATTRIBUTES) | __ALTCHARSET;
			else
				win->alines[y]->line[x].attr =
				    ch & __ATTRIBUTES;
#ifdef HAVE_WCHAR
			SET_WCOL(win->alines[y]->line[x], 1);
#endif
		}
	__touchwin(win);
	return(OK);
}
Exemple #2
0
int wbkgrnd(WINDOW *win, const cchar_t *wch)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
/* 	int	y, x, i; */
	attr_t battr;
/* 	nschar_t *np, *tnp, *pnp; */

#ifdef DEBUG
	__CTRACE(__CTRACE_ATTR, "wbkgrnd: (%p), '%s', %x\n",
		win, (const char *) wunctrl(wch), wch->attributes);
#endif

	/* ignore multi-column characters */
	if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 )
		return ERR;

	/* Background attributes (check colour). */
	battr = wch->attributes & WA_ATTRIBUTES;
	if (__using_color && !( battr & __COLOR))
		battr |= __default_color;

	win->battr = battr;
	wbkgrndset(win, wch);
	__touchwin(win);
	return OK;
#endif /* HAVE_WCHAR */
}
Exemple #3
0
/*
 * wbkgd --
 *	Set new background and new background attributes.
 */
int
wbkgd(WINDOW *win, chtype ch)
{
	int	y, x;

	/* Background attributes (check colour). */
	if (__using_color && !(ch & __COLOR))
		ch |= __default_color;

	win->battr = (attr_t) ch & __ATTRIBUTES;
	wbkgdset(win, ch);
	for (y = 0; y < win->maxy; y++)
		for (x = 0; x < win->maxx; x++) {
			/* Copy character if space */
			if (ch & A_CHARTEXT && win->alines[y]->line[x].ch == ' ')
				win->alines[y]->line[x].ch = ch & __CHARTEXT;
			/* Merge attributes */
			if (win->alines[y]->line[x].attr & __ALTCHARSET)
				win->alines[y]->line[x].attr =
				    (ch & __ATTRIBUTES) | __ALTCHARSET;
			else
				win->alines[y]->line[x].attr =
				    ch & __ATTRIBUTES;
			SET_WCOL(win->alines[y]->line[x], 1);
		}
	__touchwin(win);
	return(OK);
}
Exemple #4
0
/*
 * werase --
 *	Erases everything on the window.
 */
int
werase(WINDOW *win)
{

	int     y;
	__LDATA *sp, *end, *start;
	attr_t	attr;

#ifdef DEBUG
	__CTRACE(__CTRACE_ERASE, "werase: (%p)\n", win);
#endif
	if (win != curscr)
		attr = win->battr & __ATTRIBUTES;
	else
		attr = 0;
	for (y = 0; y < win->maxy; y++) {
		start = win->alines[y]->line;
		end = &start[win->maxx];
		for (sp = start; sp < end; sp++)
#ifndef HAVE_WCHAR
			if (sp->ch != win->bch || sp->attr != 0) {
#else
			if (sp->ch != ( wchar_t )btowc(( int ) win->bch ) ||
			    (sp->attr & WA_ATTRIBUTES) != 0 || sp->nsp) {
#endif /* HAVE_WCHAR */
				if (sp->attr & __ALTCHARSET)
					sp->attr = attr | __ALTCHARSET;
				else
					sp->attr = attr;
#ifdef HAVE_WCHAR
				sp->ch = ( wchar_t )btowc(( int ) win->bch);
				if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
					return ERR;
				SET_WCOL( *sp, 1 );
#else
				sp->ch = win->bch;
#endif /* HAVE_WCHAR */
			}
	}
	/*
	 * Mark the whole window as changed in case we have overlapping
	 * windows - this will result in the (intended) clearing of the
	 * screen over the area covered by the window. */
	__touchwin(win);
	wmove(win, 0, 0);
	return (OK);
}
Exemple #5
0
int wbkgrnd(WINDOW *win, const cchar_t *wch)
{
/* 	int	y, x, i; */
	attr_t battr;
/* 	nschar_t *np, *tnp, *pnp; */

	/* ignore multi-column characters */
	if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 )
		return ERR;

	/* Background attributes (check colour). */
	battr = wch->attributes & WA_ATTRIBUTES;
	if (__using_color && !( battr & __COLOR))
		battr |= __default_color;

	win->battr = battr;
	wbkgrndset(win, wch);
	__touchwin(win);
	return OK;
}
Exemple #6
0
/*
 * copywin --
 *     Copy the box starting at (sminrow, smincol) with a size that
 *     matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
 *     from the source window srcwin to the destination window dstwin.
 *     All these coordindinates are relative to the relevant window.
 *     If dooverlay is true then the copy is nondestructive otherwise the
 *     copy is destructive.
 */
int copywin(const WINDOW *srcwin, WINDOW *dstwin,
	    int sminrow, int smincol,
	    int dminrow, int dmincol, int dmaxrow, int dmaxcol, int dooverlay)
{
	int dcol;
	__LDATA *sp, *end;
#ifdef HAVE_WCHAR
	cchar_t cc;
	nschar_t *np;
#endif /* HAVE_WCHAR */

	/* overwrite() and overlay() can come here with -ve srcwin coords */
	if (sminrow < 0) {
		dminrow -= sminrow;
		sminrow = 0;
	}
	if (smincol < 0) {
		dmincol -= smincol;
		smincol = 0;
	}

	/* for symmetry allow dstwin coords to be -ve as well */
	if (dminrow < 0) {
		sminrow -= dminrow;
		dminrow = 0;
	}
	if (dmincol < 0) {
		smincol -= dmincol;
		dmincol = 0;
	}

	/* Bound dmaxcol for both windows (should be ok for dstwin) */
	if (dmaxcol >= dstwin->maxx)
		dmaxcol = dstwin->maxx - 1;
	if (smincol + (dmaxcol - dmincol) >= srcwin->maxx)
		dmaxcol = srcwin->maxx + dmincol - smincol - 1;
	if (dmaxcol < dmincol)
		/* nothing in the intersection */
		return OK;

	/* Bound dmaxrow for both windows (should be ok for dstwin) */
	if (dmaxrow >= dstwin->maxy)
		dmaxrow = dstwin->maxy - 1;
	if (sminrow + (dmaxrow - dminrow) >= srcwin->maxy)
		dmaxrow = srcwin->maxy + dminrow - sminrow - 1;

#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW,
	    "copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n",
	    dooverlay ? "overlay" : "overwrite",
	    sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
#endif

	for (; dminrow <= dmaxrow; sminrow++, dminrow++) {
		sp = &srcwin->alines[sminrow]->line[smincol];
		end = sp + dmaxcol - dmincol;
		for (dcol = dmincol; sp <= end; dcol++, sp++) {
			/* XXX: Perhaps this should check for the
			 * background character
			 */
			if ((dooverlay && !isspace(sp->ch)) || !dooverlay) {
				wmove(dstwin, dminrow, dcol);
#ifndef HAVE_WCHAR
				__waddch(dstwin, sp);
#else
				cc.vals[0] = sp->ch;
				cc.attributes = sp->attr;
				cc.elements = 1;
				np = sp->nsp;
				if (np) {
					while (np && cc.elements <=
					    CURSES_CCHAR_MAX) {
						cc.vals[cc.elements++] = np->ch;
						np = np->next;
					}
				}
				wadd_wch(dstwin, &cc);
#endif /* HAVE_WCHAR */
			}
		}
	}
	__touchwin(dstwin);
	return OK;
}
Exemple #7
0
/*
 * wborder --
 *	Draw a border around the given window using the specified delimiting
 *	characters.
 */
int
wborder(WINDOW *win, chtype left, chtype right, chtype top, chtype bottom,
	chtype topleft, chtype topright, chtype botleft, chtype botright)
{
#ifndef HAVE_WCHAR
	int	 endy, endx, i;
	__LDATA	*fp, *lp;

	if (!(left & __CHARTEXT))
		left |= ACS_VLINE;
	if (!(right & __CHARTEXT))
		right |= ACS_VLINE;
	if (!(top & __CHARTEXT))
		top |= ACS_HLINE;
	if (!(bottom & __CHARTEXT))
		bottom |= ACS_HLINE;
	if (!(topleft & __CHARTEXT))
		topleft |= ACS_ULCORNER;
	if (!(topright & __CHARTEXT))
		topright |= ACS_URCORNER;
	if (!(botleft & __CHARTEXT))
		botleft |= ACS_LLCORNER;
	if (!(botright & __CHARTEXT))
		botright |= ACS_LRCORNER;

#ifdef DEBUG
	__CTRACE(__CTRACE_INPUT, "wborder: left = %c, 0x%x\n",
	    left & __CHARTEXT, left & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: right = %c, 0x%x\n",
	    right & __CHARTEXT, right & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: top = %c, 0x%x\n",
	    top & __CHARTEXT, top & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: bottom = %c, 0x%x\n",
	    bottom & __CHARTEXT, bottom & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: topleft = %c, 0x%x\n",
	    topleft & __CHARTEXT, topleft & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: topright = %c, 0x%x\n",
	    topright & __CHARTEXT, topright & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: botleft = %c, 0x%x\n",
	    botleft & __CHARTEXT, botleft & __ATTRIBUTES);
	__CTRACE(__CTRACE_INPUT, "wborder: botright = %c, 0x%x\n",
	    botright & __CHARTEXT, botright & __ATTRIBUTES);
#endif

	/* Merge window and background attributes */
	left |= (left & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	left |= (left & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	right |= (right & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	right |= (right & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	top |= (top & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	top |= (top & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	bottom |= (bottom & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	bottom |= (bottom & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	topleft |= (topleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	topleft |= (topleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	topright |= (topright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	topright |= (topright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	botleft |= (botleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	botleft |= (botleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
	botright |= (botright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
	botright |= (botright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;

	endx = win->maxx - 1;
	endy = win->maxy - 1;
	fp = win->alines[0]->line;
	lp = win->alines[endy]->line;

	/* Sides */
	for (i = 1; i < endy; i++) {
		win->alines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
		win->alines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
		win->alines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
		win->alines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
	}
	for (i = 1; i < endx; i++) {
		fp[i].ch = (wchar_t) top & __CHARTEXT;
		fp[i].attr = (attr_t) top & __ATTRIBUTES;
		lp[i].ch = (wchar_t) bottom & __CHARTEXT;
		lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
	}

	/* Corners */
	if (!(win->maxx == LINES && win->maxy == COLS &&
	    (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
		fp[0].ch = (wchar_t) topleft & __CHARTEXT;
		fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
		fp[endx].ch = (wchar_t) topright & __CHARTEXT;
		fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
		lp[0].ch = (wchar_t) botleft & __CHARTEXT;
		lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
		lp[endx].ch = (wchar_t) botright & __CHARTEXT;
		lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
	}
	__touchwin(win);
	return (OK);
#else /* HAVE_WCHAR */
	cchar_t ls, rs, ts, bs, tl, tr, bl, br;
	cchar_t *lsp, *rsp, *tsp, *bsp, *tlp, *trp, *blp, *brp;

#define S(in, out, def) \
	if (in & __CHARTEXT) { \
		__cursesi_chtype_to_cchar(in, &out); \
	} else { \
		memcpy(&out, def, sizeof(cchar_t)); \
		out.attributes |= in & __ATTRIBUTES; \
	} \
	out##p = &out;

	S(left, ls, WACS_VLINE);
	S(right, rs, WACS_VLINE);
	S(top, ts, WACS_HLINE);
	S(bottom, bs, WACS_HLINE);
	S(topleft, tl, WACS_ULCORNER);
	S(topright, tr, WACS_URCORNER);
	S(botleft, bl, WACS_LLCORNER);
	S(botright, br, WACS_LRCORNER);
#undef S
	return wborder_set(win, lsp, rsp, tsp, bsp, tlp, trp, blp, brp);
#endif /* HAVE_WCHAR */
}
Exemple #8
0
int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
		const cchar_t *ts, const cchar_t *bs,
		const cchar_t *tl, const cchar_t *tr,
		const cchar_t *bl, const cchar_t *br)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	int	 endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw;
	cchar_t left, right, bottom, top, topleft, topright, botleft, botright;
	nschar_t *np, *tnp;

	if ( ls && wcwidth( ls->vals[ 0 ]))
		memcpy( &left, ls, sizeof( cchar_t ));
	else
		memcpy( &left, WACS_VLINE, sizeof( cchar_t ));
	if ( rs && wcwidth( rs->vals[ 0 ]))
		memcpy( &right, rs, sizeof( cchar_t ));
	else
		memcpy( &right, WACS_VLINE, sizeof( cchar_t ));
	if ( ts && wcwidth( ts->vals[ 0 ]))
		memcpy( &top, ts, sizeof( cchar_t ));
	else
		memcpy( &top, WACS_HLINE, sizeof( cchar_t ));
	if ( bs && wcwidth( bs->vals[ 0 ]))
		memcpy( &bottom, bs, sizeof( cchar_t ));
	else
		memcpy( &bottom, WACS_HLINE, sizeof( cchar_t ));
	if ( tl && wcwidth( tl->vals[ 0 ]))
		memcpy( &topleft, tl, sizeof( cchar_t ));
	else
		memcpy( &topleft, WACS_ULCORNER, sizeof( cchar_t ));
	if ( tr && wcwidth( tr->vals[ 0 ]))
		memcpy( &topright, tr, sizeof( cchar_t ));
	else
		memcpy( &topright, WACS_URCORNER, sizeof( cchar_t ));
	if ( bl && wcwidth( bl->vals[ 0 ]))
		memcpy( &botleft, bl, sizeof( cchar_t ));
	else
		memcpy( &botleft, WACS_LLCORNER, sizeof( cchar_t ));
	if ( br && wcwidth( br->vals[ 0 ]))
		memcpy( &botright, br, sizeof( cchar_t ));
	else
		memcpy( &botright, WACS_LRCORNER, sizeof( cchar_t ));

#ifdef DEBUG
	__CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n",
	    left.vals[0], left.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n",
	    right.vals[0], right.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n",
	    top.vals[0], top.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n",
	    bottom.vals[0], bottom.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n",
	    topleft.vals[0], topleft.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n",
	    topright.vals[0], topright.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n",
	    botleft.vals[0], botleft.attributes );
	__CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n",
	    botright.vals[0], botright.attributes );
#endif

	/* Merge window attributes */
	left.attributes |= (left.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	left.attributes |= (left.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	right.attributes |= (right.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	right.attributes |= (right.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	top.attributes |= (top.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	top.attributes |= (top.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	bottom.attributes |= (bottom.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	bottom.attributes |= (bottom.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	topleft.attributes |= (topleft.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	topleft.attributes |= (topleft.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	topright.attributes |= (topright.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	topright.attributes |= (topright.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	botleft.attributes |= (botleft.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	botleft.attributes |= (botleft.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;
	botright.attributes |= (botright.attributes & __COLOR) ?
		(win->wattr & ~__COLOR) : win->wattr;
	botright.attributes |= (botright.attributes & __COLOR) ?
		(win->battr & ~__COLOR) : win->battr;

	endx = win->maxx - 1;
	endy = win->maxy - 1;

	/* Sides */
	for (i = 1; i < endy; i++) {
		/* left border */
		cw = wcwidth( left.vals[ 0 ]);
		if (cw < 0)
			cw = 1;
		for ( j = 0; j < cw; j++ ) {
			win->alines[i]->line[j].ch = left.vals[ 0 ];
			win->alines[i]->line[j].attr = left.attributes;
			np = win->alines[i]->line[j].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[i]->line[j].nsp = NULL;
			}
			if ( j )
				SET_WCOL( win->alines[i]->line[j], -j );
			else {
				SET_WCOL( win->alines[i]->line[j], cw );
				if ( left.elements > 1 ) {
					for (k = 1; k < left.elements; k++) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = left.vals[ k ];
						np->next = win->alines[i]->line[j].nsp;
						win->alines[i]->line[j].nsp
							= np;
					}
				}
			}
		}
		for ( j = cw; WCOL( win->alines[i]->line[j]) < 0; j++ ) {
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "wborder_set: clean out partial char[%d]", j);
#endif /* DEBUG */
			win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch);
			if (_cursesi_copy_nsp(win->bnsp,
					      &win->alines[i]->line[j]) == ERR)
				return ERR;
			SET_WCOL( win->alines[i]->line[j], 1 );
		}
		/* right border */
		cw = wcwidth( right.vals[ 0 ]);
		if (cw < 0)
			cw = 1;
		pcw = WCOL( win->alines[i]->line[endx - cw]);
		for ( j = endx - cw + 1; j <= endx; j++ ) {
			win->alines[i]->line[j].ch = right.vals[ 0 ];
			win->alines[i]->line[j].attr = right.attributes;
			np = win->alines[i]->line[j].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[i]->line[j].nsp = NULL;
			}
			if ( j == endx - cw + 1 ) {
				SET_WCOL( win->alines[i]->line[j], cw );
				if ( right.elements > 1 ) {
					for (k = 1; k < right.elements; k++) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = right.vals[ k ];
						np->next = win->alines[i]->line[j].nsp;
						win->alines[i]->line[j].nsp
							= np;
					}
				}
			} else
				SET_WCOL( win->alines[i]->line[j],
					endx - cw + 1 - j );
		}
		if ( pcw != 1 ) {
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "wborder_set: clean out partial chars[%d:%d]",
			    endx - cw + pcw, endx - cw );
#endif /* DEBUG */
			k = pcw < 0 ? endx -cw + pcw : endx - cw;
			for ( j = endx - cw; j >= k; j-- ) {
				win->alines[i]->line[j].ch
					= (wchar_t)btowc(win->bch);
				if (_cursesi_copy_nsp(win->bnsp,
					       &win->alines[i]->line[j]) == ERR)
					return ERR;
				win->alines[i]->line[j].attr = win->battr;
				SET_WCOL( win->alines[i]->line[j], 1 );
			}
		}
	}
	tlcw = wcwidth( topleft.vals[ 0 ]);
	if (tlcw < 0)
		tlcw = 1;
	blcw = wcwidth( botleft.vals[ 0 ]);
	if (blcw < 0)
		blcw = 1;
	trcw = wcwidth( topright.vals[ 0 ]);
	if (trcw < 0)
		trcw = 1;
	brcw = wcwidth( botright.vals[ 0 ]);
	if (brcw < 0)
		brcw = 1;
	/* upper border */
	cw = wcwidth( top.vals[ 0 ]);
	if (cw < 0)
		cw = 1;
	for (i = tlcw; i <= min( endx - cw, endx - trcw ); i += cw ) {
		for ( j = 0; j < cw; j++ ) {
			win->alines[ 0 ]->line[i + j].ch = top.vals[ 0 ];
			win->alines[ 0 ]->line[i + j].attr = top.attributes;
			np = win->alines[ 0 ]->line[i + j].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ 0 ]->line[i + j].nsp = NULL;
			}
			if ( j )
				SET_WCOL( win->alines[ 0 ]->line[ i + j ], -j );
			else {
				SET_WCOL( win->alines[ 0 ]->line[ i + j ], cw );
				if ( top.elements > 1 ) {
					for ( k = 1; k < top.elements; k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = top.vals[ k ];
						np->next = win->alines[0]->line[i + j].nsp;
						win->alines[0]->line[i + j].nsp
							= np;
					}
				}
			}
		}
	}
	while ( i <= endx - trcw ) {
		win->alines[0]->line[i].ch =
			( wchar_t )btowc(( int ) win->bch );
		if (_cursesi_copy_nsp(win->bnsp,
				      &win->alines[0]->line[i]) == ERR)
			return ERR;
		win->alines[ 0 ]->line[ i ].attr = win->battr;
		SET_WCOL( win->alines[ 0 ]->line[ i ], 1 );
		i++;
	}
	/* lower border */
	for (i = blcw; i <= min( endx - cw, endx - brcw ); i += cw ) {
		for ( j = 0; j < cw; j++ ) {
			win->alines[ endy ]->line[i + j].ch = bottom.vals[ 0 ];
			win->alines[endy]->line[i + j].attr = bottom.attributes;
			np = win->alines[ endy ]->line[i + j].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ endy ]->line[i + j].nsp = NULL;
			}
			if ( j )
				SET_WCOL( win->alines[endy]->line[i + j], -j);
			else {
				SET_WCOL( win->alines[endy]->line[i + j], cw );
				if ( bottom.elements > 1 ) {
					for ( k = 1; k < bottom.elements;
							k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = bottom.vals[ k ];
						np->next = win->alines[endy]->line[i + j].nsp;
						win->alines[endy]->line[i + j].nsp = np;
					}
				}
			}
		}
	}
	while ( i <= endx - brcw ) {
		win->alines[endy]->line[i].ch =
			(wchar_t)btowc((int) win->bch );
		if (_cursesi_copy_nsp(win->bnsp,
				      &win->alines[endy]->line[i]) == ERR)
			return ERR;
		win->alines[ endy ]->line[ i ].attr = win->battr;
		SET_WCOL( win->alines[ endy ]->line[ i ], 1 );
		i++;
	}

	/* Corners */
	if (!(win->maxx == LINES && win->maxy == COLS &&
		(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
		for ( i = 0; i < tlcw; i++ ) {
			win->alines[ 0 ]->line[i].ch = topleft.vals[ 0 ];
			win->alines[ 0 ]->line[i].attr = topleft.attributes;
			np = win->alines[ 0 ]->line[i].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ 0 ]->line[i].nsp = NULL;
			}
			if ( i )
				SET_WCOL( win->alines[ 0 ]->line[ i ], -i );
			else {
				SET_WCOL( win->alines[ 0 ]->line[ i ], tlcw );
				if ( topleft.elements > 1 ) {
					for ( k = 1; k < topleft.elements;
							k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = topleft.vals[ k ];
						np->next = win->alines[ 0 ]->line[i].nsp;
						win->alines[ 0 ]->line[i].nsp
							= np;
					}
				}
			}
		}
		for ( i = endx - trcw + 1; i <= endx; i++ ) {
			win->alines[ 0 ]->line[i].ch = topright.vals[ 0 ];
			win->alines[ 0 ]->line[i].attr = topright.attributes;
			np = win->alines[ 0 ]->line[i].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ 0 ]->line[i].nsp = NULL;
			}
			if ( i == endx - trcw + 1 ) {
				SET_WCOL( win->alines[ 0 ]->line[ i ], trcw );
				if ( topright.elements > 1 ) {
					for ( k = 1; k < topright.elements;
							k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = topright.vals[ k ];
						np->next = win->alines[0]->line[i].nsp;
						win->alines[ 0 ]->line[i].nsp
							= np;
					}
				}
			} else
				SET_WCOL( win->alines[ 0 ]->line[ i ],
					  endx - trcw + 1 - i );
		}
		for ( i = 0; i < blcw; i++ ) {
			win->alines[ endy ]->line[i].ch = botleft.vals[ 0 ];
			win->alines[ endy ]->line[i].attr = botleft.attributes;
			np = win->alines[ endy ]->line[i].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ endy ]->line[i].nsp = NULL;
			}
			if ( i )
				SET_WCOL( win->alines[endy]->line[i], -i );
			else {
				SET_WCOL( win->alines[endy]->line[i], blcw );
				if ( botleft.elements > 1 ) {
					for ( k = 1; k < botleft.elements;
							k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = botleft.vals[ k ];
						np->next = win->alines[endy]->line[i].nsp;
						win->alines[endy]->line[i].nsp
							= np;
					}
				}
			}
		}
		for ( i = endx - brcw + 1; i <= endx; i++ ) {
			win->alines[ endy ]->line[i].ch = botright.vals[ 0 ];
			win->alines[ endy ]->line[i].attr = botright.attributes;
			np = win->alines[ endy ]->line[i].nsp;
			if (np) {
				while ( np ) {
					tnp = np->next;
					free( np );
					np = tnp;
				}
				win->alines[ endy ]->line[i].nsp = NULL;
			}
			if ( i == endx - brcw + 1 ) {
				SET_WCOL( win->alines[ endy ]->line[ i ],
					  brcw );
				if ( botright.elements > 1 ) {
					for ( k = 1; k < botright.elements; k++ ) {
						np = malloc(sizeof(nschar_t));
						if (!np)
							return ERR;
						np->ch = botright.vals[ k ];
						np->next = win->alines[endy]->line[i].nsp;
						win->alines[endy]->line[i].nsp
							= np;
					}
				}
			} else
				SET_WCOL( win->alines[ endy ]->line[ i ],
					endx - brcw + 1 - i );
		}
	}
	__touchwin(win);
	return (OK);
#endif /* HAVE_WCHAR */
}
Exemple #9
0
/*
 * start_color --
 *	Initialise colour support.
 */
int
start_color(void)
{
	int			 i;
	attr_t			 temp_nc;
	struct __winlist	*wlp;
	WINDOW			*win;
	int			 y, x;

	if (has_colors() == FALSE)
		return(ERR);

	/* Max colours and colour pairs */
	if (max_colors == -1)
		COLORS = 0;
	else {
		COLORS = max_colors > MAX_COLORS ? MAX_COLORS : max_colors;
		if (max_pairs == -1) {
			COLOR_PAIRS = 0;
			COLORS = 0;
		} else {
			COLOR_PAIRS = ((unsigned int)max_pairs > MAX_PAIRS - 1 ?
			    MAX_PAIRS - 1 : max_pairs);
			 /* Use the last colour pair for curses default. */
			__default_color = COLOR_PAIR(MAX_PAIRS - 1);
		}
	}
	if (!COLORS)
		return (ERR);

	_cursesi_screen->COLORS = COLORS;
	_cursesi_screen->COLOR_PAIRS = COLOR_PAIRS;

	/* Reset terminal colour and colour pairs. */
	if (orig_colors != NULL)
		tputs(orig_colors, 0, __cputchar);
	if (orig_pair != NULL) {
		tputs(orig_pair, 0, __cputchar);
		curscr->wattr &= _cursesi_screen->mask_op;
	}

	/* Type of colour manipulation - ANSI/TEK/HP/other */
	if (set_a_foreground != NULL && set_a_background != NULL)
		_cursesi_screen->color_type = COLOR_ANSI;
	else if (initialize_pair != NULL)
		_cursesi_screen->color_type = COLOR_HP;
	else if (initialize_color != NULL)
		_cursesi_screen->color_type = COLOR_TEK;
	else if (set_foreground != NULL && set_background != NULL)
		_cursesi_screen->color_type = COLOR_OTHER;
	else
		return(ERR);		/* Unsupported colour method */

	/*
	 * Attributes that cannot be used with color.
	 * Store these in an attr_t for wattrset()/wattron().
	 */
	_cursesi_screen->nca = __NORMAL;
	if (no_color_video != -1) {
		temp_nc = (attr_t) t_no_color_video(_cursesi_screen->term);
		if (temp_nc & 0x0001)
			_cursesi_screen->nca |= __STANDOUT;
		if (temp_nc & 0x0002)
			_cursesi_screen->nca |= __UNDERSCORE;
		if (temp_nc & 0x0004)
			_cursesi_screen->nca |= __REVERSE;
		if (temp_nc & 0x0008)
			_cursesi_screen->nca |= __BLINK;
		if (temp_nc & 0x0010)
			_cursesi_screen->nca |= __DIM;
		if (temp_nc & 0x0020)
			_cursesi_screen->nca |= __BOLD;
		if (temp_nc & 0x0040)
			_cursesi_screen->nca |= __BLANK;
		if (temp_nc & 0x0080)
			_cursesi_screen->nca |= __PROTECT;
		if (temp_nc & 0x0100)
			_cursesi_screen->nca |= __ALTCHARSET;
	}

	/* Set up initial 8 colours */
	if (COLORS >= COLOR_BLACK)
		(void) init_color(COLOR_BLACK, 0, 0, 0);
	if (COLORS >= COLOR_RED)
		(void) init_color(COLOR_RED, 1000, 0, 0);
	if (COLORS >= COLOR_GREEN)
		(void) init_color(COLOR_GREEN, 0, 1000, 0);
	if (COLORS >= COLOR_YELLOW)
		(void) init_color(COLOR_YELLOW, 1000, 1000, 0);
	if (COLORS >= COLOR_BLUE)
		(void) init_color(COLOR_BLUE, 0, 0, 1000);
	if (COLORS >= COLOR_MAGENTA)
		(void) init_color(COLOR_MAGENTA, 1000, 0, 1000);
	if (COLORS >= COLOR_CYAN)
		(void) init_color(COLOR_CYAN, 0, 1000, 1000);
	if (COLORS >= COLOR_WHITE)
		(void) init_color(COLOR_WHITE, 1000, 1000, 1000);

	/* Initialise other colours */
	for (i = 8; i < COLORS; i++) {
		_cursesi_screen->colours[i].red = 0;
		_cursesi_screen->colours[i].green = 0;
		_cursesi_screen->colours[i].blue = 0;
		_cursesi_screen->colours[i].flags = 0;
	}

	/* Initialise pair 0 to default colours. */
	_cursesi_screen->colour_pairs[0].fore = -1;
	_cursesi_screen->colour_pairs[0].back = -1;
	_cursesi_screen->colour_pairs[0].flags = 0;

	/* Initialise user colour pairs to default (white on black) */
	for (i = 0; i < COLOR_PAIRS; i++) {
		_cursesi_screen->colour_pairs[i].fore = COLOR_WHITE;
		_cursesi_screen->colour_pairs[i].back = COLOR_BLACK;
		_cursesi_screen->colour_pairs[i].flags = 0;
	}

	/* Initialise default colour pair. */
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore =
	    __default_pair.fore;
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back =
	    __default_pair.back;
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags =
	    __default_pair.flags;

	__using_color = 1;

	/* Set all positions on all windows to curses default colours. */
	for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) {
		win = wlp->winp;
		if (wlp->winp != __virtscr && wlp->winp != curscr) {
			/* Set color attribute on other windows */
			win->battr |= __default_color;
			for (y = 0; y < win->maxy; y++) {
				for (x = 0; x < win->maxx; x++) {
					win->alines[y]->line[x].attr &= ~__COLOR;
					win->alines[y]->line[x].attr |= __default_color;
				}
			}
			__touchwin(win);
		}
	}

	return(OK);
}