Return error message "User Cancelled" when user press cancel in password box
[TortoiseGit.git] / ext / ResizableLib / ResizableFormView.cpp
blob1c7aa85a3f273a5638c2a3c9286f3e2e37338057
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 inline void CResizableFormView::PrivateConstruct()
36 m_dwGripTempState = GHR_SCROLLBAR | GHR_ALIGNMENT | GHR_MAXIMIZED;
39 CResizableFormView::CResizableFormView(UINT nIDTemplate)
40 : CFormView(nIDTemplate)
42 PrivateConstruct();
45 CResizableFormView::CResizableFormView(LPCTSTR lpszTemplateName)
46 : CFormView(lpszTemplateName)
48 PrivateConstruct();
51 CResizableFormView::~CResizableFormView()
56 BEGIN_MESSAGE_MAP(CResizableFormView, CFormView)
57 //{{AFX_MSG_MAP(CResizableFormView)
58 ON_WM_SIZE()
59 ON_WM_ERASEBKGND()
60 ON_WM_GETMINMAXINFO()
61 ON_WM_DESTROY()
62 ON_WM_NCCREATE()
63 //}}AFX_MSG_MAP
64 END_MESSAGE_MAP()
66 /////////////////////////////////////////////////////////////////////////////
67 // CResizableFormView diagnostics
69 #ifdef _DEBUG
70 void CResizableFormView::AssertValid() const
72 CFormView::AssertValid();
75 void CResizableFormView::Dump(CDumpContext& dc) const
77 CFormView::Dump(dc);
79 #endif //_DEBUG
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);
93 else
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);
100 else
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;
107 GetWindowRect(rect);
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)
117 bCanResize = FALSE;
118 break;
121 if ((dwStyle & WS_THICKFRAME) && bCanResize)
122 ShowSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
123 else
124 HideSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
126 // update grip and layout
127 UpdateSizeGrip();
128 ArrangeLayout();
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;
138 int nMapMode = 0;
139 GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);
141 // otherwise, give the correct size if scrollbars active
143 if (nMapMode < 0) // scrollbars disabled
144 return;
146 // enlarge reported client area when needed
147 CRect rect(lpRect);
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());
154 *lpRect = rect;
157 BOOL CResizableFormView::OnEraseBkgnd(CDC* pDC)
159 ClipChildren(pDC, FALSE);
161 BOOL bRet = CFormView::OnEraseBkgnd(pDC);
163 ClipChildren(pDC, TRUE);
165 return bRet;
168 void CResizableFormView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
170 MinMaxInfo(lpMMI);
173 void CResizableFormView::OnDestroy()
175 RemoveAllAnchors();
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
189 LRESULT lResult = 0;
190 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
191 lResult = CFormView::WindowProc(message, wParam, lParam);
192 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
193 return 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
203 UpdateData(FALSE);
205 // set default scroll size
206 CRect rectTemplate;
207 GetWindowRect(rectTemplate);
208 SetScrollSizes(MM_TEXT, rectTemplate.Size());
210 return bRet;
213 BOOL CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
215 if (!CFormView::OnNcCreate(lpCreateStruct))
216 return FALSE;
218 // create and init the size-grip
219 if (!CreateSizeGrip())
220 return FALSE;
222 return TRUE;