1 /* $OpenBSD: lib_box_set.c,v 1.2 2023/10/17 09:52:09 nicm Exp $ */
2
3 /****************************************************************************
4 * Copyright 2020 Thomas E. Dickey *
5 * Copyright 2002-2009,2011 Free Software Foundation, Inc. *
6 * *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
29 * authorization. *
30 ****************************************************************************/
31
32 /****************************************************************************
33 * Authors: Sven Verdoolaege and Thomas Dickey 2001,2002 *
34 ****************************************************************************/
35
36 /*
37 ** lib_box_set.c
38 **
39 ** The routine wborder_set().
40 **
41 */
42
43 #include <curses.priv.h>
44
45 MODULE_ID("$Id: lib_box_set.c,v 1.2 2023/10/17 09:52:09 nicm Exp $")
46
NCURSES_EXPORT(int)47 NCURSES_EXPORT(int)
48 wborder_set(WINDOW *win,
49 const ARG_CH_T ls, const ARG_CH_T rs,
50 const ARG_CH_T ts, const ARG_CH_T bs,
51 const ARG_CH_T tl, const ARG_CH_T tr,
52 const ARG_CH_T bl, const ARG_CH_T br)
53 {
54 NCURSES_SIZE_T i;
55 NCURSES_SIZE_T endx, endy;
56 NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
57
58 T((T_CALLED("wborder_set(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
59 (void *) win,
60 _tracech_t2(1, ls),
61 _tracech_t2(2, rs),
62 _tracech_t2(3, ts),
63 _tracech_t2(4, bs),
64 _tracech_t2(5, tl),
65 _tracech_t2(6, tr),
66 _tracech_t2(7, bl),
67 _tracech_t2(8, br)));
68
69 if (!win)
70 returnCode(ERR);
71
72 #define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch)
73
74 RENDER_WITH_DEFAULT(ls, WACS_VLINE);
75 RENDER_WITH_DEFAULT(rs, WACS_VLINE);
76 RENDER_WITH_DEFAULT(ts, WACS_HLINE);
77 RENDER_WITH_DEFAULT(bs, WACS_HLINE);
78 RENDER_WITH_DEFAULT(tl, WACS_ULCORNER);
79 RENDER_WITH_DEFAULT(tr, WACS_URCORNER);
80 RENDER_WITH_DEFAULT(bl, WACS_LLCORNER);
81 RENDER_WITH_DEFAULT(br, WACS_LRCORNER);
82
83 T(("using %s, %s, %s, %s, %s, %s, %s, %s",
84 _tracech_t2(1, CHREF(wls)),
85 _tracech_t2(2, CHREF(wrs)),
86 _tracech_t2(3, CHREF(wts)),
87 _tracech_t2(4, CHREF(wbs)),
88 _tracech_t2(5, CHREF(wtl)),
89 _tracech_t2(6, CHREF(wtr)),
90 _tracech_t2(7, CHREF(wbl)),
91 _tracech_t2(8, CHREF(wbr))));
92
93 endx = win->_maxx;
94 endy = win->_maxy;
95
96 for (i = 0; i <= endx; i++) {
97 win->_line[0].text[i] = wts;
98 win->_line[endy].text[i] = wbs;
99 }
100 win->_line[endy].firstchar = win->_line[0].firstchar = 0;
101 win->_line[endy].lastchar = win->_line[0].lastchar = endx;
102
103 for (i = 0; i <= endy; i++) {
104 win->_line[i].text[0] = wls;
105 win->_line[i].text[endx] = wrs;
106 win->_line[i].firstchar = 0;
107 win->_line[i].lastchar = endx;
108 }
109 win->_line[0].text[0] = wtl;
110 win->_line[0].text[endx] = wtr;
111 win->_line[endy].text[0] = wbl;
112 win->_line[endy].text[endx] = wbr;
113
114 _nc_synchook(win);
115 returnCode(OK);
116 }
117