Deriving a
presenter class
In this step, instead of using TGUIPresenterFor<TTilesView> directly, the Tiles document component uses a presenter derived from TGUIPresenterFor<TTilesView>--TTilesPresenter--that builds a menu specifically for the Tiles program. TGUIPresenterFor<AView> derives from TGUIPresenter, which provides functions called by the Presentation framework to build menus and to control their behavior. You override these functions to build and manage the extended Tiles menu:
You determine which functions to override and how to implement them based on whether you built the menu with the cpConstructor tool. The cpConstructor tool puts interface elements into an archive associated with your program, so if you build the menu with the cpConstructor tool your presenter needs to retrieve the menu from that archive. If you don't want to build your menu using the cpConstructor tool, your presenter needs to build the Tiles menu programmatically.
You also implement menu items differently based on whether the menu was archived or not:
- When you construct a menu programmatically, you implement each menu item by creating a control state to represent each item, as described in the previous section, "Adding menus." When the user selects the menu item, the control state initiates the corresponding operation.
- When you create a menu using the cpConstructor tool, you associate an action with each menu item that describes the corresponding operation. The cpConstructor tool provides an action control state for each menu item. When the user selects a menu item, this control state sends the action back to your program, which is responsible for processing it. Actions are described in more detail in "Building a menu with the cpConstructor tool" on page 85.
To add menus to the presentation for a document component, you need to override HandleMenuActivate and HandleMenuDeactivate. The Presentation framework calls these functions whenever a presentation on your document component is activated or deactivated:
- HandleMenuActivate is responsible for building the menu, either programmatically or by reconstructing it from the archive, and for activating the menu. You only need to build the menu once for a document session, the first time the document is activated. Subsequent calls to HandleMenuActivate should just activate the menu. TTilesPresenter activates the Tiles menu by adding it to the main menu and setting the state to active.
- HandleMenuDeactivate is responsible for deactivating the menu. TTilesPresenter does this by orphaning each currently active menu item and setting the state to inactive.
HandleMenuActivate and HandleMenuDeactivate should also call the parent functions to activate and deactivate any inherited menus.
You need to override the functions HandleMenuAction and HandleCurrentSelectionChange only when you reconstruct menus from an archive:
- HandleMenuAction is called by the Presentation framework each time the presenter receives a menu action. HandleMenuAction receives the action generated by the action control state and initiates the corresponding operation. See "Handling actions" on page 88 for more information.
- HandleCurrentSelectionChange is called by the Presentation framework each time the user makes a new selection. TTilesPresenter implements this function to control when individual menu items are enabled or disabled. See "Enabling and disabling items from an archived menu" on page 89 for more information.
Storing the menu
TTilesPresenter uses a special helper class, TMenuHolder, to facilitate storing and activating the Tiles menu. TMenuHolder stores menu items and provides functions that activate and deactivate them. The TTilesPresenter HandleMenuActivate function builds the menu and stores it in a TMenuHolder object:
For more information about this class, you can examine the code in the files MenuHolder.h
and MenuHolder.C
in the directory ./TilesTutorial/05.Menus/Tiles
.
[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