Improve parenthesis positions
[TortoiseGit.git] / ext / ResizableLib / ResizableDialog.cpp
blob9acf16bc9a1a237b342b3625d0a94cc4ddd06f21
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;
36 m_bRectOnly = FALSE;
39 CResizableDialog::CResizableDialog()
41 PrivateConstruct();
44 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)
45 : CDialog(nIDTemplate, pParentWnd)
47 PrivateConstruct();
50 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
51 : CDialog(lpszTemplateName, pParentWnd)
53 PrivateConstruct();
56 CResizableDialog::~CResizableDialog()
61 BEGIN_MESSAGE_MAP(CResizableDialog, CDialog)
62 //{{AFX_MSG_MAP(CResizableDialog)
63 ON_WM_GETMINMAXINFO()
64 ON_WM_SIZE()
65 ON_WM_DESTROY()
66 ON_WM_ERASEBKGND()
67 ON_WM_NCCREATE()
68 //}}AFX_MSG_MAP
69 END_MESSAGE_MAP()
71 /////////////////////////////////////////////////////////////////////////////
72 // CResizableDialog message handlers
74 BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
76 if (!CDialog::OnNcCreate(lpCreateStruct))
77 return FALSE;
79 // child dialogs don't want resizable border or size grip,
80 // nor they can handle the min/max size constraints
81 BOOL bChild = lpCreateStruct->style & WS_CHILD;
83 // create and init the size-grip
84 if (!CreateSizeGrip(!bChild))
85 return FALSE;
87 if (!bChild)
89 // set the initial size as the min track size
90 SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy));
93 MakeResizable(lpCreateStruct);
95 return TRUE;
98 void CResizableDialog::OnDestroy()
100 if (m_bEnableSaveRestore)
101 SaveWindowRect(m_sSection, m_bRectOnly);
103 // remove child windows
104 RemoveAllAnchors();
106 CDialog::OnDestroy();
109 void CResizableDialog::OnSize(UINT nType, int cx, int cy)
111 CWnd::OnSize(nType, cx, cy);
113 if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)
114 return; // arrangement not needed
116 if (nType == SIZE_MAXIMIZED)
117 HideSizeGrip(&m_dwGripTempState);
118 else
119 ShowSizeGrip(&m_dwGripTempState);
121 // update grip and layout
122 UpdateSizeGrip();
123 ArrangeLayout();
124 // on Vista, the redrawing doesn't work right, so we have to work
125 // around this by invalidating the whole dialog so the DWM recognizes
126 // that it has to update the application window.
127 Invalidate();
130 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
132 MinMaxInfo(lpMMI);
135 // NOTE: this must be called after setting the layout
136 // to have the dialog and its controls displayed properly
137 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly, BOOL bHorzResize, BOOL bVertResize)
139 m_sSection = pszSection;
141 m_bEnableSaveRestore = TRUE;
142 m_bRectOnly = bRectOnly;
144 // restore immediately
145 LoadWindowRect(pszSection, bRectOnly, bHorzResize, bVertResize);
147 CMenu* pMenu = GetMenu();
148 if ( pMenu )
149 DrawMenuBar();
152 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
154 ClipChildren(pDC, FALSE);
156 BOOL bRet = CDialog::OnEraseBkgnd(pDC);
158 ClipChildren(pDC, TRUE);
160 return bRet;
163 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
165 if (message != WM_NCCALCSIZE || wParam == 0)
166 return CDialog::WindowProc(message, wParam, lParam);
168 LRESULT lResult = 0;
169 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
170 lResult = CDialog::WindowProc(message, wParam, lParam);
171 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
172 return lResult;
175 BOOL CResizableDialog::AddOthersToAnchor()
177 CWnd * pWnd = GetWindow(GW_CHILD);
178 while(pWnd)
180 if(!IsInAnchorList(pWnd->m_hWnd) && pWnd->m_hWnd != m_wndGrip.m_hWnd )
181 this->AddAnchor(pWnd->m_hWnd,TOP_LEFT);
183 pWnd=pWnd->GetNextWindow(GW_HWNDNEXT);
185 return TRUE;