Supporting input methods in a text editor

To support input methods in a text editor, you need to implement the abstract class TInputMethodTextPresentation. Your text editor's typing mechanism must pass your implementation of TInputMethodTextPresentation to the typing configuration, using the TTypingConfigurationHandle function Attach, as described in "Processing keystrokes" on page 172.

The Text Editing framework provides an implementation, TTextInputMethodTextPresentation, used by editable text components. See "Supporting input methods" on page 131 for more information on the Text Editing framework's support for input methods.


TInputMethodTextPresentation provides protocols for:

The functions you must override are described next.

Providing visual feedback

Input methods use styles to provide feedback to the user during the conversion process. For example, a particular background color might be used to indicate unconfirmed text in the active area. These styles are displayed by the text editor but are not actually part of the text being edited.

You need to specify how these styles are to be managed. The Text Editing framework provides one possible implementation; the input method styles are maintained by two special classes, TFilteredText and TFilteredTextRepresentation, described in "Supporting input methods" on page 131. These classes act as a filter on the text being edited, letting the text editor superimpose the styles on the text without actually modifying the text. You could also provide an implementation that applied the styles directly to the text. However, be aware that these styles may conflict with similar styles applied to the text by the end user.

To implement your solution for maintaining and displaying styles, override:

These functions take a style set containing the styles to add or remove, the range of text to operate on, and the style kind. The default is to assume styles of the kind Character.

A similar function, RemoveAllActiveStyles, removes all the input method styles of a specified kind from the input method display. If your implementation applies styles directly to the text rather than using a filter, then your class must keep track of where the styles are so that this function can locate and remove them.

Two additional functions are called to alert the presentation when the styles change due to insertion or deletion of characters in the active area:

By default, these functions do nothing. If your implementation uses a filter, you should implement these functions to keep the filter synchronized. If your implementation applies the styles directly to the text, you do not need to override these functions.

Accessing selections

You must override the following functions to allow an input method to access the current selection in the text being edited:

These functions use a
TTextArea instance to represent the selection.

Adopting behaviors

To provide the behaviors used to handle input events--keystrokes and mouse clicks--you need to override these functions:

These functions mirror corresponding functions provided by
MEventTarget. Your implementation should probably call the MEventTarget functions on the view for the text being edited. Calling the default MEventTarget functions ensures that the input method behaviors come before any other behaviors associated with the view.

Processing input

TInputMethodTextPresentation provides a function, FlushInput, that is called by input method behaviors and by other functions that need to ensure that all typing has been processed. Override this function to flush any pending keystrokes into the text object being edited.

Adding interface elements

To allow input methods to install user interface elements, implement the following functions. Typically you can implement all these functions using the GUI bundle mechanism to get a window group accessor from the view on the text component:

To provide a fully functional input method, you must support these functions, as input methods can be extremely difficult to use without the features provided by additional windows. If your text editor cannot support these functions, implement them to throw
TInputMethodCantUseGUIElementException. In this case, the specified window is not adopted.

TInputMethodTextPresentation also provides the following functions that are called by an input method to install and remove a customized menu:

The input method menu provides access to the other input method operations, such as the additional tool palettes, and should be placed near the typing configuration menu. The AdoptInputMethodMenuItem function is called when an input method is activated, and should throw TInputMethodCantUseGUIElementException if your text editor does not support adopting the additional input method menu.

The OrphanInputMethodMenuItem function is called when an input method is deactivated--for example, when a different typing configuration is selected or the view is deactivated. This function should remove the menu from wherever it was installed and return the storage to the caller. OrphanInputMethodMenuItem should not be called if the previous call to AdoptInputMethodMenuItem threw an exception.

Converting between text offsets and coordinates

TInputMethodTextPresentation includes four functions you must override to provide conversion between offsets within the text being edited and either local or global positions:

Input methods call these functions to process mouse clicks and to position floating user interface elements close to the text currently being edited.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker