Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Toolkit User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

30.13 Window Layout Manager for Composite Controls

The Layout Manager classes provide child window size and position dynamics for resizable ATL composite controls, dialog boxes, and windows. You can also utilize the size constraint capabilities to limit the sizing of your control or dialog to reasonable values. Layout capabilities are expressed in the layout algorithm classes. OT/ATL provides the COtlScaleNode and COtlRelativeNode algorithm classes for this purpose. A corresponding layout node object represents each child window. The top-level window or dialog is usually represented by an algorithm node object that maintains a collection of managed child nodes, much like child window relationships. Layout management is enabled by inheriting from an algorithm class and a message listener or plug-in class. This can be done in one step with the template class COtlLayoutImpl. You need to create child nodes for the child windows that you want to manage. Typically, do this in OnInitDialog(). The COtlLayoutFactory class has convenience functions for creating child window nodes (COtlWindowNode) for all child windows or selected ranges. You can create your own layout node types derived from COtlLayoutNode. These can be algorithm nodes or simple child nodes. The following sections below explore these topics in more detail.

30.13.1 Layout Manager Algorithms

This section describes each of the default layout algorithms provided with the Objective Toolkit for ATL Layout Manager component. You can also create your own custom layouts that are derived from our algorithms or from the common base class COtlLayoutNode.

30.13.2 Scale Layout

The Scale Layout maintains all children with a constant aspect ratio to the parent scale node. In other words, the child node's top, left, right, and bottom coordinates are stored as percentages of the parent node's size and are resolved to actual pixel values with each recalculation. This guarantees a constant aspect ratio no matter what size the parent node is. This algorithm is implemented by COtlScaleNode.

30.13.3 Relative Layout

The Relative Layout allows a logical organization of layout nodes in coordinates relative to other layout nodes. Common actions here might include moving or stretching child controls in response to an overall dialog size change.

For example, you can achieve layouts such as:

Each of these rules is called a constraint. Constraints are objects that define units of relative layout behavior.

This algorithm is implemented by COtlRelativeNode.

30.13.4 Adding Layout Management to Your Applications

Choose a layout algorithm and then include the necessary header files in your dialog or window implementation class. The Layout Manager implementation class (COtlLayoutImpl) is added to your list of base classes, templatized on the algorithm chosen. Here is the scale algorithm:

Now the Layout Manager needs to gather a list of child nodes to manage. Typically, a window layout node is created for every child window on the dialog, although this is not a requirement. We can use the OnInitDialog() message handler to create child nodes. Insert the following code after all the child windows have been created and initialized:

In this case, the dialog itself serves as the parent scale node and all its child windows are managed as child COtlWindowNode objects. Some Layout Manager functions require a parent node and a window handle. This allows for flexibility in the case of nested layouts, and when the parent node is not the same as the window class. Notice that the preceding example uses a helper object, COtlLayoutFactory. This is a convenient utility class that you can use to build the layout node tree.

The only thing you need to do is let the Layout Manager look at the incoming window messages. To do this, add the following line to the dialog's message map:

The template parameter for COtlLayoutImpl must match the one you used for the base class. COtlLayoutImpl is a very thin convenience class that derives from your algorithm of choice and COtlLayoutPlugin, which listens for sizing messages.

Now, give your dialog a resizable border using the resource editor so scaling is applied when the dialog is resized.



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.