Handling actions

To make the menu retrieved from the archive work, you need to implement a menu action handler for the Tiles document component. When the user selects a menu item, the Action framework generates the corresponding action and sends it up the view hierarchy, where the parent view is responsible for distributing the action to the appropriate action handler.

View classes that derive from TDocumentComponentView send menu actions to the document component's presenter. Because TTilesView derives from TDocumentComponentView, this means that actions generated by the Tiles menu are handled by the TTilesPresenter class. TTilesPresenter, through its parent class TGUIPresenter, already derives from the class that defines the protocol for handling menu actions, MMenuActionHandler:


To handle an action, the Tiles presenter:

  1. Identifies the action by retrieving the encapsulated action string.
    This is the string you entered in the "Action" field when you constructed the menu item with the cpConstructor tool--for example, "RedAction."
  2. Creates the command that needs to be issued to process the action.
    The Tiles presenter processes the following actions by initiating these associated commands:


Action Command

"RedAction"
TChangeColorCommand constructed with the color red (TRGBColor( 1,0,0 ))

"GreenAction"
TChangeColorCommand constructed with the color green (TRGBColor( 0,1,0 ))

"BlueAction"
TChangeColorCommand constructed with the color blue (TRGBColor( 0,0,1 ))

"RockAction"
TCreateTileCommand constructed to create a tile of type kRock at the position TGPoint( 10,10 )

"PaperAction"
TCreateTileCommand constructed to create a tile of type kPaper at the position TGPoint( 70,10 )

"ScissorsAction"
TCreateTileCommand constructed to create a tile of type kScissors at the position TGPoint( 130,10 )

  1. Accesses the current selection, via the document's GUI bundle.
  2. Binds the command to the current selection with a TGUIDocumentComponentCommandBindingTo<TTilesSelection>.
  3. Requests the document to adopt and execute the command.
  4. If the action could not be handled, passes the action to the parent class, calling TGUIPresenter::HandleMenuAction.
For more information on actions, see the section "Action framework" in Chapter 5, "GUI Application framework concepts," in Desktop Framework Concepts.


[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