template<class Interface>
class CViewInterface< Interface >
Base class for snapshot view interfaces. Use of snapshot view interfaces is extremely rare in the application codebase. They should only be used if absolutely necessary. For example, ILayoutControlData on the layout widget is a snapshot view interface. The data in this interface is depended on by many other objects and must be kept in tight synchronisation with the database at all times.
Background:
Suppose that you have a user interface object such as a widget that has data that depends on model objects that persist in a database that supports undo and your data needs to be updated when the model objects it depends on are modified, or when modifications are undone or redone. You have concluded that you cannot use lazy notification to update your data because it must be kept up to date with changes to the model at all times.
The state of a snapshot view interface is snapshot before it is changed, reverted on undo and restored on redo. It is very similar to a snapshot interface. The distinction is that the database a snapshot interface is associated with is fixed and is implicitly defined by the persistent boss it is aggregated on. A snapshot view interface on the other hand, is part of a user interface object and must explicitly identify the database containing the model objects it depends on. Also, it is not fixed to be one specific database. For example, a widget that tracks some state in the front document must change the target database when the front document changes.
To implement a snapshot view interface:
- Aggregate IID_IVIEWOBJECTCHANGES on the user interface boss class and use the implementation, kViewObjectChangesImpl, provided by the API.
- Aggregate your snapshot view interface on the user interface boss class.
- Provide an abstract interface for your snapshot view interface that uses IPMUnknown as a base class, IYourViewableInterface for example.
- Provide an implementation of this IYourViewableInterface using the templated class CViewInterface. For example: class YourViewableInterface : public CViewInterface<IYourViewableInterface>
- Use CREATE_VIEW_PMINTERFACE to make your implementation class available to the
- Define a SnapshotReadWrite method for your implementation class, it gets called to serialize snapshots of your data when needed.
- Call PreDirty within mutator methods before changing member variables that you serialize in SnapshotReadWrite.
- When the model objects you depend on are changed call mutator methods to modify the state of your interface. The application takes a snapshot of your interface, reverts the state on undo and restores it on redo.
- When your Reset method is called forcibly rebuild the data in the interface. For example, imagine a panel that has a snapshot view interface that tracks data from the front document. Consider performing a set of operations on a document with a panel closed. When the panel opens it refreshes and displays information from the front document. As the document is modified by subsequent operations the snapshot view interface tracks the changes. If the user performs undo on the document, to a point prior to when the panel was opened, a mechanism is required to forcibly rebuild the data in the snapshot view interface. The Reset method provides that functionality.
- Make sure the target database is set by calling IViewObjectChanges::SetTargetDB on the interface that resides on the same boss.
- See Also
- IViewObjectChanges