1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2010,2011 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 * and: Juergen Pfeifer *
35 ****************************************************************************/
40 * The routines wrefresh() and wnoutrefresh().
44 #include <curses.priv.h>
46 MODULE_ID("$Id: lib_refresh.c,v 1.47 2021/11/06 22:22:03 tom Exp $")
53 SCREEN *SP_PARM = _nc_screen_of(win);
56 T((T_CALLED("wrefresh(%p)"), (void *) win));
60 } else if (win == CurScreen(SP_PARM)) {
61 CurScreen(SP_PARM)->_clear = TRUE;
62 code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
63 } else if ((code = wnoutrefresh(win)) == OK) {
65 NewScreen(SP_PARM)->_clear = TRUE;
66 code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
68 * Reset the clearok() flag in case it was set for the special
69 * case in hardscroll.c (if we don't reset it here, we'll get 2
70 * refreshes because the flag is copied from stdscr to newscr).
71 * Resetting the flag shouldn't do any harm, anyway.
79 wnoutrefresh(WINDOW *win)
90 SCREEN *SP_PARM = _nc_screen_of(win);
93 T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
99 * Handle pads as a special case.
102 returnCode(pnoutrefresh(win,
107 win->_pad._pad_bottom,
108 win->_pad._pad_right));
111 if (USE_TRACEF(TRACE_UPDATE)) {
112 _tracedump("...win", win);
113 _nc_unlock_global(tracef);
117 /* put them here so "win == 0" won't break our code */
121 NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
122 WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
124 /* merge in change information from all subwindows of this window */
129 * For pure efficiency, we'd want to transfer scrolling information
130 * from the window to newscr whenever the window is wide enough that
131 * its update will dominate the cost of the update for the horizontal
132 * band of newscr that it occupies. Unfortunately, this threshold
133 * tends to be complex to estimate, and in any case scrolling the
134 * whole band and rewriting the parts outside win's image would look
135 * really ugly. So. What we do is consider the window "wide" if it
136 * either (a) occupies the whole width of newscr, or (b) occupies
137 * all but at most one column on either vertical edge of the screen
138 * (this caters to fussy people who put boxes around full-screen
139 * windows). Note that changing this formula will not break any code,
140 * merely change the costs of various update cases.
142 wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
145 win->_flags &= ~_HASMOVED;
148 * Microtweaking alert! This double loop is one of the genuine
149 * hot spots in the code. Even gcc doesn't seem to do enough
150 * common-subexpression chunking to make it really tense,
151 * so we'll force the issue.
155 limit_x = win->_maxx;
157 if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
158 limit_x = NewScreen(SP_PARM)->_maxx - begx;
160 for (src_row = 0, dst_row = begy + win->_yoffset;
161 src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
162 src_row++, dst_row++) {
163 struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
164 struct ldat *oline = &win->_line[src_row];
166 if (oline->firstchar != _NOCHANGE) {
167 int last_src = oline->lastchar;
169 if (last_src > limit_x)
172 src_col = oline->firstchar;
173 dst_col = src_col + begx;
179 * Ensure that we will copy complete multi-column characters
180 * on the left-boundary.
182 if (isWidecExt(oline->text[src_col])) {
183 j = 1 + dst_col - WidecExt(oline->text[src_col]);
187 src_col -= (dst_col - j);
193 * Ensure that we will copy complete multi-column characters
194 * on the right-boundary.
197 if (WidecExt(oline->text[j])) {
199 while (j <= limit_x) {
200 if (isWidecBase(oline->text[j])) {
211 static cchar_t blank = BLANK;
212 int last_dst = begx + ((last_src < win->_maxx)
215 int fix_left = dst_col;
216 int fix_right = last_dst;
220 * Check for boundary cases where we may overwrite part of a
221 * multi-column character. For those, wipe the remainder of
222 * the character to blanks.
225 if (isWidecExt(nline->text[j])) {
227 * On the left, we only care about multi-column characters
228 * that extend into the changed region.
230 fix_left = 1 + j - WidecExt(nline->text[j]);
232 fix_left = 0; /* only if cell is corrupt */
236 if (WidecExt(nline->text[j]) != 0) {
238 * On the right, any multi-column character is a problem,
239 * unless it happens to be contained in the change, and
240 * ending at the right boundary of the change. The
241 * computation for 'fix_left' accounts for the left-side of
242 * this character. Find the end of the character.
245 while (j <= NewScreen(SP_PARM)->_maxx &&
246 isWidecExt(nline->text[j])) {
252 * The analysis is simpler if we do the clearing afterwards.
255 if (fix_left < dst_col || fix_right > last_dst) {
256 for (j = fix_left; j <= fix_right; ++j) {
257 nline->text[j] = blank;
258 CHANGED_CELL(nline, j);
264 * Copy the changed text.
266 for (; src_col <= last_src; src_col++, dst_col++) {
267 if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
268 nline->text[dst_col] = oline->text[src_col];
269 CHANGED_CELL(nline, dst_col);
276 int oind = oline->oldindex;
278 nline->oldindex = ((oind == _NEWINDEX)
280 : (begy + oind + win->_yoffset));
282 #endif /* USE_SCROLL_HINTS */
284 oline->firstchar = oline->lastchar = _NOCHANGE;
285 if_USE_SCROLL_HINTS(oline->oldindex = src_row);
290 NewScreen(SP_PARM)->_clear = TRUE;
293 if (!win->_leaveok) {
294 NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
295 win->_begy + win->_yoffset);
296 NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
298 NewScreen(SP_PARM)->_leaveok = win->_leaveok;
301 if (USE_TRACEF(TRACE_UPDATE)) {
302 _tracedump("newscr", NewScreen(SP_PARM));
303 _nc_unlock_global(tracef);