diff options
Diffstat (limited to 'scripts/kconfig/libcurses/refresh.c')
| -rw-r--r-- | scripts/kconfig/libcurses/refresh.c | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/refresh.c b/scripts/kconfig/libcurses/refresh.c new file mode 100644 index 000000000..1dce414e5 --- /dev/null +++ b/scripts/kconfig/libcurses/refresh.c | |||
| @@ -0,0 +1,289 @@ | |||
| 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 | |||
| 49 | Function | X/Open | ncurses | NetBSD | ||
| 50 | :---------------------|:------:|:-------:|:------: | ||
| 51 | refresh | Y | Y | Y | ||
| 52 | wrefresh | Y | Y | Y | ||
| 53 | wnoutrefresh | Y | Y | Y | ||
| 54 | doupdate | Y | Y | Y | ||
| 55 | redrawwin | Y | Y | Y | ||
| 56 | wredrawln | Y | Y | Y | ||
| 57 | |||
| 58 | **man-end****************************************************************/ | ||
| 59 | |||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | int wnoutrefresh(WINDOW *win) | ||
| 63 | { | ||
| 64 | int begy, begx; /* window's place on screen */ | ||
| 65 | int i, j; | ||
| 66 | |||
| 67 | PDC_LOG(("wnoutrefresh() - called: win=%p\n", win)); | ||
| 68 | |||
| 69 | if (!win) | ||
| 70 | return ERR; | ||
| 71 | if (is_pad(win)) | ||
| 72 | return pnoutrefresh(win, | ||
| 73 | win->_pad._pad_y, | ||
| 74 | win->_pad._pad_x, | ||
| 75 | win->_pad._pad_top, | ||
| 76 | win->_pad._pad_left, | ||
| 77 | win->_pad._pad_bottom, | ||
| 78 | win->_pad._pad_right); | ||
| 79 | |||
| 80 | begy = win->_begy; | ||
| 81 | begx = win->_begx; | ||
| 82 | |||
| 83 | for (i = 0, j = begy; i < win->_maxy; i++, j++) | ||
| 84 | { | ||
| 85 | if (win->_firstch[i] != _NO_CHANGE) | ||
| 86 | { | ||
| 87 | chtype *src = win->_y[i]; | ||
| 88 | chtype *dest = curscr->_y[j] + begx; | ||
| 89 | |||
| 90 | int first = win->_firstch[i]; /* first changed */ | ||
| 91 | int last = win->_lastch[i]; /* last changed */ | ||
| 92 | |||
| 93 | /* ignore areas on the outside that are marked as changed, | ||
| 94 | but really aren't */ | ||
| 95 | |||
| 96 | while (first <= last && src[first] == dest[first]) | ||
| 97 | first++; | ||
| 98 | |||
| 99 | while (last >= first && src[last] == dest[last]) | ||
| 100 | last--; | ||
| 101 | |||
| 102 | /* if any have really changed... */ | ||
| 103 | |||
| 104 | if (first <= last) | ||
| 105 | { | ||
| 106 | memcpy(dest + first, src + first, | ||
| 107 | (last - first + 1) * sizeof(chtype)); | ||
| 108 | |||
| 109 | first += begx; | ||
| 110 | last += begx; | ||
| 111 | |||
| 112 | if (first < curscr->_firstch[j] || | ||
| 113 | curscr->_firstch[j] == _NO_CHANGE) | ||
| 114 | curscr->_firstch[j] = first; | ||
| 115 | |||
| 116 | if (last > curscr->_lastch[j]) | ||
| 117 | curscr->_lastch[j] = last; | ||
| 118 | } | ||
| 119 | |||
| 120 | win->_firstch[i] = _NO_CHANGE; /* updated now */ | ||
| 121 | } | ||
| 122 | |||
| 123 | win->_lastch[i] = _NO_CHANGE; /* updated now */ | ||
| 124 | } | ||
| 125 | |||
| 126 | if (win->_clear) | ||
| 127 | win->_clear = FALSE; | ||
| 128 | |||
| 129 | if (!win->_leaveit) | ||
| 130 | { | ||
| 131 | curscr->_cury = win->_cury + begy; | ||
| 132 | curscr->_curx = win->_curx + begx; | ||
| 133 | } | ||
| 134 | |||
| 135 | return OK; | ||
| 136 | } | ||
| 137 | |||
| 138 | int doupdate(void) | ||
| 139 | { | ||
| 140 | int y; | ||
| 141 | bool clearall; | ||
| 142 | |||
| 143 | PDC_LOG(("doupdate() - called\n")); | ||
| 144 | |||
| 145 | if (!SP || !curscr) | ||
| 146 | return ERR; | ||
| 147 | |||
| 148 | if (isendwin()) /* coming back after endwin() called */ | ||
| 149 | { | ||
| 150 | reset_prog_mode(); | ||
| 151 | clearall = TRUE; | ||
| 152 | SP->alive = TRUE; /* so isendwin() result is correct */ | ||
| 153 | } | ||
| 154 | else | ||
| 155 | clearall = curscr->_clear; | ||
| 156 | |||
| 157 | for (y = 0; y < SP->lines; y++) | ||
| 158 | { | ||
| 159 | PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n", | ||
| 160 | y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ? | ||
| 161 | "Yes" : "No")); | ||
| 162 | |||
| 163 | if (clearall || curscr->_firstch[y] != _NO_CHANGE) | ||
| 164 | { | ||
| 165 | int first, last; | ||
| 166 | |||
| 167 | chtype *src = curscr->_y[y]; | ||
| 168 | chtype *dest = SP->lastscr->_y[y]; | ||
| 169 | |||
| 170 | if (clearall) | ||
| 171 | { | ||
| 172 | first = 0; | ||
| 173 | last = COLS - 1; | ||
| 174 | } | ||
| 175 | else | ||
| 176 | { | ||
| 177 | first = curscr->_firstch[y]; | ||
| 178 | last = curscr->_lastch[y]; | ||
| 179 | } | ||
| 180 | |||
| 181 | while (first <= last) | ||
| 182 | { | ||
| 183 | int len = 0; | ||
| 184 | |||
| 185 | /* build up a run of changed cells; if two runs are | ||
| 186 | separated by a single unchanged cell, ignore the | ||
| 187 | break */ | ||
| 188 | |||
| 189 | if (clearall) | ||
| 190 | len = last - first + 1; | ||
| 191 | else | ||
| 192 | while (first + len <= last && | ||
| 193 | (src[first + len] != dest[first + len] || | ||
| 194 | (len && first + len < last && | ||
| 195 | src[first + len + 1] != dest[first + len + 1]) | ||
| 196 | ) | ||
| 197 | ) | ||
| 198 | len++; | ||
| 199 | |||
| 200 | /* update the screen, and SP->lastscr */ | ||
| 201 | |||
| 202 | if (len) | ||
| 203 | { | ||
| 204 | PDC_transform_line(y, first, len, src + first); | ||
| 205 | memcpy(dest + first, src + first, len * sizeof(chtype)); | ||
| 206 | first += len; | ||
| 207 | } | ||
| 208 | |||
| 209 | /* skip over runs of unchanged cells */ | ||
| 210 | |||
| 211 | while (first <= last && src[first] == dest[first]) | ||
| 212 | first++; | ||
| 213 | } | ||
| 214 | |||
| 215 | curscr->_firstch[y] = _NO_CHANGE; | ||
| 216 | curscr->_lastch[y] = _NO_CHANGE; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | curscr->_clear = FALSE; | ||
| 221 | |||
| 222 | if (SP->visibility) | ||
| 223 | PDC_gotoyx(curscr->_cury, curscr->_curx); | ||
| 224 | |||
| 225 | SP->cursrow = curscr->_cury; | ||
| 226 | SP->curscol = curscr->_curx; | ||
| 227 | |||
| 228 | PDC_doupdate(); | ||
| 229 | |||
| 230 | return OK; | ||
| 231 | } | ||
| 232 | |||
| 233 | int wrefresh(WINDOW *win) | ||
| 234 | { | ||
| 235 | bool save_clear; | ||
| 236 | |||
| 237 | PDC_LOG(("wrefresh() - called\n")); | ||
| 238 | |||
| 239 | if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) | ||
| 240 | return ERR; | ||
| 241 | |||
| 242 | save_clear = win->_clear; | ||
| 243 | |||
| 244 | if (win == curscr) | ||
| 245 | curscr->_clear = TRUE; | ||
| 246 | else | ||
| 247 | wnoutrefresh(win); | ||
| 248 | |||
| 249 | if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols) | ||
| 250 | curscr->_clear = TRUE; | ||
| 251 | |||
| 252 | return doupdate(); | ||
| 253 | } | ||
| 254 | |||
| 255 | int refresh(void) | ||
| 256 | { | ||
| 257 | PDC_LOG(("refresh() - called\n")); | ||
| 258 | |||
| 259 | return wrefresh(stdscr); | ||
| 260 | } | ||
| 261 | |||
| 262 | int wredrawln(WINDOW *win, int start, int num) | ||
| 263 | { | ||
| 264 | int i; | ||
| 265 | |||
| 266 | PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n", | ||
| 267 | win, start, num)); | ||
| 268 | |||
| 269 | if (!win || start > win->_maxy || start + num > win->_maxy) | ||
| 270 | return ERR; | ||
| 271 | |||
| 272 | for (i = start; i < start + num; i++) | ||
| 273 | { | ||
| 274 | win->_firstch[i] = 0; | ||
| 275 | win->_lastch[i] = win->_maxx - 1; | ||
| 276 | } | ||
| 277 | |||
| 278 | return OK; | ||
| 279 | } | ||
| 280 | |||
| 281 | int redrawwin(WINDOW *win) | ||
| 282 | { | ||
| 283 | PDC_LOG(("redrawwin() - called: win=%p\n", win)); | ||
| 284 | |||
| 285 | if (!win) | ||
| 286 | return ERR; | ||
| 287 | |||
| 288 | return wredrawln(win, 0, win->_maxy); | ||
| 289 | } | ||
