/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56bkgd7----89### Synopsis1011int bkgd(chtype ch);12void bkgdset(chtype ch);13chtype getbkgd(WINDOW *win);14int wbkgd(WINDOW *win, chtype ch);15void wbkgdset(WINDOW *win, chtype ch);1617int bkgrnd(const cchar_t *wch);18void bkgrndset(const cchar_t *wch);19int getbkgrnd(cchar_t *wch);20int wbkgrnd(WINDOW *win, const cchar_t *wch);21void wbkgrndset(WINDOW *win, const cchar_t *wch);22int wgetbkgrnd(WINDOW *win, cchar_t *wch);2324### Description2526bkgdset() and wbkgdset() manipulate the background of a window. The27background is a chtype consisting of any combination of attributes28and a character; it is combined with each chtype added or inserted to29the window by waddch() or winsch(). Only the attribute part is used30to set the background of non-blank characters, while both character31and attributes are used for blank positions.3233bkgd() and wbkgd() not only change the background, but apply it34immediately to every cell in the window.3536wbkgrnd(), wbkgrndset() and wgetbkgrnd() are the "wide-character"37versions of these functions, taking a pointer to a cchar_t instead of38a chtype. However, in PDCurses, cchar_t and chtype are the same.3940The attributes that are defined with the attrset()/attron() set of41functions take precedence over the background attributes if there is42a conflict (e.g., different color pairs).4344### Return Value4546bkgd() and wbkgd() return OK, unless the window is NULL, in which47case they return ERR.4849### Portability50X/Open ncurses NetBSD51bkgd Y Y Y52bkgdset Y Y Y53getbkgd Y Y Y54wbkgd Y Y Y55wbkgdset Y Y Y56bkgrnd Y Y Y57bkgrndset Y Y Y58getbkgrnd Y Y Y59wbkgrnd Y Y Y60wbkgrndset Y Y Y61wgetbkgrnd Y Y Y6263**man-end****************************************************************/6465int wbkgd(WINDOW *win, chtype ch)66{67int x, y;68chtype oldcolr, oldch, newcolr, newch, colr, attr;69chtype oldattr = 0, newattr = 0;70chtype *winptr;7172PDC_LOG(("wbkgd() - called\n"));7374if (!win)75return ERR;7677if (win->_bkgd == ch)78return OK;7980oldcolr = win->_bkgd & A_COLOR;81if (oldcolr)82oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr;8384oldch = win->_bkgd & A_CHARTEXT;8586wbkgdset(win, ch);8788newcolr = win->_bkgd & A_COLOR;89if (newcolr)90newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr;9192newch = win->_bkgd & A_CHARTEXT;9394/* what follows is what seems to occur in the System V95implementation of this routine */9697for (y = 0; y < win->_maxy; y++)98{99for (x = 0; x < win->_maxx; x++)100{101winptr = win->_y[y] + x;102103ch = *winptr;104105/* determine the colors and attributes of the character read106from the window */107108colr = ch & A_COLOR;109attr = ch & (A_ATTRIBUTES ^ A_COLOR);110111/* if the color is the same as the old background color,112then make it the new background color, otherwise leave it */113114if (colr == oldcolr)115colr = newcolr;116117/* remove any attributes (non color) from the character that118were part of the old background, then combine the119remaining ones with the new background */120121attr ^= oldattr;122attr |= newattr;123124/* change character if it is there because it was the old125background character */126127ch &= A_CHARTEXT;128if (ch == oldch)129ch = newch;130131ch |= (attr | colr);132133*winptr = ch;134135}136}137138touchwin(win);139PDC_sync(win);140return OK;141}142143int bkgd(chtype ch)144{145PDC_LOG(("bkgd() - called\n"));146147return wbkgd(stdscr, ch);148}149150void wbkgdset(WINDOW *win, chtype ch)151{152PDC_LOG(("wbkgdset() - called\n"));153154if (win)155{156if (!(ch & A_CHARTEXT))157ch |= ' ';158159win->_bkgd = ch;160}161}162163void bkgdset(chtype ch)164{165PDC_LOG(("bkgdset() - called\n"));166167wbkgdset(stdscr, ch);168}169170chtype getbkgd(WINDOW *win)171{172PDC_LOG(("getbkgd() - called\n"));173174return win ? win->_bkgd : (chtype)ERR;175}176177#ifdef PDC_WIDE178int wbkgrnd(WINDOW *win, const cchar_t *wch)179{180PDC_LOG(("wbkgrnd() - called\n"));181182return wch ? wbkgd(win, *wch) : ERR;183}184185int bkgrnd(const cchar_t *wch)186{187PDC_LOG(("bkgrnd() - called\n"));188189return wbkgrnd(stdscr, wch);190}191192void wbkgrndset(WINDOW *win, const cchar_t *wch)193{194PDC_LOG(("wbkgdset() - called\n"));195196if (wch)197wbkgdset(win, *wch);198}199200void bkgrndset(const cchar_t *wch)201{202PDC_LOG(("bkgrndset() - called\n"));203204wbkgrndset(stdscr, wch);205}206207int wgetbkgrnd(WINDOW *win, cchar_t *wch)208{209PDC_LOG(("wgetbkgrnd() - called\n"));210211if (!win || !wch)212return ERR;213214*wch = win->_bkgd;215216return OK;217}218219int getbkgrnd(cchar_t *wch)220{221PDC_LOG(("getbkgrnd() - called\n"));222223return wgetbkgrnd(stdscr, wch);224}225#endif226227228