Minor cleanup
[TortoiseGit.git] / src / Utils / MiscUI / StandAloneDlg.cpp
blob2c29823da5ed67aea4ec1dc1657a61e5e1d65736
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008,2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "Resource.h"
21 #include "StandAloneDlg.h"
23 const UINT TaskBarButtonCreated = RegisterWindowMessage(L"TaskbarButtonCreated");
25 BEGIN_TEMPLATE_MESSAGE_MAP(CStandAloneDialogTmpl, BaseType, BaseType)
26 ON_REGISTERED_MESSAGE(TaskBarButtonCreated, OnTaskbarButtonCreated)
27 END_MESSAGE_MAP()
29 IMPLEMENT_DYNAMIC(CStandAloneDialog, CStandAloneDialogTmpl<CDialog>)
30 CStandAloneDialog::CStandAloneDialog(UINT nIDTemplate, CWnd* pParentWnd /*= NULL*/)
31 : CStandAloneDialogTmpl<CDialog>(nIDTemplate, pParentWnd)
34 BEGIN_MESSAGE_MAP(CStandAloneDialog, CStandAloneDialogTmpl<CDialog>)
35 END_MESSAGE_MAP()
37 IMPLEMENT_DYNAMIC(CStateStandAloneDialog, CStandAloneDialogTmpl<CStateDialog>)
38 CStateStandAloneDialog::CStateStandAloneDialog(UINT nIDTemplate, CWnd* pParentWnd /*= NULL*/)
39 : CStandAloneDialogTmpl<CStateDialog>(nIDTemplate, pParentWnd)
42 BEGIN_MESSAGE_MAP(CStateStandAloneDialog, CStandAloneDialogTmpl<CStateDialog>)
43 ON_WM_DESTROY()
44 END_MESSAGE_MAP()
46 IMPLEMENT_DYNAMIC(CResizableStandAloneDialog, CDialog)
47 CResizableStandAloneDialog::CResizableStandAloneDialog(UINT nIDTemplate, CWnd* pParentWnd /*= NULL*/)
48 : CStandAloneDialogTmpl<CResizableDialog>(nIDTemplate, pParentWnd)
49 , m_bVertical(false)
50 , m_bHorizontal(false)
54 BEGIN_MESSAGE_MAP(CResizableStandAloneDialog, CStandAloneDialogTmpl<CResizableDialog>)
55 ON_WM_SIZING()
56 ON_WM_MOVING()
57 ON_WM_NCMBUTTONUP()
58 ON_WM_NCRBUTTONUP()
59 ON_BN_CLICKED(IDHELP, OnHelp)
60 END_MESSAGE_MAP()
62 void CResizableStandAloneDialog::OnSizing(UINT fwSide, LPRECT pRect)
64 m_bVertical = m_bVertical && (fwSide == WMSZ_LEFT || fwSide == WMSZ_RIGHT);
65 m_bHorizontal = m_bHorizontal && (fwSide == WMSZ_TOP || fwSide == WMSZ_BOTTOM);
66 CStandAloneDialogTmpl<CResizableDialog>::OnSizing(fwSide, pRect);
69 void CResizableStandAloneDialog::OnMoving(UINT fwSide, LPRECT pRect)
71 m_bVertical = m_bHorizontal = false;
72 CStandAloneDialogTmpl<CResizableDialog>::OnMoving(fwSide, pRect);
75 void CResizableStandAloneDialog::OnNcMButtonUp(UINT nHitTest, CPoint point)
77 WINDOWPLACEMENT windowPlacement;
78 if ((nHitTest == HTMAXBUTTON) && GetWindowPlacement(&windowPlacement) && windowPlacement.showCmd == SW_SHOWNORMAL)
80 CRect rcWorkArea, rcWindowRect;
81 GetWindowRect(&rcWindowRect);
82 if (m_bVertical)
84 rcWindowRect.top = m_rcOrgWindowRect.top;
85 rcWindowRect.bottom = m_rcOrgWindowRect.bottom;
87 else if (SystemParametersInfo(SPI_GETWORKAREA, 0U, &rcWorkArea, 0U))
89 m_rcOrgWindowRect.top = rcWindowRect.top;
90 m_rcOrgWindowRect.bottom = rcWindowRect.bottom;
91 rcWindowRect.top = rcWorkArea.top;
92 rcWindowRect.bottom = rcWorkArea.bottom;
94 m_bVertical = !m_bVertical;
95 MoveWindow(&rcWindowRect);
97 CStandAloneDialogTmpl<CResizableDialog>::OnNcMButtonUp(nHitTest, point);
100 void CResizableStandAloneDialog::OnNcRButtonUp(UINT nHitTest, CPoint point)
102 WINDOWPLACEMENT windowPlacement;
103 if ((nHitTest == HTMAXBUTTON) && GetWindowPlacement(&windowPlacement) && windowPlacement.showCmd == SW_SHOWNORMAL)
105 CRect rcWorkArea, rcWindowRect;
106 GetWindowRect(&rcWindowRect);
107 if (m_bHorizontal)
109 rcWindowRect.left = m_rcOrgWindowRect.left;
110 rcWindowRect.right = m_rcOrgWindowRect.right;
112 else if (SystemParametersInfo(SPI_GETWORKAREA, 0U, &rcWorkArea, 0U))
114 m_rcOrgWindowRect.left = rcWindowRect.left;
115 m_rcOrgWindowRect.right = rcWindowRect.right;
116 rcWindowRect.left = rcWorkArea.left;
117 rcWindowRect.right = rcWorkArea.right;
119 m_bHorizontal = !m_bHorizontal;
120 MoveWindow(&rcWindowRect);
121 // WORKAROUND
122 // for some reasons, when the window is resized horizontally, its menu size is not get adjusted.
123 // so, we force it to happen.
124 SetMenu(GetMenu());
126 CStandAloneDialogTmpl<CResizableDialog>::OnNcRButtonUp(nHitTest, point);
129 BEGIN_MESSAGE_MAP(CStateDialog, CDialog)
130 ON_BN_CLICKED(IDHELP, OnHelp)
131 END_MESSAGE_MAP()