Fix logical background handling by merging it from ncurses 4.1

No new user-visible functions added
This commit is contained in:
Andrey A. Chernov 1997-07-30 17:21:39 +00:00
parent ed29ca4685
commit c8a57a4fe5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27773
14 changed files with 102 additions and 37 deletions

View File

@ -32,8 +32,21 @@ typedef struct sigaction sigaction_t;
#define FG(n) ((n) & 0x0f)
#define BG(n) (((n) & 0xf0) >> 4)
#define TextOf(c) ((c) & (chtype)A_CHARTEXT)
#define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES)
#define BLANK (' '|A_NORMAL)
#define CHANGED -1
#define ALL_BUT_COLOR ((chtype)~(A_COLOR))
/* Macro to put together character and attribute info and return it.
If colors are in the attribute, they have precedence. */
#define ch_or_attr(ch,at) \
((PAIR_NUMBER(at) > 0) ? \
((((chtype)ch) & ALL_BUT_COLOR) | (at)) : ((((chtype)ch) | (at))))
extern WINDOW *newscr;
#ifdef TRACE
@ -51,6 +64,8 @@ extern void init_acs(void);
extern void tstp(int);
extern WINDOW *makenew(int, int, int, int);
extern int timed_wait(int fd, int wait, int *timeleft);
extern chtype _nc_background(WINDOW *);
extern chtype _nc_render(WINDOW *, chtype);
struct try {
struct try *child; /* ptr to child. NULL if none */

View File

@ -13,6 +13,31 @@
#include "curses.priv.h"
#include "unctrl.h"
static inline chtype render_char(WINDOW *win, chtype ch)
/* compute a rendition of the given char correct for the current context */
{
if (TextOf(ch) == ' ')
ch = ch_or_attr(ch, win->_bkgd);
else if (!(ch & A_ATTRIBUTES))
ch = ch_or_attr(ch, (win->_bkgd & A_ATTRIBUTES));
TR(TRACE_VIRTPUT, ("bkg = %#lx -> ch = %#lx", win->_bkgd, ch));
return(ch);
}
chtype _nc_background(WINDOW *win)
/* make render_char() visible while still allowing us to inline it below */
{
return(render_char(win, BLANK));
}
chtype _nc_render(WINDOW *win, chtype ch)
/* make render_char() visible while still allowing us to inline it below */
{
chtype c = render_char(win,ch);
return (ch_or_attr(c,win->_attrs));
}
static int
wladdch(WINDOW *win, chtype c, bool literal)
{
@ -54,13 +79,8 @@ chtype ch = c;
/* FALL THROUGH */
noctrl:
T(("win attr = %x", win->_attrs));
ch |= win->_attrs;
if (win->_line[y][x]&A_CHARTEXT == ' ')
ch |= win->_bkgd;
else
ch |= (win->_bkgd&A_ATTRIBUTES);
T(("bkg = %x -> ch = %x", win->_bkgd, ch));
ch = render_char(win, ch);
ch = ch_or_attr(ch,win->_attrs);
if (win->_line[y][x] != ch) {
if (win->_firstchar[y] == _NOCHANGE)

View File

@ -23,14 +23,26 @@
int wbkgd(WINDOW *win, chtype ch)
{
int x, y;
chtype old_bkgd = getbkgd(win);
chtype new_bkgd = ch;
T(("wbkgd(%x, %x) called", win, ch));
for (y = 0; y <= win->_maxy; y++)
for (x = 0; x <= win->_maxx; x++)
if (win->_line[y][x]&A_CHARTEXT == ' ')
win->_line[y][x] |= ch;
if (TextOf(new_bkgd) == 0)
new_bkgd |= BLANK;
wbkgdset(win, new_bkgd);
wattrset(win, AttrOf(new_bkgd));
for (y = 0; y <= win->_maxy; y++) {
for (x = 0; x <= win->_maxx; x++) {
if (win->_line[y][x] == old_bkgd)
win->_line[y][x] = new_bkgd;
else
win->_line[y][x] |= (ch&A_ATTRIBUTES);
win->_line[y][x] =
TextOf(win->_line[y][x])
| AttrOf(new_bkgd);
}
}
touchwin(win);
return OK;
}

View File

@ -32,14 +32,14 @@ int endx, endy;
if (bl == 0) bl = ACS_LLCORNER;
if (br == 0) br = ACS_LRCORNER;
ls |= win->_attrs;
rs |= win->_attrs;
ts |= win->_attrs;
bs |= win->_attrs;
tl |= win->_attrs;
tr |= win->_attrs;
bl |= win->_attrs;
br |= win->_attrs;
ls = _nc_render(win, ls);
rs = _nc_render(win, rs);
ts = _nc_render(win, ts);
bs = _nc_render(win, bs);
tl = _nc_render(win, tl);
tr = _nc_render(win, tr);
bl = _nc_render(win, bl);
br = _nc_render(win, br);
T(("using %x, %x, %x, %x, %x, %x, %x, %x", ls, rs, ts, bs, tl, tr, bl, br));

View File

@ -12,8 +12,6 @@
#include "curses.priv.h"
#define BLANK ' '|A_NORMAL
int wclrtobot(WINDOW *win)
{
chtype *ptr, *end, *maxx = NULL;
@ -30,11 +28,13 @@ int y, startx, minx;
end = &win->_line[y][win->_maxx];
for (ptr = &win->_line[y][startx]; ptr <= end; ptr++) {
if (*ptr != BLANK) {
chtype blank = _nc_background(win);
if (*ptr != blank) {
maxx = ptr;
if (minx == _NOCHANGE)
minx = ptr - win->_line[y];
*ptr = BLANK;
*ptr = blank;
}
}

View File

@ -12,8 +12,6 @@
#include "curses.priv.h"
#define BLANK ' '|A_NORMAL
int wclrtoeol(WINDOW *win)
{
chtype *maxx, *ptr, *end;
@ -29,11 +27,13 @@ int y, x, minx;
maxx = &win->_line[y][x];
for (ptr = maxx; ptr <= end; ptr++) {
if (*ptr != BLANK) {
chtype blank = _nc_background(win);
if (*ptr != blank) {
maxx = ptr;
if (minx == _NOCHANGE)
minx = ptr - win->_line[y];
*ptr = BLANK;
*ptr = blank;
}
}

View File

@ -17,6 +17,7 @@ int wdelch(WINDOW *win)
{
chtype *temp1, *temp2;
chtype *end;
chtype blank = _nc_background(win);
T(("wdelch(%x) called", win));
@ -27,7 +28,7 @@ chtype *end;
while (temp1 < end)
*temp1++ = *temp2++;
*temp1 = ' ' | win->_attrs;
*temp1 = blank;
win->_lastchar[win->_cury] = win->_maxx;

View File

@ -195,8 +195,6 @@ static int countc(int c)
**
*/
#define BLANK ' '|A_NORMAL
static void ClrUpdate(WINDOW *scr)
{
int i = 0, j = 0;

View File

@ -13,8 +13,6 @@
#include "curses.priv.h"
#include "terminfo.h"
#define BLANK ' '
int werase(WINDOW *win)
{
int y;
@ -33,7 +31,7 @@ int minx;
maxx = sp;
if (minx == _NOCHANGE)
minx = sp - start;
*sp = BLANK;
*sp = _nc_background(win);
}
if (minx != _NOCHANGE) {

View File

@ -26,7 +26,7 @@ chtype *end;
while (temp1 > end)
*temp1-- = *temp2--;
*temp1 = c | win->_attrs;
*temp1 = _nc_render(win, c);
win->_lastchar[win->_cury] = win->_maxx;
if (win->_firstchar[win->_cury] == _NOCHANGE

View File

@ -144,7 +144,7 @@ WINDOW *win;
win->_flags = 0;
win->_attrs = A_NORMAL;
win->_bkgd = ' ';
win->_bkgd = BLANK;
win->_clear = (num_lines == lines && num_columns == columns);
win->_idlok = FALSE;

View File

@ -40,6 +40,23 @@ int m, n;
T(("wnoutrefresh(%x) called", win));
/*
* This function will break badly if we try to refresh a pad.
*/
if ((win == 0)
|| (win->_flags & _ISPAD))
return(ERR);
/*
* If 'newscr' has a different background than the window that we're
* trying to refresh, we'll have to copy the whole thing.
*/
if (win->_bkgd != newscr->_bkgd) {
touchwin(win);
newscr->_bkgd = win->_bkgd;
}
newscr->_attrs = win->_attrs;
win->_flags &= ~_HASMOVED;
for (i = 0, m = begy; i <= win->_maxy; i++, m++) {
if (win->_firstchar[i] != _NOCHANGE) {

View File

@ -21,7 +21,7 @@ void scroll_window(WINDOW *win, int n, int regtop, int regbottom)
int line, i;
chtype *ptr, *temp;
chtype **saved;
chtype blank = ' ';
chtype blank = _nc_background(win);
saved = (chtype **)malloc(sizeof(chtype *) * abs(n));

View File

@ -180,6 +180,10 @@ SLK *slk = SP->_slk;
if (slk == NULL)
return ERR;
slk->hidden = TRUE;
/* For simulated SLK's it's looks much more natural to
inherit those attributes from the standard screen */
slk->win->_bkgd = stdscr->_bkgd;
slk->win->_attrs = stdscr->_attrs;
werase(slk->win);
return wrefresh(slk->win);
}