Important: The information in this document is obsolete and should not be used for new development.
MacApp's Document Classes
As the hierarchy in Figure 7-1 shows, each of MacApp's document classes descends from theTCommandHandlerclass and each inherits from theMScriptableObjectclass. As a result, each of MacApp's document classes is capable of creating commands to respond to user actions and of working with Apple events.MacApp provides the following document classes for your application to build on:
These document classes are described in greater detail in the sections that follow.
TDocument- The
TDocumentclass is an abstract class that defines methods for performing basic document operations.TFileBasedDocument- The
TFileBasedDocumentsubclass ofTDocumentadds methods for working with disk files.TFileBasedDocumentis a suitable parent class for many standard documents.TEditionDocument- The
TEditionDocumentsubclass ofTFileBasedDocumentadds Edition Manager support for publishing and subscribing. Applications that use publish and subscribe can define a subclass ofTEditionDocument.TMailableDocument- The
TMailableDocumentsubclass ofTFileBasedDocumentadds support for turning a document into an electronic mailer. If your application needs to take advantage of MacApp's PowerTalk mailer support, you can define a subclass of theTMailableDocumentclass.TTEDocument- This subclass of
TMailableDocumentis defined in the DemoText sample application. While not a part of the MacApp class library, it does demonstrate the use of PowerTalk mailers and many text-editing features.The TDocument Class
TheTDocumentclass is an abstract class--you don't normally instantiate objects of this type. Some of the methods defined inTDocumentdo nothing and are overridden in MacApp's document subclasses.Most of MacApp's document classes are designed primarily for working with disk-based documents. If your application requires other types of documents, such as documents contained in databases or documents contained inside other documents, you can define a subclass of
TDocument.The
TDocumentclass provide basic services, such as creating a document's views, setting up its menu items, and handling document-related menu commands, including Save, Save As, Save a Copy, and Revert to Saved.TDocumentalso mixes in theMScriptableclass, so any subclass ofTDocumentcan be a target for Apple events and can return contained objects. TheMScriptableclass is described in Chapter 6, "Scripting."
TDocumentdefines these methods for responding to Apple event object-specifier queries:GetContainedObject,GetObjectProperty, andSetObjectProperty. These methods can handle certain requests themselves and pass others on to the mixinMScriptableclass.
TDocumentalso defines these methods for handling Apple events:DoAEClose,DoAEPrint, andDoAESave. These methods create command objects to handle the specified operation. For example,DoAEClosecreates aTCloseDocCommandobject to close the document.The TFileBasedDocument Class
TheTFileBasedDocumentclass is a subclass ofTDocumentthat adds fields and methods for reading a document from a file, writing a document to a file, and determining how much room a document will take on disk. If the document has an attached script, theTFileBasedDocumentclass can write the script to the document's resource fork or read it from the resource fork.
TFileBasedDocumentworks with theTFileHandlerandTFileclasses.TFileprovides a convenient interface to files on disk.TFileHandlercontains much of the code for saving and opening file-based documents.TFileBasedDocumentandTFileHandlerare so tightly integrated that they can be thought of as two parts of the same object. Files and file handlers are described in greater detail in "Document Operations," beginning on page 168.Subclasses of
TFileBasedDocumenttypically override methods for reading and writing data and for determining how much room data will require on disk.TFileBasedDocumentalso overridesDoAECloseto create aTCloseFileDocCommandobject to close the document. For recipes and code samples that demonstrate how to work with file-based documents, see Chapter 16, "Working With Documents."The TEditionDocument Class
TheTEditionDocumentclass is a subclass ofTFileBasedDocumentthat adds support for publish and subscribe, using the Edition Manager. This class enables and handles the menu commands Create Publisher, Subscribe To, Publisher/Subscriber Options, Show/Hide Borders, and Stop All Editions.When you define a subclass of
TEditionDocument, you don't normally override methods that supply Edition Manager functions. Instead, you override methods involved in reading, writing, or displaying your document's edition data.MacApp's Edition Manager support is described in detail in "Publish and Subscribe," beginning on page 184. Recipes and code samples are provided in Chapter 31, "Working With the Edition Manager." Edition Manager support for publish and subscribe is demonstrated in the Calc sample application.
The TMailableDocument Class
TheTMailableDocumentclass is a subclass ofTFileBasedDocumentthat adds methods for working with a document as electronic mail, using MacApp's PowerTalk support. Working with the mixin classMMailable, which in turn works with theTFileBasedLetterclass, theTMailableDocumentclass enables and handles the Mail menu commands Add/Delete Mailer, Send, Reply, Forward, and Open Next Letter.Any document object based on the
TMailableDocumentclass can be turned into an electronic mailer. Subclasses ofTMailableDocumenttypically override methods for supplying or extracting their own data, such asAddStandardMailContent,ReadStandardMailContent, andSetReplyContents. TheTTEDocumentclass from the DemoText sample application provides a detailed example of a mailable document class.TTEDocumentis described in the next section.For more information on mailers, see "PowerTalk Mailers," beginning on page 192. Recipes and code samples are provided in Chapter 29, "Working With PowerTalk Mailers."
The TTEDocument Class
TheTTEDocumentclass is a subclass ofTFileBasedDocumentthat adds fields and methods for handling text and text-editing views, as well as for adding a PowerTalk electronic mailer to a document. This class demonstrates how to write text data to a file and read it back. It also demonstrates how to read and write mailer data in various formats. TheTTEDocumentclass is not a part of MacApp itself, but is defined in the DemoText sample application. You can read more about theTTEDocumentclass in Chapter 29, "Working With PowerTalk Mailers."