Creating the selection class

A selection specifies a range of data contained by a model. It can specify the whole model, a portion of the model, or none of the model. A common example of a selection is within a word-processing application: a user highlights (selects) a portion of the text and then performs an operation (command) on it, such as underlining or deleting. Selections can vary from simple all-or-nothing selections to complex disjoint selections. How complex a selection needs to be depends on the application.

All selection classes should support an empty selection and a whole model selection to support standard Presentation framework operations such as "Select All". The Tiles application also needs a selection that can specify a single TTile in the model.

Up to now the TTilesModel has been using the Presentation framework template class TGUIModelSelectionFor<TTilesModel> as a "dummy" selection. In this step, this "dummy" selection is replaced by TTilesSelection, a class derived from TGUIModelSelectionFor<TTilesModel>.

A TGUIModelSelectionFor<TTilesModel> maintains a reference (a TModelReference) back to the TTilesModel. The TTilesSelection class additionally provides the ability for the selection to indicate a range within the model. This combination of the model reference and the range information is all you need to create a usable selection on a TTilesModel.

NOTE A selection cannot contain a direct pointer to a model or to data inside the model. This is because selections must be address-space independent so that they can be saved and restored. This supports operations like cutting and pasting across documents. Therefore, selection classes use a combination of a TModelReference--which is address-space independent--and some type of range specifier (or multiple range specifiers for disjoint selections).

To indicate a range within a TTilesModel, TTilesSelection maintains a low and a high TTile index indicating the range of the selection. For selections containing a single tile, the low and high bounds are equal.

To support the framework's mechanism for setting selections, TTilesSelection overrides several functions inherited from TGUIModelSelectionFor<TTilesModel>. These functions are called by the framework--for example, SelectWholeModel is called when a user chooses the "Select All" function from the standard menu.

TTilesSelection has an additional function, SelectTile, to support setting a selection on a single tile. SelectTile takes a tile index and sets a selection on that tile.

TTilesSelection also includes several functions for commands to use when modifying the data model--for the Tiles application, changing the color of the selected tile(s):


The TTilesSelection functions for accessing the data model support the protocol encouraged by the CommonPoint programming model, that is, two levels--selections and commands--between a model and the model's clients. To modify a data model, the client issues a command and the command then calls selection functions that access the data. In other words, the command doesn't call the model's accessor functions directly.

NOTE One exception to this protocol is commands that add data to the model. These commands use the selection to access the model, but because they don't operate on a selected range of data in the model, they add data to the model by calling model functions directly.

For example, when the TChangeColorCommand is issued against a selection:

  1. The command calls TTilesSelection::SetColorAll to request the color change.
  2. TTilesSelection::SetColorAll locks the model for writing and calls TTilesModel::GetTileForWriting to access the tile. Then the actual color change is made by calling TTile::SetColor on each 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