1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
38 * The routines wrefresh() and wnoutrefresh().
42 #include <curses.priv.h>
44 MODULE_ID("$Id: lib_refresh.c,v 1.37 2007/06/30 23:35:43 tom Exp $")
51 T((T_CALLED("wrefresh(%p)"), win));
55 } else if (win == curscr) {
56 curscr->_clear = TRUE;
58 } else if ((code = wnoutrefresh(win)) == OK) {
60 newscr->_clear = TRUE;
63 * Reset the clearok() flag in case it was set for the special
64 * case in hardscroll.c (if we don't reset it here, we'll get 2
65 * refreshes because the flag is copied from stdscr to newscr).
66 * Resetting the flag shouldn't do any harm, anyway.
74 wnoutrefresh(WINDOW *win)
76 NCURSES_SIZE_T limit_x;
77 NCURSES_SIZE_T src_row, src_col;
80 NCURSES_SIZE_T dst_row, dst_col;
85 T((T_CALLED("wnoutrefresh(%p)"), win));
87 if (_nc_tracing & TRACE_UPDATE)
88 _tracedump("...win", win);
92 * This function will break badly if we try to refresh a pad.
95 || (win->_flags & _ISPAD))
98 /* put them here so "win == 0" won't break our code */
102 newscr->_nc_bkgd = win->_nc_bkgd;
103 WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win);
105 /* merge in change information from all subwindows of this window */
110 * For pure efficiency, we'd want to transfer scrolling information
111 * from the window to newscr whenever the window is wide enough that
112 * its update will dominate the cost of the update for the horizontal
113 * band of newscr that it occupies. Unfortunately, this threshold
114 * tends to be complex to estimate, and in any case scrolling the
115 * whole band and rewriting the parts outside win's image would look
116 * really ugly. So. What we do is consider the window "wide" if it
117 * either (a) occupies the whole width of newscr, or (b) occupies
118 * all but at most one column on either vertical edge of the screen
119 * (this caters to fussy people who put boxes around full-screen
120 * windows). Note that changing this formula will not break any code,
121 * merely change the costs of various update cases.
123 wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
126 win->_flags &= ~_HASMOVED;
129 * Microtweaking alert! This double loop is one of the genuine
130 * hot spots in the code. Even gcc doesn't seem to do enough
131 * common-subexpression chunking to make it really tense,
132 * so we'll force the issue.
136 limit_x = win->_maxx;
138 if (limit_x > newscr->_maxx - begx)
139 limit_x = newscr->_maxx - begx;
141 for (src_row = 0, dst_row = begy + win->_yoffset;
142 src_row <= win->_maxy && dst_row <= newscr->_maxy;
143 src_row++, dst_row++) {
144 register struct ldat *nline = &newscr->_line[dst_row];
145 register struct ldat *oline = &win->_line[src_row];
147 if (oline->firstchar != _NOCHANGE) {
148 int last = oline->lastchar;
153 src_col = oline->firstchar;
154 dst_col = src_col + begx;
157 static cchar_t blank = BLANK;
158 int last_col = begx + ((last < win->_maxx)
161 int fix_left = dst_col;
162 int fix_right = last_col;
166 * Check for boundary cases where we may overwrite part of a
167 * multi-column character. For those, wipe the remainder of
168 * the character to blanks.
171 if (isWidecExt(nline->text[j])) {
173 * On the left, we only care about multi-column characters
174 * that extend into the changed region.
176 fix_left = 1 + j - WidecExt(nline->text[j]);
178 fix_left = 0; /* only if cell is corrupt */
182 if (WidecExt(nline->text[j]) != 0) {
184 * On the right, any multi-column character is a problem,
185 * unless it happens to be contained in the change, and
186 * ending at the right boundary of the change. The
187 * computation for 'fix_left' accounts for the left-side of
188 * this character. Find the end of the character.
191 while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
197 * The analysis is simpler if we do the clearing afterwards.
200 for (j = fix_left; j < dst_col; ++j) {
201 nline->text[j] = blank;
202 CHANGED_CELL(nline, j);
204 for (j = last_col + 1; j <= fix_right; ++j) {
205 nline->text[j] = blank;
206 CHANGED_CELL(nline, j);
211 * Copy the changed text.
213 for (; src_col <= last; src_col++, dst_col++) {
214 if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
215 nline->text[dst_col] = oline->text[src_col];
216 CHANGED_CELL(nline, dst_col);
223 int oind = oline->oldindex;
225 nline->oldindex = ((oind == _NEWINDEX)
227 : (begy + oind + win->_yoffset));
229 #endif /* USE_SCROLL_HINTS */
231 oline->firstchar = oline->lastchar = _NOCHANGE;
232 if_USE_SCROLL_HINTS(oline->oldindex = src_row);
237 newscr->_clear = TRUE;
240 if (!win->_leaveok) {
241 newscr->_cury = win->_cury + win->_begy + win->_yoffset;
242 newscr->_curx = win->_curx + win->_begx;
244 newscr->_leaveok = win->_leaveok;
247 if (_nc_tracing & TRACE_UPDATE)
248 _tracedump("newscr", newscr);