1 /////////////////////////////////////////////////////////////////////////////
3 // This file is part of ResizableLib
4 // http://sourceforge.net/projects/resizablelib
6 // Copyright (C) 2000-2004 by Paolo Messina
7 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
9 // The contents of this file are subject to the Artistic License (the "License").
10 // You may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at:
12 // http://www.opensource.org/licenses/artistic-license.html
14 // If you find this code useful, credits would be nice!
16 /////////////////////////////////////////////////////////////////////////////
20 * @brief Implementation of the CResizableMinMax class.
24 #include "ResizableMinMax.h"
28 static char THIS_FILE
[]=__FILE__
;
32 //////////////////////////////////////////////////////////////////////
33 // Construction/Destruction
34 //////////////////////////////////////////////////////////////////////
36 CResizableMinMax::CResizableMinMax()
38 m_bUseMinTrack
= FALSE
;
39 m_bUseMaxTrack
= FALSE
;
40 m_bUseMaxRect
= FALSE
;
43 CResizableMinMax::~CResizableMinMax()
48 void CResizableMinMax::MinMaxInfo(LPMINMAXINFO lpMMI
)
51 lpMMI
->ptMinTrackSize
= m_ptMinTrackSize
;
54 lpMMI
->ptMaxTrackSize
= m_ptMaxTrackSize
;
58 lpMMI
->ptMaxPosition
= m_ptMaxPos
;
59 lpMMI
->ptMaxSize
= m_ptMaxSize
;
63 void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI
, CWnd
* pParentFrame
, CWnd
* pWnd
)
65 // get the extra size from child to parent
66 CRect rectClient
, rectWnd
;
67 if ((pParentFrame
->GetStyle() & WS_CHILD
) && pParentFrame
->IsZoomed())
68 pParentFrame
->GetClientRect(rectWnd
);
70 pParentFrame
->GetWindowRect(rectWnd
);
71 pParentFrame
->RepositionBars(0, 0xFFFF,
72 AFX_IDW_PANE_FIRST
, CWnd::reposQuery
, rectClient
);
73 CSize sizeExtra
= rectWnd
.Size() - rectClient
.Size();
75 ChainMinMaxInfo(lpMMI
, pWnd
->GetSafeHwnd(), sizeExtra
);
78 void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI
, HWND hWndChild
, CSize sizeExtra
)
80 // ask the child window for track size
81 MINMAXINFO mmiChild
= *lpMMI
;
82 ::SendMessage(hWndChild
, WM_GETMINMAXINFO
, 0, (LPARAM
)&mmiChild
);
83 BOOL bRetMax
= (lpMMI
->ptMaxTrackSize
.x
!= mmiChild
.ptMaxTrackSize
.x
84 || lpMMI
->ptMaxTrackSize
.y
!= mmiChild
.ptMaxTrackSize
.y
);
85 BOOL bRetMin
= (lpMMI
->ptMinTrackSize
.x
!= mmiChild
.ptMinTrackSize
.x
86 || lpMMI
->ptMinTrackSize
.y
!= mmiChild
.ptMinTrackSize
.y
);
88 // add static extra size
89 mmiChild
.ptMaxTrackSize
= sizeExtra
+ mmiChild
.ptMaxTrackSize
;
90 mmiChild
.ptMinTrackSize
= sizeExtra
+ mmiChild
.ptMinTrackSize
;
92 // min size is the largest
95 lpMMI
->ptMinTrackSize
.x
= __max(lpMMI
->ptMinTrackSize
.x
,
96 mmiChild
.ptMinTrackSize
.x
);
97 lpMMI
->ptMinTrackSize
.y
= __max(lpMMI
->ptMinTrackSize
.y
,
98 mmiChild
.ptMinTrackSize
.y
);
100 // max size is the shortest
103 lpMMI
->ptMaxTrackSize
.x
= __min(lpMMI
->ptMaxTrackSize
.x
,
104 mmiChild
.ptMaxTrackSize
.x
);
105 lpMMI
->ptMaxTrackSize
.y
= __min(lpMMI
->ptMaxTrackSize
.y
,
106 mmiChild
.ptMaxTrackSize
.y
);
110 BOOL
CResizableMinMax::CalcSizeExtra(HWND
/*hWndChild*/, CSize
/*sizeChild*/, CSize
& /*sizeExtra*/)
112 // should be overridden if you use ChainMinMaxInfoCB
117 void CResizableMinMax::ChainMinMaxInfoCB(LPMINMAXINFO lpMMI
, HWND hWndChild
)
119 // ask the child window for track size
120 MINMAXINFO mmiChild
= *lpMMI
;
121 ::SendMessage(hWndChild
, WM_GETMINMAXINFO
, 0, (LPARAM
)&mmiChild
);
122 BOOL bRetMax
= (lpMMI
->ptMaxTrackSize
.x
!= mmiChild
.ptMaxTrackSize
.x
123 || lpMMI
->ptMaxTrackSize
.y
!= mmiChild
.ptMaxTrackSize
.y
);
124 BOOL bRetMin
= (lpMMI
->ptMinTrackSize
.x
!= mmiChild
.ptMinTrackSize
.x
125 || lpMMI
->ptMinTrackSize
.y
!= mmiChild
.ptMinTrackSize
.y
);
127 // use a callback to determine extra size
128 CSize
sizeExtra(0, 0);
129 bRetMax
= bRetMax
&& CalcSizeExtra(hWndChild
, mmiChild
.ptMaxTrackSize
, sizeExtra
);
130 mmiChild
.ptMaxTrackSize
= sizeExtra
+ mmiChild
.ptMaxTrackSize
;
131 bRetMin
= bRetMin
&& CalcSizeExtra(hWndChild
, mmiChild
.ptMinTrackSize
, sizeExtra
);
132 mmiChild
.ptMinTrackSize
= sizeExtra
+ mmiChild
.ptMinTrackSize
;
134 // min size is the largest
137 lpMMI
->ptMinTrackSize
.x
= __max(lpMMI
->ptMinTrackSize
.x
,
138 mmiChild
.ptMinTrackSize
.x
);
139 lpMMI
->ptMinTrackSize
.y
= __max(lpMMI
->ptMinTrackSize
.y
,
140 mmiChild
.ptMinTrackSize
.y
);
142 // max size is the shortest
145 lpMMI
->ptMaxTrackSize
.x
= __min(lpMMI
->ptMaxTrackSize
.x
,
146 mmiChild
.ptMaxTrackSize
.x
);
147 lpMMI
->ptMaxTrackSize
.y
= __min(lpMMI
->ptMaxTrackSize
.y
,
148 mmiChild
.ptMaxTrackSize
.y
);
152 void CResizableMinMax::SetMaximizedRect(const CRect
& rc
)
154 m_bUseMaxRect
= TRUE
;
156 m_ptMaxPos
= rc
.TopLeft();
157 m_ptMaxSize
.x
= rc
.Width();
158 m_ptMaxSize
.y
= rc
.Height();
161 void CResizableMinMax::ResetMaximizedRect()
163 m_bUseMaxRect
= FALSE
;
166 void CResizableMinMax::SetMinTrackSize(const CSize
& size
)
168 m_bUseMinTrack
= TRUE
;
170 m_ptMinTrackSize
.x
= size
.cx
;
171 m_ptMinTrackSize
.y
= size
.cy
;
174 void CResizableMinMax::ResetMinTrackSize()
176 m_bUseMinTrack
= FALSE
;
179 void CResizableMinMax::SetMaxTrackSize(const CSize
& size
)
181 m_bUseMaxTrack
= TRUE
;
183 m_ptMaxTrackSize
.x
= size
.cx
;
184 m_ptMaxTrackSize
.y
= size
.cy
;
187 void CResizableMinMax::ResetMaxTrackSize()
189 m_bUseMaxTrack
= FALSE
;