1 /* Public Domain Curses */
5 RCSID("$Id: border.c,v 1.53 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
13 chtype tr, chtype bl, chtype br);
14 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
15 chtype bs, chtype tl, chtype tr, chtype bl, chtype br);
16 int box(WINDOW *win, chtype verch, chtype horch);
17 int hline(chtype ch, int n);
18 int vline(chtype ch, int n);
19 int whline(WINDOW *win, chtype ch, int n);
20 int wvline(WINDOW *win, chtype ch, int n);
21 int mvhline(int y, int x, chtype ch, int n);
22 int mvvline(int y, int x, chtype ch, int n);
23 int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);
24 int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);
26 int border_set(const cchar_t *ls, const cchar_t *rs,
27 const cchar_t *ts, const cchar_t *bs,
28 const cchar_t *tl, const cchar_t *tr,
29 const cchar_t *bl, const cchar_t *br);
30 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
31 const cchar_t *ts, const cchar_t *bs,
32 const cchar_t *tl, const cchar_t *tr,
33 const cchar_t *bl, const cchar_t *br);
34 int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);
35 int hline_set(const cchar_t *wch, int n);
36 int vline_set(const cchar_t *wch, int n);
37 int whline_set(WINDOW *win, const cchar_t *wch, int n);
38 int wvline_set(WINDOW *win, const cchar_t *wch, int n);
39 int mvhline_set(int y, int x, const cchar_t *wch, int n);
40 int mvvline_set(int y, int x, const cchar_t *wch, int n);
41 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
42 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
45 border(), wborder(), and box() draw a border around the edge of
46 the window. If any argument is zero, an appropriate default is
49 ls left side of border ACS_VLINE
50 rs right side of border ACS_VLINE
51 ts top side of border ACS_HLINE
52 bs bottom side of border ACS_HLINE
53 tl top left corner of border ACS_ULCORNER
54 tr top right corner of border ACS_URCORNER
55 bl bottom left corner of border ACS_LLCORNER
56 br bottom right corner of border ACS_LRCORNER
58 hline() and whline() draw a horizontal line, using ch, starting
59 from the current cursor position. The cursor position does not
60 change. The line is at most n characters long, or as many as
61 will fit in the window.
63 vline() and wvline() draw a vertical line, using ch, starting
64 from the current cursor position. The cursor position does not
65 change. The line is at most n characters long, or as many as
66 will fit in the window.
69 These functions return OK on success and ERR on error.
71 Portability X/Open BSD SYS V
95 **man-end****************************************************************/
97 /* _attr_passthru() -- Takes a single chtype 'ch' and checks if the
98 current attribute of window 'win', as set by wattrset(), and/or the
99 current background of win, as set by wbkgd(), should by combined with
100 it. Attributes set explicitly in ch take precedence. */
102 static chtype
_attr_passthru(WINDOW
*win
, chtype ch
)
106 /* If the incoming character doesn't have its own attribute, then
107 use the current attributes for the window. If the incoming
108 character has attributes, but not a color component, OR the
109 attributes to the current attributes for the window. If the
110 incoming character has a color component, use only the attributes
111 from the incoming character. */
113 attr
= ch
& A_ATTRIBUTES
;
114 if (!(attr
& A_COLOR
))
117 /* wrs (4/10/93) -- Apply the same sort of logic for the window
118 background, in that it only takes precedence if other color
119 attributes are not there. */
121 if (!(attr
& A_COLOR
))
122 attr
|= win
->_bkgd
& A_ATTRIBUTES
;
124 attr
|= win
->_bkgd
& (A_ATTRIBUTES
^ A_COLOR
);
126 ch
= (ch
& A_CHARTEXT
) | attr
;
131 int wborder(WINDOW
*win
, chtype ls
, chtype rs
, chtype ts
, chtype bs
,
132 chtype tl
, chtype tr
, chtype bl
, chtype br
)
136 PDC_LOG(("wborder() - called\n"));
141 ymax
= win
->_maxy
- 1;
142 xmax
= win
->_maxx
- 1;
144 ls
= _attr_passthru(win
, ls
? ls
: ACS_VLINE
);
145 rs
= _attr_passthru(win
, rs
? rs
: ACS_VLINE
);
146 ts
= _attr_passthru(win
, ts
? ts
: ACS_HLINE
);
147 bs
= _attr_passthru(win
, bs
? bs
: ACS_HLINE
);
148 tl
= _attr_passthru(win
, tl
? tl
: ACS_ULCORNER
);
149 tr
= _attr_passthru(win
, tr
? tr
: ACS_URCORNER
);
150 bl
= _attr_passthru(win
, bl
? bl
: ACS_LLCORNER
);
151 br
= _attr_passthru(win
, br
? br
: ACS_LRCORNER
);
153 for (i
= 1; i
< xmax
; i
++)
156 win
->_y
[ymax
][i
] = bs
;
159 for (i
= 1; i
< ymax
; i
++)
162 win
->_y
[i
][xmax
] = rs
;
166 win
->_y
[0][xmax
] = tr
;
167 win
->_y
[ymax
][0] = bl
;
168 win
->_y
[ymax
][xmax
] = br
;
170 for (i
= 0; i
<= ymax
; i
++)
172 win
->_firstch
[i
] = 0;
173 win
->_lastch
[i
] = xmax
;
181 int border(chtype ls
, chtype rs
, chtype ts
, chtype bs
, chtype tl
,
182 chtype tr
, chtype bl
, chtype br
)
184 PDC_LOG(("border() - called\n"));
186 return wborder(stdscr
, ls
, rs
, ts
, bs
, tl
, tr
, bl
, br
);
189 int box(WINDOW
*win
, chtype verch
, chtype horch
)
191 PDC_LOG(("box() - called\n"));
193 return wborder(win
, verch
, verch
, horch
, horch
, 0, 0, 0, 0);
196 int whline(WINDOW
*win
, chtype ch
, int n
)
199 int startpos
, endpos
;
201 PDC_LOG(("whline() - called\n"));
206 startpos
= win
->_curx
;
207 endpos
= min(startpos
+ n
, win
->_maxx
) - 1;
208 dest
= win
->_y
[win
->_cury
];
209 ch
= _attr_passthru(win
, ch
? ch
: ACS_HLINE
);
211 for (n
= startpos
; n
<= endpos
; n
++)
216 if (startpos
< win
->_firstch
[n
] || win
->_firstch
[n
] == _NO_CHANGE
)
217 win
->_firstch
[n
] = startpos
;
219 if (endpos
> win
->_lastch
[n
])
220 win
->_lastch
[n
] = endpos
;
227 int hline(chtype ch
, int n
)
229 PDC_LOG(("hline() - called\n"));
231 return whline(stdscr
, ch
, n
);
234 int mvhline(int y
, int x
, chtype ch
, int n
)
236 PDC_LOG(("mvhline() - called\n"));
238 if (move(y
, x
) == ERR
)
241 return whline(stdscr
, ch
, n
);
244 int mvwhline(WINDOW
*win
, int y
, int x
, chtype ch
, int n
)
246 PDC_LOG(("mvwhline() - called\n"));
248 if (wmove(win
, y
, x
) == ERR
)
251 return whline(win
, ch
, n
);
254 int wvline(WINDOW
*win
, chtype ch
, int n
)
258 PDC_LOG(("wvline() - called\n"));
263 endpos
= min(win
->_cury
+ n
, win
->_maxy
);
266 ch
= _attr_passthru(win
, ch
? ch
: ACS_VLINE
);
268 for (n
= win
->_cury
; n
< endpos
; n
++)
272 if (x
< win
->_firstch
[n
] || win
->_firstch
[n
] == _NO_CHANGE
)
273 win
->_firstch
[n
] = x
;
275 if (x
> win
->_lastch
[n
])
284 int vline(chtype ch
, int n
)
286 PDC_LOG(("vline() - called\n"));
288 return wvline(stdscr
, ch
, n
);
291 int mvvline(int y
, int x
, chtype ch
, int n
)
293 PDC_LOG(("mvvline() - called\n"));
295 if (move(y
, x
) == ERR
)
298 return wvline(stdscr
, ch
, n
);
301 int mvwvline(WINDOW
*win
, int y
, int x
, chtype ch
, int n
)
303 PDC_LOG(("mvwvline() - called\n"));
305 if (wmove(win
, y
, x
) == ERR
)
308 return wvline(win
, ch
, n
);
312 int wborder_set(WINDOW
*win
, const cchar_t
*ls
, const cchar_t
*rs
,
313 const cchar_t
*ts
, const cchar_t
*bs
, const cchar_t
*tl
,
314 const cchar_t
*tr
, const cchar_t
*bl
, const cchar_t
*br
)
316 PDC_LOG(("wborder_set() - called\n"));
318 return wborder(win
, ls
? *ls
: 0, rs
? *rs
: 0, ts
? *ts
: 0,
319 bs
? *bs
: 0, tl
? *tl
: 0, tr
? *tr
: 0,
320 bl
? *bl
: 0, br
? *br
: 0);
323 int border_set(const cchar_t
*ls
, const cchar_t
*rs
, const cchar_t
*ts
,
324 const cchar_t
*bs
, const cchar_t
*tl
, const cchar_t
*tr
,
325 const cchar_t
*bl
, const cchar_t
*br
)
327 PDC_LOG(("border_set() - called\n"));
329 return wborder_set(stdscr
, ls
, rs
, ts
, bs
, tl
, tr
, bl
, br
);
332 int box_set(WINDOW
*win
, const cchar_t
*verch
, const cchar_t
*horch
)
334 PDC_LOG(("box_set() - called\n"));
336 return wborder_set(win
, verch
, verch
, horch
, horch
,
337 (const cchar_t
*)NULL
, (const cchar_t
*)NULL
,
338 (const cchar_t
*)NULL
, (const cchar_t
*)NULL
);
341 int whline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
343 PDC_LOG(("whline_set() - called\n"));
345 return wch
? whline(win
, *wch
, n
) : ERR
;
348 int hline_set(const cchar_t
*wch
, int n
)
350 PDC_LOG(("hline_set() - called\n"));
352 return whline_set(stdscr
, wch
, n
);
355 int mvhline_set(int y
, int x
, const cchar_t
*wch
, int n
)
357 PDC_LOG(("mvhline_set() - called\n"));
359 if (move(y
, x
) == ERR
)
362 return whline_set(stdscr
, wch
, n
);
365 int mvwhline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
367 PDC_LOG(("mvwhline_set() - called\n"));
369 if (wmove(win
, y
, x
) == ERR
)
372 return whline_set(win
, wch
, n
);
375 int wvline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
377 PDC_LOG(("wvline_set() - called\n"));
379 return wch
? wvline(win
, *wch
, n
) : ERR
;
382 int vline_set(const cchar_t
*wch
, int n
)
384 PDC_LOG(("vline_set() - called\n"));
386 return wvline_set(stdscr
, wch
, n
);
389 int mvvline_set(int y
, int x
, const cchar_t
*wch
, int n
)
391 PDC_LOG(("mvvline_set() - called\n"));
393 if (move(y
, x
) == ERR
)
396 return wvline_set(stdscr
, wch
, n
);
399 int mvwvline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
401 PDC_LOG(("mvwvline_set() - called\n"));
403 if (wmove(win
, y
, x
) == ERR
)
406 return wvline_set(win
, wch
, n
);