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