Selecting a tile and issuing a command

In the previous step, when a user clicked the mouse within the view the TTilesView::MouseDown function only identified which tile was clicked on. In this step, the MouseDown function will cause the tile that was clicked on to change color.

To do this, the Tiles program needs a selection class, TTilesSelection, to indicate a selected tile, and a command, TChangeColorCommand, that acts on a TTilesSelection. To cause a tile to change color, the following happens:

  1. The MouseDown function creates a TTilesSelection on the tile chosen by the user, and instantiates a TChangeColorCommand.
  2. MouseDown binds the selection and command together and passes them to the document.
  3. The document executes the command on the selection, causing the model to be modified.
  4. Finally, changing the model causes the view to be updated--the Presentation framework includes a default notification mechanism that ensures that anytime a command is executed the view is notified. The default behavior of the view is to invoke InvalidateAll, which causes the framework to call DrawContents.
NOTE This default notification mechanism might change in a future release.

When the document executes a command, it also saves the command/selection pair in an undo/redo history log. If the user chooses the Undo feature, the framework retrieves the command and selection, and requests the command to undo its effect on the selection. Similarly, if the user chooses the Redo feature after undoing a command, the framework retrieves the command selection and requests the command to redo the operation.


To implement this behavior, this step shows you how to:


[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