aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/libcurses/border.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/kconfig/libcurses/border.c418
1 files changed, 418 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/border.c b/scripts/kconfig/libcurses/border.c
new file mode 100644
index 000000000..409f2351a
--- /dev/null
+++ b/scripts/kconfig/libcurses/border.c
@@ -0,0 +1,418 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7border
8------
9
10### Synopsis
11
12 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
13 chtype tr, chtype bl, chtype br);
14 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
15 chtype bs, chtype tl, chtype tr, chtype bl, chtype br);
16 int box(WINDOW *win, chtype verch, chtype horch);
17 int hline(chtype ch, int n);
18 int vline(chtype ch, int n);
19 int whline(WINDOW *win, chtype ch, int n);
20 int wvline(WINDOW *win, chtype ch, int n);
21 int mvhline(int y, int x, chtype ch, int n);
22 int mvvline(int y, int x, chtype ch, int n);
23 int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);
24 int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);
25
26 int border_set(const cchar_t *ls, const cchar_t *rs,
27 const cchar_t *ts, const cchar_t *bs,
28 const cchar_t *tl, const cchar_t *tr,
29 const cchar_t *bl, const cchar_t *br);
30 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
31 const cchar_t *ts, const cchar_t *bs,
32 const cchar_t *tl, const cchar_t *tr,
33 const cchar_t *bl, const cchar_t *br);
34 int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);
35 int hline_set(const cchar_t *wch, int n);
36 int vline_set(const cchar_t *wch, int n);
37 int whline_set(WINDOW *win, const cchar_t *wch, int n);
38 int wvline_set(WINDOW *win, const cchar_t *wch, int n);
39 int mvhline_set(int y, int x, const cchar_t *wch, int n);
40 int mvvline_set(int y, int x, const cchar_t *wch, int n);
41 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
42 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
43
44### Description
45
46 border(), wborder(), and box() draw a border around the edge of the
47 window. If any argument is zero, an appropriate default is used:
48
49 Name | Element | Default
50 :----|:------------------------------|:------------
51 ls | left side of border | ACS_VLINE
52 rs | right side of border | ACS_VLINE
53 ts | top side of border | ACS_HLINE
54 bs | bottom side of border | ACS_HLINE
55 tl | top left corner of border | ACS_ULCORNER
56 tr | top right corner of border | ACS_URCORNER
57 bl | bottom left corner of border | ACS_LLCORNER
58 br | bottom right corner of border | ACS_LRCORNER
59
60 hline() and whline() draw a horizontal line, using ch, starting from
61 the current cursor position. The cursor position does not change. The
62 line is at most n characters long, or as many as will fit in the
63 window.
64
65 vline() and wvline() draw a vertical line, using ch, starting from
66 the current cursor position. The cursor position does not change. The
67 line is at most n characters long, or as many as will fit in the
68 window.
69
70 The *_set functions are the "wide-character" versions, taking
71 pointers to cchar_t instead of chtype. Note that in PDCurses, chtype
72 and cchar_t are the same.
73
74### Return Value
75
76 These functions return OK on success and ERR on error.
77
78### Portability
79
80 Function | X/Open | ncurses | NetBSD
81 :---------------------|:------:|:-------:|:------:
82 border | Y | Y | Y
83 wborder | Y | Y | Y
84 box | Y | Y | Y
85 hline | Y | Y | Y
86 vline | Y | Y | Y
87 whline | Y | Y | Y
88 wvline | Y | Y | Y
89 mvhline | Y | Y | Y
90 mvvline | Y | Y | Y
91 mvwhline | Y | Y | Y
92 mvwvline | Y | Y | Y
93 border_set | Y | Y | Y
94 wborder_set | Y | Y | Y
95 box_set | Y | Y | Y
96 hline_set | Y | Y | Y
97 vline_set | Y | Y | Y
98 whline_set | Y | Y | Y
99 wvline_set | Y | Y | Y
100 mvhline_set | Y | Y | Y
101 mvvline_set | Y | Y | Y
102 mvwhline_set | Y | Y | Y
103 mvwvline_set | Y | Y | Y
104
105**man-end****************************************************************/
106
107/* _attr_passthru() -- Takes a single chtype 'ch' and checks if the
108 current attribute of window 'win', as set by wattrset(), and/or the
109 current background of win, as set by wbkgd(), should by combined with
110 it. Attributes set explicitly in ch take precedence. */
111
112static chtype _attr_passthru(WINDOW *win, chtype ch)
113{
114 chtype attr;
115
116 /* If the incoming character doesn't have its own attribute, then
117 use the current attributes for the window. If the incoming
118 character has attributes, but not a color component, OR the
119 attributes to the current attributes for the window. If the
120 incoming character has a color component, use only the attributes
121 from the incoming character. */
122
123 attr = ch & A_ATTRIBUTES;
124 if (!(attr & A_COLOR))
125 attr |= win->_attrs;
126
127 /* wrs (4/10/93) -- Apply the same sort of logic for the window
128 background, in that it only takes precedence if other color
129 attributes are not there. */
130
131 if (!(attr & A_COLOR))
132 attr |= win->_bkgd & A_ATTRIBUTES;
133 else
134 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
135
136 ch = (ch & A_CHARTEXT) | attr;
137
138 return ch;
139}
140
141int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
142 chtype tl, chtype tr, chtype bl, chtype br)
143{
144 int i, ymax, xmax;
145
146 PDC_LOG(("wborder() - called\n"));
147
148 if (!win)
149 return ERR;
150
151 ymax = win->_maxy - 1;
152 xmax = win->_maxx - 1;
153
154 ls = _attr_passthru(win, ls ? ls : ACS_VLINE);
155 rs = _attr_passthru(win, rs ? rs : ACS_VLINE);
156 ts = _attr_passthru(win, ts ? ts : ACS_HLINE);
157 bs = _attr_passthru(win, bs ? bs : ACS_HLINE);
158 tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER);
159 tr = _attr_passthru(win, tr ? tr : ACS_URCORNER);
160 bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER);
161 br = _attr_passthru(win, br ? br : ACS_LRCORNER);
162
163 for (i = 1; i < xmax; i++)
164 {
165 win->_y[0][i] = ts;
166 win->_y[ymax][i] = bs;
167 }
168
169 for (i = 1; i < ymax; i++)
170 {
171 win->_y[i][0] = ls;
172 win->_y[i][xmax] = rs;
173 }
174
175 win->_y[0][0] = tl;
176 win->_y[0][xmax] = tr;
177 win->_y[ymax][0] = bl;
178 win->_y[ymax][xmax] = br;
179
180 for (i = 0; i <= ymax; i++)
181 {
182 win->_firstch[i] = 0;
183 win->_lastch[i] = xmax;
184 }
185
186 PDC_sync(win);
187
188 return OK;
189}
190
191int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
192 chtype tr, chtype bl, chtype br)
193{
194 PDC_LOG(("border() - called\n"));
195
196 return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
197}
198
199int box(WINDOW *win, chtype verch, chtype horch)
200{
201 PDC_LOG(("box() - called\n"));
202
203 return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0);
204}
205
206int whline(WINDOW *win, chtype ch, int n)
207{
208 chtype *dest;
209 int startpos, endpos;
210
211 PDC_LOG(("whline() - called\n"));
212
213 if (!win || n < 1)
214 return ERR;
215
216 startpos = win->_curx;
217 endpos = min(startpos + n, win->_maxx) - 1;
218 dest = win->_y[win->_cury];
219 ch = _attr_passthru(win, ch ? ch : ACS_HLINE);
220
221 for (n = startpos; n <= endpos; n++)
222 dest[n] = ch;
223
224 n = win->_cury;
225
226 if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
227 win->_firstch[n] = startpos;
228
229 if (endpos > win->_lastch[n])
230 win->_lastch[n] = endpos;
231
232 PDC_sync(win);
233
234 return OK;
235}
236
237int hline(chtype ch, int n)
238{
239 PDC_LOG(("hline() - called\n"));
240
241 return whline(stdscr, ch, n);
242}
243
244int mvhline(int y, int x, chtype ch, int n)
245{
246 PDC_LOG(("mvhline() - called\n"));
247
248 if (move(y, x) == ERR)
249 return ERR;
250
251 return whline(stdscr, ch, n);
252}
253
254int mvwhline(WINDOW *win, int y, int x, chtype ch, int n)
255{
256 PDC_LOG(("mvwhline() - called\n"));
257
258 if (wmove(win, y, x) == ERR)
259 return ERR;
260
261 return whline(win, ch, n);
262}
263
264int wvline(WINDOW *win, chtype ch, int n)
265{
266 int endpos, x;
267
268 PDC_LOG(("wvline() - called\n"));
269
270 if (!win || n < 1)
271 return ERR;
272
273 endpos = min(win->_cury + n, win->_maxy);
274 x = win->_curx;
275
276 ch = _attr_passthru(win, ch ? ch : ACS_VLINE);
277
278 for (n = win->_cury; n < endpos; n++)
279 {
280 win->_y[n][x] = ch;
281
282 if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
283 win->_firstch[n] = x;
284
285 if (x > win->_lastch[n])
286 win->_lastch[n] = x;
287 }
288
289 PDC_sync(win);
290
291 return OK;
292}
293
294int vline(chtype ch, int n)
295{
296 PDC_LOG(("vline() - called\n"));
297
298 return wvline(stdscr, ch, n);
299}
300
301int mvvline(int y, int x, chtype ch, int n)
302{
303 PDC_LOG(("mvvline() - called\n"));
304
305 if (move(y, x) == ERR)
306 return ERR;
307
308 return wvline(stdscr, ch, n);
309}
310
311int mvwvline(WINDOW *win, int y, int x, chtype ch, int n)
312{
313 PDC_LOG(("mvwvline() - called\n"));
314
315 if (wmove(win, y, x) == ERR)
316 return ERR;
317
318 return wvline(win, ch, n);
319}
320
321#ifdef PDC_WIDE
322int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
323 const cchar_t *ts, const cchar_t *bs, const cchar_t *tl,
324 const cchar_t *tr, const cchar_t *bl, const cchar_t *br)
325{
326 PDC_LOG(("wborder_set() - called\n"));
327
328 return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0,
329 bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0,
330 bl ? *bl : 0, br ? *br : 0);
331}
332
333int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
334 const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
335 const cchar_t *bl, const cchar_t *br)
336{
337 PDC_LOG(("border_set() - called\n"));
338
339 return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
340}
341
342int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)
343{
344 PDC_LOG(("box_set() - called\n"));
345
346 return wborder_set(win, verch, verch, horch, horch,
347 (const cchar_t *)NULL, (const cchar_t *)NULL,
348 (const cchar_t *)NULL, (const cchar_t *)NULL);
349}
350
351int whline_set(WINDOW *win, const cchar_t *wch, int n)
352{
353 PDC_LOG(("whline_set() - called\n"));
354
355 return wch ? whline(win, *wch, n) : ERR;
356}
357
358int hline_set(const cchar_t *wch, int n)
359{
360 PDC_LOG(("hline_set() - called\n"));
361
362 return whline_set(stdscr, wch, n);
363}
364
365int mvhline_set(int y, int x, const cchar_t *wch, int n)
366{
367 PDC_LOG(("mvhline_set() - called\n"));
368
369 if (move(y, x) == ERR)
370 return ERR;
371
372 return whline_set(stdscr, wch, n);
373}
374
375int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
376{
377 PDC_LOG(("mvwhline_set() - called\n"));
378
379 if (wmove(win, y, x) == ERR)
380 return ERR;
381
382 return whline_set(win, wch, n);
383}
384
385int wvline_set(WINDOW *win, const cchar_t *wch, int n)
386{
387 PDC_LOG(("wvline_set() - called\n"));
388
389 return wch ? wvline(win, *wch, n) : ERR;
390}
391
392int vline_set(const cchar_t *wch, int n)
393{
394 PDC_LOG(("vline_set() - called\n"));
395
396 return wvline_set(stdscr, wch, n);
397}
398
399int mvvline_set(int y, int x, const cchar_t *wch, int n)
400{
401 PDC_LOG(("mvvline_set() - called\n"));
402
403 if (move(y, x) == ERR)
404 return ERR;
405
406 return wvline_set(stdscr, wch, n);
407}
408
409int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
410{
411 PDC_LOG(("mvwvline_set() - called\n"));
412
413 if (wmove(win, y, x) == ERR)
414 return ERR;
415
416 return wvline_set(win, wch, n);
417}
418#endif