Classes for creating text cursor tools

The framework includes general classes that you can use to instantiate your own cursor tools by specifying a command to be applied to selected text or a text presentation. The framework also includes several convenience classes for creating highlight tools and controlling the cursor tool graphic.

Standard cursor tool classes

This figure shows the classes you use to create text cursor tools that apply a command to a text or text presenter state selection.


TSimpleTextTool builds a tool that applies a command to a text selection. Typically, TSimpleTextTool represents a tool that an end user selects from a tool palette and uses to apply a command to the next selection created; each TSimpleTextTool encapsulates the command to issue. When the user activates the tool, the creates a TSimpleTextToolInteractor and passes the command to it.

TSimpleTextToolInteractor controls the interaction required to use a TSimpleTextTool. This interactor overrides MMouseEventHandler functions to implement the behavior users see when using the associated text cursor tool, providing feedback as the selection is created. TSimpleTextToolInteractor tracks the mouse and, when the mouse is released, issues the appropriate command against the final target. The interactor uses a TTextToolInteractionTarget to handle creating the target selection.

TTextToolInteractionTarget creates and extends the text selection during tool interaction, based on positional information passed by the tool interactor. The framework includes two concrete derived classes:

Highlight tool classes

The framework includes these classes that implement a text highlighter:


THighlightTextTool implements a tool that highlights text by setting a background color on a text selection. THighlightTextTool provides a highlighter pen-shaped graphic as the cursor graphic. Override CreateCursorGraphic to provide your own cursor graphic.

THighlightTextToolInteractor controls the interaction required to use a THighlightTextTool.

To instantiate a highlighter tool, simply create a THighlightTextTool and specify the highlight color. Set the highlight color either in the constructor or with the SetHighlightColor function. For example, to create a green highlighting tool:

      TRGBColor* highlightColor = new TRGBColor( .5, 1, .5 );
      THighlightTextTool greenHighlighter = new THighlightTextTool( highlightColor );
The default text Tool menu built by TTextMenu includes highlighter tools in red and blue. To build your own menus with highlighting tools, use the control state class TCursorToolSelectionState to build each menu item. Building menu items for text tools is described in "Adding a tool to a menu" on page 118.

NOTE When you select text that has a background color associated with it (for example, highlighted text) using the default selection color, the text does not change color to indicate the selected range. Set the selection color to black to make the selection easier to see.

Text selection I-beam

The framework also includes a single class that implements the standard cursor graphic for text selection:


The text view uses this tool to control selection handling behavior. When the cursor enters a text view, the cursor graphic changes from an arrow to an I-beam.

This tool also appears on the text Tool menu. Selecting this tool deactivates any other active cursor tool.


[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