How the typing configuration handles typing input
The typing configuration provides only a portion of the functionality required to process text input. The typing configuration is responsible for:
- Converting a keystroke to text based on the virtual keyboard
- Calling each text modifier
- Calling the input method
Each text editor must provide a mechanism for interacting with the typing configuration. The Text Editing framework provides this mechanism with the class TTypingInteractor, derived from TInteractor and MKeyEventHandler. All text components based on the Text Editing framework use this class or a derived class, TDocumentTypingInteractor, to process typing input and to control interaction with the typing configuration.
When a user begins typing into a text component, the view for that component activates the typing interactor to handle the input. As the key events occur, the framework calls the TTypingInteractor functions TypeBegin, TypeIncrement, and TypeEnd to process the keystrokes. These interactor functions are responsible for:
- Accessing the text representation object for the text component
- Choosing the typing configuration to use based on the language of the surrounding text or the last configuration explicitly selected by the user
- Invoking the typing configuration to process the keystrokes and convert them to text
- Modifying the text representation object for the text component based on the input text (TTypingInteractor uses the text commands TTypingCommand and TDocumentTypingCommand)
The interaction begins when the user types the first keystroke and ends when either the view is deactivated or the user initiates another kind of interaction--for example, a selection interactor or a cursor tool.
Choosing the typing configuration
In the user environment, one typing configuration is active globally at any given time. For text entered in an empty text input area, TTypingInteractor uses the system typing configuration, or the configuration the user explicitly chooses. End users can alternate between typing configurations as they enter text.
For text input into a nonempty text component, TTypingInteractor attempts to choose the most appropriate typing configuration for the current selection in the text component. For example, if the end user is typing using a global configuration for the English language, but makes a selection in an input area containing Japanese text, the framework switches to a Japanese typing configuration. TTypingInteractor selects a configuration based on the language of the character immediately preceding the selection, choosing the last-selected configuration for that language.
When you create your own typing interaction mechanism, call the TTypingConfigurationHandle functions ChooseConfiguration or GetSystemTypingConfiguration to activate an appropriate configuration. You might also implement a mechanism that does not select a configuration based on language, but changes the configuration only when an end user explicitly requests a change. You would never call ChooseConfiguration when implementing this mechanism.
Representing text
during editing
The Typing framework also provides a class, TTypingStore, that provides abstract protocol for representing the text being edited during the typing interaction:
Each text editor must implement these TTypingStore functions:
- GetText returns a constant pointer to the text currently being edited.
- TypeText takes a text object and a text range and replaces the specified range in the text being editing with the text supplied. You should not be holding a read entry on the typing store object when you call TypeText.
- TypeEnd allows for special behavior to terminate the typing transaction. For example, if the typing interaction is performed using a command, this function commits the command. Using TypeText and TypeEnd together, you can provide an implementation that either directly modifies the text being edited or modifies an incremental typing command and lets it update the text.
- LockTextForReading and UnlockTextForReading provide access control for the text being edited. If your typing mechanism does not require access control, you can override these functions to do nothing. These functions are called by instances of the class TTypingStoreReadEntry when they are created and destroyed. You must acquire a lock by creating the read entry object before calling GetText on a typing store object.
The text editor must provide its implementation of the typing store to the typing configuration when the configuration is invoked. The Text Editing framework provides two implementations, TDocumentTextTypingStore and TSimpleTextTypingStore, used for typing interactions with editable text document components and with simple editable text elements, respectively. TTypingInteractor constructs and maintains the appropriate typing store object. See "Typing interactors" on page 128 for more information on the Text Editing framework implementation.
The Typing framework also provides a special exception class for use with the typing store. TTypingStoreChangedException should be thrown by your TypeText implementation if a situation occurs in which further typing in the current typing transaction is not possible.
TTypingConfigurationHandle provides the functions that allow you to invoke each element of the typing configuration.
To access the virtual keyboard, TTypingConfigurationHandle provides two functions:
- MapKeyToText takes a virtual key code and a modifier key and maps them to text using the virtual keyboard.
- MapKeyEventToText takes the key-event object and maps it to text.
After converting the key event to text, you need to call any text modifiers and the input method. TTypingConfigurationHandle provides mechanisms for both noninteractive and interactive processing of text input.
For noninteractive processing, call the Modify function. Modify takes the following data:
- The text currently being edited
- A range indicating where the new text is to be added
- The text to be added
The Modify function generates the replacement text by invoking each modifier in the chain of modifiers. It returns the replacement text and range. You do not need to provide a typing store if you use Modify.
For interactive processing, your interaction mechanism should call the following TTypingConfigurationHandle functions:
- Attach, passing the typing store and the presentation on the input method (described in "Input Method framework" on page 186). This function allows the configuration to access the typing callbacks while processing the input. Call this function at the beginning of the typing session--for example, in the typing interactor constructor.
- TypeText, to invoke the modifiers and input method. TypeText first calls Modify to invoke the modifiers, and then calls the TypeText function of the typing store. The typing store passes the result of the Modify function to the input method.
- TypeEnd, to finalize the transaction. TypeEnd allows the input method to complete its processing and then calls the typing store's TypeEnd function.
- Detach--a parallel function to Attach, Detach should be called at the end of each typing session (for example, in the typing interactor destructor).
[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