1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /****************************************************************************
31  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
32  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
33  *     and: Thomas E. Dickey                        1996-on                 *
34  *     and: Sven Verdoolaege                        2001                    *
35  ****************************************************************************/
36 
37 /*
38 **	lib_box.c
39 **
40 **	The routine wborder().
41 **
42 */
43 
44 #include <curses.priv.h>
45 
46 MODULE_ID("$Id: lib_box.c,v 1.26 2020/02/02 23:34:34 tom Exp $")
47 
48 #if USE_WIDEC_SUPPORT
49 static NCURSES_INLINE chtype
_my_render(WINDOW * win,chtype ch)50 _my_render(WINDOW *win, chtype ch)
51 {
52     NCURSES_CH_T wch;
53     SetChar2(wch, ch);
54     wch = _nc_render(win, wch);
55     return ((attr_t) CharOf(wch)) | AttrOf(wch);
56 }
57 
58 #define RENDER_WITH_DEFAULT(ch,def) w ## ch = _my_render(win, (ch == 0) ? def : ch)
59 #else
60 #define RENDER_WITH_DEFAULT(ch,def) w ## ch = _nc_render(win, (ch == 0) ? def : ch)
61 #endif
62 
63 NCURSES_EXPORT(int)
wborder(WINDOW * win,chtype ls,chtype rs,chtype ts,chtype bs,chtype tl,chtype tr,chtype bl,chtype br)64 wborder(WINDOW *win,
65 	chtype ls, chtype rs,
66 	chtype ts, chtype bs,
67 	chtype tl, chtype tr,
68 	chtype bl, chtype br)
69 {
70     NCURSES_SIZE_T i;
71     NCURSES_SIZE_T endx, endy;
72     chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
73 
74     T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
75        (void *) win,
76        _tracechtype2(1, ls),
77        _tracechtype2(2, rs),
78        _tracechtype2(3, ts),
79        _tracechtype2(4, bs),
80        _tracechtype2(5, tl),
81        _tracechtype2(6, tr),
82        _tracechtype2(7, bl),
83        _tracechtype2(8, br)));
84 
85     if (!win)
86 	returnCode(ERR);
87 
88     RENDER_WITH_DEFAULT(ls, ACS_VLINE);
89     RENDER_WITH_DEFAULT(rs, ACS_VLINE);
90     RENDER_WITH_DEFAULT(ts, ACS_HLINE);
91     RENDER_WITH_DEFAULT(bs, ACS_HLINE);
92     RENDER_WITH_DEFAULT(tl, ACS_ULCORNER);
93     RENDER_WITH_DEFAULT(tr, ACS_URCORNER);
94     RENDER_WITH_DEFAULT(bl, ACS_LLCORNER);
95     RENDER_WITH_DEFAULT(br, ACS_LRCORNER);
96 
97     T(("using %s, %s, %s, %s, %s, %s, %s, %s",
98        _tracechtype2(1, wls),
99        _tracechtype2(2, wrs),
100        _tracechtype2(3, wts),
101        _tracechtype2(4, wbs),
102        _tracechtype2(5, wtl),
103        _tracechtype2(6, wtr),
104        _tracechtype2(7, wbl),
105        _tracechtype2(8, wbr)));
106 
107     endx = win->_maxx;
108     endy = win->_maxy;
109 
110     for (i = 0; i <= endx; i++) {
111 	SetChar2(win->_line[0].text[i], wts);
112 	SetChar2(win->_line[endy].text[i], wbs);
113     }
114     win->_line[endy].firstchar = win->_line[0].firstchar = 0;
115     win->_line[endy].lastchar = win->_line[0].lastchar = endx;
116 
117     for (i = 0; i <= endy; i++) {
118 #if USE_WIDEC_SUPPORT
119 	if (endx > 0 && isWidecExt(win->_line[i].text[endx])) {
120 	    SetChar2(win->_line[i].text[endx - 1], ' ');
121 	}
122 #endif
123 	SetChar2(win->_line[i].text[0], wls);
124 	SetChar2(win->_line[i].text[endx], wrs);
125 	win->_line[i].firstchar = 0;
126 	win->_line[i].lastchar = endx;
127 #if USE_WIDEC_SUPPORT
128 	if (isWidecExt(win->_line[i].text[1])) {
129 	    SetChar2(win->_line[i].text[1], ' ');
130 	}
131 #endif
132     }
133     SetChar2(win->_line[0].text[0], wtl);
134     SetChar2(win->_line[0].text[endx], wtr);
135     SetChar2(win->_line[endy].text[0], wbl);
136     SetChar2(win->_line[endy].text[endx], wbr);
137 
138     _nc_synchook(win);
139     returnCode(OK);
140 }
141