// This is a part of the Microsoft Foundation Classes C++ library. // Copyright (C) Microsoft Corporation // All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. #pragma once #include <__atlmfc_core.h> #pragma warning(push) #pragma warning(disable : _ATLMFC_DISABLED_WARNINGS) #ifdef _AFX_PACKING #pragma pack(push, _AFX_PACKING) #endif #ifdef _AFX_MINREBUILD #pragma component(minrebuild, off) #endif struct AFX_DYNAMIC_LAYOUT_ITEM; ///////////////////////////////////////////////////////////////////////////// // CMFCDynamicLayout /// /// Dynamic layout performs automatic reposition of controls hosted in a window. /// class CMFCDynamicLayout : public CObject { DECLARE_DYNAMIC(CMFCDynamicLayout) public: /// /// Vertical and horizontal ratios define move direction of a child control when a hosting window is being resized. /// struct MoveSettings { MoveSettings() { m_nXRatio = 0; m_nYRatio = 0; } BOOL IsHorizontal() const { return m_nXRatio > 0; } BOOL IsVertical() const { return m_nYRatio > 0; } BOOL IsNone() const { return !IsHorizontal() && !IsVertical(); } /// /// Defines (in percents) how far a child control is moved horizontally when size of host has been changed. /// For example, m_nXRatio is 50%. If size of host is changed by 20 pixels, the child is moved horizontally by 10 pixels from its current position. /// int m_nXRatio; /// /// Defines (in percents) how far a child control is moved vertically when size of host has been changed. /// For example, m_nYRatio is 50%. If size of host is changed by 20 pixels, the child is moved vertically by 10 pixels from its current position. /// int m_nYRatio; }; /// /// Vertical and horizontal ratios define how to resize a child control when a hosting window is being resized. /// struct SizeSettings { SizeSettings() { m_nXRatio = 0; m_nYRatio = 0; } BOOL IsHorizontal() const { return m_nXRatio > 0; } BOOL IsVertical() const { return m_nYRatio > 0; } BOOL IsNone() const { return !IsHorizontal() && !IsVertical(); } /// /// Defines (in percents) how a child control is resized horizontally when size of host has been changed. /// For example, m_nXRatio is 50%. If the size of host is changed by 20 pixels, the child is resized by 10 pixels. /// int m_nXRatio; /// /// Defines (in percents) how a child control is resized vertically when size of host has been changed. /// For example, m_nYRatio is 50%. If the size of host is changed by 20 pixels, the child is resized by 10 pixels. /// int m_nYRatio; }; // Construction: public: CMFCDynamicLayout(); virtual ~CMFCDynamicLayout(); // Operations: public: /// /// Stores and validates the host window. /// TRUE if creation succeeded; otherwise FALSE. /// A pointer to a host window. BOOL Create(CWnd* pHostWnd); /// /// This method recalculates positions and sizes of child controls that have been added to layout using AddItem. /// Called by the framework when the hosting window is being resized. void Adjust(); // Behavior settings: /// /// No move when a hosting window is being resized. /// Behavior settings define move direction. static MoveSettings MoveNone(); /// /// A child control is moved horizontally only when a hosting window is being resized. /// Behavior settings define move direction. /// Defines (in percents) how far a child control is moved horizontally when size of host has been changed. static MoveSettings MoveHorizontal(int nRatio); /// /// A child control is moved vertically only when a hosting window is being resized. /// Behavior settings define move direction. /// Defines (in percents) how far a child control is moved vertically when size of host has been changed. static MoveSettings MoveVertical(int nRatio); /// /// A child control is moved horizontally and vertically when a hosting window is being resized. /// Behavior settings define move direction. /// Defines (in percents) how far a child control is moved horizontally when size of host has been changed. /// Defines (in percents) how far a child control is moved vertically when size of host has been changed. static MoveSettings MoveHorizontalAndVertical(int nXRatio, int nYRatio); /// /// No resize when a hosting window is being resized. /// Behavior settings define resize method. static SizeSettings SizeNone(); /// /// X dimension of a child window is changed when a hosting window is being resized. /// Behavior settings define resize method. /// Defines (in percents) how a child control is resized horizontally when size of host has been changed. static SizeSettings SizeHorizontal(int nRatio); /// /// Y dimension of a child window is changed when a hosting window is being resized. /// Behavior settings define resize method. /// Defines (in percents) how a child control is resized vertically when size of host has been changed. static SizeSettings SizeVertical(int nRatio); /// /// Width and height of a child window are changed when a hosting window is being resized. /// Behavior settings define resize method. /// Defines (in percents) how a child control is resized horizontally when size of host has been changed. /// Defines (in percents) how a child control is resized vertically when size of host has been changed. static SizeSettings SizeHorizontalAndVertical(int nXRatio, int nYRatio); /// /// Adds a child control to dynamic layout. /// The position and size of a child control is changed dynamically when a hosting window is being resized. /// TRUE if succeeded; otherwise FALSE. /// Child control ID. /// Reposition behavior settings contain vertical and horizontal ratios. Specifies how to adjust position of a control. /// Resizing behavior settings contain vertical and horizontal distribution ratios. Specifies how to adjust position of a control. BOOL AddItem(UINT nID, MoveSettings moveSettings, SizeSettings sizeSettings); /// /// Adds a child control to dynamic layout. /// The position and size of a child control is changed dynamically when a hosting window is being resized. /// TRUE if succeeded; otherwise FALSE. /// Handle of a child control. /// Reposition behavior settings contain vertical and horizontal ratios. Specifies how to adjust position of a control. /// Resizing behavior settings contain vertical and horizontal distribution ratios. Specifies how to adjust position of a control. BOOL AddItem(HWND hwnd, MoveSettings moveSettings, SizeSettings sizeSettings); /// /// Checks if a child control was added to dynamic layout. /// /// TRUE if layout already has this item; otherwise FALSE. /// Handle of a child control. BOOL HasItem(HWND hwnd) {return FindItem(hwnd) != NULL; } /// /// Checks if a dynamic layout is empty. /// /// TRUE if layout is empty; otherwise FALSE. BOOL IsEmpty() const { return m_listWnd.IsEmpty(); } /// /// This method returns client area of host window. /// When the function returns this parameter contains bounding rectangle of layout area.. void GetHostWndRect(CRect& rect) const; /// /// This method reads the dynamic layout from AFX_DIALOG_LAYOUT resource and then applies the layout to the host window. /// TRUE if resource is loaded and applied to the host window; otherwise FALSE. /// A pointer to the host window. /// A pointer to the buffer containing AFX_DIALOG_LAYOUT resource. /// Size of buffer in bytes. static BOOL LoadResource(CWnd* pHostWnd, LPVOID lpResource, DWORD dwSize); protected: AFX_DYNAMIC_LAYOUT_ITEM* FindItem(HWND hWnd); void CorrectItem(AFX_DYNAMIC_LAYOUT_ITEM& item) const; BOOL PrepareItem(AFX_DYNAMIC_LAYOUT_ITEM& item) const; UINT AdjustItemRect(AFX_DYNAMIC_LAYOUT_ITEM& item, CRect& rectItem) const; CRect GetItemRect(AFX_DYNAMIC_LAYOUT_ITEM& item) const; // Attributes: public: /// /// This method returns a pointer to a host window. By default all child control positions recalculated relatively to this window. /// /// A pointer to a host window. CWnd* GetHostWnd() { return m_pHostWnd; } /// /// This method returns minimal size of layout area. If a host window is resized beyond this area, the layout is not calculated. /// For dialog templates the initial minimal size is set to client rectangle. /// /// Minimal size of layout area. CSize GetMinSize() const { return m_MinSize; } /// /// This function sets minimal size of layout area. If a host window is resized beyond this area, the layout is not calculated. /// Specifies the minimal size of layout area. void SetMinSize(const CSize& size) { m_MinSize = size; } private: CWnd* m_pHostWnd; CSize m_MinSize; CList m_listWnd; }; ///////////////////////////////////////////////////////////////////////////// // CMFCDynamicLayoutData /// /// A helper class to store layout data. It's used while loading dynamic layout from resource and applying it to a host window. /// class CMFCDynamicLayoutData { public: /// /// A helper class to store layout data of one child control. /// struct Item { CMFCDynamicLayout::MoveSettings m_moveSettings; CMFCDynamicLayout::SizeSettings m_sizeSettings; }; public: /// /// Remove layout data that's stored in this helper class. void CleanUp(); /// /// This method reads the dynamic layout data from AFX_DIALOG_LAYOUT resource. /// TRUE if resource is loaded; otherwise FALSE. /// A pointer to the buffer containing AFX_DIALOG_LAYOUT resource. /// Size of buffer in bytes. BOOL ReadResource(LPVOID lpResource, UINT nSize); /// /// This method enables the dynamic layout to a host window. /// TRUE if succeeds; otherwise FALSE. /// A pointer to the host window. /// Use TRUE to update positions and sizes of child controls. BOOL ApplyLayoutDataTo(CWnd* pHostWnd, BOOL bUpdate); protected: CList m_listCtrls; }; #ifdef _AFX_MINREBUILD #pragma component(minrebuild, on) #endif #ifdef _AFX_PACKING #pragma pack(pop) #endif // _ATLMFC_DISABLED_WARNINGS #pragma warning(pop)