Programming Guide


Writes text into a word wrapped text widget

int sm_ww_write(int field_number, char *buffer, int offset);
int sm_n_ww_write(char *field_name, char *buffer, int offset);

field_name, field_number
Specifies the field to receive the contents of buffer. The field must be a multiline text widget whose word_wrap property is set to PV_YES.

A pointer to a null-terminated buffer that contains the text to write.

The offset into the word wrap field at which to start writing. Supply a value of 0 to start writing at the beginning of the field. If supplied value is greater than the field's total length, Panther recalculates the value of offset to the field's length + 1; the contents of buffer are thereby appended to the end of the field.



sm_ww_write copies buffer text into the specified word wrap field—that is, a multiline text widget whose Word Wrap property is set to Yes. sm_ww_write wraps at the end of words and leaves a space at the end of each line. If a word is equal to or longer than the length of the field, sm_ww_write breaks the word one character before the end of the field, appends a space, and wraps the rest of the word on the next line.

Overflow and Underflow

If you try to copy data that is too large for the field to hold, sm_ww_write truncates the excess text. If the field's original contents exceeds the amount of text in buffer, the leftover text remains in the field. To avoid this, first clear the field with sm_clear_array or one of its variants before calling sm_ww_write.


/* this procedure reads text from a filestream and
* reads each line into a word wrapped field. It uses
* sm_ww_write to reformat the file text so that it
* wraps within the field.
proc wrapFileTextToMulti
vars str, last_char, wwErr, err, fileStream

call sm_fio_error_set(0)

/* get file stream sent from previous dialog */
receive DATA fileStream
err = 0

while (err == 0)
str = sm_fio_gets(fileStream, 255)
/* check for error condition like EOF */
if (str != "")
last_char = sm_n_ww_length("comments")

/* if writing to empty array */
if (last_char = 0)
wwErr = sm_n_ww_write("comments", str, last_char)

/* otherwise add space after last char before write*/
wwErr = sm_n_ww_write("comments", " ", last_char)
wwErr = sm_n_ww_write("comments", str, last_char + 1)
err = sm_fio_error()
call sm_fio_close(fileStream)

See Also

sm_clear_array, sm_ww_length, sm_ww_read