OSDN Git Service

3e098658c435770dc266f297f6502300eb5d5cc4
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / StandAloneDlg.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "Resource.h"\r
21 #include "StandAloneDlg.h"\r
22 \r
23 IMPLEMENT_DYNAMIC(CResizableStandAloneDialog, CDialog)\r
24 CResizableStandAloneDialog::CResizableStandAloneDialog(UINT nIDTemplate, CWnd* pParentWnd /*= NULL*/)\r
25         : CStandAloneDialogTmpl<CResizableDialog>(nIDTemplate, pParentWnd)\r
26         , m_bVertical(false)\r
27         , m_bHorizontal(false)\r
28 {\r
29 }\r
30 \r
31 BEGIN_MESSAGE_MAP(CResizableStandAloneDialog, CStandAloneDialogTmpl<CResizableDialog>)\r
32         ON_WM_SIZING()\r
33         ON_WM_MOVING()\r
34         ON_WM_NCMBUTTONUP()\r
35         ON_WM_NCRBUTTONUP()\r
36 END_MESSAGE_MAP()\r
37 \r
38 void CResizableStandAloneDialog::OnSizing(UINT fwSide, LPRECT pRect)\r
39 {\r
40         m_bVertical = m_bVertical && (fwSide == WMSZ_LEFT || fwSide == WMSZ_RIGHT);\r
41         m_bHorizontal = m_bHorizontal && (fwSide == WMSZ_TOP || fwSide == WMSZ_BOTTOM);\r
42         CStandAloneDialogTmpl<CResizableDialog>::OnSizing(fwSide, pRect);\r
43 }\r
44 \r
45 void CResizableStandAloneDialog::OnMoving(UINT fwSide, LPRECT pRect)\r
46 {\r
47         m_bVertical = m_bHorizontal = false;\r
48         CStandAloneDialogTmpl<CResizableDialog>::OnMoving(fwSide, pRect);\r
49 }\r
50 \r
51 void CResizableStandAloneDialog::OnNcMButtonUp(UINT nHitTest, CPoint point) \r
52 {\r
53         WINDOWPLACEMENT windowPlacement;\r
54         if ((nHitTest == HTMAXBUTTON) && GetWindowPlacement(&windowPlacement) && windowPlacement.showCmd == SW_SHOWNORMAL)\r
55         {\r
56                 CRect rcWorkArea, rcWindowRect;\r
57                 GetWindowRect(&rcWindowRect);\r
58                 if (m_bVertical)\r
59                 {\r
60                         rcWindowRect.top = m_rcOrgWindowRect.top;\r
61                         rcWindowRect.bottom = m_rcOrgWindowRect.bottom;\r
62                 }\r
63                 else if (SystemParametersInfo(SPI_GETWORKAREA, 0U, &rcWorkArea, 0U))\r
64                 {\r
65                         m_rcOrgWindowRect.top = rcWindowRect.top;\r
66                         m_rcOrgWindowRect.bottom = rcWindowRect.bottom;\r
67                         rcWindowRect.top = rcWorkArea.top;\r
68                         rcWindowRect.bottom = rcWorkArea.bottom;\r
69                 }\r
70                 m_bVertical = !m_bVertical;\r
71                 m_bHorizontal = m_bHorizontal;\r
72                 MoveWindow(&rcWindowRect);\r
73         }\r
74         CStandAloneDialogTmpl<CResizableDialog>::OnNcMButtonUp(nHitTest, point);\r
75 }\r
76 \r
77 void CResizableStandAloneDialog::OnNcRButtonUp(UINT nHitTest, CPoint point) \r
78 {\r
79         WINDOWPLACEMENT windowPlacement;\r
80         if ((nHitTest == HTMAXBUTTON) && GetWindowPlacement(&windowPlacement) && windowPlacement.showCmd == SW_SHOWNORMAL)\r
81         {\r
82                 CRect rcWorkArea, rcWindowRect;\r
83                 GetWindowRect(&rcWindowRect);\r
84                 if (m_bHorizontal)\r
85                 {\r
86                         rcWindowRect.left = m_rcOrgWindowRect.left;\r
87                         rcWindowRect.right = m_rcOrgWindowRect.right;\r
88                 }\r
89                 else if (SystemParametersInfo(SPI_GETWORKAREA, 0U, &rcWorkArea, 0U))\r
90                 {\r
91                         m_rcOrgWindowRect.left = rcWindowRect.left;\r
92                         m_rcOrgWindowRect.right = rcWindowRect.right;\r
93                         rcWindowRect.left = rcWorkArea.left;\r
94                         rcWindowRect.right = rcWorkArea.right;\r
95                 }\r
96                 m_bVertical = m_bVertical;\r
97                 m_bHorizontal = !m_bHorizontal;\r
98                 MoveWindow(&rcWindowRect);\r
99                 // WORKAROUND\r
100                 // for some reasons, when the window is resized horizontally, its menu size is not get adjusted.\r
101                 // so, we force it to happen.\r
102                 SetMenu(GetMenu());\r
103         }\r
104         CStandAloneDialogTmpl<CResizableDialog>::OnNcRButtonUp(nHitTest, point);\r
105 }\r