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