/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56border7------89### Synopsis1011int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,12chtype tr, chtype bl, chtype br);13int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,14chtype bs, chtype tl, chtype tr, chtype bl, chtype br);15int box(WINDOW *win, chtype verch, chtype horch);16int hline(chtype ch, int n);17int vline(chtype ch, int n);18int whline(WINDOW *win, chtype ch, int n);19int wvline(WINDOW *win, chtype ch, int n);20int mvhline(int y, int x, chtype ch, int n);21int mvvline(int y, int x, chtype ch, int n);22int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);23int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);2425int border_set(const cchar_t *ls, const cchar_t *rs,26const cchar_t *ts, const cchar_t *bs,27const cchar_t *tl, const cchar_t *tr,28const cchar_t *bl, const cchar_t *br);29int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,30const cchar_t *ts, const cchar_t *bs,31const cchar_t *tl, const cchar_t *tr,32const cchar_t *bl, const cchar_t *br);33int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);34int hline_set(const cchar_t *wch, int n);35int vline_set(const cchar_t *wch, int n);36int whline_set(WINDOW *win, const cchar_t *wch, int n);37int wvline_set(WINDOW *win, const cchar_t *wch, int n);38int mvhline_set(int y, int x, const cchar_t *wch, int n);39int mvvline_set(int y, int x, const cchar_t *wch, int n);40int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);41int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);4243### Description4445border(), wborder(), and box() draw a border around the edge of the46window. If any argument is zero, an appropriate default is used:4748ls left side of border ACS_VLINE49rs right side of border ACS_VLINE50ts top side of border ACS_HLINE51bs bottom side of border ACS_HLINE52tl top left corner of border ACS_ULCORNER53tr top right corner of border ACS_URCORNER54bl bottom left corner of border ACS_LLCORNER55br bottom right corner of border ACS_LRCORNER5657hline() and whline() draw a horizontal line, using ch, starting from58the current cursor position. The cursor position does not change. The59line is at most n characters long, or as many as will fit in the60window.6162vline() and wvline() draw a vertical line, using ch, starting from63the current cursor position. The cursor position does not change. The64line is at most n characters long, or as many as will fit in the65window.6667The *_set functions are the "wide-character" versions, taking68pointers to cchar_t instead of chtype. Note that in PDCurses, chtype69and cchar_t are the same.7071### Return Value7273These functions return OK on success and ERR on error.7475### Portability76X/Open ncurses NetBSD77border Y Y Y78wborder Y Y Y79box Y Y Y80hline Y Y Y81vline Y Y Y82whline Y Y Y83wvline Y Y Y84mvhline Y Y Y85mvvline Y Y Y86mvwhline Y Y Y87mvwvline Y Y Y88border_set Y Y Y89wborder_set Y Y Y90box_set Y Y Y91hline_set Y Y Y92vline_set Y Y Y93whline_set Y Y Y94wvline_set Y Y Y95mvhline_set Y Y Y96mvvline_set Y Y Y97mvwhline_set Y Y Y98mvwvline_set Y Y Y99100**man-end****************************************************************/101102/* _attr_passthru() -- Takes a single chtype 'ch' and checks if the103current attribute of window 'win', as set by wattrset(), and/or the104current background of win, as set by wbkgd(), should by combined with105it. Attributes set explicitly in ch take precedence. */106107static chtype _attr_passthru(WINDOW *win, chtype ch)108{109chtype attr;110111/* If the incoming character doesn't have its own attribute, then112use the current attributes for the window. If the incoming113character has attributes, but not a color component, OR the114attributes to the current attributes for the window. If the115incoming character has a color component, use only the attributes116from the incoming character. */117118attr = ch & A_ATTRIBUTES;119if (!(attr & A_COLOR))120attr |= win->_attrs;121122/* wrs (4/10/93) -- Apply the same sort of logic for the window123background, in that it only takes precedence if other color124attributes are not there. */125126if (!(attr & A_COLOR))127attr |= win->_bkgd & A_ATTRIBUTES;128else129attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);130131ch = (ch & A_CHARTEXT) | attr;132133return ch;134}135136int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,137chtype tl, chtype tr, chtype bl, chtype br)138{139int i, ymax, xmax;140141PDC_LOG(("wborder() - called\n"));142143if (!win)144return ERR;145146ymax = win->_maxy - 1;147xmax = win->_maxx - 1;148149ls = _attr_passthru(win, ls ? ls : ACS_VLINE);150rs = _attr_passthru(win, rs ? rs : ACS_VLINE);151ts = _attr_passthru(win, ts ? ts : ACS_HLINE);152bs = _attr_passthru(win, bs ? bs : ACS_HLINE);153tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER);154tr = _attr_passthru(win, tr ? tr : ACS_URCORNER);155bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER);156br = _attr_passthru(win, br ? br : ACS_LRCORNER);157158for (i = 1; i < xmax; i++)159{160win->_y[0][i] = ts;161win->_y[ymax][i] = bs;162}163164for (i = 1; i < ymax; i++)165{166win->_y[i][0] = ls;167win->_y[i][xmax] = rs;168}169170win->_y[0][0] = tl;171win->_y[0][xmax] = tr;172win->_y[ymax][0] = bl;173win->_y[ymax][xmax] = br;174175for (i = 0; i <= ymax; i++)176{177win->_firstch[i] = 0;178win->_lastch[i] = xmax;179}180181PDC_sync(win);182183return OK;184}185186int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,187chtype tr, chtype bl, chtype br)188{189PDC_LOG(("border() - called\n"));190191return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br);192}193194int box(WINDOW *win, chtype verch, chtype horch)195{196PDC_LOG(("box() - called\n"));197198return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0);199}200201int whline(WINDOW *win, chtype ch, int n)202{203chtype *dest;204int startpos, endpos;205206PDC_LOG(("whline() - called\n"));207208if (!win || n < 1)209return ERR;210211startpos = win->_curx;212endpos = min(startpos + n, win->_maxx) - 1;213dest = win->_y[win->_cury];214ch = _attr_passthru(win, ch ? ch : ACS_HLINE);215216for (n = startpos; n <= endpos; n++)217dest[n] = ch;218219n = win->_cury;220221if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)222win->_firstch[n] = startpos;223224if (endpos > win->_lastch[n])225win->_lastch[n] = endpos;226227PDC_sync(win);228229return OK;230}231232int hline(chtype ch, int n)233{234PDC_LOG(("hline() - called\n"));235236return whline(stdscr, ch, n);237}238239int mvhline(int y, int x, chtype ch, int n)240{241PDC_LOG(("mvhline() - called\n"));242243if (move(y, x) == ERR)244return ERR;245246return whline(stdscr, ch, n);247}248249int mvwhline(WINDOW *win, int y, int x, chtype ch, int n)250{251PDC_LOG(("mvwhline() - called\n"));252253if (wmove(win, y, x) == ERR)254return ERR;255256return whline(win, ch, n);257}258259int wvline(WINDOW *win, chtype ch, int n)260{261int endpos, x;262263PDC_LOG(("wvline() - called\n"));264265if (!win || n < 1)266return ERR;267268endpos = min(win->_cury + n, win->_maxy);269x = win->_curx;270271ch = _attr_passthru(win, ch ? ch : ACS_VLINE);272273for (n = win->_cury; n < endpos; n++)274{275win->_y[n][x] = ch;276277if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)278win->_firstch[n] = x;279280if (x > win->_lastch[n])281win->_lastch[n] = x;282}283284PDC_sync(win);285286return OK;287}288289int vline(chtype ch, int n)290{291PDC_LOG(("vline() - called\n"));292293return wvline(stdscr, ch, n);294}295296int mvvline(int y, int x, chtype ch, int n)297{298PDC_LOG(("mvvline() - called\n"));299300if (move(y, x) == ERR)301return ERR;302303return wvline(stdscr, ch, n);304}305306int mvwvline(WINDOW *win, int y, int x, chtype ch, int n)307{308PDC_LOG(("mvwvline() - called\n"));309310if (wmove(win, y, x) == ERR)311return ERR;312313return wvline(win, ch, n);314}315316#ifdef PDC_WIDE317int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,318const cchar_t *ts, const cchar_t *bs, const cchar_t *tl,319const cchar_t *tr, const cchar_t *bl, const cchar_t *br)320{321PDC_LOG(("wborder_set() - called\n"));322323return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0,324bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0,325bl ? *bl : 0, br ? *br : 0);326}327328int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,329const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,330const cchar_t *bl, const cchar_t *br)331{332PDC_LOG(("border_set() - called\n"));333334return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);335}336337int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)338{339PDC_LOG(("box_set() - called\n"));340341return wborder_set(win, verch, verch, horch, horch,342(const cchar_t *)NULL, (const cchar_t *)NULL,343(const cchar_t *)NULL, (const cchar_t *)NULL);344}345346int whline_set(WINDOW *win, const cchar_t *wch, int n)347{348PDC_LOG(("whline_set() - called\n"));349350return wch ? whline(win, *wch, n) : ERR;351}352353int hline_set(const cchar_t *wch, int n)354{355PDC_LOG(("hline_set() - called\n"));356357return whline_set(stdscr, wch, n);358}359360int mvhline_set(int y, int x, const cchar_t *wch, int n)361{362PDC_LOG(("mvhline_set() - called\n"));363364if (move(y, x) == ERR)365return ERR;366367return whline_set(stdscr, wch, n);368}369370int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)371{372PDC_LOG(("mvwhline_set() - called\n"));373374if (wmove(win, y, x) == ERR)375return ERR;376377return whline_set(win, wch, n);378}379380int wvline_set(WINDOW *win, const cchar_t *wch, int n)381{382PDC_LOG(("wvline_set() - called\n"));383384return wch ? wvline(win, *wch, n) : ERR;385}386387int vline_set(const cchar_t *wch, int n)388{389PDC_LOG(("vline_set() - called\n"));390391return wvline_set(stdscr, wch, n);392}393394int mvvline_set(int y, int x, const cchar_t *wch, int n)395{396PDC_LOG(("mvvline_set() - called\n"));397398if (move(y, x) == ERR)399return ERR;400401return wvline_set(stdscr, wch, n);402}403404int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)405{406PDC_LOG(("mvwvline_set() - called\n"));407408if (wmove(win, y, x) == ERR)409return ERR;410411return wvline_set(win, wch, n);412}413#endif414415416