OSDN Git Service

Merge remove x86 build
[tortoisegit/TortoiseGitJp.git] / ext / ResizableLib / ResizableFormView.cpp
1 // ResizableFormView.cpp : implementation file\r
2 //\r
3 /////////////////////////////////////////////////////////////////////////////\r
4 //\r
5 // This file is part of ResizableLib\r
6 // http://sourceforge.net/projects/resizablelib\r
7 //\r
8 // Copyright (C) 2000-2004 by Paolo Messina\r
9 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com\r
10 //\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
15 //\r
16 // If you find this code useful, credits would be nice!\r
17 //\r
18 /////////////////////////////////////////////////////////////////////////////\r
19 \r
20 #include "stdafx.h"\r
21 #include "ResizableFormView.h"\r
22 \r
23 #ifdef _DEBUG\r
24 #define new DEBUG_NEW\r
25 #undef THIS_FILE\r
26 static char THIS_FILE[] = __FILE__;\r
27 #endif\r
28 \r
29 /////////////////////////////////////////////////////////////////////////////\r
30 // CResizableFormView\r
31 \r
32 IMPLEMENT_DYNAMIC(CResizableFormView, CFormView)\r
33 \r
34 inline void CResizableFormView::PrivateConstruct()\r
35 {\r
36         m_dwGripTempState = GHR_SCROLLBAR | GHR_ALIGNMENT | GHR_MAXIMIZED;\r
37 }\r
38 \r
39 CResizableFormView::CResizableFormView(UINT nIDTemplate)\r
40         : CFormView(nIDTemplate)\r
41 {\r
42         PrivateConstruct();\r
43 }\r
44 \r
45 CResizableFormView::CResizableFormView(LPCTSTR lpszTemplateName)\r
46         : CFormView(lpszTemplateName)\r
47 {\r
48         PrivateConstruct();\r
49 }\r
50 \r
51 CResizableFormView::~CResizableFormView()\r
52 {\r
53 }\r
54 \r
55 \r
56 BEGIN_MESSAGE_MAP(CResizableFormView, CFormView)\r
57         //{{AFX_MSG_MAP(CResizableFormView)\r
58         ON_WM_SIZE()\r
59         ON_WM_ERASEBKGND()\r
60         ON_WM_GETMINMAXINFO()\r
61         ON_WM_DESTROY()\r
62         ON_WM_NCCREATE()\r
63         //}}AFX_MSG_MAP\r
64 END_MESSAGE_MAP()\r
65 \r
66 /////////////////////////////////////////////////////////////////////////////\r
67 // CResizableFormView diagnostics\r
68 \r
69 #ifdef _DEBUG\r
70 void CResizableFormView::AssertValid() const\r
71 {\r
72         CFormView::AssertValid();\r
73 }\r
74 \r
75 void CResizableFormView::Dump(CDumpContext& dc) const\r
76 {\r
77         CFormView::Dump(dc);\r
78 }\r
79 #endif //_DEBUG\r
80 \r
81 /////////////////////////////////////////////////////////////////////////////\r
82 // CResizableFormView message handlers\r
83 \r
84 void CResizableFormView::OnSize(UINT nType, int cx, int cy) \r
85 {\r
86         CFormView::OnSize(nType, cx, cy);\r
87 \r
88         CWnd* pParent = GetParentFrame();\r
89 \r
90         // hide size grip when parent is maximized\r
91         if (pParent->IsZoomed())\r
92                 HideSizeGrip(&m_dwGripTempState, GHR_MAXIMIZED);\r
93         else\r
94                 ShowSizeGrip(&m_dwGripTempState, GHR_MAXIMIZED);\r
95 \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
100         else\r
101                 ShowSizeGrip(&m_dwGripTempState, GHR_SCROLLBAR);\r
102 \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
108 \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
112         {\r
113                 ::GetWindowRect(hWndChild, rectChild);\r
114                 //! @todo check RTL layouts!\r
115                 if (rectChild.right > rect.right || rectChild.bottom > rect.bottom)\r
116                 {\r
117                         bCanResize = FALSE;\r
118                         break;\r
119                 }\r
120         }\r
121         if ((dwStyle & WS_THICKFRAME) && bCanResize)\r
122                 ShowSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);\r
123         else\r
124                 HideSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);\r
125 \r
126         // update grip and layout\r
127         UpdateSizeGrip();\r
128         ArrangeLayout();\r
129 }\r
130 \r
131 void CResizableFormView::GetTotalClientRect(LPRECT lpRect) const\r
132 {\r
133         GetClientRect(lpRect);\r
134 \r
135         // get dialog template's size\r
136         // (this is set in CFormView::Create)\r
137         CSize sizeTotal, sizePage, sizeLine;\r
138         int nMapMode = 0;\r
139         GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);\r
140 \r
141         // otherwise, give the correct size if scrollbars active\r
142 \r
143         if (nMapMode < 0)       // scrollbars disabled\r
144                 return;\r
145 \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
152 \r
153         rect.OffsetRect(-GetDeviceScrollPosition());\r
154         *lpRect = rect;\r
155 }\r
156 \r
157 BOOL CResizableFormView::OnEraseBkgnd(CDC* pDC) \r
158 {\r
159         ClipChildren(pDC, FALSE);\r
160 \r
161         BOOL bRet = CFormView::OnEraseBkgnd(pDC);\r
162 \r
163         ClipChildren(pDC, TRUE);\r
164 \r
165         return bRet;\r
166 }\r
167 \r
168 void CResizableFormView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) \r
169 {\r
170         MinMaxInfo(lpMMI);\r
171 }\r
172 \r
173 void CResizableFormView::OnDestroy() \r
174 {\r
175         RemoveAllAnchors();\r
176 \r
177         CFormView::OnDestroy();\r
178 }\r
179 \r
180 LRESULT CResizableFormView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) \r
181 {\r
182         if (message == WM_INITDIALOG)\r
183                 return (LRESULT)OnInitDialog();\r
184 \r
185         if (message != WM_NCCALCSIZE || wParam == 0)\r
186                 return CFormView::WindowProc(message, wParam, lParam);\r
187 \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
193         return lResult;\r
194 }\r
195 \r
196 BOOL CResizableFormView::OnInitDialog() \r
197 {\r
198         const MSG* pMsg = GetCurrentMessage();\r
199 \r
200         BOOL bRet = (BOOL)CFormView::WindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);\r
201 \r
202         // we need to associate member variables with control IDs\r
203         UpdateData(FALSE);\r
204         \r
205         // set default scroll size\r
206         CRect rectTemplate;\r
207         GetWindowRect(rectTemplate);\r
208         SetScrollSizes(MM_TEXT, rectTemplate.Size());\r
209 \r
210         return bRet;\r
211 }\r
212 \r
213 BOOL CResizableFormView::OnNcCreate(LPCREATESTRUCT lpCreateStruct) \r
214 {\r
215         if (!CFormView::OnNcCreate(lpCreateStruct))\r
216                 return FALSE;\r
217         \r
218         // create and init the size-grip\r
219         if (!CreateSizeGrip())\r
220                 return FALSE;\r
221 \r
222         return TRUE;\r
223 }\r