1 /* Public Domain Curses */
5 RCSID("$Id: addch.c,v 1.54 2008/07/13 16:08:17 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int addch(const chtype ch);
13 int waddch(WINDOW *win, const chtype ch);
14 int mvaddch(int y, int x, const chtype ch);
15 int mvwaddch(WINDOW *win, int y, int x, const chtype ch);
16 int echochar(const chtype ch);
17 int wechochar(WINDOW *win, const chtype ch);
19 int addrawch(chtype ch);
20 int waddrawch(WINDOW *win, chtype ch);
21 int mvaddrawch(int y, int x, chtype ch);
22 int mvwaddrawch(WINDOW *win, int y, int x, chtype ch);
24 int add_wch(const cchar_t *wch);
25 int wadd_wch(WINDOW *win, const cchar_t *wch);
26 int mvadd_wch(int y, int x, const cchar_t *wch);
27 int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch);
28 int echo_wchar(const cchar_t *wch);
29 int wecho_wchar(WINDOW *win, const cchar_t *wch);
32 addch() adds the chtype ch to the default window (stdscr) at the
33 current cursor position, and advances the cursor. Note that
34 chtypes can convey both text (a single character) and
35 attributes, including a color pair. add_wch() is the wide-
36 character version of this function, taking a pointer to a
37 cchar_t instead of a chtype.
39 waddch() is like addch(), but also lets you specify the window.
40 (This is in fact the core output routine.) wadd_wch() is the
43 mvaddch() moves the cursor to the specified (y, x) position, and
44 adds ch to stdscr. mvadd_wch() is the wide version.
46 mvwaddch() moves the cursor to the specified position and adds
47 ch to the specified window. mvwadd_wch() is the wide version.
49 echochar() adds ch to stdscr at the current cursor position and
50 calls refresh(). echo_wchar() is the wide version.
52 wechochar() adds ch to the specified window and calls
53 wrefresh(). wecho_wchar() is the wide version.
55 addrawch(), waddrawch(), mvaddrawch() and mvwaddrawch() are
56 PDCurses-specific wrappers for addch() etc. that disable the
57 translation of control characters.
59 The following applies to all these functions:
61 If the cursor moves on to the right margin, an automatic newline
62 is performed. If scrollok is enabled, and a character is added
63 to the bottom right corner of the window, the scrolling region
64 will be scrolled up one line. If scrolling is not allowed, ERR
67 If ch is a tab, newline, or backspace, the cursor will be moved
68 appropriately within the window. If ch is a newline, the
69 clrtoeol routine is called before the cursor is moved to the
70 beginning of the next line. If newline mapping is off, the
71 cursor will be moved to the next line, but the x coordinate will
72 be unchanged. If ch is a tab the cursor is moved to the next
73 tab position within the window. If ch is another control
74 character, it will be drawn in the ^X notation. Calling the
75 inch() routine after adding a control character returns the
76 representation of the control character, not the control
79 Video attributes can be combined with a character by ORing them
80 into the parameter. Text, including attributes, can be copied
81 from one place to another by using inch() and addch().
83 Note that in PDCurses, for now, a cchar_t and a chtype are the
84 same. The text field is 16 bits wide, and is treated as Unicode
85 (UCS-2) when PDCurses is built with wide-character support
86 (define PDC_WIDE). So, in functions that take a chtype, like
87 addch(), both the wide and narrow versions will handle Unicode.
88 But for portability, you should use the wide functions.
91 All functions return OK on success and ERR on error.
93 Portability X/Open BSD SYS V
111 **man-end****************************************************************/
113 int waddch(WINDOW
*win
, const chtype ch
)
119 PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
120 win
, ch
, ch
& A_CHARTEXT
, ch
& A_ATTRIBUTES
));
128 if (y
> win
->_maxy
|| x
> win
->_maxx
|| y
< 0 || x
< 0)
131 xlat
= !SP
->raw_out
&& !(ch
& A_ALTCHARSET
);
132 text
= ch
& A_CHARTEXT
;
133 attr
= ch
& A_ATTRIBUTES
;
135 if (xlat
&& (text
< ' ' || text
== 0x7f))
142 for (x2
= ((x
/ TABSIZE
) + 1) * TABSIZE
; x
< x2
; x
++)
144 if (waddch(win
, attr
| ' ') == ERR
)
147 /* if tab to next line, exit the loop */
162 if (++y
> win
->_bmarg
)
166 if (wscrl(win
, 1) == ERR
)
173 /* don't back over left margin */
184 if (waddch(win
, attr
| '^') == ERR
)
187 return waddch(win
, attr
| '?');
190 /* handle control chars */
192 if (waddch(win
, attr
| '^') == ERR
)
195 return waddch(win
, ch
+ '@');
200 /* If the incoming character doesn't have its own attribute,
201 then use the current attributes for the window. If it has
202 attributes but not a color component, OR the attributes to
203 the current attributes for the window. If it has a color
204 component, use the attributes solely from the incoming
207 if (!(attr
& A_COLOR
))
210 /* wrs (4/10/93): Apply the same sort of logic for the window
211 background, in that it only takes precedence if other color
212 attributes are not there and that the background character
213 will only print if the printing character is blank. */
215 if (!(attr
& A_COLOR
))
216 attr
|= win
->_bkgd
& A_ATTRIBUTES
;
218 attr
|= win
->_bkgd
& (A_ATTRIBUTES
^ A_COLOR
);
221 text
= win
->_bkgd
& A_CHARTEXT
;
223 /* Add the attribute back into the character. */
227 /* Only change _firstch/_lastch if the character to be added is
228 different from the character/attribute that is already in
229 that position in the window. */
231 if (win
->_y
[y
][x
] != text
)
233 if (win
->_firstch
[y
] == _NO_CHANGE
)
234 win
->_firstch
[y
] = win
->_lastch
[y
] = x
;
236 if (x
< win
->_firstch
[y
])
237 win
->_firstch
[y
] = x
;
239 if (x
> win
->_lastch
[y
])
242 win
->_y
[y
][x
] = text
;
245 if (++x
>= win
->_maxx
)
247 /* wrap around test */
251 if (++y
> win
->_bmarg
)
255 if (wscrl(win
, 1) == ERR
)
275 int addch(const chtype ch
)
277 PDC_LOG(("addch() - called: ch=%x\n", ch
));
279 return waddch(stdscr
, ch
);
282 int mvaddch(int y
, int x
, const chtype ch
)
284 PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y
, x
, ch
));
286 if (move(y
,x
) == ERR
)
289 return waddch(stdscr
, ch
);
292 int mvwaddch(WINDOW
*win
, int y
, int x
, const chtype ch
)
294 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win
, y
, x
, ch
));
296 if (wmove(win
, y
, x
) == ERR
)
299 return waddch(win
, ch
);
302 int echochar(const chtype ch
)
304 PDC_LOG(("echochar() - called: ch=%x\n", ch
));
306 return wechochar(stdscr
, ch
);
309 int wechochar(WINDOW
*win
, const chtype ch
)
311 PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win
, ch
));
313 if (waddch(win
, ch
) == ERR
)
316 return wrefresh(win
);
319 int waddrawch(WINDOW
*win
, chtype ch
)
321 PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
322 win
, ch
, ch
& A_CHARTEXT
, ch
& A_ATTRIBUTES
));
324 if ((ch
& A_CHARTEXT
) < ' ' || (ch
& A_CHARTEXT
) == 0x7f)
327 return waddch(win
, ch
);
330 int addrawch(chtype ch
)
332 PDC_LOG(("addrawch() - called: ch=%x\n", ch
));
334 return waddrawch(stdscr
, ch
);
337 int mvaddrawch(int y
, int x
, chtype ch
)
339 PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y
, x
, ch
));
341 if (move(y
, x
) == ERR
)
344 return waddrawch(stdscr
, ch
);
347 int mvwaddrawch(WINDOW
*win
, int y
, int x
, chtype ch
)
349 PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n",
352 if (wmove(win
, y
, x
) == ERR
)
355 return waddrawch(win
, ch
);
359 int wadd_wch(WINDOW
*win
, const cchar_t
*wch
)
361 PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win
, *wch
));
363 return wch
? waddch(win
, *wch
) : ERR
;
366 int add_wch(const cchar_t
*wch
)
368 PDC_LOG(("add_wch() - called: wch=%x\n", *wch
));
370 return wadd_wch(stdscr
, wch
);
373 int mvadd_wch(int y
, int x
, const cchar_t
*wch
)
375 PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y
, x
, *wch
));
377 if (move(y
,x
) == ERR
)
380 return wadd_wch(stdscr
, wch
);
383 int mvwadd_wch(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
)
385 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n",
388 if (wmove(win
, y
, x
) == ERR
)
391 return wadd_wch(win
, wch
);
394 int echo_wchar(const cchar_t
*wch
)
396 PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch
));
398 return wecho_wchar(stdscr
, wch
);
401 int wecho_wchar(WINDOW
*win
, const cchar_t
*wch
)
403 PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win
, *wch
));
405 if (!wch
|| (wadd_wch(win
, wch
) == ERR
))
408 return wrefresh(win
);