diff options
Diffstat (limited to 'scripts/kconfig/libcurses/pad.c')
-rw-r--r-- | scripts/kconfig/libcurses/pad.c | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/pad.c b/scripts/kconfig/libcurses/pad.c new file mode 100644 index 000000000..3dfdfe5d6 --- /dev/null +++ b/scripts/kconfig/libcurses/pad.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* PDCurses */ | ||
2 | |||
3 | #include "curspriv.h" | ||
4 | |||
5 | /*man-start************************************************************** | ||
6 | |||
7 | pad | ||
8 | --- | ||
9 | |||
10 | ### Synopsis | ||
11 | |||
12 | WINDOW *newpad(int nlines, int ncols); | ||
13 | WINDOW *subpad(WINDOW *orig, int nlines, int ncols, | ||
14 | int begy, int begx); | ||
15 | int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, | ||
16 | int sy2, int sx2); | ||
17 | int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, | ||
18 | int sy2, int sx2); | ||
19 | int pechochar(WINDOW *pad, chtype ch); | ||
20 | int pecho_wchar(WINDOW *pad, const cchar_t *wch); | ||
21 | |||
22 | bool is_pad(const WINDOW *pad); | ||
23 | |||
24 | ### Description | ||
25 | |||
26 | A pad is a special kind of window, which is not restricted by the | ||
27 | screen size, and is not necessarily associated with a particular part | ||
28 | of the screen. You can use a pad when you need a large window, and | ||
29 | only a part of the window will be on the screen at one time. Pads are | ||
30 | not refreshed automatically (e.g., from scrolling or echoing of | ||
31 | input). You can't call wrefresh() with a pad as an argument; use | ||
32 | prefresh() or pnoutrefresh() instead. Note that these routines | ||
33 | require additional parameters to specify the part of the pad to be | ||
34 | displayed, and the location to use on the screen. | ||
35 | |||
36 | newpad() creates a new pad data structure. | ||
37 | |||
38 | subpad() creates a new sub-pad within a pad, at position (begy, | ||
39 | begx), with dimensions of nlines lines and ncols columns. This | ||
40 | position is relative to the pad, and not to the screen as with | ||
41 | subwin. Changes to either the parent pad or sub-pad will affect both. | ||
42 | When using sub-pads, you may need to call touchwin() before calling | ||
43 | prefresh(). | ||
44 | |||
45 | pnoutrefresh() copies the specified pad to the virtual screen. | ||
46 | |||
47 | prefresh() calls pnoutrefresh(), followed by doupdate(). | ||
48 | |||
49 | These routines are analogous to wnoutrefresh() and wrefresh(). (py, | ||
50 | px) specifies the upper left corner of the part of the pad to be | ||
51 | displayed; (sy1, sx1) and (sy2, sx2) describe the screen rectangle | ||
52 | that will contain the selected part of the pad. | ||
53 | |||
54 | pechochar() is functionally equivalent to addch() followed by a call | ||
55 | to prefresh(), with the last-used coordinates and dimensions. | ||
56 | pecho_wchar() is the wide-character version. | ||
57 | |||
58 | is_pad() reports whether the specified window is a pad. | ||
59 | |||
60 | ### Return Value | ||
61 | |||
62 | All functions except is_pad() return OK on success and ERR on error. | ||
63 | |||
64 | ### Portability | ||
65 | X/Open ncurses NetBSD | ||
66 | newpad Y Y Y | ||
67 | subpad Y Y Y | ||
68 | prefresh Y Y Y | ||
69 | pnoutrefresh Y Y Y | ||
70 | pechochar Y Y Y | ||
71 | pecho_wchar Y Y Y | ||
72 | is_pad - Y Y | ||
73 | |||
74 | **man-end****************************************************************/ | ||
75 | |||
76 | #include <string.h> | ||
77 | |||
78 | WINDOW *newpad(int nlines, int ncols) | ||
79 | { | ||
80 | WINDOW *win; | ||
81 | |||
82 | PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols)); | ||
83 | |||
84 | win = PDC_makenew(nlines, ncols, 0, 0); | ||
85 | if (win) | ||
86 | win = PDC_makelines(win); | ||
87 | |||
88 | if (!win) | ||
89 | return (WINDOW *)NULL; | ||
90 | |||
91 | werase(win); | ||
92 | |||
93 | win->_flags = _PAD; | ||
94 | win->_pad._pad_y = 0; | ||
95 | win->_pad._pad_x = 0; | ||
96 | win->_pad._pad_top = 0; | ||
97 | win->_pad._pad_left = 0; | ||
98 | win->_pad._pad_bottom = min(LINES, nlines) - 1; | ||
99 | win->_pad._pad_right = min(COLS, ncols) - 1; | ||
100 | |||
101 | return win; | ||
102 | } | ||
103 | |||
104 | WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) | ||
105 | { | ||
106 | WINDOW *win; | ||
107 | int i; | ||
108 | |||
109 | PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n", | ||
110 | nlines, ncols, begy, begx)); | ||
111 | |||
112 | if (!orig || !(orig->_flags & _PAD)) | ||
113 | return (WINDOW *)NULL; | ||
114 | |||
115 | /* make sure window fits inside the original one */ | ||
116 | |||
117 | if (begy < 0 || begx < 0 || | ||
118 | (begy + nlines) > orig->_maxy || | ||
119 | (begx + ncols) > orig->_maxx) | ||
120 | return (WINDOW *)NULL; | ||
121 | |||
122 | if (!nlines) | ||
123 | nlines = orig->_maxy - begy; | ||
124 | |||
125 | if (!ncols) | ||
126 | ncols = orig->_maxx - begx; | ||
127 | |||
128 | win = PDC_makenew(nlines, ncols, begy, begx); | ||
129 | if (!win) | ||
130 | return (WINDOW *)NULL; | ||
131 | |||
132 | /* initialize window variables */ | ||
133 | |||
134 | win->_attrs = orig->_attrs; | ||
135 | win->_leaveit = orig->_leaveit; | ||
136 | win->_scroll = orig->_scroll; | ||
137 | win->_nodelay = orig->_nodelay; | ||
138 | win->_use_keypad = orig->_use_keypad; | ||
139 | win->_parent = orig; | ||
140 | |||
141 | for (i = 0; i < nlines; i++) | ||
142 | win->_y[i] = orig->_y[begy + i] + begx; | ||
143 | |||
144 | win->_flags = _SUBPAD; | ||
145 | win->_pad._pad_y = 0; | ||
146 | win->_pad._pad_x = 0; | ||
147 | win->_pad._pad_top = 0; | ||
148 | win->_pad._pad_left = 0; | ||
149 | win->_pad._pad_bottom = min(LINES, nlines) - 1; | ||
150 | win->_pad._pad_right = min(COLS, ncols) - 1; | ||
151 | |||
152 | return win; | ||
153 | } | ||
154 | |||
155 | int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2) | ||
156 | { | ||
157 | PDC_LOG(("prefresh() - called\n")); | ||
158 | |||
159 | if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR) | ||
160 | return ERR; | ||
161 | |||
162 | doupdate(); | ||
163 | return OK; | ||
164 | } | ||
165 | |||
166 | int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2) | ||
167 | { | ||
168 | int num_cols; | ||
169 | int sline; | ||
170 | int pline; | ||
171 | |||
172 | PDC_LOG(("pnoutrefresh() - called\n")); | ||
173 | |||
174 | if (py < 0) | ||
175 | py = 0; | ||
176 | if (px < 0) | ||
177 | px = 0; | ||
178 | if (sy1 < 0) | ||
179 | sy1 = 0; | ||
180 | if (sx1 < 0) | ||
181 | sx1 = 0; | ||
182 | |||
183 | if ((!w || !(w->_flags & (_PAD|_SUBPAD)) || | ||
184 | (sy2 >= LINES) || (sx2 >= COLS)) || | ||
185 | (sy2 < sy1) || (sx2 < sx1)) | ||
186 | return ERR; | ||
187 | |||
188 | sline = sy1; | ||
189 | pline = py; | ||
190 | |||
191 | num_cols = min((sx2 - sx1 + 1), (w->_maxx - px)); | ||
192 | |||
193 | while (sline <= sy2) | ||
194 | { | ||
195 | if (pline < w->_maxy) | ||
196 | { | ||
197 | memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px, | ||
198 | num_cols * sizeof(chtype)); | ||
199 | |||
200 | if ((curscr->_firstch[sline] == _NO_CHANGE) | ||
201 | || (curscr->_firstch[sline] > sx1)) | ||
202 | curscr->_firstch[sline] = sx1; | ||
203 | |||
204 | if (sx2 > curscr->_lastch[sline]) | ||
205 | curscr->_lastch[sline] = sx2; | ||
206 | |||
207 | w->_firstch[pline] = _NO_CHANGE; /* updated now */ | ||
208 | w->_lastch[pline] = _NO_CHANGE; /* updated now */ | ||
209 | } | ||
210 | |||
211 | sline++; | ||
212 | pline++; | ||
213 | } | ||
214 | |||
215 | if (w->_clear) | ||
216 | { | ||
217 | w->_clear = FALSE; | ||
218 | curscr->_clear = TRUE; | ||
219 | } | ||
220 | |||
221 | /* position the cursor to the pad's current position if possible -- | ||
222 | is the pad current position going to end up displayed? if not, | ||
223 | then don't move the cursor; if so, move it to the correct place */ | ||
224 | |||
225 | if (!w->_leaveit && w->_cury >= py && w->_curx >= px && | ||
226 | w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1)) | ||
227 | { | ||
228 | curscr->_cury = (w->_cury - py) + sy1; | ||
229 | curscr->_curx = (w->_curx - px) + sx1; | ||
230 | } | ||
231 | |||
232 | w->_pad._pad_y = py; | ||
233 | w->_pad._pad_x = px; | ||
234 | w->_pad._pad_top = sy1; | ||
235 | w->_pad._pad_left = sx1; | ||
236 | w->_pad._pad_bottom = sy2; | ||
237 | w->_pad._pad_right = sx2; | ||
238 | |||
239 | return OK; | ||
240 | } | ||
241 | |||
242 | int pechochar(WINDOW *pad, chtype ch) | ||
243 | { | ||
244 | PDC_LOG(("pechochar() - called\n")); | ||
245 | |||
246 | if (waddch(pad, ch) == ERR) | ||
247 | return ERR; | ||
248 | |||
249 | return prefresh(pad, pad->_pad._pad_y, pad->_pad._pad_x, pad->_pad._pad_top, | ||
250 | pad->_pad._pad_left, pad->_pad._pad_bottom, pad->_pad._pad_right); | ||
251 | } | ||
252 | |||
253 | #ifdef PDC_WIDE | ||
254 | int pecho_wchar(WINDOW *pad, const cchar_t *wch) | ||
255 | { | ||
256 | PDC_LOG(("pecho_wchar() - called\n")); | ||
257 | |||
258 | if (!wch || (waddch(pad, *wch) == ERR)) | ||
259 | return ERR; | ||
260 | |||
261 | return prefresh(pad, pad->_pad._pad_y, pad->_pad._pad_x, pad->_pad._pad_top, | ||
262 | pad->_pad._pad_left, pad->_pad._pad_bottom, pad->_pad._pad_right); | ||
263 | } | ||
264 | #endif | ||
265 | |||
266 | bool is_pad(const WINDOW *pad) | ||
267 | { | ||
268 | PDC_LOG(("is_pad() - called\n")); | ||
269 | |||
270 | if (!pad) | ||
271 | return FALSE; | ||
272 | |||
273 | return (pad->_flags & _PAD) ? TRUE : FALSE; | ||
274 | } | ||