[comp.sys.mac.programmer] TESetStyle bug

laba-5as@web8g.berkeley.edu (Bob Heiney) (04/30/88)

	I think I've found a bug in TESetStyle.  If it has already been
found and is in a technote, excuse me for posting.

	My application does the following when the user chooses a text
face option (bold, shadow, etc.) from my hierarchical text face menu:

	1. Get the current selection/insertion point style.

	2. If the option is plain text, then set the current face to
[], and go to step 4.

	3. Look and see if the face option is checked or not checked
in the menu.

	3. If it is checked, set the new face to be the current face -
[option], otherwise set the new face to be the current face +
[option].  

	4. Call TESetStyle(doFace,...) with the modified style record.

Here's what happens:

Adding options to the current face always works.

If there is only one face option selected and the user says to
unselect it, then it works just like you'd expect.  The new style is
the old one except that it is no longer bold, shadowed, or whatever it
was before.

No matter how many face options are selected, plain text always works.

If, however, there is more than one face option (e.g. [bold,italic]),
and I try to set the new face (e.g. to [bold,italic]-[italic]) then
TESetStyle does not work.  It leaves the options unchanged.

The work-around to this bug is to call TESetStyle(doFace,...) with a
style whose face is plain text ([]).  Then Call TESetStyle(doFace,...)
with a style that includes the new face.

This bug is not in my code, to the best of my knowledge, because of
the behavior mentioned in the work-around.  If my code were at fault
and I were getting the wrong style or something then the work-around
wouldn't work either.

Sorry if I was a little redundant above, but I wanted the bug and its
circumstances to be very clear.  I have a Mac Plus and am running System
Release 5.0 (System 4.2, Finder 6.0, Multifinder).

Anyone from Apple have any comments?

--------------------------------------------------------------------------
Bob Heiney
laba-5as@widow.berkeley.edu

tecot@Apple.COM (Ed Tecot) (05/10/88)

TESetStyle was ambiguous.  Especially if the selection ran over multiple
styles.  In particular, does the client want to toggle the particular style,
or is this a replacement.  In other words, does [bold] mean "add the bold
attribute to this text" or "make this text just bold"?

TESetStyle in System 6.0 has a new mode selector, doToggle which addresses
these issues.  Stay tuned for a technote near you.

						_emt

freek@uva.UUCP (Freek Wiedijk) (05/11/88)

In article <9453@apple.Apple.Com> tecot@apple.UUCP (Ed Tecot) writes:
>TESetStyle was ambiguous.  Especially if the selection ran over multiple
>styles.  In particular, does the client want to toggle the particular style,
>or is this a replacement.  In other words, does [bold] mean "add the bold
>attribute to this text" or "make this text just bold"?

Why doesn't TESetStyle behave the same way as the Style menu in MacWrite does?

Also: Is it possible to obtain the style information of the selection when it
is longer than one character, without checking all individual characters with
TEGetStyle?
-- 
Freek Wiedijk <the pistol major>                   UUCP: uunet!mcvax!uva!freek
#P:+/ = #+/P?*+/ = i<<*+/P?*+/ = +/i<<**P?*+/ = +/(i<<*P?)*+/ = +/+/(i<<*P?)**

tecot@Apple.COM (Ed Tecot) (06/02/88)

In article <311@uva.UUCP> freek@uva.UUCP (Freek Wiedijk) writes:
>Why doesn't TESetStyle behave the same was as the Style menu in MacWrite does?

It does now, with the "doToggle" bit in the "mode" parameter of the TESetStyle
call.  Otherwise, the given attributes are applied to the entire selection.

>Also: Is it possible to obtain the style information of the selection when it
>is longer than one character, without checking all individual characters with
>TEGetStyle?

Yes.  With the new call "TEContinuousStyle", you can test for style information
continuity across the selection (i.e. is the _whole_ selection italicized?)
Otherwise, the most cost-effective way to handle style analysis is to step
through the "runs" array of the TEStyleRec structure.  It is kept in sorted
order by character position of the start of each unique style (so you can do
a binary search to find the style element for the first character, and search
linearly over the rest of the selection.)

A technical note on these additions is being written and should appear in
the next batch.