Fix typos
[TortoiseGit.git] / ext / ResizableLib / ResizableDialog.cpp
blobdfa1cf7a0ad079af5e232068a8c7e321927ba82c
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 CResizableDialog::CResizableDialog()
36 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)
37 : CDialog(nIDTemplate, pParentWnd)
41 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
42 : CDialog(lpszTemplateName, pParentWnd)
46 CResizableDialog::~CResizableDialog()
51 BEGIN_MESSAGE_MAP(CResizableDialog, CDialog)
52 //{{AFX_MSG_MAP(CResizableDialog)
53 ON_WM_GETMINMAXINFO()
54 ON_WM_SIZE()
55 ON_WM_DESTROY()
56 ON_WM_ERASEBKGND()
57 ON_WM_NCCREATE()
58 //}}AFX_MSG_MAP
59 END_MESSAGE_MAP()
61 /////////////////////////////////////////////////////////////////////////////
62 // CResizableDialog message handlers
64 BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
66 if (!CDialog::OnNcCreate(lpCreateStruct))
67 return FALSE;
69 // child dialogs don't want resizable border or size grip,
70 // nor they can handle the min/max size constraints
71 BOOL bChild = lpCreateStruct->style & WS_CHILD;
73 // create and init the size-grip
74 if (!CreateSizeGrip(!bChild))
75 return FALSE;
77 if (!bChild)
79 // set the initial size as the min track size
80 SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy));
83 MakeResizable(lpCreateStruct);
85 return TRUE;
88 void CResizableDialog::OnDestroy()
90 if (m_bEnableSaveRestore)
91 SaveWindowRect(m_sSection, m_bRectOnly);
93 // remove child windows
94 RemoveAllAnchors();
96 CDialog::OnDestroy();
99 void CResizableDialog::OnSize(UINT nType, int cx, int cy)
101 CWnd::OnSize(nType, cx, cy);
103 if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)
104 return; // arrangement not needed
106 if (nType == SIZE_MAXIMIZED)
107 HideSizeGrip(&m_dwGripTempState);
108 else
109 ShowSizeGrip(&m_dwGripTempState);
111 // update grip and layout
112 UpdateSizeGrip();
113 ArrangeLayout();
114 // on Vista, the redrawing doesn't work right, so we have to work
115 // around this by invalidating the whole dialog so the DWM recognizes
116 // that it has to update the application window.
117 Invalidate();
120 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
122 MinMaxInfo(lpMMI);
125 // NOTE: this must be called after setting the layout
126 // to have the dialog and its controls displayed properly
127 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly, BOOL bHorzResize, BOOL bVertResize)
129 m_sSection = pszSection;
131 m_bEnableSaveRestore = TRUE;
132 m_bRectOnly = bRectOnly;
134 // restore immediately
135 LoadWindowRect(pszSection, bRectOnly, bHorzResize, bVertResize);
137 CMenu* pMenu = GetMenu();
138 if ( pMenu )
139 DrawMenuBar();
142 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
144 ClipChildren(pDC, FALSE);
146 BOOL bRet = CDialog::OnEraseBkgnd(pDC);
148 ClipChildren(pDC, TRUE);
150 return bRet;
153 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
155 if (message != WM_NCCALCSIZE || wParam == 0 || m_noNcCalcSizeAdjustments)
156 return CDialog::WindowProc(message, wParam, lParam);
158 LRESULT lResult = 0;
159 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
160 lResult = CDialog::WindowProc(message, wParam, lParam);
161 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
162 return lResult;
165 BOOL CResizableDialog::AddOthersToAnchor()
167 CWnd * pWnd = GetWindow(GW_CHILD);
168 while(pWnd)
170 if(!IsInAnchorList(pWnd->m_hWnd) && pWnd->m_hWnd != m_wndGrip.m_hWnd )
171 this->AddAnchor(pWnd->m_hWnd,TOP_LEFT);
173 pWnd=pWnd->GetNextWindow(GW_HWNDNEXT);
175 return TRUE;