diff options
author | ache <ache@FreeBSD.org> | 1997-07-30 17:21:39 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-07-30 17:21:39 +0000 |
commit | d6cf2089bc5887f137a83ede9767e5154e3b8186 (patch) | |
tree | 2eda095cc49ccd84c07771c2714cb72c8d3a931c /lib | |
parent | 2d46d6b6b7899598c975cea266468603c9a442ba (diff) | |
download | FreeBSD-src-d6cf2089bc5887f137a83ede9767e5154e3b8186.zip FreeBSD-src-d6cf2089bc5887f137a83ede9767e5154e3b8186.tar.gz |
Fix logical background handling by merging it from ncurses 4.1
No new user-visible functions added
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libncurses/curses.priv.h | 15 | ||||
-rw-r--r-- | lib/libncurses/lib_addch.c | 34 | ||||
-rw-r--r-- | lib/libncurses/lib_bkgd.c | 22 | ||||
-rw-r--r-- | lib/libncurses/lib_box.c | 16 | ||||
-rw-r--r-- | lib/libncurses/lib_clrbot.c | 8 | ||||
-rw-r--r-- | lib/libncurses/lib_clreol.c | 8 | ||||
-rw-r--r-- | lib/libncurses/lib_delch.c | 3 | ||||
-rw-r--r-- | lib/libncurses/lib_doupdate.c | 2 | ||||
-rw-r--r-- | lib/libncurses/lib_erase.c | 4 | ||||
-rw-r--r-- | lib/libncurses/lib_insch.c | 2 | ||||
-rw-r--r-- | lib/libncurses/lib_newwin.c | 2 | ||||
-rw-r--r-- | lib/libncurses/lib_refresh.c | 17 | ||||
-rw-r--r-- | lib/libncurses/lib_scroll.c | 2 | ||||
-rw-r--r-- | lib/libncurses/lib_slk.c | 4 |
14 files changed, 102 insertions, 37 deletions
diff --git a/lib/libncurses/curses.priv.h b/lib/libncurses/curses.priv.h index 42952ce..794781e 100644 --- a/lib/libncurses/curses.priv.h +++ b/lib/libncurses/curses.priv.h @@ -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 */ diff --git a/lib/libncurses/lib_addch.c b/lib/libncurses/lib_addch.c index 00684ed..88c826c 100644 --- a/lib/libncurses/lib_addch.c +++ b/lib/libncurses/lib_addch.c @@ -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) diff --git a/lib/libncurses/lib_bkgd.c b/lib/libncurses/lib_bkgd.c index 4b8043a..d75585c 100644 --- a/lib/libncurses/lib_bkgd.c +++ b/lib/libncurses/lib_bkgd.c @@ -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; } diff --git a/lib/libncurses/lib_box.c b/lib/libncurses/lib_box.c index a0ffd12..a467808 100644 --- a/lib/libncurses/lib_box.c +++ b/lib/libncurses/lib_box.c @@ -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)); diff --git a/lib/libncurses/lib_clrbot.c b/lib/libncurses/lib_clrbot.c index fa48db8..e803920 100644 --- a/lib/libncurses/lib_clrbot.c +++ b/lib/libncurses/lib_clrbot.c @@ -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; } } diff --git a/lib/libncurses/lib_clreol.c b/lib/libncurses/lib_clreol.c index a22d6b2..b0a15b9 100644 --- a/lib/libncurses/lib_clreol.c +++ b/lib/libncurses/lib_clreol.c @@ -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; } } diff --git a/lib/libncurses/lib_delch.c b/lib/libncurses/lib_delch.c index bc802ca..0a0fd0a 100644 --- a/lib/libncurses/lib_delch.c +++ b/lib/libncurses/lib_delch.c @@ -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; diff --git a/lib/libncurses/lib_doupdate.c b/lib/libncurses/lib_doupdate.c index 2dba944..39c8b8f 100644 --- a/lib/libncurses/lib_doupdate.c +++ b/lib/libncurses/lib_doupdate.c @@ -195,8 +195,6 @@ static int countc(int c) ** */ -#define BLANK ' '|A_NORMAL - static void ClrUpdate(WINDOW *scr) { int i = 0, j = 0; diff --git a/lib/libncurses/lib_erase.c b/lib/libncurses/lib_erase.c index f7b79c1..38bf5ea 100644 --- a/lib/libncurses/lib_erase.c +++ b/lib/libncurses/lib_erase.c @@ -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) { diff --git a/lib/libncurses/lib_insch.c b/lib/libncurses/lib_insch.c index a86732d..ff30668 100644 --- a/lib/libncurses/lib_insch.c +++ b/lib/libncurses/lib_insch.c @@ -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 diff --git a/lib/libncurses/lib_newwin.c b/lib/libncurses/lib_newwin.c index 793d06e..b58eb07 100644 --- a/lib/libncurses/lib_newwin.c +++ b/lib/libncurses/lib_newwin.c @@ -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; diff --git a/lib/libncurses/lib_refresh.c b/lib/libncurses/lib_refresh.c index 72ab095..9948025 100644 --- a/lib/libncurses/lib_refresh.c +++ b/lib/libncurses/lib_refresh.c @@ -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) { diff --git a/lib/libncurses/lib_scroll.c b/lib/libncurses/lib_scroll.c index 1721a3f..03e7136 100644 --- a/lib/libncurses/lib_scroll.c +++ b/lib/libncurses/lib_scroll.c @@ -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)); diff --git a/lib/libncurses/lib_slk.c b/lib/libncurses/lib_slk.c index 5d59c69..8be6ac0 100644 --- a/lib/libncurses/lib_slk.c +++ b/lib/libncurses/lib_slk.c @@ -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); } |