1 // ResizableLayout.h: interface for the CResizableLayout class.
3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2000-2002 by Paolo Messina
6 // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
8 // The contents of this file are subject to the Artistic License (the "License").
9 // You may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at:
11 // http://www.opensource.org/licenses/artistic-license.html
13 // If you find this code useful, credits would be nice!
15 /////////////////////////////////////////////////////////////////////////////
17 #if !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)
18 #define AFX_RESIZABLELAYOUT_H__INCLUDED_
21 #include "ResizableMsgSupport.h"
25 #endif // _MSC_VER > 1000
27 // useful compatibility constants (the only one required is NOANCHOR)
29 const CSize
NOANCHOR(-1,-1),
30 TOP_LEFT(0,0), TOP_CENTER(50,0), TOP_RIGHT(100,0),
31 MIDDLE_LEFT(0,50), MIDDLE_CENTER(50,50), MIDDLE_RIGHT(100,50),
32 BOTTOM_LEFT(0,100), BOTTOM_CENTER(50,100), BOTTOM_RIGHT(100,100);
35 class CResizableLayout
50 // bottom-right corner
54 // custom window support
56 RESIZEPROPERTIES properties
;
59 LayoutInfo() : hWnd(NULL
), nCallbackID(0), bMsgSupport(FALSE
)
69 memset(&properties
, 0, sizeof properties
);
72 LayoutInfo(HWND hwnd
, SIZE tl_t
, SIZE tl_m
,
73 SIZE br_t
, SIZE br_m
, CString classname
)
74 : hWnd(hwnd
), nCallbackID(0),
75 sWndClass(classname
), bMsgSupport(FALSE
),
76 sizeTypeTL(tl_t
), sizeMarginTL(tl_m
),
77 sizeTypeBR(br_t
), sizeMarginBR(br_m
)
79 memset(&properties
, 0, sizeof properties
);
84 // list of repositionable controls
85 CMap
<HWND
, HWND
, POSITION
, POSITION
> m_mapLayout
;
86 CList
<LayoutInfo
, LayoutInfo
&> m_listLayout
;
87 CList
<LayoutInfo
, LayoutInfo
&> m_listLayoutCB
;
89 void ClipChildWindow(const CResizableLayout::LayoutInfo
&layout
, CRgn
* pRegion
);
91 void CalcNewChildPosition(const CResizableLayout::LayoutInfo
&layout
,
92 const CRect
&rectParent
, CRect
&rectChild
, UINT
& uFlags
);
95 // override to initialize resize properties (clipping, refresh)
96 virtual void InitResizeProperties(CResizableLayout::LayoutInfo
& layout
);
98 // override to specify clipping for unsupported windows
99 virtual BOOL
LikesClipping(const CResizableLayout::LayoutInfo
&layout
);
101 // override to specify refresh for unsupported windows
102 virtual BOOL
NeedsRefresh(const CResizableLayout::LayoutInfo
&layout
,
103 const CRect
&rectOld
, const CRect
&rectNew
);
105 // paint the background on the given DC (for XP theme's compatibility)
106 void EraseBackground(CDC
* pDC
);
108 // clip out child windows from the given DC (support old code)
109 void ClipChildren(CDC
* pDC
);
111 // get the clipping region (without clipped child windows)
112 void GetClippingRegion(CRgn
* pRegion
);
114 // override for scrollable or expanding parent windows
115 virtual void GetTotalClientRect(LPRECT lpRect
);
117 // add anchors to a control, given its HWND
118 void AddAnchor(HWND hWnd
, CSize sizeTypeTL
, CSize sizeTypeBR
= NOANCHOR
);
120 // add anchors to a control, given its ID
121 void AddAnchor(UINT nID
, CSize sizeTypeTL
, CSize sizeTypeBR
= NOANCHOR
)
123 AddAnchor(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID
),
124 sizeTypeTL
, sizeTypeBR
);
127 // add a callback (control ID or HWND is unknown or may change)
128 void AddAnchorCallback(UINT nCallbackID
);
130 // get rect of an anchored window, given the parent's client area
131 BOOL
GetAnchorPosition(HWND hWnd
, const CRect
&rectParent
,
132 CRect
&rectChild
, UINT
* lpFlags
= NULL
)
135 if (!m_mapLayout
.Lookup(hWnd
, pos
))
139 CalcNewChildPosition(m_listLayout
.GetAt(pos
), rectParent
, rectChild
,
140 (lpFlags
!= NULL
) ? (*lpFlags
) : uTmpFlags
);
144 // get rect of an anchored window, given the parent's client area
145 BOOL
GetAnchorPosition(UINT nID
, const CRect
&rectParent
,
146 CRect
&rectChild
, UINT
* lpFlags
= NULL
)
148 return GetAnchorPosition(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID
),
149 rectParent
, rectChild
, lpFlags
);
152 // remove an anchored control from the layout, given its HWND
153 BOOL
RemoveAnchor(HWND hWnd
)
156 if (!m_mapLayout
.Lookup(hWnd
, pos
))
159 m_listLayout
.RemoveAt(pos
);
160 return m_mapLayout
.RemoveKey(hWnd
);
163 // remove an anchored control from the layout, given its HWND
164 BOOL
RemoveAnchor(UINT nID
)
166 return RemoveAnchor(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID
));
169 // reset layout content
170 void RemoveAllAnchors()
172 m_mapLayout
.RemoveAll();
173 m_listLayout
.RemoveAll();
174 m_listLayoutCB
.RemoveAll();
177 // adjust children's layout, when parent's size changes
178 void ArrangeLayout();
180 // override to provide dynamic control's layout info
181 virtual BOOL
ArrangeLayoutCallback(CResizableLayout::LayoutInfo
& layout
);
183 // override to provide the parent window
184 virtual CWnd
* GetResizableWnd() = 0;
187 CResizableLayout() { }
189 virtual ~CResizableLayout()
196 #endif // !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)