OSDN Git Service

Compiler warnings removal Numerous tweaks to remove compiler warnings where solution...
[tortoisegit/TortoiseGitJp.git] / ext / ResizableLib / ResizableDialog.cpp
1 // ResizableDialog.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 "ResizableDialog.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 // CResizableDialog\r
31 \r
32 inline void CResizableDialog::PrivateConstruct()\r
33 {\r
34         m_bEnableSaveRestore = FALSE;\r
35         m_dwGripTempState = 1;\r
36 }\r
37 \r
38 CResizableDialog::CResizableDialog()\r
39 {\r
40         PrivateConstruct();\r
41 }\r
42 \r
43 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)\r
44         : CDialog(nIDTemplate, pParentWnd)\r
45 {\r
46         PrivateConstruct();\r
47 }\r
48 \r
49 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)\r
50         : CDialog(lpszTemplateName, pParentWnd)\r
51 {\r
52         PrivateConstruct();\r
53 }\r
54 \r
55 CResizableDialog::~CResizableDialog()\r
56 {\r
57 }\r
58 \r
59 \r
60 BEGIN_MESSAGE_MAP(CResizableDialog, CDialog)\r
61         //{{AFX_MSG_MAP(CResizableDialog)\r
62         ON_WM_GETMINMAXINFO()\r
63         ON_WM_SIZE()\r
64         ON_WM_DESTROY()\r
65         ON_WM_ERASEBKGND()\r
66         ON_WM_NCCREATE()\r
67         //}}AFX_MSG_MAP\r
68 END_MESSAGE_MAP()\r
69 \r
70 /////////////////////////////////////////////////////////////////////////////\r
71 // CResizableDialog message handlers\r
72 \r
73 BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct) \r
74 {\r
75         if (!CDialog::OnNcCreate(lpCreateStruct))\r
76                 return FALSE;\r
77 \r
78         // child dialogs don't want resizable border or size grip,\r
79         // nor they can handle the min/max size constraints\r
80         BOOL bChild = lpCreateStruct->style & WS_CHILD;\r
81 \r
82         // create and init the size-grip\r
83         if (!CreateSizeGrip(!bChild))\r
84                 return FALSE;\r
85 \r
86         if (!bChild)\r
87         {\r
88                 // set the initial size as the min track size\r
89                 SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy));\r
90         }\r
91         \r
92         MakeResizable(lpCreateStruct);\r
93 \r
94         return TRUE;\r
95 }\r
96 \r
97 void CResizableDialog::OnDestroy() \r
98 {\r
99         if (m_bEnableSaveRestore)\r
100                 SaveWindowRect(m_sSection, m_bRectOnly);\r
101 \r
102         // remove child windows\r
103         RemoveAllAnchors();\r
104 \r
105         CDialog::OnDestroy();\r
106 }\r
107 \r
108 void CResizableDialog::OnSize(UINT nType, int cx, int cy) \r
109 {\r
110         CWnd::OnSize(nType, cx, cy);\r
111         \r
112         if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)\r
113                 return;         // arrangement not needed\r
114 \r
115         if (nType == SIZE_MAXIMIZED)\r
116                 HideSizeGrip(&m_dwGripTempState);\r
117         else\r
118                 ShowSizeGrip(&m_dwGripTempState);\r
119 \r
120         // update grip and layout\r
121         UpdateSizeGrip();\r
122         ArrangeLayout();\r
123         // on Vista, the redrawing doesn't work right, so we have to work\r
124         // around this by invalidating the whole dialog so the DWM recognizes\r
125         // that it has to update the application window.\r
126         OSVERSIONINFOEX inf;\r
127         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
128         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
129         GetVersionEx((OSVERSIONINFO *)&inf);\r
130         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
131         if (fullver >= 0x0600)\r
132                 Invalidate();\r
133 }\r
134 \r
135 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) \r
136 {\r
137         MinMaxInfo(lpMMI);\r
138 }\r
139 \r
140 // NOTE: this must be called after setting the layout\r
141 //       to have the dialog and its controls displayed properly\r
142 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)\r
143 {\r
144         m_sSection = pszSection;\r
145 \r
146         m_bEnableSaveRestore = TRUE;\r
147         m_bRectOnly = bRectOnly;\r
148 \r
149         // restore immediately\r
150         LoadWindowRect(pszSection, bRectOnly);\r
151 \r
152         CMenu* pMenu = GetMenu();\r
153         if ( pMenu )\r
154                 DrawMenuBar();\r
155 }\r
156 \r
157 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC) \r
158 {\r
159         ClipChildren(pDC, FALSE);\r
160 \r
161         BOOL bRet = CDialog::OnEraseBkgnd(pDC);\r
162 \r
163         ClipChildren(pDC, TRUE);\r
164 \r
165         return bRet;\r
166 }\r
167 \r
168 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) \r
169 {\r
170         if (message != WM_NCCALCSIZE || wParam == 0)\r
171                 return CDialog::WindowProc(message, wParam, lParam);\r
172 \r
173         LRESULT lResult = 0;\r
174         HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);\r
175         lResult = CDialog::WindowProc(message, wParam, lParam);\r
176         HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);\r
177         return lResult;\r
178 }\r