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 CResizableFormView::CResizableFormView(UINT nIDTemplate
)
35 : CFormView(nIDTemplate
)
39 CResizableFormView::CResizableFormView(LPCTSTR lpszTemplateName
)
40 : CFormView(lpszTemplateName
)
44 CResizableFormView::~CResizableFormView()
49 BEGIN_MESSAGE_MAP(CResizableFormView
, CFormView
)
50 //{{AFX_MSG_MAP(CResizableFormView)
59 /////////////////////////////////////////////////////////////////////////////
60 // CResizableFormView diagnostics
63 void CResizableFormView::AssertValid() const
65 CFormView::AssertValid();
68 void CResizableFormView::Dump(CDumpContext
& dc
) const
74 /////////////////////////////////////////////////////////////////////////////
75 // CResizableFormView message handlers
77 void CResizableFormView::OnSize(UINT nType
, int cx
, int cy
)
79 CFormView::OnSize(nType
, cx
, cy
);
81 CWnd
* pParent
= GetParentFrame();
83 // hide size grip when parent is maximized
84 if (pParent
->IsZoomed())
85 HideSizeGrip(&m_dwGripTempState
, GHR_MAXIMIZED
);
87 ShowSizeGrip(&m_dwGripTempState
, GHR_MAXIMIZED
);
89 // hide size grip when there are scrollbars
90 CSize size
= GetTotalSize();
91 if ((cx
< size
.cx
|| cy
< size
.cy
) && (m_nMapMode
>= 0))
92 HideSizeGrip(&m_dwGripTempState
, GHR_SCROLLBAR
);
94 ShowSizeGrip(&m_dwGripTempState
, GHR_SCROLLBAR
);
96 // hide size grip when the parent frame window is not resizable
97 // or the form is not bottom-right aligned (e.g. there's a statusbar)
98 DWORD dwStyle
= pParent
->GetStyle();
99 CRect rect
, rectChild
;
102 BOOL bCanResize
= TRUE
; // whether the grip can size the frame
103 for (HWND hWndChild
= ::GetWindow(m_hWnd
, GW_HWNDFIRST
); hWndChild
!= NULL
;
104 hWndChild
= ::GetNextWindow(hWndChild
, GW_HWNDNEXT
))
106 ::GetWindowRect(hWndChild
, rectChild
);
107 //! @todo check RTL layouts!
108 if (rectChild
.right
> rect
.right
|| rectChild
.bottom
> rect
.bottom
)
114 if ((dwStyle
& WS_THICKFRAME
) && bCanResize
)
115 ShowSizeGrip(&m_dwGripTempState
, GHR_ALIGNMENT
);
117 HideSizeGrip(&m_dwGripTempState
, GHR_ALIGNMENT
);
119 // update grip and layout
124 void CResizableFormView::GetTotalClientRect(LPRECT lpRect
) const
126 GetClientRect(lpRect
);
128 // get dialog template's size
129 // (this is set in CFormView::Create)
130 CSize sizeTotal
, sizePage
, sizeLine
;
132 GetDeviceScrollSizes(nMapMode
, sizeTotal
, sizePage
, sizeLine
);
134 // otherwise, give the correct size if scrollbars active
136 if (nMapMode
< 0) // scrollbars disabled
139 // enlarge reported client area when needed
141 if (rect
.Width() < sizeTotal
.cx
)
142 rect
.right
= rect
.left
+ sizeTotal
.cx
;
143 if (rect
.Height() < sizeTotal
.cy
)
144 rect
.bottom
= rect
.top
+ sizeTotal
.cy
;
146 rect
.OffsetRect(-GetDeviceScrollPosition());
150 BOOL
CResizableFormView::OnEraseBkgnd(CDC
* pDC
)
152 ClipChildren(pDC
, FALSE
);
154 BOOL bRet
= CFormView::OnEraseBkgnd(pDC
);
156 ClipChildren(pDC
, TRUE
);
161 void CResizableFormView::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
166 void CResizableFormView::OnDestroy()
170 CFormView::OnDestroy();
173 LRESULT
CResizableFormView::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
175 if (message
== WM_INITDIALOG
)
176 return (LRESULT
)OnInitDialog();
178 if (message
!= WM_NCCALCSIZE
|| wParam
== 0)
179 return CFormView::WindowProc(message
, wParam
, lParam
);
181 // specifying valid rects needs controls already anchored
183 HandleNcCalcSize(FALSE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
184 lResult
= CFormView::WindowProc(message
, wParam
, lParam
);
185 HandleNcCalcSize(TRUE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
189 BOOL
CResizableFormView::OnInitDialog()
191 const MSG
* pMsg
= GetCurrentMessage();
193 BOOL bRet
= (BOOL
)CFormView::WindowProc(pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
195 // we need to associate member variables with control IDs
198 // set default scroll size
200 GetWindowRect(rectTemplate
);
201 SetScrollSizes(MM_TEXT
, rectTemplate
.Size());
206 BOOL
CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct
)
208 if (!CFormView::OnNcCreate(lpCreateStruct
))
211 // create and init the size-grip
212 if (!CreateSizeGrip())