OSDN Git Service

0133460588ae3b3140d4523eba6c3e35ba530951
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / MainFrm.cpp
1 \r
2 // MainFrm.cpp : implementation of the CMainFrame class\r
3 //\r
4 \r
5 #include "stdafx.h"\r
6 #include "TortoiseGitBlame.h"\r
7 \r
8 #include "MainFrm.h"\r
9 \r
10 #ifdef _DEBUG\r
11 #define new DEBUG_NEW\r
12 #endif\r
13 \r
14 // CMainFrame\r
15 \r
16 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)\r
17 \r
18 const int  iMaxUserToolbars = 10;\r
19 const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;\r
20 const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;\r
21 \r
22 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)\r
23         ON_WM_CREATE()\r
24         // Global help commands\r
25         ON_COMMAND(ID_HELP_FINDER, &CFrameWndEx::OnHelpFinder)\r
26         ON_COMMAND(ID_HELP, &CFrameWndEx::OnHelp)\r
27         ON_COMMAND(ID_CONTEXT_HELP, &CFrameWndEx::OnContextHelp)\r
28         ON_COMMAND(ID_DEFAULT_HELP, &CFrameWndEx::OnHelpFinder)\r
29         ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)\r
30         ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)\r
31         ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnApplicationLook)\r
32         ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnUpdateApplicationLook)\r
33 END_MESSAGE_MAP()\r
34 \r
35 static UINT indicators[] =\r
36 {\r
37         ID_SEPARATOR,           // status line indicator\r
38         ID_INDICATOR_CAPS,\r
39         ID_INDICATOR_NUM,\r
40         ID_INDICATOR_SCRL,\r
41 };\r
42 \r
43 // CMainFrame construction/destruction\r
44 \r
45 CMainFrame::CMainFrame()\r
46 {\r
47         // TODO: add member initialization code here\r
48         theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);\r
49 }\r
50 \r
51 CMainFrame::~CMainFrame()\r
52 {\r
53 }\r
54 \r
55 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
56 {\r
57         if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)\r
58                 return -1;\r
59 \r
60         BOOL bNameValid;\r
61         // set the visual manager and style based on persisted value\r
62         OnApplicationLook(theApp.m_nAppLook);\r
63 \r
64         if (!m_wndMenuBar.Create(this))\r
65         {\r
66                 TRACE0("Failed to create menubar\n");\r
67                 return -1;      // fail to create\r
68         }\r
69 \r
70         m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);\r
71 \r
72         // prevent the menu bar from taking the focus on activation\r
73         CMFCPopupMenu::SetForceMenuFocus(FALSE);\r
74 \r
75         if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||\r
76                 !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_TORTOISE_GIT_BLAME_MAINFRAME_256 : IDR_TORTOISE_GIT_BLAME_MAINFRAME))\r
77         {\r
78                 TRACE0("Failed to create toolbar\n");\r
79                 return -1;      // fail to create\r
80         }\r
81 \r
82         CString strToolBarName;\r
83         bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);\r
84         ASSERT(bNameValid);\r
85         m_wndToolBar.SetWindowText(strToolBarName);\r
86 \r
87         CString strCustomize;\r
88         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
89         ASSERT(bNameValid);\r
90         m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
91 \r
92         // Allow user-defined toolbars operations:\r
93         InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);\r
94 \r
95         if (!m_wndStatusBar.Create(this))\r
96         {\r
97                 TRACE0("Failed to create status bar\n");\r
98                 return -1;      // fail to create\r
99         }\r
100         m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));\r
101 \r
102         // TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable\r
103         m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);\r
104         m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);\r
105         EnableDocking(CBRS_ALIGN_ANY);\r
106         DockPane(&m_wndMenuBar);\r
107         DockPane(&m_wndToolBar);\r
108 \r
109 \r
110         // enable Visual Studio 2005 style docking window behavior\r
111         CDockingManager::SetDockingMode(DT_SMART);\r
112         // enable Visual Studio 2005 style docking window auto-hide behavior\r
113         EnableAutoHidePanes(CBRS_ALIGN_ANY);\r
114 \r
115         // create docking windows\r
116         if (!CreateDockingWindows())\r
117         {\r
118                 TRACE0("Failed to create docking windows\n");\r
119                 return -1;\r
120         }\r
121 \r
122         m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);\r
123         DockPane(&m_wndOutput);\r
124         m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);\r
125         DockPane(&m_wndProperties);\r
126 \r
127 \r
128         // Enable toolbar and docking window menu replacement\r
129         EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);\r
130 \r
131         // enable quick (Alt+drag) toolbar customization\r
132         CMFCToolBar::EnableQuickCustomization();\r
133 \r
134         if (CMFCToolBar::GetUserImages() == NULL)\r
135         {\r
136                 // load user-defined toolbar images\r
137                 if (m_UserImages.Load(_T(".\\UserImages.bmp")))\r
138                 {\r
139                         m_UserImages.SetImageSize(CSize(16, 16), FALSE);\r
140                         CMFCToolBar::SetUserImages(&m_UserImages);\r
141                 }\r
142         }\r
143 \r
144         // enable menu personalization (most-recently used commands)\r
145         // TODO: define your own basic commands, ensuring that each pulldown menu has at least one basic command.\r
146         CList<UINT, UINT> lstBasicCommands;\r
147 \r
148         lstBasicCommands.AddTail(ID_FILE_NEW);\r
149         lstBasicCommands.AddTail(ID_FILE_OPEN);\r
150         lstBasicCommands.AddTail(ID_FILE_SAVE);\r
151         lstBasicCommands.AddTail(ID_FILE_PRINT);\r
152         lstBasicCommands.AddTail(ID_APP_EXIT);\r
153         lstBasicCommands.AddTail(ID_EDIT_CUT);\r
154         lstBasicCommands.AddTail(ID_EDIT_PASTE);\r
155         lstBasicCommands.AddTail(ID_EDIT_UNDO);\r
156         lstBasicCommands.AddTail(ID_APP_ABOUT);\r
157         lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);\r
158         lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);\r
159         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003);\r
160         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005);\r
161         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE);\r
162         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER);\r
163         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK);\r
164         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA);\r
165 \r
166         CMFCToolBar::SetBasicCommands(lstBasicCommands);\r
167 \r
168         return 0;\r
169 }\r
170 \r
171 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)\r
172 {\r
173         if( !CFrameWndEx::PreCreateWindow(cs) )\r
174                 return FALSE;\r
175         // TODO: Modify the Window class or styles here by modifying\r
176         //  the CREATESTRUCT cs\r
177 \r
178         return TRUE;\r
179 }\r
180 \r
181 BOOL CMainFrame::CreateDockingWindows()\r
182 {\r
183         BOOL bNameValid;\r
184         // Create output window\r
185         CString strOutputWnd;\r
186         bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);\r
187         ASSERT(bNameValid);\r
188         if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))\r
189         {\r
190                 TRACE0("Failed to create Output window\n");\r
191                 return FALSE; // failed to create\r
192         }\r
193 \r
194         // Create properties window\r
195         CString strPropertiesWnd;\r
196         bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);\r
197         ASSERT(bNameValid);\r
198         if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))\r
199         {\r
200                 TRACE0("Failed to create Properties window\n");\r
201                 return FALSE; // failed to create\r
202         }\r
203 \r
204         SetDockingWindowIcons(theApp.m_bHiColorIcons);\r
205         return TRUE;\r
206 }\r
207 \r
208 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)\r
209 {\r
210         HICON hOutputBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_OUTPUT_WND_HC : IDI_OUTPUT_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);\r
211         m_wndOutput.SetIcon(hOutputBarIcon, FALSE);\r
212 \r
213         HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);\r
214         m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);\r
215 \r
216 }\r
217 \r
218 // CMainFrame diagnostics\r
219 \r
220 #ifdef _DEBUG\r
221 void CMainFrame::AssertValid() const\r
222 {\r
223         CFrameWndEx::AssertValid();\r
224 }\r
225 \r
226 void CMainFrame::Dump(CDumpContext& dc) const\r
227 {\r
228         CFrameWndEx::Dump(dc);\r
229 }\r
230 #endif //_DEBUG\r
231 \r
232 \r
233 // CMainFrame message handlers\r
234 \r
235 void CMainFrame::OnViewCustomize()\r
236 {\r
237         CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */);\r
238         pDlgCust->EnableUserDefinedToolbars();\r
239         pDlgCust->Create();\r
240 }\r
241 \r
242 LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)\r
243 {\r
244         LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp);\r
245         if (lres == 0)\r
246         {\r
247                 return 0;\r
248         }\r
249 \r
250         CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;\r
251         ASSERT_VALID(pUserToolbar);\r
252 \r
253         BOOL bNameValid;\r
254         CString strCustomize;\r
255         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
256         ASSERT(bNameValid);\r
257 \r
258         pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
259         return lres;\r
260 }\r
261 \r
262 void CMainFrame::OnApplicationLook(UINT id)\r
263 {\r
264         CWaitCursor wait;\r
265 \r
266         theApp.m_nAppLook = id;\r
267 \r
268         switch (theApp.m_nAppLook)\r
269         {\r
270         case ID_VIEW_APPLOOK_WIN_2000:\r
271                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));\r
272                 break;\r
273 \r
274         case ID_VIEW_APPLOOK_OFF_XP:\r
275                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));\r
276                 break;\r
277 \r
278         case ID_VIEW_APPLOOK_WIN_XP:\r
279                 CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;\r
280                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));\r
281                 break;\r
282 \r
283         case ID_VIEW_APPLOOK_OFF_2003:\r
284                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));\r
285                 CDockingManager::SetDockingMode(DT_SMART);\r
286                 break;\r
287 \r
288         case ID_VIEW_APPLOOK_VS_2005:\r
289                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));\r
290                 CDockingManager::SetDockingMode(DT_SMART);\r
291                 break;\r
292 \r
293         default:\r
294                 switch (theApp.m_nAppLook)\r
295                 {\r
296                 case ID_VIEW_APPLOOK_OFF_2007_BLUE:\r
297                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);\r
298                         break;\r
299 \r
300                 case ID_VIEW_APPLOOK_OFF_2007_BLACK:\r
301                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);\r
302                         break;\r
303 \r
304                 case ID_VIEW_APPLOOK_OFF_2007_SILVER:\r
305                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);\r
306                         break;\r
307 \r
308                 case ID_VIEW_APPLOOK_OFF_2007_AQUA:\r
309                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);\r
310                         break;\r
311                 }\r
312 \r
313                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));\r
314                 CDockingManager::SetDockingMode(DT_SMART);\r
315         }\r
316 \r
317         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);\r
318 \r
319         theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);\r
320 }\r
321 \r
322 void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)\r
323 {\r
324         pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);\r
325 }\r
326 \r
327 BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) \r
328 {\r
329         // base class does the real work\r
330 \r
331         if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))\r
332         {\r
333                 return FALSE;\r
334         }\r
335 \r
336 \r
337         // enable customization button for all user toolbars\r
338         BOOL bNameValid;\r
339         CString strCustomize;\r
340         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
341         ASSERT(bNameValid);\r
342 \r
343         for (int i = 0; i < iMaxUserToolbars; i ++)\r
344         {\r
345                 CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);\r
346                 if (pUserToolbar != NULL)\r
347                 {\r
348                         pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
349                 }\r
350         }\r
351 \r
352         return TRUE;\r
353 }\r
354 \r