wordBreak hook
wordBreak hook
The wordBreak hook (the wordBreak field in the edit record) exists to replace
TextEdit's word breaking routine. However, unless you include explicit tests
for scripts, the algorithms you provide may be incorrect for non-Roman
scripts. To provide better compatibility for your application, TextEdit.
disregards the wordBreak hook on non-Roman script systems
supplies a higher-level hook, TEFindWord, which allows you to
customize TextEdit's word breaking
The TEFindWord hook is at a higher level than the wordBreak hook and
replaces TextEdit's word breaking routine. This gives your application more
control over the breaking process and allows you to write more efficient
routines. However, unless your routine correctly determines breaks for all
scripts, you must be sure to check for non-Roman scripts before replacing
TextEdit's routine, which calls the Script Manager's FindWord
procedure.
Here's how the default TEFindWord routine works:
TextEdit initially determines whether a non-Roman script system is
installed. If one is installed, TextEdit always uses the
Script Manager's FindWord procedure for line breaking and word
selection.
If TextEdit determines that only the Roman Script System is
installed and TEFindWord is being called for line breaking, it calls
the wordBreak hook.
If TEFindWord is called for word selection for system software with
only the Roman Script System installed, TextEdit checks to see if
your application has placed the address of a different word breaking
routine in the wordBreak field of the edit record. If so, TextEdit calls
your word breaking routine. Otherwise, if the wordBreak field contains
the address of TextEdit's internal word breaking routine, TextEdit
uses the Script Manager's FindWord procedure to determine word
breaks.
The hook TEFindWord is global and supersedes this default behavior. If you
prefer to customize TextEdit, remember to check for non-Roman scripts if
you desire to replace the word breaking code only on the Roman Script System
with no other scripts installed. To check if non-Roman scripts are enabled, use
the GetEnvirons function with the smEnabled verb. See the
Worldwide Software Overview for details on GetEnvirons.
If you replace TEFindWord, be careful to set the correct values in the
appropriate registers on exit.
When TextEdit calls the Script Manager's FindWord procedure, it uses
information in the edit record to provide the necessary parameters. TextEdit
determines the current script boundaries for the
Script Manager's FindWord routine by using the font-run information in
the style record ( defined by the TEStyleRec data type). TextEdit also
determines the length of the script run and the offset within the script run
from which to begin searching for a word boundary. TextEdit uses the value
in the clikStuff field of the edit record to determine the leadingEdge flag for the
Script Manager's FindWord procedure. You must use similar information
to replace TEFindWord correctly for non-Roman scripts. For more
information, see the Worldwide Software Overview and Macintosh
Worldwide Development: Guide to System Software.