Implementing TCreateTileCommand

Like the other Tiles commands, the command used to add a new tile to a TTilesModel--TCreateTileCommand--derives from TCommandOn<TTilesSelection>. You specify the kind of tile to add in the constructor for the command, using the enum TTile::EType. The command object maintains this information to support undo and redo. The TCreateTileCommand constructor also takes values specifying the position of the tile.

TCreateTileCommand implements HandleDoBegin, HandleDoUndo, and HandleDoRedo. TCreateTileCommand isn't an incremental command, so it doesn't need to implement HandleDoIncrement.

HandleDoBegin does all the work of the command:

  1. Creates a new TTile object of the specified type with a default location, color, and size
  2. Requests the model to adopt the tile
  3. Sets the current selection on the new tile
  4. Saves the index of the new tile within the model to support undo
TCreateTileCommand differs from the other Tiles commands, TChangeColorCommand and TMoveCommand, in that the command functions act directly on the model instead of making calls on the target selection. The TCreateTileCommand command functions use the selection to get write access to the model, and then call either TTilesModel::AdoptTile to add a tile to the model or TTilesModel::OrphanTile to remove a tile from the model (for an Undo operation). This is an exception to the usual protocol that commands should only operate on the model by calling functions on the selection. It makes sense in this situation because TCreateTileCommand doesn't act on selected data--it adds a new tile to the model without considering what is currently selected. TCreateTileCommand only uses the target selection to access the model. It also changes the selection to specify the newly created tile.



[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