NCURSES_SP_NAME(slk_attr_set) (NCURSES_SP_DCLx const attr_t attr, NCURSES_PAIRS_T pair_arg, void *opts) { int code = ERR; int color_pair = pair_arg; T((T_CALLED("slk_attr_set(%p,%s,%d)"), (void *) SP_PARM, _traceattr(attr), color_pair)); set_extended_pair(opts, color_pair); if (SP_PARM != 0 && SP_PARM->_slk != 0 && color_pair >= 0 && color_pair < SP_PARM->_pair_limit) { TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); SetAttr(SP_PARM->_slk->attr, attr); if (color_pair > 0) { SetPair(SP_PARM->_slk->attr, color_pair); } TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); code = OK; } returnCode(code); }
static NCURSES_INLINE NCURSES_CH_T render_char(WINDOW *win, NCURSES_CH_T ch) /* compute a rendition of the given char correct for the current context */ { attr_t a = WINDOW_ATTRS(win); int pair = GetPair(ch); if (ISBLANK(ch) && AttrOf(ch) == A_NORMAL && pair == 0) { /* color/pair in attrs has precedence over bkgrnd */ ch = win->_nc_bkgd; SetAttr(ch, a | AttrOf(win->_nc_bkgd)); if ((pair = GET_WINDOW_PAIR(win)) == 0) pair = GetPair(win->_nc_bkgd); SetPair(ch, pair); } else { /* color in attrs has precedence over bkgrnd */ a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a); /* color in ch has precedence */ if (pair == 0) { if ((pair = GET_WINDOW_PAIR(win)) == 0) pair = GetPair(win->_nc_bkgd); } #if 0 if (pair > 255) { NCURSES_CH_T fixme = ch; SetPair(fixme, pair); } #endif AddAttr(ch, (a & COLOR_MASK(AttrOf(ch)))); SetPair(ch, pair); } TR(TRACE_VIRTPUT, ("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)", _tracech_t2(1, CHREF(win->_nc_bkgd)), GetPair(win->_nc_bkgd), _traceattr(WINDOW_ATTRS(win)), GET_WINDOW_PAIR(win), _tracech_t2(3, CHREF(ch)), GetPair(ch))); return (ch); }
static NCURSES_INLINE void #endif wbkgrndset(WINDOW *win, const ARG_CH_T ch) { T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracech_t(ch))); if (win) { attr_t off = AttrOf(win->_nc_bkgd); attr_t on = AttrOf(CHDEREF(ch)); toggle_attr_off(WINDOW_ATTRS(win), off); toggle_attr_on(WINDOW_ATTRS(win), on); #if NCURSES_EXT_COLORS { int pair; if ((pair = GetPair(win->_nc_bkgd)) != 0) SET_WINDOW_PAIR(win, 0); if ((pair = GetPair(CHDEREF(ch))) != 0) SET_WINDOW_PAIR(win, pair); } #endif if (CharOf(CHDEREF(ch)) == L('\0')) { SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch))); if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch)))); } else { win->_nc_bkgd = CHDEREF(ch); } #if USE_WIDEC_SUPPORT /* * If we're compiled for wide-character support, _bkgrnd is the * preferred location for the background information since it stores * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the * macro getbkgd() will work. */ { cchar_t wch; int tmp; (void) wgetbkgrnd(win, &wch); tmp = _nc_to_char((wint_t) CharOf(wch)); win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp) | (AttrOf(wch) & ALL_BUT_COLOR) | ColorPair(GET_WINDOW_PAIR(win))); } #endif } returnVoid; }
slk_color(short color_pair_number) { T((T_CALLED("slk_color(%d)"), color_pair_number)); if (SP != 0 && SP->_slk != 0 && color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) { TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(SP->_slk->attr)))); SetPair(SP->_slk->attr, color_pair_number); TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); }
slk_attroff(const chtype attr) { T((T_CALLED("slk_attroff(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr)))); RemAttr(SP->_slk->attr, attr); if ((attr & A_COLOR) != 0) { SetPair(SP->_slk->attr, 0); } TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); }
NCURSES_SP_NAME(slk_attron) (NCURSES_SP_DCLx const chtype attr) { T((T_CALLED("slk_attron(%p,%s)"), (void *) SP_PARM, _traceattr(attr))); if (SP_PARM != 0 && SP_PARM->_slk != 0) { TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); AddAttr(SP_PARM->_slk->attr, attr); if ((attr & A_COLOR) != 0) { SetPair(SP_PARM->_slk->attr, PAIR_NUMBER(attr)); } TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); returnCode(OK); } else returnCode(ERR); }
static int update_cost_from_blank(NCURSES_CH_T * to) { int cost = 0; int i; NCURSES_CH_T blank = blankchar; if (back_color_erase) SetPair(blank, GetPair(stdscr->_nc_bkgd)); for (i = TEXTWIDTH; i > 0; i--) if (!(CharEq(blank, *to++))) cost++; return cost; }
slk_attr_set(const attr_t attr, short color_pair_number, void *opts) { T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number)); if (SP != 0 && SP->_slk != 0 && !opts && color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) { TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr)))); SetAttr(SP->_slk->attr, attr); if (color_pair_number > 0) { SetPair(SP->_slk->attr, color_pair_number); } TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); }
_nc_build_wch(WINDOW *win, ARG_CH_T ch) { char *buffer = WINDOW_EXT(win, addch_work); int len; int x = win->_curx; int y = win->_cury; mbstate_t state; wchar_t result; if ((WINDOW_EXT(win, addch_used) != 0) && (WINDOW_EXT(win, addch_x) != x || WINDOW_EXT(win, addch_y) != y)) { /* discard the incomplete multibyte character */ WINDOW_EXT(win, addch_used) = 0; TR(TRACE_VIRTPUT, ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)", WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x), y, x)); } WINDOW_EXT(win, addch_x) = x; WINDOW_EXT(win, addch_y) = y; init_mb(state); buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch)); WINDOW_EXT(win, addch_used) += 1; buffer[WINDOW_EXT(win, addch_used)] = '\0'; if ((len = (int) mbrtowc(&result, buffer, (size_t) WINDOW_EXT(win, addch_used), &state)) > 0) { attr_t attrs = AttrOf(CHDEREF(ch)); if_EXT_COLORS(int pair = GetPair(CHDEREF(ch))); SetChar(CHDEREF(ch), result, attrs); if_EXT_COLORS(SetPair(CHDEREF(ch), pair)); WINDOW_EXT(win, addch_used) = 0; } else if (len == -1) { /* * An error occurred. We could either discard everything, * or assume that the error was in the previous input. * Try the latter. */ TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error")); /* handle this with unctrl() */ WINDOW_EXT(win, addch_used) = 0; } return len; }
setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, short color_pair, const void *opts) { unsigned i; unsigned len; int code = OK; TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"), (void *) wcval, _nc_viswbuf(wch), (unsigned long) attrs, color_pair, opts)); len = (unsigned) wcslen(wch); if (opts != NULL || (len > 1 && wcwidth(wch[0]) < 0)) { code = ERR; } else { if (len > CCHARW_MAX) len = CCHARW_MAX; /* * If we have a following spacing-character, stop at that point. We * are only interested in adding non-spacing characters. */ for (i = 1; i < len; ++i) { if (wcwidth(wch[i]) != 0) { len = i; break; } } memset(wcval, 0, sizeof(*wcval)); if (len != 0) { SetAttr(*wcval, attrs | (attr_t) ColorPair(color_pair)); SetPair(CHDEREF(wcval), color_pair); memcpy(&wcval->chars, wch, len * sizeof(wchar_t)); TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len, _tracecchar_t(wcval))); } } TR(TRACE_CCALLS, (T_RETURN("%d"), code)); return (code); }
NCURSES_SP_NAME(slk_attr_set) (NCURSES_SP_DCLx const attr_t attr, short color_pair_number, void *opts) { int code = ERR; T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number)); if (SP_PARM != 0 && SP_PARM->_slk != 0 && !opts && color_pair_number >= 0 && color_pair_number < SP_PARM->_pair_limit) { TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); SetAttr(SP_PARM->_slk->attr, attr); if (color_pair_number > 0) { SetPair(SP_PARM->_slk->attr, color_pair_number); } TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr)))); code = OK; } returnCode(code); }
static NCURSES_INLINE int wadd_wch_nosync(WINDOW *win, cchar_t ch) /* the workhorse function -- add a character to the given window */ { NCURSES_SIZE_T x, y; wchar_t *s; int tabsize = 8; #if USE_REENTRANT SCREEN *sp = _nc_screen_of(win); #endif /* * If we are using the alternate character set, forget about locale. * Otherwise, if the locale claims the code is printable, treat it that * way. */ if ((AttrOf(ch) & A_ALTCHARSET) || iswprint((wint_t) CharOf(ch))) return wadd_wch_literal(win, ch); /* * Handle carriage control and other codes that are not printable, or are * known to expand to more than one character according to unctrl(). */ x = win->_curx; y = win->_cury; switch (CharOf(ch)) { case '\t': #if USE_REENTRANT tabsize = *ptrTabsize(sp); #else tabsize = TABSIZE; #endif x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize))); /* * Space-fill the tab on the bottom line so that we'll get the * "correct" cursor position. */ if ((!win->_scroll && (y == win->_regbottom)) || (x <= win->_maxx)) { cchar_t blank = blankchar; AddAttr(blank, AttrOf(ch)); while (win->_curx < x) { if (wadd_wch_literal(win, blank) == ERR) return (ERR); } break; } else { wclrtoeol(win); win->_flags |= _WRAPPED; if (newline_forces_scroll(win, &y)) { x = win->_maxx; if (win->_scroll) { scroll(win); x = 0; } } else { x = 0; } } break; case '\n': wclrtoeol(win); if (newline_forces_scroll(win, &y)) { if (win->_scroll) scroll(win); else return (ERR); } /* FALLTHRU */ case '\r': x = 0; win->_flags &= ~_WRAPPED; break; case '\b': if (x == 0) return (OK); x--; win->_flags &= ~_WRAPPED; break; default: if ((s = wunctrl(&ch)) != 0) { while (*s) { cchar_t sch; SetChar(sch, *s++, AttrOf(ch)); if_EXT_COLORS(SetPair(sch, GetPair(ch))); if (wadd_wch_literal(win, sch) == ERR) return ERR; } return OK; } return ERR; } win->_curx = x; win->_cury = y; return OK; }