CommitDlg: Update index using libgit2 incrementally
[TortoiseGit.git] / ext / ResizableLib / ResizableDialog.cpp
blob5f6db9d3a8a31b40595c64697a4aad9d3493cf7d
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 OSVERSIONINFOEX inf;
128 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
129 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
130 GetVersionEx((OSVERSIONINFO *)&inf);
131 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
132 if (fullver >= 0x0600)
133 Invalidate();
136 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
138 MinMaxInfo(lpMMI);
141 // NOTE: this must be called after setting the layout
142 // to have the dialog and its controls displayed properly
143 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
145 m_sSection = pszSection;
147 m_bEnableSaveRestore = TRUE;
148 m_bRectOnly = bRectOnly;
150 // restore immediately
151 LoadWindowRect(pszSection, bRectOnly);
153 CMenu* pMenu = GetMenu();
154 if ( pMenu )
155 DrawMenuBar();
158 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
160 ClipChildren(pDC, FALSE);
162 BOOL bRet = CDialog::OnEraseBkgnd(pDC);
164 ClipChildren(pDC, TRUE);
166 return bRet;
169 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
171 if (message != WM_NCCALCSIZE || wParam == 0)
172 return CDialog::WindowProc(message, wParam, lParam);
174 LRESULT lResult = 0;
175 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
176 lResult = CDialog::WindowProc(message, wParam, lParam);
177 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
178 return lResult;
181 BOOL CResizableDialog::AddOthersToAnchor()
183 CWnd * pWnd = GetWindow(GW_CHILD);
184 while(pWnd)
186 if(!IsInAnchorList(pWnd->m_hWnd) && pWnd->m_hWnd != m_wndGrip.m_hWnd )
187 this->AddAnchor(pWnd->m_hWnd,TOP_LEFT);
189 pWnd=pWnd->GetNextWindow(GW_HWNDNEXT);
191 return TRUE;