1 /****************************************************************************
2 * Copyright (c) 1998-2001,2002 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 ****************************************************************************/
37 * The routines wrefresh() and wnoutrefresh().
41 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_refresh.c,v 1.32 2002/05/26 00:17:04 tom Exp $")
50 T((T_CALLED("wrefresh(%p)"), win));
53 curscr->_clear = TRUE;
55 } else if ((code = wnoutrefresh(win)) == OK) {
57 newscr->_clear = TRUE;
60 * Reset the clearok() flag in case it was set for the special
61 * case in hardscroll.c (if we don't reset it here, we'll get 2
62 * refreshes because the flag is copied from stdscr to newscr).
63 * Resetting the flag shouldn't do any harm, anyway.
71 wnoutrefresh(WINDOW *win)
73 NCURSES_SIZE_T limit_x;
82 T((T_CALLED("wnoutrefresh(%p)"), win));
84 if (_nc_tracing & TRACE_UPDATE)
85 _tracedump("...win", win);
89 * This function will break badly if we try to refresh a pad.
92 || (win->_flags & _ISPAD))
95 /* put them here so "win == 0" won't break our code */
99 newscr->_nc_bkgd = win->_nc_bkgd;
100 newscr->_attrs = win->_attrs;
102 /* merge in change information from all subwindows of this window */
107 * For pure efficiency, we'd want to transfer scrolling information
108 * from the window to newscr whenever the window is wide enough that
109 * its update will dominate the cost of the update for the horizontal
110 * band of newscr that it occupies. Unfortunately, this threshold
111 * tends to be complex to estimate, and in any case scrolling the
112 * whole band and rewriting the parts outside win's image would look
113 * really ugly. So. What we do is consider the window "wide" if it
114 * either (a) occupies the whole width of newscr, or (b) occupies
115 * all but at most one column on either vertical edge of the screen
116 * (this caters to fussy people who put boxes around full-screen
117 * windows). Note that changing this formula will not break any code,
118 * merely change the costs of various update cases.
120 wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
123 win->_flags &= ~_HASMOVED;
126 * Microtweaking alert! This double loop is one of the genuine
127 * hot spots in the code. Even gcc doesn't seem to do enough
128 * common-subexpression chunking to make it really tense,
129 * so we'll force the issue.
133 limit_x = win->_maxx;
135 if (limit_x > newscr->_maxx - begx)
136 limit_x = newscr->_maxx - begx;
138 for (i = 0, m = begy + win->_yoffset;
139 i <= win->_maxy && m <= newscr->_maxy;
141 register struct ldat *nline = &newscr->_line[m];
142 register struct ldat *oline = &win->_line[i];
144 if (oline->firstchar != _NOCHANGE) {
145 int last = oline->lastchar;
150 for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
151 if (!CharEq(oline->text[j], nline->text[n])) {
152 nline->text[n] = oline->text[j];
153 CHANGED_CELL(nline, n);
160 int oind = oline->oldindex;
162 nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind
165 #endif /* USE_SCROLL_HINTS */
167 oline->firstchar = oline->lastchar = _NOCHANGE;
168 if_USE_SCROLL_HINTS(oline->oldindex = i);
173 newscr->_clear = TRUE;
176 if (!win->_leaveok) {
177 newscr->_cury = win->_cury + win->_begy + win->_yoffset;
178 newscr->_curx = win->_curx + win->_begx;
180 newscr->_leaveok = win->_leaveok;
183 if (_nc_tracing & TRACE_UPDATE)
184 _tracedump("newscr", newscr);