1 // ResizableFormView.cpp : implementation file
\r
3 /////////////////////////////////////////////////////////////////////////////
\r
5 // This file is part of ResizableLib
\r
6 // http://sourceforge.net/projects/resizablelib
\r
8 // Copyright (C) 2000-2004 by Paolo Messina
\r
9 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
\r
11 // The contents of this file are subject to the Artistic License (the "License").
\r
12 // You may not use this file except in compliance with the License.
\r
13 // You may obtain a copy of the License at:
\r
14 // http://www.opensource.org/licenses/artistic-license.html
\r
16 // If you find this code useful, credits would be nice!
\r
18 /////////////////////////////////////////////////////////////////////////////
\r
21 #include "ResizableFormView.h"
\r
24 #define new DEBUG_NEW
\r
26 static char THIS_FILE[] = __FILE__;
\r
29 /////////////////////////////////////////////////////////////////////////////
\r
30 // CResizableFormView
\r
32 IMPLEMENT_DYNAMIC(CResizableFormView, CFormView)
\r
34 inline void CResizableFormView::PrivateConstruct()
\r
36 m_dwGripTempState = GHR_SCROLLBAR | GHR_ALIGNMENT | GHR_MAXIMIZED;
\r
39 CResizableFormView::CResizableFormView(UINT nIDTemplate)
\r
40 : CFormView(nIDTemplate)
\r
45 CResizableFormView::CResizableFormView(LPCTSTR lpszTemplateName)
\r
46 : CFormView(lpszTemplateName)
\r
51 CResizableFormView::~CResizableFormView()
\r
56 BEGIN_MESSAGE_MAP(CResizableFormView, CFormView)
\r
57 //{{AFX_MSG_MAP(CResizableFormView)
\r
60 ON_WM_GETMINMAXINFO()
\r
66 /////////////////////////////////////////////////////////////////////////////
\r
67 // CResizableFormView diagnostics
\r
70 void CResizableFormView::AssertValid() const
\r
72 CFormView::AssertValid();
\r
75 void CResizableFormView::Dump(CDumpContext& dc) const
\r
77 CFormView::Dump(dc);
\r
81 /////////////////////////////////////////////////////////////////////////////
\r
82 // CResizableFormView message handlers
\r
84 void CResizableFormView::OnSize(UINT nType, int cx, int cy)
\r
86 CFormView::OnSize(nType, cx, cy);
\r
88 CWnd* pParent = GetParentFrame();
\r
90 // hide size grip when parent is maximized
\r
91 if (pParent->IsZoomed())
\r
92 HideSizeGrip(&m_dwGripTempState, GHR_MAXIMIZED);
\r
94 ShowSizeGrip(&m_dwGripTempState, GHR_MAXIMIZED);
\r
96 // hide size grip when there are scrollbars
\r
97 CSize size = GetTotalSize();
\r
98 if ((cx < size.cx || cy < size.cy) && (m_nMapMode >= 0))
\r
99 HideSizeGrip(&m_dwGripTempState, GHR_SCROLLBAR);
\r
101 ShowSizeGrip(&m_dwGripTempState, GHR_SCROLLBAR);
\r
103 // hide size grip when the parent frame window is not resizable
\r
104 // or the form is not bottom-right aligned (e.g. there's a statusbar)
\r
105 DWORD dwStyle = pParent->GetStyle();
\r
106 CRect rect, rectChild;
\r
107 GetWindowRect(rect);
\r
109 BOOL bCanResize = TRUE; // whether the grip can size the frame
\r
110 for (HWND hWndChild = ::GetWindow(m_hWnd, GW_HWNDFIRST); hWndChild != NULL;
\r
111 hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT))
\r
113 ::GetWindowRect(hWndChild, rectChild);
\r
114 //! @todo check RTL layouts!
\r
115 if (rectChild.right > rect.right || rectChild.bottom > rect.bottom)
\r
117 bCanResize = FALSE;
\r
121 if ((dwStyle & WS_THICKFRAME) && bCanResize)
\r
122 ShowSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
\r
124 HideSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
\r
126 // update grip and layout
\r
131 void CResizableFormView::GetTotalClientRect(LPRECT lpRect) const
\r
133 GetClientRect(lpRect);
\r
135 // get dialog template's size
\r
136 // (this is set in CFormView::Create)
\r
137 CSize sizeTotal, sizePage, sizeLine;
\r
139 GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);
\r
141 // otherwise, give the correct size if scrollbars active
\r
143 if (nMapMode < 0) // scrollbars disabled
\r
146 // enlarge reported client area when needed
\r
147 CRect rect(lpRect);
\r
148 if (rect.Width() < sizeTotal.cx)
\r
149 rect.right = rect.left + sizeTotal.cx;
\r
150 if (rect.Height() < sizeTotal.cy)
\r
151 rect.bottom = rect.top + sizeTotal.cy;
\r
153 rect.OffsetRect(-GetDeviceScrollPosition());
\r
157 BOOL CResizableFormView::OnEraseBkgnd(CDC* pDC)
\r
159 ClipChildren(pDC, FALSE);
\r
161 BOOL bRet = CFormView::OnEraseBkgnd(pDC);
\r
163 ClipChildren(pDC, TRUE);
\r
168 void CResizableFormView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
\r
173 void CResizableFormView::OnDestroy()
\r
175 RemoveAllAnchors();
\r
177 CFormView::OnDestroy();
\r
180 LRESULT CResizableFormView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
\r
182 if (message == WM_INITDIALOG)
\r
183 return (LRESULT)OnInitDialog();
\r
185 if (message != WM_NCCALCSIZE || wParam == 0)
\r
186 return CFormView::WindowProc(message, wParam, lParam);
\r
188 // specifying valid rects needs controls already anchored
\r
189 LRESULT lResult = 0;
\r
190 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
\r
191 lResult = CFormView::WindowProc(message, wParam, lParam);
\r
192 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
\r
196 BOOL CResizableFormView::OnInitDialog()
\r
198 const MSG* pMsg = GetCurrentMessage();
\r
200 BOOL bRet = (BOOL)CFormView::WindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);
\r
202 // we need to associate member variables with control IDs
\r
205 // set default scroll size
\r
206 CRect rectTemplate;
\r
207 GetWindowRect(rectTemplate);
\r
208 SetScrollSizes(MM_TEXT, rectTemplate.Size());
\r
213 BOOL CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
\r
215 if (!CFormView::OnNcCreate(lpCreateStruct))
\r
218 // create and init the size-grip
\r
219 if (!CreateSizeGrip())
\r