TESetStyle
TESetStyle
Apply a style to currently selected text short mode ; a bit-coded style-operation mode; a Style Mode
TextStyle *newStyle ; address of a 12-byte record containing style info The TESetStyle procedure lets you set a new style for the current selection specified by the edit record.
TESetStyle modifies the characteristics of the currently-selected text. You may change any or all of the font, size, character-style, and color. Options let
you increase or decrease the size of the text and to "toggle" certain attributes.
mode specifies a style operation mode (see Style Mode). Bits of this
value specify which characteristics of the selected text you wish to
modify. The bits are:
newStyle is the address of a 12-byte TextStyle structure. Its fields identify the new characteristics to apply. Depending upon the value of mode,
some fields of this structure may be ignored.
redraw specifies whether or not to redraw the text (update the screen to
reflect the changes). It is one of:
FALSE (0) don't redraw now; wait for an update event and TEUpdate TRUE (1) redraw immediately hTE is a handle obtained via TENew (old style TextEdit record) or TEStylNew (new style TextEdit record). It leads to a variable-length TERec structure and identifies the edit record to be affected by this change.
You specify the new style with the newStyle parameter. The hTE parameter is
a handle to a styled edit record.The mode parameter allows you to control which
style attributes to set. The style attributes may be any additive combination of
the TESetStyle mode constants. The redraw parameter indicates whether to redraw the current selection in its new style.
additional mode, doToggle (= 32). If doToggle is specified along with doFace and
if a style specified in the given newStyle parameter exists across the entire
selected range, then TESetStyle removes (turns off) that style. Otherwise, if the style doesn't exist across the entire selection range, all of the selected text
is set to include that style. When a particular style is set for an entire
selection range, that style is said to be continuous over the selection.
For example, in the selected text in the next figure, the bold style is
continuous over the selection range and the italic style is not.
An initial selection before TESetStyle is called
If you call TESetStyle with a mode of doFace + doToggle and a newStyle parameter with a tsFace field of bold, the resulting selection is as shown in the
following figure. (The text style record is defined by the TextStyle data type.) The result of calling TESetStyle to toggle with a bold style
On the other hand, if you call TESetStyle with a mode of doFace + doToggle and a newStyle parameter with a tsFace field of italic, the resulting selection
is shown in this figure:
The result of calling TESetStyle to toggle with an italic style
If the redraw parameter is set to TRUE, TextEdit redraws the current selection in the new style, recalculating line breaks, line heights, and line
ascents. If the redraw parameter is FALSE, TextEdit does not recalculate line breaks, line heights, and line ascents. Therefore, when a routine is called that
uses any of this information, such as TEGetHeight (which returns a total height between two specified lines), it does not reflect the new style
information set with TESetStyle. Instead, the routine uses the information set before TESetStyle was called. To update this information, you must call the TECalText procedure. A simpler way to be certain that current information is always reflected when drawing is to call the TESetStyle procedure with the redraw parameter set to TRUE. behavior specified above.
If no text is currently selected, TESetStyle sets the values for the NullSTRec (to be applied to text subsequently added at the insertion point).
variety and complexity of the style runs in a selection range.
Face (style) Changes
When mode has the doFace bit set, the effect is to add the characteristic(s)
in newStyle->tsFace into each of the style runs in the selection range. For
instance, if the currently-selected text is:
Some underlined and some italics.
then after:
the text will be redrawn as:
Some Ï underlined and some italics.
The exception is when you use newStyle->tsFace=0; this clears all style face
attributes.
Note: Before you clear the attributes, make sure that all the bytes in
tsFace really are zero. The style information is contained only in the
high byte of tsFace, but TESetStyle checks both bytes. If the high byte is zero and the low byte isn't, TESetStyle will try to add the
characteristics in the high byte. Since the high byte is zero, the text
isn't changed.
instance, you can change each run of bold text with italic text. However, any
combination, such as bold+ underline won't be affected. Face (style) Toggling
When the selected text is already, e.g., italics, the user expects that pressing
I (or selecting an Italics menu item) will turn italics OFF. System 6.0 implements this common technique via a new Style Mode bit, doToggle. When
the user has selected text having multiple face styles, and then presses I to set it as italics, the doToggle+doFace mode either adds italic to all styles in the
selection, OR, if all styles in the selection already contain italics, it clears
italics from each style run. This is probably exactly what the user wanted
when pressing I. For instance, if the selected text is: Some underlined, some italics, some normal, and Èsome outlined.
when the user presses I for italics and you execute the code: theStyle.tsFace = italic;
the text will be redrawn as:
Ô-Some underlined, some italics, some normal, and Ô.some outlined.
That is, it works exactly as doFace alone does. But now, if the user presses
I, the meaning is probably "turn italics OFF". And since italics is continuous across the entire selection, the same call sequence will yield:
Some underlined, some italics, some normal, and Èsome outlined.
or use some other toggling algorithm.
Font Size Changes
Set mode to doSize, and set newStyle->tsSize to change the point-size of all selected text.
When mode has the addSize bit set, the value in newStyle->tsSize is taken as a "delta" to be added to the current size in each style run in the selected text. For
instance, if the selected text is:
Ô/Some 18-pt and some 12-Pt type
then after:
theStyle.tsSize = -6;
the selected text will be:
Some 18-pt and some 12-Pt type