The following examples demonstrate integration of the layout manager into an application. For more information, look at the Clouds, Scribble, DialogApp or LayoutControl samples in SFL (available on request from support@roguewave.com). The code in the examples is to be inserted in the InitLayout override of the window you are adding layout management to.
virtual void InitLayout(foundation::ILayoutNode* pRootNode) { // Scale is perhaps the simplest and easiest layout algorithm to // merge into your code. This is all the code you need: pRootNode = CreateLayoutNode(__uuidof(foundation::CScaleLayout)); // optional: set dialog box size limits pRootNode->SetMinMaxSize(CSize(150, 255), CSize(900, 600), 0); // set all child nodes to use optimized redraw // (static controls require it) pRootNode->ModifyNodeStyleEx(0, foundation::OptimizeRedraw, true); // Delegate to base class to autopopulate the root node // and kick off the layout process _LayoutManager::InitLayout(pRootNode); } |
virtual void InitLayout(foundation::ILayoutNode* pRootNode) { // The "relative" layout is perhaps the most intuitive of the // layout algorithms. Nodes can be moved or stretched relative to // each other in a very logical and straightforward manner. Since // each additional constraint specified results in a higher // calculation overhead, it is up to the application writer to // specify the minimum required set of constraints to achieve the // desired layout. IRelativeLayout* pRelative = CreateLayoutNode(__uuidof(CRelativeLayout), pRelative); pRootNode = guid_cast<foundation::ILayoutNode*>(pRelative); // Create a Window node for each child window in the dialog ILayoutNode* pNodeSearchText = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_SEARCH_STATIC); ILayoutNode* pNodeSearchEdit = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_SEARCH_EDIT); ILayoutNode* pNodeBrowse = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_SEARCH_BROWSE); ILayoutNode* pNodeGroup = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUPBOX); ILayoutNode* pNodeGroupEdit = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_EDIT); ILayoutNode* pNodeRadio1 = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_RADIO1); ILayoutNode* pNodeRadio2 = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_RADIO2); ILayoutNode* pNodeCheck1 = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_CHECK1); ILayoutNode* pNodeCheck2 = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_CHECK2); ILayoutNode* pNodeCheck3 = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_GROUP_CHECK3); ILayoutNode* pNodeEdit = CreateLayoutNode(__uuidof(CWindowLayoutNode), pRootNode, IDC_NONGROUP_EDIT); // Since we want the ok, cancel, help, and "display again" checkbox // to float as 1 unit, configure as a nested alignment layout for // easiest configurability. We can then use this parent node easily // in the relative layout constraints below. ILayoutNode* pNodeOKCANCEL = CreateLayoutNode(__uuidof(foundation::CScaleLayout)); ILayoutNode* pOkButton = CreateLayoutNode(__uuidof(foundation::CWindowLayoutNode), pNodeOKCANCEL, IDOK); ILayoutNode* pCancelButton = CreateLayoutNode(__uuidof(foundation::CWindowLayoutNode), pNodeOKCANCEL, IDCANCEL); ILayoutNode* pHelpButton = CreateLayoutNode(__uuidof(foundation::CWindowLayoutNode), pNodeOKCANCEL, IDC_HELP_BUTTON); ILayoutNode* pNoAgain = CreateLayoutNode(__uuidof(foundation::CWindowLayoutNode), pNodeOKCANCEL, IDC_NOAGAIN_CHECK); pNodeOKCANCEL->Init(m_hWnd); pRelative->AddLayoutNode(pNodeOKCANCEL); // Move browse node such that right side is 20 pixels left of // right side of the parent relative node (i.e. right border). pRelative->SetConstraint(pNodeBrowse, RelMoveRight, pRelative, RelRight, -20); // Stretch search edit node such that right side is 10 pixels // left of the left side of the browse node. // (left-10=10 pels to left) pRelative->SetConstraint(pNodeSearchEdit, RelRight, pNodeBrowse, RelLeft, -10); // Bottom justify/HCenter the ok, cancel, help, // and "do not display" check // Move the "ok/cancel/help" node such that its bottom is 20 // pixels above the bottom side of the parent relative node pRelative->SetConstraint(pNodeOKCANCEL, RelMoveBottom, pRelative, RelBottom, -20); // Horz center the ok/cancel/help node relative to the parent pRelative->SetConstraint(pNodeOKCANCEL, RelCenterHorizontal, pRelative); // Stretch the group and edit box as needed pRelative->SetConstraint(pNodeGroup, RelTop, pNodeBrowse, RelBottom, 20); pRelative->SetConstraint(pNodeEdit, RelTop, pNodeGroup, RelTop); pRelative->SetConstraint(pNodeGroup, RelBottom, pNodeOKCANCEL, RelTop, -10); pRelative->SetConstraint(pNodeEdit, RelBottom, pNodeGroup, RelBottom); // Set right side position of groupbox node equal to the value of // the width of the parent relative node times 0.48. // In other words, align right just a little left of the dialog // midpoint. pRelative->SetConstraint(pNodeGroup, RelRight, pRelative, RelWidth, 0, (float)0.48); pRelative->SetConstraint(pNodeEdit, RelLeft, pNodeGroup, RelRight, 20); pRelative->SetConstraint(pNodeEdit, RelRight, pNodeBrowse, RelRight); // Size/Position the elements within the group box // Center the check1 node relative to the width of the groupbox pRelative->SetConstraint(pNodeCheck1, RelCenterHorizontal, pNodeGroup, RelWidth); pRelative->SetConstraint(pNodeCheck2, RelMoveLeft, pNodeCheck1, RelLeft); pRelative->SetConstraint(pNodeCheck3, RelMoveLeft, pNodeCheck1, RelLeft); pRelative->SetConstraint(pNodeGroupEdit, RelRight, pNodeGroup, RelRight, -15); pRelative->SetMinMaxSize(CSize(475, 450), CSize(0, 0), foundation::NoMaxSize); _LayoutManager::InitLayout(pRootNode); } |
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.