8.4.3 Writing to a Text Subwindow
To insert text into a text subwindow at the current insertion point, call:
textsw_insert(textsw, buf, buf_len)
The return value is the number of characters actually inserted into the text subwindow. This
number will equal buf_len unless either the text subwindow has had a memory allocation
failure or the portion of text containing the insertion point is read only. The insertion point is
moved forward by the number of characters inserted.
This routine does not do terminal-style interpretation of the input characters. Thus, editing
characters (such as CTRL-H or DEL for character erase) are simply inserted into the text
subwindow rather than performing edits to the existing contents of the text subwindow. To
emulate a terminal, scan the characters to be inserted and invoke textsw_edit() where
appropriate, as described in the next section.
220.127.116.11 Setting the insertion point
TEXTSW_INSERTION_POINT is used to interrogate and set the insertion point.
For instance, the following call determines where the insertion point is:
point = (Textsw_index)xv_get(textsw, TEXTSW_INSERTION_POINT);
Whereas the following call sets the insertion point to be just before the third character of the
xv_set(textsw, TEXTSW_INSERTION_POINT, 2, NULL);
To set the insertion point at the end of the text, set TEXTSW_INSERTION_POINT to the special
index TEXTSW_INFINITY. This call does not ensure that the new insertion point will be visi-
ble in the text subwindow, even if TEXTSW_INSERT_MAKES_VISIBLE is TRUE. To guarantee
that the caret will be visible afterwards, call textsw_possibly_normalize(), a pro-
cedure that is described later in this chapter.
8.4.4 Reading from a Text Subwindow
Many applications that incorporate text subwindows never need to read the contents of the
text directly from the text subwindow. For instance, the text subwindow might display text
for the user to view but not to edit.
Even when the user is allowed to edit text, some applications simply wait for the user to per-
form some action that indicates that all of the edits have been made. The application can
then use either textsw_save() or textsw_store_file() to place the text in the ﬁle.
Text Subwindows 219