X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_pad.c;h=73978fbb8ad270920579054159885262425423a1;hp=af7dd3b501945d9760bace4bcab7fcc955477103;hb=7f4b9f390624835ceb0849965a7f6ff2dcb39d00;hpb=b1f61d9f3aa244512045a6b02e759825d7049d34 diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c index af7dd3b5..73978fbb 100644 --- a/ncurses/base/lib_pad.c +++ b/ncurses/base/lib_pad.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 1998-2010,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +30,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * + * and: Juergen Pfeifer 2009 * ****************************************************************************/ /* @@ -40,37 +43,46 @@ #include -MODULE_ID("$Id: lib_pad.c,v 1.29 2000/04/29 21:19:44 tom Exp $") +MODULE_ID("$Id: lib_pad.c,v 1.48 2020/02/02 23:34:34 tom Exp $") -WINDOW * -newpad(int l, int c) +NCURSES_EXPORT(WINDOW *) +NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c) { WINDOW *win; - chtype *ptr; + NCURSES_CH_T *ptr; int i; - T((T_CALLED("newpad(%d, %d)"), l, c)); + T((T_CALLED("newpad(%p,%d, %d)"), (void *) SP_PARM, l, c)); if (l <= 0 || c <= 0) returnWin(0); - if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL) + win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx l, c, 0, 0, _ISPAD); + if (win == NULL) returnWin(0); for (i = 0; i < l; i++) { if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); - if ((win->_line[i].text = typeCalloc(chtype, ((size_t) c))) == 0) { - _nc_freewin(win); + if ((win->_line[i].text = typeCalloc(NCURSES_CH_T, ((size_t) c))) == 0) { + (void) _nc_freewin(win); returnWin(0); } - for (ptr = win->_line[i].text; ptr < win->_line[i].text + c;) - *ptr++ = ' '; + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ptr++) + SetChar(*ptr, BLANK_TEXT, BLANK_ATTR); } returnWin(win); } -WINDOW * +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(WINDOW *) +newpad(int l, int c) +{ + return NCURSES_SP_NAME(newpad) (CURRENT_SCREEN, l, c); +} +#endif + +NCURSES_EXPORT(WINDOW *) subpad(WINDOW *orig, int l, int c, int begy, int begx) { WINDOW *win = (WINDOW *) 0; @@ -85,33 +97,51 @@ subpad(WINDOW *orig, int l, int c, int begy, int begx) returnWin(win); } -int -prefresh(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +NCURSES_EXPORT(int) +prefresh(WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) { +#if NCURSES_SP_FUNCS + SCREEN *sp = _nc_screen_of(win); +#endif + T((T_CALLED("prefresh()"))); if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, - smaxcol) != ERR - && doupdate() != ERR) { + smaxcol) != ERR + && NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG) != ERR) { returnCode(OK); } returnCode(ERR); } -int -pnoutrefresh(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +NCURSES_EXPORT(int) +pnoutrefresh(WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) { + int i, j; + int m, n; + int pmaxrow; + int pmaxcol; + SCREEN *sp; + +#if USE_SCROLL_HINTS const int my_len = 2; /* parameterize the threshold for hardscroll */ - NCURSES_SIZE_T i, j; - NCURSES_SIZE_T m, n; - NCURSES_SIZE_T pmaxrow; - NCURSES_SIZE_T pmaxcol; NCURSES_SIZE_T displaced; bool wide; +#endif T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), - win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); + (void *) win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); if (win == 0) returnCode(ERR); @@ -119,6 +149,8 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, if (!(win->_flags & _ISPAD)) returnCode(ERR); + sp = _nc_screen_of(win); + /* negative values are interpreted as zero */ if (pminrow < 0) pminrow = 0; @@ -132,8 +164,10 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, pmaxrow = pminrow + smaxrow - sminrow; pmaxcol = pmincol + smaxcol - smincol; - T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); - T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + T((" pminrow + smaxrow - sminrow %ld, win->_maxy %ld", + (long) pmaxrow, (long) win->_maxy)); + T((" pmincol + smaxcol - smincol %ld, win->_maxx %ld", + (long) pmaxcol, (long) win->_maxx)); /* * Trim the caller's screen size back to the actual limits. @@ -147,20 +181,28 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, pmaxcol = pmincol + smaxcol - smincol; } - if (smaxrow > screen_lines - || smaxcol > screen_columns + if (smaxrow >= screen_lines(sp) + || smaxcol >= screen_columns(sp) || sminrow > smaxrow || smincol > smaxcol) returnCode(ERR); T(("pad being refreshed")); +#ifdef TRACE + if (USE_TRACEF(TRACE_UPDATE)) { + _tracedump("...pad", win); + _nc_unlock_global(tracef); + } +#endif /* TRACE */ +#if USE_SCROLL_HINTS if (win->_pad._pad_y >= 0) { displaced = pminrow - win->_pad._pad_y - (sminrow - win->_pad._pad_top); T(("pad being shifted by %d line(s)", displaced)); } else displaced = 0; +#endif /* * For pure efficiency, we'd want to transfer scrolling information @@ -176,17 +218,30 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, * windows). Note that changing this formula will not break any code, * merely change the costs of various update cases. */ - wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); +#if USE_SCROLL_HINTS + wide = (smincol < my_len && smaxcol > (NewScreen(sp)->_maxx - my_len)); +#endif for (i = pminrow, m = sminrow + win->_yoffset; - i <= pmaxrow && m <= newscr->_maxy; - i++, m++) { - register struct ldat *nline = &newscr->_line[m]; + i <= pmaxrow && m <= NewScreen(sp)->_maxy; + i++, m++) { + register struct ldat *nline = &NewScreen(sp)->_line[m]; register struct ldat *oline = &win->_line[i]; - for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { - if (oline->text[j] != nline->text[n]) { - nline->text[n] = oline->text[j]; + NCURSES_CH_T ch = oline->text[j]; +#if USE_WIDEC_SUPPORT + /* + * Special case for leftmost character of the displayed area. + * Only half of a double-width character may be visible. + */ + if (j == pmincol + && j > 0 + && isWidecExt(ch)) { + SetChar(ch, L(' '), AttrOf(oline->text[j - 1])); + } +#endif + if (!CharEq(ch, nline->text[n])) { + nline->text[n] = ch; CHANGED_CELL(nline, n); } } @@ -199,9 +254,9 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, || nind > smaxrow) { nind = _NEWINDEX; } else if (displaced) { - register struct ldat *pline = &curscr->_line[nind]; + register struct ldat *pline = &CurScreen(sp)->_line[nind]; for (j = 0; j <= my_len; j++) { - int k = newscr->_maxx - j; + int k = NewScreen(sp)->_maxx - j; if (pline->text[j] != nline->text[j] || pline->text[k] != nline->text[k]) { nind = _NEWINDEX; @@ -227,16 +282,16 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, for (i = pminrow - 1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) win->_line[i].oldindex = _NEWINDEX; for (i = pmaxrow + 1; (i <= win->_maxy) - && (win->_line[i].oldindex >= 0); i++) + && (win->_line[i].oldindex >= 0); i++) win->_line[i].oldindex = _NEWINDEX; #endif - win->_begx = smincol; - win->_begy = sminrow; + win->_begx = (NCURSES_SIZE_T) smincol; + win->_begy = (NCURSES_SIZE_T) sminrow; if (win->_clear) { win->_clear = FALSE; - newscr->_clear = TRUE; + NewScreen(sp)->_clear = TRUE; } /* @@ -248,10 +303,12 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, && win->_curx >= pmincol && win->_cury <= pmaxrow && win->_curx <= pmaxcol) { - newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; - newscr->_curx = win->_curx - pmincol + win->_begx; + NewScreen(sp)->_cury = (NCURSES_SIZE_T) (win->_cury - pminrow + + win->_begy + win->_yoffset); + NewScreen(sp)->_curx = (NCURSES_SIZE_T) (win->_curx - pmincol + + win->_begx); } - newscr->_leaveok = win->_leaveok; + NewScreen(sp)->_leaveok = win->_leaveok; win->_flags &= ~_HASMOVED; /* @@ -259,20 +316,20 @@ pnoutrefresh(WINDOW *win, int pminrow, int pmincol, * We will use this on subsequent calls to this function to derive * values to stuff into 'oldindex[]' -- for scrolling optimization. */ - win->_pad._pad_y = pminrow; - win->_pad._pad_x = pmincol; - win->_pad._pad_top = sminrow; - win->_pad._pad_left = smincol; - win->_pad._pad_bottom = smaxrow; - win->_pad._pad_right = smaxcol; + win->_pad._pad_y = (NCURSES_SIZE_T) pminrow; + win->_pad._pad_x = (NCURSES_SIZE_T) pmincol; + win->_pad._pad_top = (NCURSES_SIZE_T) sminrow; + win->_pad._pad_left = (NCURSES_SIZE_T) smincol; + win->_pad._pad_bottom = (NCURSES_SIZE_T) smaxrow; + win->_pad._pad_right = (NCURSES_SIZE_T) smaxcol; returnCode(OK); } -int +NCURSES_EXPORT(int) pechochar(WINDOW *pad, const chtype ch) { - T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); + T((T_CALLED("pechochar(%p, %s)"), (void *) pad, _tracechtype(ch))); if (pad == 0) returnCode(ERR); @@ -282,11 +339,11 @@ pechochar(WINDOW *pad, const chtype ch) waddch(pad, ch); prefresh(pad, pad->_pad._pad_y, - pad->_pad._pad_x, - pad->_pad._pad_top, - pad->_pad._pad_left, - pad->_pad._pad_bottom, - pad->_pad._pad_right); + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); returnCode(OK); }