| 1 |
|
| 2 |
|
| 3 |
#include <curspriv.h> |
| 4 |
|
| 5 |
RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $") |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
int wattroff(WINDOW *win, chtype attrs) |
| 101 |
{ |
| 102 |
PDC_LOG(("wattroff() - called\n")); |
| 103 |
|
| 104 |
if (!win) |
| 105 |
return ERR; |
| 106 |
|
| 107 |
win->_attrs &= (~attrs & A_ATTRIBUTES); |
| 108 |
|
| 109 |
return OK; |
| 110 |
} |
| 111 |
|
| 112 |
int attroff(chtype attrs) |
| 113 |
{ |
| 114 |
PDC_LOG(("attroff() - called\n")); |
| 115 |
|
| 116 |
return wattroff(stdscr, attrs); |
| 117 |
} |
| 118 |
|
| 119 |
int wattron(WINDOW *win, chtype attrs) |
| 120 |
{ |
| 121 |
chtype newcolr, oldcolr, newattr, oldattr; |
| 122 |
|
| 123 |
PDC_LOG(("wattron() - called\n")); |
| 124 |
|
| 125 |
if (!win) |
| 126 |
return ERR; |
| 127 |
|
| 128 |
if ((win->_attrs & A_COLOR) && (attrs & A_COLOR)) |
| 129 |
{ |
| 130 |
oldcolr = win->_attrs & A_COLOR; |
| 131 |
oldattr = win->_attrs ^ oldcolr; |
| 132 |
newcolr = attrs & A_COLOR; |
| 133 |
newattr = (attrs & A_ATTRIBUTES) ^ newcolr; |
| 134 |
newattr |= oldattr; |
| 135 |
win->_attrs = newattr | newcolr; |
| 136 |
} |
| 137 |
else |
| 138 |
win->_attrs |= (attrs & A_ATTRIBUTES); |
| 139 |
|
| 140 |
return OK; |
| 141 |
} |
| 142 |
|
| 143 |
int attron(chtype attrs) |
| 144 |
{ |
| 145 |
PDC_LOG(("attron() - called\n")); |
| 146 |
|
| 147 |
return wattron(stdscr, attrs); |
| 148 |
} |
| 149 |
|
| 150 |
int wattrset(WINDOW *win, chtype attrs) |
| 151 |
{ |
| 152 |
PDC_LOG(("wattrset() - called\n")); |
| 153 |
|
| 154 |
if (!win) |
| 155 |
return ERR; |
| 156 |
|
| 157 |
win->_attrs = attrs & A_ATTRIBUTES; |
| 158 |
|
| 159 |
return OK; |
| 160 |
} |
| 161 |
|
| 162 |
int attrset(chtype attrs) |
| 163 |
{ |
| 164 |
PDC_LOG(("attrset() - called\n")); |
| 165 |
|
| 166 |
return wattrset(stdscr, attrs); |
| 167 |
} |
| 168 |
|
| 169 |
int standend(void) |
| 170 |
{ |
| 171 |
PDC_LOG(("standend() - called\n")); |
| 172 |
|
| 173 |
return wattrset(stdscr, A_NORMAL); |
| 174 |
} |
| 175 |
|
| 176 |
int standout(void) |
| 177 |
{ |
| 178 |
PDC_LOG(("standout() - called\n")); |
| 179 |
|
| 180 |
return wattrset(stdscr, A_STANDOUT); |
| 181 |
} |
| 182 |
|
| 183 |
int wstandend(WINDOW *win) |
| 184 |
{ |
| 185 |
PDC_LOG(("wstandend() - called\n")); |
| 186 |
|
| 187 |
return wattrset(win, A_NORMAL); |
| 188 |
} |
| 189 |
|
| 190 |
int wstandout(WINDOW *win) |
| 191 |
{ |
| 192 |
PDC_LOG(("wstandout() - called\n")); |
| 193 |
|
| 194 |
return wattrset(win, A_STANDOUT); |
| 195 |
} |
| 196 |
|
| 197 |
chtype getattrs(WINDOW *win) |
| 198 |
{ |
| 199 |
return win ? win->_attrs : 0; |
| 200 |
} |
| 201 |
|
| 202 |
int wcolor_set(WINDOW *win, short color_pair, void *opts) |
| 203 |
{ |
| 204 |
PDC_LOG(("wcolor_set() - called\n")); |
| 205 |
|
| 206 |
if (!win) |
| 207 |
return ERR; |
| 208 |
|
| 209 |
win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair); |
| 210 |
|
| 211 |
return OK; |
| 212 |
} |
| 213 |
|
| 214 |
int color_set(short color_pair, void *opts) |
| 215 |
{ |
| 216 |
PDC_LOG(("color_set() - called\n")); |
| 217 |
|
| 218 |
return wcolor_set(stdscr, color_pair, opts); |
| 219 |
} |
| 220 |
|
| 221 |
int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts) |
| 222 |
{ |
| 223 |
PDC_LOG(("wattr_get() - called\n")); |
| 224 |
|
| 225 |
if (!win) |
| 226 |
return ERR; |
| 227 |
|
| 228 |
if (attrs) |
| 229 |
*attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR); |
| 230 |
|
| 231 |
if (color_pair) |
| 232 |
*color_pair = PAIR_NUMBER(win->_attrs); |
| 233 |
|
| 234 |
return OK; |
| 235 |
} |
| 236 |
|
| 237 |
int attr_get(attr_t *attrs, short *color_pair, void *opts) |
| 238 |
{ |
| 239 |
PDC_LOG(("attr_get() - called\n")); |
| 240 |
|
| 241 |
return wattr_get(stdscr, attrs, color_pair, opts); |
| 242 |
} |
| 243 |
|
| 244 |
int wattr_off(WINDOW *win, attr_t attrs, void *opts) |
| 245 |
{ |
| 246 |
PDC_LOG(("wattr_off() - called\n")); |
| 247 |
|
| 248 |
return wattroff(win, attrs); |
| 249 |
} |
| 250 |
|
| 251 |
int attr_off(attr_t attrs, void *opts) |
| 252 |
{ |
| 253 |
PDC_LOG(("attr_off() - called\n")); |
| 254 |
|
| 255 |
return wattroff(stdscr, attrs); |
| 256 |
} |
| 257 |
|
| 258 |
int wattr_on(WINDOW *win, attr_t attrs, void *opts) |
| 259 |
{ |
| 260 |
PDC_LOG(("wattr_off() - called\n")); |
| 261 |
|
| 262 |
return wattron(win, attrs); |
| 263 |
} |
| 264 |
|
| 265 |
int attr_on(attr_t attrs, void *opts) |
| 266 |
{ |
| 267 |
PDC_LOG(("attr_on() - called\n")); |
| 268 |
|
| 269 |
return wattron(stdscr, attrs); |
| 270 |
} |
| 271 |
|
| 272 |
int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts) |
| 273 |
{ |
| 274 |
PDC_LOG(("wattr_set() - called\n")); |
| 275 |
|
| 276 |
if (!win) |
| 277 |
return ERR; |
| 278 |
|
| 279 |
win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair); |
| 280 |
|
| 281 |
return OK; |
| 282 |
} |
| 283 |
|
| 284 |
int attr_set(attr_t attrs, short color_pair, void *opts) |
| 285 |
{ |
| 286 |
PDC_LOG(("attr_get() - called\n")); |
| 287 |
|
| 288 |
return wattr_set(stdscr, attrs, color_pair, opts); |
| 289 |
} |
| 290 |
|
| 291 |
int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts) |
| 292 |
{ |
| 293 |
chtype *dest, newattr; |
| 294 |
int startpos, endpos; |
| 295 |
|
| 296 |
PDC_LOG(("wchgat() - called\n")); |
| 297 |
|
| 298 |
if (!win) |
| 299 |
return ERR; |
| 300 |
|
| 301 |
newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color); |
| 302 |
|
| 303 |
startpos = win->_curx; |
| 304 |
endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1; |
| 305 |
dest = win->_y[win->_cury]; |
| 306 |
|
| 307 |
for (n = startpos; n <= endpos; n++) |
| 308 |
dest[n] = (dest[n] & A_CHARTEXT) | newattr; |
| 309 |
|
| 310 |
n = win->_cury; |
| 311 |
|
| 312 |
if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE) |
| 313 |
win->_firstch[n] = startpos; |
| 314 |
|
| 315 |
if (endpos > win->_lastch[n]) |
| 316 |
win->_lastch[n] = endpos; |
| 317 |
|
| 318 |
PDC_sync(win); |
| 319 |
|
| 320 |
return OK; |
| 321 |
} |
| 322 |
|
| 323 |
int chgat(int n, attr_t attr, short color, const void *opts) |
| 324 |
{ |
| 325 |
PDC_LOG(("chgat() - called\n")); |
| 326 |
|
| 327 |
return wchgat(stdscr, n, attr, color, opts); |
| 328 |
} |
| 329 |
|
| 330 |
int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts) |
| 331 |
{ |
| 332 |
PDC_LOG(("mvchgat() - called\n")); |
| 333 |
|
| 334 |
if (move(y, x) == ERR) |
| 335 |
return ERR; |
| 336 |
|
| 337 |
return wchgat(stdscr, n, attr, color, opts); |
| 338 |
} |
| 339 |
|
| 340 |
int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color, |
| 341 |
const void *opts) |
| 342 |
{ |
| 343 |
PDC_LOG(("mvwchgat() - called\n")); |
| 344 |
|
| 345 |
if (wmove(win, y, x) == ERR) |
| 346 |
return ERR; |
| 347 |
|
| 348 |
return wchgat(win, n, attr, color, opts); |
| 349 |
} |