1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/* $OpenBSD: lib_refresh.c,v 1.4 2001/01/22 18:01:43 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
/*
* lib_refresh.c
*
* The routines wrefresh() and wnoutrefresh().
*
*/
#include <curses.priv.h>
MODULE_ID("$From: lib_refresh.c,v 1.28 2000/12/10 02:43:27 tom Exp $")
NCURSES_EXPORT(int)
wrefresh(WINDOW *win)
{
int code;
T((T_CALLED("wrefresh(%p)"), win));
if (win == curscr) {
curscr->_clear = TRUE;
code = doupdate();
} else if ((code = wnoutrefresh(win)) == OK) {
if (win->_clear)
newscr->_clear = TRUE;
code = doupdate();
/*
* Reset the clearok() flag in case it was set for the special
* case in hardscroll.c (if we don't reset it here, we'll get 2
* refreshes because the flag is copied from stdscr to newscr).
* Resetting the flag shouldn't do any harm, anyway.
*/
win->_clear = FALSE;
}
returnCode(code);
}
NCURSES_EXPORT(int)
wnoutrefresh(WINDOW *win)
{
NCURSES_SIZE_T limit_x;
NCURSES_SIZE_T i, j;
NCURSES_SIZE_T begx;
NCURSES_SIZE_T begy;
NCURSES_SIZE_T m, n;
#if USE_SCROLL_HINTS
bool wide;
#endif
T((T_CALLED("wnoutrefresh(%p)"), win));
#ifdef TRACE
if (_nc_tracing & TRACE_UPDATE)
_tracedump("...win", win);
#endif /* TRACE */
/*
* This function will break badly if we try to refresh a pad.
*/
if ((win == 0)
|| (win->_flags & _ISPAD))
returnCode(ERR);
/* put them here so "win == 0" won't break our code */
begx = win->_begx;
begy = win->_begy;
newscr->_bkgd = win->_bkgd;
newscr->_attrs = win->_attrs;
/* merge in change information from all subwindows of this window */
wsyncdown(win);
#if USE_SCROLL_HINTS
/*
* For pure efficiency, we'd want to transfer scrolling information
* from the window to newscr whenever the window is wide enough that
* its update will dominate the cost of the update for the horizontal
* band of newscr that it occupies. Unfortunately, this threshold
* tends to be complex to estimate, and in any case scrolling the
* whole band and rewriting the parts outside win's image would look
* really ugly. So. What we do is consider the window "wide" if it
* either (a) occupies the whole width of newscr, or (b) occupies
* all but at most one column on either vertical edge of the screen
* (this caters to fussy people who put boxes around full-screen
* windows). Note that changing this formula will not break any code,
* merely change the costs of various update cases.
*/
wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
#endif
win->_flags &= ~_HASMOVED;
/*
* Microtweaking alert! This double loop is one of the genuine
* hot spots in the code. Even gcc doesn't seem to do enough
* common-subexpression chunking to make it really tense,
* so we'll force the issue.
*/
/* limit(n) */
limit_x = win->_maxx;
/* limit(j) */
if (limit_x > win->_maxx)
limit_x = win->_maxx;
for (i = 0, m = begy + win->_yoffset;
i <= win->_maxy && m <= newscr->_maxy;
i++, m++) {
register struct ldat *nline = &newscr->_line[m];
register struct ldat *oline = &win->_line[i];
if (oline->firstchar != _NOCHANGE) {
int last = oline->lastchar;
if (last > limit_x)
last = limit_x;
for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
if (oline->text[j] != nline->text[n]) {
nline->text[n] = oline->text[j];
CHANGED_CELL(nline, n);
}
}
}
#if USE_SCROLL_HINTS
if (wide) {
int oind = oline->oldindex;
nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind
+ win->_yoffset;
}
#endif /* USE_SCROLL_HINTS */
oline->firstchar = oline->lastchar = _NOCHANGE;
if_USE_SCROLL_HINTS(oline->oldindex = i);
}
if (win->_clear) {
win->_clear = FALSE;
newscr->_clear = TRUE;
}
if (!win->_leaveok) {
newscr->_cury = win->_cury + win->_begy + win->_yoffset;
newscr->_curx = win->_curx + win->_begx;
}
newscr->_leaveok = win->_leaveok;
#ifdef TRACE
if (_nc_tracing & TRACE_UPDATE)
_tracedump("newscr", newscr);
#endif /* TRACE */
returnCode(OK);
}
|