aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/libcurses/pad.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/libcurses/pad.c')
-rw-r--r--scripts/kconfig/libcurses/pad.c278
1 files changed, 278 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/pad.c b/scripts/kconfig/libcurses/pad.c
new file mode 100644
index 000000000..5003ecbb4
--- /dev/null
+++ b/scripts/kconfig/libcurses/pad.c
@@ -0,0 +1,278 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7pad
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/* save values for pechochar() */
79
80static int save_pminrow, save_pmincol;
81static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol;
82
83WINDOW *newpad(int nlines, int ncols)
84{
85 WINDOW *win;
86
87 PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols));
88
89 win = PDC_makenew(nlines, ncols, 0, 0);
90 if (win)
91 win = PDC_makelines(win);
92
93 if (!win)
94 return (WINDOW *)NULL;
95
96 werase(win);
97
98 win->_flags = _PAD;
99
100 /* save default values in case pechochar() is the first call to
101 prefresh(). */
102
103 save_pminrow = 0;
104 save_pmincol = 0;
105 save_sminrow = 0;
106 save_smincol = 0;
107 save_smaxrow = min(LINES, nlines) - 1;
108 save_smaxcol = min(COLS, ncols) - 1;
109
110 return win;
111}
112
113WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx)
114{
115 WINDOW *win;
116 int i;
117
118 PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n",
119 nlines, ncols, begy, begx));
120
121 if (!orig || !(orig->_flags & _PAD))
122 return (WINDOW *)NULL;
123
124 /* make sure window fits inside the original one */
125
126 if (begy < 0 || begx < 0 ||
127 (begy + nlines) > orig->_maxy ||
128 (begx + ncols) > orig->_maxx)
129 return (WINDOW *)NULL;
130
131 if (!nlines)
132 nlines = orig->_maxy - begy;
133
134 if (!ncols)
135 ncols = orig->_maxx - begx;
136
137 win = PDC_makenew(nlines, ncols, begy, begx);
138 if (!win)
139 return (WINDOW *)NULL;
140
141 /* initialize window variables */
142
143 win->_attrs = orig->_attrs;
144 win->_leaveit = orig->_leaveit;
145 win->_scroll = orig->_scroll;
146 win->_nodelay = orig->_nodelay;
147 win->_use_keypad = orig->_use_keypad;
148 win->_parent = orig;
149
150 for (i = 0; i < nlines; i++)
151 win->_y[i] = orig->_y[begy + i] + begx;
152
153 win->_flags = _SUBPAD;
154
155 /* save default values in case pechochar() is the first call
156 to prefresh(). */
157
158 save_pminrow = 0;
159 save_pmincol = 0;
160 save_sminrow = 0;
161 save_smincol = 0;
162 save_smaxrow = min(LINES, nlines) - 1;
163 save_smaxcol = min(COLS, ncols) - 1;
164
165 return win;
166}
167
168int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2)
169{
170 PDC_LOG(("prefresh() - called\n"));
171
172 if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR)
173 return ERR;
174
175 doupdate();
176 return OK;
177}
178
179int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2)
180{
181 int num_cols;
182 int sline = sy1;
183 int pline = py;
184
185 PDC_LOG(("pnoutrefresh() - called\n"));
186
187 if (!w || !(w->_flags & (_PAD|_SUBPAD)) || (sy2 >= LINES) || (sx2 >= COLS))
188 return ERR;
189
190 if (py < 0)
191 py = 0;
192 if (px < 0)
193 px = 0;
194 if (sy1 < 0)
195 sy1 = 0;
196 if (sx1 < 0)
197 sx1 = 0;
198
199 if (sy2 < sy1 || sx2 < sx1)
200 return ERR;
201
202 num_cols = min((sx2 - sx1 + 1), (w->_maxx - px));
203
204 while (sline <= sy2)
205 {
206 if (pline < w->_maxy)
207 {
208 memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px,
209 num_cols * sizeof(chtype));
210
211 if ((curscr->_firstch[sline] == _NO_CHANGE)
212 || (curscr->_firstch[sline] > sx1))
213 curscr->_firstch[sline] = sx1;
214
215 if (sx2 > curscr->_lastch[sline])
216 curscr->_lastch[sline] = sx2;
217
218 w->_firstch[pline] = _NO_CHANGE; /* updated now */
219 w->_lastch[pline] = _NO_CHANGE; /* updated now */
220 }
221
222 sline++;
223 pline++;
224 }
225
226 if (w->_clear)
227 {
228 w->_clear = FALSE;
229 curscr->_clear = TRUE;
230 }
231
232 /* position the cursor to the pad's current position if possible --
233 is the pad current position going to end up displayed? if not,
234 then don't move the cursor; if so, move it to the correct place */
235
236 if (!w->_leaveit && w->_cury >= py && w->_curx >= px &&
237 w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1))
238 {
239 curscr->_cury = (w->_cury - py) + sy1;
240 curscr->_curx = (w->_curx - px) + sx1;
241 }
242
243 return OK;
244}
245
246int pechochar(WINDOW *pad, chtype ch)
247{
248 PDC_LOG(("pechochar() - called\n"));
249
250 if (waddch(pad, ch) == ERR)
251 return ERR;
252
253 return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
254 save_smincol, save_smaxrow, save_smaxcol);
255}
256
257#ifdef PDC_WIDE
258int pecho_wchar(WINDOW *pad, const cchar_t *wch)
259{
260 PDC_LOG(("pecho_wchar() - called\n"));
261
262 if (!wch || (waddch(pad, *wch) == ERR))
263 return ERR;
264
265 return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
266 save_smincol, save_smaxrow, save_smaxcol);
267}
268#endif
269
270bool is_pad(const WINDOW *pad)
271{
272 PDC_LOG(("is_pad() - called\n"));
273
274 if (!pad)
275 return FALSE;
276
277 return (pad->_flags & _PAD) ? TRUE : FALSE;
278}