OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Using the Document Manager

The document manager, an instance of TDocManager or a TDocManager-derived class, performs a number of tasks:

  • Manages the list of current documents and registered templates
  • Handles the standard File menu command events CM_FILENEW, CM_FILEOPEN, CM_FILESAVE, CM_FILESAVEAS, CM_FILECLOSE, and optionally CM_FILEREVERT
  • Provides the file selection interface

To support the Doc/View model, a document manager must be attached to the application. This is done by creating an instance of TDocManager and making it the document manager for your application. The following code shows an example of how to attach a document manager to your application:

class TMyApp : public TApplication
{
public:
TMyApp() : TApplication()
{}
void InitMainWindow()
{
.
.
.
SetDocManager(new TDocManager(dmMDI | dmMenu));
.
.
.
}
};

You can set the application document manager to a new object using the TApplication::SetDocManager() function, which takes a TDocManager* and returns a pointer to the old document manager.

Note that there are two SetDocManager functions, TApplication::SetDocManager() and TDocument::SetDocManager(). These functions have different signatures and member functions. Do not confuse them.

The document manager's public data and functions can be accessed through the document's GetDocManager function. GetDocManager takes no parameters and returns a TDocManager&. The document manager provides the following functions for creating documents and views:

  • CreateAnyDoc presents all the visible templates, while the TDocTemplate member function CreateDoc presents only its own template.
  • CreateAnyView filters the template list for those views that support the current document and presents a list of the view names, while the TDocTemplate member function CreateView directly constructs the view specified by the document template class.

Specialized document managers can be used to support other needs. For example, an OLE 2 server needs to support class factories that create documents and views through interfaces that are not their own. If the server is invoked with the Embedded command-line flags, it doesn't bring up its own user interface and can attach a document manager that replaces the user interface with the appropriate OLE support.

See Also