/TilesTutorial/07.Embedding/Tiles. New code is shown here in bold.
TTilesModel
Following is the new declaration for the TTilesModel class, found in the file
./TilesTutorial/07.Embedding/Tiles/TilesModel.h:
The new source is in the file . // Copyright (C) 1995 Taligent, Inc. All rights reserved.
class TTilesModel : public TGUIEmbedderModel
{
// TTilesModel function declarations are unchanged.
private:
// Adds a value to identify version two.
enum {kOriginalVersion, kVersionTwo};
TArrayOf<TTile> fTiles;
};
/TilesTutorial/07.Embedding/Tiles/TilesModel.C. Explicit calls to base class functions are changed to call TGUIEmbedderModel in the following functions:
ModelDefinitionsMacro(TTilesModel, kVersionTwo, TGUIEmbedderModel);
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
TStream&
TTilesModel::operator<<=(TStream& fromStream)
{
VersionInfo version = ::ReadVersion(fromStream, kOriginalVersion, kVersionTwo);
switch (version) {
case kOriginalVersion: {
// Streams in data from the appropriate base class, depending on the
// version being streamed in.
TModel::operator<<=(fromStream);
fTiles.DeleteAll();
fTiles <<= fromStream;
break;
}
case kVersionTwo: {
// Streams in data from the appropriate base class, depending on the
// version being streamed in.
TGUIEmbedderModel::operator<<=(fromStream);
fTiles.DeleteAll();
fTiles <<= fromStream;
break;
}
default:
throw TInvalidVersionError();
}
return fromStream;
}
./TilesTutorial/07.Embedding/Tiles/TileView.h:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
class TTilesView : public TGUIEmbedderModelView
{
// TTilesView function declarations and data members are unchanged.
};
./TilesTutorial/07.Embedding/Tiles/TilesView.C. Explicit calls to base class functions are changed to call TGUIEmbedderModelView in the following functions:
./TilesTutorial/07.Embedding/Tiles/TilesSelections.h:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
class TTilesSelection : public TGUIEmbedderModelSelectionFor<TTilesModel>
{
// Existing TTilesSelection functions and data members are unchanged.
public:
// Called to Copy data.
virtual void CopyDataIntoModelSubclass(TTilesModel& theDestModel) const;
// Called to Cut data.
virtual void MoveDataIntoModelSubclass(TTilesModel& theDestModel);
// Called to Paste data.
virtual void MoveDataOutofModelSubclass(TTilesModel& theSrcModel);
};
/TilesTutorial/07.Embedding/Tiles/TilesSelections.C. Explicit calls to base class functions are changed to call TGUIEmbedderModelSelectionFor<TTilesModel> in the following functions:
./TilesTutorial/07.Embedding/Tiles/TilesSelections.C:
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
void
TTilesSelection::CopyDataIntoModelSubclass( TTilesModel& destModel ) const
{
TileIndex i;
// Verifies that there is selected data to copy.
if (!IsEmpty()) {
const TTilesModel* sourceModel = GetModelForReading();
// Creates a copy of each selected tile and has the destination model adopt it.
for (i = fLowBound; i <= fHighBound; i++) {
destModel.AdoptTile(new TTile(*(sourceModel->GetTileForReading(i))));
}
}
}
void
TTilesSelection::MoveDataIntoModelSubclass(TTilesModel& destModel )
{
TileIndex i;
if (!IsEmpty()) {
TTilesModel* sourceModel = GetModelForWriting();
// Creates a copy of each selected tile and has the destination model adopt it.
for (i = fLowBound; i <= fHighBound; i++) {
destModel.AdoptTile(new TTile(*(sourceModel->GetTileForReading(i))));
}
// Deletes each selected tile from the source model.
for (i = fLowBound; i <= fHighBound; i++) {
TTile* tile = sourceModel->OrphanTile(fLowBound);
delete tile;
}
// Resets selection to empty, because previously selected tiles were deleted.
DeselectAll();
}
}
void
TTilesSelection::MoveDataOutofModelSubclass(TTilesModel& sourceModel )
{
TileIndex i;
TTilesModel* destModel = GetModelForWriting();
TileIndex numTilesToCopy = sourceModel.GetNumTiles();
if (numTilesToCopy > 0) {
if (!IsEmpty()) {
// Deletes any selected tiles in the source model.
for (i = fLowBound; i <= fHighBound; i++) {
TTile* tile = destModel->OrphanTile(fLowBound);
delete tile;
}
// Resets selection to empty.
DeselectAll();
}
// Copies first tile and stores its index as the low bound.
fLowBound = fHighBound = destModel->
AdoptTile(new TTile(*(sourceModel.GetTileForReading(0))));
// Copies remaining tiles and stores the last index as the high bound.
for (i = 1; i < numTilesToCopy; i++) {
fHighBound = destModel->AdoptTile(
new TTile(*(sourceModel.GetTileForReading(i))));
}
// Resets state to indicate a selection has been set.
SetState(kNotEmpty);
}
}