Selection interactors
When you create your own selection interactor for use with an editable text component, it needs to:
- Implement mouse event handling functions to convert mouse events to text selections.
- Reset the current selection on the text component.
Handling mouse events
To provide the mouse event handling, override the MMouseEventHandler functions MouseDown, MouseMoved, and MouseUp. These mouse event handling functions should convert the mouse position to positions within the text representation object for the text component. You can call the TTextView function CoordinateToInsertionOffset to map mouse event positions to insertion point positions.
At a minimum, your selection interactor must be able to create insertion point selections when the user single-clicks the mouse and range selections when the user clicks and drags the mouse. You probably also want your selection interactor to support more sophisticated selection handling. The Text Editing framework selection interactor--TSelectTextInteractor--lets the user:
- Extend a previous selection by holding the Shift modifier key down when selecting with the mouse. When the Shift key is pressed when the interactor is started, the TSelectTextInteractor MouseDown function calls the protected function HandleExtendTextSelection to create the extended selection. The extension can be either contiguous or discontiguous to the original selection.
- Double-click to select a word. When MouseDown receives a double-click, it calls the protected function HandleSelectWord. This function uses a TTextChunkIterator to determine the word on which the mouse was double-clicked.
To use a text chunk iterator to find a word:
- Call the TTextChunkIterator function CreatePreferredWordSelectionIterator to get a word selection iterator.
- Call the Current function on the returned iterator, passing it the position of the double mouse click. This function returns the range of the word.
The word selection iterator uses a set of rules specific to the current language to allow it to determine word boundaries. Text chunk iterators are described in "Language-sensitive text selection" on page 208.
- Triple-click to select a sentence. When MouseDown receives a triple-click, it calls the protected function HandleSelectLine. This function also uses a TTextChunkIterator to determine the sentence boundary.
Using a TTextChunkIterator to find a line is identical to using it to find a word, except that you call CreatePreferredSentenceSelectionIterator to get the correct iterator. The sentence selection iterator also uses a set of rules specific to the current language to determine the sentence boundary.
You can change this implementation if it is not appropriate for your application. For example, for a program editor you might want a triple-click to select the current line. To change the implementation, derive your own interactor class from TSelectTextInteractor and override HandleSelectLine.
Creating the selection
To reset the current selection for the component, the MouseUp function should compute the final selection and reset the selection through the view. You can call one of these TTextView functions to reset the selection:
- AdoptCurrentSelection takes the selection as an instance of MTextSelection and adopts it into the view.
- SetCurrentSelection takes a TTextArea representing the selected range, creates a text selection, and adopts it into the view. TTextArea, a simple class that encapsulates either an insertion point position or the currently selected text region, provides an easy way for you to identify a selection without creating a text selection object.
[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