diff options
Diffstat (limited to 'scripts/kconfig/libcurses/touch.c')
| -rw-r--r-- | scripts/kconfig/libcurses/touch.c | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/touch.c b/scripts/kconfig/libcurses/touch.c new file mode 100644 index 000000000..7ea0b64b2 --- /dev/null +++ b/scripts/kconfig/libcurses/touch.c | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | /* PDCurses */ | ||
| 2 | |||
| 3 | #include "curspriv.h" | ||
| 4 | |||
| 5 | /*man-start************************************************************** | ||
| 6 | |||
| 7 | touch | ||
| 8 | ----- | ||
| 9 | |||
| 10 | ### Synopsis | ||
| 11 | |||
| 12 | int touchwin(WINDOW *win); | ||
| 13 | int touchline(WINDOW *win, int start, int count); | ||
| 14 | int untouchwin(WINDOW *win); | ||
| 15 | int wtouchln(WINDOW *win, int y, int n, int changed); | ||
| 16 | bool is_linetouched(WINDOW *win, int line); | ||
| 17 | bool is_wintouched(WINDOW *win); | ||
| 18 | |||
| 19 | int touchoverlap(const WINDOW *win1, WINDOW *win2); | ||
| 20 | |||
| 21 | ### Description | ||
| 22 | |||
| 23 | touchwin() and touchline() throw away all information about which | ||
| 24 | parts of the window have been touched, pretending that the entire | ||
| 25 | window has been drawn on. This is sometimes necessary when using | ||
| 26 | overlapping windows, since a change to one window will affect the | ||
| 27 | other window, but the records of which lines have been changed in the | ||
| 28 | other window will not reflect the change. | ||
| 29 | |||
| 30 | untouchwin() marks all lines in the window as unchanged since the | ||
| 31 | last call to wrefresh(). | ||
| 32 | |||
| 33 | wtouchln() makes n lines in the window, starting at line y, look as | ||
| 34 | if they have (changed == 1) or have not (changed == 0) been changed | ||
| 35 | since the last call to wrefresh(). | ||
| 36 | |||
| 37 | is_linetouched() returns TRUE if the specified line in the specified | ||
| 38 | window has been changed since the last call to wrefresh(). | ||
| 39 | |||
| 40 | is_wintouched() returns TRUE if the specified window has been changed | ||
| 41 | since the last call to wrefresh(). | ||
| 42 | |||
| 43 | touchoverlap(win1, win2) marks the portion of win2 which overlaps | ||
| 44 | with win1 as modified. | ||
| 45 | |||
| 46 | ### Return Value | ||
| 47 | |||
| 48 | All functions return OK on success and ERR on error except | ||
| 49 | is_wintouched() and is_linetouched(). | ||
| 50 | |||
| 51 | ### Portability | ||
| 52 | |||
| 53 | Function | X/Open | ncurses | NetBSD | ||
| 54 | :---------------------|:------:|:-------:|:------: | ||
| 55 | touchwin | Y | Y | Y | ||
| 56 | touchline | Y | Y | Y | ||
| 57 | untouchwin | Y | Y | Y | ||
| 58 | wtouchln | Y | Y | Y | ||
| 59 | is_linetouched | Y | Y | Y | ||
| 60 | is_wintouched | Y | Y | Y | ||
| 61 | touchoverlap | - | - | Y | ||
| 62 | |||
| 63 | **man-end****************************************************************/ | ||
| 64 | |||
| 65 | int touchwin(WINDOW *win) | ||
| 66 | { | ||
| 67 | int i; | ||
| 68 | |||
| 69 | PDC_LOG(("touchwin() - called: Win=%x\n", win)); | ||
| 70 | |||
| 71 | if (!win) | ||
| 72 | return ERR; | ||
| 73 | |||
| 74 | for (i = 0; i < win->_maxy; i++) | ||
| 75 | { | ||
| 76 | win->_firstch[i] = 0; | ||
| 77 | win->_lastch[i] = win->_maxx - 1; | ||
| 78 | } | ||
| 79 | |||
| 80 | return OK; | ||
| 81 | } | ||
| 82 | |||
| 83 | int touchline(WINDOW *win, int start, int count) | ||
| 84 | { | ||
| 85 | int i; | ||
| 86 | |||
| 87 | PDC_LOG(("touchline() - called: win=%p start %d count %d\n", | ||
| 88 | win, start, count)); | ||
| 89 | |||
| 90 | if (!win || start > win->_maxy || start + count > win->_maxy) | ||
| 91 | return ERR; | ||
| 92 | |||
| 93 | for (i = start; i < start + count; i++) | ||
| 94 | { | ||
| 95 | win->_firstch[i] = 0; | ||
| 96 | win->_lastch[i] = win->_maxx - 1; | ||
| 97 | } | ||
| 98 | |||
| 99 | return OK; | ||
| 100 | } | ||
| 101 | |||
| 102 | int untouchwin(WINDOW *win) | ||
| 103 | { | ||
| 104 | int i; | ||
| 105 | |||
| 106 | PDC_LOG(("untouchwin() - called: win=%p", win)); | ||
| 107 | |||
| 108 | if (!win) | ||
| 109 | return ERR; | ||
| 110 | |||
| 111 | for (i = 0; i < win->_maxy; i++) | ||
| 112 | { | ||
| 113 | win->_firstch[i] = _NO_CHANGE; | ||
| 114 | win->_lastch[i] = _NO_CHANGE; | ||
| 115 | } | ||
| 116 | |||
| 117 | return OK; | ||
| 118 | } | ||
| 119 | |||
| 120 | int wtouchln(WINDOW *win, int y, int n, int changed) | ||
| 121 | { | ||
| 122 | int i; | ||
| 123 | |||
| 124 | PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n", | ||
| 125 | win, y, n, changed)); | ||
| 126 | |||
| 127 | if (!win || y > win->_maxy || y + n > win->_maxy) | ||
| 128 | return ERR; | ||
| 129 | |||
| 130 | for (i = y; i < y + n; i++) | ||
| 131 | { | ||
| 132 | if (changed) | ||
| 133 | { | ||
| 134 | win->_firstch[i] = 0; | ||
| 135 | win->_lastch[i] = win->_maxx - 1; | ||
| 136 | } | ||
| 137 | else | ||
| 138 | { | ||
| 139 | win->_firstch[i] = _NO_CHANGE; | ||
| 140 | win->_lastch[i] = _NO_CHANGE; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | return OK; | ||
| 145 | } | ||
| 146 | |||
| 147 | bool is_linetouched(WINDOW *win, int line) | ||
| 148 | { | ||
| 149 | PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line)); | ||
| 150 | |||
| 151 | if (!win || line > win->_maxy || line < 0) | ||
| 152 | return FALSE; | ||
| 153 | |||
| 154 | return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE; | ||
| 155 | } | ||
| 156 | |||
| 157 | bool is_wintouched(WINDOW *win) | ||
| 158 | { | ||
| 159 | int i; | ||
| 160 | |||
| 161 | PDC_LOG(("is_wintouched() - called: win=%p\n", win)); | ||
| 162 | |||
| 163 | if (win) | ||
| 164 | for (i = 0; i < win->_maxy; i++) | ||
| 165 | if (win->_firstch[i] != _NO_CHANGE) | ||
| 166 | return TRUE; | ||
| 167 | |||
| 168 | return FALSE; | ||
| 169 | } | ||
| 170 | |||
| 171 | int touchoverlap(const WINDOW *win1, WINDOW *win2) | ||
| 172 | { | ||
| 173 | int y, endy, endx, starty, startx, begy1, begx1, begy2, begx2; | ||
| 174 | |||
| 175 | PDC_LOG(("touchoverlap() - called: win1=%p win2=%p\n", win1, win2)); | ||
| 176 | |||
| 177 | if (!win1 || !win2) | ||
| 178 | return ERR; | ||
| 179 | |||
| 180 | begy1 = win1->_begy; | ||
| 181 | begx1 = win1->_begx; | ||
| 182 | begy2 = win2->_begy; | ||
| 183 | begx2 = win2->_begy; | ||
| 184 | |||
| 185 | starty = max(begy1, begy2); | ||
| 186 | startx = max(begx1, begx2); | ||
| 187 | endy = min(win1->_maxy + begy1, win2->_maxy + begy2); | ||
| 188 | endx = min(win1->_maxx + begx1, win2->_maxx + begx2); | ||
| 189 | |||
| 190 | if (starty >= endy || startx >= endx) | ||
| 191 | return OK; | ||
| 192 | |||
| 193 | starty -= begy2; | ||
| 194 | startx -= begx2; | ||
| 195 | endy -= begy2; | ||
| 196 | endx -= begx2; | ||
| 197 | endx -= 1; | ||
| 198 | |||
| 199 | for (y = starty; y < endy; y++) | ||
| 200 | { | ||
| 201 | int first = win2->_firstch[y]; | ||
| 202 | |||
| 203 | if (first == _NO_CHANGE || win2->_lastch[y] < endx) | ||
| 204 | win2->_lastch[y] = endx; | ||
| 205 | if (first == _NO_CHANGE || first > startx) | ||
| 206 | win2->_firstch[y] = startx; | ||
| 207 | } | ||
| 208 | |||
| 209 | return OK; | ||
| 210 | } | ||
