2022-04-12 10:03:04 +03:00
|
|
|
/* $NetBSD: background.c,v 1.29 2022/04/12 07:03:04 blymn Exp $ */
|
2000-04-13 01:43:37 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Julian Coleman.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-04-24 18:09:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2022-04-12 10:03:04 +03:00
|
|
|
__RCSID("$NetBSD: background.c,v 1.29 2022/04/12 07:03:04 blymn Exp $");
|
2000-04-24 18:09:41 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2007-05-28 19:01:53 +04:00
|
|
|
#include <stdlib.h>
|
2000-04-13 01:43:37 +04:00
|
|
|
#include "curses.h"
|
|
|
|
#include "curses_private.h"
|
|
|
|
|
2000-04-16 13:52:49 +04:00
|
|
|
/*
|
|
|
|
* bkgdset
|
|
|
|
* Set new background attributes on stdscr.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bkgdset(chtype ch)
|
|
|
|
{
|
|
|
|
wbkgdset(stdscr, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bkgd --
|
2018-11-18 23:26:29 +03:00
|
|
|
* Set new background attributes on stdscr and apply them to its
|
|
|
|
* contents.
|
2000-04-16 13:52:49 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
bkgd(chtype ch)
|
|
|
|
{
|
|
|
|
return(wbkgd(stdscr, ch));
|
|
|
|
}
|
|
|
|
|
2000-04-13 01:43:37 +04:00
|
|
|
/*
|
|
|
|
* wbkgdset
|
2018-11-18 23:26:29 +03:00
|
|
|
* Set new background attributes on the specified window.
|
2000-04-13 01:43:37 +04:00
|
|
|
*/
|
|
|
|
void
|
2000-04-15 17:17:02 +04:00
|
|
|
wbkgdset(WINDOW *win, chtype ch)
|
2000-04-13 01:43:37 +04:00
|
|
|
{
|
2007-01-21 16:25:36 +03:00
|
|
|
__CTRACE(__CTRACE_ATTR, "wbkgdset: (%p), '%s', %08x\n",
|
2018-11-18 21:52:29 +03:00
|
|
|
win, unctrl(ch & __CHARTEXT), ch & __ATTRIBUTES);
|
2002-08-04 20:43:04 +04:00
|
|
|
|
|
|
|
/* Background character. */
|
|
|
|
if (ch & __CHARTEXT)
|
|
|
|
win->bch = (wchar_t) ch & __CHARTEXT;
|
|
|
|
|
|
|
|
/* Background attributes (check colour). */
|
|
|
|
if (__using_color && !(ch & __COLOR))
|
|
|
|
ch |= __default_color;
|
|
|
|
win->battr = (attr_t) ch & __ATTRIBUTES;
|
2000-04-13 01:43:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wbkgd --
|
2018-11-18 23:26:29 +03:00
|
|
|
* Set new background attributes on the specified window and
|
|
|
|
* apply them to its contents.
|
2000-04-13 01:43:37 +04:00
|
|
|
*/
|
|
|
|
int
|
2000-04-15 17:17:02 +04:00
|
|
|
wbkgd(WINDOW *win, chtype ch)
|
2000-04-13 01:43:37 +04:00
|
|
|
{
|
2018-11-19 23:37:04 +03:00
|
|
|
chtype obch;
|
|
|
|
int y, x;
|
2000-04-19 02:44:21 +04:00
|
|
|
|
2007-01-21 16:25:36 +03:00
|
|
|
__CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n",
|
2018-11-18 21:52:29 +03:00
|
|
|
win, unctrl(ch & __CHARTEXT), ch & __ATTRIBUTES);
|
2018-11-19 23:37:04 +03:00
|
|
|
obch = win->bch;
|
2000-04-13 01:43:37 +04:00
|
|
|
wbkgdset(win, ch);
|
2018-11-19 00:01:16 +03:00
|
|
|
|
2018-11-19 23:37:04 +03:00
|
|
|
for (y = 0; y < win->maxy; y++) {
|
2000-04-19 02:44:21 +04:00
|
|
|
for (x = 0; x < win->maxx; x++) {
|
2018-11-19 23:37:04 +03:00
|
|
|
__LDATA *cp = &win->alines[y]->line[x];
|
|
|
|
|
|
|
|
/* Update/switch background characters */
|
|
|
|
if (cp->ch == obch)
|
|
|
|
cp->ch = win->bch;
|
|
|
|
|
|
|
|
/* Update/merge attributes */
|
|
|
|
cp->attr = win->battr | (cp->attr & __ALTCHARSET);
|
2007-09-20 02:13:14 +04:00
|
|
|
#ifdef HAVE_WCHAR
|
2022-01-25 06:05:06 +03:00
|
|
|
cp->wcols = 1;
|
2007-09-20 02:13:14 +04:00
|
|
|
#endif
|
2000-04-19 02:44:21 +04:00
|
|
|
}
|
2018-11-19 23:37:04 +03:00
|
|
|
}
|
2022-04-12 10:03:04 +03:00
|
|
|
__touchwin(win, 1);
|
2018-11-19 23:37:04 +03:00
|
|
|
return OK;
|
2000-04-13 01:43:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getbkgd --
|
|
|
|
* Get current background attributes.
|
2007-05-28 19:01:53 +04:00
|
|
|
*/
|
2000-04-13 01:43:37 +04:00
|
|
|
chtype
|
2000-04-15 17:17:02 +04:00
|
|
|
getbkgd(WINDOW *win)
|
2000-04-13 01:43:37 +04:00
|
|
|
{
|
2002-08-04 20:43:04 +04:00
|
|
|
attr_t battr;
|
|
|
|
|
|
|
|
/* Background attributes (check colour). */
|
|
|
|
battr = win->battr & A_ATTRIBUTES;
|
|
|
|
if (__using_color && ((battr & __COLOR) == __default_color))
|
2018-11-19 01:34:32 +03:00
|
|
|
battr &= ~__COLOR;
|
2002-08-04 20:43:04 +04:00
|
|
|
|
|
|
|
return ((chtype) ((win->bch & A_CHARTEXT) | battr));
|
2000-04-13 01:43:37 +04:00
|
|
|
}
|
2007-05-28 19:01:53 +04:00
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_WCHAR
|
|
|
|
|
|
|
|
void
|
|
|
|
bkgrndset(const cchar_t *wch)
|
2007-05-28 19:01:53 +04:00
|
|
|
{
|
2018-11-19 01:18:02 +03:00
|
|
|
wbkgrndset(stdscr, wch);
|
2007-05-28 19:01:53 +04:00
|
|
|
}
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
|
|
|
|
int
|
2018-11-19 01:18:02 +03:00
|
|
|
bkgrnd(const cchar_t *wch)
|
2007-05-28 19:01:53 +04:00
|
|
|
{
|
2018-11-19 01:18:02 +03:00
|
|
|
return wbkgrnd(stdscr, wch);
|
2007-05-28 19:01:53 +04:00
|
|
|
}
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
|
|
|
|
int
|
2018-11-19 01:18:02 +03:00
|
|
|
getbkgrnd(cchar_t *wch)
|
2007-05-28 19:01:53 +04:00
|
|
|
{
|
2018-11-19 01:18:02 +03:00
|
|
|
return wgetbkgrnd(stdscr, wch);
|
2007-05-28 19:01:53 +04:00
|
|
|
}
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
wbkgrndset(WINDOW *win, const cchar_t *wch)
|
2007-05-28 19:01:53 +04:00
|
|
|
{
|
|
|
|
attr_t battr;
|
|
|
|
nschar_t *np, *tnp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
__CTRACE(__CTRACE_ATTR, "wbkgrndset: (%p), '%s', %x\n",
|
2021-09-06 10:45:48 +03:00
|
|
|
win, (const char *)wunctrl(wch), wch->attributes);
|
2007-05-28 19:01:53 +04:00
|
|
|
|
|
|
|
/* ignore multi-column characters */
|
2017-01-06 16:53:18 +03:00
|
|
|
if (!wch->elements || wcwidth(wch->vals[0]) > 1)
|
2007-05-28 19:01:53 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Background character. */
|
|
|
|
tnp = np = win->bnsp;
|
2017-01-06 16:53:18 +03:00
|
|
|
if (wcwidth( wch->vals[0]))
|
|
|
|
win->bch = wch->vals[0];
|
2007-05-28 19:01:53 +04:00
|
|
|
else {
|
2017-01-06 16:53:18 +03:00
|
|
|
if (!np) {
|
2016-10-23 00:55:06 +03:00
|
|
|
np = malloc(sizeof(nschar_t));
|
2007-05-28 19:01:53 +04:00
|
|
|
if (!np)
|
|
|
|
return;
|
|
|
|
np->next = NULL;
|
|
|
|
win->bnsp = np;
|
|
|
|
}
|
2017-01-06 16:53:18 +03:00
|
|
|
np->ch = wch->vals[0];
|
2007-05-28 19:01:53 +04:00
|
|
|
tnp = np;
|
|
|
|
np = np->next;
|
|
|
|
}
|
|
|
|
/* add non-spacing characters */
|
2017-01-06 16:53:18 +03:00
|
|
|
if (wch->elements > 1) {
|
|
|
|
for (i = 1; i < wch->elements; i++) {
|
2007-05-28 19:01:53 +04:00
|
|
|
if ( !np ) {
|
2016-10-23 00:55:06 +03:00
|
|
|
np = malloc(sizeof(nschar_t));
|
2007-05-28 19:01:53 +04:00
|
|
|
if (!np)
|
|
|
|
return;
|
|
|
|
np->next = NULL;
|
2017-01-06 16:53:18 +03:00
|
|
|
if (tnp)
|
2007-05-28 19:01:53 +04:00
|
|
|
tnp->next = np;
|
|
|
|
else
|
|
|
|
win->bnsp = np;
|
|
|
|
}
|
2017-01-06 16:53:18 +03:00
|
|
|
np->ch = wch->vals[i];
|
2007-05-28 19:01:53 +04:00
|
|
|
tnp = np;
|
|
|
|
np = np->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* clear the old non-spacing characters */
|
2017-01-06 16:53:18 +03:00
|
|
|
while (np) {
|
2007-05-28 19:01:53 +04:00
|
|
|
tnp = np->next;
|
2017-01-06 16:53:18 +03:00
|
|
|
free(np);
|
2007-05-28 19:01:53 +04:00
|
|
|
np = tnp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Background attributes (check colour). */
|
|
|
|
battr = wch->attributes & WA_ATTRIBUTES;
|
|
|
|
if (__using_color && !( battr & __COLOR))
|
|
|
|
battr |= __default_color;
|
|
|
|
win->battr = battr;
|
2022-01-25 06:05:06 +03:00
|
|
|
win->wcols = 1;
|
2007-05-28 19:01:53 +04:00
|
|
|
}
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
|
2018-11-19 01:18:02 +03:00
|
|
|
int
|
|
|
|
wbkgrnd(WINDOW *win, const cchar_t *wch)
|
|
|
|
{
|
|
|
|
__CTRACE(__CTRACE_ATTR, "wbkgrnd: (%p), '%s', %x\n",
|
2021-09-06 10:45:48 +03:00
|
|
|
win, (const char *)wunctrl(wch), wch->attributes);
|
2018-11-19 01:18:02 +03:00
|
|
|
|
|
|
|
/* ignore multi-column characters */
|
|
|
|
if (!wch->elements || wcwidth( wch->vals[ 0 ]) > 1)
|
|
|
|
return ERR;
|
|
|
|
|
|
|
|
wbkgrndset(win, wch);
|
2022-04-12 10:03:04 +03:00
|
|
|
__touchwin(win, 1);
|
2018-11-19 01:18:02 +03:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
int
|
|
|
|
wgetbkgrnd(WINDOW *win, cchar_t *wch)
|
2007-05-28 19:01:53 +04:00
|
|
|
{
|
|
|
|
nschar_t *np;
|
|
|
|
|
|
|
|
/* Background attributes (check colour). */
|
|
|
|
wch->attributes = win->battr & WA_ATTRIBUTES;
|
2018-11-19 01:34:32 +03:00
|
|
|
if (__using_color && ((wch->attributes & __COLOR) == __default_color))
|
|
|
|
wch->attributes &= ~__COLOR;
|
2017-01-06 16:53:18 +03:00
|
|
|
wch->vals[0] = win->bch;
|
2007-05-28 19:01:53 +04:00
|
|
|
wch->elements = 1;
|
|
|
|
np = win->bnsp;
|
|
|
|
if (np) {
|
2017-01-06 16:53:18 +03:00
|
|
|
while (np && wch->elements < CURSES_CCHAR_MAX) {
|
|
|
|
wch->vals[wch->elements++] = np->ch;
|
2007-05-28 19:01:53 +04:00
|
|
|
np = np->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2018-11-19 01:11:38 +03:00
|
|
|
|
|
|
|
#else /* !HAVE_WCHAR */
|
|
|
|
|
|
|
|
void
|
|
|
|
bkgrndset(const cchar_t *wch)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-11-19 01:18:02 +03:00
|
|
|
bkgrnd(const cchar_t *wch)
|
2018-11-19 01:11:38 +03:00
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2018-11-19 01:18:02 +03:00
|
|
|
getbkgrnd(cchar_t *wch)
|
2018-11-19 01:11:38 +03:00
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
wbkgrndset(WINDOW *win, const cchar_t *wch)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 01:18:02 +03:00
|
|
|
int
|
|
|
|
wbkgrnd(WINDOW *win, const cchar_t *wch)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 01:11:38 +03:00
|
|
|
int
|
|
|
|
wgetbkgrnd(WINDOW *win, cchar_t *wch)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !HAVE_WCHAR */
|