Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 1 | /* Public Domain Curses */ |
| 2 | |
| 3 | #include <curspriv.h> |
| 4 | |
| 5 | RCSID("$Id: touch.c,v 1.29 2008/07/13 16:08:18 wmcbrine Exp $") |
| 6 | |
| 7 | /*man-start************************************************************** |
| 8 | |
| 9 | Name: touch |
| 10 | |
| 11 | Synopsis: |
| 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 | Description: |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 20 | touchwin() and touchline() throw away all information about |
| 21 | which parts of the window have been touched, pretending that the |
| 22 | entire window has been drawn on. This is sometimes necessary |
| 23 | when using overlapping windows, since a change to one window |
| 24 | will affect the other window, but the records of which lines |
| 25 | have been changed in the other window will not reflect the |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 26 | change. |
| 27 | |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 28 | untouchwin() marks all lines in the window as unchanged since |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 29 | the last call to wrefresh(). |
| 30 | |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 31 | wtouchln() makes n lines in the window, starting at line y, look |
| 32 | as if they have (changed == 1) or have not (changed == 0) been |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 33 | changed since the last call to wrefresh(). |
| 34 | |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 35 | is_linetouched() returns TRUE if the specified line in the |
| 36 | specified window has been changed since the last call to |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 37 | wrefresh(). |
| 38 | |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 39 | is_wintouched() returns TRUE if the specified window |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 40 | has been changed since the last call to wrefresh(). |
| 41 | |
| 42 | Return Value: |
| 43 | All functions return OK on success and ERR on error except |
| 44 | is_wintouched() and is_linetouched(). |
| 45 | |
| 46 | Portability X/Open BSD SYS V |
| 47 | touchwin Y Y Y |
| 48 | touchline Y - 3.0 |
| 49 | untouchwin Y - 4.0 |
| 50 | wtouchln Y Y Y |
| 51 | is_linetouched Y - 4.0 |
| 52 | is_wintouched Y - 4.0 |
| 53 | |
| 54 | **man-end****************************************************************/ |
| 55 | |
| 56 | int touchwin(WINDOW *win) |
| 57 | { |
| 58 | int i; |
| 59 | |
| 60 | PDC_LOG(("touchwin() - called: Win=%x\n", win)); |
| 61 | |
| 62 | if (!win) |
| 63 | return ERR; |
| 64 | |
| 65 | for (i = 0; i < win->_maxy; i++) |
| 66 | { |
| 67 | win->_firstch[i] = 0; |
| 68 | win->_lastch[i] = win->_maxx - 1; |
| 69 | } |
| 70 | |
| 71 | return OK; |
| 72 | } |
| 73 | |
| 74 | int touchline(WINDOW *win, int start, int count) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | PDC_LOG(("touchline() - called: win=%p start %d count %d\n", |
| 79 | win, start, count)); |
| 80 | |
| 81 | if (!win || start > win->_maxy || start + count > win->_maxy) |
| 82 | return ERR; |
| 83 | |
| 84 | for (i = start; i < start + count; i++) |
| 85 | { |
| 86 | win->_firstch[i] = 0; |
| 87 | win->_lastch[i] = win->_maxx - 1; |
| 88 | } |
| 89 | |
| 90 | return OK; |
| 91 | } |
| 92 | |
| 93 | int untouchwin(WINDOW *win) |
| 94 | { |
| 95 | int i; |
| 96 | |
| 97 | PDC_LOG(("untouchwin() - called: win=%p", win)); |
| 98 | |
| 99 | if (!win) |
| 100 | return ERR; |
| 101 | |
| 102 | for (i = 0; i < win->_maxy; i++) |
| 103 | { |
| 104 | win->_firstch[i] = _NO_CHANGE; |
| 105 | win->_lastch[i] = _NO_CHANGE; |
| 106 | } |
| 107 | |
| 108 | return OK; |
| 109 | } |
| 110 | |
| 111 | int wtouchln(WINDOW *win, int y, int n, int changed) |
| 112 | { |
| 113 | int i; |
| 114 | |
| 115 | PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n", |
| 116 | win, y, n, changed)); |
| 117 | |
| 118 | if (!win || y > win->_maxy || y + n > win->_maxy) |
| 119 | return ERR; |
| 120 | |
| 121 | for (i = y; i < y + n; i++) |
| 122 | { |
| 123 | if (changed) |
| 124 | { |
| 125 | win->_firstch[i] = 0; |
| 126 | win->_lastch[i] = win->_maxx - 1; |
| 127 | } |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 128 | else |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 129 | { |
| 130 | win->_firstch[i] = _NO_CHANGE; |
| 131 | win->_lastch[i] = _NO_CHANGE; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return OK; |
| 136 | } |
| 137 | |
| 138 | bool is_linetouched(WINDOW *win, int line) |
| 139 | { |
| 140 | PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line)); |
| 141 | |
| 142 | if (!win || line > win->_maxy || line < 0) |
| 143 | return FALSE; |
| 144 | |
| 145 | return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE; |
| 146 | } |
| 147 | |
| 148 | bool is_wintouched(WINDOW *win) |
| 149 | { |
| 150 | int i; |
| 151 | |
| 152 | PDC_LOG(("is_wintouched() - called: win=%p\n", win)); |
| 153 | |
| 154 | if (win) |
| 155 | for (i = 0; i < win->_maxy; i++) |
| 156 | if (win->_firstch[i] != _NO_CHANGE) |
| 157 | return TRUE; |
| 158 | |
| 159 | return FALSE; |
| 160 | } |