OSDN Git Service

Create TortoiseGitBlame
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
1 \r
2 #include "stdafx.h"\r
3 \r
4 #include "PropertiesWnd.h"\r
5 #include "Resource.h"\r
6 #include "MainFrm.h"\r
7 #include "TortoiseGitBlame.h"\r
8 \r
9 #ifdef _DEBUG\r
10 #undef THIS_FILE\r
11 static char THIS_FILE[]=__FILE__;\r
12 #define new DEBUG_NEW\r
13 #endif\r
14 \r
15 /////////////////////////////////////////////////////////////////////////////\r
16 // CResourceViewBar\r
17 \r
18 CPropertiesWnd::CPropertiesWnd()\r
19 {\r
20 }\r
21 \r
22 CPropertiesWnd::~CPropertiesWnd()\r
23 {\r
24 }\r
25 \r
26 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)\r
27         ON_WM_CREATE()\r
28         ON_WM_SIZE()\r
29         ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)\r
30         ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)\r
31         ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)\r
32         ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)\r
33         ON_COMMAND(ID_PROPERTIES1, OnProperties1)\r
34         ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)\r
35         ON_COMMAND(ID_PROPERTIES2, OnProperties2)\r
36         ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)\r
37         ON_WM_SETFOCUS()\r
38         ON_WM_SETTINGCHANGE()\r
39 END_MESSAGE_MAP()\r
40 \r
41 /////////////////////////////////////////////////////////////////////////////\r
42 // CResourceViewBar message handlers\r
43 \r
44 void CPropertiesWnd::AdjustLayout()\r
45 {\r
46         if (GetSafeHwnd() == NULL)\r
47         {\r
48                 return;\r
49         }\r
50 \r
51         CRect rectClient,rectCombo;\r
52         GetClientRect(rectClient);\r
53 \r
54         m_wndObjectCombo.GetWindowRect(&rectCombo);\r
55 \r
56         int cyCmb = rectCombo.Size().cy;\r
57         int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;\r
58 \r
59         m_wndObjectCombo.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
60         m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);\r
61         m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb + cyTlb, rectClient.Width(), rectClient.Height() -(cyCmb+cyTlb), SWP_NOACTIVATE | SWP_NOZORDER);\r
62 }\r
63 \r
64 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
65 {\r
66         if (CDockablePane::OnCreate(lpCreateStruct) == -1)\r
67                 return -1;\r
68 \r
69         CRect rectDummy;\r
70         rectDummy.SetRectEmpty();\r
71 \r
72         // Create combo:\r
73         const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;\r
74 \r
75         if (!m_wndObjectCombo.Create(dwViewStyle, rectDummy, this, 1))\r
76         {\r
77                 TRACE0("Failed to create Properties Combo \n");\r
78                 return -1;      // fail to create\r
79         }\r
80 \r
81         m_wndObjectCombo.AddString(_T("Application"));\r
82         m_wndObjectCombo.AddString(_T("Properties Window"));\r
83         m_wndObjectCombo.SetFont(CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)));\r
84         m_wndObjectCombo.SetCurSel(0);\r
85 \r
86         if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))\r
87         {\r
88                 TRACE0("Failed to create Properties Grid \n");\r
89                 return -1;      // fail to create\r
90         }\r
91 \r
92         InitPropList();\r
93 \r
94         m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_PROPERTIES);\r
95         m_wndToolBar.LoadToolBar(IDR_PROPERTIES, 0, 0, TRUE /* Is locked */);\r
96         m_wndToolBar.CleanUpLockedImages();\r
97         m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_PROPERTIES_HC : IDR_PROPERTIES, 0, 0, TRUE /* Locked */);\r
98 \r
99         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);\r
100         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));\r
101         m_wndToolBar.SetOwner(this);\r
102 \r
103         // All commands will be routed via this control , not via the parent frame:\r
104         m_wndToolBar.SetRouteCommandsViaFrame(FALSE);\r
105 \r
106         AdjustLayout();\r
107         return 0;\r
108 }\r
109 \r
110 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)\r
111 {\r
112         CDockablePane::OnSize(nType, cx, cy);\r
113         AdjustLayout();\r
114 }\r
115 \r
116 void CPropertiesWnd::OnExpandAllProperties()\r
117 {\r
118         m_wndPropList.ExpandAll();\r
119 }\r
120 \r
121 void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* pCmdUI)\r
122 {\r
123 }\r
124 \r
125 void CPropertiesWnd::OnSortProperties()\r
126 {\r
127         m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());\r
128 }\r
129 \r
130 void CPropertiesWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)\r
131 {\r
132         pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());\r
133 }\r
134 \r
135 void CPropertiesWnd::OnProperties1()\r
136 {\r
137         // TODO: Add your command handler code here\r
138 }\r
139 \r
140 void CPropertiesWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)\r
141 {\r
142         // TODO: Add your command update UI handler code here\r
143 }\r
144 \r
145 void CPropertiesWnd::OnProperties2()\r
146 {\r
147         // TODO: Add your command handler code here\r
148 }\r
149 \r
150 void CPropertiesWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)\r
151 {\r
152         // TODO: Add your command update UI handler code here\r
153 }\r
154 \r
155 void CPropertiesWnd::InitPropList()\r
156 {\r
157         SetPropListFont();\r
158 \r
159         m_wndPropList.EnableHeaderCtrl(FALSE);\r
160         m_wndPropList.EnableDescriptionArea();\r
161         m_wndPropList.SetVSDotNetLook();\r
162         m_wndPropList.MarkModifiedProperties();\r
163 \r
164         CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Appearance"));\r
165 \r
166         pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("3D Look"), (_variant_t) false, _T("Specifies the window's font will be non-bold and controls will have a 3D border")));\r
167 \r
168         CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("Border"), _T("Dialog Frame"), _T("One of: None, Thin, Resizable, or Dialog Frame"));\r
169         pProp->AddOption(_T("None"));\r
170         pProp->AddOption(_T("Thin"));\r
171         pProp->AddOption(_T("Resizable"));\r
172         pProp->AddOption(_T("Dialog Frame"));\r
173         pProp->AllowEdit(FALSE);\r
174 \r
175         pGroup1->AddSubItem(pProp);\r
176         pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Caption"), (_variant_t) _T("About"), _T("Specifies the text that will be displayed in the window's title bar")));\r
177 \r
178         m_wndPropList.AddProperty(pGroup1);\r
179 \r
180         CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Window Size"), 0, TRUE);\r
181 \r
182         pProp = new CMFCPropertyGridProperty(_T("Height"), (_variant_t) 250l, _T("Specifies the window's height"));\r
183         pProp->EnableSpinControl(TRUE, 0, 1000);\r
184         pSize->AddSubItem(pProp);\r
185 \r
186         pProp = new CMFCPropertyGridProperty( _T("Width"), (_variant_t) 150l, _T("Specifies the window's width"));\r
187         pProp->EnableSpinControl();\r
188         pSize->AddSubItem(pProp);\r
189 \r
190         m_wndPropList.AddProperty(pSize);\r
191 \r
192         CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Font"));\r
193 \r
194         LOGFONT lf;\r
195         CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));\r
196         font->GetLogFont(&lf);\r
197 \r
198         lstrcpy(lf.lfFaceName, _T("Arial"));\r
199 \r
200         pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Font"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the window")));\r
201         pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Use System Font"), (_variant_t) true, _T("Specifies that the window uses MS Shell Dlg font")));\r
202 \r
203         m_wndPropList.AddProperty(pGroup2);\r
204 \r
205         CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc"));\r
206         pProp = new CMFCPropertyGridProperty(_T("(Name)"), _T("Application"));\r
207         pProp->Enable(FALSE);\r
208         pGroup3->AddSubItem(pProp);\r
209 \r
210         CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Window Color"), RGB(210, 192, 254), NULL, _T("Specifies the default window color"));\r
211         pColorProp->EnableOtherButton(_T("Other..."));\r
212         pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));\r
213         pGroup3->AddSubItem(pColorProp);\r
214 \r
215         static TCHAR BASED_CODE szFilter[] = _T("Icon Files(*.ico)|*.ico|All Files(*.*)|*.*||");\r
216         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Icon"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Specifies the window icon")));\r
217 \r
218         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Folder"), _T("c:\\")));\r
219 \r
220         m_wndPropList.AddProperty(pGroup3);\r
221 \r
222         CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Hierarchy"));\r
223 \r
224         CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("First sub-level"));\r
225         pGroup4->AddSubItem(pGroup41);\r
226 \r
227         CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Second sub-level"));\r
228         pGroup41->AddSubItem(pGroup411);\r
229 \r
230         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 1"), (_variant_t) _T("Value 1"), _T("This is a description")));\r
231         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 2"), (_variant_t) _T("Value 2"), _T("This is a description")));\r
232         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 3"), (_variant_t) _T("Value 3"), _T("This is a description")));\r
233 \r
234         pGroup4->Expand(FALSE);\r
235         m_wndPropList.AddProperty(pGroup4);\r
236 }\r
237 \r
238 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)\r
239 {\r
240         CDockablePane::OnSetFocus(pOldWnd);\r
241         m_wndPropList.SetFocus();\r
242 }\r
243 \r
244 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)\r
245 {\r
246         CDockablePane::OnSettingChange(uFlags, lpszSection);\r
247         SetPropListFont();\r
248 }\r
249 \r
250 void CPropertiesWnd::SetPropListFont()\r
251 {\r
252         ::DeleteObject(m_fntPropList.Detach());\r
253 \r
254         LOGFONT lf;\r
255         afxGlobalData.fontRegular.GetLogFont(&lf);\r
256 \r
257         NONCLIENTMETRICS info;\r
258         info.cbSize = sizeof(info);\r
259 \r
260         afxGlobalData.GetNonClientMetrics(info);\r
261 \r
262         lf.lfHeight = info.lfMenuFont.lfHeight;\r
263         lf.lfWeight = info.lfMenuFont.lfWeight;\r
264         lf.lfItalic = info.lfMenuFont.lfItalic;\r
265 \r
266         m_fntPropList.CreateFontIndirect(&lf);\r
267 \r
268         m_wndPropList.SetFont(&m_fntPropList);\r
269 }\r