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