[comp.sys.next] Appkit question on fonts & text

jl3p+@andrew.cmu.edu (James Ting Lui) (02/19/91)

I am currently working on an application which requires
the frequent entry of some common mathematical symbols.
To facilitate this, I have created a panel which contains
buttons for the symbols needed.  When one of these buttons
are pushed, it puts the appropriate symbol into a text object.
I have noticed that any text following the symbol is also
of the symbol font.  Does anyone know how to insert the symbol
into the text without affecting the font of the characters
which are entered following it?

I have tried selecting the zero-length position following the symbol
and setting it to the text's font.  This doesn't work, and the font
method for Text returns the first font in the text in a multi-font
text object anyway.

I've also tried inserting the symbol with an extra space, where both
the symbol and space are in the current text font, then changing the
symbol character to the symbol font and then deleting the space.  This
does not work either.  But I have noticed that if I do this but do not
delete the space programmatically ( with delete: method or by a replaceSel:
with "" ) but by pushing the delete key, it has the desired result.
Is there a better solution then simulating a key press?

Finally, I used setAutodisplay: NO/YES to make the symbol insertion
look cleaner.  The code goes something like this:

    [ theText setAutodisplay: NO ];
    [ theText setSel: start : end ];
    newEnd = start + theSymbolLen;
    [ theText replaceSel: theSymbol ];
    [ theText setFontFamily: [ theSymbolFont name ] ];
    [ theText setAutodisplay: YES ];
    [ theText setSel: newEnd : newEnd ];

When I pushed the symbol button to insert the symbol,
I get these funny white blocks on the panel next to
the button I am pushing.  It's as if the changes made
to the text object is somehow reflected back to the
panel where the button is ( the text is on a separate window
all of its own ).  If the setAutodisplay: YES line above
is moved up to before the setSelFontFamily: method is called,
then these white blocks do not show up.  By the way, these
blocks appear after I've pushed the button a couple of times,
then they appear one-to-one for each button press thereafter.

Sorry to make this all sound so complicated, but this really
seems to be a big mess of a problem and I have no clue on how
to solve it.  I'd appreciate any help anyone can give me on it.

Thanks a lot,
    -- Jim

dml@esl.com (Denis Lynch) (02/26/91)

In article <8bk42oS00UhWM3B1Yx@andrew.cmu.edu> jl3p+@andrew.cmu.edu (James Ting Lui) writes:

<A lot of stuff I don't know the answer to, unfortunately)

   Finally, I used setAutodisplay: NO/YES to make the symbol insertion
   look cleaner.  The code goes something like this:

       [ theText setAutodisplay: NO ];
       [ theText setSel: start : end ];
       newEnd = start + theSymbolLen;
       [ theText replaceSel: theSymbol ];
       [ theText setFontFamily: [ theSymbolFont name ] ];
       [ theText setAutodisplay: YES ];
       [ theText setSel: newEnd : newEnd ];

   When I pushed the symbol button to insert the symbol,
   I get these funny white blocks on the panel next to
   the button I am pushing.  It's as if the changes made
   to the text object is somehow reflected back to the
   panel where the button is ( the text is on a separate window
   all of its own ).  If the setAutodisplay: YES line above
   is moved up to before the setSelFontFamily: method is called,
   then these white blocks do not show up

Exactly right. Don't mess with a Text object with display disabled!
Or, more specifically, don't do a setSel: with display disabled.
What appears to happen is that disabling display tells the Text not
to do *almost all* of its display stuff. Among other things, that
means it doesn't lockFocus on its way through its operation.

Unfortunately, the highlight part of setSel: doesn't notice that
display is disabled, it just goes right ahead and does the highlight
operation. But wait, it didn't lockFocus! Look at those pretty white
blocks in my menu! See the splotchy background in my window!
(This bug has been there at least since 0.9, when I reported it.)

In the mean time, use disableFlushWindow and reenableFlushWindow.
(Remember the flushWindow or flushWindowIfNeeded).  They work fine,
and have the desired visual effect. Probably not as fast as the
disableDisplay, but that's not important in your case anyway.

--Denis Lynch, ESL Inc.