/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56attr7----89### Synopsis1011int attroff(chtype attrs);12int wattroff(WINDOW *win, chtype attrs);13int attron(chtype attrs);14int wattron(WINDOW *win, chtype attrs);15int attrset(chtype attrs);16int wattrset(WINDOW *win, chtype attrs);17int standend(void);18int wstandend(WINDOW *win);19int standout(void);20int wstandout(WINDOW *win);2122int color_set(short color_pair, void *opts);23int wcolor_set(WINDOW *win, short color_pair, void *opts);2425int attr_get(attr_t *attrs, short *color_pair, void *opts);26int attr_off(attr_t attrs, void *opts);27int attr_on(attr_t attrs, void *opts);28int attr_set(attr_t attrs, short color_pair, void *opts);29int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,30void *opts);31int wattr_off(WINDOW *win, attr_t attrs, void *opts);32int wattr_on(WINDOW *win, attr_t attrs, void *opts);33int wattr_set(WINDOW *win, attr_t attrs, short color_pair,34void *opts);3536int chgat(int n, attr_t attr, short color, const void *opts);37int mvchgat(int y, int x, int n, attr_t attr, short color,38const void *opts);39int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,40short color, const void *opts);41int wchgat(WINDOW *win, int n, attr_t attr, short color,42const void *opts);4344chtype getattrs(WINDOW *win);4546int underend(void);47int wunderend(WINDOW *win);48int underscore(void);49int wunderscore(WINDOW *win);5051### Description5253These functions manipulate the current attributes and/or colors of54the named window. These attributes can be any combination of55A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE. These56constants are defined in <curses.h> and can be combined with the57bitwise-OR operator (|).5859The current attributes of a window are applied to all chtypes that60are written into the window with waddch(). Attributes are a property61of the chtype, and move with the character through any scrolling or62insert/delete operations.6364wattrset() sets the current attributes of the given window to attrs.65attrset() is the stdscr version.6667wattroff() turns off the named attributes without affecting any other68attributes; wattron() turns them on.6970wcolor_set() sets the window color to the value of color_pair. opts71is unused.7273standout() is the same as attron(A_STANDOUT). standend() is the same74as attrset(A_NORMAL); that is, it turns off all attributes.7576The attr_* and wattr_* functions are intended for use with the WA_*77attributes. In PDCurses, these are the same as A_*, and there is no78difference in bevahior from the chtype-based functions. In all cases,79opts is unused.8081wattr_get() retrieves the attributes and color pair for the specified82window.8384wchgat() sets the color pair and attributes for the next n cells on85the current line of a given window, without changing the existing86text, or alterting the window's attributes. An n of -1 extends the87change to the edge of the window. The changes take effect88immediately. opts is unused.8990wunderscore() turns on the A_UNDERLINE attribute; wunderend() turns91it off. underscore() and underend() are the stdscr versions.9293### Return Value9495All functions return OK on success and ERR on error.9697### Portability98X/Open ncurses NetBSD99attroff Y Y Y100wattroff Y Y Y101attron Y Y Y102wattron Y Y Y103attrset Y Y Y104wattrset Y Y Y105standend Y Y Y106wstandend Y Y Y107standout Y Y Y108wstandout Y Y Y109color_set Y Y Y110wcolor_set Y Y Y111attr_get Y Y Y112wattr_get Y Y Y113attr_on Y Y Y114wattr_on Y Y Y115attr_off Y Y Y116wattr_off Y Y Y117attr_set Y Y Y118wattr_set Y Y Y119chgat Y Y Y120wchgat Y Y Y121mvchgat Y Y Y122mvwchgat Y Y Y123getattrs - Y Y124underend - - Y125wunderend - - Y126underscore - - Y127wunderscore - - Y128129**man-end****************************************************************/130131int wattroff(WINDOW *win, chtype attrs)132{133PDC_LOG(("wattroff() - called\n"));134135if (!win)136return ERR;137138win->_attrs &= (~attrs & A_ATTRIBUTES);139140return OK;141}142143int attroff(chtype attrs)144{145PDC_LOG(("attroff() - called\n"));146147return wattroff(stdscr, attrs);148}149150int wattron(WINDOW *win, chtype attrs)151{152chtype newcolr, oldcolr, newattr, oldattr;153154PDC_LOG(("wattron() - called\n"));155156if (!win)157return ERR;158159if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))160{161oldcolr = win->_attrs & A_COLOR;162oldattr = win->_attrs ^ oldcolr;163newcolr = attrs & A_COLOR;164newattr = (attrs & A_ATTRIBUTES) ^ newcolr;165newattr |= oldattr;166win->_attrs = newattr | newcolr;167}168else169win->_attrs |= (attrs & A_ATTRIBUTES);170171return OK;172}173174int attron(chtype attrs)175{176PDC_LOG(("attron() - called\n"));177178return wattron(stdscr, attrs);179}180181int wattrset(WINDOW *win, chtype attrs)182{183PDC_LOG(("wattrset() - called\n"));184185if (!win)186return ERR;187188win->_attrs = attrs & A_ATTRIBUTES;189190return OK;191}192193int attrset(chtype attrs)194{195PDC_LOG(("attrset() - called\n"));196197return wattrset(stdscr, attrs);198}199200int standend(void)201{202PDC_LOG(("standend() - called\n"));203204return wattrset(stdscr, A_NORMAL);205}206207int standout(void)208{209PDC_LOG(("standout() - called\n"));210211return wattrset(stdscr, A_STANDOUT);212}213214int wstandend(WINDOW *win)215{216PDC_LOG(("wstandend() - called\n"));217218return wattrset(win, A_NORMAL);219}220221int wstandout(WINDOW *win)222{223PDC_LOG(("wstandout() - called\n"));224225return wattrset(win, A_STANDOUT);226}227228chtype getattrs(WINDOW *win)229{230return win ? win->_attrs : 0;231}232233int wcolor_set(WINDOW *win, short color_pair, void *opts)234{235PDC_LOG(("wcolor_set() - called\n"));236237if (!win)238return ERR;239240win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);241242return OK;243}244245int color_set(short color_pair, void *opts)246{247PDC_LOG(("color_set() - called\n"));248249return wcolor_set(stdscr, color_pair, opts);250}251252int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)253{254PDC_LOG(("wattr_get() - called\n"));255256if (!win)257return ERR;258259if (attrs)260*attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);261262if (color_pair)263*color_pair = PAIR_NUMBER(win->_attrs);264265return OK;266}267268int attr_get(attr_t *attrs, short *color_pair, void *opts)269{270PDC_LOG(("attr_get() - called\n"));271272return wattr_get(stdscr, attrs, color_pair, opts);273}274275int wattr_off(WINDOW *win, attr_t attrs, void *opts)276{277PDC_LOG(("wattr_off() - called\n"));278279return wattroff(win, attrs);280}281282int attr_off(attr_t attrs, void *opts)283{284PDC_LOG(("attr_off() - called\n"));285286return wattroff(stdscr, attrs);287}288289int wattr_on(WINDOW *win, attr_t attrs, void *opts)290{291PDC_LOG(("wattr_off() - called\n"));292293return wattron(win, attrs);294}295296int attr_on(attr_t attrs, void *opts)297{298PDC_LOG(("attr_on() - called\n"));299300return wattron(stdscr, attrs);301}302303int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)304{305PDC_LOG(("wattr_set() - called\n"));306307if (!win)308return ERR;309310win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);311312return OK;313}314315int attr_set(attr_t attrs, short color_pair, void *opts)316{317PDC_LOG(("attr_get() - called\n"));318319return wattr_set(stdscr, attrs, color_pair, opts);320}321322int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)323{324chtype *dest, newattr;325int startpos, endpos;326327PDC_LOG(("wchgat() - called\n"));328329if (!win)330return ERR;331332newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);333334startpos = win->_curx;335endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;336dest = win->_y[win->_cury];337338for (n = startpos; n <= endpos; n++)339dest[n] = (dest[n] & A_CHARTEXT) | newattr;340341n = win->_cury;342343if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)344win->_firstch[n] = startpos;345346if (endpos > win->_lastch[n])347win->_lastch[n] = endpos;348349PDC_sync(win);350351return OK;352}353354int chgat(int n, attr_t attr, short color, const void *opts)355{356PDC_LOG(("chgat() - called\n"));357358return wchgat(stdscr, n, attr, color, opts);359}360361int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)362{363PDC_LOG(("mvchgat() - called\n"));364365if (move(y, x) == ERR)366return ERR;367368return wchgat(stdscr, n, attr, color, opts);369}370371int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,372const void *opts)373{374PDC_LOG(("mvwchgat() - called\n"));375376if (wmove(win, y, x) == ERR)377return ERR;378379return wchgat(win, n, attr, color, opts);380}381382int underend(void)383{384PDC_LOG(("underend() - called\n"));385386return wattroff(stdscr, A_UNDERLINE);387}388389int wunderend(WINDOW *win)390{391PDC_LOG(("wunderend() - called\n"));392393return wattroff(win, A_UNDERLINE);394}395396int underscore(void)397{398PDC_LOG(("underscore() - called\n"));399400return wattron(stdscr, A_UNDERLINE);401}402403int wunderscore(WINDOW *win)404{405PDC_LOG(("wunderscore() - called\n"));406407return wattron(win, A_UNDERLINE);408}409410411