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; }
wcolor_set(WINDOW *win, short color_pair_number, void *opts) { T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number)); if (win && !opts && (color_pair_number >= 0) && (color_pair_number < COLOR_PAIRS)) { TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win))); SET_WINDOW_PAIR(win, color_pair_number); if_EXT_COLORS(win->_color = color_pair_number); 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; }
wcolor_set(WINDOW *win, short color_pair_number, void *opts) { int code = ERR; T((T_CALLED("wcolor_set(%p,%d)"), (void *) win, color_pair_number)); if (win && !opts && (SP != 0) && (color_pair_number >= 0) && (color_pair_number < SP->_pair_limit)) { TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win))); SET_WINDOW_PAIR(win, color_pair_number); if_EXT_COLORS(win->_color = color_pair_number); 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; }