Supporting embedding
To support embedding, the major components of your program should derive from the Presentation framework classes that provide the protocol for embedding:
- TGUIEmbedderModel provides a simple mechanism for embedding in which the model keeps a list of embedded document components separate from its own native data.
- TGUIEmbedderModelView builds a view on a TGUIEmbedderModel. It maintains frames for embedded document components in a separate layer on top of the main view, and handles adding and removing these frames as necessary.
- TGUIEmbedderModelSelection allows selections on a TGUIEmbedderModel to be cut or copied to the clipboard and then pasted into another document. TGUIEmbedderModelSelectionFor<AModel> is a template class that you can derive from to create a selection class for a specific TGUIEmbedderModel class. You need only override the three functions that handle the data exchange for the data in your model class. The framework handles cutting and pasting embedded components into your model.
If you derive your model, view, and selection from these classes, the Presentation framework provides the following automatic support:
- Cut, copy, and paste capability with full support for undo and redo
- Automatic highlighting of the Cut, Copy, Paste, Undo, and Redo menu items on the Edit window for your document component
- Support for fully active embedded components, including the ability to select, drag, and resize them
- Saveless model for compound documents
In this step, the classes representing the major components of the Tiles program--model, view, and selection--are modified to derive from the three embedder classes described above. With the exception of TTilesSelection, this change doesn't require any additional or changed functions (the GUI embedder classes derive from the same classes that the Tiles classes were originally derived from).
This figure shows the new class hierarchy for the Tiles program:
TTilesSelection needs to override the three functions that support data exchange for a TTilesModel:
- CopyDataIntoModelSubclass takes a destination model as a parameter and copies the data in the source model specified by this selection into the destination model. You can assume that the destination model is empty.
The Presentation framework calls this function to copy selected data to the clipboard when a user chooses the Copy feature, as shown in this figure:
- MoveDataIntoModelSubclass takes a destination model as a parameter and moves (copies and deletes) the data in the source model specified by this selection into the destination model. Again, you can assume that the destination model is empty. After moving in the data, this function should reset the selection so that it indicates where data should be reinserted.
The Presentation framework calls this function to copy selected data to the clipboard when a user chooses the Cut feature, as shown in this figure:
The Presentation framework also calls MoveDataIntoModelSubclass just before doing a Paste function over selected data, saving the data so the Paste operation can be undone.
- MoveDataOutofModelSubclass takes a source model as a parameter and copies the data from the source model into the range of the model specified by this selection. It replaces any data currently specified by this selection with the new data (like pasting over it). After moving in the new data, this function should reset this selection to specify the new data.
The Presentation framework calls this function to move data from the clipboard into the selected range of a model when a user chooses the Paste feature, as shown in this figure:
NOTE
MoveDataIntoModelSubclass and MoveDataOutofModelSubclass must be inverse operations to support undo and redo. Because the selection is responsible for moving selected data in or out during a Paste or Cut operation, you need to make sure the selection is updated to indicate the position where the inverse operation (Undo) should be performed.
You need to implement these functions only to support data exchange between your model and selection classes. The Presentation framework calls these functions as appropriate during cut, copy, and paste operations within a document component based on your model. Data is cut or copied into an embedded model of the same type on the clipboard. When the data is pasted into another model of the same type, the data in the embedded clipboard is added to the source model's data.
When a user tries to cut, copy, and paste data between document components based on different models, data is still cut or copied into an embedded model on the clipboard. However, the Presentation framework creates a new embedded model in the source document, and then pastes the data from the embedded model on the clipboard into that model instead of adding the data to the source model's data.
This table describes the behavior provided by the Presentation framework during cut, copy, and paste operations between a Tiles document and a Scribbler document. All newly created embedded models, whether on the clipboard or within a document, are created by the Presentation framework.
|
User Action
|
Source Model
|
Destination Model
|
Function called by Framework
|
|
Copy in the Tiles window
|
TTilesModel in the Tiles document
|
A newly created TTilesModel embedded in the Clipboard document
|
CopyDataIntoModelSubclass
|
|
Cut in the Tiles window
|
TTilesModel in the Tiles document
|
A newly created TTilesModel embedded in the Clipboard document
|
MoveDataIntoModelSubclass
|
|
Paste in the Tiles window
|
Previously cut/copied TTilesModel embedded in the Clipboard document
|
TTilesModel in the Tiles document
|
MoveDataOutofModelSubclass
|
|
Undo after Cut in the Tiles window
|
Previously cut/copied TTilesModel embedded in the Clipboard document
|
TTilesModel in the Tiles document
|
MoveDataOutofModelSubclass
|
|
Undo after Paste in the Tiles window
|
TTilesModel in the Tiles document
|
A newly created TTilesModel embedded in the Clipboard
|
MoveDataIntoModelSubclass
|
|
Paste in a Scribbler window after a cut/copy in the Tiles window
|
Previously cut/copied TTilesModel embedded in the Clipboard document
|
A newly created TTilesModel embedded in the Scribbler document
|
MoveDataOutofModelSubclass
|
|
Paste in the Tiles window after a cut/copy in Scribbler window
|
Previously cut/copied Scribbler model embedded in the Clipboard document
|
A newly created Scribbler model embedded in the Tiles document
|
MoveDataOutofModelSubclass
|
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker