1 /****************************************************************************
2 * Copyright (c) 1998 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 ****************************************************************************/
39 * The routines wrefresh() and wnoutrefresh().
43 #include <curses.priv.h>
45 MODULE_ID("$Id: lib_refresh.c,v 1.19 1998/02/11 12:13:59 tom Exp $")
47 int wrefresh(WINDOW *win)
51 T((T_CALLED("wrefresh(%p)"), win));
54 curscr->_clear = TRUE;
56 } else if ((code = wnoutrefresh(win)) == OK) {
58 newscr->_clear = TRUE;
61 * Reset the clearok() flag in case it was set for the special
62 * case in hardscroll.c (if we don't reset it here, we'll get 2
63 * refreshes because the flag is copied from stdscr to newscr).
64 * Resetting the flag shouldn't do any harm, anyway.
71 int wnoutrefresh(WINDOW *win)
79 T((T_CALLED("wnoutrefresh(%p)"), win));
81 if (_nc_tracing & TRACE_UPDATE)
82 _tracedump("...win", win);
86 * This function will break badly if we try to refresh a pad.
89 || (win->_flags & _ISPAD))
92 /* put them here so "win == 0" won't break our code */
97 * If 'newscr' has a different background than the window that we're
98 * trying to refresh, we'll have to copy the whole thing.
100 if (win->_bkgd != newscr->_bkgd) {
102 newscr->_bkgd = win->_bkgd;
104 newscr->_attrs = win->_attrs;
106 /* 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));
125 win->_flags &= ~_HASMOVED;
128 * Microtweaking alert! This double loop is one of the genuine
129 * hot spots in the code. Even gcc doesn't seem to do enough
130 * common-subexpression chunking to make it really tense,
131 * so we'll force the issue.
133 for (i = 0, m = begy + win->_yoffset;
134 i <= win->_maxy && m <= newscr->_maxy;
136 register struct ldat *nline = &newscr->_line[m];
137 register struct ldat *oline = &win->_line[i];
139 if (oline->firstchar != _NOCHANGE) {
140 int last = oline->lastchar;
143 if (last > win->_maxx)
146 if (last > newscr->_maxx - begx)
147 last = newscr->_maxx - begx;
149 for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
150 if (oline->text[j] != nline->text[n]) {
151 nline->text[n] = oline->text[j];
153 if (nline->firstchar == _NOCHANGE)
154 nline->firstchar = nline->lastchar = n;
155 else if (n < nline->firstchar)
156 nline->firstchar = n;
157 else if (n > nline->lastchar)
166 int oind = oline->oldindex;
168 nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset;
170 #endif /* USE_SCROLL_HINTS */
172 oline->firstchar = oline->lastchar = _NOCHANGE;
173 if_USE_SCROLL_HINTS(oline->oldindex = i);
178 newscr->_clear = TRUE;
181 if (! win->_leaveok) {
182 newscr->_cury = win->_cury + win->_begy + win->_yoffset;
183 newscr->_curx = win->_curx + win->_begx;
186 if (_nc_tracing & TRACE_UPDATE)
187 _tracedump("newscr", newscr);