TAbstractPanelFormatter provides a complete set of abstract member functions that you implement to create a text formatter. TAbstractPanelFormatter also stores the resolution at which to format the text as an instance of TGrafMatrix, and provides the protocol for accessing the resolution. You can set this resolution to an ideal resolution for your layout and formatting or to the resolution of a specific device. TAbstractPanelFormatter treats this resolution as a const value. When text is displayed, it uses the actual resolution of the port into which the text is drawn.
This figure shows the TAbstractPanelFormatter functions you must implement:
The TAbstractPanelFormatter functions provide protocol for referencing a single panel (or formatting area). Your derived class must specifically provide for any formatting across multiple panels.
Following are brief descriptions of the TAbstractPanelFormatter abstract member functions. For complete descriptions, see the online class and member function documentation.
Initialize sets the parameters for the formatter, specifying:
- The text to format
- The formatting area
- Whether to wrap the text when formatting
- Whether the area has an infinite height that grows as text is input
The Initialize function must be called after the formatter has been constructed and the initial text and size of the formatting area are present. You must ensure that Initialize is called once before any other formatter functions are called.
The following functions provide access to information about the panel (formatting area):
- GetNumberOfLines returns the number of lines of text after the text is formatted according to the bounds of the formatting area.
- GetLineInformation returns the following information about a specific line, identified by line number:
- The range of text in the line relative to the text object being formatted
- The area of the line as a TGRect
- The baseline origin of the line
- GetTargetRectangle and SetTargetArea access the shape of the formatting area, assuming the shape is a rectangle. If you use these accessors, the value IsTargetAreaRectangular should automatically be set to True.
- IsTargetAreaRectangular lets you query whether the formatting area is rectangular.
- IsInfiniteHeight and SetIsInfiniteHeight determine whether the formatting area is of infinite height--that is, whether it grows infinitely to contain all input text. By default this value is True.
- IsNoWrap and SetIsNoWrap determine whether the formatter wraps lines and hyphenates words to fit within the formatting area. By default, the formatter wraps lines--the value of IsNoWrap is False. When you set this value to True, you effectively create a formatting area of infinite width.
- GetResultantRectangle provides the actual area of formatted text after formatting. The area returned by this function should represent tight bounds--that is, with no allowance for the border thickness.
- GetLooseBoundsRectangle also provides the actual area of formatted text, allowing for border thickness and other factors that determine the actual area drawn in when displaying the text. The area returned by this function completely contains the area returned by GetResultantRectangle.
The following functions handle changes to the associated text or to the size and shape of the formatting area:
- PostChanges receives TTextNotification objects. When you create your own text editing application, you should ensure that this function receives notification of any change to the text, style, or formatting area that would affect text visibility, metrics, spacing, or text flow. The formatter should accumulate posted changes until FlushChanges is called.
- FlushChanges reformats the text based on the changes accumulated since the last call. The formatter should maintain information about damaged areas that need to be redrawn. FlushChanges should flush this information and record information about newly damaged areas as it reformats the text.
- GetDamagedArea returns the currently damaged area within the formatting area. This represents the area that was changed during the last call to the FlushChanges function.
Draw displays the formatted text. The Draw function resolves the text to the resolution of the specified graf port, but it does not recalculate line breaks. You should ensure that FlushChanges is called before drawing if any changes occurred since the last time FlushChanges was called.
The following functions allow conversion between external graphics coordinates and ranges of text--that is, a text range, text area, or insertion offset:
- GetSelectedArea calculates the area of a text selection within the formatting area. You pass in the TTextArea representing the selection, and GetSelectedArea returns a TGArea.
- ConvertPositionToInsertionOffset and ConvertInsertionOffsetToPosition perform conversions between a TGPoint and a TInsertionOffset.
- FindNewInsertionOffset calculates the insertion offset either one character or line above, below, to the left of, or to the right of the current insertion offset. TAbstractPanelFormatter provides two enumerations you use to specify the offset to calculate:
- EDirectionToMove lets you specify whether you want the insertion offset to move up, down, left, or right.
- EAmountToMove lets you specify whether you want the insertion offset to move a single position (one character or line) or to the limits of the range (either to the beginning or end of the line or to the first or last line).
[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