00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 #if !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)
00018 #define AFX_RESIZABLELAYOUT_H__INCLUDED_
00019
00020 #include <afxtempl.h>
00021 #include "ResizableMsgSupport.h"
00022
00023 #if _MSC_VER > 1000
00024 #pragma once
00025 #endif // _MSC_VER > 1000
00026
00027
00028
00029 const CSize NOANCHOR(-1,-1),
00030 TOP_LEFT(0,0), TOP_CENTER(50,0), TOP_RIGHT(100,0),
00031 MIDDLE_LEFT(0,50), MIDDLE_CENTER(50,50), MIDDLE_RIGHT(100,50),
00032 BOTTOM_LEFT(0,100), BOTTOM_CENTER(50,100), BOTTOM_RIGHT(100,100);
00033
00034
00035 class CResizableLayout
00036 {
00037 protected:
00038 class LayoutInfo
00039 {
00040 public:
00041 HWND hWnd;
00042 UINT nCallbackID;
00043
00044 CString sWndClass;
00045
00046
00047 SIZE sizeTypeTL;
00048 SIZE sizeMarginTL;
00049
00050
00051 SIZE sizeTypeBR;
00052 SIZE sizeMarginBR;
00053
00054
00055 BOOL bMsgSupport;
00056 RESIZEPROPERTIES properties;
00057
00058 public:
00059 LayoutInfo() : hWnd(NULL), nCallbackID(0), bMsgSupport(FALSE)
00060 {
00061 sizeTypeTL.cx = 0;
00062 sizeTypeTL.cy = 0;
00063 sizeMarginTL.cx = 0;
00064 sizeMarginTL.cy = 0;
00065 sizeTypeBR.cx = 0;
00066 sizeTypeBR.cy = 0;
00067 sizeMarginBR.cx = 0;
00068 sizeMarginBR.cy = 0;
00069 memset(&properties, 0, sizeof properties);
00070 }
00071
00072 LayoutInfo(HWND hwnd, SIZE tl_t, SIZE tl_m,
00073 SIZE br_t, SIZE br_m, CString classname)
00074 : hWnd(hwnd), nCallbackID(0),
00075 sWndClass(classname), bMsgSupport(FALSE),
00076 sizeTypeTL(tl_t), sizeMarginTL(tl_m),
00077 sizeTypeBR(br_t), sizeMarginBR(br_m)
00078 {
00079 memset(&properties, 0, sizeof properties);
00080 }
00081 };
00082
00083 private:
00084
00085 CMap<HWND, HWND, POSITION, POSITION> m_mapLayout;
00086 CList<LayoutInfo, LayoutInfo&> m_listLayout;
00087 CList<LayoutInfo, LayoutInfo&> m_listLayoutCB;
00088
00089 void ClipChildWindow(const CResizableLayout::LayoutInfo &layout, CRgn* pRegion);
00090
00091 void CalcNewChildPosition(const CResizableLayout::LayoutInfo &layout,
00092 const CRect &rectParent, CRect &rectChild, UINT& uFlags);
00093
00094 protected:
00095
00096 virtual void InitResizeProperties(CResizableLayout::LayoutInfo& layout);
00097
00098
00099 virtual BOOL LikesClipping(const CResizableLayout::LayoutInfo &layout);
00100
00101
00102 virtual BOOL NeedsRefresh(const CResizableLayout::LayoutInfo &layout,
00103 const CRect &rectOld, const CRect &rectNew);
00104
00105
00106 void EraseBackground(CDC* pDC);
00107
00108
00109 void ClipChildren(CDC* pDC);
00110
00111
00112 void GetClippingRegion(CRgn* pRegion);
00113
00114
00115 virtual void GetTotalClientRect(LPRECT lpRect);
00116
00117
00118 void AddAnchor(HWND hWnd, CSize sizeTypeTL, CSize sizeTypeBR = NOANCHOR);
00119
00120
00121 void AddAnchor(UINT nID, CSize sizeTypeTL, CSize sizeTypeBR = NOANCHOR)
00122 {
00123 AddAnchor(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID),
00124 sizeTypeTL, sizeTypeBR);
00125 }
00126
00127
00128 void AddAnchorCallback(UINT nCallbackID);
00129
00130
00131 BOOL GetAnchorPosition(HWND hWnd, const CRect &rectParent,
00132 CRect &rectChild, UINT* lpFlags = NULL)
00133 {
00134 POSITION pos;
00135 if (!m_mapLayout.Lookup(hWnd, pos))
00136 return FALSE;
00137
00138 UINT uTmpFlags;
00139 CalcNewChildPosition(m_listLayout.GetAt(pos), rectParent, rectChild,
00140 (lpFlags != NULL) ? (*lpFlags) : uTmpFlags);
00141 return TRUE;
00142 }
00143
00144
00145 BOOL GetAnchorPosition(UINT nID, const CRect &rectParent,
00146 CRect &rectChild, UINT* lpFlags = NULL)
00147 {
00148 return GetAnchorPosition(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID),
00149 rectParent, rectChild, lpFlags);
00150 }
00151
00152
00153 BOOL RemoveAnchor(HWND hWnd)
00154 {
00155 POSITION pos;
00156 if (!m_mapLayout.Lookup(hWnd, pos))
00157 return FALSE;
00158
00159 m_listLayout.RemoveAt(pos);
00160 return m_mapLayout.RemoveKey(hWnd);
00161 }
00162
00163
00164 BOOL RemoveAnchor(UINT nID)
00165 {
00166 return RemoveAnchor(::GetDlgItem(GetResizableWnd()->GetSafeHwnd(), nID));
00167 }
00168
00169
00170 void RemoveAllAnchors()
00171 {
00172 m_mapLayout.RemoveAll();
00173 m_listLayout.RemoveAll();
00174 m_listLayoutCB.RemoveAll();
00175 }
00176
00177
00178 void ArrangeLayout();
00179
00180
00181 virtual BOOL ArrangeLayoutCallback(CResizableLayout::LayoutInfo& layout);
00182
00183
00184 virtual CWnd* GetResizableWnd() = 0;
00185
00186 public:
00187 CResizableLayout() { }
00188
00189 virtual ~CResizableLayout()
00190 {
00191
00192 RemoveAllAnchors();
00193 }
00194 };
00195
00196 #endif // !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_)