Text Object Model

This section contains information about the programming elements used with the Text Object Model (TOM).

The TOM defines a substantial set of text manipulation interfaces. Text solutions such as Microsoft Word and rich edit controls support the TOM feature set. TOM was greatly influenced by WordBasic (the programming language used for Word) and it is easy to use from Microsoft Visual Basic for Applications (VBA). This compatibility has several advantages:

  • Code can migrate fairly easily from one solution to another.
  • One language can be used to share text information between different text engines.
  • It reduces the need for documentation and code compared to the separate low-level Component Object Model (COM) and VBA interfaces.

However, it can be less efficient for C/C++ purposes than the use of more general lower level COM interfaces.

TOM is a straightforward set of interfaces to implement for its primary text solutions, Word and rich edit controls. However, for applications that place minor emphasis on text, it is better to provide TOM interfaces by transferring the text to an edit control that supports TOM. Since rich edit controls ship with Microsoft operating systems, they are the standard means of obtaining TOM functionality.

Overviews

Topic Contents
About Text Object Model The top-level Text Object Model (TOM) object is defined by the ITextDocument interface, which has methods for creating and retrieving objects lower in the object hierarchy.
Using The Text Object Model The code samples in this document show various aspects of using the Text Object Model (TOM).

Interfaces

Topic Contents
ITextDocument The ITextDocument interface is the TOM top-level interface, which retrieves the active selection and range objects for any story in the document whether active or not. It enables the application to:
  • Open and save documents.
  • Control undo behavior and screen updating.
  • Find a range from a screen position.
  • Get an ITextStoryRanges story enumerator.

When to Implement
Applications typically do not implement the ITextDocument interface. Microsoft text solutions, such as rich edit controls, implement ITextDocument as part of their TOM implementation.
When to Use
Applications can retrieve an ITextDocument pointer from a rich edit control. To do this, send an EM_GETOLEINTERFACE message to retrieve an IRichEditOle object from a rich edit control. Then, call the object's IUnknown::QueryInterface method to retrieve an ITextDocument pointer.
ITextFont TOM rich text-range attributes are accessed through a pair of dual interfaces, ITextFont and ITextPara.
ITextPara TOM rich text-range attributes are accessed through a pair of dual interfaces, ITextFont and ITextPara.
ITextRange The ITextRange objects are powerful editing and data-binding tools that allow a program to select text in a story and then examine or change that text.
ITextSelection A text selection is a text range with selection highlighting.
ITextStoryRanges The purpose of the ITextStoryRanges interface is to enumerate the stories in an ITextDocument.