blob: c808058b81c95d5b7f9809b6ae0fccc1f3b0e0d7 [file] [log] [blame]
Patrick Georgi3b77b722011-07-07 15:41:53 +02001/* Public Domain Curses */
2
3#include <curspriv.h>
4
5RCSID("$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 Reinauere11835e2011-10-31 12:54:00 -070020 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 Georgi3b77b722011-07-07 15:41:53 +020026 change.
27
Stefan Reinauere11835e2011-10-31 12:54:00 -070028 untouchwin() marks all lines in the window as unchanged since
Patrick Georgi3b77b722011-07-07 15:41:53 +020029 the last call to wrefresh().
30
Stefan Reinauere11835e2011-10-31 12:54:00 -070031 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 Georgi3b77b722011-07-07 15:41:53 +020033 changed since the last call to wrefresh().
34
Stefan Reinauere11835e2011-10-31 12:54:00 -070035 is_linetouched() returns TRUE if the specified line in the
36 specified window has been changed since the last call to
Patrick Georgi3b77b722011-07-07 15:41:53 +020037 wrefresh().
38
Stefan Reinauere11835e2011-10-31 12:54:00 -070039 is_wintouched() returns TRUE if the specified window
Patrick Georgi3b77b722011-07-07 15:41:53 +020040 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
56int 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
74int 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
93int 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
111int 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 Reinauere11835e2011-10-31 12:54:00 -0700128 else
Patrick Georgi3b77b722011-07-07 15:41:53 +0200129 {
130 win->_firstch[i] = _NO_CHANGE;
131 win->_lastch[i] = _NO_CHANGE;
132 }
133 }
134
135 return OK;
136}
137
138bool 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
148bool 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}