TextEdit from BASIC
Volume Number: 3
Issue Number: 6
Column Tag: BASIC School
TextEdit from MS BASIC 
By Dave Kelly, MacTutor Editorial Board
As you may recall from previous discussions about MS Basic, there are several
statements in version 3.0 of the interpreter and version 1.0 of the compiler which
have not yet been documented. Well, at least these statements have not been
documented by Microsoft. In fact, they are documented in Inside Macintosh (and books
like Macintosh Revealed ). The statements I refer to are all calls to the Macintosh
Toolbox text-editing routines. Before this version of Basic text-editing was limited to
whatever you could do with the Edit Field statement. The Macintosh text-edit routines
provide basic text editing, with no added features. Some basic text edit capabilities
include cut, paste, copy, insert, delete, and scrolling are provided. Word wrap,
double-clicking to select words, inverse highlighting is supported. It allows you to
edit a single font, style, and size (display only one at a time). It provides the basics of
what full blown word processors provide. Text Edit does NOT support the use of more
than one font or style, fully justified text, tabs and adjustment of spaces between
words in the current system file. However, under the new system file for the Mac II
and SE, multiple fonts and style are supported, but tabs and 32K limitations remain a
problem. The new system file is scheduled to ship in May and should bring these new
features to Mac Plus systems as well. A good review of text edit’s capabilities is given
in the Pascal multi-window example in the January issue of MacTutor.
The Inside Macintosh Edit Records are automatically prepared by MS Basic when
the EDIT FIELD statement is first defined. The Edit Record contains information which
defines the complete Editing environment. You don’t have to know or worry about what
goes on with the Edit Records to use the new calls. Each Edit Field has a handle
(teHandle) which refers to the Edit Record. Microsoft has beefed up the EDIT FIELD
statement so that when the Text Edit field is defined the text string no longer defaults to
a selected state. Otherwise, your program may not have quite the appearance that you
desire, e specially if you are creating a text editor.
In the text edit field, a character position is an index into the text. Position zero
corresponds to the first character of the edit field. The selection range is indicated by
a starting and ending index into the text. The text that will be highlighted when
selected by the mouse is indicated by the start and end indexes. If the starting and
ending position is the same then the position is indicated by the insertion point. The
insertion point is the position where the characters will be inserted.
Fig. 1 Edit Field Text Wraps!
There are 10 new calls which are already built into Basic. These 10 are only
about half of the total number of routines given in Inside Macintosh . The routines
which are not implemented are already provided for by using the EDIT FIELD statement
in Basic. The statements NOT available are:
TEClick TECopy TECut
TEDispose TEGetText TEIdle
TEInit TENew TEPaste
TESetJust TextBox
First a few words about some of the syntax used. The WINDOW(6) function is
used to return the handle (same as teHandle) for the active edit field in the current
output window. WINDOW(6) returns zero if the window has no active edit field. The
SADD() function returns the address of the first byte of data in
. Note that this value is only valid until another string allocation
of a new variable assignment takes place, since string allocations and variable
assignments can cause existing strings to move in memory. The selection range
referred to in some of the statements is the range of text which is selected in an edit
field. Here are the new commands with a quick description of their use and syntax:
TEACTIVATE
Syntax: TEACTIVATE WINDOW(6)
Description: TEACTIVATE displays the insertion point and highlights the selected
text (unless the selection is the insertion point) in the text edit field specified by the
WINDOW(6) function. Macintosh User Interface Guidelines indicate that when a
window is inactive, the text selected in a text field should be inactive and the insertion
point should be hidden. Use this call when your window is activated. Remember that
text edit always works on the currently active grafPort; ie the SetPort result. See
TEDEACTIVATE also.
TECALTEXT
Syntax: TECALTEXT WINDOW(6)
Description: TECALTEXT recalculates each line of text in the edit field indicated
by the WINDOW(6) function. This call should be used whenever the number of
characters per line of the edit field has been changed.
TEDEACTIVATE
Syntax: TEDEACTIVATE WINDOW(6)
Description: TEDEACTIVATE hides the insertion point and unhighlights the
selected text in the text edit field specified by the WINDOW(6) function. Macintosh
User Interface Guidelines indicate that when a window is inactive, the text selected in a
text field should be inactive and the insertion point should be hidden. Use this call
when your window is deactivated. See TEACTIVATE also.
TEDELETE