Fixed issue #1220: ext/CrashServer/CommonLibs/Zlib/Zlib.vcproj immediate dir Win32...
[TortoiseGit.git] / ext / ResizableLib / ResizableDialog.cpp
blobd9b33b39f4171493c09916e4ac732d5db92b4e1a
1 // ResizableDialog.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 "ResizableDialog.h"
23 #ifdef _DEBUG
24 #define new DEBUG_NEW
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
29 /////////////////////////////////////////////////////////////////////////////
30 // CResizableDialog
32 inline void CResizableDialog::PrivateConstruct()
34 m_bEnableSaveRestore = FALSE;
35 m_dwGripTempState = 1;
38 CResizableDialog::CResizableDialog()
40 PrivateConstruct();
43 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)
44 : CDialog(nIDTemplate, pParentWnd)
46 PrivateConstruct();
49 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
50 : CDialog(lpszTemplateName, pParentWnd)
52 PrivateConstruct();
55 CResizableDialog::~CResizableDialog()
60 BEGIN_MESSAGE_MAP(CResizableDialog, CDialog)
61 //{{AFX_MSG_MAP(CResizableDialog)
62 ON_WM_GETMINMAXINFO()
63 ON_WM_SIZE()
64 ON_WM_DESTROY()
65 ON_WM_ERASEBKGND()
66 ON_WM_NCCREATE()
67 //}}AFX_MSG_MAP
68 END_MESSAGE_MAP()
70 /////////////////////////////////////////////////////////////////////////////
71 // CResizableDialog message handlers
73 BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
75 if (!CDialog::OnNcCreate(lpCreateStruct))
76 return FALSE;
78 // child dialogs don't want resizable border or size grip,
79 // nor they can handle the min/max size constraints
80 BOOL bChild = lpCreateStruct->style & WS_CHILD;
82 // create and init the size-grip
83 if (!CreateSizeGrip(!bChild))
84 return FALSE;
86 if (!bChild)
88 // set the initial size as the min track size
89 SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy));
92 MakeResizable(lpCreateStruct);
94 return TRUE;
97 void CResizableDialog::OnDestroy()
99 if (m_bEnableSaveRestore)
100 SaveWindowRect(m_sSection, m_bRectOnly);
102 // remove child windows
103 RemoveAllAnchors();
105 CDialog::OnDestroy();
108 void CResizableDialog::OnSize(UINT nType, int cx, int cy)
110 CWnd::OnSize(nType, cx, cy);
112 if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)
113 return; // arrangement not needed
115 if (nType == SIZE_MAXIMIZED)
116 HideSizeGrip(&m_dwGripTempState);
117 else
118 ShowSizeGrip(&m_dwGripTempState);
120 // update grip and layout
121 UpdateSizeGrip();
122 ArrangeLayout();
123 // on Vista, the redrawing doesn't work right, so we have to work
124 // around this by invalidating the whole dialog so the DWM recognizes
125 // that it has to update the application window.
126 OSVERSIONINFOEX inf;
127 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
128 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
129 GetVersionEx((OSVERSIONINFO *)&inf);
130 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
131 if (fullver >= 0x0600)
132 Invalidate();
135 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
137 MinMaxInfo(lpMMI);
140 // NOTE: this must be called after setting the layout
141 // to have the dialog and its controls displayed properly
142 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
144 m_sSection = pszSection;
146 m_bEnableSaveRestore = TRUE;
147 m_bRectOnly = bRectOnly;
149 // restore immediately
150 LoadWindowRect(pszSection, bRectOnly);
152 CMenu* pMenu = GetMenu();
153 if ( pMenu )
154 DrawMenuBar();
157 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
159 ClipChildren(pDC, FALSE);
161 BOOL bRet = CDialog::OnEraseBkgnd(pDC);
163 ClipChildren(pDC, TRUE);
165 return bRet;
168 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
170 if (message != WM_NCCALCSIZE || wParam == 0)
171 return CDialog::WindowProc(message, wParam, lParam);
173 LRESULT lResult = 0;
174 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
175 lResult = CDialog::WindowProc(message, wParam, lParam);
176 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
177 return lResult;
180 BOOL CResizableDialog::AddOthersToAnchor()
182 CWnd * pWnd = GetWindow(GW_CHILD);
183 while(pWnd)
185 if(!IsInAnchorList(pWnd->m_hWnd) && pWnd->m_hWnd != m_wndGrip.m_hWnd )
186 this->AddAnchor(pWnd->m_hWnd,TOP_LEFT);
188 pWnd=pWnd->GetNextWindow(GW_HWNDNEXT);
190 return TRUE;