]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/widechar/lib_box_set.c
ncurses 6.2 - patch 20200301
[ncurses.git] / ncurses / widechar / lib_box_set.c
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 2002-2009,2011 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  * Authors: Sven Verdoolaege and Thomas Dickey 2001,2002                    *
32  ****************************************************************************/
33
34 /*
35 **      lib_box_set.c
36 **
37 **      The routine wborder_set().
38 **
39 */
40
41 #include <curses.priv.h>
42
43 MODULE_ID("$Id: lib_box_set.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
44
45 NCURSES_EXPORT(int)
46 wborder_set(WINDOW *win,
47             const ARG_CH_T ls, const ARG_CH_T rs,
48             const ARG_CH_T ts, const ARG_CH_T bs,
49             const ARG_CH_T tl, const ARG_CH_T tr,
50             const ARG_CH_T bl, const ARG_CH_T br)
51 {
52     NCURSES_SIZE_T i;
53     NCURSES_SIZE_T endx, endy;
54     NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
55
56     T((T_CALLED("wborder_set(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
57        (void *) win,
58        _tracech_t2(1, ls),
59        _tracech_t2(2, rs),
60        _tracech_t2(3, ts),
61        _tracech_t2(4, bs),
62        _tracech_t2(5, tl),
63        _tracech_t2(6, tr),
64        _tracech_t2(7, bl),
65        _tracech_t2(8, br)));
66
67     if (!win)
68         returnCode(ERR);
69
70 #define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch)
71
72     RENDER_WITH_DEFAULT(ls, WACS_VLINE);
73     RENDER_WITH_DEFAULT(rs, WACS_VLINE);
74     RENDER_WITH_DEFAULT(ts, WACS_HLINE);
75     RENDER_WITH_DEFAULT(bs, WACS_HLINE);
76     RENDER_WITH_DEFAULT(tl, WACS_ULCORNER);
77     RENDER_WITH_DEFAULT(tr, WACS_URCORNER);
78     RENDER_WITH_DEFAULT(bl, WACS_LLCORNER);
79     RENDER_WITH_DEFAULT(br, WACS_LRCORNER);
80
81     T(("using %s, %s, %s, %s, %s, %s, %s, %s",
82        _tracech_t2(1, CHREF(wls)),
83        _tracech_t2(2, CHREF(wrs)),
84        _tracech_t2(3, CHREF(wts)),
85        _tracech_t2(4, CHREF(wbs)),
86        _tracech_t2(5, CHREF(wtl)),
87        _tracech_t2(6, CHREF(wtr)),
88        _tracech_t2(7, CHREF(wbl)),
89        _tracech_t2(8, CHREF(wbr))));
90
91     endx = win->_maxx;
92     endy = win->_maxy;
93
94     for (i = 0; i <= endx; i++) {
95         win->_line[0].text[i] = wts;
96         win->_line[endy].text[i] = wbs;
97     }
98     win->_line[endy].firstchar = win->_line[0].firstchar = 0;
99     win->_line[endy].lastchar = win->_line[0].lastchar = endx;
100
101     for (i = 0; i <= endy; i++) {
102         win->_line[i].text[0] = wls;
103         win->_line[i].text[endx] = wrs;
104         win->_line[i].firstchar = 0;
105         win->_line[i].lastchar = endx;
106     }
107     win->_line[0].text[0] = wtl;
108     win->_line[0].text[endx] = wtr;
109     win->_line[endy].text[0] = wbl;
110     win->_line[endy].text[endx] = wbr;
111
112     _nc_synchook(win);
113     returnCode(OK);
114 }