diff options
Diffstat (limited to 'scripts/kconfig/libcurses/refresh.c')
-rw-r--r-- | scripts/kconfig/libcurses/refresh.c | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/refresh.c b/scripts/kconfig/libcurses/refresh.c new file mode 100644 index 000000000..306f4efb3 --- /dev/null +++ b/scripts/kconfig/libcurses/refresh.c | |||
@@ -0,0 +1,287 @@ | |||
1 | /* PDCurses */ | ||
2 | |||
3 | #include "curspriv.h" | ||
4 | |||
5 | /*man-start************************************************************** | ||
6 | |||
7 | refresh | ||
8 | ------- | ||
9 | |||
10 | ### Synopsis | ||
11 | |||
12 | int refresh(void); | ||
13 | int wrefresh(WINDOW *win); | ||
14 | int wnoutrefresh(WINDOW *win); | ||
15 | int doupdate(void); | ||
16 | int redrawwin(WINDOW *win); | ||
17 | int wredrawln(WINDOW *win, int beg_line, int num_lines); | ||
18 | |||
19 | ### Description | ||
20 | |||
21 | wrefresh() copies the named window to the physical terminal screen, | ||
22 | taking into account what is already there in order to optimize cursor | ||
23 | movement. refresh() does the same, using stdscr. These routines must | ||
24 | be called to get any output on the terminal, as other routines only | ||
25 | manipulate data structures. Unless leaveok() has been enabled, the | ||
26 | physical cursor of the terminal is left at the location of the | ||
27 | window's cursor. | ||
28 | |||
29 | wnoutrefresh() and doupdate() allow multiple updates with more | ||
30 | efficiency than wrefresh() alone. wrefresh() works by first calling | ||
31 | wnoutrefresh(), which copies the named window to the virtual screen. | ||
32 | It then calls doupdate(), which compares the virtual screen to the | ||
33 | physical screen and does the actual update. A series of calls to | ||
34 | wrefresh() will result in alternating calls to wnoutrefresh() and | ||
35 | doupdate(), causing several bursts of output to the screen. By first | ||
36 | calling wnoutrefresh() for each window, it is then possible to call | ||
37 | doupdate() only once. | ||
38 | |||
39 | In PDCurses, redrawwin() is equivalent to touchwin(), and wredrawln() | ||
40 | is the same as touchline(). In some other curses implementations, | ||
41 | there's a subtle distinction, but it has no meaning in PDCurses. | ||
42 | |||
43 | ### Return Value | ||
44 | |||
45 | All functions return OK on success and ERR on error. | ||
46 | |||
47 | ### Portability | ||
48 | X/Open ncurses NetBSD | ||
49 | refresh Y Y Y | ||
50 | wrefresh Y Y Y | ||
51 | wnoutrefresh Y Y Y | ||
52 | doupdate Y Y Y | ||
53 | redrawwin Y Y Y | ||
54 | wredrawln Y Y Y | ||
55 | |||
56 | **man-end****************************************************************/ | ||
57 | |||
58 | #include <string.h> | ||
59 | |||
60 | int wnoutrefresh(WINDOW *win) | ||
61 | { | ||
62 | int begy, begx; /* window's place on screen */ | ||
63 | int i, j; | ||
64 | |||
65 | PDC_LOG(("wnoutrefresh() - called: win=%p\n", win)); | ||
66 | |||
67 | if (!win) | ||
68 | return ERR; | ||
69 | if (is_pad(win)) | ||
70 | return pnoutrefresh(win, | ||
71 | win->_pad._pad_y, | ||
72 | win->_pad._pad_x, | ||
73 | win->_pad._pad_top, | ||
74 | win->_pad._pad_left, | ||
75 | win->_pad._pad_bottom, | ||
76 | win->_pad._pad_right); | ||
77 | |||
78 | begy = win->_begy; | ||
79 | begx = win->_begx; | ||
80 | |||
81 | for (i = 0, j = begy; i < win->_maxy; i++, j++) | ||
82 | { | ||
83 | if (win->_firstch[i] != _NO_CHANGE) | ||
84 | { | ||
85 | chtype *src = win->_y[i]; | ||
86 | chtype *dest = curscr->_y[j] + begx; | ||
87 | |||
88 | int first = win->_firstch[i]; /* first changed */ | ||
89 | int last = win->_lastch[i]; /* last changed */ | ||
90 | |||
91 | /* ignore areas on the outside that are marked as changed, | ||
92 | but really aren't */ | ||
93 | |||
94 | while (first <= last && src[first] == dest[first]) | ||
95 | first++; | ||
96 | |||
97 | while (last >= first && src[last] == dest[last]) | ||
98 | last--; | ||
99 | |||
100 | /* if any have really changed... */ | ||
101 | |||
102 | if (first <= last) | ||
103 | { | ||
104 | memcpy(dest + first, src + first, | ||
105 | (last - first + 1) * sizeof(chtype)); | ||
106 | |||
107 | first += begx; | ||
108 | last += begx; | ||
109 | |||
110 | if (first < curscr->_firstch[j] || | ||
111 | curscr->_firstch[j] == _NO_CHANGE) | ||
112 | curscr->_firstch[j] = first; | ||
113 | |||
114 | if (last > curscr->_lastch[j]) | ||
115 | curscr->_lastch[j] = last; | ||
116 | } | ||
117 | |||
118 | win->_firstch[i] = _NO_CHANGE; /* updated now */ | ||
119 | } | ||
120 | |||
121 | win->_lastch[i] = _NO_CHANGE; /* updated now */ | ||
122 | } | ||
123 | |||
124 | if (win->_clear) | ||
125 | win->_clear = FALSE; | ||
126 | |||
127 | if (!win->_leaveit) | ||
128 | { | ||
129 | curscr->_cury = win->_cury + begy; | ||
130 | curscr->_curx = win->_curx + begx; | ||
131 | } | ||
132 | |||
133 | return OK; | ||
134 | } | ||
135 | |||
136 | int doupdate(void) | ||
137 | { | ||
138 | int y; | ||
139 | bool clearall; | ||
140 | |||
141 | PDC_LOG(("doupdate() - called\n")); | ||
142 | |||
143 | if (!SP || !curscr) | ||
144 | return ERR; | ||
145 | |||
146 | if (isendwin()) /* coming back after endwin() called */ | ||
147 | { | ||
148 | reset_prog_mode(); | ||
149 | clearall = TRUE; | ||
150 | SP->alive = TRUE; /* so isendwin() result is correct */ | ||
151 | } | ||
152 | else | ||
153 | clearall = curscr->_clear; | ||
154 | |||
155 | for (y = 0; y < SP->lines; y++) | ||
156 | { | ||
157 | PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n", | ||
158 | y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ? | ||
159 | "Yes" : "No")); | ||
160 | |||
161 | if (clearall || curscr->_firstch[y] != _NO_CHANGE) | ||
162 | { | ||
163 | int first, last; | ||
164 | |||
165 | chtype *src = curscr->_y[y]; | ||
166 | chtype *dest = SP->lastscr->_y[y]; | ||
167 | |||
168 | if (clearall) | ||
169 | { | ||
170 | first = 0; | ||
171 | last = COLS - 1; | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | first = curscr->_firstch[y]; | ||
176 | last = curscr->_lastch[y]; | ||
177 | } | ||
178 | |||
179 | while (first <= last) | ||
180 | { | ||
181 | int len = 0; | ||
182 | |||
183 | /* build up a run of changed cells; if two runs are | ||
184 | separated by a single unchanged cell, ignore the | ||
185 | break */ | ||
186 | |||
187 | if (clearall) | ||
188 | len = last - first + 1; | ||
189 | else | ||
190 | while (first + len <= last && | ||
191 | (src[first + len] != dest[first + len] || | ||
192 | (len && first + len < last && | ||
193 | src[first + len + 1] != dest[first + len + 1]) | ||
194 | ) | ||
195 | ) | ||
196 | len++; | ||
197 | |||
198 | /* update the screen, and SP->lastscr */ | ||
199 | |||
200 | if (len) | ||
201 | { | ||
202 | PDC_transform_line(y, first, len, src + first); | ||
203 | memcpy(dest + first, src + first, len * sizeof(chtype)); | ||
204 | first += len; | ||
205 | } | ||
206 | |||
207 | /* skip over runs of unchanged cells */ | ||
208 | |||
209 | while (first <= last && src[first] == dest[first]) | ||
210 | first++; | ||
211 | } | ||
212 | |||
213 | curscr->_firstch[y] = _NO_CHANGE; | ||
214 | curscr->_lastch[y] = _NO_CHANGE; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | curscr->_clear = FALSE; | ||
219 | |||
220 | if (SP->visibility) | ||
221 | PDC_gotoyx(curscr->_cury, curscr->_curx); | ||
222 | |||
223 | SP->cursrow = curscr->_cury; | ||
224 | SP->curscol = curscr->_curx; | ||
225 | |||
226 | PDC_doupdate(); | ||
227 | |||
228 | return OK; | ||
229 | } | ||
230 | |||
231 | int wrefresh(WINDOW *win) | ||
232 | { | ||
233 | bool save_clear; | ||
234 | |||
235 | PDC_LOG(("wrefresh() - called\n")); | ||
236 | |||
237 | if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) | ||
238 | return ERR; | ||
239 | |||
240 | save_clear = win->_clear; | ||
241 | |||
242 | if (win == curscr) | ||
243 | curscr->_clear = TRUE; | ||
244 | else | ||
245 | wnoutrefresh(win); | ||
246 | |||
247 | if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols) | ||
248 | curscr->_clear = TRUE; | ||
249 | |||
250 | return doupdate(); | ||
251 | } | ||
252 | |||
253 | int refresh(void) | ||
254 | { | ||
255 | PDC_LOG(("refresh() - called\n")); | ||
256 | |||
257 | return wrefresh(stdscr); | ||
258 | } | ||
259 | |||
260 | int wredrawln(WINDOW *win, int start, int num) | ||
261 | { | ||
262 | int i; | ||
263 | |||
264 | PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n", | ||
265 | win, start, num)); | ||
266 | |||
267 | if (!win || start > win->_maxy || start + num > win->_maxy) | ||
268 | return ERR; | ||
269 | |||
270 | for (i = start; i < start + num; i++) | ||
271 | { | ||
272 | win->_firstch[i] = 0; | ||
273 | win->_lastch[i] = win->_maxx - 1; | ||
274 | } | ||
275 | |||
276 | return OK; | ||
277 | } | ||
278 | |||
279 | int redrawwin(WINDOW *win) | ||
280 | { | ||
281 | PDC_LOG(("redrawwin() - called: win=%p\n", win)); | ||
282 | |||
283 | if (!win) | ||
284 | return ERR; | ||
285 | |||
286 | return wredrawln(win, 0, win->_maxy); | ||
287 | } | ||