1 /****************************************************************************
2 * Copyright 2020 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.46 2020/02/02 23:34:34 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));
96 * This function will break badly if we try to refresh a pad.
99 || (win->_flags & _ISPAD))
103 if (USE_TRACEF(TRACE_UPDATE)) {
104 _tracedump("...win", win);
105 _nc_unlock_global(tracef);
109 /* put them here so "win == 0" won't break our code */
113 NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
114 WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
116 /* merge in change information from all subwindows of this window */
121 * For pure efficiency, we'd want to transfer scrolling information
122 * from the window to newscr whenever the window is wide enough that
123 * its update will dominate the cost of the update for the horizontal
124 * band of newscr that it occupies. Unfortunately, this threshold
125 * tends to be complex to estimate, and in any case scrolling the
126 * whole band and rewriting the parts outside win's image would look
127 * really ugly. So. What we do is consider the window "wide" if it
128 * either (a) occupies the whole width of newscr, or (b) occupies
129 * all but at most one column on either vertical edge of the screen
130 * (this caters to fussy people who put boxes around full-screen
131 * windows). Note that changing this formula will not break any code,
132 * merely change the costs of various update cases.
134 wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
137 win->_flags &= ~_HASMOVED;
140 * Microtweaking alert! This double loop is one of the genuine
141 * hot spots in the code. Even gcc doesn't seem to do enough
142 * common-subexpression chunking to make it really tense,
143 * so we'll force the issue.
147 limit_x = win->_maxx;
149 if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
150 limit_x = NewScreen(SP_PARM)->_maxx - begx;
152 for (src_row = 0, dst_row = begy + win->_yoffset;
153 src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
154 src_row++, dst_row++) {
155 struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
156 struct ldat *oline = &win->_line[src_row];
158 if (oline->firstchar != _NOCHANGE) {
159 int last_src = oline->lastchar;
161 if (last_src > limit_x)
164 src_col = oline->firstchar;
165 dst_col = src_col + begx;
171 * Ensure that we will copy complete multi-column characters
172 * on the left-boundary.
174 if (isWidecExt(oline->text[src_col])) {
175 j = 1 + dst_col - WidecExt(oline->text[src_col]);
179 src_col -= (dst_col - j);
185 * Ensure that we will copy complete multi-column characters
186 * on the right-boundary.
189 if (WidecExt(oline->text[j])) {
191 while (j <= limit_x) {
192 if (isWidecBase(oline->text[j])) {
203 static cchar_t blank = BLANK;
204 int last_dst = begx + ((last_src < win->_maxx)
207 int fix_left = dst_col;
208 int fix_right = last_dst;
212 * Check for boundary cases where we may overwrite part of a
213 * multi-column character. For those, wipe the remainder of
214 * the character to blanks.
217 if (isWidecExt(nline->text[j])) {
219 * On the left, we only care about multi-column characters
220 * that extend into the changed region.
222 fix_left = 1 + j - WidecExt(nline->text[j]);
224 fix_left = 0; /* only if cell is corrupt */
228 if (WidecExt(nline->text[j]) != 0) {
230 * On the right, any multi-column character is a problem,
231 * unless it happens to be contained in the change, and
232 * ending at the right boundary of the change. The
233 * computation for 'fix_left' accounts for the left-side of
234 * this character. Find the end of the character.
237 while (j <= NewScreen(SP_PARM)->_maxx &&
238 isWidecExt(nline->text[j])) {
244 * The analysis is simpler if we do the clearing afterwards.
247 if (fix_left < dst_col || fix_right > last_dst) {
248 for (j = fix_left; j <= fix_right; ++j) {
249 nline->text[j] = blank;
250 CHANGED_CELL(nline, j);
256 * Copy the changed text.
258 for (; src_col <= last_src; src_col++, dst_col++) {
259 if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
260 nline->text[dst_col] = oline->text[src_col];
261 CHANGED_CELL(nline, dst_col);
268 int oind = oline->oldindex;
270 nline->oldindex = ((oind == _NEWINDEX)
272 : (begy + oind + win->_yoffset));
274 #endif /* USE_SCROLL_HINTS */
276 oline->firstchar = oline->lastchar = _NOCHANGE;
277 if_USE_SCROLL_HINTS(oline->oldindex = src_row);
282 NewScreen(SP_PARM)->_clear = TRUE;
285 if (!win->_leaveok) {
286 NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
287 win->_begy + win->_yoffset);
288 NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
290 NewScreen(SP_PARM)->_leaveok = win->_leaveok;
293 if (USE_TRACEF(TRACE_UPDATE)) {
294 _tracedump("newscr", NewScreen(SP_PARM));
295 _nc_unlock_global(tracef);