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 theTCommandHandler
class and each inherits from theMScriptableObject
class. 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
TDocument
class is an abstract class that defines methods for performing basic document operations.TFileBasedDocument
- The
TFileBasedDocument
subclass ofTDocument
adds methods for working with disk files.TFileBasedDocument
is a suitable parent class for many standard documents.TEditionDocument
- The
TEditionDocument
subclass ofTFileBasedDocument
adds Edition Manager support for publishing and subscribing. Applications that use publish and subscribe can define a subclass ofTEditionDocument
.TMailableDocument
- The
TMailableDocument
subclass ofTFileBasedDocument
adds 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 theTMailableDocument
class.TTEDocument
- This subclass of
TMailableDocument
is 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
TheTDocument
class is an abstract class--you don't normally instantiate objects of this type. Some of the methods defined inTDocument
do 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
TDocument
class 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.TDocument
also mixes in theMScriptable
class, so any subclass ofTDocument
can be a target for Apple events and can return contained objects. TheMScriptable
class is described in Chapter 6, "Scripting."
TDocument
defines 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 mixinMScriptable
class.
TDocument
also defines these methods for handling Apple events:DoAEClose
,DoAEPrint
, andDoAESave
. These methods create command objects to handle the specified operation. For example,DoAEClose
creates aTCloseDocCommand
object to close the document.The TFileBasedDocument Class
TheTFileBasedDocument
class is a subclass ofTDocument
that 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, theTFileBasedDocument
class can write the script to the document's resource fork or read it from the resource fork.
TFileBasedDocument
works with theTFileHandler
andTFile
classes.TFile
provides a convenient interface to files on disk.TFileHandler
contains much of the code for saving and opening file-based documents.TFileBasedDocument
andTFileHandler
are 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
TFileBasedDocument
typically override methods for reading and writing data and for determining how much room data will require on disk.TFileBasedDocument
also overridesDoAEClose
to create aTCloseFileDocCommand
object 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
TheTEditionDocument
class is a subclass ofTFileBasedDocument
that 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
TheTMailableDocument
class is a subclass ofTFileBasedDocument
that 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 theTFileBasedLetter
class, theTMailableDocument
class enables and handles the Mail menu commands Add/Delete Mailer, Send, Reply, Forward, and Open Next Letter.Any document object based on the
TMailableDocument
class can be turned into an electronic mailer. Subclasses ofTMailableDocument
typically override methods for supplying or extracting their own data, such asAddStandardMailContent
,ReadStandardMailContent
, andSetReplyContents
. TheTTEDocument
class from the DemoText sample application provides a detailed example of a mailable document class.TTEDocument
is 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
TheTTEDocument
class is a subclass ofTFileBasedDocument
that 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. TheTTEDocument
class is not a part of MacApp itself, but is defined in the DemoText sample application. You can read more about theTTEDocument
class in Chapter 29, "Working With PowerTalk Mailers."