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.24 1999/07/31 11:36:37 juergen 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)
80 T((T_CALLED("wnoutrefresh(%p)"), win));
82 if (_nc_tracing & TRACE_UPDATE)
83 _tracedump("...win", win);
87 * This function will break badly if we try to refresh a pad.
90 || (win->_flags & _ISPAD))
93 /* put them here so "win == 0" won't break our code */
97 newscr->_bkgd = win->_bkgd;
98 newscr->_attrs = win->_attrs;
100 /* merge in change information from all subwindows of this window */
104 * For pure efficiency, we'd want to transfer scrolling information
105 * from the window to newscr whenever the window is wide enough that
106 * its update will dominate the cost of the update for the horizontal
107 * band of newscr that it occupies. Unfortunately, this threshold
108 * tends to be complex to estimate, and in any case scrolling the
109 * whole band and rewriting the parts outside win's image would look
110 * really ugly. So. What we do is consider the window "wide" if it
111 * either (a) occupies the whole width of newscr, or (b) occupies
112 * all but at most one column on either vertical edge of the screen
113 * (this caters to fussy people who put boxes around full-screen
114 * windows). Note that changing this formula will not break any code,
115 * merely change the costs of various update cases.
117 wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
119 win->_flags &= ~_HASMOVED;
122 * Microtweaking alert! This double loop is one of the genuine
123 * hot spots in the code. Even gcc doesn't seem to do enough
124 * common-subexpression chunking to make it really tense,
125 * so we'll force the issue.
129 limit_x = win->_maxx;
131 if (limit_x > win->_maxx)
132 limit_x = win->_maxx;
134 for (i = 0, m = begy + win->_yoffset;
135 i <= win->_maxy && m <= newscr->_maxy;
137 register struct ldat *nline = &newscr->_line[m];
138 register struct ldat *oline = &win->_line[i];
140 if (oline->firstchar != _NOCHANGE) {
141 int last = oline->lastchar;
146 for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
147 if (oline->text[j] != nline->text[n]) {
148 nline->text[n] = oline->text[j];
149 CHANGED_CELL(nline, n);
157 int oind = oline->oldindex;
159 nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset;
161 #endif /* USE_SCROLL_HINTS */
163 oline->firstchar = oline->lastchar = _NOCHANGE;
164 if_USE_SCROLL_HINTS(oline->oldindex = i);
169 newscr->_clear = TRUE;
172 if (! win->_leaveok) {
173 newscr->_cury = win->_cury + win->_begy + win->_yoffset;
174 newscr->_curx = win->_curx + win->_begx;
176 newscr->_leaveok = win->_leaveok;
179 if (_nc_tracing & TRACE_UPDATE)
180 _tracedump("newscr", newscr);