Issuing the command

You don't generally call the command function directly to execute a command, you use a command binding. A command binding is an object that binds a command instance to a target selection. To issue a command, you request the document to adopt and execute the command binding. You can access the document through MGUIBundle, calling the MGUIBundle function AdoptAndDo to pass the binding to the document. The document takes ownership of the command binding and executes the command against the target selection.

The Presentation framework provides a class template for command bindings, TGUIDocumentComponentCommandBindingTo<ATarget>. This template lets you easily create a class to use as a binding for any command you create. To bind a TChangeColorCommand to a TTilesSelection, the Tiles program uses an instance of TGUIDocumentComponentCommandBindingTo<TTilesSelection>, named TTilesCommandBinding by a typedef statement in the code.

NOTE TGUIDocumentComponentCommandBindingTo<ATarget> also provides a parameter that lets you control the label for the Undo/Redo menu item. In the current release, undo/redo labels do not appear in the presentation. In a later release, when the framework supports undo/redo labels, you could set a label to "Set to Red", and the undo/redo labels would read "Undo Set to Red" and "Redo Set to Red".

This diagram shows how the binding connects a command and its target selection:


You can compile and run the Tiles project in the directory $TaligentRoot/TaligentSamples/Supported/Apps/TilesTutorial/03.CommandsAndSelections/Tiles and launch a Tiles document using TilesTutorialApp to see the functionality. Make sure that a previous version of a Tiles document is not running when you compile this version. When you click on a tile, the color of that tile will change. See "Launching a document" on page 21 for directions on how to compile a project and launch a document.


[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