The Text Object Model (TOM) is a Microsoft Windows API that provides developers with object-based rich text manipulation interfaces. It is implemented through the Component Object Model (COM) and can be accessed through Microsoft Word or through the RichEdit controls that ship with Windows.
History
TOM was developed under heavy influence from WordBasic, the macro language used in Microsoft Word prior to the introduction of Visual Basic for Applications (VBA) in Word 95 and earlier releases. TOM has evolved alongside RichEdit technology and has been present since version 1.0 of the RichEdit components. The API has been available as an option for Windows CE since RichEdit version 2.5 (Western Languages only), and was used by Pocket Word at that time. Version 8.0 of RichEdit, which shipped with Windows 8, added support for OpenType math.
Technical Details
TOM defines a set of text manipulation interfaces that are supported in varying degrees by several Microsoft text solutions, including the rich edit control. The top-level TOM object is defined by the ITextDocument interface, which has methods for creating and retrieving objects lower in the object hierarchy. To retrieve an implemented instance of the ITextDocument interface, the EM_GETOLEINTERFACE message may be sent via the SendMessage API to obtain a pointer to an IRichEditOle object, which also implements the ITextDocument interface.
Key COM Interfaces
- ITextDocument — The top-level interface. Documents may be opened and saved through this interface. It provides arbitrary text ranges (ITextRange) and a text range for currently selected text (ITextSelection).
- ITextRange — Provides editing and data-binding tools to select text within a document that can be examined, modified, or removed.
- ITextSelection — Provides selection information in addition to functionality provided by ITextRange.
- ITextFont — A dual interface (with ITextPara) for inspection and modification of rich edit font attributes.
- ITextPara — A dual interface (with ITextFont) providing information about paragraph position, formatting, behavior, and purpose.
- ITextStoryRanges — Enumerates the stories in an ITextDocument.
Advantages
- Code can migrate fairly easily between different text solutions (e.g., Word and rich edit controls).
- One language can be used to share text information between different text engines.
- Reduces the need for documentation and code compared to separate low-level COM and VBA interfaces.
Limitations
TOM can be less efficient for C/C++ purposes than the use of more general lower-level COM interfaces. For applications that place minor emphasis on text, it is recommended to provide TOM interfaces by transferring text to an edit control that supports TOM.