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 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: