Representing a text selection

The text system includes classes that conceptually encapsulate a selection within a text object. A text selection can be an insertion point, a selected range, or multiple discontiguous selected ranges. The Text Editing framework uses these two simple classes to represent selections within a text component:

Representing insertion points

TInsertionOffset encapsulates the following information to identify the position of an insertion point:

By default, the TInsertionOffset positions the insertion point just before the offset. If you do not specify an offset, the insertion point is placed just before offset zero, at the beginning of the text object.


The Text Editing framework uses TInsertionOffset to represent the current insertion point within editable text components. Use this class to represent insertion points when you want to support placement of an insertion point within displayed text by the user's cursor key movements or mouse clicks.

Encapsulating the selection

TTextArea encapsulates data that identifies a selection within a text object. TTextArea encapsulates two objects:


You can construct a TTextArea with a TInsertionOffset, a TTextRange, or a TTextRegion. Both the insertion offset and text region data members are guaranteed to always have valid values. When you set the TTextArea to identify an insertion point selection, the TTextRegion object contains a single text range of length zero. When you set the TTextArea to identify a selected range or multiple selected ranges, the TInsertionOffset refers to the final offset of the last range in the selection.

The system also includes an iterator, TTextAreaIterator, that you can use to retrieve ranges from a TTextArea. TTextAreaIterator provides standard iteration functions that return the first, last, next, and previous range in a TTextArea instance. You specify the TTextArea when you construct the iterator.

The Text Editing framework uses this class as a lightweight mechanism for representing text selections. TTextArea includes functions that facilitate creating selection--SelectAllText, DeselectAllText, and ExtendTextSelection. See "Text selection classes" on page 142 for more information on how TTextArea is used.


[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