Selection interactors

When you create your own selection interactor for use with an editable text component, it needs to:

  1. Implement mouse event handling functions to convert mouse events to text selections.
  2. 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:

    To use a text chunk iterator to find a word:
    1. Call the TTextChunkIterator function CreatePreferredWordSelectionIterator to get a word selection iterator.
    2. 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.
    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:


[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