Free format textboxes

image0

Assigning a value to the optional height = clause turns a textbox into a standard Microsoft type free format box, with word wrapping.

A free format type textbox should be linked to a long text field. This is a subscripted alphanumeric (type a) field with the p (packed text) flag. In this field type text is packed into the array, instead of being stored in each element on a line by line basis. This prevents text from being lost when the user types short lines with hard line feeds (as opposed to soft line feeds generated by the automatic word wrap. Packed text was introduced in Sculptor 5.3. Its use is strongly recommended, even if this requires some modification to existing code that parses words from the text, since words can now be split across array elements. See Field flags.

The maximum number of characters which may be typed into the box (excluding new line characters) is equal to the number of text lines times the width of the box. The defaults for these values are derived from the linked field, but may both be changed, as shown below.


Number of text lines

The maximum number of text lines possible defaults to the dimension of the linked field. This can be changed by use of the rows = clause, which can be used to limit the total number or characters typed. When used in conjunction with a free format textbox, the rows = clause defines the maximum number of lines of text which can be entered. If the textbox height is not sufficient to display all the rows, use the style flag WS_VSCROLL to create a vertical scroll bar for the textbox.


Width

The width = clause can be used with a free format textbox to limit the number of characters on one line. It may be advisable to use this property to reduce the default width if a proportional font is being used for the display of textbox data. This is because Sculptor sets the default free format textbox width assuming that characters of average width will be used. In a free format textbox, if a line of text with a lot of narrow characters is entered, characters will be lost unless the textbox width is reduced from the default.

If a proportional font is being used for the display of textbox data, ensure that the length of the linked field is sufficient to store the maximum number of characters that can be entered on a single line.

The style flag WS_HSCROLL can be used with a free format textbox to create a horizontal scroll bar. Note however that automatic word wrapping will not take place, because the number of characters that can be typed on one line is unlimited. This feature should therefore be used with great care.

The display command takes each line of text from the linked field and displays it in the corresponding row of the textbox.

The dialog and input commands store each line of text in the corresponding element of the linked field.


Terminating lines manually

Free format textboxes will store in the linked field a new line character (RETURN) entered by the user. The newline character (chr(13)) is the last non-space character in a line containing previous input. When the text is redisplayed, user-entered newlines are preserved. Elements of the linked field which do not end with a newline character were caused to end by automatic word wrap, and are redisplayed with text wrapped to fit the width of the textbox.


Exporting free format text

Free format text may be exported to Windows applications which expect to receive text in standard Windows format. To achieve this, append chr(10) to all rows which Sculptor terminates with chr(13). Optionally, to preserve soft newlines (those created by auto-wrapping), add chr(13), chr(10, chr(13) to other rows.

Note that the following definitions exist in $SCULPTOR/include/sculptor.h.

!define CHR_LINEFEED

chr(10)

!define CHR_RETURN

chr(13)


EXAMPLE

In this example the text to be displayed in a free format textbox is retrieved from a sequential file.

!temp QueryText,,a200[_MAXQUERYLINES],,p

+window wintask at 10,86 {
    max_width = 780
    max_height = 530
    title = "Free format textbox test"

    +textbox QueryTextBox at 18,78 {
        field = QueryText
        label = ""
        rows = _MAXQUERYLINES
        height = 500
        width = 605
        data_font = "Courier New @10"
    }
}

!function DisplayQuery(Path) {
!temp Line,,a200,,v

    open #2, Path read nsf = OPENNSF err = OPENERR
    while (TRUE) {
        get #2, Line err = BREAK
        Line = Line + chr(13) + chr(10)
        QueryText = QueryText / Line
    }

    display QueryTextBox
    close #2
    return

OPENNSF:
    ErrMsg = "No such file error reading file " + Path / ""
    return

OPENERR:
    ErrMsg = "Error " + tostr(sys.Error) / " reading file " + Path / ""
    return
}

RELATED TOPICS

Textboxes

Multi-row textboxes