While working with WText, I encountered the following
situation: I used a CmdBevelButton to change the color of a
WTextView. The result was that the text would be redrawn
twice, once on top of the button that was pressed, and the
second time in the correct place.
The cause was tracked down to my code selecting all the
text programatically and then calling WESetStyle() to change
the color. The call to SelectAll() Focused the Text for
drawing, but not in the desired port. Since the button was
the last thing that had tried to draw, WText established that
as it's port, and drew on top of the button. Installing a
StFocusAndClipIfHidden() call before calling SelectAll() fixes
the problem.
Why, however, should changing the selection range require a
change in Focus? If this were in response to the user clicking
in the text, then the Focus should be set elsewhere. If the
program is setting the selection range programatically, then
it seems that the Focus should remain unchanged.