1 /* Public Domain Curses */
5 RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int attroff(chtype attrs);
13 int wattroff(WINDOW *win, chtype attrs);
14 int attron(chtype attrs);
15 int wattron(WINDOW *win, chtype attrs);
16 int attrset(chtype attrs);
17 int wattrset(WINDOW *win, chtype attrs);
19 int wstandend(WINDOW *win);
21 int wstandout(WINDOW *win);
23 int color_set(short color_pair, void *opts);
24 int wcolor_set(WINDOW *win, short color_pair, void *opts);
26 int attr_get(attr_t *attrs, short *color_pair, void *opts);
27 int attr_off(attr_t attrs, void *opts);
28 int attr_on(attr_t attrs, void *opts);
29 int attr_set(attr_t attrs, short color_pair, void *opts);
30 int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
32 int wattr_off(WINDOW *win, attr_t attrs, void *opts);
33 int wattr_on(WINDOW *win, attr_t attrs, void *opts);
34 int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
37 int chgat(int n, attr_t attr, short color, const void *opts);
38 int mvchgat(int y, int x, int n, attr_t attr, short color,
40 int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
41 short color, const void *opts);
42 int wchgat(WINDOW *win, int n, attr_t attr, short color,
45 chtype getattrs(WINDOW *win);
48 These functions manipulate the current attributes and/or colors
49 of the named window. These attributes can be any combination
50 of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE.
52 These constants are defined in <curses.h> and can be combined
53 with the bitwise-OR operator (|).
55 The current attributes of a window are applied to all chtypes
56 that are written into the window with waddch(). Attributes are
57 a property of the chtype, and move with the character through
58 any scrolling or insert/delete operations.
60 attrset() sets the current attributes of the given window to
61 attrs. attroff() turns off the named attributes without
62 affecting any other attributes; attron() turns them on.
63 color_set() sets the window color to the value of color_pair.
65 standout() is the same as attron(A_STANDOUT). standend() is the
66 same as attrset(A_NORMAL); that is, it turns off all attributes.
69 All functions return OK on success and ERR on error.
71 Portability X/Open BSD SYS V
98 **man-end****************************************************************/
100 int wattroff(WINDOW
*win
, chtype attrs
)
102 PDC_LOG(("wattroff() - called\n"));
107 win
->_attrs
&= (~attrs
& A_ATTRIBUTES
);
112 int attroff(chtype attrs
)
114 PDC_LOG(("attroff() - called\n"));
116 return wattroff(stdscr
, attrs
);
119 int wattron(WINDOW
*win
, chtype attrs
)
121 chtype newcolr
, oldcolr
, newattr
, oldattr
;
123 PDC_LOG(("wattron() - called\n"));
128 if ((win
->_attrs
& A_COLOR
) && (attrs
& A_COLOR
))
130 oldcolr
= win
->_attrs
& A_COLOR
;
131 oldattr
= win
->_attrs
^ oldcolr
;
132 newcolr
= attrs
& A_COLOR
;
133 newattr
= (attrs
& A_ATTRIBUTES
) ^ newcolr
;
135 win
->_attrs
= newattr
| newcolr
;
138 win
->_attrs
|= (attrs
& A_ATTRIBUTES
);
143 int attron(chtype attrs
)
145 PDC_LOG(("attron() - called\n"));
147 return wattron(stdscr
, attrs
);
150 int wattrset(WINDOW
*win
, chtype attrs
)
152 PDC_LOG(("wattrset() - called\n"));
157 win
->_attrs
= attrs
& A_ATTRIBUTES
;
162 int attrset(chtype attrs
)
164 PDC_LOG(("attrset() - called\n"));
166 return wattrset(stdscr
, attrs
);
171 PDC_LOG(("standend() - called\n"));
173 return wattrset(stdscr
, A_NORMAL
);
178 PDC_LOG(("standout() - called\n"));
180 return wattrset(stdscr
, A_STANDOUT
);
183 int wstandend(WINDOW
*win
)
185 PDC_LOG(("wstandend() - called\n"));
187 return wattrset(win
, A_NORMAL
);
190 int wstandout(WINDOW
*win
)
192 PDC_LOG(("wstandout() - called\n"));
194 return wattrset(win
, A_STANDOUT
);
197 chtype
getattrs(WINDOW
*win
)
199 return win
? win
->_attrs
: 0;
202 int wcolor_set(WINDOW
*win
, short color_pair
, void *opts
)
204 PDC_LOG(("wcolor_set() - called\n"));
209 win
->_attrs
= (win
->_attrs
& ~A_COLOR
) | COLOR_PAIR(color_pair
);
214 int color_set(short color_pair
, void *opts
)
216 PDC_LOG(("color_set() - called\n"));
218 return wcolor_set(stdscr
, color_pair
, opts
);
221 int wattr_get(WINDOW
*win
, attr_t
*attrs
, short *color_pair
, void *opts
)
223 PDC_LOG(("wattr_get() - called\n"));
229 *attrs
= win
->_attrs
& (A_ATTRIBUTES
& ~A_COLOR
);
232 *color_pair
= PAIR_NUMBER(win
->_attrs
);
237 int attr_get(attr_t
*attrs
, short *color_pair
, void *opts
)
239 PDC_LOG(("attr_get() - called\n"));
241 return wattr_get(stdscr
, attrs
, color_pair
, opts
);
244 int wattr_off(WINDOW
*win
, attr_t attrs
, void *opts
)
246 PDC_LOG(("wattr_off() - called\n"));
248 return wattroff(win
, attrs
);
251 int attr_off(attr_t attrs
, void *opts
)
253 PDC_LOG(("attr_off() - called\n"));
255 return wattroff(stdscr
, attrs
);
258 int wattr_on(WINDOW
*win
, attr_t attrs
, void *opts
)
260 PDC_LOG(("wattr_off() - called\n"));
262 return wattron(win
, attrs
);
265 int attr_on(attr_t attrs
, void *opts
)
267 PDC_LOG(("attr_on() - called\n"));
269 return wattron(stdscr
, attrs
);
272 int wattr_set(WINDOW
*win
, attr_t attrs
, short color_pair
, void *opts
)
274 PDC_LOG(("wattr_set() - called\n"));
279 win
->_attrs
= (attrs
& (A_ATTRIBUTES
& ~A_COLOR
)) | COLOR_PAIR(color_pair
);
284 int attr_set(attr_t attrs
, short color_pair
, void *opts
)
286 PDC_LOG(("attr_get() - called\n"));
288 return wattr_set(stdscr
, attrs
, color_pair
, opts
);
291 int wchgat(WINDOW
*win
, int n
, attr_t attr
, short color
, const void *opts
)
293 chtype
*dest
, newattr
;
294 int startpos
, endpos
;
296 PDC_LOG(("wchgat() - called\n"));
301 newattr
= (attr
& A_ATTRIBUTES
) | COLOR_PAIR(color
);
303 startpos
= win
->_curx
;
304 endpos
= ((n
< 0) ? win
->_maxx
: min(startpos
+ n
, win
->_maxx
)) - 1;
305 dest
= win
->_y
[win
->_cury
];
307 for (n
= startpos
; n
<= endpos
; n
++)
308 dest
[n
] = (dest
[n
] & A_CHARTEXT
) | newattr
;
312 if (startpos
< win
->_firstch
[n
] || win
->_firstch
[n
] == _NO_CHANGE
)
313 win
->_firstch
[n
] = startpos
;
315 if (endpos
> win
->_lastch
[n
])
316 win
->_lastch
[n
] = endpos
;
323 int chgat(int n
, attr_t attr
, short color
, const void *opts
)
325 PDC_LOG(("chgat() - called\n"));
327 return wchgat(stdscr
, n
, attr
, color
, opts
);
330 int mvchgat(int y
, int x
, int n
, attr_t attr
, short color
, const void *opts
)
332 PDC_LOG(("mvchgat() - called\n"));
334 if (move(y
, x
) == ERR
)
337 return wchgat(stdscr
, n
, attr
, color
, opts
);
340 int mvwchgat(WINDOW
*win
, int y
, int x
, int n
, attr_t attr
, short color
,
343 PDC_LOG(("mvwchgat() - called\n"));
345 if (wmove(win
, y
, x
) == ERR
)
348 return wchgat(win
, n
, attr
, color
, opts
);