Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Text /
Chapter 3 - QuickDraw Text / About QuickDraw Text


Carets and Highlighting

Highlighting a selection range and marking the insertion point with a caret both involve converting offsets of characters in a text buffer to pixel locations on a display screen. This task is prerequisite to both drawing a caret and highlighting text. See the chapter "Introduction to Text on the Macintosh" in this book for a discussion of the conventions underlying the relationship of a character at a byte offset to a caret position for unidirectional text and text at a direction boundary.

When the text is unidirectional, performing these tasks is uncomplicated because storage order and display order are the same. For unidirectional text, a caret position always falls between the corresponding glyphs of these characters--on the leading edge of one and the trailing edge of the other. When the text is bidirectional, it can contain characters that occur on direction boundaries; although the characters are stored contiguously in memory, the leading edge of one character's glyph does not constitute the trailing edge of the other in display order. Consequently, two physically separate caret positions exist on the display screen, one associated with each glyph.

There are a number of situations in which you need to know a caret position, and they fall within two categories: drawing a caret to mark the insertion point, and using a caret position to denote an endpoint for highlighting a text selection. For a discussion of marking an insertion point with either a single caret or a dual caret, and caret movement with arrow keys, see the chapter "Introduction to Text on the Macintosh."

You need to know the caret positions marking the endpoints of a text selection to highlight it when the user selects either a word or a range of text, and for other features that the application supports, such as a search operation. Generally, you know the byte offsets of the characters that begin and end a selection range for tasks such as search operations. However, when the user clicks in or selects a range of text to be highlighted, usually you first need to convert the pixel locations marking the cursor locations to the corresponding characters' byte offsets in memory, and then convert the characters' byte offsets to caret positions.To encompass all of the characters within the text segment to be highlighted, you use caret positions that mark endpoints which include the beginning and ending characters of the text.

On a black-and-white screen, highlighting a selection is simple; white pixels turn black and vice versa. In a color environment, the inversion of multibit pixel values usually yields many different colors, which is unsuitable for highlighting text. To highlight text rendered in color, QuickDraw lets you specify a highlight value that it uses instead of the current graphics ports background color. Generally the user sets the highlighting color, but your application can change the color. When you use highlight mode, all pixel values of the current background color are replaced with the value of the highlighting color.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996