Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Stingray Foundation Library User's Guide

8.6 MVC Controllers

An MVC controller is an object that receives events and translates them into actions on the model and viewport. A controller determines the behavior of an MVC component. The controller has a strongly typed relationship with the model so that it can call methods exposed by the model's interface and execute commands against the model. The controller can also call methods on the viewport. One of the attractive features of the MVC architecture is that different controllers can be used with the same viewport and model. The behavior of an MVC component can be modified by swapping one controller for another.

8.6.1 CMvcController

The CMvcController template class provides a base class for controllers. It takes two template parameters: the type of model and the type of viewport. An excerpt from the declaration of CMvcController is shown in Example 78.

Example 78: Declaration of CMvcController

Notice that CMvcController declares embedded types for the model and viewport, which provides a way for code outside of the scope of the class to have knowledge of the model and viewport types.

The CMvcController class implements the IEventRouter interface. Event listeners can be added to the controller using the AddListener() function. Event listeners can either be mixed into the controller class or aggregated into the controller.

The sample code shown in Example 79 below demonstrates an implementation for an SFL Scribble controller. This sample code also implements the drawing canvas as an MVC component.

Example 79: Sample Code for an SFL Scribble controller

8.6.2 MFC Specifics

The MvcController class provides an MFC-specific implementation of a controller that is tightly integrated with MFC message maps. It is derived from the more generic CMvcController class and mixes in the MFC-specific SECWndPlugIn class. The SECWndPlugIn is derived from CWnd and provides a mechanism for receiving messages from a window. SECWndPlugIn does not actually create a window. Instead, it is assigned the handle to the window it is plugged into. The advantage to this approach is that the MFC Class Wizard can be used to add message handlers directly to the controller, since it is derived from CWnd and contains an MFC message map.

This class does not conform to the SFL naming conventions for historical reasons. In previous versions of the MVC library, the MvcController class was the base class for all controllers.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.