Prepare release and bump version numbers to 2.17.0.2
[TortoiseGit.git] / ext / ResizableLib / ResizableFormView.cpp
blob74b8d9f41f2cb6d249e77af2b5170256be38dfe0
1 // ResizableFormView.cpp : implementation file
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // This file is part of ResizableLib
6 // http://sourceforge.net/projects/resizablelib
7 //
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 /////////////////////////////////////////////////////////////////////////////
20 #include "stdafx.h"
21 #include "ResizableFormView.h"
23 #ifdef _DEBUG
24 #define new DEBUG_NEW
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
29 /////////////////////////////////////////////////////////////////////////////
30 // CResizableFormView
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)
51 ON_WM_SIZE()
52 ON_WM_ERASEBKGND()
53 ON_WM_GETMINMAXINFO()
54 ON_WM_DESTROY()
55 ON_WM_NCCREATE()
56 //}}AFX_MSG_MAP
57 END_MESSAGE_MAP()
59 /////////////////////////////////////////////////////////////////////////////
60 // CResizableFormView diagnostics
62 #ifdef _DEBUG
63 void CResizableFormView::AssertValid() const
65 CFormView::AssertValid();
68 void CResizableFormView::Dump(CDumpContext& dc) const
70 CFormView::Dump(dc);
72 #endif //_DEBUG
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);
86 else
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);
93 else
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;
100 GetWindowRect(rect);
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)
110 bCanResize = FALSE;
111 break;
114 if ((dwStyle & WS_THICKFRAME) && bCanResize)
115 ShowSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
116 else
117 HideSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
119 // update grip and layout
120 UpdateSizeGrip();
121 ArrangeLayout();
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;
131 int nMapMode = 0;
132 GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);
134 // otherwise, give the correct size if scrollbars active
136 if (nMapMode < 0) // scrollbars disabled
137 return;
139 // enlarge reported client area when needed
140 CRect rect(lpRect);
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());
147 *lpRect = rect;
150 BOOL CResizableFormView::OnEraseBkgnd(CDC* pDC)
152 ClipChildren(pDC, FALSE);
154 BOOL bRet = CFormView::OnEraseBkgnd(pDC);
156 ClipChildren(pDC, TRUE);
158 return bRet;
161 void CResizableFormView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
163 MinMaxInfo(lpMMI);
166 void CResizableFormView::OnDestroy()
168 RemoveAllAnchors();
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
182 LRESULT lResult = 0;
183 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
184 lResult = CFormView::WindowProc(message, wParam, lParam);
185 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
186 return 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
196 UpdateData(FALSE);
198 // set default scroll size
199 CRect rectTemplate;
200 GetWindowRect(rectTemplate);
201 SetScrollSizes(MM_TEXT, rectTemplate.Size());
203 return bRet;
206 BOOL CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
208 if (!CFormView::OnNcCreate(lpCreateStruct))
209 return FALSE;
211 // create and init the size-grip
212 if (!CreateSizeGrip())
213 return FALSE;
215 return TRUE;